Skip to content

Commit

Permalink
test: Verify routing preference 255 is inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
axkar committed Nov 13, 2024
1 parent 13116fd commit 17e90d7
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 1 deletion.
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


<<<

120 changes: 120 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,120 @@
#!/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 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"):
route_active = route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-routing:static", active_check=True)
assert route_active, "Static route with preference 254 should be active."

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"):
route_not_active = not route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-routing:static", active_check=True)
assert route_not_active, "Static route with preference 255 should not be active."

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"]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
2 changes: 1 addition & 1 deletion test/spec/Readme.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:topdoc:

= Test specification
Infix v24.10.1-23-g8fc0ab9b-dirty
v24.10.2-7-g13116fd9-dirty
:title-page:
:toc:
:toclevels: 2
Expand Down

0 comments on commit 17e90d7

Please sign in to comment.