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