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, self).tearDown()
18 if_dump = self.vapi.sw_interface_vhost_user_dump()
20 self.vapi.delete_vhost_user_if(ifc.sw_if_index)
23 """ Vhost User add/delete interface test """
24 self.logger.info("Vhost User add interfaces")
26 # create interface 1 (VirtualEthernet0/0/0)
27 vhost_if1 = VppVhostInterface(self, sock_filename='/tmp/sock1')
28 vhost_if1.add_vpp_config()
31 # create interface 2 (VirtualEthernet0/0/1)
32 vhost_if2 = VppVhostInterface(self, sock_filename='/tmp/sock2')
33 vhost_if2.add_vpp_config()
36 # verify both interfaces in the show
37 ifs = self.vapi.cli("show interface")
38 self.assertNotEqual(ifs.find('VirtualEthernet0/0/0'), -1)
39 self.assertNotEqual(ifs.find('VirtualEthernet0/0/1'), -1)
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))
46 # delete VirtualEthernet0/0/1
47 self.logger.info("Deleting VirtualEthernet0/0/1")
48 vhost_if2.remove_vpp_config()
50 self.logger.info("Verifying VirtualEthernet0/0/1 is deleted")
52 ifs = self.vapi.cli("show interface")
53 # verify VirtualEthernet0/0/0 still in the show
54 self.assertNotEqual(ifs.find('VirtualEthernet0/0/0'), -1)
56 # verify VirtualEthernet0/0/1 not in the show
57 self.assertEqual(ifs.find('VirtualEthernet0/0/1'), -1)
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))
63 # verify VirtualEthernet0/0/0 is still in the dump
64 self.assertTrue(vhost_if1.is_interface_config_in_dump(if_dump))
66 # delete VirtualEthernet0/0/0
67 self.logger.info("Deleting VirtualEthernet0/0/0")
68 vhost_if1.remove_vpp_config()
70 self.logger.info("Verifying VirtualEthernet0/0/0 is deleted")
72 # verify VirtualEthernet0/0/0 not in the show
73 ifs = self.vapi.cli("show interface")
74 self.assertEqual(ifs.find('VirtualEthernet0/0/0'), -1)
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))
80 def test_vhost_interface_state(self):
81 """ Vhost User interface states and events test """
83 self.vapi.want_interface_events()
85 # clear outstanding events
86 # (like delete interface events from other tests)
87 self.vapi.collect_events()
89 vhost_if = VppVhostInterface(self, sock_filename='/tmp/sock1')
91 # create vhost interface
92 vhost_if.add_vpp_config()
94 events = self.vapi.collect_events()
95 # creating interface doesn't currently create events
96 self.assert_equal(len(events), 0, "number of events")
99 vhost_if.assert_interface_state(1, 0, expect_event=True)
101 vhost_if.admin_down()
102 vhost_if.assert_interface_state(0, 0, expect_event=True)
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,
109 self.assert_equal(event.deleted, 1, "deleted flag")
111 # verify there are no more events
112 events = self.vapi.collect_events()
113 self.assert_equal(len(events), 0, "number of events")
115 if __name__ == '__main__':
116 unittest.main(testRunner=VppTestRunner)