5 from framework import VppTestCase, VppTestRunner, running_gcov_tests
6 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
7 from os import path, remove
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 """
31 cmds = ["loop create",
32 "set int ip address loop0 11.22.33.1/24",
33 "set int state loop0 up",
35 "set int ip address loop1 11.22.34.1/24",
36 "set int state loop1 up",
37 "set ip neighbor loop1 11.22.34.44 03:00:11:22:34:44",
38 "packet-generator new {\n"
43 " tx-interface loop1\n"
44 " node loop1-output\n"
45 " buffer-flags ip4 offload-ip-cksum offload-udp-cksum\n"
47 " IP4: 1.2.3 -> dead.0000.0001\n"
48 " UDP: 11.22.33.44 -> 11.22.34.44\n"
49 " ttl 2 checksum 13\n"
50 " UDP: 1234 -> 2345\n"
55 "pcap dispatch trace on max 100 buffer-trace pg-input 10",
57 "pcap dispatch trace off",
58 "pcap trace rx tx max 1000 intfc any",
61 "pcap trace rx tx off",
62 "classify filter pcap mask l3 ip4 src "
63 "match l3 ip4 src 11.22.33.44",
64 "pcap trace rx tx max 1000 intfc any file filt.pcap filter",
65 "show cla t verbose 2",
69 "pcap trace rx tx off",
70 "classify filter pcap del mask l3 ip4 src"]
73 r = self.vapi.cli_return_response(cmd)
75 if hasattr(r, 'reply'):
76 self.logger.info(cmd + " FAIL reply " + r.reply)
78 self.logger.info(cmd + " FAIL retval " + str(r.retval))
80 self.assertTrue(path.exists('/tmp/dispatch.pcap'))
81 self.assertTrue(path.exists('/tmp/rxtx.pcap'))
82 self.assertTrue(path.exists('/tmp/filt.pcap'))
83 os.remove('/tmp/dispatch.pcap')
84 os.remove('/tmp/rxtx.pcap')
85 os.remove('/tmp/filt.pcap')
87 if __name__ == '__main__':
88 unittest.main(testRunner=VppTestRunner)