tests: Added STN plugin test to improve coverage. 57/39757/2
authoradrianvillin <avillin@cisco.com>
Mon, 23 Oct 2023 16:54:29 +0000 (18:54 +0200)
committerDave Wallace <dwallacelf@gmail.com>
Wed, 25 Oct 2023 02:15:54 +0000 (02:15 +0000)
Type: test

Change-Id: I30dfaed684e1f808089bb8eb301486434425ccd7
Signed-off-by: adrianvillin <avillin@cisco.com>
test/test_stn.py [new file with mode: 0644]

diff --git a/test/test_stn.py b/test/test_stn.py
new file mode 100644 (file)
index 0000000..d6c8284
--- /dev/null
@@ -0,0 +1,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)