6 from framework import VppTestCase, VppTestRunner
7 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
10 class TestPcap(VppTestCase):
11 """Pcap Unit Test Cases"""
15 super(TestPcap, cls).setUpClass()
18 def tearDownClass(cls):
19 super(TestPcap, cls).tearDownClass()
22 super(TestPcap, self).setUp()
25 super(TestPcap, self).tearDown()
27 # This is a code coverage test, but it only runs for 0.3 seconds
28 # might as well just run it...
29 def test_pcap_unittest(self):
30 """PCAP Capture Tests"""
33 "set int ip address loop0 11.22.33.1/24",
34 "set int state loop0 up",
36 "set int ip address loop1 11.22.34.1/24",
37 "set int state loop1 up",
38 "set ip neighbor loop1 11.22.34.44 03:00:11:22:34:44",
39 "packet-generator new {\n"
44 " tx-interface loop1\n"
45 " node loop1-output\n"
46 " buffer-flags ip4 offload\n"
47 " buffer-offload-flags offload-ip-cksum offload-udp-cksum\n"
49 " IP4: 1.2.3 -> dead.0000.0001\n"
50 " UDP: 11.22.33.44 -> 11.22.34.44\n"
51 " ttl 2 checksum 13\n"
52 " UDP: 1234 -> 2345\n"
57 "pcap dispatch trace on max 100 buffer-trace pg-input 10",
59 "pcap dispatch trace off",
60 "pcap trace rx tx max 1000 intfc any",
63 "pcap trace rx tx off",
64 "classify filter pcap mask l3 ip4 src match l3 ip4 src 11.22.33.44",
65 "pcap trace rx tx max 1000 intfc any file filt.pcap filter",
66 "show cla t verbose 2",
70 "pcap trace rx tx off",
71 "classify filter pcap del mask l3 ip4 src",
75 r = self.vapi.cli_return_response(cmd)
77 if hasattr(r, "reply"):
78 self.logger.info(cmd + " FAIL reply " + r.reply)
80 self.logger.info(cmd + " FAIL retval " + str(r.retval))
82 self.assertTrue(os.path.exists("/tmp/dispatch.pcap"))
83 self.assertTrue(os.path.exists("/tmp/rxtx.pcap"))
84 self.assertTrue(os.path.exists("/tmp/filt.pcap"))
85 os.remove("/tmp/dispatch.pcap")
86 os.remove("/tmp/rxtx.pcap")
87 os.remove("/tmp/filt.pcap")
90 if __name__ == "__main__":
91 unittest.main(testRunner=VppTestRunner)