Skip to content

Commit 529dba9

Browse files
authored
Merge pull request #822 from Kani999/extend-show-bgp-address-family-class
Extend ShowBgpAddressFamily class to parse additional BGP commands
2 parents 18e3046 + 6aafd21 commit 529dba9

File tree

9 files changed

+762
-14
lines changed

9 files changed

+762
-14
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--------------------------------------------------------------------------------
2+
Fix
3+
--------------------------------------------------------------------------------
4+
* IOSXR
5+
* Modified ShowBgpAddressFamily:
6+
* New Show Command - show bgp {address_family} community {community}
7+
* New Show Command - show bgp {address_family} community {community} {exact_match}
8+
* Updated regex for handling IPv6 adresses/prefixes
9+
* Updated regex pattern for handling new lines in IPv6 address family output

sdk_generator/outputs/github_parser.json

Lines changed: 36 additions & 4 deletions
Large diffs are not rendered by default.

src/genie/libs/parser/iosxr/show_bgp.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8696,9 +8696,16 @@ def cli(self, vrf=None, address_family=None, summary=None, value=None, output=No
86968696
# *>i10.169.1.0/24 10.64.4.4 2219 100 0 300 33299 51178 47751 {27016} e
86978697
# *>i192.168.111.0/24 10.189.99.98 0 0 i
86988698
# *> 10.7.7.7/32 10.10.10.107 0 0 65107.65107 ?
8699+
# OR
8700+
# s>i2001:718::2:99/128 195.113.156.4 0 100 0 i
8701+
# s i 195.113.156.4 0 100 0 i
8702+
# s>i2001:718::2:101/128
8703+
# 10.2.8.1 0 100 0 i
8704+
# s i 10.2.8.1 0 100 0 i
8705+
# s>i2001:718::2:116/128
86998706
p13 = re.compile(r'^(?P<status_codes>(i|s|x|S|d|h|\*|\>|\s)+)'
8700-
r' *(?P<prefix>(?P<ip>[0-9\.\:\[\]]+)\/(?P<mask>\d+))?'
8701-
r' +(?P<next_hop>\S+) +(?P<number>[\d\.\s\{\}]+)'
8707+
r' *(?P<prefix>(?P<ip>[0-9a-f\.\:\[\]]+)\/(?P<mask>\d+))?[\n\r]*'
8708+
r' +(?P<next_hop>\S+)[\n\r]* +(?P<number>[\d\.\s\{\}]+)'
87028709
r'(?: *(?P<origin_codes>(i|e|\?)))?$')
87038710

87048711
# Processed 40 prefixes, 50 paths
@@ -9122,16 +9129,23 @@ class ShowBgpAddressFamily(ShowBgpAddressFamilySchema):
91229129
'''Parser for:
91239130
'show bgp'
91249131
'show bgp {address_family}'
9132+
'show bgp {address_family} community {community}'
9133+
'show bgp {address_family} community {community} {exact_match}'
91259134
'''
9135+
cli_command = [
9136+
'show bgp',
9137+
'show bgp {address_family}',
9138+
'show bgp {address_family} community {community}',
9139+
'show bgp {address_family} community {community} {exact_match}',]
91269140

9127-
cli_command = ['show bgp',
9128-
'show bgp {address_family}']
9129-
9130-
def cli(self, address_family=None, output=None):
9131-
9141+
def cli(self, address_family=None, community=None, exact_match=None, output=None):
91329142
# Execute command
91339143
if output is None:
9134-
if address_family:
9144+
if address_family and community and exact_match:
9145+
command = self.cli_command[3].format(address_family=address_family, community=community, exact_match=exact_match)
9146+
elif address_family and community:
9147+
command = self.cli_command[2].format(address_family=address_family, community=community)
9148+
elif address_family:
91359149
command = self.cli_command[1].format(address_family=address_family)
91369150
else:
91379151
command = self.cli_command[0]
@@ -9193,9 +9207,16 @@ def cli(self, address_family=None, output=None):
91939207
# *>i10.169.1.0/24 10.64.4.4 2219 100 0 300 33299 51178 47751 {27016} e
91949208
# *>i192.168.111.0/24 10.189.99.98 0 0 i
91959209
# *> 10.7.7.7/32 10.10.10.107 0 0 65107.65107 ?
9210+
# OR
9211+
# s>i2001:718::2:99/128 195.113.156.4 0 100 0 i
9212+
# s i 195.113.156.4 0 100 0 i
9213+
# s>i2001:718::2:101/128
9214+
# 10.2.8.1 0 100 0 i
9215+
# s i 10.2.8.1 0 100 0 i
9216+
# s>i2001:718::2:116/128
91969217
p11 = re.compile(r'^(?P<status_codes>(i|s|x|S|d|h|\*|\>|\s)+)'
9197-
r' *(?P<prefix>(?P<ip>[0-9\.\:\[\]]+)\/(?P<mask>\d+))?'
9198-
r' +(?P<next_hop>\S+) +(?P<number>[\d\.\s\{\}]+)'
9218+
r' *(?P<prefix>(?P<ip>[0-9a-f\.\:\[\]]+)\/(?P<mask>\d+))?[\n\r]*'
9219+
r' +(?P<next_hop>\S+)[\n\r]* +(?P<number>[\d\.\s\{\}]+)'
91999220
r'(?: *(?P<origin_codes>(i|e|\?)))?$')
92009221

92019222
# Processed 40 prefixes, 50 paths
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"address_family": "ipv6 all",
3+
"community": "1234:1234",
4+
"exact_match": "exact_match"
5+
}
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
expected_output = {
2+
'address_family': {
3+
'ipv6_all': {
4+
'bgp_table_version': 5530,
5+
'generic_scan_interval': 60,
6+
'local_as': 1234,
7+
'non_stop_routing': True,
8+
'nsr_initial_init_ver_status': 'reached',
9+
'nsr_initial_initsync_version': '7',
10+
'nsr_issu_sync_group_versions': '5530/0',
11+
'route_distinguisher': {
12+
'1234:1234': {
13+
'prefix': {
14+
'2001:0db8:85a3:0:0:0:0:1403::/48': {
15+
'index': {
16+
1: {
17+
'locprf': '0',
18+
'next_hop': '192.0.2.1',
19+
'origin_codes': 'i',
20+
'path': '0',
21+
'status_codes': '*>i',
22+
'weight': '100',
23+
},
24+
2: {
25+
'locprf': '0',
26+
'next_hop': '192.0.2.1',
27+
'origin_codes': 'i',
28+
'path': '0',
29+
'status_codes': '*i',
30+
'weight': '100',
31+
},
32+
},
33+
},
34+
'2001:0db8:85a3::/64': {
35+
'index': {
36+
1: {
37+
'locprf': '0',
38+
'next_hop': '192.0.2.1',
39+
'origin_codes': 'i',
40+
'path': '0',
41+
'status_codes': '*>i',
42+
'weight': '100',
43+
},
44+
2: {
45+
'locprf': '0',
46+
'next_hop': '192.0.2.1',
47+
'origin_codes': 'i',
48+
'path': '0',
49+
'status_codes': '*i',
50+
'weight': '100',
51+
},
52+
},
53+
},
54+
},
55+
},
56+
'1234:2505005': {
57+
'prefix': {
58+
'2001:0db8:85a3:0:0:0:0:6:10:205::/112': {
59+
'index': {
60+
1: {
61+
'locprf': '100',
62+
'metric': '4294967295',
63+
'next_hop': '192.0.2.2',
64+
'origin_codes': 'i',
65+
'path': '65031',
66+
'status_codes': '*>i',
67+
'weight': '0',
68+
},
69+
2: {
70+
'locprf': '100',
71+
'metric': '4294967295',
72+
'next_hop': '192.0.2.2',
73+
'origin_codes': 'i',
74+
'path': '65031',
75+
'status_codes': '*i',
76+
'weight': '0',
77+
},
78+
},
79+
},
80+
'2001:0db8:85a3:0:0:0:0:6:192:168:201::/112': {
81+
'index': {
82+
1: {
83+
'locprf': '100',
84+
'metric': '4294967295',
85+
'next_hop': '192.0.2.2',
86+
'origin_codes': 'i',
87+
'path': '65031',
88+
'status_codes': '*>i',
89+
'weight': '0',
90+
},
91+
2: {
92+
'locprf': '100',
93+
'metric': '4294967295',
94+
'next_hop': '192.0.2.2',
95+
'origin_codes': 'i',
96+
'path': '65031',
97+
'status_codes': '*i',
98+
'weight': '0',
99+
},
100+
},
101+
},
102+
'2001:0db8:85a3:0:0:0:0:6:195:113:123:128:0/112': {
103+
'index': {
104+
1: {
105+
'locprf': '100',
106+
'metric': '4294967295',
107+
'next_hop': '192.0.2.2',
108+
'origin_codes': 'i',
109+
'path': '65031',
110+
'status_codes': '*>i',
111+
'weight': '0',
112+
},
113+
2: {
114+
'locprf': '100',
115+
'metric': '4294967295',
116+
'next_hop': '192.0.2.2',
117+
'origin_codes': 'i',
118+
'path': '65031',
119+
'status_codes': '*i',
120+
'weight': '0',
121+
},
122+
},
123+
},
124+
'2001:0db8:85a3:0:0:0:0:6:195:113:123:80/125': {
125+
'index': {
126+
1: {
127+
'locprf': '100',
128+
'metric': '4294967295',
129+
'next_hop': '192.0.2.2',
130+
'origin_codes': 'i',
131+
'path': '65031',
132+
'status_codes': '*>i',
133+
'weight': '0',
134+
},
135+
2: {
136+
'locprf': '100',
137+
'metric': '4294967295',
138+
'next_hop': '192.0.2.2',
139+
'origin_codes': 'i',
140+
'path': '65031',
141+
'status_codes': '*i',
142+
'weight': '0',
143+
},
144+
},
145+
},
146+
'2001:0db8:85a3:0:0:0:0:6:195:113:123:96:0/112': {
147+
'index': {
148+
1: {
149+
'locprf': '100',
150+
'metric': '4294967295',
151+
'next_hop': '192.0.2.2',
152+
'origin_codes': 'i',
153+
'path': '65031',
154+
'status_codes': '*>i',
155+
'weight': '0',
156+
},
157+
2: {
158+
'locprf': '100',
159+
'metric': '4294967295',
160+
'next_hop': '192.0.2.2',
161+
'origin_codes': 'i',
162+
'path': '65031',
163+
'status_codes': '*i',
164+
'weight': '0',
165+
},
166+
},
167+
},
168+
'2001:0db8:85a3:0:0:0:0:6::10/127': {
169+
'index': {
170+
1: {
171+
'locprf': '0',
172+
'next_hop': '192.0.2.2',
173+
'origin_codes': 'i',
174+
'path': '0',
175+
'status_codes': '*>i',
176+
'weight': '100',
177+
},
178+
2: {
179+
'locprf': '0',
180+
'next_hop': '192.0.2.2',
181+
'origin_codes': 'i',
182+
'path': '0',
183+
'status_codes': '*i',
184+
'weight': '100',
185+
},
186+
},
187+
},
188+
},
189+
},
190+
'1234:2505118': {
191+
'prefix': {
192+
'2001:0db8:85a3:0:0:0:0:18::/56': {
193+
'index': {
194+
1: {
195+
'locprf': '100',
196+
'next_hop': '203.0.113.7',
197+
'origin_codes': 'i',
198+
'path': '0',
199+
'status_codes': '*>i',
200+
'weight': '100',
201+
},
202+
2: {
203+
'locprf': '100',
204+
'next_hop': '203.0.113.7',
205+
'origin_codes': 'i',
206+
'path': '0',
207+
'status_codes': '*i',
208+
'weight': '100',
209+
},
210+
},
211+
},
212+
'2001:0db8:85a3:0:0:0:0:1e08::/48': {
213+
'index': {
214+
1: {
215+
'locprf': '100',
216+
'next_hop': '203.0.113.7',
217+
'origin_codes': 'i',
218+
'path': '0',
219+
'status_codes': '*>i',
220+
'weight': '100',
221+
},
222+
2: {
223+
'locprf': '100',
224+
'next_hop': '203.0.113.7',
225+
'origin_codes': 'i',
226+
'path': '0',
227+
'status_codes': '*i',
228+
'weight': '100',
229+
},
230+
},
231+
},
232+
},
233+
},
234+
},
235+
'router_identifier': '192.168.1.1',
236+
'scan_interval': 60,
237+
'table_state': 'active',
238+
},
239+
},
240+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
RP/0/RSP0/CPU0:router# show bgp ivp6 all community 1234:1234 exact-match
2+
Address Family: VPNv6 Unicast
3+
-----------------------------
4+
5+
BGP router identifier 192.168.1.1, local AS number 1234
6+
BGP generic scan interval 60 secs
7+
Non-stop routing is enabled
8+
BGP table state: Active
9+
Table ID: 0x0
10+
BGP main routing table version 5530
11+
BGP NSR Initial initsync version 7 (Reached)
12+
BGP NSR/ISSU Sync-Group versions 5530/0
13+
BGP scan interval 60 secs
14+
15+
Status codes: s suppressed, d damped, h history, * valid, > best i - internal, r RIB-failure, S stale, N Nexthop-discard
16+
Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path
17+
Route Distinguisher: 1234:1234
18+
Route Distinguisher Version: 53
19+
*>i2001:0db8:85a3::/64 192.0.2.1 0 100 0 i
20+
* i 192.0.2.1 0 100 0 i
21+
*>i2001:0db8:85a3:0:0:0:0:1403::/48 192.0.2.1 0 100 0 i
22+
* i 192.0.2.1 0 100 0 i
23+
Route Distinguisher: 1234:2505005
24+
Route Distinguisher Version: 54
25+
*>i2001:0db8:85a3:0:0:0:0:6::10/127 192.0.2.2 0 100 0 i
26+
* i 192.0.2.2 0 100 0 i
27+
*>i2001:0db8:85a3:0:0:0:0:6:195:113:123:80/125 192.0.2.2 4294967295 100 0 65031 i
28+
* i 192.0.2.2 4294967295 100 0 65031 i
29+
*>i2001:0db8:85a3:0:0:0:0:6:10:205::/112 192.0.2.2 4294967295 100 0 65031 i
30+
* i 192.0.2.2 4294967295 100 0 65031 i
31+
*>i2001:0db8:85a3:0:0:0:0:6:192:168:201::/112 192.0.2.2 4294967295 100 0 65031 i
32+
* i 192.0.2.2 4294967295 100 0 65031 i
33+
*>i2001:0db8:85a3:0:0:0:0:6:195:113:123:96:0/112 192.0.2.2 4294967295 100 0 65031 i
34+
* i 192.0.2.2 4294967295 100 0 65031 i
35+
*>i2001:0db8:85a3:0:0:0:0:6:195:113:123:128:0/112 192.0.2.2 4294967295 100 0 65031 i
36+
* i 192.0.2.2 4294967295 100 0 65031 i
37+
Route Distinguisher: 1234:2505118
38+
Route Distinguisher Version: 49
39+
*>i2001:0db8:85a3:0:0:0:0:18::/56 203.0.113.7 100 100 0 i
40+
* i 203.0.113.7 100 100 0 i
41+
*>i2001:0db8:85a3:0:0:0:0:1e08::/48 203.0.113.7 100 100 0 i
42+
* i 203.0.113.7 100 100 0 i
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"vrf": "xNet",
3+
"address_family": "ipv6 unicast"
4+
}

0 commit comments

Comments
 (0)