From 2fb8f3d90e9b2f7495a0ee33a293030bf179a7c0 Mon Sep 17 00:00:00 2001 From: Jan Krupa Date: Fri, 8 Nov 2024 10:32:55 +0100 Subject: [PATCH 1/3] Enhance interface parsing in 'show vrf all detail' parser - Implemented a general regex pattern 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 `r'^(?P[A-Za-z][-A-Za-z0-9/.:]+)$'` - Introduced `in_interfaces_section` flag for accurate section tracking --- src/genie/libs/parser/iosxr/show_vrf.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/genie/libs/parser/iosxr/show_vrf.py b/src/genie/libs/parser/iosxr/show_vrf.py index 6853531210..6f012bf2e8 100755 --- a/src/genie/libs/parser/iosxr/show_vrf.py +++ b/src/genie/libs/parser/iosxr/show_vrf.py @@ -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', ' ') @@ -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([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[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[\w\s]+)$') From b7025671222e8a69a93c371763d0a44a9430abc8 Mon Sep 17 00:00:00 2001 From: Jan Krupa Date: Fri, 8 Nov 2024 10:36:26 +0100 Subject: [PATCH 2/3] Add test for 'show vrf all detail' parser reflecting interface changes --- .../cli/equal/golden_output_4_expected.py | 94 ++++++++++++++++++ .../cli/equal/golden_output_4_output.txt | 99 +++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 src/genie/libs/parser/iosxr/tests/ShowVrfAllDetail/cli/equal/golden_output_4_expected.py create mode 100644 src/genie/libs/parser/iosxr/tests/ShowVrfAllDetail/cli/equal/golden_output_4_output.txt diff --git a/src/genie/libs/parser/iosxr/tests/ShowVrfAllDetail/cli/equal/golden_output_4_expected.py b/src/genie/libs/parser/iosxr/tests/ShowVrfAllDetail/cli/equal/golden_output_4_expected.py new file mode 100644 index 0000000000..25ed7f5551 --- /dev/null +++ b/src/genie/libs/parser/iosxr/tests/ShowVrfAllDetail/cli/equal/golden_output_4_expected.py @@ -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", + }, +} diff --git a/src/genie/libs/parser/iosxr/tests/ShowVrfAllDetail/cli/equal/golden_output_4_output.txt b/src/genie/libs/parser/iosxr/tests/ShowVrfAllDetail/cli/equal/golden_output_4_output.txt new file mode 100644 index 0000000000..ac4f47841f --- /dev/null +++ b/src/genie/libs/parser/iosxr/tests/ShowVrfAllDetail/cli/equal/golden_output_4_output.txt @@ -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 \ No newline at end of file From 63f819cf1bbc8489ecbf169399a835c9dd097025 Mon Sep 17 00:00:00 2001 From: Jan Krupa Date: Fri, 8 Nov 2024 10:41:21 +0100 Subject: [PATCH 3/3] Add changelog to ShowVrfAllDetail parser changes --- ...changelog_show_vrf_all_detail_iosxr_20241108103720.rst | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 genieparser/changelog/undistributed/changelog_show_vrf_all_detail_iosxr_20241108103720.rst diff --git a/genieparser/changelog/undistributed/changelog_show_vrf_all_detail_iosxr_20241108103720.rst b/genieparser/changelog/undistributed/changelog_show_vrf_all_detail_iosxr_20241108103720.rst new file mode 100644 index 0000000000..fdfbb1c11d --- /dev/null +++ b/genieparser/changelog/undistributed/changelog_show_vrf_all_detail_iosxr_20241108103720.rst @@ -0,0 +1,8 @@ +-------------------------------------------------------------------------------- + Fix +-------------------------------------------------------------------------------- +* IOSXR + * Modified ShowVrfAllDetail: + * Modified regex 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 \ No newline at end of file