Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 1 | from asfframework import VppTestRunner |
| 2 | from framework import VppTestCase |
adrianvillin | 52aaa9b | 2023-10-23 18:54:29 +0200 | [diff] [blame] | 3 | import unittest |
| 4 | from config import config |
| 5 | |
| 6 | |
| 7 | @unittest.skipIf("stn" in config.excluded_plugins, "Exclude stn plugin tests") |
| 8 | class TestStn(VppTestCase): |
| 9 | """STN plugin tests""" |
| 10 | |
| 11 | # TODO: actually test the rules by sending packets |
| 12 | @classmethod |
| 13 | def setUpClass(cls): |
| 14 | super(TestStn, cls).setUpClass() |
| 15 | try: |
| 16 | cls.create_pg_interfaces(range(2)) |
| 17 | for i in cls.pg_interfaces: |
| 18 | i.config_ip4() |
| 19 | i.resolve_arp() |
| 20 | i.admin_up() |
| 21 | except Exception: |
| 22 | cls.tearDownClass() |
| 23 | raise |
| 24 | |
| 25 | @classmethod |
| 26 | def tearDownClass(cls): |
| 27 | for i in cls.pg_interfaces: |
| 28 | i.unconfig_ip4() |
| 29 | i.admin_down() |
| 30 | super(TestStn, cls).tearDownClass() |
| 31 | |
| 32 | def test_stn_cli(self): |
| 33 | """Add, dump and delete stn rule [CLI]""" |
| 34 | expected = [ |
| 35 | "rule_index: 0", |
| 36 | f"address: {self.pg0.local_ip4}", |
| 37 | "iface: pg0", |
| 38 | "next_node: pg0-output", |
| 39 | ] |
| 40 | self.vapi.cli(f"stn rule address {self.pg0.local_ip4} interface pg0") |
| 41 | |
| 42 | reply = self.vapi.cli("show stn rules") |
| 43 | for entry in expected: |
| 44 | self.assertIn(entry, reply) |
| 45 | |
| 46 | self.vapi.cli(f"stn rule address {self.pg0.local_ip4} interface pg0 del") |
| 47 | |
| 48 | def test_stn_vapi(self): |
| 49 | """Add, dump and delete stn rule [VAPI]""" |
| 50 | self.vapi.stn_add_del_rule( |
| 51 | ip_address=self.pg1.local_ip4, |
| 52 | sw_if_index=1, |
| 53 | is_add=1, |
| 54 | ) |
| 55 | self.vapi.stn_rules_dump() |
| 56 | self.vapi.stn_add_del_rule( |
| 57 | ip_address=self.pg1.local_ip4, |
| 58 | sw_if_index=1, |
| 59 | is_add=0, |
| 60 | ) |
| 61 | |
| 62 | |
| 63 | if __name__ == "__main__": |
| 64 | unittest.main(testRunner=VppTestRunner) |