Skip to content

Commit

Permalink
test: Verify routing preference 255 is inactive
Browse files Browse the repository at this point in the history
Fixes #784
  • Loading branch information
axkar committed Nov 26, 2024
1 parent e9efd22 commit d9eae88
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/case/ietf_routing/Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ include::ospf_bfd/Readme.adoc[]
include::route_pref_ospf/Readme.adoc[]

include::route_pref_dhcp/Readme.adoc[]

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

- 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.

0 comments on commit d9eae88

Please sign in to comment.