test: update with static route canary

Now that all routes acquired from DHCP (and ZeroConf) are installed in
the kernel FIB via Frr (staticd -> zebra -> kernel), instead of directly
to the kernel FIB, let's extend this test slightly.

Add a canary static route that is installed before the DHCP client is
even started.  This canary route should be installed along with the
DHCP (classless) route(s) when the interface comes up and acquires a
DHCP lease.

We take this opportunity to also verify that the route-preference is
properly carried over from test to operational RIB status.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-09-26 15:55:46 +02:00
parent 8ea0af6385
commit dc1a2c39e8
+60 -27
View File
@@ -1,47 +1,80 @@
#!/usr/bin/env python3
# Verify DHCP option 121 (staticroutes) is used over option 3
"""
DHCP router
DHCP option 121 vs option 3
Verify DHCP option 121 (staticroutes) is used over option 3 and that the routes exist in
the operational datastore
Verify DHCP option 121 (staticroutes) is used over option 3 and that the
routes exist in the operational datastore.
Installing unrelated routes from a DHCP server should not affect already
existing routes. To verify this a canary route is set up in the client
before initiating DHCP. This canary route does not need to be reachable
before a DHCP lease has been acquired.
"""
import time
import infamy, infamy.dhcp
import infamy.iface as iface
import infamy
import infamy.dhcp
import infamy.route as route
from infamy.util import until
with infamy.Test() as test:
PREFIX = '10.0.0.0/24'
ROUTER = '192.168.0.254'
with test.step("Initialize"):
PREFIX = '10.0.0.0/24'
ROUTER = '192.168.0.254'
CANARY = '20.0.0.0/24'
CANHOP = '192.168.0.2'
with test.step("Setting up client"):
env = infamy.Env()
client = env.attach("client", "mgmt")
_, host = env.ltop.xlate("host", "data")
_, port = env.ltop.xlate("client", "data")
# Install canary route to smoke out any regressions in
# how the DHCP client installs routes in the kernel FIB
client.put_config_dict("ietf-routing", {
"routing": {
"control-plane-protocols": {
"control-plane-protocol": [{
"type": "infix-routing:static",
"name": "default",
"static-routes": {
"ipv4": {
"route": [{
"destination-prefix": CANARY,
"next-hop": {
"next-hop-address": CANHOP
},
"infix-routing:route-preference": 250
}]
}
}
}]
}
}
})
client.put_config_dict("infix-dhcp-client", {
"dhcp-client": {
"client-if": [{
"if-name": f"{port}",
"option": [
{"name": "router"},
{"name": "staticroutes"}
]
}]
}
})
with infamy.IsolatedMacVlan(host) as netns:
netns.addip("192.168.0.1")
with infamy.dhcp.Server(netns, prefix=PREFIX, router=ROUTER):
_, port = env.ltop.xlate("client", "data")
config = {
"dhcp-client": {
"client-if": [{
"if-name": f"{port}",
"option": [
{ "name": "router" },
{ "name": "staticroutes" }
]
}]
}
}
client.put_config_dict("infix-dhcp-client", config)
with test.step(f"Verify client sets up correct route via {ROUTER}"):
# Wait for client to set the classless static route, option 121
with test.step("Verify client use classless routes, option 121"):
until(lambda: route.ipv4_route_exist(client, PREFIX, ROUTER))
# Ensure client did *not* use option 3 (option 121 takes precedence)
with test.step("Verify client did *not* use option 3"):
if route.ipv4_route_exist(client, "0.0.0.0/0", ROUTER):
test.fail()
with test.step("Verify client has canary route, 20.0.0.0/24"):
until(lambda: route.ipv4_route_exist(client, CANARY,
CANHOP, pref=250))
test.succeed()