blob: d8739775f27e609a83b7f3a9197d89804bf87151 [file] [log] [blame]
Steven Luonga4611b82020-05-15 12:21:50 -07001#!/usr/bin/env python3
2
Steven Luonga4611b82020-05-15 12:21:50 -07003import unittest
4
5from scapy.contrib.lacp import LACP, SlowProtocol, MarkerProtocol
6from scapy.layers.l2 import Ether
7
Dave Wallace8800f732023-08-31 00:47:44 -04008from framework import VppTestCase
9from asfframework import VppTestRunner
10from vpp_memif import VppSocketFilename, VppMemif
Steven Luonga4611b82020-05-15 12:21:50 -070011from vpp_bond_interface import VppBondInterface
Dave Wallace8800f732023-08-31 00:47:44 -040012from vpp_papi import VppEnum
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000013from config import config
Steven Luonga4611b82020-05-15 12:21:50 -070014
15bond_mac = "02:02:02:02:02:02"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020016lacp_dst_mac = "01:80:c2:00:00:02"
Steven Luonga4611b82020-05-15 12:21:50 -070017LACP_COLLECTION_AND_DISTRIBUTION_STATE = 63
18
19
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000020@unittest.skipIf("lacp" in config.excluded_plugins, "Exclude LACP plugin tests")
Steven Luonga4611b82020-05-15 12:21:50 -070021class TestMarker(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020022 """LACP Marker Protocol Test Case"""
Steven Luonga4611b82020-05-15 12:21:50 -070023
24 @classmethod
25 def setUpClass(cls):
26 super().setUpClass()
27 # Test variables
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020028 cls.pkts_per_burst = 257 # Number of packets per burst
Steven Luonga4611b82020-05-15 12:21:50 -070029 # create 3 pg interfaces
30 cls.create_pg_interfaces(range(1))
31
32 # packet sizes
33 cls.pg_if_packet_sizes = [64, 512, 1518] # , 9018]
34
35 # setup all interfaces
36 for i in cls.pg_interfaces:
37 i.admin_up()
38
39 @classmethod
40 def tearDownClass(cls):
41 super().tearDownClass()
42
43 def setUp(self):
44 super().setUp()
45
46 def tearDown(self):
47 super().tearDown()
48
49 def show_commands_at_teardown(self):
50 self.logger.info(self.vapi.ppcli("show interface"))
51
52 def test_marker_request(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020053 """Marker Request test"""
Steven Luonga4611b82020-05-15 12:21:50 -070054
55 # topology
56 #
57 # +-+ +-+
58 # memif1 -----|B| |B|---- memif11
59 # |o| |o|
60 # |n|------|n|
61 # |d| |d|
62 # pg0 -----|0| |1|
63 # +-+ +-+
64
65 socket1 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020066 self, socket_id=1, socket_filename="%s/memif.sock1" % self.tempdir
67 )
Steven Luonga4611b82020-05-15 12:21:50 -070068 socket1.add_vpp_config()
69
70 socket11 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020071 self, socket_id=2, socket_filename="%s/memif.sock1" % self.tempdir
72 )
Steven Luonga4611b82020-05-15 12:21:50 -070073 socket11.add_vpp_config()
74
75 memif1 = VppMemif(
76 self,
77 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
78 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020079 socket_id=1,
80 )
Steven Luonga4611b82020-05-15 12:21:50 -070081 memif1.add_vpp_config()
82 memif1.admin_up()
83
84 memif11 = VppMemif(
85 self,
86 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
87 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020088 socket_id=2,
89 )
Steven Luonga4611b82020-05-15 12:21:50 -070090 memif11.add_vpp_config()
91 memif11.admin_up()
92
93 bond0 = VppBondInterface(
94 self,
95 mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP,
96 use_custom_mac=1,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020097 mac_address=bond_mac,
98 )
Steven Luonga4611b82020-05-15 12:21:50 -070099
100 bond0.add_vpp_config()
101 bond0.admin_up()
102
103 bond1 = VppBondInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200104 self, mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP
105 )
Steven Luonga4611b82020-05-15 12:21:50 -0700106 bond1.add_vpp_config()
107 bond1.admin_up()
108
Steven Luong4c4223e2020-07-15 08:44:54 -0700109 bond0.add_member_vpp_bond_interface(sw_if_index=memif1.sw_if_index)
110 bond1.add_member_vpp_bond_interface(sw_if_index=memif11.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700111
112 # wait for memif protocol exchange and hardware carrier to come up
113 self.assertEqual(memif1.wait_for_link_up(10), True)
114 self.assertEqual(memif11.wait_for_link_up(10), True)
115
116 # verify memif1 in bond0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200117 intfs = self.vapi.sw_member_interface_dump(sw_if_index=bond0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700118 for intf in intfs:
119 self.assertEqual(intf.sw_if_index, memif1.sw_if_index)
120
121 # verify memif11 in bond1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200122 intfs = self.vapi.sw_member_interface_dump(sw_if_index=bond1.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700123 for intf in intfs:
124 self.assertEqual(intf.sw_if_index, memif11.sw_if_index)
125
126 self.vapi.ppcli("trace add memif-input 100")
127
128 # create marker request
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200129 marker = (
130 Ether(src=bond_mac, dst=lacp_dst_mac)
131 / SlowProtocol()
132 / MarkerProtocol(
133 marker_type=1,
134 requester_port=1,
135 requester_system=bond_mac,
136 requester_transaction_id=1,
137 )
138 )
Steven Luonga4611b82020-05-15 12:21:50 -0700139
Steven Luong4c4223e2020-07-15 08:44:54 -0700140 bond1.add_member_vpp_bond_interface(sw_if_index=self.pg0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700141 self.pg0.add_stream(marker)
142 self.pg_enable_capture(self.pg_interfaces)
143 self.pg_start()
144
145 show_trace = self.vapi.ppcli("show trace max 100")
146 self.assertIn("Marker Information TLV:", show_trace)
147
148 bond0.remove_vpp_config()
149 bond1.remove_vpp_config()
150
151
Dmitry Valter34fa0ce2024-03-11 10:38:46 +0000152@unittest.skipIf("lacp" in config.excluded_plugins, "Exclude LACP plugin tests")
Steven Luonga4611b82020-05-15 12:21:50 -0700153class TestLACP(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200154 """LACP Test Case"""
Steven Luonga4611b82020-05-15 12:21:50 -0700155
156 @classmethod
157 def setUpClass(cls):
158 super().setUpClass()
159
160 @classmethod
161 def tearDownClass(cls):
162 super().tearDownClass()
163
164 def setUp(self):
165 super().setUp()
166
167 def tearDown(self):
168 super().tearDown()
169
170 def show_commands_at_teardown(self):
171 self.logger.info(self.vapi.ppcli("show interface"))
172
173 def wait_for_lacp_connect(self, timeout, step=1):
174 while 1:
175 intfs = self.vapi.sw_interface_lacp_dump()
176 all_good = 1
177 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200178 if (intf.actor_state != LACP_COLLECTION_AND_DISTRIBUTION_STATE) or (
179 intf.partner_state != LACP_COLLECTION_AND_DISTRIBUTION_STATE
180 ):
Steven Luonga4611b82020-05-15 12:21:50 -0700181 all_good = 0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200182 if all_good == 1:
Steven Luonga4611b82020-05-15 12:21:50 -0700183 return 1
184 self.sleep(step)
185 timeout -= step
186 if timeout <= 0:
187 return 0
188
Steven Luong4c4223e2020-07-15 08:44:54 -0700189 def wait_for_member_detach(self, bond, timeout, count, step=1):
Steven Luonga4611b82020-05-15 12:21:50 -0700190 while 1:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200191 intfs = self.vapi.sw_bond_interface_dump(sw_if_index=bond.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700192 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200193 if (intf.members == count) and (intf.active_members == count):
Steven Luong4c4223e2020-07-15 08:44:54 -0700194 return 1
195 else:
196 self.sleep(1)
197 timeout -= step
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200198 if timeouut <= 0:
Steven Luong4c4223e2020-07-15 08:44:54 -0700199 return 0
Steven Luonga4611b82020-05-15 12:21:50 -0700200
201 def test_lacp_connect(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200202 """LACP protocol connect test"""
Steven Luonga4611b82020-05-15 12:21:50 -0700203
204 # topology
205 #
206 # +-+ +-+
207 # memif1 -----|B| |B|---- memif11
208 # |o| |o|
209 # |n|------|n|
210 # |d| |d|
211 # memif2 -----|0| |1|---- memif12
212 # +-+ +-+
213
214 socket1 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200215 self, socket_id=1, socket_filename="%s/memif.sock1" % self.tempdir
216 )
Steven Luonga4611b82020-05-15 12:21:50 -0700217 socket1.add_vpp_config()
218
219 socket11 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200220 self, socket_id=2, socket_filename="%s/memif.sock1" % self.tempdir
221 )
Steven Luonga4611b82020-05-15 12:21:50 -0700222 socket11.add_vpp_config()
223
224 socket2 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200225 self, socket_id=3, socket_filename="%s/memif.sock2" % self.tempdir
226 )
Steven Luonga4611b82020-05-15 12:21:50 -0700227 socket2.add_vpp_config()
228
229 socket22 = VppSocketFilename(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200230 self, socket_id=4, socket_filename="%s/memif.sock2" % self.tempdir
231 )
Steven Luonga4611b82020-05-15 12:21:50 -0700232 socket22.add_vpp_config()
233
234 memif1 = VppMemif(
235 self,
236 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
237 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200238 socket_id=1,
239 )
Steven Luonga4611b82020-05-15 12:21:50 -0700240 memif1.add_vpp_config()
241 memif1.admin_up()
242
243 memif11 = VppMemif(
244 self,
245 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
246 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200247 socket_id=2,
248 )
Steven Luonga4611b82020-05-15 12:21:50 -0700249 memif11.add_vpp_config()
250 memif11.admin_up()
251
252 memif2 = VppMemif(
253 self,
254 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
255 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200256 socket_id=3,
257 )
Steven Luonga4611b82020-05-15 12:21:50 -0700258 memif2.add_vpp_config()
259 memif2.admin_up()
260
261 memif12 = VppMemif(
262 self,
263 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
264 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200265 socket_id=4,
266 )
Steven Luonga4611b82020-05-15 12:21:50 -0700267 memif12.add_vpp_config()
268 memif12.admin_up()
269
270 self.logger.info(self.vapi.ppcli("debug lacp on"))
271 bond0 = VppBondInterface(
272 self,
273 mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP,
274 use_custom_mac=1,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200275 mac_address=bond_mac,
276 )
Steven Luonga4611b82020-05-15 12:21:50 -0700277
278 bond0.add_vpp_config()
279 bond0.admin_up()
280
281 bond1 = VppBondInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200282 self, mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP
283 )
Steven Luonga4611b82020-05-15 12:21:50 -0700284 bond1.add_vpp_config()
285 bond1.admin_up()
286
Steven Luong4c4223e2020-07-15 08:44:54 -0700287 # add member memif1 and memif2 to bond0
288 bond0.add_member_vpp_bond_interface(sw_if_index=memif1.sw_if_index)
289 bond0.add_member_vpp_bond_interface(sw_if_index=memif2.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700290
Steven Luong4c4223e2020-07-15 08:44:54 -0700291 # add member memif11 and memif12 to bond1
292 bond1.add_member_vpp_bond_interface(sw_if_index=memif11.sw_if_index)
293 bond1.add_member_vpp_bond_interface(sw_if_index=memif12.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700294
295 # wait for memif protocol exchange and hardware carrier to come up
296 self.assertEqual(memif1.wait_for_link_up(10), True)
297 self.assertEqual(memif2.wait_for_link_up(10), True)
298 self.assertEqual(memif11.wait_for_link_up(10), True)
299 self.assertEqual(memif12.wait_for_link_up(10), True)
300
301 # verify memif1 and memif2 in bond0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200302 intfs = self.vapi.sw_member_interface_dump(sw_if_index=bond0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700303 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200304 self.assertIn(intf.sw_if_index, (memif1.sw_if_index, memif2.sw_if_index))
Steven Luonga4611b82020-05-15 12:21:50 -0700305
306 # verify memif11 and memif12 in bond1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200307 intfs = self.vapi.sw_member_interface_dump(sw_if_index=bond1.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700308 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200309 self.assertIn(intf.sw_if_index, (memif11.sw_if_index, memif12.sw_if_index))
Steven Luonga4611b82020-05-15 12:21:50 -0700310 self.assertEqual(intf.is_long_timeout, 0)
311 self.assertEqual(intf.is_passive, 0)
312
313 # Let LACP create the bundle
314 self.wait_for_lacp_connect(30)
315
316 intfs = self.vapi.sw_interface_lacp_dump()
317 for intf in intfs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200318 self.assertEqual(intf.actor_state, LACP_COLLECTION_AND_DISTRIBUTION_STATE)
319 self.assertEqual(intf.partner_state, LACP_COLLECTION_AND_DISTRIBUTION_STATE)
Steven Luonga4611b82020-05-15 12:21:50 -0700320
Steven Luong4c4223e2020-07-15 08:44:54 -0700321 intfs = self.vapi.sw_bond_interface_dump(sw_if_index=0xFFFFFFFF)
Steven Luonga4611b82020-05-15 12:21:50 -0700322 for intf in intfs:
Steven Luong4c4223e2020-07-15 08:44:54 -0700323 self.assertEqual(intf.members, 2)
324 self.assertEqual(intf.active_members, 2)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200325 self.assertEqual(intf.mode, VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP)
Steven Luonga4611b82020-05-15 12:21:50 -0700326
327 self.logger.info(self.vapi.ppcli("show lacp"))
328 self.logger.info(self.vapi.ppcli("show lacp details"))
329
Steven Luong4c4223e2020-07-15 08:44:54 -0700330 # detach member memif1
Steven Luonga4611b82020-05-15 12:21:50 -0700331 bond0.detach_vpp_bond_interface(sw_if_index=memif1.sw_if_index)
332
Steven Luong4c4223e2020-07-15 08:44:54 -0700333 self.wait_for_member_detach(bond0, timeout=10, count=1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200334 intfs = self.vapi.sw_bond_interface_dump(sw_if_index=bond0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700335 for intf in intfs:
Steven Luong4c4223e2020-07-15 08:44:54 -0700336 self.assertEqual(intf.members, 1)
337 self.assertEqual(intf.active_members, 1)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200338 self.assertEqual(intf.mode, VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP)
Steven Luonga4611b82020-05-15 12:21:50 -0700339
Steven Luong4c4223e2020-07-15 08:44:54 -0700340 # detach member memif2
Steven Luonga4611b82020-05-15 12:21:50 -0700341 bond0.detach_vpp_bond_interface(sw_if_index=memif2.sw_if_index)
Steven Luong4c4223e2020-07-15 08:44:54 -0700342 self.wait_for_member_detach(bond0, timeout=10, count=0)
Steven Luonga4611b82020-05-15 12:21:50 -0700343
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200344 intfs = self.vapi.sw_bond_interface_dump(sw_if_index=bond0.sw_if_index)
Steven Luonga4611b82020-05-15 12:21:50 -0700345 for intf in intfs:
Steven Luong4c4223e2020-07-15 08:44:54 -0700346 self.assertEqual(intf.members, 0)
347 self.assertEqual(intf.active_members, 0)
Steven Luonga4611b82020-05-15 12:21:50 -0700348
349 bond0.remove_vpp_config()
350 bond1.remove_vpp_config()
351
352
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200353if __name__ == "__main__":
Steven Luonga4611b82020-05-15 12:21:50 -0700354 unittest.main(testRunner=VppTestRunner)