summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranlan_cs <anlan_cs@126.com>2024-12-13 11:38:08 +0100
committeranlan_cs <anlan_cs@126.com>2024-12-17 09:14:35 +0100
commit2f1bd3fe4dd663b29a0e62ad9f78997a176de5ae (patch)
tree0b83a8c09020423e47283285a3172d7639bad059
parentzebra: check kernel routes when interface becomes up (diff)
downloadfrr-2f1bd3fe4dd663b29a0e62ad9f78997a176de5ae.tar.xz
frr-2f1bd3fe4dd663b29a0e62ad9f78997a176de5ae.zip
tests: add nexthop/interface's down/up topo for kernel routes
Signed-off-by: anlan_cs <anlan_cs@126.com>
-rw-r--r--tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_interface_down.json20
-rw-r--r--tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_interface_up.json21
-rw-r--r--tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py47
3 files changed, 88 insertions, 0 deletions
diff --git a/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_interface_down.json b/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_interface_down.json
new file mode 100644
index 000000000..50871ae03
--- /dev/null
+++ b/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_interface_down.json
@@ -0,0 +1,20 @@
+{
+ "5.5.6.7/32":[
+ {
+ "prefix":"5.5.6.7/32",
+ "prefixLen":32,
+ "protocol":"kernel",
+ "vrfName":"default",
+ "internalFlags":0,
+ "internalNextHopNum":1,
+ "internalNextHopActiveNum":0,
+ "nexthops":[
+ {
+ "flags":0,
+ "interfaceName":"r1-eth2"
+ }
+ ]
+
+ }
+ ]
+}
diff --git a/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_interface_up.json b/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_interface_up.json
new file mode 100644
index 000000000..d0ab2fa18
--- /dev/null
+++ b/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_interface_up.json
@@ -0,0 +1,21 @@
+{
+ "5.5.6.7/32":[
+ {
+ "prefix":"5.5.6.7/32",
+ "prefixLen":32,
+ "protocol":"kernel",
+ "vrfName":"default",
+ "internalFlags":8,
+ "internalNextHopNum":1,
+ "internalNextHopActiveNum":1,
+ "nexthops":[
+ {
+ "flags":3,
+ "fib":true,
+ "interfaceName":"r1-eth2",
+ "active":true
+ }
+ ]
+ }
+ ]
+}
diff --git a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py
index eda8c8870..89bc6cf8e 100644
--- a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py
+++ b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py
@@ -65,6 +65,9 @@ def build_topo(tgen):
switch.add_link(tgen.gears["r2"])
switch.add_link(tgen.gears["r3"])
+ # Create a p2p connection between r1 and r2
+ tgen.add_link(tgen.gears["r1"], tgen.gears["r2"])
+
#####################################################
##
@@ -222,6 +225,50 @@ def test_zebra_kernel_route_blackhole_add():
result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1)
assert result, "Blackhole Route should have not been removed\n{}".format(_)
+def test_zebra_kernel_route_interface_linkdown():
+ "Test that a kernel routes should be affected by interface change"
+
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ router = tgen.gears["r1"]
+ router.run("ip route add 5.5.6.7/32 via 10.0.1.66 dev r1-eth2")
+
+ kernel = "{}/{}/ip_route_kernel_interface_up.json".format(CWD, router.name)
+ expected = json.loads(open(kernel).read())
+
+ test_func = partial(
+ topotest.router_json_cmp, router, "show ip route 5.5.6.7/32 json", expected
+ )
+ result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1)
+ assert result, "Kernel Route should be selected:\n{}".format(_)
+
+ # link down
+ router2 = tgen.gears["r2"]
+ router2.run("ip link set dev r2-eth2 down")
+
+ kernel = "{}/{}/ip_route_kernel_interface_down.json".format(CWD, router.name)
+ expected = json.loads(open(kernel).read())
+
+ test_func = partial(
+ topotest.router_json_cmp, router, "show ip route 5.5.6.7/32 json", expected
+ )
+ result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1)
+ assert result, "Kernel Route should not be selected:\n{}".format(_)
+
+ # link up
+ router2 = tgen.gears["r2"]
+ router2.run("ip link set dev r2-eth2 up")
+
+ kernel = "{}/{}/ip_route_kernel_interface_up.json".format(CWD, router.name)
+ expected = json.loads(open(kernel).read())
+
+ test_func = partial(
+ topotest.router_json_cmp, router, "show ip route 5.5.6.7/32 json", expected
+ )
+ result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1)
+ assert result, "Kernel Route should be selected:\n{}".format(_)
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]