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 ether_addr slave_mac_default = {
58 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 }
61 static const struct ether_addr parnter_mac_default = {
62 { 0x22, 0xBB, 0xFF, 0xBB, 0x00, 0x00 }
65 static const struct ether_addr parnter_system = {
66 { 0x33, 0xFF, 0xBB, 0xFF, 0x00, 0x00 }
69 static const struct 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 ether_hdr pkt_eth_hdr;
84 struct 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 = ETHER_MAX_LEN,
113 .header_split = 0, /**< Header Split disabled */
114 .hw_ip_checksum = 0, /**< IP checksum offload enabled */
115 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
116 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
117 .hw_strip_crc = 1, /**< CRC stripped by hardware */
120 .mq_mode = ETH_MQ_TX_NONE,
125 static uint8_t lacpdu_rx_count[RTE_MAX_ETHPORTS] = {0, };
127 #define FOR_EACH(_i, _item, _array, _size) \
128 for (_i = 0, _item = &_array[0]; _i < _size && (_item = &_array[_i]); _i++)
130 /* Macro for iterating over every port that can be used as a slave
132 * _i variable used as an index in test_params->slave_ports
133 * _slave pointer to &test_params->slave_ports[_idx]
135 #define FOR_EACH_PORT(_i, _port) \
136 FOR_EACH(_i, _port, test_params.slave_ports, \
137 RTE_DIM(test_params.slave_ports))
139 /* Macro for iterating over every port that can be used as a slave
140 * in this test and satisfy given condition.
142 * _i variable used as an index in test_params->slave_ports
143 * _slave pointer to &test_params->slave_ports[_idx]
144 * _condition condition that need to be checked
146 #define FOR_EACH_PORT_IF(_i, _port, _condition) FOR_EACH_PORT((_i), (_port)) \
149 /* Macro for iterating over every port that is currently a slave of a bonded
151 * _i variable used as an index in test_params->slave_ports
152 * _slave pointer to &test_params->slave_ports[_idx]
154 #define FOR_EACH_SLAVE(_i, _slave) \
155 FOR_EACH_PORT_IF(_i, _slave, (_slave)->bonded != 0)
158 * Returns packets from slaves TX queue.
161 * size size of buffer
162 * return number of packets or negative error number
165 slave_get_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
167 return rte_ring_dequeue_burst(slave->tx_queue, (void **)buf,
172 * Injects given packets into slaves RX queue.
175 * size number of packets to be injected
176 * return number of queued packets or negative error number
179 slave_put_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
181 return rte_ring_enqueue_burst(slave->rx_queue, (void **)buf,
186 bond_rx(struct rte_mbuf **buf, uint16_t size)
188 return rte_eth_rx_burst(test_params.bonded_port_id, 0, buf, size);
192 bond_tx(struct rte_mbuf **buf, uint16_t size)
194 return rte_eth_tx_burst(test_params.bonded_port_id, 0, buf, size);
198 free_pkts(struct rte_mbuf **pkts, uint16_t count)
202 for (i = 0; i < count; i++) {
204 rte_pktmbuf_free(pkts[i]);
209 configure_ethdev(uint16_t port_id, uint8_t start)
211 TEST_ASSERT(rte_eth_dev_configure(port_id, 1, 1, &default_pmd_conf) == 0,
212 "Failed to configure device %u", port_id);
214 TEST_ASSERT(rte_eth_rx_queue_setup(port_id, 0, RX_RING_SIZE,
215 rte_eth_dev_socket_id(port_id), NULL, test_params.mbuf_pool) == 0,
216 "Failed to setup rx queue.");
218 TEST_ASSERT(rte_eth_tx_queue_setup(port_id, 0, TX_RING_SIZE,
219 rte_eth_dev_socket_id(port_id), NULL) == 0,
220 "Failed to setup tx queue.");
223 TEST_ASSERT(rte_eth_dev_start(port_id) == 0,
224 "Failed to start device (%d).", port_id);
230 add_slave(struct slave_conf *slave, uint8_t start)
232 struct ether_addr addr, addr_check;
234 /* Some sanity check */
235 RTE_VERIFY(test_params.slave_ports <= slave &&
236 slave - test_params.slave_ports < (int)RTE_DIM(test_params.slave_ports));
237 RTE_VERIFY(slave->bonded == 0);
238 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
240 ether_addr_copy(&slave_mac_default, &addr);
241 addr.addr_bytes[ETHER_ADDR_LEN - 1] = slave->port_id;
243 rte_eth_dev_mac_addr_remove(slave->port_id, &addr);
245 TEST_ASSERT_SUCCESS(rte_eth_dev_mac_addr_add(slave->port_id, &addr, 0),
246 "Failed to set slave MAC address");
248 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params.bonded_port_id,
250 "Failed to add slave (idx=%u, id=%u) to bonding (id=%u)",
251 (uint8_t)(slave - test_params.slave_ports), slave->port_id,
252 test_params.bonded_port_id);
256 TEST_ASSERT_SUCCESS(rte_eth_dev_start(slave->port_id),
257 "Failed to start slave %u", slave->port_id);
260 rte_eth_macaddr_get(slave->port_id, &addr_check);
261 TEST_ASSERT_EQUAL(is_same_ether_addr(&addr, &addr_check), 1,
262 "Slave MAC address is not as expected");
264 RTE_VERIFY(slave->lacp_parnter_state == 0);
269 remove_slave(struct slave_conf *slave)
271 ptrdiff_t slave_idx = slave - test_params.slave_ports;
273 RTE_VERIFY(test_params.slave_ports <= slave &&
274 slave_idx < (ptrdiff_t)RTE_DIM(test_params.slave_ports));
276 RTE_VERIFY(slave->bonded == 1);
277 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
279 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
280 "Slave %u tx queue not empty while removing from bonding.",
283 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
284 "Slave %u tx queue not empty while removing from bonding.",
287 TEST_ASSERT_EQUAL(rte_eth_bond_slave_remove(test_params.bonded_port_id,
289 "Failed to remove slave (idx=%u, id=%u) from bonding (id=%u)",
290 (uint8_t)slave_idx, slave->port_id,
291 test_params.bonded_port_id);
294 slave->lacp_parnter_state = 0;
299 lacp_recv_cb(uint16_t slave_id, struct rte_mbuf *lacp_pkt)
301 struct ether_hdr *hdr;
302 struct slow_protocol_frame *slow_hdr;
304 RTE_VERIFY(lacp_pkt != NULL);
306 hdr = rte_pktmbuf_mtod(lacp_pkt, struct ether_hdr *);
307 RTE_VERIFY(hdr->ether_type == rte_cpu_to_be_16(ETHER_TYPE_SLOW));
309 slow_hdr = rte_pktmbuf_mtod(lacp_pkt, struct slow_protocol_frame *);
310 RTE_VERIFY(slow_hdr->slow_protocol.subtype == SLOW_SUBTYPE_LACP);
312 lacpdu_rx_count[slave_id]++;
313 rte_pktmbuf_free(lacp_pkt);
317 initialize_bonded_device_with_slaves(uint16_t slave_count, uint8_t external_sm)
321 RTE_VERIFY(test_params.bonded_port_id != INVALID_PORT_ID);
323 for (i = 0; i < slave_count; i++) {
324 TEST_ASSERT_SUCCESS(add_slave(&test_params.slave_ports[i], 1),
325 "Failed to add port %u to bonded device.\n",
326 test_params.slave_ports[i].port_id);
329 /* Reset mode 4 configuration */
330 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, NULL);
331 rte_eth_promiscuous_disable(test_params.bonded_port_id);
334 struct rte_eth_bond_8023ad_conf conf;
336 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
337 conf.slowrx_cb = lacp_recv_cb;
338 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
342 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params.bonded_port_id),
343 "Failed to start bonded device");
349 remove_slaves_and_stop_bonded_device(void)
351 struct slave_conf *slave;
353 uint16_t slaves[RTE_MAX_ETHPORTS];
356 rte_eth_dev_stop(test_params.bonded_port_id);
358 FOR_EACH_SLAVE(i, slave)
361 retval = rte_eth_bond_slaves_get(test_params.bonded_port_id, slaves,
364 TEST_ASSERT_EQUAL(retval, 0,
365 "Expected bonded device %u have 0 slaves but returned %d.",
366 test_params.bonded_port_id, retval);
368 FOR_EACH_PORT(i, slave) {
369 rte_eth_dev_stop(slave->port_id);
371 TEST_ASSERT(slave->bonded == 0,
372 "Port id=%u is still marked as enslaved.", slave->port_id);
381 int retval, nb_mbuf_per_pool;
382 char name[RTE_ETH_NAME_MAX_LEN];
383 struct slave_conf *port;
384 const uint8_t socket_id = rte_socket_id();
387 if (test_params.mbuf_pool == NULL) {
388 nb_mbuf_per_pool = TEST_RX_DESC_MAX + DEF_PKT_BURST +
389 TEST_TX_DESC_MAX + MAX_PKT_BURST;
390 test_params.mbuf_pool = rte_pktmbuf_pool_create("TEST_MODE4",
391 nb_mbuf_per_pool, MBUF_CACHE_SIZE, 0,
392 RTE_MBUF_DEFAULT_BUF_SIZE, socket_id);
394 TEST_ASSERT(test_params.mbuf_pool != NULL,
395 "rte_mempool_create failed\n");
398 /* Create / initialize ring eth devs. */
399 FOR_EACH_PORT(i, port) {
400 port = &test_params.slave_ports[i];
402 if (port->rx_queue == NULL) {
403 retval = snprintf(name, RTE_DIM(name), SLAVE_RX_QUEUE_FMT, i);
404 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
405 port->rx_queue = rte_ring_create(name, RX_RING_SIZE, socket_id, 0);
406 TEST_ASSERT(port->rx_queue != NULL,
407 "Failed to allocate rx ring '%s': %s", name,
408 rte_strerror(rte_errno));
411 if (port->tx_queue == NULL) {
412 retval = snprintf(name, RTE_DIM(name), SLAVE_TX_QUEUE_FMT, i);
413 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
414 port->tx_queue = rte_ring_create(name, TX_RING_SIZE, socket_id, 0);
415 TEST_ASSERT_NOT_NULL(port->tx_queue,
416 "Failed to allocate tx ring '%s': %s", name,
417 rte_strerror(rte_errno));
420 if (port->port_id == INVALID_PORT_ID) {
421 retval = snprintf(name, RTE_DIM(name), SLAVE_DEV_NAME_FMT, i);
422 TEST_ASSERT(retval < (int)RTE_DIM(name) - 1, "Name too long");
423 retval = rte_eth_from_rings(name, &port->rx_queue, 1,
424 &port->tx_queue, 1, socket_id);
425 TEST_ASSERT(retval >= 0,
426 "Failed to create ring ethdev '%s'\n", name);
428 port->port_id = rte_eth_dev_count_avail() - 1;
431 retval = configure_ethdev(port->port_id, 1);
432 TEST_ASSERT_SUCCESS(retval, "Failed to configure virtual ethdev %s\n",
436 if (test_params.bonded_port_id == INVALID_PORT_ID) {
437 retval = rte_eth_bond_create(BONDED_DEV_NAME, BONDING_MODE_8023AD,
440 TEST_ASSERT(retval >= 0, "Failed to create bonded ethdev %s",
443 test_params.bonded_port_id = retval;
444 TEST_ASSERT_SUCCESS(configure_ethdev(test_params.bonded_port_id, 0),
445 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME);
446 } else if (rte_eth_bond_mode_get(test_params.bonded_port_id) !=
447 BONDING_MODE_8023AD) {
448 TEST_ASSERT(rte_eth_bond_mode_set(test_params.bonded_port_id,
449 BONDING_MODE_8023AD) == 0,
450 "Failed to set ethdev %d to mode %d",
451 test_params.bonded_port_id, BONDING_MODE_8023AD);
458 testsuite_teardown(void)
460 struct slave_conf *port;
464 * Any cleanup/reset state is done when particular test is
467 rte_eth_dev_stop(test_params.bonded_port_id);
469 FOR_EACH_PORT(i, port)
470 rte_eth_dev_stop(port->port_id);
474 * Check if given LACP packet. If it is, make make replay packet to force
476 * return 0 when pkt is LACP frame, 1 if it is not slow frame, 2 if it is slow
480 make_lacp_reply(struct slave_conf *slave, struct rte_mbuf *pkt)
482 struct ether_hdr *hdr;
483 struct slow_protocol_frame *slow_hdr;
487 hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
488 if (hdr->ether_type != rte_cpu_to_be_16(ETHER_TYPE_SLOW))
491 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
492 /* ignore packets of other types */
493 if (slow_hdr->slow_protocol.subtype != SLOW_SUBTYPE_LACP)
496 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
498 /* Change source address to partner address */
499 ether_addr_copy(&parnter_mac_default, &slow_hdr->eth_hdr.s_addr);
500 slow_hdr->eth_hdr.s_addr.addr_bytes[ETHER_ADDR_LEN - 1] = slave->port_id;
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 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 ether_addr *src_mac,
727 struct 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] = IPv4(192, 168, 0, 1) };
737 uint32_t ip_dst[4] = { [0 ... 2] = 0xFEEDFACE, [3] = IPv4(192, 168, 0, 2) };
739 struct ether_hdr pkt_eth_hdr;
740 struct udp_hdr pkt_udp_hdr;
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, struct ether_addr *src_mac,
774 struct ether_addr *dst_mac, uint16_t count)
776 struct rte_mbuf *pkts[MAX_PKT_BURST];
779 retval = generate_packets(src_mac, dst_mac, count, pkts);
780 if (retval != (int)count)
783 retval = slave_put_pkts(slave, pkts, count);
784 if (retval > 0 && retval != count)
785 free_pkts(&pkts[retval], count - retval);
787 TEST_ASSERT_EQUAL(retval, count,
788 "Failed to enqueue packets into slave %u RX queue", slave->port_id);
796 struct slave_conf *slave;
799 uint16_t expected_pkts_cnt;
800 struct rte_mbuf *pkts[MAX_PKT_BURST];
804 struct ether_hdr *hdr;
806 struct ether_addr src_mac = { { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
807 struct ether_addr dst_mac;
808 struct ether_addr bonded_mac;
810 retval = initialize_bonded_device_with_slaves(TEST_PROMISC_SLAVE_COUNT,
812 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
814 retval = bond_handshake();
815 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
817 rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
818 ether_addr_copy(&bonded_mac, &dst_mac);
820 /* Assert that dst address is not bonding address. Do not set the
821 * least significant bit of the zero byte as this would create a
824 dst_mac.addr_bytes[0] += 2;
826 /* First try with promiscuous mode enabled.
827 * Add 2 packets to each slave. First with bonding MAC address, second with
828 * different. Check if we received all of them. */
829 rte_eth_promiscuous_enable(test_params.bonded_port_id);
831 expected_pkts_cnt = 0;
832 FOR_EACH_SLAVE(i, slave) {
833 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
834 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
837 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
838 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
841 /* Expect 2 packets per slave */
842 expected_pkts_cnt += 2;
845 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
848 if (retval == expected_pkts_cnt) {
849 int cnt[2] = { 0, 0 };
851 for (i = 0; i < expected_pkts_cnt; i++) {
852 hdr = rte_pktmbuf_mtod(pkts[i], struct ether_hdr *);
853 cnt[is_same_ether_addr(&hdr->d_addr, &bonded_mac)]++;
856 free_pkts(pkts, expected_pkts_cnt);
858 /* For division by 2 expected_pkts_cnt must be even */
859 RTE_VERIFY((expected_pkts_cnt & 1) == 0);
860 TEST_ASSERT(cnt[0] == expected_pkts_cnt / 2 &&
861 cnt[1] == expected_pkts_cnt / 2,
862 "Expected %u packets with the same MAC and %u with different but "
863 "got %u with the same and %u with different MAC",
864 expected_pkts_cnt / 2, expected_pkts_cnt / 2, cnt[1], cnt[0]);
865 } else if (retval > 0)
866 free_pkts(pkts, retval);
868 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
869 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
871 /* Now, disable promiscuous mode. When promiscuous mode is disabled we
872 * expect to receive only packets that are directed to bonding port. */
873 rte_eth_promiscuous_disable(test_params.bonded_port_id);
875 expected_pkts_cnt = 0;
876 FOR_EACH_SLAVE(i, slave) {
877 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
878 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
881 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
882 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
885 /* Expect only one packet per slave */
886 expected_pkts_cnt += 1;
889 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
892 if (retval == expected_pkts_cnt) {
895 for (i = 0; i < expected_pkts_cnt; i++) {
896 hdr = rte_pktmbuf_mtod(pkts[i], struct ether_hdr *);
897 eq_cnt += is_same_ether_addr(&hdr->d_addr, &bonded_mac);
900 free_pkts(pkts, expected_pkts_cnt);
901 TEST_ASSERT_EQUAL(eq_cnt, expected_pkts_cnt, "Packet address mismatch");
902 } else if (retval > 0)
903 free_pkts(pkts, retval);
905 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
906 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
908 /* Link down test: simulate link down for first slave. */
909 delay = bond_get_update_timeout_ms();
911 uint8_t slave_down_id = INVALID_PORT_ID;
913 /* Find first slave and make link down on it*/
914 FOR_EACH_SLAVE(i, slave) {
915 rte_eth_dev_set_link_down(slave->port_id);
916 slave_down_id = slave->port_id;
920 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
922 /* Give some time to rearrange bonding */
923 for (i = 0; i < 3; i++) {
928 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
930 /* Put packet to each slave */
931 FOR_EACH_SLAVE(i, slave) {
934 dst_mac.addr_bytes[ETHER_ADDR_LEN - 1] = slave->port_id;
935 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
936 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
938 src_mac.addr_bytes[ETHER_ADDR_LEN - 1] = slave->port_id;
939 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
940 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
942 retval = bond_rx(pkts, RTE_DIM(pkts));
946 free_pkts(pkts, retval);
948 while (rte_ring_dequeue(slave->rx_queue, (void **)&pkt) == 0)
949 rte_pktmbuf_free(pkt);
951 if (slave_down_id == slave->port_id)
952 TEST_ASSERT_EQUAL(retval, 0, "Packets received unexpectedly.");
954 TEST_ASSERT_NOT_EQUAL(retval, 0,
955 "Expected to receive some packets on slave %u.",
957 rte_eth_dev_start(slave->port_id);
959 for (j = 0; j < 5; j++) {
960 TEST_ASSERT(bond_handshake_reply(slave) >= 0,
961 "Handshake after link up");
963 if (bond_handshake_done(slave) == 1)
967 TEST_ASSERT(j < 5, "Failed to aggregate slave after link up");
970 remove_slaves_and_stop_bonded_device();
975 test_mode4_tx_burst(void)
977 struct slave_conf *slave;
980 uint16_t exp_pkts_cnt, pkts_cnt = 0;
981 struct rte_mbuf *pkts[MAX_PKT_BURST];
985 struct ether_addr dst_mac = { { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
986 struct ether_addr bonded_mac;
988 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
989 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
991 retval = bond_handshake();
992 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
994 rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
997 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
998 dst_mac.addr_bytes[ETHER_ADDR_LEN - 1] = pkts_cnt;
999 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1002 free_pkts(pkts, pkts_cnt);
1004 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate packet %u", pkts_cnt);
1006 exp_pkts_cnt = pkts_cnt;
1008 /* Transmit packets on bonded device */
1009 retval = bond_tx(pkts, pkts_cnt);
1010 if (retval > 0 && retval < pkts_cnt)
1011 free_pkts(&pkts[retval], pkts_cnt - retval);
1013 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1015 /* Check if packets were transmitted properly. Every slave should have
1016 * at least one packet, and sum must match. Under normal operation
1017 * there should be no LACP nor MARKER frames. */
1019 FOR_EACH_SLAVE(i, slave) {
1020 uint16_t normal_cnt, slow_cnt;
1022 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1026 for (j = 0; j < retval; j++) {
1027 if (make_lacp_reply(slave, pkts[j]) == 1)
1033 free_pkts(pkts, normal_cnt + slow_cnt);
1034 TEST_ASSERT_EQUAL(slow_cnt, 0,
1035 "slave %u unexpectedly transmitted %d SLOW packets", slave->port_id,
1038 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1039 "slave %u did not transmitted any packets", slave->port_id);
1041 pkts_cnt += normal_cnt;
1044 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1045 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1048 * simulate link down for first slave. */
1049 delay = bond_get_update_timeout_ms();
1051 uint8_t slave_down_id = INVALID_PORT_ID;
1053 FOR_EACH_SLAVE(i, slave) {
1054 rte_eth_dev_set_link_down(slave->port_id);
1055 slave_down_id = slave->port_id;
1059 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
1061 /* Give some time to rearrange bonding. */
1062 for (i = 0; i < 3; i++) {
1064 rte_delay_ms(delay);
1067 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
1069 /* Prepare burst. */
1070 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1071 dst_mac.addr_bytes[ETHER_ADDR_LEN - 1] = pkts_cnt;
1072 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1075 free_pkts(pkts, pkts_cnt);
1077 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate test packet %u",
1080 exp_pkts_cnt = pkts_cnt;
1082 /* Transmit packets on bonded device. */
1083 retval = bond_tx(pkts, pkts_cnt);
1084 if (retval > 0 && retval < pkts_cnt)
1085 free_pkts(&pkts[retval], pkts_cnt - retval);
1087 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1089 /* Check if packets was transmitted properly. Every slave should have
1090 * at least one packet, and sum must match. Under normal operation
1091 * there should be no LACP nor MARKER frames. */
1093 FOR_EACH_SLAVE(i, slave) {
1094 uint16_t normal_cnt, slow_cnt;
1096 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1100 for (j = 0; j < retval; j++) {
1101 if (make_lacp_reply(slave, pkts[j]) == 1)
1107 free_pkts(pkts, normal_cnt + slow_cnt);
1109 if (slave_down_id == slave->port_id) {
1110 TEST_ASSERT_EQUAL(normal_cnt + slow_cnt, 0,
1111 "slave %u enexpectedly transmitted %u packets",
1112 normal_cnt + slow_cnt, slave->port_id);
1114 TEST_ASSERT_EQUAL(slow_cnt, 0,
1115 "slave %u unexpectedly transmitted %d SLOW packets",
1116 slave->port_id, slow_cnt);
1118 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1119 "slave %u did not transmitted any packets", slave->port_id);
1122 pkts_cnt += normal_cnt;
1125 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1126 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1128 return remove_slaves_and_stop_bonded_device();
1132 init_marker(struct rte_mbuf *pkt, struct slave_conf *slave)
1134 struct marker_header *marker_hdr = rte_pktmbuf_mtod(pkt,
1135 struct marker_header *);
1137 /* Copy multicast destination address */
1138 ether_addr_copy(&slow_protocol_mac_addr, &marker_hdr->eth_hdr.d_addr);
1140 /* Init source address */
1141 ether_addr_copy(&parnter_mac_default, &marker_hdr->eth_hdr.s_addr);
1142 marker_hdr->eth_hdr.s_addr.addr_bytes[ETHER_ADDR_LEN-1] = slave->port_id;
1144 marker_hdr->eth_hdr.ether_type = rte_cpu_to_be_16(ETHER_TYPE_SLOW);
1146 marker_hdr->marker.subtype = SLOW_SUBTYPE_MARKER;
1147 marker_hdr->marker.version_number = 1;
1148 marker_hdr->marker.tlv_type_marker = MARKER_TLV_TYPE_INFO;
1149 marker_hdr->marker.info_length =
1150 offsetof(struct marker, reserved_90) -
1151 offsetof(struct marker, requester_port);
1152 RTE_VERIFY(marker_hdr->marker.info_length == 16);
1153 marker_hdr->marker.requester_port = slave->port_id + 1;
1154 marker_hdr->marker.tlv_type_terminator = TLV_TYPE_TERMINATOR_INFORMATION;
1155 marker_hdr->marker.terminator_length = 0;
1159 test_mode4_marker(void)
1161 struct slave_conf *slave;
1162 struct rte_mbuf *pkts[MAX_PKT_BURST];
1163 struct rte_mbuf *marker_pkt;
1164 struct marker_header *marker_hdr;
1170 const uint16_t ethtype_slow_be = rte_be_to_cpu_16(ETHER_TYPE_SLOW);
1172 retval = initialize_bonded_device_with_slaves(TEST_MARKER_SLAVE_COUT,
1174 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1176 /* Test LACP handshake function */
1177 retval = bond_handshake();
1178 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1180 delay = bond_get_update_timeout_ms();
1181 FOR_EACH_SLAVE(i, slave) {
1182 marker_pkt = rte_pktmbuf_alloc(test_params.mbuf_pool);
1183 TEST_ASSERT_NOT_NULL(marker_pkt, "Failed to allocate marker packet");
1184 init_marker(marker_pkt, slave);
1186 retval = slave_put_pkts(slave, &marker_pkt, 1);
1188 rte_pktmbuf_free(marker_pkt);
1190 TEST_ASSERT_EQUAL(retval, 1,
1191 "Failed to send marker packet to slave %u", slave->port_id);
1193 for (j = 0; j < 20; ++j) {
1194 rte_delay_ms(delay);
1195 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
1199 free_pkts(pkts, retval);
1201 TEST_ASSERT_EQUAL(retval, 0, "Received packets unexpectedly");
1203 retval = rte_eth_tx_burst(test_params.bonded_port_id, 0, NULL, 0);
1204 TEST_ASSERT_EQUAL(retval, 0,
1205 "Requested TX of 0 packets but %d transmitted", retval);
1207 /* Check if LACP packet was send by state machines
1208 First and only packet must be a maker response */
1209 retval = slave_get_pkts(slave, pkts, MAX_PKT_BURST);
1213 free_pkts(pkts, retval);
1215 TEST_ASSERT_EQUAL(retval, 1, "failed to get slave packets");
1218 marker_hdr = rte_pktmbuf_mtod(pkts[0], struct marker_header *);
1219 /* Check if it's slow packet*/
1220 if (marker_hdr->eth_hdr.ether_type != ethtype_slow_be)
1222 /* Check if it's marker packet */
1223 else if (marker_hdr->marker.subtype != SLOW_SUBTYPE_MARKER)
1225 else if (marker_hdr->marker.tlv_type_marker != MARKER_TLV_TYPE_RESP)
1228 free_pkts(pkts, nb_pkts);
1230 TEST_ASSERT_NOT_EQUAL(retval, -1, "Unexpected protocol type");
1231 TEST_ASSERT_NOT_EQUAL(retval, -2, "Unexpected sub protocol type");
1232 TEST_ASSERT_NOT_EQUAL(retval, -3, "Unexpected marker type");
1236 TEST_ASSERT(j < 20, "Marker response not found");
1239 retval = remove_slaves_and_stop_bonded_device();
1240 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1242 return TEST_SUCCESS;
1246 test_mode4_expired(void)
1248 struct slave_conf *slave, *exp_slave = NULL;
1249 struct rte_mbuf *pkts[MAX_PKT_BURST];
1256 struct rte_eth_bond_8023ad_conf conf;
1258 retval = initialize_bonded_device_with_slaves(TEST_EXPIRED_SLAVE_COUNT,
1260 /* Set custom timeouts to make test last shorter. */
1261 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
1262 conf.fast_periodic_ms = 100;
1263 conf.slow_periodic_ms = 600;
1264 conf.short_timeout_ms = 300;
1265 conf.long_timeout_ms = 900;
1266 conf.aggregate_wait_timeout_ms = 200;
1267 conf.tx_period_ms = 100;
1268 old_delay = conf.update_timeout_ms;
1269 conf.update_timeout_ms = 10;
1270 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
1272 /* Wait for new settings to be applied. */
1273 for (i = 0; i < old_delay/conf.update_timeout_ms * 2; i++) {
1274 FOR_EACH_SLAVE(j, slave)
1275 bond_handshake_reply(slave);
1277 rte_delay_ms(conf.update_timeout_ms);
1280 retval = bond_handshake();
1281 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1283 /* Find first slave */
1284 FOR_EACH_SLAVE(i, slave) {
1289 RTE_VERIFY(exp_slave != NULL);
1291 /* When one of partners do not send or respond to LACP frame in
1292 * conf.long_timeout_ms time, internal state machines should detect this
1293 * and transit to expired state. */
1294 for (j = 0; j < conf.long_timeout_ms/conf.update_timeout_ms + 2; j++) {
1295 rte_delay_ms(conf.update_timeout_ms);
1297 retval = bond_tx(NULL, 0);
1298 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1301 FOR_EACH_SLAVE(i, slave) {
1302 retval = bond_handshake_reply(slave);
1303 TEST_ASSERT(retval >= 0, "Handshake failed");
1305 /* Remove replay for slave that suppose to be expired. */
1306 if (slave == exp_slave) {
1307 while (rte_ring_count(slave->rx_queue) > 0) {
1310 rte_ring_dequeue(slave->rx_queue, &pkt);
1311 rte_pktmbuf_free(pkt);
1316 retval = bond_rx(pkts, RTE_DIM(pkts));
1318 free_pkts(pkts, retval);
1320 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1324 /* After test only expected slave should be in EXPIRED state */
1325 FOR_EACH_SLAVE(i, slave) {
1326 if (slave == exp_slave)
1327 TEST_ASSERT(slave->lacp_parnter_state & STATE_EXPIRED,
1328 "Slave %u should be in expired.", slave->port_id);
1330 TEST_ASSERT_EQUAL(bond_handshake_done(slave), 1,
1331 "Slave %u should be operational.", slave->port_id);
1334 retval = remove_slaves_and_stop_bonded_device();
1335 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1337 return TEST_SUCCESS;
1341 test_mode4_ext_ctrl(void)
1344 * configure bonded interface without the external sm enabled
1345 * . try to transmit lacpdu (should fail)
1346 * . try to set collecting and distributing flags (should fail)
1347 * reconfigure w/external sm
1348 * . transmit one lacpdu on each slave using new api
1349 * . make sure each slave receives one lacpdu using the callback api
1350 * . transmit one data pdu on each slave (should fail)
1351 * . enable distribution and collection, send one data pdu each again
1355 struct slave_conf *slave = NULL;
1358 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1359 struct ether_addr src_mac, dst_mac;
1360 struct lacpdu_header lacpdu = {
1362 .subtype = SLOW_SUBTYPE_LACP,
1366 ether_addr_copy(&parnter_system, &src_mac);
1367 ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1369 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1370 ETHER_TYPE_SLOW, 0, 0);
1372 for (i = 0; i < SLAVE_COUNT; i++) {
1373 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1374 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1375 &lacpdu, sizeof(lacpdu));
1376 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1379 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1380 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1382 FOR_EACH_SLAVE(i, slave) {
1383 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_slowtx(
1384 test_params.bonded_port_id,
1385 slave->port_id, lacp_tx_buf[i]),
1386 "Slave should not allow manual LACP xmit");
1387 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_collect(
1388 test_params.bonded_port_id,
1390 "Slave should not allow external state controls");
1393 free_pkts(lacp_tx_buf, RTE_DIM(lacp_tx_buf));
1395 retval = remove_slaves_and_stop_bonded_device();
1396 TEST_ASSERT_SUCCESS(retval, "Bonded device cleanup failed.");
1398 return TEST_SUCCESS;
1403 test_mode4_ext_lacp(void)
1406 struct slave_conf *slave = NULL;
1407 uint8_t all_slaves_done = 0, i;
1409 const unsigned int delay = bond_get_update_timeout_ms();
1411 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1412 struct rte_mbuf *buf[SLAVE_COUNT];
1413 struct ether_addr src_mac, dst_mac;
1414 struct lacpdu_header lacpdu = {
1416 .subtype = SLOW_SUBTYPE_LACP,
1420 ether_addr_copy(&parnter_system, &src_mac);
1421 ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1423 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1424 ETHER_TYPE_SLOW, 0, 0);
1426 for (i = 0; i < SLAVE_COUNT; i++) {
1427 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1428 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1429 &lacpdu, sizeof(lacpdu));
1430 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1433 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 1);
1434 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1436 memset(lacpdu_rx_count, 0, sizeof(lacpdu_rx_count));
1438 /* Wait for new settings to be applied. */
1439 for (i = 0; i < 30; ++i)
1440 rte_delay_ms(delay);
1442 FOR_EACH_SLAVE(i, slave) {
1443 retval = rte_eth_bond_8023ad_ext_slowtx(
1444 test_params.bonded_port_id,
1445 slave->port_id, lacp_tx_buf[i]);
1446 TEST_ASSERT_SUCCESS(retval,
1447 "Slave should allow manual LACP xmit");
1450 nb_pkts = bond_tx(NULL, 0);
1451 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
1453 FOR_EACH_SLAVE(i, slave) {
1454 nb_pkts = slave_get_pkts(slave, buf, RTE_DIM(buf));
1455 TEST_ASSERT_EQUAL(nb_pkts, 1, "found %u packets on slave %d\n",
1457 slave_put_pkts(slave, buf, nb_pkts);
1460 nb_pkts = bond_rx(buf, RTE_DIM(buf));
1461 free_pkts(buf, nb_pkts);
1462 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
1464 /* wait for the periodic callback to run */
1465 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
1466 uint8_t s, total = 0;
1468 rte_delay_ms(delay);
1469 FOR_EACH_SLAVE(s, slave) {
1470 total += lacpdu_rx_count[slave->port_id];
1473 if (total >= SLAVE_COUNT)
1474 all_slaves_done = 1;
1477 FOR_EACH_SLAVE(i, slave) {
1478 TEST_ASSERT_EQUAL(lacpdu_rx_count[slave->port_id], 1,
1479 "Slave port %u should have received 1 lacpdu (count=%u)",
1481 lacpdu_rx_count[slave->port_id]);
1484 retval = remove_slaves_and_stop_bonded_device();
1485 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1487 return TEST_SUCCESS;
1491 check_environment(void)
1493 struct slave_conf *port;
1494 uint8_t i, env_state;
1495 uint16_t slaves[RTE_DIM(test_params.slave_ports)];
1499 FOR_EACH_PORT(i, port) {
1500 if (rte_ring_count(port->rx_queue) != 0)
1503 if (rte_ring_count(port->tx_queue) != 0)
1506 if (port->bonded != 0)
1509 if (port->lacp_parnter_state != 0)
1516 slaves_count = rte_eth_bond_slaves_get(test_params.bonded_port_id,
1517 slaves, RTE_DIM(slaves));
1519 if (slaves_count != 0)
1522 TEST_ASSERT_EQUAL(env_state, 0,
1523 "Environment not clean (port %u):%s%s%s%s%s",
1525 env_state & 0x01 ? " slave rx queue not clean" : "",
1526 env_state & 0x02 ? " slave tx queue not clean" : "",
1527 env_state & 0x04 ? " port marked as enslaved" : "",
1528 env_state & 0x80 ? " slave state is not reset" : "",
1529 env_state & 0x10 ? " slave count not equal 0" : ".");
1532 return TEST_SUCCESS;
1536 test_mode4_executor(int (*test_func)(void))
1538 struct slave_conf *port;
1543 /* Check if environment is clean. Fail to launch a test if there was
1544 * a critical error before that prevented to reset environment. */
1545 TEST_ASSERT_SUCCESS(check_environment(),
1546 "Refusing to launch test in dirty environment.");
1548 RTE_VERIFY(test_func != NULL);
1549 test_result = (*test_func)();
1551 /* If test succeed check if environment wast left in good condition. */
1552 if (test_result == TEST_SUCCESS)
1553 test_result = check_environment();
1555 /* Reset environment in case test failed to do that. */
1556 if (test_result != TEST_SUCCESS) {
1557 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
1558 "Failed to stop bonded device");
1560 FOR_EACH_PORT(i, port) {
1561 while (rte_ring_count(port->rx_queue) != 0) {
1562 if (rte_ring_dequeue(port->rx_queue, &pkt) == 0)
1563 rte_pktmbuf_free(pkt);
1566 while (rte_ring_count(port->tx_queue) != 0) {
1567 if (rte_ring_dequeue(port->tx_queue, &pkt) == 0)
1568 rte_pktmbuf_free(pkt);
1577 test_mode4_agg_mode_selection_wrapper(void){
1578 return test_mode4_executor(&test_mode4_agg_mode_selection);
1582 test_mode4_lacp_wrapper(void)
1584 return test_mode4_executor(&test_mode4_lacp);
1588 test_mode4_marker_wrapper(void)
1590 return test_mode4_executor(&test_mode4_marker);
1594 test_mode4_rx_wrapper(void)
1596 return test_mode4_executor(&test_mode4_rx);
1600 test_mode4_tx_burst_wrapper(void)
1602 return test_mode4_executor(&test_mode4_tx_burst);
1606 test_mode4_expired_wrapper(void)
1608 return test_mode4_executor(&test_mode4_expired);
1612 test_mode4_ext_ctrl_wrapper(void)
1614 return test_mode4_executor(&test_mode4_ext_ctrl);
1618 test_mode4_ext_lacp_wrapper(void)
1620 return test_mode4_executor(&test_mode4_ext_lacp);
1623 static struct unit_test_suite link_bonding_mode4_test_suite = {
1624 .suite_name = "Link Bonding mode 4 Unit Test Suite",
1625 .setup = test_setup,
1626 .teardown = testsuite_teardown,
1627 .unit_test_cases = {
1628 TEST_CASE_NAMED("test_mode4_agg_mode_selection",
1629 test_mode4_agg_mode_selection_wrapper),
1630 TEST_CASE_NAMED("test_mode4_lacp", test_mode4_lacp_wrapper),
1631 TEST_CASE_NAMED("test_mode4_rx", test_mode4_rx_wrapper),
1632 TEST_CASE_NAMED("test_mode4_tx_burst", test_mode4_tx_burst_wrapper),
1633 TEST_CASE_NAMED("test_mode4_marker", test_mode4_marker_wrapper),
1634 TEST_CASE_NAMED("test_mode4_expired", test_mode4_expired_wrapper),
1635 TEST_CASE_NAMED("test_mode4_ext_ctrl",
1636 test_mode4_ext_ctrl_wrapper),
1637 TEST_CASE_NAMED("test_mode4_ext_lacp",
1638 test_mode4_ext_lacp_wrapper),
1640 TEST_CASES_END() /**< NULL terminate unit test array */
1645 test_link_bonding_mode4(void)
1647 return unit_test_suite_runner(&link_bonding_mode4_test_suite);
1650 REGISTER_TEST_COMMAND(link_bonding_mode4_autotest, test_link_bonding_mode4);