Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 2 | |
| 3 | import unittest |
| 4 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 5 | from asfframework import VppAsfTestCase, VppTestRunner |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 6 | |
| 7 | from vpp_vhost_interface import VppVhostInterface |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 8 | from config import config |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 9 | |
| 10 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 11 | @unittest.skipIf("vhost" in config.excluded_plugins, "Exclude Vhost plugin tests") |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 12 | class TesVhostInterface(VppAsfTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 13 | """Vhost User Test Case""" |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 14 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 15 | @classmethod |
| 16 | def setUpClass(cls): |
| 17 | super(TesVhostInterface, cls).setUpClass() |
| 18 | |
| 19 | @classmethod |
| 20 | def tearDownClass(cls): |
| 21 | super(TesVhostInterface, cls).tearDownClass() |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 22 | |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 23 | def tearDown(self): |
| 24 | super(TesVhostInterface, self).tearDown() |
| 25 | if not self.vpp_dead: |
| 26 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 27 | for ifc in if_dump: |
| 28 | self.vapi.delete_vhost_user_if(ifc.sw_if_index) |
| 29 | |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 30 | def test_vhost(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 31 | """Vhost User add/delete interface test""" |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 32 | self.logger.info("Vhost User add interfaces") |
| 33 | |
| 34 | # create interface 1 (VirtualEthernet0/0/0) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 35 | vhost_if1 = VppVhostInterface(self, sock_filename="/tmp/sock1") |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 36 | vhost_if1.add_vpp_config() |
| 37 | vhost_if1.admin_up() |
| 38 | |
| 39 | # create interface 2 (VirtualEthernet0/0/1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 40 | vhost_if2 = VppVhostInterface(self, sock_filename="/tmp/sock2") |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 41 | vhost_if2.add_vpp_config() |
| 42 | vhost_if2.admin_up() |
| 43 | |
| 44 | # verify both interfaces in the show |
| 45 | ifs = self.vapi.cli("show interface") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 46 | self.assertIn("VirtualEthernet0/0/0", ifs) |
| 47 | self.assertIn("VirtualEthernet0/0/1", ifs) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 48 | |
| 49 | # verify they are in the dump also |
| 50 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 51 | self.assertTrue(vhost_if1.is_interface_config_in_dump(if_dump)) |
| 52 | self.assertTrue(vhost_if2.is_interface_config_in_dump(if_dump)) |
| 53 | |
| 54 | # delete VirtualEthernet0/0/1 |
| 55 | self.logger.info("Deleting VirtualEthernet0/0/1") |
| 56 | vhost_if2.remove_vpp_config() |
| 57 | |
| 58 | self.logger.info("Verifying VirtualEthernet0/0/1 is deleted") |
| 59 | |
| 60 | ifs = self.vapi.cli("show interface") |
| 61 | # verify VirtualEthernet0/0/0 still in the show |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 62 | self.assertIn("VirtualEthernet0/0/0", ifs) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 63 | |
| 64 | # verify VirtualEthernet0/0/1 not in the show |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 65 | self.assertNotIn("VirtualEthernet0/0/1", ifs) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 66 | |
| 67 | # verify VirtualEthernet0/0/1 is not in the dump |
| 68 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 69 | self.assertFalse(vhost_if2.is_interface_config_in_dump(if_dump)) |
| 70 | |
| 71 | # verify VirtualEthernet0/0/0 is still in the dump |
| 72 | self.assertTrue(vhost_if1.is_interface_config_in_dump(if_dump)) |
| 73 | |
| 74 | # delete VirtualEthernet0/0/0 |
| 75 | self.logger.info("Deleting VirtualEthernet0/0/0") |
| 76 | vhost_if1.remove_vpp_config() |
| 77 | |
| 78 | self.logger.info("Verifying VirtualEthernet0/0/0 is deleted") |
| 79 | |
| 80 | # verify VirtualEthernet0/0/0 not in the show |
| 81 | ifs = self.vapi.cli("show interface") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 82 | self.assertNotIn("VirtualEthernet0/0/0", ifs) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 83 | |
| 84 | # verify VirtualEthernet0/0/0 is not in the dump |
| 85 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 86 | self.assertFalse(vhost_if1.is_interface_config_in_dump(if_dump)) |
| 87 | |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 88 | def test_vhost_interface_state(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 89 | """Vhost User interface states and events test""" |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 90 | |
| 91 | self.vapi.want_interface_events() |
| 92 | |
| 93 | # clear outstanding events |
| 94 | # (like delete interface events from other tests) |
| 95 | self.vapi.collect_events() |
| 96 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 97 | vhost_if = VppVhostInterface(self, sock_filename="/tmp/sock1") |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 98 | |
| 99 | # create vhost interface |
| 100 | vhost_if.add_vpp_config() |
| 101 | self.sleep(0.1) |
| 102 | events = self.vapi.collect_events() |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 103 | # creating interface does now create events |
| 104 | self.assert_equal(len(events), 1, "number of events") |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 105 | |
| 106 | vhost_if.admin_up() |
| 107 | vhost_if.assert_interface_state(1, 0, expect_event=True) |
| 108 | |
| 109 | vhost_if.admin_down() |
| 110 | vhost_if.assert_interface_state(0, 0, expect_event=True) |
| 111 | |
| 112 | # delete vhost interface |
| 113 | vhost_if.remove_vpp_config() |
| 114 | event = self.vapi.wait_for_event(timeout=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 115 | self.assert_equal(event.sw_if_index, vhost_if.sw_if_index, "sw_if_index") |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 116 | self.assert_equal(event.deleted, 1, "deleted flag") |
| 117 | |
| 118 | # verify there are no more events |
| 119 | events = self.vapi.collect_events() |
| 120 | self.assert_equal(len(events), 0, "number of events") |
| 121 | |
Fahad Naeem | 08183d7 | 2022-04-04 10:31:04 -0400 | [diff] [blame] | 122 | def test_vhost_interface_custom_mac_addr(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 123 | """Vhost User interface custom mac address test""" |
Fahad Naeem | 08183d7 | 2022-04-04 10:31:04 -0400 | [diff] [blame] | 124 | |
| 125 | mac_addr = "aa:bb:cc:dd:ee:ff" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 126 | vhost_if = VppVhostInterface( |
| 127 | self, sock_filename="/tmp/sock1", use_custom_mac=1, mac_address=mac_addr |
| 128 | ) |
Fahad Naeem | 08183d7 | 2022-04-04 10:31:04 -0400 | [diff] [blame] | 129 | |
| 130 | # create vhost interface |
| 131 | vhost_if.add_vpp_config() |
| 132 | self.sleep(0.1) |
| 133 | |
| 134 | # verify mac in the dump |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 135 | if_dump_list = self.vapi.sw_interface_dump(sw_if_index=vhost_if.sw_if_index) |
Fahad Naeem | 08183d7 | 2022-04-04 10:31:04 -0400 | [diff] [blame] | 136 | self.assert_equal(len(if_dump_list), 1, "if dump length") |
| 137 | |
| 138 | [if_dump] = if_dump_list |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 139 | self.assert_equal(if_dump.l2_address.mac_string, mac_addr, "MAC Address") |
Fahad Naeem | 08183d7 | 2022-04-04 10:31:04 -0400 | [diff] [blame] | 140 | |
| 141 | # delete VirtualEthernet |
| 142 | self.logger.info("Deleting VirtualEthernet") |
| 143 | vhost_if.remove_vpp_config() |
| 144 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 145 | |
| 146 | if __name__ == "__main__": |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 147 | unittest.main(testRunner=VppTestRunner) |