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,
111 .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
115 .mq_mode = ETH_MQ_TX_NONE,
120 static uint8_t lacpdu_rx_count[RTE_MAX_ETHPORTS] = {0, };
122 #define FOR_EACH(_i, _item, _array, _size) \
123 for (_i = 0, _item = &_array[0]; _i < _size && (_item = &_array[_i]); _i++)
125 /* Macro for iterating over every port that can be used as a slave
127 * _i variable used as an index in test_params->slave_ports
128 * _slave pointer to &test_params->slave_ports[_idx]
130 #define FOR_EACH_PORT(_i, _port) \
131 FOR_EACH(_i, _port, test_params.slave_ports, \
132 RTE_DIM(test_params.slave_ports))
134 /* Macro for iterating over every port that can be used as a slave
135 * in this test and satisfy given condition.
137 * _i variable used as an index in test_params->slave_ports
138 * _slave pointer to &test_params->slave_ports[_idx]
139 * _condition condition that need to be checked
141 #define FOR_EACH_PORT_IF(_i, _port, _condition) FOR_EACH_PORT((_i), (_port)) \
144 /* Macro for iterating over every port that is currently a slave of a bonded
146 * _i variable used as an index in test_params->slave_ports
147 * _slave pointer to &test_params->slave_ports[_idx]
149 #define FOR_EACH_SLAVE(_i, _slave) \
150 FOR_EACH_PORT_IF(_i, _slave, (_slave)->bonded != 0)
153 * Returns packets from slaves TX queue.
156 * size size of buffer
157 * return number of packets or negative error number
160 slave_get_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
162 return rte_ring_dequeue_burst(slave->tx_queue, (void **)buf,
167 * Injects given packets into slaves RX queue.
170 * size number of packets to be injected
171 * return number of queued packets or negative error number
174 slave_put_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
176 return rte_ring_enqueue_burst(slave->rx_queue, (void **)buf,
181 bond_rx(struct rte_mbuf **buf, uint16_t size)
183 return rte_eth_rx_burst(test_params.bonded_port_id, 0, buf, size);
187 bond_tx(struct rte_mbuf **buf, uint16_t size)
189 return rte_eth_tx_burst(test_params.bonded_port_id, 0, buf, size);
193 free_pkts(struct rte_mbuf **pkts, uint16_t count)
197 for (i = 0; i < count; i++) {
199 rte_pktmbuf_free(pkts[i]);
204 configure_ethdev(uint16_t port_id, uint8_t start)
206 TEST_ASSERT(rte_eth_dev_configure(port_id, 1, 1, &default_pmd_conf) == 0,
207 "Failed to configure device %u", port_id);
209 TEST_ASSERT(rte_eth_rx_queue_setup(port_id, 0, RX_RING_SIZE,
210 rte_eth_dev_socket_id(port_id), NULL, test_params.mbuf_pool) == 0,
211 "Failed to setup rx queue.");
213 TEST_ASSERT(rte_eth_tx_queue_setup(port_id, 0, TX_RING_SIZE,
214 rte_eth_dev_socket_id(port_id), NULL) == 0,
215 "Failed to setup tx queue.");
218 TEST_ASSERT(rte_eth_dev_start(port_id) == 0,
219 "Failed to start device (%d).", port_id);
225 add_slave(struct slave_conf *slave, uint8_t start)
227 struct rte_ether_addr addr, addr_check;
230 /* Some sanity check */
231 RTE_VERIFY(test_params.slave_ports <= slave &&
232 slave - test_params.slave_ports < (int)RTE_DIM(test_params.slave_ports));
233 RTE_VERIFY(slave->bonded == 0);
234 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
236 rte_ether_addr_copy(&slave_mac_default, &addr);
237 addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
239 rte_eth_dev_mac_addr_remove(slave->port_id, &addr);
241 TEST_ASSERT_SUCCESS(rte_eth_dev_mac_addr_add(slave->port_id, &addr, 0),
242 "Failed to set slave MAC address");
244 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params.bonded_port_id,
246 "Failed to add slave (idx=%u, id=%u) to bonding (id=%u)",
247 (uint8_t)(slave - test_params.slave_ports), slave->port_id,
248 test_params.bonded_port_id);
252 TEST_ASSERT_SUCCESS(rte_eth_dev_start(slave->port_id),
253 "Failed to start slave %u", slave->port_id);
256 retval = rte_eth_macaddr_get(slave->port_id, &addr_check);
257 TEST_ASSERT_SUCCESS(retval, "Failed to get slave mac address: %s",
259 TEST_ASSERT_EQUAL(rte_is_same_ether_addr(&addr, &addr_check), 1,
260 "Slave MAC address is not as expected");
262 RTE_VERIFY(slave->lacp_parnter_state == 0);
267 remove_slave(struct slave_conf *slave)
269 ptrdiff_t slave_idx = slave - test_params.slave_ports;
271 RTE_VERIFY(test_params.slave_ports <= slave &&
272 slave_idx < (ptrdiff_t)RTE_DIM(test_params.slave_ports));
274 RTE_VERIFY(slave->bonded == 1);
275 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
277 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
278 "Slave %u tx queue not empty while removing from bonding.",
281 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
282 "Slave %u tx queue not empty while removing from bonding.",
285 TEST_ASSERT_EQUAL(rte_eth_bond_slave_remove(test_params.bonded_port_id,
287 "Failed to remove slave (idx=%u, id=%u) from bonding (id=%u)",
288 (uint8_t)slave_idx, slave->port_id,
289 test_params.bonded_port_id);
292 slave->lacp_parnter_state = 0;
297 lacp_recv_cb(uint16_t slave_id, struct rte_mbuf *lacp_pkt)
299 struct rte_ether_hdr *hdr;
300 struct slow_protocol_frame *slow_hdr;
302 RTE_VERIFY(lacp_pkt != NULL);
304 hdr = rte_pktmbuf_mtod(lacp_pkt, struct rte_ether_hdr *);
305 RTE_VERIFY(hdr->ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW));
307 slow_hdr = rte_pktmbuf_mtod(lacp_pkt, struct slow_protocol_frame *);
308 RTE_VERIFY(slow_hdr->slow_protocol.subtype == SLOW_SUBTYPE_LACP);
310 lacpdu_rx_count[slave_id]++;
311 rte_pktmbuf_free(lacp_pkt);
315 initialize_bonded_device_with_slaves(uint16_t slave_count, uint8_t external_sm)
320 RTE_VERIFY(test_params.bonded_port_id != INVALID_PORT_ID);
322 for (i = 0; i < slave_count; i++) {
323 TEST_ASSERT_SUCCESS(add_slave(&test_params.slave_ports[i], 1),
324 "Failed to add port %u to bonded device.\n",
325 test_params.slave_ports[i].port_id);
328 /* Reset mode 4 configuration */
329 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, NULL);
330 ret = rte_eth_promiscuous_disable(test_params.bonded_port_id);
331 TEST_ASSERT_SUCCESS(ret,
332 "Failed disable promiscuous mode for port %d: %s",
333 test_params.bonded_port_id, rte_strerror(-ret));
336 struct rte_eth_bond_8023ad_conf conf;
338 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
339 conf.slowrx_cb = lacp_recv_cb;
340 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
344 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params.bonded_port_id),
345 "Failed to start bonded device");
351 remove_slaves_and_stop_bonded_device(void)
353 struct slave_conf *slave;
355 uint16_t slaves[RTE_MAX_ETHPORTS];
358 rte_eth_dev_stop(test_params.bonded_port_id);
360 FOR_EACH_SLAVE(i, slave)
363 retval = rte_eth_bond_slaves_get(test_params.bonded_port_id, slaves,
366 TEST_ASSERT_EQUAL(retval, 0,
367 "Expected bonded device %u have 0 slaves but returned %d.",
368 test_params.bonded_port_id, retval);
370 FOR_EACH_PORT(i, slave) {
371 rte_eth_dev_stop(slave->port_id);
373 TEST_ASSERT(slave->bonded == 0,
374 "Port id=%u is still marked as enslaved.", slave->port_id);
383 int retval, nb_mbuf_per_pool;
384 char name[RTE_ETH_NAME_MAX_LEN];
385 struct slave_conf *port;
386 const uint8_t socket_id = rte_socket_id();
389 if (test_params.mbuf_pool == NULL) {
390 nb_mbuf_per_pool = TEST_RX_DESC_MAX + DEF_PKT_BURST +
391 TEST_TX_DESC_MAX + MAX_PKT_BURST;
392 test_params.mbuf_pool = rte_pktmbuf_pool_create("TEST_MODE4",
393 nb_mbuf_per_pool, MBUF_CACHE_SIZE, 0,
394 RTE_MBUF_DEFAULT_BUF_SIZE, socket_id);
396 TEST_ASSERT(test_params.mbuf_pool != NULL,
397 "rte_mempool_create failed\n");
400 /* Create / initialize ring eth devs. */
401 FOR_EACH_PORT(i, port) {
402 port = &test_params.slave_ports[i];
404 if (port->rx_queue == NULL) {
405 retval = snprintf(name, RTE_DIM(name), SLAVE_RX_QUEUE_FMT, i);
406 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
407 port->rx_queue = rte_ring_create(name, RX_RING_SIZE, socket_id, 0);
408 TEST_ASSERT(port->rx_queue != NULL,
409 "Failed to allocate rx ring '%s': %s", name,
410 rte_strerror(rte_errno));
413 if (port->tx_queue == NULL) {
414 retval = snprintf(name, RTE_DIM(name), SLAVE_TX_QUEUE_FMT, i);
415 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
416 port->tx_queue = rte_ring_create(name, TX_RING_SIZE, socket_id, 0);
417 TEST_ASSERT_NOT_NULL(port->tx_queue,
418 "Failed to allocate tx ring '%s': %s", name,
419 rte_strerror(rte_errno));
422 if (port->port_id == INVALID_PORT_ID) {
423 retval = snprintf(name, RTE_DIM(name), SLAVE_DEV_NAME_FMT, i);
424 TEST_ASSERT(retval < (int)RTE_DIM(name) - 1, "Name too long");
425 retval = rte_eth_from_rings(name, &port->rx_queue, 1,
426 &port->tx_queue, 1, socket_id);
427 TEST_ASSERT(retval >= 0,
428 "Failed to create ring ethdev '%s'\n", name);
430 port->port_id = rte_eth_dev_count_avail() - 1;
433 retval = configure_ethdev(port->port_id, 1);
434 TEST_ASSERT_SUCCESS(retval, "Failed to configure virtual ethdev %s\n",
438 if (test_params.bonded_port_id == INVALID_PORT_ID) {
439 retval = rte_eth_bond_create(BONDED_DEV_NAME, BONDING_MODE_8023AD,
442 TEST_ASSERT(retval >= 0, "Failed to create bonded ethdev %s",
445 test_params.bonded_port_id = retval;
446 TEST_ASSERT_SUCCESS(configure_ethdev(test_params.bonded_port_id, 0),
447 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME);
448 } else if (rte_eth_bond_mode_get(test_params.bonded_port_id) !=
449 BONDING_MODE_8023AD) {
450 TEST_ASSERT(rte_eth_bond_mode_set(test_params.bonded_port_id,
451 BONDING_MODE_8023AD) == 0,
452 "Failed to set ethdev %d to mode %d",
453 test_params.bonded_port_id, BONDING_MODE_8023AD);
460 testsuite_teardown(void)
462 struct slave_conf *port;
466 * Any cleanup/reset state is done when particular test is
469 rte_eth_dev_stop(test_params.bonded_port_id);
471 FOR_EACH_PORT(i, port)
472 rte_eth_dev_stop(port->port_id);
476 * Check if given LACP packet. If it is, make make replay packet to force
478 * return 0 when pkt is LACP frame, 1 if it is not slow frame, 2 if it is slow
482 make_lacp_reply(struct slave_conf *slave, struct rte_mbuf *pkt)
484 struct rte_ether_hdr *hdr;
485 struct slow_protocol_frame *slow_hdr;
489 hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
490 if (hdr->ether_type != rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW))
493 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
494 /* ignore packets of other types */
495 if (slow_hdr->slow_protocol.subtype != SLOW_SUBTYPE_LACP)
498 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
500 /* Change source address to partner address */
501 rte_ether_addr_copy(&parnter_mac_default, &slow_hdr->eth_hdr.s_addr);
502 slow_hdr->eth_hdr.s_addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
505 lacp = (struct lacpdu *) &slow_hdr->slow_protocol;
506 /* Save last received state */
507 slave->lacp_parnter_state = lacp->actor.state;
508 /* Change it into LACP replay by matching parameters. */
509 memcpy(&lacp->partner.port_params, &lacp->actor.port_params,
510 sizeof(struct port_params));
512 lacp->partner.state = lacp->actor.state;
514 rte_ether_addr_copy(&parnter_system, &lacp->actor.port_params.system);
515 lacp->actor.state = STATE_LACP_ACTIVE |
516 STATE_SYNCHRONIZATION |
525 * Reads packets from given slave, search for LACP packet and reply them.
527 * Receives burst of packets from slave. Looks for LACP packet. Drops
528 * all other packets. Prepares response LACP and sends it back.
530 * return number of LACP received and replied, -1 on error.
533 bond_handshake_reply(struct slave_conf *slave)
536 struct rte_mbuf *rx_buf[MAX_PKT_BURST];
537 struct rte_mbuf *lacp_tx_buf[MAX_PKT_BURST];
538 uint16_t lacp_tx_buf_cnt = 0, i;
540 retval = slave_get_pkts(slave, rx_buf, RTE_DIM(rx_buf));
541 TEST_ASSERT(retval >= 0, "Getting slave %u packets failed.",
544 for (i = 0; i < (uint16_t)retval; i++) {
545 if (make_lacp_reply(slave, rx_buf[i]) == 0) {
546 /* reply with actor's LACP */
547 lacp_tx_buf[lacp_tx_buf_cnt++] = rx_buf[i];
549 rte_pktmbuf_free(rx_buf[i]);
552 if (lacp_tx_buf_cnt == 0)
555 retval = slave_put_pkts(slave, lacp_tx_buf, lacp_tx_buf_cnt);
556 if (retval <= lacp_tx_buf_cnt) {
557 /* retval might be negative */
558 for (i = RTE_MAX(0, retval); retval < lacp_tx_buf_cnt; retval++)
559 rte_pktmbuf_free(lacp_tx_buf[i]);
562 TEST_ASSERT_EQUAL(retval, lacp_tx_buf_cnt,
563 "Failed to equeue lacp packets into slave %u tx queue.",
566 return lacp_tx_buf_cnt;
570 * Function check if given slave tx queue contains packets that make mode 4
571 * handshake complete. It will drain slave queue.
572 * return 0 if handshake not completed, 1 if handshake was complete,
575 bond_handshake_done(struct slave_conf *slave)
577 const uint8_t expected_state = STATE_LACP_ACTIVE | STATE_SYNCHRONIZATION |
578 STATE_AGGREGATION | STATE_COLLECTING | STATE_DISTRIBUTING;
580 return slave->lacp_parnter_state == expected_state;
584 bond_get_update_timeout_ms(void)
586 struct rte_eth_bond_8023ad_conf conf;
588 if (rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf) < 0) {
589 RTE_LOG(DEBUG, EAL, "Failed to get bonding configuration: "
590 "%s at %d\n", __func__, __LINE__);
591 RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__);
595 return conf.update_timeout_ms;
599 * Exchanges LACP packets with partner to achieve dynamic port configuration.
600 * return TEST_SUCCESS if initial handshake succeed, TEST_FAILED otherwise.
605 struct slave_conf *slave;
606 struct rte_mbuf *buf[MAX_PKT_BURST];
608 uint8_t all_slaves_done, i, j;
609 uint8_t status[RTE_DIM(test_params.slave_ports)] = { 0 };
610 const unsigned delay = bond_get_update_timeout_ms();
612 /* Exchange LACP frames */
614 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
618 FOR_EACH_SLAVE(j, slave) {
619 /* If response already send, skip slave */
623 if (bond_handshake_reply(slave) < 0) {
628 status[j] = bond_handshake_done(slave);
633 nb_pkts = bond_tx(NULL, 0);
634 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
636 nb_pkts = bond_rx(buf, RTE_DIM(buf));
637 free_pkts(buf, nb_pkts);
638 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
640 /* If response didn't send - report failure */
641 TEST_ASSERT_EQUAL(all_slaves_done, 1, "Bond handshake failed\n");
643 /* If flags doesn't match - report failure */
644 return all_slaves_done == 1 ? TEST_SUCCESS : TEST_FAILED;
647 #define TEST_LACP_SLAVE_COUT RTE_DIM(test_params.slave_ports)
649 test_mode4_lacp(void)
653 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
654 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
656 /* Test LACP handshake function */
657 retval = bond_handshake();
658 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
660 retval = remove_slaves_and_stop_bonded_device();
661 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
666 test_mode4_agg_mode_selection(void)
669 /* Test and verify for Stable mode */
670 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
671 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
674 retval = rte_eth_bond_8023ad_agg_selection_set(
675 test_params.bonded_port_id, AGG_STABLE);
676 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bond aggregation mode");
677 retval = bond_handshake();
678 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
681 retval = rte_eth_bond_8023ad_agg_selection_get(
682 test_params.bonded_port_id);
683 TEST_ASSERT_EQUAL(retval, AGG_STABLE,
684 "Wrong agg mode received from bonding device");
686 retval = remove_slaves_and_stop_bonded_device();
687 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
690 /* test and verify for Bandwidth mode */
691 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
692 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
695 retval = rte_eth_bond_8023ad_agg_selection_set(
696 test_params.bonded_port_id,
698 TEST_ASSERT_SUCCESS(retval,
699 "Failed to initialize bond aggregation mode");
700 retval = bond_handshake();
701 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
703 retval = rte_eth_bond_8023ad_agg_selection_get(
704 test_params.bonded_port_id);
705 TEST_ASSERT_EQUAL(retval, AGG_BANDWIDTH,
706 "Wrong agg mode received from bonding device");
708 retval = remove_slaves_and_stop_bonded_device();
709 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
711 /* test and verify selection for count mode */
712 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
713 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
716 retval = rte_eth_bond_8023ad_agg_selection_set(
717 test_params.bonded_port_id, AGG_COUNT);
718 TEST_ASSERT_SUCCESS(retval,
719 "Failed to initialize bond aggregation mode");
720 retval = bond_handshake();
721 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
723 retval = rte_eth_bond_8023ad_agg_selection_get(
724 test_params.bonded_port_id);
725 TEST_ASSERT_EQUAL(retval, AGG_COUNT,
726 "Wrong agg mode received from bonding device");
728 retval = remove_slaves_and_stop_bonded_device();
729 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
735 generate_packets(struct rte_ether_addr *src_mac,
736 struct rte_ether_addr *dst_mac, uint16_t count, struct rte_mbuf **buf)
738 uint16_t pktlen = PACKET_BURST_GEN_PKT_LEN;
739 uint8_t vlan_enable = 0;
740 uint16_t vlan_id = 0;
741 uint8_t ip4_type = 1; /* 0 - ipv6 */
743 uint16_t src_port = 10, dst_port = 20;
745 uint32_t ip_src[4] = { [0 ... 2] = 0xDEADBEEF, [3] = RTE_IPV4(192, 168, 0, 1) };
746 uint32_t ip_dst[4] = { [0 ... 2] = 0xFEEDFACE, [3] = RTE_IPV4(192, 168, 0, 2) };
748 struct rte_ether_hdr pkt_eth_hdr;
749 struct rte_udp_hdr pkt_udp_hdr;
751 struct rte_ipv4_hdr v4;
752 struct rte_ipv6_hdr v6;
757 initialize_eth_header(&pkt_eth_hdr, src_mac, dst_mac, ip4_type,
758 vlan_enable, vlan_id);
761 initialize_ipv4_header(&pkt_ip_hdr.v4, ip_src[3], ip_dst[3], pktlen);
763 initialize_ipv6_header(&pkt_ip_hdr.v6, (uint8_t *)ip_src,
764 (uint8_t *)&ip_dst, pktlen);
766 initialize_udp_header(&pkt_udp_hdr, src_port, dst_port, 16);
768 retval = generate_packet_burst(test_params.mbuf_pool, buf,
769 &pkt_eth_hdr, vlan_enable, &pkt_ip_hdr, 1, &pkt_udp_hdr,
772 if (retval > 0 && retval != count)
773 free_pkts(&buf[count - retval], retval);
775 TEST_ASSERT_EQUAL(retval, count, "Failed to generate %u packets",
782 generate_and_put_packets(struct slave_conf *slave,
783 struct rte_ether_addr *src_mac,
784 struct rte_ether_addr *dst_mac, uint16_t count)
786 struct rte_mbuf *pkts[MAX_PKT_BURST];
789 retval = generate_packets(src_mac, dst_mac, count, pkts);
790 if (retval != (int)count)
793 retval = slave_put_pkts(slave, pkts, count);
794 if (retval > 0 && retval != count)
795 free_pkts(&pkts[retval], count - retval);
797 TEST_ASSERT_EQUAL(retval, count,
798 "Failed to enqueue packets into slave %u RX queue", slave->port_id);
806 struct slave_conf *slave;
809 uint16_t expected_pkts_cnt;
810 struct rte_mbuf *pkts[MAX_PKT_BURST];
814 struct rte_ether_hdr *hdr;
816 struct rte_ether_addr src_mac = {
817 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
818 struct rte_ether_addr dst_mac;
819 struct rte_ether_addr bonded_mac;
821 retval = initialize_bonded_device_with_slaves(TEST_PROMISC_SLAVE_COUNT,
823 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
825 retval = bond_handshake();
826 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
828 retval = rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
829 TEST_ASSERT_SUCCESS(retval, "Failed to get mac address: %s",
831 rte_ether_addr_copy(&bonded_mac, &dst_mac);
833 /* Assert that dst address is not bonding address. Do not set the
834 * least significant bit of the zero byte as this would create a
837 dst_mac.addr_bytes[0] += 2;
839 /* First try with promiscuous mode enabled.
840 * Add 2 packets to each slave. First with bonding MAC address, second with
841 * different. Check if we received all of them. */
842 retval = rte_eth_promiscuous_enable(test_params.bonded_port_id);
843 TEST_ASSERT_SUCCESS(retval,
844 "Failed to enable promiscuous mode for port %d: %s",
845 test_params.bonded_port_id, rte_strerror(-retval));
847 expected_pkts_cnt = 0;
848 FOR_EACH_SLAVE(i, slave) {
849 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
850 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
853 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
854 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
857 /* Expect 2 packets per slave */
858 expected_pkts_cnt += 2;
861 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
864 if (retval == expected_pkts_cnt) {
865 int cnt[2] = { 0, 0 };
867 for (i = 0; i < expected_pkts_cnt; i++) {
868 hdr = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *);
869 cnt[rte_is_same_ether_addr(&hdr->d_addr,
873 free_pkts(pkts, expected_pkts_cnt);
875 /* For division by 2 expected_pkts_cnt must be even */
876 RTE_VERIFY((expected_pkts_cnt & 1) == 0);
877 TEST_ASSERT(cnt[0] == expected_pkts_cnt / 2 &&
878 cnt[1] == expected_pkts_cnt / 2,
879 "Expected %u packets with the same MAC and %u with different but "
880 "got %u with the same and %u with different MAC",
881 expected_pkts_cnt / 2, expected_pkts_cnt / 2, cnt[1], cnt[0]);
882 } else if (retval > 0)
883 free_pkts(pkts, retval);
885 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
886 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
888 /* Now, disable promiscuous mode. When promiscuous mode is disabled we
889 * expect to receive only packets that are directed to bonding port. */
890 retval = rte_eth_promiscuous_disable(test_params.bonded_port_id);
891 TEST_ASSERT_SUCCESS(retval,
892 "Failed to disable promiscuous mode for port %d: %s",
893 test_params.bonded_port_id, rte_strerror(-retval));
895 expected_pkts_cnt = 0;
896 FOR_EACH_SLAVE(i, slave) {
897 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
898 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
901 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
902 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
905 /* Expect only one packet per slave */
906 expected_pkts_cnt += 1;
909 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
912 if (retval == expected_pkts_cnt) {
915 for (i = 0; i < expected_pkts_cnt; i++) {
916 hdr = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *);
917 eq_cnt += rte_is_same_ether_addr(&hdr->d_addr,
921 free_pkts(pkts, expected_pkts_cnt);
922 TEST_ASSERT_EQUAL(eq_cnt, expected_pkts_cnt, "Packet address mismatch");
923 } else if (retval > 0)
924 free_pkts(pkts, retval);
926 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
927 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
929 /* Link down test: simulate link down for first slave. */
930 delay = bond_get_update_timeout_ms();
932 uint8_t slave_down_id = INVALID_PORT_ID;
934 /* Find first slave and make link down on it*/
935 FOR_EACH_SLAVE(i, slave) {
936 rte_eth_dev_set_link_down(slave->port_id);
937 slave_down_id = slave->port_id;
941 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
943 /* Give some time to rearrange bonding */
944 for (i = 0; i < 3; i++) {
949 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
951 /* Put packet to each slave */
952 FOR_EACH_SLAVE(i, slave) {
955 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
956 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
957 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
959 src_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
960 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
961 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
963 retval = bond_rx(pkts, RTE_DIM(pkts));
967 free_pkts(pkts, retval);
969 while (rte_ring_dequeue(slave->rx_queue, (void **)&pkt) == 0)
970 rte_pktmbuf_free(pkt);
972 if (slave_down_id == slave->port_id)
973 TEST_ASSERT_EQUAL(retval, 0, "Packets received unexpectedly.");
975 TEST_ASSERT_NOT_EQUAL(retval, 0,
976 "Expected to receive some packets on slave %u.",
978 rte_eth_dev_start(slave->port_id);
980 for (j = 0; j < 5; j++) {
981 TEST_ASSERT(bond_handshake_reply(slave) >= 0,
982 "Handshake after link up");
984 if (bond_handshake_done(slave) == 1)
988 TEST_ASSERT(j < 5, "Failed to aggregate slave after link up");
991 remove_slaves_and_stop_bonded_device();
996 test_mode4_tx_burst(void)
998 struct slave_conf *slave;
1001 uint16_t exp_pkts_cnt, pkts_cnt = 0;
1002 struct rte_mbuf *pkts[MAX_PKT_BURST];
1006 struct rte_ether_addr dst_mac = {
1007 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
1008 struct rte_ether_addr bonded_mac;
1010 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1011 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1013 retval = bond_handshake();
1014 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1016 retval = rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
1017 TEST_ASSERT_SUCCESS(retval, "Failed to get mac address: %s",
1020 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1021 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = pkts_cnt;
1022 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1025 free_pkts(pkts, pkts_cnt);
1027 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate packet %u", pkts_cnt);
1029 exp_pkts_cnt = pkts_cnt;
1031 /* Transmit packets on bonded device */
1032 retval = bond_tx(pkts, pkts_cnt);
1033 if (retval > 0 && retval < pkts_cnt)
1034 free_pkts(&pkts[retval], pkts_cnt - retval);
1036 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1038 /* Check if packets were transmitted properly. Every slave should have
1039 * at least one packet, and sum must match. Under normal operation
1040 * there should be no LACP nor MARKER frames. */
1042 FOR_EACH_SLAVE(i, slave) {
1043 uint16_t normal_cnt, slow_cnt;
1045 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1049 for (j = 0; j < retval; j++) {
1050 if (make_lacp_reply(slave, pkts[j]) == 1)
1056 free_pkts(pkts, normal_cnt + slow_cnt);
1057 TEST_ASSERT_EQUAL(slow_cnt, 0,
1058 "slave %u unexpectedly transmitted %d SLOW packets", slave->port_id,
1061 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1062 "slave %u did not transmitted any packets", slave->port_id);
1064 pkts_cnt += normal_cnt;
1067 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1068 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1071 * simulate link down for first slave. */
1072 delay = bond_get_update_timeout_ms();
1074 uint8_t slave_down_id = INVALID_PORT_ID;
1076 FOR_EACH_SLAVE(i, slave) {
1077 rte_eth_dev_set_link_down(slave->port_id);
1078 slave_down_id = slave->port_id;
1082 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
1084 /* Give some time to rearrange bonding. */
1085 for (i = 0; i < 3; i++) {
1087 rte_delay_ms(delay);
1090 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
1092 /* Prepare burst. */
1093 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1094 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = pkts_cnt;
1095 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1098 free_pkts(pkts, pkts_cnt);
1100 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate test packet %u",
1103 exp_pkts_cnt = pkts_cnt;
1105 /* Transmit packets on bonded device. */
1106 retval = bond_tx(pkts, pkts_cnt);
1107 if (retval > 0 && retval < pkts_cnt)
1108 free_pkts(&pkts[retval], pkts_cnt - retval);
1110 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1112 /* Check if packets was transmitted properly. Every slave should have
1113 * at least one packet, and sum must match. Under normal operation
1114 * there should be no LACP nor MARKER frames. */
1116 FOR_EACH_SLAVE(i, slave) {
1117 uint16_t normal_cnt, slow_cnt;
1119 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1123 for (j = 0; j < retval; j++) {
1124 if (make_lacp_reply(slave, pkts[j]) == 1)
1130 free_pkts(pkts, normal_cnt + slow_cnt);
1132 if (slave_down_id == slave->port_id) {
1133 TEST_ASSERT_EQUAL(normal_cnt + slow_cnt, 0,
1134 "slave %u enexpectedly transmitted %u packets",
1135 normal_cnt + slow_cnt, slave->port_id);
1137 TEST_ASSERT_EQUAL(slow_cnt, 0,
1138 "slave %u unexpectedly transmitted %d SLOW packets",
1139 slave->port_id, slow_cnt);
1141 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1142 "slave %u did not transmitted any packets", slave->port_id);
1145 pkts_cnt += normal_cnt;
1148 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1149 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1151 return remove_slaves_and_stop_bonded_device();
1155 init_marker(struct rte_mbuf *pkt, struct slave_conf *slave)
1157 struct marker_header *marker_hdr = rte_pktmbuf_mtod(pkt,
1158 struct marker_header *);
1160 /* Copy multicast destination address */
1161 rte_ether_addr_copy(&slow_protocol_mac_addr,
1162 &marker_hdr->eth_hdr.d_addr);
1164 /* Init source address */
1165 rte_ether_addr_copy(&parnter_mac_default, &marker_hdr->eth_hdr.s_addr);
1166 marker_hdr->eth_hdr.s_addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
1169 marker_hdr->eth_hdr.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW);
1171 marker_hdr->marker.subtype = SLOW_SUBTYPE_MARKER;
1172 marker_hdr->marker.version_number = 1;
1173 marker_hdr->marker.tlv_type_marker = MARKER_TLV_TYPE_INFO;
1174 marker_hdr->marker.info_length =
1175 offsetof(struct marker, reserved_90) -
1176 offsetof(struct marker, requester_port);
1177 RTE_VERIFY(marker_hdr->marker.info_length == 16);
1178 marker_hdr->marker.requester_port = slave->port_id + 1;
1179 marker_hdr->marker.tlv_type_terminator = TLV_TYPE_TERMINATOR_INFORMATION;
1180 marker_hdr->marker.terminator_length = 0;
1184 test_mode4_marker(void)
1186 struct slave_conf *slave;
1187 struct rte_mbuf *pkts[MAX_PKT_BURST];
1188 struct rte_mbuf *marker_pkt;
1189 struct marker_header *marker_hdr;
1195 const uint16_t ethtype_slow_be = rte_be_to_cpu_16(RTE_ETHER_TYPE_SLOW);
1197 retval = initialize_bonded_device_with_slaves(TEST_MARKER_SLAVE_COUT,
1199 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1201 /* Test LACP handshake function */
1202 retval = bond_handshake();
1203 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1205 delay = bond_get_update_timeout_ms();
1206 FOR_EACH_SLAVE(i, slave) {
1207 marker_pkt = rte_pktmbuf_alloc(test_params.mbuf_pool);
1208 TEST_ASSERT_NOT_NULL(marker_pkt, "Failed to allocate marker packet");
1209 init_marker(marker_pkt, slave);
1211 retval = slave_put_pkts(slave, &marker_pkt, 1);
1213 rte_pktmbuf_free(marker_pkt);
1215 TEST_ASSERT_EQUAL(retval, 1,
1216 "Failed to send marker packet to slave %u", slave->port_id);
1218 for (j = 0; j < 20; ++j) {
1219 rte_delay_ms(delay);
1220 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
1224 free_pkts(pkts, retval);
1226 TEST_ASSERT_EQUAL(retval, 0, "Received packets unexpectedly");
1228 retval = rte_eth_tx_burst(test_params.bonded_port_id, 0, NULL, 0);
1229 TEST_ASSERT_EQUAL(retval, 0,
1230 "Requested TX of 0 packets but %d transmitted", retval);
1232 /* Check if LACP packet was send by state machines
1233 First and only packet must be a maker response */
1234 retval = slave_get_pkts(slave, pkts, MAX_PKT_BURST);
1238 free_pkts(pkts, retval);
1240 TEST_ASSERT_EQUAL(retval, 1, "failed to get slave packets");
1243 marker_hdr = rte_pktmbuf_mtod(pkts[0], struct marker_header *);
1244 /* Check if it's slow packet*/
1245 if (marker_hdr->eth_hdr.ether_type != ethtype_slow_be)
1247 /* Check if it's marker packet */
1248 else if (marker_hdr->marker.subtype != SLOW_SUBTYPE_MARKER)
1250 else if (marker_hdr->marker.tlv_type_marker != MARKER_TLV_TYPE_RESP)
1253 free_pkts(pkts, nb_pkts);
1255 TEST_ASSERT_NOT_EQUAL(retval, -1, "Unexpected protocol type");
1256 TEST_ASSERT_NOT_EQUAL(retval, -2, "Unexpected sub protocol type");
1257 TEST_ASSERT_NOT_EQUAL(retval, -3, "Unexpected marker type");
1261 TEST_ASSERT(j < 20, "Marker response not found");
1264 retval = remove_slaves_and_stop_bonded_device();
1265 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1267 return TEST_SUCCESS;
1271 test_mode4_expired(void)
1273 struct slave_conf *slave, *exp_slave = NULL;
1274 struct rte_mbuf *pkts[MAX_PKT_BURST];
1281 struct rte_eth_bond_8023ad_conf conf;
1283 retval = initialize_bonded_device_with_slaves(TEST_EXPIRED_SLAVE_COUNT,
1285 /* Set custom timeouts to make test last shorter. */
1286 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
1287 conf.fast_periodic_ms = 100;
1288 conf.slow_periodic_ms = 600;
1289 conf.short_timeout_ms = 300;
1290 conf.long_timeout_ms = 900;
1291 conf.aggregate_wait_timeout_ms = 200;
1292 conf.tx_period_ms = 100;
1293 old_delay = conf.update_timeout_ms;
1294 conf.update_timeout_ms = 10;
1295 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
1297 /* Wait for new settings to be applied. */
1298 for (i = 0; i < old_delay/conf.update_timeout_ms * 2; i++) {
1299 FOR_EACH_SLAVE(j, slave)
1300 bond_handshake_reply(slave);
1302 rte_delay_ms(conf.update_timeout_ms);
1305 retval = bond_handshake();
1306 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1308 /* Find first slave */
1309 FOR_EACH_SLAVE(i, slave) {
1314 RTE_VERIFY(exp_slave != NULL);
1316 /* When one of partners do not send or respond to LACP frame in
1317 * conf.long_timeout_ms time, internal state machines should detect this
1318 * and transit to expired state. */
1319 for (j = 0; j < conf.long_timeout_ms/conf.update_timeout_ms + 2; j++) {
1320 rte_delay_ms(conf.update_timeout_ms);
1322 retval = bond_tx(NULL, 0);
1323 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1326 FOR_EACH_SLAVE(i, slave) {
1327 retval = bond_handshake_reply(slave);
1328 TEST_ASSERT(retval >= 0, "Handshake failed");
1330 /* Remove replay for slave that suppose to be expired. */
1331 if (slave == exp_slave) {
1332 while (rte_ring_count(slave->rx_queue) > 0) {
1335 rte_ring_dequeue(slave->rx_queue, &pkt);
1336 rte_pktmbuf_free(pkt);
1341 retval = bond_rx(pkts, RTE_DIM(pkts));
1343 free_pkts(pkts, retval);
1345 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1349 /* After test only expected slave should be in EXPIRED state */
1350 FOR_EACH_SLAVE(i, slave) {
1351 if (slave == exp_slave)
1352 TEST_ASSERT(slave->lacp_parnter_state & STATE_EXPIRED,
1353 "Slave %u should be in expired.", slave->port_id);
1355 TEST_ASSERT_EQUAL(bond_handshake_done(slave), 1,
1356 "Slave %u should be operational.", slave->port_id);
1359 retval = remove_slaves_and_stop_bonded_device();
1360 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1362 return TEST_SUCCESS;
1366 test_mode4_ext_ctrl(void)
1369 * configure bonded interface without the external sm enabled
1370 * . try to transmit lacpdu (should fail)
1371 * . try to set collecting and distributing flags (should fail)
1372 * reconfigure w/external sm
1373 * . transmit one lacpdu on each slave using new api
1374 * . make sure each slave receives one lacpdu using the callback api
1375 * . transmit one data pdu on each slave (should fail)
1376 * . enable distribution and collection, send one data pdu each again
1380 struct slave_conf *slave = NULL;
1383 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1384 struct rte_ether_addr src_mac, dst_mac;
1385 struct lacpdu_header lacpdu = {
1387 .subtype = SLOW_SUBTYPE_LACP,
1391 rte_ether_addr_copy(&parnter_system, &src_mac);
1392 rte_ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1394 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1395 RTE_ETHER_TYPE_SLOW, 0, 0);
1397 for (i = 0; i < SLAVE_COUNT; i++) {
1398 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1399 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1400 &lacpdu, sizeof(lacpdu));
1401 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1404 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1405 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1407 FOR_EACH_SLAVE(i, slave) {
1408 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_slowtx(
1409 test_params.bonded_port_id,
1410 slave->port_id, lacp_tx_buf[i]),
1411 "Slave should not allow manual LACP xmit");
1412 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_collect(
1413 test_params.bonded_port_id,
1415 "Slave should not allow external state controls");
1418 free_pkts(lacp_tx_buf, RTE_DIM(lacp_tx_buf));
1420 retval = remove_slaves_and_stop_bonded_device();
1421 TEST_ASSERT_SUCCESS(retval, "Bonded device cleanup failed.");
1423 return TEST_SUCCESS;
1428 test_mode4_ext_lacp(void)
1431 struct slave_conf *slave = NULL;
1432 uint8_t all_slaves_done = 0, i;
1434 const unsigned int delay = bond_get_update_timeout_ms();
1436 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1437 struct rte_mbuf *buf[SLAVE_COUNT];
1438 struct rte_ether_addr src_mac, dst_mac;
1439 struct lacpdu_header lacpdu = {
1441 .subtype = SLOW_SUBTYPE_LACP,
1445 rte_ether_addr_copy(&parnter_system, &src_mac);
1446 rte_ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1448 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1449 RTE_ETHER_TYPE_SLOW, 0, 0);
1451 for (i = 0; i < SLAVE_COUNT; i++) {
1452 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1453 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1454 &lacpdu, sizeof(lacpdu));
1455 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1458 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 1);
1459 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1461 memset(lacpdu_rx_count, 0, sizeof(lacpdu_rx_count));
1463 /* Wait for new settings to be applied. */
1464 for (i = 0; i < 30; ++i)
1465 rte_delay_ms(delay);
1467 FOR_EACH_SLAVE(i, slave) {
1468 retval = rte_eth_bond_8023ad_ext_slowtx(
1469 test_params.bonded_port_id,
1470 slave->port_id, lacp_tx_buf[i]);
1471 TEST_ASSERT_SUCCESS(retval,
1472 "Slave should allow manual LACP xmit");
1475 nb_pkts = bond_tx(NULL, 0);
1476 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
1478 FOR_EACH_SLAVE(i, slave) {
1479 nb_pkts = slave_get_pkts(slave, buf, RTE_DIM(buf));
1480 TEST_ASSERT_EQUAL(nb_pkts, 1, "found %u packets on slave %d\n",
1482 slave_put_pkts(slave, buf, nb_pkts);
1485 nb_pkts = bond_rx(buf, RTE_DIM(buf));
1486 free_pkts(buf, nb_pkts);
1487 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
1489 /* wait for the periodic callback to run */
1490 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
1491 uint8_t s, total = 0;
1493 rte_delay_ms(delay);
1494 FOR_EACH_SLAVE(s, slave) {
1495 total += lacpdu_rx_count[slave->port_id];
1498 if (total >= SLAVE_COUNT)
1499 all_slaves_done = 1;
1502 FOR_EACH_SLAVE(i, slave) {
1503 TEST_ASSERT_EQUAL(lacpdu_rx_count[slave->port_id], 1,
1504 "Slave port %u should have received 1 lacpdu (count=%u)",
1506 lacpdu_rx_count[slave->port_id]);
1509 retval = remove_slaves_and_stop_bonded_device();
1510 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1512 return TEST_SUCCESS;
1516 check_environment(void)
1518 struct slave_conf *port;
1519 uint8_t i, env_state;
1520 uint16_t slaves[RTE_DIM(test_params.slave_ports)];
1524 FOR_EACH_PORT(i, port) {
1525 if (rte_ring_count(port->rx_queue) != 0)
1528 if (rte_ring_count(port->tx_queue) != 0)
1531 if (port->bonded != 0)
1534 if (port->lacp_parnter_state != 0)
1541 slaves_count = rte_eth_bond_slaves_get(test_params.bonded_port_id,
1542 slaves, RTE_DIM(slaves));
1544 if (slaves_count != 0)
1547 TEST_ASSERT_EQUAL(env_state, 0,
1548 "Environment not clean (port %u):%s%s%s%s%s",
1550 env_state & 0x01 ? " slave rx queue not clean" : "",
1551 env_state & 0x02 ? " slave tx queue not clean" : "",
1552 env_state & 0x04 ? " port marked as enslaved" : "",
1553 env_state & 0x80 ? " slave state is not reset" : "",
1554 env_state & 0x10 ? " slave count not equal 0" : ".");
1557 return TEST_SUCCESS;
1561 test_mode4_executor(int (*test_func)(void))
1563 struct slave_conf *port;
1568 /* Check if environment is clean. Fail to launch a test if there was
1569 * a critical error before that prevented to reset environment. */
1570 TEST_ASSERT_SUCCESS(check_environment(),
1571 "Refusing to launch test in dirty environment.");
1573 RTE_VERIFY(test_func != NULL);
1574 test_result = (*test_func)();
1576 /* If test succeed check if environment wast left in good condition. */
1577 if (test_result == TEST_SUCCESS)
1578 test_result = check_environment();
1580 /* Reset environment in case test failed to do that. */
1581 if (test_result != TEST_SUCCESS) {
1582 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
1583 "Failed to stop bonded device");
1585 FOR_EACH_PORT(i, port) {
1586 while (rte_ring_count(port->rx_queue) != 0) {
1587 if (rte_ring_dequeue(port->rx_queue, &pkt) == 0)
1588 rte_pktmbuf_free(pkt);
1591 while (rte_ring_count(port->tx_queue) != 0) {
1592 if (rte_ring_dequeue(port->tx_queue, &pkt) == 0)
1593 rte_pktmbuf_free(pkt);
1602 test_mode4_agg_mode_selection_wrapper(void){
1603 return test_mode4_executor(&test_mode4_agg_mode_selection);
1607 test_mode4_lacp_wrapper(void)
1609 return test_mode4_executor(&test_mode4_lacp);
1613 test_mode4_marker_wrapper(void)
1615 return test_mode4_executor(&test_mode4_marker);
1619 test_mode4_rx_wrapper(void)
1621 return test_mode4_executor(&test_mode4_rx);
1625 test_mode4_tx_burst_wrapper(void)
1627 return test_mode4_executor(&test_mode4_tx_burst);
1631 test_mode4_expired_wrapper(void)
1633 return test_mode4_executor(&test_mode4_expired);
1637 test_mode4_ext_ctrl_wrapper(void)
1639 return test_mode4_executor(&test_mode4_ext_ctrl);
1643 test_mode4_ext_lacp_wrapper(void)
1645 return test_mode4_executor(&test_mode4_ext_lacp);
1648 static struct unit_test_suite link_bonding_mode4_test_suite = {
1649 .suite_name = "Link Bonding mode 4 Unit Test Suite",
1650 .setup = test_setup,
1651 .teardown = testsuite_teardown,
1652 .unit_test_cases = {
1653 TEST_CASE_NAMED("test_mode4_agg_mode_selection",
1654 test_mode4_agg_mode_selection_wrapper),
1655 TEST_CASE_NAMED("test_mode4_lacp", test_mode4_lacp_wrapper),
1656 TEST_CASE_NAMED("test_mode4_rx", test_mode4_rx_wrapper),
1657 TEST_CASE_NAMED("test_mode4_tx_burst", test_mode4_tx_burst_wrapper),
1658 TEST_CASE_NAMED("test_mode4_marker", test_mode4_marker_wrapper),
1659 TEST_CASE_NAMED("test_mode4_expired", test_mode4_expired_wrapper),
1660 TEST_CASE_NAMED("test_mode4_ext_ctrl",
1661 test_mode4_ext_ctrl_wrapper),
1662 TEST_CASE_NAMED("test_mode4_ext_lacp",
1663 test_mode4_ext_lacp_wrapper),
1665 TEST_CASES_END() /**< NULL terminate unit test array */
1670 test_link_bonding_mode4(void)
1672 return unit_test_suite_runner(&link_bonding_mode4_test_suite);
1675 REGISTER_TEST_COMMAND(link_bonding_mode4_autotest, test_link_bonding_mode4);