aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_stn.py
blob: d6c8284f8295bab80e077d70522e18c770f4a452 (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
from framework import VppTestCase, VppTestRunner
import unittest
from config import config


@unittest.skipIf("stn" in config.excluded_plugins, "Exclude stn plugin tests")
class TestStn(VppTestCase):
    """STN plugin tests"""

    # TODO: actually test the rules by sending packets
    @classmethod
    def setUpClass(cls):
        super(TestStn, cls).setUpClass()
        try:
            cls.create_pg_interfaces(range(2))
            for i in cls.pg_interfaces:
                i.config_ip4()
                i.resolve_arp()
                i.admin_up()
        except Exception:
            cls.tearDownClass()
            raise

    @classmethod
    def tearDownClass(cls):
        for i in cls.pg_interfaces:
            i.unconfig_ip4()
            i.admin_down()
        super(TestStn, cls).tearDownClass()

    def test_stn_cli(self):
        """Add, dump and delete stn rule [CLI]"""
        expected = [
            "rule_index: 0",
            f"address: {self.pg0.local_ip4}",
            "iface: pg0",
            "next_node: pg0-output",
        ]
        self.vapi.cli(f"stn rule address {self.pg0.local_ip4} interface pg0")

        reply = self.vapi.cli("show stn rules")
        for entry in expected:
            self.assertIn(entry, reply)

        self.vapi.cli(f"stn rule address {self.pg0.local_ip4} interface pg0 del")

    def test_stn_vapi(self):
        """Add, dump and delete stn rule [VAPI]"""
        self.vapi.stn_add_del_rule(
            ip_address=self.pg1.local_ip4,
            sw_if_index=1,
            is_add=1,
        )
        self.vapi.stn_rules_dump()
        self.vapi.stn_add_del_rule(
            ip_address=self.pg1.local_ip4,
            sw_if_index=1,
            is_add=0,
        )


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