Skip to content

Commit

Permalink
topotests: add static mpls routing auto mode
Browse files Browse the repository at this point in the history
There is no test that checks for the mpls auto mode
configuration.
New checks are added to the static mpls routing test:
- check that a labeled route turns on mpls on the interface
where the auto mode is set
- check that a configured interface recovers the mpls setting

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Aug 4, 2023
1 parent 6beefe9 commit 0ab52f3
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tests/topotests/static_routing_mpls/r1/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ int lo
!
int r1-eth1
ip addr 192.168.2.1/24
mpls auto
!
int r1-eth1.100
ip address 172.31.100.1/24
mpls auto
!

5 changes: 5 additions & 0 deletions tests/topotests/static_routing_mpls/r2/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ip forwarding
ipv6 forwarding

int r2-eth0
mpls auto
ip addr 192.168.2.2/24
!
int r2-eth1
Expand All @@ -16,3 +17,7 @@ int r2-eth2
int lo
ip addr 192.0.2.2/32
!
int r2-eth0.100
ip address 172.31.100.2/24
mpls auto
!
103 changes: 101 additions & 2 deletions tests/topotests/static_routing_mpls/test_static_routing_mpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
##
#####################################################

cmds_list_iface = [
"ip link add link {0}-eth{1} name {0}-eth{1}.{3} type vlan id {3}",
"ip link set dev {0}-eth{1}.{3} up",
]

def build_topo(tgen):
"Build function"
Expand All @@ -65,7 +69,7 @@ def build_topo(tgen):
## Tests starting
##
#####################################################
def _populate_mpls_labels():
def _populate_iface():
tgen = get_topogen()
cmds_list = ["echo 100000 > /proc/sys/net/mpls/platform_labels"]
for cmd in cmds_list:
Expand All @@ -74,13 +78,26 @@ def _populate_mpls_labels():
output = tgen.net[host].cmd(cmd)
logger.info("output: " + output)

# 1st interface <router>-eth<x>.<vlanid>
for cmd in cmds_list_iface:
input = cmd.format("r1", "1", "1", "100")
logger.info("input: " + cmd.format("r1", "1", "1", "100"))
output = tgen.net["r1"].cmd(cmd.format("r1", "1", "1", "100"))
logger.info("output: " + output)

for cmd in cmds_list_iface:
input = cmd.format("r2", "0", "2", "100")
logger.info("input: " + cmd.format("r2", "0", "2", "100"))
output = tgen.net["r2"].cmd(cmd.format("r2", "0", "2", "100"))
logger.info("output: " + output)


def setup_module(module):
"Setup topology"
tgen = Topogen(build_topo, module.__name__)
tgen.start_topology()

_populate_mpls_labels()
_populate_iface()

# This is a sample of configuration loading.
router_list = tgen.routers()
Expand Down Expand Up @@ -134,6 +151,88 @@ def test_mpls_configured_on_interface():
assert _check_mpls_state(tgen.gears["r2"], "r2-eth2", False), assertmsg


def test_mpls_zebra_route_nexthop():
"Test 'mpls' state is correctly configured with labeled routes configured"

tgen = get_topogen()
# Don't run this test if we have any failure.
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

router = tgen.gears["r2"]
output = router.vtysh_cmd("config terminal\nmpls lsp 33 192.168.2.3 implicit-null")

logger.info(
"r1, configuring a route with labeled nexthop address, checking that MPLS state is on on r1-eth1"
)
router = tgen.gears["r1"]
output = router.vtysh_cmd(
"config terminal\nip route 192.0.2.3/32 192.168.2.2 label 33"
)
assertmsg = "r1, interface r1-eth1, mpls operational state is off, not expected"
assert _check_mpls_state(tgen.gears["r1"], "r1-eth1"), assertmsg
# interface r1-eth1 should have mpls turned on

logger.info(
"r2, configuring a route with labeled nexthop interface, checking that MPLS state is on on r2-eth0"
)
router = tgen.gears["r2"]
output = router.vtysh_cmd(
"config terminal\nip route 192.0.2.100/32 192.168.2.1 r2-eth0 label 100"
)
# interface r2-eth0 should have mpls turned on
assertmsg = "r2, interface r2-eth0, mpls operational state is off, not expected"
assert _check_mpls_state(tgen.gears["r2"], "r2-eth0"), assertmsg

def test_mpls_interface_configured_delete():
"Test 'mpls' state is correctly set on a configured interface before and after deletion of that interface"

tgen = get_topogen()
# Don't run this test if we have any failure.
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

logger.info(
"r1, configuring a route with labeled nexthop address, checking that MPLS is configured on r1-eth1.100"
)
router = tgen.gears["r1"]
output = router.vtysh_cmd(
"config terminal\nip route 192.0.2.160/32 172.31.100.2 label 100"
)
# interface r1-eth1.100 should have mpls turned on
assertmsg = "r1, interface r1-eth1.100, mpls operational state is off, not expected"
assert _check_mpls_state(tgen.gears["r1"], "r1-eth1.100"), assertmsg

logger.info(
"r1, deleting r1-eth1.100, checking that MPLS is unconfigured on r1-eth1.200"
)
tgen.net["r1"].cmd("ip link delete r1-eth1.100")
# interface r1-eth1.100 should be turned down
output = router.vtysh_cmd(
"config terminal\nno ip route 192.0.2.160/32 172.31.100.2 label 100"
)
# static route is really removed to not conflict with mpls saved state

# interface r1-eth1.100 should be turned off, and mpls should be on
assertmsg = "r1, interface r1-eth1.100, mpls operational state is on, not expected"
assert _check_mpls_state(
tgen.gears["r1"], "r1-eth1.100", configured=False
), assertmsg

logger.info(
"r1, re-creating r1-eth1.100, checking that MPLS is configured on r1-eth1.100"
)
for cmd in cmds_list_iface:
input = cmd.format("r1", "1", "1", "100")
logger.info("input: " + cmd.format("r1", "1", "1", "100"))
output = tgen.net["r1"].cmd(cmd.format("r1", "1", "1", "100"))
logger.info("output: " + output)

# interface r1-eth1.100 should be turned on, and mpls should be on
assertmsg = "r1, interface r1-eth1.100, mpls operational state is off, not expected"
assert _check_mpls_state(tgen.gears["r1"], "r1-eth1.100"), assertmsg


if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

0 comments on commit 0ab52f3

Please sign in to comment.