1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <rte_cycles.h>
13 #include <sys/queue.h>
15 #include <rte_byteorder.h>
16 #include <rte_common.h>
17 #include <rte_debug.h>
18 #include <rte_ethdev.h>
20 #include <rte_lcore.h>
21 #include <rte_memory.h>
23 #include <rte_string_fns.h>
25 #include <rte_eth_ring.h>
26 #include <rte_errno.h>
27 #include <rte_eth_bond.h>
28 #include <rte_eth_bond_8023ad.h>
30 #include "packet_burst_generator.h"
34 #define SLAVE_COUNT (4)
36 #define RX_RING_SIZE 1024
37 #define TX_RING_SIZE 1024
39 #define MBUF_CACHE_SIZE (250)
40 #define BURST_SIZE (32)
42 #define TEST_RX_DESC_MAX (2048)
43 #define TEST_TX_DESC_MAX (2048)
44 #define MAX_PKT_BURST (32)
45 #define DEF_PKT_BURST (16)
47 #define BONDED_DEV_NAME ("net_bonding_m4_bond_dev")
49 #define SLAVE_DEV_NAME_FMT ("net_virt_%d")
50 #define SLAVE_RX_QUEUE_FMT ("net_virt_%d_rx")
51 #define SLAVE_TX_QUEUE_FMT ("net_virt_%d_tx")
53 #define INVALID_SOCKET_ID (-1)
54 #define INVALID_PORT_ID (0xFF)
55 #define INVALID_BONDING_MODE (-1)
57 static const struct rte_ether_addr slave_mac_default = {
58 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 }
61 static const struct rte_ether_addr parnter_mac_default = {
62 { 0x22, 0xBB, 0xFF, 0xBB, 0x00, 0x00 }
65 static const struct rte_ether_addr parnter_system = {
66 { 0x33, 0xFF, 0xBB, 0xFF, 0x00, 0x00 }
69 static const struct rte_ether_addr slow_protocol_mac_addr = {
70 { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02 }
74 struct rte_ring *rx_queue;
75 struct rte_ring *tx_queue;
79 uint8_t lacp_parnter_state;
82 struct ether_vlan_hdr {
83 struct rte_ether_hdr pkt_eth_hdr;
84 struct rte_vlan_hdr vlan_hdr;
87 struct link_bonding_unittest_params {
88 uint8_t bonded_port_id;
89 struct slave_conf slave_ports[SLAVE_COUNT];
91 struct rte_mempool *mbuf_pool;
94 #define TEST_DEFAULT_SLAVE_COUNT RTE_DIM(test_params.slave_ports)
95 #define TEST_RX_SLAVE_COUT TEST_DEFAULT_SLAVE_COUNT
96 #define TEST_TX_SLAVE_COUNT TEST_DEFAULT_SLAVE_COUNT
97 #define TEST_MARKER_SLAVE_COUT TEST_DEFAULT_SLAVE_COUNT
98 #define TEST_EXPIRED_SLAVE_COUNT TEST_DEFAULT_SLAVE_COUNT
99 #define TEST_PROMISC_SLAVE_COUNT TEST_DEFAULT_SLAVE_COUNT
101 static struct link_bonding_unittest_params test_params = {
102 .bonded_port_id = INVALID_PORT_ID,
103 .slave_ports = { [0 ... SLAVE_COUNT - 1] = { .port_id = INVALID_PORT_ID} },
108 static struct rte_eth_conf default_pmd_conf = {
110 .mq_mode = ETH_MQ_RX_NONE,
114 .mq_mode = ETH_MQ_TX_NONE,
119 static uint8_t lacpdu_rx_count[RTE_MAX_ETHPORTS] = {0, };
121 #define FOR_EACH(_i, _item, _array, _size) \
122 for (_i = 0, _item = &_array[0]; _i < _size && (_item = &_array[_i]); _i++)
124 /* Macro for iterating over every port that can be used as a slave
126 * _i variable used as an index in test_params->slave_ports
127 * _slave pointer to &test_params->slave_ports[_idx]
129 #define FOR_EACH_PORT(_i, _port) \
130 FOR_EACH(_i, _port, test_params.slave_ports, \
131 RTE_DIM(test_params.slave_ports))
133 /* Macro for iterating over every port that can be used as a slave
134 * in this test and satisfy given condition.
136 * _i variable used as an index in test_params->slave_ports
137 * _slave pointer to &test_params->slave_ports[_idx]
138 * _condition condition that need to be checked
140 #define FOR_EACH_PORT_IF(_i, _port, _condition) FOR_EACH_PORT((_i), (_port)) \
143 /* Macro for iterating over every port that is currently a slave of a bonded
145 * _i variable used as an index in test_params->slave_ports
146 * _slave pointer to &test_params->slave_ports[_idx]
148 #define FOR_EACH_SLAVE(_i, _slave) \
149 FOR_EACH_PORT_IF(_i, _slave, (_slave)->bonded != 0)
152 * Returns packets from slaves TX queue.
155 * size size of buffer
156 * return number of packets or negative error number
159 slave_get_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
161 return rte_ring_dequeue_burst(slave->tx_queue, (void **)buf,
166 * Injects given packets into slaves RX queue.
169 * size number of packets to be injected
170 * return number of queued packets or negative error number
173 slave_put_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
175 return rte_ring_enqueue_burst(slave->rx_queue, (void **)buf,
180 bond_rx(struct rte_mbuf **buf, uint16_t size)
182 return rte_eth_rx_burst(test_params.bonded_port_id, 0, buf, size);
186 bond_tx(struct rte_mbuf **buf, uint16_t size)
188 return rte_eth_tx_burst(test_params.bonded_port_id, 0, buf, size);
192 free_pkts(struct rte_mbuf **pkts, uint16_t count)
196 for (i = 0; i < count; i++) {
198 rte_pktmbuf_free(pkts[i]);
203 configure_ethdev(uint16_t port_id, uint8_t start)
205 TEST_ASSERT(rte_eth_dev_configure(port_id, 1, 1, &default_pmd_conf) == 0,
206 "Failed to configure device %u", port_id);
208 TEST_ASSERT(rte_eth_rx_queue_setup(port_id, 0, RX_RING_SIZE,
209 rte_eth_dev_socket_id(port_id), NULL, test_params.mbuf_pool) == 0,
210 "Failed to setup rx queue.");
212 TEST_ASSERT(rte_eth_tx_queue_setup(port_id, 0, TX_RING_SIZE,
213 rte_eth_dev_socket_id(port_id), NULL) == 0,
214 "Failed to setup tx queue.");
217 TEST_ASSERT(rte_eth_dev_start(port_id) == 0,
218 "Failed to start device (%d).", port_id);
224 add_slave(struct slave_conf *slave, uint8_t start)
226 struct rte_ether_addr addr, addr_check;
229 /* Some sanity check */
230 RTE_VERIFY(test_params.slave_ports <= slave &&
231 slave - test_params.slave_ports < (int)RTE_DIM(test_params.slave_ports));
232 RTE_VERIFY(slave->bonded == 0);
233 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
235 rte_ether_addr_copy(&slave_mac_default, &addr);
236 addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
238 rte_eth_dev_mac_addr_remove(slave->port_id, &addr);
240 TEST_ASSERT_SUCCESS(rte_eth_dev_mac_addr_add(slave->port_id, &addr, 0),
241 "Failed to set slave MAC address");
243 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params.bonded_port_id,
245 "Failed to add slave (idx=%u, id=%u) to bonding (id=%u)",
246 (uint8_t)(slave - test_params.slave_ports), slave->port_id,
247 test_params.bonded_port_id);
251 TEST_ASSERT_SUCCESS(rte_eth_dev_start(slave->port_id),
252 "Failed to start slave %u", slave->port_id);
255 retval = rte_eth_macaddr_get(slave->port_id, &addr_check);
256 TEST_ASSERT_SUCCESS(retval, "Failed to get slave mac address: %s",
258 TEST_ASSERT_EQUAL(rte_is_same_ether_addr(&addr, &addr_check), 1,
259 "Slave MAC address is not as expected");
261 RTE_VERIFY(slave->lacp_parnter_state == 0);
266 remove_slave(struct slave_conf *slave)
268 ptrdiff_t slave_idx = slave - test_params.slave_ports;
270 RTE_VERIFY(test_params.slave_ports <= slave &&
271 slave_idx < (ptrdiff_t)RTE_DIM(test_params.slave_ports));
273 RTE_VERIFY(slave->bonded == 1);
274 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
276 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
277 "Slave %u tx queue not empty while removing from bonding.",
280 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
281 "Slave %u tx queue not empty while removing from bonding.",
284 TEST_ASSERT_EQUAL(rte_eth_bond_slave_remove(test_params.bonded_port_id,
286 "Failed to remove slave (idx=%u, id=%u) from bonding (id=%u)",
287 (uint8_t)slave_idx, slave->port_id,
288 test_params.bonded_port_id);
291 slave->lacp_parnter_state = 0;
296 lacp_recv_cb(uint16_t slave_id, struct rte_mbuf *lacp_pkt)
298 struct rte_ether_hdr *hdr;
299 struct slow_protocol_frame *slow_hdr;
301 RTE_VERIFY(lacp_pkt != NULL);
303 hdr = rte_pktmbuf_mtod(lacp_pkt, struct rte_ether_hdr *);
304 RTE_VERIFY(hdr->ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW));
306 slow_hdr = rte_pktmbuf_mtod(lacp_pkt, struct slow_protocol_frame *);
307 RTE_VERIFY(slow_hdr->slow_protocol.subtype == SLOW_SUBTYPE_LACP);
309 lacpdu_rx_count[slave_id]++;
310 rte_pktmbuf_free(lacp_pkt);
314 initialize_bonded_device_with_slaves(uint16_t slave_count, uint8_t external_sm)
319 RTE_VERIFY(test_params.bonded_port_id != INVALID_PORT_ID);
321 for (i = 0; i < slave_count; i++) {
322 TEST_ASSERT_SUCCESS(add_slave(&test_params.slave_ports[i], 1),
323 "Failed to add port %u to bonded device.\n",
324 test_params.slave_ports[i].port_id);
327 /* Reset mode 4 configuration */
328 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, NULL);
329 ret = rte_eth_promiscuous_disable(test_params.bonded_port_id);
330 TEST_ASSERT_SUCCESS(ret,
331 "Failed disable promiscuous mode for port %d: %s",
332 test_params.bonded_port_id, rte_strerror(-ret));
335 struct rte_eth_bond_8023ad_conf conf;
337 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
338 conf.slowrx_cb = lacp_recv_cb;
339 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
343 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params.bonded_port_id),
344 "Failed to start bonded device");
350 remove_slaves_and_stop_bonded_device(void)
352 struct slave_conf *slave;
354 uint16_t slaves[RTE_MAX_ETHPORTS];
357 TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params.bonded_port_id),
358 "Failed to stop bonded port %u",
359 test_params.bonded_port_id);
361 FOR_EACH_SLAVE(i, slave)
364 retval = rte_eth_bond_slaves_get(test_params.bonded_port_id, slaves,
367 TEST_ASSERT_EQUAL(retval, 0,
368 "Expected bonded device %u have 0 slaves but returned %d.",
369 test_params.bonded_port_id, retval);
371 FOR_EACH_PORT(i, slave) {
372 TEST_ASSERT_SUCCESS(rte_eth_dev_stop(slave->port_id),
373 "Failed to stop bonded port %u",
376 TEST_ASSERT(slave->bonded == 0,
377 "Port id=%u is still marked as enslaved.", slave->port_id);
386 int retval, nb_mbuf_per_pool;
387 char name[RTE_ETH_NAME_MAX_LEN];
388 struct slave_conf *port;
389 const uint8_t socket_id = rte_socket_id();
392 if (test_params.mbuf_pool == NULL) {
393 nb_mbuf_per_pool = TEST_RX_DESC_MAX + DEF_PKT_BURST +
394 TEST_TX_DESC_MAX + MAX_PKT_BURST;
395 test_params.mbuf_pool = rte_pktmbuf_pool_create("TEST_MODE4",
396 nb_mbuf_per_pool, MBUF_CACHE_SIZE, 0,
397 RTE_MBUF_DEFAULT_BUF_SIZE, socket_id);
399 TEST_ASSERT(test_params.mbuf_pool != NULL,
400 "rte_mempool_create failed\n");
403 /* Create / initialize ring eth devs. */
404 FOR_EACH_PORT(i, port) {
405 port = &test_params.slave_ports[i];
407 if (port->rx_queue == NULL) {
408 retval = snprintf(name, RTE_DIM(name), SLAVE_RX_QUEUE_FMT, i);
409 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
410 port->rx_queue = rte_ring_create(name, RX_RING_SIZE, socket_id, 0);
411 TEST_ASSERT(port->rx_queue != NULL,
412 "Failed to allocate rx ring '%s': %s", name,
413 rte_strerror(rte_errno));
416 if (port->tx_queue == NULL) {
417 retval = snprintf(name, RTE_DIM(name), SLAVE_TX_QUEUE_FMT, i);
418 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
419 port->tx_queue = rte_ring_create(name, TX_RING_SIZE, socket_id, 0);
420 TEST_ASSERT_NOT_NULL(port->tx_queue,
421 "Failed to allocate tx ring '%s': %s", name,
422 rte_strerror(rte_errno));
425 if (port->port_id == INVALID_PORT_ID) {
426 retval = snprintf(name, RTE_DIM(name), SLAVE_DEV_NAME_FMT, i);
427 TEST_ASSERT(retval < (int)RTE_DIM(name) - 1, "Name too long");
428 retval = rte_eth_from_rings(name, &port->rx_queue, 1,
429 &port->tx_queue, 1, socket_id);
430 TEST_ASSERT(retval >= 0,
431 "Failed to create ring ethdev '%s'\n", name);
433 port->port_id = rte_eth_dev_count_avail() - 1;
436 retval = configure_ethdev(port->port_id, 1);
437 TEST_ASSERT_SUCCESS(retval, "Failed to configure virtual ethdev %s\n",
441 if (test_params.bonded_port_id == INVALID_PORT_ID) {
442 retval = rte_eth_bond_create(BONDED_DEV_NAME, BONDING_MODE_8023AD,
445 TEST_ASSERT(retval >= 0, "Failed to create bonded ethdev %s",
448 test_params.bonded_port_id = retval;
449 TEST_ASSERT_SUCCESS(configure_ethdev(test_params.bonded_port_id, 0),
450 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME);
451 } else if (rte_eth_bond_mode_get(test_params.bonded_port_id) !=
452 BONDING_MODE_8023AD) {
453 TEST_ASSERT(rte_eth_bond_mode_set(test_params.bonded_port_id,
454 BONDING_MODE_8023AD) == 0,
455 "Failed to set ethdev %d to mode %d",
456 test_params.bonded_port_id, BONDING_MODE_8023AD);
463 testsuite_teardown(void)
465 struct slave_conf *port;
469 * Any cleanup/reset state is done when particular test is
472 rte_eth_dev_stop(test_params.bonded_port_id);
474 FOR_EACH_PORT(i, port)
475 rte_eth_dev_stop(port->port_id);
479 * Check if given LACP packet. If it is, make make replay packet to force
481 * return 0 when pkt is LACP frame, 1 if it is not slow frame, 2 if it is slow
485 make_lacp_reply(struct slave_conf *slave, struct rte_mbuf *pkt)
487 struct rte_ether_hdr *hdr;
488 struct slow_protocol_frame *slow_hdr;
492 hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
493 if (hdr->ether_type != rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW))
496 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
497 /* ignore packets of other types */
498 if (slow_hdr->slow_protocol.subtype != SLOW_SUBTYPE_LACP)
501 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
503 /* Change source address to partner address */
504 rte_ether_addr_copy(&parnter_mac_default, &slow_hdr->eth_hdr.src_addr);
505 slow_hdr->eth_hdr.src_addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
508 lacp = (struct lacpdu *) &slow_hdr->slow_protocol;
509 /* Save last received state */
510 slave->lacp_parnter_state = lacp->actor.state;
511 /* Change it into LACP replay by matching parameters. */
512 memcpy(&lacp->partner.port_params, &lacp->actor.port_params,
513 sizeof(struct port_params));
515 lacp->partner.state = lacp->actor.state;
517 rte_ether_addr_copy(&parnter_system, &lacp->actor.port_params.system);
518 lacp->actor.state = STATE_LACP_ACTIVE |
519 STATE_SYNCHRONIZATION |
528 * Reads packets from given slave, search for LACP packet and reply them.
530 * Receives burst of packets from slave. Looks for LACP packet. Drops
531 * all other packets. Prepares response LACP and sends it back.
533 * return number of LACP received and replied, -1 on error.
536 bond_handshake_reply(struct slave_conf *slave)
539 struct rte_mbuf *rx_buf[MAX_PKT_BURST];
540 struct rte_mbuf *lacp_tx_buf[MAX_PKT_BURST];
541 uint16_t lacp_tx_buf_cnt = 0, i;
543 retval = slave_get_pkts(slave, rx_buf, RTE_DIM(rx_buf));
544 TEST_ASSERT(retval >= 0, "Getting slave %u packets failed.",
547 for (i = 0; i < (uint16_t)retval; i++) {
548 if (make_lacp_reply(slave, rx_buf[i]) == 0) {
549 /* reply with actor's LACP */
550 lacp_tx_buf[lacp_tx_buf_cnt++] = rx_buf[i];
552 rte_pktmbuf_free(rx_buf[i]);
555 if (lacp_tx_buf_cnt == 0)
558 retval = slave_put_pkts(slave, lacp_tx_buf, lacp_tx_buf_cnt);
559 if (retval <= lacp_tx_buf_cnt) {
560 /* retval might be negative */
561 for (i = RTE_MAX(0, retval); retval < lacp_tx_buf_cnt; retval++)
562 rte_pktmbuf_free(lacp_tx_buf[i]);
565 TEST_ASSERT_EQUAL(retval, lacp_tx_buf_cnt,
566 "Failed to equeue lacp packets into slave %u tx queue.",
569 return lacp_tx_buf_cnt;
573 * Function check if given slave tx queue contains packets that make mode 4
574 * handshake complete. It will drain slave queue.
575 * return 0 if handshake not completed, 1 if handshake was complete,
578 bond_handshake_done(struct slave_conf *slave)
580 const uint8_t expected_state = STATE_LACP_ACTIVE | STATE_SYNCHRONIZATION |
581 STATE_AGGREGATION | STATE_COLLECTING | STATE_DISTRIBUTING;
583 return slave->lacp_parnter_state == expected_state;
587 bond_get_update_timeout_ms(void)
589 struct rte_eth_bond_8023ad_conf conf;
591 if (rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf) < 0) {
592 RTE_LOG(DEBUG, EAL, "Failed to get bonding configuration: "
593 "%s at %d\n", __func__, __LINE__);
594 RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__);
598 return conf.update_timeout_ms;
602 * Exchanges LACP packets with partner to achieve dynamic port configuration.
603 * return TEST_SUCCESS if initial handshake succeed, TEST_FAILED otherwise.
608 struct slave_conf *slave;
609 struct rte_mbuf *buf[MAX_PKT_BURST];
611 uint8_t all_slaves_done, i, j;
612 uint8_t status[RTE_DIM(test_params.slave_ports)] = { 0 };
613 const unsigned delay = bond_get_update_timeout_ms();
615 /* Exchange LACP frames */
617 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
621 FOR_EACH_SLAVE(j, slave) {
622 /* If response already send, skip slave */
626 if (bond_handshake_reply(slave) < 0) {
631 status[j] = bond_handshake_done(slave);
636 nb_pkts = bond_tx(NULL, 0);
637 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
639 nb_pkts = bond_rx(buf, RTE_DIM(buf));
640 free_pkts(buf, nb_pkts);
641 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
643 /* If response didn't send - report failure */
644 TEST_ASSERT_EQUAL(all_slaves_done, 1, "Bond handshake failed\n");
646 /* If flags doesn't match - report failure */
647 return all_slaves_done == 1 ? TEST_SUCCESS : TEST_FAILED;
650 #define TEST_LACP_SLAVE_COUT RTE_DIM(test_params.slave_ports)
652 test_mode4_lacp(void)
656 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
657 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
659 /* Test LACP handshake function */
660 retval = bond_handshake();
661 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
663 retval = remove_slaves_and_stop_bonded_device();
664 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
669 test_mode4_agg_mode_selection(void)
672 /* Test and verify for Stable mode */
673 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
674 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
677 retval = rte_eth_bond_8023ad_agg_selection_set(
678 test_params.bonded_port_id, AGG_STABLE);
679 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bond aggregation mode");
680 retval = bond_handshake();
681 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
684 retval = rte_eth_bond_8023ad_agg_selection_get(
685 test_params.bonded_port_id);
686 TEST_ASSERT_EQUAL(retval, AGG_STABLE,
687 "Wrong agg mode received from bonding device");
689 retval = remove_slaves_and_stop_bonded_device();
690 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
693 /* test and verify for Bandwidth mode */
694 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
695 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
698 retval = rte_eth_bond_8023ad_agg_selection_set(
699 test_params.bonded_port_id,
701 TEST_ASSERT_SUCCESS(retval,
702 "Failed to initialize bond aggregation mode");
703 retval = bond_handshake();
704 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
706 retval = rte_eth_bond_8023ad_agg_selection_get(
707 test_params.bonded_port_id);
708 TEST_ASSERT_EQUAL(retval, AGG_BANDWIDTH,
709 "Wrong agg mode received from bonding device");
711 retval = remove_slaves_and_stop_bonded_device();
712 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
714 /* test and verify selection for count mode */
715 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
716 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
719 retval = rte_eth_bond_8023ad_agg_selection_set(
720 test_params.bonded_port_id, AGG_COUNT);
721 TEST_ASSERT_SUCCESS(retval,
722 "Failed to initialize bond aggregation mode");
723 retval = bond_handshake();
724 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
726 retval = rte_eth_bond_8023ad_agg_selection_get(
727 test_params.bonded_port_id);
728 TEST_ASSERT_EQUAL(retval, AGG_COUNT,
729 "Wrong agg mode received from bonding device");
731 retval = remove_slaves_and_stop_bonded_device();
732 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
738 generate_packets(struct rte_ether_addr *src_mac,
739 struct rte_ether_addr *dst_mac, uint16_t count, struct rte_mbuf **buf)
741 uint16_t pktlen = PACKET_BURST_GEN_PKT_LEN;
742 uint8_t vlan_enable = 0;
743 uint16_t vlan_id = 0;
744 uint8_t ip4_type = 1; /* 0 - ipv6 */
746 uint16_t src_port = 10, dst_port = 20;
748 uint32_t ip_src[4] = { [0 ... 2] = 0xDEADBEEF, [3] = RTE_IPV4(192, 168, 0, 1) };
749 uint32_t ip_dst[4] = { [0 ... 2] = 0xFEEDFACE, [3] = RTE_IPV4(192, 168, 0, 2) };
751 struct rte_ether_hdr pkt_eth_hdr;
752 struct rte_udp_hdr pkt_udp_hdr;
754 struct rte_ipv4_hdr v4;
755 struct rte_ipv6_hdr v6;
760 initialize_eth_header(&pkt_eth_hdr, src_mac, dst_mac, ip4_type,
761 vlan_enable, vlan_id);
764 initialize_ipv4_header(&pkt_ip_hdr.v4, ip_src[3], ip_dst[3], pktlen);
766 initialize_ipv6_header(&pkt_ip_hdr.v6, (uint8_t *)ip_src,
767 (uint8_t *)&ip_dst, pktlen);
769 initialize_udp_header(&pkt_udp_hdr, src_port, dst_port, 16);
771 retval = generate_packet_burst(test_params.mbuf_pool, buf,
772 &pkt_eth_hdr, vlan_enable, &pkt_ip_hdr, 1, &pkt_udp_hdr,
775 if (retval > 0 && retval != count)
776 free_pkts(&buf[count - retval], retval);
778 TEST_ASSERT_EQUAL(retval, count, "Failed to generate %u packets",
785 generate_and_put_packets(struct slave_conf *slave,
786 struct rte_ether_addr *src_mac,
787 struct rte_ether_addr *dst_mac, uint16_t count)
789 struct rte_mbuf *pkts[MAX_PKT_BURST];
792 retval = generate_packets(src_mac, dst_mac, count, pkts);
793 if (retval != (int)count)
796 retval = slave_put_pkts(slave, pkts, count);
797 if (retval > 0 && retval != count)
798 free_pkts(&pkts[retval], count - retval);
800 TEST_ASSERT_EQUAL(retval, count,
801 "Failed to enqueue packets into slave %u RX queue", slave->port_id);
809 struct slave_conf *slave;
812 uint16_t expected_pkts_cnt;
813 struct rte_mbuf *pkts[MAX_PKT_BURST];
817 struct rte_ether_hdr *hdr;
819 struct rte_ether_addr src_mac = {
820 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
821 struct rte_ether_addr dst_mac;
822 struct rte_ether_addr bonded_mac;
824 retval = initialize_bonded_device_with_slaves(TEST_PROMISC_SLAVE_COUNT,
826 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
828 retval = bond_handshake();
829 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
831 retval = rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
832 TEST_ASSERT_SUCCESS(retval, "Failed to get mac address: %s",
834 rte_ether_addr_copy(&bonded_mac, &dst_mac);
836 /* Assert that dst address is not bonding address. Do not set the
837 * least significant bit of the zero byte as this would create a
840 dst_mac.addr_bytes[0] += 2;
842 /* First try with promiscuous mode enabled.
843 * Add 2 packets to each slave. First with bonding MAC address, second with
844 * different. Check if we received all of them. */
845 retval = rte_eth_promiscuous_enable(test_params.bonded_port_id);
846 TEST_ASSERT_SUCCESS(retval,
847 "Failed to enable promiscuous mode for port %d: %s",
848 test_params.bonded_port_id, rte_strerror(-retval));
850 expected_pkts_cnt = 0;
851 FOR_EACH_SLAVE(i, slave) {
852 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
853 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
856 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
857 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
860 /* Expect 2 packets per slave */
861 expected_pkts_cnt += 2;
864 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
867 if (retval == expected_pkts_cnt) {
868 int cnt[2] = { 0, 0 };
870 for (i = 0; i < expected_pkts_cnt; i++) {
871 hdr = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *);
872 cnt[rte_is_same_ether_addr(&hdr->dst_addr,
876 free_pkts(pkts, expected_pkts_cnt);
878 /* For division by 2 expected_pkts_cnt must be even */
879 RTE_VERIFY((expected_pkts_cnt & 1) == 0);
880 TEST_ASSERT(cnt[0] == expected_pkts_cnt / 2 &&
881 cnt[1] == expected_pkts_cnt / 2,
882 "Expected %u packets with the same MAC and %u with different but "
883 "got %u with the same and %u with different MAC",
884 expected_pkts_cnt / 2, expected_pkts_cnt / 2, cnt[1], cnt[0]);
885 } else if (retval > 0)
886 free_pkts(pkts, retval);
888 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
889 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
891 /* Now, disable promiscuous mode. When promiscuous mode is disabled we
892 * expect to receive only packets that are directed to bonding port. */
893 retval = rte_eth_promiscuous_disable(test_params.bonded_port_id);
894 TEST_ASSERT_SUCCESS(retval,
895 "Failed to disable promiscuous mode for port %d: %s",
896 test_params.bonded_port_id, rte_strerror(-retval));
898 expected_pkts_cnt = 0;
899 FOR_EACH_SLAVE(i, slave) {
900 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
901 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
904 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
905 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
908 /* Expect only one packet per slave */
909 expected_pkts_cnt += 1;
912 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
915 if (retval == expected_pkts_cnt) {
918 for (i = 0; i < expected_pkts_cnt; i++) {
919 hdr = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *);
920 eq_cnt += rte_is_same_ether_addr(&hdr->dst_addr,
924 free_pkts(pkts, expected_pkts_cnt);
925 TEST_ASSERT_EQUAL(eq_cnt, expected_pkts_cnt, "Packet address mismatch");
926 } else if (retval > 0)
927 free_pkts(pkts, retval);
929 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
930 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
932 /* Link down test: simulate link down for first slave. */
933 delay = bond_get_update_timeout_ms();
935 uint8_t slave_down_id = INVALID_PORT_ID;
937 /* Find first slave and make link down on it*/
938 FOR_EACH_SLAVE(i, slave) {
939 rte_eth_dev_set_link_down(slave->port_id);
940 slave_down_id = slave->port_id;
944 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
946 /* Give some time to rearrange bonding */
947 for (i = 0; i < 3; i++) {
952 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
954 /* Put packet to each slave */
955 FOR_EACH_SLAVE(i, slave) {
958 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
959 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
960 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
962 src_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
963 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
964 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
966 retval = bond_rx(pkts, RTE_DIM(pkts));
970 free_pkts(pkts, retval);
972 while (rte_ring_dequeue(slave->rx_queue, (void **)&pkt) == 0)
973 rte_pktmbuf_free(pkt);
975 if (slave_down_id == slave->port_id)
976 TEST_ASSERT_EQUAL(retval, 0, "Packets received unexpectedly.");
978 TEST_ASSERT_NOT_EQUAL(retval, 0,
979 "Expected to receive some packets on slave %u.",
981 rte_eth_dev_start(slave->port_id);
983 for (j = 0; j < 5; j++) {
984 TEST_ASSERT(bond_handshake_reply(slave) >= 0,
985 "Handshake after link up");
987 if (bond_handshake_done(slave) == 1)
991 TEST_ASSERT(j < 5, "Failed to aggregate slave after link up");
994 remove_slaves_and_stop_bonded_device();
999 test_mode4_tx_burst(void)
1001 struct slave_conf *slave;
1004 uint16_t exp_pkts_cnt, pkts_cnt = 0;
1005 struct rte_mbuf *pkts[MAX_PKT_BURST];
1009 struct rte_ether_addr dst_mac = {
1010 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
1011 struct rte_ether_addr bonded_mac;
1013 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1014 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1016 retval = bond_handshake();
1017 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1019 retval = rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
1020 TEST_ASSERT_SUCCESS(retval, "Failed to get mac address: %s",
1023 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1024 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = pkts_cnt;
1025 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1028 free_pkts(pkts, pkts_cnt);
1030 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate packet %u", pkts_cnt);
1032 exp_pkts_cnt = pkts_cnt;
1034 /* Transmit packets on bonded device */
1035 retval = bond_tx(pkts, pkts_cnt);
1036 if (retval > 0 && retval < pkts_cnt)
1037 free_pkts(&pkts[retval], pkts_cnt - retval);
1039 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1041 /* Check if packets were transmitted properly. Every slave should have
1042 * at least one packet, and sum must match. Under normal operation
1043 * there should be no LACP nor MARKER frames. */
1045 FOR_EACH_SLAVE(i, slave) {
1046 uint16_t normal_cnt, slow_cnt;
1048 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1052 for (j = 0; j < retval; j++) {
1053 if (make_lacp_reply(slave, pkts[j]) == 1)
1059 free_pkts(pkts, normal_cnt + slow_cnt);
1060 TEST_ASSERT_EQUAL(slow_cnt, 0,
1061 "slave %u unexpectedly transmitted %d SLOW packets", slave->port_id,
1064 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1065 "slave %u did not transmitted any packets", slave->port_id);
1067 pkts_cnt += normal_cnt;
1070 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1071 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1074 * simulate link down for first slave. */
1075 delay = bond_get_update_timeout_ms();
1077 uint8_t slave_down_id = INVALID_PORT_ID;
1079 FOR_EACH_SLAVE(i, slave) {
1080 rte_eth_dev_set_link_down(slave->port_id);
1081 slave_down_id = slave->port_id;
1085 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
1087 /* Give some time to rearrange bonding. */
1088 for (i = 0; i < 3; i++) {
1090 rte_delay_ms(delay);
1093 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
1095 /* Prepare burst. */
1096 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1097 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = pkts_cnt;
1098 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1101 free_pkts(pkts, pkts_cnt);
1103 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate test packet %u",
1106 exp_pkts_cnt = pkts_cnt;
1108 /* Transmit packets on bonded device. */
1109 retval = bond_tx(pkts, pkts_cnt);
1110 if (retval > 0 && retval < pkts_cnt)
1111 free_pkts(&pkts[retval], pkts_cnt - retval);
1113 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1115 /* Check if packets was transmitted properly. Every slave should have
1116 * at least one packet, and sum must match. Under normal operation
1117 * there should be no LACP nor MARKER frames. */
1119 FOR_EACH_SLAVE(i, slave) {
1120 uint16_t normal_cnt, slow_cnt;
1122 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1126 for (j = 0; j < retval; j++) {
1127 if (make_lacp_reply(slave, pkts[j]) == 1)
1133 free_pkts(pkts, normal_cnt + slow_cnt);
1135 if (slave_down_id == slave->port_id) {
1136 TEST_ASSERT_EQUAL(normal_cnt + slow_cnt, 0,
1137 "slave %u enexpectedly transmitted %u packets",
1138 normal_cnt + slow_cnt, slave->port_id);
1140 TEST_ASSERT_EQUAL(slow_cnt, 0,
1141 "slave %u unexpectedly transmitted %d SLOW packets",
1142 slave->port_id, slow_cnt);
1144 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1145 "slave %u did not transmitted any packets", slave->port_id);
1148 pkts_cnt += normal_cnt;
1151 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1152 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1154 return remove_slaves_and_stop_bonded_device();
1158 init_marker(struct rte_mbuf *pkt, struct slave_conf *slave)
1160 struct marker_header *marker_hdr = rte_pktmbuf_mtod(pkt,
1161 struct marker_header *);
1163 /* Copy multicast destination address */
1164 rte_ether_addr_copy(&slow_protocol_mac_addr,
1165 &marker_hdr->eth_hdr.dst_addr);
1167 /* Init source address */
1168 rte_ether_addr_copy(&parnter_mac_default,
1169 &marker_hdr->eth_hdr.src_addr);
1170 marker_hdr->eth_hdr.src_addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
1173 marker_hdr->eth_hdr.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW);
1175 marker_hdr->marker.subtype = SLOW_SUBTYPE_MARKER;
1176 marker_hdr->marker.version_number = 1;
1177 marker_hdr->marker.tlv_type_marker = MARKER_TLV_TYPE_INFO;
1178 marker_hdr->marker.info_length =
1179 offsetof(struct marker, reserved_90) -
1180 offsetof(struct marker, requester_port);
1181 RTE_VERIFY(marker_hdr->marker.info_length == 16);
1182 marker_hdr->marker.requester_port = slave->port_id + 1;
1183 marker_hdr->marker.tlv_type_terminator = TLV_TYPE_TERMINATOR_INFORMATION;
1184 marker_hdr->marker.terminator_length = 0;
1188 test_mode4_marker(void)
1190 struct slave_conf *slave;
1191 struct rte_mbuf *pkts[MAX_PKT_BURST];
1192 struct rte_mbuf *marker_pkt;
1193 struct marker_header *marker_hdr;
1199 const uint16_t ethtype_slow_be = rte_be_to_cpu_16(RTE_ETHER_TYPE_SLOW);
1201 retval = initialize_bonded_device_with_slaves(TEST_MARKER_SLAVE_COUT,
1203 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1205 /* Test LACP handshake function */
1206 retval = bond_handshake();
1207 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1209 delay = bond_get_update_timeout_ms();
1210 FOR_EACH_SLAVE(i, slave) {
1211 marker_pkt = rte_pktmbuf_alloc(test_params.mbuf_pool);
1212 TEST_ASSERT_NOT_NULL(marker_pkt, "Failed to allocate marker packet");
1213 init_marker(marker_pkt, slave);
1215 retval = slave_put_pkts(slave, &marker_pkt, 1);
1217 rte_pktmbuf_free(marker_pkt);
1219 TEST_ASSERT_EQUAL(retval, 1,
1220 "Failed to send marker packet to slave %u", slave->port_id);
1222 for (j = 0; j < 20; ++j) {
1223 rte_delay_ms(delay);
1224 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
1228 free_pkts(pkts, retval);
1230 TEST_ASSERT_EQUAL(retval, 0, "Received packets unexpectedly");
1232 retval = rte_eth_tx_burst(test_params.bonded_port_id, 0, NULL, 0);
1233 TEST_ASSERT_EQUAL(retval, 0,
1234 "Requested TX of 0 packets but %d transmitted", retval);
1236 /* Check if LACP packet was send by state machines
1237 First and only packet must be a maker response */
1238 retval = slave_get_pkts(slave, pkts, MAX_PKT_BURST);
1242 free_pkts(pkts, retval);
1244 TEST_ASSERT_EQUAL(retval, 1, "failed to get slave packets");
1247 marker_hdr = rte_pktmbuf_mtod(pkts[0], struct marker_header *);
1248 /* Check if it's slow packet*/
1249 if (marker_hdr->eth_hdr.ether_type != ethtype_slow_be)
1251 /* Check if it's marker packet */
1252 else if (marker_hdr->marker.subtype != SLOW_SUBTYPE_MARKER)
1254 else if (marker_hdr->marker.tlv_type_marker != MARKER_TLV_TYPE_RESP)
1257 free_pkts(pkts, nb_pkts);
1259 TEST_ASSERT_NOT_EQUAL(retval, -1, "Unexpected protocol type");
1260 TEST_ASSERT_NOT_EQUAL(retval, -2, "Unexpected sub protocol type");
1261 TEST_ASSERT_NOT_EQUAL(retval, -3, "Unexpected marker type");
1265 TEST_ASSERT(j < 20, "Marker response not found");
1268 retval = remove_slaves_and_stop_bonded_device();
1269 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1271 return TEST_SUCCESS;
1275 test_mode4_expired(void)
1277 struct slave_conf *slave, *exp_slave = NULL;
1278 struct rte_mbuf *pkts[MAX_PKT_BURST];
1285 struct rte_eth_bond_8023ad_conf conf;
1287 retval = initialize_bonded_device_with_slaves(TEST_EXPIRED_SLAVE_COUNT,
1289 /* Set custom timeouts to make test last shorter. */
1290 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
1291 conf.fast_periodic_ms = 100;
1292 conf.slow_periodic_ms = 600;
1293 conf.short_timeout_ms = 300;
1294 conf.long_timeout_ms = 900;
1295 conf.aggregate_wait_timeout_ms = 200;
1296 conf.tx_period_ms = 100;
1297 old_delay = conf.update_timeout_ms;
1298 conf.update_timeout_ms = 10;
1299 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
1301 /* Wait for new settings to be applied. */
1302 for (i = 0; i < old_delay/conf.update_timeout_ms * 2; i++) {
1303 FOR_EACH_SLAVE(j, slave)
1304 bond_handshake_reply(slave);
1306 rte_delay_ms(conf.update_timeout_ms);
1309 retval = bond_handshake();
1310 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1312 /* Find first slave */
1313 FOR_EACH_SLAVE(i, slave) {
1318 RTE_VERIFY(exp_slave != NULL);
1320 /* When one of partners do not send or respond to LACP frame in
1321 * conf.long_timeout_ms time, internal state machines should detect this
1322 * and transit to expired state. */
1323 for (j = 0; j < conf.long_timeout_ms/conf.update_timeout_ms + 2; j++) {
1324 rte_delay_ms(conf.update_timeout_ms);
1326 retval = bond_tx(NULL, 0);
1327 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1330 FOR_EACH_SLAVE(i, slave) {
1331 retval = bond_handshake_reply(slave);
1332 TEST_ASSERT(retval >= 0, "Handshake failed");
1334 /* Remove replay for slave that suppose to be expired. */
1335 if (slave == exp_slave) {
1336 while (rte_ring_count(slave->rx_queue) > 0) {
1339 rte_ring_dequeue(slave->rx_queue, &pkt);
1340 rte_pktmbuf_free(pkt);
1345 retval = bond_rx(pkts, RTE_DIM(pkts));
1347 free_pkts(pkts, retval);
1349 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1353 /* After test only expected slave should be in EXPIRED state */
1354 FOR_EACH_SLAVE(i, slave) {
1355 if (slave == exp_slave)
1356 TEST_ASSERT(slave->lacp_parnter_state & STATE_EXPIRED,
1357 "Slave %u should be in expired.", slave->port_id);
1359 TEST_ASSERT_EQUAL(bond_handshake_done(slave), 1,
1360 "Slave %u should be operational.", slave->port_id);
1363 retval = remove_slaves_and_stop_bonded_device();
1364 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1366 return TEST_SUCCESS;
1370 test_mode4_ext_ctrl(void)
1373 * configure bonded interface without the external sm enabled
1374 * . try to transmit lacpdu (should fail)
1375 * . try to set collecting and distributing flags (should fail)
1376 * reconfigure w/external sm
1377 * . transmit one lacpdu on each slave using new api
1378 * . make sure each slave receives one lacpdu using the callback api
1379 * . transmit one data pdu on each slave (should fail)
1380 * . enable distribution and collection, send one data pdu each again
1384 struct slave_conf *slave = NULL;
1387 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1388 struct rte_ether_addr src_mac, dst_mac;
1389 struct lacpdu_header lacpdu = {
1391 .subtype = SLOW_SUBTYPE_LACP,
1395 rte_ether_addr_copy(&parnter_system, &src_mac);
1396 rte_ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1398 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1399 RTE_ETHER_TYPE_SLOW, 0, 0);
1401 for (i = 0; i < SLAVE_COUNT; i++) {
1402 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1403 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1404 &lacpdu, sizeof(lacpdu));
1405 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1408 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1409 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1411 FOR_EACH_SLAVE(i, slave) {
1412 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_slowtx(
1413 test_params.bonded_port_id,
1414 slave->port_id, lacp_tx_buf[i]),
1415 "Slave should not allow manual LACP xmit");
1416 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_collect(
1417 test_params.bonded_port_id,
1419 "Slave should not allow external state controls");
1422 free_pkts(lacp_tx_buf, RTE_DIM(lacp_tx_buf));
1424 retval = remove_slaves_and_stop_bonded_device();
1425 TEST_ASSERT_SUCCESS(retval, "Bonded device cleanup failed.");
1427 return TEST_SUCCESS;
1432 test_mode4_ext_lacp(void)
1435 struct slave_conf *slave = NULL;
1436 uint8_t all_slaves_done = 0, i;
1438 const unsigned int delay = bond_get_update_timeout_ms();
1440 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1441 struct rte_mbuf *buf[SLAVE_COUNT];
1442 struct rte_ether_addr src_mac, dst_mac;
1443 struct lacpdu_header lacpdu = {
1445 .subtype = SLOW_SUBTYPE_LACP,
1449 rte_ether_addr_copy(&parnter_system, &src_mac);
1450 rte_ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1452 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1453 RTE_ETHER_TYPE_SLOW, 0, 0);
1455 for (i = 0; i < SLAVE_COUNT; i++) {
1456 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1457 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1458 &lacpdu, sizeof(lacpdu));
1459 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1462 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 1);
1463 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1465 memset(lacpdu_rx_count, 0, sizeof(lacpdu_rx_count));
1467 /* Wait for new settings to be applied. */
1468 for (i = 0; i < 30; ++i)
1469 rte_delay_ms(delay);
1471 FOR_EACH_SLAVE(i, slave) {
1472 retval = rte_eth_bond_8023ad_ext_slowtx(
1473 test_params.bonded_port_id,
1474 slave->port_id, lacp_tx_buf[i]);
1475 TEST_ASSERT_SUCCESS(retval,
1476 "Slave should allow manual LACP xmit");
1479 nb_pkts = bond_tx(NULL, 0);
1480 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
1482 FOR_EACH_SLAVE(i, slave) {
1483 nb_pkts = slave_get_pkts(slave, buf, RTE_DIM(buf));
1484 TEST_ASSERT_EQUAL(nb_pkts, 1, "found %u packets on slave %d\n",
1486 slave_put_pkts(slave, buf, nb_pkts);
1489 nb_pkts = bond_rx(buf, RTE_DIM(buf));
1490 free_pkts(buf, nb_pkts);
1491 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
1493 /* wait for the periodic callback to run */
1494 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
1495 uint8_t s, total = 0;
1497 rte_delay_ms(delay);
1498 FOR_EACH_SLAVE(s, slave) {
1499 total += lacpdu_rx_count[slave->port_id];
1502 if (total >= SLAVE_COUNT)
1503 all_slaves_done = 1;
1506 FOR_EACH_SLAVE(i, slave) {
1507 TEST_ASSERT_EQUAL(lacpdu_rx_count[slave->port_id], 1,
1508 "Slave port %u should have received 1 lacpdu (count=%u)",
1510 lacpdu_rx_count[slave->port_id]);
1513 retval = remove_slaves_and_stop_bonded_device();
1514 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1516 return TEST_SUCCESS;
1520 check_environment(void)
1522 struct slave_conf *port;
1523 uint8_t i, env_state;
1524 uint16_t slaves[RTE_DIM(test_params.slave_ports)];
1528 FOR_EACH_PORT(i, port) {
1529 if (rte_ring_count(port->rx_queue) != 0)
1532 if (rte_ring_count(port->tx_queue) != 0)
1535 if (port->bonded != 0)
1538 if (port->lacp_parnter_state != 0)
1545 slaves_count = rte_eth_bond_slaves_get(test_params.bonded_port_id,
1546 slaves, RTE_DIM(slaves));
1548 if (slaves_count != 0)
1551 TEST_ASSERT_EQUAL(env_state, 0,
1552 "Environment not clean (port %u):%s%s%s%s%s",
1554 env_state & 0x01 ? " slave rx queue not clean" : "",
1555 env_state & 0x02 ? " slave tx queue not clean" : "",
1556 env_state & 0x04 ? " port marked as enslaved" : "",
1557 env_state & 0x80 ? " slave state is not reset" : "",
1558 env_state & 0x10 ? " slave count not equal 0" : ".");
1561 return TEST_SUCCESS;
1565 test_mode4_executor(int (*test_func)(void))
1567 struct slave_conf *port;
1572 /* Check if environment is clean. Fail to launch a test if there was
1573 * a critical error before that prevented to reset environment. */
1574 TEST_ASSERT_SUCCESS(check_environment(),
1575 "Refusing to launch test in dirty environment.");
1577 RTE_VERIFY(test_func != NULL);
1578 test_result = (*test_func)();
1580 /* If test succeed check if environment wast left in good condition. */
1581 if (test_result == TEST_SUCCESS)
1582 test_result = check_environment();
1584 /* Reset environment in case test failed to do that. */
1585 if (test_result != TEST_SUCCESS) {
1586 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
1587 "Failed to stop bonded device");
1589 FOR_EACH_PORT(i, port) {
1590 while (rte_ring_count(port->rx_queue) != 0) {
1591 if (rte_ring_dequeue(port->rx_queue, &pkt) == 0)
1592 rte_pktmbuf_free(pkt);
1595 while (rte_ring_count(port->tx_queue) != 0) {
1596 if (rte_ring_dequeue(port->tx_queue, &pkt) == 0)
1597 rte_pktmbuf_free(pkt);
1606 test_mode4_agg_mode_selection_wrapper(void){
1607 return test_mode4_executor(&test_mode4_agg_mode_selection);
1611 test_mode4_lacp_wrapper(void)
1613 return test_mode4_executor(&test_mode4_lacp);
1617 test_mode4_marker_wrapper(void)
1619 return test_mode4_executor(&test_mode4_marker);
1623 test_mode4_rx_wrapper(void)
1625 return test_mode4_executor(&test_mode4_rx);
1629 test_mode4_tx_burst_wrapper(void)
1631 return test_mode4_executor(&test_mode4_tx_burst);
1635 test_mode4_expired_wrapper(void)
1637 return test_mode4_executor(&test_mode4_expired);
1641 test_mode4_ext_ctrl_wrapper(void)
1643 return test_mode4_executor(&test_mode4_ext_ctrl);
1647 test_mode4_ext_lacp_wrapper(void)
1649 return test_mode4_executor(&test_mode4_ext_lacp);
1652 static struct unit_test_suite link_bonding_mode4_test_suite = {
1653 .suite_name = "Link Bonding mode 4 Unit Test Suite",
1654 .setup = test_setup,
1655 .teardown = testsuite_teardown,
1656 .unit_test_cases = {
1657 TEST_CASE_NAMED("test_mode4_agg_mode_selection",
1658 test_mode4_agg_mode_selection_wrapper),
1659 TEST_CASE_NAMED("test_mode4_lacp", test_mode4_lacp_wrapper),
1660 TEST_CASE_NAMED("test_mode4_rx", test_mode4_rx_wrapper),
1661 TEST_CASE_NAMED("test_mode4_tx_burst", test_mode4_tx_burst_wrapper),
1662 TEST_CASE_NAMED("test_mode4_marker", test_mode4_marker_wrapper),
1663 TEST_CASE_NAMED("test_mode4_expired", test_mode4_expired_wrapper),
1664 TEST_CASE_NAMED("test_mode4_ext_ctrl",
1665 test_mode4_ext_ctrl_wrapper),
1666 TEST_CASE_NAMED("test_mode4_ext_lacp",
1667 test_mode4_ext_lacp_wrapper),
1669 TEST_CASES_END() /**< NULL terminate unit test array */
1674 test_link_bonding_mode4(void)
1676 return unit_test_suite_runner(&link_bonding_mode4_test_suite);
1679 REGISTER_TEST_COMMAND(link_bonding_mode4_autotest, test_link_bonding_mode4);