Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOS-XR] Fix show vrf all detail parser - capture all interface names #911

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--------------------------------------------------------------------------------
Fix
--------------------------------------------------------------------------------
* IOSXR
* Modified ShowVrfAllDetail:
* Modified regex <p4_1> to capture all interface names
* Replaced the previous regex that relied on specific interface prefixes (e.g., Gi, Bun, Ten, etc.) with a more general pattern.
* Introduced `in_interfaces_section` flag for accurate section tracking
25 changes: 15 additions & 10 deletions src/genie/libs/parser/iosxr/show_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def cli(self, vrf='', output=None):
vrf_dict = {}
af_dict = {}
rt_type = None
in_interfaces_section = False # Initialize here

for line in out.splitlines():
line = line.replace('\t', ' ')
Expand Down Expand Up @@ -107,18 +108,22 @@ def cli(self, vrf='', output=None):
m = p4.match(line)
if m:
vrf_dict[vrf]['interfaces'] = []
in_interfaces_section = True
continue
# GigabitEthernet0/0/0/0.390
# Bundle-Ether15.514
p4_1 = re.compile(r'^(?P<intf>([G|g]i.*|[B|b]un.*|'
r'[T|t]en.*|[P|p]o.*|[V|v]lan.*|'
r'[L|l]o.*))$')

m = p4_1.match(line)
if m:
intf = m.groupdict()['intf']
vrf_dict[vrf]['interfaces'].append(intf)
continue
if in_interfaces_section:
# Match interface lines
# GigabitEthernet0/0/0/0.390
# Bundle-Ether15.514
p4_1 = re.compile(r'^(?P<intf>[A-Za-z][-A-Za-z0-9/.:]+)$')
m = p4_1.match(line)
if m:
intf = m.groupdict()['intf']
vrf_dict[vrf]['interfaces'].append(intf)
continue
else:
# Exit the Interfaces section when a non-interface line is encountered
in_interfaces_section = False

# Address family IPV4 Unicast
p5 = re.compile(r'^Address +family +(?P<af>[\w\s]+)$')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
expected_output = {
"TEST_1": {
"address_family": {
"ipv4 unicast": {
"route_target": {
"1234:5678": {"route_target": "1234:5678", "rt_type": "import"},
"8765:4321": {"route_target": "8765:4321", "rt_type": "export"},
}
},
"ipv6 unicast": {},
},
"description": "not set",
"interfaces": [
"GigabitEthernet0/0/0/0.2",
"Gi0/0/0/0.1",
"GigabitEthernet0/0/0/1",
"Gi0/0/0/4",
"TenGigE0/0/0/0.1",
"TenGigabitEthernet0/0/0/0.2",
"Te0/0/0/0.3",
],
"route_distinguisher": "10.10.10.10:10",
"vrf_mode": "regular",
},
"TEST_2": {
"address_family": {
"ipv4 unicast": {
"route_target": {
"1111:2222": {"route_target": "1111:2222", "rt_type": "import"},
"2222:1111": {"route_target": "2222:1111", "rt_type": "export"},
}
},
"ipv6 unicast": {},
},
"description": "not set",
"interfaces": [
"FortyGigE0/0/0/0.1",
"FortyGigabitEthernet0/0/0/0.2",
"Fo0/0/0/0.3",
"FortyGigE0/0/0/1",
"FortyGigabitEthernet0/0/0/2",
"Fo0/0/0/3",
"HundredGigE0/0/0/0.1",
"HundredGigabitEthernet0/0/0/0.2",
"Hu0/0/0/0.3",
"HundredGigE0/0/0/1",
"HundredGigabitEthernet0/0/0/2",
"Hu0/0/0/3",
],
"route_distinguisher": "1.2.3.4:5",
"vrf_mode": "regular",
},
"TEST_3": {
"address_family": {
"ipv4 unicast": {
"route_target": {
"13285:56891": {"route_target": "13285:56891", "rt_type": "export"},
"7984:4657": {"route_target": "7984:4657", "rt_type": "import"},
}
},
"ipv6 unicast": {},
},
"description": "not set",
"interfaces": [
"Bundle-Ether0",
"Bundle-Ethernet1",
"BE2",
"Loopback1",
"Lo0",
"Null0",
"Nu1",
"MgmtEth0/RP0/CPU0/0",
"ManagementEthernet1/RP0/CPU0/0",
"MgmtEth0/0/3",
],
"route_distinguisher": "5.4.3.2:1",
"vrf_mode": "regular",
},
"TEST_4": {
"address_family": {
"ipv4 unicast": {
"route_target": {
"1111:1111": {"route_target": "1111:1111", "rt_type": "export"},
"7985:4654": {"route_target": "7985:4654", "rt_type": "import"},
}
},
"ipv6 unicast": {},
},
"description": "not set",
"interfaces": ["POS0/0/0/0", "PacketOverSonet0/0/0/1", "PoS0/0/0/2"],
"route_distinguisher": "1.1.1.1:1",
"vrf_mode": "regular",
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
VRF TEST_1; RD 10.10.10.10:10; VPN ID not set
VRF mode: Regular
Description not set
Interfaces:
GigabitEthernet0/0/0/0.2
Gi0/0/0/0.1
GigabitEthernet0/0/0/1
Gi0/0/0/4
TenGigE0/0/0/0.1
TenGigabitEthernet0/0/0/0.2
Te0/0/0/0.3
Address family IPV4 Unicast
Import VPN route-target communities:
RT:1234:5678
Export VPN route-target communities:
RT:8765:4321
No import route policy
No export route policy
Address family IPV6 Unicast
No import VPN route-target communities
No export VPN route-target communities
No import route policy
No export route policy

VRF TEST_2; RD 1.2.3.4:5; VPN ID not set
VRF mode: Regular
Description not set
Interfaces:
FortyGigE0/0/0/0.1
FortyGigabitEthernet0/0/0/0.2
Fo0/0/0/0.3
FortyGigE0/0/0/1
FortyGigabitEthernet0/0/0/2
Fo0/0/0/3
HundredGigE0/0/0/0.1
HundredGigabitEthernet0/0/0/0.2
Hu0/0/0/0.3
HundredGigE0/0/0/1
HundredGigabitEthernet0/0/0/2
Hu0/0/0/3
Address family IPV4 Unicast
Import VPN route-target communities:
RT:1111:2222
Export VPN route-target communities:
RT:2222:1111
No import route policy
No export route policy
Address family IPV6 Unicast
No import VPN route-target communities
No export VPN route-target communities
No import route policy
No export route policy

VRF TEST_3; RD 5.4.3.2:1; VPN ID not set
VRF mode: Regular
Description not set
Interfaces:
Bundle-Ether0
Bundle-Ethernet1
BE2
Loopback1
Lo0
Null0
Nu1
MgmtEth0/RP0/CPU0/0
ManagementEthernet1/RP0/CPU0/0
MgmtEth0/0/3
Address family IPV4 Unicast
Import VPN route-target communities:
RT:7984:4657
Export VPN route-target communities:
RT:13285:56891
No import route policy
No export route policy
Address family IPV6 Unicast
No import VPN route-target communities
No export VPN route-target communities
No import route policy
No export route policy

VRF TEST_4; RD 1.1.1.1:1; VPN ID not set
VRF mode: Regular
Description not set
Interfaces:
POS0/0/0/0
PacketOverSonet0/0/0/1
PoS0/0/0/2
Address family IPV4 Unicast
Import VPN route-target communities:
RT:7985:4654
Export VPN route-target communities:
RT:1111:1111
No import route policy
No export route policy
Address family IPV6 Unicast
No import VPN route-target communities
No export VPN route-target communities
No import route policy
No export route policy
Loading