Skip to content

Commit eabf79c

Browse files
authored
Merge pull request #824 from kernelkit/add-routing-pref-tests
Add Routing Preference Tests
2 parents 68c86c8 + d9eae88 commit eabf79c

File tree

17 files changed

+1051
-37
lines changed

17 files changed

+1051
-37
lines changed

test/case/ietf_routing/Readme.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ include::ospf_unnumbered_interface/Readme.adoc[]
1313
include::ospf_multiarea/Readme.adoc[]
1414

1515
include::ospf_bfd/Readme.adoc[]
16+
17+
include::route_pref_ospf/Readme.adoc[]
18+
19+
include::route_pref_dhcp/Readme.adoc[]
20+
21+
include::route_pref_255/Readme.adoc[]

test/case/ietf_routing/ietf_routing.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@
1313

1414
- name: ospf_bfd
1515
case: ospf_bfd/test.py
16+
17+
- name: route_pref_ospf
18+
case: route_pref_ospf/test.py
19+
20+
- name: route_pref_dhcp
21+
case: route_pref_dhcp/test.py
22+
23+
- name: route_pref_255
24+
case: route_pref_255/test.py
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== Route preference: Static Route Activation and Maximum Distance
2+
==== Description
3+
This test configures a device with a static route to a destination with
4+
a moderate routing preference (254), verifying that it becomes active.
5+
Then, the routing preference is increased to the maximum value (255),
6+
which should prevent the route from becoming active.
7+
8+
==== Topology
9+
ifdef::topdoc[]
10+
image::../../test/case/ietf_routing/route_pref_255/topology.svg[Route preference: Static Route Activation and Maximum Distance topology]
11+
endif::topdoc[]
12+
ifndef::topdoc[]
13+
ifdef::testgroup[]
14+
image::route_pref_255/topology.svg[Route preference: Static Route Activation and Maximum Distance topology]
15+
endif::testgroup[]
16+
ifndef::testgroup[]
17+
image::topology.svg[Route preference: Static Route Activation and Maximum Distance topology]
18+
endif::testgroup[]
19+
endif::topdoc[]
20+
==== Test sequence
21+
. Set up topology and attach to target DUTs
22+
. Configure targets with active static route
23+
. Verify that static route with preference 254 is active
24+
. Update static route preference to 255
25+
. Verify that high-preference static route (255) does not become active
26+
27+
28+
<<<
29+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Route preference: Static Route Activation and Maximum Distance
4+
5+
This test configures a device with a static route to a destination with
6+
a moderate routing preference (254), verifying that it becomes active.
7+
Then, the routing preference is increased to the maximum value (255),
8+
which should prevent the route from becoming active.
9+
"""
10+
11+
import infamy
12+
import infamy.route as route
13+
from infamy.util import until, parallel
14+
15+
def configure_interface(name, ip, prefix_length, forwarding=True):
16+
return {
17+
"name": name,
18+
"enabled": True,
19+
"ipv4": {
20+
"forwarding": forwarding,
21+
"address": [{"ip": ip, "prefix-length": prefix_length}]
22+
}
23+
}
24+
25+
def config_target1_initial(target, data, link):
26+
target.put_config_dicts({
27+
"ietf-interfaces": {
28+
"interfaces": {
29+
"interface": [
30+
configure_interface(data, "192.168.10.1", 24),
31+
configure_interface(link, "192.168.50.1", 24)
32+
]
33+
}
34+
},
35+
"ietf-routing": {
36+
"routing": {
37+
"control-plane-protocols": {
38+
"control-plane-protocol": [
39+
{
40+
"type": "infix-routing:static",
41+
"name": "default",
42+
"static-routes": {
43+
"ipv4": {
44+
"route": [{
45+
"destination-prefix": "192.168.20.0/24",
46+
"next-hop": {"next-hop-address": "192.168.50.2"},
47+
"route-preference": 254
48+
}]
49+
}
50+
}
51+
}
52+
]
53+
}
54+
}
55+
}
56+
})
57+
58+
def config_target1_update(target):
59+
target.put_config_dicts({
60+
"ietf-routing": {
61+
"routing": {
62+
"control-plane-protocols": {
63+
"control-plane-protocol": [
64+
{
65+
"type": "infix-routing:static",
66+
"name": "default",
67+
"static-routes": {
68+
"ipv4": {
69+
"route": [{
70+
"destination-prefix": "192.168.20.0/24",
71+
"next-hop": {"next-hop-address": "192.168.50.2"},
72+
"route-preference": 255
73+
}]
74+
}
75+
}
76+
}
77+
]
78+
}
79+
}
80+
}
81+
})
82+
83+
def config_target2(target, data, link):
84+
target.put_config_dicts({
85+
"ietf-interfaces": {
86+
"interfaces": {
87+
"interface": [
88+
configure_interface(data, "192.168.20.2", 24),
89+
configure_interface(link, "192.168.50.2", 24)
90+
]
91+
}
92+
}
93+
})
94+
95+
with infamy.Test() as test:
96+
with test.step("Set up topology and attach to target DUTs"):
97+
env = infamy.Env()
98+
R1 = env.attach("R1", "mgmt")
99+
R2 = env.attach("R2", "mgmt")
100+
101+
with test.step("Configure targets with active static route"):
102+
_, R1data = env.ltop.xlate("R1", "data")
103+
_, R1link = env.ltop.xlate("R1", "link")
104+
_, R2data = env.ltop.xlate("R2", "data")
105+
_, R2link = env.ltop.xlate("R2", "link")
106+
107+
parallel(config_target1_initial(R1, R1data, R1link), config_target2(R2, R2data, R2link))
108+
109+
with test.step("Verify that static route with preference 254 is active"):
110+
until(lambda: route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-routing:static", active_check=True))
111+
112+
with test.step("Update static route preference to 255"):
113+
config_target1_update(R1)
114+
115+
with test.step("Verify that high-preference static route (255) does not become active"):
116+
until(lambda: not route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-routing:static", active_check=True))
117+
118+
test.succeed()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
graph "route-preference" {
2+
layout="neato";
3+
overlap="false";
4+
esep="+20";
5+
size=10
6+
7+
node [shape=record, fontname="DejaVu Sans Mono, Book"];
8+
edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"];
9+
10+
PC
11+
[
12+
label="PC | { <mgmt1> mgmt1 | <data1> data1 | <data2> data2 | <mgmt2> mgmt2 }",
13+
pos="20,58!",
14+
kind="controller",
15+
];
16+
17+
R1
18+
[
19+
label="{ <mgmt> mgmt | <data> data | <link> link } | R1",
20+
pos="80,60!",
21+
kind="infix",
22+
];
23+
24+
R2
25+
[
26+
label="{ <link> link | <data> data | <mgmt> mgmt } | R2",
27+
pos="80,42!",
28+
kind="infix",
29+
];
30+
31+
PC:mgmt1 -- R1:mgmt [kind=mgmt, color="lightgray"]
32+
PC:mgmt2 -- R2:mgmt [kind=mgmt, color="lightgray"]
33+
34+
PC:data1 -- R1:data [color="black", headlabel="192.168.10.1/24", taillabel="192.168.10.11/24", fontcolor="black"]
35+
PC:data2 -- R2:data [color="black", headlabel="192.168.20.2/24", taillabel="192.168.20.22/24", fontcolor="black"]
36+
37+
R1:link -- R2:link [headlabel="192.168.50.2/24", taillabel="192.168.50.1/24", labeldistance=1, fontcolor="black", color="black"]
38+
}
Lines changed: 81 additions & 0 deletions
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== Route preference: DHCP vs Static
2+
==== Description
3+
This test configures a device with both a DHCP-acquired route on a
4+
dedicated interface and a static route to the same destination on
5+
another interface.
6+
7+
Initially, DHCP is preferred over Static. Afterwards, the static
8+
route takes precedence by adjusting the routing preference value
9+
to the one lower than DHCP.
10+
11+
==== Topology
12+
ifdef::topdoc[]
13+
image::../../test/case/ietf_routing/route_pref_dhcp/topology.svg[Route preference: DHCP vs Static topology]
14+
endif::topdoc[]
15+
ifndef::topdoc[]
16+
ifdef::testgroup[]
17+
image::route_pref_dhcp/topology.svg[Route preference: DHCP vs Static topology]
18+
endif::testgroup[]
19+
ifndef::testgroup[]
20+
image::topology.svg[Route preference: DHCP vs Static topology]
21+
endif::testgroup[]
22+
endif::topdoc[]
23+
==== Test sequence
24+
. Set up topology and attach to target DUTs
25+
. Configure targets. Assign higher priority to the dhcp route
26+
. Wait for DHCP and static routes
27+
. Verify connectivity from PC:data12 to R2:lo via DHCP
28+
. Assign higher priority to the static route
29+
. Verify connectivity from PC:data12 to R2:lo via static route
30+
31+
32+
<<<
33+

0 commit comments

Comments
 (0)