blob: c058c5467af955349e16d5dffe2b9b7f8eb55bfd [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
6from framework import VppTestCase, VppTestRunner, running_gcov_tests
7from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Dave Barach6d6711b2020-04-27 09:11:19 -04008
9
10class TestPcap(VppTestCase):
11 """ Pcap Unit Test Cases """
12
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
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",
34 "loop create",
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"
39 " name s0\n"
40 " limit 10\n"
41 " size 128-128\n"
42 " interface loop0\n"
43 " tx-interface loop1\n"
44 " node loop1-output\n"
Mohsin Kazmi68095382021-02-10 11:26:24 +010045 " buffer-flags ip4 offload\n"
46 " buffer-offload-flags offload-ip-cksum offload-udp-cksum\n"
Dave Barach6d6711b2020-04-27 09:11:19 -040047 " data {\n"
48 " IP4: 1.2.3 -> dead.0000.0001\n"
49 " UDP: 11.22.33.44 -> 11.22.34.44\n"
50 " ttl 2 checksum 13\n"
51 " UDP: 1234 -> 2345\n"
52 " checksum 11\n"
53 " incrementing 114\n"
54 " }\n"
55 "}",
56 "pcap dispatch trace on max 100 buffer-trace pg-input 10",
57 "pa en",
58 "pcap dispatch trace off",
59 "pcap trace rx tx max 1000 intfc any",
60 "pa en",
61 "pcap trace status",
62 "pcap trace rx tx off",
63 "classify filter pcap mask l3 ip4 src "
64 "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",
Jon Loeliger5f7f47e2020-11-03 15:49:10 -050071 "classify filter pcap del mask l3 ip4 src"]
Dave Barach6d6711b2020-04-27 09:11:19 -040072
73 for cmd in cmds:
74 r = self.vapi.cli_return_response(cmd)
75 if r.retval != 0:
76 if hasattr(r, 'reply'):
77 self.logger.info(cmd + " FAIL reply " + r.reply)
78 else:
79 self.logger.info(cmd + " FAIL retval " + str(r.retval))
80
Paul Vinciguerraae936082020-05-06 16:38:40 -040081 self.assertTrue(os.path.exists('/tmp/dispatch.pcap'))
82 self.assertTrue(os.path.exists('/tmp/rxtx.pcap'))
83 self.assertTrue(os.path.exists('/tmp/filt.pcap'))
Dave Barach6d6711b2020-04-27 09:11:19 -040084 os.remove('/tmp/dispatch.pcap')
85 os.remove('/tmp/rxtx.pcap')
86 os.remove('/tmp/filt.pcap')
87
Paul Vinciguerraae936082020-05-06 16:38:40 -040088
Dave Barach6d6711b2020-04-27 09:11:19 -040089if __name__ == '__main__':
90 unittest.main(testRunner=VppTestRunner)