aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_trace_filter.py
blob: bde732d289f2b3dfe8e66975619c0acb927a9f2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3

import unittest

from framework import VppTestCase, VppTestRunner, running_extended_tests
from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath


class TestTracefilter(VppTestCase):
    """ Packet Tracer Filter Test """

    @classmethod
    def setUpClass(cls):
        super(TestTracefilter, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestTracefilter, cls).tearDownClass()

    def setUp(self):
        super(TestTracefilter, self).setUp()

    def tearDown(self):
        super(TestTracefilter, self).tearDown()

    def test_mactime_unitTest(self):
        """ Packet Tracer Filter Test """
        cmds = ["loopback create",
                "set int ip address loop0 192.168.1.1/24",
                "set int state loop0 up",
                "packet-generator new {\n"
                " name classifyme\n"
                " limit 100\n"
                " size 300-300\n"
                " interface loop0\n"
                " node ethernet-input\n"
                " data { \n"
                "      IP4: 1.2.3 -> 4.5.6\n"
                "      UDP: 192.168.1.10 - 192.168.1.20 -> 192.168.2.10\n"
                "      UDP: 1234 -> 2345\n"
                "      incrementing 286\n"
                "     }\n"
                "}\n",
                "classify filter trace mask l3 ip4 src\n"
                " match l3 ip4 src 192.168.1.15",
                "trace add pg-input 100 filter",
                "pa en"]

        for cmd in cmds:
            r = self.vapi.cli_return_response(cmd)
            if r.retval != 0:
                if hasattr(r, 'reply'):
                    self.logger.info(cmd + " FAIL reply " + r.reply)
                else:
                    self.logger.info(cmd + " FAIL retval " + str(r.retval))

        # Check for 9 classifier hits, which is the right answer
        r = self.vapi.cli_return_response("show classify table verbose 2")
        self.assertTrue(r.retval == 0)
        self.assertTrue(hasattr(r, 'reply'))
        self.assertTrue(r.reply.find("hits 9") != -1)

if __name__ == '__main__':
    unittest.main(testRunner=VppTestRunner)