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.
42 #include <sys/queue.h>
44 #include <rte_cycles.h>
45 #include <rte_byteorder.h>
46 #include <rte_common.h>
47 #include <rte_debug.h>
48 #include <rte_ethdev.h>
50 #include <rte_lcore.h>
51 #include <rte_memory.h>
52 #include <rte_string_fns.h>
53 #include <rte_eth_bond.h>
55 #include "virtual_pmd.h"
56 #include "packet_burst_generator.h"
60 #define TEST_MAX_NUMBER_OF_PORTS (6)
62 #define RX_RING_SIZE 128
63 #define RX_FREE_THRESH 32
68 #define TX_RING_SIZE 512
69 #define TX_FREE_THRESH 32
73 #define TX_RSBIT_THRESH 32
74 #define TX_Q_FLAGS (ETH_TXQ_FLAGS_NOMULTSEGS | ETH_TXQ_FLAGS_NOVLANOFFL |\
75 ETH_TXQ_FLAGS_NOXSUMSCTP | ETH_TXQ_FLAGS_NOXSUMUDP | \
76 ETH_TXQ_FLAGS_NOXSUMTCP)
78 #define MBUF_CACHE_SIZE (250)
79 #define BURST_SIZE (32)
81 #define RTE_TEST_RX_DESC_MAX (2048)
82 #define RTE_TEST_TX_DESC_MAX (2048)
83 #define MAX_PKT_BURST (512)
84 #define DEF_PKT_BURST (16)
86 #define BONDED_DEV_NAME ("net_bonding_ut")
88 #define INVALID_SOCKET_ID (-1)
89 #define INVALID_PORT_ID (-1)
90 #define INVALID_BONDING_MODE (-1)
93 uint8_t slave_mac[] = {0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 };
94 uint8_t bonded_mac[] = {0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
96 struct link_bonding_unittest_params {
97 int16_t bonded_port_id;
98 int16_t slave_port_ids[TEST_MAX_NUMBER_OF_PORTS];
99 uint16_t bonded_slave_count;
100 uint8_t bonding_mode;
105 struct rte_mempool *mbuf_pool;
107 struct ether_addr *default_slave_mac;
108 struct ether_addr *default_bonded_mac;
111 struct ether_hdr *pkt_eth_hdr;
112 struct ipv4_hdr *pkt_ipv4_hdr;
113 struct ipv6_hdr *pkt_ipv6_hdr;
114 struct udp_hdr *pkt_udp_hdr;
118 static struct ipv4_hdr pkt_ipv4_hdr;
119 static struct ipv6_hdr pkt_ipv6_hdr;
120 static struct udp_hdr pkt_udp_hdr;
122 static struct link_bonding_unittest_params default_params = {
123 .bonded_port_id = -1,
124 .slave_port_ids = { -1 },
125 .bonded_slave_count = 0,
126 .bonding_mode = BONDING_MODE_ROUND_ROBIN,
133 .default_slave_mac = (struct ether_addr *)slave_mac,
134 .default_bonded_mac = (struct ether_addr *)bonded_mac,
137 .pkt_ipv4_hdr = &pkt_ipv4_hdr,
138 .pkt_ipv6_hdr = &pkt_ipv6_hdr,
139 .pkt_udp_hdr = &pkt_udp_hdr
143 static struct link_bonding_unittest_params *test_params = &default_params;
145 static uint8_t src_mac[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
146 static uint8_t dst_mac_0[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
147 static uint8_t dst_mac_1[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAB };
149 static uint32_t src_addr = IPV4_ADDR(192, 168, 1, 98);
150 static uint32_t dst_addr_0 = IPV4_ADDR(192, 168, 1, 98);
151 static uint32_t dst_addr_1 = IPV4_ADDR(193, 166, 10, 97);
153 static uint8_t src_ipv6_addr[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF,
154 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA , 0xFF, 0xAA };
155 static uint8_t dst_ipv6_addr_0[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF,
156 0xAA, 0xFF, 0xAA, 0xFF, 0xAA , 0xFF, 0xAA, 0xFF, 0xAA };
157 static uint8_t dst_ipv6_addr_1[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF,
158 0xAA, 0xFF, 0xAA, 0xFF, 0xAA , 0xFF, 0xAA , 0xFF, 0xAB };
160 static uint16_t src_port = 1024;
161 static uint16_t dst_port_0 = 1024;
162 static uint16_t dst_port_1 = 2024;
164 static uint16_t vlan_id = 0x100;
166 struct rte_eth_rxmode rx_mode = {
167 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
169 .header_split = 0, /**< Header Split disabled. */
170 .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
171 .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
172 .hw_vlan_strip = 1, /**< VLAN strip enabled. */
173 .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
174 .jumbo_frame = 0, /**< Jumbo Frame Support disabled. */
175 .hw_strip_crc = 1, /**< CRC stripping by hardware enabled. */
178 struct rte_fdir_conf fdir_conf = {
179 .mode = RTE_FDIR_MODE_NONE,
180 .pballoc = RTE_FDIR_PBALLOC_64K,
181 .status = RTE_FDIR_REPORT_STATUS,
185 static struct rte_eth_conf default_pmd_conf = {
187 .mq_mode = ETH_MQ_RX_NONE,
188 .max_rx_pkt_len = ETHER_MAX_LEN,
190 .header_split = 0, /**< Header Split disabled */
191 .hw_ip_checksum = 0, /**< IP checksum offload enabled */
192 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
193 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
194 .hw_strip_crc = 1, /**< CRC stripped by hardware */
197 .mq_mode = ETH_MQ_TX_NONE,
202 static const struct rte_eth_rxconf rx_conf_default = {
204 .pthresh = RX_PTHRESH,
205 .hthresh = RX_HTHRESH,
206 .wthresh = RX_WTHRESH,
208 .rx_free_thresh = RX_FREE_THRESH,
212 static struct rte_eth_txconf tx_conf_default = {
214 .pthresh = TX_PTHRESH,
215 .hthresh = TX_HTHRESH,
216 .wthresh = TX_WTHRESH,
218 .tx_free_thresh = TX_FREE_THRESH,
219 .tx_rs_thresh = TX_RSBIT_THRESH,
220 .txq_flags = TX_Q_FLAGS
224 static void free_virtualpmd_tx_queue(void);
229 configure_ethdev(uint8_t port_id, uint8_t start, uint8_t en_isr)
234 default_pmd_conf.intr_conf.lsc = 1;
236 default_pmd_conf.intr_conf.lsc = 0;
238 TEST_ASSERT_SUCCESS(rte_eth_dev_configure(port_id, test_params->nb_rx_q,
239 test_params->nb_tx_q, &default_pmd_conf),
240 "rte_eth_dev_configure for port %d failed", port_id);
242 for (q_id = 0; q_id < test_params->nb_rx_q; q_id++)
243 TEST_ASSERT_SUCCESS(rte_eth_rx_queue_setup(port_id, q_id, RX_RING_SIZE,
244 rte_eth_dev_socket_id(port_id), &rx_conf_default,
245 test_params->mbuf_pool) ,
246 "rte_eth_rx_queue_setup for port %d failed", port_id);
248 for (q_id = 0; q_id < test_params->nb_tx_q; q_id++)
249 TEST_ASSERT_SUCCESS(rte_eth_tx_queue_setup(port_id, q_id, TX_RING_SIZE,
250 rte_eth_dev_socket_id(port_id), &tx_conf_default),
251 "rte_eth_tx_queue_setup for port %d failed", port_id);
254 TEST_ASSERT_SUCCESS(rte_eth_dev_start(port_id),
255 "rte_eth_dev_start for port %d failed", port_id);
260 static int slaves_initialized;
262 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
263 static pthread_cond_t cvar = PTHREAD_COND_INITIALIZER;
269 int i, nb_mbuf_per_pool;
270 struct ether_addr *mac_addr = (struct ether_addr *)slave_mac;
272 /* Allocate ethernet packet header with space for VLAN header */
273 if (test_params->pkt_eth_hdr == NULL) {
274 test_params->pkt_eth_hdr = malloc(sizeof(struct ether_hdr) +
275 sizeof(struct vlan_hdr));
277 TEST_ASSERT_NOT_NULL(test_params->pkt_eth_hdr,
278 "Ethernet header struct allocation failed!");
281 nb_mbuf_per_pool = RTE_TEST_RX_DESC_MAX + DEF_PKT_BURST +
282 RTE_TEST_TX_DESC_MAX + MAX_PKT_BURST;
283 if (test_params->mbuf_pool == NULL) {
284 test_params->mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL",
285 nb_mbuf_per_pool, MBUF_CACHE_SIZE, 0,
286 RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
287 TEST_ASSERT_NOT_NULL(test_params->mbuf_pool,
288 "rte_mempool_create failed");
291 /* Create / Initialize virtual eth devs */
292 if (!slaves_initialized) {
293 for (i = 0; i < TEST_MAX_NUMBER_OF_PORTS; i++) {
294 char pmd_name[RTE_ETH_NAME_MAX_LEN];
296 mac_addr->addr_bytes[ETHER_ADDR_LEN-1] = i;
298 snprintf(pmd_name, RTE_ETH_NAME_MAX_LEN, "eth_virt_%d", i);
300 test_params->slave_port_ids[i] = virtual_ethdev_create(pmd_name,
301 mac_addr, rte_socket_id(), 1);
302 TEST_ASSERT(test_params->slave_port_ids[i] >= 0,
303 "Failed to create virtual virtual ethdev %s", pmd_name);
305 TEST_ASSERT_SUCCESS(configure_ethdev(
306 test_params->slave_port_ids[i], 1, 0),
307 "Failed to configure virtual ethdev %s", pmd_name);
309 slaves_initialized = 1;
316 test_create_bonded_device(void)
318 int current_slave_count;
320 uint16_t slaves[RTE_MAX_ETHPORTS];
322 /* Don't try to recreate bonded device if re-running test suite*/
323 if (test_params->bonded_port_id == -1) {
324 test_params->bonded_port_id = rte_eth_bond_create(BONDED_DEV_NAME,
325 test_params->bonding_mode, rte_socket_id());
327 TEST_ASSERT(test_params->bonded_port_id >= 0,
328 "Failed to create bonded ethdev %s", BONDED_DEV_NAME);
330 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0, 0),
331 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME);
334 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
335 test_params->bonding_mode), "Failed to set ethdev %d to mode %d",
336 test_params->bonded_port_id, test_params->bonding_mode);
338 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
339 slaves, RTE_MAX_ETHPORTS);
341 TEST_ASSERT_EQUAL(current_slave_count, 0,
342 "Number of slaves %d is great than expected %d.",
343 current_slave_count, 0);
345 current_slave_count = rte_eth_bond_active_slaves_get(
346 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
348 TEST_ASSERT_EQUAL(current_slave_count, 0,
349 "Number of active slaves %d is great than expected %d.",
350 current_slave_count, 0);
357 test_create_bonded_device_with_invalid_params(void)
361 test_params->bonding_mode = BONDING_MODE_ROUND_ROBIN;
364 port_id = rte_eth_bond_create(NULL, test_params->bonding_mode,
366 TEST_ASSERT(port_id < 0, "Created bonded device unexpectedly");
368 test_params->bonding_mode = INVALID_BONDING_MODE;
370 /* Invalid bonding mode */
371 port_id = rte_eth_bond_create(BONDED_DEV_NAME, test_params->bonding_mode,
373 TEST_ASSERT(port_id < 0, "Created bonded device unexpectedly.");
375 test_params->bonding_mode = BONDING_MODE_ROUND_ROBIN;
377 /* Invalid socket id */
378 port_id = rte_eth_bond_create(BONDED_DEV_NAME, test_params->bonding_mode,
380 TEST_ASSERT(port_id < 0, "Created bonded device unexpectedly.");
386 test_add_slave_to_bonded_device(void)
388 int current_slave_count;
390 uint16_t slaves[RTE_MAX_ETHPORTS];
392 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params->bonded_port_id,
393 test_params->slave_port_ids[test_params->bonded_slave_count]),
394 "Failed to add slave (%d) to bonded port (%d).",
395 test_params->slave_port_ids[test_params->bonded_slave_count],
396 test_params->bonded_port_id);
398 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
399 slaves, RTE_MAX_ETHPORTS);
400 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count + 1,
401 "Number of slaves (%d) is greater than expected (%d).",
402 current_slave_count, test_params->bonded_slave_count + 1);
404 current_slave_count = rte_eth_bond_active_slaves_get(
405 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
406 TEST_ASSERT_EQUAL(current_slave_count, 0,
407 "Number of active slaves (%d) is not as expected (%d).\n",
408 current_slave_count, 0);
410 test_params->bonded_slave_count++;
416 test_add_slave_to_invalid_bonded_device(void)
418 /* Invalid port ID */
419 TEST_ASSERT_FAIL(rte_eth_bond_slave_add(test_params->bonded_port_id + 5,
420 test_params->slave_port_ids[test_params->bonded_slave_count]),
421 "Expected call to failed as invalid port specified.");
423 /* Non bonded device */
424 TEST_ASSERT_FAIL(rte_eth_bond_slave_add(test_params->slave_port_ids[0],
425 test_params->slave_port_ids[test_params->bonded_slave_count]),
426 "Expected call to failed as invalid port specified.");
433 test_remove_slave_from_bonded_device(void)
435 int current_slave_count;
436 struct ether_addr read_mac_addr, *mac_addr;
437 uint16_t slaves[RTE_MAX_ETHPORTS];
439 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_remove(test_params->bonded_port_id,
440 test_params->slave_port_ids[test_params->bonded_slave_count-1]),
441 "Failed to remove slave %d from bonded port (%d).",
442 test_params->slave_port_ids[test_params->bonded_slave_count-1],
443 test_params->bonded_port_id);
446 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
447 slaves, RTE_MAX_ETHPORTS);
449 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count - 1,
450 "Number of slaves (%d) is great than expected (%d).\n",
451 current_slave_count, test_params->bonded_slave_count - 1);
454 mac_addr = (struct ether_addr *)slave_mac;
455 mac_addr->addr_bytes[ETHER_ADDR_LEN-1] =
456 test_params->bonded_slave_count-1;
459 test_params->slave_port_ids[test_params->bonded_slave_count-1],
461 TEST_ASSERT_SUCCESS(memcmp(mac_addr, &read_mac_addr, sizeof(read_mac_addr)),
462 "bonded port mac address not set to that of primary port\n");
465 test_params->slave_port_ids[test_params->bonded_slave_count-1]);
467 virtual_ethdev_simulate_link_status_interrupt(test_params->bonded_port_id,
470 test_params->bonded_slave_count--;
476 test_remove_slave_from_invalid_bonded_device(void)
478 /* Invalid port ID */
479 TEST_ASSERT_FAIL(rte_eth_bond_slave_remove(
480 test_params->bonded_port_id + 5,
481 test_params->slave_port_ids[test_params->bonded_slave_count - 1]),
482 "Expected call to failed as invalid port specified.");
484 /* Non bonded device */
485 TEST_ASSERT_FAIL(rte_eth_bond_slave_remove(
486 test_params->slave_port_ids[0],
487 test_params->slave_port_ids[test_params->bonded_slave_count - 1]),
488 "Expected call to failed as invalid port specified.");
493 static int bonded_id = 2;
496 test_add_already_bonded_slave_to_bonded_device(void)
498 int port_id, current_slave_count;
499 uint16_t slaves[RTE_MAX_ETHPORTS];
500 char pmd_name[RTE_ETH_NAME_MAX_LEN];
502 test_add_slave_to_bonded_device();
504 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
505 slaves, RTE_MAX_ETHPORTS);
506 TEST_ASSERT_EQUAL(current_slave_count, 1,
507 "Number of slaves (%d) is not that expected (%d).",
508 current_slave_count, 1);
510 snprintf(pmd_name, RTE_ETH_NAME_MAX_LEN, "%s_%d", BONDED_DEV_NAME, ++bonded_id);
512 port_id = rte_eth_bond_create(pmd_name, test_params->bonding_mode,
514 TEST_ASSERT(port_id >= 0, "Failed to create bonded device.");
516 TEST_ASSERT(rte_eth_bond_slave_add(port_id,
517 test_params->slave_port_ids[test_params->bonded_slave_count - 1])
519 "Added slave (%d) to bonded port (%d) unexpectedly.",
520 test_params->slave_port_ids[test_params->bonded_slave_count-1],
523 return test_remove_slave_from_bonded_device();
528 test_get_slaves_from_bonded_device(void)
530 int current_slave_count;
531 uint16_t slaves[RTE_MAX_ETHPORTS];
533 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
534 "Failed to add slave to bonded device");
536 /* Invalid port id */
537 current_slave_count = rte_eth_bond_slaves_get(INVALID_PORT_ID, slaves,
539 TEST_ASSERT(current_slave_count < 0,
540 "Invalid port id unexpectedly succeeded");
542 current_slave_count = rte_eth_bond_active_slaves_get(INVALID_PORT_ID,
543 slaves, RTE_MAX_ETHPORTS);
544 TEST_ASSERT(current_slave_count < 0,
545 "Invalid port id unexpectedly succeeded");
547 /* Invalid slaves pointer */
548 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
549 NULL, RTE_MAX_ETHPORTS);
550 TEST_ASSERT(current_slave_count < 0,
551 "Invalid slave array unexpectedly succeeded");
553 current_slave_count = rte_eth_bond_active_slaves_get(
554 test_params->bonded_port_id, NULL, RTE_MAX_ETHPORTS);
555 TEST_ASSERT(current_slave_count < 0,
556 "Invalid slave array unexpectedly succeeded");
558 /* non bonded device*/
559 current_slave_count = rte_eth_bond_slaves_get(
560 test_params->slave_port_ids[0], NULL, RTE_MAX_ETHPORTS);
561 TEST_ASSERT(current_slave_count < 0,
562 "Invalid port id unexpectedly succeeded");
564 current_slave_count = rte_eth_bond_active_slaves_get(
565 test_params->slave_port_ids[0], NULL, RTE_MAX_ETHPORTS);
566 TEST_ASSERT(current_slave_count < 0,
567 "Invalid port id unexpectedly succeeded");
569 TEST_ASSERT_SUCCESS(test_remove_slave_from_bonded_device(),
570 "Failed to remove slaves from bonded device");
577 test_add_remove_multiple_slaves_to_from_bonded_device(void)
581 for (i = 0; i < TEST_MAX_NUMBER_OF_PORTS; i++)
582 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
583 "Failed to add slave to bonded device");
585 for (i = 0; i < TEST_MAX_NUMBER_OF_PORTS; i++)
586 TEST_ASSERT_SUCCESS(test_remove_slave_from_bonded_device(),
587 "Failed to remove slaves from bonded device");
593 enable_bonded_slaves(void)
597 for (i = 0; i < test_params->bonded_slave_count; i++) {
598 virtual_ethdev_tx_burst_fn_set_success(test_params->slave_port_ids[i],
601 virtual_ethdev_simulate_link_status_interrupt(
602 test_params->slave_port_ids[i], 1);
607 test_start_bonded_device(void)
609 struct rte_eth_link link_status;
611 int current_slave_count, current_bonding_mode, primary_port;
612 uint16_t slaves[RTE_MAX_ETHPORTS];
614 /* Add slave to bonded device*/
615 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
616 "Failed to add slave to bonded device");
618 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
619 "Failed to start bonded pmd eth device %d.",
620 test_params->bonded_port_id);
622 /* Change link status of virtual pmd so it will be added to the active
623 * slave list of the bonded device*/
624 virtual_ethdev_simulate_link_status_interrupt(
625 test_params->slave_port_ids[test_params->bonded_slave_count-1], 1);
627 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
628 slaves, RTE_MAX_ETHPORTS);
629 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count,
630 "Number of slaves (%d) is not expected value (%d).",
631 current_slave_count, test_params->bonded_slave_count);
633 current_slave_count = rte_eth_bond_active_slaves_get(
634 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
635 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count,
636 "Number of active slaves (%d) is not expected value (%d).",
637 current_slave_count, test_params->bonded_slave_count);
639 current_bonding_mode = rte_eth_bond_mode_get(test_params->bonded_port_id);
640 TEST_ASSERT_EQUAL(current_bonding_mode, test_params->bonding_mode,
641 "Bonded device mode (%d) is not expected value (%d).\n",
642 current_bonding_mode, test_params->bonding_mode);
644 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
645 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[0],
646 "Primary port (%d) is not expected value (%d).",
647 primary_port, test_params->slave_port_ids[0]);
649 rte_eth_link_get(test_params->bonded_port_id, &link_status);
650 TEST_ASSERT_EQUAL(link_status.link_status, 1,
651 "Bonded port (%d) status (%d) is not expected value (%d).\n",
652 test_params->bonded_port_id, link_status.link_status, 1);
658 test_stop_bonded_device(void)
660 int current_slave_count;
661 uint16_t slaves[RTE_MAX_ETHPORTS];
663 struct rte_eth_link link_status;
665 rte_eth_dev_stop(test_params->bonded_port_id);
667 rte_eth_link_get(test_params->bonded_port_id, &link_status);
668 TEST_ASSERT_EQUAL(link_status.link_status, 0,
669 "Bonded port (%d) status (%d) is not expected value (%d).",
670 test_params->bonded_port_id, link_status.link_status, 0);
672 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
673 slaves, RTE_MAX_ETHPORTS);
674 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count,
675 "Number of slaves (%d) is not expected value (%d).",
676 current_slave_count, test_params->bonded_slave_count);
678 current_slave_count = rte_eth_bond_active_slaves_get(
679 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
680 TEST_ASSERT_EQUAL(current_slave_count, 0,
681 "Number of active slaves (%d) is not expected value (%d).",
682 current_slave_count, 0);
688 remove_slaves_and_stop_bonded_device(void)
690 /* Clean up and remove slaves from bonded device */
691 free_virtualpmd_tx_queue();
692 while (test_params->bonded_slave_count > 0)
693 TEST_ASSERT_SUCCESS(test_remove_slave_from_bonded_device(),
694 "test_remove_slave_from_bonded_device failed");
696 rte_eth_dev_stop(test_params->bonded_port_id);
697 rte_eth_stats_reset(test_params->bonded_port_id);
698 rte_eth_bond_mac_address_reset(test_params->bonded_port_id);
704 test_set_bonding_mode(void)
708 int bonding_modes[] = { BONDING_MODE_ROUND_ROBIN,
709 BONDING_MODE_ACTIVE_BACKUP,
710 BONDING_MODE_BALANCE,
711 BONDING_MODE_BROADCAST
714 /* Test supported link bonding modes */
715 for (i = 0; i < (int)RTE_DIM(bonding_modes); i++) {
716 /* Invalid port ID */
717 TEST_ASSERT_FAIL(rte_eth_bond_mode_set(INVALID_PORT_ID,
719 "Expected call to failed as invalid port (%d) specified.",
722 /* Non bonded device */
723 TEST_ASSERT_FAIL(rte_eth_bond_mode_set(test_params->slave_port_ids[0],
725 "Expected call to failed as invalid port (%d) specified.",
726 test_params->slave_port_ids[0]);
728 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
730 "Failed to set link bonding mode on port (%d) to (%d).",
731 test_params->bonded_port_id, bonding_modes[i]);
733 bonding_mode = rte_eth_bond_mode_get(test_params->bonded_port_id);
734 TEST_ASSERT_EQUAL(bonding_mode, bonding_modes[i],
735 "Link bonding mode (%d) of port (%d) is not expected value (%d).",
736 bonding_mode, test_params->bonded_port_id,
739 /* Invalid port ID */
740 bonding_mode = rte_eth_bond_mode_get(INVALID_PORT_ID);
741 TEST_ASSERT(bonding_mode < 0,
742 "Expected call to failed as invalid port (%d) specified.",
745 /* Non bonded device */
746 bonding_mode = rte_eth_bond_mode_get(test_params->slave_port_ids[0]);
747 TEST_ASSERT(bonding_mode < 0,
748 "Expected call to failed as invalid port (%d) specified.",
749 test_params->slave_port_ids[0]);
752 return remove_slaves_and_stop_bonded_device();
756 test_set_primary_slave(void)
759 struct ether_addr read_mac_addr;
760 struct ether_addr *expected_mac_addr;
762 /* Add 4 slaves to bonded device */
763 for (i = test_params->bonded_slave_count; i < 4; i++)
764 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
765 "Failed to add slave to bonded device.");
767 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
768 BONDING_MODE_ROUND_ROBIN),
769 "Failed to set link bonding mode on port (%d) to (%d).",
770 test_params->bonded_port_id, BONDING_MODE_ROUND_ROBIN);
772 /* Invalid port ID */
773 TEST_ASSERT_FAIL(rte_eth_bond_primary_set(INVALID_PORT_ID,
774 test_params->slave_port_ids[i]),
775 "Expected call to failed as invalid port specified.");
777 /* Non bonded device */
778 TEST_ASSERT_FAIL(rte_eth_bond_primary_set(test_params->slave_port_ids[i],
779 test_params->slave_port_ids[i]),
780 "Expected call to failed as invalid port specified.");
782 /* Set slave as primary
783 * Verify slave it is now primary slave
784 * Verify that MAC address of bonded device is that of primary slave
785 * Verify that MAC address of all bonded slaves are that of primary slave
787 for (i = 0; i < 4; i++) {
788 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(test_params->bonded_port_id,
789 test_params->slave_port_ids[i]),
790 "Failed to set bonded port (%d) primary port to (%d)",
791 test_params->bonded_port_id, test_params->slave_port_ids[i]);
793 retval = rte_eth_bond_primary_get(test_params->bonded_port_id);
794 TEST_ASSERT(retval >= 0,
795 "Failed to read primary port from bonded port (%d)\n",
796 test_params->bonded_port_id);
798 TEST_ASSERT_EQUAL(retval, test_params->slave_port_ids[i],
799 "Bonded port (%d) primary port (%d) not expected value (%d)\n",
800 test_params->bonded_port_id, retval,
801 test_params->slave_port_ids[i]);
803 /* stop/start bonded eth dev to apply new MAC */
804 rte_eth_dev_stop(test_params->bonded_port_id);
806 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
807 "Failed to start bonded port %d",
808 test_params->bonded_port_id);
810 expected_mac_addr = (struct ether_addr *)&slave_mac;
811 expected_mac_addr->addr_bytes[ETHER_ADDR_LEN-1] = i;
813 /* Check primary slave MAC */
814 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
815 TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
816 sizeof(read_mac_addr)),
817 "bonded port mac address not set to that of primary port\n");
819 /* Check bonded MAC */
820 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
821 TEST_ASSERT_SUCCESS(memcmp(&read_mac_addr, &read_mac_addr,
822 sizeof(read_mac_addr)),
823 "bonded port mac address not set to that of primary port\n");
825 /* Check other slaves MACs */
826 for (j = 0; j < 4; j++) {
828 rte_eth_macaddr_get(test_params->slave_port_ids[j],
830 TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
831 sizeof(read_mac_addr)),
832 "slave port mac address not set to that of primary "
839 /* Test with none existent port */
840 TEST_ASSERT_FAIL(rte_eth_bond_primary_get(test_params->bonded_port_id + 10),
841 "read primary port from expectedly");
843 /* Test with slave port */
844 TEST_ASSERT_FAIL(rte_eth_bond_primary_get(test_params->slave_port_ids[0]),
845 "read primary port from expectedly\n");
847 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
848 "Failed to stop and remove slaves from bonded device");
851 TEST_ASSERT(rte_eth_bond_primary_get(test_params->bonded_port_id) < 0,
852 "read primary port from expectedly\n");
858 test_set_explicit_bonded_mac(void)
861 struct ether_addr read_mac_addr;
862 struct ether_addr *mac_addr;
864 uint8_t explicit_bonded_mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01 };
866 mac_addr = (struct ether_addr *)explicit_bonded_mac;
868 /* Invalid port ID */
869 TEST_ASSERT_FAIL(rte_eth_bond_mac_address_set(INVALID_PORT_ID, mac_addr),
870 "Expected call to failed as invalid port specified.");
872 /* Non bonded device */
873 TEST_ASSERT_FAIL(rte_eth_bond_mac_address_set(
874 test_params->slave_port_ids[0], mac_addr),
875 "Expected call to failed as invalid port specified.");
877 /* NULL MAC address */
878 TEST_ASSERT_FAIL(rte_eth_bond_mac_address_set(
879 test_params->bonded_port_id, NULL),
880 "Expected call to failed as NULL MAC specified");
882 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
883 test_params->bonded_port_id, mac_addr),
884 "Failed to set MAC address on bonded port (%d)",
885 test_params->bonded_port_id);
887 /* Add 4 slaves to bonded device */
888 for (i = test_params->bonded_slave_count; i < 4; i++) {
889 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
890 "Failed to add slave to bonded device.\n");
893 /* Check bonded MAC */
894 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
895 TEST_ASSERT_SUCCESS(memcmp(mac_addr, &read_mac_addr, sizeof(read_mac_addr)),
896 "bonded port mac address not set to that of primary port");
898 /* Check other slaves MACs */
899 for (i = 0; i < 4; i++) {
900 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
901 TEST_ASSERT_SUCCESS(memcmp(mac_addr, &read_mac_addr,
902 sizeof(read_mac_addr)),
903 "slave port mac address not set to that of primary port");
906 /* test resetting mac address on bonded device */
908 rte_eth_bond_mac_address_reset(test_params->bonded_port_id),
909 "Failed to reset MAC address on bonded port (%d)",
910 test_params->bonded_port_id);
913 rte_eth_bond_mac_address_reset(test_params->slave_port_ids[0]),
914 "Reset MAC address on bonded port (%d) unexpectedly",
915 test_params->slave_port_ids[1]);
917 /* test resetting mac address on bonded device with no slaves */
918 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
919 "Failed to remove slaves and stop bonded device");
921 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_reset(test_params->bonded_port_id),
922 "Failed to reset MAC address on bonded port (%d)",
923 test_params->bonded_port_id);
928 #define BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT (3)
931 test_set_bonded_port_initialization_mac_assignment(void)
933 int i, slave_count, bonded_port_id;
935 uint16_t slaves[RTE_MAX_ETHPORTS];
936 int slave_port_ids[BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT];
938 struct ether_addr slave_mac_addr, bonded_mac_addr, read_mac_addr;
940 /* Initialize default values for MAC addresses */
941 memcpy(&slave_mac_addr, slave_mac, sizeof(struct ether_addr));
942 memcpy(&bonded_mac_addr, slave_mac, sizeof(struct ether_addr));
945 * 1. a - Create / configure bonded / slave ethdevs
947 bonded_port_id = rte_eth_bond_create("net_bonding_mac_ass_test",
948 BONDING_MODE_ACTIVE_BACKUP, rte_socket_id());
949 TEST_ASSERT(bonded_port_id > 0, "failed to create bonded device");
951 TEST_ASSERT_SUCCESS(configure_ethdev(bonded_port_id, 0, 0),
952 "Failed to configure bonded ethdev");
954 for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
955 char pmd_name[RTE_ETH_NAME_MAX_LEN];
957 slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = i + 100;
959 snprintf(pmd_name, RTE_ETH_NAME_MAX_LEN, "eth_slave_%d", i);
961 slave_port_ids[i] = virtual_ethdev_create(pmd_name,
962 &slave_mac_addr, rte_socket_id(), 1);
964 TEST_ASSERT(slave_port_ids[i] >= 0,
965 "Failed to create slave ethdev %s", pmd_name);
967 TEST_ASSERT_SUCCESS(configure_ethdev(slave_port_ids[i], 1, 0),
968 "Failed to configure virtual ethdev %s",
974 * 2. Add slave ethdevs to bonded device
976 for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
977 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(bonded_port_id,
979 "Failed to add slave (%d) to bonded port (%d).",
980 slave_port_ids[i], bonded_port_id);
983 slave_count = rte_eth_bond_slaves_get(bonded_port_id, slaves,
985 TEST_ASSERT_EQUAL(BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT, slave_count,
986 "Number of slaves (%d) is not as expected (%d)",
987 slave_count, BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT);
991 * 3. Set explicit MAC address on bonded ethdev
993 bonded_mac_addr.addr_bytes[ETHER_ADDR_LEN-2] = 0xFF;
994 bonded_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 0xAA;
996 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
997 bonded_port_id, &bonded_mac_addr),
998 "Failed to set MAC address on bonded port (%d)",
1002 /* 4. a - Start bonded ethdev
1003 * b - Enable slave devices
1004 * c - Verify bonded/slaves ethdev MAC addresses
1006 TEST_ASSERT_SUCCESS(rte_eth_dev_start(bonded_port_id),
1007 "Failed to start bonded pmd eth device %d.",
1010 for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
1011 virtual_ethdev_simulate_link_status_interrupt(
1012 slave_port_ids[i], 1);
1015 rte_eth_macaddr_get(bonded_port_id, &read_mac_addr);
1016 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
1017 sizeof(read_mac_addr)),
1018 "bonded port mac address not as expected");
1020 rte_eth_macaddr_get(slave_port_ids[0], &read_mac_addr);
1021 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
1022 sizeof(read_mac_addr)),
1023 "slave port 0 mac address not as expected");
1025 slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 1 + 100;
1026 rte_eth_macaddr_get(slave_port_ids[1], &read_mac_addr);
1027 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1028 sizeof(read_mac_addr)),
1029 "slave port 1 mac address not as expected");
1031 slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 2 + 100;
1032 rte_eth_macaddr_get(slave_port_ids[2], &read_mac_addr);
1033 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1034 sizeof(read_mac_addr)),
1035 "slave port 2 mac address not as expected");
1038 /* 7. a - Change primary port
1039 * b - Stop / Start bonded port
1040 * d - Verify slave ethdev MAC addresses
1042 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(bonded_port_id,
1044 "failed to set primary port on bonded device.");
1046 rte_eth_dev_stop(bonded_port_id);
1047 TEST_ASSERT_SUCCESS(rte_eth_dev_start(bonded_port_id),
1048 "Failed to start bonded pmd eth device %d.",
1051 rte_eth_macaddr_get(bonded_port_id, &read_mac_addr);
1052 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
1053 sizeof(read_mac_addr)),
1054 "bonded port mac address not as expected");
1056 slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 0 + 100;
1057 rte_eth_macaddr_get(slave_port_ids[0], &read_mac_addr);
1058 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1059 sizeof(read_mac_addr)),
1060 "slave port 0 mac address not as expected");
1062 slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 1 + 100;
1063 rte_eth_macaddr_get(slave_port_ids[1], &read_mac_addr);
1064 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1065 sizeof(read_mac_addr)),
1066 "slave port 1 mac address not as expected");
1068 rte_eth_macaddr_get(slave_port_ids[2], &read_mac_addr);
1069 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
1070 sizeof(read_mac_addr)),
1071 "slave port 2 mac address not as expected");
1073 /* 6. a - Stop bonded ethdev
1074 * b - remove slave ethdevs
1075 * c - Verify slave ethdevs MACs are restored
1077 rte_eth_dev_stop(bonded_port_id);
1079 for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
1080 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_remove(bonded_port_id,
1082 "Failed to remove slave %d from bonded port (%d).",
1083 slave_port_ids[i], bonded_port_id);
1086 slave_count = rte_eth_bond_slaves_get(bonded_port_id, slaves,
1089 TEST_ASSERT_EQUAL(slave_count, 0,
1090 "Number of slaves (%d) is great than expected (%d).",
1093 slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 0 + 100;
1094 rte_eth_macaddr_get(slave_port_ids[0], &read_mac_addr);
1095 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1096 sizeof(read_mac_addr)),
1097 "slave port 0 mac address not as expected");
1099 slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 1 + 100;
1100 rte_eth_macaddr_get(slave_port_ids[1], &read_mac_addr);
1101 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1102 sizeof(read_mac_addr)),
1103 "slave port 1 mac address not as expected");
1105 slave_mac_addr.addr_bytes[ETHER_ADDR_LEN-1] = 2 + 100;
1106 rte_eth_macaddr_get(slave_port_ids[2], &read_mac_addr);
1107 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1108 sizeof(read_mac_addr)),
1109 "slave port 2 mac address not as expected");
1116 initialize_bonded_device_with_slaves(uint8_t bonding_mode, uint8_t bond_en_isr,
1117 uint16_t number_of_slaves, uint8_t enable_slave)
1119 /* Configure bonded device */
1120 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0,
1121 bond_en_isr), "Failed to configure bonding port (%d) in mode %d "
1122 "with (%d) slaves.", test_params->bonded_port_id, bonding_mode,
1125 /* Add slaves to bonded device */
1126 while (number_of_slaves > test_params->bonded_slave_count)
1127 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
1128 "Failed to add slave (%d to bonding port (%d).",
1129 test_params->bonded_slave_count - 1,
1130 test_params->bonded_port_id);
1132 /* Set link bonding mode */
1133 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
1135 "Failed to set link bonding mode on port (%d) to (%d).",
1136 test_params->bonded_port_id, bonding_mode);
1138 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
1139 "Failed to start bonded pmd eth device %d.",
1140 test_params->bonded_port_id);
1143 enable_bonded_slaves();
1149 test_adding_slave_after_bonded_device_started(void)
1153 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1154 BONDING_MODE_ROUND_ROBIN, 0, 4, 0),
1155 "Failed to add slaves to bonded device");
1157 /* Enabled slave devices */
1158 for (i = 0; i < test_params->bonded_slave_count + 1; i++) {
1159 virtual_ethdev_simulate_link_status_interrupt(
1160 test_params->slave_port_ids[i], 1);
1163 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params->bonded_port_id,
1164 test_params->slave_port_ids[test_params->bonded_slave_count]),
1165 "Failed to add slave to bonded port.\n");
1167 rte_eth_stats_reset(
1168 test_params->slave_port_ids[test_params->bonded_slave_count]);
1170 test_params->bonded_slave_count++;
1172 return remove_slaves_and_stop_bonded_device();
1175 #define TEST_STATUS_INTERRUPT_SLAVE_COUNT 4
1176 #define TEST_LSC_WAIT_TIMEOUT_MS 500
1178 int test_lsc_interrupt_count;
1182 test_bonding_lsc_event_callback(uint16_t port_id __rte_unused,
1183 enum rte_eth_event_type type __rte_unused,
1184 void *param __rte_unused,
1185 void *ret_param __rte_unused)
1187 pthread_mutex_lock(&mutex);
1188 test_lsc_interrupt_count++;
1190 pthread_cond_signal(&cvar);
1191 pthread_mutex_unlock(&mutex);
1197 lsc_timeout(int wait_us)
1204 gettimeofday(&tp, NULL);
1206 /* Convert from timeval to timespec */
1207 ts.tv_sec = tp.tv_sec;
1208 ts.tv_nsec = tp.tv_usec * 1000;
1209 ts.tv_nsec += wait_us * 1000;
1211 pthread_mutex_lock(&mutex);
1212 if (test_lsc_interrupt_count < 1)
1213 retval = pthread_cond_timedwait(&cvar, &mutex, &ts);
1215 pthread_mutex_unlock(&mutex);
1217 if (retval == 0 && test_lsc_interrupt_count < 1)
1224 test_status_interrupt(void)
1227 uint16_t slaves[RTE_MAX_ETHPORTS];
1229 /* initialized bonding device with T slaves */
1230 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1231 BONDING_MODE_ROUND_ROBIN, 1,
1232 TEST_STATUS_INTERRUPT_SLAVE_COUNT, 1),
1233 "Failed to initialise bonded device");
1235 test_lsc_interrupt_count = 0;
1237 /* register link status change interrupt callback */
1238 rte_eth_dev_callback_register(test_params->bonded_port_id,
1239 RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
1240 &test_params->bonded_port_id);
1242 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1243 slaves, RTE_MAX_ETHPORTS);
1245 TEST_ASSERT_EQUAL(slave_count, TEST_STATUS_INTERRUPT_SLAVE_COUNT,
1246 "Number of active slaves (%d) is not as expected (%d)",
1247 slave_count, TEST_STATUS_INTERRUPT_SLAVE_COUNT);
1249 /* Bring all 4 slaves link status to down and test that we have received a
1251 virtual_ethdev_simulate_link_status_interrupt(
1252 test_params->slave_port_ids[0], 0);
1253 virtual_ethdev_simulate_link_status_interrupt(
1254 test_params->slave_port_ids[1], 0);
1255 virtual_ethdev_simulate_link_status_interrupt(
1256 test_params->slave_port_ids[2], 0);
1258 TEST_ASSERT_EQUAL(test_lsc_interrupt_count, 0,
1259 "Received a link status change interrupt unexpectedly");
1261 virtual_ethdev_simulate_link_status_interrupt(
1262 test_params->slave_port_ids[3], 0);
1264 TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_MS) == 0,
1265 "timed out waiting for interrupt");
1267 TEST_ASSERT(test_lsc_interrupt_count > 0,
1268 "Did not receive link status change interrupt");
1270 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1271 slaves, RTE_MAX_ETHPORTS);
1273 TEST_ASSERT_EQUAL(slave_count, 0,
1274 "Number of active slaves (%d) is not as expected (%d)",
1277 /* bring one slave port up so link status will change */
1278 test_lsc_interrupt_count = 0;
1280 virtual_ethdev_simulate_link_status_interrupt(
1281 test_params->slave_port_ids[0], 1);
1283 TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_MS) == 0,
1284 "timed out waiting for interrupt");
1286 /* test that we have received another lsc interrupt */
1287 TEST_ASSERT(test_lsc_interrupt_count > 0,
1288 "Did not receive link status change interrupt");
1290 /* Verify that calling the same slave lsc interrupt doesn't cause another
1291 * lsc interrupt from bonded device */
1292 test_lsc_interrupt_count = 0;
1294 virtual_ethdev_simulate_link_status_interrupt(
1295 test_params->slave_port_ids[0], 1);
1297 TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_MS) != 0,
1298 "received unexpected interrupt");
1300 TEST_ASSERT_EQUAL(test_lsc_interrupt_count, 0,
1301 "Did not receive link status change interrupt");
1304 /* unregister lsc callback before exiting */
1305 rte_eth_dev_callback_unregister(test_params->bonded_port_id,
1306 RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
1307 &test_params->bonded_port_id);
1309 /* Clean up and remove slaves from bonded device */
1310 return remove_slaves_and_stop_bonded_device();
1314 generate_test_burst(struct rte_mbuf **pkts_burst, uint16_t burst_size,
1315 uint8_t vlan, uint8_t ipv4, uint8_t toggle_dst_mac,
1316 uint8_t toggle_ip_addr, uint16_t toggle_udp_port)
1318 uint16_t pktlen, generated_burst_size, ether_type;
1322 ether_type = ETHER_TYPE_IPv4;
1324 ether_type = ETHER_TYPE_IPv6;
1327 initialize_eth_header(test_params->pkt_eth_hdr,
1328 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_1,
1329 ether_type, vlan, vlan_id);
1331 initialize_eth_header(test_params->pkt_eth_hdr,
1332 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_0,
1333 ether_type, vlan, vlan_id);
1336 if (toggle_udp_port)
1337 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
1340 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
1345 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
1346 dst_addr_1, pktlen);
1348 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
1349 dst_addr_0, pktlen);
1351 ip_hdr = test_params->pkt_ipv4_hdr;
1354 pktlen = initialize_ipv6_header(test_params->pkt_ipv6_hdr,
1355 (uint8_t *)src_ipv6_addr, (uint8_t *)dst_ipv6_addr_1,
1358 pktlen = initialize_ipv6_header(test_params->pkt_ipv6_hdr,
1359 (uint8_t *)src_ipv6_addr, (uint8_t *)dst_ipv6_addr_0,
1362 ip_hdr = test_params->pkt_ipv6_hdr;
1365 /* Generate burst of packets to transmit */
1366 generated_burst_size = generate_packet_burst(test_params->mbuf_pool,
1367 pkts_burst, test_params->pkt_eth_hdr, vlan, ip_hdr, ipv4,
1368 test_params->pkt_udp_hdr, burst_size, PACKET_BURST_GEN_PKT_LEN_128,
1370 TEST_ASSERT_EQUAL(generated_burst_size, burst_size,
1371 "Failed to generate packet burst");
1373 return generated_burst_size;
1376 /** Round Robin Mode Tests */
1379 test_roundrobin_tx_burst(void)
1382 struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
1383 struct rte_eth_stats port_stats;
1385 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1386 BONDING_MODE_ROUND_ROBIN, 0, 2, 1),
1387 "Failed to initialise bonded device");
1389 burst_size = 20 * test_params->bonded_slave_count;
1391 TEST_ASSERT(burst_size <= MAX_PKT_BURST,
1392 "Burst size specified is greater than supported.");
1394 /* Generate test bursts of packets to transmit */
1395 TEST_ASSERT_EQUAL(generate_test_burst(pkt_burst, burst_size, 0, 1, 0, 0, 0),
1396 burst_size, "failed to generate test burst");
1398 /* Send burst on bonded port */
1399 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
1400 test_params->bonded_port_id, 0, pkt_burst, burst_size), burst_size,
1403 /* Verify bonded port tx stats */
1404 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1405 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
1406 "Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
1407 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
1410 /* Verify slave ports tx stats */
1411 for (i = 0; i < test_params->bonded_slave_count; i++) {
1412 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
1413 TEST_ASSERT_EQUAL(port_stats.opackets,
1414 (uint64_t)burst_size / test_params->bonded_slave_count,
1415 "Slave Port (%d) opackets value (%u) not as expected (%d)\n",
1416 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
1417 burst_size / test_params->bonded_slave_count);
1420 /* Put all slaves down and try and transmit */
1421 for (i = 0; i < test_params->bonded_slave_count; i++) {
1422 virtual_ethdev_simulate_link_status_interrupt(
1423 test_params->slave_port_ids[i], 0);
1426 /* Send burst on bonded port */
1427 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
1428 pkt_burst, burst_size), 0,
1429 "tx burst return unexpected value");
1431 /* Clean up and remove slaves from bonded device */
1432 return remove_slaves_and_stop_bonded_device();
1436 verify_mbufs_ref_count(struct rte_mbuf **mbufs, int nb_mbufs, int val)
1440 for (i = 0; i < nb_mbufs; i++) {
1441 refcnt = rte_mbuf_refcnt_read(mbufs[i]);
1442 TEST_ASSERT_EQUAL(refcnt, val,
1443 "mbuf ref count (%d)is not the expected value (%d)",
1450 free_mbufs(struct rte_mbuf **mbufs, int nb_mbufs)
1454 for (i = 0; i < nb_mbufs; i++)
1455 rte_pktmbuf_free(mbufs[i]);
1458 #define TEST_RR_SLAVE_TX_FAIL_SLAVE_COUNT (2)
1459 #define TEST_RR_SLAVE_TX_FAIL_BURST_SIZE (64)
1460 #define TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT (22)
1461 #define TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX (1)
1464 test_roundrobin_tx_burst_slave_tx_fail(void)
1466 struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
1467 struct rte_mbuf *expected_tx_fail_pkts[MAX_PKT_BURST];
1469 struct rte_eth_stats port_stats;
1471 int i, first_fail_idx, tx_count;
1473 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1474 BONDING_MODE_ROUND_ROBIN, 0,
1475 TEST_RR_SLAVE_TX_FAIL_SLAVE_COUNT, 1),
1476 "Failed to initialise bonded device");
1478 /* Generate test bursts of packets to transmit */
1479 TEST_ASSERT_EQUAL(generate_test_burst(pkt_burst,
1480 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE, 0, 1, 0, 0, 0),
1481 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE,
1482 "Failed to generate test packet burst");
1484 /* Copy references to packets which we expect not to be transmitted */
1485 first_fail_idx = (TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1486 (TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT *
1487 TEST_RR_SLAVE_TX_FAIL_SLAVE_COUNT)) +
1488 TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX;
1490 for (i = 0; i < TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT; i++) {
1491 expected_tx_fail_pkts[i] = pkt_burst[first_fail_idx +
1492 (i * TEST_RR_SLAVE_TX_FAIL_SLAVE_COUNT)];
1495 /* Set virtual slave to only fail transmission of
1496 * TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT packets in burst */
1497 virtual_ethdev_tx_burst_fn_set_success(
1498 test_params->slave_port_ids[TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX],
1501 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
1502 test_params->slave_port_ids[TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX],
1503 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT);
1505 tx_count = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkt_burst,
1506 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE);
1508 TEST_ASSERT_EQUAL(tx_count, TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1509 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT,
1510 "Transmitted (%d) an unexpected (%d) number of packets", tx_count,
1511 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1512 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT);
1514 /* Verify that failed packet are expected failed packets */
1515 for (i = 0; i < TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT; i++) {
1516 TEST_ASSERT_EQUAL(expected_tx_fail_pkts[i], pkt_burst[i + tx_count],
1517 "expected mbuf (%d) pointer %p not expected pointer %p",
1518 i, expected_tx_fail_pkts[i], pkt_burst[i + tx_count]);
1521 /* Verify bonded port tx stats */
1522 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1524 TEST_ASSERT_EQUAL(port_stats.opackets,
1525 (uint64_t)TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1526 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT,
1527 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
1528 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
1529 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1530 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT);
1532 /* Verify slave ports tx stats */
1533 for (i = 0; i < test_params->bonded_slave_count; i++) {
1534 int slave_expected_tx_count;
1536 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
1538 slave_expected_tx_count = TEST_RR_SLAVE_TX_FAIL_BURST_SIZE /
1539 test_params->bonded_slave_count;
1541 if (i == TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX)
1542 slave_expected_tx_count = slave_expected_tx_count -
1543 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT;
1545 TEST_ASSERT_EQUAL(port_stats.opackets,
1546 (uint64_t)slave_expected_tx_count,
1547 "Slave Port (%d) opackets value (%u) not as expected (%d)",
1548 test_params->slave_port_ids[i],
1549 (unsigned int)port_stats.opackets, slave_expected_tx_count);
1552 /* Verify that all mbufs have a ref value of zero */
1553 TEST_ASSERT_SUCCESS(verify_mbufs_ref_count(&pkt_burst[tx_count],
1554 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT, 1),
1555 "mbufs refcnts not as expected");
1556 free_mbufs(&pkt_burst[tx_count], TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT);
1558 /* Clean up and remove slaves from bonded device */
1559 return remove_slaves_and_stop_bonded_device();
1563 test_roundrobin_rx_burst_on_single_slave(void)
1565 struct rte_mbuf *gen_pkt_burst[MAX_PKT_BURST] = { NULL };
1566 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1568 struct rte_eth_stats port_stats;
1570 int i, j, burst_size = 25;
1572 /* Initialize bonded device with 4 slaves in round robin mode */
1573 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1574 BONDING_MODE_ROUND_ROBIN, 0, 4, 1),
1575 "Failed to initialize bonded device with slaves");
1577 /* Generate test bursts of packets to transmit */
1578 TEST_ASSERT_EQUAL(generate_test_burst(
1579 gen_pkt_burst, burst_size, 0, 1, 0, 0, 0), burst_size,
1580 "burst generation failed");
1582 for (i = 0; i < test_params->bonded_slave_count; i++) {
1583 /* Add rx data to slave */
1584 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1585 &gen_pkt_burst[0], burst_size);
1587 /* Call rx burst on bonded device */
1588 /* Send burst on bonded port */
1589 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
1590 test_params->bonded_port_id, 0, rx_pkt_burst,
1591 MAX_PKT_BURST), burst_size,
1592 "round-robin rx burst failed");
1594 /* Verify bonded device rx count */
1595 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1596 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
1597 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
1598 test_params->bonded_port_id,
1599 (unsigned int)port_stats.ipackets, burst_size);
1603 /* Verify bonded slave devices rx count */
1604 /* Verify slave ports tx stats */
1605 for (j = 0; j < test_params->bonded_slave_count; j++) {
1606 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
1609 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
1610 "Slave Port (%d) ipackets value (%u) not as expected"
1611 " (%d)", test_params->slave_port_ids[i],
1612 (unsigned int)port_stats.ipackets, burst_size);
1614 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
1615 "Slave Port (%d) ipackets value (%u) not as expected"
1616 " (%d)", test_params->slave_port_ids[i],
1617 (unsigned int)port_stats.ipackets, 0);
1620 /* Reset bonded slaves stats */
1621 rte_eth_stats_reset(test_params->slave_port_ids[j]);
1623 /* reset bonded device stats */
1624 rte_eth_stats_reset(test_params->bonded_port_id);
1628 for (i = 0; i < MAX_PKT_BURST; i++) {
1629 if (rx_pkt_burst[i] != NULL)
1630 rte_pktmbuf_free(rx_pkt_burst[i]);
1634 /* Clean up and remove slaves from bonded device */
1635 return remove_slaves_and_stop_bonded_device();
1638 #define TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT (3)
1641 test_roundrobin_rx_burst_on_multiple_slaves(void)
1643 struct rte_mbuf *gen_pkt_burst[TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
1645 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1646 struct rte_eth_stats port_stats;
1648 int burst_size[TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT] = { 15, 13, 36 };
1651 /* Initialize bonded device with 4 slaves in round robin mode */
1652 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1653 BONDING_MODE_ROUND_ROBIN, 0, 4, 1),
1654 "Failed to initialize bonded device with slaves");
1656 /* Generate test bursts of packets to transmit */
1657 for (i = 0; i < TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT; i++) {
1658 TEST_ASSERT_EQUAL(generate_test_burst(
1659 &gen_pkt_burst[i][0], burst_size[i], 0, 1, 0, 0, 0),
1660 burst_size[i], "burst generation failed");
1663 /* Add rx data to slaves */
1664 for (i = 0; i < TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT; i++) {
1665 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1666 &gen_pkt_burst[i][0], burst_size[i]);
1669 /* Call rx burst on bonded device */
1670 /* Send burst on bonded port */
1671 nb_rx = rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
1673 TEST_ASSERT_EQUAL(nb_rx , burst_size[0] + burst_size[1] + burst_size[2],
1674 "round-robin rx burst failed (%d != %d)\n", nb_rx,
1675 burst_size[0] + burst_size[1] + burst_size[2]);
1677 /* Verify bonded device rx count */
1678 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1679 TEST_ASSERT_EQUAL(port_stats.ipackets,
1680 (uint64_t)(burst_size[0] + burst_size[1] + burst_size[2]),
1681 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
1682 test_params->bonded_port_id, (unsigned int)port_stats.ipackets,
1683 burst_size[0] + burst_size[1] + burst_size[2]);
1685 /* Verify bonded slave devices rx counts */
1686 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
1687 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[0],
1688 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
1689 test_params->slave_port_ids[0],
1690 (unsigned int)port_stats.ipackets, burst_size[0]);
1692 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
1693 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[1],
1694 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
1695 test_params->slave_port_ids[1], (unsigned int)port_stats.ipackets,
1698 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
1699 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[2],
1700 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
1701 test_params->slave_port_ids[2],
1702 (unsigned int)port_stats.ipackets, burst_size[2]);
1704 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
1705 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
1706 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
1707 test_params->slave_port_ids[3],
1708 (unsigned int)port_stats.ipackets, 0);
1711 for (i = 0; i < MAX_PKT_BURST; i++) {
1712 if (rx_pkt_burst[i] != NULL)
1713 rte_pktmbuf_free(rx_pkt_burst[i]);
1716 /* Clean up and remove slaves from bonded device */
1717 return remove_slaves_and_stop_bonded_device();
1721 test_roundrobin_verify_mac_assignment(void)
1723 struct ether_addr read_mac_addr, expected_mac_addr_0, expected_mac_addr_2;
1727 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
1728 rte_eth_macaddr_get(test_params->slave_port_ids[2], &expected_mac_addr_2);
1730 /* Initialize bonded device with 4 slaves in round robin mode */
1731 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1732 BONDING_MODE_ROUND_ROBIN, 0, 4, 1),
1733 "Failed to initialize bonded device with slaves");
1735 /* Verify that all MACs are the same as first slave added to bonded dev */
1736 for (i = 0; i < test_params->bonded_slave_count; i++) {
1737 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1738 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
1739 sizeof(read_mac_addr)),
1740 "slave port (%d) mac address not set to that of primary port",
1741 test_params->slave_port_ids[i]);
1744 /* change primary and verify that MAC addresses haven't changed */
1745 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(test_params->bonded_port_id,
1746 test_params->slave_port_ids[2]),
1747 "Failed to set bonded port (%d) primary port to (%d)",
1748 test_params->bonded_port_id, test_params->slave_port_ids[i]);
1750 for (i = 0; i < test_params->bonded_slave_count; i++) {
1751 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1752 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
1753 sizeof(read_mac_addr)),
1754 "slave port (%d) mac address has changed to that of primary"
1755 " port without stop/start toggle of bonded device",
1756 test_params->slave_port_ids[i]);
1759 /* stop / start bonded device and verify that primary MAC address is
1760 * propagate to bonded device and slaves */
1761 rte_eth_dev_stop(test_params->bonded_port_id);
1763 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
1764 "Failed to start bonded device");
1766 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
1767 TEST_ASSERT_SUCCESS(
1768 memcmp(&expected_mac_addr_2, &read_mac_addr, sizeof(read_mac_addr)),
1769 "bonded port (%d) mac address not set to that of new primary port",
1770 test_params->slave_port_ids[i]);
1772 for (i = 0; i < test_params->bonded_slave_count; i++) {
1773 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1774 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_2, &read_mac_addr,
1775 sizeof(read_mac_addr)),
1776 "slave port (%d) mac address not set to that of new primary"
1777 " port", test_params->slave_port_ids[i]);
1780 /* Set explicit MAC address */
1781 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
1782 test_params->bonded_port_id, (struct ether_addr *)bonded_mac),
1783 "Failed to set MAC");
1785 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
1786 TEST_ASSERT_SUCCESS(memcmp(bonded_mac, &read_mac_addr,
1787 sizeof(read_mac_addr)),
1788 "bonded port (%d) mac address not set to that of new primary port",
1789 test_params->slave_port_ids[i]);
1791 for (i = 0; i < test_params->bonded_slave_count; i++) {
1792 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1793 TEST_ASSERT_SUCCESS(memcmp(bonded_mac, &read_mac_addr,
1794 sizeof(read_mac_addr)), "slave port (%d) mac address not set to"
1795 " that of new primary port\n", test_params->slave_port_ids[i]);
1798 /* Clean up and remove slaves from bonded device */
1799 return remove_slaves_and_stop_bonded_device();
1803 test_roundrobin_verify_promiscuous_enable_disable(void)
1805 int i, promiscuous_en;
1807 /* Initialize bonded device with 4 slaves in round robin mode */
1808 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1809 BONDING_MODE_ROUND_ROBIN, 0, 4, 1),
1810 "Failed to initialize bonded device with slaves");
1812 rte_eth_promiscuous_enable(test_params->bonded_port_id);
1814 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
1815 TEST_ASSERT_EQUAL(promiscuous_en, 1,
1816 "Port (%d) promiscuous mode not enabled",
1817 test_params->bonded_port_id);
1819 for (i = 0; i < test_params->bonded_slave_count; i++) {
1820 promiscuous_en = rte_eth_promiscuous_get(
1821 test_params->slave_port_ids[i]);
1822 TEST_ASSERT_EQUAL(promiscuous_en, 1,
1823 "slave port (%d) promiscuous mode not enabled",
1824 test_params->slave_port_ids[i]);
1827 rte_eth_promiscuous_disable(test_params->bonded_port_id);
1829 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
1830 TEST_ASSERT_EQUAL(promiscuous_en, 0,
1831 "Port (%d) promiscuous mode not disabled\n",
1832 test_params->bonded_port_id);
1834 for (i = 0; i < test_params->bonded_slave_count; i++) {
1835 promiscuous_en = rte_eth_promiscuous_get(
1836 test_params->slave_port_ids[i]);
1837 TEST_ASSERT_EQUAL(promiscuous_en, 0,
1838 "Port (%d) promiscuous mode not disabled\n",
1839 test_params->slave_port_ids[i]);
1842 /* Clean up and remove slaves from bonded device */
1843 return remove_slaves_and_stop_bonded_device();
1846 #define TEST_RR_LINK_STATUS_SLAVE_COUNT (4)
1847 #define TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT (2)
1850 test_roundrobin_verify_slave_link_status_change_behaviour(void)
1852 struct rte_mbuf *tx_pkt_burst[MAX_PKT_BURST] = { NULL };
1853 struct rte_mbuf *gen_pkt_burst[TEST_RR_LINK_STATUS_SLAVE_COUNT][MAX_PKT_BURST];
1854 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1856 struct rte_eth_stats port_stats;
1857 uint16_t slaves[RTE_MAX_ETHPORTS];
1859 int i, burst_size, slave_count;
1861 /* NULL all pointers in array to simplify cleanup */
1862 memset(gen_pkt_burst, 0, sizeof(gen_pkt_burst));
1864 /* Initialize bonded device with TEST_RR_LINK_STATUS_SLAVE_COUNT slaves
1865 * in round robin mode */
1866 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1867 BONDING_MODE_ROUND_ROBIN, 0, TEST_RR_LINK_STATUS_SLAVE_COUNT, 1),
1868 "Failed to initialize bonded device with slaves");
1870 /* Verify Current Slaves Count /Active Slave Count is */
1871 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
1873 TEST_ASSERT_EQUAL(slave_count, TEST_RR_LINK_STATUS_SLAVE_COUNT,
1874 "Number of slaves (%d) is not as expected (%d).",
1875 slave_count, TEST_RR_LINK_STATUS_SLAVE_COUNT);
1877 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1878 slaves, RTE_MAX_ETHPORTS);
1879 TEST_ASSERT_EQUAL(slave_count, TEST_RR_LINK_STATUS_SLAVE_COUNT,
1880 "Number of active slaves (%d) is not as expected (%d).",
1881 slave_count, TEST_RR_LINK_STATUS_SLAVE_COUNT);
1883 /* Set 2 slaves eth_devs link status to down */
1884 virtual_ethdev_simulate_link_status_interrupt(
1885 test_params->slave_port_ids[1], 0);
1886 virtual_ethdev_simulate_link_status_interrupt(
1887 test_params->slave_port_ids[3], 0);
1889 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1890 slaves, RTE_MAX_ETHPORTS);
1891 TEST_ASSERT_EQUAL(slave_count,
1892 TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT,
1893 "Number of active slaves (%d) is not as expected (%d).\n",
1894 slave_count, TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT);
1898 /* Verify that pkts are not sent on slaves with link status down:
1900 * 1. Generate test burst of traffic
1901 * 2. Transmit burst on bonded eth_dev
1902 * 3. Verify stats for bonded eth_dev (opackets = burst_size)
1903 * 4. Verify stats for slave eth_devs (s0 = 10, s1 = 0, s2 = 10, s3 = 0)
1906 generate_test_burst(tx_pkt_burst, burst_size, 0, 1, 0, 0, 0),
1907 burst_size, "generate_test_burst failed");
1909 rte_eth_stats_reset(test_params->bonded_port_id);
1913 rte_eth_tx_burst(test_params->bonded_port_id, 0, tx_pkt_burst,
1914 burst_size), burst_size, "rte_eth_tx_burst failed");
1916 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1917 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
1918 "Port (%d) opackets stats (%d) not expected (%d) value",
1919 test_params->bonded_port_id, (int)port_stats.opackets,
1922 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
1923 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)10,
1924 "Port (%d) opackets stats (%d) not expected (%d) value",
1925 test_params->slave_port_ids[0], (int)port_stats.opackets, 10);
1927 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
1928 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)0,
1929 "Port (%d) opackets stats (%d) not expected (%d) value",
1930 test_params->slave_port_ids[1], (int)port_stats.opackets, 0);
1932 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
1933 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)10,
1934 "Port (%d) opackets stats (%d) not expected (%d) value",
1935 test_params->slave_port_ids[2], (int)port_stats.opackets, 10);
1937 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
1938 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)0,
1939 "Port (%d) opackets stats (%d) not expected (%d) value",
1940 test_params->slave_port_ids[3], (int)port_stats.opackets, 0);
1942 /* Verify that pkts are not sent on slaves with link status down:
1944 * 1. Generate test bursts of traffic
1945 * 2. Add bursts on to virtual eth_devs
1946 * 3. Rx burst on bonded eth_dev, expected (burst_ size *
1947 * TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT) received
1948 * 4. Verify stats for bonded eth_dev
1949 * 6. Verify stats for slave eth_devs (s0 = 10, s1 = 0, s2 = 10, s3 = 0)
1951 for (i = 0; i < TEST_RR_LINK_STATUS_SLAVE_COUNT; i++) {
1952 TEST_ASSERT_EQUAL(generate_test_burst(
1953 &gen_pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0),
1954 burst_size, "failed to generate packet burst");
1956 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1957 &gen_pkt_burst[i][0], burst_size);
1960 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
1961 test_params->bonded_port_id, 0, rx_pkt_burst, MAX_PKT_BURST),
1962 burst_size + burst_size,
1963 "rte_eth_rx_burst failed");
1965 /* Verify bonded device rx count */
1966 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1967 TEST_ASSERT_EQUAL(port_stats.ipackets , (uint64_t)(burst_size + burst_size),
1968 "(%d) port_stats.ipackets not as expected\n",
1969 test_params->bonded_port_id);
1972 for (i = 0; i < MAX_PKT_BURST; i++) {
1973 if (rx_pkt_burst[i] != NULL)
1974 rte_pktmbuf_free(rx_pkt_burst[i]);
1977 /* Clean up and remove slaves from bonded device */
1978 return remove_slaves_and_stop_bonded_device();
1981 #define TEST_RR_POLLING_LINK_STATUS_SLAVE_COUNT (2)
1983 uint8_t polling_slave_mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00 };
1986 int polling_test_slaves[TEST_RR_POLLING_LINK_STATUS_SLAVE_COUNT] = { -1, -1 };
1989 test_roundrobin_verfiy_polling_slave_link_status_change(void)
1991 struct ether_addr *mac_addr = (struct ether_addr *)polling_slave_mac;
1992 char slave_name[RTE_ETH_NAME_MAX_LEN];
1996 for (i = 0; i < TEST_RR_POLLING_LINK_STATUS_SLAVE_COUNT; i++) {
1997 /* Generate slave name / MAC address */
1998 snprintf(slave_name, RTE_ETH_NAME_MAX_LEN, "eth_virt_poll_%d", i);
1999 mac_addr->addr_bytes[ETHER_ADDR_LEN-1] = i;
2001 /* Create slave devices with no ISR Support */
2002 if (polling_test_slaves[i] == -1) {
2003 polling_test_slaves[i] = virtual_ethdev_create(slave_name, mac_addr,
2004 rte_socket_id(), 0);
2005 TEST_ASSERT(polling_test_slaves[i] >= 0,
2006 "Failed to create virtual virtual ethdev %s\n", slave_name);
2008 /* Configure slave */
2009 TEST_ASSERT_SUCCESS(configure_ethdev(polling_test_slaves[i], 0, 0),
2010 "Failed to configure virtual ethdev %s(%d)", slave_name,
2011 polling_test_slaves[i]);
2014 /* Add slave to bonded device */
2015 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params->bonded_port_id,
2016 polling_test_slaves[i]),
2017 "Failed to add slave %s(%d) to bonded device %d",
2018 slave_name, polling_test_slaves[i],
2019 test_params->bonded_port_id);
2022 /* Initialize bonded device */
2023 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 1, 1),
2024 "Failed to configure bonded device %d",
2025 test_params->bonded_port_id);
2028 /* Register link status change interrupt callback */
2029 rte_eth_dev_callback_register(test_params->bonded_port_id,
2030 RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
2031 &test_params->bonded_port_id);
2033 /* link status change callback for first slave link up */
2034 test_lsc_interrupt_count = 0;
2036 virtual_ethdev_set_link_status(polling_test_slaves[0], 1);
2038 TEST_ASSERT_SUCCESS(lsc_timeout(15000), "timed out waiting for interrupt");
2041 /* no link status change callback for second slave link up */
2042 test_lsc_interrupt_count = 0;
2044 virtual_ethdev_set_link_status(polling_test_slaves[1], 1);
2046 TEST_ASSERT_FAIL(lsc_timeout(15000), "unexpectedly succeeded");
2048 /* link status change callback for both slave links down */
2049 test_lsc_interrupt_count = 0;
2051 virtual_ethdev_set_link_status(polling_test_slaves[0], 0);
2052 virtual_ethdev_set_link_status(polling_test_slaves[1], 0);
2054 TEST_ASSERT_SUCCESS(lsc_timeout(20000), "timed out waiting for interrupt");
2056 /* Un-Register link status change interrupt callback */
2057 rte_eth_dev_callback_unregister(test_params->bonded_port_id,
2058 RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
2059 &test_params->bonded_port_id);
2062 /* Clean up and remove slaves from bonded device */
2063 for (i = 0; i < TEST_RR_POLLING_LINK_STATUS_SLAVE_COUNT; i++) {
2065 TEST_ASSERT_SUCCESS(
2066 rte_eth_bond_slave_remove(test_params->bonded_port_id,
2067 polling_test_slaves[i]),
2068 "Failed to remove slave %d from bonded port (%d)",
2069 polling_test_slaves[i], test_params->bonded_port_id);
2072 return remove_slaves_and_stop_bonded_device();
2076 /** Active Backup Mode Tests */
2079 test_activebackup_tx_burst(void)
2081 int i, pktlen, primary_port, burst_size;
2082 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
2083 struct rte_eth_stats port_stats;
2085 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2086 BONDING_MODE_ACTIVE_BACKUP, 0, 1, 1),
2087 "Failed to initialize bonded device with slaves");
2089 initialize_eth_header(test_params->pkt_eth_hdr,
2090 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_0,
2091 ETHER_TYPE_IPv4, 0, 0);
2092 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
2094 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
2095 dst_addr_0, pktlen);
2097 burst_size = 20 * test_params->bonded_slave_count;
2099 TEST_ASSERT(burst_size < MAX_PKT_BURST,
2100 "Burst size specified is greater than supported.");
2102 /* Generate a burst of packets to transmit */
2103 TEST_ASSERT_EQUAL(generate_packet_burst(test_params->mbuf_pool, pkts_burst,
2104 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr, 1,
2105 test_params->pkt_udp_hdr, burst_size, PACKET_BURST_GEN_PKT_LEN, 1),
2106 burst_size, "failed to generate burst correctly");
2108 /* Send burst on bonded port */
2109 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst,
2110 burst_size), burst_size, "tx burst failed");
2112 /* Verify bonded port tx stats */
2113 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2114 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
2115 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
2116 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
2119 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2121 /* Verify slave ports tx stats */
2122 for (i = 0; i < test_params->bonded_slave_count; i++) {
2123 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
2124 if (test_params->slave_port_ids[i] == primary_port) {
2125 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
2126 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2127 test_params->bonded_port_id,
2128 (unsigned int)port_stats.opackets,
2129 burst_size / test_params->bonded_slave_count);
2131 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2132 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2133 test_params->bonded_port_id,
2134 (unsigned int)port_stats.opackets, 0);
2138 /* Put all slaves down and try and transmit */
2139 for (i = 0; i < test_params->bonded_slave_count; i++) {
2140 virtual_ethdev_simulate_link_status_interrupt(
2141 test_params->slave_port_ids[i], 0);
2144 /* Send burst on bonded port */
2145 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
2146 pkts_burst, burst_size), 0, "Sending empty burst failed");
2148 /* Clean up and remove slaves from bonded device */
2149 return remove_slaves_and_stop_bonded_device();
2152 #define TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT (4)
2155 test_activebackup_rx_burst(void)
2157 struct rte_mbuf *gen_pkt_burst[MAX_PKT_BURST] = { NULL };
2158 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
2160 struct rte_eth_stats port_stats;
2164 int i, j, burst_size = 17;
2166 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2167 BONDING_MODE_ACTIVE_BACKUP, 0,
2168 TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT, 1),
2169 "Failed to initialize bonded device with slaves");
2171 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2172 TEST_ASSERT(primary_port >= 0,
2173 "failed to get primary slave for bonded port (%d)",
2174 test_params->bonded_port_id);
2176 for (i = 0; i < test_params->bonded_slave_count; i++) {
2177 /* Generate test bursts of packets to transmit */
2178 TEST_ASSERT_EQUAL(generate_test_burst(
2179 &gen_pkt_burst[0], burst_size, 0, 1, 0, 0, 0),
2180 burst_size, "burst generation failed");
2182 /* Add rx data to slave */
2183 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
2184 &gen_pkt_burst[0], burst_size);
2186 /* Call rx burst on bonded device */
2187 TEST_ASSERT_EQUAL(rte_eth_rx_burst(test_params->bonded_port_id, 0,
2188 &rx_pkt_burst[0], MAX_PKT_BURST), burst_size,
2189 "rte_eth_rx_burst failed");
2191 if (test_params->slave_port_ids[i] == primary_port) {
2192 /* Verify bonded device rx count */
2193 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2194 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
2195 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
2196 test_params->bonded_port_id,
2197 (unsigned int)port_stats.ipackets, burst_size);
2199 /* Verify bonded slave devices rx count */
2200 for (j = 0; j < test_params->bonded_slave_count; j++) {
2201 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
2203 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
2204 "Slave Port (%d) ipackets value (%u) not as "
2205 "expected (%d)", test_params->slave_port_ids[i],
2206 (unsigned int)port_stats.ipackets, burst_size);
2208 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
2209 "Slave Port (%d) ipackets value (%u) not as "
2210 "expected (%d)\n", test_params->slave_port_ids[i],
2211 (unsigned int)port_stats.ipackets, 0);
2215 for (j = 0; j < test_params->bonded_slave_count; j++) {
2216 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
2217 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
2218 "Slave Port (%d) ipackets value (%u) not as expected "
2219 "(%d)", test_params->slave_port_ids[i],
2220 (unsigned int)port_stats.ipackets, 0);
2225 for (i = 0; i < MAX_PKT_BURST; i++) {
2226 if (rx_pkt_burst[i] != NULL) {
2227 rte_pktmbuf_free(rx_pkt_burst[i]);
2228 rx_pkt_burst[i] = NULL;
2232 /* reset bonded device stats */
2233 rte_eth_stats_reset(test_params->bonded_port_id);
2236 /* Clean up and remove slaves from bonded device */
2237 return remove_slaves_and_stop_bonded_device();
2241 test_activebackup_verify_promiscuous_enable_disable(void)
2243 int i, primary_port, promiscuous_en;
2245 /* Initialize bonded device with 4 slaves in round robin mode */
2246 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2247 BONDING_MODE_ACTIVE_BACKUP, 0, 4, 1),
2248 "Failed to initialize bonded device with slaves");
2250 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2251 TEST_ASSERT(primary_port >= 0,
2252 "failed to get primary slave for bonded port (%d)",
2253 test_params->bonded_port_id);
2255 rte_eth_promiscuous_enable(test_params->bonded_port_id);
2257 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 1,
2258 "Port (%d) promiscuous mode not enabled",
2259 test_params->bonded_port_id);
2261 for (i = 0; i < test_params->bonded_slave_count; i++) {
2262 promiscuous_en = rte_eth_promiscuous_get(
2263 test_params->slave_port_ids[i]);
2264 if (primary_port == test_params->slave_port_ids[i]) {
2265 TEST_ASSERT_EQUAL(promiscuous_en, 1,
2266 "slave port (%d) promiscuous mode not enabled",
2267 test_params->slave_port_ids[i]);
2269 TEST_ASSERT_EQUAL(promiscuous_en, 0,
2270 "slave port (%d) promiscuous mode enabled",
2271 test_params->slave_port_ids[i]);
2276 rte_eth_promiscuous_disable(test_params->bonded_port_id);
2278 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 0,
2279 "Port (%d) promiscuous mode not disabled\n",
2280 test_params->bonded_port_id);
2282 for (i = 0; i < test_params->bonded_slave_count; i++) {
2283 promiscuous_en = rte_eth_promiscuous_get(
2284 test_params->slave_port_ids[i]);
2285 TEST_ASSERT_EQUAL(promiscuous_en, 0,
2286 "slave port (%d) promiscuous mode not disabled\n",
2287 test_params->slave_port_ids[i]);
2290 /* Clean up and remove slaves from bonded device */
2291 return remove_slaves_and_stop_bonded_device();
2295 test_activebackup_verify_mac_assignment(void)
2297 struct ether_addr read_mac_addr, expected_mac_addr_0, expected_mac_addr_1;
2299 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
2300 rte_eth_macaddr_get(test_params->slave_port_ids[1], &expected_mac_addr_1);
2302 /* Initialize bonded device with 2 slaves in active backup mode */
2303 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2304 BONDING_MODE_ACTIVE_BACKUP, 0, 2, 1),
2305 "Failed to initialize bonded device with slaves");
2307 /* Verify that bonded MACs is that of first slave and that the other slave
2308 * MAC hasn't been changed */
2309 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2310 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2311 sizeof(read_mac_addr)),
2312 "bonded port (%d) mac address not set to that of primary port",
2313 test_params->bonded_port_id);
2315 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2316 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2317 sizeof(read_mac_addr)),
2318 "slave port (%d) mac address not set to that of primary port",
2319 test_params->slave_port_ids[0]);
2321 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2322 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
2323 sizeof(read_mac_addr)),
2324 "slave port (%d) mac address not as expected",
2325 test_params->slave_port_ids[1]);
2327 /* change primary and verify that MAC addresses haven't changed */
2328 TEST_ASSERT_EQUAL(rte_eth_bond_primary_set(test_params->bonded_port_id,
2329 test_params->slave_port_ids[1]), 0,
2330 "Failed to set bonded port (%d) primary port to (%d)",
2331 test_params->bonded_port_id, test_params->slave_port_ids[1]);
2333 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2334 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2335 sizeof(read_mac_addr)),
2336 "bonded port (%d) mac address not set to that of primary port",
2337 test_params->bonded_port_id);
2339 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2340 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2341 sizeof(read_mac_addr)),
2342 "slave port (%d) mac address not set to that of primary port",
2343 test_params->slave_port_ids[0]);
2345 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2346 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
2347 sizeof(read_mac_addr)),
2348 "slave port (%d) mac address not as expected",
2349 test_params->slave_port_ids[1]);
2351 /* stop / start bonded device and verify that primary MAC address is
2352 * propagated to bonded device and slaves */
2354 rte_eth_dev_stop(test_params->bonded_port_id);
2356 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
2357 "Failed to start device");
2359 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2360 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
2361 sizeof(read_mac_addr)),
2362 "bonded port (%d) mac address not set to that of primary port",
2363 test_params->bonded_port_id);
2365 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2366 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2367 sizeof(read_mac_addr)),
2368 "slave port (%d) mac address not as expected",
2369 test_params->slave_port_ids[0]);
2371 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2372 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
2373 sizeof(read_mac_addr)),
2374 "slave port (%d) mac address not set to that of primary port",
2375 test_params->slave_port_ids[1]);
2377 /* Set explicit MAC address */
2378 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
2379 test_params->bonded_port_id, (struct ether_addr *)bonded_mac),
2380 "failed to set MAC address");
2382 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2383 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
2384 sizeof(read_mac_addr)),
2385 "bonded port (%d) mac address not set to that of bonded port",
2386 test_params->bonded_port_id);
2388 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2389 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2390 sizeof(read_mac_addr)),
2391 "slave port (%d) mac address not as expected",
2392 test_params->slave_port_ids[0]);
2394 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2395 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
2396 sizeof(read_mac_addr)),
2397 "slave port (%d) mac address not set to that of bonded port",
2398 test_params->slave_port_ids[1]);
2400 /* Clean up and remove slaves from bonded device */
2401 return remove_slaves_and_stop_bonded_device();
2405 test_activebackup_verify_slave_link_status_change_failover(void)
2407 struct rte_mbuf *pkt_burst[TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
2408 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
2409 struct rte_eth_stats port_stats;
2411 uint16_t slaves[RTE_MAX_ETHPORTS];
2413 int i, burst_size, slave_count, primary_port;
2417 memset(pkt_burst, 0, sizeof(pkt_burst));
2419 /* Generate packet burst for testing */
2420 TEST_ASSERT_EQUAL(generate_test_burst(
2421 &pkt_burst[0][0], burst_size, 0, 1, 0, 0, 0), burst_size,
2422 "generate_test_burst failed");
2424 /* Initialize bonded device with 4 slaves in round robin mode */
2425 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2426 BONDING_MODE_ACTIVE_BACKUP, 0,
2427 TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT, 1),
2428 "Failed to initialize bonded device with slaves");
2430 /* Verify Current Slaves Count /Active Slave Count is */
2431 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
2433 TEST_ASSERT_EQUAL(slave_count, 4,
2434 "Number of slaves (%d) is not as expected (%d).",
2437 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
2438 slaves, RTE_MAX_ETHPORTS);
2439 TEST_ASSERT_EQUAL(slave_count, 4,
2440 "Number of active slaves (%d) is not as expected (%d).",
2443 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2444 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[0],
2445 "Primary port not as expected");
2447 /* Bring 2 slaves down and verify active slave count */
2448 virtual_ethdev_simulate_link_status_interrupt(
2449 test_params->slave_port_ids[1], 0);
2450 virtual_ethdev_simulate_link_status_interrupt(
2451 test_params->slave_port_ids[3], 0);
2453 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
2454 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 2,
2455 "Number of active slaves (%d) is not as expected (%d).",
2458 virtual_ethdev_simulate_link_status_interrupt(
2459 test_params->slave_port_ids[1], 1);
2460 virtual_ethdev_simulate_link_status_interrupt(
2461 test_params->slave_port_ids[3], 1);
2464 /* Bring primary port down, verify that active slave count is 3 and primary
2466 virtual_ethdev_simulate_link_status_interrupt(
2467 test_params->slave_port_ids[0], 0);
2469 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
2470 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS),
2472 "Number of active slaves (%d) is not as expected (%d).",
2475 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2476 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[2],
2477 "Primary port not as expected");
2479 /* Verify that pkts are sent on new primary slave */
2481 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
2482 test_params->bonded_port_id, 0, &pkt_burst[0][0],
2483 burst_size), burst_size, "rte_eth_tx_burst failed");
2485 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
2486 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
2487 "(%d) port_stats.opackets not as expected",
2488 test_params->slave_port_ids[2]);
2490 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2491 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2492 "(%d) port_stats.opackets not as expected\n",
2493 test_params->slave_port_ids[0]);
2495 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2496 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2497 "(%d) port_stats.opackets not as expected\n",
2498 test_params->slave_port_ids[1]);
2500 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
2501 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2502 "(%d) port_stats.opackets not as expected\n",
2503 test_params->slave_port_ids[3]);
2505 /* Generate packet burst for testing */
2507 for (i = 0; i < TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT; i++) {
2508 TEST_ASSERT_EQUAL(generate_test_burst(
2509 &pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0), burst_size,
2510 "generate_test_burst failed");
2512 virtual_ethdev_add_mbufs_to_rx_queue(
2513 test_params->slave_port_ids[i], &pkt_burst[i][0], burst_size);
2516 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
2517 test_params->bonded_port_id, 0, rx_pkt_burst, MAX_PKT_BURST),
2518 burst_size, "rte_eth_rx_burst\n");
2520 /* Verify bonded device rx count */
2521 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2522 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
2523 "(%d) port_stats.ipackets not as expected",
2524 test_params->bonded_port_id);
2526 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
2527 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
2528 "(%d) port_stats.opackets not as expected",
2529 test_params->slave_port_ids[2]);
2531 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2532 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2533 "(%d) port_stats.opackets not as expected",
2534 test_params->slave_port_ids[0]);
2536 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2537 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2538 "(%d) port_stats.opackets not as expected",
2539 test_params->slave_port_ids[1]);
2541 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
2542 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2543 "(%d) port_stats.opackets not as expected",
2544 test_params->slave_port_ids[3]);
2546 /* Clean up and remove slaves from bonded device */
2547 return remove_slaves_and_stop_bonded_device();
2550 /** Balance Mode Tests */
2553 test_balance_xmit_policy_configuration(void)
2555 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2556 BONDING_MODE_ACTIVE_BACKUP, 0, 2, 1),
2557 "Failed to initialize_bonded_device_with_slaves.");
2559 /* Invalid port id */
2560 TEST_ASSERT_FAIL(rte_eth_bond_xmit_policy_set(
2561 INVALID_PORT_ID, BALANCE_XMIT_POLICY_LAYER2),
2562 "Expected call to failed as invalid port specified.");
2564 /* Set xmit policy on non bonded device */
2565 TEST_ASSERT_FAIL(rte_eth_bond_xmit_policy_set(
2566 test_params->slave_port_ids[0], BALANCE_XMIT_POLICY_LAYER2),
2567 "Expected call to failed as invalid port specified.");
2570 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2571 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER2),
2572 "Failed to set balance xmit policy.");
2574 TEST_ASSERT_EQUAL(rte_eth_bond_xmit_policy_get(test_params->bonded_port_id),
2575 BALANCE_XMIT_POLICY_LAYER2, "balance xmit policy not as expected.");
2578 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2579 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER23),
2580 "Failed to set balance xmit policy.");
2582 TEST_ASSERT_EQUAL(rte_eth_bond_xmit_policy_get(test_params->bonded_port_id),
2583 BALANCE_XMIT_POLICY_LAYER23,
2584 "balance xmit policy not as expected.");
2587 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2588 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER34),
2589 "Failed to set balance xmit policy.");
2591 TEST_ASSERT_EQUAL(rte_eth_bond_xmit_policy_get(test_params->bonded_port_id),
2592 BALANCE_XMIT_POLICY_LAYER34,
2593 "balance xmit policy not as expected.");
2595 /* Invalid port id */
2596 TEST_ASSERT_FAIL(rte_eth_bond_xmit_policy_get(INVALID_PORT_ID),
2597 "Expected call to failed as invalid port specified.");
2599 /* Clean up and remove slaves from bonded device */
2600 return remove_slaves_and_stop_bonded_device();
2603 #define TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT (2)
2606 test_balance_l2_tx_burst(void)
2608 struct rte_mbuf *pkts_burst[TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
2609 int burst_size[TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT] = { 10, 15 };
2613 struct rte_eth_stats port_stats;
2615 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2616 BONDING_MODE_BALANCE, 0, TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT, 1),
2617 "Failed to initialize_bonded_device_with_slaves.");
2619 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2620 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER2),
2621 "Failed to set balance xmit policy.");
2623 initialize_eth_header(test_params->pkt_eth_hdr,
2624 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_0,
2625 ETHER_TYPE_IPv4, 0, 0);
2626 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
2628 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
2629 dst_addr_0, pktlen);
2631 /* Generate a burst 1 of packets to transmit */
2632 TEST_ASSERT_EQUAL(generate_packet_burst(test_params->mbuf_pool, &pkts_burst[0][0],
2633 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr, 1,
2634 test_params->pkt_udp_hdr, burst_size[0],
2635 PACKET_BURST_GEN_PKT_LEN, 1), burst_size[0],
2636 "failed to generate packet burst");
2638 initialize_eth_header(test_params->pkt_eth_hdr,
2639 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_1,
2640 ETHER_TYPE_IPv4, 0, 0);
2642 /* Generate a burst 2 of packets to transmit */
2643 TEST_ASSERT_EQUAL(generate_packet_burst(test_params->mbuf_pool, &pkts_burst[1][0],
2644 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr, 1,
2645 test_params->pkt_udp_hdr, burst_size[1],
2646 PACKET_BURST_GEN_PKT_LEN, 1), burst_size[1],
2647 "failed to generate packet burst");
2649 /* Send burst 1 on bonded port */
2650 for (i = 0; i < TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT; i++) {
2651 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
2652 &pkts_burst[i][0], burst_size[i]),
2653 burst_size[i], "Failed to transmit packet burst");
2656 /* Verify bonded port tx stats */
2657 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2658 TEST_ASSERT_EQUAL(port_stats.opackets,
2659 (uint64_t)(burst_size[0] + burst_size[1]),
2660 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
2661 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
2662 burst_size[0] + burst_size[1]);
2665 /* Verify slave ports tx stats */
2666 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2667 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size[0],
2668 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2669 test_params->slave_port_ids[0], (unsigned int)port_stats.opackets,
2672 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2673 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size[1],
2674 "Slave Port (%d) opackets value (%u) not as expected (%d)\n",
2675 test_params->slave_port_ids[1], (unsigned int)port_stats.opackets,
2678 /* Put all slaves down and try and transmit */
2679 for (i = 0; i < test_params->bonded_slave_count; i++) {
2681 virtual_ethdev_simulate_link_status_interrupt(
2682 test_params->slave_port_ids[i], 0);
2685 /* Send burst on bonded port */
2686 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
2687 test_params->bonded_port_id, 0, &pkts_burst[0][0], burst_size[0]),
2688 0, "Expected zero packet");
2690 /* Clean up and remove slaves from bonded device */
2691 return remove_slaves_and_stop_bonded_device();
2695 balance_l23_tx_burst(uint8_t vlan_enabled, uint8_t ipv4,
2696 uint8_t toggle_mac_addr, uint8_t toggle_ip_addr)
2698 int i, burst_size_1, burst_size_2, nb_tx_1, nb_tx_2;
2700 struct rte_mbuf *pkts_burst_1[MAX_PKT_BURST];
2701 struct rte_mbuf *pkts_burst_2[MAX_PKT_BURST];
2703 struct rte_eth_stats port_stats;
2705 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2706 BONDING_MODE_BALANCE, 0, 2, 1),
2707 "Failed to initialize_bonded_device_with_slaves.");
2709 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2710 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER23),
2711 "Failed to set balance xmit policy.");
2716 TEST_ASSERT(burst_size_1 < MAX_PKT_BURST || burst_size_2 < MAX_PKT_BURST,
2717 "Burst size specified is greater than supported.");
2719 /* Generate test bursts of packets to transmit */
2720 TEST_ASSERT_EQUAL(generate_test_burst(
2721 pkts_burst_1, burst_size_1, vlan_enabled, ipv4, 0, 0, 0),
2722 burst_size_1, "failed to generate packet burst");
2724 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst_2, burst_size_2, vlan_enabled, ipv4,
2725 toggle_mac_addr, toggle_ip_addr, 0), burst_size_2,
2726 "failed to generate packet burst");
2728 /* Send burst 1 on bonded port */
2729 nb_tx_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2731 TEST_ASSERT_EQUAL(nb_tx_1, burst_size_1, "tx burst failed");
2733 /* Send burst 2 on bonded port */
2734 nb_tx_2 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_2,
2736 TEST_ASSERT_EQUAL(nb_tx_2, burst_size_2, "tx burst failed");
2738 /* Verify bonded port tx stats */
2739 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2740 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(nb_tx_1 + nb_tx_2),
2741 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
2742 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
2745 /* Verify slave ports tx stats */
2746 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2747 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)nb_tx_1,
2748 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2749 test_params->slave_port_ids[0], (unsigned int)port_stats.opackets,
2752 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2753 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)nb_tx_2,
2754 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2755 test_params->slave_port_ids[1], (unsigned int)port_stats.opackets,
2758 /* Put all slaves down and try and transmit */
2759 for (i = 0; i < test_params->bonded_slave_count; i++) {
2761 virtual_ethdev_simulate_link_status_interrupt(
2762 test_params->slave_port_ids[i], 0);
2765 /* Send burst on bonded port */
2766 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
2767 test_params->bonded_port_id, 0, pkts_burst_1,
2768 burst_size_1), 0, "Expected zero packet");
2771 /* Clean up and remove slaves from bonded device */
2772 return remove_slaves_and_stop_bonded_device();
2776 test_balance_l23_tx_burst_ipv4_toggle_ip_addr(void)
2778 return balance_l23_tx_burst(0, 1, 0, 1);
2782 test_balance_l23_tx_burst_vlan_ipv4_toggle_ip_addr(void)
2784 return balance_l23_tx_burst(1, 1, 0, 1);
2788 test_balance_l23_tx_burst_ipv6_toggle_ip_addr(void)
2790 return balance_l23_tx_burst(0, 0, 0, 1);
2794 test_balance_l23_tx_burst_vlan_ipv6_toggle_ip_addr(void)
2796 return balance_l23_tx_burst(1, 0, 0, 1);
2800 test_balance_l23_tx_burst_toggle_mac_addr(void)
2802 return balance_l23_tx_burst(0, 0, 1, 0);
2806 balance_l34_tx_burst(uint8_t vlan_enabled, uint8_t ipv4,
2807 uint8_t toggle_mac_addr, uint8_t toggle_ip_addr,
2808 uint8_t toggle_udp_port)
2810 int i, burst_size_1, burst_size_2, nb_tx_1, nb_tx_2;
2812 struct rte_mbuf *pkts_burst_1[MAX_PKT_BURST];
2813 struct rte_mbuf *pkts_burst_2[MAX_PKT_BURST];
2815 struct rte_eth_stats port_stats;
2817 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2818 BONDING_MODE_BALANCE, 0, 2, 1),
2819 "Failed to initialize_bonded_device_with_slaves.");
2821 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2822 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER34),
2823 "Failed to set balance xmit policy.");
2828 TEST_ASSERT(burst_size_1 < MAX_PKT_BURST || burst_size_2 < MAX_PKT_BURST,
2829 "Burst size specified is greater than supported.");
2831 /* Generate test bursts of packets to transmit */
2832 TEST_ASSERT_EQUAL(generate_test_burst(
2833 pkts_burst_1, burst_size_1, vlan_enabled, ipv4, 0, 0, 0),
2834 burst_size_1, "failed to generate burst");
2836 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst_2, burst_size_2,
2837 vlan_enabled, ipv4, toggle_mac_addr, toggle_ip_addr,
2838 toggle_udp_port), burst_size_2, "failed to generate burst");
2840 /* Send burst 1 on bonded port */
2841 nb_tx_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2843 TEST_ASSERT_EQUAL(nb_tx_1, burst_size_1, "tx burst failed");
2845 /* Send burst 2 on bonded port */
2846 nb_tx_2 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_2,
2848 TEST_ASSERT_EQUAL(nb_tx_2, burst_size_2, "tx burst failed");
2851 /* Verify bonded port tx stats */
2852 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2853 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(nb_tx_1 + nb_tx_2),
2854 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
2855 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
2858 /* Verify slave ports tx stats */
2859 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2860 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)nb_tx_1,
2861 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2862 test_params->slave_port_ids[0], (unsigned int)port_stats.opackets,
2865 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2866 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)nb_tx_2,
2867 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2868 test_params->slave_port_ids[1], (unsigned int)port_stats.opackets,
2871 /* Put all slaves down and try and transmit */
2872 for (i = 0; i < test_params->bonded_slave_count; i++) {
2874 virtual_ethdev_simulate_link_status_interrupt(
2875 test_params->slave_port_ids[i], 0);
2878 /* Send burst on bonded port */
2879 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
2880 test_params->bonded_port_id, 0, pkts_burst_1,
2881 burst_size_1), 0, "Expected zero packet");
2883 /* Clean up and remove slaves from bonded device */
2884 return remove_slaves_and_stop_bonded_device();
2888 test_balance_l34_tx_burst_ipv4_toggle_ip_addr(void)
2890 return balance_l34_tx_burst(0, 1, 0, 1, 0);
2894 test_balance_l34_tx_burst_ipv4_toggle_udp_port(void)
2896 return balance_l34_tx_burst(0, 1, 0, 0, 1);
2900 test_balance_l34_tx_burst_vlan_ipv4_toggle_ip_addr(void)
2902 return balance_l34_tx_burst(1, 1, 0, 1, 0);
2906 test_balance_l34_tx_burst_ipv6_toggle_ip_addr(void)
2908 return balance_l34_tx_burst(0, 0, 0, 1, 0);
2912 test_balance_l34_tx_burst_vlan_ipv6_toggle_ip_addr(void)
2914 return balance_l34_tx_burst(1, 0, 0, 1, 0);
2918 test_balance_l34_tx_burst_ipv6_toggle_udp_port(void)
2920 return balance_l34_tx_burst(0, 0, 0, 0, 1);
2923 #define TEST_BAL_SLAVE_TX_FAIL_SLAVE_COUNT (2)
2924 #define TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 (40)
2925 #define TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2 (20)
2926 #define TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT (25)
2927 #define TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX (0)
2930 test_balance_tx_burst_slave_tx_fail(void)
2932 struct rte_mbuf *pkts_burst_1[TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1];
2933 struct rte_mbuf *pkts_burst_2[TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2];
2935 struct rte_mbuf *expected_fail_pkts[TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT];
2937 struct rte_eth_stats port_stats;
2939 int i, first_tx_fail_idx, tx_count_1, tx_count_2;
2941 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2942 BONDING_MODE_BALANCE, 0,
2943 TEST_BAL_SLAVE_TX_FAIL_SLAVE_COUNT, 1),
2944 "Failed to initialise bonded device");
2946 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2947 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER2),
2948 "Failed to set balance xmit policy.");
2951 /* Generate test bursts for transmission */
2952 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst_1,
2953 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1, 0, 0, 0, 0, 0),
2954 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1,
2955 "Failed to generate test packet burst 1");
2957 first_tx_fail_idx = TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
2958 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT;
2960 /* copy mbuf referneces for expected transmission failures */
2961 for (i = 0; i < TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT; i++)
2962 expected_fail_pkts[i] = pkts_burst_1[i + first_tx_fail_idx];
2964 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst_2,
2965 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2, 0, 0, 1, 0, 0),
2966 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2,
2967 "Failed to generate test packet burst 2");
2970 /* Set virtual slave TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX to only fail
2971 * transmission of TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT packets of burst */
2972 virtual_ethdev_tx_burst_fn_set_success(
2973 test_params->slave_port_ids[TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX],
2976 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
2977 test_params->slave_port_ids[TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX],
2978 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT);
2981 /* Transmit burst 1 */
2982 tx_count_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2983 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1);
2985 TEST_ASSERT_EQUAL(tx_count_1, TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
2986 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT,
2987 "Transmitted (%d) packets, expected to transmit (%d) packets",
2988 tx_count_1, TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
2989 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT);
2991 /* Verify that failed packet are expected failed packets */
2992 for (i = 0; i < TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT; i++) {
2993 TEST_ASSERT_EQUAL(expected_fail_pkts[i], pkts_burst_1[i + tx_count_1],
2994 "expected mbuf (%d) pointer %p not expected pointer %p",
2995 i, expected_fail_pkts[i], pkts_burst_1[i + tx_count_1]);
2998 /* Transmit burst 2 */
2999 tx_count_2 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_2,
3000 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2);
3002 TEST_ASSERT_EQUAL(tx_count_2, TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2,
3003 "Transmitted (%d) packets, expected to transmit (%d) packets",
3004 tx_count_2, TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2);
3007 /* Verify bonded port tx stats */
3008 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3010 TEST_ASSERT_EQUAL(port_stats.opackets,
3011 (uint64_t)((TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
3012 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT) +
3013 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2),
3014 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
3015 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3016 (TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
3017 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT) +
3018 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2);
3020 /* Verify slave ports tx stats */
3022 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3024 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)
3025 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
3026 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT,
3027 "Slave Port (%d) opackets value (%u) not as expected (%d)",
3028 test_params->slave_port_ids[0],
3029 (unsigned int)port_stats.opackets,
3030 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
3031 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT);
3036 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3038 TEST_ASSERT_EQUAL(port_stats.opackets,
3039 (uint64_t)TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2,
3040 "Slave Port (%d) opackets value (%u) not as expected (%d)",
3041 test_params->slave_port_ids[1],
3042 (unsigned int)port_stats.opackets,
3043 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2);
3045 /* Verify that all mbufs have a ref value of zero */
3046 TEST_ASSERT_SUCCESS(verify_mbufs_ref_count(&pkts_burst_1[tx_count_1],
3047 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT, 1),
3048 "mbufs refcnts not as expected");
3050 free_mbufs(&pkts_burst_1[tx_count_1],
3051 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT);
3053 /* Clean up and remove slaves from bonded device */
3054 return remove_slaves_and_stop_bonded_device();
3057 #define TEST_BALANCE_RX_BURST_SLAVE_COUNT (3)
3060 test_balance_rx_burst(void)
3062 struct rte_mbuf *gen_pkt_burst[TEST_BALANCE_RX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
3064 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3065 struct rte_eth_stats port_stats;
3067 int burst_size[TEST_BALANCE_RX_BURST_SLAVE_COUNT] = { 10, 5, 30 };
3070 memset(gen_pkt_burst, 0, sizeof(gen_pkt_burst));
3072 /* Initialize bonded device with 4 slaves in round robin mode */
3073 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3074 BONDING_MODE_BALANCE, 0, 3, 1),
3075 "Failed to initialise bonded device");
3077 /* Generate test bursts of packets to transmit */
3078 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
3079 TEST_ASSERT_EQUAL(generate_test_burst(
3080 &gen_pkt_burst[i][0], burst_size[i], 0, 0, 1,
3081 0, 0), burst_size[i],
3082 "failed to generate packet burst");
3085 /* Add rx data to slaves */
3086 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
3087 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3088 &gen_pkt_burst[i][0], burst_size[i]);
3091 /* Call rx burst on bonded device */
3092 /* Send burst on bonded port */
3093 TEST_ASSERT_EQUAL(rte_eth_rx_burst(test_params->bonded_port_id, 0,
3094 rx_pkt_burst, MAX_PKT_BURST),
3095 burst_size[0] + burst_size[1] + burst_size[2],
3096 "balance rx burst failed\n");
3098 /* Verify bonded device rx count */
3099 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3100 TEST_ASSERT_EQUAL(port_stats.ipackets,
3101 (uint64_t)(burst_size[0] + burst_size[1] + burst_size[2]),
3102 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
3103 test_params->bonded_port_id, (unsigned int)port_stats.ipackets,
3104 burst_size[0] + burst_size[1] + burst_size[2]);
3107 /* Verify bonded slave devices rx counts */
3108 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3109 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[0],
3110 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3111 test_params->slave_port_ids[0],
3112 (unsigned int)port_stats.ipackets, burst_size[0]);
3114 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3115 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[1],
3116 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3117 test_params->slave_port_ids[1], (unsigned int)port_stats.ipackets,
3120 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3121 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[2],
3122 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3123 test_params->slave_port_ids[2], (unsigned int)port_stats.ipackets,
3126 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
3127 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
3128 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3129 test_params->slave_port_ids[3], (unsigned int)port_stats.ipackets,
3133 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
3134 for (j = 0; j < MAX_PKT_BURST; j++) {
3135 if (gen_pkt_burst[i][j] != NULL) {
3136 rte_pktmbuf_free(gen_pkt_burst[i][j]);
3137 gen_pkt_burst[i][j] = NULL;
3142 /* Clean up and remove slaves from bonded device */
3143 return remove_slaves_and_stop_bonded_device();
3147 test_balance_verify_promiscuous_enable_disable(void)
3151 /* Initialize bonded device with 4 slaves in round robin mode */
3152 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3153 BONDING_MODE_BALANCE, 0, 4, 1),
3154 "Failed to initialise bonded device");
3156 rte_eth_promiscuous_enable(test_params->bonded_port_id);
3158 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 1,
3159 "Port (%d) promiscuous mode not enabled",
3160 test_params->bonded_port_id);
3162 for (i = 0; i < test_params->bonded_slave_count; i++) {
3163 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(
3164 test_params->slave_port_ids[i]), 1,
3165 "Port (%d) promiscuous mode not enabled",
3166 test_params->slave_port_ids[i]);
3169 rte_eth_promiscuous_disable(test_params->bonded_port_id);
3171 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 0,
3172 "Port (%d) promiscuous mode not disabled",
3173 test_params->bonded_port_id);
3175 for (i = 0; i < test_params->bonded_slave_count; i++) {
3176 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(
3177 test_params->slave_port_ids[i]), 0,
3178 "Port (%d) promiscuous mode not disabled",
3179 test_params->slave_port_ids[i]);
3182 /* Clean up and remove slaves from bonded device */
3183 return remove_slaves_and_stop_bonded_device();
3187 test_balance_verify_mac_assignment(void)
3189 struct ether_addr read_mac_addr, expected_mac_addr_0, expected_mac_addr_1;
3191 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
3192 rte_eth_macaddr_get(test_params->slave_port_ids[1], &expected_mac_addr_1);
3194 /* Initialize bonded device with 2 slaves in active backup mode */
3195 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3196 BONDING_MODE_BALANCE, 0, 2, 1),
3197 "Failed to initialise bonded device");
3199 /* Verify that bonded MACs is that of first slave and that the other slave
3200 * MAC hasn't been changed */
3201 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3202 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3203 sizeof(read_mac_addr)),
3204 "bonded port (%d) mac address not set to that of primary port",
3205 test_params->bonded_port_id);
3207 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
3208 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3209 sizeof(read_mac_addr)),
3210 "slave port (%d) mac address not set to that of primary port",
3211 test_params->slave_port_ids[0]);
3213 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
3214 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3215 sizeof(read_mac_addr)),
3216 "slave port (%d) mac address not set to that of primary port",
3217 test_params->slave_port_ids[1]);
3219 /* change primary and verify that MAC addresses haven't changed */
3220 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(test_params->bonded_port_id,
3221 test_params->slave_port_ids[1]),
3222 "Failed to set bonded port (%d) primary port to (%d)\n",
3223 test_params->bonded_port_id, test_params->slave_port_ids[1]);
3225 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3226 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3227 sizeof(read_mac_addr)),
3228 "bonded port (%d) mac address not set to that of primary port",
3229 test_params->bonded_port_id);
3231 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
3232 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3233 sizeof(read_mac_addr)),
3234 "slave port (%d) mac address not set to that of primary port",
3235 test_params->slave_port_ids[0]);
3237 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
3238 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3239 sizeof(read_mac_addr)),
3240 "slave port (%d) mac address not set to that of primary port",
3241 test_params->slave_port_ids[1]);
3243 /* stop / start bonded device and verify that primary MAC address is
3244 * propagated to bonded device and slaves */
3246 rte_eth_dev_stop(test_params->bonded_port_id);
3248 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
3249 "Failed to start bonded device");
3251 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3252 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3253 sizeof(read_mac_addr)),
3254 "bonded port (%d) mac address not set to that of primary port",
3255 test_params->bonded_port_id);
3257 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
3258 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3259 sizeof(read_mac_addr)),
3260 "slave port (%d) mac address not set to that of primary port",
3261 test_params->slave_port_ids[0]);
3263 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
3264 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3265 sizeof(read_mac_addr)),
3266 "slave port (%d) mac address not set to that of primary port",
3267 test_params->slave_port_ids[1]);
3269 /* Set explicit MAC address */
3270 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
3271 test_params->bonded_port_id, (struct ether_addr *)bonded_mac),
3272 "failed to set MAC");
3274 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3275 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
3276 sizeof(read_mac_addr)),
3277 "bonded port (%d) mac address not set to that of bonded port",
3278 test_params->bonded_port_id);
3280 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
3281 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
3282 sizeof(read_mac_addr)),
3283 "slave port (%d) mac address not as expected\n",
3284 test_params->slave_port_ids[0]);
3286 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
3287 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
3288 sizeof(read_mac_addr)),
3289 "slave port (%d) mac address not set to that of bonded port",
3290 test_params->slave_port_ids[1]);
3292 /* Clean up and remove slaves from bonded device */
3293 return remove_slaves_and_stop_bonded_device();
3296 #define TEST_BALANCE_LINK_STATUS_SLAVE_COUNT (4)
3299 test_balance_verify_slave_link_status_change_behaviour(void)
3301 struct rte_mbuf *pkt_burst[TEST_BALANCE_LINK_STATUS_SLAVE_COUNT][MAX_PKT_BURST];
3302 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3303 struct rte_eth_stats port_stats;
3305 uint16_t slaves[RTE_MAX_ETHPORTS];
3307 int i, burst_size, slave_count;
3309 memset(pkt_burst, 0, sizeof(pkt_burst));
3311 /* Initialize bonded device with 4 slaves in round robin mode */
3312 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3313 BONDING_MODE_BALANCE, 0, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT, 1),
3314 "Failed to initialise bonded device");
3316 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
3317 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER2),
3318 "Failed to set balance xmit policy.");
3321 /* Verify Current Slaves Count /Active Slave Count is */
3322 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
3324 TEST_ASSERT_EQUAL(slave_count, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT,
3325 "Number of slaves (%d) is not as expected (%d).",
3326 slave_count, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT);
3328 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
3329 slaves, RTE_MAX_ETHPORTS);
3330 TEST_ASSERT_EQUAL(slave_count, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT,
3331 "Number of active slaves (%d) is not as expected (%d).",
3332 slave_count, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT);
3334 /* Set 2 slaves link status to down */
3335 virtual_ethdev_simulate_link_status_interrupt(
3336 test_params->slave_port_ids[1], 0);
3337 virtual_ethdev_simulate_link_status_interrupt(
3338 test_params->slave_port_ids[3], 0);
3340 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
3341 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 2,
3342 "Number of active slaves (%d) is not as expected (%d).",
3345 /* Send to sets of packet burst and verify that they are balanced across
3349 TEST_ASSERT_EQUAL(generate_test_burst(
3350 &pkt_burst[0][0], burst_size, 0, 1, 0, 0, 0), burst_size,
3351 "generate_test_burst failed");
3353 TEST_ASSERT_EQUAL(generate_test_burst(
3354 &pkt_burst[1][0], burst_size, 0, 1, 1, 0, 0), burst_size,
3355 "generate_test_burst failed");
3357 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
3358 test_params->bonded_port_id, 0, &pkt_burst[0][0], burst_size),
3359 burst_size, "rte_eth_tx_burst failed");
3361 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
3362 test_params->bonded_port_id, 0, &pkt_burst[1][0], burst_size),
3363 burst_size, "rte_eth_tx_burst failed");
3366 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3367 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(burst_size + burst_size),
3368 "(%d) port_stats.opackets (%d) not as expected (%d).",
3369 test_params->bonded_port_id, (int)port_stats.opackets,
3370 burst_size + burst_size);
3372 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3373 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
3374 "(%d) port_stats.opackets (%d) not as expected (%d).",
3375 test_params->slave_port_ids[0], (int)port_stats.opackets,
3378 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3379 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
3380 "(%d) port_stats.opackets (%d) not as expected (%d).",
3381 test_params->slave_port_ids[2], (int)port_stats.opackets,
3384 /* verify that all packets get send on primary slave when no other slaves
3386 virtual_ethdev_simulate_link_status_interrupt(
3387 test_params->slave_port_ids[2], 0);
3389 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
3390 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 1,
3391 "Number of active slaves (%d) is not as expected (%d).",
3394 TEST_ASSERT_EQUAL(generate_test_burst(
3395 &pkt_burst[1][0], burst_size, 0, 1, 1, 0, 0), burst_size,
3396 "generate_test_burst failed");
3398 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
3399 test_params->bonded_port_id, 0, &pkt_burst[1][0], burst_size),
3400 burst_size, "rte_eth_tx_burst failed");
3402 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3403 TEST_ASSERT_EQUAL(port_stats.opackets,
3404 (uint64_t)(burst_size + burst_size + burst_size),
3405 "(%d) port_stats.opackets (%d) not as expected (%d).\n",
3406 test_params->bonded_port_id, (int)port_stats.opackets,
3407 burst_size + burst_size + burst_size);
3409 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3410 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(burst_size + burst_size),
3411 "(%d) port_stats.opackets (%d) not as expected (%d).",
3412 test_params->slave_port_ids[0], (int)port_stats.opackets,
3413 burst_size + burst_size);
3415 virtual_ethdev_simulate_link_status_interrupt(
3416 test_params->slave_port_ids[0], 0);
3417 virtual_ethdev_simulate_link_status_interrupt(
3418 test_params->slave_port_ids[1], 1);
3419 virtual_ethdev_simulate_link_status_interrupt(
3420 test_params->slave_port_ids[2], 1);
3421 virtual_ethdev_simulate_link_status_interrupt(
3422 test_params->slave_port_ids[3], 1);
3424 for (i = 0; i < TEST_BALANCE_LINK_STATUS_SLAVE_COUNT; i++) {
3425 TEST_ASSERT_EQUAL(generate_test_burst(
3426 &pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0), burst_size,
3427 "Failed to generate packet burst");
3429 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3430 &pkt_burst[i][0], burst_size);
3433 /* Verify that pkts are not received on slaves with link status down */
3435 rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
3438 /* Verify bonded device rx count */
3439 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3440 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)(burst_size * 3),
3441 "(%d) port_stats.ipackets (%d) not as expected (%d)\n",
3442 test_params->bonded_port_id, (int)port_stats.ipackets,
3445 /* Clean up and remove slaves from bonded device */
3446 return remove_slaves_and_stop_bonded_device();
3450 test_broadcast_tx_burst(void)
3452 int i, pktlen, burst_size;
3453 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
3455 struct rte_eth_stats port_stats;
3457 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3458 BONDING_MODE_BROADCAST, 0, 2, 1),
3459 "Failed to initialise bonded device");
3461 initialize_eth_header(test_params->pkt_eth_hdr,
3462 (struct ether_addr *)src_mac, (struct ether_addr *)dst_mac_0,
3463 ETHER_TYPE_IPv4, 0, 0);
3465 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
3467 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
3468 dst_addr_0, pktlen);
3470 burst_size = 20 * test_params->bonded_slave_count;
3472 TEST_ASSERT(burst_size < MAX_PKT_BURST,
3473 "Burst size specified is greater than supported.");
3475 /* Generate a burst of packets to transmit */
3476 TEST_ASSERT_EQUAL(generate_packet_burst(test_params->mbuf_pool,
3477 pkts_burst, test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr,
3478 1, test_params->pkt_udp_hdr, burst_size, PACKET_BURST_GEN_PKT_LEN,
3479 1), burst_size, "Failed to generate packet burst");
3481 /* Send burst on bonded port */
3482 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
3483 pkts_burst, burst_size), burst_size,
3484 "Bonded Port (%d) rx burst failed, packets transmitted value "
3485 "not as expected (%d)",
3486 test_params->bonded_port_id, burst_size);
3488 /* Verify bonded port tx stats */
3489 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3490 TEST_ASSERT_EQUAL(port_stats.opackets,
3491 (uint64_t)burst_size * test_params->bonded_slave_count,
3492 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
3493 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3496 /* Verify slave ports tx stats */
3497 for (i = 0; i < test_params->bonded_slave_count; i++) {
3498 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
3499 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
3500 "Slave Port (%d) opackets value (%u) not as expected (%d)\n",
3501 test_params->bonded_port_id,
3502 (unsigned int)port_stats.opackets, burst_size);
3505 /* Put all slaves down and try and transmit */
3506 for (i = 0; i < test_params->bonded_slave_count; i++) {
3508 virtual_ethdev_simulate_link_status_interrupt(
3509 test_params->slave_port_ids[i], 0);
3512 /* Send burst on bonded port */
3513 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
3514 test_params->bonded_port_id, 0, pkts_burst, burst_size), 0,
3515 "transmitted an unexpected number of packets");
3517 /* Clean up and remove slaves from bonded device */
3518 return remove_slaves_and_stop_bonded_device();
3522 #define TEST_BCAST_SLAVE_TX_FAIL_SLAVE_COUNT (3)
3523 #define TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE (40)
3524 #define TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT (15)
3525 #define TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT (10)
3528 test_broadcast_tx_burst_slave_tx_fail(void)
3530 struct rte_mbuf *pkts_burst[TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE];
3531 struct rte_mbuf *expected_fail_pkts[TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT];
3533 struct rte_eth_stats port_stats;
3537 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3538 BONDING_MODE_BROADCAST, 0,
3539 TEST_BCAST_SLAVE_TX_FAIL_SLAVE_COUNT, 1),
3540 "Failed to initialise bonded device");
3542 /* Generate test bursts for transmission */
3543 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst,
3544 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE, 0, 0, 0, 0, 0),
3545 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE,
3546 "Failed to generate test packet burst");
3548 for (i = 0; i < TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT; i++) {
3549 expected_fail_pkts[i] = pkts_burst[TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3550 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT + i];
3553 /* Set virtual slave TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX to only fail
3554 * transmission of TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT packets of burst */
3555 virtual_ethdev_tx_burst_fn_set_success(
3556 test_params->slave_port_ids[0],
3558 virtual_ethdev_tx_burst_fn_set_success(
3559 test_params->slave_port_ids[1],
3561 virtual_ethdev_tx_burst_fn_set_success(
3562 test_params->slave_port_ids[2],
3565 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
3566 test_params->slave_port_ids[0],
3567 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT);
3569 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
3570 test_params->slave_port_ids[1],
3571 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT);
3573 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
3574 test_params->slave_port_ids[2],
3575 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT);
3577 /* Transmit burst */
3578 tx_count = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst,
3579 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE);
3581 TEST_ASSERT_EQUAL(tx_count, TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3582 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT,
3583 "Transmitted (%d) packets, expected to transmit (%d) packets",
3584 tx_count, TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3585 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT);
3587 /* Verify that failed packet are expected failed packets */
3588 for (i = 0; i < TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT; i++) {
3589 TEST_ASSERT_EQUAL(expected_fail_pkts[i], pkts_burst[i + tx_count],
3590 "expected mbuf (%d) pointer %p not expected pointer %p",
3591 i, expected_fail_pkts[i], pkts_burst[i + tx_count]);
3594 /* Verify slave ports tx stats */
3596 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3598 TEST_ASSERT_EQUAL(port_stats.opackets,
3599 (uint64_t)TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3600 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT,
3601 "Port (%d) opackets value (%u) not as expected (%d)",
3602 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3603 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3604 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT);
3607 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3609 TEST_ASSERT_EQUAL(port_stats.opackets,
3610 (uint64_t)TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3611 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT,
3612 "Port (%d) opackets value (%u) not as expected (%d)",
3613 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3614 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3615 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT);
3617 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3619 TEST_ASSERT_EQUAL(port_stats.opackets,
3620 (uint64_t)TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3621 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT,
3622 "Port (%d) opackets value (%u) not as expected (%d)",
3623 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3624 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3625 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT);
3628 /* Verify that all mbufs who transmission failed have a ref value of one */
3629 TEST_ASSERT_SUCCESS(verify_mbufs_ref_count(&pkts_burst[tx_count],
3630 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT, 1),
3631 "mbufs refcnts not as expected");
3633 free_mbufs(&pkts_burst[tx_count],
3634 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT);
3636 /* Clean up and remove slaves from bonded device */
3637 return remove_slaves_and_stop_bonded_device();
3640 #define BROADCAST_RX_BURST_NUM_OF_SLAVES (3)
3643 test_broadcast_rx_burst(void)
3645 struct rte_mbuf *gen_pkt_burst[BROADCAST_RX_BURST_NUM_OF_SLAVES][MAX_PKT_BURST];
3647 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3648 struct rte_eth_stats port_stats;
3650 int burst_size[BROADCAST_RX_BURST_NUM_OF_SLAVES] = { 10, 5, 30 };
3653 memset(gen_pkt_burst, 0, sizeof(gen_pkt_burst));
3655 /* Initialize bonded device with 4 slaves in round robin mode */
3656 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3657 BONDING_MODE_BROADCAST, 0, 3, 1),
3658 "Failed to initialise bonded device");
3660 /* Generate test bursts of packets to transmit */
3661 for (i = 0; i < BROADCAST_RX_BURST_NUM_OF_SLAVES; i++) {
3662 TEST_ASSERT_EQUAL(generate_test_burst(
3663 &gen_pkt_burst[i][0], burst_size[i], 0, 0, 1, 0, 0),
3664 burst_size[i], "failed to generate packet burst");
3667 /* Add rx data to slave 0 */
3668 for (i = 0; i < BROADCAST_RX_BURST_NUM_OF_SLAVES; i++) {
3669 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3670 &gen_pkt_burst[i][0], burst_size[i]);
3674 /* Call rx burst on bonded device */
3675 /* Send burst on bonded port */
3676 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
3677 test_params->bonded_port_id, 0, rx_pkt_burst, MAX_PKT_BURST),
3678 burst_size[0] + burst_size[1] + burst_size[2],
3681 /* Verify bonded device rx count */
3682 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3683 TEST_ASSERT_EQUAL(port_stats.ipackets,
3684 (uint64_t)(burst_size[0] + burst_size[1] + burst_size[2]),
3685 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
3686 test_params->bonded_port_id, (unsigned int)port_stats.ipackets,
3687 burst_size[0] + burst_size[1] + burst_size[2]);
3690 /* Verify bonded slave devices rx counts */
3691 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3692 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[0],
3693 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3694 test_params->slave_port_ids[0], (unsigned int)port_stats.ipackets,
3697 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3698 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[1],
3699 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3700 test_params->slave_port_ids[0], (unsigned int)port_stats.ipackets,
3703 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3704 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[2],
3705 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3706 test_params->slave_port_ids[2], (unsigned int)port_stats.ipackets,
3709 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
3710 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
3711 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3712 test_params->slave_port_ids[3], (unsigned int)port_stats.ipackets,
3715 /* free mbufs allocate for rx testing */
3716 for (i = 0; i < BROADCAST_RX_BURST_NUM_OF_SLAVES; i++) {
3717 for (j = 0; j < MAX_PKT_BURST; j++) {
3718 if (gen_pkt_burst[i][j] != NULL) {
3719 rte_pktmbuf_free(gen_pkt_burst[i][j]);
3720 gen_pkt_burst[i][j] = NULL;
3725 /* Clean up and remove slaves from bonded device */
3726 return remove_slaves_and_stop_bonded_device();
3730 test_broadcast_verify_promiscuous_enable_disable(void)
3734 /* Initialize bonded device with 4 slaves in round robin mode */
3735 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3736 BONDING_MODE_BROADCAST, 0, 4, 1),
3737 "Failed to initialise bonded device");
3739 rte_eth_promiscuous_enable(test_params->bonded_port_id);
3742 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 1,
3743 "Port (%d) promiscuous mode not enabled",
3744 test_params->bonded_port_id);
3746 for (i = 0; i < test_params->bonded_slave_count; i++) {
3747 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(
3748 test_params->slave_port_ids[i]), 1,
3749 "Port (%d) promiscuous mode not enabled",
3750 test_params->slave_port_ids[i]);
3753 rte_eth_promiscuous_disable(test_params->bonded_port_id);
3755 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 0,
3756 "Port (%d) promiscuous mode not disabled",
3757 test_params->bonded_port_id);
3759 for (i = 0; i < test_params->bonded_slave_count; i++) {
3760 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(
3761 test_params->slave_port_ids[i]), 0,
3762 "Port (%d) promiscuous mode not disabled",
3763 test_params->slave_port_ids[i]);
3766 /* Clean up and remove slaves from bonded device */
3767 return remove_slaves_and_stop_bonded_device();
3771 test_broadcast_verify_mac_assignment(void)
3773 struct ether_addr read_mac_addr, expected_mac_addr_0, expected_mac_addr_1;
3777 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
3778 rte_eth_macaddr_get(test_params->slave_port_ids[2], &expected_mac_addr_1);
3780 /* Initialize bonded device with 4 slaves in round robin mode */
3781 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3782 BONDING_MODE_BROADCAST, 0, 4, 1),
3783 "Failed to initialise bonded device");
3785 /* Verify that all MACs are the same as first slave added to bonded
3787 for (i = 0; i < test_params->bonded_slave_count; i++) {
3788 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3789 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3790 sizeof(read_mac_addr)),
3791 "slave port (%d) mac address not set to that of primary port",
3792 test_params->slave_port_ids[i]);
3795 /* change primary and verify that MAC addresses haven't changed */
3796 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(test_params->bonded_port_id,
3797 test_params->slave_port_ids[2]),
3798 "Failed to set bonded port (%d) primary port to (%d)",
3799 test_params->bonded_port_id, test_params->slave_port_ids[i]);
3801 for (i = 0; i < test_params->bonded_slave_count; i++) {
3802 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3803 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3804 sizeof(read_mac_addr)),
3805 "slave port (%d) mac address has changed to that of primary "
3806 "port without stop/start toggle of bonded device",
3807 test_params->slave_port_ids[i]);
3810 /* stop / start bonded device and verify that primary MAC address is
3811 * propagated to bonded device and slaves */
3813 rte_eth_dev_stop(test_params->bonded_port_id);
3815 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
3816 "Failed to start bonded device");
3818 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3819 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3820 sizeof(read_mac_addr)),
3821 "bonded port (%d) mac address not set to that of new primary port",
3822 test_params->slave_port_ids[i]);
3824 for (i = 0; i < test_params->bonded_slave_count; i++) {
3825 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3826 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3827 sizeof(read_mac_addr)),
3828 "slave port (%d) mac address not set to that of new primary "
3829 "port", test_params->slave_port_ids[i]);
3832 /* Set explicit MAC address */
3833 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
3834 test_params->bonded_port_id, (struct ether_addr *)bonded_mac),
3835 "Failed to set MAC address");
3837 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3838 TEST_ASSERT_SUCCESS(memcmp(bonded_mac, &read_mac_addr,
3839 sizeof(read_mac_addr)),
3840 "bonded port (%d) mac address not set to that of new primary port",
3841 test_params->slave_port_ids[i]);
3844 for (i = 0; i < test_params->bonded_slave_count; i++) {
3845 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3846 TEST_ASSERT_SUCCESS(memcmp(bonded_mac, &read_mac_addr,
3847 sizeof(read_mac_addr)),
3848 "slave port (%d) mac address not set to that of new primary "
3849 "port", test_params->slave_port_ids[i]);
3852 /* Clean up and remove slaves from bonded device */
3853 return remove_slaves_and_stop_bonded_device();
3856 #define BROADCAST_LINK_STATUS_NUM_OF_SLAVES (4)
3858 test_broadcast_verify_slave_link_status_change_behaviour(void)
3860 struct rte_mbuf *pkt_burst[BROADCAST_LINK_STATUS_NUM_OF_SLAVES][MAX_PKT_BURST];
3861 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3862 struct rte_eth_stats port_stats;
3864 uint16_t slaves[RTE_MAX_ETHPORTS];
3866 int i, burst_size, slave_count;
3868 memset(pkt_burst, 0, sizeof(pkt_burst));
3870 /* Initialize bonded device with 4 slaves in round robin mode */
3871 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3872 BONDING_MODE_BROADCAST, 0, BROADCAST_LINK_STATUS_NUM_OF_SLAVES,
3873 1), "Failed to initialise bonded device");
3875 /* Verify Current Slaves Count /Active Slave Count is */
3876 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
3878 TEST_ASSERT_EQUAL(slave_count, 4,
3879 "Number of slaves (%d) is not as expected (%d).",
3882 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
3883 slaves, RTE_MAX_ETHPORTS);
3884 TEST_ASSERT_EQUAL(slave_count, 4,
3885 "Number of active slaves (%d) is not as expected (%d).",
3888 /* Set 2 slaves link status to down */
3889 virtual_ethdev_simulate_link_status_interrupt(
3890 test_params->slave_port_ids[1], 0);
3891 virtual_ethdev_simulate_link_status_interrupt(
3892 test_params->slave_port_ids[3], 0);
3894 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
3895 slaves, RTE_MAX_ETHPORTS);
3896 TEST_ASSERT_EQUAL(slave_count, 2,
3897 "Number of active slaves (%d) is not as expected (%d).",
3900 for (i = 0; i < test_params->bonded_slave_count; i++)
3901 rte_eth_stats_reset(test_params->slave_port_ids[i]);
3903 /* Verify that pkts are not sent on slaves with link status down */
3906 TEST_ASSERT_EQUAL(generate_test_burst(
3907 &pkt_burst[0][0], burst_size, 0, 0, 1, 0, 0), burst_size,
3908 "generate_test_burst failed");
3910 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
3911 &pkt_burst[0][0], burst_size), burst_size,
3912 "rte_eth_tx_burst failed\n");
3914 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3915 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(burst_size * slave_count),
3916 "(%d) port_stats.opackets (%d) not as expected (%d)\n",
3917 test_params->bonded_port_id, (int)port_stats.opackets,
3918 burst_size * slave_count);
3920 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3921 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
3922 "(%d) port_stats.opackets not as expected",
3923 test_params->slave_port_ids[0]);
3925 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3926 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
3927 "(%d) port_stats.opackets not as expected",
3928 test_params->slave_port_ids[1]);
3930 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3931 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
3932 "(%d) port_stats.opackets not as expected",
3933 test_params->slave_port_ids[2]);
3936 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
3937 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
3938 "(%d) port_stats.opackets not as expected",
3939 test_params->slave_port_ids[3]);
3942 for (i = 0; i < BROADCAST_LINK_STATUS_NUM_OF_SLAVES; i++) {
3943 TEST_ASSERT_EQUAL(generate_test_burst(
3944 &pkt_burst[i][0], burst_size, 0, 0, 1, 0, 0),
3945 burst_size, "failed to generate packet burst");
3947 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3948 &pkt_burst[i][0], burst_size);
3951 /* Verify that pkts are not received on slaves with link status down */
3952 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
3953 test_params->bonded_port_id, 0, rx_pkt_burst, MAX_PKT_BURST),
3954 burst_size + burst_size, "rte_eth_rx_burst failed");
3957 /* Verify bonded device rx count */
3958 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3959 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)(burst_size + burst_size),
3960 "(%d) port_stats.ipackets not as expected\n",
3961 test_params->bonded_port_id);
3963 /* Clean up and remove slaves from bonded device */
3964 return remove_slaves_and_stop_bonded_device();
3968 test_reconfigure_bonded_device(void)
3970 test_params->nb_rx_q = 4;
3971 test_params->nb_tx_q = 4;
3973 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0, 0),
3974 "failed to reconfigure bonded device");
3976 test_params->nb_rx_q = 2;
3977 test_params->nb_tx_q = 2;
3979 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0, 0),
3980 "failed to reconfigure bonded device with less rx/tx queues");
3987 test_close_bonded_device(void)
3989 rte_eth_dev_close(test_params->bonded_port_id);
3994 testsuite_teardown(void)
3996 free(test_params->pkt_eth_hdr);
3997 test_params->pkt_eth_hdr = NULL;
3999 /* Clean up and remove slaves from bonded device */
4000 remove_slaves_and_stop_bonded_device();
4004 free_virtualpmd_tx_queue(void)
4006 int i, slave_port, to_free_cnt;
4007 struct rte_mbuf *pkts_to_free[MAX_PKT_BURST];
4009 /* Free tx queue of virtual pmd */
4010 for (slave_port = 0; slave_port < test_params->bonded_slave_count;
4012 to_free_cnt = virtual_ethdev_get_mbufs_from_tx_queue(
4013 test_params->slave_port_ids[slave_port],
4014 pkts_to_free, MAX_PKT_BURST);
4015 for (i = 0; i < to_free_cnt; i++)
4016 rte_pktmbuf_free(pkts_to_free[i]);
4021 test_tlb_tx_burst(void)
4023 int i, burst_size, nb_tx;
4024 uint64_t nb_tx2 = 0;
4025 struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
4026 struct rte_eth_stats port_stats[32];
4027 uint64_t sum_ports_opackets = 0, all_bond_opackets = 0, all_bond_obytes = 0;
4030 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves
4031 (BONDING_MODE_TLB, 1, 3, 1),
4032 "Failed to initialise bonded device");
4034 burst_size = 20 * test_params->bonded_slave_count;
4036 TEST_ASSERT(burst_size < MAX_PKT_BURST,
4037 "Burst size specified is greater than supported.\n");
4040 /* Generate bursts of packets */
4041 for (i = 0; i < 400000; i++) {
4042 /*test two types of mac src own(bonding) and others */
4044 initialize_eth_header(test_params->pkt_eth_hdr,
4045 (struct ether_addr *)src_mac,
4046 (struct ether_addr *)dst_mac_0, ETHER_TYPE_IPv4, 0, 0);
4048 initialize_eth_header(test_params->pkt_eth_hdr,
4049 (struct ether_addr *)test_params->default_slave_mac,
4050 (struct ether_addr *)dst_mac_0, ETHER_TYPE_IPv4, 0, 0);
4052 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
4054 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
4055 dst_addr_0, pktlen);
4056 generate_packet_burst(test_params->mbuf_pool, pkt_burst,
4057 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr,
4058 1, test_params->pkt_udp_hdr, burst_size, 60, 1);
4059 /* Send burst on bonded port */
4060 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkt_burst,
4064 free_virtualpmd_tx_queue();
4066 TEST_ASSERT_EQUAL(nb_tx, burst_size,
4067 "number of packet not equal burst size");
4073 /* Verify bonded port tx stats */
4074 rte_eth_stats_get(test_params->bonded_port_id, &port_stats[0]);
4076 all_bond_opackets = port_stats[0].opackets;
4077 all_bond_obytes = port_stats[0].obytes;
4079 TEST_ASSERT_EQUAL(port_stats[0].opackets, (uint64_t)nb_tx2,
4080 "Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
4081 test_params->bonded_port_id, (unsigned int)port_stats[0].opackets,
4085 /* Verify slave ports tx stats */
4086 for (i = 0; i < test_params->bonded_slave_count; i++) {
4087 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats[i]);
4088 sum_ports_opackets += port_stats[i].opackets;
4091 TEST_ASSERT_EQUAL(sum_ports_opackets, (uint64_t)all_bond_opackets,
4092 "Total packets sent by slaves is not equal to packets sent by bond interface");
4094 /* checking if distribution of packets is balanced over slaves */
4095 for (i = 0; i < test_params->bonded_slave_count; i++) {
4096 TEST_ASSERT(port_stats[i].obytes > 0 &&
4097 port_stats[i].obytes < all_bond_obytes,
4098 "Packets are not balanced over slaves");
4101 /* Put all slaves down and try and transmit */
4102 for (i = 0; i < test_params->bonded_slave_count; i++) {
4103 virtual_ethdev_simulate_link_status_interrupt(
4104 test_params->slave_port_ids[i], 0);
4107 /* Send burst on bonded port */
4108 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkt_burst,
4110 TEST_ASSERT_EQUAL(nb_tx, 0, " bad number of packet in burst");
4112 /* Clean ugit checkout masterp and remove slaves from bonded device */
4113 return remove_slaves_and_stop_bonded_device();
4116 #define TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT (4)
4119 test_tlb_rx_burst(void)
4121 struct rte_mbuf *gen_pkt_burst[MAX_PKT_BURST] = { NULL };
4122 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
4124 struct rte_eth_stats port_stats;
4128 uint16_t i, j, nb_rx, burst_size = 17;
4130 /* Initialize bonded device with 4 slaves in transmit load balancing mode */
4131 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
4133 TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT, 1, 1),
4134 "Failed to initialize bonded device");
4137 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
4138 TEST_ASSERT(primary_port >= 0,
4139 "failed to get primary slave for bonded port (%d)",
4140 test_params->bonded_port_id);
4142 for (i = 0; i < test_params->bonded_slave_count; i++) {
4143 /* Generate test bursts of packets to transmit */
4144 TEST_ASSERT_EQUAL(generate_test_burst(
4145 &gen_pkt_burst[0], burst_size, 0, 1, 0, 0, 0), burst_size,
4146 "burst generation failed");
4148 /* Add rx data to slave */
4149 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
4150 &gen_pkt_burst[0], burst_size);
4152 /* Call rx burst on bonded device */
4153 nb_rx = rte_eth_rx_burst(test_params->bonded_port_id, 0,
4154 &rx_pkt_burst[0], MAX_PKT_BURST);
4156 TEST_ASSERT_EQUAL(nb_rx, burst_size, "rte_eth_rx_burst failed\n");
4158 if (test_params->slave_port_ids[i] == primary_port) {
4159 /* Verify bonded device rx count */
4160 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
4161 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
4162 "Bonded Port (%d) ipackets value (%u) not as expected (%d)\n",
4163 test_params->bonded_port_id,
4164 (unsigned int)port_stats.ipackets, burst_size);
4166 /* Verify bonded slave devices rx count */
4167 for (j = 0; j < test_params->bonded_slave_count; j++) {
4168 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
4170 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
4171 "Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
4172 test_params->slave_port_ids[i],
4173 (unsigned int)port_stats.ipackets, burst_size);
4175 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)0,
4176 "Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
4177 test_params->slave_port_ids[i],
4178 (unsigned int)port_stats.ipackets, 0);
4182 for (j = 0; j < test_params->bonded_slave_count; j++) {
4183 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
4184 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)0,
4185 "Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
4186 test_params->slave_port_ids[i],
4187 (unsigned int)port_stats.ipackets, 0);
4192 for (i = 0; i < burst_size; i++)
4193 rte_pktmbuf_free(rx_pkt_burst[i]);
4195 /* reset bonded device stats */
4196 rte_eth_stats_reset(test_params->bonded_port_id);
4199 /* Clean up and remove slaves from bonded device */
4200 return remove_slaves_and_stop_bonded_device();
4204 test_tlb_verify_promiscuous_enable_disable(void)
4206 int i, primary_port, promiscuous_en;
4208 /* Initialize bonded device with 4 slaves in transmit load balancing mode */
4209 TEST_ASSERT_SUCCESS( initialize_bonded_device_with_slaves(
4210 BONDING_MODE_TLB, 0, 4, 1),
4211 "Failed to initialize bonded device");
4213 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
4214 TEST_ASSERT(primary_port >= 0,
4215 "failed to get primary slave for bonded port (%d)",
4216 test_params->bonded_port_id);
4218 rte_eth_promiscuous_enable(test_params->bonded_port_id);
4220 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
4221 TEST_ASSERT_EQUAL(promiscuous_en, (int)1,
4222 "Port (%d) promiscuous mode not enabled\n",
4223 test_params->bonded_port_id);
4224 for (i = 0; i < test_params->bonded_slave_count; i++) {
4225 promiscuous_en = rte_eth_promiscuous_get(
4226 test_params->slave_port_ids[i]);
4227 if (primary_port == test_params->slave_port_ids[i]) {
4228 TEST_ASSERT_EQUAL(promiscuous_en, (int)1,
4229 "Port (%d) promiscuous mode not enabled\n",
4230 test_params->bonded_port_id);
4232 TEST_ASSERT_EQUAL(promiscuous_en, (int)0,
4233 "Port (%d) promiscuous mode enabled\n",
4234 test_params->bonded_port_id);
4239 rte_eth_promiscuous_disable(test_params->bonded_port_id);
4241 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
4242 TEST_ASSERT_EQUAL(promiscuous_en, (int)0,
4243 "Port (%d) promiscuous mode not disabled\n",
4244 test_params->bonded_port_id);
4246 for (i = 0; i < test_params->bonded_slave_count; i++) {
4247 promiscuous_en = rte_eth_promiscuous_get(
4248 test_params->slave_port_ids[i]);
4249 TEST_ASSERT_EQUAL(promiscuous_en, (int)0,
4250 "slave port (%d) promiscuous mode not disabled\n",
4251 test_params->slave_port_ids[i]);
4254 /* Clean up and remove slaves from bonded device */
4255 return remove_slaves_and_stop_bonded_device();
4259 test_tlb_verify_mac_assignment(void)
4261 struct ether_addr read_mac_addr, expected_mac_addr_0, expected_mac_addr_1;
4263 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
4264 rte_eth_macaddr_get(test_params->slave_port_ids[1], &expected_mac_addr_1);
4266 /* Initialize bonded device with 2 slaves in active backup mode */
4267 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
4268 BONDING_MODE_TLB, 0, 2, 1),
4269 "Failed to initialize bonded device");
4271 /* Verify that bonded MACs is that of first slave and that the other slave
4272 * MAC hasn't been changed */
4273 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
4274 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4275 sizeof(read_mac_addr)),
4276 "bonded port (%d) mac address not set to that of primary port",
4277 test_params->bonded_port_id);
4279 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
4280 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4281 sizeof(read_mac_addr)),
4282 "slave port (%d) mac address not set to that of primary port",
4283 test_params->slave_port_ids[0]);
4285 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
4286 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
4287 sizeof(read_mac_addr)),
4288 "slave port (%d) mac address not as expected",
4289 test_params->slave_port_ids[1]);
4291 /* change primary and verify that MAC addresses haven't changed */
4292 TEST_ASSERT_EQUAL(rte_eth_bond_primary_set(test_params->bonded_port_id,
4293 test_params->slave_port_ids[1]), 0,
4294 "Failed to set bonded port (%d) primary port to (%d)",
4295 test_params->bonded_port_id, test_params->slave_port_ids[1]);
4297 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
4298 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4299 sizeof(read_mac_addr)),
4300 "bonded port (%d) mac address not set to that of primary port",
4301 test_params->bonded_port_id);
4303 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
4304 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4305 sizeof(read_mac_addr)),
4306 "slave port (%d) mac address not set to that of primary port",
4307 test_params->slave_port_ids[0]);
4309 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
4310 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
4311 sizeof(read_mac_addr)),
4312 "slave port (%d) mac address not as expected",
4313 test_params->slave_port_ids[1]);
4315 /* stop / start bonded device and verify that primary MAC address is
4316 * propagated to bonded device and slaves */
4318 rte_eth_dev_stop(test_params->bonded_port_id);
4320 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
4321 "Failed to start device");
4323 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
4324 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
4325 sizeof(read_mac_addr)),
4326 "bonded port (%d) mac address not set to that of primary port",
4327 test_params->bonded_port_id);
4329 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
4330 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4331 sizeof(read_mac_addr)),
4332 "slave port (%d) mac address not as expected",
4333 test_params->slave_port_ids[0]);
4335 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
4336 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
4337 sizeof(read_mac_addr)),
4338 "slave port (%d) mac address not set to that of primary port",
4339 test_params->slave_port_ids[1]);
4342 /* Set explicit MAC address */
4343 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
4344 test_params->bonded_port_id, (struct ether_addr *)bonded_mac),
4345 "failed to set MAC address");
4347 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
4348 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
4349 sizeof(read_mac_addr)),
4350 "bonded port (%d) mac address not set to that of bonded port",
4351 test_params->bonded_port_id);
4353 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
4354 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4355 sizeof(read_mac_addr)),
4356 "slave port (%d) mac address not as expected",
4357 test_params->slave_port_ids[0]);
4359 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
4360 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
4361 sizeof(read_mac_addr)),
4362 "slave port (%d) mac address not set to that of bonded port",
4363 test_params->slave_port_ids[1]);
4365 /* Clean up and remove slaves from bonded device */
4366 return remove_slaves_and_stop_bonded_device();
4370 test_tlb_verify_slave_link_status_change_failover(void)
4372 struct rte_mbuf *pkt_burst[TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
4373 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
4374 struct rte_eth_stats port_stats;
4376 uint16_t slaves[RTE_MAX_ETHPORTS];
4378 int i, burst_size, slave_count, primary_port;
4382 memset(pkt_burst, 0, sizeof(pkt_burst));
4386 /* Initialize bonded device with 4 slaves in round robin mode */
4387 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
4388 BONDING_MODE_TLB, 0,
4389 TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT, 1),
4390 "Failed to initialize bonded device with slaves");
4392 /* Verify Current Slaves Count /Active Slave Count is */
4393 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
4395 TEST_ASSERT_EQUAL(slave_count, 4,
4396 "Number of slaves (%d) is not as expected (%d).\n",
4399 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
4400 slaves, RTE_MAX_ETHPORTS);
4401 TEST_ASSERT_EQUAL(slave_count, (int)4,
4402 "Number of slaves (%d) is not as expected (%d).\n",
4405 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
4406 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[0],
4407 "Primary port not as expected");
4409 /* Bring 2 slaves down and verify active slave count */
4410 virtual_ethdev_simulate_link_status_interrupt(
4411 test_params->slave_port_ids[1], 0);
4412 virtual_ethdev_simulate_link_status_interrupt(
4413 test_params->slave_port_ids[3], 0);
4415 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
4416 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 2,
4417 "Number of active slaves (%d) is not as expected (%d).",
4420 virtual_ethdev_simulate_link_status_interrupt(
4421 test_params->slave_port_ids[1], 1);
4422 virtual_ethdev_simulate_link_status_interrupt(
4423 test_params->slave_port_ids[3], 1);
4426 /* Bring primary port down, verify that active slave count is 3 and primary
4428 virtual_ethdev_simulate_link_status_interrupt(
4429 test_params->slave_port_ids[0], 0);
4431 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
4432 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 3,
4433 "Number of active slaves (%d) is not as expected (%d).",
4436 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
4437 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[2],
4438 "Primary port not as expected");
4439 rte_delay_us(500000);
4440 /* Verify that pkts are sent on new primary slave */
4441 for (i = 0; i < 4; i++) {
4442 TEST_ASSERT_EQUAL(generate_test_burst(
4443 &pkt_burst[0][0], burst_size, 0, 1, 0, 0, 0), burst_size,
4444 "generate_test_burst failed\n");
4445 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
4446 test_params->bonded_port_id, 0, &pkt_burst[0][0], burst_size), burst_size,
4447 "rte_eth_tx_burst failed\n");
4448 rte_delay_us(11000);
4451 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
4452 TEST_ASSERT_EQUAL(port_stats.opackets, (int8_t)0,
4453 "(%d) port_stats.opackets not as expected\n",
4454 test_params->slave_port_ids[0]);
4456 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
4457 TEST_ASSERT_NOT_EQUAL(port_stats.opackets, (int8_t)0,
4458 "(%d) port_stats.opackets not as expected\n",
4459 test_params->slave_port_ids[1]);
4461 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
4462 TEST_ASSERT_NOT_EQUAL(port_stats.opackets, (int8_t)0,
4463 "(%d) port_stats.opackets not as expected\n",
4464 test_params->slave_port_ids[2]);
4466 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
4467 TEST_ASSERT_NOT_EQUAL(port_stats.opackets, (int8_t)0,
4468 "(%d) port_stats.opackets not as expected\n",
4469 test_params->slave_port_ids[3]);
4472 /* Generate packet burst for testing */
4474 for (i = 0; i < TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT; i++) {
4475 if (generate_test_burst(&pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0) !=
4479 virtual_ethdev_add_mbufs_to_rx_queue(
4480 test_params->slave_port_ids[i], &pkt_burst[i][0], burst_size);
4483 if (rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
4484 MAX_PKT_BURST) != burst_size) {
4485 printf("rte_eth_rx_burst\n");
4490 /* Verify bonded device rx count */
4491 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
4492 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
4493 "(%d) port_stats.ipackets not as expected\n",
4494 test_params->bonded_port_id);
4496 /* Clean up and remove slaves from bonded device */
4497 return remove_slaves_and_stop_bonded_device();
4500 #define TEST_ALB_SLAVE_COUNT 2
4502 static uint8_t mac_client1[] = {0x00, 0xAA, 0x55, 0xFF, 0xCC, 1};
4503 static uint8_t mac_client2[] = {0x00, 0xAA, 0x55, 0xFF, 0xCC, 2};
4504 static uint8_t mac_client3[] = {0x00, 0xAA, 0x55, 0xFF, 0xCC, 3};
4505 static uint8_t mac_client4[] = {0x00, 0xAA, 0x55, 0xFF, 0xCC, 4};
4507 static uint32_t ip_host = IPV4_ADDR(192, 168, 0, 0);
4508 static uint32_t ip_client1 = IPV4_ADDR(192, 168, 0, 1);
4509 static uint32_t ip_client2 = IPV4_ADDR(192, 168, 0, 2);
4510 static uint32_t ip_client3 = IPV4_ADDR(192, 168, 0, 3);
4511 static uint32_t ip_client4 = IPV4_ADDR(192, 168, 0, 4);
4514 test_alb_change_mac_in_reply_sent(void)
4516 struct rte_mbuf *pkt;
4517 struct rte_mbuf *pkts_sent[MAX_PKT_BURST];
4519 struct ether_hdr *eth_pkt;
4520 struct arp_hdr *arp_pkt;
4522 int slave_idx, nb_pkts, pkt_idx;
4525 struct ether_addr bond_mac, client_mac;
4526 struct ether_addr *slave_mac1, *slave_mac2;
4528 TEST_ASSERT_SUCCESS(
4529 initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
4530 0, TEST_ALB_SLAVE_COUNT, 1),
4531 "Failed to initialize_bonded_device_with_slaves.");
4533 /* Flush tx queue */
4534 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4535 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count;
4537 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4538 test_params->slave_port_ids[slave_idx], pkts_sent,
4543 rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
4547 * Generating four packets with different mac and ip addresses and sending
4548 * them through the bonding port.
4550 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4551 memcpy(client_mac.addr_bytes, mac_client1, ETHER_ADDR_LEN);
4552 eth_pkt = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
4553 initialize_eth_header(eth_pkt, &bond_mac, &client_mac, ETHER_TYPE_ARP, 0,
4555 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4556 initialize_arp_header(arp_pkt, &bond_mac, &client_mac, ip_host, ip_client1,
4558 rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
4560 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4561 memcpy(client_mac.addr_bytes, mac_client2, ETHER_ADDR_LEN);
4562 eth_pkt = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
4563 initialize_eth_header(eth_pkt, &bond_mac, &client_mac, ETHER_TYPE_ARP, 0,
4565 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4566 initialize_arp_header(arp_pkt, &bond_mac, &client_mac, ip_host, ip_client2,
4568 rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
4570 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4571 memcpy(client_mac.addr_bytes, mac_client3, ETHER_ADDR_LEN);
4572 eth_pkt = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
4573 initialize_eth_header(eth_pkt, &bond_mac, &client_mac, ETHER_TYPE_ARP, 0,
4575 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4576 initialize_arp_header(arp_pkt, &bond_mac, &client_mac, ip_host, ip_client3,
4578 rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
4580 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4581 memcpy(client_mac.addr_bytes, mac_client4, ETHER_ADDR_LEN);
4582 eth_pkt = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
4583 initialize_eth_header(eth_pkt, &bond_mac, &client_mac, ETHER_TYPE_ARP, 0,
4585 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4586 initialize_arp_header(arp_pkt, &bond_mac, &client_mac, ip_host, ip_client4,
4588 rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
4591 rte_eth_devices[test_params->slave_port_ids[0]].data->mac_addrs;
4593 rte_eth_devices[test_params->slave_port_ids[1]].data->mac_addrs;
4596 * Checking if packets are properly distributed on bonding ports. Packets
4597 * 0 and 2 should be sent on port 0 and packets 1 and 3 on port 1.
4599 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4600 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4601 test_params->slave_port_ids[slave_idx], pkts_sent,
4604 for (pkt_idx = 0; pkt_idx < nb_pkts; pkt_idx++) {
4605 eth_pkt = rte_pktmbuf_mtod(pkts_sent[pkt_idx], struct ether_hdr *);
4606 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4608 if (slave_idx%2 == 0) {
4609 if (!is_same_ether_addr(slave_mac1, &arp_pkt->arp_data.arp_sha)) {
4614 if (!is_same_ether_addr(slave_mac2, &arp_pkt->arp_data.arp_sha)) {
4623 retval += remove_slaves_and_stop_bonded_device();
4628 test_alb_reply_from_client(void)
4630 struct ether_hdr *eth_pkt;
4631 struct arp_hdr *arp_pkt;
4633 struct rte_mbuf *pkt;
4634 struct rte_mbuf *pkts_sent[MAX_PKT_BURST];
4636 int slave_idx, nb_pkts, pkt_idx, nb_pkts_sum = 0;
4639 struct ether_addr bond_mac, client_mac;
4640 struct ether_addr *slave_mac1, *slave_mac2;
4642 TEST_ASSERT_SUCCESS(
4643 initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
4644 0, TEST_ALB_SLAVE_COUNT, 1),
4645 "Failed to initialize_bonded_device_with_slaves.");
4647 /* Flush tx queue */
4648 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4649 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4650 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4651 test_params->slave_port_ids[slave_idx], pkts_sent,
4656 rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
4660 * Generating four packets with different mac and ip addresses and placing
4661 * them in the rx queue to be received by the bonding driver on rx_burst.
4663 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4664 memcpy(client_mac.addr_bytes, mac_client1, ETHER_ADDR_LEN);
4665 eth_pkt = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
4666 initialize_eth_header(eth_pkt, &bond_mac, &client_mac, ETHER_TYPE_ARP, 0,
4668 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4669 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client1, ip_host,
4671 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4674 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4675 memcpy(client_mac.addr_bytes, mac_client2, ETHER_ADDR_LEN);
4676 eth_pkt = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
4677 initialize_eth_header(eth_pkt, &bond_mac, &client_mac, ETHER_TYPE_ARP, 0,
4679 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4680 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client2, ip_host,
4682 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4685 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4686 memcpy(client_mac.addr_bytes, mac_client3, ETHER_ADDR_LEN);
4687 eth_pkt = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
4688 initialize_eth_header(eth_pkt, &bond_mac, &client_mac, ETHER_TYPE_ARP, 0,
4690 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4691 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client3, ip_host,
4693 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4696 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4697 memcpy(client_mac.addr_bytes, mac_client4, ETHER_ADDR_LEN);
4698 eth_pkt = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
4699 initialize_eth_header(eth_pkt, &bond_mac, &client_mac, ETHER_TYPE_ARP, 0,
4701 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4702 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client4, ip_host,
4704 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4708 * Issue rx_burst and tx_burst to force bonding driver to send update ARP
4709 * packets to every client in alb table.
4711 rte_eth_rx_burst(test_params->bonded_port_id, 0, pkts_sent, MAX_PKT_BURST);
4712 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4714 slave_mac1 = rte_eth_devices[test_params->slave_port_ids[0]].data->mac_addrs;
4715 slave_mac2 = rte_eth_devices[test_params->slave_port_ids[1]].data->mac_addrs;
4718 * Checking if update ARP packets were properly send on slave ports.
4720 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4721 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4722 test_params->slave_port_ids[slave_idx], pkts_sent, MAX_PKT_BURST);
4723 nb_pkts_sum += nb_pkts;
4725 for (pkt_idx = 0; pkt_idx < nb_pkts; pkt_idx++) {
4726 eth_pkt = rte_pktmbuf_mtod(pkts_sent[pkt_idx], struct ether_hdr *);
4727 arp_pkt = (struct arp_hdr *)((char *)eth_pkt + sizeof(struct ether_hdr));
4729 if (slave_idx%2 == 0) {
4730 if (!is_same_ether_addr(slave_mac1, &arp_pkt->arp_data.arp_sha)) {
4735 if (!is_same_ether_addr(slave_mac2, &arp_pkt->arp_data.arp_sha)) {
4743 /* Check if proper number of packets was send */
4744 if (nb_pkts_sum < 4) {
4750 retval += remove_slaves_and_stop_bonded_device();
4755 test_alb_receive_vlan_reply(void)
4757 struct ether_hdr *eth_pkt;
4758 struct vlan_hdr *vlan_pkt;
4759 struct arp_hdr *arp_pkt;
4761 struct rte_mbuf *pkt;
4762 struct rte_mbuf *pkts_sent[MAX_PKT_BURST];
4764 int slave_idx, nb_pkts, pkt_idx;
4767 struct ether_addr bond_mac, client_mac;
4769 TEST_ASSERT_SUCCESS(
4770 initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
4771 0, TEST_ALB_SLAVE_COUNT, 1),
4772 "Failed to initialize_bonded_device_with_slaves.");
4774 /* Flush tx queue */
4775 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4776 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4777 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4778 test_params->slave_port_ids[slave_idx], pkts_sent,
4783 rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
4787 * Generating packet with double VLAN header and placing it in the rx queue.
4789 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4790 memcpy(client_mac.addr_bytes, mac_client1, ETHER_ADDR_LEN);
4791 eth_pkt = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
4792 initialize_eth_header(eth_pkt, &bond_mac, &client_mac, ETHER_TYPE_VLAN, 0,
4794 vlan_pkt = (struct vlan_hdr *)((char *)(eth_pkt + 1));
4795 vlan_pkt->vlan_tci = rte_cpu_to_be_16(1);
4796 vlan_pkt->eth_proto = rte_cpu_to_be_16(ETHER_TYPE_VLAN);
4797 vlan_pkt = vlan_pkt+1;
4798 vlan_pkt->vlan_tci = rte_cpu_to_be_16(2);
4799 vlan_pkt->eth_proto = rte_cpu_to_be_16(ETHER_TYPE_ARP);
4800 arp_pkt = (struct arp_hdr *)((char *)(vlan_pkt + 1));
4801 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client1, ip_host,
4803 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4806 rte_eth_rx_burst(test_params->bonded_port_id, 0, pkts_sent, MAX_PKT_BURST);
4807 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4810 * Checking if VLAN headers in generated ARP Update packet are correct.
4812 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4813 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4814 test_params->slave_port_ids[slave_idx], pkts_sent,
4817 for (pkt_idx = 0; pkt_idx < nb_pkts; pkt_idx++) {
4818 eth_pkt = rte_pktmbuf_mtod(pkts_sent[pkt_idx], struct ether_hdr *);
4819 vlan_pkt = (struct vlan_hdr *)((char *)(eth_pkt + 1));
4820 if (vlan_pkt->vlan_tci != rte_cpu_to_be_16(1)) {
4824 if (vlan_pkt->eth_proto != rte_cpu_to_be_16(ETHER_TYPE_VLAN)) {
4828 vlan_pkt = vlan_pkt+1;
4829 if (vlan_pkt->vlan_tci != rte_cpu_to_be_16(2)) {
4833 if (vlan_pkt->eth_proto != rte_cpu_to_be_16(ETHER_TYPE_ARP)) {
4841 retval += remove_slaves_and_stop_bonded_device();
4846 test_alb_ipv4_tx(void)
4848 int burst_size, retval, pkts_send;
4849 struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
4853 TEST_ASSERT_SUCCESS(
4854 initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
4855 0, TEST_ALB_SLAVE_COUNT, 1),
4856 "Failed to initialize_bonded_device_with_slaves.");
4860 /* Generate test bursts of packets to transmit */
4861 if (generate_test_burst(pkt_burst, burst_size, 0, 1, 0, 0, 0) != burst_size) {
4867 * Checking if ipv4 traffic is transmitted via TLB policy.
4869 pkts_send = rte_eth_tx_burst(
4870 test_params->bonded_port_id, 0, pkt_burst, burst_size);
4871 if (pkts_send != burst_size) {
4877 retval += remove_slaves_and_stop_bonded_device();
4881 static struct unit_test_suite link_bonding_test_suite = {
4882 .suite_name = "Link Bonding Unit Test Suite",
4883 .setup = test_setup,
4884 .teardown = testsuite_teardown,
4885 .unit_test_cases = {
4886 TEST_CASE(test_create_bonded_device),
4887 TEST_CASE(test_create_bonded_device_with_invalid_params),
4888 TEST_CASE(test_add_slave_to_bonded_device),
4889 TEST_CASE(test_add_slave_to_invalid_bonded_device),
4890 TEST_CASE(test_remove_slave_from_bonded_device),
4891 TEST_CASE(test_remove_slave_from_invalid_bonded_device),
4892 TEST_CASE(test_get_slaves_from_bonded_device),
4893 TEST_CASE(test_add_already_bonded_slave_to_bonded_device),
4894 TEST_CASE(test_add_remove_multiple_slaves_to_from_bonded_device),
4895 TEST_CASE(test_start_bonded_device),
4896 TEST_CASE(test_stop_bonded_device),
4897 TEST_CASE(test_set_bonding_mode),
4898 TEST_CASE(test_set_primary_slave),
4899 TEST_CASE(test_set_explicit_bonded_mac),
4900 TEST_CASE(test_set_bonded_port_initialization_mac_assignment),
4901 TEST_CASE(test_status_interrupt),
4902 TEST_CASE(test_adding_slave_after_bonded_device_started),
4903 TEST_CASE(test_roundrobin_tx_burst),
4904 TEST_CASE(test_roundrobin_tx_burst_slave_tx_fail),
4905 TEST_CASE(test_roundrobin_rx_burst_on_single_slave),
4906 TEST_CASE(test_roundrobin_rx_burst_on_multiple_slaves),
4907 TEST_CASE(test_roundrobin_verify_promiscuous_enable_disable),
4908 TEST_CASE(test_roundrobin_verify_mac_assignment),
4909 TEST_CASE(test_roundrobin_verify_slave_link_status_change_behaviour),
4910 TEST_CASE(test_roundrobin_verfiy_polling_slave_link_status_change),
4911 TEST_CASE(test_activebackup_tx_burst),
4912 TEST_CASE(test_activebackup_rx_burst),
4913 TEST_CASE(test_activebackup_verify_promiscuous_enable_disable),
4914 TEST_CASE(test_activebackup_verify_mac_assignment),
4915 TEST_CASE(test_activebackup_verify_slave_link_status_change_failover),
4916 TEST_CASE(test_balance_xmit_policy_configuration),
4917 TEST_CASE(test_balance_l2_tx_burst),
4918 TEST_CASE(test_balance_l23_tx_burst_ipv4_toggle_ip_addr),
4919 TEST_CASE(test_balance_l23_tx_burst_vlan_ipv4_toggle_ip_addr),
4920 TEST_CASE(test_balance_l23_tx_burst_ipv6_toggle_ip_addr),
4921 TEST_CASE(test_balance_l23_tx_burst_vlan_ipv6_toggle_ip_addr),
4922 TEST_CASE(test_balance_l23_tx_burst_toggle_mac_addr),
4923 TEST_CASE(test_balance_l34_tx_burst_ipv4_toggle_ip_addr),
4924 TEST_CASE(test_balance_l34_tx_burst_ipv4_toggle_udp_port),
4925 TEST_CASE(test_balance_l34_tx_burst_vlan_ipv4_toggle_ip_addr),
4926 TEST_CASE(test_balance_l34_tx_burst_ipv6_toggle_ip_addr),
4927 TEST_CASE(test_balance_l34_tx_burst_vlan_ipv6_toggle_ip_addr),
4928 TEST_CASE(test_balance_l34_tx_burst_ipv6_toggle_udp_port),
4929 TEST_CASE(test_balance_tx_burst_slave_tx_fail),
4930 TEST_CASE(test_balance_rx_burst),
4931 TEST_CASE(test_balance_verify_promiscuous_enable_disable),
4932 TEST_CASE(test_balance_verify_mac_assignment),
4933 TEST_CASE(test_balance_verify_slave_link_status_change_behaviour),
4934 TEST_CASE(test_tlb_tx_burst),
4935 TEST_CASE(test_tlb_rx_burst),
4936 TEST_CASE(test_tlb_verify_mac_assignment),
4937 TEST_CASE(test_tlb_verify_promiscuous_enable_disable),
4938 TEST_CASE(test_tlb_verify_slave_link_status_change_failover),
4939 TEST_CASE(test_alb_change_mac_in_reply_sent),
4940 TEST_CASE(test_alb_reply_from_client),
4941 TEST_CASE(test_alb_receive_vlan_reply),
4942 TEST_CASE(test_alb_ipv4_tx),
4943 TEST_CASE(test_broadcast_tx_burst),
4944 TEST_CASE(test_broadcast_tx_burst_slave_tx_fail),
4945 TEST_CASE(test_broadcast_rx_burst),
4946 TEST_CASE(test_broadcast_verify_promiscuous_enable_disable),
4947 TEST_CASE(test_broadcast_verify_mac_assignment),
4948 TEST_CASE(test_broadcast_verify_slave_link_status_change_behaviour),
4949 TEST_CASE(test_reconfigure_bonded_device),
4950 TEST_CASE(test_close_bonded_device),
4952 TEST_CASES_END() /**< NULL terminate unit test array */
4958 test_link_bonding(void)
4960 return unit_test_suite_runner(&link_bonding_test_suite);
4963 REGISTER_TEST_COMMAND(link_bonding_autotest, test_link_bonding);