Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import unittest |
| 4 | |
| 5 | from framework import VppTestCase, VppTestRunner |
| 6 | |
| 7 | from vpp_vhost_interface import VppVhostInterface |
| 8 | |
| 9 | |
| 10 | class TesVhostInterface(VppTestCase): |
| 11 | """Vhost User Test Case |
| 12 | |
| 13 | """ |
| 14 | |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 15 | def tearDown(self): |
| 16 | super(TesVhostInterface, self).tearDown() |
| 17 | if not self.vpp_dead: |
| 18 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 19 | for ifc in if_dump: |
| 20 | self.vapi.delete_vhost_user_if(ifc.sw_if_index) |
| 21 | |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 22 | def test_vhost(self): |
| 23 | """ Vhost User add/delete interface test """ |
| 24 | self.logger.info("Vhost User add interfaces") |
| 25 | |
| 26 | # create interface 1 (VirtualEthernet0/0/0) |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 27 | vhost_if1 = VppVhostInterface(self, sock_filename=b'/tmp/sock1') |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 28 | vhost_if1.add_vpp_config() |
| 29 | vhost_if1.admin_up() |
| 30 | |
| 31 | # create interface 2 (VirtualEthernet0/0/1) |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 32 | vhost_if2 = VppVhostInterface(self, sock_filename=b'/tmp/sock2') |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 33 | vhost_if2.add_vpp_config() |
| 34 | vhost_if2.admin_up() |
| 35 | |
| 36 | # verify both interfaces in the show |
| 37 | ifs = self.vapi.cli("show interface") |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 38 | self.assertIn('VirtualEthernet0/0/0', ifs) |
| 39 | self.assertIn('VirtualEthernet0/0/1', ifs) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 40 | |
| 41 | # verify they are in the dump also |
| 42 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 43 | self.assertTrue(vhost_if1.is_interface_config_in_dump(if_dump)) |
| 44 | self.assertTrue(vhost_if2.is_interface_config_in_dump(if_dump)) |
| 45 | |
| 46 | # delete VirtualEthernet0/0/1 |
| 47 | self.logger.info("Deleting VirtualEthernet0/0/1") |
| 48 | vhost_if2.remove_vpp_config() |
| 49 | |
| 50 | self.logger.info("Verifying VirtualEthernet0/0/1 is deleted") |
| 51 | |
| 52 | ifs = self.vapi.cli("show interface") |
| 53 | # verify VirtualEthernet0/0/0 still in the show |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 54 | self.assertIn('VirtualEthernet0/0/0', ifs) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 55 | |
| 56 | # verify VirtualEthernet0/0/1 not in the show |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 57 | self.assertNotIn('VirtualEthernet0/0/1', ifs) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 58 | |
| 59 | # verify VirtualEthernet0/0/1 is not in the dump |
| 60 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 61 | self.assertFalse(vhost_if2.is_interface_config_in_dump(if_dump)) |
| 62 | |
| 63 | # verify VirtualEthernet0/0/0 is still in the dump |
| 64 | self.assertTrue(vhost_if1.is_interface_config_in_dump(if_dump)) |
| 65 | |
| 66 | # delete VirtualEthernet0/0/0 |
| 67 | self.logger.info("Deleting VirtualEthernet0/0/0") |
| 68 | vhost_if1.remove_vpp_config() |
| 69 | |
| 70 | self.logger.info("Verifying VirtualEthernet0/0/0 is deleted") |
| 71 | |
| 72 | # verify VirtualEthernet0/0/0 not in the show |
| 73 | ifs = self.vapi.cli("show interface") |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 74 | self.assertNotIn('VirtualEthernet0/0/0', ifs) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 75 | |
| 76 | # verify VirtualEthernet0/0/0 is not in the dump |
| 77 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 78 | self.assertFalse(vhost_if1.is_interface_config_in_dump(if_dump)) |
| 79 | |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 80 | def test_vhost_interface_state(self): |
| 81 | """ Vhost User interface states and events test """ |
| 82 | |
| 83 | self.vapi.want_interface_events() |
| 84 | |
| 85 | # clear outstanding events |
| 86 | # (like delete interface events from other tests) |
| 87 | self.vapi.collect_events() |
| 88 | |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 89 | vhost_if = VppVhostInterface(self, sock_filename=b'/tmp/sock1') |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 90 | |
| 91 | # create vhost interface |
| 92 | vhost_if.add_vpp_config() |
| 93 | self.sleep(0.1) |
| 94 | events = self.vapi.collect_events() |
| 95 | # creating interface doesn't currently create events |
| 96 | self.assert_equal(len(events), 0, "number of events") |
| 97 | |
| 98 | vhost_if.admin_up() |
| 99 | vhost_if.assert_interface_state(1, 0, expect_event=True) |
| 100 | |
| 101 | vhost_if.admin_down() |
| 102 | vhost_if.assert_interface_state(0, 0, expect_event=True) |
| 103 | |
| 104 | # delete vhost interface |
| 105 | vhost_if.remove_vpp_config() |
| 106 | event = self.vapi.wait_for_event(timeout=1) |
| 107 | self.assert_equal(event.sw_if_index, vhost_if.sw_if_index, |
| 108 | "sw_if_index") |
| 109 | self.assert_equal(event.deleted, 1, "deleted flag") |
| 110 | |
| 111 | # verify there are no more events |
| 112 | events = self.vapi.collect_events() |
| 113 | self.assert_equal(len(events), 0, "number of events") |
| 114 | |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 115 | if __name__ == '__main__': |
| 116 | unittest.main(testRunner=VppTestRunner) |