From 52aaa9b0ac20d7dca1b342c1dec3a9726ff45f4c Mon Sep 17 00:00:00 2001 From: adrianvillin Date: Mon, 23 Oct 2023 18:54:29 +0200 Subject: [PATCH] tests: Added STN plugin test to improve coverage. Type: test Change-Id: I30dfaed684e1f808089bb8eb301486434425ccd7 Signed-off-by: adrianvillin --- test/test_stn.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test/test_stn.py diff --git a/test/test_stn.py b/test/test_stn.py new file mode 100644 index 00000000000..d6c8284f829 --- /dev/null +++ b/test/test_stn.py @@ -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) -- 2.16.6