mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
test: Verify route preference (OSPF vs Static)
This commit is contained in:
@@ -14,4 +14,6 @@ include::ospf_multiarea/Readme.adoc[]
|
||||
|
||||
include::ospf_bfd/Readme.adoc[]
|
||||
|
||||
include::route_pref_ospf/Readme.adoc[]
|
||||
|
||||
include::route_pref_dhcp/Readme.adoc[]
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
|
||||
- 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
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
=== Route preference: OSPF vs Static
|
||||
==== Description
|
||||
This test configures a device with both an OSPF-acquired route on a
|
||||
dedicated interface and a static route to the same destination on
|
||||
another interface. The static route has a higher preference value than
|
||||
OSPF.
|
||||
|
||||
Initially, the device should prefer the OSPF route; if the OSPF route
|
||||
becomes unavailable, the static route should take over.
|
||||
|
||||
==== Topology
|
||||
ifdef::topdoc[]
|
||||
image::../../test/case/ietf_routing/route_pref_ospf/topology.svg[Route preference: OSPF vs Static topology]
|
||||
endif::topdoc[]
|
||||
ifndef::topdoc[]
|
||||
ifdef::testgroup[]
|
||||
image::route_pref_ospf/topology.svg[Route preference: OSPF vs Static topology]
|
||||
endif::testgroup[]
|
||||
ifndef::testgroup[]
|
||||
image::topology.svg[Route preference: OSPF vs Static topology]
|
||||
endif::testgroup[]
|
||||
endif::topdoc[]
|
||||
==== Test sequence
|
||||
. Set up topology and attach to target DUTs
|
||||
. Set up TPMR between R1ospf and R2ospf
|
||||
. Configure targets
|
||||
. Set up persistent MacVlan namespaces
|
||||
. Wait for OSPF and static routes
|
||||
. Verify connectivity from PC:data1 to PC:data2 via OSPF
|
||||
. Simulate OSPF route loss by blocking OSPF interface
|
||||
. Verify connectivity via static route after OSPF failover
|
||||
|
||||
|
||||
<<<
|
||||
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Route preference: OSPF vs Static
|
||||
|
||||
This test configures a device with both an OSPF-acquired route on a
|
||||
dedicated interface and a static route to the same destination on
|
||||
another interface. The static route has a higher preference value than
|
||||
OSPF.
|
||||
|
||||
Initially, the device should prefer the OSPF route; if the OSPF route
|
||||
becomes unavailable, the static route should take over.
|
||||
"""
|
||||
|
||||
import infamy
|
||||
import infamy.route as route
|
||||
from infamy.util import until, parallel
|
||||
from infamy.netns import TPMR
|
||||
|
||||
|
||||
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(target, data, link, ospf):
|
||||
target.put_config_dicts({
|
||||
"ietf-interfaces": {
|
||||
"interfaces": {
|
||||
"interface": [
|
||||
configure_interface(data, "192.168.10.1", 24),
|
||||
configure_interface(link, "192.168.50.1", 24),
|
||||
configure_interface(ospf, "192.168.60.1", 24)
|
||||
]
|
||||
}
|
||||
},
|
||||
"ietf-routing": {
|
||||
"routing": {
|
||||
"control-plane-protocols": {
|
||||
"control-plane-protocol": [
|
||||
{
|
||||
"type": "infix-routing:ospfv2",
|
||||
"name": "ospf-default",
|
||||
"ospf": {
|
||||
"redistribute": {
|
||||
"redistribute": [{"protocol": "connected"}]
|
||||
},
|
||||
"areas": {
|
||||
"area": [{
|
||||
"area-id": "0.0.0.0",
|
||||
"interfaces": {
|
||||
"interface": [{
|
||||
"name": ospf,
|
||||
"hello-interval": 1,
|
||||
"dead-interval": 3
|
||||
}]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "infix-routing:static",
|
||||
"name": "dot20",
|
||||
"static-routes": {
|
||||
"ipv4": {
|
||||
"route": [{
|
||||
"destination-prefix": "192.168.20.0/24",
|
||||
"next-hop": {"next-hop-address": "192.168.50.2"},
|
||||
"route-preference": 120
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
def config_target2(target, data, link, ospf):
|
||||
target.put_config_dicts({
|
||||
"ietf-interfaces": {
|
||||
"interfaces": {
|
||||
"interface": [
|
||||
configure_interface(data, "192.168.20.2", 24),
|
||||
configure_interface(link, "192.168.50.2", 24),
|
||||
configure_interface(ospf, "192.168.60.2", 24)
|
||||
]
|
||||
}
|
||||
},
|
||||
"ietf-routing": {
|
||||
"routing": {
|
||||
"control-plane-protocols": {
|
||||
"control-plane-protocol": [
|
||||
{
|
||||
"type": "infix-routing:ospfv2",
|
||||
"name": "ospf-default",
|
||||
"ospf": {
|
||||
"redistribute": {
|
||||
"redistribute": [{"protocol": "connected"}]
|
||||
},
|
||||
"areas": {
|
||||
"area": [{
|
||||
"area-id": "0.0.0.0",
|
||||
"interfaces": {
|
||||
"interface": [{
|
||||
"name": ospf,
|
||||
"hello-interval": 1,
|
||||
"dead-interval": 3
|
||||
}]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "infix-routing:static",
|
||||
"name": "default",
|
||||
"static-routes": {
|
||||
"ipv4": {
|
||||
"route": [{
|
||||
"destination-prefix": "0.0.0.0/0",
|
||||
"next-hop": {"next-hop-address": "192.168.50.1"}
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
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("Set up TPMR between R1ospf and R2ospf"):
|
||||
ospf_breaker = TPMR(env.ltop.xlate("PC", "R1_ospf")[1], env.ltop.xlate("PC", "R2_ospf")[1]).start()
|
||||
|
||||
with test.step("Configure targets"):
|
||||
_, R1data = env.ltop.xlate("R1", "data")
|
||||
_, R1link = env.ltop.xlate("R1", "link")
|
||||
_, R1ospf = env.ltop.xlate("R1", "ospf")
|
||||
_, R2data = env.ltop.xlate("R2", "data")
|
||||
_, R2link = env.ltop.xlate("R2", "link")
|
||||
_, R2ospf = env.ltop.xlate("R2", "ospf")
|
||||
|
||||
parallel(config_target1(R1, R1data, R1link, R1ospf), config_target2(R2, R2data, R2link, R2ospf))
|
||||
|
||||
with test.step("Set up persistent MacVlan namespaces"):
|
||||
_, hport_data1 = env.ltop.xlate("PC", "data1")
|
||||
_, hport_data2 = env.ltop.xlate("PC", "data2")
|
||||
|
||||
ns1 = infamy.IsolatedMacVlan(hport_data1).start()
|
||||
ns1.addip("192.168.10.11", prefix_length=24)
|
||||
ns1.addroute("default", "192.168.10.1")
|
||||
|
||||
ns2 = infamy.IsolatedMacVlan(hport_data2).start()
|
||||
ns2.addip("192.168.20.22", prefix_length=24)
|
||||
ns2.addroute("default", "192.168.20.2")
|
||||
|
||||
with test.step("Wait for OSPF and static routes"):
|
||||
print("Waiting for OSPF and static routes...")
|
||||
until(lambda: route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-ospf:ospfv2"), attempts=200)
|
||||
until(lambda: route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-routing:static"), attempts=200)
|
||||
|
||||
with test.step("Verify connectivity from PC:data1 to PC:data2 via OSPF"):
|
||||
ns1.must_reach("192.168.20.22")
|
||||
|
||||
ospf_route_active = route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-ospf:ospfv2", active_check=True)
|
||||
assert ospf_route_active, "OSPF route should be preferred when available."
|
||||
|
||||
hops = [row[1] for row in ns1.traceroute("192.168.20.22")]
|
||||
assert "192.168.60.2" in hops, f"Path does not use expected OSPF route: {hops}"
|
||||
|
||||
with test.step("Simulate OSPF route loss by blocking OSPF interface"):
|
||||
ospf_breaker.block()
|
||||
until(lambda: not route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-ospf:ospfv2"), attempts=200)
|
||||
|
||||
with test.step("Verify connectivity via static route after OSPF failover"):
|
||||
ns1.must_reach("192.168.20.22")
|
||||
|
||||
static_route_active = route.ipv4_route_exist(R1, "192.168.20.0/24", proto="ietf-routing:static", active_check=True)
|
||||
assert static_route_active, "Static route should be preferred when OSPF route is unavailable."
|
||||
|
||||
hops = [row[1] for row in ns1.traceroute("192.168.20.22")]
|
||||
assert "192.168.50.2" in hops, f"Path does not use expected static route: {hops}"
|
||||
|
||||
test.succeed()
|
||||
@@ -0,0 +1,41 @@
|
||||
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 | <> \n\n | <R1_ospf> R1_ospf | <R2_ospf> R2_ospf | <> \n\n | <data2> data2 | <mgmt2> mgmt2 }",
|
||||
pos="20,50!",
|
||||
kind="controller",
|
||||
];
|
||||
|
||||
R1
|
||||
[
|
||||
label="{ <mgmt> mgmt | <data> data | <ospf> ospf | <link> link } | R1",
|
||||
pos="70,58!",
|
||||
kind="infix",
|
||||
];
|
||||
|
||||
R2
|
||||
[
|
||||
label="{ <link> link | <ospf> ospf | <data> data | <mgmt> mgmt } | R2",
|
||||
pos="70,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"]
|
||||
|
||||
R1:ospf -- PC:R1_ospf [color="lightgreen", taillabel="192.168.60.1/24"]
|
||||
R2:ospf -- PC:R2_ospf [color="lightgreen", taillabel="192.168.60.2/24"]
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
|
||||
<!-- Title: route-preference Pages: 1 -->
|
||||
<svg width="555pt" height="244pt"
|
||||
viewBox="0.00 0.00 554.65 244.01" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 240.01)">
|
||||
<title>route-preference</title>
|
||||
<polygon fill="white" stroke="transparent" points="-4,4 -4,-240.01 550.65,-240.01 550.65,4 -4,4"/>
|
||||
<!-- PC -->
|
||||
<g id="node1" class="node">
|
||||
<title>PC</title>
|
||||
<polygon fill="none" stroke="black" points="0,-9.01 0,-227.01 107,-227.01 107,-9.01 0,-9.01"/>
|
||||
<text text-anchor="middle" x="16.5" y="-114.31" font-family="DejaVu Sans Mono, Book" font-size="14.00">PC</text>
|
||||
<polyline fill="none" stroke="black" points="33,-9.01 33,-227.01 "/>
|
||||
<text text-anchor="middle" x="70" y="-211.81" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt1</text>
|
||||
<polyline fill="none" stroke="black" points="33,-204.01 107,-204.01 "/>
|
||||
<text text-anchor="middle" x="70" y="-188.81" font-family="DejaVu Sans Mono, Book" font-size="14.00">data1</text>
|
||||
<polyline fill="none" stroke="black" points="33,-181.01 107,-181.01 "/>
|
||||
<polyline fill="none" stroke="black" points="33,-141.01 107,-141.01 "/>
|
||||
<text text-anchor="middle" x="70" y="-125.81" font-family="DejaVu Sans Mono, Book" font-size="14.00">R1_ospf</text>
|
||||
<polyline fill="none" stroke="black" points="33,-118.01 107,-118.01 "/>
|
||||
<text text-anchor="middle" x="70" y="-102.81" font-family="DejaVu Sans Mono, Book" font-size="14.00">R2_ospf</text>
|
||||
<polyline fill="none" stroke="black" points="33,-95.01 107,-95.01 "/>
|
||||
<polyline fill="none" stroke="black" points="33,-55.01 107,-55.01 "/>
|
||||
<text text-anchor="middle" x="70" y="-39.81" font-family="DejaVu Sans Mono, Book" font-size="14.00">data2</text>
|
||||
<polyline fill="none" stroke="black" points="33,-32.01 107,-32.01 "/>
|
||||
<text text-anchor="middle" x="70" y="-16.81" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt2</text>
|
||||
</g>
|
||||
<!-- R1 -->
|
||||
<g id="node2" class="node">
|
||||
<title>R1</title>
|
||||
<polygon fill="none" stroke="black" points="458.92,-143.51 458.92,-235.51 541.92,-235.51 541.92,-143.51 458.92,-143.51"/>
|
||||
<text text-anchor="middle" x="483.92" y="-220.31" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt</text>
|
||||
<polyline fill="none" stroke="black" points="458.92,-212.51 508.92,-212.51 "/>
|
||||
<text text-anchor="middle" x="483.92" y="-197.31" font-family="DejaVu Sans Mono, Book" font-size="14.00">data</text>
|
||||
<polyline fill="none" stroke="black" points="458.92,-189.51 508.92,-189.51 "/>
|
||||
<text text-anchor="middle" x="483.92" y="-174.31" font-family="DejaVu Sans Mono, Book" font-size="14.00">ospf</text>
|
||||
<polyline fill="none" stroke="black" points="458.92,-166.51 508.92,-166.51 "/>
|
||||
<text text-anchor="middle" x="483.92" y="-151.31" font-family="DejaVu Sans Mono, Book" font-size="14.00">link</text>
|
||||
<polyline fill="none" stroke="black" points="508.92,-143.51 508.92,-235.51 "/>
|
||||
<text text-anchor="middle" x="525.42" y="-185.81" font-family="DejaVu Sans Mono, Book" font-size="14.00">R1</text>
|
||||
</g>
|
||||
<!-- PC--R1 -->
|
||||
<g id="edge1" class="edge">
|
||||
<title>PC:mgmt1--R1:mgmt</title>
|
||||
<path fill="none" stroke="lightgray" stroke-width="2" d="M107.5,-216.01C107.5,-216.01 458.42,-224.51 458.42,-224.51"/>
|
||||
</g>
|
||||
<!-- PC--R1 -->
|
||||
<g id="edge3" class="edge">
|
||||
<title>PC:data1--R1:data</title>
|
||||
<path fill="none" stroke="black" stroke-width="2" d="M107.5,-193.01C107.5,-193.01 458.42,-201.51 458.42,-201.51"/>
|
||||
<text text-anchor="middle" x="399.42" y="-205.31" font-family="DejaVu Serif, Book" font-size="14.00">192.168.10.1/24</text>
|
||||
<text text-anchor="middle" x="171" y="-196.81" font-family="DejaVu Serif, Book" font-size="14.00">192.168.10.11/24</text>
|
||||
</g>
|
||||
<!-- R2 -->
|
||||
<g id="node3" class="node">
|
||||
<title>R2</title>
|
||||
<polygon fill="none" stroke="black" points="458.92,-0.5 458.92,-92.5 541.92,-92.5 541.92,-0.5 458.92,-0.5"/>
|
||||
<text text-anchor="middle" x="483.92" y="-77.3" font-family="DejaVu Sans Mono, Book" font-size="14.00">link</text>
|
||||
<polyline fill="none" stroke="black" points="458.92,-69.5 508.92,-69.5 "/>
|
||||
<text text-anchor="middle" x="483.92" y="-54.3" font-family="DejaVu Sans Mono, Book" font-size="14.00">ospf</text>
|
||||
<polyline fill="none" stroke="black" points="458.92,-46.5 508.92,-46.5 "/>
|
||||
<text text-anchor="middle" x="483.92" y="-31.3" font-family="DejaVu Sans Mono, Book" font-size="14.00">data</text>
|
||||
<polyline fill="none" stroke="black" points="458.92,-23.5 508.92,-23.5 "/>
|
||||
<text text-anchor="middle" x="483.92" y="-8.3" font-family="DejaVu Sans Mono, Book" font-size="14.00">mgmt</text>
|
||||
<polyline fill="none" stroke="black" points="508.92,-0.5 508.92,-92.5 "/>
|
||||
<text text-anchor="middle" x="525.42" y="-42.8" font-family="DejaVu Sans Mono, Book" font-size="14.00">R2</text>
|
||||
</g>
|
||||
<!-- PC--R2 -->
|
||||
<g id="edge2" class="edge">
|
||||
<title>PC:mgmt2--R2:mgmt</title>
|
||||
<path fill="none" stroke="lightgray" stroke-width="2" d="M107.5,-20.01C107.5,-20.01 458.42,-11.5 458.42,-11.5"/>
|
||||
</g>
|
||||
<!-- PC--R2 -->
|
||||
<g id="edge4" class="edge">
|
||||
<title>PC:data2--R2:data</title>
|
||||
<path fill="none" stroke="black" stroke-width="2" d="M107.5,-43.01C107.5,-43.01 458.42,-34.5 458.42,-34.5"/>
|
||||
<text text-anchor="middle" x="399.42" y="-38.3" font-family="DejaVu Serif, Book" font-size="14.00">192.168.20.2/24</text>
|
||||
<text text-anchor="middle" x="171" y="-46.81" font-family="DejaVu Serif, Book" font-size="14.00">192.168.20.22/24</text>
|
||||
</g>
|
||||
<!-- R1--PC -->
|
||||
<g id="edge6" class="edge">
|
||||
<title>R1:ospf--PC:R1_ospf</title>
|
||||
<path fill="none" stroke="lightgreen" stroke-width="2" d="M458.42,-177.51C458.42,-177.51 107.5,-130.01 107.5,-130.01"/>
|
||||
<text text-anchor="middle" x="399.42" y="-181.31" font-family="DejaVu Serif, Book" font-size="14.00">192.168.60.1/24</text>
|
||||
</g>
|
||||
<!-- R1--R2 -->
|
||||
<g id="edge5" class="edge">
|
||||
<title>R1:link--R2:link</title>
|
||||
<path fill="none" stroke="black" stroke-width="2" d="M483.42,-143.51C483.42,-143.51 483.42,-92.5 483.42,-92.5"/>
|
||||
<text text-anchor="middle" x="487.65" y="-97.86" font-family="DejaVu Serif, Book" font-size="14.00">192.168.50.2/24</text>
|
||||
<text text-anchor="middle" x="479.19" y="-130.75" font-family="DejaVu Serif, Book" font-size="14.00">192.168.50.1/24</text>
|
||||
</g>
|
||||
<!-- R2--PC -->
|
||||
<g id="edge7" class="edge">
|
||||
<title>R2:ospf--PC:R2_ospf</title>
|
||||
<path fill="none" stroke="lightgreen" stroke-width="2" d="M458.42,-58.5C458.42,-58.5 107.5,-106.01 107.5,-106.01"/>
|
||||
<text text-anchor="middle" x="399.42" y="-62.3" font-family="DejaVu Serif, Book" font-size="14.00">192.168.60.2/24</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.5 KiB |
Reference in New Issue
Block a user