5 from framework import VppTestCase, VppTestRunner
7 from vpp_vhost_interface import VppVhostInterface
10 class TesVhostInterface(VppTestCase):
11 """Vhost User Test Case
16 super(TesVhostInterface, cls).setUpClass()
19 def tearDownClass(cls):
20 super(TesVhostInterface, cls).tearDownClass()
23 super(TesVhostInterface, self).tearDown()
25 if_dump = self.vapi.sw_interface_vhost_user_dump()
27 self.vapi.delete_vhost_user_if(ifc.sw_if_index)
30 """ Vhost User add/delete interface test """
31 self.logger.info("Vhost User add interfaces")
33 # create interface 1 (VirtualEthernet0/0/0)
34 vhost_if1 = VppVhostInterface(self, sock_filename='/tmp/sock1')
35 vhost_if1.add_vpp_config()
38 # create interface 2 (VirtualEthernet0/0/1)
39 vhost_if2 = VppVhostInterface(self, sock_filename='/tmp/sock2')
40 vhost_if2.add_vpp_config()
43 # verify both interfaces in the show
44 ifs = self.vapi.cli("show interface")
45 self.assertIn('VirtualEthernet0/0/0', ifs)
46 self.assertIn('VirtualEthernet0/0/1', ifs)
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))
53 # delete VirtualEthernet0/0/1
54 self.logger.info("Deleting VirtualEthernet0/0/1")
55 vhost_if2.remove_vpp_config()
57 self.logger.info("Verifying VirtualEthernet0/0/1 is deleted")
59 ifs = self.vapi.cli("show interface")
60 # verify VirtualEthernet0/0/0 still in the show
61 self.assertIn('VirtualEthernet0/0/0', ifs)
63 # verify VirtualEthernet0/0/1 not in the show
64 self.assertNotIn('VirtualEthernet0/0/1', ifs)
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))
70 # verify VirtualEthernet0/0/0 is still in the dump
71 self.assertTrue(vhost_if1.is_interface_config_in_dump(if_dump))
73 # delete VirtualEthernet0/0/0
74 self.logger.info("Deleting VirtualEthernet0/0/0")
75 vhost_if1.remove_vpp_config()
77 self.logger.info("Verifying VirtualEthernet0/0/0 is deleted")
79 # verify VirtualEthernet0/0/0 not in the show
80 ifs = self.vapi.cli("show interface")
81 self.assertNotIn('VirtualEthernet0/0/0', ifs)
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))
87 def test_vhost_interface_state(self):
88 """ Vhost User interface states and events test """
90 self.vapi.want_interface_events()
92 # clear outstanding events
93 # (like delete interface events from other tests)
94 self.vapi.collect_events()
96 vhost_if = VppVhostInterface(self, sock_filename='/tmp/sock1')
98 # create vhost interface
99 vhost_if.add_vpp_config()
101 events = self.vapi.collect_events()
102 # creating interface does now create events
103 self.assert_equal(len(events), 1, "number of events")
106 vhost_if.assert_interface_state(1, 0, expect_event=True)
108 vhost_if.admin_down()
109 vhost_if.assert_interface_state(0, 0, expect_event=True)
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,
116 self.assert_equal(event.deleted, 1, "deleted flag")
118 # verify there are no more events
119 events = self.vapi.collect_events()
120 self.assert_equal(len(events), 0, "number of events")
122 if __name__ == '__main__':
123 unittest.main(testRunner=VppTestRunner)