]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/tc_basic/test_tc_basic.py
2 # SPDX-License-Identifier: ISC
7 # Copyright (c) 2022 by Shichu Yang
10 test_tc_basic.py: Test basic TC filters, classes and qdiscs.
17 # Save the Current Working Directory to find configuration files.
18 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
19 sys
.path
.append(os
.path
.join(CWD
, "../"))
20 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
22 from lib
.topogen
import Topogen
, TopoRouter
23 from lib
.topolog
import logger
32 r1
= tgen
.add_router("r1")
33 r2
= tgen
.add_router("r2")
35 # Create a p2p connection between r1 and r2
38 # Create switches with each router connected to it to simulate a empty network.
39 switch
= tgen
.add_switch("s1")
42 switch
= tgen
.add_switch("s2")
45 # New form of setup/teardown using pytest fixture
46 @pytest.fixture(scope
="module")
48 "Setup/Teardown the environment and provide tgen argument to tests"
50 # This function initiates the topology build with Topogen...
51 tgen
= Topogen(build_topo
, request
.module
.__name
__)
53 # ... and here it calls initialization functions.
56 # This is a sample of configuration loading.
57 router_list
= tgen
.routers()
59 # For all routers arrange for:
60 # - starting zebra using config file from <rtrname>/zebra.conf
61 # - starting ospfd using an empty config file.
62 for _
, router
in router_list
.items():
63 router
.load_config(TopoRouter
.RD_ZEBRA
)
64 router
.load_config(TopoRouter
.RD_SHARP
)
66 # Start and configure the router daemons
69 # Provide tgen as argument to each test function
72 # Teardown after last test runs
76 # Fixture that executes before each test
77 @pytest.fixture(autouse
=True)
78 def skip_on_failure(tgen
):
79 if tgen
.routers_have_failure():
80 pytest
.skip("skipped because of previous test failure")
82 def fetch_iproute2_tc_info(r
, interface
):
83 qdisc
= r
.cmd("tc qdisc show dev %s" % interface
)
84 tclass
= r
.cmd("tc class show dev %s" % interface
)
85 tfilter
= r
.cmd("tc filter show dev %s" % interface
)
86 return qdisc
, tclass
, tfilter
92 def test_tc_basic(tgen
):
93 "Test installing one pair of filter & class by sharpd"
97 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
)
101 qdisc
, tclass
, tfilter
= fetch_iproute2_tc_info(r1
, intf
)
103 logger
.info("tc qdisc on %s: %s", intf
, qdisc
)
104 logger
.info("tc class on %s: %s", intf
, tclass
)
105 logger
.info("tc filter on %s: %s", intf
, tfilter
)
107 assert "htb" in qdisc
108 assert "beef:" in qdisc
110 assert "20Mbit" in tclass
112 assert "tcp" in tfilter
113 assert "dst_ip 192.168.101.0/24" in tfilter
114 assert "src_ip 192.168.100.0/24" in tfilter
115 assert "dst_port 8001" in tfilter
116 assert "src_port 8000" in tfilter
118 if __name__
== "__main__":
119 args
= ["-s"] + sys
.argv
[1:]
120 sys
.exit(pytest
.main(args
))