Skip to content

Commit ed40758

Browse files
authored
Merge pull request #971 from bigevilbeard/fix-mroute-mbps-support
Fix: Support mbps/kbps/gbps in show ip mroute summary parser
2 parents bad8497 + 0a73313 commit ed40758

File tree

6 files changed

+248
-4
lines changed

6 files changed

+248
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--------------------------------------------------------------------------------
2+
New
3+
--------------------------------------------------------------------------------
4+
* NXOS
5+
* Modified ShowIpMrouteSummary:
6+
* Updated regex pattern p8 to capture bitrate_unit with optional k/m/g/t prefixes.
7+
* Added conversion logic to normalize bitrate values to bps format.
8+
* Modified ShowIpv6MrouteSummary:
9+
* Updated regex pattern p8 to capture bitrate_unit with optional k/m/g/t prefixes.
10+
* Added conversion logic to normalize bitrate values to bps format.

src/genie/libs/parser/nxos/show_mcast.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ def cli(self, vrf="default", output=None):
10931093
#100.100.100.5 1743 88893 51 0 27.200 bps 1
10941094
#(*,G) 0 0 0 0 0.000 bps 2
10951095
p8 = re.compile(r'^\s*(?P<source>\S+) +(?P<packets>[0-9]+) +(?P<bytes>[0-9]+) +(?P<aps>[0-9]+) +(?P<pps>[0-9]+) +'
1096-
r'(?P<bitrate>[0-9.]+) +bps +(?P<oifs>[0-9]+)$')
1096+
r'(?P<bitrate>[0-9.]+) +(?P<bitrate_unit>[kmgt]?bps) +(?P<oifs>[0-9]+)$')
10971097

10981098
for line in out.splitlines():
10991099
line = line.strip()
@@ -1139,8 +1139,23 @@ def cli(self, vrf="default", output=None):
11391139
continue
11401140
m = p8.match(line)
11411141
if m:
1142+
# Capture the values
1143+
bitrate_value = float(m.groupdict()['bitrate'])
1144+
bitrate_unit = m.groupdict()['bitrate_unit']
1145+
1146+
# Convert to bps
1147+
conversion_factors = {
1148+
'bps': 1,
1149+
'kbps': 1000,
1150+
'mbps': 1000000,
1151+
'gbps': 1000000000,
1152+
'tbps': 1000000000000
1153+
}
1154+
1155+
bitrate_in_bps = bitrate_value * conversion_factors.get(bitrate_unit, 1)
1156+
11421157
src_dict = group_dict.setdefault('source',{}).setdefault(m.groupdict()['source'],{})
1143-
src_dict.update({'packets': int(m.groupdict()['packets']),'bytes': int(m.groupdict()['bytes']),'aps': int(m.groupdict()['aps']),'pps': int(m.groupdict()['pps']),'bitrate': float(m.groupdict()['bitrate']),'bitrate_unit':'bps','oifs': int(m.groupdict()['oifs'])})
1158+
src_dict.update({'packets': int(m.groupdict()['packets']),'bytes': int(m.groupdict()['bytes']),'aps': int(m.groupdict()['aps']),'pps': int(m.groupdict()['pps']),'bitrate': bitrate_in_bps,'bitrate_unit':'bps','oifs': int(m.groupdict()['oifs'])})
11441159
continue
11451160
return mroute_dict
11461161

@@ -1231,7 +1246,7 @@ def cli(self, vrf="default", output=None):
12311246
#2001:180:1:57::1181 968 49478 51 0 0.000 bps 1
12321247
#(*,G) 0 0 0 0 0.000 bps 2
12331248
p8 = re.compile(r'^\s*(?P<source>\S+) +(?P<packets>[0-9]+) +(?P<bytes>[0-9]+) +(?P<aps>[0-9]+) +(?P<pps>[0-9]+) +'
1234-
r'(?P<bitrate>[0-9.]+) +bps +(?P<oifs>[0-9]+)$')
1249+
r'(?P<bitrate>[0-9.]+) +(?P<bitrate_unit>[kmgt]?bps) +(?P<oifs>[0-9]+)$')
12351250

12361251
for line in out.splitlines():
12371252
line = line.strip()
@@ -1276,7 +1291,22 @@ def cli(self, vrf="default", output=None):
12761291
continue
12771292
m = p8.match(line)
12781293
if m:
1294+
# Capture the values
1295+
bitrate_value = float(m.groupdict()['bitrate'])
1296+
bitrate_unit = m.groupdict()['bitrate_unit']
1297+
1298+
# Convert to bps
1299+
conversion_factors = {
1300+
'bps': 1,
1301+
'kbps': 1000,
1302+
'mbps': 1000000,
1303+
'gbps': 1000000000,
1304+
'tbps': 1000000000000
1305+
}
1306+
1307+
bitrate_in_bps = bitrate_value * conversion_factors.get(bitrate_unit, 1)
1308+
12791309
src_dict = group_dict.setdefault('source',{}).setdefault(m.groupdict()['source'],{})
1280-
src_dict.update({'packets': int(m.groupdict()['packets']),'bytes': int(m.groupdict()['bytes']),'aps': int(m.groupdict()['aps']),'pps': int(m.groupdict()['pps']),'bitrate': float(m.groupdict()['bitrate']),'bitrate_unit':'bps','oifs': int(m.groupdict()['oifs'])})
1310+
src_dict.update({'packets': int(m.groupdict()['packets']),'bytes': int(m.groupdict()['bytes']),'aps': int(m.groupdict()['aps']),'pps': int(m.groupdict()['pps']),'bitrate': bitrate_in_bps,'bitrate_unit':'bps','oifs': int(m.groupdict()['oifs'])})
12811311
continue
12821312
return mroute_dict
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
expected_output = {
2+
'vrf': {
3+
'default': {
4+
'address_family': {
5+
'ipv4': {
6+
'count_multicast_starg': 2,
7+
'count_multicast_sg': 4,
8+
'count_multicast_starg_prefix': 0,
9+
'count_multicast_total': 6,
10+
'group_count': 2,
11+
'avg_source_per_group': 2.0,
12+
'groups': {
13+
'225.0.0.1/32': {
14+
'source_count': 2,
15+
'source': {
16+
'(*,G)': {
17+
'packets': 0,
18+
'bytes': 0,
19+
'aps': 0,
20+
'pps': 0,
21+
'bitrate': 0.0,
22+
'bitrate_unit': 'bps',
23+
'oifs': 2
24+
},
25+
'100.100.100.5': {
26+
'packets': 1704,
27+
'bytes': 86904,
28+
'aps': 51,
29+
'pps': 0,
30+
'bitrate': 1500000.0,
31+
'bitrate_unit': 'bps',
32+
'oifs': 2
33+
},
34+
'100.100.100.6': {
35+
'packets': 1700,
36+
'bytes': 86700,
37+
'aps': 51,
38+
'pps': 0,
39+
'bitrate': 500000.0,
40+
'bitrate_unit': 'bps',
41+
'oifs': 1
42+
}
43+
}
44+
},
45+
'225.0.0.2/32': {
46+
'source_count': 2,
47+
'source': {
48+
'(*,G)': {
49+
'packets': 0,
50+
'bytes': 0,
51+
'aps': 0,
52+
'pps': 0,
53+
'bitrate': 0.0,
54+
'bitrate_unit': 'bps',
55+
'oifs': 2
56+
},
57+
'100.100.100.7': {
58+
'packets': 1743,
59+
'bytes': 88893,
60+
'aps': 51,
61+
'pps': 0,
62+
'bitrate': 2000000000.0,
63+
'bitrate_unit': 'bps',
64+
'oifs': 1
65+
},
66+
'100.100.100.8': {
67+
'packets': 1891,
68+
'bytes': 100806,
69+
'aps': 53,
70+
'pps': 0,
71+
'bitrate': 1000000000000.0,
72+
'bitrate_unit': 'bps',
73+
'oifs': 2
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}
82+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
IP Multicast Routing Table for VRF "default"
2+
Route Statistics unavailable - only liveness detected
3+
4+
Total number of routes: 6
5+
Total number of (*,G) routes: 2
6+
Total number of (S,G) routes: 4
7+
Total number of (*,G-prefix) routes: 0
8+
Group count: 2, rough average sources per group: 2.0
9+
10+
Group: 225.0.0.1/32, Source count: 2
11+
Source packets bytes aps pps bit-rate oifs
12+
(*,G) 0 0 0 0 0.000 bps 2
13+
100.100.100.5 1704 86904 51 0 1.500 mbps 2
14+
100.100.100.6 1700 86700 51 0 500.000 kbps 1
15+
16+
Group: 225.0.0.2/32, Source count: 2
17+
Source packets bytes aps pps bit-rate oifs
18+
(*,G) 0 0 0 0 0.000 bps 2
19+
100.100.100.7 1743 88893 51 0 2.000 gbps 1
20+
100.100.100.8 1891 100806 53 0 1.000 tbps 2
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
expected_output = {
2+
'vrf': {
3+
'default': {
4+
'address_family': {
5+
'ipv6': {
6+
'count_multicast_starg': 2,
7+
'count_multicast_sg': 4,
8+
'count_multicast_starg_prefix': 0,
9+
'count_multicast_total': 6,
10+
'group_count': 2,
11+
'avg_source_per_group': 2.0,
12+
'groups': {
13+
'ff32::/32': {
14+
'source_count': 2,
15+
'source': {
16+
'(*,G)': {
17+
'packets': 0,
18+
'bytes': 0,
19+
'aps': 0,
20+
'pps': 0,
21+
'bitrate': 0.0,
22+
'bitrate_unit': 'bps',
23+
'oifs': 2
24+
},
25+
'2001:180:1:57::1181': {
26+
'packets': 968,
27+
'bytes': 49478,
28+
'aps': 51,
29+
'pps': 0,
30+
'bitrate': 1500000.0,
31+
'bitrate_unit': 'bps',
32+
'oifs': 1
33+
},
34+
'2001:180:1:57::1182': {
35+
'packets': 970,
36+
'bytes': 49580,
37+
'aps': 51,
38+
'pps': 0,
39+
'bitrate': 750000.0,
40+
'bitrate_unit': 'bps',
41+
'oifs': 1
42+
}
43+
}
44+
},
45+
'ff33:0:0:1197::1/128': {
46+
'source_count': 2,
47+
'source': {
48+
'(*,G)': {
49+
'packets': 0,
50+
'bytes': 0,
51+
'aps': 0,
52+
'pps': 0,
53+
'bitrate': 0.0,
54+
'bitrate_unit': 'bps',
55+
'oifs': 2
56+
},
57+
'2001:180:1:57::1183': {
58+
'packets': 1000,
59+
'bytes': 51000,
60+
'aps': 52,
61+
'pps': 0,
62+
'bitrate': 3000000000.0,
63+
'bitrate_unit': 'bps',
64+
'oifs': 1
65+
},
66+
'2001:180:1:57::1184': {
67+
'packets': 1100,
68+
'bytes': 56100,
69+
'aps': 53,
70+
'pps': 0,
71+
'bitrate': 2000000000000.0,
72+
'bitrate_unit': 'bps',
73+
'oifs': 2
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}
82+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
IPv6 Multicast Routing Table for VRF "default"
2+
Route Statistics unavailable - only liveness detected
3+
4+
Total number of routes: 6
5+
Total number of (*,G) routes: 2
6+
Total number of (S,G) routes: 4
7+
Total number of (*,G-prefix) routes: 0
8+
Group count: 2, rough average sources per group: 2.0
9+
10+
Group: ff32::/32, Source count: 2
11+
Source packets bytes aps pps bit-rate oifs
12+
(*,G) 0 0 0 0 0.000 bps 2
13+
2001:180:1:57::1181 968 49478 51 0 1.500 mbps 1
14+
2001:180:1:57::1182 970 49580 51 0 750.000 kbps 1
15+
16+
Group: ff33:0:0:1197::1/128, Source count: 2
17+
Source packets bytes aps pps bit-rate oifs
18+
(*,G) 0 0 0 0 0.000 bps 2
19+
2001:180:1:57::1183 1000 51000 52 0 3.000 gbps 1
20+
2001:180:1:57::1184 1100 56100 53 0 2.000 tbps 2

0 commit comments

Comments
 (0)