summaryrefslogtreecommitdiff
path: root/tests/topotests/all-protocol-startup/test_all_protocol_startup.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/topotests/all-protocol-startup/test_all_protocol_startup.py')
-rwxr-xr-xtests/topotests/all-protocol-startup/test_all_protocol_startup.py216
1 files changed, 202 insertions, 14 deletions
diff --git a/tests/topotests/all-protocol-startup/test_all_protocol_startup.py b/tests/topotests/all-protocol-startup/test_all_protocol_startup.py
index 16609221c1..f78c2b4bc0 100755
--- a/tests/topotests/all-protocol-startup/test_all_protocol_startup.py
+++ b/tests/topotests/all-protocol-startup/test_all_protocol_startup.py
@@ -307,7 +307,7 @@ def test_converge_protocols():
expected = open(v4_routesFile).read().rstrip()
expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1)
- actual = net['r%s' %i].cmd('vtysh -c "show ip route" | /usr/bin/tail -n +7 | sort 2> /dev/null').rstrip()
+ actual = net['r%s' %i].cmd('vtysh -c "show ip route" | /usr/bin/tail -n +7 | env LC_ALL=en_US.UTF-8 sort 2> /dev/null').rstrip()
# Drop time in last update
actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual)
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
@@ -329,7 +329,7 @@ def test_converge_protocols():
expected = open(v6_routesFile).read().rstrip()
expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1)
- actual = net['r%s' %i].cmd('vtysh -c "show ipv6 route" | /usr/bin/tail -n +7 | sort 2> /dev/null').rstrip()
+ actual = net['r%s' %i].cmd('vtysh -c "show ipv6 route" | /usr/bin/tail -n +7 | env LC_ALL=en_US.UTF-8 sort 2> /dev/null').rstrip()
# Drop time in last update
actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual)
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
@@ -347,6 +347,35 @@ def test_converge_protocols():
# For debugging after starting FRR/Quagga daemons, uncomment the next line
## CLI(net)
+def route_get_nhg_id(route_str):
+ output = net["r1"].cmd('vtysh -c "show ip route %s nexthop-group"' % route_str)
+ match = re.search(r"Nexthop Group ID: (\d+)", output)
+ assert match is not None, "Nexthop Group ID not found for sharpd route %s" % route_str
+
+ nhg_id = int(match.group(1))
+ return nhg_id
+
+def verify_nexthop_group(nhg_id, recursive=False):
+ # Verify NHG is valid/installed
+ output = net["r1"].cmd('vtysh -c "show nexthop-group rib %d"' % nhg_id)
+
+ match = re.search(r"Valid", output)
+ assert match is not None, "Nexthop Group ID=%d not marked Valid" % nhg_id
+
+ # If recursive, we need to look at its resolved group
+ if recursive:
+ match = re.search(r"Depends: \((\d+)\)", output)
+ resolved_id = int(match.group(1))
+ verify_nexthop_group(resolved_id, False)
+ else:
+ match = re.search(r"Installed", output)
+ assert match is not None, "Nexthop Group ID=%d not marked Installed" % nhg_id
+
+def verify_route_nexthop_group(route_str, recursive=False):
+ # Verify route and that zebra created NHGs for and they are valid/installed
+ nhg_id = route_get_nhg_id(route_str)
+ verify_nexthop_group(nhg_id, recursive)
+
def test_nexthop_groups():
global fatal_error
global net
@@ -358,25 +387,77 @@ def test_nexthop_groups():
print("\n\n** Verifying Nexthop Groups")
print("******************************************\n")
+ ### Nexthop Group Tests
+
+ ## Basic test
+
# Create a lib nexthop-group
- net["r1"].cmd('vtysh -c "c t" -c "nexthop-group red" -c "nexthop 1.1.1.1" -c "nexthop 1.1.1.2"')
+ net["r1"].cmd('vtysh -c "c t" -c "nexthop-group basic" -c "nexthop 1.1.1.1" -c "nexthop 1.1.1.2"')
# Create with sharpd using nexthop-group
- net["r1"].cmd('vtysh -c "sharp install routes 2.2.2.1 nexthop-group red 1"')
+ net["r1"].cmd('vtysh -c "sharp install routes 2.2.2.1 nexthop-group basic 1"')
- # Verify route and that zebra created NHGs for and they are valid/installed
- output = net["r1"].cmd('vtysh -c "show ip route 2.2.2.1/32 nexthop-group"')
- match = re.search(r"Nexthop Group ID: (\d+)", output);
- assert match is not None, "Nexthop Group ID not found for sharpd route 2.2.2.1/32"
+ verify_route_nexthop_group("2.2.2.1/32")
- nhe_id = int(match.group(1))
+ ## Connected
- output = net["r1"].cmd('vtysh -c "show nexthop-group rib %d"' % nhe_id)
- match = re.search(r"Valid", output)
- assert match is not None, "Nexthop Group ID=%d not marked Valid" % nhe_id
+ net["r1"].cmd('vtysh -c "c t" -c "nexthop-group connected" -c "nexthop r1-eth1" -c "nexthop r1-eth2"')
- match = re.search(r"Installed", output)
- assert match is not None, "Nexthop Group ID=%d not marked Installed" % nhe_id
+ net["r1"].cmd('vtysh -c "sharp install routes 2.2.2.2 nexthop-group connected 1"')
+
+ verify_route_nexthop_group("2.2.2.2/32")
+
+ ## Recursive
+
+ net["r1"].cmd('vtysh -c "c t" -c "nexthop-group basic-recursive" -c "nexthop 2.2.2.1"')
+
+ net["r1"].cmd('vtysh -c "sharp install routes 3.3.3.1 nexthop-group basic-recursive 1"')
+
+ verify_route_nexthop_group("3.3.3.1/32", True)
+
+ ## Duplicate
+
+ net["r1"].cmd('vtysh -c "c t" -c "nexthop-group duplicate" -c "nexthop 2.2.2.1" -c "nexthop 1.1.1.1"')
+
+ net["r1"].cmd('vtysh -c "sharp install routes 3.3.3.2 nexthop-group duplicate 1"')
+
+ verify_route_nexthop_group("3.3.3.2/32")
+
+ ## Two 4-Way ECMP
+
+ net["r1"].cmd('vtysh -c "c t" -c "nexthop-group fourA" -c "nexthop 1.1.1.1" -c "nexthop 1.1.1.2" \
+ -c "nexthop 1.1.1.3" -c "nexthop 1.1.1.4"')
+
+ net["r1"].cmd('vtysh -c "sharp install routes 4.4.4.1 nexthop-group fourA 1"')
+
+ verify_route_nexthop_group("4.4.4.1/32")
+
+ net["r1"].cmd('vtysh -c "c t" -c "nexthop-group fourB" -c "nexthop 1.1.1.5" -c "nexthop 1.1.1.6" \
+ -c "nexthop 1.1.1.7" -c "nexthop 1.1.1.8"')
+
+ net["r1"].cmd('vtysh -c "sharp install routes 4.4.4.2 nexthop-group fourB 1"')
+
+ verify_route_nexthop_group("4.4.4.2/32")
+
+ ## Recursive to 8-Way ECMP
+
+ net["r1"].cmd('vtysh -c "c t" -c "nexthop-group eight-recursive" -c "nexthop 4.4.4.1" -c "nexthop 4.4.4.2"')
+
+ net["r1"].cmd('vtysh -c "sharp install routes 5.5.5.1 nexthop-group eight-recursive 1"')
+
+ verify_route_nexthop_group("5.5.5.1/32")
+
+ ##CLI(net)
+
+ ## Remove all NHG routes
+
+ net["r1"].cmd('vtysh -c "sharp remove routes 2.2.2.1 1"')
+ net["r1"].cmd('vtysh -c "sharp remove routes 2.2.2.2 1"')
+ net["r1"].cmd('vtysh -c "sharp remove routes 3.3.3.1 1"')
+ net["r1"].cmd('vtysh -c "sharp remove routes 3.3.3.2 1"')
+ net["r1"].cmd('vtysh -c "sharp remove routes 4.4.4.1 1"')
+ net["r1"].cmd('vtysh -c "sharp remove routes 4.4.4.2 1"')
+ net["r1"].cmd('vtysh -c "sharp remove routes 5.5.5.1 1"')
def test_rip_status():
global fatal_error
@@ -891,7 +972,114 @@ def test_bgp_ipv6():
# For debugging after starting FRR/Quagga daemons, uncomment the next line
# CLI(net)
+def test_route_map():
+ global fatal_error
+ global net
+
+ if (fatal_error != ""):
+ pytest.skip(fatal_error)
+ thisDir = os.path.dirname(os.path.realpath(__file__))
+
+ print("\n\n** Verifying some basic routemap forward references\n")
+ print("*******************************************************\n")
+ failures = 0
+ for i in range(1, 2):
+ refroutemap = '%s/r%s/show_route_map.ref' % (thisDir, i)
+ if os.path.isfile(refroutemap):
+ expected = open(refroutemap).read().rstrip()
+ expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1)
+
+ actual = net['r%s' %i].cmd('vtysh -c "show route-map" 2> /dev/null').rstrip()
+ actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
+
+ diff = topotest.get_textdiff(actual, expected,
+ title1="actual show route-map",
+ title2="expected show route-map")
+
+ if diff:
+ sys.stderr.write('r%s failed show route-map command Check:\n%s\n' % (i, diff))
+ failures += 1
+ else:
+ print("r%s ok" %i)
+
+ assert failures == 0, "Show route-map command failed for router r%s:\n%s" % (i, diff)
+
+def test_nexthop_groups_with_route_maps():
+ global fatal_error
+ global net
+
+ # Skip if previous fatal error condition is raised
+ if (fatal_error != ""):
+ pytest.skip(fatal_error)
+
+ print("\n\n** Verifying Nexthop Groups With Route-Maps")
+ print("******************************************\n")
+
+ ### Nexthop Group With Route-Map Tests
+
+ # Create a lib nexthop-group
+ net["r1"].cmd('vtysh -c "c t" -c "nexthop-group test" -c "nexthop 1.1.1.1" -c "nexthop 1.1.1.2"')
+
+ ## Route-Map Proto Source
+
+ route_str = "2.2.2.1"
+ src_str = "192.168.0.1"
+
+ net["r1"].cmd('vtysh -c "c t" -c "route-map NH-SRC permit 111" -c "set src %s"' % src_str)
+ net["r1"].cmd('vtysh -c "c t" -c "ip protocol sharp route-map NH-SRC"')
+
+ net["r1"].cmd('vtysh -c "sharp install routes %s nexthop-group test 1"' % route_str)
+
+ verify_route_nexthop_group("%s/32" % route_str)
+
+ # Only a valid test on linux using nexthop objects
+ if sys.platform.startswith("linux"):
+ output = net["r1"].cmd('ip route show %s/32' % route_str)
+ match = re.search(r"src %s" % src_str, output)
+ assert match is not None, "Route %s/32 not installed with src %s" % (route_str, src_str)
+
+ # Remove NHG routes and route-map
+ net["r1"].cmd('vtysh -c "sharp remove routes %s 1"' % route_str)
+ net["r1"].cmd('vtysh -c "c t" -c "no ip protocol sharp route-map NH-SRC"')
+ net["r1"].cmd('vtysh -c "c t" -c "no route-map NH-SRC permit 111" -c "set src %s"' % src_str)
+ net["r1"].cmd('vtysh -c "c t" -c "no route-map NH-SRC"')
+
+ ## Route-Map Deny/Permit with same nexthop group
+
+ permit_route_str = "3.3.3.1"
+ deny_route_str = "3.3.3.2"
+
+ net["r1"].cmd('vtysh -c "c t" -c "ip prefix-list NOPE seq 5 permit %s/32"' % permit_route_str)
+ net["r1"].cmd('vtysh -c "c t" -c "route-map NOPE permit 111" -c "match ip address prefix-list NOPE"')
+ net["r1"].cmd('vtysh -c "c t" -c "route-map NOPE deny 222"')
+ net["r1"].cmd('vtysh -c "c t" -c "ip protocol sharp route-map NOPE"')
+
+ # This route should be permitted
+ net["r1"].cmd('vtysh -c "sharp install routes %s nexthop-group test 1"' % permit_route_str)
+
+ verify_route_nexthop_group("%s/32" % permit_route_str)
+
+ # This route should be denied
+ net["r1"].cmd('vtysh -c "sharp install routes %s nexthop-group test 1"' % deny_route_str)
+
+ nhg_id = route_get_nhg_id(deny_route_str)
+ output = net["r1"].cmd('vtysh -c "show nexthop-group rib %d"' % nhg_id)
+
+ match = re.search(r"Valid", output)
+ assert match is None, "Nexthop Group ID=%d should not be marked Valid" % nhg_id
+
+ match = re.search(r"Installed", output)
+ assert match is None, "Nexthop Group ID=%d should not be marked Installed" % nhg_id
+
+ # Remove NHG routes and route-map
+ net["r1"].cmd('vtysh -c "sharp remove routes %s 1"' % permit_route_str)
+ net["r1"].cmd('vtysh -c "sharp remove routes %s 1"' % deny_route_str)
+ net["r1"].cmd('vtysh -c "c t" -c "no ip protocol sharp route-map NOPE"')
+ net["r1"].cmd('vtysh -c "c t" -c "no route-map NOPE permit 111"')
+ net["r1"].cmd('vtysh -c "c t" -c "no route-map NOPE deny 222"')
+ net["r1"].cmd('vtysh -c "c t" -c "no route-map NOPE"')
+ net["r1"].cmd('vtysh -c "c t" -c "no ip prefix-list NOPE seq 5 permit %s/32"' % permit_route_str)
def test_mpls_interfaces():
global fatal_error