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;
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 rte_eth_macaddr_get(slave->port_id, &addr_check);
256 TEST_ASSERT_EQUAL(rte_is_same_ether_addr(&addr, &addr_check), 1,
257 "Slave MAC address is not as expected");
259 RTE_VERIFY(slave->lacp_parnter_state == 0);
264 remove_slave(struct slave_conf *slave)
266 ptrdiff_t slave_idx = slave - test_params.slave_ports;
268 RTE_VERIFY(test_params.slave_ports <= slave &&
269 slave_idx < (ptrdiff_t)RTE_DIM(test_params.slave_ports));
271 RTE_VERIFY(slave->bonded == 1);
272 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
274 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
275 "Slave %u tx queue not empty while removing from bonding.",
278 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
279 "Slave %u tx queue not empty while removing from bonding.",
282 TEST_ASSERT_EQUAL(rte_eth_bond_slave_remove(test_params.bonded_port_id,
284 "Failed to remove slave (idx=%u, id=%u) from bonding (id=%u)",
285 (uint8_t)slave_idx, slave->port_id,
286 test_params.bonded_port_id);
289 slave->lacp_parnter_state = 0;
294 lacp_recv_cb(uint16_t slave_id, struct rte_mbuf *lacp_pkt)
296 struct rte_ether_hdr *hdr;
297 struct slow_protocol_frame *slow_hdr;
299 RTE_VERIFY(lacp_pkt != NULL);
301 hdr = rte_pktmbuf_mtod(lacp_pkt, struct rte_ether_hdr *);
302 RTE_VERIFY(hdr->ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW));
304 slow_hdr = rte_pktmbuf_mtod(lacp_pkt, struct slow_protocol_frame *);
305 RTE_VERIFY(slow_hdr->slow_protocol.subtype == SLOW_SUBTYPE_LACP);
307 lacpdu_rx_count[slave_id]++;
308 rte_pktmbuf_free(lacp_pkt);
312 initialize_bonded_device_with_slaves(uint16_t slave_count, uint8_t external_sm)
317 RTE_VERIFY(test_params.bonded_port_id != INVALID_PORT_ID);
319 for (i = 0; i < slave_count; i++) {
320 TEST_ASSERT_SUCCESS(add_slave(&test_params.slave_ports[i], 1),
321 "Failed to add port %u to bonded device.\n",
322 test_params.slave_ports[i].port_id);
325 /* Reset mode 4 configuration */
326 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, NULL);
327 ret = rte_eth_promiscuous_disable(test_params.bonded_port_id);
328 TEST_ASSERT_SUCCESS(ret,
329 "Failed disable promiscuous mode for port %d: %s",
330 test_params.bonded_port_id, rte_strerror(-ret));
333 struct rte_eth_bond_8023ad_conf conf;
335 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
336 conf.slowrx_cb = lacp_recv_cb;
337 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
341 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params.bonded_port_id),
342 "Failed to start bonded device");
348 remove_slaves_and_stop_bonded_device(void)
350 struct slave_conf *slave;
352 uint16_t slaves[RTE_MAX_ETHPORTS];
355 rte_eth_dev_stop(test_params.bonded_port_id);
357 FOR_EACH_SLAVE(i, slave)
360 retval = rte_eth_bond_slaves_get(test_params.bonded_port_id, slaves,
363 TEST_ASSERT_EQUAL(retval, 0,
364 "Expected bonded device %u have 0 slaves but returned %d.",
365 test_params.bonded_port_id, retval);
367 FOR_EACH_PORT(i, slave) {
368 rte_eth_dev_stop(slave->port_id);
370 TEST_ASSERT(slave->bonded == 0,
371 "Port id=%u is still marked as enslaved.", slave->port_id);
380 int retval, nb_mbuf_per_pool;
381 char name[RTE_ETH_NAME_MAX_LEN];
382 struct slave_conf *port;
383 const uint8_t socket_id = rte_socket_id();
386 if (test_params.mbuf_pool == NULL) {
387 nb_mbuf_per_pool = TEST_RX_DESC_MAX + DEF_PKT_BURST +
388 TEST_TX_DESC_MAX + MAX_PKT_BURST;
389 test_params.mbuf_pool = rte_pktmbuf_pool_create("TEST_MODE4",
390 nb_mbuf_per_pool, MBUF_CACHE_SIZE, 0,
391 RTE_MBUF_DEFAULT_BUF_SIZE, socket_id);
393 TEST_ASSERT(test_params.mbuf_pool != NULL,
394 "rte_mempool_create failed\n");
397 /* Create / initialize ring eth devs. */
398 FOR_EACH_PORT(i, port) {
399 port = &test_params.slave_ports[i];
401 if (port->rx_queue == NULL) {
402 retval = snprintf(name, RTE_DIM(name), SLAVE_RX_QUEUE_FMT, i);
403 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
404 port->rx_queue = rte_ring_create(name, RX_RING_SIZE, socket_id, 0);
405 TEST_ASSERT(port->rx_queue != NULL,
406 "Failed to allocate rx ring '%s': %s", name,
407 rte_strerror(rte_errno));
410 if (port->tx_queue == NULL) {
411 retval = snprintf(name, RTE_DIM(name), SLAVE_TX_QUEUE_FMT, i);
412 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
413 port->tx_queue = rte_ring_create(name, TX_RING_SIZE, socket_id, 0);
414 TEST_ASSERT_NOT_NULL(port->tx_queue,
415 "Failed to allocate tx ring '%s': %s", name,
416 rte_strerror(rte_errno));
419 if (port->port_id == INVALID_PORT_ID) {
420 retval = snprintf(name, RTE_DIM(name), SLAVE_DEV_NAME_FMT, i);
421 TEST_ASSERT(retval < (int)RTE_DIM(name) - 1, "Name too long");
422 retval = rte_eth_from_rings(name, &port->rx_queue, 1,
423 &port->tx_queue, 1, socket_id);
424 TEST_ASSERT(retval >= 0,
425 "Failed to create ring ethdev '%s'\n", name);
427 port->port_id = rte_eth_dev_count_avail() - 1;
430 retval = configure_ethdev(port->port_id, 1);
431 TEST_ASSERT_SUCCESS(retval, "Failed to configure virtual ethdev %s\n",
435 if (test_params.bonded_port_id == INVALID_PORT_ID) {
436 retval = rte_eth_bond_create(BONDED_DEV_NAME, BONDING_MODE_8023AD,
439 TEST_ASSERT(retval >= 0, "Failed to create bonded ethdev %s",
442 test_params.bonded_port_id = retval;
443 TEST_ASSERT_SUCCESS(configure_ethdev(test_params.bonded_port_id, 0),
444 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME);
445 } else if (rte_eth_bond_mode_get(test_params.bonded_port_id) !=
446 BONDING_MODE_8023AD) {
447 TEST_ASSERT(rte_eth_bond_mode_set(test_params.bonded_port_id,
448 BONDING_MODE_8023AD) == 0,
449 "Failed to set ethdev %d to mode %d",
450 test_params.bonded_port_id, BONDING_MODE_8023AD);
457 testsuite_teardown(void)
459 struct slave_conf *port;
463 * Any cleanup/reset state is done when particular test is
466 rte_eth_dev_stop(test_params.bonded_port_id);
468 FOR_EACH_PORT(i, port)
469 rte_eth_dev_stop(port->port_id);
473 * Check if given LACP packet. If it is, make make replay packet to force
475 * return 0 when pkt is LACP frame, 1 if it is not slow frame, 2 if it is slow
479 make_lacp_reply(struct slave_conf *slave, struct rte_mbuf *pkt)
481 struct rte_ether_hdr *hdr;
482 struct slow_protocol_frame *slow_hdr;
486 hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
487 if (hdr->ether_type != rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW))
490 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
491 /* ignore packets of other types */
492 if (slow_hdr->slow_protocol.subtype != SLOW_SUBTYPE_LACP)
495 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
497 /* Change source address to partner address */
498 rte_ether_addr_copy(&parnter_mac_default, &slow_hdr->eth_hdr.s_addr);
499 slow_hdr->eth_hdr.s_addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
502 lacp = (struct lacpdu *) &slow_hdr->slow_protocol;
503 /* Save last received state */
504 slave->lacp_parnter_state = lacp->actor.state;
505 /* Change it into LACP replay by matching parameters. */
506 memcpy(&lacp->partner.port_params, &lacp->actor.port_params,
507 sizeof(struct port_params));
509 lacp->partner.state = lacp->actor.state;
511 rte_ether_addr_copy(&parnter_system, &lacp->actor.port_params.system);
512 lacp->actor.state = STATE_LACP_ACTIVE |
513 STATE_SYNCHRONIZATION |
522 * Reads packets from given slave, search for LACP packet and reply them.
524 * Receives burst of packets from slave. Looks for LACP packet. Drops
525 * all other packets. Prepares response LACP and sends it back.
527 * return number of LACP received and replied, -1 on error.
530 bond_handshake_reply(struct slave_conf *slave)
533 struct rte_mbuf *rx_buf[MAX_PKT_BURST];
534 struct rte_mbuf *lacp_tx_buf[MAX_PKT_BURST];
535 uint16_t lacp_tx_buf_cnt = 0, i;
537 retval = slave_get_pkts(slave, rx_buf, RTE_DIM(rx_buf));
538 TEST_ASSERT(retval >= 0, "Getting slave %u packets failed.",
541 for (i = 0; i < (uint16_t)retval; i++) {
542 if (make_lacp_reply(slave, rx_buf[i]) == 0) {
543 /* reply with actor's LACP */
544 lacp_tx_buf[lacp_tx_buf_cnt++] = rx_buf[i];
546 rte_pktmbuf_free(rx_buf[i]);
549 if (lacp_tx_buf_cnt == 0)
552 retval = slave_put_pkts(slave, lacp_tx_buf, lacp_tx_buf_cnt);
553 if (retval <= lacp_tx_buf_cnt) {
554 /* retval might be negative */
555 for (i = RTE_MAX(0, retval); retval < lacp_tx_buf_cnt; retval++)
556 rte_pktmbuf_free(lacp_tx_buf[i]);
559 TEST_ASSERT_EQUAL(retval, lacp_tx_buf_cnt,
560 "Failed to equeue lacp packets into slave %u tx queue.",
563 return lacp_tx_buf_cnt;
567 * Function check if given slave tx queue contains packets that make mode 4
568 * handshake complete. It will drain slave queue.
569 * return 0 if handshake not completed, 1 if handshake was complete,
572 bond_handshake_done(struct slave_conf *slave)
574 const uint8_t expected_state = STATE_LACP_ACTIVE | STATE_SYNCHRONIZATION |
575 STATE_AGGREGATION | STATE_COLLECTING | STATE_DISTRIBUTING;
577 return slave->lacp_parnter_state == expected_state;
581 bond_get_update_timeout_ms(void)
583 struct rte_eth_bond_8023ad_conf conf;
585 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
586 return conf.update_timeout_ms;
590 * Exchanges LACP packets with partner to achieve dynamic port configuration.
591 * return TEST_SUCCESS if initial handshake succeed, TEST_FAILED otherwise.
596 struct slave_conf *slave;
597 struct rte_mbuf *buf[MAX_PKT_BURST];
599 uint8_t all_slaves_done, i, j;
600 uint8_t status[RTE_DIM(test_params.slave_ports)] = { 0 };
601 const unsigned delay = bond_get_update_timeout_ms();
603 /* Exchange LACP frames */
605 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
609 FOR_EACH_SLAVE(j, slave) {
610 /* If response already send, skip slave */
614 if (bond_handshake_reply(slave) < 0) {
619 status[j] = bond_handshake_done(slave);
624 nb_pkts = bond_tx(NULL, 0);
625 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
627 nb_pkts = bond_rx(buf, RTE_DIM(buf));
628 free_pkts(buf, nb_pkts);
629 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
631 /* If response didn't send - report failure */
632 TEST_ASSERT_EQUAL(all_slaves_done, 1, "Bond handshake failed\n");
634 /* If flags doesn't match - report failure */
635 return all_slaves_done == 1 ? TEST_SUCCESS : TEST_FAILED;
638 #define TEST_LACP_SLAVE_COUT RTE_DIM(test_params.slave_ports)
640 test_mode4_lacp(void)
644 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
645 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
647 /* Test LACP handshake function */
648 retval = bond_handshake();
649 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
651 retval = remove_slaves_and_stop_bonded_device();
652 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
657 test_mode4_agg_mode_selection(void)
660 /* Test and verify for Stable mode */
661 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
662 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
665 retval = rte_eth_bond_8023ad_agg_selection_set(
666 test_params.bonded_port_id, AGG_STABLE);
667 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bond aggregation mode");
668 retval = bond_handshake();
669 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
672 retval = rte_eth_bond_8023ad_agg_selection_get(
673 test_params.bonded_port_id);
674 TEST_ASSERT_EQUAL(retval, AGG_STABLE,
675 "Wrong agg mode received from bonding device");
677 retval = remove_slaves_and_stop_bonded_device();
678 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
681 /* test and verify for Bandwidth mode */
682 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
683 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
686 retval = rte_eth_bond_8023ad_agg_selection_set(
687 test_params.bonded_port_id,
689 TEST_ASSERT_SUCCESS(retval,
690 "Failed to initialize bond aggregation mode");
691 retval = bond_handshake();
692 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
694 retval = rte_eth_bond_8023ad_agg_selection_get(
695 test_params.bonded_port_id);
696 TEST_ASSERT_EQUAL(retval, AGG_BANDWIDTH,
697 "Wrong agg mode received from bonding device");
699 retval = remove_slaves_and_stop_bonded_device();
700 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
702 /* test and verify selection for count mode */
703 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
704 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
707 retval = rte_eth_bond_8023ad_agg_selection_set(
708 test_params.bonded_port_id, AGG_COUNT);
709 TEST_ASSERT_SUCCESS(retval,
710 "Failed to initialize bond aggregation mode");
711 retval = bond_handshake();
712 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
714 retval = rte_eth_bond_8023ad_agg_selection_get(
715 test_params.bonded_port_id);
716 TEST_ASSERT_EQUAL(retval, AGG_COUNT,
717 "Wrong agg mode received from bonding device");
719 retval = remove_slaves_and_stop_bonded_device();
720 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
726 generate_packets(struct rte_ether_addr *src_mac,
727 struct rte_ether_addr *dst_mac, uint16_t count, struct rte_mbuf **buf)
729 uint16_t pktlen = PACKET_BURST_GEN_PKT_LEN;
730 uint8_t vlan_enable = 0;
731 uint16_t vlan_id = 0;
732 uint8_t ip4_type = 1; /* 0 - ipv6 */
734 uint16_t src_port = 10, dst_port = 20;
736 uint32_t ip_src[4] = { [0 ... 2] = 0xDEADBEEF, [3] = RTE_IPV4(192, 168, 0, 1) };
737 uint32_t ip_dst[4] = { [0 ... 2] = 0xFEEDFACE, [3] = RTE_IPV4(192, 168, 0, 2) };
739 struct rte_ether_hdr pkt_eth_hdr;
740 struct rte_udp_hdr pkt_udp_hdr;
742 struct rte_ipv4_hdr v4;
743 struct rte_ipv6_hdr v6;
748 initialize_eth_header(&pkt_eth_hdr, src_mac, dst_mac, ip4_type,
749 vlan_enable, vlan_id);
752 initialize_ipv4_header(&pkt_ip_hdr.v4, ip_src[3], ip_dst[3], pktlen);
754 initialize_ipv6_header(&pkt_ip_hdr.v6, (uint8_t *)ip_src,
755 (uint8_t *)&ip_dst, pktlen);
757 initialize_udp_header(&pkt_udp_hdr, src_port, dst_port, 16);
759 retval = generate_packet_burst(test_params.mbuf_pool, buf,
760 &pkt_eth_hdr, vlan_enable, &pkt_ip_hdr, 1, &pkt_udp_hdr,
763 if (retval > 0 && retval != count)
764 free_pkts(&buf[count - retval], retval);
766 TEST_ASSERT_EQUAL(retval, count, "Failed to generate %u packets",
773 generate_and_put_packets(struct slave_conf *slave,
774 struct rte_ether_addr *src_mac,
775 struct rte_ether_addr *dst_mac, uint16_t count)
777 struct rte_mbuf *pkts[MAX_PKT_BURST];
780 retval = generate_packets(src_mac, dst_mac, count, pkts);
781 if (retval != (int)count)
784 retval = slave_put_pkts(slave, pkts, count);
785 if (retval > 0 && retval != count)
786 free_pkts(&pkts[retval], count - retval);
788 TEST_ASSERT_EQUAL(retval, count,
789 "Failed to enqueue packets into slave %u RX queue", slave->port_id);
797 struct slave_conf *slave;
800 uint16_t expected_pkts_cnt;
801 struct rte_mbuf *pkts[MAX_PKT_BURST];
805 struct rte_ether_hdr *hdr;
807 struct rte_ether_addr src_mac = {
808 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
809 struct rte_ether_addr dst_mac;
810 struct rte_ether_addr bonded_mac;
812 retval = initialize_bonded_device_with_slaves(TEST_PROMISC_SLAVE_COUNT,
814 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
816 retval = bond_handshake();
817 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
819 rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
820 rte_ether_addr_copy(&bonded_mac, &dst_mac);
822 /* Assert that dst address is not bonding address. Do not set the
823 * least significant bit of the zero byte as this would create a
826 dst_mac.addr_bytes[0] += 2;
828 /* First try with promiscuous mode enabled.
829 * Add 2 packets to each slave. First with bonding MAC address, second with
830 * different. Check if we received all of them. */
831 retval = rte_eth_promiscuous_enable(test_params.bonded_port_id);
832 TEST_ASSERT_SUCCESS(retval,
833 "Failed to enable promiscuous mode for port %d: %s",
834 test_params.bonded_port_id, rte_strerror(-retval));
836 expected_pkts_cnt = 0;
837 FOR_EACH_SLAVE(i, slave) {
838 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
839 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
842 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
843 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
846 /* Expect 2 packets per slave */
847 expected_pkts_cnt += 2;
850 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
853 if (retval == expected_pkts_cnt) {
854 int cnt[2] = { 0, 0 };
856 for (i = 0; i < expected_pkts_cnt; i++) {
857 hdr = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *);
858 cnt[rte_is_same_ether_addr(&hdr->d_addr,
862 free_pkts(pkts, expected_pkts_cnt);
864 /* For division by 2 expected_pkts_cnt must be even */
865 RTE_VERIFY((expected_pkts_cnt & 1) == 0);
866 TEST_ASSERT(cnt[0] == expected_pkts_cnt / 2 &&
867 cnt[1] == expected_pkts_cnt / 2,
868 "Expected %u packets with the same MAC and %u with different but "
869 "got %u with the same and %u with different MAC",
870 expected_pkts_cnt / 2, expected_pkts_cnt / 2, cnt[1], cnt[0]);
871 } else if (retval > 0)
872 free_pkts(pkts, retval);
874 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
875 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
877 /* Now, disable promiscuous mode. When promiscuous mode is disabled we
878 * expect to receive only packets that are directed to bonding port. */
879 retval = rte_eth_promiscuous_disable(test_params.bonded_port_id);
880 TEST_ASSERT_SUCCESS(retval,
881 "Failed to disable promiscuous mode for port %d: %s",
882 test_params.bonded_port_id, rte_strerror(-retval));
884 expected_pkts_cnt = 0;
885 FOR_EACH_SLAVE(i, slave) {
886 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
887 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
890 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
891 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
894 /* Expect only one packet per slave */
895 expected_pkts_cnt += 1;
898 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
901 if (retval == expected_pkts_cnt) {
904 for (i = 0; i < expected_pkts_cnt; i++) {
905 hdr = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *);
906 eq_cnt += rte_is_same_ether_addr(&hdr->d_addr,
910 free_pkts(pkts, expected_pkts_cnt);
911 TEST_ASSERT_EQUAL(eq_cnt, expected_pkts_cnt, "Packet address mismatch");
912 } else if (retval > 0)
913 free_pkts(pkts, retval);
915 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
916 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
918 /* Link down test: simulate link down for first slave. */
919 delay = bond_get_update_timeout_ms();
921 uint8_t slave_down_id = INVALID_PORT_ID;
923 /* Find first slave and make link down on it*/
924 FOR_EACH_SLAVE(i, slave) {
925 rte_eth_dev_set_link_down(slave->port_id);
926 slave_down_id = slave->port_id;
930 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
932 /* Give some time to rearrange bonding */
933 for (i = 0; i < 3; i++) {
938 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
940 /* Put packet to each slave */
941 FOR_EACH_SLAVE(i, slave) {
944 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
945 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
946 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
948 src_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
949 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
950 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
952 retval = bond_rx(pkts, RTE_DIM(pkts));
956 free_pkts(pkts, retval);
958 while (rte_ring_dequeue(slave->rx_queue, (void **)&pkt) == 0)
959 rte_pktmbuf_free(pkt);
961 if (slave_down_id == slave->port_id)
962 TEST_ASSERT_EQUAL(retval, 0, "Packets received unexpectedly.");
964 TEST_ASSERT_NOT_EQUAL(retval, 0,
965 "Expected to receive some packets on slave %u.",
967 rte_eth_dev_start(slave->port_id);
969 for (j = 0; j < 5; j++) {
970 TEST_ASSERT(bond_handshake_reply(slave) >= 0,
971 "Handshake after link up");
973 if (bond_handshake_done(slave) == 1)
977 TEST_ASSERT(j < 5, "Failed to aggregate slave after link up");
980 remove_slaves_and_stop_bonded_device();
985 test_mode4_tx_burst(void)
987 struct slave_conf *slave;
990 uint16_t exp_pkts_cnt, pkts_cnt = 0;
991 struct rte_mbuf *pkts[MAX_PKT_BURST];
995 struct rte_ether_addr dst_mac = {
996 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
997 struct rte_ether_addr bonded_mac;
999 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1000 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1002 retval = bond_handshake();
1003 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1005 rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
1008 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1009 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = pkts_cnt;
1010 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1013 free_pkts(pkts, pkts_cnt);
1015 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate packet %u", pkts_cnt);
1017 exp_pkts_cnt = pkts_cnt;
1019 /* Transmit packets on bonded device */
1020 retval = bond_tx(pkts, pkts_cnt);
1021 if (retval > 0 && retval < pkts_cnt)
1022 free_pkts(&pkts[retval], pkts_cnt - retval);
1024 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1026 /* Check if packets were transmitted properly. Every slave should have
1027 * at least one packet, and sum must match. Under normal operation
1028 * there should be no LACP nor MARKER frames. */
1030 FOR_EACH_SLAVE(i, slave) {
1031 uint16_t normal_cnt, slow_cnt;
1033 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1037 for (j = 0; j < retval; j++) {
1038 if (make_lacp_reply(slave, pkts[j]) == 1)
1044 free_pkts(pkts, normal_cnt + slow_cnt);
1045 TEST_ASSERT_EQUAL(slow_cnt, 0,
1046 "slave %u unexpectedly transmitted %d SLOW packets", slave->port_id,
1049 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1050 "slave %u did not transmitted any packets", slave->port_id);
1052 pkts_cnt += normal_cnt;
1055 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1056 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1059 * simulate link down for first slave. */
1060 delay = bond_get_update_timeout_ms();
1062 uint8_t slave_down_id = INVALID_PORT_ID;
1064 FOR_EACH_SLAVE(i, slave) {
1065 rte_eth_dev_set_link_down(slave->port_id);
1066 slave_down_id = slave->port_id;
1070 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
1072 /* Give some time to rearrange bonding. */
1073 for (i = 0; i < 3; i++) {
1075 rte_delay_ms(delay);
1078 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
1080 /* Prepare burst. */
1081 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1082 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = pkts_cnt;
1083 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1086 free_pkts(pkts, pkts_cnt);
1088 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate test packet %u",
1091 exp_pkts_cnt = pkts_cnt;
1093 /* Transmit packets on bonded device. */
1094 retval = bond_tx(pkts, pkts_cnt);
1095 if (retval > 0 && retval < pkts_cnt)
1096 free_pkts(&pkts[retval], pkts_cnt - retval);
1098 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1100 /* Check if packets was transmitted properly. Every slave should have
1101 * at least one packet, and sum must match. Under normal operation
1102 * there should be no LACP nor MARKER frames. */
1104 FOR_EACH_SLAVE(i, slave) {
1105 uint16_t normal_cnt, slow_cnt;
1107 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1111 for (j = 0; j < retval; j++) {
1112 if (make_lacp_reply(slave, pkts[j]) == 1)
1118 free_pkts(pkts, normal_cnt + slow_cnt);
1120 if (slave_down_id == slave->port_id) {
1121 TEST_ASSERT_EQUAL(normal_cnt + slow_cnt, 0,
1122 "slave %u enexpectedly transmitted %u packets",
1123 normal_cnt + slow_cnt, slave->port_id);
1125 TEST_ASSERT_EQUAL(slow_cnt, 0,
1126 "slave %u unexpectedly transmitted %d SLOW packets",
1127 slave->port_id, slow_cnt);
1129 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1130 "slave %u did not transmitted any packets", slave->port_id);
1133 pkts_cnt += normal_cnt;
1136 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1137 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1139 return remove_slaves_and_stop_bonded_device();
1143 init_marker(struct rte_mbuf *pkt, struct slave_conf *slave)
1145 struct marker_header *marker_hdr = rte_pktmbuf_mtod(pkt,
1146 struct marker_header *);
1148 /* Copy multicast destination address */
1149 rte_ether_addr_copy(&slow_protocol_mac_addr,
1150 &marker_hdr->eth_hdr.d_addr);
1152 /* Init source address */
1153 rte_ether_addr_copy(&parnter_mac_default, &marker_hdr->eth_hdr.s_addr);
1154 marker_hdr->eth_hdr.s_addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
1157 marker_hdr->eth_hdr.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW);
1159 marker_hdr->marker.subtype = SLOW_SUBTYPE_MARKER;
1160 marker_hdr->marker.version_number = 1;
1161 marker_hdr->marker.tlv_type_marker = MARKER_TLV_TYPE_INFO;
1162 marker_hdr->marker.info_length =
1163 offsetof(struct marker, reserved_90) -
1164 offsetof(struct marker, requester_port);
1165 RTE_VERIFY(marker_hdr->marker.info_length == 16);
1166 marker_hdr->marker.requester_port = slave->port_id + 1;
1167 marker_hdr->marker.tlv_type_terminator = TLV_TYPE_TERMINATOR_INFORMATION;
1168 marker_hdr->marker.terminator_length = 0;
1172 test_mode4_marker(void)
1174 struct slave_conf *slave;
1175 struct rte_mbuf *pkts[MAX_PKT_BURST];
1176 struct rte_mbuf *marker_pkt;
1177 struct marker_header *marker_hdr;
1183 const uint16_t ethtype_slow_be = rte_be_to_cpu_16(RTE_ETHER_TYPE_SLOW);
1185 retval = initialize_bonded_device_with_slaves(TEST_MARKER_SLAVE_COUT,
1187 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1189 /* Test LACP handshake function */
1190 retval = bond_handshake();
1191 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1193 delay = bond_get_update_timeout_ms();
1194 FOR_EACH_SLAVE(i, slave) {
1195 marker_pkt = rte_pktmbuf_alloc(test_params.mbuf_pool);
1196 TEST_ASSERT_NOT_NULL(marker_pkt, "Failed to allocate marker packet");
1197 init_marker(marker_pkt, slave);
1199 retval = slave_put_pkts(slave, &marker_pkt, 1);
1201 rte_pktmbuf_free(marker_pkt);
1203 TEST_ASSERT_EQUAL(retval, 1,
1204 "Failed to send marker packet to slave %u", slave->port_id);
1206 for (j = 0; j < 20; ++j) {
1207 rte_delay_ms(delay);
1208 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
1212 free_pkts(pkts, retval);
1214 TEST_ASSERT_EQUAL(retval, 0, "Received packets unexpectedly");
1216 retval = rte_eth_tx_burst(test_params.bonded_port_id, 0, NULL, 0);
1217 TEST_ASSERT_EQUAL(retval, 0,
1218 "Requested TX of 0 packets but %d transmitted", retval);
1220 /* Check if LACP packet was send by state machines
1221 First and only packet must be a maker response */
1222 retval = slave_get_pkts(slave, pkts, MAX_PKT_BURST);
1226 free_pkts(pkts, retval);
1228 TEST_ASSERT_EQUAL(retval, 1, "failed to get slave packets");
1231 marker_hdr = rte_pktmbuf_mtod(pkts[0], struct marker_header *);
1232 /* Check if it's slow packet*/
1233 if (marker_hdr->eth_hdr.ether_type != ethtype_slow_be)
1235 /* Check if it's marker packet */
1236 else if (marker_hdr->marker.subtype != SLOW_SUBTYPE_MARKER)
1238 else if (marker_hdr->marker.tlv_type_marker != MARKER_TLV_TYPE_RESP)
1241 free_pkts(pkts, nb_pkts);
1243 TEST_ASSERT_NOT_EQUAL(retval, -1, "Unexpected protocol type");
1244 TEST_ASSERT_NOT_EQUAL(retval, -2, "Unexpected sub protocol type");
1245 TEST_ASSERT_NOT_EQUAL(retval, -3, "Unexpected marker type");
1249 TEST_ASSERT(j < 20, "Marker response not found");
1252 retval = remove_slaves_and_stop_bonded_device();
1253 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1255 return TEST_SUCCESS;
1259 test_mode4_expired(void)
1261 struct slave_conf *slave, *exp_slave = NULL;
1262 struct rte_mbuf *pkts[MAX_PKT_BURST];
1269 struct rte_eth_bond_8023ad_conf conf;
1271 retval = initialize_bonded_device_with_slaves(TEST_EXPIRED_SLAVE_COUNT,
1273 /* Set custom timeouts to make test last shorter. */
1274 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
1275 conf.fast_periodic_ms = 100;
1276 conf.slow_periodic_ms = 600;
1277 conf.short_timeout_ms = 300;
1278 conf.long_timeout_ms = 900;
1279 conf.aggregate_wait_timeout_ms = 200;
1280 conf.tx_period_ms = 100;
1281 old_delay = conf.update_timeout_ms;
1282 conf.update_timeout_ms = 10;
1283 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
1285 /* Wait for new settings to be applied. */
1286 for (i = 0; i < old_delay/conf.update_timeout_ms * 2; i++) {
1287 FOR_EACH_SLAVE(j, slave)
1288 bond_handshake_reply(slave);
1290 rte_delay_ms(conf.update_timeout_ms);
1293 retval = bond_handshake();
1294 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1296 /* Find first slave */
1297 FOR_EACH_SLAVE(i, slave) {
1302 RTE_VERIFY(exp_slave != NULL);
1304 /* When one of partners do not send or respond to LACP frame in
1305 * conf.long_timeout_ms time, internal state machines should detect this
1306 * and transit to expired state. */
1307 for (j = 0; j < conf.long_timeout_ms/conf.update_timeout_ms + 2; j++) {
1308 rte_delay_ms(conf.update_timeout_ms);
1310 retval = bond_tx(NULL, 0);
1311 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1314 FOR_EACH_SLAVE(i, slave) {
1315 retval = bond_handshake_reply(slave);
1316 TEST_ASSERT(retval >= 0, "Handshake failed");
1318 /* Remove replay for slave that suppose to be expired. */
1319 if (slave == exp_slave) {
1320 while (rte_ring_count(slave->rx_queue) > 0) {
1323 rte_ring_dequeue(slave->rx_queue, &pkt);
1324 rte_pktmbuf_free(pkt);
1329 retval = bond_rx(pkts, RTE_DIM(pkts));
1331 free_pkts(pkts, retval);
1333 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1337 /* After test only expected slave should be in EXPIRED state */
1338 FOR_EACH_SLAVE(i, slave) {
1339 if (slave == exp_slave)
1340 TEST_ASSERT(slave->lacp_parnter_state & STATE_EXPIRED,
1341 "Slave %u should be in expired.", slave->port_id);
1343 TEST_ASSERT_EQUAL(bond_handshake_done(slave), 1,
1344 "Slave %u should be operational.", slave->port_id);
1347 retval = remove_slaves_and_stop_bonded_device();
1348 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1350 return TEST_SUCCESS;
1354 test_mode4_ext_ctrl(void)
1357 * configure bonded interface without the external sm enabled
1358 * . try to transmit lacpdu (should fail)
1359 * . try to set collecting and distributing flags (should fail)
1360 * reconfigure w/external sm
1361 * . transmit one lacpdu on each slave using new api
1362 * . make sure each slave receives one lacpdu using the callback api
1363 * . transmit one data pdu on each slave (should fail)
1364 * . enable distribution and collection, send one data pdu each again
1368 struct slave_conf *slave = NULL;
1371 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1372 struct rte_ether_addr src_mac, dst_mac;
1373 struct lacpdu_header lacpdu = {
1375 .subtype = SLOW_SUBTYPE_LACP,
1379 rte_ether_addr_copy(&parnter_system, &src_mac);
1380 rte_ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1382 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1383 RTE_ETHER_TYPE_SLOW, 0, 0);
1385 for (i = 0; i < SLAVE_COUNT; i++) {
1386 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1387 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1388 &lacpdu, sizeof(lacpdu));
1389 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1392 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1393 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1395 FOR_EACH_SLAVE(i, slave) {
1396 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_slowtx(
1397 test_params.bonded_port_id,
1398 slave->port_id, lacp_tx_buf[i]),
1399 "Slave should not allow manual LACP xmit");
1400 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_collect(
1401 test_params.bonded_port_id,
1403 "Slave should not allow external state controls");
1406 free_pkts(lacp_tx_buf, RTE_DIM(lacp_tx_buf));
1408 retval = remove_slaves_and_stop_bonded_device();
1409 TEST_ASSERT_SUCCESS(retval, "Bonded device cleanup failed.");
1411 return TEST_SUCCESS;
1416 test_mode4_ext_lacp(void)
1419 struct slave_conf *slave = NULL;
1420 uint8_t all_slaves_done = 0, i;
1422 const unsigned int delay = bond_get_update_timeout_ms();
1424 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1425 struct rte_mbuf *buf[SLAVE_COUNT];
1426 struct rte_ether_addr src_mac, dst_mac;
1427 struct lacpdu_header lacpdu = {
1429 .subtype = SLOW_SUBTYPE_LACP,
1433 rte_ether_addr_copy(&parnter_system, &src_mac);
1434 rte_ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1436 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1437 RTE_ETHER_TYPE_SLOW, 0, 0);
1439 for (i = 0; i < SLAVE_COUNT; i++) {
1440 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1441 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1442 &lacpdu, sizeof(lacpdu));
1443 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1446 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 1);
1447 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1449 memset(lacpdu_rx_count, 0, sizeof(lacpdu_rx_count));
1451 /* Wait for new settings to be applied. */
1452 for (i = 0; i < 30; ++i)
1453 rte_delay_ms(delay);
1455 FOR_EACH_SLAVE(i, slave) {
1456 retval = rte_eth_bond_8023ad_ext_slowtx(
1457 test_params.bonded_port_id,
1458 slave->port_id, lacp_tx_buf[i]);
1459 TEST_ASSERT_SUCCESS(retval,
1460 "Slave should allow manual LACP xmit");
1463 nb_pkts = bond_tx(NULL, 0);
1464 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
1466 FOR_EACH_SLAVE(i, slave) {
1467 nb_pkts = slave_get_pkts(slave, buf, RTE_DIM(buf));
1468 TEST_ASSERT_EQUAL(nb_pkts, 1, "found %u packets on slave %d\n",
1470 slave_put_pkts(slave, buf, nb_pkts);
1473 nb_pkts = bond_rx(buf, RTE_DIM(buf));
1474 free_pkts(buf, nb_pkts);
1475 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
1477 /* wait for the periodic callback to run */
1478 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
1479 uint8_t s, total = 0;
1481 rte_delay_ms(delay);
1482 FOR_EACH_SLAVE(s, slave) {
1483 total += lacpdu_rx_count[slave->port_id];
1486 if (total >= SLAVE_COUNT)
1487 all_slaves_done = 1;
1490 FOR_EACH_SLAVE(i, slave) {
1491 TEST_ASSERT_EQUAL(lacpdu_rx_count[slave->port_id], 1,
1492 "Slave port %u should have received 1 lacpdu (count=%u)",
1494 lacpdu_rx_count[slave->port_id]);
1497 retval = remove_slaves_and_stop_bonded_device();
1498 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1500 return TEST_SUCCESS;
1504 check_environment(void)
1506 struct slave_conf *port;
1507 uint8_t i, env_state;
1508 uint16_t slaves[RTE_DIM(test_params.slave_ports)];
1512 FOR_EACH_PORT(i, port) {
1513 if (rte_ring_count(port->rx_queue) != 0)
1516 if (rte_ring_count(port->tx_queue) != 0)
1519 if (port->bonded != 0)
1522 if (port->lacp_parnter_state != 0)
1529 slaves_count = rte_eth_bond_slaves_get(test_params.bonded_port_id,
1530 slaves, RTE_DIM(slaves));
1532 if (slaves_count != 0)
1535 TEST_ASSERT_EQUAL(env_state, 0,
1536 "Environment not clean (port %u):%s%s%s%s%s",
1538 env_state & 0x01 ? " slave rx queue not clean" : "",
1539 env_state & 0x02 ? " slave tx queue not clean" : "",
1540 env_state & 0x04 ? " port marked as enslaved" : "",
1541 env_state & 0x80 ? " slave state is not reset" : "",
1542 env_state & 0x10 ? " slave count not equal 0" : ".");
1545 return TEST_SUCCESS;
1549 test_mode4_executor(int (*test_func)(void))
1551 struct slave_conf *port;
1556 /* Check if environment is clean. Fail to launch a test if there was
1557 * a critical error before that prevented to reset environment. */
1558 TEST_ASSERT_SUCCESS(check_environment(),
1559 "Refusing to launch test in dirty environment.");
1561 RTE_VERIFY(test_func != NULL);
1562 test_result = (*test_func)();
1564 /* If test succeed check if environment wast left in good condition. */
1565 if (test_result == TEST_SUCCESS)
1566 test_result = check_environment();
1568 /* Reset environment in case test failed to do that. */
1569 if (test_result != TEST_SUCCESS) {
1570 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
1571 "Failed to stop bonded device");
1573 FOR_EACH_PORT(i, port) {
1574 while (rte_ring_count(port->rx_queue) != 0) {
1575 if (rte_ring_dequeue(port->rx_queue, &pkt) == 0)
1576 rte_pktmbuf_free(pkt);
1579 while (rte_ring_count(port->tx_queue) != 0) {
1580 if (rte_ring_dequeue(port->tx_queue, &pkt) == 0)
1581 rte_pktmbuf_free(pkt);
1590 test_mode4_agg_mode_selection_wrapper(void){
1591 return test_mode4_executor(&test_mode4_agg_mode_selection);
1595 test_mode4_lacp_wrapper(void)
1597 return test_mode4_executor(&test_mode4_lacp);
1601 test_mode4_marker_wrapper(void)
1603 return test_mode4_executor(&test_mode4_marker);
1607 test_mode4_rx_wrapper(void)
1609 return test_mode4_executor(&test_mode4_rx);
1613 test_mode4_tx_burst_wrapper(void)
1615 return test_mode4_executor(&test_mode4_tx_burst);
1619 test_mode4_expired_wrapper(void)
1621 return test_mode4_executor(&test_mode4_expired);
1625 test_mode4_ext_ctrl_wrapper(void)
1627 return test_mode4_executor(&test_mode4_ext_ctrl);
1631 test_mode4_ext_lacp_wrapper(void)
1633 return test_mode4_executor(&test_mode4_ext_lacp);
1636 static struct unit_test_suite link_bonding_mode4_test_suite = {
1637 .suite_name = "Link Bonding mode 4 Unit Test Suite",
1638 .setup = test_setup,
1639 .teardown = testsuite_teardown,
1640 .unit_test_cases = {
1641 TEST_CASE_NAMED("test_mode4_agg_mode_selection",
1642 test_mode4_agg_mode_selection_wrapper),
1643 TEST_CASE_NAMED("test_mode4_lacp", test_mode4_lacp_wrapper),
1644 TEST_CASE_NAMED("test_mode4_rx", test_mode4_rx_wrapper),
1645 TEST_CASE_NAMED("test_mode4_tx_burst", test_mode4_tx_burst_wrapper),
1646 TEST_CASE_NAMED("test_mode4_marker", test_mode4_marker_wrapper),
1647 TEST_CASE_NAMED("test_mode4_expired", test_mode4_expired_wrapper),
1648 TEST_CASE_NAMED("test_mode4_ext_ctrl",
1649 test_mode4_ext_ctrl_wrapper),
1650 TEST_CASE_NAMED("test_mode4_ext_lacp",
1651 test_mode4_ext_lacp_wrapper),
1653 TEST_CASES_END() /**< NULL terminate unit test array */
1658 test_link_bonding_mode4(void)
1660 return unit_test_suite_runner(&link_bonding_mode4_test_suite);
1663 REGISTER_TEST_COMMAND(link_bonding_mode4_autotest, test_link_bonding_mode4);