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