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