4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <rte_cycles.h>
42 #include <sys/queue.h>
44 #include <rte_byteorder.h>
45 #include <rte_common.h>
46 #include <rte_debug.h>
47 #include <rte_ethdev.h>
49 #include <rte_lcore.h>
50 #include <rte_memory.h>
52 #include <rte_string_fns.h>
54 #include <rte_eth_ring.h>
55 #include <rte_errno.h>
56 #include <rte_eth_bond.h>
57 #include <rte_eth_bond_8023ad.h>
59 #include "packet_burst_generator.h"
63 #define SLAVE_COUNT (4)
65 #define RX_RING_SIZE 128
66 #define TX_RING_SIZE 512
68 #define MBUF_CACHE_SIZE (250)
69 #define BURST_SIZE (32)
71 #define TEST_RX_DESC_MAX (2048)
72 #define TEST_TX_DESC_MAX (2048)
73 #define MAX_PKT_BURST (32)
74 #define DEF_PKT_BURST (16)
76 #define BONDED_DEV_NAME ("unit_test_mode4_bond_dev")
78 #define SLAVE_DEV_NAME_FMT ("unit_test_mode4_slave_%d")
79 #define SLAVE_RX_QUEUE_FMT ("unit_test_mode4_slave_%d_rx")
80 #define SLAVE_TX_QUEUE_FMT ("unit_test_mode4_slave_%d_tx")
82 #define INVALID_SOCKET_ID (-1)
83 #define INVALID_PORT_ID (0xFF)
84 #define INVALID_BONDING_MODE (-1)
86 static const struct ether_addr slave_mac_default = {
87 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 }
90 static const struct ether_addr parnter_mac_default = {
91 { 0x22, 0xBB, 0xFF, 0xBB, 0x00, 0x00 }
94 static const struct ether_addr parnter_system = {
95 { 0x33, 0xFF, 0xBB, 0xFF, 0x00, 0x00 }
98 static const struct ether_addr slow_protocol_mac_addr = {
99 { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02 }
103 struct rte_ring *rx_queue;
104 struct rte_ring *tx_queue;
108 uint8_t lacp_parnter_state;
111 struct ether_vlan_hdr {
112 struct ether_hdr pkt_eth_hdr;
113 struct vlan_hdr vlan_hdr;
116 struct link_bonding_unittest_params {
117 uint8_t bonded_port_id;
118 struct slave_conf slave_ports[SLAVE_COUNT];
120 struct rte_mempool *mbuf_pool;
123 #define TEST_DEFAULT_SLAVE_COUNT RTE_DIM(test_params.slave_ports)
124 #define TEST_RX_SLAVE_COUT TEST_DEFAULT_SLAVE_COUNT
125 #define TEST_TX_SLAVE_COUNT TEST_DEFAULT_SLAVE_COUNT
126 #define TEST_MARKER_SLAVE_COUT TEST_DEFAULT_SLAVE_COUNT
127 #define TEST_EXPIRED_SLAVE_COUNT TEST_DEFAULT_SLAVE_COUNT
128 #define TEST_PROMISC_SLAVE_COUNT TEST_DEFAULT_SLAVE_COUNT
130 static struct link_bonding_unittest_params test_params = {
131 .bonded_port_id = INVALID_PORT_ID,
132 .slave_ports = { [0 ... SLAVE_COUNT - 1] = { .port_id = INVALID_PORT_ID} },
137 static struct rte_eth_conf default_pmd_conf = {
139 .mq_mode = ETH_MQ_RX_NONE,
140 .max_rx_pkt_len = ETHER_MAX_LEN,
142 .header_split = 0, /**< Header Split disabled */
143 .hw_ip_checksum = 0, /**< IP checksum offload enabled */
144 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
145 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
146 .hw_strip_crc = 0, /**< CRC stripped by hardware */
149 .mq_mode = ETH_MQ_TX_NONE,
154 static uint8_t lacpdu_rx_count[RTE_MAX_ETHPORTS] = {0, };
156 #define FOR_EACH(_i, _item, _array, _size) \
157 for (_i = 0, _item = &_array[0]; _i < _size && (_item = &_array[_i]); _i++)
159 /* Macro for iterating over every port that can be used as a slave
161 * _i variable used as an index in test_params->slave_ports
162 * _slave pointer to &test_params->slave_ports[_idx]
164 #define FOR_EACH_PORT(_i, _port) \
165 FOR_EACH(_i, _port, test_params.slave_ports, \
166 RTE_DIM(test_params.slave_ports))
168 /* Macro for iterating over every port that can be used as a slave
169 * in this test and satisfy given condition.
171 * _i variable used as an index in test_params->slave_ports
172 * _slave pointer to &test_params->slave_ports[_idx]
173 * _condition condition that need to be checked
175 #define FOR_EACH_PORT_IF(_i, _port, _condition) FOR_EACH_PORT((_i), (_port)) \
178 /* Macro for iterating over every port that is currently a slave of a bonded
180 * _i variable used as an index in test_params->slave_ports
181 * _slave pointer to &test_params->slave_ports[_idx]
183 #define FOR_EACH_SLAVE(_i, _slave) \
184 FOR_EACH_PORT_IF(_i, _slave, (_slave)->bonded != 0)
187 * Returns packets from slaves TX queue.
190 * size size of buffer
191 * return number of packets or negative error number
194 slave_get_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
196 return rte_ring_dequeue_burst(slave->tx_queue, (void **)buf, size);
200 * Injects given packets into slaves RX queue.
203 * size number of packets to be injected
204 * return number of queued packets or negative error number
207 slave_put_pkts(struct slave_conf *slave, struct rte_mbuf **buf, uint16_t size)
209 return rte_ring_enqueue_burst(slave->rx_queue, (void **)buf, size);
213 bond_rx(struct rte_mbuf **buf, uint16_t size)
215 return rte_eth_rx_burst(test_params.bonded_port_id, 0, buf, size);
219 bond_tx(struct rte_mbuf **buf, uint16_t size)
221 return rte_eth_tx_burst(test_params.bonded_port_id, 0, buf, size);
225 free_pkts(struct rte_mbuf **pkts, uint16_t count)
229 for (i = 0; i < count; i++) {
231 rte_pktmbuf_free(pkts[i]);
236 configure_ethdev(uint8_t port_id, uint8_t start)
238 TEST_ASSERT(rte_eth_dev_configure(port_id, 1, 1, &default_pmd_conf) == 0,
239 "Failed to configure device %u", port_id);
241 TEST_ASSERT(rte_eth_rx_queue_setup(port_id, 0, RX_RING_SIZE,
242 rte_eth_dev_socket_id(port_id), NULL, test_params.mbuf_pool) == 0,
243 "Failed to setup rx queue.");
245 TEST_ASSERT(rte_eth_tx_queue_setup(port_id, 0, TX_RING_SIZE,
246 rte_eth_dev_socket_id(port_id), NULL) == 0,
247 "Failed to setup tx queue.");
250 TEST_ASSERT(rte_eth_dev_start(port_id) == 0,
251 "Failed to start device (%d).", port_id);
257 add_slave(struct slave_conf *slave, uint8_t start)
259 struct ether_addr addr, addr_check;
261 /* Some sanity check */
262 RTE_VERIFY(test_params.slave_ports <= slave &&
263 slave - test_params.slave_ports < (int)RTE_DIM(test_params.slave_ports));
264 RTE_VERIFY(slave->bonded == 0);
265 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
267 ether_addr_copy(&slave_mac_default, &addr);
268 addr.addr_bytes[ETHER_ADDR_LEN - 1] = slave->port_id;
270 rte_eth_dev_mac_addr_remove(slave->port_id, &addr);
272 TEST_ASSERT_SUCCESS(rte_eth_dev_mac_addr_add(slave->port_id, &addr, 0),
273 "Failed to set slave MAC address");
275 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params.bonded_port_id,
277 "Failed to add slave (idx=%u, id=%u) to bonding (id=%u)",
278 (uint8_t)(slave - test_params.slave_ports), slave->port_id,
279 test_params.bonded_port_id);
283 TEST_ASSERT_SUCCESS(rte_eth_dev_start(slave->port_id),
284 "Failed to start slave %u", slave->port_id);
287 rte_eth_macaddr_get(slave->port_id, &addr_check);
288 TEST_ASSERT_EQUAL(is_same_ether_addr(&addr, &addr_check), 1,
289 "Slave MAC address is not as expected");
291 RTE_VERIFY(slave->lacp_parnter_state == 0);
296 remove_slave(struct slave_conf *slave)
298 ptrdiff_t slave_idx = slave - test_params.slave_ports;
300 RTE_VERIFY(test_params.slave_ports <= slave &&
301 slave_idx < (ptrdiff_t)RTE_DIM(test_params.slave_ports));
303 RTE_VERIFY(slave->bonded == 1);
304 RTE_VERIFY(slave->port_id != INVALID_PORT_ID);
306 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
307 "Slave %u tx queue not empty while removing from bonding.",
310 TEST_ASSERT_EQUAL(rte_ring_count(slave->rx_queue), 0,
311 "Slave %u tx queue not empty while removing from bonding.",
314 TEST_ASSERT_EQUAL(rte_eth_bond_slave_remove(test_params.bonded_port_id,
316 "Failed to remove slave (idx=%u, id=%u) from bonding (id=%u)",
317 (uint8_t)slave_idx, slave->port_id,
318 test_params.bonded_port_id);
321 slave->lacp_parnter_state = 0;
326 lacp_recv_cb(uint8_t slave_id, struct rte_mbuf *lacp_pkt)
328 struct ether_hdr *hdr;
329 struct slow_protocol_frame *slow_hdr;
331 RTE_VERIFY(lacp_pkt != NULL);
333 hdr = rte_pktmbuf_mtod(lacp_pkt, struct ether_hdr *);
334 RTE_VERIFY(hdr->ether_type == rte_cpu_to_be_16(ETHER_TYPE_SLOW));
336 slow_hdr = rte_pktmbuf_mtod(lacp_pkt, struct slow_protocol_frame *);
337 RTE_VERIFY(slow_hdr->slow_protocol.subtype == SLOW_SUBTYPE_LACP);
339 lacpdu_rx_count[slave_id]++;
340 rte_pktmbuf_free(lacp_pkt);
344 initialize_bonded_device_with_slaves(uint8_t slave_count, uint8_t external_sm)
348 RTE_VERIFY(test_params.bonded_port_id != INVALID_PORT_ID);
350 for (i = 0; i < slave_count; i++) {
351 TEST_ASSERT_SUCCESS(add_slave(&test_params.slave_ports[i], 1),
352 "Failed to add port %u to bonded device.\n",
353 test_params.slave_ports[i].port_id);
356 /* Reset mode 4 configuration */
357 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, NULL);
358 rte_eth_promiscuous_disable(test_params.bonded_port_id);
361 struct rte_eth_bond_8023ad_conf conf;
363 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
364 conf.slowrx_cb = lacp_recv_cb;
365 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
369 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params.bonded_port_id),
370 "Failed to start bonded device");
376 remove_slaves_and_stop_bonded_device(void)
378 struct slave_conf *slave;
380 uint8_t slaves[RTE_MAX_ETHPORTS];
383 rte_eth_dev_stop(test_params.bonded_port_id);
385 FOR_EACH_SLAVE(i, slave)
388 retval = rte_eth_bond_slaves_get(test_params.bonded_port_id, slaves,
391 TEST_ASSERT_EQUAL(retval, 0,
392 "Expected bonded device %u have 0 slaves but returned %d.",
393 test_params.bonded_port_id, retval);
395 FOR_EACH_PORT(i, slave) {
396 rte_eth_dev_stop(slave->port_id);
398 TEST_ASSERT(slave->bonded == 0,
399 "Port id=%u is still marked as enslaved.", slave->port_id);
408 int retval, nb_mbuf_per_pool;
409 char name[RTE_ETH_NAME_MAX_LEN];
410 struct slave_conf *port;
411 const uint8_t socket_id = rte_socket_id();
414 if (test_params.mbuf_pool == NULL) {
415 nb_mbuf_per_pool = TEST_RX_DESC_MAX + DEF_PKT_BURST +
416 TEST_TX_DESC_MAX + MAX_PKT_BURST;
417 test_params.mbuf_pool = rte_pktmbuf_pool_create("TEST_MODE4",
418 nb_mbuf_per_pool, MBUF_CACHE_SIZE, 0,
419 RTE_MBUF_DEFAULT_BUF_SIZE, socket_id);
421 TEST_ASSERT(test_params.mbuf_pool != NULL,
422 "rte_mempool_create failed\n");
425 /* Create / initialize ring eth devs. */
426 FOR_EACH_PORT(i, port) {
427 port = &test_params.slave_ports[i];
429 if (port->rx_queue == NULL) {
430 retval = snprintf(name, RTE_DIM(name), SLAVE_RX_QUEUE_FMT, i);
431 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
432 port->rx_queue = rte_ring_create(name, RX_RING_SIZE, socket_id, 0);
433 TEST_ASSERT(port->rx_queue != NULL,
434 "Failed to allocate rx ring '%s': %s", name,
435 rte_strerror(rte_errno));
438 if (port->tx_queue == NULL) {
439 retval = snprintf(name, RTE_DIM(name), SLAVE_TX_QUEUE_FMT, i);
440 TEST_ASSERT(retval <= (int)RTE_DIM(name) - 1, "Name too long");
441 port->tx_queue = rte_ring_create(name, TX_RING_SIZE, socket_id, 0);
442 TEST_ASSERT_NOT_NULL(port->tx_queue,
443 "Failed to allocate tx ring '%s': %s", name,
444 rte_strerror(rte_errno));
447 if (port->port_id == INVALID_PORT_ID) {
448 retval = snprintf(name, RTE_DIM(name), SLAVE_DEV_NAME_FMT, i);
449 TEST_ASSERT(retval < (int)RTE_DIM(name) - 1, "Name too long");
450 retval = rte_eth_from_rings(name, &port->rx_queue, 1,
451 &port->tx_queue, 1, socket_id);
452 TEST_ASSERT(retval >= 0,
453 "Failed to create ring ethdev '%s'\n", name);
455 port->port_id = rte_eth_dev_count() - 1;
458 retval = configure_ethdev(port->port_id, 1);
459 TEST_ASSERT_SUCCESS(retval, "Failed to configure virtual ethdev %s\n",
463 if (test_params.bonded_port_id == INVALID_PORT_ID) {
464 retval = rte_eth_bond_create(BONDED_DEV_NAME, BONDING_MODE_8023AD,
467 TEST_ASSERT(retval >= 0, "Failed to create bonded ethdev %s",
470 test_params.bonded_port_id = retval;
471 TEST_ASSERT_SUCCESS(configure_ethdev(test_params.bonded_port_id, 0),
472 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME);
473 } else if (rte_eth_bond_mode_get(test_params.bonded_port_id) !=
474 BONDING_MODE_8023AD) {
475 TEST_ASSERT(rte_eth_bond_mode_set(test_params.bonded_port_id,
476 BONDING_MODE_8023AD) == 0,
477 "Failed to set ethdev %d to mode %d",
478 test_params.bonded_port_id, BONDING_MODE_8023AD);
485 testsuite_teardown(void)
487 struct slave_conf *port;
491 * Any cleanup/reset state is done when particular test is
494 rte_eth_dev_stop(test_params.bonded_port_id);
496 FOR_EACH_PORT(i, port)
497 rte_eth_dev_stop(port->port_id);
501 * Check if given LACP packet. If it is, make make replay packet to force
503 * return 0 when pkt is LACP frame, 1 if it is not slow frame, 2 if it is slow
507 make_lacp_reply(struct slave_conf *slave, struct rte_mbuf *pkt)
509 struct ether_hdr *hdr;
510 struct slow_protocol_frame *slow_hdr;
514 hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
515 if (hdr->ether_type != rte_cpu_to_be_16(ETHER_TYPE_SLOW))
518 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
519 /* ignore packets of other types */
520 if (slow_hdr->slow_protocol.subtype != SLOW_SUBTYPE_LACP)
523 slow_hdr = rte_pktmbuf_mtod(pkt, struct slow_protocol_frame *);
525 /* Change source address to partner address */
526 ether_addr_copy(&parnter_mac_default, &slow_hdr->eth_hdr.s_addr);
527 slow_hdr->eth_hdr.s_addr.addr_bytes[ETHER_ADDR_LEN - 1] = slave->port_id;
529 lacp = (struct lacpdu *) &slow_hdr->slow_protocol;
530 /* Save last received state */
531 slave->lacp_parnter_state = lacp->actor.state;
532 /* Change it into LACP replay by matching parameters. */
533 memcpy(&lacp->partner.port_params, &lacp->actor.port_params,
534 sizeof(struct port_params));
536 lacp->partner.state = lacp->actor.state;
538 ether_addr_copy(&parnter_system, &lacp->actor.port_params.system);
539 lacp->actor.state = STATE_LACP_ACTIVE |
540 STATE_SYNCHRONIZATION |
549 * Reads packets from given slave, search for LACP packet and reply them.
551 * Receives burst of packets from slave. Looks for LACP packet. Drops
552 * all other packets. Prepares response LACP and sends it back.
554 * return number of LACP received and replied, -1 on error.
557 bond_handshake_reply(struct slave_conf *slave)
560 struct rte_mbuf *rx_buf[MAX_PKT_BURST];
561 struct rte_mbuf *lacp_tx_buf[MAX_PKT_BURST];
562 uint16_t lacp_tx_buf_cnt = 0, i;
564 retval = slave_get_pkts(slave, rx_buf, RTE_DIM(rx_buf));
565 TEST_ASSERT(retval >= 0, "Getting slave %u packets failed.",
568 for (i = 0; i < (uint16_t)retval; i++) {
569 if (make_lacp_reply(slave, rx_buf[i]) == 0) {
570 /* reply with actor's LACP */
571 lacp_tx_buf[lacp_tx_buf_cnt++] = rx_buf[i];
573 rte_pktmbuf_free(rx_buf[i]);
576 if (lacp_tx_buf_cnt == 0)
579 retval = slave_put_pkts(slave, lacp_tx_buf, lacp_tx_buf_cnt);
580 if (retval <= lacp_tx_buf_cnt) {
581 /* retval might be negative */
582 for (i = RTE_MAX(0, retval); retval < lacp_tx_buf_cnt; retval++)
583 rte_pktmbuf_free(lacp_tx_buf[i]);
586 TEST_ASSERT_EQUAL(retval, lacp_tx_buf_cnt,
587 "Failed to equeue lacp packets into slave %u tx queue.",
590 return lacp_tx_buf_cnt;
594 * Function check if given slave tx queue contains packets that make mode 4
595 * handshake complete. It will drain slave queue.
596 * return 0 if handshake not completed, 1 if handshake was complete,
599 bond_handshake_done(struct slave_conf *slave)
601 const uint8_t expected_state = STATE_LACP_ACTIVE | STATE_SYNCHRONIZATION |
602 STATE_AGGREGATION | STATE_COLLECTING | STATE_DISTRIBUTING;
604 return slave->lacp_parnter_state == expected_state;
608 bond_get_update_timeout_ms(void)
610 struct rte_eth_bond_8023ad_conf conf;
612 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
613 return conf.update_timeout_ms;
617 * Exchanges LACP packets with partner to achieve dynamic port configuration.
618 * return TEST_SUCCESS if initial handshake succeed, TEST_FAILED otherwise.
623 struct slave_conf *slave;
624 struct rte_mbuf *buf[MAX_PKT_BURST];
626 uint8_t all_slaves_done, i, j;
627 uint8_t status[RTE_DIM(test_params.slave_ports)] = { 0 };
628 const unsigned delay = bond_get_update_timeout_ms();
630 /* Exchange LACP frames */
632 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
636 FOR_EACH_SLAVE(j, slave) {
637 /* If response already send, skip slave */
641 if (bond_handshake_reply(slave) < 0) {
646 status[j] = bond_handshake_done(slave);
651 nb_pkts = bond_tx(NULL, 0);
652 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
654 nb_pkts = bond_rx(buf, RTE_DIM(buf));
655 free_pkts(buf, nb_pkts);
656 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
658 /* If response didn't send - report failure */
659 TEST_ASSERT_EQUAL(all_slaves_done, 1, "Bond handshake failed\n");
661 /* If flags doesn't match - report failure */
662 return all_slaves_done = 1 ? TEST_SUCCESS : TEST_FAILED;
665 #define TEST_LACP_SLAVE_COUT RTE_DIM(test_params.slave_ports)
667 test_mode4_lacp(void)
671 retval = initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT, 0);
672 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
674 /* Test LACP handshake function */
675 retval = bond_handshake();
676 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
678 retval = remove_slaves_and_stop_bonded_device();
679 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
685 generate_packets(struct ether_addr *src_mac,
686 struct ether_addr *dst_mac, uint16_t count, struct rte_mbuf **buf)
688 uint16_t pktlen = PACKET_BURST_GEN_PKT_LEN;
689 uint8_t vlan_enable = 0;
690 uint16_t vlan_id = 0;
691 uint8_t ip4_type = 1; /* 0 - ipv6 */
693 uint16_t src_port = 10, dst_port = 20;
695 uint32_t ip_src[4] = { [0 ... 2] = 0xDEADBEEF, [3] = IPv4(192, 168, 0, 1) };
696 uint32_t ip_dst[4] = { [0 ... 2] = 0xFEEDFACE, [3] = IPv4(192, 168, 0, 2) };
698 struct ether_hdr pkt_eth_hdr;
699 struct udp_hdr pkt_udp_hdr;
707 initialize_eth_header(&pkt_eth_hdr, src_mac, dst_mac, ip4_type,
708 vlan_enable, vlan_id);
711 initialize_ipv4_header(&pkt_ip_hdr.v4, ip_src[3], ip_dst[3], pktlen);
713 initialize_ipv6_header(&pkt_ip_hdr.v6, (uint8_t *)ip_src,
714 (uint8_t *)&ip_dst, pktlen);
716 initialize_udp_header(&pkt_udp_hdr, src_port, dst_port, 16);
718 retval = generate_packet_burst(test_params.mbuf_pool, buf,
719 &pkt_eth_hdr, vlan_enable, &pkt_ip_hdr, 1, &pkt_udp_hdr,
722 if (retval > 0 && retval != count)
723 free_pkts(&buf[count - retval], retval);
725 TEST_ASSERT_EQUAL(retval, count, "Failed to generate %u packets",
732 generate_and_put_packets(struct slave_conf *slave, struct ether_addr *src_mac,
733 struct ether_addr *dst_mac, uint16_t count)
735 struct rte_mbuf *pkts[MAX_PKT_BURST];
738 retval = generate_packets(src_mac, dst_mac, count, pkts);
739 if (retval != (int)count)
742 retval = slave_put_pkts(slave, pkts, count);
743 if (retval > 0 && retval != count)
744 free_pkts(&pkts[retval], count - retval);
746 TEST_ASSERT_EQUAL(retval, count,
747 "Failed to enqueue packets into slave %u RX queue", slave->port_id);
755 struct slave_conf *slave;
758 uint16_t expected_pkts_cnt;
759 struct rte_mbuf *pkts[MAX_PKT_BURST];
763 struct ether_hdr *hdr;
765 struct ether_addr src_mac = { { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
766 struct ether_addr dst_mac;
767 struct ether_addr bonded_mac;
769 retval = initialize_bonded_device_with_slaves(TEST_PROMISC_SLAVE_COUNT,
771 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
773 retval = bond_handshake();
774 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
776 rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
777 ether_addr_copy(&bonded_mac, &dst_mac);
779 /* Assert that dst address is not bonding address. Do not set the
780 * least significant bit of the zero byte as this would create a
783 dst_mac.addr_bytes[0] += 2;
785 /* First try with promiscuous mode enabled.
786 * Add 2 packets to each slave. First with bonding MAC address, second with
787 * different. Check if we received all of them. */
788 rte_eth_promiscuous_enable(test_params.bonded_port_id);
790 expected_pkts_cnt = 0;
791 FOR_EACH_SLAVE(i, slave) {
792 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
793 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
796 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
797 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
800 /* Expect 2 packets per slave */
801 expected_pkts_cnt += 2;
804 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
807 if (retval == expected_pkts_cnt) {
808 int cnt[2] = { 0, 0 };
810 for (i = 0; i < expected_pkts_cnt; i++) {
811 hdr = rte_pktmbuf_mtod(pkts[i], struct ether_hdr *);
812 cnt[is_same_ether_addr(&hdr->d_addr, &bonded_mac)]++;
815 free_pkts(pkts, expected_pkts_cnt);
817 /* For division by 2 expected_pkts_cnt must be even */
818 RTE_VERIFY((expected_pkts_cnt & 1) == 0);
819 TEST_ASSERT(cnt[0] == expected_pkts_cnt / 2 &&
820 cnt[1] == expected_pkts_cnt / 2,
821 "Expected %u packets with the same MAC and %u with different but "
822 "got %u with the same and %u with diffrent MAC",
823 expected_pkts_cnt / 2, expected_pkts_cnt / 2, cnt[1], cnt[0]);
824 } else if (retval > 0)
825 free_pkts(pkts, retval);
827 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
828 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
830 /* Now, disable promiscuous mode. When promiscuous mode is disabled we
831 * expect to receive only packets that are directed to bonding port. */
832 rte_eth_promiscuous_disable(test_params.bonded_port_id);
834 expected_pkts_cnt = 0;
835 FOR_EACH_SLAVE(i, slave) {
836 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
837 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
840 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
841 TEST_ASSERT_SUCCESS(retval, "Failed to enqueue packets to slave %u",
844 /* Expect only one packet per slave */
845 expected_pkts_cnt += 1;
848 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
851 if (retval == expected_pkts_cnt) {
854 for (i = 0; i < expected_pkts_cnt; i++) {
855 hdr = rte_pktmbuf_mtod(pkts[i], struct ether_hdr *);
856 eq_cnt += is_same_ether_addr(&hdr->d_addr, &bonded_mac);
859 free_pkts(pkts, expected_pkts_cnt);
860 TEST_ASSERT_EQUAL(eq_cnt, expected_pkts_cnt, "Packet address mismatch");
861 } else if (retval > 0)
862 free_pkts(pkts, retval);
864 TEST_ASSERT_EQUAL(retval, expected_pkts_cnt,
865 "Expected %u packets but received only %d", expected_pkts_cnt, retval);
867 /* Link down test: simulate link down for first slave. */
868 delay = bond_get_update_timeout_ms();
870 uint8_t slave_down_id = INVALID_PORT_ID;
872 /* Find first slave and make link down on it*/
873 FOR_EACH_SLAVE(i, slave) {
874 rte_eth_dev_set_link_down(slave->port_id);
875 slave_down_id = slave->port_id;
879 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
881 /* Give some time to rearrange bonding */
882 for (i = 0; i < 3; i++) {
887 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
889 /* Put packet to each slave */
890 FOR_EACH_SLAVE(i, slave) {
893 dst_mac.addr_bytes[ETHER_ADDR_LEN - 1] = slave->port_id;
894 retval = generate_and_put_packets(slave, &src_mac, &dst_mac, 1);
895 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
897 src_mac.addr_bytes[ETHER_ADDR_LEN - 1] = slave->port_id;
898 retval = generate_and_put_packets(slave, &src_mac, &bonded_mac, 1);
899 TEST_ASSERT_SUCCESS(retval, "Failed to generate test packet burst.");
901 retval = bond_rx(pkts, RTE_DIM(pkts));
905 free_pkts(pkts, retval);
907 while (rte_ring_dequeue(slave->rx_queue, (void **)&pkt) == 0)
908 rte_pktmbuf_free(pkt);
910 if (slave_down_id == slave->port_id)
911 TEST_ASSERT_EQUAL(retval, 0, "Packets received unexpectedly.");
913 TEST_ASSERT_NOT_EQUAL(retval, 0,
914 "Expected to receive some packets on slave %u.",
916 rte_eth_dev_start(slave->port_id);
918 for (j = 0; j < 5; j++) {
919 TEST_ASSERT(bond_handshake_reply(slave) >= 0,
920 "Handshake after link up");
922 if (bond_handshake_done(slave) == 1)
926 TEST_ASSERT(j < 5, "Failed to agregate slave after link up");
929 remove_slaves_and_stop_bonded_device();
934 test_mode4_tx_burst(void)
936 struct slave_conf *slave;
939 uint16_t exp_pkts_cnt, pkts_cnt = 0;
940 struct rte_mbuf *pkts[MAX_PKT_BURST];
944 struct ether_addr dst_mac = { { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
945 struct ether_addr bonded_mac;
947 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
948 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
950 retval = bond_handshake();
951 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
953 rte_eth_macaddr_get(test_params.bonded_port_id, &bonded_mac);
956 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
957 dst_mac.addr_bytes[ETHER_ADDR_LEN - 1] = pkts_cnt;
958 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
961 free_pkts(pkts, pkts_cnt);
963 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate packet %u", pkts_cnt);
965 exp_pkts_cnt = pkts_cnt;
967 /* Transmit packets on bonded device */
968 retval = bond_tx(pkts, pkts_cnt);
969 if (retval > 0 && retval < pkts_cnt)
970 free_pkts(&pkts[retval], pkts_cnt - retval);
972 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
974 /* Check if packets were transmitted properly. Every slave should have
975 * at least one packet, and sum must match. Under normal operation
976 * there should be no LACP nor MARKER frames. */
978 FOR_EACH_SLAVE(i, slave) {
979 uint16_t normal_cnt, slow_cnt;
981 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
985 for (j = 0; j < retval; j++) {
986 if (make_lacp_reply(slave, pkts[j]) == 1)
992 free_pkts(pkts, normal_cnt + slow_cnt);
993 TEST_ASSERT_EQUAL(slow_cnt, 0,
994 "slave %u unexpectedly transmitted %d SLOW packets", slave->port_id,
997 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
998 "slave %u did not transmitted any packets", slave->port_id);
1000 pkts_cnt += normal_cnt;
1003 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1004 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1007 * simulate link down for first slave. */
1008 delay = bond_get_update_timeout_ms();
1010 uint8_t slave_down_id = INVALID_PORT_ID;
1012 FOR_EACH_SLAVE(i, slave) {
1013 rte_eth_dev_set_link_down(slave->port_id);
1014 slave_down_id = slave->port_id;
1018 RTE_VERIFY(slave_down_id != INVALID_PORT_ID);
1020 /* Give some time to rearrange bonding. */
1021 for (i = 0; i < 3; i++) {
1023 rte_delay_ms(delay);
1026 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
1028 /* Prepare burst. */
1029 for (pkts_cnt = 0; pkts_cnt < RTE_DIM(pkts); pkts_cnt++) {
1030 dst_mac.addr_bytes[ETHER_ADDR_LEN - 1] = pkts_cnt;
1031 retval = generate_packets(&bonded_mac, &dst_mac, 1, &pkts[pkts_cnt]);
1034 free_pkts(pkts, pkts_cnt);
1036 TEST_ASSERT_EQUAL(retval, 1, "Failed to generate test packet %u",
1039 exp_pkts_cnt = pkts_cnt;
1041 /* Transmit packets on bonded device. */
1042 retval = bond_tx(pkts, pkts_cnt);
1043 if (retval > 0 && retval < pkts_cnt)
1044 free_pkts(&pkts[retval], pkts_cnt - retval);
1046 TEST_ASSERT_EQUAL(retval, pkts_cnt, "TX on bonded device failed");
1048 /* Check if packets was transmitted properly. Every slave should have
1049 * at least one packet, and sum must match. Under normal operation
1050 * there should be no LACP nor MARKER frames. */
1052 FOR_EACH_SLAVE(i, slave) {
1053 uint16_t normal_cnt, slow_cnt;
1055 retval = slave_get_pkts(slave, pkts, RTE_DIM(pkts));
1059 for (j = 0; j < retval; j++) {
1060 if (make_lacp_reply(slave, pkts[j]) == 1)
1066 free_pkts(pkts, normal_cnt + slow_cnt);
1068 if (slave_down_id == slave->port_id) {
1069 TEST_ASSERT_EQUAL(normal_cnt + slow_cnt, 0,
1070 "slave %u enexpectedly transmitted %u packets",
1071 normal_cnt + slow_cnt, slave->port_id);
1073 TEST_ASSERT_EQUAL(slow_cnt, 0,
1074 "slave %u unexpectedly transmitted %d SLOW packets",
1075 slave->port_id, slow_cnt);
1077 TEST_ASSERT_NOT_EQUAL(normal_cnt, 0,
1078 "slave %u did not transmitted any packets", slave->port_id);
1081 pkts_cnt += normal_cnt;
1084 TEST_ASSERT_EQUAL(exp_pkts_cnt, pkts_cnt,
1085 "Expected %u packets but transmitted only %d", exp_pkts_cnt, pkts_cnt);
1087 return remove_slaves_and_stop_bonded_device();
1091 init_marker(struct rte_mbuf *pkt, struct slave_conf *slave)
1093 struct marker_header *marker_hdr = rte_pktmbuf_mtod(pkt,
1094 struct marker_header *);
1096 /* Copy multicast destination address */
1097 ether_addr_copy(&slow_protocol_mac_addr, &marker_hdr->eth_hdr.d_addr);
1099 /* Init source address */
1100 ether_addr_copy(&parnter_mac_default, &marker_hdr->eth_hdr.s_addr);
1101 marker_hdr->eth_hdr.s_addr.addr_bytes[ETHER_ADDR_LEN-1] = slave->port_id;
1103 marker_hdr->eth_hdr.ether_type = rte_cpu_to_be_16(ETHER_TYPE_SLOW);
1105 marker_hdr->marker.subtype = SLOW_SUBTYPE_MARKER;
1106 marker_hdr->marker.version_number = 1;
1107 marker_hdr->marker.tlv_type_marker = MARKER_TLV_TYPE_INFO;
1108 marker_hdr->marker.info_length =
1109 offsetof(struct marker, reserved_90) -
1110 offsetof(struct marker, requester_port);
1111 RTE_VERIFY(marker_hdr->marker.info_length == 16);
1112 marker_hdr->marker.requester_port = slave->port_id + 1;
1113 marker_hdr->marker.tlv_type_terminator = TLV_TYPE_TERMINATOR_INFORMATION;
1114 marker_hdr->marker.terminator_length = 0;
1118 test_mode4_marker(void)
1120 struct slave_conf *slave;
1121 struct rte_mbuf *pkts[MAX_PKT_BURST];
1122 struct rte_mbuf *marker_pkt;
1123 struct marker_header *marker_hdr;
1129 const uint16_t ethtype_slow_be = rte_be_to_cpu_16(ETHER_TYPE_SLOW);
1131 retval = initialize_bonded_device_with_slaves(TEST_MARKER_SLAVE_COUT,
1133 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1135 /* Test LACP handshake function */
1136 retval = bond_handshake();
1137 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1139 delay = bond_get_update_timeout_ms();
1140 FOR_EACH_SLAVE(i, slave) {
1141 marker_pkt = rte_pktmbuf_alloc(test_params.mbuf_pool);
1142 TEST_ASSERT_NOT_NULL(marker_pkt, "Failed to allocate marker packet");
1143 init_marker(marker_pkt, slave);
1145 retval = slave_put_pkts(slave, &marker_pkt, 1);
1147 rte_pktmbuf_free(marker_pkt);
1149 TEST_ASSERT_EQUAL(retval, 1,
1150 "Failed to send marker packet to slave %u", slave->port_id);
1152 for (j = 0; j < 20; ++j) {
1153 rte_delay_ms(delay);
1154 retval = rte_eth_rx_burst(test_params.bonded_port_id, 0, pkts,
1158 free_pkts(pkts, retval);
1160 TEST_ASSERT_EQUAL(retval, 0, "Received packets unexpectedly");
1162 retval = rte_eth_tx_burst(test_params.bonded_port_id, 0, NULL, 0);
1163 TEST_ASSERT_EQUAL(retval, 0,
1164 "Requested TX of 0 packets but %d transmitted", retval);
1166 /* Check if LACP packet was send by state machines
1167 First and only packet must be a maker response */
1168 retval = slave_get_pkts(slave, pkts, MAX_PKT_BURST);
1172 free_pkts(pkts, retval);
1174 TEST_ASSERT_EQUAL(retval, 1, "failed to get slave packets");
1177 marker_hdr = rte_pktmbuf_mtod(pkts[0], struct marker_header *);
1178 /* Check if it's slow packet*/
1179 if (marker_hdr->eth_hdr.ether_type != ethtype_slow_be)
1181 /* Check if it's marker packet */
1182 else if (marker_hdr->marker.subtype != SLOW_SUBTYPE_MARKER)
1184 else if (marker_hdr->marker.tlv_type_marker != MARKER_TLV_TYPE_RESP)
1187 free_pkts(pkts, nb_pkts);
1189 TEST_ASSERT_NOT_EQUAL(retval, -1, "Unexpected protocol type");
1190 TEST_ASSERT_NOT_EQUAL(retval, -2, "Unexpected sub protocol type");
1191 TEST_ASSERT_NOT_EQUAL(retval, -3, "Unexpected marker type");
1195 TEST_ASSERT(j < 20, "Marker response not found");
1198 retval = remove_slaves_and_stop_bonded_device();
1199 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1201 return TEST_SUCCESS;
1205 test_mode4_expired(void)
1207 struct slave_conf *slave, *exp_slave = NULL;
1208 struct rte_mbuf *pkts[MAX_PKT_BURST];
1215 struct rte_eth_bond_8023ad_conf conf;
1217 retval = initialize_bonded_device_with_slaves(TEST_EXPIRED_SLAVE_COUNT,
1219 /* Set custom timeouts to make test last shorter. */
1220 rte_eth_bond_8023ad_conf_get(test_params.bonded_port_id, &conf);
1221 conf.fast_periodic_ms = 100;
1222 conf.slow_periodic_ms = 600;
1223 conf.short_timeout_ms = 300;
1224 conf.long_timeout_ms = 900;
1225 conf.aggregate_wait_timeout_ms = 200;
1226 conf.tx_period_ms = 100;
1227 old_delay = conf.update_timeout_ms;
1228 conf.update_timeout_ms = 10;
1229 rte_eth_bond_8023ad_setup(test_params.bonded_port_id, &conf);
1231 /* Wait for new settings to be applied. */
1232 for (i = 0; i < old_delay/conf.update_timeout_ms * 2; i++) {
1233 FOR_EACH_SLAVE(j, slave)
1234 bond_handshake_reply(slave);
1236 rte_delay_ms(conf.update_timeout_ms);
1239 retval = bond_handshake();
1240 TEST_ASSERT_SUCCESS(retval, "Initial handshake failed");
1242 /* Find first slave */
1243 FOR_EACH_SLAVE(i, slave) {
1248 RTE_VERIFY(exp_slave != NULL);
1250 /* When one of partners do not send or respond to LACP frame in
1251 * conf.long_timeout_ms time, internal state machines should detect this
1252 * and transit to expired state. */
1253 for (j = 0; j < conf.long_timeout_ms/conf.update_timeout_ms + 2; j++) {
1254 rte_delay_ms(conf.update_timeout_ms);
1256 retval = bond_tx(NULL, 0);
1257 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1260 FOR_EACH_SLAVE(i, slave) {
1261 retval = bond_handshake_reply(slave);
1262 TEST_ASSERT(retval >= 0, "Handshake failed");
1264 /* Remove replay for slave that supose to be expired. */
1265 if (slave == exp_slave) {
1266 while (rte_ring_count(slave->rx_queue) > 0) {
1269 rte_ring_dequeue(slave->rx_queue, &pkt);
1270 rte_pktmbuf_free(pkt);
1275 retval = bond_rx(pkts, RTE_DIM(pkts));
1277 free_pkts(pkts, retval);
1279 TEST_ASSERT_EQUAL(retval, 0, "Unexpectedly received %d packets",
1283 /* After test only expected slave should be in EXPIRED state */
1284 FOR_EACH_SLAVE(i, slave) {
1285 if (slave == exp_slave)
1286 TEST_ASSERT(slave->lacp_parnter_state & STATE_EXPIRED,
1287 "Slave %u should be in expired.", slave->port_id);
1289 TEST_ASSERT_EQUAL(bond_handshake_done(slave), 1,
1290 "Slave %u should be operational.", slave->port_id);
1293 retval = remove_slaves_and_stop_bonded_device();
1294 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1296 return TEST_SUCCESS;
1300 test_mode4_ext_ctrl(void)
1303 * configure bonded interface without the external sm enabled
1304 * . try to transmit lacpdu (should fail)
1305 * . try to set collecting and distributing flags (should fail)
1306 * reconfigure w/external sm
1307 * . transmit one lacpdu on each slave using new api
1308 * . make sure each slave receives one lacpdu using the callback api
1309 * . transmit one data pdu on each slave (should fail)
1310 * . enable distribution and collection, send one data pdu each again
1314 struct slave_conf *slave = NULL;
1317 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1318 struct ether_addr src_mac, dst_mac;
1319 struct lacpdu_header lacpdu = {
1321 .subtype = SLOW_SUBTYPE_LACP,
1325 ether_addr_copy(&parnter_system, &src_mac);
1326 ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1328 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1329 ETHER_TYPE_SLOW, 0, 0);
1331 for (i = 0; i < SLAVE_COUNT; i++) {
1332 lacp_tx_buf[i] = rte_pktmbuf_alloc(test_params.mbuf_pool);
1333 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf[i], char *),
1334 &lacpdu, sizeof(lacpdu));
1335 rte_pktmbuf_pkt_len(lacp_tx_buf[i]) = sizeof(lacpdu);
1338 retval = initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT, 0);
1339 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1341 FOR_EACH_SLAVE(i, slave) {
1342 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_slowtx(
1343 test_params.bonded_port_id,
1344 slave->port_id, lacp_tx_buf[i]),
1345 "Slave should not allow manual LACP xmit");
1346 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_collect(
1347 test_params.bonded_port_id,
1349 "Slave should not allow external state controls");
1352 free_pkts(lacp_tx_buf, RTE_DIM(lacp_tx_buf));
1354 retval = remove_slaves_and_stop_bonded_device();
1355 TEST_ASSERT_SUCCESS(retval, "Bonded device cleanup failed.");
1357 return TEST_SUCCESS;
1362 test_mode4_ext_lacp(void)
1365 struct slave_conf *slave = NULL;
1366 uint8_t all_slaves_done = 0, i;
1368 const unsigned int delay = bond_get_update_timeout_ms();
1370 struct rte_mbuf *lacp_tx_buf[SLAVE_COUNT];
1371 struct rte_mbuf *buf[SLAVE_COUNT];
1372 struct ether_addr src_mac, dst_mac;
1373 struct lacpdu_header lacpdu = {
1375 .subtype = SLOW_SUBTYPE_LACP,
1379 ether_addr_copy(&parnter_system, &src_mac);
1380 ether_addr_copy(&slow_protocol_mac_addr, &dst_mac);
1382 initialize_eth_header(&lacpdu.eth_hdr, &src_mac, &dst_mac,
1383 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, 1);
1393 TEST_ASSERT_SUCCESS(retval, "Failed to initialize bonded device");
1395 memset(lacpdu_rx_count, 0, sizeof(lacpdu_rx_count));
1397 /* Wait for new settings to be applied. */
1398 for (i = 0; i < 30; ++i)
1399 rte_delay_ms(delay);
1401 FOR_EACH_SLAVE(i, slave) {
1402 retval = rte_eth_bond_8023ad_ext_slowtx(
1403 test_params.bonded_port_id,
1404 slave->port_id, lacp_tx_buf[i]);
1405 TEST_ASSERT_SUCCESS(retval,
1406 "Slave should allow manual LACP xmit");
1409 nb_pkts = bond_tx(NULL, 0);
1410 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets transmitted unexpectedly");
1412 FOR_EACH_SLAVE(i, slave) {
1413 nb_pkts = slave_get_pkts(slave, buf, RTE_DIM(buf));
1414 TEST_ASSERT_EQUAL(nb_pkts, 1, "found %u packets on slave %d\n",
1416 slave_put_pkts(slave, buf, nb_pkts);
1419 nb_pkts = bond_rx(buf, RTE_DIM(buf));
1420 free_pkts(buf, nb_pkts);
1421 TEST_ASSERT_EQUAL(nb_pkts, 0, "Packets received unexpectedly");
1423 /* wait for the periodic callback to run */
1424 for (i = 0; i < 30 && all_slaves_done == 0; ++i) {
1425 uint8_t s, total = 0;
1427 rte_delay_ms(delay);
1428 FOR_EACH_SLAVE(s, slave) {
1429 total += lacpdu_rx_count[slave->port_id];
1432 if (total >= SLAVE_COUNT)
1433 all_slaves_done = 1;
1436 FOR_EACH_SLAVE(i, slave) {
1437 TEST_ASSERT_EQUAL(lacpdu_rx_count[slave->port_id], 1,
1438 "Slave port %u should have received 1 lacpdu (count=%u)",
1440 lacpdu_rx_count[slave->port_id]);
1443 retval = remove_slaves_and_stop_bonded_device();
1444 TEST_ASSERT_SUCCESS(retval, "Test cleanup failed.");
1446 return TEST_SUCCESS;
1450 check_environment(void)
1452 struct slave_conf *port;
1453 uint8_t i, env_state;
1454 uint8_t slaves[RTE_DIM(test_params.slave_ports)];
1458 FOR_EACH_PORT(i, port) {
1459 if (rte_ring_count(port->rx_queue) != 0)
1462 if (rte_ring_count(port->tx_queue) != 0)
1465 if (port->bonded != 0)
1468 if (port->lacp_parnter_state != 0)
1475 slaves_count = rte_eth_bond_slaves_get(test_params.bonded_port_id,
1476 slaves, RTE_DIM(slaves));
1478 if (slaves_count != 0)
1481 TEST_ASSERT_EQUAL(env_state, 0,
1482 "Environment not clean (port %u):%s%s%s%s%s",
1484 env_state & 0x01 ? " slave rx queue not clean" : "",
1485 env_state & 0x02 ? " slave tx queue not clean" : "",
1486 env_state & 0x04 ? " port marked as enslaved" : "",
1487 env_state & 0x80 ? " slave state is not reset" : "",
1488 env_state & 0x10 ? " slave count not equal 0" : ".");
1491 return TEST_SUCCESS;
1495 test_mode4_executor(int (*test_func)(void))
1497 struct slave_conf *port;
1502 /* Check if environment is clean. Fail to launch a test if there was
1503 * a critical error before that prevented to reset environment. */
1504 TEST_ASSERT_SUCCESS(check_environment(),
1505 "Refusing to launch test in dirty environment.");
1507 RTE_VERIFY(test_func != NULL);
1508 test_result = (*test_func)();
1510 /* If test succeed check if environment wast left in good condition. */
1511 if (test_result == TEST_SUCCESS)
1512 test_result = check_environment();
1514 /* Reset environment in case test failed to do that. */
1515 if (test_result != TEST_SUCCESS) {
1516 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
1517 "Failed to stop bonded device");
1519 FOR_EACH_PORT(i, port) {
1520 while (rte_ring_count(port->rx_queue) != 0) {
1521 if (rte_ring_dequeue(port->rx_queue, &pkt) == 0)
1522 rte_pktmbuf_free(pkt);
1525 while (rte_ring_count(port->tx_queue) != 0) {
1526 if (rte_ring_dequeue(port->tx_queue, &pkt) == 0)
1527 rte_pktmbuf_free(pkt);
1536 test_mode4_lacp_wrapper(void)
1538 return test_mode4_executor(&test_mode4_lacp);
1542 test_mode4_marker_wrapper(void)
1544 return test_mode4_executor(&test_mode4_marker);
1548 test_mode4_rx_wrapper(void)
1550 return test_mode4_executor(&test_mode4_rx);
1554 test_mode4_tx_burst_wrapper(void)
1556 return test_mode4_executor(&test_mode4_tx_burst);
1560 test_mode4_expired_wrapper(void)
1562 return test_mode4_executor(&test_mode4_expired);
1566 test_mode4_ext_ctrl_wrapper(void)
1568 return test_mode4_executor(&test_mode4_ext_ctrl);
1572 test_mode4_ext_lacp_wrapper(void)
1574 return test_mode4_executor(&test_mode4_ext_lacp);
1577 static struct unit_test_suite link_bonding_mode4_test_suite = {
1578 .suite_name = "Link Bonding mode 4 Unit Test Suite",
1579 .setup = test_setup,
1580 .teardown = testsuite_teardown,
1581 .unit_test_cases = {
1582 TEST_CASE_NAMED("test_mode4_lacp", test_mode4_lacp_wrapper),
1583 TEST_CASE_NAMED("test_mode4_rx", test_mode4_rx_wrapper),
1584 TEST_CASE_NAMED("test_mode4_tx_burst", test_mode4_tx_burst_wrapper),
1585 TEST_CASE_NAMED("test_mode4_marker", test_mode4_marker_wrapper),
1586 TEST_CASE_NAMED("test_mode4_expired", test_mode4_expired_wrapper),
1587 TEST_CASE_NAMED("test_mode4_ext_ctrl",
1588 test_mode4_ext_ctrl_wrapper),
1589 TEST_CASE_NAMED("test_mode4_ext_lacp",
1590 test_mode4_ext_lacp_wrapper),
1592 TEST_CASES_END() /**< NULL terminate unit test array */
1597 test_link_bonding_mode4(void)
1599 return unit_test_suite_runner(&link_bonding_mode4_test_suite);
1602 REGISTER_TEST_COMMAND(link_bonding_mode4_autotest, test_link_bonding_mode4);