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 = RTE_ETH_MQ_RX_NONE,
114 .mq_mode = RTE_ETH_MQ_TX_NONE,
119 static uint8_t lacpdu_rx_count[RTE_MAX_ETHPORTS] = {0, };
121 #define FOR_EACH(_i, _item, _array, _size) \
122 for (_i = 0, _item = &_array[0]; _i < _size && (_item = &_array[_i]); _i++)
124 /* Macro for iterating over every port that can be used as a slave
126 * _i variable used as an index in test_params->slave_ports
127 * _slave pointer to &test_params->slave_ports[_idx]
129 #define FOR_EACH_PORT(_i, _port) \
130 FOR_EACH(_i, _port, test_params.slave_ports, \
131 RTE_DIM(test_params.slave_ports))
133 /* Macro for iterating over every port that can be used as a slave
134 * in this test and satisfy given condition.
136 * _i variable used as an index in test_params->slave_ports
137 * _slave pointer to &test_params->slave_ports[_idx]
138 * _condition condition that need to be checked
140 #define FOR_EACH_PORT_IF(_i, _port, _condition) FOR_EACH_PORT((_i), (_port)) \
143 /* Macro for iterating over every port that is currently a slave of a bonded
145 * _i variable used as an index in test_params->slave_ports
146 * _slave pointer to &test_params->slave_ports[_idx]
148 #define FOR_EACH_SLAVE(_i, _slave) \
149 FOR_EACH_PORT_IF(_i, _slave, (_slave)->bonded != 0)
152 * Returns packets from slaves TX queue.
155 * size size of buffer
156 * return number of packets or negative error number
159 slave_get_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
161 return rte_ring_dequeue_burst(slave->tx_queue, (void **)buf,
166 * Injects given packets into slaves RX queue.
169 * size number of packets to be injected
170 * return number of queued packets or negative error number
173 slave_put_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
175 return rte_ring_enqueue_burst(slave->rx_queue, (void **)buf,
180 bond_rx(struct rte_mbuf **buf, uint16_t size)
182 return rte_eth_rx_burst(test_params.bonded_port_id, 0, buf, size);
186 bond_tx(struct rte_mbuf **buf, uint16_t size)
188 return rte_eth_tx_burst(test_params.bonded_port_id, 0, buf, size);
192 free_pkts(struct rte_mbuf **pkts, uint16_t count)
196 for (i = 0; i < count; i++) {
197 rte_pktmbuf_free(pkts[i]);
202 configure_ethdev(uint16_t port_id, uint8_t start)
204 TEST_ASSERT(rte_eth_dev_configure(port_id, 1, 1, &default_pmd_conf) == 0,
205 "Failed to configure device %u", port_id);
207 TEST_ASSERT(rte_eth_rx_queue_setup(port_id, 0, RX_RING_SIZE,
208 rte_eth_dev_socket_id(port_id), NULL, test_params.mbuf_pool) == 0,
209 "Failed to setup rx queue.");
211 TEST_ASSERT(rte_eth_tx_queue_setup(port_id, 0, TX_RING_SIZE,
212 rte_eth_dev_socket_id(port_id), NULL) == 0,
213 "Failed to setup tx queue.");
216 TEST_ASSERT(rte_eth_dev_start(port_id) == 0,
217 "Failed to start device (%d).", port_id);
223 add_slave(struct slave_conf *slave, uint8_t start)
225 struct rte_ether_addr addr, addr_check;
228 /* Some sanity check */
229 RTE_VERIFY(test_params.slave_ports <= slave &&
230 slave - test_params.slave_ports < (int)RTE_DIM(test_params.slave_ports));
231 RTE_VERIFY(slave->bonded == 0);
232 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
234 rte_ether_addr_copy(&slave_mac_default, &addr);
235 addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
237 rte_eth_dev_mac_addr_remove(slave->port_id, &addr);
239 TEST_ASSERT_SUCCESS(rte_eth_dev_mac_addr_add(slave->port_id, &addr, 0),
240 "Failed to set slave MAC address");
242 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params.bonded_port_id,
244 "Failed to add slave (idx=%u, id=%u) to bonding (id=%u)",
245 (uint8_t)(slave - test_params.slave_ports), slave->port_id,
246 test_params.bonded_port_id);
250 TEST_ASSERT_SUCCESS(rte_eth_dev_start(slave->port_id),
251 "Failed to start slave %u", slave->port_id);
254 retval = rte_eth_macaddr_get(slave->port_id, &addr_check);
255 TEST_ASSERT_SUCCESS(retval, "Failed to get slave mac address: %s",
257 TEST_ASSERT_EQUAL(rte_is_same_ether_addr(&addr, &addr_check), 1,
258 "Slave MAC address is not as expected");
260 RTE_VERIFY(slave->lacp_parnter_state == 0);
265 remove_slave(struct slave_conf *slave)
267 ptrdiff_t slave_idx = slave - test_params.slave_ports;
269 RTE_VERIFY(test_params.slave_ports <= slave &&
270 slave_idx < (ptrdiff_t)RTE_DIM(test_params.slave_ports));
272 RTE_VERIFY(slave->bonded == 1);
273 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
275 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
276 "Slave %u tx queue not empty while removing from bonding.",
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_eth_bond_slave_remove(test_params.bonded_port_id,
285 "Failed to remove slave (idx=%u, id=%u) from bonding (id=%u)",
286 (uint8_t)slave_idx, slave->port_id,
287 test_params.bonded_port_id);
290 slave->lacp_parnter_state = 0;
295 lacp_recv_cb(uint16_t slave_id, struct rte_mbuf *lacp_pkt)
297 struct rte_ether_hdr *hdr;
298 struct slow_protocol_frame *slow_hdr;
300 RTE_VERIFY(lacp_pkt != NULL);
302 hdr = rte_pktmbuf_mtod(lacp_pkt, struct rte_ether_hdr *);
303 RTE_VERIFY(hdr->ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW));
305 slow_hdr = rte_pktmbuf_mtod(lacp_pkt, struct slow_protocol_frame *);
306 RTE_VERIFY(slow_hdr->slow_protocol.subtype == SLOW_SUBTYPE_LACP);
308 lacpdu_rx_count[slave_id]++;
309 rte_pktmbuf_free(lacp_pkt);
313 initialize_bonded_device_with_slaves(uint16_t slave_count, uint8_t external_sm)
318 RTE_VERIFY(test_params.bonded_port_id != INVALID_PORT_ID);
320 for (i = 0; i < slave_count; i++) {
321 TEST_ASSERT_SUCCESS(add_slave(&test_params.slave_ports[i], 1),
322 "Failed to add port %u to bonded device.\n",
323 test_params.slave_ports[i].port_id);
326 /* Reset mode 4 configuration */
327 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, NULL);
328 ret = rte_eth_promiscuous_disable(test_params.bonded_port_id);
329 TEST_ASSERT_SUCCESS(ret,
330 "Failed disable promiscuous mode for port %d: %s",
331 test_params.bonded_port_id, rte_strerror(-ret));
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 TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params.bonded_port_id),
357 "Failed to stop bonded port %u",
358 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 TEST_ASSERT_SUCCESS(rte_eth_dev_stop(slave->port_id),
372 "Failed to stop bonded port %u",
375 TEST_ASSERT(slave->bonded == 0,
376 "Port id=%u is still marked as enslaved.", slave->port_id);
385 int retval, nb_mbuf_per_pool;
386 char name[RTE_ETH_NAME_MAX_LEN];
387 struct slave_conf *port;
388 const uint8_t socket_id = rte_socket_id();
391 if (test_params.mbuf_pool == NULL) {
392 nb_mbuf_per_pool = TEST_RX_DESC_MAX + DEF_PKT_BURST +
393 TEST_TX_DESC_MAX + MAX_PKT_BURST;
394 test_params.mbuf_pool = rte_pktmbuf_pool_create("TEST_MODE4",
395 nb_mbuf_per_pool, MBUF_CACHE_SIZE, 0,
396 RTE_MBUF_DEFAULT_BUF_SIZE, socket_id);
398 TEST_ASSERT(test_params.mbuf_pool != NULL,
399 "rte_mempool_create failed\n");
402 /* Create / initialize ring eth devs. */
403 FOR_EACH_PORT(i, port) {
404 port = &test_params.slave_ports[i];
406 if (port->rx_queue == NULL) {
407 retval = snprintf(name, RTE_DIM(name), SLAVE_RX_QUEUE_FMT, i);
408 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
409 port->rx_queue = rte_ring_create(name, RX_RING_SIZE, socket_id, 0);
410 TEST_ASSERT(port->rx_queue != NULL,
411 "Failed to allocate rx ring '%s': %s", name,
412 rte_strerror(rte_errno));
415 if (port->tx_queue == NULL) {
416 retval = snprintf(name, RTE_DIM(name), SLAVE_TX_QUEUE_FMT, i);
417 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
418 port->tx_queue = rte_ring_create(name, TX_RING_SIZE, socket_id, 0);
419 TEST_ASSERT_NOT_NULL(port->tx_queue,
420 "Failed to allocate tx ring '%s': %s", name,
421 rte_strerror(rte_errno));
424 if (port->port_id == INVALID_PORT_ID) {
425 retval = snprintf(name, RTE_DIM(name), SLAVE_DEV_NAME_FMT, i);
426 TEST_ASSERT(retval < (int)RTE_DIM(name) - 1, "Name too long");
427 retval = rte_eth_from_rings(name, &port->rx_queue, 1,
428 &port->tx_queue, 1, socket_id);
429 TEST_ASSERT(retval >= 0,
430 "Failed to create ring ethdev '%s'\n", name);
432 port->port_id = rte_eth_dev_count_avail() - 1;
435 retval = configure_ethdev(port->port_id, 1);
436 TEST_ASSERT_SUCCESS(retval, "Failed to configure virtual ethdev %s\n",
440 if (test_params.bonded_port_id == INVALID_PORT_ID) {
441 retval = rte_eth_bond_create(BONDED_DEV_NAME, BONDING_MODE_8023AD,
444 TEST_ASSERT(retval >= 0, "Failed to create bonded ethdev %s",
447 test_params.bonded_port_id = retval;
448 TEST_ASSERT_SUCCESS(configure_ethdev(test_params.bonded_port_id, 0),
449 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME);
450 } else if (rte_eth_bond_mode_get(test_params.bonded_port_id) !=
451 BONDING_MODE_8023AD) {
452 TEST_ASSERT(rte_eth_bond_mode_set(test_params.bonded_port_id,
453 BONDING_MODE_8023AD) == 0,
454 "Failed to set ethdev %d to mode %d",
455 test_params.bonded_port_id, BONDING_MODE_8023AD);
462 testsuite_teardown(void)
464 struct slave_conf *port;
468 * Any cleanup/reset state is done when particular test is
471 rte_eth_dev_stop(test_params.bonded_port_id);
473 FOR_EACH_PORT(i, port)
474 rte_eth_dev_stop(port->port_id);
478 * Check if given LACP packet. If it is, make make replay packet to force
480 * return 0 when pkt is LACP frame, 1 if it is not slow frame, 2 if it is slow
484 make_lacp_reply(struct slave_conf *slave, struct rte_mbuf *pkt)
486 struct rte_ether_hdr *hdr;
487 struct slow_protocol_frame *slow_hdr;
491 hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
492 if (hdr->ether_type != rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW))
495 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
496 /* ignore packets of other types */
497 if (slow_hdr->slow_protocol.subtype != SLOW_SUBTYPE_LACP)
500 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
502 /* Change source address to partner address */
503 rte_ether_addr_copy(&parnter_mac_default, &slow_hdr->eth_hdr.src_addr);
504 slow_hdr->eth_hdr.src_addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
507 lacp = (struct lacpdu *) &slow_hdr->slow_protocol;
508 /* Save last received state */
509 slave->lacp_parnter_state = lacp->actor.state;
510 /* Change it into LACP replay by matching parameters. */
511 memcpy(&lacp->partner.port_params, &lacp->actor.port_params,
512 sizeof(struct port_params));
514 lacp->partner.state = lacp->actor.state;
516 rte_ether_addr_copy(&parnter_system, &lacp->actor.port_params.system);
517 lacp->actor.state = STATE_LACP_ACTIVE |
518 STATE_SYNCHRONIZATION |
527 * Reads packets from given slave, search for LACP packet and reply them.
529 * Receives burst of packets from slave. Looks for LACP packet. Drops
530 * all other packets. Prepares response LACP and sends it back.
532 * return number of LACP received and replied, -1 on error.
535 bond_handshake_reply(struct slave_conf *slave)
538 struct rte_mbuf *rx_buf[MAX_PKT_BURST];
539 struct rte_mbuf *lacp_tx_buf[MAX_PKT_BURST];
540 uint16_t lacp_tx_buf_cnt = 0, i;
542 retval = slave_get_pkts(slave, rx_buf, RTE_DIM(rx_buf));
543 TEST_ASSERT(retval >= 0, "Getting slave %u packets failed.",
546 for (i = 0; i < (uint16_t)retval; i++) {
547 if (make_lacp_reply(slave, rx_buf[i]) == 0) {
548 /* reply with actor's LACP */
549 lacp_tx_buf[lacp_tx_buf_cnt++] = rx_buf[i];
551 rte_pktmbuf_free(rx_buf[i]);
554 if (lacp_tx_buf_cnt == 0)
557 retval = slave_put_pkts(slave, lacp_tx_buf, lacp_tx_buf_cnt);
558 if (retval <= lacp_tx_buf_cnt) {
559 /* retval might be negative */
560 for (i = RTE_MAX(0, retval); retval < lacp_tx_buf_cnt; retval++)
561 rte_pktmbuf_free(lacp_tx_buf[i]);
564 TEST_ASSERT_EQUAL(retval, lacp_tx_buf_cnt,
565 "Failed to equeue lacp packets into slave %u tx queue.",
568 return lacp_tx_buf_cnt;
572 * Function check if given slave tx queue contains packets that make mode 4
573 * handshake complete. It will drain slave queue.
574 * return 0 if handshake not completed, 1 if handshake was complete,
577 bond_handshake_done(struct slave_conf *slave)
579 const uint8_t expected_state = STATE_LACP_ACTIVE | STATE_SYNCHRONIZATION |
580 STATE_AGGREGATION | STATE_COLLECTING | STATE_DISTRIBUTING;
582 return slave->lacp_parnter_state == expected_state;
586 bond_get_update_timeout_ms(void)
588 struct rte_eth_bond_8023ad_conf conf;
590 if (rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf) < 0) {
591 RTE_LOG(DEBUG, EAL, "Failed to get bonding configuration: "
592 "%s at %d\n", __func__, __LINE__);
593 RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__);
597 return conf.update_timeout_ms;
601 * Exchanges LACP packets with partner to achieve dynamic port configuration.
602 * return TEST_SUCCESS if initial handshake succeed, TEST_FAILED otherwise.
607 struct slave_conf *slave;
608 struct rte_mbuf *buf[MAX_PKT_BURST];
610 uint8_t all_slaves_done, i, j;
611 uint8_t status[RTE_DIM(test_params.slave_ports)] = { 0 };
612 const unsigned delay = bond_get_update_timeout_ms();
614 /* Exchange LACP frames */
616 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
620 FOR_EACH_SLAVE(j, slave) {
621 /* If response already send, skip slave */
625 if (bond_handshake_reply(slave) < 0) {
630 status[j] = bond_handshake_done(slave);
635 nb_pkts = bond_tx(NULL, 0);
636 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
638 nb_pkts = bond_rx(buf, RTE_DIM(buf));
639 free_pkts(buf, nb_pkts);
640 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
642 /* If response didn't send - report failure */
643 TEST_ASSERT_EQUAL(all_slaves_done, 1, "Bond handshake failed\n");
645 /* If flags doesn't match - report failure */
646 return all_slaves_done == 1 ? TEST_SUCCESS : TEST_FAILED;
649 #define TEST_LACP_SLAVE_COUT RTE_DIM(test_params.slave_ports)
651 test_mode4_lacp(void)
655 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
656 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
658 /* Test LACP handshake function */
659 retval = bond_handshake();
660 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
662 retval = remove_slaves_and_stop_bonded_device();
663 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
668 test_mode4_agg_mode_selection(void)
671 /* Test and verify for Stable mode */
672 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
673 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
676 retval = rte_eth_bond_8023ad_agg_selection_set(
677 test_params.bonded_port_id, AGG_STABLE);
678 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bond aggregation mode");
679 retval = bond_handshake();
680 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
683 retval = rte_eth_bond_8023ad_agg_selection_get(
684 test_params.bonded_port_id);
685 TEST_ASSERT_EQUAL(retval, AGG_STABLE,
686 "Wrong agg mode received from bonding device");
688 retval = remove_slaves_and_stop_bonded_device();
689 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
692 /* test and verify for Bandwidth mode */
693 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
694 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
697 retval = rte_eth_bond_8023ad_agg_selection_set(
698 test_params.bonded_port_id,
700 TEST_ASSERT_SUCCESS(retval,
701 "Failed to initialize bond aggregation mode");
702 retval = bond_handshake();
703 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
705 retval = rte_eth_bond_8023ad_agg_selection_get(
706 test_params.bonded_port_id);
707 TEST_ASSERT_EQUAL(retval, AGG_BANDWIDTH,
708 "Wrong agg mode received from bonding device");
710 retval = remove_slaves_and_stop_bonded_device();
711 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
713 /* test and verify selection for count mode */
714 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
715 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
718 retval = rte_eth_bond_8023ad_agg_selection_set(
719 test_params.bonded_port_id, AGG_COUNT);
720 TEST_ASSERT_SUCCESS(retval,
721 "Failed to initialize bond aggregation mode");
722 retval = bond_handshake();
723 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
725 retval = rte_eth_bond_8023ad_agg_selection_get(
726 test_params.bonded_port_id);
727 TEST_ASSERT_EQUAL(retval, AGG_COUNT,
728 "Wrong agg mode received from bonding device");
730 retval = remove_slaves_and_stop_bonded_device();
731 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
737 generate_packets(struct rte_ether_addr *src_mac,
738 struct rte_ether_addr *dst_mac, uint16_t count, struct rte_mbuf **buf)
740 uint16_t pktlen = PACKET_BURST_GEN_PKT_LEN;
741 uint8_t vlan_enable = 0;
742 uint16_t vlan_id = 0;
743 uint8_t ip4_type = 1; /* 0 - ipv6 */
745 uint16_t src_port = 10, dst_port = 20;
747 uint32_t ip_src[4] = { [0 ... 2] = 0xDEADBEEF, [3] = RTE_IPV4(192, 168, 0, 1) };
748 uint32_t ip_dst[4] = { [0 ... 2] = 0xFEEDFACE, [3] = RTE_IPV4(192, 168, 0, 2) };
750 struct rte_ether_hdr pkt_eth_hdr;
751 struct rte_udp_hdr pkt_udp_hdr;
753 struct rte_ipv4_hdr v4;
754 struct rte_ipv6_hdr v6;
759 initialize_eth_header(&pkt_eth_hdr, src_mac, dst_mac, ip4_type,
760 vlan_enable, vlan_id);
763 initialize_ipv4_header(&pkt_ip_hdr.v4, ip_src[3], ip_dst[3], pktlen);
765 initialize_ipv6_header(&pkt_ip_hdr.v6, (uint8_t *)ip_src,
766 (uint8_t *)&ip_dst, pktlen);
768 initialize_udp_header(&pkt_udp_hdr, src_port, dst_port, 16);
770 retval = generate_packet_burst(test_params.mbuf_pool, buf,
771 &pkt_eth_hdr, vlan_enable, &pkt_ip_hdr, 1, &pkt_udp_hdr,
774 if (retval > 0 && retval != count)
775 free_pkts(&buf[count - retval], retval);
777 TEST_ASSERT_EQUAL(retval, count, "Failed to generate %u packets",
784 generate_and_put_packets(struct slave_conf *slave,
785 struct rte_ether_addr *src_mac,
786 struct rte_ether_addr *dst_mac, uint16_t count)
788 struct rte_mbuf *pkts[MAX_PKT_BURST];
791 retval = generate_packets(src_mac, dst_mac, count, pkts);
792 if (retval != (int)count)
795 retval = slave_put_pkts(slave, pkts, count);
796 if (retval > 0 && retval != count)
797 free_pkts(&pkts[retval], count - retval);
799 TEST_ASSERT_EQUAL(retval, count,
800 "Failed to enqueue packets into slave %u RX queue", slave->port_id);
808 struct slave_conf *slave;
811 uint16_t expected_pkts_cnt;
812 struct rte_mbuf *pkts[MAX_PKT_BURST];
816 struct rte_ether_hdr *hdr;
818 struct rte_ether_addr src_mac = {
819 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
820 struct rte_ether_addr dst_mac;
821 struct rte_ether_addr bonded_mac;
823 retval = initialize_bonded_device_with_slaves(TEST_PROMISC_SLAVE_COUNT,
825 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
827 retval = bond_handshake();
828 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
830 retval = rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
831 TEST_ASSERT_SUCCESS(retval, "Failed to get mac address: %s",
833 rte_ether_addr_copy(&bonded_mac, &dst_mac);
835 /* Assert that dst address is not bonding address. Do not set the
836 * least significant bit of the zero byte as this would create a
839 dst_mac.addr_bytes[0] += 2;
841 /* First try with promiscuous mode enabled.
842 * Add 2 packets to each slave. First with bonding MAC address, second with
843 * different. Check if we received all of them. */
844 retval = rte_eth_promiscuous_enable(test_params.bonded_port_id);
845 TEST_ASSERT_SUCCESS(retval,
846 "Failed to enable promiscuous mode for port %d: %s",
847 test_params.bonded_port_id, rte_strerror(-retval));
849 expected_pkts_cnt = 0;
850 FOR_EACH_SLAVE(i, slave) {
851 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
852 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
855 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
856 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
859 /* Expect 2 packets per slave */
860 expected_pkts_cnt += 2;
863 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
866 if (retval == expected_pkts_cnt) {
867 int cnt[2] = { 0, 0 };
869 for (i = 0; i < expected_pkts_cnt; i++) {
870 hdr = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *);
871 cnt[rte_is_same_ether_addr(&hdr->dst_addr,
875 free_pkts(pkts, expected_pkts_cnt);
877 /* For division by 2 expected_pkts_cnt must be even */
878 RTE_VERIFY((expected_pkts_cnt & 1) == 0);
879 TEST_ASSERT(cnt[0] == expected_pkts_cnt / 2 &&
880 cnt[1] == expected_pkts_cnt / 2,
881 "Expected %u packets with the same MAC and %u with different but "
882 "got %u with the same and %u with different MAC",
883 expected_pkts_cnt / 2, expected_pkts_cnt / 2, cnt[1], cnt[0]);
884 } else if (retval > 0)
885 free_pkts(pkts, retval);
887 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
888 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
890 /* Now, disable promiscuous mode. When promiscuous mode is disabled we
891 * expect to receive only packets that are directed to bonding port. */
892 retval = rte_eth_promiscuous_disable(test_params.bonded_port_id);
893 TEST_ASSERT_SUCCESS(retval,
894 "Failed to disable promiscuous mode for port %d: %s",
895 test_params.bonded_port_id, rte_strerror(-retval));
897 expected_pkts_cnt = 0;
898 FOR_EACH_SLAVE(i, slave) {
899 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
900 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
903 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
904 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
907 /* Expect only one packet per slave */
908 expected_pkts_cnt += 1;
911 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
914 if (retval == expected_pkts_cnt) {
917 for (i = 0; i < expected_pkts_cnt; i++) {
918 hdr = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *);
919 eq_cnt += rte_is_same_ether_addr(&hdr->dst_addr,
923 free_pkts(pkts, expected_pkts_cnt);
924 TEST_ASSERT_EQUAL(eq_cnt, expected_pkts_cnt, "Packet address mismatch");
925 } else if (retval > 0)
926 free_pkts(pkts, retval);
928 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
929 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
931 /* Link down test: simulate link down for first slave. */
932 delay = bond_get_update_timeout_ms();
934 uint8_t slave_down_id = INVALID_PORT_ID;
936 /* Find first slave and make link down on it*/
937 FOR_EACH_SLAVE(i, slave) {
938 rte_eth_dev_set_link_down(slave->port_id);
939 slave_down_id = slave->port_id;
943 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
945 /* Give some time to rearrange bonding */
946 for (i = 0; i < 3; i++) {
951 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
953 /* Put packet to each slave */
954 FOR_EACH_SLAVE(i, slave) {
957 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
958 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
959 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
961 src_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = slave->port_id;
962 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
963 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
965 retval = bond_rx(pkts, RTE_DIM(pkts));
969 free_pkts(pkts, retval);
971 while (rte_ring_dequeue(slave->rx_queue, (void **)&pkt) == 0)
972 rte_pktmbuf_free(pkt);
974 if (slave_down_id == slave->port_id)
975 TEST_ASSERT_EQUAL(retval, 0, "Packets received unexpectedly.");
977 TEST_ASSERT_NOT_EQUAL(retval, 0,
978 "Expected to receive some packets on slave %u.",
980 rte_eth_dev_start(slave->port_id);
982 for (j = 0; j < 5; j++) {
983 TEST_ASSERT(bond_handshake_reply(slave) >= 0,
984 "Handshake after link up");
986 if (bond_handshake_done(slave) == 1)
990 TEST_ASSERT(j < 5, "Failed to aggregate slave after link up");
993 remove_slaves_and_stop_bonded_device();
998 test_mode4_tx_burst(void)
1000 struct slave_conf *slave;
1003 uint16_t exp_pkts_cnt, pkts_cnt = 0;
1004 struct rte_mbuf *pkts[MAX_PKT_BURST];
1008 struct rte_ether_addr dst_mac = {
1009 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
1010 struct rte_ether_addr bonded_mac;
1012 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1013 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1015 retval = bond_handshake();
1016 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1018 retval = rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
1019 TEST_ASSERT_SUCCESS(retval, "Failed to get mac address: %s",
1022 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1023 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = pkts_cnt;
1024 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1027 free_pkts(pkts, pkts_cnt);
1029 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate packet %u", pkts_cnt);
1031 exp_pkts_cnt = pkts_cnt;
1033 /* Transmit packets on bonded device */
1034 retval = bond_tx(pkts, pkts_cnt);
1035 if (retval > 0 && retval < pkts_cnt)
1036 free_pkts(&pkts[retval], pkts_cnt - retval);
1038 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1040 /* Check if packets were transmitted properly. Every slave should have
1041 * at least one packet, and sum must match. Under normal operation
1042 * there should be no LACP nor MARKER frames. */
1044 FOR_EACH_SLAVE(i, slave) {
1045 uint16_t normal_cnt, slow_cnt;
1047 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1051 for (j = 0; j < retval; j++) {
1052 if (make_lacp_reply(slave, pkts[j]) == 1)
1058 free_pkts(pkts, normal_cnt + slow_cnt);
1059 TEST_ASSERT_EQUAL(slow_cnt, 0,
1060 "slave %u unexpectedly transmitted %d SLOW packets", slave->port_id,
1063 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1064 "slave %u did not transmitted any packets", slave->port_id);
1066 pkts_cnt += normal_cnt;
1069 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1070 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1073 * simulate link down for first slave. */
1074 delay = bond_get_update_timeout_ms();
1076 uint8_t slave_down_id = INVALID_PORT_ID;
1078 FOR_EACH_SLAVE(i, slave) {
1079 rte_eth_dev_set_link_down(slave->port_id);
1080 slave_down_id = slave->port_id;
1084 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
1086 /* Give some time to rearrange bonding. */
1087 for (i = 0; i < 3; i++) {
1089 rte_delay_ms(delay);
1092 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
1094 /* Prepare burst. */
1095 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1096 dst_mac.addr_bytes[RTE_ETHER_ADDR_LEN - 1] = pkts_cnt;
1097 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1100 free_pkts(pkts, pkts_cnt);
1102 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate test packet %u",
1105 exp_pkts_cnt = pkts_cnt;
1107 /* Transmit packets on bonded device. */
1108 retval = bond_tx(pkts, pkts_cnt);
1109 if (retval > 0 && retval < pkts_cnt)
1110 free_pkts(&pkts[retval], pkts_cnt - retval);
1112 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1114 /* Check if packets was transmitted properly. Every slave should have
1115 * at least one packet, and sum must match. Under normal operation
1116 * there should be no LACP nor MARKER frames. */
1118 FOR_EACH_SLAVE(i, slave) {
1119 uint16_t normal_cnt, slow_cnt;
1121 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1125 for (j = 0; j < retval; j++) {
1126 if (make_lacp_reply(slave, pkts[j]) == 1)
1132 free_pkts(pkts, normal_cnt + slow_cnt);
1134 if (slave_down_id == slave->port_id) {
1135 TEST_ASSERT_EQUAL(normal_cnt + slow_cnt, 0,
1136 "slave %u enexpectedly transmitted %u packets",
1137 normal_cnt + slow_cnt, slave->port_id);
1139 TEST_ASSERT_EQUAL(slow_cnt, 0,
1140 "slave %u unexpectedly transmitted %d SLOW packets",
1141 slave->port_id, slow_cnt);
1143 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1144 "slave %u did not transmitted any packets", slave->port_id);
1147 pkts_cnt += normal_cnt;
1150 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1151 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1153 return remove_slaves_and_stop_bonded_device();
1157 init_marker(struct rte_mbuf *pkt, struct slave_conf *slave)
1159 struct marker_header *marker_hdr = rte_pktmbuf_mtod(pkt,
1160 struct marker_header *);
1162 /* Copy multicast destination address */
1163 rte_ether_addr_copy(&slow_protocol_mac_addr,
1164 &marker_hdr->eth_hdr.dst_addr);
1166 /* Init source address */
1167 rte_ether_addr_copy(&parnter_mac_default,
1168 &marker_hdr->eth_hdr.src_addr);
1169 marker_hdr->eth_hdr.src_addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
1172 marker_hdr->eth_hdr.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_SLOW);
1174 marker_hdr->marker.subtype = SLOW_SUBTYPE_MARKER;
1175 marker_hdr->marker.version_number = 1;
1176 marker_hdr->marker.tlv_type_marker = MARKER_TLV_TYPE_INFO;
1177 marker_hdr->marker.info_length =
1178 offsetof(struct marker, reserved_90) -
1179 offsetof(struct marker, requester_port);
1180 RTE_VERIFY(marker_hdr->marker.info_length == 16);
1181 marker_hdr->marker.requester_port = slave->port_id + 1;
1182 marker_hdr->marker.tlv_type_terminator = TLV_TYPE_TERMINATOR_INFORMATION;
1183 marker_hdr->marker.terminator_length = 0;
1187 test_mode4_marker(void)
1189 struct slave_conf *slave;
1190 struct rte_mbuf *pkts[MAX_PKT_BURST];
1191 struct rte_mbuf *marker_pkt;
1192 struct marker_header *marker_hdr;
1198 const uint16_t ethtype_slow_be = rte_be_to_cpu_16(RTE_ETHER_TYPE_SLOW);
1200 retval = initialize_bonded_device_with_slaves(TEST_MARKER_SLAVE_COUT,
1202 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1204 /* Test LACP handshake function */
1205 retval = bond_handshake();
1206 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1208 delay = bond_get_update_timeout_ms();
1209 FOR_EACH_SLAVE(i, slave) {
1210 marker_pkt = rte_pktmbuf_alloc(test_params.mbuf_pool);
1211 TEST_ASSERT_NOT_NULL(marker_pkt, "Failed to allocate marker packet");
1212 init_marker(marker_pkt, slave);
1214 retval = slave_put_pkts(slave, &marker_pkt, 1);
1216 rte_pktmbuf_free(marker_pkt);
1218 TEST_ASSERT_EQUAL(retval, 1,
1219 "Failed to send marker packet to slave %u", slave->port_id);
1221 for (j = 0; j < 20; ++j) {
1222 rte_delay_ms(delay);
1223 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
1227 free_pkts(pkts, retval);
1229 TEST_ASSERT_EQUAL(retval, 0, "Received packets unexpectedly");
1231 retval = rte_eth_tx_burst(test_params.bonded_port_id, 0, NULL, 0);
1232 TEST_ASSERT_EQUAL(retval, 0,
1233 "Requested TX of 0 packets but %d transmitted", retval);
1235 /* Check if LACP packet was send by state machines
1236 First and only packet must be a maker response */
1237 retval = slave_get_pkts(slave, pkts, MAX_PKT_BURST);
1241 free_pkts(pkts, retval);
1243 TEST_ASSERT_EQUAL(retval, 1, "failed to get slave packets");
1246 marker_hdr = rte_pktmbuf_mtod(pkts[0], struct marker_header *);
1247 /* Check if it's slow packet*/
1248 if (marker_hdr->eth_hdr.ether_type != ethtype_slow_be)
1250 /* Check if it's marker packet */
1251 else if (marker_hdr->marker.subtype != SLOW_SUBTYPE_MARKER)
1253 else if (marker_hdr->marker.tlv_type_marker != MARKER_TLV_TYPE_RESP)
1256 free_pkts(pkts, nb_pkts);
1258 TEST_ASSERT_NOT_EQUAL(retval, -1, "Unexpected protocol type");
1259 TEST_ASSERT_NOT_EQUAL(retval, -2, "Unexpected sub protocol type");
1260 TEST_ASSERT_NOT_EQUAL(retval, -3, "Unexpected marker type");
1264 TEST_ASSERT(j < 20, "Marker response not found");
1267 retval = remove_slaves_and_stop_bonded_device();
1268 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1270 return TEST_SUCCESS;
1274 test_mode4_expired(void)
1276 struct slave_conf *slave, *exp_slave = NULL;
1277 struct rte_mbuf *pkts[MAX_PKT_BURST];
1284 struct rte_eth_bond_8023ad_conf conf;
1286 retval = initialize_bonded_device_with_slaves(TEST_EXPIRED_SLAVE_COUNT,
1288 /* Set custom timeouts to make test last shorter. */
1289 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
1290 conf.fast_periodic_ms = 100;
1291 conf.slow_periodic_ms = 600;
1292 conf.short_timeout_ms = 300;
1293 conf.long_timeout_ms = 900;
1294 conf.aggregate_wait_timeout_ms = 200;
1295 conf.tx_period_ms = 100;
1296 old_delay = conf.update_timeout_ms;
1297 conf.update_timeout_ms = 10;
1298 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
1300 /* Wait for new settings to be applied. */
1301 for (i = 0; i < old_delay/conf.update_timeout_ms * 2; i++) {
1302 FOR_EACH_SLAVE(j, slave)
1303 bond_handshake_reply(slave);
1305 rte_delay_ms(conf.update_timeout_ms);
1308 retval = bond_handshake();
1309 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1311 /* Find first slave */
1312 FOR_EACH_SLAVE(i, slave) {
1317 RTE_VERIFY(exp_slave != NULL);
1319 /* When one of partners do not send or respond to LACP frame in
1320 * conf.long_timeout_ms time, internal state machines should detect this
1321 * and transit to expired state. */
1322 for (j = 0; j < conf.long_timeout_ms/conf.update_timeout_ms + 2; j++) {
1323 rte_delay_ms(conf.update_timeout_ms);
1325 retval = bond_tx(NULL, 0);
1326 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1329 FOR_EACH_SLAVE(i, slave) {
1330 retval = bond_handshake_reply(slave);
1331 TEST_ASSERT(retval >= 0, "Handshake failed");
1333 /* Remove replay for slave that suppose to be expired. */
1334 if (slave == exp_slave) {
1335 while (rte_ring_count(slave->rx_queue) > 0) {
1338 rte_ring_dequeue(slave->rx_queue, &pkt);
1339 rte_pktmbuf_free(pkt);
1344 retval = bond_rx(pkts, RTE_DIM(pkts));
1346 free_pkts(pkts, retval);
1348 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1352 /* After test only expected slave should be in EXPIRED state */
1353 FOR_EACH_SLAVE(i, slave) {
1354 if (slave == exp_slave)
1355 TEST_ASSERT(slave->lacp_parnter_state & STATE_EXPIRED,
1356 "Slave %u should be in expired.", slave->port_id);
1358 TEST_ASSERT_EQUAL(bond_handshake_done(slave), 1,
1359 "Slave %u should be operational.", slave->port_id);
1362 retval = remove_slaves_and_stop_bonded_device();
1363 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1365 return TEST_SUCCESS;
1369 test_mode4_ext_ctrl(void)
1372 * configure bonded interface without the external sm enabled
1373 * . try to transmit lacpdu (should fail)
1374 * . try to set collecting and distributing flags (should fail)
1375 * reconfigure w/external sm
1376 * . transmit one lacpdu on each slave using new api
1377 * . make sure each slave receives one lacpdu using the callback api
1378 * . transmit one data pdu on each slave (should fail)
1379 * . enable distribution and collection, send one data pdu each again
1383 struct slave_conf *slave = NULL;
1386 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1387 struct rte_ether_addr src_mac, dst_mac;
1388 struct lacpdu_header lacpdu = {
1390 .subtype = SLOW_SUBTYPE_LACP,
1394 rte_ether_addr_copy(&parnter_system, &src_mac);
1395 rte_ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1397 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1398 RTE_ETHER_TYPE_SLOW, 0, 0);
1400 for (i = 0; i < SLAVE_COUNT; i++) {
1401 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1402 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1403 &lacpdu, sizeof(lacpdu));
1404 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1407 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1408 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1410 FOR_EACH_SLAVE(i, slave) {
1411 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_slowtx(
1412 test_params.bonded_port_id,
1413 slave->port_id, lacp_tx_buf[i]),
1414 "Slave should not allow manual LACP xmit");
1415 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_collect(
1416 test_params.bonded_port_id,
1418 "Slave should not allow external state controls");
1421 free_pkts(lacp_tx_buf, RTE_DIM(lacp_tx_buf));
1423 retval = remove_slaves_and_stop_bonded_device();
1424 TEST_ASSERT_SUCCESS(retval, "Bonded device cleanup failed.");
1426 return TEST_SUCCESS;
1431 test_mode4_ext_lacp(void)
1434 struct slave_conf *slave = NULL;
1435 uint8_t all_slaves_done = 0, i;
1437 const unsigned int delay = bond_get_update_timeout_ms();
1439 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1440 struct rte_mbuf *buf[SLAVE_COUNT];
1441 struct rte_ether_addr src_mac, dst_mac;
1442 struct lacpdu_header lacpdu = {
1444 .subtype = SLOW_SUBTYPE_LACP,
1448 rte_ether_addr_copy(&parnter_system, &src_mac);
1449 rte_ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1451 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1452 RTE_ETHER_TYPE_SLOW, 0, 0);
1454 for (i = 0; i < SLAVE_COUNT; i++) {
1455 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1456 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1457 &lacpdu, sizeof(lacpdu));
1458 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1461 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 1);
1462 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1464 memset(lacpdu_rx_count, 0, sizeof(lacpdu_rx_count));
1466 /* Wait for new settings to be applied. */
1467 for (i = 0; i < 30; ++i)
1468 rte_delay_ms(delay);
1470 FOR_EACH_SLAVE(i, slave) {
1471 retval = rte_eth_bond_8023ad_ext_slowtx(
1472 test_params.bonded_port_id,
1473 slave->port_id, lacp_tx_buf[i]);
1474 TEST_ASSERT_SUCCESS(retval,
1475 "Slave should allow manual LACP xmit");
1478 nb_pkts = bond_tx(NULL, 0);
1479 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
1481 FOR_EACH_SLAVE(i, slave) {
1482 nb_pkts = slave_get_pkts(slave, buf, RTE_DIM(buf));
1483 TEST_ASSERT_EQUAL(nb_pkts, 1, "found %u packets on slave %d\n",
1485 slave_put_pkts(slave, buf, nb_pkts);
1488 nb_pkts = bond_rx(buf, RTE_DIM(buf));
1489 free_pkts(buf, nb_pkts);
1490 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
1492 /* wait for the periodic callback to run */
1493 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
1494 uint8_t s, total = 0;
1496 rte_delay_ms(delay);
1497 FOR_EACH_SLAVE(s, slave) {
1498 total += lacpdu_rx_count[slave->port_id];
1501 if (total >= SLAVE_COUNT)
1502 all_slaves_done = 1;
1505 FOR_EACH_SLAVE(i, slave) {
1506 TEST_ASSERT_EQUAL(lacpdu_rx_count[slave->port_id], 1,
1507 "Slave port %u should have received 1 lacpdu (count=%u)",
1509 lacpdu_rx_count[slave->port_id]);
1512 retval = remove_slaves_and_stop_bonded_device();
1513 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1515 return TEST_SUCCESS;
1519 check_environment(void)
1521 struct slave_conf *port;
1522 uint8_t i, env_state;
1523 uint16_t slaves[RTE_DIM(test_params.slave_ports)];
1527 FOR_EACH_PORT(i, port) {
1528 if (rte_ring_count(port->rx_queue) != 0)
1531 if (rte_ring_count(port->tx_queue) != 0)
1534 if (port->bonded != 0)
1537 if (port->lacp_parnter_state != 0)
1544 slaves_count = rte_eth_bond_slaves_get(test_params.bonded_port_id,
1545 slaves, RTE_DIM(slaves));
1547 if (slaves_count != 0)
1550 TEST_ASSERT_EQUAL(env_state, 0,
1551 "Environment not clean (port %u):%s%s%s%s%s",
1553 env_state & 0x01 ? " slave rx queue not clean" : "",
1554 env_state & 0x02 ? " slave tx queue not clean" : "",
1555 env_state & 0x04 ? " port marked as enslaved" : "",
1556 env_state & 0x80 ? " slave state is not reset" : "",
1557 env_state & 0x10 ? " slave count not equal 0" : ".");
1560 return TEST_SUCCESS;
1564 test_mode4_executor(int (*test_func)(void))
1566 struct slave_conf *port;
1571 /* Check if environment is clean. Fail to launch a test if there was
1572 * a critical error before that prevented to reset environment. */
1573 TEST_ASSERT_SUCCESS(check_environment(),
1574 "Refusing to launch test in dirty environment.");
1576 RTE_VERIFY(test_func != NULL);
1577 test_result = (*test_func)();
1579 /* If test succeed check if environment wast left in good condition. */
1580 if (test_result == TEST_SUCCESS)
1581 test_result = check_environment();
1583 /* Reset environment in case test failed to do that. */
1584 if (test_result != TEST_SUCCESS) {
1585 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
1586 "Failed to stop bonded device");
1588 FOR_EACH_PORT(i, port) {
1589 while (rte_ring_count(port->rx_queue) != 0) {
1590 if (rte_ring_dequeue(port->rx_queue, &pkt) == 0)
1591 rte_pktmbuf_free(pkt);
1594 while (rte_ring_count(port->tx_queue) != 0) {
1595 if (rte_ring_dequeue(port->tx_queue, &pkt) == 0)
1596 rte_pktmbuf_free(pkt);
1605 test_mode4_agg_mode_selection_wrapper(void){
1606 return test_mode4_executor(&test_mode4_agg_mode_selection);
1610 test_mode4_lacp_wrapper(void)
1612 return test_mode4_executor(&test_mode4_lacp);
1616 test_mode4_marker_wrapper(void)
1618 return test_mode4_executor(&test_mode4_marker);
1622 test_mode4_rx_wrapper(void)
1624 return test_mode4_executor(&test_mode4_rx);
1628 test_mode4_tx_burst_wrapper(void)
1630 return test_mode4_executor(&test_mode4_tx_burst);
1634 test_mode4_expired_wrapper(void)
1636 return test_mode4_executor(&test_mode4_expired);
1640 test_mode4_ext_ctrl_wrapper(void)
1642 return test_mode4_executor(&test_mode4_ext_ctrl);
1646 test_mode4_ext_lacp_wrapper(void)
1648 return test_mode4_executor(&test_mode4_ext_lacp);
1651 static struct unit_test_suite link_bonding_mode4_test_suite = {
1652 .suite_name = "Link Bonding mode 4 Unit Test Suite",
1653 .setup = test_setup,
1654 .teardown = testsuite_teardown,
1655 .unit_test_cases = {
1656 TEST_CASE_NAMED("test_mode4_agg_mode_selection",
1657 test_mode4_agg_mode_selection_wrapper),
1658 TEST_CASE_NAMED("test_mode4_lacp", test_mode4_lacp_wrapper),
1659 TEST_CASE_NAMED("test_mode4_rx", test_mode4_rx_wrapper),
1660 TEST_CASE_NAMED("test_mode4_tx_burst", test_mode4_tx_burst_wrapper),
1661 TEST_CASE_NAMED("test_mode4_marker", test_mode4_marker_wrapper),
1662 TEST_CASE_NAMED("test_mode4_expired", test_mode4_expired_wrapper),
1663 TEST_CASE_NAMED("test_mode4_ext_ctrl",
1664 test_mode4_ext_ctrl_wrapper),
1665 TEST_CASE_NAMED("test_mode4_ext_lacp",
1666 test_mode4_ext_lacp_wrapper),
1668 TEST_CASES_END() /**< NULL terminate unit test array */
1673 test_link_bonding_mode4(void)
1675 return unit_test_suite_runner(&link_bonding_mode4_test_suite);
1678 REGISTER_TEST_COMMAND(link_bonding_mode4_autotest, test_link_bonding_mode4);