diff --git a/tests/topotests/static_routing_mpls/r1/zebra.conf b/tests/topotests/static_routing_mpls/r1/zebra.conf index 4e5d29af988c..a1e81c05bf17 100644 --- a/tests/topotests/static_routing_mpls/r1/zebra.conf +++ b/tests/topotests/static_routing_mpls/r1/zebra.conf @@ -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 +! + diff --git a/tests/topotests/static_routing_mpls/r2/zebra.conf b/tests/topotests/static_routing_mpls/r2/zebra.conf index 4e06ae520270..505b75bdea4f 100644 --- a/tests/topotests/static_routing_mpls/r2/zebra.conf +++ b/tests/topotests/static_routing_mpls/r2/zebra.conf @@ -3,6 +3,7 @@ ip forwarding ipv6 forwarding int r2-eth0 + mpls auto ip addr 192.168.2.2/24 ! int r2-eth1 @@ -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 +! diff --git a/tests/topotests/static_routing_mpls/test_static_routing_mpls.py b/tests/topotests/static_routing_mpls/test_static_routing_mpls.py index c1e249cc8f0f..8051694e1da2 100644 --- a/tests/topotests/static_routing_mpls/test_static_routing_mpls.py +++ b/tests/topotests/static_routing_mpls/test_static_routing_mpls.py @@ -39,6 +39,11 @@ ## ##################################################### +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" @@ -65,7 +70,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: @@ -74,13 +79,26 @@ def _populate_mpls_labels(): output = tgen.net[host].cmd(cmd) logger.info("output: " + output) + # 1st interface -eth. + 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() @@ -134,6 +152,89 @@ 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))