mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-01 05:13:01 +02:00
test/case: add basic routing test
This commit is contained in:
committed by
Joachim Wiberg
parent
920a4481b1
commit
2c4b67cbbc
@@ -2,3 +2,4 @@
|
||||
- case: vlan_ping.py
|
||||
- case: ipv4_address.py
|
||||
- case: iface_status.py
|
||||
- case: routing_basic.py
|
||||
|
||||
Executable
+98
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python3
|
||||
# ,------------------------------------------------,
|
||||
# | [TARGET] |
|
||||
# | br0 |
|
||||
# | / \ |
|
||||
# | target:mgmt target:data0 targetgt:data1 |
|
||||
# | [192.168.0.1] [10.0.0.1] |
|
||||
# '------------------------------------------------'
|
||||
# | | |
|
||||
# | | |
|
||||
# ,----------------------------------------------,
|
||||
# | host:mgmt host:data0 host:data1 |
|
||||
# | [192.168.0.10] [10.0.0.10] |
|
||||
# | (ns0) (ns1) |
|
||||
# | |
|
||||
# | [ HOST ] |
|
||||
# '----------------------------------------------'
|
||||
|
||||
import infamy
|
||||
|
||||
def config_target(target, tport0, tport1, enable_fwd):
|
||||
target.put_config_dict("ietf-interfaces", {
|
||||
"interfaces": {
|
||||
"interface": [
|
||||
{
|
||||
"name": tport0,
|
||||
"type": "iana-if-type:ethernetCsmacd",
|
||||
"enabled": True,
|
||||
"ipv4": {
|
||||
"forwarding": enable_fwd,
|
||||
"address": [{
|
||||
"ip": "192.168.0.1",
|
||||
"prefix-length": 24
|
||||
}]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": tport1,
|
||||
"type": "iana-if-type:ethernetCsmacd",
|
||||
"enabled": True,
|
||||
"ipv4": {
|
||||
"forwarding": enable_fwd,
|
||||
"address": [{
|
||||
"ip": "10.0.0.1",
|
||||
"prefix-length": 24
|
||||
}]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
with infamy.Test() as test:
|
||||
with test.step("Initialize"):
|
||||
env = infamy.Env(infamy.std_topology("1x3"))
|
||||
target = env.attach("target", "mgmt")
|
||||
|
||||
with test.step("Configure target physical ports [enable routing]"):
|
||||
_, tport0 = env.ltop.xlate("target", "data0")
|
||||
_, tport1 = env.ltop.xlate("target", "data1")
|
||||
|
||||
config_target(target, tport0, tport1, True)
|
||||
|
||||
with test.step("Test: Ip routing enabled"):
|
||||
_, hport0 = env.ltop.xlate("host", "data0")
|
||||
_, hport1 = env.ltop.xlate("host", "data1")
|
||||
|
||||
with infamy.IsolatedMacVlan(hport0) as ns0, \
|
||||
infamy.IsolatedMacVlan(hport1) as ns1 :
|
||||
|
||||
ns0.addip("192.168.0.10")
|
||||
ns0.addroute("default", "192.168.0.1")
|
||||
|
||||
ns1.addip("10.0.0.10")
|
||||
ns1.addroute("default", "10.0.0.1")
|
||||
|
||||
ns0.must_reach("10.0.0.10")
|
||||
ns1.must_reach("192.168.0.10")
|
||||
|
||||
with test.step("Configure target physical ports [disable routing]"):
|
||||
|
||||
config_target(target, tport0, tport1, False)
|
||||
|
||||
with test.step("Test: Ip routing disabled"):
|
||||
|
||||
with infamy.IsolatedMacVlan(hport0) as ns0, \
|
||||
infamy.IsolatedMacVlan(hport1) as ns1 :
|
||||
|
||||
ns0.addip("192.168.0.10")
|
||||
ns0.addroute("default", "192.168.0.1")
|
||||
|
||||
ns1.addip("10.0.0.10")
|
||||
ns1.addroute("default", "10.0.0.1")
|
||||
|
||||
ns0.must_not_reach("10.0.0.10")
|
||||
ns1.must_not_reach("192.168.0.10")
|
||||
|
||||
test.succeed()
|
||||
+12
-2
@@ -67,11 +67,20 @@ class IsolatedMacVlan:
|
||||
return self.run("/bin/sh", text=True, input=script,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, *args, **kwargs)
|
||||
|
||||
def addip(self, addr, subnet=24):
|
||||
def addroute(self, subnet, nexthop, prefix_length=""):
|
||||
if prefix_length:
|
||||
prefix_length=f"/{prefix_length}"
|
||||
|
||||
self.runsh(f"""
|
||||
set -ex
|
||||
ip route add {subnet}{prefix_length} via {nexthop}
|
||||
""", check=True)
|
||||
|
||||
def addip(self, addr, prefix_length=24):
|
||||
self.runsh(f"""
|
||||
set -ex
|
||||
ip link set iface up
|
||||
ip addr add {addr}/{subnet} dev iface
|
||||
ip addr add {addr}/{prefix_length} dev iface
|
||||
""", check=True)
|
||||
|
||||
def ping(self, daddr, count=1, timeout=2, check=False):
|
||||
@@ -86,3 +95,4 @@ class IsolatedMacVlan:
|
||||
res = self.ping(daddr)
|
||||
if res.returncode == 0:
|
||||
raise Exception(res.stdout)
|
||||
|
||||
Reference in New Issue
Block a user