blob: 016e8de4d617da70464cfbed697c1ea5cd575f14 [file] [log] [blame]
Steven Luonga4611b82020-05-15 12:21:50 -07001#!/usr/bin/env python3
2
3import time
4import unittest
5
6from scapy.contrib.lacp import LACP, SlowProtocol, MarkerProtocol
7from scapy.layers.l2 import Ether
8
9from framework import VppTestCase, VppTestRunner
10from vpp_memif import remove_all_memif_vpp_config, VppSocketFilename, VppMemif
11from vpp_bond_interface import VppBondInterface
12from vpp_papi import VppEnum, MACAddress
13
14bond_mac = "02:02:02:02:02:02"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020015lacp_dst_mac = "01:80:c2:00:00:02"
Steven Luonga4611b82020-05-15 12:21:50 -070016LACP_COLLECTION_AND_DISTRIBUTION_STATE = 63
17
18
19class TestMarker(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020020 """LACP Marker Protocol Test Case"""
Steven Luonga4611b82020-05-15 12:21:50 -070021
22 @classmethod
23 def setUpClass(cls):
24 super().setUpClass()
25 # Test variables
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020026 cls.pkts_per_burst = 257 # Number of packets per burst
Steven Luonga4611b82020-05-15 12:21:50 -070027 # create 3 pg interfaces
28 cls.create_pg_interfaces(range(1))
29
30 # packet sizes
31 cls.pg_if_packet_sizes = [64, 512, 1518] # , 9018]
32
33 # setup all interfaces
34 for i in cls.pg_interfaces:
35 i.admin_up()
36
37 @classmethod
38 def tearDownClass(cls):
39 super().tearDownClass()
40
41 def setUp(self):
42 super().setUp()
43
44 def tearDown(self):
45 super().tearDown()
46
47 def show_commands_at_teardown(self):
48 self.logger.info(self.vapi.ppcli("show interface"))
49
50 def test_marker_request(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020051 """Marker Request test"""
Steven Luonga4611b82020-05-15 12:21:50 -070052
53 # topology
54 #
55 # +-+ +-+
56 # memif1 -----|B| |B|---- memif11
57 # |o| |o|
58 # |n|------|n|
59 # |d| |d|
60 # pg0 -----|0| |1|
61 # +-+ +-+
62
63 socket1 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020064 self, socket_id=1, socket_filename="%s/memif.sock1" % self.tempdir
65 )
Steven Luonga4611b82020-05-15 12:21:50 -070066 socket1.add_vpp_config()
67
68 socket11 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020069 self, socket_id=2, socket_filename="%s/memif.sock1" % self.tempdir
70 )
Steven Luonga4611b82020-05-15 12:21:50 -070071 socket11.add_vpp_config()
72
73 memif1 = VppMemif(
74 self,
75 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
76 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020077 socket_id=1,
78 )
Steven Luonga4611b82020-05-15 12:21:50 -070079 memif1.add_vpp_config()
80 memif1.admin_up()
81
82 memif11 = VppMemif(
83 self,
84 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
85 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020086 socket_id=2,
87 )
Steven Luonga4611b82020-05-15 12:21:50 -070088 memif11.add_vpp_config()
89 memif11.admin_up()
90
91 bond0 = VppBondInterface(
92 self,
93 mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP,
94 use_custom_mac=1,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020095 mac_address=bond_mac,
96 )
Steven Luonga4611b82020-05-15 12:21:50 -070097
98 bond0.add_vpp_config()
99 bond0.admin_up()
100
101 bond1 = VppBondInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200102 self, mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP
103 )
Steven Luonga4611b82020-05-15 12:21:50 -0700104 bond1.add_vpp_config()
105 bond1.admin_up()
106
Steven Luong4c4223e2020-07-15 08:44:54 -0700107 bond0.add_member_vpp_bond_interface(sw_if_index=memif1.sw_if_index)
108 bond1.add_member_vpp_bond_interface(sw_if_index=memif11.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700109
110 # wait for memif protocol exchange and hardware carrier to come up
111 self.assertEqual(memif1.wait_for_link_up(10), True)
112 self.assertEqual(memif11.wait_for_link_up(10), True)
113
114 # verify memif1 in bond0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200115 intfs = self.vapi.sw_member_interface_dump(sw_if_index=bond0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700116 for intf in intfs:
117 self.assertEqual(intf.sw_if_index, memif1.sw_if_index)
118
119 # verify memif11 in bond1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200120 intfs = self.vapi.sw_member_interface_dump(sw_if_index=bond1.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700121 for intf in intfs:
122 self.assertEqual(intf.sw_if_index, memif11.sw_if_index)
123
124 self.vapi.ppcli("trace add memif-input 100")
125
126 # create marker request
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200127 marker = (
128 Ether(src=bond_mac, dst=lacp_dst_mac)
129 / SlowProtocol()
130 / MarkerProtocol(
131 marker_type=1,
132 requester_port=1,
133 requester_system=bond_mac,
134 requester_transaction_id=1,
135 )
136 )
Steven Luonga4611b82020-05-15 12:21:50 -0700137
Steven Luong4c4223e2020-07-15 08:44:54 -0700138 bond1.add_member_vpp_bond_interface(sw_if_index=self.pg0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700139 self.pg0.add_stream(marker)
140 self.pg_enable_capture(self.pg_interfaces)
141 self.pg_start()
142
143 show_trace = self.vapi.ppcli("show trace max 100")
144 self.assertIn("Marker Information TLV:", show_trace)
145
146 bond0.remove_vpp_config()
147 bond1.remove_vpp_config()
148
149
150class TestLACP(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200151 """LACP Test Case"""
Steven Luonga4611b82020-05-15 12:21:50 -0700152
153 @classmethod
154 def setUpClass(cls):
155 super().setUpClass()
156
157 @classmethod
158 def tearDownClass(cls):
159 super().tearDownClass()
160
161 def setUp(self):
162 super().setUp()
163
164 def tearDown(self):
165 super().tearDown()
166
167 def show_commands_at_teardown(self):
168 self.logger.info(self.vapi.ppcli("show interface"))
169
170 def wait_for_lacp_connect(self, timeout, step=1):
171 while 1:
172 intfs = self.vapi.sw_interface_lacp_dump()
173 all_good = 1
174 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200175 if (intf.actor_state != LACP_COLLECTION_AND_DISTRIBUTION_STATE) or (
176 intf.partner_state != LACP_COLLECTION_AND_DISTRIBUTION_STATE
177 ):
Steven Luonga4611b82020-05-15 12:21:50 -0700178 all_good = 0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200179 if all_good == 1:
Steven Luonga4611b82020-05-15 12:21:50 -0700180 return 1
181 self.sleep(step)
182 timeout -= step
183 if timeout <= 0:
184 return 0
185
Steven Luong4c4223e2020-07-15 08:44:54 -0700186 def wait_for_member_detach(self, bond, timeout, count, step=1):
Steven Luonga4611b82020-05-15 12:21:50 -0700187 while 1:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200188 intfs = self.vapi.sw_bond_interface_dump(sw_if_index=bond.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700189 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200190 if (intf.members == count) and (intf.active_members == count):
Steven Luong4c4223e2020-07-15 08:44:54 -0700191 return 1
192 else:
193 self.sleep(1)
194 timeout -= step
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200195 if timeouut <= 0:
Steven Luong4c4223e2020-07-15 08:44:54 -0700196 return 0
Steven Luonga4611b82020-05-15 12:21:50 -0700197
198 def test_lacp_connect(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200199 """LACP protocol connect test"""
Steven Luonga4611b82020-05-15 12:21:50 -0700200
201 # topology
202 #
203 # +-+ +-+
204 # memif1 -----|B| |B|---- memif11
205 # |o| |o|
206 # |n|------|n|
207 # |d| |d|
208 # memif2 -----|0| |1|---- memif12
209 # +-+ +-+
210
211 socket1 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200212 self, socket_id=1, socket_filename="%s/memif.sock1" % self.tempdir
213 )
Steven Luonga4611b82020-05-15 12:21:50 -0700214 socket1.add_vpp_config()
215
216 socket11 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200217 self, socket_id=2, socket_filename="%s/memif.sock1" % self.tempdir
218 )
Steven Luonga4611b82020-05-15 12:21:50 -0700219 socket11.add_vpp_config()
220
221 socket2 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200222 self, socket_id=3, socket_filename="%s/memif.sock2" % self.tempdir
223 )
Steven Luonga4611b82020-05-15 12:21:50 -0700224 socket2.add_vpp_config()
225
226 socket22 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200227 self, socket_id=4, socket_filename="%s/memif.sock2" % self.tempdir
228 )
Steven Luonga4611b82020-05-15 12:21:50 -0700229 socket22.add_vpp_config()
230
231 memif1 = VppMemif(
232 self,
233 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
234 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200235 socket_id=1,
236 )
Steven Luonga4611b82020-05-15 12:21:50 -0700237 memif1.add_vpp_config()
238 memif1.admin_up()
239
240 memif11 = VppMemif(
241 self,
242 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
243 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200244 socket_id=2,
245 )
Steven Luonga4611b82020-05-15 12:21:50 -0700246 memif11.add_vpp_config()
247 memif11.admin_up()
248
249 memif2 = VppMemif(
250 self,
251 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
252 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200253 socket_id=3,
254 )
Steven Luonga4611b82020-05-15 12:21:50 -0700255 memif2.add_vpp_config()
256 memif2.admin_up()
257
258 memif12 = VppMemif(
259 self,
260 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
261 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200262 socket_id=4,
263 )
Steven Luonga4611b82020-05-15 12:21:50 -0700264 memif12.add_vpp_config()
265 memif12.admin_up()
266
267 self.logger.info(self.vapi.ppcli("debug lacp on"))
268 bond0 = VppBondInterface(
269 self,
270 mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP,
271 use_custom_mac=1,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200272 mac_address=bond_mac,
273 )
Steven Luonga4611b82020-05-15 12:21:50 -0700274
275 bond0.add_vpp_config()
276 bond0.admin_up()
277
278 bond1 = VppBondInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200279 self, mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP
280 )
Steven Luonga4611b82020-05-15 12:21:50 -0700281 bond1.add_vpp_config()
282 bond1.admin_up()
283
Steven Luong4c4223e2020-07-15 08:44:54 -0700284 # add member memif1 and memif2 to bond0
285 bond0.add_member_vpp_bond_interface(sw_if_index=memif1.sw_if_index)
286 bond0.add_member_vpp_bond_interface(sw_if_index=memif2.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700287
Steven Luong4c4223e2020-07-15 08:44:54 -0700288 # add member memif11 and memif12 to bond1
289 bond1.add_member_vpp_bond_interface(sw_if_index=memif11.sw_if_index)
290 bond1.add_member_vpp_bond_interface(sw_if_index=memif12.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700291
292 # wait for memif protocol exchange and hardware carrier to come up
293 self.assertEqual(memif1.wait_for_link_up(10), True)
294 self.assertEqual(memif2.wait_for_link_up(10), True)
295 self.assertEqual(memif11.wait_for_link_up(10), True)
296 self.assertEqual(memif12.wait_for_link_up(10), True)
297
298 # verify memif1 and memif2 in bond0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200299 intfs = self.vapi.sw_member_interface_dump(sw_if_index=bond0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700300 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200301 self.assertIn(intf.sw_if_index, (memif1.sw_if_index, memif2.sw_if_index))
Steven Luonga4611b82020-05-15 12:21:50 -0700302
303 # verify memif11 and memif12 in bond1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200304 intfs = self.vapi.sw_member_interface_dump(sw_if_index=bond1.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700305 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200306 self.assertIn(intf.sw_if_index, (memif11.sw_if_index, memif12.sw_if_index))
Steven Luonga4611b82020-05-15 12:21:50 -0700307 self.assertEqual(intf.is_long_timeout, 0)
308 self.assertEqual(intf.is_passive, 0)
309
310 # Let LACP create the bundle
311 self.wait_for_lacp_connect(30)
312
313 intfs = self.vapi.sw_interface_lacp_dump()
314 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200315 self.assertEqual(intf.actor_state, LACP_COLLECTION_AND_DISTRIBUTION_STATE)
316 self.assertEqual(intf.partner_state, LACP_COLLECTION_AND_DISTRIBUTION_STATE)
Steven Luonga4611b82020-05-15 12:21:50 -0700317
Steven Luong4c4223e2020-07-15 08:44:54 -0700318 intfs = self.vapi.sw_bond_interface_dump(sw_if_index=0xFFFFFFFF)
Steven Luonga4611b82020-05-15 12:21:50 -0700319 for intf in intfs:
Steven Luong4c4223e2020-07-15 08:44:54 -0700320 self.assertEqual(intf.members, 2)
321 self.assertEqual(intf.active_members, 2)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200322 self.assertEqual(intf.mode, VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP)
Steven Luonga4611b82020-05-15 12:21:50 -0700323
324 self.logger.info(self.vapi.ppcli("show lacp"))
325 self.logger.info(self.vapi.ppcli("show lacp details"))
326
Steven Luong4c4223e2020-07-15 08:44:54 -0700327 # detach member memif1
Steven Luonga4611b82020-05-15 12:21:50 -0700328 bond0.detach_vpp_bond_interface(sw_if_index=memif1.sw_if_index)
329
Steven Luong4c4223e2020-07-15 08:44:54 -0700330 self.wait_for_member_detach(bond0, timeout=10, count=1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200331 intfs = self.vapi.sw_bond_interface_dump(sw_if_index=bond0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700332 for intf in intfs:
Steven Luong4c4223e2020-07-15 08:44:54 -0700333 self.assertEqual(intf.members, 1)
334 self.assertEqual(intf.active_members, 1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200335 self.assertEqual(intf.mode, VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP)
Steven Luonga4611b82020-05-15 12:21:50 -0700336
Steven Luong4c4223e2020-07-15 08:44:54 -0700337 # detach member memif2
Steven Luonga4611b82020-05-15 12:21:50 -0700338 bond0.detach_vpp_bond_interface(sw_if_index=memif2.sw_if_index)
Steven Luong4c4223e2020-07-15 08:44:54 -0700339 self.wait_for_member_detach(bond0, timeout=10, count=0)
Steven Luonga4611b82020-05-15 12:21:50 -0700340
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200341 intfs = self.vapi.sw_bond_interface_dump(sw_if_index=bond0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700342 for intf in intfs:
Steven Luong4c4223e2020-07-15 08:44:54 -0700343 self.assertEqual(intf.members, 0)
344 self.assertEqual(intf.active_members, 0)
Steven Luonga4611b82020-05-15 12:21:50 -0700345
346 bond0.remove_vpp_config()
347 bond1.remove_vpp_config()
348
349
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200350if __name__ == "__main__":
Steven Luonga4611b82020-05-15 12:21:50 -0700351 unittest.main(testRunner=VppTestRunner)