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 <sys/queue.h>
43 #include <rte_byteorder.h>
44 #include <rte_common.h>
45 #include <rte_debug.h>
46 #include <rte_ethdev.h>
48 #include <rte_lcore.h>
49 #include <rte_memory.h>
50 #include <rte_string_fns.h>
51 #include <rte_eth_bond.h>
53 #include "virtual_pmd.h"
54 #include "packet_burst_generator.h"
58 #define TEST_MAX_NUMBER_OF_PORTS (16)
60 #define RX_RING_SIZE 128
61 #define RX_FREE_THRESH 32
66 #define TX_RING_SIZE 512
67 #define TX_FREE_THRESH 32
71 #define TX_RSBIT_THRESH 32
72 #define TX_Q_FLAGS (ETH_TXQ_FLAGS_NOMULTSEGS | ETH_TXQ_FLAGS_NOVLANOFFL |\
73 ETH_TXQ_FLAGS_NOXSUMSCTP | ETH_TXQ_FLAGS_NOXSUMUDP | \
74 ETH_TXQ_FLAGS_NOXSUMTCP)
76 #define MBUF_PAYLOAD_SIZE (2048)
77 #define MBUF_SIZE (MBUF_PAYLOAD_SIZE + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
78 #define MBUF_CACHE_SIZE (250)
79 #define BURST_SIZE (32)
81 #define DEFAULT_MBUF_DATA_SIZE (2048)
82 #define RTE_TEST_RX_DESC_MAX (2048)
83 #define RTE_TEST_TX_DESC_MAX (2048)
84 #define MAX_PKT_BURST (512)
85 #define DEF_PKT_BURST (16)
87 #define BONDED_DEV_NAME ("unit_test_bonded_device")
89 #define INVALID_SOCKET_ID (-1)
90 #define INVALID_PORT_ID (-1)
91 #define INVALID_BONDING_MODE (-1)
94 uint8_t slave_mac[] = {0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 };
95 uint8_t bonded_mac[] = {0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
97 struct link_bonding_unittest_params {
98 int8_t bonded_port_id;
99 int8_t slave_port_ids[TEST_MAX_NUMBER_OF_PORTS];
100 uint8_t bonded_slave_count;
101 uint8_t bonding_mode;
106 struct rte_mempool *mbuf_pool;
108 struct ether_addr *default_slave_mac;
109 struct ether_addr *default_bonded_mac;
112 struct ether_hdr *pkt_eth_hdr;
113 struct ipv4_hdr *pkt_ipv4_hdr;
114 struct ipv6_hdr *pkt_ipv6_hdr;
115 struct udp_hdr *pkt_udp_hdr;
119 static struct ipv4_hdr pkt_ipv4_hdr;
120 static struct ipv6_hdr pkt_ipv6_hdr;
121 static struct udp_hdr pkt_udp_hdr;
123 static struct link_bonding_unittest_params default_params = {
124 .bonded_port_id = -1,
125 .slave_port_ids = { -1 },
126 .bonded_slave_count = 0,
127 .bonding_mode = BONDING_MODE_ROUND_ROBIN,
134 .default_slave_mac = (struct ether_addr *)slave_mac,
135 .default_bonded_mac = (struct ether_addr *)bonded_mac,
138 .pkt_ipv4_hdr = &pkt_ipv4_hdr,
139 .pkt_ipv6_hdr = &pkt_ipv6_hdr,
140 .pkt_udp_hdr = &pkt_udp_hdr
144 static struct link_bonding_unittest_params *test_params = &default_params;
146 static uint8_t src_mac[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
147 static uint8_t dst_mac_0[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
148 static uint8_t dst_mac_1[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAB };
150 static uint32_t src_addr = IPV4_ADDR(192, 168, 1, 98);
151 static uint32_t dst_addr_0 = IPV4_ADDR(192, 168, 1, 98);
152 static uint32_t dst_addr_1 = IPV4_ADDR(193, 166, 10, 97);
154 static uint8_t src_ipv6_addr[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF,
155 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA , 0xFF, 0xAA };
156 static uint8_t dst_ipv6_addr_0[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF,
157 0xAA, 0xFF, 0xAA, 0xFF, 0xAA , 0xFF, 0xAA, 0xFF, 0xAA };
158 static uint8_t dst_ipv6_addr_1[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF,
159 0xAA, 0xFF, 0xAA, 0xFF, 0xAA , 0xFF, 0xAA , 0xFF, 0xAB };
161 static uint16_t src_port = 1024;
162 static uint16_t dst_port_0 = 1024;
163 static uint16_t dst_port_1 = 2024;
165 static uint16_t vlan_id = 0x100;
167 struct rte_eth_rxmode rx_mode = {
168 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
170 .header_split = 0, /**< Header Split disabled. */
171 .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
172 .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
173 .hw_vlan_strip = 1, /**< VLAN strip enabled. */
174 .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
175 .jumbo_frame = 0, /**< Jumbo Frame Support disabled. */
176 .hw_strip_crc = 0, /**< CRC stripping by hardware disabled. */
179 struct rte_fdir_conf fdir_conf = {
180 .mode = RTE_FDIR_MODE_NONE,
181 .pballoc = RTE_FDIR_PBALLOC_64K,
182 .status = RTE_FDIR_REPORT_STATUS,
183 .flexbytes_offset = 0x6,
187 static struct rte_eth_conf default_pmd_conf = {
189 .mq_mode = ETH_MQ_RX_NONE,
190 .max_rx_pkt_len = ETHER_MAX_LEN,
192 .header_split = 0, /**< Header Split disabled */
193 .hw_ip_checksum = 0, /**< IP checksum offload enabled */
194 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
195 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
196 .hw_strip_crc = 0, /**< CRC stripped by hardware */
199 .mq_mode = ETH_MQ_TX_NONE,
204 static const struct rte_eth_rxconf rx_conf_default = {
206 .pthresh = RX_PTHRESH,
207 .hthresh = RX_HTHRESH,
208 .wthresh = RX_WTHRESH,
210 .rx_free_thresh = RX_FREE_THRESH,
214 static struct rte_eth_txconf tx_conf_default = {
216 .pthresh = TX_PTHRESH,
217 .hthresh = TX_HTHRESH,
218 .wthresh = TX_WTHRESH,
220 .tx_free_thresh = TX_FREE_THRESH,
221 .tx_rs_thresh = TX_RSBIT_THRESH,
222 .txq_flags = TX_Q_FLAGS
227 configure_ethdev(uint8_t port_id, uint8_t start)
231 if (rte_eth_dev_configure(port_id, test_params->nb_rx_q,
232 test_params->nb_tx_q, &default_pmd_conf) != 0) {
236 for (q_id = 0; q_id < test_params->nb_rx_q; q_id++) {
237 if (rte_eth_rx_queue_setup(port_id, q_id, RX_RING_SIZE,
238 rte_eth_dev_socket_id(port_id), &rx_conf_default,
239 test_params->mbuf_pool) < 0) {
244 for (q_id = 0; q_id < test_params->nb_tx_q; q_id++) {
245 if (rte_eth_tx_queue_setup(port_id, q_id, TX_RING_SIZE,
246 rte_eth_dev_socket_id(port_id), &tx_conf_default) < 0) {
247 printf("Failed to setup tx queue (%d).\n", q_id);
253 if (rte_eth_dev_start(port_id) < 0) {
254 printf("Failed to start device (%d).\n", port_id);
261 printf("Failed to configure ethdev %d\n", port_id);
265 static int slaves_initialized;
270 int i, retval, nb_mbuf_per_pool;
271 struct ether_addr *mac_addr = (struct ether_addr *)slave_mac;
273 /* Allocate ethernet packet header with space for VLAN header */
274 if (test_params->pkt_eth_hdr == NULL) {
275 test_params->pkt_eth_hdr = malloc(sizeof(struct ether_hdr) +
276 sizeof(struct vlan_hdr));
278 if (test_params->pkt_eth_hdr == NULL) {
279 printf("ethernet header struct allocation failed!\n");
284 nb_mbuf_per_pool = RTE_TEST_RX_DESC_MAX + DEF_PKT_BURST +
285 RTE_TEST_TX_DESC_MAX + MAX_PKT_BURST;
286 if (test_params->mbuf_pool == NULL) {
287 test_params->mbuf_pool = rte_mempool_create("MBUF_POOL", nb_mbuf_per_pool,
288 MBUF_SIZE, MBUF_CACHE_SIZE, sizeof(struct rte_pktmbuf_pool_private),
289 rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL,
291 if (test_params->mbuf_pool == NULL) {
292 printf("rte_mempool_create failed\n");
297 /* Create / Initialize virtual eth devs */
298 if (!slaves_initialized) {
299 for (i = 0; i < TEST_MAX_NUMBER_OF_PORTS; i++) {
300 char pmd_name[RTE_ETH_NAME_MAX_LEN];
302 mac_addr->addr_bytes[ETHER_ADDR_LEN-1] = i;
304 snprintf(pmd_name, RTE_ETH_NAME_MAX_LEN, "eth_virt_%d", i);
306 test_params->slave_port_ids[i] = virtual_ethdev_create(pmd_name,
307 mac_addr, rte_socket_id());
308 if (test_params->slave_port_ids[i] < 0) {
309 printf("Failed to create virtual virtual ethdev %s\n", pmd_name);
313 printf("Created virtual ethdev %s\n", pmd_name);
315 retval = configure_ethdev(test_params->slave_port_ids[i], 1);
317 printf("Failed to configure virtual ethdev %s\n", pmd_name);
321 printf("Configured virtual ethdev %s\n", pmd_name);
323 slaves_initialized = 1;
330 test_create_bonded_device(void)
332 int current_slave_count;
334 uint8_t slaves[RTE_MAX_ETHPORTS];
336 /* Don't try to recreate bonded device if re-running test suite*/
337 if (test_params->bonded_port_id == -1) {
338 test_params->bonded_port_id = rte_eth_bond_create(BONDED_DEV_NAME,
339 test_params->bonding_mode, rte_socket_id());
341 TEST_ASSERT(test_params->bonded_port_id >= 0,
342 "Failed to create bonded ethdev %s", BONDED_DEV_NAME);
344 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0),
345 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME);
348 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
349 test_params->bonding_mode), "Failed to set ethdev %d to mode %d",
350 test_params->bonded_port_id, test_params->bonding_mode);
352 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
353 slaves, RTE_MAX_ETHPORTS);
355 TEST_ASSERT(current_slave_count == 0,
356 "Number of slaves %d is great than expected %d.",
357 current_slave_count, 0);
359 current_slave_count = rte_eth_bond_active_slaves_get(
360 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
362 TEST_ASSERT(current_slave_count == 0,
363 "Number of active slaves %d is great than expected %d.",
364 current_slave_count, 0);
371 test_create_bonded_device_with_invalid_params(void)
375 test_params->bonding_mode = BONDING_MODE_ROUND_ROBIN;
378 port_id = rte_eth_bond_create(NULL, test_params->bonding_mode,
381 printf("Created bonded device unexpectedly.\n");
385 test_params->bonding_mode = INVALID_BONDING_MODE;
387 /* Invalid bonding mode */
388 port_id = rte_eth_bond_create(BONDED_DEV_NAME, test_params->bonding_mode,
391 printf("Created bonded device unexpectedly.\n");
395 test_params->bonding_mode = BONDING_MODE_ROUND_ROBIN;
397 /* Invalid socket id */
398 port_id = rte_eth_bond_create(BONDED_DEV_NAME, test_params->bonding_mode,
401 printf("Created bonded device unexpectedly.\n");
409 test_add_slave_to_bonded_device(void)
411 int retval, current_slave_count;
413 uint8_t slaves[RTE_MAX_ETHPORTS];
415 retval = rte_eth_bond_slave_add(test_params->bonded_port_id,
416 test_params->slave_port_ids[test_params->bonded_slave_count]);
418 printf("Failed to add slave (%d) to bonded port (%d).\n",
419 test_params->bonded_port_id,
420 test_params->slave_port_ids[test_params->bonded_slave_count]);
424 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
425 slaves, RTE_MAX_ETHPORTS);
426 if (current_slave_count != test_params->bonded_slave_count + 1) {
427 printf("Number of slaves (%d) is greater than expected (%d).\n",
428 current_slave_count, test_params->bonded_slave_count + 1);
432 current_slave_count = rte_eth_bond_active_slaves_get(
433 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
434 if (current_slave_count != 0) {
435 printf("Number of active slaves (%d) is not as expected (%d).\n",
436 current_slave_count, 0);
440 test_params->bonded_slave_count++;
446 test_add_slave_to_invalid_bonded_device(void)
450 /* Invalid port ID */
451 retval = rte_eth_bond_slave_add(test_params->bonded_port_id + 5,
452 test_params->slave_port_ids[test_params->bonded_slave_count]);
454 printf("Expected call to failed as invalid port specified.\n");
458 /* Non bonded device */
459 retval = rte_eth_bond_slave_add(test_params->slave_port_ids[0],
460 test_params->slave_port_ids[test_params->bonded_slave_count]);
462 printf("Expected call to failed as invalid port specified.\n");
471 test_remove_slave_from_bonded_device(void)
473 int retval, current_slave_count;
474 struct ether_addr read_mac_addr, *mac_addr;
475 uint8_t slaves[RTE_MAX_ETHPORTS];
477 retval = rte_eth_bond_slave_remove(test_params->bonded_port_id,
478 test_params->slave_port_ids[test_params->bonded_slave_count-1]);
480 printf("\t Failed to remove slave %d from bonded port (%d).\n",
481 test_params->slave_port_ids[test_params->bonded_slave_count-1],
482 test_params->bonded_port_id);
487 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
488 slaves, RTE_MAX_ETHPORTS);
489 if (current_slave_count != test_params->bonded_slave_count - 1) {
490 printf("Number of slaves (%d) is great than expected (%d).\n",
491 current_slave_count, 0);
496 mac_addr = (struct ether_addr *)slave_mac;
497 mac_addr->addr_bytes[ETHER_ADDR_LEN-1] =
498 test_params->slave_port_ids[test_params->bonded_slave_count-1];
501 test_params->slave_port_ids[test_params->bonded_slave_count-1],
503 if (memcmp(mac_addr, &read_mac_addr, sizeof(read_mac_addr))) {
504 printf("bonded port mac address not set to that of primary port\n");
509 test_params->slave_port_ids[test_params->bonded_slave_count-1]);
511 virtual_ethdev_simulate_link_status_interrupt(test_params->bonded_port_id,
514 test_params->bonded_slave_count--;
520 test_remove_slave_from_invalid_bonded_device(void)
524 /* Invalid port ID */
525 retval = rte_eth_bond_slave_remove(test_params->bonded_port_id + 5,
526 test_params->slave_port_ids[test_params->bonded_slave_count - 1]);
528 printf("Expected call to failed as invalid port specified.\n");
532 /* Non bonded device */
533 retval = rte_eth_bond_slave_remove(test_params->slave_port_ids[0],
534 test_params->slave_port_ids[test_params->bonded_slave_count - 1]);
536 printf("Expected call to failed as invalid port specified.\n");
543 static int bonded_id = 2;
546 test_add_already_bonded_slave_to_bonded_device(void)
548 int retval, port_id, current_slave_count;
549 uint8_t slaves[RTE_MAX_ETHPORTS];
550 char pmd_name[RTE_ETH_NAME_MAX_LEN];
552 test_add_slave_to_bonded_device();
554 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
555 slaves, RTE_MAX_ETHPORTS);
556 if (current_slave_count != 1) {
557 printf("Number of slaves (%d) is not that expected (%d).\n",
558 current_slave_count, 1);
562 snprintf(pmd_name, RTE_ETH_NAME_MAX_LEN, "%s_%d", BONDED_DEV_NAME, ++bonded_id);
564 port_id = rte_eth_bond_create(pmd_name, test_params->bonding_mode,
567 printf("Failed to create bonded device.\n");
571 retval = rte_eth_bond_slave_add(port_id,
572 test_params->slave_port_ids[test_params->bonded_slave_count - 1]);
574 printf("Added slave (%d) to bonded port (%d) unexpectedly.\n",
575 test_params->slave_port_ids[test_params->bonded_slave_count-1],
580 return test_remove_slave_from_bonded_device();
585 test_get_slaves_from_bonded_device(void)
587 int retval, current_slave_count;
589 uint8_t slaves[RTE_MAX_ETHPORTS];
591 retval = test_add_slave_to_bonded_device();
595 /* Invalid port id */
596 current_slave_count = rte_eth_bond_slaves_get(INVALID_PORT_ID, slaves,
598 if (current_slave_count >= 0)
601 current_slave_count = rte_eth_bond_active_slaves_get(INVALID_PORT_ID,
602 slaves, RTE_MAX_ETHPORTS);
603 if (current_slave_count >= 0)
606 /* Invalid slaves pointer */
607 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
608 NULL, RTE_MAX_ETHPORTS);
609 if (current_slave_count >= 0)
612 current_slave_count = rte_eth_bond_active_slaves_get(
613 test_params->bonded_port_id, NULL, RTE_MAX_ETHPORTS);
614 if (current_slave_count >= 0)
617 /* non bonded device*/
618 current_slave_count = rte_eth_bond_slaves_get(
619 test_params->slave_port_ids[0], NULL, RTE_MAX_ETHPORTS);
620 if (current_slave_count >= 0)
623 current_slave_count = rte_eth_bond_active_slaves_get(
624 test_params->slave_port_ids[0], NULL, RTE_MAX_ETHPORTS);
625 if (current_slave_count >= 0)
628 retval = test_remove_slave_from_bonded_device();
637 test_add_remove_multiple_slaves_to_from_bonded_device(void)
641 for (i = 0; i < TEST_MAX_NUMBER_OF_PORTS; i++) {
642 if (test_add_slave_to_bonded_device() != 0)
646 for (i = 0; i < TEST_MAX_NUMBER_OF_PORTS; i++) {
647 if (test_remove_slave_from_bonded_device() != 0)
655 enable_bonded_slaves(void)
659 for (i = 0; i < test_params->bonded_slave_count; i++) {
660 virtual_ethdev_simulate_link_status_interrupt(
661 test_params->slave_port_ids[i], 1);
666 test_start_bonded_device(void)
668 struct rte_eth_link link_status;
670 int current_slave_count, current_bonding_mode, primary_port;
671 uint8_t slaves[RTE_MAX_ETHPORTS];
673 /* Add slave to bonded device*/
674 if (test_add_slave_to_bonded_device() != 0)
677 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
678 "Failed to start bonded pmd eth device %d.",
679 test_params->bonded_port_id);
681 /* Change link status of virtual pmd so it will be added to the active
682 * slave list of the bonded device*/
683 virtual_ethdev_simulate_link_status_interrupt(
684 test_params->slave_port_ids[test_params->bonded_slave_count-1], 1);
686 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
687 slaves, RTE_MAX_ETHPORTS);
688 if (current_slave_count != test_params->bonded_slave_count) {
689 printf("Number of slaves (%d) is not expected value (%d).\n",
690 current_slave_count, test_params->bonded_slave_count);
694 current_slave_count = rte_eth_bond_active_slaves_get(
695 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
696 if (current_slave_count != test_params->bonded_slave_count) {
697 printf("Number of active slaves (%d) is not expected value (%d).\n",
698 current_slave_count, test_params->bonded_slave_count);
702 current_bonding_mode = rte_eth_bond_mode_get(test_params->bonded_port_id);
703 if (current_bonding_mode != test_params->bonding_mode) {
704 printf("Bonded device mode (%d) is not expected value (%d).\n",
705 current_bonding_mode, test_params->bonding_mode);
710 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
711 if (primary_port != test_params->slave_port_ids[0]) {
712 printf("Primary port (%d) is not expected value (%d).\n",
713 primary_port, test_params->slave_port_ids[0]);
718 rte_eth_link_get(test_params->bonded_port_id, &link_status);
719 if (!link_status.link_status) {
720 printf("Bonded port (%d) status (%d) is not expected value (%d).\n",
721 test_params->bonded_port_id, link_status.link_status, 1);
730 test_stop_bonded_device(void)
732 int current_slave_count;
733 uint8_t slaves[RTE_MAX_ETHPORTS];
735 struct rte_eth_link link_status;
737 rte_eth_dev_stop(test_params->bonded_port_id);
739 rte_eth_link_get(test_params->bonded_port_id, &link_status);
740 if (link_status.link_status) {
741 printf("Bonded port (%d) status (%d) is not expected value (%d).\n",
742 test_params->bonded_port_id, link_status.link_status, 0);
746 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
747 slaves, RTE_MAX_ETHPORTS);
748 if (current_slave_count != test_params->bonded_slave_count) {
749 printf("Number of slaves (%d) is not expected value (%d).\n",
750 current_slave_count, test_params->bonded_slave_count);
754 current_slave_count = rte_eth_bond_active_slaves_get(
755 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
756 if (current_slave_count != 0) {
757 printf("Number of active slaves (%d) is not expected value (%d).\n",
758 current_slave_count, 0);
765 static int remove_slaves_and_stop_bonded_device(void)
767 /* Clean up and remove slaves from bonded device */
768 while (test_params->bonded_slave_count > 0) {
769 if (test_remove_slave_from_bonded_device() != 0) {
770 printf("test_remove_slave_from_bonded_device failed\n");
775 rte_eth_dev_stop(test_params->bonded_port_id);
776 rte_eth_stats_reset(test_params->bonded_port_id);
777 rte_eth_bond_mac_address_reset(test_params->bonded_port_id);
783 test_set_bonding_mode(void)
786 int retval, bonding_mode;
788 int bonding_modes[] = { BONDING_MODE_ROUND_ROBIN,
789 BONDING_MODE_ACTIVE_BACKUP,
790 BONDING_MODE_BALANCE,
791 #ifdef RTE_MBUF_REFCNT
792 BONDING_MODE_BROADCAST
796 /* Test supported link bonding modes */
797 for (i = 0; i < (int)RTE_DIM(bonding_modes); i++) {
798 /* Invalid port ID */
799 retval = rte_eth_bond_mode_set(INVALID_PORT_ID, bonding_modes[i]);
801 printf("Expected call to failed as invalid port (%d) specified.\n",
806 /* Non bonded device */
807 retval = rte_eth_bond_mode_set(test_params->slave_port_ids[0],
810 printf("Expected call to failed as invalid port (%d) specified.\n",
811 test_params->slave_port_ids[0]);
815 retval = rte_eth_bond_mode_set(test_params->bonded_port_id,
818 printf("Failed to set link bonding mode on port (%d) to (%d).\n",
819 test_params->bonded_port_id, bonding_modes[i]);
823 bonding_mode = rte_eth_bond_mode_get(test_params->bonded_port_id);
824 if (bonding_mode != bonding_modes[i]) {
825 printf("Link bonding mode (%d) of port (%d) is not expected value (%d).\n",
826 bonding_mode, test_params->bonded_port_id,
832 /* Invalid port ID */
833 bonding_mode = rte_eth_bond_mode_get(INVALID_PORT_ID);
834 if (bonding_mode >= 0) {
835 printf("Expected call to failed as invalid port (%d) specified.\n",
841 /* Non bonded device */
842 bonding_mode = rte_eth_bond_mode_get(test_params->slave_port_ids[0]);
843 if (bonding_mode >= 0) {
844 printf("Expected call to failed as invalid port (%d) specified.\n",
845 test_params->slave_port_ids[0]);
851 return remove_slaves_and_stop_bonded_device();
855 test_set_primary_slave(void)
858 struct ether_addr read_mac_addr;
859 struct ether_addr *expected_mac_addr;
861 /* Add 4 slaves to bonded device */
862 for (i = test_params->bonded_slave_count; i < 4; i++) {
863 retval = test_add_slave_to_bonded_device();
865 printf("Failed to add slave to bonded device.\n");
869 retval = rte_eth_bond_mode_set(test_params->bonded_port_id,
870 BONDING_MODE_ROUND_ROBIN);
872 printf("Failed to set link bonding mode on port (%d) to (%d).\n",
873 test_params->bonded_port_id, BONDING_MODE_ROUND_ROBIN);
877 /* Invalid port ID */
878 retval = rte_eth_bond_primary_set(INVALID_PORT_ID,
879 test_params->slave_port_ids[i]);
881 printf("Expected call to failed as invalid port specified.\n");
885 /* Set slave as primary
886 * Verify slave it is now primary slave
887 * Verify that MAC address of bonded device is that of primary slave
888 * Verify that MAC address of all bonded slaves are that of primary slave
890 for (i = 0; i < 4; i++) {
892 /* Non bonded device */
893 retval = rte_eth_bond_primary_set(test_params->slave_port_ids[i],
894 test_params->slave_port_ids[i]);
896 printf("Expected call to failed as invalid port specified.\n");
900 retval = rte_eth_bond_primary_set(test_params->bonded_port_id,
901 test_params->slave_port_ids[i]);
903 printf("Failed to set bonded port (%d) primary port to (%d)\n",
904 test_params->bonded_port_id,
905 test_params->slave_port_ids[i]);
909 retval = rte_eth_bond_primary_get(test_params->bonded_port_id);
911 printf("Failed to read primary port from bonded port (%d)\n",
912 test_params->bonded_port_id);
914 } else if (retval != test_params->slave_port_ids[i]) {
915 printf("Bonded port (%d) primary port (%d) not expected value (%d)\n",
916 test_params->bonded_port_id, retval,
917 test_params->slave_port_ids[i]);
921 /* stop/start bonded eth dev to apply new MAC */
922 rte_eth_dev_stop(test_params->bonded_port_id);
923 if (rte_eth_dev_start(test_params->bonded_port_id) != 0)
926 expected_mac_addr = (struct ether_addr *)&slave_mac;
927 expected_mac_addr->addr_bytes[ETHER_ADDR_LEN-1] =
928 test_params->slave_port_ids[i];
930 /* Check primary slave MAC */
931 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
932 if (memcmp(expected_mac_addr, &read_mac_addr, sizeof(read_mac_addr))) {
933 printf("bonded port mac address not set to that of primary port\n");
937 /* Check bonded MAC */
938 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
939 if (memcmp(&read_mac_addr, &read_mac_addr, sizeof(read_mac_addr))) {
940 printf("bonded port mac address not set to that of primary port\n");
944 /* Check other slaves MACs */
945 for (j = 0; j < 4; j++) {
947 rte_eth_macaddr_get(test_params->slave_port_ids[j],
949 if (memcmp(expected_mac_addr, &read_mac_addr,
950 sizeof(read_mac_addr))) {
951 printf("slave port mac address not set to that of primary port\n");
959 /* Test with none existent port */
960 retval = rte_eth_bond_primary_get(test_params->bonded_port_id + 10);
962 printf("read primary port from expectedly\n");
966 /* Test with slave port */
967 retval = rte_eth_bond_primary_get(test_params->slave_port_ids[0]);
969 printf("read primary port from expectedly\n");
973 if (remove_slaves_and_stop_bonded_device() != 0)
977 retval = rte_eth_bond_primary_get(test_params->bonded_port_id);
979 printf("read primary port from expectedly\n");
987 test_set_explicit_bonded_mac(void)
990 struct ether_addr read_mac_addr;
991 struct ether_addr *mac_addr;
993 uint8_t explicit_bonded_mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01 };
995 mac_addr = (struct ether_addr *)explicit_bonded_mac;
997 /* Invalid port ID */
998 retval = rte_eth_bond_mac_address_set(INVALID_PORT_ID, mac_addr);
1000 printf("Expected call to failed as invalid port specified.\n");
1004 /* Non bonded device */
1005 retval = rte_eth_bond_mac_address_set(test_params->slave_port_ids[0],
1008 printf("Expected call to failed as invalid port specified.\n");
1012 /* NULL MAC address */
1013 retval = rte_eth_bond_mac_address_set(test_params->bonded_port_id, NULL);
1015 printf("Expected call to failed as NULL MAC specified\n");
1019 retval = rte_eth_bond_mac_address_set(test_params->bonded_port_id,
1022 printf("Failed to set MAC address on bonded port (%d)\n",
1023 test_params->bonded_port_id);
1027 /* Add 4 slaves to bonded device */
1028 for (i = test_params->bonded_slave_count; i < 4; i++) {
1029 retval = test_add_slave_to_bonded_device();
1031 printf("Failed to add slave to bonded device.\n");
1036 /* Check bonded MAC */
1037 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
1038 if (memcmp(mac_addr, &read_mac_addr, sizeof(read_mac_addr))) {
1039 printf("bonded port mac address not set to that of primary port\n");
1043 /* Check other slaves MACs */
1044 for (i = 0; i < 4; i++) {
1045 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1046 if (memcmp(mac_addr, &read_mac_addr, sizeof(read_mac_addr))) {
1047 printf("slave port mac address not set to that of primary port\n");
1052 /* test resetting mac address on bonded device */
1053 if (rte_eth_bond_mac_address_reset(test_params->bonded_port_id) != 0) {
1054 printf("Failed to reset MAC address on bonded port (%d)\n",
1055 test_params->bonded_port_id);
1060 if (rte_eth_bond_mac_address_reset(test_params->slave_port_ids[0]) == 0) {
1061 printf("Reset MAC address on bonded port (%d) unexpectedly\n",
1062 test_params->slave_port_ids[1]);
1067 /* test resetting mac address on bonded device with no slaves */
1069 if (remove_slaves_and_stop_bonded_device() != 0)
1072 if (rte_eth_bond_mac_address_reset(test_params->bonded_port_id) != 0) {
1073 printf("Failed to reset MAC address on bonded port (%d)\n",
1074 test_params->bonded_port_id);
1084 initialize_bonded_device_with_slaves(uint8_t bonding_mode,
1085 uint8_t number_of_slaves, uint8_t enable_slave)
1087 /* configure bonded device */
1088 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0),
1089 "Failed to configure bonding port (%d) in mode %d "
1090 "with (%d) slaves.", test_params->bonded_port_id, bonding_mode,
1093 while (number_of_slaves > test_params->bonded_slave_count) {
1094 /* Add slaves to bonded device */
1095 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
1096 "Failed to add slave (%d to bonding port (%d).",
1097 test_params->bonded_slave_count - 1,
1098 test_params->bonded_port_id);
1101 /* Set link bonding mode */
1102 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
1104 "Failed to set link bonding mode on port (%d) to (%d).",
1105 test_params->bonded_port_id, bonding_mode);
1107 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
1108 "Failed to start bonded pmd eth device %d.",
1109 test_params->bonded_port_id);
1112 enable_bonded_slaves();
1118 test_adding_slave_after_bonded_device_started(void)
1122 if (initialize_bonded_device_with_slaves(BONDING_MODE_ROUND_ROBIN, 4, 0) !=
1126 /* Enabled slave devices */
1127 for (i = 0; i < test_params->bonded_slave_count + 1; i++) {
1128 virtual_ethdev_simulate_link_status_interrupt(
1129 test_params->slave_port_ids[i], 1);
1132 if (rte_eth_bond_slave_add(test_params->bonded_port_id,
1133 test_params->slave_port_ids[test_params->bonded_slave_count]) !=
1135 printf("\t Failed to add slave to bonded port.\n");
1139 rte_eth_stats_reset(
1140 test_params->slave_port_ids[test_params->bonded_slave_count]);
1142 test_params->bonded_slave_count++;
1144 return remove_slaves_and_stop_bonded_device();
1148 generate_test_burst(struct rte_mbuf **pkts_burst, uint16_t burst_size,
1149 uint8_t vlan, uint8_t ipv4, uint8_t toggle_dst_mac,
1150 uint8_t toggle_ip_addr, uint8_t toggle_udp_port)
1152 uint16_t pktlen, generated_burst_size;
1156 initialize_eth_header(test_params->pkt_eth_hdr,
1157 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_1,
1160 initialize_eth_header(test_params->pkt_eth_hdr,
1161 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_0,
1165 if (toggle_udp_port)
1166 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
1169 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
1174 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
1175 dst_addr_1, pktlen);
1177 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
1178 dst_addr_0, pktlen);
1180 ip_hdr = test_params->pkt_ipv4_hdr;
1183 pktlen = initialize_ipv6_header(test_params->pkt_ipv6_hdr,
1184 (uint8_t *)src_ipv6_addr, (uint8_t *)dst_ipv6_addr_1,
1187 pktlen = initialize_ipv6_header(test_params->pkt_ipv6_hdr,
1188 (uint8_t *)src_ipv6_addr, (uint8_t *)dst_ipv6_addr_0,
1191 ip_hdr = test_params->pkt_ipv6_hdr;
1194 /* Generate burst of packets to transmit */
1195 generated_burst_size = generate_packet_burst(test_params->mbuf_pool,
1196 pkts_burst, test_params->pkt_eth_hdr, vlan, ip_hdr, ipv4,
1197 test_params->pkt_udp_hdr, burst_size);
1198 if (generated_burst_size != burst_size) {
1199 printf("Failed to generate packet burst");
1203 return generated_burst_size;
1206 /** Round Robin Mode Tests */
1209 test_roundrobin_tx_burst(void)
1211 int i, burst_size, nb_tx;
1212 struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
1213 struct rte_eth_stats port_stats;
1215 if (initialize_bonded_device_with_slaves(BONDING_MODE_ROUND_ROBIN, 2, 1)
1219 burst_size = 20 * test_params->bonded_slave_count;
1221 if (burst_size > MAX_PKT_BURST) {
1222 printf("Burst size specified is greater than supported.\n");
1226 /* Generate test bursts of packets to transmit */
1227 if (generate_test_burst(pkt_burst, burst_size, 0, 1, 0, 0, 0) != burst_size)
1230 /* Send burst on bonded port */
1231 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkt_burst,
1233 if (nb_tx != burst_size)
1236 /* Verify bonded port tx stats */
1237 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1238 if (port_stats.opackets != (uint64_t)burst_size) {
1239 printf("Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
1240 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
1245 /* Verify slave ports tx stats */
1246 for (i = 0; i < test_params->bonded_slave_count; i++) {
1247 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
1248 if (port_stats.opackets !=
1249 (uint64_t)burst_size / test_params->bonded_slave_count) {
1250 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
1251 test_params->bonded_port_id,
1252 (unsigned int)port_stats.opackets,
1253 burst_size / test_params->bonded_slave_count);
1258 /* Put all slaves down and try and transmit */
1259 for (i = 0; i < test_params->bonded_slave_count; i++) {
1260 virtual_ethdev_simulate_link_status_interrupt(
1261 test_params->slave_port_ids[i], 0);
1264 /* Send burst on bonded port */
1265 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkt_burst,
1270 /* Clean up and remove slaves from bonded device */
1271 return remove_slaves_and_stop_bonded_device();
1275 test_roundrobin_rx_burst_on_single_slave(void)
1277 struct rte_mbuf *gen_pkt_burst[MAX_PKT_BURST] = { NULL };
1278 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1280 struct rte_eth_stats port_stats;
1282 int i, j, nb_rx, burst_size = 25;
1284 /* Initialize bonded device with 4 slaves in round robin mode */
1285 if (initialize_bonded_device_with_slaves(BONDING_MODE_ROUND_ROBIN, 4, 1) !=
1289 /* Generate test bursts of packets to transmit */
1290 if (generate_test_burst(gen_pkt_burst, burst_size, 0, 1, 0, 0, 0) !=
1294 for (i = 0; i < test_params->bonded_slave_count; i++) {
1295 /* Add rx data to slave */
1296 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1297 &gen_pkt_burst[0], burst_size);
1299 /* Call rx burst on bonded device */
1300 /* Send burst on bonded port */
1301 nb_rx = rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
1303 if (nb_rx != burst_size) {
1304 printf("round-robin rx burst failed");
1308 /* Verify bonded device rx count */
1309 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1310 if (port_stats.ipackets != (uint64_t)burst_size) {
1311 printf("Bonded Port (%d) ipackets value (%u) not as expected (%d)\n",
1312 test_params->bonded_port_id,
1313 (unsigned int)port_stats.ipackets, burst_size);
1318 /* Verify bonded slave devices rx count */
1319 /* Verify slave ports tx stats */
1320 for (j = 0; j < test_params->bonded_slave_count; j++) {
1321 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
1324 if (port_stats.ipackets != (uint64_t)burst_size) {
1325 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
1326 test_params->slave_port_ids[i],
1327 (unsigned int)port_stats.ipackets, burst_size);
1331 if (port_stats.ipackets != 0) {
1332 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
1333 test_params->slave_port_ids[i],
1334 (unsigned int)port_stats.ipackets, 0);
1339 /* Reset bonded slaves stats */
1340 rte_eth_stats_reset(test_params->slave_port_ids[j]);
1342 /* reset bonded device stats */
1343 rte_eth_stats_reset(test_params->bonded_port_id);
1347 for (i = 0; i < MAX_PKT_BURST; i++) {
1348 if (gen_pkt_burst[i] != NULL)
1349 rte_pktmbuf_free(gen_pkt_burst[i]);
1351 if (rx_pkt_burst[i] != NULL)
1352 rte_pktmbuf_free(rx_pkt_burst[i]);
1356 /* Clean up and remove slaves from bonded device */
1357 return remove_slaves_and_stop_bonded_device();
1360 #define TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT (3)
1363 test_roundrobin_rx_burst_on_multiple_slaves(void)
1365 struct rte_mbuf *gen_pkt_burst[TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
1367 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1368 struct rte_eth_stats port_stats;
1370 int burst_size[TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT] = { 15, 13, 36 };
1374 /* Initialize bonded device with 4 slaves in round robin mode */
1375 if (initialize_bonded_device_with_slaves(BONDING_MODE_ROUND_ROBIN, 4, 1) !=
1379 /* Generate test bursts of packets to transmit */
1380 for (i = 0; i < TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT; i++) {
1381 if (generate_test_burst(&gen_pkt_burst[i][0], burst_size[i], 0, 1, 0, 0,
1382 0) != burst_size[i])
1386 /* Add rx data to slaves */
1387 for (i = 0; i < TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT; i++) {
1388 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1389 &gen_pkt_burst[i][0], burst_size[i]);
1392 /* Call rx burst on bonded device */
1393 /* Send burst on bonded port */
1394 nb_rx = rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
1396 if (nb_rx != burst_size[0] + burst_size[1] + burst_size[2]) {
1397 printf("round-robin rx burst failed (%d != %d)\n", nb_rx,
1398 burst_size[0] + burst_size[1] + burst_size[2]);
1402 /* Verify bonded device rx count */
1403 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1404 if (port_stats.ipackets != (uint64_t)(burst_size[0] + burst_size[1] +
1406 printf("Bonded Port (%d) ipackets value (%u) not as expected (%d)\n",
1407 test_params->bonded_port_id, (unsigned int)port_stats.ipackets,
1408 burst_size[0] + burst_size[1] + burst_size[2]);
1413 /* Verify bonded slave devices rx counts */
1414 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
1415 if (port_stats.ipackets != (uint64_t)burst_size[0]) {
1416 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
1417 test_params->slave_port_ids[0],
1418 (unsigned int)port_stats.ipackets, burst_size[0]);
1422 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
1423 if (port_stats.ipackets != (uint64_t)burst_size[1]) {
1424 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
1425 test_params->slave_port_ids[1],
1426 (unsigned int)port_stats.ipackets, burst_size[1]);
1430 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
1431 if (port_stats.ipackets != (uint64_t)burst_size[2]) {
1432 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
1433 test_params->slave_port_ids[2],
1434 (unsigned int)port_stats.ipackets, burst_size[2]);
1438 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
1439 if (port_stats.ipackets != 0) {
1440 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
1441 test_params->slave_port_ids[3],
1442 (unsigned int)port_stats.ipackets, 0);
1447 for (i = 0; i < MAX_PKT_BURST; i++) {
1448 if (rx_pkt_burst[i] != NULL)
1449 rte_pktmbuf_free(rx_pkt_burst[i]);
1452 /* Clean up and remove slaves from bonded device */
1453 return remove_slaves_and_stop_bonded_device();
1457 test_roundrobin_verify_mac_assignment(void)
1459 struct ether_addr read_mac_addr, expected_mac_addr_0, expected_mac_addr_2;
1463 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
1464 rte_eth_macaddr_get(test_params->slave_port_ids[2], &expected_mac_addr_2);
1466 /* Initialize bonded device with 4 slaves in round robin mode */
1467 if (initialize_bonded_device_with_slaves(BONDING_MODE_ROUND_ROBIN, 4, 1)
1471 /* Verify that all MACs are the same as first slave added to bonded dev */
1472 for (i = 0; i < test_params->bonded_slave_count; i++) {
1473 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1474 if (memcmp(&expected_mac_addr_0, &read_mac_addr,
1475 sizeof(read_mac_addr))) {
1476 printf("slave port (%d) mac address not set to that of primary port\n",
1477 test_params->slave_port_ids[i]);
1482 /* change primary and verify that MAC addresses haven't changed */
1483 retval = rte_eth_bond_primary_set(test_params->bonded_port_id,
1484 test_params->slave_port_ids[2]);
1486 printf("Failed to set bonded port (%d) primary port to (%d)\n",
1487 test_params->bonded_port_id, test_params->slave_port_ids[i]);
1491 for (i = 0; i < test_params->bonded_slave_count; i++) {
1492 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1493 if (memcmp(&expected_mac_addr_0, &read_mac_addr,
1494 sizeof(read_mac_addr))) {
1495 printf("slave port (%d) mac address has changed to that of primary port without stop/start toggle of bonded device\n",
1496 test_params->slave_port_ids[i]);
1501 /* stop / start bonded device and verify that primary MAC address is
1502 * propagate to bonded device and slaves */
1504 rte_eth_dev_stop(test_params->bonded_port_id);
1506 if (rte_eth_dev_start(test_params->bonded_port_id) != 0)
1509 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
1510 if (memcmp(&expected_mac_addr_2, &read_mac_addr, sizeof(read_mac_addr))) {
1511 printf("bonded port (%d) mac address not set to that of new primary port\n",
1512 test_params->slave_port_ids[i]);
1516 for (i = 0; i < test_params->bonded_slave_count; i++) {
1517 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1518 if (memcmp(&expected_mac_addr_2, &read_mac_addr,
1519 sizeof(read_mac_addr))) {
1520 printf("slave port (%d) mac address not set to that of new primary port\n",
1521 test_params->slave_port_ids[i]);
1526 /* Set explicit MAC address */
1527 if (rte_eth_bond_mac_address_set(test_params->bonded_port_id,
1528 (struct ether_addr *)bonded_mac) != 0) {
1532 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
1533 if (memcmp(bonded_mac, &read_mac_addr, sizeof(read_mac_addr))) {
1534 printf("bonded port (%d) mac address not set to that of new primary port\n",
1535 test_params->slave_port_ids[i]);
1539 for (i = 0; i < test_params->bonded_slave_count; i++) {
1540 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1541 if (memcmp(bonded_mac, &read_mac_addr, sizeof(read_mac_addr))) {
1542 printf("slave port (%d) mac address not set to that of new primary port\n",
1543 test_params->slave_port_ids[i]);
1548 /* Clean up and remove slaves from bonded device */
1549 return remove_slaves_and_stop_bonded_device();
1553 test_roundrobin_verify_promiscuous_enable_disable(void)
1555 int i, promiscuous_en;
1557 /* Initialize bonded device with 4 slaves in round robin mode */
1558 if (initialize_bonded_device_with_slaves(BONDING_MODE_ROUND_ROBIN, 4, 1) !=
1562 rte_eth_promiscuous_enable(test_params->bonded_port_id);
1564 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
1565 if (promiscuous_en != 1) {
1566 printf("Port (%d) promiscuous mode not enabled\n",
1567 test_params->bonded_port_id);
1571 for (i = 0; i < test_params->bonded_slave_count; i++) {
1572 promiscuous_en = rte_eth_promiscuous_get(test_params->slave_port_ids[i]);
1573 if (promiscuous_en != 1) {
1574 printf("slave port (%d) promiscuous mode not enabled\n",
1575 test_params->slave_port_ids[i]);
1580 rte_eth_promiscuous_disable(test_params->bonded_port_id);
1582 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
1583 if (promiscuous_en != 0) {
1584 printf("Port (%d) promiscuous mode not disabled\n",
1585 test_params->bonded_port_id);
1589 for (i = 0; i < test_params->bonded_slave_count; i++) {
1590 promiscuous_en = rte_eth_promiscuous_get(test_params->slave_port_ids[i]);
1591 if (promiscuous_en != 0) {
1592 printf("slave port (%d) promiscuous mode not disabled\n",
1593 test_params->slave_port_ids[i]);
1598 /* Clean up and remove slaves from bonded device */
1599 return remove_slaves_and_stop_bonded_device();
1602 #define TEST_RR_LINK_STATUS_SLAVE_COUNT (4)
1603 #define TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT (2)
1606 test_roundrobin_verify_slave_link_status_change_behaviour(void)
1608 struct rte_mbuf *tx_pkt_burst[MAX_PKT_BURST] = { NULL };
1609 struct rte_mbuf *gen_pkt_burst[TEST_RR_LINK_STATUS_SLAVE_COUNT][MAX_PKT_BURST];
1610 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1612 struct rte_eth_stats port_stats;
1613 uint8_t slaves[RTE_MAX_ETHPORTS];
1615 int i, burst_size, slave_count;
1617 /* NULL all pointers in array to simplify cleanup */
1618 memset(gen_pkt_burst, 0, sizeof(gen_pkt_burst));
1620 /* Initialize bonded device with TEST_RR_LINK_STATUS_SLAVE_COUNT slaves
1621 * in round robin mode */
1622 if (initialize_bonded_device_with_slaves(BONDING_MODE_ROUND_ROBIN,
1623 TEST_RR_LINK_STATUS_SLAVE_COUNT, 1) != 0)
1626 /* Verify Current Slaves Count /Active Slave Count is */
1627 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
1629 if (slave_count != TEST_RR_LINK_STATUS_SLAVE_COUNT) {
1630 printf("Number of slaves (%d) is not as expected (%d).\n", slave_count,
1631 TEST_RR_LINK_STATUS_SLAVE_COUNT);
1635 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1636 slaves, RTE_MAX_ETHPORTS);
1637 if (slave_count != TEST_RR_LINK_STATUS_SLAVE_COUNT) {
1638 printf("Number of active slaves (%d) is not as expected (%d).\n",
1639 slave_count, TEST_RR_LINK_STATUS_SLAVE_COUNT);
1643 /* Set 2 slaves eth_devs link status to down */
1644 virtual_ethdev_simulate_link_status_interrupt(
1645 test_params->slave_port_ids[1], 0);
1646 virtual_ethdev_simulate_link_status_interrupt(
1647 test_params->slave_port_ids[3], 0);
1649 if (rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1650 slaves, RTE_MAX_ETHPORTS) !=
1651 TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT) {
1652 printf("Number of active slaves (%d) is not as expected (%d).\n",
1653 slave_count, TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT);
1659 /* Verify that pkts are not sent on slaves with link status down:
1661 * 1. Generate test burst of traffic
1662 * 2. Transmit burst on bonded eth_dev
1663 * 3. Verify stats for bonded eth_dev (opackets = burst_size)
1664 * 4. Verify stats for slave eth_devs (s0 = 10, s1 = 0, s2 = 10, s3 = 0)
1666 if (generate_test_burst(tx_pkt_burst, burst_size, 0, 1, 0, 0, 0) !=
1668 printf("generate_test_burst failed\n");
1672 rte_eth_stats_reset(test_params->bonded_port_id);
1674 if (rte_eth_tx_burst(test_params->bonded_port_id, 0, tx_pkt_burst,
1675 burst_size) != burst_size) {
1676 printf("rte_eth_tx_burst failed\n");
1680 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1681 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
1682 "Port (%d) opackets stats (%d) not expected (%d) value",
1683 test_params->bonded_port_id, (int)port_stats.opackets,
1686 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
1687 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)10,
1688 "Port (%d) opackets stats (%d) not expected (%d) value",
1689 test_params->slave_port_ids[0], (int)port_stats.opackets, 10);
1691 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
1692 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)0,
1693 "Port (%d) opackets stats (%d) not expected (%d) value",
1694 test_params->slave_port_ids[1], (int)port_stats.opackets, 0);
1696 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
1697 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)10,
1698 "Port (%d) opackets stats (%d) not expected (%d) value",
1699 test_params->slave_port_ids[2], (int)port_stats.opackets, 10);
1701 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
1702 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)0,
1703 "Port (%d) opackets stats (%d) not expected (%d) value",
1704 test_params->slave_port_ids[3], (int)port_stats.opackets, 0);
1706 /* Verify that pkts are not sent on slaves with link status down:
1708 * 1. Generate test bursts of traffic
1709 * 2. Add bursts on to virtual eth_devs
1710 * 3. Rx burst on bonded eth_dev, expected (burst_ size *
1711 * TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT) received
1712 * 4. Verify stats for bonded eth_dev
1713 * 6. Verify stats for slave eth_devs (s0 = 10, s1 = 0, s2 = 10, s3 = 0)
1715 for (i = 0; i < TEST_RR_LINK_STATUS_SLAVE_COUNT; i++) {
1716 if (generate_test_burst(&gen_pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0)
1720 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1721 &gen_pkt_burst[i][0], burst_size);
1724 if (rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
1725 MAX_PKT_BURST) != burst_size + burst_size) {
1726 printf("rte_eth_rx_burst\n");
1730 /* Verify bonded device rx count */
1731 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1732 if (port_stats.ipackets != (uint64_t)(burst_size + burst_size)) {
1733 printf("(%d) port_stats.ipackets not as expected\n",
1734 test_params->bonded_port_id);
1739 for (i = 0; i < MAX_PKT_BURST; i++) {
1740 if (rx_pkt_burst[i] != NULL)
1741 rte_pktmbuf_free(rx_pkt_burst[i]);
1743 if (gen_pkt_burst[1][i] != NULL)
1744 rte_pktmbuf_free(gen_pkt_burst[1][i]);
1746 if (gen_pkt_burst[3][i] != NULL)
1747 rte_pktmbuf_free(gen_pkt_burst[1][i]);
1750 /* Clean up and remove slaves from bonded device */
1751 return remove_slaves_and_stop_bonded_device();
1754 /** Active Backup Mode Tests */
1757 test_activebackup_tx_burst(void)
1759 int i, retval, pktlen, primary_port, burst_size, generated_burst_size, nb_tx;
1760 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1761 struct rte_eth_stats port_stats;
1763 retval = initialize_bonded_device_with_slaves(BONDING_MODE_ACTIVE_BACKUP, 2, 1);
1765 printf("Failed to initialize_bonded_device_with_slaves.\n");
1769 initialize_eth_header(test_params->pkt_eth_hdr,
1770 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_0, 0, 0);
1771 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
1773 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
1774 dst_addr_0, pktlen);
1776 burst_size = 20 * test_params->bonded_slave_count;
1778 if (burst_size > MAX_PKT_BURST) {
1779 printf("Burst size specified is greater than supported.\n");
1783 /* Generate a burst of packets to transmit */
1784 generated_burst_size = generate_packet_burst(test_params->mbuf_pool,
1785 pkts_burst, test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr,
1786 1, test_params->pkt_udp_hdr, burst_size);
1787 if (generated_burst_size != burst_size)
1790 /* Send burst on bonded port */
1791 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst,
1793 if (nb_tx != burst_size)
1796 /* Verify bonded port tx stats */
1797 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1798 if (port_stats.opackets != (uint64_t)burst_size) {
1799 printf("Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
1800 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
1805 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
1807 /* Verify slave ports tx stats */
1808 for (i = 0; i < test_params->bonded_slave_count; i++) {
1809 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
1810 if (test_params->slave_port_ids[i] == primary_port) {
1811 if (port_stats.opackets != (uint64_t)burst_size) {
1812 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
1813 test_params->bonded_port_id,
1814 (unsigned int)port_stats.opackets,
1815 burst_size / test_params->bonded_slave_count);
1819 if (port_stats.opackets != 0) {
1820 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
1821 test_params->bonded_port_id,
1822 (unsigned int)port_stats.opackets, 0);
1828 /* Put all slaves down and try and transmit */
1829 for (i = 0; i < test_params->bonded_slave_count; i++) {
1831 virtual_ethdev_simulate_link_status_interrupt(
1832 test_params->slave_port_ids[i], 0);
1835 /* Send burst on bonded port */
1836 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst,
1841 /* Clean up and remove slaves from bonded device */
1842 return remove_slaves_and_stop_bonded_device();
1845 #define TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT (4)
1848 test_activebackup_rx_burst(void)
1850 struct rte_mbuf *gen_pkt_burst[MAX_PKT_BURST] = { NULL };
1851 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1853 struct rte_eth_stats port_stats;
1857 int i, j, nb_rx, burst_size = 17;
1859 /* Initialize bonded device with 4 slaves in round robin mode */
1860 if (initialize_bonded_device_with_slaves(BONDING_MODE_ACTIVE_BACKUP,
1861 TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT, 1)
1866 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
1867 if (primary_port < 0) {
1868 printf("failed to get primary slave for bonded port (%d)",
1869 test_params->bonded_port_id);
1872 for (i = 0; i < test_params->bonded_slave_count; i++) {
1873 /* Generate test bursts of packets to transmit */
1874 if (generate_test_burst(&gen_pkt_burst[0], burst_size, 0, 1, 0, 0, 0)
1879 /* Add rx data to slave */
1880 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1881 &gen_pkt_burst[0], burst_size);
1883 /* Call rx burst on bonded device */
1884 nb_rx = rte_eth_rx_burst(test_params->bonded_port_id, 0,
1885 &rx_pkt_burst[0], MAX_PKT_BURST);
1887 printf("rte_eth_rx_burst failed\n");
1891 if (test_params->slave_port_ids[i] == primary_port) {
1892 /* Verify bonded device rx count */
1893 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1894 if (port_stats.ipackets != (uint64_t)burst_size) {
1895 printf("Bonded Port (%d) ipackets value (%u) not as expected (%d)\n",
1896 test_params->bonded_port_id,
1897 (unsigned int)port_stats.ipackets, burst_size);
1901 /* Verify bonded slave devices rx count */
1902 for (j = 0; j < test_params->bonded_slave_count; j++) {
1903 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
1905 if (port_stats.ipackets != (uint64_t)burst_size) {
1906 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
1907 test_params->slave_port_ids[i],
1908 (unsigned int)port_stats.ipackets, burst_size);
1912 if (port_stats.ipackets != 0) {
1913 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
1914 test_params->slave_port_ids[i],
1915 (unsigned int)port_stats.ipackets, 0);
1921 for (j = 0; j < test_params->bonded_slave_count; j++) {
1922 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
1923 if (port_stats.ipackets != 0) {
1924 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
1925 test_params->slave_port_ids[i],
1926 (unsigned int)port_stats.ipackets, 0);
1933 for (i = 0; i < MAX_PKT_BURST; i++) {
1934 if (rx_pkt_burst[i] != NULL) {
1935 rte_pktmbuf_free(rx_pkt_burst[i]);
1936 rx_pkt_burst[i] = NULL;
1940 /* reset bonded device stats */
1941 rte_eth_stats_reset(test_params->bonded_port_id);
1944 /* Clean up and remove slaves from bonded device */
1945 return remove_slaves_and_stop_bonded_device();
1949 test_activebackup_verify_promiscuous_enable_disable(void)
1951 int i, primary_port, promiscuous_en;
1953 /* Initialize bonded device with 4 slaves in round robin mode */
1954 if (initialize_bonded_device_with_slaves(BONDING_MODE_ACTIVE_BACKUP, 4, 1)
1958 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
1959 if (primary_port < 0) {
1960 printf("failed to get primary slave for bonded port (%d)",
1961 test_params->bonded_port_id);
1964 rte_eth_promiscuous_enable(test_params->bonded_port_id);
1966 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
1967 if (promiscuous_en != 1) {
1968 printf("Port (%d) promiscuous mode not enabled\n",
1969 test_params->bonded_port_id);
1973 for (i = 0; i < test_params->bonded_slave_count; i++) {
1974 promiscuous_en = rte_eth_promiscuous_get(
1975 test_params->slave_port_ids[i]);
1976 if (primary_port == test_params->slave_port_ids[i]) {
1977 if (promiscuous_en != 1) {
1978 printf("slave port (%d) promiscuous mode not enabled\n",
1979 test_params->slave_port_ids[i]);
1983 if (promiscuous_en != 0) {
1984 printf("slave port (%d) promiscuous mode enabled\n",
1985 test_params->slave_port_ids[i]);
1992 rte_eth_promiscuous_disable(test_params->bonded_port_id);
1994 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
1995 if (promiscuous_en != 0) {
1996 printf("Port (%d) promiscuous mode not disabled\n",
1997 test_params->bonded_port_id);
2001 for (i = 0; i < test_params->bonded_slave_count; i++) {
2002 promiscuous_en = rte_eth_promiscuous_get(
2003 test_params->slave_port_ids[i]);
2004 if (promiscuous_en != 0) {
2005 printf("slave port (%d) promiscuous mode not disabled\n",
2006 test_params->slave_port_ids[i]);
2011 /* Clean up and remove slaves from bonded device */
2012 return remove_slaves_and_stop_bonded_device();
2016 test_activebackup_verify_mac_assignment(void)
2018 struct ether_addr read_mac_addr, expected_mac_addr_0, expected_mac_addr_1;
2020 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
2021 rte_eth_macaddr_get(test_params->slave_port_ids[1], &expected_mac_addr_1);
2023 /* Initialize bonded device with 2 slaves in active backup mode */
2024 if (initialize_bonded_device_with_slaves(BONDING_MODE_ACTIVE_BACKUP, 2, 1)
2028 /* Verify that bonded MACs is that of first slave and that the other slave
2029 * MAC hasn't been changed */
2030 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2031 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2032 printf("bonded port (%d) mac address not set to that of primary port\n",
2033 test_params->bonded_port_id);
2037 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2038 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2039 printf("slave port (%d) mac address not set to that of primary port\n",
2040 test_params->slave_port_ids[0]);
2044 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2045 if (memcmp(&expected_mac_addr_1, &read_mac_addr, sizeof(read_mac_addr))) {
2046 printf("slave port (%d) mac address not as expected\n",
2047 test_params->slave_port_ids[1]);
2051 /* change primary and verify that MAC addresses haven't changed */
2052 if (rte_eth_bond_primary_set(test_params->bonded_port_id,
2053 test_params->slave_port_ids[1]) != 0) {
2054 printf("Failed to set bonded port (%d) primary port to (%d)\n",
2055 test_params->bonded_port_id, test_params->slave_port_ids[1]);
2059 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2060 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2061 printf("bonded port (%d) mac address not set to that of primary port\n",
2062 test_params->bonded_port_id);
2066 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2067 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2068 printf("slave port (%d) mac address not set to that of primary port\n",
2069 test_params->slave_port_ids[0]);
2073 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2074 if (memcmp(&expected_mac_addr_1, &read_mac_addr, sizeof(read_mac_addr))) {
2075 printf("slave port (%d) mac address not as expected\n",
2076 test_params->slave_port_ids[1]);
2080 /* stop / start bonded device and verify that primary MAC address is
2081 * propagated to bonded device and slaves */
2083 rte_eth_dev_stop(test_params->bonded_port_id);
2085 if (rte_eth_dev_start(test_params->bonded_port_id) != 0)
2088 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2089 if (memcmp(&expected_mac_addr_1, &read_mac_addr, sizeof(read_mac_addr))) {
2090 printf("bonded port (%d) mac address not set to that of primary port\n",
2091 test_params->bonded_port_id);
2095 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2096 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2097 printf("slave port (%d) mac address not as expected\n",
2098 test_params->slave_port_ids[0]);
2102 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2103 if (memcmp(&expected_mac_addr_1, &read_mac_addr, sizeof(read_mac_addr))) {
2104 printf("slave port (%d) mac address not set to that of primary port\n",
2105 test_params->slave_port_ids[1]);
2109 /* Set explicit MAC address */
2110 if (rte_eth_bond_mac_address_set(test_params->bonded_port_id,
2111 (struct ether_addr *)bonded_mac) != 0) {
2115 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2116 if (memcmp(&bonded_mac, &read_mac_addr, sizeof(read_mac_addr))) {
2117 printf("bonded port (%d) mac address not set to that of bonded port\n",
2118 test_params->bonded_port_id);
2122 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2123 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2124 printf("slave port (%d) mac address not as expected\n",
2125 test_params->slave_port_ids[0]);
2129 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2130 if (memcmp(&bonded_mac, &read_mac_addr, sizeof(read_mac_addr))) {
2131 printf("slave port (%d) mac address not set to that of bonded port\n",
2132 test_params->slave_port_ids[1]);
2136 /* Clean up and remove slaves from bonded device */
2137 return remove_slaves_and_stop_bonded_device();
2141 test_activebackup_verify_slave_link_status_change_failover(void)
2143 struct rte_mbuf *pkt_burst[TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
2144 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
2145 struct rte_eth_stats port_stats;
2147 uint8_t slaves[RTE_MAX_ETHPORTS];
2149 int i, j, burst_size, slave_count, primary_port;
2153 memset(pkt_burst, 0, sizeof(pkt_burst));
2155 /* Generate packet burst for testing */
2156 if (generate_test_burst(&pkt_burst[0][0], burst_size, 0, 1, 0, 0, 0) !=
2158 printf("generate_test_burst failed\n");
2162 /* Initialize bonded device with 4 slaves in round robin mode */
2163 if (initialize_bonded_device_with_slaves(BONDING_MODE_ACTIVE_BACKUP,
2164 TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT, 1)
2168 /* Verify Current Slaves Count /Active Slave Count is */
2169 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
2171 if (slave_count != 4) {
2172 printf("Number of slaves (%d) is not as expected (%d).\n",
2177 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
2178 slaves, RTE_MAX_ETHPORTS);
2179 if (slave_count != 4) {
2180 printf("Number of active slaves (%d) is not as expected (%d).\n",
2185 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2186 if (primary_port != test_params->slave_port_ids[0])
2187 printf("Primary port not as expected");
2189 /* Bring 2 slaves down and verify active slave count */
2190 virtual_ethdev_simulate_link_status_interrupt(
2191 test_params->slave_port_ids[1], 0);
2192 virtual_ethdev_simulate_link_status_interrupt(
2193 test_params->slave_port_ids[3], 0);
2195 if (rte_eth_bond_active_slaves_get(test_params->bonded_port_id, slaves,
2196 RTE_MAX_ETHPORTS) != 2) {
2197 printf("Number of active slaves (%d) is not as expected (%d).\n",
2202 virtual_ethdev_simulate_link_status_interrupt(
2203 test_params->slave_port_ids[1], 1);
2204 virtual_ethdev_simulate_link_status_interrupt(
2205 test_params->slave_port_ids[3], 1);
2208 /* Bring primary port down, verify that active slave count is 3 and primary
2210 virtual_ethdev_simulate_link_status_interrupt(
2211 test_params->slave_port_ids[0], 0);
2213 if (rte_eth_bond_active_slaves_get(test_params->bonded_port_id, slaves,
2214 RTE_MAX_ETHPORTS) != 3) {
2215 printf("Number of active slaves (%d) is not as expected (%d).\n",
2220 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2221 if (primary_port != test_params->slave_port_ids[2])
2222 printf("Primary port not as expected");
2224 /* Verify that pkts are sent on new primary slave */
2226 if (rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt_burst[0][0], burst_size)
2228 printf("rte_eth_tx_burst failed\n");
2232 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
2233 if (port_stats.opackets != (uint64_t)burst_size) {
2234 printf("(%d) port_stats.opackets not as expected\n",
2235 test_params->slave_port_ids[2]);
2239 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2240 if (port_stats.opackets != 0) {
2241 printf("(%d) port_stats.opackets not as expected\n",
2242 test_params->slave_port_ids[0]);
2245 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2246 if (port_stats.opackets != 0) {
2247 printf("(%d) port_stats.opackets not as expected\n",
2248 test_params->slave_port_ids[1]);
2251 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
2252 if (port_stats.opackets != 0) {
2253 printf("(%d) port_stats.opackets not as expected\n",
2254 test_params->slave_port_ids[3]);
2258 /* Generate packet burst for testing */
2260 for (i = 0; i < TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT; i++) {
2261 if (generate_test_burst(&pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0) !=
2265 virtual_ethdev_add_mbufs_to_rx_queue(
2266 test_params->slave_port_ids[i], &pkt_burst[i][0], burst_size);
2269 if (rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
2270 MAX_PKT_BURST) != burst_size) {
2271 printf("rte_eth_rx_burst\n");
2275 /* Verify bonded device rx count */
2276 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2277 if (port_stats.ipackets != (uint64_t)burst_size) {
2278 printf("(%d) port_stats.ipackets not as expected\n",
2279 test_params->bonded_port_id);
2283 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
2284 if (port_stats.opackets != (uint64_t)burst_size) {
2285 printf("(%d) port_stats.opackets not as expected\n",
2286 test_params->slave_port_ids[2]);
2290 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2291 if (port_stats.opackets != 0) {
2292 printf("(%d) port_stats.opackets not as expected\n",
2293 test_params->slave_port_ids[0]);
2297 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2298 if (port_stats.opackets != 0) {
2299 printf("(%d) port_stats.opackets not as expected\n",
2300 test_params->slave_port_ids[1]);
2304 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
2305 if (port_stats.opackets != 0) {
2306 printf("(%d) port_stats.opackets not as expected\n",
2307 test_params->slave_port_ids[3]);
2313 for (i = 0; i < TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT; i++) {
2314 for (j = 0; j < MAX_PKT_BURST; j++) {
2315 if (pkt_burst[i][j] != NULL) {
2316 rte_pktmbuf_free(pkt_burst[i][j]);
2317 pkt_burst[i][j] = NULL;
2323 /* Clean up and remove slaves from bonded device */
2324 return remove_slaves_and_stop_bonded_device();
2327 /** Balance Mode Tests */
2330 test_balance_xmit_policy_configuration(void)
2334 retval = initialize_bonded_device_with_slaves(BONDING_MODE_ACTIVE_BACKUP,
2337 printf("Failed to initialize_bonded_device_with_slaves.\n");
2341 /* Invalid port id */
2342 retval = rte_eth_bond_xmit_policy_set(INVALID_PORT_ID,
2343 BALANCE_XMIT_POLICY_LAYER2);
2345 printf("Expected call to failed as invalid port specified.\n");
2349 /* Set xmit policy on non bonded device */
2350 retval = rte_eth_bond_xmit_policy_set(test_params->slave_port_ids[0],
2351 BALANCE_XMIT_POLICY_LAYER2);
2353 printf("Expected call to failed as invalid port specified.\n");
2357 retval = rte_eth_bond_xmit_policy_set(test_params->bonded_port_id,
2358 BALANCE_XMIT_POLICY_LAYER2);
2360 printf("Failed to set balance xmit policy.\n");
2363 if (rte_eth_bond_xmit_policy_get(test_params->bonded_port_id) !=
2364 BALANCE_XMIT_POLICY_LAYER2) {
2365 printf("balance xmit policy not as expected.\n");
2369 retval = rte_eth_bond_xmit_policy_set(test_params->bonded_port_id,
2370 BALANCE_XMIT_POLICY_LAYER23);
2372 printf("Failed to set balance xmit policy.\n");
2375 if (rte_eth_bond_xmit_policy_get(test_params->bonded_port_id) !=
2376 BALANCE_XMIT_POLICY_LAYER23) {
2377 printf("balance xmit policy not as expected.\n");
2381 retval = rte_eth_bond_xmit_policy_set(test_params->bonded_port_id,
2382 BALANCE_XMIT_POLICY_LAYER34);
2384 printf("Failed to set balance xmit policy.\n");
2387 if (rte_eth_bond_xmit_policy_get(test_params->bonded_port_id) !=
2388 BALANCE_XMIT_POLICY_LAYER34) {
2389 printf("balance xmit policy not as expected.\n");
2393 /* Invalid port id */
2394 if (rte_eth_bond_xmit_policy_get(INVALID_PORT_ID) >= 0)
2397 /* Clean up and remove slaves from bonded device */
2398 return remove_slaves_and_stop_bonded_device();
2401 #define TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT (2)
2404 test_balance_l2_tx_burst(void)
2406 struct rte_mbuf *pkts_burst[TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
2407 int burst_size[TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT] = { 10, 15 };
2412 struct rte_eth_stats port_stats;
2414 retval = initialize_bonded_device_with_slaves(BONDING_MODE_BALANCE,
2415 TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT, 1);
2417 printf("Failed to initialize_bonded_device_with_slaves.\n");
2421 retval = rte_eth_bond_xmit_policy_set(test_params->bonded_port_id,
2422 BALANCE_XMIT_POLICY_LAYER2);
2424 printf("Failed to set balance xmit policy.\n");
2429 initialize_eth_header(test_params->pkt_eth_hdr,
2430 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_0, 0, 0);
2431 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
2433 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
2434 dst_addr_0, pktlen);
2436 /* Generate a burst 1 of packets to transmit */
2437 if (generate_packet_burst(test_params->mbuf_pool, &pkts_burst[0][0],
2438 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr, 1,
2439 test_params->pkt_udp_hdr, burst_size[0]) != burst_size[0])
2442 initialize_eth_header(test_params->pkt_eth_hdr,
2443 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_1, 0, 0);
2445 /* Generate a burst 2 of packets to transmit */
2446 if (generate_packet_burst(test_params->mbuf_pool, &pkts_burst[1][0],
2447 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr, 1,
2448 test_params->pkt_udp_hdr, burst_size[1]) != burst_size[1])
2451 /* Send burst 1 on bonded port */
2452 for (i = 0; i < TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT; i++) {
2453 if (rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkts_burst[i][0],
2454 burst_size[i]) != burst_size[i])
2457 /* Verify bonded port tx stats */
2458 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2459 if (port_stats.opackets != (uint64_t)(burst_size[0] + burst_size[1])) {
2460 printf("Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
2461 test_params->bonded_port_id,
2462 (unsigned int)port_stats.opackets, burst_size[0] + burst_size[1]);
2467 /* Verify slave ports tx stats */
2468 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2469 if (port_stats.opackets != (uint64_t)burst_size[0]) {
2470 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
2471 test_params->slave_port_ids[0],
2472 (unsigned int)port_stats.opackets, burst_size[0]);
2476 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2477 if (port_stats.opackets != (uint64_t)burst_size[1]) {
2478 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
2479 test_params->slave_port_ids[1], (
2480 unsigned int)port_stats.opackets, burst_size[1]);
2484 /* Put all slaves down and try and transmit */
2485 for (i = 0; i < test_params->bonded_slave_count; i++) {
2487 virtual_ethdev_simulate_link_status_interrupt(
2488 test_params->slave_port_ids[i], 0);
2491 /* Send burst on bonded port */
2492 if (rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkts_burst[0][0],
2493 burst_size[0]) != 0)
2496 /* Clean up and remove slaves from bonded device */
2497 return remove_slaves_and_stop_bonded_device();
2501 balance_l23_tx_burst(uint8_t vlan_enabled, uint8_t ipv4,
2502 uint8_t toggle_mac_addr, uint8_t toggle_ip_addr)
2505 int burst_size_1, burst_size_2, nb_tx_1, nb_tx_2;
2507 struct rte_mbuf *pkts_burst_1[MAX_PKT_BURST];
2508 struct rte_mbuf *pkts_burst_2[MAX_PKT_BURST];
2510 struct rte_eth_stats port_stats;
2512 retval = initialize_bonded_device_with_slaves(BONDING_MODE_BALANCE, 2, 1);
2514 printf("Failed to initialize_bonded_device_with_slaves.\n");
2518 retval = rte_eth_bond_xmit_policy_set(test_params->bonded_port_id,
2519 BALANCE_XMIT_POLICY_LAYER23);
2521 printf("Failed to set balance xmit policy.\n");
2528 if (burst_size_1 > MAX_PKT_BURST || burst_size_2 > MAX_PKT_BURST) {
2529 printf("Burst size specified is greater than supported.\n");
2533 /* Generate test bursts of packets to transmit */
2534 if (generate_test_burst(pkts_burst_1, burst_size_1, vlan_enabled, ipv4,
2535 0, 0, 0) != burst_size_1)
2538 if (generate_test_burst(pkts_burst_2, burst_size_2, vlan_enabled, ipv4,
2539 toggle_mac_addr, toggle_ip_addr, 0) != burst_size_2)
2542 /* Send burst 1 on bonded port */
2543 nb_tx_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2545 if (nb_tx_1 != burst_size_1)
2548 /* Send burst 2 on bonded port */
2549 nb_tx_2 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_2,
2551 if (nb_tx_2 != burst_size_2)
2554 /* Verify bonded port tx stats */
2555 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2556 if (port_stats.opackets != (uint64_t)(nb_tx_1 + nb_tx_2)) {
2557 printf("Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
2558 test_params->bonded_port_id,
2559 (unsigned int)port_stats.opackets, nb_tx_1 + nb_tx_2);
2563 /* Verify slave ports tx stats */
2564 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2565 if (port_stats.opackets != (uint64_t)nb_tx_1) {
2566 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
2567 test_params->slave_port_ids[0],
2568 (unsigned int)port_stats.opackets, nb_tx_1);
2572 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2573 if (port_stats.opackets != (uint64_t)nb_tx_2) {
2574 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
2575 test_params->slave_port_ids[1],
2576 (unsigned int)port_stats.opackets, nb_tx_2);
2580 /* Put all slaves down and try and transmit */
2581 for (i = 0; i < test_params->bonded_slave_count; i++) {
2583 virtual_ethdev_simulate_link_status_interrupt(
2584 test_params->slave_port_ids[i], 0);
2587 /* Send burst on bonded port */
2588 nb_tx_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2593 /* Clean up and remove slaves from bonded device */
2594 return remove_slaves_and_stop_bonded_device();
2598 test_balance_l23_tx_burst_ipv4_toggle_ip_addr(void)
2600 return balance_l23_tx_burst(0, 1, 1, 0);
2604 test_balance_l23_tx_burst_vlan_ipv4_toggle_ip_addr(void)
2606 return balance_l23_tx_burst(1, 1, 0, 1);
2610 test_balance_l23_tx_burst_ipv6_toggle_ip_addr(void)
2612 return balance_l23_tx_burst(0, 0, 0, 1);
2616 test_balance_l23_tx_burst_vlan_ipv6_toggle_ip_addr(void)
2618 return balance_l23_tx_burst(1, 0, 0, 1);
2622 test_balance_l23_tx_burst_toggle_mac_addr(void)
2624 return balance_l23_tx_burst(0, 0, 1, 0);
2628 balance_l34_tx_burst(uint8_t vlan_enabled, uint8_t ipv4,
2629 uint8_t toggle_mac_addr, uint8_t toggle_ip_addr,
2630 uint8_t toggle_udp_port)
2633 int burst_size_1, burst_size_2, nb_tx_1, nb_tx_2;
2635 struct rte_mbuf *pkts_burst_1[MAX_PKT_BURST];
2636 struct rte_mbuf *pkts_burst_2[MAX_PKT_BURST];
2638 struct rte_eth_stats port_stats;
2640 retval = initialize_bonded_device_with_slaves(BONDING_MODE_BALANCE, 2, 1);
2642 printf("Failed to initialize_bonded_device_with_slaves.\n");
2646 retval = rte_eth_bond_xmit_policy_set(test_params->bonded_port_id,
2647 BALANCE_XMIT_POLICY_LAYER34);
2649 printf("Failed to set balance xmit policy.\n");
2656 if (burst_size_1 > MAX_PKT_BURST || burst_size_2 > MAX_PKT_BURST) {
2657 printf("Burst size specified is greater than supported.\n");
2661 /* Generate test bursts of packets to transmit */
2662 if (generate_test_burst(pkts_burst_1, burst_size_1, vlan_enabled, ipv4, 0,
2663 0, 0) != burst_size_1)
2666 if (generate_test_burst(pkts_burst_2, burst_size_2, vlan_enabled, ipv4,
2667 toggle_mac_addr, toggle_ip_addr, toggle_udp_port) != burst_size_2)
2670 /* Send burst 1 on bonded port */
2671 nb_tx_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2673 if (nb_tx_1 != burst_size_1)
2676 /* Send burst 2 on bonded port */
2677 nb_tx_2 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_2,
2679 if (nb_tx_2 != burst_size_2)
2683 /* Verify bonded port tx stats */
2684 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2685 if (port_stats.opackets != (uint64_t)(nb_tx_1 + nb_tx_2)) {
2686 printf("Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
2687 test_params->bonded_port_id,
2688 (unsigned int)port_stats.opackets, nb_tx_1 + nb_tx_2);
2692 /* Verify slave ports tx stats */
2693 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2694 if (port_stats.opackets != (uint64_t)nb_tx_1) {
2695 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
2696 test_params->slave_port_ids[0],
2697 (unsigned int)port_stats.opackets, nb_tx_1);
2701 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2702 if (port_stats.opackets != (uint64_t)nb_tx_2) {
2703 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
2704 test_params->slave_port_ids[1],
2705 (unsigned int)port_stats.opackets, nb_tx_2);
2709 /* Put all slaves down and try and transmit */
2710 for (i = 0; i < test_params->bonded_slave_count; i++) {
2712 virtual_ethdev_simulate_link_status_interrupt(
2713 test_params->slave_port_ids[i], 0);
2716 /* Send burst on bonded port */
2717 nb_tx_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2722 /* Clean up and remove slaves from bonded device */
2723 return remove_slaves_and_stop_bonded_device();
2727 test_balance_l34_tx_burst_ipv4_toggle_ip_addr(void)
2729 return balance_l34_tx_burst(0, 1, 0, 1, 0);
2733 test_balance_l34_tx_burst_ipv4_toggle_udp_port(void)
2735 return balance_l34_tx_burst(0, 1, 0, 0, 1);
2739 test_balance_l34_tx_burst_vlan_ipv4_toggle_ip_addr(void)
2741 return balance_l34_tx_burst(1, 1, 0, 1, 0);
2745 test_balance_l34_tx_burst_ipv6_toggle_ip_addr(void)
2747 return balance_l34_tx_burst(0, 0, 0, 1, 0);
2751 test_balance_l34_tx_burst_vlan_ipv6_toggle_ip_addr(void)
2753 return balance_l34_tx_burst(1, 0, 0, 1, 0);
2757 test_balance_l34_tx_burst_ipv6_toggle_udp_port(void)
2759 return balance_l34_tx_burst(0, 0, 0, 0, 1);
2762 #define TEST_BALANCE_RX_BURST_SLAVE_COUNT (3)
2765 test_balance_rx_burst(void)
2767 struct rte_mbuf *gen_pkt_burst[TEST_BALANCE_RX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
2769 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
2770 struct rte_eth_stats port_stats;
2772 int burst_size[TEST_BALANCE_RX_BURST_SLAVE_COUNT] = { 10, 5, 30 };
2775 memset(gen_pkt_burst, 0, sizeof(gen_pkt_burst));
2777 /* Initialize bonded device with 4 slaves in round robin mode */
2778 if (initialize_bonded_device_with_slaves(BONDING_MODE_BALANCE, 3, 1)
2782 /* Generate test bursts of packets to transmit */
2783 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
2784 if (generate_test_burst(&gen_pkt_burst[i][0], burst_size[i], 0, 0, 1,
2785 0, 0) != burst_size[i])
2788 /* Add rx data to slaves */
2789 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
2790 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
2791 &gen_pkt_burst[i][0], burst_size[i]);
2794 /* Call rx burst on bonded device */
2795 /* Send burst on bonded port */
2796 nb_rx = rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
2798 if (nb_rx != burst_size[0] + burst_size[1] + burst_size[2]) {
2799 printf("balance rx burst failed\n");
2803 /* Verify bonded device rx count */
2804 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2805 if (port_stats.ipackets != (uint64_t)(burst_size[0] + burst_size[1] +
2807 printf("Bonded Port (%d) ipackets value (%u) not as expected (%d)\n",
2808 test_params->bonded_port_id, (unsigned int)port_stats.ipackets,
2809 burst_size[0] + burst_size[1] + burst_size[2]);
2814 /* Verify bonded slave devices rx counts */
2815 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2816 if (port_stats.ipackets != (uint64_t)burst_size[0]) {
2817 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
2818 test_params->slave_port_ids[0],
2819 (unsigned int)port_stats.ipackets, burst_size[0]);
2823 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2824 if (port_stats.ipackets != (uint64_t)burst_size[1]) {
2825 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
2826 test_params->slave_port_ids[1],
2827 (unsigned int)port_stats.ipackets, burst_size[1]);
2831 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
2832 if (port_stats.ipackets != (uint64_t)burst_size[2]) {
2833 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
2834 test_params->slave_port_ids[2],
2835 (unsigned int)port_stats.ipackets, burst_size[2]);
2839 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
2840 if (port_stats.ipackets != 0) {
2841 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
2842 test_params->slave_port_ids[3],
2843 (unsigned int)port_stats.ipackets, 0);
2848 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
2849 for (j = 0; j < MAX_PKT_BURST; j++) {
2850 if (gen_pkt_burst[i][j] != NULL) {
2851 rte_pktmbuf_free(gen_pkt_burst[i][j]);
2852 gen_pkt_burst[i][j] = NULL;
2857 /* Clean up and remove slaves from bonded device */
2858 return remove_slaves_and_stop_bonded_device();
2862 test_balance_verify_promiscuous_enable_disable(void)
2864 int i, promiscuous_en;
2866 /* Initialize bonded device with 4 slaves in round robin mode */
2867 if (initialize_bonded_device_with_slaves(BONDING_MODE_BALANCE, 4, 1) != 0)
2870 rte_eth_promiscuous_enable(test_params->bonded_port_id);
2872 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
2873 if (promiscuous_en != 1) {
2874 printf("Port (%d) promiscuous mode not enabled\n",
2875 test_params->bonded_port_id);
2879 for (i = 0; i < test_params->bonded_slave_count; i++) {
2880 promiscuous_en = rte_eth_promiscuous_get(
2881 test_params->slave_port_ids[i]);
2882 if (promiscuous_en != 1) {
2883 printf("slave port (%d) promiscuous mode not enabled\n",
2884 test_params->slave_port_ids[i]);
2889 rte_eth_promiscuous_disable(test_params->bonded_port_id);
2891 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
2892 if (promiscuous_en != 0) {
2893 printf("Port (%d) promiscuous mode not disabled\n",
2894 test_params->bonded_port_id);
2898 for (i = 0; i < test_params->bonded_slave_count; i++) {
2899 promiscuous_en = rte_eth_promiscuous_get(
2900 test_params->slave_port_ids[i]);
2901 if (promiscuous_en != 0) {
2902 printf("slave port (%d) promiscuous mode not disabled\n",
2903 test_params->slave_port_ids[i]);
2908 /* Clean up and remove slaves from bonded device */
2909 return remove_slaves_and_stop_bonded_device();
2913 test_balance_verify_mac_assignment(void)
2915 struct ether_addr read_mac_addr, expected_mac_addr_0, expected_mac_addr_1;
2917 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
2918 rte_eth_macaddr_get(test_params->slave_port_ids[1], &expected_mac_addr_1);
2920 /* Initialize bonded device with 2 slaves in active backup mode */
2921 if (initialize_bonded_device_with_slaves(BONDING_MODE_BALANCE, 2, 1) != 0)
2924 /* Verify that bonded MACs is that of first slave and that the other slave
2925 * MAC hasn't been changed */
2926 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2927 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2928 printf("bonded port (%d) mac address not set to that of primary port\n",
2929 test_params->bonded_port_id);
2933 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2934 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2935 printf("slave port (%d) mac address not set to that of primary port\n",
2936 test_params->slave_port_ids[0]);
2940 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2941 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2942 printf("slave port (%d) mac address not set to that of primary port\n",
2943 test_params->slave_port_ids[1]);
2947 /* change primary and verify that MAC addresses haven't changed */
2948 if (rte_eth_bond_primary_set(test_params->bonded_port_id,
2949 test_params->slave_port_ids[1]) != 0) {
2950 printf("Failed to set bonded port (%d) primary port to (%d)\n",
2951 test_params->bonded_port_id, test_params->slave_port_ids[1]);
2955 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2956 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2957 printf("bonded port (%d) mac address not set to that of primary port\n",
2958 test_params->bonded_port_id);
2962 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2963 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2964 printf("slave port (%d) mac address not set to that of primary port\n",
2965 test_params->slave_port_ids[0]);
2969 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2970 if (memcmp(&expected_mac_addr_0, &read_mac_addr, sizeof(read_mac_addr))) {
2971 printf("slave port (%d) mac address not set to that of primary port\n",
2972 test_params->slave_port_ids[1]);
2976 /* stop / start bonded device and verify that primary MAC address is
2977 * propagated to bonded device and slaves */
2979 rte_eth_dev_stop(test_params->bonded_port_id);
2981 if (rte_eth_dev_start(test_params->bonded_port_id) != 0)
2984 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2985 if (memcmp(&expected_mac_addr_1, &read_mac_addr, sizeof(read_mac_addr))) {
2986 printf("bonded port (%d) mac address not set to that of primary port\n",
2987 test_params->bonded_port_id);
2991 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2992 if (memcmp(&expected_mac_addr_1, &read_mac_addr, sizeof(read_mac_addr))) {
2993 printf("slave port (%d) mac address not set to that of primary port\n",
2994 test_params->slave_port_ids[0]);
2998 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2999 if (memcmp(&expected_mac_addr_1, &read_mac_addr, sizeof(read_mac_addr))) {
3000 printf("slave port (%d) mac address not set to that of primary port\n",
3001 test_params->slave_port_ids[1]);
3005 /* Set explicit MAC address */
3006 if (rte_eth_bond_mac_address_set(test_params->bonded_port_id,
3007 (struct ether_addr *)bonded_mac) != 0)
3010 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3011 if (memcmp(&bonded_mac, &read_mac_addr, sizeof(read_mac_addr))) {
3012 printf("bonded port (%d) mac address not set to that of bonded port\n",
3013 test_params->bonded_port_id);
3017 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
3018 if (memcmp(&bonded_mac, &read_mac_addr, sizeof(read_mac_addr))) {
3019 printf("slave port (%d) mac address not as expected\n",
3020 test_params->slave_port_ids[0]);
3024 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
3025 if (memcmp(&bonded_mac, &read_mac_addr, sizeof(read_mac_addr))) {
3026 printf("slave port (%d) mac address not set to that of bonded port\n",
3027 test_params->slave_port_ids[1]);
3031 /* Clean up and remove slaves from bonded device */
3032 return remove_slaves_and_stop_bonded_device();
3035 #define TEST_BALANCE_LINK_STATUS_SLAVE_COUNT (4)
3038 test_balance_verify_slave_link_status_change_behaviour(void)
3040 struct rte_mbuf *pkt_burst[TEST_BALANCE_LINK_STATUS_SLAVE_COUNT][MAX_PKT_BURST];
3041 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3042 struct rte_eth_stats port_stats;
3044 uint8_t slaves[RTE_MAX_ETHPORTS];
3046 int i, j, burst_size, slave_count;
3048 memset(pkt_burst, 0, sizeof(pkt_burst));
3050 /* Initialize bonded device with 4 slaves in round robin mode */
3051 if (initialize_bonded_device_with_slaves(BONDING_MODE_BALANCE,
3052 TEST_BALANCE_LINK_STATUS_SLAVE_COUNT, 1) != 0)
3055 if (rte_eth_bond_xmit_policy_set(test_params->bonded_port_id,
3056 BALANCE_XMIT_POLICY_LAYER2)) {
3057 printf("Failed to set balance xmit policy.\n");
3061 /* Verify Current Slaves Count /Active Slave Count is */
3062 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
3064 if (slave_count != TEST_BALANCE_LINK_STATUS_SLAVE_COUNT) {
3065 printf("Number of slaves (%d) is not as expected (%d).\n", slave_count,
3066 TEST_BALANCE_LINK_STATUS_SLAVE_COUNT);
3070 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
3071 slaves, RTE_MAX_ETHPORTS);
3072 if (slave_count != TEST_BALANCE_LINK_STATUS_SLAVE_COUNT) {
3073 printf("Number of active slaves (%d) is not as expected (%d).\n",
3074 slave_count, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT);
3078 /* Set 2 slaves link status to down */
3079 virtual_ethdev_simulate_link_status_interrupt(
3080 test_params->slave_port_ids[1], 0);
3081 virtual_ethdev_simulate_link_status_interrupt(
3082 test_params->slave_port_ids[3], 0);
3084 if (rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
3085 slaves, RTE_MAX_ETHPORTS) != 2) {
3086 printf("Number of active slaves (%d) is not as expected (%d).\n",
3091 /* Send to sets of packet burst and verify that they are balanced across
3095 if (generate_test_burst(&pkt_burst[0][0], burst_size, 0, 1, 0, 0, 0) !=
3097 printf("generate_test_burst failed\n");
3101 if (generate_test_burst(&pkt_burst[1][0], burst_size, 0, 1, 1, 0, 0) !=
3103 printf("generate_test_burst failed\n");
3107 if (rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt_burst[0][0],
3108 burst_size) != burst_size) {
3109 printf("rte_eth_tx_burst failed\n");
3113 if (rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt_burst[1][0],
3114 burst_size) != burst_size) {
3115 printf("rte_eth_tx_burst failed\n");
3119 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3120 if (port_stats.opackets != (uint64_t)(burst_size + burst_size)) {
3121 printf("(%d) port_stats.opackets (%d) not as expected (%d).\n",
3122 test_params->bonded_port_id, (int)port_stats.opackets,
3123 burst_size + burst_size);
3127 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3128 if (port_stats.opackets != (uint64_t)burst_size) {
3129 printf("(%d) port_stats.opackets (%d) not as expected (%d).\n",
3130 test_params->slave_port_ids[0], (int)port_stats.opackets,
3135 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3136 if (port_stats.opackets != (uint64_t)burst_size) {
3137 printf("(%d) port_stats.opackets (%d) not as expected (%d).\n",
3138 test_params->slave_port_ids[2], (int)port_stats.opackets,
3143 /* verify that all packets get send on primary slave when no other slaves
3145 virtual_ethdev_simulate_link_status_interrupt(
3146 test_params->slave_port_ids[2], 0);
3148 if (rte_eth_bond_active_slaves_get(test_params->bonded_port_id, slaves,
3149 RTE_MAX_ETHPORTS) != 1) {
3150 printf("Number of active slaves (%d) is not as expected (%d).\n",
3155 if (generate_test_burst(&pkt_burst[1][0], burst_size, 0, 1, 1, 0, 0) !=
3157 printf("generate_test_burst failed\n");
3161 if (rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt_burst[1][0],
3162 burst_size) != burst_size) {
3163 printf("rte_eth_tx_burst failed\n");
3167 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3168 if (port_stats.opackets != (uint64_t)(burst_size + burst_size +
3170 printf("(%d) port_stats.opackets (%d) not as expected (%d).\n",
3171 test_params->bonded_port_id, (int)port_stats.opackets,
3172 burst_size + burst_size + burst_size);
3176 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3177 if (port_stats.opackets != (uint64_t)(burst_size + burst_size)) {
3178 printf("(%d) port_stats.opackets (%d) not as expected (%d).\n",
3179 test_params->slave_port_ids[0], (int)port_stats.opackets,
3180 burst_size + burst_size);
3185 virtual_ethdev_simulate_link_status_interrupt(
3186 test_params->slave_port_ids[0], 0);
3187 virtual_ethdev_simulate_link_status_interrupt(
3188 test_params->slave_port_ids[1], 1);
3189 virtual_ethdev_simulate_link_status_interrupt(
3190 test_params->slave_port_ids[2], 1);
3191 virtual_ethdev_simulate_link_status_interrupt(
3192 test_params->slave_port_ids[3], 1);
3194 for (i = 0; i < TEST_BALANCE_LINK_STATUS_SLAVE_COUNT; i++) {
3195 if (generate_test_burst(&pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0) !=
3199 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3200 &pkt_burst[i][0], burst_size);
3205 /* Verify that pkts are not received on slaves with link status down */
3207 rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
3210 /* Verify bonded device rx count */
3211 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3212 if (port_stats.ipackets != (uint64_t)(burst_size * 3)) {
3213 printf("(%d) port_stats.ipackets (%d) not as expected (%d)\n",
3214 test_params->bonded_port_id, (int)port_stats.ipackets,
3219 /* free mbufs allocate for rx testing */
3220 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
3221 for (j = 0; j < MAX_PKT_BURST; j++) {
3222 if (pkt_burst[i][j] != NULL) {
3223 rte_pktmbuf_free(pkt_burst[i][j]);
3224 pkt_burst[i][j] = NULL;
3229 /* Clean up and remove slaves from bonded device */
3230 return remove_slaves_and_stop_bonded_device();
3233 #ifdef RTE_MBUF_REFCNT
3234 /** Broadcast Mode Tests */
3237 test_broadcast_tx_burst(void)
3239 int i, pktlen, retval, burst_size, generated_burst_size, nb_tx;
3240 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
3242 struct rte_eth_stats port_stats;
3244 retval = initialize_bonded_device_with_slaves(BONDING_MODE_BROADCAST, 2, 1);
3246 printf("Failed to initialize_bonded_device_with_slaves.\n");
3250 initialize_eth_header(test_params->pkt_eth_hdr,
3251 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_0, 0, 0);
3253 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
3255 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
3256 dst_addr_0, pktlen);
3258 burst_size = 20 * test_params->bonded_slave_count;
3260 if (burst_size > MAX_PKT_BURST) {
3261 printf("Burst size specified is greater than supported.\n");
3265 /* Generate a burst of packets to transmit */
3266 generated_burst_size = generate_packet_burst(test_params->mbuf_pool,
3267 pkts_burst, test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr,
3268 1, test_params->pkt_udp_hdr, burst_size);
3269 if (generated_burst_size != burst_size)
3272 /* Send burst on bonded port */
3273 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst,
3275 if (nb_tx != burst_size * test_params->bonded_slave_count) {
3276 printf("Bonded Port (%d) rx burst failed, packets transmitted value (%u) not as expected (%d)\n",
3277 test_params->bonded_port_id,
3282 /* Verify bonded port tx stats */
3283 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3284 if (port_stats.opackets != (uint64_t)burst_size *
3285 test_params->bonded_slave_count) {
3286 printf("Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
3287 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3291 /* Verify slave ports tx stats */
3292 for (i = 0; i < test_params->bonded_slave_count; i++) {
3293 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
3294 if (port_stats.opackets != (uint64_t)burst_size) {
3295 printf("Slave Port (%d) opackets value (%u) not as expected (%d)\n",
3296 test_params->bonded_port_id,
3297 (unsigned int)port_stats.opackets, burst_size);
3301 /* Put all slaves down and try and transmit */
3302 for (i = 0; i < test_params->bonded_slave_count; i++) {
3304 virtual_ethdev_simulate_link_status_interrupt(
3305 test_params->slave_port_ids[i], 0);
3308 /* Send burst on bonded port */
3309 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst,
3314 /* Clean up and remove slaves from bonded device */
3315 return remove_slaves_and_stop_bonded_device();
3318 #define BROADCAST_RX_BURST_NUM_OF_SLAVES (3)
3321 test_broadcast_rx_burst(void)
3323 struct rte_mbuf *gen_pkt_burst[BROADCAST_RX_BURST_NUM_OF_SLAVES][MAX_PKT_BURST];
3325 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3326 struct rte_eth_stats port_stats;
3328 int burst_size[BROADCAST_RX_BURST_NUM_OF_SLAVES] = { 10, 5, 30 };
3331 memset(gen_pkt_burst, 0, sizeof(gen_pkt_burst));
3333 /* Initialize bonded device with 4 slaves in round robin mode */
3334 if (initialize_bonded_device_with_slaves(BONDING_MODE_BROADCAST, 3, 1) != 0)
3338 /* Generate test bursts of packets to transmit */
3339 for (i = 0; i < BROADCAST_RX_BURST_NUM_OF_SLAVES; i++) {
3340 if (generate_test_burst(&gen_pkt_burst[i][0], burst_size[i], 0, 0, 1, 0,
3341 0) != burst_size[i])
3345 /* Add rx data to slave 0 */
3346 for (i = 0; i < BROADCAST_RX_BURST_NUM_OF_SLAVES; i++) {
3347 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3348 &gen_pkt_burst[i][0], burst_size[i]);
3352 /* Call rx burst on bonded device */
3353 /* Send burst on bonded port */
3354 nb_rx = rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
3356 if (nb_rx != burst_size[0] + burst_size[1] + burst_size[2]) {
3357 printf("round-robin rx burst failed");
3361 /* Verify bonded device rx count */
3362 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3363 if (port_stats.ipackets != (uint64_t)(burst_size[0] + burst_size[1] +
3365 printf("Bonded Port (%d) ipackets value (%u) not as expected (%d)\n",
3366 test_params->bonded_port_id, (unsigned int)port_stats.ipackets,
3367 burst_size[0] + burst_size[1] + burst_size[2]);
3372 /* Verify bonded slave devices rx counts */
3373 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3374 if (port_stats.ipackets != (uint64_t)burst_size[0]) {
3375 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
3376 test_params->slave_port_ids[0],
3377 (unsigned int)port_stats.ipackets, burst_size[0]);
3381 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3382 if (port_stats.ipackets != (uint64_t)burst_size[1]) {
3383 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
3384 test_params->slave_port_ids[1],
3385 (unsigned int)port_stats.ipackets, burst_size[1]);
3389 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3390 if (port_stats.ipackets != (uint64_t)burst_size[2]) {
3391 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
3392 test_params->slave_port_ids[2],
3393 (unsigned int)port_stats.ipackets,
3398 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
3399 if (port_stats.ipackets != 0) {
3400 printf("Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
3401 test_params->slave_port_ids[3],
3402 (unsigned int)port_stats.ipackets, 0);
3406 /* free mbufs allocate for rx testing */
3407 for (i = 0; i < BROADCAST_RX_BURST_NUM_OF_SLAVES; i++) {
3408 for (j = 0; j < MAX_PKT_BURST; j++) {
3409 if (gen_pkt_burst[i][j] != NULL) {
3410 rte_pktmbuf_free(gen_pkt_burst[i][j]);
3411 gen_pkt_burst[i][j] = NULL;
3416 /* Clean up and remove slaves from bonded device */
3417 return remove_slaves_and_stop_bonded_device();
3421 test_broadcast_verify_promiscuous_enable_disable(void)
3423 int i, promiscuous_en;
3425 /* Initialize bonded device with 4 slaves in round robin mode */
3426 if (initialize_bonded_device_with_slaves(BONDING_MODE_BALANCE, 4, 1) != 0)
3429 rte_eth_promiscuous_enable(test_params->bonded_port_id);
3431 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
3432 if (promiscuous_en != 1) {
3433 printf("Port (%d) promiscuous mode not enabled\n",
3434 test_params->bonded_port_id);
3438 for (i = 0; i < test_params->bonded_slave_count; i++) {
3439 promiscuous_en = rte_eth_promiscuous_get(
3440 test_params->slave_port_ids[i]);
3441 if (promiscuous_en != 1) {
3442 printf("slave port (%d) promiscuous mode not enabled\n",
3443 test_params->slave_port_ids[i]);
3448 rte_eth_promiscuous_disable(test_params->bonded_port_id);
3450 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
3451 if (promiscuous_en != 0) {
3452 printf("Port (%d) promiscuous mode not disabled\n",
3453 test_params->bonded_port_id);
3457 for (i = 0; i < test_params->bonded_slave_count; i++) {
3458 promiscuous_en = rte_eth_promiscuous_get(
3459 test_params->slave_port_ids[i]);
3460 if (promiscuous_en != 0) {
3461 printf("slave port (%d) promiscuous mode not disabled\n",
3462 test_params->slave_port_ids[i]);
3467 /* Clean up and remove slaves from bonded device */
3468 return remove_slaves_and_stop_bonded_device();
3472 test_broadcast_verify_mac_assignment(void)
3474 struct ether_addr read_mac_addr, expected_mac_addr_0, expected_mac_addr_1;
3478 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
3479 rte_eth_macaddr_get(test_params->slave_port_ids[2], &expected_mac_addr_1);
3481 /* Initialize bonded device with 4 slaves in round robin mode */
3482 if (initialize_bonded_device_with_slaves(BONDING_MODE_BROADCAST, 4, 1) != 0)
3485 /* Verify that all MACs are the same as first slave added to bonded
3487 for (i = 0; i < test_params->bonded_slave_count; i++) {
3488 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3489 if (memcmp(&expected_mac_addr_0, &read_mac_addr,
3490 sizeof(read_mac_addr))) {
3491 printf("slave port (%d) mac address not set to that of primary port\n",
3492 test_params->slave_port_ids[i]);
3497 /* change primary and verify that MAC addresses haven't changed */
3498 retval = rte_eth_bond_primary_set(test_params->bonded_port_id,
3499 test_params->slave_port_ids[2]);
3501 printf("Failed to set bonded port (%d) primary port to (%d)\n",
3502 test_params->bonded_port_id, test_params->slave_port_ids[i]);
3506 for (i = 0; i < test_params->bonded_slave_count; i++) {
3507 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3508 if (memcmp(&expected_mac_addr_0, &read_mac_addr,
3509 sizeof(read_mac_addr))) {
3510 printf("slave port (%d) mac address has changed to that of primary"
3511 "port without stop/start toggle of bonded device\n",
3512 test_params->slave_port_ids[i]);
3517 /* stop / start bonded device and verify that primary MAC address is
3518 * propagated to bonded device and slaves */
3520 rte_eth_dev_stop(test_params->bonded_port_id);
3522 if (rte_eth_dev_start(test_params->bonded_port_id) != 0)
3525 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3526 if (memcmp(&expected_mac_addr_1, &read_mac_addr, sizeof(read_mac_addr))) {
3527 printf("bonded port (%d) mac address not set to that of new primary"
3528 " port\n", test_params->slave_port_ids[i]);
3532 for (i = 0; i < test_params->bonded_slave_count; i++) {
3533 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3534 if (memcmp(&expected_mac_addr_1, &read_mac_addr,
3535 sizeof(read_mac_addr))) {
3536 printf("slave port (%d) mac address not set to that of new primary"
3537 "port\n", test_params->slave_port_ids[i]);
3542 /* Set explicit MAC address */
3543 if (rte_eth_bond_mac_address_set(test_params->bonded_port_id,
3544 (struct ether_addr *)bonded_mac) != 0)
3547 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3548 if (memcmp(bonded_mac, &read_mac_addr, sizeof(read_mac_addr))) {
3549 printf("bonded port (%d) mac address not set to that of new primary port\n",
3550 test_params->slave_port_ids[i]);
3554 for (i = 0; i < test_params->bonded_slave_count; i++) {
3555 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3556 if (memcmp(bonded_mac, &read_mac_addr, sizeof(read_mac_addr))) {
3557 printf("slave port (%d) mac address not set to that of new primary port\n",
3558 test_params->slave_port_ids[i]);
3563 /* Clean up and remove slaves from bonded device */
3564 return remove_slaves_and_stop_bonded_device();
3567 #define BROADCAST_LINK_STATUS_NUM_OF_SLAVES (4)
3569 test_broadcast_verify_slave_link_status_change_behaviour(void)
3571 struct rte_mbuf *pkt_burst[BROADCAST_LINK_STATUS_NUM_OF_SLAVES][MAX_PKT_BURST];
3572 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3573 struct rte_eth_stats port_stats;
3575 uint8_t slaves[RTE_MAX_ETHPORTS];
3577 int i, j, burst_size, slave_count;
3579 memset(pkt_burst, 0, sizeof(pkt_burst));
3581 /* Initialize bonded device with 4 slaves in round robin mode */
3582 if (initialize_bonded_device_with_slaves(BONDING_MODE_BROADCAST,
3583 BROADCAST_LINK_STATUS_NUM_OF_SLAVES, 1) != 0)
3586 /* Verify Current Slaves Count /Active Slave Count is */
3587 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
3589 if (slave_count != 4) {
3590 printf("Number of slaves (%d) is not as expected (%d).\n",
3595 slave_count = rte_eth_bond_active_slaves_get(
3596 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
3597 if (slave_count != 4) {
3598 printf("Number of active slaves (%d) is not as expected (%d).\n",
3603 /* Set 2 slaves link status to down */
3604 virtual_ethdev_simulate_link_status_interrupt(
3605 test_params->slave_port_ids[1], 0);
3606 virtual_ethdev_simulate_link_status_interrupt(
3607 test_params->slave_port_ids[3], 0);
3609 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
3610 slaves, RTE_MAX_ETHPORTS);
3611 if (slave_count != 2) {
3612 printf("Number of active slaves (%d) is not as expected (%d).\n",
3617 for (i = 0; i < test_params->bonded_slave_count; i++)
3618 rte_eth_stats_reset(test_params->slave_port_ids[i]);
3620 /* Verify that pkts are not sent on slaves with link status down */
3623 if (generate_test_burst(&pkt_burst[0][0], burst_size, 0, 0, 1, 0, 0) !=
3625 printf("generate_test_burst failed\n");
3629 if (rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt_burst[0][0],
3630 burst_size) != (burst_size * slave_count)) {
3631 printf("rte_eth_tx_burst failed\n");
3635 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3636 if (port_stats.opackets != (uint64_t)(burst_size * slave_count)) {
3637 printf("(%d) port_stats.opackets (%d) not as expected (%d)\n",
3638 test_params->bonded_port_id, (int)port_stats.opackets,
3639 burst_size * slave_count);
3643 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3644 if (port_stats.opackets != (uint64_t)burst_size) {
3645 printf("(%d) port_stats.opackets not as expected\n",
3646 test_params->slave_port_ids[0]);
3650 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3651 if (port_stats.opackets != 0) {
3652 printf("(%d) port_stats.opackets not as expected\n",
3653 test_params->slave_port_ids[1]);
3657 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3658 if (port_stats.opackets != (uint64_t)burst_size) {
3659 printf("(%d) port_stats.opackets not as expected\n",
3660 test_params->slave_port_ids[2]);
3664 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
3665 if (port_stats.opackets != 0) {
3666 printf("(%d) port_stats.opackets not as expected\n",
3667 test_params->slave_port_ids[3]);
3671 for (i = 0; i < BROADCAST_LINK_STATUS_NUM_OF_SLAVES; i++) {
3672 if (generate_test_burst(&pkt_burst[i][0], burst_size, 0, 0, 1, 0, 0) !=
3677 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3678 &pkt_burst[i][0], burst_size);
3681 /* Verify that pkts are not received on slaves with link status down */
3683 if (rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
3685 burst_size + burst_size) {
3686 printf("rte_eth_rx_burst\n");
3690 /* Verify bonded device rx count */
3691 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3692 if (port_stats.ipackets != (uint64_t)(burst_size + burst_size)) {
3693 printf("(%d) port_stats.ipackets not as expected\n",
3694 test_params->bonded_port_id);
3698 /* free mbufs allocate for rx testing */
3699 for (i = 0; i < BROADCAST_LINK_STATUS_NUM_OF_SLAVES; i++) {
3700 for (j = 0; j < MAX_PKT_BURST; j++) {
3701 if (pkt_burst[i][j] != NULL) {
3702 rte_pktmbuf_free(pkt_burst[i][j]);
3703 pkt_burst[i][j] = NULL;
3708 /* Clean up and remove slaves from bonded device */
3709 return remove_slaves_and_stop_bonded_device();
3714 test_reconfigure_bonded_device(void)
3716 test_params->nb_rx_q = 4;
3717 test_params->nb_tx_q = 4;
3719 if (configure_ethdev(test_params->bonded_port_id, 0) != 0) {
3720 printf("failed to reconfigure bonded device");
3725 test_params->nb_rx_q = 2;
3726 test_params->nb_tx_q = 2;
3728 if (configure_ethdev(test_params->bonded_port_id, 0) != 0) {
3729 printf("failed to reconfigure bonded device with less rx/tx queues");
3738 test_close_bonded_device(void)
3740 rte_eth_dev_close(test_params->bonded_port_id);
3745 testsuite_teardown(void)
3747 if (test_params->pkt_eth_hdr != NULL) {
3748 free(test_params->pkt_eth_hdr);
3749 test_params->pkt_eth_hdr = NULL;
3752 /* Clean up and remove slaves from bonded device */
3753 return remove_slaves_and_stop_bonded_device();
3757 static struct unit_test_suite link_bonding_test_suite = {
3758 .suite_name = "Link Bonding Unit Test Suite",
3759 .setup = test_setup,
3760 .teardown = testsuite_teardown,
3761 .unit_test_cases = {
3762 TEST_CASE(test_create_bonded_device),
3763 TEST_CASE(test_create_bonded_device_with_invalid_params),
3764 TEST_CASE(test_add_slave_to_bonded_device),
3765 TEST_CASE(test_add_slave_to_invalid_bonded_device),
3766 TEST_CASE(test_remove_slave_from_bonded_device),
3767 TEST_CASE(test_remove_slave_from_invalid_bonded_device),
3768 TEST_CASE(test_get_slaves_from_bonded_device),
3769 TEST_CASE(test_add_already_bonded_slave_to_bonded_device),
3770 TEST_CASE(test_add_remove_multiple_slaves_to_from_bonded_device),
3771 TEST_CASE(test_start_bonded_device),
3772 TEST_CASE(test_stop_bonded_device),
3773 TEST_CASE(test_set_bonding_mode),
3774 TEST_CASE(test_set_primary_slave),
3775 TEST_CASE(test_set_explicit_bonded_mac),
3776 TEST_CASE(test_adding_slave_after_bonded_device_started),
3777 TEST_CASE(test_roundrobin_tx_burst),
3778 TEST_CASE(test_roundrobin_rx_burst_on_single_slave),
3779 TEST_CASE(test_roundrobin_rx_burst_on_multiple_slaves),
3780 TEST_CASE(test_roundrobin_verify_promiscuous_enable_disable),
3781 TEST_CASE(test_roundrobin_verify_mac_assignment),
3782 TEST_CASE(test_roundrobin_verify_slave_link_status_change_behaviour),
3783 TEST_CASE(test_activebackup_tx_burst),
3784 TEST_CASE(test_activebackup_rx_burst),
3785 TEST_CASE(test_activebackup_verify_promiscuous_enable_disable),
3786 TEST_CASE(test_activebackup_verify_mac_assignment),
3787 TEST_CASE(test_activebackup_verify_slave_link_status_change_failover),
3788 TEST_CASE(test_balance_xmit_policy_configuration),
3789 TEST_CASE(test_balance_l2_tx_burst),
3790 TEST_CASE(test_balance_l23_tx_burst_ipv4_toggle_ip_addr),
3791 TEST_CASE(test_balance_l23_tx_burst_vlan_ipv4_toggle_ip_addr),
3792 TEST_CASE(test_balance_l23_tx_burst_ipv6_toggle_ip_addr),
3793 TEST_CASE(test_balance_l23_tx_burst_vlan_ipv6_toggle_ip_addr),
3794 TEST_CASE(test_balance_l23_tx_burst_toggle_mac_addr),
3795 TEST_CASE(test_balance_l34_tx_burst_ipv4_toggle_ip_addr),
3796 TEST_CASE(test_balance_l34_tx_burst_ipv4_toggle_udp_port),
3797 TEST_CASE(test_balance_l34_tx_burst_vlan_ipv4_toggle_ip_addr),
3798 TEST_CASE(test_balance_l34_tx_burst_ipv6_toggle_ip_addr),
3799 TEST_CASE(test_balance_l34_tx_burst_vlan_ipv6_toggle_ip_addr),
3800 TEST_CASE(test_balance_l34_tx_burst_ipv6_toggle_udp_port),
3801 TEST_CASE(test_balance_rx_burst),
3802 TEST_CASE(test_balance_verify_promiscuous_enable_disable),
3803 TEST_CASE(test_balance_verify_mac_assignment),
3804 TEST_CASE(test_balance_verify_slave_link_status_change_behaviour),
3805 #ifdef RTE_MBUF_REFCNT
3806 TEST_CASE(test_broadcast_tx_burst),
3807 TEST_CASE(test_broadcast_rx_burst),
3808 TEST_CASE(test_broadcast_verify_promiscuous_enable_disable),
3809 TEST_CASE(test_broadcast_verify_mac_assignment),
3810 TEST_CASE(test_broadcast_verify_slave_link_status_change_behaviour),
3812 TEST_CASE(test_reconfigure_bonded_device),
3813 TEST_CASE(test_close_bonded_device),
3815 { NULL, NULL, NULL, NULL, NULL } /**< NULL terminate unit test array */
3821 test_link_bonding(void)
3823 return unit_test_suite_runner(&link_bonding_test_suite);
3826 static struct test_command link_bonding_cmd = {
3827 .command = "link_bonding_autotest",
3828 .callback = test_link_bonding,
3830 REGISTER_TEST_COMMAND(link_bonding_cmd);