4 * Copyright(c) 2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <rte_cycles.h>
42 #include <sys/queue.h>
44 #include <rte_byteorder.h>
45 #include <rte_common.h>
46 #include <rte_debug.h>
47 #include <rte_ethdev.h>
49 #include <rte_lcore.h>
50 #include <rte_memory.h>
51 #include <rte_bus_vdev.h>
53 #include <rte_string_fns.h>
54 #include <rte_errno.h>
55 #include <rte_eth_bond.h>
59 #define SLAVE_COUNT (4)
61 #define RXTX_RING_SIZE 1024
62 #define RXTX_QUEUE_COUNT 4
64 #define BONDED_DEV_NAME ("net_bonding_rss")
66 #define SLAVE_DEV_NAME_FMT ("net_null%d")
67 #define SLAVE_RXTX_QUEUE_FMT ("rssconf_slave%d_q%d")
69 #define NUM_MBUFS 8191
70 #define MBUF_SIZE (1600 + RTE_PKTMBUF_HEADROOM)
71 #define MBUF_CACHE_SIZE 250
74 #define INVALID_SOCKET_ID (-1)
75 #define INVALID_PORT_ID (0xFF)
76 #define INVALID_BONDING_MODE (-1)
80 struct rte_eth_dev_info dev_info;
82 struct rte_eth_rss_conf rss_conf;
84 struct rte_eth_rss_reta_entry64 reta_conf[512 / RTE_RETA_GROUP_SIZE];
87 struct rte_ring *rxtx_queue[RXTX_QUEUE_COUNT];
90 struct link_bonding_rssconf_unittest_params {
92 struct rte_eth_dev_info bond_dev_info;
93 struct rte_eth_rss_reta_entry64 bond_reta_conf[512 / RTE_RETA_GROUP_SIZE];
94 struct slave_conf slave_ports[SLAVE_COUNT];
96 struct rte_mempool *mbuf_pool;
99 static struct link_bonding_rssconf_unittest_params test_params = {
100 .bond_port_id = INVALID_PORT_ID,
102 [0 ... SLAVE_COUNT - 1] = { .port_id = INVALID_PORT_ID, .is_slave = 0}
108 * Default port configuration with RSS turned off
110 static struct rte_eth_conf default_pmd_conf = {
112 .mq_mode = ETH_MQ_RX_NONE,
113 .max_rx_pkt_len = ETHER_MAX_LEN,
115 .header_split = 0, /**< Header Split disabled */
116 .hw_ip_checksum = 0, /**< IP checksum offload enabled */
117 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
118 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
119 .hw_strip_crc = 1, /**< CRC stripped by hardware */
122 .mq_mode = ETH_MQ_TX_NONE,
127 static struct rte_eth_conf rss_pmd_conf = {
129 .mq_mode = ETH_MQ_RX_RSS,
130 .max_rx_pkt_len = ETHER_MAX_LEN,
132 .header_split = 0, /**< Header Split disabled */
133 .hw_ip_checksum = 0, /**< IP checksum offload enabled */
134 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
135 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
136 .hw_strip_crc = 1, /**< CRC stripped by hardware */
139 .mq_mode = ETH_MQ_TX_NONE,
144 .rss_hf = ETH_RSS_IPV6,
150 #define FOR_EACH(_i, _item, _array, _size) \
151 for (_i = 0, _item = &_array[0]; _i < _size && (_item = &_array[_i]); _i++)
153 /* Macro for iterating over every port that can be used as a slave
155 * _i variable used as an index in test_params->slave_ports
156 * _slave pointer to &test_params->slave_ports[_idx]
158 #define FOR_EACH_PORT(_i, _port) \
159 FOR_EACH(_i, _port, test_params.slave_ports, \
160 RTE_DIM(test_params.slave_ports))
163 configure_ethdev(uint16_t port_id, struct rte_eth_conf *eth_conf,
168 TEST_ASSERT(rte_eth_dev_configure(port_id, RXTX_QUEUE_COUNT,
169 RXTX_QUEUE_COUNT, eth_conf) == 0, "Failed to configure device %u",
172 for (rxq = 0; rxq < RXTX_QUEUE_COUNT; rxq++) {
173 TEST_ASSERT(rte_eth_rx_queue_setup(port_id, rxq, RXTX_RING_SIZE,
174 rte_eth_dev_socket_id(port_id), NULL,
175 test_params.mbuf_pool) == 0, "Failed to setup rx queue.");
178 for (txq = 0; txq < RXTX_QUEUE_COUNT; txq++) {
179 TEST_ASSERT(rte_eth_tx_queue_setup(port_id, txq, RXTX_RING_SIZE,
180 rte_eth_dev_socket_id(port_id), NULL) == 0,
181 "Failed to setup tx queue.");
185 TEST_ASSERT(rte_eth_dev_start(port_id) == 0,
186 "Failed to start device (%d).", port_id);
193 * Remove all slaves from bonding
199 struct slave_conf *port;
201 FOR_EACH_PORT(n, port) {
202 port = &test_params.slave_ports[n];
203 if (port->is_slave) {
204 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_remove(
205 test_params.bond_port_id, port->port_id),
206 "Cannot remove slave %d from bonding", port->port_id);
215 remove_slaves_and_stop_bonded_device(void)
217 TEST_ASSERT_SUCCESS(remove_slaves(), "Removing slaves");
218 rte_eth_dev_stop(test_params.bond_port_id);
223 * Add all slaves to bonding
229 struct slave_conf *port;
231 FOR_EACH_PORT(n, port) {
232 port = &test_params.slave_ports[n];
233 if (!port->is_slave) {
234 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params.bond_port_id,
235 port->port_id), "Cannot attach slave %d to the bonding",
245 * Set all RETA values in port_id to value
248 reta_set(uint16_t port_id, uint8_t value, int reta_size)
250 struct rte_eth_rss_reta_entry64 reta_conf[512/RTE_RETA_GROUP_SIZE];
253 for (i = 0; i < reta_size / RTE_RETA_GROUP_SIZE; i++) {
254 /* select all fields to set */
255 reta_conf[i].mask = ~0LL;
256 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++)
257 reta_conf[i].reta[j] = value;
260 return rte_eth_dev_rss_reta_update(port_id, reta_conf, reta_size);
264 * Check if slaves RETA is synchronized with bonding port. Returns 1 if slave
265 * port is synced with bonding port.
268 reta_check_synced(struct slave_conf *port)
272 for (i = 0; i < test_params.bond_dev_info.reta_size;
275 int index = i / RTE_RETA_GROUP_SIZE;
276 int shift = i % RTE_RETA_GROUP_SIZE;
278 if (port->reta_conf[index].reta[shift] !=
279 test_params.bond_reta_conf[index].reta[shift])
288 * Fetch bonding ports RETA
291 bond_reta_fetch(void) {
294 for (j = 0; j < test_params.bond_dev_info.reta_size / RTE_RETA_GROUP_SIZE;
296 test_params.bond_reta_conf[j].mask = ~0LL;
298 TEST_ASSERT_SUCCESS(rte_eth_dev_rss_reta_query(test_params.bond_port_id,
299 test_params.bond_reta_conf, test_params.bond_dev_info.reta_size),
300 "Cannot take bonding ports RSS configuration");
308 slave_reta_fetch(struct slave_conf *port) {
311 for (j = 0; j < port->dev_info.reta_size / RTE_RETA_GROUP_SIZE; j++)
312 port->reta_conf[j].mask = ~0LL;
314 TEST_ASSERT_SUCCESS(rte_eth_dev_rss_reta_query(port->port_id,
315 port->reta_conf, port->dev_info.reta_size),
316 "Cannot take bonding ports RSS configuration");
321 * Remove and add slave to check if slaves configuration is synced with
322 * the bonding ports values after adding new slave.
325 slave_remove_and_add(void)
327 struct slave_conf *port = &(test_params.slave_ports[0]);
329 /* 1. Remove first slave from bonding */
330 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_remove(test_params.bond_port_id,
331 port->port_id), "Cannot remove slave #d from bonding");
333 /* 2. Change removed (ex-)slave and bonding configuration to different
336 reta_set(test_params.bond_port_id, 1, test_params.bond_dev_info.reta_size);
339 reta_set(port->port_id, 2, port->dev_info.reta_size);
340 slave_reta_fetch(port);
342 TEST_ASSERT(reta_check_synced(port) == 0,
343 "Removed slave didn't should be synchronized with bonding port");
345 /* 3. Add (ex-)slave and check if configuration changed*/
346 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params.bond_port_id,
347 port->port_id), "Cannot add slave");
350 slave_reta_fetch(port);
352 return reta_check_synced(port);
356 * Test configuration propagation over slaves.
363 struct slave_conf *port;
364 uint8_t bond_rss_key[40];
365 struct rte_eth_rss_conf bond_rss_conf;
369 uint64_t default_rss_hf = 0;
371 rte_eth_dev_info_get(test_params.bond_port_id, &test_params.bond_dev_info);
374 * Test hash function propagation
376 for (i = 0; i < sizeof(test_params.bond_dev_info.flow_type_rss_offloads)*8;
379 rss_hf = test_params.bond_dev_info.flow_type_rss_offloads & (1<<i);
381 bond_rss_conf.rss_key = NULL;
382 bond_rss_conf.rss_hf = rss_hf;
384 retval = rte_eth_dev_rss_hash_update(test_params.bond_port_id,
386 TEST_ASSERT_SUCCESS(retval, "Cannot set slaves hash function");
388 FOR_EACH_PORT(n, port) {
389 port = &test_params.slave_ports[n];
391 retval = rte_eth_dev_rss_hash_conf_get(port->port_id,
393 TEST_ASSERT_SUCCESS(retval,
394 "Cannot take slaves RSS configuration");
396 TEST_ASSERT(port->rss_conf.rss_hf == rss_hf,
397 "Hash function not propagated for slave %d",
401 default_rss_hf = rss_hf;
407 * Test key propagation
409 for (i = 1; i < 10; i++) {
411 /* Set all keys to zero */
412 FOR_EACH_PORT(n, port) {
413 port = &test_params.slave_ports[n];
414 memset(port->rss_conf.rss_key, 0, 40);
415 retval = rte_eth_dev_rss_hash_update(port->port_id,
417 TEST_ASSERT_SUCCESS(retval, "Cannot set slaves RSS keys");
420 memset(bond_rss_key, i, sizeof(bond_rss_key));
421 bond_rss_conf.rss_hf = default_rss_hf,
422 bond_rss_conf.rss_key = bond_rss_key;
423 bond_rss_conf.rss_key_len = 40;
425 retval = rte_eth_dev_rss_hash_update(test_params.bond_port_id,
427 TEST_ASSERT_SUCCESS(retval, "Cannot set bonded port RSS keys");
429 FOR_EACH_PORT(n, port) {
430 port = &test_params.slave_ports[n];
432 retval = rte_eth_dev_rss_hash_conf_get(port->port_id,
435 TEST_ASSERT_SUCCESS(retval,
436 "Cannot take slaves RSS configuration");
439 retval = memcmp(port->rss_conf.rss_key, bond_rss_key,
440 sizeof(bond_rss_key));
441 TEST_ASSERT(retval == 0, "Key value not propagated for slave %d",
447 * Test RETA propagation
449 for (i = 0; i < RXTX_QUEUE_COUNT; i++) {
451 /* Set all keys to zero */
452 FOR_EACH_PORT(n, port) {
453 port = &test_params.slave_ports[n];
454 retval = reta_set(port->port_id, (i + 1) % RXTX_QUEUE_COUNT,
455 port->dev_info.reta_size);
456 TEST_ASSERT_SUCCESS(retval, "Cannot set slaves RETA");
459 TEST_ASSERT_SUCCESS(reta_set(test_params.bond_port_id,
460 i % RXTX_QUEUE_COUNT, test_params.bond_dev_info.reta_size),
461 "Cannot set bonded port RETA");
465 FOR_EACH_PORT(n, port) {
466 port = &test_params.slave_ports[n];
468 slave_reta_fetch(port);
469 TEST_ASSERT(reta_check_synced(port) == 1, "RETAs inconsistent");
477 * Test propagation logic, when RX_RSS mq_mode is turned on for bonding port
483 * Configure bonding port in RSS mq mode
485 TEST_ASSERT_SUCCESS(configure_ethdev(test_params.bond_port_id,
486 &rss_pmd_conf, 0), "Failed to configure bonding device\n");
488 rte_eth_dev_info_get(test_params.bond_port_id, &test_params.bond_dev_info);
490 TEST_ASSERT_SUCCESS(bond_slaves(), "Bonding slaves failed");
492 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params.bond_port_id),
493 "Failed to start bonding port (%d).", test_params.bond_port_id);
495 TEST_ASSERT_SUCCESS(test_propagate(), "Propagation test failed");
497 TEST_ASSERT(slave_remove_and_add() == 1, "New slave should be synced");
499 remove_slaves_and_stop_bonded_device();
505 * Test propagation logic, when RX_RSS mq_mode is turned off for bonding port
510 TEST_ASSERT_SUCCESS(configure_ethdev(test_params.bond_port_id,
511 &default_pmd_conf, 0), "Failed to configure bonding device\n");
513 rte_eth_dev_info_get(test_params.bond_port_id, &test_params.bond_dev_info);
515 TEST_ASSERT_SUCCESS(bond_slaves(), "Bonding slaves failed");
517 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params.bond_port_id),
518 "Failed to start bonding port (%d).", test_params.bond_port_id);
520 TEST_ASSERT_SUCCESS(test_propagate(), "Propagation test failed");
522 TEST_ASSERT(slave_remove_and_add() == 0, "New slave shouldn't be synced");
524 remove_slaves_and_stop_bonded_device();
536 struct slave_conf *port;
538 if (test_params.mbuf_pool == NULL) {
540 test_params.mbuf_pool = rte_pktmbuf_pool_create(
541 "RSS_MBUF_POOL", NUM_MBUFS * SLAVE_COUNT,
542 MBUF_CACHE_SIZE, 0, MBUF_SIZE, rte_socket_id());
544 TEST_ASSERT(test_params.mbuf_pool != NULL,
545 "rte_pktmbuf_pool_create failed\n");
548 /* Create / initialize ring eth devs. */
549 FOR_EACH_PORT(n, port) {
550 port = &test_params.slave_ports[n];
552 port_id = rte_eth_dev_count();
553 snprintf(name, sizeof(name), SLAVE_DEV_NAME_FMT, port_id);
555 retval = rte_vdev_init(name, "size=64,copy=0");
556 TEST_ASSERT_SUCCESS(retval, "Failed to create null device '%s'\n",
559 port->port_id = port_id;
561 port->rss_conf.rss_key = port->rss_key;
562 port->rss_conf.rss_key_len = 40;
564 retval = configure_ethdev(port->port_id, &default_pmd_conf, 0);
565 TEST_ASSERT_SUCCESS(retval, "Failed to configure virtual ethdev %s\n",
568 rte_eth_dev_info_get(port->port_id, &port->dev_info);
571 if (test_params.bond_port_id == INVALID_PORT_ID) {
572 retval = rte_eth_bond_create(BONDED_DEV_NAME, 0, rte_socket_id());
574 TEST_ASSERT(retval >= 0, "Failed to create bonded ethdev %s",
577 test_params.bond_port_id = retval;
579 TEST_ASSERT_SUCCESS(configure_ethdev(test_params.bond_port_id,
580 &default_pmd_conf, 0), "Failed to configure bonding device\n");
582 rte_eth_dev_info_get(test_params.bond_port_id,
583 &test_params.bond_dev_info);
590 testsuite_teardown(void)
592 struct slave_conf *port;
596 * Any cleanup/reset state is done when particular test is
599 rte_eth_dev_stop(test_params.bond_port_id);
601 FOR_EACH_PORT(i, port)
602 rte_eth_dev_stop(port->port_id);
606 check_environment(void)
612 test_rssconf_executor(int (*test_func)(void))
616 /* Check if environment is clean. Fail to launch a test if there was
617 * a critical error before that prevented to reset environment. */
618 TEST_ASSERT_SUCCESS(check_environment(),
619 "Refusing to launch test in dirty environment.");
621 RTE_VERIFY(test_func != NULL);
622 test_result = (*test_func)();
624 /* If test succeed check if environment wast left in good condition. */
625 if (test_result == TEST_SUCCESS)
626 test_result = check_environment();
628 /* Reset environment in case test failed to do that. */
629 if (test_result != TEST_SUCCESS) {
630 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
631 "Failed to stop bonded device");
638 test_setup_wrapper(void)
640 return test_rssconf_executor(&test_setup);
644 test_rss_wrapper(void)
646 return test_rssconf_executor(&test_rss);
650 test_rss_lazy_wrapper(void)
652 return test_rssconf_executor(&test_rss_lazy);
655 static struct unit_test_suite link_bonding_rssconf_test_suite = {
656 .suite_name = "RSS Dynamic Configuration for Bonding Unit Test Suite",
657 .teardown = testsuite_teardown,
659 TEST_CASE_NAMED("test_setup", test_setup_wrapper),
660 TEST_CASE_NAMED("test_rss", test_rss_wrapper),
661 TEST_CASE_NAMED("test_rss_lazy", test_rss_lazy_wrapper),
668 test_link_bonding_rssconf(void)
670 return unit_test_suite_runner(&link_bonding_rssconf_test_suite);
673 REGISTER_TEST_COMMAND(link_bonding_rssconf_autotest, test_link_bonding_rssconf);