MAP: Convert from DPO to input feature.
[vpp.git] / test / test_vhost.py
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
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
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)
27         vhost_if1 = VppVhostInterface(self, sock_filename='/tmp/sock1')
28         vhost_if1.add_vpp_config()
29         vhost_if1.admin_up()
30
31         # create interface 2 (VirtualEthernet0/0/1)
32         vhost_if2 = VppVhostInterface(self, sock_filename='/tmp/sock2')
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")
38         self.assertNotEqual(ifs.find('VirtualEthernet0/0/0'), -1)
39         self.assertNotEqual(ifs.find('VirtualEthernet0/0/1'), -1)
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
54         self.assertNotEqual(ifs.find('VirtualEthernet0/0/0'), -1)
55
56         # verify VirtualEthernet0/0/1 not in the show
57         self.assertEqual(ifs.find('VirtualEthernet0/0/1'), -1)
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")
74         self.assertEqual(ifs.find('VirtualEthernet0/0/0'), -1)
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
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
89         vhost_if = VppVhostInterface(self, sock_filename='/tmp/sock1')
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
115 if __name__ == '__main__':
116     unittest.main(testRunner=VppTestRunner)