1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <sys/queue.h>
15 #include <rte_cycles.h>
16 #include <rte_byteorder.h>
17 #include <rte_common.h>
18 #include <rte_debug.h>
19 #include <rte_ethdev.h>
20 #include <rte_ethdev_driver.h>
22 #include <rte_lcore.h>
23 #include <rte_memory.h>
24 #include <rte_string_fns.h>
25 #include <rte_eth_bond.h>
27 #include "virtual_pmd.h"
28 #include "packet_burst_generator.h"
32 #define TEST_MAX_NUMBER_OF_PORTS (6)
34 #define RX_RING_SIZE 1024
35 #define RX_FREE_THRESH 32
40 #define TX_RING_SIZE 1024
41 #define TX_FREE_THRESH 32
45 #define TX_RSBIT_THRESH 32
47 #define MBUF_CACHE_SIZE (250)
48 #define BURST_SIZE (32)
50 #define RTE_TEST_RX_DESC_MAX (2048)
51 #define RTE_TEST_TX_DESC_MAX (2048)
52 #define MAX_PKT_BURST (512)
53 #define DEF_PKT_BURST (16)
55 #define BONDED_DEV_NAME ("net_bonding_ut")
57 #define INVALID_SOCKET_ID (-1)
58 #define INVALID_PORT_ID (-1)
59 #define INVALID_BONDING_MODE (-1)
62 uint8_t slave_mac[] = {0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 };
63 uint8_t bonded_mac[] = {0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
65 struct link_bonding_unittest_params {
66 int16_t bonded_port_id;
67 int16_t slave_port_ids[TEST_MAX_NUMBER_OF_PORTS];
68 uint16_t bonded_slave_count;
74 struct rte_mempool *mbuf_pool;
76 struct rte_ether_addr *default_slave_mac;
77 struct rte_ether_addr *default_bonded_mac;
80 struct rte_ether_hdr *pkt_eth_hdr;
81 struct rte_ipv4_hdr *pkt_ipv4_hdr;
82 struct rte_ipv6_hdr *pkt_ipv6_hdr;
83 struct rte_udp_hdr *pkt_udp_hdr;
87 static struct rte_ipv4_hdr pkt_ipv4_hdr;
88 static struct rte_ipv6_hdr pkt_ipv6_hdr;
89 static struct rte_udp_hdr pkt_udp_hdr;
91 static struct link_bonding_unittest_params default_params = {
93 .slave_port_ids = { -1 },
94 .bonded_slave_count = 0,
95 .bonding_mode = BONDING_MODE_ROUND_ROBIN,
102 .default_slave_mac = (struct rte_ether_addr *)slave_mac,
103 .default_bonded_mac = (struct rte_ether_addr *)bonded_mac,
106 .pkt_ipv4_hdr = &pkt_ipv4_hdr,
107 .pkt_ipv6_hdr = &pkt_ipv6_hdr,
108 .pkt_udp_hdr = &pkt_udp_hdr
112 static struct link_bonding_unittest_params *test_params = &default_params;
114 static uint8_t src_mac[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
115 static uint8_t dst_mac_0[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
116 static uint8_t dst_mac_1[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAB };
118 static uint32_t src_addr = IPV4_ADDR(192, 168, 1, 98);
119 static uint32_t dst_addr_0 = IPV4_ADDR(192, 168, 1, 98);
120 static uint32_t dst_addr_1 = IPV4_ADDR(193, 166, 10, 97);
122 static uint8_t src_ipv6_addr[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF,
123 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA , 0xFF, 0xAA };
124 static uint8_t dst_ipv6_addr_0[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF,
125 0xAA, 0xFF, 0xAA, 0xFF, 0xAA , 0xFF, 0xAA, 0xFF, 0xAA };
126 static uint8_t dst_ipv6_addr_1[] = { 0xFF, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF,
127 0xAA, 0xFF, 0xAA, 0xFF, 0xAA , 0xFF, 0xAA , 0xFF, 0xAB };
129 static uint16_t src_port = 1024;
130 static uint16_t dst_port_0 = 1024;
131 static uint16_t dst_port_1 = 2024;
133 static uint16_t vlan_id = 0x100;
135 static struct rte_eth_conf default_pmd_conf = {
137 .mq_mode = ETH_MQ_RX_NONE,
139 .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
142 .mq_mode = ETH_MQ_TX_NONE,
147 static const struct rte_eth_rxconf rx_conf_default = {
149 .pthresh = RX_PTHRESH,
150 .hthresh = RX_HTHRESH,
151 .wthresh = RX_WTHRESH,
153 .rx_free_thresh = RX_FREE_THRESH,
157 static struct rte_eth_txconf tx_conf_default = {
159 .pthresh = TX_PTHRESH,
160 .hthresh = TX_HTHRESH,
161 .wthresh = TX_WTHRESH,
163 .tx_free_thresh = TX_FREE_THRESH,
164 .tx_rs_thresh = TX_RSBIT_THRESH,
167 static void free_virtualpmd_tx_queue(void);
172 configure_ethdev(uint16_t port_id, uint8_t start, uint8_t en_isr)
177 default_pmd_conf.intr_conf.lsc = 1;
179 default_pmd_conf.intr_conf.lsc = 0;
181 TEST_ASSERT_SUCCESS(rte_eth_dev_configure(port_id, test_params->nb_rx_q,
182 test_params->nb_tx_q, &default_pmd_conf),
183 "rte_eth_dev_configure for port %d failed", port_id);
185 for (q_id = 0; q_id < test_params->nb_rx_q; q_id++)
186 TEST_ASSERT_SUCCESS(rte_eth_rx_queue_setup(port_id, q_id, RX_RING_SIZE,
187 rte_eth_dev_socket_id(port_id), &rx_conf_default,
188 test_params->mbuf_pool) ,
189 "rte_eth_rx_queue_setup for port %d failed", port_id);
191 for (q_id = 0; q_id < test_params->nb_tx_q; q_id++)
192 TEST_ASSERT_SUCCESS(rte_eth_tx_queue_setup(port_id, q_id, TX_RING_SIZE,
193 rte_eth_dev_socket_id(port_id), &tx_conf_default),
194 "rte_eth_tx_queue_setup for port %d failed", port_id);
197 TEST_ASSERT_SUCCESS(rte_eth_dev_start(port_id),
198 "rte_eth_dev_start for port %d failed", port_id);
203 static int slaves_initialized;
204 static int mac_slaves_initialized;
206 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
207 static pthread_cond_t cvar = PTHREAD_COND_INITIALIZER;
213 int i, nb_mbuf_per_pool;
214 struct rte_ether_addr *mac_addr = (struct rte_ether_addr *)slave_mac;
216 /* Allocate ethernet packet header with space for VLAN header */
217 if (test_params->pkt_eth_hdr == NULL) {
218 test_params->pkt_eth_hdr = malloc(sizeof(struct rte_ether_hdr) +
219 sizeof(struct rte_vlan_hdr));
221 TEST_ASSERT_NOT_NULL(test_params->pkt_eth_hdr,
222 "Ethernet header struct allocation failed!");
225 nb_mbuf_per_pool = RTE_TEST_RX_DESC_MAX + DEF_PKT_BURST +
226 RTE_TEST_TX_DESC_MAX + MAX_PKT_BURST;
227 if (test_params->mbuf_pool == NULL) {
228 test_params->mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL",
229 nb_mbuf_per_pool, MBUF_CACHE_SIZE, 0,
230 RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
231 TEST_ASSERT_NOT_NULL(test_params->mbuf_pool,
232 "rte_mempool_create failed");
235 /* Create / Initialize virtual eth devs */
236 if (!slaves_initialized) {
237 for (i = 0; i < TEST_MAX_NUMBER_OF_PORTS; i++) {
238 char pmd_name[RTE_ETH_NAME_MAX_LEN];
240 mac_addr->addr_bytes[RTE_ETHER_ADDR_LEN-1] = i;
242 snprintf(pmd_name, RTE_ETH_NAME_MAX_LEN, "eth_virt_%d", i);
244 test_params->slave_port_ids[i] = virtual_ethdev_create(pmd_name,
245 mac_addr, rte_socket_id(), 1);
246 TEST_ASSERT(test_params->slave_port_ids[i] >= 0,
247 "Failed to create virtual virtual ethdev %s", pmd_name);
249 TEST_ASSERT_SUCCESS(configure_ethdev(
250 test_params->slave_port_ids[i], 1, 0),
251 "Failed to configure virtual ethdev %s", pmd_name);
253 slaves_initialized = 1;
260 test_create_bonded_device(void)
262 int current_slave_count;
264 uint16_t slaves[RTE_MAX_ETHPORTS];
266 /* Don't try to recreate bonded device if re-running test suite*/
267 if (test_params->bonded_port_id == -1) {
268 test_params->bonded_port_id = rte_eth_bond_create(BONDED_DEV_NAME,
269 test_params->bonding_mode, rte_socket_id());
271 TEST_ASSERT(test_params->bonded_port_id >= 0,
272 "Failed to create bonded ethdev %s", BONDED_DEV_NAME);
274 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0, 0),
275 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME);
278 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
279 test_params->bonding_mode), "Failed to set ethdev %d to mode %d",
280 test_params->bonded_port_id, test_params->bonding_mode);
282 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
283 slaves, RTE_MAX_ETHPORTS);
285 TEST_ASSERT_EQUAL(current_slave_count, 0,
286 "Number of slaves %d is great than expected %d.",
287 current_slave_count, 0);
289 current_slave_count = rte_eth_bond_active_slaves_get(
290 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
292 TEST_ASSERT_EQUAL(current_slave_count, 0,
293 "Number of active slaves %d is great than expected %d.",
294 current_slave_count, 0);
301 test_create_bonded_device_with_invalid_params(void)
305 test_params->bonding_mode = BONDING_MODE_ROUND_ROBIN;
308 port_id = rte_eth_bond_create(NULL, test_params->bonding_mode,
310 TEST_ASSERT(port_id < 0, "Created bonded device unexpectedly");
312 test_params->bonding_mode = INVALID_BONDING_MODE;
314 /* Invalid bonding mode */
315 port_id = rte_eth_bond_create(BONDED_DEV_NAME, test_params->bonding_mode,
317 TEST_ASSERT(port_id < 0, "Created bonded device unexpectedly.");
319 test_params->bonding_mode = BONDING_MODE_ROUND_ROBIN;
321 /* Invalid socket id */
322 port_id = rte_eth_bond_create(BONDED_DEV_NAME, test_params->bonding_mode,
324 TEST_ASSERT(port_id < 0, "Created bonded device unexpectedly.");
330 test_add_slave_to_bonded_device(void)
332 int current_slave_count;
334 uint16_t slaves[RTE_MAX_ETHPORTS];
336 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params->bonded_port_id,
337 test_params->slave_port_ids[test_params->bonded_slave_count]),
338 "Failed to add slave (%d) to bonded port (%d).",
339 test_params->slave_port_ids[test_params->bonded_slave_count],
340 test_params->bonded_port_id);
342 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
343 slaves, RTE_MAX_ETHPORTS);
344 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count + 1,
345 "Number of slaves (%d) is greater than expected (%d).",
346 current_slave_count, test_params->bonded_slave_count + 1);
348 current_slave_count = rte_eth_bond_active_slaves_get(
349 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
350 TEST_ASSERT_EQUAL(current_slave_count, 0,
351 "Number of active slaves (%d) is not as expected (%d).\n",
352 current_slave_count, 0);
354 test_params->bonded_slave_count++;
360 test_add_slave_to_invalid_bonded_device(void)
362 /* Invalid port ID */
363 TEST_ASSERT_FAIL(rte_eth_bond_slave_add(test_params->bonded_port_id + 5,
364 test_params->slave_port_ids[test_params->bonded_slave_count]),
365 "Expected call to failed as invalid port specified.");
367 /* Non bonded device */
368 TEST_ASSERT_FAIL(rte_eth_bond_slave_add(test_params->slave_port_ids[0],
369 test_params->slave_port_ids[test_params->bonded_slave_count]),
370 "Expected call to failed as invalid port specified.");
377 test_remove_slave_from_bonded_device(void)
379 int current_slave_count;
380 struct rte_ether_addr read_mac_addr, *mac_addr;
381 uint16_t slaves[RTE_MAX_ETHPORTS];
383 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_remove(test_params->bonded_port_id,
384 test_params->slave_port_ids[test_params->bonded_slave_count-1]),
385 "Failed to remove slave %d from bonded port (%d).",
386 test_params->slave_port_ids[test_params->bonded_slave_count-1],
387 test_params->bonded_port_id);
390 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
391 slaves, RTE_MAX_ETHPORTS);
393 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count - 1,
394 "Number of slaves (%d) is great than expected (%d).\n",
395 current_slave_count, test_params->bonded_slave_count - 1);
398 mac_addr = (struct rte_ether_addr *)slave_mac;
399 mac_addr->addr_bytes[RTE_ETHER_ADDR_LEN-1] =
400 test_params->bonded_slave_count-1;
403 test_params->slave_port_ids[test_params->bonded_slave_count-1],
405 TEST_ASSERT_SUCCESS(memcmp(mac_addr, &read_mac_addr, sizeof(read_mac_addr)),
406 "bonded port mac address not set to that of primary port\n");
409 test_params->slave_port_ids[test_params->bonded_slave_count-1]);
411 virtual_ethdev_simulate_link_status_interrupt(test_params->bonded_port_id,
414 test_params->bonded_slave_count--;
420 test_remove_slave_from_invalid_bonded_device(void)
422 /* Invalid port ID */
423 TEST_ASSERT_FAIL(rte_eth_bond_slave_remove(
424 test_params->bonded_port_id + 5,
425 test_params->slave_port_ids[test_params->bonded_slave_count - 1]),
426 "Expected call to failed as invalid port specified.");
428 /* Non bonded device */
429 TEST_ASSERT_FAIL(rte_eth_bond_slave_remove(
430 test_params->slave_port_ids[0],
431 test_params->slave_port_ids[test_params->bonded_slave_count - 1]),
432 "Expected call to failed as invalid port specified.");
437 static int bonded_id = 2;
440 test_add_already_bonded_slave_to_bonded_device(void)
442 int port_id, current_slave_count;
443 uint16_t slaves[RTE_MAX_ETHPORTS];
444 char pmd_name[RTE_ETH_NAME_MAX_LEN];
446 test_add_slave_to_bonded_device();
448 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
449 slaves, RTE_MAX_ETHPORTS);
450 TEST_ASSERT_EQUAL(current_slave_count, 1,
451 "Number of slaves (%d) is not that expected (%d).",
452 current_slave_count, 1);
454 snprintf(pmd_name, RTE_ETH_NAME_MAX_LEN, "%s_%d", BONDED_DEV_NAME, ++bonded_id);
456 port_id = rte_eth_bond_create(pmd_name, test_params->bonding_mode,
458 TEST_ASSERT(port_id >= 0, "Failed to create bonded device.");
460 TEST_ASSERT(rte_eth_bond_slave_add(port_id,
461 test_params->slave_port_ids[test_params->bonded_slave_count - 1])
463 "Added slave (%d) to bonded port (%d) unexpectedly.",
464 test_params->slave_port_ids[test_params->bonded_slave_count-1],
467 return test_remove_slave_from_bonded_device();
472 test_get_slaves_from_bonded_device(void)
474 int current_slave_count;
475 uint16_t slaves[RTE_MAX_ETHPORTS];
477 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
478 "Failed to add slave to bonded device");
480 /* Invalid port id */
481 current_slave_count = rte_eth_bond_slaves_get(INVALID_PORT_ID, slaves,
483 TEST_ASSERT(current_slave_count < 0,
484 "Invalid port id unexpectedly succeeded");
486 current_slave_count = rte_eth_bond_active_slaves_get(INVALID_PORT_ID,
487 slaves, RTE_MAX_ETHPORTS);
488 TEST_ASSERT(current_slave_count < 0,
489 "Invalid port id unexpectedly succeeded");
491 /* Invalid slaves pointer */
492 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
493 NULL, RTE_MAX_ETHPORTS);
494 TEST_ASSERT(current_slave_count < 0,
495 "Invalid slave array unexpectedly succeeded");
497 current_slave_count = rte_eth_bond_active_slaves_get(
498 test_params->bonded_port_id, NULL, RTE_MAX_ETHPORTS);
499 TEST_ASSERT(current_slave_count < 0,
500 "Invalid slave array unexpectedly succeeded");
502 /* non bonded device*/
503 current_slave_count = rte_eth_bond_slaves_get(
504 test_params->slave_port_ids[0], NULL, RTE_MAX_ETHPORTS);
505 TEST_ASSERT(current_slave_count < 0,
506 "Invalid port id unexpectedly succeeded");
508 current_slave_count = rte_eth_bond_active_slaves_get(
509 test_params->slave_port_ids[0], NULL, RTE_MAX_ETHPORTS);
510 TEST_ASSERT(current_slave_count < 0,
511 "Invalid port id unexpectedly succeeded");
513 TEST_ASSERT_SUCCESS(test_remove_slave_from_bonded_device(),
514 "Failed to remove slaves from bonded device");
521 test_add_remove_multiple_slaves_to_from_bonded_device(void)
525 for (i = 0; i < TEST_MAX_NUMBER_OF_PORTS; i++)
526 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
527 "Failed to add slave to bonded device");
529 for (i = 0; i < TEST_MAX_NUMBER_OF_PORTS; i++)
530 TEST_ASSERT_SUCCESS(test_remove_slave_from_bonded_device(),
531 "Failed to remove slaves from bonded device");
537 enable_bonded_slaves(void)
541 for (i = 0; i < test_params->bonded_slave_count; i++) {
542 virtual_ethdev_tx_burst_fn_set_success(test_params->slave_port_ids[i],
545 virtual_ethdev_simulate_link_status_interrupt(
546 test_params->slave_port_ids[i], 1);
551 test_start_bonded_device(void)
553 struct rte_eth_link link_status;
555 int current_slave_count, current_bonding_mode, primary_port;
556 uint16_t slaves[RTE_MAX_ETHPORTS];
559 /* Add slave to bonded device*/
560 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
561 "Failed to add slave to bonded device");
563 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
564 "Failed to start bonded pmd eth device %d.",
565 test_params->bonded_port_id);
567 /* Change link status of virtual pmd so it will be added to the active
568 * slave list of the bonded device*/
569 virtual_ethdev_simulate_link_status_interrupt(
570 test_params->slave_port_ids[test_params->bonded_slave_count-1], 1);
572 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
573 slaves, RTE_MAX_ETHPORTS);
574 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count,
575 "Number of slaves (%d) is not expected value (%d).",
576 current_slave_count, test_params->bonded_slave_count);
578 current_slave_count = rte_eth_bond_active_slaves_get(
579 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
580 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count,
581 "Number of active slaves (%d) is not expected value (%d).",
582 current_slave_count, test_params->bonded_slave_count);
584 current_bonding_mode = rte_eth_bond_mode_get(test_params->bonded_port_id);
585 TEST_ASSERT_EQUAL(current_bonding_mode, test_params->bonding_mode,
586 "Bonded device mode (%d) is not expected value (%d).\n",
587 current_bonding_mode, test_params->bonding_mode);
589 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
590 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[0],
591 "Primary port (%d) is not expected value (%d).",
592 primary_port, test_params->slave_port_ids[0]);
594 retval = rte_eth_link_get(test_params->bonded_port_id, &link_status);
595 TEST_ASSERT(retval >= 0,
596 "Bonded port (%d) link get failed: %s\n",
597 test_params->bonded_port_id, rte_strerror(-retval));
598 TEST_ASSERT_EQUAL(link_status.link_status, 1,
599 "Bonded port (%d) status (%d) is not expected value (%d).\n",
600 test_params->bonded_port_id, link_status.link_status, 1);
606 test_stop_bonded_device(void)
608 int current_slave_count;
609 uint16_t slaves[RTE_MAX_ETHPORTS];
611 struct rte_eth_link link_status;
614 rte_eth_dev_stop(test_params->bonded_port_id);
616 retval = rte_eth_link_get(test_params->bonded_port_id, &link_status);
617 TEST_ASSERT(retval >= 0,
618 "Bonded port (%d) link get failed: %s\n",
619 test_params->bonded_port_id, rte_strerror(-retval));
620 TEST_ASSERT_EQUAL(link_status.link_status, 0,
621 "Bonded port (%d) status (%d) is not expected value (%d).",
622 test_params->bonded_port_id, link_status.link_status, 0);
624 current_slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id,
625 slaves, RTE_MAX_ETHPORTS);
626 TEST_ASSERT_EQUAL(current_slave_count, test_params->bonded_slave_count,
627 "Number of slaves (%d) is not expected value (%d).",
628 current_slave_count, test_params->bonded_slave_count);
630 current_slave_count = rte_eth_bond_active_slaves_get(
631 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS);
632 TEST_ASSERT_EQUAL(current_slave_count, 0,
633 "Number of active slaves (%d) is not expected value (%d).",
634 current_slave_count, 0);
640 remove_slaves_and_stop_bonded_device(void)
642 /* Clean up and remove slaves from bonded device */
643 free_virtualpmd_tx_queue();
644 while (test_params->bonded_slave_count > 0)
645 TEST_ASSERT_SUCCESS(test_remove_slave_from_bonded_device(),
646 "test_remove_slave_from_bonded_device failed");
648 rte_eth_dev_stop(test_params->bonded_port_id);
649 rte_eth_stats_reset(test_params->bonded_port_id);
650 rte_eth_bond_mac_address_reset(test_params->bonded_port_id);
656 test_set_bonding_mode(void)
660 int bonding_modes[] = { BONDING_MODE_ROUND_ROBIN,
661 BONDING_MODE_ACTIVE_BACKUP,
662 BONDING_MODE_BALANCE,
663 BONDING_MODE_BROADCAST
666 /* Test supported link bonding modes */
667 for (i = 0; i < (int)RTE_DIM(bonding_modes); i++) {
668 /* Invalid port ID */
669 TEST_ASSERT_FAIL(rte_eth_bond_mode_set(INVALID_PORT_ID,
671 "Expected call to failed as invalid port (%d) specified.",
674 /* Non bonded device */
675 TEST_ASSERT_FAIL(rte_eth_bond_mode_set(test_params->slave_port_ids[0],
677 "Expected call to failed as invalid port (%d) specified.",
678 test_params->slave_port_ids[0]);
680 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
682 "Failed to set link bonding mode on port (%d) to (%d).",
683 test_params->bonded_port_id, bonding_modes[i]);
685 bonding_mode = rte_eth_bond_mode_get(test_params->bonded_port_id);
686 TEST_ASSERT_EQUAL(bonding_mode, bonding_modes[i],
687 "Link bonding mode (%d) of port (%d) is not expected value (%d).",
688 bonding_mode, test_params->bonded_port_id,
691 /* Invalid port ID */
692 bonding_mode = rte_eth_bond_mode_get(INVALID_PORT_ID);
693 TEST_ASSERT(bonding_mode < 0,
694 "Expected call to failed as invalid port (%d) specified.",
697 /* Non bonded device */
698 bonding_mode = rte_eth_bond_mode_get(test_params->slave_port_ids[0]);
699 TEST_ASSERT(bonding_mode < 0,
700 "Expected call to failed as invalid port (%d) specified.",
701 test_params->slave_port_ids[0]);
704 return remove_slaves_and_stop_bonded_device();
708 test_set_primary_slave(void)
711 struct rte_ether_addr read_mac_addr;
712 struct rte_ether_addr *expected_mac_addr;
714 /* Add 4 slaves to bonded device */
715 for (i = test_params->bonded_slave_count; i < 4; i++)
716 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
717 "Failed to add slave to bonded device.");
719 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
720 BONDING_MODE_ROUND_ROBIN),
721 "Failed to set link bonding mode on port (%d) to (%d).",
722 test_params->bonded_port_id, BONDING_MODE_ROUND_ROBIN);
724 /* Invalid port ID */
725 TEST_ASSERT_FAIL(rte_eth_bond_primary_set(INVALID_PORT_ID,
726 test_params->slave_port_ids[i]),
727 "Expected call to failed as invalid port specified.");
729 /* Non bonded device */
730 TEST_ASSERT_FAIL(rte_eth_bond_primary_set(test_params->slave_port_ids[i],
731 test_params->slave_port_ids[i]),
732 "Expected call to failed as invalid port specified.");
734 /* Set slave as primary
735 * Verify slave it is now primary slave
736 * Verify that MAC address of bonded device is that of primary slave
737 * Verify that MAC address of all bonded slaves are that of primary slave
739 for (i = 0; i < 4; i++) {
740 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(test_params->bonded_port_id,
741 test_params->slave_port_ids[i]),
742 "Failed to set bonded port (%d) primary port to (%d)",
743 test_params->bonded_port_id, test_params->slave_port_ids[i]);
745 retval = rte_eth_bond_primary_get(test_params->bonded_port_id);
746 TEST_ASSERT(retval >= 0,
747 "Failed to read primary port from bonded port (%d)\n",
748 test_params->bonded_port_id);
750 TEST_ASSERT_EQUAL(retval, test_params->slave_port_ids[i],
751 "Bonded port (%d) primary port (%d) not expected value (%d)\n",
752 test_params->bonded_port_id, retval,
753 test_params->slave_port_ids[i]);
755 /* stop/start bonded eth dev to apply new MAC */
756 rte_eth_dev_stop(test_params->bonded_port_id);
758 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
759 "Failed to start bonded port %d",
760 test_params->bonded_port_id);
762 expected_mac_addr = (struct rte_ether_addr *)&slave_mac;
763 expected_mac_addr->addr_bytes[RTE_ETHER_ADDR_LEN-1] = i;
765 /* Check primary slave MAC */
766 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
767 TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
768 sizeof(read_mac_addr)),
769 "bonded port mac address not set to that of primary port\n");
771 /* Check bonded MAC */
772 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
773 TEST_ASSERT_SUCCESS(memcmp(&read_mac_addr, &read_mac_addr,
774 sizeof(read_mac_addr)),
775 "bonded port mac address not set to that of primary port\n");
777 /* Check other slaves MACs */
778 for (j = 0; j < 4; j++) {
780 rte_eth_macaddr_get(test_params->slave_port_ids[j],
782 TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
783 sizeof(read_mac_addr)),
784 "slave port mac address not set to that of primary "
791 /* Test with none existent port */
792 TEST_ASSERT_FAIL(rte_eth_bond_primary_get(test_params->bonded_port_id + 10),
793 "read primary port from expectedly");
795 /* Test with slave port */
796 TEST_ASSERT_FAIL(rte_eth_bond_primary_get(test_params->slave_port_ids[0]),
797 "read primary port from expectedly\n");
799 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
800 "Failed to stop and remove slaves from bonded device");
803 TEST_ASSERT(rte_eth_bond_primary_get(test_params->bonded_port_id) < 0,
804 "read primary port from expectedly\n");
810 test_set_explicit_bonded_mac(void)
813 struct rte_ether_addr read_mac_addr;
814 struct rte_ether_addr *mac_addr;
816 uint8_t explicit_bonded_mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01 };
818 mac_addr = (struct rte_ether_addr *)explicit_bonded_mac;
820 /* Invalid port ID */
821 TEST_ASSERT_FAIL(rte_eth_bond_mac_address_set(INVALID_PORT_ID, mac_addr),
822 "Expected call to failed as invalid port specified.");
824 /* Non bonded device */
825 TEST_ASSERT_FAIL(rte_eth_bond_mac_address_set(
826 test_params->slave_port_ids[0], mac_addr),
827 "Expected call to failed as invalid port specified.");
829 /* NULL MAC address */
830 TEST_ASSERT_FAIL(rte_eth_bond_mac_address_set(
831 test_params->bonded_port_id, NULL),
832 "Expected call to failed as NULL MAC specified");
834 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
835 test_params->bonded_port_id, mac_addr),
836 "Failed to set MAC address on bonded port (%d)",
837 test_params->bonded_port_id);
839 /* Add 4 slaves to bonded device */
840 for (i = test_params->bonded_slave_count; i < 4; i++) {
841 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
842 "Failed to add slave to bonded device.\n");
845 /* Check bonded MAC */
846 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
847 TEST_ASSERT_SUCCESS(memcmp(mac_addr, &read_mac_addr, sizeof(read_mac_addr)),
848 "bonded port mac address not set to that of primary port");
850 /* Check other slaves MACs */
851 for (i = 0; i < 4; i++) {
852 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
853 TEST_ASSERT_SUCCESS(memcmp(mac_addr, &read_mac_addr,
854 sizeof(read_mac_addr)),
855 "slave port mac address not set to that of primary port");
858 /* test resetting mac address on bonded device */
860 rte_eth_bond_mac_address_reset(test_params->bonded_port_id),
861 "Failed to reset MAC address on bonded port (%d)",
862 test_params->bonded_port_id);
865 rte_eth_bond_mac_address_reset(test_params->slave_port_ids[0]),
866 "Reset MAC address on bonded port (%d) unexpectedly",
867 test_params->slave_port_ids[1]);
869 /* test resetting mac address on bonded device with no slaves */
870 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
871 "Failed to remove slaves and stop bonded device");
873 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_reset(test_params->bonded_port_id),
874 "Failed to reset MAC address on bonded port (%d)",
875 test_params->bonded_port_id);
880 #define BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT (3)
883 test_set_bonded_port_initialization_mac_assignment(void)
887 uint16_t slaves[RTE_MAX_ETHPORTS];
888 static int bonded_port_id = -1;
889 static int slave_port_ids[BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT];
891 struct rte_ether_addr slave_mac_addr, bonded_mac_addr, read_mac_addr;
893 /* Initialize default values for MAC addresses */
894 memcpy(&slave_mac_addr, slave_mac, sizeof(struct rte_ether_addr));
895 memcpy(&bonded_mac_addr, slave_mac, sizeof(struct rte_ether_addr));
898 * 1. a - Create / configure bonded / slave ethdevs
900 if (bonded_port_id == -1) {
901 bonded_port_id = rte_eth_bond_create("net_bonding_mac_ass_test",
902 BONDING_MODE_ACTIVE_BACKUP, rte_socket_id());
903 TEST_ASSERT(bonded_port_id > 0, "failed to create bonded device");
905 TEST_ASSERT_SUCCESS(configure_ethdev(bonded_port_id, 0, 0),
906 "Failed to configure bonded ethdev");
909 if (!mac_slaves_initialized) {
910 for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
911 char pmd_name[RTE_ETH_NAME_MAX_LEN];
913 slave_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
916 snprintf(pmd_name, RTE_ETH_NAME_MAX_LEN,
919 slave_port_ids[i] = virtual_ethdev_create(pmd_name,
920 &slave_mac_addr, rte_socket_id(), 1);
922 TEST_ASSERT(slave_port_ids[i] >= 0,
923 "Failed to create slave ethdev %s",
926 TEST_ASSERT_SUCCESS(configure_ethdev(slave_port_ids[i], 1, 0),
927 "Failed to configure virtual ethdev %s",
930 mac_slaves_initialized = 1;
935 * 2. Add slave ethdevs to bonded device
937 for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
938 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(bonded_port_id,
940 "Failed to add slave (%d) to bonded port (%d).",
941 slave_port_ids[i], bonded_port_id);
944 slave_count = rte_eth_bond_slaves_get(bonded_port_id, slaves,
946 TEST_ASSERT_EQUAL(BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT, slave_count,
947 "Number of slaves (%d) is not as expected (%d)",
948 slave_count, BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT);
952 * 3. Set explicit MAC address on bonded ethdev
954 bonded_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN-2] = 0xFF;
955 bonded_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN-1] = 0xAA;
957 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
958 bonded_port_id, &bonded_mac_addr),
959 "Failed to set MAC address on bonded port (%d)",
963 /* 4. a - Start bonded ethdev
964 * b - Enable slave devices
965 * c - Verify bonded/slaves ethdev MAC addresses
967 TEST_ASSERT_SUCCESS(rte_eth_dev_start(bonded_port_id),
968 "Failed to start bonded pmd eth device %d.",
971 for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
972 virtual_ethdev_simulate_link_status_interrupt(
973 slave_port_ids[i], 1);
976 rte_eth_macaddr_get(bonded_port_id, &read_mac_addr);
977 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
978 sizeof(read_mac_addr)),
979 "bonded port mac address not as expected");
981 rte_eth_macaddr_get(slave_port_ids[0], &read_mac_addr);
982 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
983 sizeof(read_mac_addr)),
984 "slave port 0 mac address not as expected");
986 slave_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN-1] = 1 + 100;
987 rte_eth_macaddr_get(slave_port_ids[1], &read_mac_addr);
988 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
989 sizeof(read_mac_addr)),
990 "slave port 1 mac address not as expected");
992 slave_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN-1] = 2 + 100;
993 rte_eth_macaddr_get(slave_port_ids[2], &read_mac_addr);
994 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
995 sizeof(read_mac_addr)),
996 "slave port 2 mac address not as expected");
999 /* 7. a - Change primary port
1000 * b - Stop / Start bonded port
1001 * d - Verify slave ethdev MAC addresses
1003 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(bonded_port_id,
1005 "failed to set primary port on bonded device.");
1007 rte_eth_dev_stop(bonded_port_id);
1008 TEST_ASSERT_SUCCESS(rte_eth_dev_start(bonded_port_id),
1009 "Failed to start bonded pmd eth device %d.",
1012 rte_eth_macaddr_get(bonded_port_id, &read_mac_addr);
1013 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
1014 sizeof(read_mac_addr)),
1015 "bonded port mac address not as expected");
1017 slave_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN-1] = 0 + 100;
1018 rte_eth_macaddr_get(slave_port_ids[0], &read_mac_addr);
1019 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1020 sizeof(read_mac_addr)),
1021 "slave port 0 mac address not as expected");
1023 slave_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN-1] = 1 + 100;
1024 rte_eth_macaddr_get(slave_port_ids[1], &read_mac_addr);
1025 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1026 sizeof(read_mac_addr)),
1027 "slave port 1 mac address not as expected");
1029 rte_eth_macaddr_get(slave_port_ids[2], &read_mac_addr);
1030 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac_addr, &read_mac_addr,
1031 sizeof(read_mac_addr)),
1032 "slave port 2 mac address not as expected");
1034 /* 6. a - Stop bonded ethdev
1035 * b - remove slave ethdevs
1036 * c - Verify slave ethdevs MACs are restored
1038 rte_eth_dev_stop(bonded_port_id);
1040 for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
1041 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_remove(bonded_port_id,
1043 "Failed to remove slave %d from bonded port (%d).",
1044 slave_port_ids[i], bonded_port_id);
1047 slave_count = rte_eth_bond_slaves_get(bonded_port_id, slaves,
1050 TEST_ASSERT_EQUAL(slave_count, 0,
1051 "Number of slaves (%d) is great than expected (%d).",
1054 slave_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN-1] = 0 + 100;
1055 rte_eth_macaddr_get(slave_port_ids[0], &read_mac_addr);
1056 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1057 sizeof(read_mac_addr)),
1058 "slave port 0 mac address not as expected");
1060 slave_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN-1] = 1 + 100;
1061 rte_eth_macaddr_get(slave_port_ids[1], &read_mac_addr);
1062 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1063 sizeof(read_mac_addr)),
1064 "slave port 1 mac address not as expected");
1066 slave_mac_addr.addr_bytes[RTE_ETHER_ADDR_LEN-1] = 2 + 100;
1067 rte_eth_macaddr_get(slave_port_ids[2], &read_mac_addr);
1068 TEST_ASSERT_SUCCESS(memcmp(&slave_mac_addr, &read_mac_addr,
1069 sizeof(read_mac_addr)),
1070 "slave port 2 mac address not as expected");
1077 initialize_bonded_device_with_slaves(uint8_t bonding_mode, uint8_t bond_en_isr,
1078 uint16_t number_of_slaves, uint8_t enable_slave)
1080 /* Configure bonded device */
1081 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0,
1082 bond_en_isr), "Failed to configure bonding port (%d) in mode %d "
1083 "with (%d) slaves.", test_params->bonded_port_id, bonding_mode,
1086 /* Add slaves to bonded device */
1087 while (number_of_slaves > test_params->bonded_slave_count)
1088 TEST_ASSERT_SUCCESS(test_add_slave_to_bonded_device(),
1089 "Failed to add slave (%d to bonding port (%d).",
1090 test_params->bonded_slave_count - 1,
1091 test_params->bonded_port_id);
1093 /* Set link bonding mode */
1094 TEST_ASSERT_SUCCESS(rte_eth_bond_mode_set(test_params->bonded_port_id,
1096 "Failed to set link bonding mode on port (%d) to (%d).",
1097 test_params->bonded_port_id, bonding_mode);
1099 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
1100 "Failed to start bonded pmd eth device %d.",
1101 test_params->bonded_port_id);
1104 enable_bonded_slaves();
1110 test_adding_slave_after_bonded_device_started(void)
1114 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1115 BONDING_MODE_ROUND_ROBIN, 0, 4, 0),
1116 "Failed to add slaves to bonded device");
1118 /* Enabled slave devices */
1119 for (i = 0; i < test_params->bonded_slave_count + 1; i++) {
1120 virtual_ethdev_simulate_link_status_interrupt(
1121 test_params->slave_port_ids[i], 1);
1124 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params->bonded_port_id,
1125 test_params->slave_port_ids[test_params->bonded_slave_count]),
1126 "Failed to add slave to bonded port.\n");
1128 rte_eth_stats_reset(
1129 test_params->slave_port_ids[test_params->bonded_slave_count]);
1131 test_params->bonded_slave_count++;
1133 return remove_slaves_and_stop_bonded_device();
1136 #define TEST_STATUS_INTERRUPT_SLAVE_COUNT 4
1137 #define TEST_LSC_WAIT_TIMEOUT_MS 500
1139 int test_lsc_interrupt_count;
1143 test_bonding_lsc_event_callback(uint16_t port_id __rte_unused,
1144 enum rte_eth_event_type type __rte_unused,
1145 void *param __rte_unused,
1146 void *ret_param __rte_unused)
1148 pthread_mutex_lock(&mutex);
1149 test_lsc_interrupt_count++;
1151 pthread_cond_signal(&cvar);
1152 pthread_mutex_unlock(&mutex);
1158 lsc_timeout(int wait_us)
1165 gettimeofday(&tp, NULL);
1167 /* Convert from timeval to timespec */
1168 ts.tv_sec = tp.tv_sec;
1169 ts.tv_nsec = tp.tv_usec * 1000;
1170 ts.tv_nsec += wait_us * 1000;
1172 pthread_mutex_lock(&mutex);
1173 if (test_lsc_interrupt_count < 1)
1174 retval = pthread_cond_timedwait(&cvar, &mutex, &ts);
1176 pthread_mutex_unlock(&mutex);
1178 if (retval == 0 && test_lsc_interrupt_count < 1)
1185 test_status_interrupt(void)
1188 uint16_t slaves[RTE_MAX_ETHPORTS];
1190 /* initialized bonding device with T slaves */
1191 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1192 BONDING_MODE_ROUND_ROBIN, 1,
1193 TEST_STATUS_INTERRUPT_SLAVE_COUNT, 1),
1194 "Failed to initialise bonded device");
1196 test_lsc_interrupt_count = 0;
1198 /* register link status change interrupt callback */
1199 rte_eth_dev_callback_register(test_params->bonded_port_id,
1200 RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
1201 &test_params->bonded_port_id);
1203 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1204 slaves, RTE_MAX_ETHPORTS);
1206 TEST_ASSERT_EQUAL(slave_count, TEST_STATUS_INTERRUPT_SLAVE_COUNT,
1207 "Number of active slaves (%d) is not as expected (%d)",
1208 slave_count, TEST_STATUS_INTERRUPT_SLAVE_COUNT);
1210 /* Bring all 4 slaves link status to down and test that we have received a
1212 virtual_ethdev_simulate_link_status_interrupt(
1213 test_params->slave_port_ids[0], 0);
1214 virtual_ethdev_simulate_link_status_interrupt(
1215 test_params->slave_port_ids[1], 0);
1216 virtual_ethdev_simulate_link_status_interrupt(
1217 test_params->slave_port_ids[2], 0);
1219 TEST_ASSERT_EQUAL(test_lsc_interrupt_count, 0,
1220 "Received a link status change interrupt unexpectedly");
1222 virtual_ethdev_simulate_link_status_interrupt(
1223 test_params->slave_port_ids[3], 0);
1225 TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_MS) == 0,
1226 "timed out waiting for interrupt");
1228 TEST_ASSERT(test_lsc_interrupt_count > 0,
1229 "Did not receive link status change interrupt");
1231 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1232 slaves, RTE_MAX_ETHPORTS);
1234 TEST_ASSERT_EQUAL(slave_count, 0,
1235 "Number of active slaves (%d) is not as expected (%d)",
1238 /* bring one slave port up so link status will change */
1239 test_lsc_interrupt_count = 0;
1241 virtual_ethdev_simulate_link_status_interrupt(
1242 test_params->slave_port_ids[0], 1);
1244 TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_MS) == 0,
1245 "timed out waiting for interrupt");
1247 /* test that we have received another lsc interrupt */
1248 TEST_ASSERT(test_lsc_interrupt_count > 0,
1249 "Did not receive link status change interrupt");
1251 /* Verify that calling the same slave lsc interrupt doesn't cause another
1252 * lsc interrupt from bonded device */
1253 test_lsc_interrupt_count = 0;
1255 virtual_ethdev_simulate_link_status_interrupt(
1256 test_params->slave_port_ids[0], 1);
1258 TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_MS) != 0,
1259 "received unexpected interrupt");
1261 TEST_ASSERT_EQUAL(test_lsc_interrupt_count, 0,
1262 "Did not receive link status change interrupt");
1265 /* unregister lsc callback before exiting */
1266 rte_eth_dev_callback_unregister(test_params->bonded_port_id,
1267 RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
1268 &test_params->bonded_port_id);
1270 /* Clean up and remove slaves from bonded device */
1271 return remove_slaves_and_stop_bonded_device();
1275 generate_test_burst(struct rte_mbuf **pkts_burst, uint16_t burst_size,
1276 uint8_t vlan, uint8_t ipv4, uint8_t toggle_dst_mac,
1277 uint8_t toggle_ip_addr, uint16_t toggle_udp_port)
1279 uint16_t pktlen, generated_burst_size, ether_type;
1283 ether_type = RTE_ETHER_TYPE_IPV4;
1285 ether_type = RTE_ETHER_TYPE_IPV6;
1288 initialize_eth_header(test_params->pkt_eth_hdr,
1289 (struct rte_ether_addr *)src_mac,
1290 (struct rte_ether_addr *)dst_mac_1,
1291 ether_type, vlan, vlan_id);
1293 initialize_eth_header(test_params->pkt_eth_hdr,
1294 (struct rte_ether_addr *)src_mac,
1295 (struct rte_ether_addr *)dst_mac_0,
1296 ether_type, vlan, vlan_id);
1299 if (toggle_udp_port)
1300 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
1303 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
1308 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
1309 dst_addr_1, pktlen);
1311 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
1312 dst_addr_0, pktlen);
1314 ip_hdr = test_params->pkt_ipv4_hdr;
1317 pktlen = initialize_ipv6_header(test_params->pkt_ipv6_hdr,
1318 (uint8_t *)src_ipv6_addr, (uint8_t *)dst_ipv6_addr_1,
1321 pktlen = initialize_ipv6_header(test_params->pkt_ipv6_hdr,
1322 (uint8_t *)src_ipv6_addr, (uint8_t *)dst_ipv6_addr_0,
1325 ip_hdr = test_params->pkt_ipv6_hdr;
1328 /* Generate burst of packets to transmit */
1329 generated_burst_size = generate_packet_burst(test_params->mbuf_pool,
1330 pkts_burst, test_params->pkt_eth_hdr, vlan, ip_hdr, ipv4,
1331 test_params->pkt_udp_hdr, burst_size, PACKET_BURST_GEN_PKT_LEN_128,
1333 TEST_ASSERT_EQUAL(generated_burst_size, burst_size,
1334 "Failed to generate packet burst");
1336 return generated_burst_size;
1339 /** Round Robin Mode Tests */
1342 test_roundrobin_tx_burst(void)
1345 struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
1346 struct rte_eth_stats port_stats;
1348 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1349 BONDING_MODE_ROUND_ROBIN, 0, 2, 1),
1350 "Failed to initialise bonded device");
1352 burst_size = 20 * test_params->bonded_slave_count;
1354 TEST_ASSERT(burst_size <= MAX_PKT_BURST,
1355 "Burst size specified is greater than supported.");
1357 /* Generate test bursts of packets to transmit */
1358 TEST_ASSERT_EQUAL(generate_test_burst(pkt_burst, burst_size, 0, 1, 0, 0, 0),
1359 burst_size, "failed to generate test burst");
1361 /* Send burst on bonded port */
1362 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
1363 test_params->bonded_port_id, 0, pkt_burst, burst_size), burst_size,
1366 /* Verify bonded port tx stats */
1367 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1368 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
1369 "Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
1370 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
1373 /* Verify slave ports tx stats */
1374 for (i = 0; i < test_params->bonded_slave_count; i++) {
1375 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
1376 TEST_ASSERT_EQUAL(port_stats.opackets,
1377 (uint64_t)burst_size / test_params->bonded_slave_count,
1378 "Slave Port (%d) opackets value (%u) not as expected (%d)\n",
1379 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
1380 burst_size / test_params->bonded_slave_count);
1383 /* Put all slaves down and try and transmit */
1384 for (i = 0; i < test_params->bonded_slave_count; i++) {
1385 virtual_ethdev_simulate_link_status_interrupt(
1386 test_params->slave_port_ids[i], 0);
1389 /* Send burst on bonded port */
1390 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
1391 pkt_burst, burst_size), 0,
1392 "tx burst return unexpected value");
1394 /* Clean up and remove slaves from bonded device */
1395 return remove_slaves_and_stop_bonded_device();
1399 verify_mbufs_ref_count(struct rte_mbuf **mbufs, int nb_mbufs, int val)
1403 for (i = 0; i < nb_mbufs; i++) {
1404 refcnt = rte_mbuf_refcnt_read(mbufs[i]);
1405 TEST_ASSERT_EQUAL(refcnt, val,
1406 "mbuf ref count (%d)is not the expected value (%d)",
1413 free_mbufs(struct rte_mbuf **mbufs, int nb_mbufs)
1417 for (i = 0; i < nb_mbufs; i++)
1418 rte_pktmbuf_free(mbufs[i]);
1421 #define TEST_RR_SLAVE_TX_FAIL_SLAVE_COUNT (2)
1422 #define TEST_RR_SLAVE_TX_FAIL_BURST_SIZE (64)
1423 #define TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT (22)
1424 #define TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX (1)
1427 test_roundrobin_tx_burst_slave_tx_fail(void)
1429 struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
1430 struct rte_mbuf *expected_tx_fail_pkts[MAX_PKT_BURST];
1432 struct rte_eth_stats port_stats;
1434 int i, first_fail_idx, tx_count;
1436 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1437 BONDING_MODE_ROUND_ROBIN, 0,
1438 TEST_RR_SLAVE_TX_FAIL_SLAVE_COUNT, 1),
1439 "Failed to initialise bonded device");
1441 /* Generate test bursts of packets to transmit */
1442 TEST_ASSERT_EQUAL(generate_test_burst(pkt_burst,
1443 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE, 0, 1, 0, 0, 0),
1444 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE,
1445 "Failed to generate test packet burst");
1447 /* Copy references to packets which we expect not to be transmitted */
1448 first_fail_idx = (TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1449 (TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT *
1450 TEST_RR_SLAVE_TX_FAIL_SLAVE_COUNT)) +
1451 TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX;
1453 for (i = 0; i < TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT; i++) {
1454 expected_tx_fail_pkts[i] = pkt_burst[first_fail_idx +
1455 (i * TEST_RR_SLAVE_TX_FAIL_SLAVE_COUNT)];
1458 /* Set virtual slave to only fail transmission of
1459 * TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT packets in burst */
1460 virtual_ethdev_tx_burst_fn_set_success(
1461 test_params->slave_port_ids[TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX],
1464 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
1465 test_params->slave_port_ids[TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX],
1466 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT);
1468 tx_count = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkt_burst,
1469 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE);
1471 TEST_ASSERT_EQUAL(tx_count, TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1472 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT,
1473 "Transmitted (%d) an unexpected (%d) number of packets", tx_count,
1474 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1475 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT);
1477 /* Verify that failed packet are expected failed packets */
1478 for (i = 0; i < TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT; i++) {
1479 TEST_ASSERT_EQUAL(expected_tx_fail_pkts[i], pkt_burst[i + tx_count],
1480 "expected mbuf (%d) pointer %p not expected pointer %p",
1481 i, expected_tx_fail_pkts[i], pkt_burst[i + tx_count]);
1484 /* Verify bonded port tx stats */
1485 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1487 TEST_ASSERT_EQUAL(port_stats.opackets,
1488 (uint64_t)TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1489 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT,
1490 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
1491 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
1492 TEST_RR_SLAVE_TX_FAIL_BURST_SIZE -
1493 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT);
1495 /* Verify slave ports tx stats */
1496 for (i = 0; i < test_params->bonded_slave_count; i++) {
1497 int slave_expected_tx_count;
1499 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
1501 slave_expected_tx_count = TEST_RR_SLAVE_TX_FAIL_BURST_SIZE /
1502 test_params->bonded_slave_count;
1504 if (i == TEST_RR_SLAVE_TX_FAIL_FAILING_SLAVE_IDX)
1505 slave_expected_tx_count = slave_expected_tx_count -
1506 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT;
1508 TEST_ASSERT_EQUAL(port_stats.opackets,
1509 (uint64_t)slave_expected_tx_count,
1510 "Slave Port (%d) opackets value (%u) not as expected (%d)",
1511 test_params->slave_port_ids[i],
1512 (unsigned int)port_stats.opackets, slave_expected_tx_count);
1515 /* Verify that all mbufs have a ref value of zero */
1516 TEST_ASSERT_SUCCESS(verify_mbufs_ref_count(&pkt_burst[tx_count],
1517 TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT, 1),
1518 "mbufs refcnts not as expected");
1519 free_mbufs(&pkt_burst[tx_count], TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT);
1521 /* Clean up and remove slaves from bonded device */
1522 return remove_slaves_and_stop_bonded_device();
1526 test_roundrobin_rx_burst_on_single_slave(void)
1528 struct rte_mbuf *gen_pkt_burst[MAX_PKT_BURST] = { NULL };
1529 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1531 struct rte_eth_stats port_stats;
1533 int i, j, burst_size = 25;
1535 /* Initialize bonded device with 4 slaves in round robin mode */
1536 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1537 BONDING_MODE_ROUND_ROBIN, 0, 4, 1),
1538 "Failed to initialize bonded device with slaves");
1540 /* Generate test bursts of packets to transmit */
1541 TEST_ASSERT_EQUAL(generate_test_burst(
1542 gen_pkt_burst, burst_size, 0, 1, 0, 0, 0), burst_size,
1543 "burst generation failed");
1545 for (i = 0; i < test_params->bonded_slave_count; i++) {
1546 /* Add rx data to slave */
1547 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1548 &gen_pkt_burst[0], burst_size);
1550 /* Call rx burst on bonded device */
1551 /* Send burst on bonded port */
1552 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
1553 test_params->bonded_port_id, 0, rx_pkt_burst,
1554 MAX_PKT_BURST), burst_size,
1555 "round-robin rx burst failed");
1557 /* Verify bonded device rx count */
1558 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1559 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
1560 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
1561 test_params->bonded_port_id,
1562 (unsigned int)port_stats.ipackets, burst_size);
1566 /* Verify bonded slave devices rx count */
1567 /* Verify slave ports tx stats */
1568 for (j = 0; j < test_params->bonded_slave_count; j++) {
1569 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
1572 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
1573 "Slave Port (%d) ipackets value (%u) not as expected"
1574 " (%d)", test_params->slave_port_ids[i],
1575 (unsigned int)port_stats.ipackets, burst_size);
1577 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
1578 "Slave Port (%d) ipackets value (%u) not as expected"
1579 " (%d)", test_params->slave_port_ids[i],
1580 (unsigned int)port_stats.ipackets, 0);
1583 /* Reset bonded slaves stats */
1584 rte_eth_stats_reset(test_params->slave_port_ids[j]);
1586 /* reset bonded device stats */
1587 rte_eth_stats_reset(test_params->bonded_port_id);
1591 for (i = 0; i < MAX_PKT_BURST; i++) {
1592 if (rx_pkt_burst[i] != NULL)
1593 rte_pktmbuf_free(rx_pkt_burst[i]);
1597 /* Clean up and remove slaves from bonded device */
1598 return remove_slaves_and_stop_bonded_device();
1601 #define TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT (3)
1604 test_roundrobin_rx_burst_on_multiple_slaves(void)
1606 struct rte_mbuf *gen_pkt_burst[TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
1608 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1609 struct rte_eth_stats port_stats;
1611 int burst_size[TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT] = { 15, 13, 36 };
1614 /* Initialize bonded device with 4 slaves in round robin mode */
1615 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1616 BONDING_MODE_ROUND_ROBIN, 0, 4, 1),
1617 "Failed to initialize bonded device with slaves");
1619 /* Generate test bursts of packets to transmit */
1620 for (i = 0; i < TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT; i++) {
1621 TEST_ASSERT_EQUAL(generate_test_burst(
1622 &gen_pkt_burst[i][0], burst_size[i], 0, 1, 0, 0, 0),
1623 burst_size[i], "burst generation failed");
1626 /* Add rx data to slaves */
1627 for (i = 0; i < TEST_ROUNDROBIN_TX_BURST_SLAVE_COUNT; i++) {
1628 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1629 &gen_pkt_burst[i][0], burst_size[i]);
1632 /* Call rx burst on bonded device */
1633 /* Send burst on bonded port */
1634 nb_rx = rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
1636 TEST_ASSERT_EQUAL(nb_rx , burst_size[0] + burst_size[1] + burst_size[2],
1637 "round-robin rx burst failed (%d != %d)\n", nb_rx,
1638 burst_size[0] + burst_size[1] + burst_size[2]);
1640 /* Verify bonded device rx count */
1641 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1642 TEST_ASSERT_EQUAL(port_stats.ipackets,
1643 (uint64_t)(burst_size[0] + burst_size[1] + burst_size[2]),
1644 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
1645 test_params->bonded_port_id, (unsigned int)port_stats.ipackets,
1646 burst_size[0] + burst_size[1] + burst_size[2]);
1648 /* Verify bonded slave devices rx counts */
1649 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
1650 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[0],
1651 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
1652 test_params->slave_port_ids[0],
1653 (unsigned int)port_stats.ipackets, burst_size[0]);
1655 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
1656 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[1],
1657 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
1658 test_params->slave_port_ids[1], (unsigned int)port_stats.ipackets,
1661 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
1662 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[2],
1663 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
1664 test_params->slave_port_ids[2],
1665 (unsigned int)port_stats.ipackets, burst_size[2]);
1667 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
1668 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
1669 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
1670 test_params->slave_port_ids[3],
1671 (unsigned int)port_stats.ipackets, 0);
1674 for (i = 0; i < MAX_PKT_BURST; i++) {
1675 if (rx_pkt_burst[i] != NULL)
1676 rte_pktmbuf_free(rx_pkt_burst[i]);
1679 /* Clean up and remove slaves from bonded device */
1680 return remove_slaves_and_stop_bonded_device();
1684 test_roundrobin_verify_mac_assignment(void)
1686 struct rte_ether_addr read_mac_addr;
1687 struct rte_ether_addr expected_mac_addr_0, expected_mac_addr_2;
1691 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
1692 rte_eth_macaddr_get(test_params->slave_port_ids[2], &expected_mac_addr_2);
1694 /* Initialize bonded device with 4 slaves in round robin mode */
1695 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1696 BONDING_MODE_ROUND_ROBIN, 0, 4, 1),
1697 "Failed to initialize bonded device with slaves");
1699 /* Verify that all MACs are the same as first slave added to bonded dev */
1700 for (i = 0; i < test_params->bonded_slave_count; i++) {
1701 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1702 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
1703 sizeof(read_mac_addr)),
1704 "slave port (%d) mac address not set to that of primary port",
1705 test_params->slave_port_ids[i]);
1708 /* change primary and verify that MAC addresses haven't changed */
1709 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(test_params->bonded_port_id,
1710 test_params->slave_port_ids[2]),
1711 "Failed to set bonded port (%d) primary port to (%d)",
1712 test_params->bonded_port_id, test_params->slave_port_ids[i]);
1714 for (i = 0; i < test_params->bonded_slave_count; i++) {
1715 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1716 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
1717 sizeof(read_mac_addr)),
1718 "slave port (%d) mac address has changed to that of primary"
1719 " port without stop/start toggle of bonded device",
1720 test_params->slave_port_ids[i]);
1723 /* stop / start bonded device and verify that primary MAC address is
1724 * propagate to bonded device and slaves */
1725 rte_eth_dev_stop(test_params->bonded_port_id);
1727 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
1728 "Failed to start bonded device");
1730 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
1731 TEST_ASSERT_SUCCESS(
1732 memcmp(&expected_mac_addr_2, &read_mac_addr, sizeof(read_mac_addr)),
1733 "bonded port (%d) mac address not set to that of new primary port",
1734 test_params->slave_port_ids[i]);
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_2, &read_mac_addr,
1739 sizeof(read_mac_addr)),
1740 "slave port (%d) mac address not set to that of new primary"
1741 " port", test_params->slave_port_ids[i]);
1744 /* Set explicit MAC address */
1745 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
1746 test_params->bonded_port_id,
1747 (struct rte_ether_addr *)bonded_mac),
1748 "Failed to set MAC");
1750 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
1751 TEST_ASSERT_SUCCESS(memcmp(bonded_mac, &read_mac_addr,
1752 sizeof(read_mac_addr)),
1753 "bonded port (%d) mac address not set to that of new primary port",
1754 test_params->slave_port_ids[i]);
1756 for (i = 0; i < test_params->bonded_slave_count; i++) {
1757 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
1758 TEST_ASSERT_SUCCESS(memcmp(bonded_mac, &read_mac_addr,
1759 sizeof(read_mac_addr)), "slave port (%d) mac address not set to"
1760 " that of new primary port\n", test_params->slave_port_ids[i]);
1763 /* Clean up and remove slaves from bonded device */
1764 return remove_slaves_and_stop_bonded_device();
1768 test_roundrobin_verify_promiscuous_enable_disable(void)
1770 int i, promiscuous_en;
1773 /* Initialize bonded device with 4 slaves in round robin mode */
1774 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1775 BONDING_MODE_ROUND_ROBIN, 0, 4, 1),
1776 "Failed to initialize bonded device with slaves");
1778 ret = rte_eth_promiscuous_enable(test_params->bonded_port_id);
1779 TEST_ASSERT_SUCCESS(ret,
1780 "Failed to enable promiscuous mode for port %d: %s",
1781 test_params->bonded_port_id, rte_strerror(-ret));
1783 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
1784 TEST_ASSERT_EQUAL(promiscuous_en, 1,
1785 "Port (%d) promiscuous mode not enabled",
1786 test_params->bonded_port_id);
1788 for (i = 0; i < test_params->bonded_slave_count; i++) {
1789 promiscuous_en = rte_eth_promiscuous_get(
1790 test_params->slave_port_ids[i]);
1791 TEST_ASSERT_EQUAL(promiscuous_en, 1,
1792 "slave port (%d) promiscuous mode not enabled",
1793 test_params->slave_port_ids[i]);
1796 ret = rte_eth_promiscuous_disable(test_params->bonded_port_id);
1797 TEST_ASSERT_SUCCESS(ret,
1798 "Failed to disable promiscuous mode for port %d: %s",
1799 test_params->bonded_port_id, rte_strerror(-ret));
1801 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
1802 TEST_ASSERT_EQUAL(promiscuous_en, 0,
1803 "Port (%d) promiscuous mode not disabled\n",
1804 test_params->bonded_port_id);
1806 for (i = 0; i < test_params->bonded_slave_count; i++) {
1807 promiscuous_en = rte_eth_promiscuous_get(
1808 test_params->slave_port_ids[i]);
1809 TEST_ASSERT_EQUAL(promiscuous_en, 0,
1810 "Port (%d) promiscuous mode not disabled\n",
1811 test_params->slave_port_ids[i]);
1814 /* Clean up and remove slaves from bonded device */
1815 return remove_slaves_and_stop_bonded_device();
1818 #define TEST_RR_LINK_STATUS_SLAVE_COUNT (4)
1819 #define TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT (2)
1822 test_roundrobin_verify_slave_link_status_change_behaviour(void)
1824 struct rte_mbuf *tx_pkt_burst[MAX_PKT_BURST] = { NULL };
1825 struct rte_mbuf *gen_pkt_burst[TEST_RR_LINK_STATUS_SLAVE_COUNT][MAX_PKT_BURST];
1826 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
1828 struct rte_eth_stats port_stats;
1829 uint16_t slaves[RTE_MAX_ETHPORTS];
1831 int i, burst_size, slave_count;
1833 /* NULL all pointers in array to simplify cleanup */
1834 memset(gen_pkt_burst, 0, sizeof(gen_pkt_burst));
1836 /* Initialize bonded device with TEST_RR_LINK_STATUS_SLAVE_COUNT slaves
1837 * in round robin mode */
1838 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
1839 BONDING_MODE_ROUND_ROBIN, 0, TEST_RR_LINK_STATUS_SLAVE_COUNT, 1),
1840 "Failed to initialize bonded device with slaves");
1842 /* Verify Current Slaves Count /Active Slave Count is */
1843 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
1845 TEST_ASSERT_EQUAL(slave_count, TEST_RR_LINK_STATUS_SLAVE_COUNT,
1846 "Number of slaves (%d) is not as expected (%d).",
1847 slave_count, TEST_RR_LINK_STATUS_SLAVE_COUNT);
1849 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1850 slaves, RTE_MAX_ETHPORTS);
1851 TEST_ASSERT_EQUAL(slave_count, TEST_RR_LINK_STATUS_SLAVE_COUNT,
1852 "Number of active slaves (%d) is not as expected (%d).",
1853 slave_count, TEST_RR_LINK_STATUS_SLAVE_COUNT);
1855 /* Set 2 slaves eth_devs link status to down */
1856 virtual_ethdev_simulate_link_status_interrupt(
1857 test_params->slave_port_ids[1], 0);
1858 virtual_ethdev_simulate_link_status_interrupt(
1859 test_params->slave_port_ids[3], 0);
1861 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
1862 slaves, RTE_MAX_ETHPORTS);
1863 TEST_ASSERT_EQUAL(slave_count,
1864 TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT,
1865 "Number of active slaves (%d) is not as expected (%d).\n",
1866 slave_count, TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT);
1870 /* Verify that pkts are not sent on slaves with link status down:
1872 * 1. Generate test burst of traffic
1873 * 2. Transmit burst on bonded eth_dev
1874 * 3. Verify stats for bonded eth_dev (opackets = burst_size)
1875 * 4. Verify stats for slave eth_devs (s0 = 10, s1 = 0, s2 = 10, s3 = 0)
1878 generate_test_burst(tx_pkt_burst, burst_size, 0, 1, 0, 0, 0),
1879 burst_size, "generate_test_burst failed");
1881 rte_eth_stats_reset(test_params->bonded_port_id);
1885 rte_eth_tx_burst(test_params->bonded_port_id, 0, tx_pkt_burst,
1886 burst_size), burst_size, "rte_eth_tx_burst failed");
1888 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1889 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
1890 "Port (%d) opackets stats (%d) not expected (%d) value",
1891 test_params->bonded_port_id, (int)port_stats.opackets,
1894 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
1895 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)10,
1896 "Port (%d) opackets stats (%d) not expected (%d) value",
1897 test_params->slave_port_ids[0], (int)port_stats.opackets, 10);
1899 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
1900 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)0,
1901 "Port (%d) opackets stats (%d) not expected (%d) value",
1902 test_params->slave_port_ids[1], (int)port_stats.opackets, 0);
1904 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
1905 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)10,
1906 "Port (%d) opackets stats (%d) not expected (%d) value",
1907 test_params->slave_port_ids[2], (int)port_stats.opackets, 10);
1909 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
1910 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)0,
1911 "Port (%d) opackets stats (%d) not expected (%d) value",
1912 test_params->slave_port_ids[3], (int)port_stats.opackets, 0);
1914 /* Verify that pkts are not sent on slaves with link status down:
1916 * 1. Generate test bursts of traffic
1917 * 2. Add bursts on to virtual eth_devs
1918 * 3. Rx burst on bonded eth_dev, expected (burst_ size *
1919 * TEST_RR_LINK_STATUS_EXPECTED_ACTIVE_SLAVE_COUNT) received
1920 * 4. Verify stats for bonded eth_dev
1921 * 6. Verify stats for slave eth_devs (s0 = 10, s1 = 0, s2 = 10, s3 = 0)
1923 for (i = 0; i < TEST_RR_LINK_STATUS_SLAVE_COUNT; i++) {
1924 TEST_ASSERT_EQUAL(generate_test_burst(
1925 &gen_pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0),
1926 burst_size, "failed to generate packet burst");
1928 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
1929 &gen_pkt_burst[i][0], burst_size);
1932 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
1933 test_params->bonded_port_id, 0, rx_pkt_burst, MAX_PKT_BURST),
1934 burst_size + burst_size,
1935 "rte_eth_rx_burst failed");
1937 /* Verify bonded device rx count */
1938 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
1939 TEST_ASSERT_EQUAL(port_stats.ipackets , (uint64_t)(burst_size + burst_size),
1940 "(%d) port_stats.ipackets not as expected\n",
1941 test_params->bonded_port_id);
1944 for (i = 0; i < MAX_PKT_BURST; i++) {
1945 if (rx_pkt_burst[i] != NULL)
1946 rte_pktmbuf_free(rx_pkt_burst[i]);
1949 /* Clean up and remove slaves from bonded device */
1950 return remove_slaves_and_stop_bonded_device();
1953 #define TEST_RR_POLLING_LINK_STATUS_SLAVE_COUNT (2)
1955 uint8_t polling_slave_mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00 };
1958 int polling_test_slaves[TEST_RR_POLLING_LINK_STATUS_SLAVE_COUNT] = { -1, -1 };
1961 test_roundrobin_verfiy_polling_slave_link_status_change(void)
1963 struct rte_ether_addr *mac_addr =
1964 (struct rte_ether_addr *)polling_slave_mac;
1965 char slave_name[RTE_ETH_NAME_MAX_LEN];
1969 for (i = 0; i < TEST_RR_POLLING_LINK_STATUS_SLAVE_COUNT; i++) {
1970 /* Generate slave name / MAC address */
1971 snprintf(slave_name, RTE_ETH_NAME_MAX_LEN, "eth_virt_poll_%d", i);
1972 mac_addr->addr_bytes[RTE_ETHER_ADDR_LEN-1] = i;
1974 /* Create slave devices with no ISR Support */
1975 if (polling_test_slaves[i] == -1) {
1976 polling_test_slaves[i] = virtual_ethdev_create(slave_name, mac_addr,
1977 rte_socket_id(), 0);
1978 TEST_ASSERT(polling_test_slaves[i] >= 0,
1979 "Failed to create virtual virtual ethdev %s\n", slave_name);
1981 /* Configure slave */
1982 TEST_ASSERT_SUCCESS(configure_ethdev(polling_test_slaves[i], 0, 0),
1983 "Failed to configure virtual ethdev %s(%d)", slave_name,
1984 polling_test_slaves[i]);
1987 /* Add slave to bonded device */
1988 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params->bonded_port_id,
1989 polling_test_slaves[i]),
1990 "Failed to add slave %s(%d) to bonded device %d",
1991 slave_name, polling_test_slaves[i],
1992 test_params->bonded_port_id);
1995 /* Initialize bonded device */
1996 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 1, 1),
1997 "Failed to configure bonded device %d",
1998 test_params->bonded_port_id);
2001 /* Register link status change interrupt callback */
2002 rte_eth_dev_callback_register(test_params->bonded_port_id,
2003 RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
2004 &test_params->bonded_port_id);
2006 /* link status change callback for first slave link up */
2007 test_lsc_interrupt_count = 0;
2009 virtual_ethdev_set_link_status(polling_test_slaves[0], 1);
2011 TEST_ASSERT_SUCCESS(lsc_timeout(15000), "timed out waiting for interrupt");
2014 /* no link status change callback for second slave link up */
2015 test_lsc_interrupt_count = 0;
2017 virtual_ethdev_set_link_status(polling_test_slaves[1], 1);
2019 TEST_ASSERT_FAIL(lsc_timeout(15000), "unexpectedly succeeded");
2021 /* link status change callback for both slave links down */
2022 test_lsc_interrupt_count = 0;
2024 virtual_ethdev_set_link_status(polling_test_slaves[0], 0);
2025 virtual_ethdev_set_link_status(polling_test_slaves[1], 0);
2027 TEST_ASSERT_SUCCESS(lsc_timeout(20000), "timed out waiting for interrupt");
2029 /* Un-Register link status change interrupt callback */
2030 rte_eth_dev_callback_unregister(test_params->bonded_port_id,
2031 RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
2032 &test_params->bonded_port_id);
2035 /* Clean up and remove slaves from bonded device */
2036 for (i = 0; i < TEST_RR_POLLING_LINK_STATUS_SLAVE_COUNT; i++) {
2038 TEST_ASSERT_SUCCESS(
2039 rte_eth_bond_slave_remove(test_params->bonded_port_id,
2040 polling_test_slaves[i]),
2041 "Failed to remove slave %d from bonded port (%d)",
2042 polling_test_slaves[i], test_params->bonded_port_id);
2045 return remove_slaves_and_stop_bonded_device();
2049 /** Active Backup Mode Tests */
2052 test_activebackup_tx_burst(void)
2054 int i, pktlen, primary_port, burst_size;
2055 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
2056 struct rte_eth_stats port_stats;
2058 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2059 BONDING_MODE_ACTIVE_BACKUP, 0, 1, 1),
2060 "Failed to initialize bonded device with slaves");
2062 initialize_eth_header(test_params->pkt_eth_hdr,
2063 (struct rte_ether_addr *)src_mac,
2064 (struct rte_ether_addr *)dst_mac_0,
2065 RTE_ETHER_TYPE_IPV4, 0, 0);
2066 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
2068 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
2069 dst_addr_0, pktlen);
2071 burst_size = 20 * test_params->bonded_slave_count;
2073 TEST_ASSERT(burst_size < MAX_PKT_BURST,
2074 "Burst size specified is greater than supported.");
2076 /* Generate a burst of packets to transmit */
2077 TEST_ASSERT_EQUAL(generate_packet_burst(test_params->mbuf_pool, pkts_burst,
2078 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr, 1,
2079 test_params->pkt_udp_hdr, burst_size, PACKET_BURST_GEN_PKT_LEN, 1),
2080 burst_size, "failed to generate burst correctly");
2082 /* Send burst on bonded port */
2083 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst,
2084 burst_size), burst_size, "tx burst failed");
2086 /* Verify bonded port tx stats */
2087 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2088 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
2089 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
2090 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
2093 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2095 /* Verify slave ports tx stats */
2096 for (i = 0; i < test_params->bonded_slave_count; i++) {
2097 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
2098 if (test_params->slave_port_ids[i] == primary_port) {
2099 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
2100 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2101 test_params->bonded_port_id,
2102 (unsigned int)port_stats.opackets,
2103 burst_size / test_params->bonded_slave_count);
2105 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2106 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2107 test_params->bonded_port_id,
2108 (unsigned int)port_stats.opackets, 0);
2112 /* Put all slaves down and try and transmit */
2113 for (i = 0; i < test_params->bonded_slave_count; i++) {
2114 virtual_ethdev_simulate_link_status_interrupt(
2115 test_params->slave_port_ids[i], 0);
2118 /* Send burst on bonded port */
2119 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
2120 pkts_burst, burst_size), 0, "Sending empty burst failed");
2122 /* Clean up and remove slaves from bonded device */
2123 return remove_slaves_and_stop_bonded_device();
2126 #define TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT (4)
2129 test_activebackup_rx_burst(void)
2131 struct rte_mbuf *gen_pkt_burst[MAX_PKT_BURST] = { NULL };
2132 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
2134 struct rte_eth_stats port_stats;
2138 int i, j, burst_size = 17;
2140 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2141 BONDING_MODE_ACTIVE_BACKUP, 0,
2142 TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT, 1),
2143 "Failed to initialize bonded device with slaves");
2145 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2146 TEST_ASSERT(primary_port >= 0,
2147 "failed to get primary slave for bonded port (%d)",
2148 test_params->bonded_port_id);
2150 for (i = 0; i < test_params->bonded_slave_count; i++) {
2151 /* Generate test bursts of packets to transmit */
2152 TEST_ASSERT_EQUAL(generate_test_burst(
2153 &gen_pkt_burst[0], burst_size, 0, 1, 0, 0, 0),
2154 burst_size, "burst generation failed");
2156 /* Add rx data to slave */
2157 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
2158 &gen_pkt_burst[0], burst_size);
2160 /* Call rx burst on bonded device */
2161 TEST_ASSERT_EQUAL(rte_eth_rx_burst(test_params->bonded_port_id, 0,
2162 &rx_pkt_burst[0], MAX_PKT_BURST), burst_size,
2163 "rte_eth_rx_burst failed");
2165 if (test_params->slave_port_ids[i] == primary_port) {
2166 /* Verify bonded device rx count */
2167 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2168 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
2169 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
2170 test_params->bonded_port_id,
2171 (unsigned int)port_stats.ipackets, burst_size);
2173 /* Verify bonded slave devices rx count */
2174 for (j = 0; j < test_params->bonded_slave_count; j++) {
2175 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
2177 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
2178 "Slave Port (%d) ipackets value (%u) not as "
2179 "expected (%d)", test_params->slave_port_ids[i],
2180 (unsigned int)port_stats.ipackets, burst_size);
2182 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
2183 "Slave Port (%d) ipackets value (%u) not as "
2184 "expected (%d)\n", test_params->slave_port_ids[i],
2185 (unsigned int)port_stats.ipackets, 0);
2189 for (j = 0; j < test_params->bonded_slave_count; j++) {
2190 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
2191 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
2192 "Slave Port (%d) ipackets value (%u) not as expected "
2193 "(%d)", test_params->slave_port_ids[i],
2194 (unsigned int)port_stats.ipackets, 0);
2199 for (i = 0; i < MAX_PKT_BURST; i++) {
2200 if (rx_pkt_burst[i] != NULL) {
2201 rte_pktmbuf_free(rx_pkt_burst[i]);
2202 rx_pkt_burst[i] = NULL;
2206 /* reset bonded device stats */
2207 rte_eth_stats_reset(test_params->bonded_port_id);
2210 /* Clean up and remove slaves from bonded device */
2211 return remove_slaves_and_stop_bonded_device();
2215 test_activebackup_verify_promiscuous_enable_disable(void)
2217 int i, primary_port, promiscuous_en;
2220 /* Initialize bonded device with 4 slaves in round robin mode */
2221 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2222 BONDING_MODE_ACTIVE_BACKUP, 0, 4, 1),
2223 "Failed to initialize bonded device with slaves");
2225 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2226 TEST_ASSERT(primary_port >= 0,
2227 "failed to get primary slave for bonded port (%d)",
2228 test_params->bonded_port_id);
2230 ret = rte_eth_promiscuous_enable(test_params->bonded_port_id);
2231 TEST_ASSERT_SUCCESS(ret,
2232 "Failed to enable promiscuous mode for port %d: %s",
2233 test_params->bonded_port_id, rte_strerror(-ret));
2235 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 1,
2236 "Port (%d) promiscuous mode not enabled",
2237 test_params->bonded_port_id);
2239 for (i = 0; i < test_params->bonded_slave_count; i++) {
2240 promiscuous_en = rte_eth_promiscuous_get(
2241 test_params->slave_port_ids[i]);
2242 if (primary_port == test_params->slave_port_ids[i]) {
2243 TEST_ASSERT_EQUAL(promiscuous_en, 1,
2244 "slave port (%d) promiscuous mode not enabled",
2245 test_params->slave_port_ids[i]);
2247 TEST_ASSERT_EQUAL(promiscuous_en, 0,
2248 "slave port (%d) promiscuous mode enabled",
2249 test_params->slave_port_ids[i]);
2254 ret = rte_eth_promiscuous_disable(test_params->bonded_port_id);
2255 TEST_ASSERT_SUCCESS(ret,
2256 "Failed to disable promiscuous mode for port %d: %s",
2257 test_params->bonded_port_id, rte_strerror(-ret));
2259 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 0,
2260 "Port (%d) promiscuous mode not disabled\n",
2261 test_params->bonded_port_id);
2263 for (i = 0; i < test_params->bonded_slave_count; i++) {
2264 promiscuous_en = rte_eth_promiscuous_get(
2265 test_params->slave_port_ids[i]);
2266 TEST_ASSERT_EQUAL(promiscuous_en, 0,
2267 "slave port (%d) promiscuous mode not disabled\n",
2268 test_params->slave_port_ids[i]);
2271 /* Clean up and remove slaves from bonded device */
2272 return remove_slaves_and_stop_bonded_device();
2276 test_activebackup_verify_mac_assignment(void)
2278 struct rte_ether_addr read_mac_addr;
2279 struct rte_ether_addr expected_mac_addr_0, expected_mac_addr_1;
2281 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
2282 rte_eth_macaddr_get(test_params->slave_port_ids[1], &expected_mac_addr_1);
2284 /* Initialize bonded device with 2 slaves in active backup mode */
2285 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2286 BONDING_MODE_ACTIVE_BACKUP, 0, 2, 1),
2287 "Failed to initialize bonded device with slaves");
2289 /* Verify that bonded MACs is that of first slave and that the other slave
2290 * MAC hasn't been changed */
2291 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2292 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2293 sizeof(read_mac_addr)),
2294 "bonded port (%d) mac address not set to that of primary port",
2295 test_params->bonded_port_id);
2297 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2298 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2299 sizeof(read_mac_addr)),
2300 "slave port (%d) mac address not set to that of primary port",
2301 test_params->slave_port_ids[0]);
2303 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2304 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
2305 sizeof(read_mac_addr)),
2306 "slave port (%d) mac address not as expected",
2307 test_params->slave_port_ids[1]);
2309 /* change primary and verify that MAC addresses haven't changed */
2310 TEST_ASSERT_EQUAL(rte_eth_bond_primary_set(test_params->bonded_port_id,
2311 test_params->slave_port_ids[1]), 0,
2312 "Failed to set bonded port (%d) primary port to (%d)",
2313 test_params->bonded_port_id, test_params->slave_port_ids[1]);
2315 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2316 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2317 sizeof(read_mac_addr)),
2318 "bonded port (%d) mac address not set to that of primary port",
2319 test_params->bonded_port_id);
2321 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2322 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2323 sizeof(read_mac_addr)),
2324 "slave port (%d) mac address not set to that of primary port",
2325 test_params->slave_port_ids[0]);
2327 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2328 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
2329 sizeof(read_mac_addr)),
2330 "slave port (%d) mac address not as expected",
2331 test_params->slave_port_ids[1]);
2333 /* stop / start bonded device and verify that primary MAC address is
2334 * propagated to bonded device and slaves */
2336 rte_eth_dev_stop(test_params->bonded_port_id);
2338 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
2339 "Failed to start device");
2341 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2342 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
2343 sizeof(read_mac_addr)),
2344 "bonded port (%d) mac address not set to that of primary port",
2345 test_params->bonded_port_id);
2347 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2348 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2349 sizeof(read_mac_addr)),
2350 "slave port (%d) mac address not as expected",
2351 test_params->slave_port_ids[0]);
2353 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2354 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
2355 sizeof(read_mac_addr)),
2356 "slave port (%d) mac address not set to that of primary port",
2357 test_params->slave_port_ids[1]);
2359 /* Set explicit MAC address */
2360 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
2361 test_params->bonded_port_id,
2362 (struct rte_ether_addr *)bonded_mac),
2363 "failed to set MAC address");
2365 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
2366 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
2367 sizeof(read_mac_addr)),
2368 "bonded port (%d) mac address not set to that of bonded port",
2369 test_params->bonded_port_id);
2371 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
2372 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
2373 sizeof(read_mac_addr)),
2374 "slave port (%d) mac address not as expected",
2375 test_params->slave_port_ids[0]);
2377 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
2378 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
2379 sizeof(read_mac_addr)),
2380 "slave port (%d) mac address not set to that of bonded port",
2381 test_params->slave_port_ids[1]);
2383 /* Clean up and remove slaves from bonded device */
2384 return remove_slaves_and_stop_bonded_device();
2388 test_activebackup_verify_slave_link_status_change_failover(void)
2390 struct rte_mbuf *pkt_burst[TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
2391 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
2392 struct rte_eth_stats port_stats;
2394 uint16_t slaves[RTE_MAX_ETHPORTS];
2396 int i, burst_size, slave_count, primary_port;
2400 memset(pkt_burst, 0, sizeof(pkt_burst));
2402 /* Generate packet burst for testing */
2403 TEST_ASSERT_EQUAL(generate_test_burst(
2404 &pkt_burst[0][0], burst_size, 0, 1, 0, 0, 0), burst_size,
2405 "generate_test_burst failed");
2407 /* Initialize bonded device with 4 slaves in round robin mode */
2408 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2409 BONDING_MODE_ACTIVE_BACKUP, 0,
2410 TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT, 1),
2411 "Failed to initialize bonded device with slaves");
2413 /* Verify Current Slaves Count /Active Slave Count is */
2414 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
2416 TEST_ASSERT_EQUAL(slave_count, 4,
2417 "Number of slaves (%d) is not as expected (%d).",
2420 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
2421 slaves, RTE_MAX_ETHPORTS);
2422 TEST_ASSERT_EQUAL(slave_count, 4,
2423 "Number of active slaves (%d) is not as expected (%d).",
2426 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2427 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[0],
2428 "Primary port not as expected");
2430 /* Bring 2 slaves down and verify active slave count */
2431 virtual_ethdev_simulate_link_status_interrupt(
2432 test_params->slave_port_ids[1], 0);
2433 virtual_ethdev_simulate_link_status_interrupt(
2434 test_params->slave_port_ids[3], 0);
2436 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
2437 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 2,
2438 "Number of active slaves (%d) is not as expected (%d).",
2441 virtual_ethdev_simulate_link_status_interrupt(
2442 test_params->slave_port_ids[1], 1);
2443 virtual_ethdev_simulate_link_status_interrupt(
2444 test_params->slave_port_ids[3], 1);
2447 /* Bring primary port down, verify that active slave count is 3 and primary
2449 virtual_ethdev_simulate_link_status_interrupt(
2450 test_params->slave_port_ids[0], 0);
2452 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
2453 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS),
2455 "Number of active slaves (%d) is not as expected (%d).",
2458 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
2459 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[2],
2460 "Primary port not as expected");
2462 /* Verify that pkts are sent on new primary slave */
2464 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
2465 test_params->bonded_port_id, 0, &pkt_burst[0][0],
2466 burst_size), burst_size, "rte_eth_tx_burst failed");
2468 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
2469 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
2470 "(%d) port_stats.opackets not as expected",
2471 test_params->slave_port_ids[2]);
2473 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2474 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2475 "(%d) port_stats.opackets not as expected\n",
2476 test_params->slave_port_ids[0]);
2478 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2479 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2480 "(%d) port_stats.opackets not as expected\n",
2481 test_params->slave_port_ids[1]);
2483 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
2484 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2485 "(%d) port_stats.opackets not as expected\n",
2486 test_params->slave_port_ids[3]);
2488 /* Generate packet burst for testing */
2490 for (i = 0; i < TEST_ACTIVE_BACKUP_RX_BURST_SLAVE_COUNT; i++) {
2491 TEST_ASSERT_EQUAL(generate_test_burst(
2492 &pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0), burst_size,
2493 "generate_test_burst failed");
2495 virtual_ethdev_add_mbufs_to_rx_queue(
2496 test_params->slave_port_ids[i], &pkt_burst[i][0], burst_size);
2499 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
2500 test_params->bonded_port_id, 0, rx_pkt_burst, MAX_PKT_BURST),
2501 burst_size, "rte_eth_rx_burst\n");
2503 /* Verify bonded device rx count */
2504 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2505 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
2506 "(%d) port_stats.ipackets not as expected",
2507 test_params->bonded_port_id);
2509 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
2510 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
2511 "(%d) port_stats.opackets not as expected",
2512 test_params->slave_port_ids[2]);
2514 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2515 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2516 "(%d) port_stats.opackets not as expected",
2517 test_params->slave_port_ids[0]);
2519 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2520 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2521 "(%d) port_stats.opackets not as expected",
2522 test_params->slave_port_ids[1]);
2524 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
2525 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
2526 "(%d) port_stats.opackets not as expected",
2527 test_params->slave_port_ids[3]);
2529 /* Clean up and remove slaves from bonded device */
2530 return remove_slaves_and_stop_bonded_device();
2533 /** Balance Mode Tests */
2536 test_balance_xmit_policy_configuration(void)
2538 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2539 BONDING_MODE_ACTIVE_BACKUP, 0, 2, 1),
2540 "Failed to initialize_bonded_device_with_slaves.");
2542 /* Invalid port id */
2543 TEST_ASSERT_FAIL(rte_eth_bond_xmit_policy_set(
2544 INVALID_PORT_ID, BALANCE_XMIT_POLICY_LAYER2),
2545 "Expected call to failed as invalid port specified.");
2547 /* Set xmit policy on non bonded device */
2548 TEST_ASSERT_FAIL(rte_eth_bond_xmit_policy_set(
2549 test_params->slave_port_ids[0], BALANCE_XMIT_POLICY_LAYER2),
2550 "Expected call to failed as invalid port specified.");
2553 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2554 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER2),
2555 "Failed to set balance xmit policy.");
2557 TEST_ASSERT_EQUAL(rte_eth_bond_xmit_policy_get(test_params->bonded_port_id),
2558 BALANCE_XMIT_POLICY_LAYER2, "balance xmit policy not as expected.");
2561 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2562 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER23),
2563 "Failed to set balance xmit policy.");
2565 TEST_ASSERT_EQUAL(rte_eth_bond_xmit_policy_get(test_params->bonded_port_id),
2566 BALANCE_XMIT_POLICY_LAYER23,
2567 "balance xmit policy not as expected.");
2570 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2571 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER34),
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_LAYER34,
2576 "balance xmit policy not as expected.");
2578 /* Invalid port id */
2579 TEST_ASSERT_FAIL(rte_eth_bond_xmit_policy_get(INVALID_PORT_ID),
2580 "Expected call to failed as invalid port specified.");
2582 /* Clean up and remove slaves from bonded device */
2583 return remove_slaves_and_stop_bonded_device();
2586 #define TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT (2)
2589 test_balance_l2_tx_burst(void)
2591 struct rte_mbuf *pkts_burst[TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
2592 int burst_size[TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT] = { 10, 15 };
2596 struct rte_eth_stats port_stats;
2598 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2599 BONDING_MODE_BALANCE, 0, TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT, 1),
2600 "Failed to initialize_bonded_device_with_slaves.");
2602 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2603 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER2),
2604 "Failed to set balance xmit policy.");
2606 initialize_eth_header(test_params->pkt_eth_hdr,
2607 (struct rte_ether_addr *)src_mac,
2608 (struct rte_ether_addr *)dst_mac_0,
2609 RTE_ETHER_TYPE_IPV4, 0, 0);
2610 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
2612 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
2613 dst_addr_0, pktlen);
2615 /* Generate a burst 1 of packets to transmit */
2616 TEST_ASSERT_EQUAL(generate_packet_burst(test_params->mbuf_pool, &pkts_burst[0][0],
2617 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr, 1,
2618 test_params->pkt_udp_hdr, burst_size[0],
2619 PACKET_BURST_GEN_PKT_LEN, 1), burst_size[0],
2620 "failed to generate packet burst");
2622 initialize_eth_header(test_params->pkt_eth_hdr,
2623 (struct rte_ether_addr *)src_mac,
2624 (struct rte_ether_addr *)dst_mac_1,
2625 RTE_ETHER_TYPE_IPV4, 0, 0);
2627 /* Generate a burst 2 of packets to transmit */
2628 TEST_ASSERT_EQUAL(generate_packet_burst(test_params->mbuf_pool, &pkts_burst[1][0],
2629 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr, 1,
2630 test_params->pkt_udp_hdr, burst_size[1],
2631 PACKET_BURST_GEN_PKT_LEN, 1), burst_size[1],
2632 "failed to generate packet burst");
2634 /* Send burst 1 on bonded port */
2635 for (i = 0; i < TEST_BALANCE_L2_TX_BURST_SLAVE_COUNT; i++) {
2636 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
2637 &pkts_burst[i][0], burst_size[i]),
2638 burst_size[i], "Failed to transmit packet burst");
2641 /* Verify bonded port tx stats */
2642 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2643 TEST_ASSERT_EQUAL(port_stats.opackets,
2644 (uint64_t)(burst_size[0] + burst_size[1]),
2645 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
2646 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
2647 burst_size[0] + burst_size[1]);
2650 /* Verify slave ports tx stats */
2651 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2652 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size[0],
2653 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2654 test_params->slave_port_ids[0], (unsigned int)port_stats.opackets,
2657 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2658 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size[1],
2659 "Slave Port (%d) opackets value (%u) not as expected (%d)\n",
2660 test_params->slave_port_ids[1], (unsigned int)port_stats.opackets,
2663 /* Put all slaves down and try and transmit */
2664 for (i = 0; i < test_params->bonded_slave_count; i++) {
2666 virtual_ethdev_simulate_link_status_interrupt(
2667 test_params->slave_port_ids[i], 0);
2670 /* Send burst on bonded port */
2671 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
2672 test_params->bonded_port_id, 0, &pkts_burst[0][0], burst_size[0]),
2673 0, "Expected zero packet");
2675 /* Clean up and remove slaves from bonded device */
2676 return remove_slaves_and_stop_bonded_device();
2680 balance_l23_tx_burst(uint8_t vlan_enabled, uint8_t ipv4,
2681 uint8_t toggle_mac_addr, uint8_t toggle_ip_addr)
2683 int i, burst_size_1, burst_size_2, nb_tx_1, nb_tx_2;
2685 struct rte_mbuf *pkts_burst_1[MAX_PKT_BURST];
2686 struct rte_mbuf *pkts_burst_2[MAX_PKT_BURST];
2688 struct rte_eth_stats port_stats;
2690 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2691 BONDING_MODE_BALANCE, 0, 2, 1),
2692 "Failed to initialize_bonded_device_with_slaves.");
2694 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2695 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER23),
2696 "Failed to set balance xmit policy.");
2701 TEST_ASSERT(burst_size_1 < MAX_PKT_BURST || burst_size_2 < MAX_PKT_BURST,
2702 "Burst size specified is greater than supported.");
2704 /* Generate test bursts of packets to transmit */
2705 TEST_ASSERT_EQUAL(generate_test_burst(
2706 pkts_burst_1, burst_size_1, vlan_enabled, ipv4, 0, 0, 0),
2707 burst_size_1, "failed to generate packet burst");
2709 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst_2, burst_size_2, vlan_enabled, ipv4,
2710 toggle_mac_addr, toggle_ip_addr, 0), burst_size_2,
2711 "failed to generate packet burst");
2713 /* Send burst 1 on bonded port */
2714 nb_tx_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2716 TEST_ASSERT_EQUAL(nb_tx_1, burst_size_1, "tx burst failed");
2718 /* Send burst 2 on bonded port */
2719 nb_tx_2 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_2,
2721 TEST_ASSERT_EQUAL(nb_tx_2, burst_size_2, "tx burst failed");
2723 /* Verify bonded port tx stats */
2724 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2725 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(nb_tx_1 + nb_tx_2),
2726 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
2727 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
2730 /* Verify slave ports tx stats */
2731 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2732 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)nb_tx_1,
2733 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2734 test_params->slave_port_ids[0], (unsigned int)port_stats.opackets,
2737 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2738 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)nb_tx_2,
2739 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2740 test_params->slave_port_ids[1], (unsigned int)port_stats.opackets,
2743 /* Put all slaves down and try and transmit */
2744 for (i = 0; i < test_params->bonded_slave_count; i++) {
2746 virtual_ethdev_simulate_link_status_interrupt(
2747 test_params->slave_port_ids[i], 0);
2750 /* Send burst on bonded port */
2751 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
2752 test_params->bonded_port_id, 0, pkts_burst_1,
2753 burst_size_1), 0, "Expected zero packet");
2756 /* Clean up and remove slaves from bonded device */
2757 return remove_slaves_and_stop_bonded_device();
2761 test_balance_l23_tx_burst_ipv4_toggle_ip_addr(void)
2763 return balance_l23_tx_burst(0, 1, 0, 1);
2767 test_balance_l23_tx_burst_vlan_ipv4_toggle_ip_addr(void)
2769 return balance_l23_tx_burst(1, 1, 0, 1);
2773 test_balance_l23_tx_burst_ipv6_toggle_ip_addr(void)
2775 return balance_l23_tx_burst(0, 0, 0, 1);
2779 test_balance_l23_tx_burst_vlan_ipv6_toggle_ip_addr(void)
2781 return balance_l23_tx_burst(1, 0, 0, 1);
2785 test_balance_l23_tx_burst_toggle_mac_addr(void)
2787 return balance_l23_tx_burst(0, 0, 1, 0);
2791 balance_l34_tx_burst(uint8_t vlan_enabled, uint8_t ipv4,
2792 uint8_t toggle_mac_addr, uint8_t toggle_ip_addr,
2793 uint8_t toggle_udp_port)
2795 int i, burst_size_1, burst_size_2, nb_tx_1, nb_tx_2;
2797 struct rte_mbuf *pkts_burst_1[MAX_PKT_BURST];
2798 struct rte_mbuf *pkts_burst_2[MAX_PKT_BURST];
2800 struct rte_eth_stats port_stats;
2802 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2803 BONDING_MODE_BALANCE, 0, 2, 1),
2804 "Failed to initialize_bonded_device_with_slaves.");
2806 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2807 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER34),
2808 "Failed to set balance xmit policy.");
2813 TEST_ASSERT(burst_size_1 < MAX_PKT_BURST || burst_size_2 < MAX_PKT_BURST,
2814 "Burst size specified is greater than supported.");
2816 /* Generate test bursts of packets to transmit */
2817 TEST_ASSERT_EQUAL(generate_test_burst(
2818 pkts_burst_1, burst_size_1, vlan_enabled, ipv4, 0, 0, 0),
2819 burst_size_1, "failed to generate burst");
2821 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst_2, burst_size_2,
2822 vlan_enabled, ipv4, toggle_mac_addr, toggle_ip_addr,
2823 toggle_udp_port), burst_size_2, "failed to generate burst");
2825 /* Send burst 1 on bonded port */
2826 nb_tx_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2828 TEST_ASSERT_EQUAL(nb_tx_1, burst_size_1, "tx burst failed");
2830 /* Send burst 2 on bonded port */
2831 nb_tx_2 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_2,
2833 TEST_ASSERT_EQUAL(nb_tx_2, burst_size_2, "tx burst failed");
2836 /* Verify bonded port tx stats */
2837 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2838 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(nb_tx_1 + nb_tx_2),
2839 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
2840 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
2843 /* Verify slave ports tx stats */
2844 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
2845 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)nb_tx_1,
2846 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2847 test_params->slave_port_ids[0], (unsigned int)port_stats.opackets,
2850 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
2851 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)nb_tx_2,
2852 "Slave Port (%d) opackets value (%u) not as expected (%d)",
2853 test_params->slave_port_ids[1], (unsigned int)port_stats.opackets,
2856 /* Put all slaves down and try and transmit */
2857 for (i = 0; i < test_params->bonded_slave_count; i++) {
2859 virtual_ethdev_simulate_link_status_interrupt(
2860 test_params->slave_port_ids[i], 0);
2863 /* Send burst on bonded port */
2864 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
2865 test_params->bonded_port_id, 0, pkts_burst_1,
2866 burst_size_1), 0, "Expected zero packet");
2868 /* Clean up and remove slaves from bonded device */
2869 return remove_slaves_and_stop_bonded_device();
2873 test_balance_l34_tx_burst_ipv4_toggle_ip_addr(void)
2875 return balance_l34_tx_burst(0, 1, 0, 1, 0);
2879 test_balance_l34_tx_burst_ipv4_toggle_udp_port(void)
2881 return balance_l34_tx_burst(0, 1, 0, 0, 1);
2885 test_balance_l34_tx_burst_vlan_ipv4_toggle_ip_addr(void)
2887 return balance_l34_tx_burst(1, 1, 0, 1, 0);
2891 test_balance_l34_tx_burst_ipv6_toggle_ip_addr(void)
2893 return balance_l34_tx_burst(0, 0, 0, 1, 0);
2897 test_balance_l34_tx_burst_vlan_ipv6_toggle_ip_addr(void)
2899 return balance_l34_tx_burst(1, 0, 0, 1, 0);
2903 test_balance_l34_tx_burst_ipv6_toggle_udp_port(void)
2905 return balance_l34_tx_burst(0, 0, 0, 0, 1);
2908 #define TEST_BAL_SLAVE_TX_FAIL_SLAVE_COUNT (2)
2909 #define TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 (40)
2910 #define TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2 (20)
2911 #define TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT (25)
2912 #define TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX (0)
2915 test_balance_tx_burst_slave_tx_fail(void)
2917 struct rte_mbuf *pkts_burst_1[TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1];
2918 struct rte_mbuf *pkts_burst_2[TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2];
2920 struct rte_mbuf *expected_fail_pkts[TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT];
2922 struct rte_eth_stats port_stats;
2924 int i, first_tx_fail_idx, tx_count_1, tx_count_2;
2926 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
2927 BONDING_MODE_BALANCE, 0,
2928 TEST_BAL_SLAVE_TX_FAIL_SLAVE_COUNT, 1),
2929 "Failed to initialise bonded device");
2931 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
2932 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER2),
2933 "Failed to set balance xmit policy.");
2936 /* Generate test bursts for transmission */
2937 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst_1,
2938 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1, 0, 0, 0, 0, 0),
2939 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1,
2940 "Failed to generate test packet burst 1");
2942 first_tx_fail_idx = TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
2943 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT;
2945 /* copy mbuf referneces for expected transmission failures */
2946 for (i = 0; i < TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT; i++)
2947 expected_fail_pkts[i] = pkts_burst_1[i + first_tx_fail_idx];
2949 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst_2,
2950 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2, 0, 0, 1, 0, 0),
2951 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2,
2952 "Failed to generate test packet burst 2");
2955 /* Set virtual slave TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX to only fail
2956 * transmission of TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT packets of burst */
2957 virtual_ethdev_tx_burst_fn_set_success(
2958 test_params->slave_port_ids[TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX],
2961 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
2962 test_params->slave_port_ids[TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX],
2963 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT);
2966 /* Transmit burst 1 */
2967 tx_count_1 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_1,
2968 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1);
2970 TEST_ASSERT_EQUAL(tx_count_1, TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
2971 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT,
2972 "Transmitted (%d) packets, expected to transmit (%d) packets",
2973 tx_count_1, TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
2974 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT);
2976 /* Verify that failed packet are expected failed packets */
2977 for (i = 0; i < TEST_RR_SLAVE_TX_FAIL_PACKETS_COUNT; i++) {
2978 TEST_ASSERT_EQUAL(expected_fail_pkts[i], pkts_burst_1[i + tx_count_1],
2979 "expected mbuf (%d) pointer %p not expected pointer %p",
2980 i, expected_fail_pkts[i], pkts_burst_1[i + tx_count_1]);
2983 /* Transmit burst 2 */
2984 tx_count_2 = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst_2,
2985 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2);
2987 TEST_ASSERT_EQUAL(tx_count_2, TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2,
2988 "Transmitted (%d) packets, expected to transmit (%d) packets",
2989 tx_count_2, TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2);
2992 /* Verify bonded port tx stats */
2993 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
2995 TEST_ASSERT_EQUAL(port_stats.opackets,
2996 (uint64_t)((TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
2997 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT) +
2998 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2),
2999 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
3000 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3001 (TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
3002 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT) +
3003 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2);
3005 /* Verify slave ports tx stats */
3007 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3009 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)
3010 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
3011 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT,
3012 "Slave Port (%d) opackets value (%u) not as expected (%d)",
3013 test_params->slave_port_ids[0],
3014 (unsigned int)port_stats.opackets,
3015 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
3016 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT);
3021 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3023 TEST_ASSERT_EQUAL(port_stats.opackets,
3024 (uint64_t)TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2,
3025 "Slave Port (%d) opackets value (%u) not as expected (%d)",
3026 test_params->slave_port_ids[1],
3027 (unsigned int)port_stats.opackets,
3028 TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_2);
3030 /* Verify that all mbufs have a ref value of zero */
3031 TEST_ASSERT_SUCCESS(verify_mbufs_ref_count(&pkts_burst_1[tx_count_1],
3032 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT, 1),
3033 "mbufs refcnts not as expected");
3035 free_mbufs(&pkts_burst_1[tx_count_1],
3036 TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT);
3038 /* Clean up and remove slaves from bonded device */
3039 return remove_slaves_and_stop_bonded_device();
3042 #define TEST_BALANCE_RX_BURST_SLAVE_COUNT (3)
3045 test_balance_rx_burst(void)
3047 struct rte_mbuf *gen_pkt_burst[TEST_BALANCE_RX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
3049 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3050 struct rte_eth_stats port_stats;
3052 int burst_size[TEST_BALANCE_RX_BURST_SLAVE_COUNT] = { 10, 5, 30 };
3055 memset(gen_pkt_burst, 0, sizeof(gen_pkt_burst));
3057 /* Initialize bonded device with 4 slaves in round robin mode */
3058 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3059 BONDING_MODE_BALANCE, 0, 3, 1),
3060 "Failed to initialise bonded device");
3062 /* Generate test bursts of packets to transmit */
3063 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
3064 TEST_ASSERT_EQUAL(generate_test_burst(
3065 &gen_pkt_burst[i][0], burst_size[i], 0, 0, 1,
3066 0, 0), burst_size[i],
3067 "failed to generate packet burst");
3070 /* Add rx data to slaves */
3071 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
3072 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3073 &gen_pkt_burst[i][0], burst_size[i]);
3076 /* Call rx burst on bonded device */
3077 /* Send burst on bonded port */
3078 TEST_ASSERT_EQUAL(rte_eth_rx_burst(test_params->bonded_port_id, 0,
3079 rx_pkt_burst, MAX_PKT_BURST),
3080 burst_size[0] + burst_size[1] + burst_size[2],
3081 "balance rx burst failed\n");
3083 /* Verify bonded device rx count */
3084 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3085 TEST_ASSERT_EQUAL(port_stats.ipackets,
3086 (uint64_t)(burst_size[0] + burst_size[1] + burst_size[2]),
3087 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
3088 test_params->bonded_port_id, (unsigned int)port_stats.ipackets,
3089 burst_size[0] + burst_size[1] + burst_size[2]);
3092 /* Verify bonded slave devices rx counts */
3093 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3094 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[0],
3095 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3096 test_params->slave_port_ids[0],
3097 (unsigned int)port_stats.ipackets, burst_size[0]);
3099 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3100 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[1],
3101 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3102 test_params->slave_port_ids[1], (unsigned int)port_stats.ipackets,
3105 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3106 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[2],
3107 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3108 test_params->slave_port_ids[2], (unsigned int)port_stats.ipackets,
3111 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
3112 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
3113 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3114 test_params->slave_port_ids[3], (unsigned int)port_stats.ipackets,
3118 for (i = 0; i < TEST_BALANCE_RX_BURST_SLAVE_COUNT; i++) {
3119 for (j = 0; j < MAX_PKT_BURST; j++) {
3120 if (gen_pkt_burst[i][j] != NULL) {
3121 rte_pktmbuf_free(gen_pkt_burst[i][j]);
3122 gen_pkt_burst[i][j] = NULL;
3127 /* Clean up and remove slaves from bonded device */
3128 return remove_slaves_and_stop_bonded_device();
3132 test_balance_verify_promiscuous_enable_disable(void)
3137 /* Initialize bonded device with 4 slaves in round robin mode */
3138 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3139 BONDING_MODE_BALANCE, 0, 4, 1),
3140 "Failed to initialise bonded device");
3142 ret = rte_eth_promiscuous_enable(test_params->bonded_port_id);
3143 TEST_ASSERT_SUCCESS(ret,
3144 "Failed to enable promiscuous mode for port %d: %s",
3145 test_params->bonded_port_id, rte_strerror(-ret));
3147 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 1,
3148 "Port (%d) promiscuous mode not enabled",
3149 test_params->bonded_port_id);
3151 for (i = 0; i < test_params->bonded_slave_count; i++) {
3152 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(
3153 test_params->slave_port_ids[i]), 1,
3154 "Port (%d) promiscuous mode not enabled",
3155 test_params->slave_port_ids[i]);
3158 ret = rte_eth_promiscuous_disable(test_params->bonded_port_id);
3159 TEST_ASSERT_SUCCESS(ret,
3160 "Failed to disable promiscuous mode for port %d: %s",
3161 test_params->bonded_port_id, rte_strerror(-ret));
3163 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 0,
3164 "Port (%d) promiscuous mode not disabled",
3165 test_params->bonded_port_id);
3167 for (i = 0; i < test_params->bonded_slave_count; i++) {
3168 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(
3169 test_params->slave_port_ids[i]), 0,
3170 "Port (%d) promiscuous mode not disabled",
3171 test_params->slave_port_ids[i]);
3174 /* Clean up and remove slaves from bonded device */
3175 return remove_slaves_and_stop_bonded_device();
3179 test_balance_verify_mac_assignment(void)
3181 struct rte_ether_addr read_mac_addr;
3182 struct rte_ether_addr expected_mac_addr_0, expected_mac_addr_1;
3184 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
3185 rte_eth_macaddr_get(test_params->slave_port_ids[1], &expected_mac_addr_1);
3187 /* Initialize bonded device with 2 slaves in active backup mode */
3188 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3189 BONDING_MODE_BALANCE, 0, 2, 1),
3190 "Failed to initialise bonded device");
3192 /* Verify that bonded MACs is that of first slave and that the other slave
3193 * MAC hasn't been changed */
3194 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3195 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3196 sizeof(read_mac_addr)),
3197 "bonded port (%d) mac address not set to that of primary port",
3198 test_params->bonded_port_id);
3200 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
3201 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3202 sizeof(read_mac_addr)),
3203 "slave port (%d) mac address not set to that of primary port",
3204 test_params->slave_port_ids[0]);
3206 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
3207 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3208 sizeof(read_mac_addr)),
3209 "slave port (%d) mac address not set to that of primary port",
3210 test_params->slave_port_ids[1]);
3212 /* change primary and verify that MAC addresses haven't changed */
3213 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(test_params->bonded_port_id,
3214 test_params->slave_port_ids[1]),
3215 "Failed to set bonded port (%d) primary port to (%d)\n",
3216 test_params->bonded_port_id, test_params->slave_port_ids[1]);
3218 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3219 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3220 sizeof(read_mac_addr)),
3221 "bonded port (%d) mac address not set to that of primary port",
3222 test_params->bonded_port_id);
3224 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
3225 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3226 sizeof(read_mac_addr)),
3227 "slave port (%d) mac address not set to that of primary port",
3228 test_params->slave_port_ids[0]);
3230 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
3231 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3232 sizeof(read_mac_addr)),
3233 "slave port (%d) mac address not set to that of primary port",
3234 test_params->slave_port_ids[1]);
3236 /* stop / start bonded device and verify that primary MAC address is
3237 * propagated to bonded device and slaves */
3239 rte_eth_dev_stop(test_params->bonded_port_id);
3241 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
3242 "Failed to start bonded device");
3244 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3245 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3246 sizeof(read_mac_addr)),
3247 "bonded port (%d) mac address not set to that of primary port",
3248 test_params->bonded_port_id);
3250 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
3251 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3252 sizeof(read_mac_addr)),
3253 "slave port (%d) mac address not set to that of primary port",
3254 test_params->slave_port_ids[0]);
3256 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
3257 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3258 sizeof(read_mac_addr)),
3259 "slave port (%d) mac address not set to that of primary port",
3260 test_params->slave_port_ids[1]);
3262 /* Set explicit MAC address */
3263 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
3264 test_params->bonded_port_id,
3265 (struct rte_ether_addr *)bonded_mac),
3266 "failed to set MAC");
3268 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3269 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
3270 sizeof(read_mac_addr)),
3271 "bonded port (%d) mac address not set to that of bonded port",
3272 test_params->bonded_port_id);
3274 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
3275 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
3276 sizeof(read_mac_addr)),
3277 "slave port (%d) mac address not as expected\n",
3278 test_params->slave_port_ids[0]);
3280 rte_eth_macaddr_get(test_params->slave_port_ids[1], &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 set to that of bonded port",
3284 test_params->slave_port_ids[1]);
3286 /* Clean up and remove slaves from bonded device */
3287 return remove_slaves_and_stop_bonded_device();
3290 #define TEST_BALANCE_LINK_STATUS_SLAVE_COUNT (4)
3293 test_balance_verify_slave_link_status_change_behaviour(void)
3295 struct rte_mbuf *pkt_burst[TEST_BALANCE_LINK_STATUS_SLAVE_COUNT][MAX_PKT_BURST];
3296 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3297 struct rte_eth_stats port_stats;
3299 uint16_t slaves[RTE_MAX_ETHPORTS];
3301 int i, burst_size, slave_count;
3303 memset(pkt_burst, 0, sizeof(pkt_burst));
3305 /* Initialize bonded device with 4 slaves in round robin mode */
3306 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3307 BONDING_MODE_BALANCE, 0, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT, 1),
3308 "Failed to initialise bonded device");
3310 TEST_ASSERT_SUCCESS(rte_eth_bond_xmit_policy_set(
3311 test_params->bonded_port_id, BALANCE_XMIT_POLICY_LAYER2),
3312 "Failed to set balance xmit policy.");
3315 /* Verify Current Slaves Count /Active Slave Count is */
3316 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
3318 TEST_ASSERT_EQUAL(slave_count, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT,
3319 "Number of slaves (%d) is not as expected (%d).",
3320 slave_count, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT);
3322 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
3323 slaves, RTE_MAX_ETHPORTS);
3324 TEST_ASSERT_EQUAL(slave_count, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT,
3325 "Number of active slaves (%d) is not as expected (%d).",
3326 slave_count, TEST_BALANCE_LINK_STATUS_SLAVE_COUNT);
3328 /* Set 2 slaves link status to down */
3329 virtual_ethdev_simulate_link_status_interrupt(
3330 test_params->slave_port_ids[1], 0);
3331 virtual_ethdev_simulate_link_status_interrupt(
3332 test_params->slave_port_ids[3], 0);
3334 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
3335 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 2,
3336 "Number of active slaves (%d) is not as expected (%d).",
3339 /* Send to sets of packet burst and verify that they are balanced across
3343 TEST_ASSERT_EQUAL(generate_test_burst(
3344 &pkt_burst[0][0], burst_size, 0, 1, 0, 0, 0), burst_size,
3345 "generate_test_burst failed");
3347 TEST_ASSERT_EQUAL(generate_test_burst(
3348 &pkt_burst[1][0], burst_size, 0, 1, 1, 0, 0), burst_size,
3349 "generate_test_burst failed");
3351 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
3352 test_params->bonded_port_id, 0, &pkt_burst[0][0], burst_size),
3353 burst_size, "rte_eth_tx_burst failed");
3355 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
3356 test_params->bonded_port_id, 0, &pkt_burst[1][0], burst_size),
3357 burst_size, "rte_eth_tx_burst failed");
3360 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3361 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(burst_size + burst_size),
3362 "(%d) port_stats.opackets (%d) not as expected (%d).",
3363 test_params->bonded_port_id, (int)port_stats.opackets,
3364 burst_size + burst_size);
3366 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3367 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
3368 "(%d) port_stats.opackets (%d) not as expected (%d).",
3369 test_params->slave_port_ids[0], (int)port_stats.opackets,
3372 rte_eth_stats_get(test_params->slave_port_ids[2], &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[2], (int)port_stats.opackets,
3378 /* verify that all packets get send on primary slave when no other slaves
3380 virtual_ethdev_simulate_link_status_interrupt(
3381 test_params->slave_port_ids[2], 0);
3383 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
3384 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 1,
3385 "Number of active slaves (%d) is not as expected (%d).",
3388 TEST_ASSERT_EQUAL(generate_test_burst(
3389 &pkt_burst[1][0], burst_size, 0, 1, 1, 0, 0), burst_size,
3390 "generate_test_burst failed");
3392 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
3393 test_params->bonded_port_id, 0, &pkt_burst[1][0], burst_size),
3394 burst_size, "rte_eth_tx_burst failed");
3396 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3397 TEST_ASSERT_EQUAL(port_stats.opackets,
3398 (uint64_t)(burst_size + burst_size + burst_size),
3399 "(%d) port_stats.opackets (%d) not as expected (%d).\n",
3400 test_params->bonded_port_id, (int)port_stats.opackets,
3401 burst_size + burst_size + burst_size);
3403 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3404 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(burst_size + burst_size),
3405 "(%d) port_stats.opackets (%d) not as expected (%d).",
3406 test_params->slave_port_ids[0], (int)port_stats.opackets,
3407 burst_size + burst_size);
3409 virtual_ethdev_simulate_link_status_interrupt(
3410 test_params->slave_port_ids[0], 0);
3411 virtual_ethdev_simulate_link_status_interrupt(
3412 test_params->slave_port_ids[1], 1);
3413 virtual_ethdev_simulate_link_status_interrupt(
3414 test_params->slave_port_ids[2], 1);
3415 virtual_ethdev_simulate_link_status_interrupt(
3416 test_params->slave_port_ids[3], 1);
3418 for (i = 0; i < TEST_BALANCE_LINK_STATUS_SLAVE_COUNT; i++) {
3419 TEST_ASSERT_EQUAL(generate_test_burst(
3420 &pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0), burst_size,
3421 "Failed to generate packet burst");
3423 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3424 &pkt_burst[i][0], burst_size);
3427 /* Verify that pkts are not received on slaves with link status down */
3429 rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
3432 /* Verify bonded device rx count */
3433 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3434 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)(burst_size * 3),
3435 "(%d) port_stats.ipackets (%d) not as expected (%d)\n",
3436 test_params->bonded_port_id, (int)port_stats.ipackets,
3439 /* Clean up and remove slaves from bonded device */
3440 return remove_slaves_and_stop_bonded_device();
3444 test_broadcast_tx_burst(void)
3446 int i, pktlen, burst_size;
3447 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
3449 struct rte_eth_stats port_stats;
3451 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3452 BONDING_MODE_BROADCAST, 0, 2, 1),
3453 "Failed to initialise bonded device");
3455 initialize_eth_header(test_params->pkt_eth_hdr,
3456 (struct rte_ether_addr *)src_mac,
3457 (struct rte_ether_addr *)dst_mac_0,
3458 RTE_ETHER_TYPE_IPV4, 0, 0);
3460 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
3462 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
3463 dst_addr_0, pktlen);
3465 burst_size = 20 * test_params->bonded_slave_count;
3467 TEST_ASSERT(burst_size < MAX_PKT_BURST,
3468 "Burst size specified is greater than supported.");
3470 /* Generate a burst of packets to transmit */
3471 TEST_ASSERT_EQUAL(generate_packet_burst(test_params->mbuf_pool,
3472 pkts_burst, test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr,
3473 1, test_params->pkt_udp_hdr, burst_size, PACKET_BURST_GEN_PKT_LEN,
3474 1), burst_size, "Failed to generate packet burst");
3476 /* Send burst on bonded port */
3477 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
3478 pkts_burst, burst_size), burst_size,
3479 "Bonded Port (%d) rx burst failed, packets transmitted value "
3480 "not as expected (%d)",
3481 test_params->bonded_port_id, burst_size);
3483 /* Verify bonded port tx stats */
3484 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3485 TEST_ASSERT_EQUAL(port_stats.opackets,
3486 (uint64_t)burst_size * test_params->bonded_slave_count,
3487 "Bonded Port (%d) opackets value (%u) not as expected (%d)",
3488 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3491 /* Verify slave ports tx stats */
3492 for (i = 0; i < test_params->bonded_slave_count; i++) {
3493 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats);
3494 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
3495 "Slave Port (%d) opackets value (%u) not as expected (%d)\n",
3496 test_params->bonded_port_id,
3497 (unsigned int)port_stats.opackets, burst_size);
3500 /* Put all slaves down and try and transmit */
3501 for (i = 0; i < test_params->bonded_slave_count; i++) {
3503 virtual_ethdev_simulate_link_status_interrupt(
3504 test_params->slave_port_ids[i], 0);
3507 /* Send burst on bonded port */
3508 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
3509 test_params->bonded_port_id, 0, pkts_burst, burst_size), 0,
3510 "transmitted an unexpected number of packets");
3512 /* Clean up and remove slaves from bonded device */
3513 return remove_slaves_and_stop_bonded_device();
3517 #define TEST_BCAST_SLAVE_TX_FAIL_SLAVE_COUNT (3)
3518 #define TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE (40)
3519 #define TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT (15)
3520 #define TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT (10)
3523 test_broadcast_tx_burst_slave_tx_fail(void)
3525 struct rte_mbuf *pkts_burst[TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE];
3526 struct rte_mbuf *expected_fail_pkts[TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT];
3528 struct rte_eth_stats port_stats;
3532 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3533 BONDING_MODE_BROADCAST, 0,
3534 TEST_BCAST_SLAVE_TX_FAIL_SLAVE_COUNT, 1),
3535 "Failed to initialise bonded device");
3537 /* Generate test bursts for transmission */
3538 TEST_ASSERT_EQUAL(generate_test_burst(pkts_burst,
3539 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE, 0, 0, 0, 0, 0),
3540 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE,
3541 "Failed to generate test packet burst");
3543 for (i = 0; i < TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT; i++) {
3544 expected_fail_pkts[i] = pkts_burst[TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3545 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT + i];
3548 /* Set virtual slave TEST_BAL_SLAVE_TX_FAIL_FAILING_SLAVE_IDX to only fail
3549 * transmission of TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT packets of burst */
3550 virtual_ethdev_tx_burst_fn_set_success(
3551 test_params->slave_port_ids[0],
3553 virtual_ethdev_tx_burst_fn_set_success(
3554 test_params->slave_port_ids[1],
3556 virtual_ethdev_tx_burst_fn_set_success(
3557 test_params->slave_port_ids[2],
3560 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
3561 test_params->slave_port_ids[0],
3562 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT);
3564 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
3565 test_params->slave_port_ids[1],
3566 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT);
3568 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(
3569 test_params->slave_port_ids[2],
3570 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT);
3572 /* Transmit burst */
3573 tx_count = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst,
3574 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE);
3576 TEST_ASSERT_EQUAL(tx_count, TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3577 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT,
3578 "Transmitted (%d) packets, expected to transmit (%d) packets",
3579 tx_count, TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3580 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT);
3582 /* Verify that failed packet are expected failed packets */
3583 for (i = 0; i < TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT; i++) {
3584 TEST_ASSERT_EQUAL(expected_fail_pkts[i], pkts_burst[i + tx_count],
3585 "expected mbuf (%d) pointer %p not expected pointer %p",
3586 i, expected_fail_pkts[i], pkts_burst[i + tx_count]);
3589 /* Verify slave ports tx stats */
3591 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3593 TEST_ASSERT_EQUAL(port_stats.opackets,
3594 (uint64_t)TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3595 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT,
3596 "Port (%d) opackets value (%u) not as expected (%d)",
3597 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3598 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3599 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT);
3602 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3604 TEST_ASSERT_EQUAL(port_stats.opackets,
3605 (uint64_t)TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3606 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT,
3607 "Port (%d) opackets value (%u) not as expected (%d)",
3608 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3609 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3610 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT);
3612 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3614 TEST_ASSERT_EQUAL(port_stats.opackets,
3615 (uint64_t)TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3616 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT,
3617 "Port (%d) opackets value (%u) not as expected (%d)",
3618 test_params->bonded_port_id, (unsigned int)port_stats.opackets,
3619 TEST_BCAST_SLAVE_TX_FAIL_BURST_SIZE -
3620 TEST_BCAST_SLAVE_TX_FAIL_MAX_PACKETS_COUNT);
3623 /* Verify that all mbufs who transmission failed have a ref value of one */
3624 TEST_ASSERT_SUCCESS(verify_mbufs_ref_count(&pkts_burst[tx_count],
3625 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT, 1),
3626 "mbufs refcnts not as expected");
3628 free_mbufs(&pkts_burst[tx_count],
3629 TEST_BCAST_SLAVE_TX_FAIL_MIN_PACKETS_COUNT);
3631 /* Clean up and remove slaves from bonded device */
3632 return remove_slaves_and_stop_bonded_device();
3635 #define BROADCAST_RX_BURST_NUM_OF_SLAVES (3)
3638 test_broadcast_rx_burst(void)
3640 struct rte_mbuf *gen_pkt_burst[BROADCAST_RX_BURST_NUM_OF_SLAVES][MAX_PKT_BURST];
3642 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3643 struct rte_eth_stats port_stats;
3645 int burst_size[BROADCAST_RX_BURST_NUM_OF_SLAVES] = { 10, 5, 30 };
3648 memset(gen_pkt_burst, 0, sizeof(gen_pkt_burst));
3650 /* Initialize bonded device with 4 slaves in round robin mode */
3651 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3652 BONDING_MODE_BROADCAST, 0, 3, 1),
3653 "Failed to initialise bonded device");
3655 /* Generate test bursts of packets to transmit */
3656 for (i = 0; i < BROADCAST_RX_BURST_NUM_OF_SLAVES; i++) {
3657 TEST_ASSERT_EQUAL(generate_test_burst(
3658 &gen_pkt_burst[i][0], burst_size[i], 0, 0, 1, 0, 0),
3659 burst_size[i], "failed to generate packet burst");
3662 /* Add rx data to slave 0 */
3663 for (i = 0; i < BROADCAST_RX_BURST_NUM_OF_SLAVES; i++) {
3664 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3665 &gen_pkt_burst[i][0], burst_size[i]);
3669 /* Call rx burst on bonded device */
3670 /* Send burst on bonded port */
3671 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
3672 test_params->bonded_port_id, 0, rx_pkt_burst, MAX_PKT_BURST),
3673 burst_size[0] + burst_size[1] + burst_size[2],
3676 /* Verify bonded device rx count */
3677 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3678 TEST_ASSERT_EQUAL(port_stats.ipackets,
3679 (uint64_t)(burst_size[0] + burst_size[1] + burst_size[2]),
3680 "Bonded Port (%d) ipackets value (%u) not as expected (%d)",
3681 test_params->bonded_port_id, (unsigned int)port_stats.ipackets,
3682 burst_size[0] + burst_size[1] + burst_size[2]);
3685 /* Verify bonded slave devices rx counts */
3686 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3687 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[0],
3688 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3689 test_params->slave_port_ids[0], (unsigned int)port_stats.ipackets,
3692 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3693 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[1],
3694 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3695 test_params->slave_port_ids[0], (unsigned int)port_stats.ipackets,
3698 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3699 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size[2],
3700 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3701 test_params->slave_port_ids[2], (unsigned int)port_stats.ipackets,
3704 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
3705 TEST_ASSERT_EQUAL(port_stats.ipackets, 0,
3706 "Slave Port (%d) ipackets value (%u) not as expected (%d)",
3707 test_params->slave_port_ids[3], (unsigned int)port_stats.ipackets,
3710 /* free mbufs allocate for rx testing */
3711 for (i = 0; i < BROADCAST_RX_BURST_NUM_OF_SLAVES; i++) {
3712 for (j = 0; j < MAX_PKT_BURST; j++) {
3713 if (gen_pkt_burst[i][j] != NULL) {
3714 rte_pktmbuf_free(gen_pkt_burst[i][j]);
3715 gen_pkt_burst[i][j] = NULL;
3720 /* Clean up and remove slaves from bonded device */
3721 return remove_slaves_and_stop_bonded_device();
3725 test_broadcast_verify_promiscuous_enable_disable(void)
3730 /* Initialize bonded device with 4 slaves in round robin mode */
3731 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3732 BONDING_MODE_BROADCAST, 0, 4, 1),
3733 "Failed to initialise bonded device");
3735 ret = rte_eth_promiscuous_enable(test_params->bonded_port_id);
3736 TEST_ASSERT_SUCCESS(ret,
3737 "Failed to enable promiscuous mode for port %d: %s",
3738 test_params->bonded_port_id, rte_strerror(-ret));
3741 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 1,
3742 "Port (%d) promiscuous mode not enabled",
3743 test_params->bonded_port_id);
3745 for (i = 0; i < test_params->bonded_slave_count; i++) {
3746 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(
3747 test_params->slave_port_ids[i]), 1,
3748 "Port (%d) promiscuous mode not enabled",
3749 test_params->slave_port_ids[i]);
3752 ret = rte_eth_promiscuous_disable(test_params->bonded_port_id);
3753 TEST_ASSERT_SUCCESS(ret,
3754 "Failed to disable promiscuous mode for port %d: %s",
3755 test_params->bonded_port_id, rte_strerror(-ret));
3757 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(test_params->bonded_port_id), 0,
3758 "Port (%d) promiscuous mode not disabled",
3759 test_params->bonded_port_id);
3761 for (i = 0; i < test_params->bonded_slave_count; i++) {
3762 TEST_ASSERT_EQUAL(rte_eth_promiscuous_get(
3763 test_params->slave_port_ids[i]), 0,
3764 "Port (%d) promiscuous mode not disabled",
3765 test_params->slave_port_ids[i]);
3768 /* Clean up and remove slaves from bonded device */
3769 return remove_slaves_and_stop_bonded_device();
3773 test_broadcast_verify_mac_assignment(void)
3775 struct rte_ether_addr read_mac_addr;
3776 struct rte_ether_addr expected_mac_addr_0, expected_mac_addr_1;
3780 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
3781 rte_eth_macaddr_get(test_params->slave_port_ids[2], &expected_mac_addr_1);
3783 /* Initialize bonded device with 4 slaves in round robin mode */
3784 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3785 BONDING_MODE_BROADCAST, 0, 4, 1),
3786 "Failed to initialise bonded device");
3788 /* Verify that all MACs are the same as first slave added to bonded
3790 for (i = 0; i < test_params->bonded_slave_count; i++) {
3791 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3792 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3793 sizeof(read_mac_addr)),
3794 "slave port (%d) mac address not set to that of primary port",
3795 test_params->slave_port_ids[i]);
3798 /* change primary and verify that MAC addresses haven't changed */
3799 TEST_ASSERT_SUCCESS(rte_eth_bond_primary_set(test_params->bonded_port_id,
3800 test_params->slave_port_ids[2]),
3801 "Failed to set bonded port (%d) primary port to (%d)",
3802 test_params->bonded_port_id, test_params->slave_port_ids[i]);
3804 for (i = 0; i < test_params->bonded_slave_count; i++) {
3805 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3806 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
3807 sizeof(read_mac_addr)),
3808 "slave port (%d) mac address has changed to that of primary "
3809 "port without stop/start toggle of bonded device",
3810 test_params->slave_port_ids[i]);
3813 /* stop / start bonded device and verify that primary MAC address is
3814 * propagated to bonded device and slaves */
3816 rte_eth_dev_stop(test_params->bonded_port_id);
3818 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
3819 "Failed to start bonded device");
3821 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3822 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3823 sizeof(read_mac_addr)),
3824 "bonded port (%d) mac address not set to that of new primary port",
3825 test_params->slave_port_ids[i]);
3827 for (i = 0; i < test_params->bonded_slave_count; i++) {
3828 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3829 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
3830 sizeof(read_mac_addr)),
3831 "slave port (%d) mac address not set to that of new primary "
3832 "port", test_params->slave_port_ids[i]);
3835 /* Set explicit MAC address */
3836 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
3837 test_params->bonded_port_id,
3838 (struct rte_ether_addr *)bonded_mac),
3839 "Failed to set MAC address");
3841 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
3842 TEST_ASSERT_SUCCESS(memcmp(bonded_mac, &read_mac_addr,
3843 sizeof(read_mac_addr)),
3844 "bonded port (%d) mac address not set to that of new primary port",
3845 test_params->slave_port_ids[i]);
3848 for (i = 0; i < test_params->bonded_slave_count; i++) {
3849 rte_eth_macaddr_get(test_params->slave_port_ids[i], &read_mac_addr);
3850 TEST_ASSERT_SUCCESS(memcmp(bonded_mac, &read_mac_addr,
3851 sizeof(read_mac_addr)),
3852 "slave port (%d) mac address not set to that of new primary "
3853 "port", test_params->slave_port_ids[i]);
3856 /* Clean up and remove slaves from bonded device */
3857 return remove_slaves_and_stop_bonded_device();
3860 #define BROADCAST_LINK_STATUS_NUM_OF_SLAVES (4)
3862 test_broadcast_verify_slave_link_status_change_behaviour(void)
3864 struct rte_mbuf *pkt_burst[BROADCAST_LINK_STATUS_NUM_OF_SLAVES][MAX_PKT_BURST];
3865 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
3866 struct rte_eth_stats port_stats;
3868 uint16_t slaves[RTE_MAX_ETHPORTS];
3870 int i, burst_size, slave_count;
3872 memset(pkt_burst, 0, sizeof(pkt_burst));
3874 /* Initialize bonded device with 4 slaves in round robin mode */
3875 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
3876 BONDING_MODE_BROADCAST, 0, BROADCAST_LINK_STATUS_NUM_OF_SLAVES,
3877 1), "Failed to initialise bonded device");
3879 /* Verify Current Slaves Count /Active Slave Count is */
3880 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
3882 TEST_ASSERT_EQUAL(slave_count, 4,
3883 "Number of slaves (%d) is not as expected (%d).",
3886 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
3887 slaves, RTE_MAX_ETHPORTS);
3888 TEST_ASSERT_EQUAL(slave_count, 4,
3889 "Number of active slaves (%d) is not as expected (%d).",
3892 /* Set 2 slaves link status to down */
3893 virtual_ethdev_simulate_link_status_interrupt(
3894 test_params->slave_port_ids[1], 0);
3895 virtual_ethdev_simulate_link_status_interrupt(
3896 test_params->slave_port_ids[3], 0);
3898 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
3899 slaves, RTE_MAX_ETHPORTS);
3900 TEST_ASSERT_EQUAL(slave_count, 2,
3901 "Number of active slaves (%d) is not as expected (%d).",
3904 for (i = 0; i < test_params->bonded_slave_count; i++)
3905 rte_eth_stats_reset(test_params->slave_port_ids[i]);
3907 /* Verify that pkts are not sent on slaves with link status down */
3910 TEST_ASSERT_EQUAL(generate_test_burst(
3911 &pkt_burst[0][0], burst_size, 0, 0, 1, 0, 0), burst_size,
3912 "generate_test_burst failed");
3914 TEST_ASSERT_EQUAL(rte_eth_tx_burst(test_params->bonded_port_id, 0,
3915 &pkt_burst[0][0], burst_size), burst_size,
3916 "rte_eth_tx_burst failed\n");
3918 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3919 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)(burst_size * slave_count),
3920 "(%d) port_stats.opackets (%d) not as expected (%d)\n",
3921 test_params->bonded_port_id, (int)port_stats.opackets,
3922 burst_size * slave_count);
3924 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
3925 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
3926 "(%d) port_stats.opackets not as expected",
3927 test_params->slave_port_ids[0]);
3929 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
3930 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
3931 "(%d) port_stats.opackets not as expected",
3932 test_params->slave_port_ids[1]);
3934 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
3935 TEST_ASSERT_EQUAL(port_stats.opackets, (uint64_t)burst_size,
3936 "(%d) port_stats.opackets not as expected",
3937 test_params->slave_port_ids[2]);
3940 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
3941 TEST_ASSERT_EQUAL(port_stats.opackets, 0,
3942 "(%d) port_stats.opackets not as expected",
3943 test_params->slave_port_ids[3]);
3946 for (i = 0; i < BROADCAST_LINK_STATUS_NUM_OF_SLAVES; i++) {
3947 TEST_ASSERT_EQUAL(generate_test_burst(
3948 &pkt_burst[i][0], burst_size, 0, 0, 1, 0, 0),
3949 burst_size, "failed to generate packet burst");
3951 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
3952 &pkt_burst[i][0], burst_size);
3955 /* Verify that pkts are not received on slaves with link status down */
3956 TEST_ASSERT_EQUAL(rte_eth_rx_burst(
3957 test_params->bonded_port_id, 0, rx_pkt_burst, MAX_PKT_BURST),
3958 burst_size + burst_size, "rte_eth_rx_burst failed");
3961 /* Verify bonded device rx count */
3962 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
3963 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)(burst_size + burst_size),
3964 "(%d) port_stats.ipackets not as expected\n",
3965 test_params->bonded_port_id);
3967 /* Clean up and remove slaves from bonded device */
3968 return remove_slaves_and_stop_bonded_device();
3972 test_reconfigure_bonded_device(void)
3974 test_params->nb_rx_q = 4;
3975 test_params->nb_tx_q = 4;
3977 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0, 0),
3978 "failed to reconfigure bonded device");
3980 test_params->nb_rx_q = 2;
3981 test_params->nb_tx_q = 2;
3983 TEST_ASSERT_SUCCESS(configure_ethdev(test_params->bonded_port_id, 0, 0),
3984 "failed to reconfigure bonded device with less rx/tx queues");
3991 test_close_bonded_device(void)
3993 rte_eth_dev_close(test_params->bonded_port_id);
3998 testsuite_teardown(void)
4000 free(test_params->pkt_eth_hdr);
4001 test_params->pkt_eth_hdr = NULL;
4003 /* Clean up and remove slaves from bonded device */
4004 remove_slaves_and_stop_bonded_device();
4008 free_virtualpmd_tx_queue(void)
4010 int i, slave_port, to_free_cnt;
4011 struct rte_mbuf *pkts_to_free[MAX_PKT_BURST];
4013 /* Free tx queue of virtual pmd */
4014 for (slave_port = 0; slave_port < test_params->bonded_slave_count;
4016 to_free_cnt = virtual_ethdev_get_mbufs_from_tx_queue(
4017 test_params->slave_port_ids[slave_port],
4018 pkts_to_free, MAX_PKT_BURST);
4019 for (i = 0; i < to_free_cnt; i++)
4020 rte_pktmbuf_free(pkts_to_free[i]);
4025 test_tlb_tx_burst(void)
4027 int i, burst_size, nb_tx;
4028 uint64_t nb_tx2 = 0;
4029 struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
4030 struct rte_eth_stats port_stats[32];
4031 uint64_t sum_ports_opackets = 0, all_bond_opackets = 0, all_bond_obytes = 0;
4034 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves
4035 (BONDING_MODE_TLB, 1, 3, 1),
4036 "Failed to initialise bonded device");
4038 burst_size = 20 * test_params->bonded_slave_count;
4040 TEST_ASSERT(burst_size < MAX_PKT_BURST,
4041 "Burst size specified is greater than supported.\n");
4044 /* Generate bursts of packets */
4045 for (i = 0; i < 400000; i++) {
4046 /*test two types of mac src own(bonding) and others */
4048 initialize_eth_header(test_params->pkt_eth_hdr,
4049 (struct rte_ether_addr *)src_mac,
4050 (struct rte_ether_addr *)dst_mac_0,
4051 RTE_ETHER_TYPE_IPV4, 0, 0);
4053 initialize_eth_header(test_params->pkt_eth_hdr,
4054 (struct rte_ether_addr *)test_params->default_slave_mac,
4055 (struct rte_ether_addr *)dst_mac_0,
4056 RTE_ETHER_TYPE_IPV4, 0, 0);
4058 pktlen = initialize_udp_header(test_params->pkt_udp_hdr, src_port,
4060 pktlen = initialize_ipv4_header(test_params->pkt_ipv4_hdr, src_addr,
4061 dst_addr_0, pktlen);
4062 generate_packet_burst(test_params->mbuf_pool, pkt_burst,
4063 test_params->pkt_eth_hdr, 0, test_params->pkt_ipv4_hdr,
4064 1, test_params->pkt_udp_hdr, burst_size, 60, 1);
4065 /* Send burst on bonded port */
4066 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkt_burst,
4070 free_virtualpmd_tx_queue();
4072 TEST_ASSERT_EQUAL(nb_tx, burst_size,
4073 "number of packet not equal burst size");
4079 /* Verify bonded port tx stats */
4080 rte_eth_stats_get(test_params->bonded_port_id, &port_stats[0]);
4082 all_bond_opackets = port_stats[0].opackets;
4083 all_bond_obytes = port_stats[0].obytes;
4085 TEST_ASSERT_EQUAL(port_stats[0].opackets, (uint64_t)nb_tx2,
4086 "Bonded Port (%d) opackets value (%u) not as expected (%d)\n",
4087 test_params->bonded_port_id, (unsigned int)port_stats[0].opackets,
4091 /* Verify slave ports tx stats */
4092 for (i = 0; i < test_params->bonded_slave_count; i++) {
4093 rte_eth_stats_get(test_params->slave_port_ids[i], &port_stats[i]);
4094 sum_ports_opackets += port_stats[i].opackets;
4097 TEST_ASSERT_EQUAL(sum_ports_opackets, (uint64_t)all_bond_opackets,
4098 "Total packets sent by slaves is not equal to packets sent by bond interface");
4100 /* checking if distribution of packets is balanced over slaves */
4101 for (i = 0; i < test_params->bonded_slave_count; i++) {
4102 TEST_ASSERT(port_stats[i].obytes > 0 &&
4103 port_stats[i].obytes < all_bond_obytes,
4104 "Packets are not balanced over slaves");
4107 /* Put all slaves down and try and transmit */
4108 for (i = 0; i < test_params->bonded_slave_count; i++) {
4109 virtual_ethdev_simulate_link_status_interrupt(
4110 test_params->slave_port_ids[i], 0);
4113 /* Send burst on bonded port */
4114 nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkt_burst,
4116 TEST_ASSERT_EQUAL(nb_tx, 0, " bad number of packet in burst");
4118 /* Clean ugit checkout masterp and remove slaves from bonded device */
4119 return remove_slaves_and_stop_bonded_device();
4122 #define TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT (4)
4125 test_tlb_rx_burst(void)
4127 struct rte_mbuf *gen_pkt_burst[MAX_PKT_BURST] = { NULL };
4128 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
4130 struct rte_eth_stats port_stats;
4134 uint16_t i, j, nb_rx, burst_size = 17;
4136 /* Initialize bonded device with 4 slaves in transmit load balancing mode */
4137 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
4139 TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT, 1, 1),
4140 "Failed to initialize bonded device");
4143 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
4144 TEST_ASSERT(primary_port >= 0,
4145 "failed to get primary slave for bonded port (%d)",
4146 test_params->bonded_port_id);
4148 for (i = 0; i < test_params->bonded_slave_count; i++) {
4149 /* Generate test bursts of packets to transmit */
4150 TEST_ASSERT_EQUAL(generate_test_burst(
4151 &gen_pkt_burst[0], burst_size, 0, 1, 0, 0, 0), burst_size,
4152 "burst generation failed");
4154 /* Add rx data to slave */
4155 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[i],
4156 &gen_pkt_burst[0], burst_size);
4158 /* Call rx burst on bonded device */
4159 nb_rx = rte_eth_rx_burst(test_params->bonded_port_id, 0,
4160 &rx_pkt_burst[0], MAX_PKT_BURST);
4162 TEST_ASSERT_EQUAL(nb_rx, burst_size, "rte_eth_rx_burst failed\n");
4164 if (test_params->slave_port_ids[i] == primary_port) {
4165 /* Verify bonded device rx count */
4166 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
4167 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
4168 "Bonded Port (%d) ipackets value (%u) not as expected (%d)\n",
4169 test_params->bonded_port_id,
4170 (unsigned int)port_stats.ipackets, burst_size);
4172 /* Verify bonded slave devices rx count */
4173 for (j = 0; j < test_params->bonded_slave_count; j++) {
4174 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
4176 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
4177 "Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
4178 test_params->slave_port_ids[i],
4179 (unsigned int)port_stats.ipackets, burst_size);
4181 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)0,
4182 "Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
4183 test_params->slave_port_ids[i],
4184 (unsigned int)port_stats.ipackets, 0);
4188 for (j = 0; j < test_params->bonded_slave_count; j++) {
4189 rte_eth_stats_get(test_params->slave_port_ids[j], &port_stats);
4190 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)0,
4191 "Slave Port (%d) ipackets value (%u) not as expected (%d)\n",
4192 test_params->slave_port_ids[i],
4193 (unsigned int)port_stats.ipackets, 0);
4198 for (i = 0; i < burst_size; i++)
4199 rte_pktmbuf_free(rx_pkt_burst[i]);
4201 /* reset bonded device stats */
4202 rte_eth_stats_reset(test_params->bonded_port_id);
4205 /* Clean up and remove slaves from bonded device */
4206 return remove_slaves_and_stop_bonded_device();
4210 test_tlb_verify_promiscuous_enable_disable(void)
4212 int i, primary_port, promiscuous_en;
4215 /* Initialize bonded device with 4 slaves in transmit load balancing mode */
4216 TEST_ASSERT_SUCCESS( initialize_bonded_device_with_slaves(
4217 BONDING_MODE_TLB, 0, 4, 1),
4218 "Failed to initialize bonded device");
4220 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
4221 TEST_ASSERT(primary_port >= 0,
4222 "failed to get primary slave for bonded port (%d)",
4223 test_params->bonded_port_id);
4225 ret = rte_eth_promiscuous_enable(test_params->bonded_port_id);
4226 TEST_ASSERT_SUCCESS(ret,
4227 "Failed to enable promiscuous mode for port %d: %s",
4228 test_params->bonded_port_id, rte_strerror(-ret));
4230 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
4231 TEST_ASSERT_EQUAL(promiscuous_en, (int)1,
4232 "Port (%d) promiscuous mode not enabled\n",
4233 test_params->bonded_port_id);
4234 for (i = 0; i < test_params->bonded_slave_count; i++) {
4235 promiscuous_en = rte_eth_promiscuous_get(
4236 test_params->slave_port_ids[i]);
4237 if (primary_port == test_params->slave_port_ids[i]) {
4238 TEST_ASSERT_EQUAL(promiscuous_en, (int)1,
4239 "Port (%d) promiscuous mode not enabled\n",
4240 test_params->bonded_port_id);
4242 TEST_ASSERT_EQUAL(promiscuous_en, (int)0,
4243 "Port (%d) promiscuous mode enabled\n",
4244 test_params->bonded_port_id);
4249 ret = rte_eth_promiscuous_disable(test_params->bonded_port_id);
4250 TEST_ASSERT_SUCCESS(ret,
4251 "Failed to disable promiscuous mode for port %d: %s\n",
4252 test_params->bonded_port_id, rte_strerror(-ret));
4254 promiscuous_en = rte_eth_promiscuous_get(test_params->bonded_port_id);
4255 TEST_ASSERT_EQUAL(promiscuous_en, (int)0,
4256 "Port (%d) promiscuous mode not disabled\n",
4257 test_params->bonded_port_id);
4259 for (i = 0; i < test_params->bonded_slave_count; i++) {
4260 promiscuous_en = rte_eth_promiscuous_get(
4261 test_params->slave_port_ids[i]);
4262 TEST_ASSERT_EQUAL(promiscuous_en, (int)0,
4263 "slave port (%d) promiscuous mode not disabled\n",
4264 test_params->slave_port_ids[i]);
4267 /* Clean up and remove slaves from bonded device */
4268 return remove_slaves_and_stop_bonded_device();
4272 test_tlb_verify_mac_assignment(void)
4274 struct rte_ether_addr read_mac_addr;
4275 struct rte_ether_addr expected_mac_addr_0, expected_mac_addr_1;
4277 rte_eth_macaddr_get(test_params->slave_port_ids[0], &expected_mac_addr_0);
4278 rte_eth_macaddr_get(test_params->slave_port_ids[1], &expected_mac_addr_1);
4280 /* Initialize bonded device with 2 slaves in active backup mode */
4281 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
4282 BONDING_MODE_TLB, 0, 2, 1),
4283 "Failed to initialize bonded device");
4285 /* Verify that bonded MACs is that of first slave and that the other slave
4286 * MAC hasn't been changed */
4287 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
4288 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4289 sizeof(read_mac_addr)),
4290 "bonded port (%d) mac address not set to that of primary port",
4291 test_params->bonded_port_id);
4293 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
4294 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4295 sizeof(read_mac_addr)),
4296 "slave port (%d) mac address not set to that of primary port",
4297 test_params->slave_port_ids[0]);
4299 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
4300 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
4301 sizeof(read_mac_addr)),
4302 "slave port (%d) mac address not as expected",
4303 test_params->slave_port_ids[1]);
4305 /* change primary and verify that MAC addresses haven't changed */
4306 TEST_ASSERT_EQUAL(rte_eth_bond_primary_set(test_params->bonded_port_id,
4307 test_params->slave_port_ids[1]), 0,
4308 "Failed to set bonded port (%d) primary port to (%d)",
4309 test_params->bonded_port_id, test_params->slave_port_ids[1]);
4311 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
4312 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4313 sizeof(read_mac_addr)),
4314 "bonded port (%d) mac address not set to that of primary port",
4315 test_params->bonded_port_id);
4317 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
4318 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4319 sizeof(read_mac_addr)),
4320 "slave port (%d) mac address not set to that of primary port",
4321 test_params->slave_port_ids[0]);
4323 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
4324 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
4325 sizeof(read_mac_addr)),
4326 "slave port (%d) mac address not as expected",
4327 test_params->slave_port_ids[1]);
4329 /* stop / start bonded device and verify that primary MAC address is
4330 * propagated to bonded device and slaves */
4332 rte_eth_dev_stop(test_params->bonded_port_id);
4334 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
4335 "Failed to start device");
4337 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
4338 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
4339 sizeof(read_mac_addr)),
4340 "bonded port (%d) mac address not set to that of primary port",
4341 test_params->bonded_port_id);
4343 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
4344 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4345 sizeof(read_mac_addr)),
4346 "slave port (%d) mac address not as expected",
4347 test_params->slave_port_ids[0]);
4349 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
4350 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_1, &read_mac_addr,
4351 sizeof(read_mac_addr)),
4352 "slave port (%d) mac address not set to that of primary port",
4353 test_params->slave_port_ids[1]);
4356 /* Set explicit MAC address */
4357 TEST_ASSERT_SUCCESS(rte_eth_bond_mac_address_set(
4358 test_params->bonded_port_id,
4359 (struct rte_ether_addr *)bonded_mac),
4360 "failed to set MAC address");
4362 rte_eth_macaddr_get(test_params->bonded_port_id, &read_mac_addr);
4363 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
4364 sizeof(read_mac_addr)),
4365 "bonded port (%d) mac address not set to that of bonded port",
4366 test_params->bonded_port_id);
4368 rte_eth_macaddr_get(test_params->slave_port_ids[0], &read_mac_addr);
4369 TEST_ASSERT_SUCCESS(memcmp(&expected_mac_addr_0, &read_mac_addr,
4370 sizeof(read_mac_addr)),
4371 "slave port (%d) mac address not as expected",
4372 test_params->slave_port_ids[0]);
4374 rte_eth_macaddr_get(test_params->slave_port_ids[1], &read_mac_addr);
4375 TEST_ASSERT_SUCCESS(memcmp(&bonded_mac, &read_mac_addr,
4376 sizeof(read_mac_addr)),
4377 "slave port (%d) mac address not set to that of bonded port",
4378 test_params->slave_port_ids[1]);
4380 /* Clean up and remove slaves from bonded device */
4381 return remove_slaves_and_stop_bonded_device();
4385 test_tlb_verify_slave_link_status_change_failover(void)
4387 struct rte_mbuf *pkt_burst[TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT][MAX_PKT_BURST];
4388 struct rte_mbuf *rx_pkt_burst[MAX_PKT_BURST] = { NULL };
4389 struct rte_eth_stats port_stats;
4391 uint16_t slaves[RTE_MAX_ETHPORTS];
4393 int i, burst_size, slave_count, primary_port;
4397 memset(pkt_burst, 0, sizeof(pkt_burst));
4401 /* Initialize bonded device with 4 slaves in round robin mode */
4402 TEST_ASSERT_SUCCESS(initialize_bonded_device_with_slaves(
4403 BONDING_MODE_TLB, 0,
4404 TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT, 1),
4405 "Failed to initialize bonded device with slaves");
4407 /* Verify Current Slaves Count /Active Slave Count is */
4408 slave_count = rte_eth_bond_slaves_get(test_params->bonded_port_id, slaves,
4410 TEST_ASSERT_EQUAL(slave_count, 4,
4411 "Number of slaves (%d) is not as expected (%d).\n",
4414 slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
4415 slaves, RTE_MAX_ETHPORTS);
4416 TEST_ASSERT_EQUAL(slave_count, (int)4,
4417 "Number of slaves (%d) is not as expected (%d).\n",
4420 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
4421 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[0],
4422 "Primary port not as expected");
4424 /* Bring 2 slaves down and verify active slave count */
4425 virtual_ethdev_simulate_link_status_interrupt(
4426 test_params->slave_port_ids[1], 0);
4427 virtual_ethdev_simulate_link_status_interrupt(
4428 test_params->slave_port_ids[3], 0);
4430 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
4431 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 2,
4432 "Number of active slaves (%d) is not as expected (%d).",
4435 virtual_ethdev_simulate_link_status_interrupt(
4436 test_params->slave_port_ids[1], 1);
4437 virtual_ethdev_simulate_link_status_interrupt(
4438 test_params->slave_port_ids[3], 1);
4441 /* Bring primary port down, verify that active slave count is 3 and primary
4443 virtual_ethdev_simulate_link_status_interrupt(
4444 test_params->slave_port_ids[0], 0);
4446 TEST_ASSERT_EQUAL(rte_eth_bond_active_slaves_get(
4447 test_params->bonded_port_id, slaves, RTE_MAX_ETHPORTS), 3,
4448 "Number of active slaves (%d) is not as expected (%d).",
4451 primary_port = rte_eth_bond_primary_get(test_params->bonded_port_id);
4452 TEST_ASSERT_EQUAL(primary_port, test_params->slave_port_ids[2],
4453 "Primary port not as expected");
4454 rte_delay_us(500000);
4455 /* Verify that pkts are sent on new primary slave */
4456 for (i = 0; i < 4; i++) {
4457 TEST_ASSERT_EQUAL(generate_test_burst(
4458 &pkt_burst[0][0], burst_size, 0, 1, 0, 0, 0), burst_size,
4459 "generate_test_burst failed\n");
4460 TEST_ASSERT_EQUAL(rte_eth_tx_burst(
4461 test_params->bonded_port_id, 0, &pkt_burst[0][0], burst_size), burst_size,
4462 "rte_eth_tx_burst failed\n");
4463 rte_delay_us(11000);
4466 rte_eth_stats_get(test_params->slave_port_ids[0], &port_stats);
4467 TEST_ASSERT_EQUAL(port_stats.opackets, (int8_t)0,
4468 "(%d) port_stats.opackets not as expected\n",
4469 test_params->slave_port_ids[0]);
4471 rte_eth_stats_get(test_params->slave_port_ids[1], &port_stats);
4472 TEST_ASSERT_NOT_EQUAL(port_stats.opackets, (int8_t)0,
4473 "(%d) port_stats.opackets not as expected\n",
4474 test_params->slave_port_ids[1]);
4476 rte_eth_stats_get(test_params->slave_port_ids[2], &port_stats);
4477 TEST_ASSERT_NOT_EQUAL(port_stats.opackets, (int8_t)0,
4478 "(%d) port_stats.opackets not as expected\n",
4479 test_params->slave_port_ids[2]);
4481 rte_eth_stats_get(test_params->slave_port_ids[3], &port_stats);
4482 TEST_ASSERT_NOT_EQUAL(port_stats.opackets, (int8_t)0,
4483 "(%d) port_stats.opackets not as expected\n",
4484 test_params->slave_port_ids[3]);
4487 /* Generate packet burst for testing */
4489 for (i = 0; i < TEST_ADAPTIVE_TRANSMIT_LOAD_BALANCING_RX_BURST_SLAVE_COUNT; i++) {
4490 if (generate_test_burst(&pkt_burst[i][0], burst_size, 0, 1, 0, 0, 0) !=
4494 virtual_ethdev_add_mbufs_to_rx_queue(
4495 test_params->slave_port_ids[i], &pkt_burst[i][0], burst_size);
4498 if (rte_eth_rx_burst(test_params->bonded_port_id, 0, rx_pkt_burst,
4499 MAX_PKT_BURST) != burst_size) {
4500 printf("rte_eth_rx_burst\n");
4505 /* Verify bonded device rx count */
4506 rte_eth_stats_get(test_params->bonded_port_id, &port_stats);
4507 TEST_ASSERT_EQUAL(port_stats.ipackets, (uint64_t)burst_size,
4508 "(%d) port_stats.ipackets not as expected\n",
4509 test_params->bonded_port_id);
4511 /* Clean up and remove slaves from bonded device */
4512 return remove_slaves_and_stop_bonded_device();
4515 #define TEST_ALB_SLAVE_COUNT 2
4517 static uint8_t mac_client1[] = {0x00, 0xAA, 0x55, 0xFF, 0xCC, 1};
4518 static uint8_t mac_client2[] = {0x00, 0xAA, 0x55, 0xFF, 0xCC, 2};
4519 static uint8_t mac_client3[] = {0x00, 0xAA, 0x55, 0xFF, 0xCC, 3};
4520 static uint8_t mac_client4[] = {0x00, 0xAA, 0x55, 0xFF, 0xCC, 4};
4522 static uint32_t ip_host = IPV4_ADDR(192, 168, 0, 0);
4523 static uint32_t ip_client1 = IPV4_ADDR(192, 168, 0, 1);
4524 static uint32_t ip_client2 = IPV4_ADDR(192, 168, 0, 2);
4525 static uint32_t ip_client3 = IPV4_ADDR(192, 168, 0, 3);
4526 static uint32_t ip_client4 = IPV4_ADDR(192, 168, 0, 4);
4529 test_alb_change_mac_in_reply_sent(void)
4531 struct rte_mbuf *pkt;
4532 struct rte_mbuf *pkts_sent[MAX_PKT_BURST];
4534 struct rte_ether_hdr *eth_pkt;
4535 struct rte_arp_hdr *arp_pkt;
4537 int slave_idx, nb_pkts, pkt_idx;
4540 struct rte_ether_addr bond_mac, client_mac;
4541 struct rte_ether_addr *slave_mac1, *slave_mac2;
4543 TEST_ASSERT_SUCCESS(
4544 initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
4545 0, TEST_ALB_SLAVE_COUNT, 1),
4546 "Failed to initialize_bonded_device_with_slaves.");
4548 /* Flush tx queue */
4549 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4550 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count;
4552 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4553 test_params->slave_port_ids[slave_idx], pkts_sent,
4557 rte_ether_addr_copy(
4558 rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
4562 * Generating four packets with different mac and ip addresses and sending
4563 * them through the bonding port.
4565 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4566 memcpy(client_mac.addr_bytes, mac_client1, RTE_ETHER_ADDR_LEN);
4567 eth_pkt = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
4568 initialize_eth_header(eth_pkt, &bond_mac, &client_mac,
4569 RTE_ETHER_TYPE_ARP, 0, 0);
4570 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4571 sizeof(struct rte_ether_hdr));
4572 initialize_arp_header(arp_pkt, &bond_mac, &client_mac, ip_host, ip_client1,
4574 rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
4576 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4577 memcpy(client_mac.addr_bytes, mac_client2, RTE_ETHER_ADDR_LEN);
4578 eth_pkt = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
4579 initialize_eth_header(eth_pkt, &bond_mac, &client_mac,
4580 RTE_ETHER_TYPE_ARP, 0, 0);
4581 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4582 sizeof(struct rte_ether_hdr));
4583 initialize_arp_header(arp_pkt, &bond_mac, &client_mac, ip_host, ip_client2,
4585 rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
4587 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4588 memcpy(client_mac.addr_bytes, mac_client3, RTE_ETHER_ADDR_LEN);
4589 eth_pkt = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
4590 initialize_eth_header(eth_pkt, &bond_mac, &client_mac,
4591 RTE_ETHER_TYPE_ARP, 0, 0);
4592 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4593 sizeof(struct rte_ether_hdr));
4594 initialize_arp_header(arp_pkt, &bond_mac, &client_mac, ip_host, ip_client3,
4596 rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
4598 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4599 memcpy(client_mac.addr_bytes, mac_client4, RTE_ETHER_ADDR_LEN);
4600 eth_pkt = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
4601 initialize_eth_header(eth_pkt, &bond_mac, &client_mac,
4602 RTE_ETHER_TYPE_ARP, 0, 0);
4603 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4604 sizeof(struct rte_ether_hdr));
4605 initialize_arp_header(arp_pkt, &bond_mac, &client_mac, ip_host, ip_client4,
4607 rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
4610 rte_eth_devices[test_params->slave_port_ids[0]].data->mac_addrs;
4612 rte_eth_devices[test_params->slave_port_ids[1]].data->mac_addrs;
4615 * Checking if packets are properly distributed on bonding ports. Packets
4616 * 0 and 2 should be sent on port 0 and packets 1 and 3 on port 1.
4618 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4619 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4620 test_params->slave_port_ids[slave_idx], pkts_sent,
4623 for (pkt_idx = 0; pkt_idx < nb_pkts; pkt_idx++) {
4624 eth_pkt = rte_pktmbuf_mtod(
4625 pkts_sent[pkt_idx], struct rte_ether_hdr *);
4626 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4627 sizeof(struct rte_ether_hdr));
4629 if (slave_idx%2 == 0) {
4630 if (!rte_is_same_ether_addr(slave_mac1,
4631 &arp_pkt->arp_data.arp_sha)) {
4636 if (!rte_is_same_ether_addr(slave_mac2,
4637 &arp_pkt->arp_data.arp_sha)) {
4646 retval += remove_slaves_and_stop_bonded_device();
4651 test_alb_reply_from_client(void)
4653 struct rte_ether_hdr *eth_pkt;
4654 struct rte_arp_hdr *arp_pkt;
4656 struct rte_mbuf *pkt;
4657 struct rte_mbuf *pkts_sent[MAX_PKT_BURST];
4659 int slave_idx, nb_pkts, pkt_idx, nb_pkts_sum = 0;
4662 struct rte_ether_addr bond_mac, client_mac;
4663 struct rte_ether_addr *slave_mac1, *slave_mac2;
4665 TEST_ASSERT_SUCCESS(
4666 initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
4667 0, TEST_ALB_SLAVE_COUNT, 1),
4668 "Failed to initialize_bonded_device_with_slaves.");
4670 /* Flush tx queue */
4671 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4672 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4673 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4674 test_params->slave_port_ids[slave_idx], pkts_sent,
4678 rte_ether_addr_copy(
4679 rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
4683 * Generating four packets with different mac and ip addresses and placing
4684 * them in the rx queue to be received by the bonding driver on rx_burst.
4686 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4687 memcpy(client_mac.addr_bytes, mac_client1, RTE_ETHER_ADDR_LEN);
4688 eth_pkt = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
4689 initialize_eth_header(eth_pkt, &bond_mac, &client_mac,
4690 RTE_ETHER_TYPE_ARP, 0, 0);
4691 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4692 sizeof(struct rte_ether_hdr));
4693 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client1, ip_host,
4695 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4698 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4699 memcpy(client_mac.addr_bytes, mac_client2, RTE_ETHER_ADDR_LEN);
4700 eth_pkt = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
4701 initialize_eth_header(eth_pkt, &bond_mac, &client_mac,
4702 RTE_ETHER_TYPE_ARP, 0, 0);
4703 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4704 sizeof(struct rte_ether_hdr));
4705 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client2, ip_host,
4707 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4710 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4711 memcpy(client_mac.addr_bytes, mac_client3, RTE_ETHER_ADDR_LEN);
4712 eth_pkt = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
4713 initialize_eth_header(eth_pkt, &bond_mac, &client_mac,
4714 RTE_ETHER_TYPE_ARP, 0, 0);
4715 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4716 sizeof(struct rte_ether_hdr));
4717 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client3, ip_host,
4719 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4722 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4723 memcpy(client_mac.addr_bytes, mac_client4, RTE_ETHER_ADDR_LEN);
4724 eth_pkt = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
4725 initialize_eth_header(eth_pkt, &bond_mac, &client_mac,
4726 RTE_ETHER_TYPE_ARP, 0, 0);
4727 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4728 sizeof(struct rte_ether_hdr));
4729 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client4, ip_host,
4731 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4735 * Issue rx_burst and tx_burst to force bonding driver to send update ARP
4736 * packets to every client in alb table.
4738 rte_eth_rx_burst(test_params->bonded_port_id, 0, pkts_sent, MAX_PKT_BURST);
4739 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4741 slave_mac1 = rte_eth_devices[test_params->slave_port_ids[0]].data->mac_addrs;
4742 slave_mac2 = rte_eth_devices[test_params->slave_port_ids[1]].data->mac_addrs;
4745 * Checking if update ARP packets were properly send on slave ports.
4747 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4748 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4749 test_params->slave_port_ids[slave_idx], pkts_sent, MAX_PKT_BURST);
4750 nb_pkts_sum += nb_pkts;
4752 for (pkt_idx = 0; pkt_idx < nb_pkts; pkt_idx++) {
4753 eth_pkt = rte_pktmbuf_mtod(
4754 pkts_sent[pkt_idx], struct rte_ether_hdr *);
4755 arp_pkt = (struct rte_arp_hdr *)((char *)eth_pkt +
4756 sizeof(struct rte_ether_hdr));
4758 if (slave_idx%2 == 0) {
4759 if (!rte_is_same_ether_addr(slave_mac1,
4760 &arp_pkt->arp_data.arp_sha)) {
4765 if (!rte_is_same_ether_addr(slave_mac2,
4766 &arp_pkt->arp_data.arp_sha)) {
4774 /* Check if proper number of packets was send */
4775 if (nb_pkts_sum < 4) {
4781 retval += remove_slaves_and_stop_bonded_device();
4786 test_alb_receive_vlan_reply(void)
4788 struct rte_ether_hdr *eth_pkt;
4789 struct rte_vlan_hdr *vlan_pkt;
4790 struct rte_arp_hdr *arp_pkt;
4792 struct rte_mbuf *pkt;
4793 struct rte_mbuf *pkts_sent[MAX_PKT_BURST];
4795 int slave_idx, nb_pkts, pkt_idx;
4798 struct rte_ether_addr bond_mac, client_mac;
4800 TEST_ASSERT_SUCCESS(
4801 initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
4802 0, TEST_ALB_SLAVE_COUNT, 1),
4803 "Failed to initialize_bonded_device_with_slaves.");
4805 /* Flush tx queue */
4806 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4807 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4808 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4809 test_params->slave_port_ids[slave_idx], pkts_sent,
4813 rte_ether_addr_copy(
4814 rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
4818 * Generating packet with double VLAN header and placing it in the rx queue.
4820 pkt = rte_pktmbuf_alloc(test_params->mbuf_pool);
4821 memcpy(client_mac.addr_bytes, mac_client1, RTE_ETHER_ADDR_LEN);
4822 eth_pkt = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
4823 initialize_eth_header(eth_pkt, &bond_mac, &client_mac,
4824 RTE_ETHER_TYPE_VLAN, 0, 0);
4825 vlan_pkt = (struct rte_vlan_hdr *)((char *)(eth_pkt + 1));
4826 vlan_pkt->vlan_tci = rte_cpu_to_be_16(1);
4827 vlan_pkt->eth_proto = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4828 vlan_pkt = vlan_pkt+1;
4829 vlan_pkt->vlan_tci = rte_cpu_to_be_16(2);
4830 vlan_pkt->eth_proto = rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP);
4831 arp_pkt = (struct rte_arp_hdr *)((char *)(vlan_pkt + 1));
4832 initialize_arp_header(arp_pkt, &client_mac, &bond_mac, ip_client1, ip_host,
4834 virtual_ethdev_add_mbufs_to_rx_queue(test_params->slave_port_ids[0], &pkt,
4837 rte_eth_rx_burst(test_params->bonded_port_id, 0, pkts_sent, MAX_PKT_BURST);
4838 rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
4841 * Checking if VLAN headers in generated ARP Update packet are correct.
4843 for (slave_idx = 0; slave_idx < test_params->bonded_slave_count; slave_idx++) {
4844 nb_pkts = virtual_ethdev_get_mbufs_from_tx_queue(
4845 test_params->slave_port_ids[slave_idx], pkts_sent,
4848 for (pkt_idx = 0; pkt_idx < nb_pkts; pkt_idx++) {
4849 eth_pkt = rte_pktmbuf_mtod(
4850 pkts_sent[pkt_idx], struct rte_ether_hdr *);
4851 vlan_pkt = (struct rte_vlan_hdr *)(
4852 (char *)(eth_pkt + 1));
4853 if (vlan_pkt->vlan_tci != rte_cpu_to_be_16(1)) {
4857 if (vlan_pkt->eth_proto != rte_cpu_to_be_16(
4858 RTE_ETHER_TYPE_VLAN)) {
4862 vlan_pkt = vlan_pkt+1;
4863 if (vlan_pkt->vlan_tci != rte_cpu_to_be_16(2)) {
4867 if (vlan_pkt->eth_proto != rte_cpu_to_be_16(
4868 RTE_ETHER_TYPE_ARP)) {
4876 retval += remove_slaves_and_stop_bonded_device();
4881 test_alb_ipv4_tx(void)
4883 int burst_size, retval, pkts_send;
4884 struct rte_mbuf *pkt_burst[MAX_PKT_BURST];
4888 TEST_ASSERT_SUCCESS(
4889 initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
4890 0, TEST_ALB_SLAVE_COUNT, 1),
4891 "Failed to initialize_bonded_device_with_slaves.");
4895 /* Generate test bursts of packets to transmit */
4896 if (generate_test_burst(pkt_burst, burst_size, 0, 1, 0, 0, 0) != burst_size) {
4902 * Checking if ipv4 traffic is transmitted via TLB policy.
4904 pkts_send = rte_eth_tx_burst(
4905 test_params->bonded_port_id, 0, pkt_burst, burst_size);
4906 if (pkts_send != burst_size) {
4912 retval += remove_slaves_and_stop_bonded_device();
4916 static struct unit_test_suite link_bonding_test_suite = {
4917 .suite_name = "Link Bonding Unit Test Suite",
4918 .setup = test_setup,
4919 .teardown = testsuite_teardown,
4920 .unit_test_cases = {
4921 TEST_CASE(test_create_bonded_device),
4922 TEST_CASE(test_create_bonded_device_with_invalid_params),
4923 TEST_CASE(test_add_slave_to_bonded_device),
4924 TEST_CASE(test_add_slave_to_invalid_bonded_device),
4925 TEST_CASE(test_remove_slave_from_bonded_device),
4926 TEST_CASE(test_remove_slave_from_invalid_bonded_device),
4927 TEST_CASE(test_get_slaves_from_bonded_device),
4928 TEST_CASE(test_add_already_bonded_slave_to_bonded_device),
4929 TEST_CASE(test_add_remove_multiple_slaves_to_from_bonded_device),
4930 TEST_CASE(test_start_bonded_device),
4931 TEST_CASE(test_stop_bonded_device),
4932 TEST_CASE(test_set_bonding_mode),
4933 TEST_CASE(test_set_primary_slave),
4934 TEST_CASE(test_set_explicit_bonded_mac),
4935 TEST_CASE(test_set_bonded_port_initialization_mac_assignment),
4936 TEST_CASE(test_status_interrupt),
4937 TEST_CASE(test_adding_slave_after_bonded_device_started),
4938 TEST_CASE(test_roundrobin_tx_burst),
4939 TEST_CASE(test_roundrobin_tx_burst_slave_tx_fail),
4940 TEST_CASE(test_roundrobin_rx_burst_on_single_slave),
4941 TEST_CASE(test_roundrobin_rx_burst_on_multiple_slaves),
4942 TEST_CASE(test_roundrobin_verify_promiscuous_enable_disable),
4943 TEST_CASE(test_roundrobin_verify_mac_assignment),
4944 TEST_CASE(test_roundrobin_verify_slave_link_status_change_behaviour),
4945 TEST_CASE(test_roundrobin_verfiy_polling_slave_link_status_change),
4946 TEST_CASE(test_activebackup_tx_burst),
4947 TEST_CASE(test_activebackup_rx_burst),
4948 TEST_CASE(test_activebackup_verify_promiscuous_enable_disable),
4949 TEST_CASE(test_activebackup_verify_mac_assignment),
4950 TEST_CASE(test_activebackup_verify_slave_link_status_change_failover),
4951 TEST_CASE(test_balance_xmit_policy_configuration),
4952 TEST_CASE(test_balance_l2_tx_burst),
4953 TEST_CASE(test_balance_l23_tx_burst_ipv4_toggle_ip_addr),
4954 TEST_CASE(test_balance_l23_tx_burst_vlan_ipv4_toggle_ip_addr),
4955 TEST_CASE(test_balance_l23_tx_burst_ipv6_toggle_ip_addr),
4956 TEST_CASE(test_balance_l23_tx_burst_vlan_ipv6_toggle_ip_addr),
4957 TEST_CASE(test_balance_l23_tx_burst_toggle_mac_addr),
4958 TEST_CASE(test_balance_l34_tx_burst_ipv4_toggle_ip_addr),
4959 TEST_CASE(test_balance_l34_tx_burst_ipv4_toggle_udp_port),
4960 TEST_CASE(test_balance_l34_tx_burst_vlan_ipv4_toggle_ip_addr),
4961 TEST_CASE(test_balance_l34_tx_burst_ipv6_toggle_ip_addr),
4962 TEST_CASE(test_balance_l34_tx_burst_vlan_ipv6_toggle_ip_addr),
4963 TEST_CASE(test_balance_l34_tx_burst_ipv6_toggle_udp_port),
4964 TEST_CASE(test_balance_tx_burst_slave_tx_fail),
4965 TEST_CASE(test_balance_rx_burst),
4966 TEST_CASE(test_balance_verify_promiscuous_enable_disable),
4967 TEST_CASE(test_balance_verify_mac_assignment),
4968 TEST_CASE(test_balance_verify_slave_link_status_change_behaviour),
4969 TEST_CASE(test_tlb_tx_burst),
4970 TEST_CASE(test_tlb_rx_burst),
4971 TEST_CASE(test_tlb_verify_mac_assignment),
4972 TEST_CASE(test_tlb_verify_promiscuous_enable_disable),
4973 TEST_CASE(test_tlb_verify_slave_link_status_change_failover),
4974 TEST_CASE(test_alb_change_mac_in_reply_sent),
4975 TEST_CASE(test_alb_reply_from_client),
4976 TEST_CASE(test_alb_receive_vlan_reply),
4977 TEST_CASE(test_alb_ipv4_tx),
4978 TEST_CASE(test_broadcast_tx_burst),
4979 TEST_CASE(test_broadcast_tx_burst_slave_tx_fail),
4980 TEST_CASE(test_broadcast_rx_burst),
4981 TEST_CASE(test_broadcast_verify_promiscuous_enable_disable),
4982 TEST_CASE(test_broadcast_verify_mac_assignment),
4983 TEST_CASE(test_broadcast_verify_slave_link_status_change_behaviour),
4984 TEST_CASE(test_reconfigure_bonded_device),
4985 TEST_CASE(test_close_bonded_device),
4987 TEST_CASES_END() /**< NULL terminate unit test array */
4993 test_link_bonding(void)
4995 return unit_test_suite_runner(&link_bonding_test_suite);
4998 REGISTER_TEST_COMMAND(link_bonding_autotest, test_link_bonding);