Skip to content

Commit

Permalink
Merge pull request #824 from kernelkit/add-routing-pref-tests
Browse files Browse the repository at this point in the history
Add Routing Preference Tests
  • Loading branch information
axkar authored Nov 27, 2024
2 parents 68c86c8 + d9eae88 commit eabf79c
Show file tree
Hide file tree
Showing 17 changed files with 1,051 additions and 37 deletions.
6 changes: 6 additions & 0 deletions test/case/ietf_routing/Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ include::ospf_unnumbered_interface/Readme.adoc[]
include::ospf_multiarea/Readme.adoc[]

include::ospf_bfd/Readme.adoc[]

include::route_pref_ospf/Readme.adoc[]

include::route_pref_dhcp/Readme.adoc[]

include::route_pref_255/Readme.adoc[]
9 changes: 9 additions & 0 deletions test/case/ietf_routing/ietf_routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@

- name: ospf_bfd
case: ospf_bfd/test.py

- name: route_pref_ospf
case: route_pref_ospf/test.py

- name: route_pref_dhcp
case: route_pref_dhcp/test.py

- name: route_pref_255
case: route_pref_255/test.py
29 changes: 29 additions & 0 deletions test/case/ietf_routing/route_pref_255/Readme.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== Route preference: Static Route Activation and Maximum Distance
==== Description
This test configures a device with a static route to a destination with
a moderate routing preference (254), verifying that it becomes active.
Then, the routing preference is increased to the maximum value (255),
which should prevent the route from becoming active.

==== Topology
ifdef::topdoc[]
image::../../test/case/ietf_routing/route_pref_255/topology.svg[Route preference: Static Route Activation and Maximum Distance topology]
endif::topdoc[]
ifndef::topdoc[]
ifdef::testgroup[]
image::route_pref_255/topology.svg[Route preference: Static Route Activation and Maximum Distance topology]
endif::testgroup[]
ifndef::testgroup[]
image::topology.svg[Route preference: Static Route Activation and Maximum Distance topology]
endif::testgroup[]
endif::topdoc[]
==== Test sequence
. Set up topology and attach to target DUTs
. Configure targets with active static route
. Verify that static route with preference 254 is active
. Update static route preference to 255
. Verify that high-preference static route (255) does not become active


<<<

118 changes: 118 additions & 0 deletions test/case/ietf_routing/route_pref_255/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env python3
"""
Route preference: Static Route Activation and Maximum Distance
This test configures a device with a static route to a destination with
a moderate routing preference (254), verifying that it becomes active.
Then, the routing preference is increased to the maximum value (255),
which should prevent the route from becoming active.
"""

import infamy
import infamy.route as route
from infamy.util import until, parallel

def configure_interface(name, ip, prefix_length, forwarding=True):
return {
"name": name,
"enabled": True,
"ipv4": {
"forwarding": forwarding,
"address": [{"ip": ip, "prefix-length": prefix_length}]
}
}

def config_target1_initial(target, data, link):
target.put_config_dicts({
"ietf-interfaces": {
"interfaces": {
"interface": [
configure_interface(data, "192.168.10.1", 24),
configure_interface(link, "192.168.50.1", 24)
]
}
},
"ietf-routing": {
"routing": {
"control-plane-protocols": {
"control-plane-protocol": [
{
"type": "infix-routing:static",
"name": "default",
"static-routes": {
"ipv4": {
"route": [{
"destination-prefix": "192.168.20.0/24",
"next-hop": {"next-hop-address": "192.168.50.2"},
"route-preference": 254
}]
}
}
}
]
}
}
}
})

def config_target1_update(target):
target.put_config_dicts({
"ietf-routing": {
"routing": {
"control-plane-protocols": {
"control-plane-protocol": [
{
"type": "infix-routing:static",
"name": "default",
"static-routes": {
"ipv4": {
"route": [{
"destination-prefix": "192.168.20.0/24",
"next-hop": {"next-hop-address": "192.168.50.2"},
"route-preference": 255
}]
}
}
}
]
}
}
}
})

def config_target2(target, data, link):
target.put_config_dicts({
"ietf-interfaces": {
"interfaces": {
"interface": [
configure_interface(data, "192.168.20.2", 24),
configure_interface(link, "192.168.50.2", 24)
]
}
}
})

with infamy.Test() as test:
with test.step("Set up topology and attach to target DUTs"):
env = infamy.Env()
R1 = env.attach("R1", "mgmt")
R2 = env.attach("R2", "mgmt")

with test.step("Configure targets with active static route"):
_, R1data = env.ltop.xlate("R1", "data")
_, R1link = env.ltop.xlate("R1", "link")
_, R2data = env.ltop.xlate("R2", "data")
_, R2link = env.ltop.xlate("R2", "link")

parallel(config_target1_initial(R1, R1data, R1link), config_target2(R2, R2data, R2link))

with test.step("Verify that static route with preference 254 is active"):
until(lambda: route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-routing:static", active_check=True))

with test.step("Update static route preference to 255"):
config_target1_update(R1)

with test.step("Verify that high-preference static route (255) does not become active"):
until(lambda: not route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-routing:static", active_check=True))

test.succeed()
38 changes: 38 additions & 0 deletions test/case/ietf_routing/route_pref_255/topology.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
graph "route-preference" {
layout="neato";
overlap="false";
esep="+20";
size=10

node [shape=record, fontname="DejaVu Sans Mono, Book"];
edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"];

PC
[
label="PC | { <mgmt1> mgmt1 | <data1> data1 | <data2> data2 | <mgmt2> mgmt2 }",
pos="20,58!",
kind="controller",
];

R1
[
label="{ <mgmt> mgmt | <data> data | <link> link } | R1",
pos="80,60!",
kind="infix",
];

R2
[
label="{ <link> link | <data> data | <mgmt> mgmt } | R2",
pos="80,42!",
kind="infix",
];

PC:mgmt1 -- R1:mgmt [kind=mgmt, color="lightgray"]
PC:mgmt2 -- R2:mgmt [kind=mgmt, color="lightgray"]

PC:data1 -- R1:data [color="black", headlabel="192.168.10.1/24", taillabel="192.168.10.11/24", fontcolor="black"]
PC:data2 -- R2:data [color="black", headlabel="192.168.20.2/24", taillabel="192.168.20.22/24", fontcolor="black"]

R1:link -- R2:link [headlabel="192.168.50.2/24", taillabel="192.168.50.1/24", labeldistance=1, fontcolor="black", color="black"]
}
81 changes: 81 additions & 0 deletions test/case/ietf_routing/route_pref_255/topology.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions test/case/ietf_routing/route_pref_dhcp/Readme.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== Route preference: DHCP vs Static
==== Description
This test configures a device with both a DHCP-acquired route on a
dedicated interface and a static route to the same destination on
another interface.

Initially, DHCP is preferred over Static. Afterwards, the static
route takes precedence by adjusting the routing preference value
to the one lower than DHCP.

==== Topology
ifdef::topdoc[]
image::../../test/case/ietf_routing/route_pref_dhcp/topology.svg[Route preference: DHCP vs Static topology]
endif::topdoc[]
ifndef::topdoc[]
ifdef::testgroup[]
image::route_pref_dhcp/topology.svg[Route preference: DHCP vs Static topology]
endif::testgroup[]
ifndef::testgroup[]
image::topology.svg[Route preference: DHCP vs Static topology]
endif::testgroup[]
endif::topdoc[]
==== Test sequence
. Set up topology and attach to target DUTs
. Configure targets. Assign higher priority to the dhcp route
. Wait for DHCP and static routes
. Verify connectivity from PC:data12 to R2:lo via DHCP
. Assign higher priority to the static route
. Verify connectivity from PC:data12 to R2:lo via static route


<<<

Loading

0 comments on commit eabf79c

Please sign in to comment.