blob: 15eb0701f9183b636234ab0f2510280988f09222 [file] [log] [blame]
Stevene8fa6202017-08-30 14:36:45 -07001#!/usr/bin/env python
2
3import unittest
4
5from framework import VppTestCase, VppTestRunner
6
7from vpp_vhost_interface import VppVhostInterface
8
9
10class TesVhostInterface(VppTestCase):
11 """Vhost User Test Case
12
13 """
14
Juraj Slobodab3f90502018-10-04 15:15:16 +020015 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
Stevene8fa6202017-08-30 14:36:45 -070022 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 Vinciguerra22ab6f72019-03-07 17:55:33 -080027 vhost_if1 = VppVhostInterface(self, sock_filename=b'/tmp/sock1')
Stevene8fa6202017-08-30 14:36:45 -070028 vhost_if1.add_vpp_config()
29 vhost_if1.admin_up()
30
31 # create interface 2 (VirtualEthernet0/0/1)
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -080032 vhost_if2 = VppVhostInterface(self, sock_filename=b'/tmp/sock2')
Stevene8fa6202017-08-30 14:36:45 -070033 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 Vinciguerra9a6dafd2019-03-06 15:11:28 -080038 self.assertIn('VirtualEthernet0/0/0', ifs)
39 self.assertIn('VirtualEthernet0/0/1', ifs)
Stevene8fa6202017-08-30 14:36:45 -070040
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 Vinciguerra9a6dafd2019-03-06 15:11:28 -080054 self.assertIn('VirtualEthernet0/0/0', ifs)
Stevene8fa6202017-08-30 14:36:45 -070055
56 # verify VirtualEthernet0/0/1 not in the show
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -080057 self.assertNotIn('VirtualEthernet0/0/1', ifs)
Stevene8fa6202017-08-30 14:36:45 -070058
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 Vinciguerra9a6dafd2019-03-06 15:11:28 -080074 self.assertNotIn('VirtualEthernet0/0/0', ifs)
Stevene8fa6202017-08-30 14:36:45 -070075
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 Slobodab3f90502018-10-04 15:15:16 +020080 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 Vinciguerra22ab6f72019-03-07 17:55:33 -080089 vhost_if = VppVhostInterface(self, sock_filename=b'/tmp/sock1')
Juraj Slobodab3f90502018-10-04 15:15:16 +020090
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
Stevene8fa6202017-08-30 14:36:45 -0700115if __name__ == '__main__':
116 unittest.main(testRunner=VppTestRunner)