6 from scapy.contrib.lacp import LACP, SlowProtocol, MarkerProtocol
7 from scapy.layers.l2 import Ether
9 from framework import VppTestCase, VppTestRunner
10 from vpp_memif import remove_all_memif_vpp_config, VppSocketFilename, VppMemif
11 from vpp_bond_interface import VppBondInterface
12 from vpp_papi import VppEnum, MACAddress
14 bond_mac = "02:02:02:02:02:02"
15 lacp_dst_mac = '01:80:c2:00:00:02'
16 LACP_COLLECTION_AND_DISTRIBUTION_STATE = 63
19 class TestMarker(VppTestCase):
20 """LACP Marker Protocol Test Case
28 cls.pkts_per_burst = 257 # Number of packets per burst
29 # create 3 pg interfaces
30 cls.create_pg_interfaces(range(1))
33 cls.pg_if_packet_sizes = [64, 512, 1518] # , 9018]
35 # setup all interfaces
36 for i in cls.pg_interfaces:
40 def tearDownClass(cls):
41 super().tearDownClass()
49 def show_commands_at_teardown(self):
50 self.logger.info(self.vapi.ppcli("show interface"))
52 def test_marker_request(self):
53 """ Marker Request test """
58 # memif1 -----|B| |B|---- memif11
65 socket1 = VppSocketFilename(
68 socket_filename="%s/memif.sock1" % self.tempdir)
69 socket1.add_vpp_config()
71 socket11 = VppSocketFilename(
74 socket_filename="%s/memif.sock1" % self.tempdir)
75 socket11.add_vpp_config()
79 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
80 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
82 memif1.add_vpp_config()
87 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
88 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
90 memif11.add_vpp_config()
93 bond0 = VppBondInterface(
95 mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP,
99 bond0.add_vpp_config()
102 bond1 = VppBondInterface(
104 mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP)
105 bond1.add_vpp_config()
108 bond0.add_member_vpp_bond_interface(sw_if_index=memif1.sw_if_index)
109 bond1.add_member_vpp_bond_interface(sw_if_index=memif11.sw_if_index)
111 # wait for memif protocol exchange and hardware carrier to come up
112 self.assertEqual(memif1.wait_for_link_up(10), True)
113 self.assertEqual(memif11.wait_for_link_up(10), True)
115 # verify memif1 in bond0
116 intfs = self.vapi.sw_member_interface_dump(
117 sw_if_index=bond0.sw_if_index)
119 self.assertEqual(intf.sw_if_index, memif1.sw_if_index)
121 # verify memif11 in bond1
122 intfs = self.vapi.sw_member_interface_dump(
123 sw_if_index=bond1.sw_if_index)
125 self.assertEqual(intf.sw_if_index, memif11.sw_if_index)
127 self.vapi.ppcli("trace add memif-input 100")
129 # create marker request
130 marker = (Ether(src=bond_mac, dst=lacp_dst_mac) /
132 MarkerProtocol(marker_type=1,
134 requester_system=bond_mac,
135 requester_transaction_id=1))
137 bond1.add_member_vpp_bond_interface(sw_if_index=self.pg0.sw_if_index)
138 self.pg0.add_stream(marker)
139 self.pg_enable_capture(self.pg_interfaces)
142 show_trace = self.vapi.ppcli("show trace max 100")
143 self.assertIn("Marker Information TLV:", show_trace)
145 bond0.remove_vpp_config()
146 bond1.remove_vpp_config()
149 class TestLACP(VppTestCase):
159 def tearDownClass(cls):
160 super().tearDownClass()
168 def show_commands_at_teardown(self):
169 self.logger.info(self.vapi.ppcli("show interface"))
171 def wait_for_lacp_connect(self, timeout, step=1):
173 intfs = self.vapi.sw_interface_lacp_dump()
176 if ((intf.actor_state !=
177 LACP_COLLECTION_AND_DISTRIBUTION_STATE) or
178 (intf.partner_state !=
179 LACP_COLLECTION_AND_DISTRIBUTION_STATE)):
188 def wait_for_member_detach(self, bond, timeout, count, step=1):
190 intfs = self.vapi.sw_bond_interface_dump(
191 sw_if_index=bond.sw_if_index)
193 if ((intf.members == count) and
194 (intf.active_members == count)):
202 def test_lacp_connect(self):
203 """ LACP protocol connect test """
208 # memif1 -----|B| |B|---- memif11
212 # memif2 -----|0| |1|---- memif12
215 socket1 = VppSocketFilename(
218 socket_filename="%s/memif.sock1" % self.tempdir)
219 socket1.add_vpp_config()
221 socket11 = VppSocketFilename(
224 socket_filename="%s/memif.sock1" % self.tempdir)
225 socket11.add_vpp_config()
227 socket2 = VppSocketFilename(
230 socket_filename="%s/memif.sock2" % self.tempdir)
231 socket2.add_vpp_config()
233 socket22 = VppSocketFilename(
236 socket_filename="%s/memif.sock2" % self.tempdir)
237 socket22.add_vpp_config()
241 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
242 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
244 memif1.add_vpp_config()
249 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
250 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
252 memif11.add_vpp_config()
257 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_MASTER,
258 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
260 memif2.add_vpp_config()
265 role=VppEnum.vl_api_memif_role_t.MEMIF_ROLE_API_SLAVE,
266 mode=VppEnum.vl_api_memif_mode_t.MEMIF_MODE_API_ETHERNET,
268 memif12.add_vpp_config()
271 self.logger.info(self.vapi.ppcli("debug lacp on"))
272 bond0 = VppBondInterface(
274 mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP,
276 mac_address=bond_mac)
278 bond0.add_vpp_config()
281 bond1 = VppBondInterface(
283 mode=VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP)
284 bond1.add_vpp_config()
287 # 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)
291 # 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)
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)
301 # verify memif1 and memif2 in bond0
302 intfs = self.vapi.sw_member_interface_dump(
303 sw_if_index=bond0.sw_if_index)
306 intf.sw_if_index, (memif1.sw_if_index, memif2.sw_if_index))
308 # verify memif11 and memif12 in bond1
309 intfs = self.vapi.sw_member_interface_dump(
310 sw_if_index=bond1.sw_if_index)
313 intf.sw_if_index, (memif11.sw_if_index, memif12.sw_if_index))
314 self.assertEqual(intf.is_long_timeout, 0)
315 self.assertEqual(intf.is_passive, 0)
317 # Let LACP create the bundle
318 self.wait_for_lacp_connect(30)
320 intfs = self.vapi.sw_interface_lacp_dump()
323 intf.actor_state, LACP_COLLECTION_AND_DISTRIBUTION_STATE)
325 intf.partner_state, LACP_COLLECTION_AND_DISTRIBUTION_STATE)
327 intfs = self.vapi.sw_bond_interface_dump(sw_if_index=0xFFFFFFFF)
329 self.assertEqual(intf.members, 2)
330 self.assertEqual(intf.active_members, 2)
332 intf.mode, VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP)
334 self.logger.info(self.vapi.ppcli("show lacp"))
335 self.logger.info(self.vapi.ppcli("show lacp details"))
337 # detach member memif1
338 bond0.detach_vpp_bond_interface(sw_if_index=memif1.sw_if_index)
340 self.wait_for_member_detach(bond0, timeout=10, count=1)
341 intfs = self.vapi.sw_bond_interface_dump(
342 sw_if_index=bond0.sw_if_index)
344 self.assertEqual(intf.members, 1)
345 self.assertEqual(intf.active_members, 1)
347 intf.mode, VppEnum.vl_api_bond_mode_t.BOND_API_MODE_LACP)
349 # detach member memif2
350 bond0.detach_vpp_bond_interface(sw_if_index=memif2.sw_if_index)
351 self.wait_for_member_detach(bond0, timeout=10, count=0)
353 intfs = self.vapi.sw_bond_interface_dump(
354 sw_if_index=bond0.sw_if_index)
356 self.assertEqual(intf.members, 0)
357 self.assertEqual(intf.active_members, 0)
359 bond0.remove_vpp_config()
360 bond1.remove_vpp_config()
363 if __name__ == '__main__':
364 unittest.main(testRunner=VppTestRunner)