aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_ct6.py
blob: f4d328569472503757887ce0c809c820d61fe892 (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
65
66
67
68
69
70
71
72
from config import config
from framework import VppTestCase
from asfframework import VppTestRunner
import unittest
from scapy.layers.l2 import Ether
from scapy.layers.inet import UDP
from scapy.layers.inet6 import IPv6
from random import randint


# TODO: get an actual output from "show ip6 connection-tracker"
@unittest.skipIf("ct6" in config.excluded_plugins, "Exclude CT6 plugin tests")
class TestCt6(VppTestCase):
    """CT6 plugin tests"""

    @classmethod
    def setUpClass(cls):
        super(TestCt6, cls).setUpClass()
        try:
            cls.create_pg_interfaces(range(2))
            for i in cls.pg_interfaces:
                i.config_ip6().resolve_ndp()
                i.admin_up()
        except Exception:
            cls.tearDownClass()
            raise

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

    def create_stream(self, src_if, dst_if, count):
        packets = []
        for i in range(count):
            p = (
                Ether(src=src_if.remote_mac, dst=src_if.local_mac)
                / IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6)
                / UDP(sport=randint(49152, 65535), dport=5678, chksum=0)
            )
            packets.append(p)
        return packets

    def test_ct6_vapi(self):
        self.vapi.ct6_enable_disable(enable_disable=True, is_inside=True, sw_if_index=1)
        self.vapi.ct6_enable_disable(
            enable_disable=True, is_inside=False, sw_if_index=1
        )

        packets = self.create_stream(self.pg0, self.pg1, 5)
        self.pg0.add_stream(packets)
        self.pg_start()

        self.vapi.ct6_enable_disable(1234, 567, True, True, "pg0", "disable")

    def test_ct6_cli(self):
        self.vapi.cli("set ct6 outside pg1")
        self.vapi.cli("set ct6 inside pg1")

        packets = self.create_stream(self.pg0, self.pg1, 5)
        self.pg0.add_stream(packets)
        self.pg_start()

        reply = self.vapi.cli("show ip6 connection-tracker")
        self.assertIn("Thread 0", reply)
        reply = self.vapi.cli("test ip6 connection-tracker")
        self.assertIn("End state", reply)

        self.vapi.cli("set ct6 inside pg1 disable")


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