Skip to content

Commit

Permalink
NXOS_SSH/IOS XE IPv6 Regex update (#2016)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubaumann authored Oct 23, 2023
1 parent cca35cf commit 1858e72
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 5 deletions.
2 changes: 1 addition & 1 deletion napalm/ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
IP_ADDR_REGEX = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
IPV4_ADDR_REGEX = IP_ADDR_REGEX
IPV6_ADDR_REGEX_1 = r"::"
IPV6_ADDR_REGEX_2 = r"[0-9a-fA-F:]{1,39}::[0-9a-fA-F:]{1,39}"
IPV6_ADDR_REGEX_2 = r"[0-9a-fA-F:]{0,39}::[0-9a-fA-F:]{0,39}"
IPV6_ADDR_REGEX_3 = (
r"[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:"
"[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}"
Expand Down
17 changes: 13 additions & 4 deletions napalm/nxos_ssh/nxos_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
IP_ADDR_REGEX = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
IPV4_ADDR_REGEX = IP_ADDR_REGEX
IPV6_ADDR_REGEX_1 = r"::"
IPV6_ADDR_REGEX_2 = r"[0-9a-fA-F:]{1,39}::[0-9a-fA-F:]{1,39}"
IPV6_ADDR_REGEX_2 = r"[0-9a-fA-F:]{0,39}::[0-9a-fA-F:]{0,39}"
IPV6_ADDR_REGEX_3 = (
r"[0-9a-fA-F]{1,3}:[0-9a-fA-F]{1,3}:[0-9a-fA-F]{1,3}:[0-9a-fA-F]{1,3}:"
r"[0-9a-fA-F]{1,3}:[0-9a-fA-F]{1,3}:[0-9a-fA-F]{1,3}:[0-9a-fA-F]{1,3}"
Expand Down Expand Up @@ -264,13 +264,22 @@ def bgp_normalize_table_data(bgp_table):
4 65535 163664 163693 145 0 0 3w2d 3
2001:db8:e0:dd::1
4 10 327491 327278 145 0 0 3w1d 4
2001:db8:e0:df::
4 12345678
327465 327268 145 0 0 3w1d 4
Normalize this so the line wrap doesn't exit.
"""
bgp_table = bgp_table.strip()
bgp_multiline_pattern = r"({})\s*\n".format(IPV4_OR_IPV6_REGEX)
# Strip out the newline
return re.sub(bgp_multiline_pattern, r"\1", bgp_table)
# Remove newline after ipv6 address
bgp_ipv6_multiline_pattern = r"({})\s*\n".format(IPV4_OR_IPV6_REGEX)
bgp_table = re.sub(bgp_ipv6_multiline_pattern, r"\1", bgp_table)
# Remove newline after a long AS number
bgp_long_as_multiline_pattern = r"((?:{})\s*\d*\s*\d*)\s*\n".format(
IPV4_OR_IPV6_REGEX
)
bgp_table = re.sub(bgp_long_as_multiline_pattern, r"\1", bgp_table)
return bgp_table


def bgp_table_parser(bgp_table):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"RED3": {
"router_id": "10.1.0.18",
"peers": {
"2001:db8:4:701::2": {
"is_enabled": true,
"uptime": 1987200,
"remote_as": 65535,
"address_family": {
"ipv6": {
"sent_prefixes": -1,
"accepted_prefixes": -1,
"received_prefixes": 3
}
},
"is_up": true,
"remote_id": "0.0.0.0",
"local_as": 65535,
"description": ""
},
"2001:db8:e0:df::": {
"is_enabled": true,
"uptime": 1900800,
"remote_as": 12345678,
"address_family": {
"ipv6": {
"sent_prefixes": -1,
"accepted_prefixes": -1,
"received_prefixes": 4
}
},
"is_up": true,
"remote_id": "0.0.0.0",
"local_as": 65535,
"description": ""
},
"2001:db8:e0:dd::1": {
"is_enabled": true,
"uptime": 1900800,
"remote_as": 10,
"address_family": {
"ipv6": {
"sent_prefixes": -1,
"accepted_prefixes": -1,
"received_prefixes": 4
}
},
"is_up": true,
"remote_id": "0.0.0.0",
"local_as": 65535,
"description": ""
}
}
},
"global": {
"router_id": "10.1.0.16",
"peers": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BGP summary information for VRF default, address family IPv4 Unicast
BGP router identifier 10.1.0.16, local AS number 65535
BGP table version is 361, IPv4 Unicast config peers 2, capable peers 2
13 network entries and 17 paths using 2224 bytes of memory
BGP attribute entries [4/576], BGP AS path entries [1/14]
BGP community entries [295/10792], BGP clusterlist entries [0/0]
13 received paths for inbound soft reconfiguration
4 identical, 9 modified, 0 filtered received paths using 72 bytes

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd


BGP summary information for VRF RED3, address family IPv6 Unicast
BGP router identifier 10.1.0.18, local AS number 65535
BGP table version is 145, IPv6 Unicast config peers 3, capable peers 3
12 network entries and 15 paths using 2136 bytes of memory
BGP attribute entries [16/2304], BGP AS path entries [6/72]
BGP community entries [295/10792], BGP clusterlist entries [0/0]
11 received paths for inbound soft reconfiguration
3 identical, 8 modified, 0 filtered received paths using 64 bytes

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
2001:db8:4:701::2
4 65535 163664 163693 145 0 0 3w2d 3
2001:db8:e0:dd::1
4 10 327491 327278 145 0 0 3w1d 4
2001:db8:e0:df::
4 12345678
327465 327268 145 0 0 3w1d 4

0 comments on commit 1858e72

Please sign in to comment.