blob: c3c7a662f04bf7acc679b8df24dd6a5497951d5c [file] [log] [blame]
Dave Barach6d6711b2020-04-27 09:11:19 -04001#!/usr/bin/env python3
2
3import unittest
4
5from framework import VppTestCase, VppTestRunner, running_gcov_tests
6from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
7from os import path, remove
8
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"
45 " buffer-flags ip4 offload-ip-cksum offload-udp-cksum\n"
46 " data {\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"
51 " checksum 11\n"
52 " incrementing 114\n"
53 " }\n"
54 "}",
55 "pcap dispatch trace on max 100 buffer-trace pg-input 10",
56 "pa en",
57 "pcap dispatch trace off",
58 "pcap trace rx tx max 1000 intfc any",
59 "pa en",
60 "pcap trace status",
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",
66 "show cla t verbose",
67 "show cla t",
68 "pa en",
69 "pcap trace rx tx off",
70 "classify filter pcap del mask l3 ip4 src "
71 "match l3 ip4 src 11.22.33.44"]
72
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
81 self.assertTrue(path.exists('/tmp/dispatch.pcap'))
82 self.assertTrue(path.exists('/tmp/rxtx.pcap'))
83 self.assertTrue(path.exists('/tmp/filt.pcap'))
84 os.remove('/tmp/dispatch.pcap')
85 os.remove('/tmp/rxtx.pcap')
86 os.remove('/tmp/filt.pcap')
87
88if __name__ == '__main__':
89 unittest.main(testRunner=VppTestRunner)