Skip to content

Commit

Permalink
tests: add nexthop/interface's down/up topo for kernel routes
Browse files Browse the repository at this point in the history
Signed-off-by: anlan_cs <[email protected]>
  • Loading branch information
anlancs committed Dec 17, 2024
1 parent 4d2ac71 commit 2f1bd3f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
]

}
]
}
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"])


#####################################################
##
Expand Down Expand Up @@ -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:]
Expand Down

0 comments on commit 2f1bd3f

Please sign in to comment.