blob: b9cc1102d5d350b1f661ff80a6f9fe12d8d23773 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Stevene8fa6202017-08-30 14:36:45 -07002
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 """
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070014 @classmethod
15 def setUpClass(cls):
16 super(TesVhostInterface, cls).setUpClass()
17
18 @classmethod
19 def tearDownClass(cls):
20 super(TesVhostInterface, cls).tearDownClass()
Stevene8fa6202017-08-30 14:36:45 -070021
Juraj Slobodab3f90502018-10-04 15:15:16 +020022 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
Stevene8fa6202017-08-30 14:36:45 -070029 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)
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -080034 vhost_if1 = VppVhostInterface(self, sock_filename=b'/tmp/sock1')
Stevene8fa6202017-08-30 14:36:45 -070035 vhost_if1.add_vpp_config()
36 vhost_if1.admin_up()
37
38 # create interface 2 (VirtualEthernet0/0/1)
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -080039 vhost_if2 = VppVhostInterface(self, sock_filename=b'/tmp/sock2')
Stevene8fa6202017-08-30 14:36:45 -070040 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 Vinciguerra9a6dafd2019-03-06 15:11:28 -080045 self.assertIn('VirtualEthernet0/0/0', ifs)
46 self.assertIn('VirtualEthernet0/0/1', ifs)
Stevene8fa6202017-08-30 14:36:45 -070047
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 Vinciguerra9a6dafd2019-03-06 15:11:28 -080061 self.assertIn('VirtualEthernet0/0/0', ifs)
Stevene8fa6202017-08-30 14:36:45 -070062
63 # verify VirtualEthernet0/0/1 not in the show
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -080064 self.assertNotIn('VirtualEthernet0/0/1', ifs)
Stevene8fa6202017-08-30 14:36:45 -070065
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 Vinciguerra9a6dafd2019-03-06 15:11:28 -080081 self.assertNotIn('VirtualEthernet0/0/0', ifs)
Stevene8fa6202017-08-30 14:36:45 -070082
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 Slobodab3f90502018-10-04 15:15:16 +020087 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
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -080096 vhost_if = VppVhostInterface(self, sock_filename=b'/tmp/sock1')
Juraj Slobodab3f90502018-10-04 15:15:16 +020097
98 # create vhost interface
99 vhost_if.add_vpp_config()
100 self.sleep(0.1)
101 events = self.vapi.collect_events()
Ole Troan2e1c8962019-04-10 09:44:23 +0200102 # creating interface does now create events
103 self.assert_equal(len(events), 1, "number of events")
Juraj Slobodab3f90502018-10-04 15:15:16 +0200104
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
Stevene8fa6202017-08-30 14:36:45 -0700122if __name__ == '__main__':
123 unittest.main(testRunner=VppTestRunner)