diff options
Diffstat (limited to 'tests')
18 files changed, 448 insertions, 16 deletions
diff --git a/tests/topotests/bgp_vpn_5549_route_map/__init__.py b/tests/topotests/bgp_vpn_5549_route_map/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/__init__.py diff --git a/tests/topotests/bgp_vpn_5549_route_map/cpe1/bgpd.conf b/tests/topotests/bgp_vpn_5549_route_map/cpe1/bgpd.conf new file mode 100644 index 0000000000..013cd8c258 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/cpe1/bgpd.conf @@ -0,0 +1,9 @@ +router bgp 65000 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/cpe1/zebra.conf b/tests/topotests/bgp_vpn_5549_route_map/cpe1/zebra.conf new file mode 100644 index 0000000000..49dcfc3b02 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/cpe1/zebra.conf @@ -0,0 +1,9 @@ +! +interface lo + ip address 172.16.255.1/32 +! +interface cpe1-eth0 + ip address 192.168.1.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/cpe2/bgpd.conf b/tests/topotests/bgp_vpn_5549_route_map/cpe2/bgpd.conf new file mode 100644 index 0000000000..d65d507bf4 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/cpe2/bgpd.conf @@ -0,0 +1,6 @@ +router bgp 65000 + no bgp ebgp-requires-policy + neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers 1 3 + neighbor 192.168.2.2 timers connect 1 +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/cpe2/zebra.conf b/tests/topotests/bgp_vpn_5549_route_map/cpe2/zebra.conf new file mode 100644 index 0000000000..a47319e45f --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/cpe2/zebra.conf @@ -0,0 +1,6 @@ +! +interface cpe2-eth0 + ip address 192.168.2.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe1/bgpd.conf b/tests/topotests/bgp_vpn_5549_route_map/pe1/bgpd.conf new file mode 100644 index 0000000000..93da025463 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe1/bgpd.conf @@ -0,0 +1,38 @@ +router bgp 65001 + bgp router-id 10.10.10.10 + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + neighbor 2001:db8:1::2 remote-as internal + neighbor 2001:db8:1::2 update-source 2001:db8:1::1 + neighbor 2001:db8:1::2 timers 1 3 + neighbor 2001:db8:1::2 timers connect 1 + neighbor 2001:db8:1::2 capability extended-nexthop + address-family ipv4 vpn + neighbor 2001:db8:1::2 activate + neighbor 2001:db8:1::2 route-map pe2 out + exit-address-family +! +router bgp 65001 vrf RED + bgp router-id 192.168.1.2 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 + address-family ipv4 unicast + label vpn export 1111 + rd vpn export 192.168.1.2:2 + rt vpn import 192.168.2.2:2 192.168.1.2:2 + rt vpn export 192.168.1.2:2 + export vpn + import vpn + exit-address-family +! +ip prefix-list cpe1 seq 5 permit 172.16.255.1/32 +! +route-map pe2 permit 10 + match ip address prefix-list cpe1 + set ipv6 vpn next-hop 2001:db8::1 +! +route-map pe2 permit 20 +exit +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe1/ldpd.conf b/tests/topotests/bgp_vpn_5549_route_map/pe1/ldpd.conf new file mode 100644 index 0000000000..fb40f06fa7 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe1/ldpd.conf @@ -0,0 +1,10 @@ +mpls ldp + router-id 10.10.10.10 + ! + address-family ipv4 + discovery transport-address 10.10.10.10 + ! + interface pe1-eth1 + ! + ! +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe1/ospf6d.conf b/tests/topotests/bgp_vpn_5549_route_map/pe1/ospf6d.conf new file mode 100644 index 0000000000..0053d1ecb5 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe1/ospf6d.conf @@ -0,0 +1,12 @@ +! +interface lo + ipv6 ospf6 area 0 +! +interface pe1-eth1 + ipv6 ospf6 area 0 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 dead-interval 3 +! +router ospf6 + ospf6 router-id 10.10.10.10 +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe1/zebra.conf b/tests/topotests/bgp_vpn_5549_route_map/pe1/zebra.conf new file mode 100644 index 0000000000..da91055135 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe1/zebra.conf @@ -0,0 +1,14 @@ +! +interface lo + ip address 10.10.10.10/32 + ipv6 address 2001:db8:1::1/128 +! +interface pe1-eth0 vrf RED + ip address 192.168.1.2/24 +! +interface pe1-eth1 + ip address 10.0.1.1/24 + ipv6 address 2001:db8::1/64 +! +ip forwarding +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe2/bgpd.conf b/tests/topotests/bgp_vpn_5549_route_map/pe2/bgpd.conf new file mode 100644 index 0000000000..6db1eef993 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe2/bgpd.conf @@ -0,0 +1,29 @@ +router bgp 65001 + bgp router-id 10.10.10.20 + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + neighbor 2001:db8:1::1 remote-as internal + neighbor 2001:db8:1::1 update-source 2001:db8:1::2 + neighbor 2001:db8:1::1 timers 1 3 + neighbor 2001:db8:1::1 timers connect 1 + neighbor 2001:db8:1::1 capability extended-nexthop + address-family ipv4 vpn + neighbor 2001:db8:1::1 activate + exit-address-family +! +router bgp 65001 vrf RED + bgp router-id 192.168.2.2 + no bgp ebgp-requires-policy + neighbor 192.168.2.1 remote-as external + neighbor 192.168.2.1 timers 1 3 + neighbor 192.168.2.1 timers connect 1 + address-family ipv4 unicast + label vpn export 2222 + rd vpn export 192.168.2.2:2 + rt vpn import 192.168.2.2:2 192.168.1.2:2 + rt vpn export 192.168.2.2:2 + export vpn + import vpn + exit-address-family +! + diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe2/ldpd.conf b/tests/topotests/bgp_vpn_5549_route_map/pe2/ldpd.conf new file mode 100644 index 0000000000..e2b5359993 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe2/ldpd.conf @@ -0,0 +1,10 @@ +mpls ldp + router-id 10.10.10.20 + ! + address-family ipv4 + discovery transport-address 10.10.10.20 + ! + interface pe2-eth0 + ! + ! +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe2/ospf6d.conf b/tests/topotests/bgp_vpn_5549_route_map/pe2/ospf6d.conf new file mode 100644 index 0000000000..f79bb4f5f7 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe2/ospf6d.conf @@ -0,0 +1,12 @@ +! +interface lo + ipv6 ospf6 area 0 +! +interface pe2-eth0 + ipv6 ospf6 area 0 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 dead-interval 3 +! +router ospf6 + ospf6 router-id 10.10.10.20 +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe2/zebra.conf b/tests/topotests/bgp_vpn_5549_route_map/pe2/zebra.conf new file mode 100644 index 0000000000..19ef7bf911 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe2/zebra.conf @@ -0,0 +1,14 @@ +! +interface lo + ip address 10.10.10.20/32 + ipv6 address 2001:db8:1::2/128 +! +interface pe2-eth1 vrf RED + ip address 192.168.2.2/24 +! +interface pe2-eth0 + ip address 10.0.1.2/24 + ipv6 address 2001:db8::2/64 +! +ip forwarding +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py b/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py new file mode 100644 index 0000000000..e567d3654f --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python + +# +# Copyright (c) 2022 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +Check if we can override VPN underlay next-hop from PE1 to PE2. +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + tgen.add_router("cpe1") + tgen.add_router("cpe2") + tgen.add_router("pe1") + tgen.add_router("pe2") + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["cpe1"]) + switch.add_link(tgen.gears["pe1"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["pe1"]) + switch.add_link(tgen.gears["pe2"]) + + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["pe2"]) + switch.add_link(tgen.gears["cpe2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + pe1 = tgen.gears["pe1"] + pe2 = tgen.gears["pe2"] + + pe1.run("ip link add RED type vrf table 1001") + pe1.run("ip link set up dev RED") + pe2.run("ip link add RED type vrf table 1001") + pe2.run("ip link set up dev RED") + pe1.run("ip link set pe1-eth0 master RED") + pe2.run("ip link set pe2-eth1 master RED") + + pe1.run("sysctl -w net.ipv4.ip_forward=1") + pe2.run("sysctl -w net.ipv4.ip_forward=1") + pe1.run("sysctl -w net.mpls.conf.pe1-eth0.input=1") + pe2.run("sysctl -w net.mpls.conf.pe2-eth1.input=1") + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_OSPF6, os.path.join(CWD, "{}/ospf6d.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_LDP, os.path.join(CWD, "{}/ldpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_vpn_5549(): + tgen = get_topogen() + + pe2 = tgen.gears["pe2"] + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + def _bgp_vpn_nexthop_changed(): + output = json.loads(pe2.vtysh_cmd("show bgp ipv4 vpn json")) + expected = { + "routes": { + "routeDistinguishers": { + "192.168.1.2:2": { + "172.16.255.1/32": [ + {"valid": True, "nexthops": [{"ip": "2001:db8::1"}]} + ], + "192.168.1.0/24": [ + {"valid": True, "nexthops": [{"ip": "2001:db8:1::1"}]} + ], + } + } + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_vpn_nexthop_changed) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed overriding IPv6 next-hop for VPN underlay" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator.py b/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator.py index cc250d5fc0..4bd0682bde 100755 --- a/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator.py +++ b/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator.py @@ -124,7 +124,7 @@ def test_srv6(): srv6 locators locator loc3 - prefix 2001:db8:3::/48 func-bits 16 block-len 32 node-len 16 + prefix 2001:db8:3::/48 block-len 32 node-len 16 func-bits 16 """ ) check_srv6_locator(router, "expected_locators4.json") diff --git a/tests/topotests/srv6_locator_usid/r1/zebra.conf b/tests/topotests/srv6_locator_usid/r1/zebra.conf index 78ef1e9d40..190e831ac1 100644 --- a/tests/topotests/srv6_locator_usid/r1/zebra.conf +++ b/tests/topotests/srv6_locator_usid/r1/zebra.conf @@ -12,7 +12,7 @@ segment-routing srv6 locators locator loc1 - prefix fc00:0:1::/48 func-bits 16 block-len 32 node-len 16 + prefix fc00:0:1::/48 block-len 32 node-len 16 func-bits 16 behavior usid ! ! diff --git a/tests/topotests/srv6_locator_usid/test_srv6_locator_usid.py b/tests/topotests/srv6_locator_usid/test_srv6_locator_usid.py index 37fd736d2b..4023555524 100755 --- a/tests/topotests/srv6_locator_usid/test_srv6_locator_usid.py +++ b/tests/topotests/srv6_locator_usid/test_srv6_locator_usid.py @@ -54,12 +54,10 @@ def setup_module(mod): for rname, router in tgen.routers().items(): router.run("/bin/bash {}/{}/setup.sh".format(CWD, rname)) router.load_config( - TopoRouter.RD_ZEBRA, os.path.join( - CWD, "{}/zebra.conf".format(rname)) + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) router.load_config( - TopoRouter.RD_SHARP, os.path.join( - CWD, "{}/sharpd.conf".format(rname)) + TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname)) ) tgen.start_router() @@ -71,18 +69,14 @@ def teardown_module(mod): def _check_srv6_locator(router, expected_locator_file): logger.info("checking zebra locator status") - output = json.loads( - router.vtysh_cmd("show segment-routing srv6 locator json") - ) + output = json.loads(router.vtysh_cmd("show segment-routing srv6 locator json")) expected = open_json_file("{}/{}".format(CWD, expected_locator_file)) return topotest.json_cmp(output, expected) def _check_sharpd_chunk(router, expected_chunk_file): logger.info("checking sharpd locator chunk status") - output = json.loads( - router.vtysh_cmd("show sharp segment-routing srv6 json") - ) + output = json.loads(router.vtysh_cmd("show sharp segment-routing srv6 json")) expected = open_json_file("{}/{}".format(CWD, expected_chunk_file)) return topotest.json_cmp(output, expected) @@ -164,7 +158,7 @@ def test_srv6_usid_locator_create_locator(): srv6 locators locator loc2 - prefix fc00:0:2::/48 func-bits 16 block-len 32 node-len 16 + prefix fc00:0:2::/48 block-len 32 node-len 16 func-bits 16 """ ) check_srv6_locator(router, "expected_locators_4.json") @@ -181,9 +175,7 @@ def test_srv6_usid_locator_set_behavior_usid(): # If you want to stop some specific line and start interactive shell, # please use tgen.mininet_cli() to start it. - logger.info( - "Specify the SRv6 Locator loc2 as a Micro-segment (uSID) Locator" - ) + logger.info("Specify the SRv6 Locator loc2 as a Micro-segment (uSID) Locator") router.vtysh_cmd( """ configure terminal diff --git a/tests/topotests/tc_basic/test_tc_basic.py b/tests/topotests/tc_basic/test_tc_basic.py new file mode 100755 index 0000000000..e98e11d71d --- /dev/null +++ b/tests/topotests/tc_basic/test_tc_basic.py @@ -0,0 +1,133 @@ +#!/usr/bin/python + +# +# test_tc_basic.py +# +# Copyright (c) 2022 by Shichu Yang +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# +""" +test_tc_basic.py: Test basic TC filters, classes and qdiscs. +""" +import sys +import os +import pytest +import time + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../lib/")) + +from lib.topogen import Topogen, TopoRouter +from lib.topolog import logger + +pytestmark = [ + pytest.mark.sharpd +] + +def build_topo(tgen): + "Build function" + + r1 = tgen.add_router("r1") + r2 = tgen.add_router("r2") + + # Create a p2p connection between r1 and r2 + tgen.add_link(r1, r2) + + # Create switches with each router connected to it to simulate a empty network. + switch = tgen.add_switch("s1") + switch.add_link(r1) + + switch = tgen.add_switch("s2") + switch.add_link(r2) + +# New form of setup/teardown using pytest fixture +@pytest.fixture(scope="module") +def tgen(request): + "Setup/Teardown the environment and provide tgen argument to tests" + + # This function initiates the topology build with Topogen... + tgen = Topogen(build_topo, request.module.__name__) + + # ... and here it calls initialization functions. + tgen.start_topology() + + # This is a sample of configuration loading. + router_list = tgen.routers() + + # For all routers arrange for: + # - starting zebra using config file from <rtrname>/zebra.conf + # - starting ospfd using an empty config file. + for _, router in router_list.items(): + router.load_config(TopoRouter.RD_ZEBRA) + router.load_config(TopoRouter.RD_SHARP) + + # Start and configure the router daemons + tgen.start_router() + + # Provide tgen as argument to each test function + yield tgen + + # Teardown after last test runs + tgen.stop_topology() + + +# Fixture that executes before each test +@pytest.fixture(autouse=True) +def skip_on_failure(tgen): + if tgen.routers_have_failure(): + pytest.skip("skipped because of previous test failure") + +def fetch_iproute2_tc_info(r, interface): + qdisc = r.cmd("tc qdisc show dev %s" % interface) + tclass = r.cmd("tc class show dev %s" % interface) + tfilter = r.cmd("tc filter show dev %s" % interface) + return qdisc, tclass, tfilter + +# =================== +# The tests functions +# =================== + +def test_tc_basic(tgen): + "Test installing one pair of filter & class by sharpd" + + r1 = tgen.gears["r1"] + intf = "r1-eth0" + r1.vtysh_cmd("sharp tc dev %s source 192.168.100.0/24 destination 192.168.101.0/24 ip-protocol tcp src-port 8000 dst-port 8001 rate 20mbit" % intf) + + time.sleep(3) + + qdisc, tclass, tfilter = fetch_iproute2_tc_info(r1, intf) + + logger.info("tc qdisc on %s: %s", intf, qdisc) + logger.info("tc class on %s: %s", intf, tclass) + logger.info("tc filter on %s: %s", intf, tfilter) + + assert "htb" in qdisc + assert "beef:" in qdisc + + assert "20Mbit" in tclass + + assert "tcp" in tfilter + assert "dst_ip 192.168.101.0/24" in tfilter + assert "src_ip 192.168.100.0/24" in tfilter + assert "dst_port 8001" in tfilter + assert "src_port 8000" in tfilter + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args))
\ No newline at end of file |
