blob: 7405d2e515303507626dc578af009bfadb93420c [file] [log] [blame]
Dave Barach6d6711b2020-04-27 09:11:19 -04001#!/usr/bin/env python3
2
Paul Vinciguerraae936082020-05-06 16:38:40 -04003import os
Dave Barach6d6711b2020-04-27 09:11:19 -04004import unittest
5
Klement Sekerab23ffd72021-05-31 16:08:53 +02006from framework import VppTestCase, VppTestRunner
Dave Barach6d6711b2020-04-27 09:11:19 -04007from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Dave Barach6d6711b2020-04-27 09:11:19 -04008
9
10class TestPcap(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020011 """Pcap Unit Test Cases"""
Dave Barach6d6711b2020-04-27 09:11:19 -040012
13 @classmethod
14 def setUpClass(cls):
15 super(TestPcap, cls).setUpClass()
16
17 @classmethod
18 def tearDownClass(cls):
19 super(TestPcap, cls).tearDownClass()
20
21 def setUp(self):
22 super(TestPcap, self).setUp()
23
24 def tearDown(self):
25 super(TestPcap, self).tearDown()
26
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020027 # This is a code coverage test, but it only runs for 0.3 seconds
28 # might as well just run it...
Dave Barach6d6711b2020-04-27 09:11:19 -040029 def test_pcap_unittest(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020030 """PCAP Capture Tests"""
31 cmds = [
32 "loop create",
33 "set int ip address loop0 11.22.33.1/24",
34 "set int state loop0 up",
35 "loop create",
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"
40 " name s0\n"
41 " limit 10\n"
42 " size 128-128\n"
43 " interface loop0\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"
48 " data {\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"
53 " checksum 11\n"
54 " incrementing 114\n"
55 " }\n"
56 "}",
57 "pcap dispatch trace on max 100 buffer-trace pg-input 10",
58 "pa en",
59 "pcap dispatch trace off",
60 "pcap trace rx tx max 1000 intfc any",
61 "pa en",
62 "pcap trace status",
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",
67 "show cla t verbose",
68 "show cla t",
69 "pa en",
70 "pcap trace rx tx off",
71 "classify filter pcap del mask l3 ip4 src",
72 ]
Dave Barach6d6711b2020-04-27 09:11:19 -040073
74 for cmd in cmds:
75 r = self.vapi.cli_return_response(cmd)
76 if r.retval != 0:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020077 if hasattr(r, "reply"):
Dave Barach6d6711b2020-04-27 09:11:19 -040078 self.logger.info(cmd + " FAIL reply " + r.reply)
79 else:
80 self.logger.info(cmd + " FAIL retval " + str(r.retval))
81
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020082 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")
Dave Barach6d6711b2020-04-27 09:11:19 -040088
Paul Vinciguerraae936082020-05-06 16:38:40 -040089
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020090if __name__ == "__main__":
Dave Barach6d6711b2020-04-27 09:11:19 -040091 unittest.main(testRunner=VppTestRunner)