1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <rte_cycles.h>
13 #include <sys/queue.h>
15 #include <rte_byteorder.h>
16 #include <rte_common.h>
17 #include <rte_debug.h>
18 #include <rte_ethdev.h>
20 #include <rte_lcore.h>
21 #include <rte_memory.h>
23 #include <rte_string_fns.h>
25 #include <rte_eth_ring.h>
26 #include <rte_errno.h>
27 #include <rte_eth_bond.h>
28 #include <rte_eth_bond_8023ad.h>
30 #include "packet_burst_generator.h"
34 #define SLAVE_COUNT (4)
36 #define RX_RING_SIZE 1024
37 #define TX_RING_SIZE 1024
39 #define MBUF_CACHE_SIZE (250)
40 #define BURST_SIZE (32)
42 #define TEST_RX_DESC_MAX (2048)
43 #define TEST_TX_DESC_MAX (2048)
44 #define MAX_PKT_BURST (32)
45 #define DEF_PKT_BURST (16)
47 #define BONDED_DEV_NAME ("net_bonding_m4_bond_dev")
49 #define SLAVE_DEV_NAME_FMT ("net_virt_%d")
50 #define SLAVE_RX_QUEUE_FMT ("net_virt_%d_rx")
51 #define SLAVE_TX_QUEUE_FMT ("net_virt_%d_tx")
53 #define INVALID_SOCKET_ID (-1)
54 #define INVALID_PORT_ID (0xFF)
55 #define INVALID_BONDING_MODE (-1)
57 static const struct ether_addr slave_mac_default
= {
58 { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 }
61 static const struct ether_addr parnter_mac_default
= {
62 { 0x22, 0xBB, 0xFF, 0xBB, 0x00, 0x00 }
65 static const struct ether_addr parnter_system
= {
66 { 0x33, 0xFF, 0xBB, 0xFF, 0x00, 0x00 }
69 static const struct ether_addr slow_protocol_mac_addr
= {
70 { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02 }
74 struct rte_ring
*rx_queue
;
75 struct rte_ring
*tx_queue
;
79 uint8_t lacp_parnter_state
;
82 struct ether_vlan_hdr
{
83 struct ether_hdr pkt_eth_hdr
;
84 struct vlan_hdr vlan_hdr
;
87 struct link_bonding_unittest_params
{
88 uint8_t bonded_port_id
;
89 struct slave_conf slave_ports
[SLAVE_COUNT
];
91 struct rte_mempool
*mbuf_pool
;
94 #define TEST_DEFAULT_SLAVE_COUNT RTE_DIM(test_params.slave_ports)
95 #define TEST_RX_SLAVE_COUT TEST_DEFAULT_SLAVE_COUNT
96 #define TEST_TX_SLAVE_COUNT TEST_DEFAULT_SLAVE_COUNT
97 #define TEST_MARKER_SLAVE_COUT TEST_DEFAULT_SLAVE_COUNT
98 #define TEST_EXPIRED_SLAVE_COUNT TEST_DEFAULT_SLAVE_COUNT
99 #define TEST_PROMISC_SLAVE_COUNT TEST_DEFAULT_SLAVE_COUNT
101 static struct link_bonding_unittest_params test_params
= {
102 .bonded_port_id
= INVALID_PORT_ID
,
103 .slave_ports
= { [0 ... SLAVE_COUNT
- 1] = { .port_id
= INVALID_PORT_ID
} },
108 static struct rte_eth_conf default_pmd_conf
= {
110 .mq_mode
= ETH_MQ_RX_NONE
,
111 .max_rx_pkt_len
= ETHER_MAX_LEN
,
113 .offloads
= DEV_RX_OFFLOAD_CRC_STRIP
,
116 .mq_mode
= ETH_MQ_TX_NONE
,
121 static uint8_t lacpdu_rx_count
[RTE_MAX_ETHPORTS
] = {0, };
123 #define FOR_EACH(_i, _item, _array, _size) \
124 for (_i = 0, _item = &_array[0]; _i < _size && (_item = &_array[_i]); _i++)
126 /* Macro for iterating over every port that can be used as a slave
128 * _i variable used as an index in test_params->slave_ports
129 * _slave pointer to &test_params->slave_ports[_idx]
131 #define FOR_EACH_PORT(_i, _port) \
132 FOR_EACH(_i, _port, test_params.slave_ports, \
133 RTE_DIM(test_params.slave_ports))
135 /* Macro for iterating over every port that can be used as a slave
136 * in this test and satisfy given condition.
138 * _i variable used as an index in test_params->slave_ports
139 * _slave pointer to &test_params->slave_ports[_idx]
140 * _condition condition that need to be checked
142 #define FOR_EACH_PORT_IF(_i, _port, _condition) FOR_EACH_PORT((_i), (_port)) \
145 /* Macro for iterating over every port that is currently a slave of a bonded
147 * _i variable used as an index in test_params->slave_ports
148 * _slave pointer to &test_params->slave_ports[_idx]
150 #define FOR_EACH_SLAVE(_i, _slave) \
151 FOR_EACH_PORT_IF(_i, _slave, (_slave)->bonded != 0)
154 * Returns packets from slaves TX queue.
157 * size size of buffer
158 * return number of packets or negative error number
161 slave_get_pkts(struct slave_conf
*slave
, struct rte_mbuf
**buf
, uint16_t size
)
163 return rte_ring_dequeue_burst(slave
->tx_queue
, (void **)buf
,
168 * Injects given packets into slaves RX queue.
171 * size number of packets to be injected
172 * return number of queued packets or negative error number
175 slave_put_pkts(struct slave_conf
*slave
, struct rte_mbuf
**buf
, uint16_t size
)
177 return rte_ring_enqueue_burst(slave
->rx_queue
, (void **)buf
,
182 bond_rx(struct rte_mbuf
**buf
, uint16_t size
)
184 return rte_eth_rx_burst(test_params
.bonded_port_id
, 0, buf
, size
);
188 bond_tx(struct rte_mbuf
**buf
, uint16_t size
)
190 return rte_eth_tx_burst(test_params
.bonded_port_id
, 0, buf
, size
);
194 free_pkts(struct rte_mbuf
**pkts
, uint16_t count
)
198 for (i
= 0; i
< count
; i
++) {
200 rte_pktmbuf_free(pkts
[i
]);
205 configure_ethdev(uint16_t port_id
, uint8_t start
)
207 TEST_ASSERT(rte_eth_dev_configure(port_id
, 1, 1, &default_pmd_conf
) == 0,
208 "Failed to configure device %u", port_id
);
210 TEST_ASSERT(rte_eth_rx_queue_setup(port_id
, 0, RX_RING_SIZE
,
211 rte_eth_dev_socket_id(port_id
), NULL
, test_params
.mbuf_pool
) == 0,
212 "Failed to setup rx queue.");
214 TEST_ASSERT(rte_eth_tx_queue_setup(port_id
, 0, TX_RING_SIZE
,
215 rte_eth_dev_socket_id(port_id
), NULL
) == 0,
216 "Failed to setup tx queue.");
219 TEST_ASSERT(rte_eth_dev_start(port_id
) == 0,
220 "Failed to start device (%d).", port_id
);
226 add_slave(struct slave_conf
*slave
, uint8_t start
)
228 struct ether_addr addr
, addr_check
;
230 /* Some sanity check */
231 RTE_VERIFY(test_params
.slave_ports
<= slave
&&
232 slave
- test_params
.slave_ports
< (int)RTE_DIM(test_params
.slave_ports
));
233 RTE_VERIFY(slave
->bonded
== 0);
234 RTE_VERIFY(slave
->port_id
!= INVALID_PORT_ID
);
236 ether_addr_copy(&slave_mac_default
, &addr
);
237 addr
.addr_bytes
[ETHER_ADDR_LEN
- 1] = slave
->port_id
;
239 rte_eth_dev_mac_addr_remove(slave
->port_id
, &addr
);
241 TEST_ASSERT_SUCCESS(rte_eth_dev_mac_addr_add(slave
->port_id
, &addr
, 0),
242 "Failed to set slave MAC address");
244 TEST_ASSERT_SUCCESS(rte_eth_bond_slave_add(test_params
.bonded_port_id
,
246 "Failed to add slave (idx=%u, id=%u) to bonding (id=%u)",
247 (uint8_t)(slave
- test_params
.slave_ports
), slave
->port_id
,
248 test_params
.bonded_port_id
);
252 TEST_ASSERT_SUCCESS(rte_eth_dev_start(slave
->port_id
),
253 "Failed to start slave %u", slave
->port_id
);
256 rte_eth_macaddr_get(slave
->port_id
, &addr_check
);
257 TEST_ASSERT_EQUAL(is_same_ether_addr(&addr
, &addr_check
), 1,
258 "Slave MAC address is not as expected");
260 RTE_VERIFY(slave
->lacp_parnter_state
== 0);
265 remove_slave(struct slave_conf
*slave
)
267 ptrdiff_t slave_idx
= slave
- test_params
.slave_ports
;
269 RTE_VERIFY(test_params
.slave_ports
<= slave
&&
270 slave_idx
< (ptrdiff_t)RTE_DIM(test_params
.slave_ports
));
272 RTE_VERIFY(slave
->bonded
== 1);
273 RTE_VERIFY(slave
->port_id
!= INVALID_PORT_ID
);
275 TEST_ASSERT_EQUAL(rte_ring_count(slave
->rx_queue
), 0,
276 "Slave %u tx queue not empty while removing from bonding.",
279 TEST_ASSERT_EQUAL(rte_ring_count(slave
->rx_queue
), 0,
280 "Slave %u tx queue not empty while removing from bonding.",
283 TEST_ASSERT_EQUAL(rte_eth_bond_slave_remove(test_params
.bonded_port_id
,
285 "Failed to remove slave (idx=%u, id=%u) from bonding (id=%u)",
286 (uint8_t)slave_idx
, slave
->port_id
,
287 test_params
.bonded_port_id
);
290 slave
->lacp_parnter_state
= 0;
295 lacp_recv_cb(uint16_t slave_id
, struct rte_mbuf
*lacp_pkt
)
297 struct ether_hdr
*hdr
;
298 struct slow_protocol_frame
*slow_hdr
;
300 RTE_VERIFY(lacp_pkt
!= NULL
);
302 hdr
= rte_pktmbuf_mtod(lacp_pkt
, struct ether_hdr
*);
303 RTE_VERIFY(hdr
->ether_type
== rte_cpu_to_be_16(ETHER_TYPE_SLOW
));
305 slow_hdr
= rte_pktmbuf_mtod(lacp_pkt
, struct slow_protocol_frame
*);
306 RTE_VERIFY(slow_hdr
->slow_protocol
.subtype
== SLOW_SUBTYPE_LACP
);
308 lacpdu_rx_count
[slave_id
]++;
309 rte_pktmbuf_free(lacp_pkt
);
313 initialize_bonded_device_with_slaves(uint16_t slave_count
, uint8_t external_sm
)
317 RTE_VERIFY(test_params
.bonded_port_id
!= INVALID_PORT_ID
);
319 for (i
= 0; i
< slave_count
; i
++) {
320 TEST_ASSERT_SUCCESS(add_slave(&test_params
.slave_ports
[i
], 1),
321 "Failed to add port %u to bonded device.\n",
322 test_params
.slave_ports
[i
].port_id
);
325 /* Reset mode 4 configuration */
326 rte_eth_bond_8023ad_setup(test_params
.bonded_port_id
, NULL
);
327 rte_eth_promiscuous_disable(test_params
.bonded_port_id
);
330 struct rte_eth_bond_8023ad_conf conf
;
332 rte_eth_bond_8023ad_conf_get(test_params
.bonded_port_id
, &conf
);
333 conf
.slowrx_cb
= lacp_recv_cb
;
334 rte_eth_bond_8023ad_setup(test_params
.bonded_port_id
, &conf
);
338 TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params
.bonded_port_id
),
339 "Failed to start bonded device");
345 remove_slaves_and_stop_bonded_device(void)
347 struct slave_conf
*slave
;
349 uint16_t slaves
[RTE_MAX_ETHPORTS
];
352 rte_eth_dev_stop(test_params
.bonded_port_id
);
354 FOR_EACH_SLAVE(i
, slave
)
357 retval
= rte_eth_bond_slaves_get(test_params
.bonded_port_id
, slaves
,
360 TEST_ASSERT_EQUAL(retval
, 0,
361 "Expected bonded device %u have 0 slaves but returned %d.",
362 test_params
.bonded_port_id
, retval
);
364 FOR_EACH_PORT(i
, slave
) {
365 rte_eth_dev_stop(slave
->port_id
);
367 TEST_ASSERT(slave
->bonded
== 0,
368 "Port id=%u is still marked as enslaved.", slave
->port_id
);
377 int retval
, nb_mbuf_per_pool
;
378 char name
[RTE_ETH_NAME_MAX_LEN
];
379 struct slave_conf
*port
;
380 const uint8_t socket_id
= rte_socket_id();
383 if (test_params
.mbuf_pool
== NULL
) {
384 nb_mbuf_per_pool
= TEST_RX_DESC_MAX
+ DEF_PKT_BURST
+
385 TEST_TX_DESC_MAX
+ MAX_PKT_BURST
;
386 test_params
.mbuf_pool
= rte_pktmbuf_pool_create("TEST_MODE4",
387 nb_mbuf_per_pool
, MBUF_CACHE_SIZE
, 0,
388 RTE_MBUF_DEFAULT_BUF_SIZE
, socket_id
);
390 TEST_ASSERT(test_params
.mbuf_pool
!= NULL
,
391 "rte_mempool_create failed\n");
394 /* Create / initialize ring eth devs. */
395 FOR_EACH_PORT(i
, port
) {
396 port
= &test_params
.slave_ports
[i
];
398 if (port
->rx_queue
== NULL
) {
399 retval
= snprintf(name
, RTE_DIM(name
), SLAVE_RX_QUEUE_FMT
, i
);
400 TEST_ASSERT(retval
<= (int)RTE_DIM(name
) - 1, "Name too long");
401 port
->rx_queue
= rte_ring_create(name
, RX_RING_SIZE
, socket_id
, 0);
402 TEST_ASSERT(port
->rx_queue
!= NULL
,
403 "Failed to allocate rx ring '%s': %s", name
,
404 rte_strerror(rte_errno
));
407 if (port
->tx_queue
== NULL
) {
408 retval
= snprintf(name
, RTE_DIM(name
), SLAVE_TX_QUEUE_FMT
, i
);
409 TEST_ASSERT(retval
<= (int)RTE_DIM(name
) - 1, "Name too long");
410 port
->tx_queue
= rte_ring_create(name
, TX_RING_SIZE
, socket_id
, 0);
411 TEST_ASSERT_NOT_NULL(port
->tx_queue
,
412 "Failed to allocate tx ring '%s': %s", name
,
413 rte_strerror(rte_errno
));
416 if (port
->port_id
== INVALID_PORT_ID
) {
417 retval
= snprintf(name
, RTE_DIM(name
), SLAVE_DEV_NAME_FMT
, i
);
418 TEST_ASSERT(retval
< (int)RTE_DIM(name
) - 1, "Name too long");
419 retval
= rte_eth_from_rings(name
, &port
->rx_queue
, 1,
420 &port
->tx_queue
, 1, socket_id
);
421 TEST_ASSERT(retval
>= 0,
422 "Failed to create ring ethdev '%s'\n", name
);
424 port
->port_id
= rte_eth_dev_count_avail() - 1;
427 retval
= configure_ethdev(port
->port_id
, 1);
428 TEST_ASSERT_SUCCESS(retval
, "Failed to configure virtual ethdev %s\n",
432 if (test_params
.bonded_port_id
== INVALID_PORT_ID
) {
433 retval
= rte_eth_bond_create(BONDED_DEV_NAME
, BONDING_MODE_8023AD
,
436 TEST_ASSERT(retval
>= 0, "Failed to create bonded ethdev %s",
439 test_params
.bonded_port_id
= retval
;
440 TEST_ASSERT_SUCCESS(configure_ethdev(test_params
.bonded_port_id
, 0),
441 "Failed to configure bonded ethdev %s", BONDED_DEV_NAME
);
442 } else if (rte_eth_bond_mode_get(test_params
.bonded_port_id
) !=
443 BONDING_MODE_8023AD
) {
444 TEST_ASSERT(rte_eth_bond_mode_set(test_params
.bonded_port_id
,
445 BONDING_MODE_8023AD
) == 0,
446 "Failed to set ethdev %d to mode %d",
447 test_params
.bonded_port_id
, BONDING_MODE_8023AD
);
454 testsuite_teardown(void)
456 struct slave_conf
*port
;
460 * Any cleanup/reset state is done when particular test is
463 rte_eth_dev_stop(test_params
.bonded_port_id
);
465 FOR_EACH_PORT(i
, port
)
466 rte_eth_dev_stop(port
->port_id
);
470 * Check if given LACP packet. If it is, make make replay packet to force
472 * return 0 when pkt is LACP frame, 1 if it is not slow frame, 2 if it is slow
476 make_lacp_reply(struct slave_conf
*slave
, struct rte_mbuf
*pkt
)
478 struct ether_hdr
*hdr
;
479 struct slow_protocol_frame
*slow_hdr
;
483 hdr
= rte_pktmbuf_mtod(pkt
, struct ether_hdr
*);
484 if (hdr
->ether_type
!= rte_cpu_to_be_16(ETHER_TYPE_SLOW
))
487 slow_hdr
= rte_pktmbuf_mtod(pkt
, struct slow_protocol_frame
*);
488 /* ignore packets of other types */
489 if (slow_hdr
->slow_protocol
.subtype
!= SLOW_SUBTYPE_LACP
)
492 slow_hdr
= rte_pktmbuf_mtod(pkt
, struct slow_protocol_frame
*);
494 /* Change source address to partner address */
495 ether_addr_copy(&parnter_mac_default
, &slow_hdr
->eth_hdr
.s_addr
);
496 slow_hdr
->eth_hdr
.s_addr
.addr_bytes
[ETHER_ADDR_LEN
- 1] = slave
->port_id
;
498 lacp
= (struct lacpdu
*) &slow_hdr
->slow_protocol
;
499 /* Save last received state */
500 slave
->lacp_parnter_state
= lacp
->actor
.state
;
501 /* Change it into LACP replay by matching parameters. */
502 memcpy(&lacp
->partner
.port_params
, &lacp
->actor
.port_params
,
503 sizeof(struct port_params
));
505 lacp
->partner
.state
= lacp
->actor
.state
;
507 ether_addr_copy(&parnter_system
, &lacp
->actor
.port_params
.system
);
508 lacp
->actor
.state
= STATE_LACP_ACTIVE
|
509 STATE_SYNCHRONIZATION
|
518 * Reads packets from given slave, search for LACP packet and reply them.
520 * Receives burst of packets from slave. Looks for LACP packet. Drops
521 * all other packets. Prepares response LACP and sends it back.
523 * return number of LACP received and replied, -1 on error.
526 bond_handshake_reply(struct slave_conf
*slave
)
529 struct rte_mbuf
*rx_buf
[MAX_PKT_BURST
];
530 struct rte_mbuf
*lacp_tx_buf
[MAX_PKT_BURST
];
531 uint16_t lacp_tx_buf_cnt
= 0, i
;
533 retval
= slave_get_pkts(slave
, rx_buf
, RTE_DIM(rx_buf
));
534 TEST_ASSERT(retval
>= 0, "Getting slave %u packets failed.",
537 for (i
= 0; i
< (uint16_t)retval
; i
++) {
538 if (make_lacp_reply(slave
, rx_buf
[i
]) == 0) {
539 /* reply with actor's LACP */
540 lacp_tx_buf
[lacp_tx_buf_cnt
++] = rx_buf
[i
];
542 rte_pktmbuf_free(rx_buf
[i
]);
545 if (lacp_tx_buf_cnt
== 0)
548 retval
= slave_put_pkts(slave
, lacp_tx_buf
, lacp_tx_buf_cnt
);
549 if (retval
<= lacp_tx_buf_cnt
) {
550 /* retval might be negative */
551 for (i
= RTE_MAX(0, retval
); retval
< lacp_tx_buf_cnt
; retval
++)
552 rte_pktmbuf_free(lacp_tx_buf
[i
]);
555 TEST_ASSERT_EQUAL(retval
, lacp_tx_buf_cnt
,
556 "Failed to equeue lacp packets into slave %u tx queue.",
559 return lacp_tx_buf_cnt
;
563 * Function check if given slave tx queue contains packets that make mode 4
564 * handshake complete. It will drain slave queue.
565 * return 0 if handshake not completed, 1 if handshake was complete,
568 bond_handshake_done(struct slave_conf
*slave
)
570 const uint8_t expected_state
= STATE_LACP_ACTIVE
| STATE_SYNCHRONIZATION
|
571 STATE_AGGREGATION
| STATE_COLLECTING
| STATE_DISTRIBUTING
;
573 return slave
->lacp_parnter_state
== expected_state
;
577 bond_get_update_timeout_ms(void)
579 struct rte_eth_bond_8023ad_conf conf
;
581 rte_eth_bond_8023ad_conf_get(test_params
.bonded_port_id
, &conf
);
582 return conf
.update_timeout_ms
;
586 * Exchanges LACP packets with partner to achieve dynamic port configuration.
587 * return TEST_SUCCESS if initial handshake succeed, TEST_FAILED otherwise.
592 struct slave_conf
*slave
;
593 struct rte_mbuf
*buf
[MAX_PKT_BURST
];
595 uint8_t all_slaves_done
, i
, j
;
596 uint8_t status
[RTE_DIM(test_params
.slave_ports
)] = { 0 };
597 const unsigned delay
= bond_get_update_timeout_ms();
599 /* Exchange LACP frames */
601 for (i
= 0; i
< 30 && all_slaves_done
== 0; ++i
) {
605 FOR_EACH_SLAVE(j
, slave
) {
606 /* If response already send, skip slave */
610 if (bond_handshake_reply(slave
) < 0) {
615 status
[j
] = bond_handshake_done(slave
);
620 nb_pkts
= bond_tx(NULL
, 0);
621 TEST_ASSERT_EQUAL(nb_pkts
, 0, "Packets transmitted unexpectedly");
623 nb_pkts
= bond_rx(buf
, RTE_DIM(buf
));
624 free_pkts(buf
, nb_pkts
);
625 TEST_ASSERT_EQUAL(nb_pkts
, 0, "Packets received unexpectedly");
627 /* If response didn't send - report failure */
628 TEST_ASSERT_EQUAL(all_slaves_done
, 1, "Bond handshake failed\n");
630 /* If flags doesn't match - report failure */
631 return all_slaves_done
== 1 ? TEST_SUCCESS
: TEST_FAILED
;
634 #define TEST_LACP_SLAVE_COUT RTE_DIM(test_params.slave_ports)
636 test_mode4_lacp(void)
640 retval
= initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT
, 0);
641 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bonded device");
643 /* Test LACP handshake function */
644 retval
= bond_handshake();
645 TEST_ASSERT_SUCCESS(retval
, "Initial handshake failed");
647 retval
= remove_slaves_and_stop_bonded_device();
648 TEST_ASSERT_SUCCESS(retval
, "Test cleanup failed.");
653 test_mode4_agg_mode_selection(void)
656 /* Test and verify for Stable mode */
657 retval
= initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT
, 0);
658 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bonded device");
661 retval
= rte_eth_bond_8023ad_agg_selection_set(
662 test_params
.bonded_port_id
, AGG_STABLE
);
663 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bond aggregation mode");
664 retval
= bond_handshake();
665 TEST_ASSERT_SUCCESS(retval
, "Initial handshake failed");
668 retval
= rte_eth_bond_8023ad_agg_selection_get(
669 test_params
.bonded_port_id
);
670 TEST_ASSERT_EQUAL(retval
, AGG_STABLE
,
671 "Wrong agg mode received from bonding device");
673 retval
= remove_slaves_and_stop_bonded_device();
674 TEST_ASSERT_SUCCESS(retval
, "Test cleanup failed.");
677 /* test and verify for Bandwidth mode */
678 retval
= initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT
, 0);
679 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bonded device");
682 retval
= rte_eth_bond_8023ad_agg_selection_set(
683 test_params
.bonded_port_id
,
685 TEST_ASSERT_SUCCESS(retval
,
686 "Failed to initialize bond aggregation mode");
687 retval
= bond_handshake();
688 TEST_ASSERT_SUCCESS(retval
, "Initial handshake failed");
690 retval
= rte_eth_bond_8023ad_agg_selection_get(
691 test_params
.bonded_port_id
);
692 TEST_ASSERT_EQUAL(retval
, AGG_BANDWIDTH
,
693 "Wrong agg mode received from bonding device");
695 retval
= remove_slaves_and_stop_bonded_device();
696 TEST_ASSERT_SUCCESS(retval
, "Test cleanup failed.");
698 /* test and verify selection for count mode */
699 retval
= initialize_bonded_device_with_slaves(TEST_LACP_SLAVE_COUT
, 0);
700 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bonded device");
703 retval
= rte_eth_bond_8023ad_agg_selection_set(
704 test_params
.bonded_port_id
, AGG_COUNT
);
705 TEST_ASSERT_SUCCESS(retval
,
706 "Failed to initialize bond aggregation mode");
707 retval
= bond_handshake();
708 TEST_ASSERT_SUCCESS(retval
, "Initial handshake failed");
710 retval
= rte_eth_bond_8023ad_agg_selection_get(
711 test_params
.bonded_port_id
);
712 TEST_ASSERT_EQUAL(retval
, AGG_COUNT
,
713 "Wrong agg mode received from bonding device");
715 retval
= remove_slaves_and_stop_bonded_device();
716 TEST_ASSERT_SUCCESS(retval
, "Test cleanup failed.");
722 generate_packets(struct ether_addr
*src_mac
,
723 struct ether_addr
*dst_mac
, uint16_t count
, struct rte_mbuf
**buf
)
725 uint16_t pktlen
= PACKET_BURST_GEN_PKT_LEN
;
726 uint8_t vlan_enable
= 0;
727 uint16_t vlan_id
= 0;
728 uint8_t ip4_type
= 1; /* 0 - ipv6 */
730 uint16_t src_port
= 10, dst_port
= 20;
732 uint32_t ip_src
[4] = { [0 ... 2] = 0xDEADBEEF, [3] = IPv4(192, 168, 0, 1) };
733 uint32_t ip_dst
[4] = { [0 ... 2] = 0xFEEDFACE, [3] = IPv4(192, 168, 0, 2) };
735 struct ether_hdr pkt_eth_hdr
;
736 struct udp_hdr pkt_udp_hdr
;
744 initialize_eth_header(&pkt_eth_hdr
, src_mac
, dst_mac
, ip4_type
,
745 vlan_enable
, vlan_id
);
748 initialize_ipv4_header(&pkt_ip_hdr
.v4
, ip_src
[3], ip_dst
[3], pktlen
);
750 initialize_ipv6_header(&pkt_ip_hdr
.v6
, (uint8_t *)ip_src
,
751 (uint8_t *)&ip_dst
, pktlen
);
753 initialize_udp_header(&pkt_udp_hdr
, src_port
, dst_port
, 16);
755 retval
= generate_packet_burst(test_params
.mbuf_pool
, buf
,
756 &pkt_eth_hdr
, vlan_enable
, &pkt_ip_hdr
, 1, &pkt_udp_hdr
,
759 if (retval
> 0 && retval
!= count
)
760 free_pkts(&buf
[count
- retval
], retval
);
762 TEST_ASSERT_EQUAL(retval
, count
, "Failed to generate %u packets",
769 generate_and_put_packets(struct slave_conf
*slave
, struct ether_addr
*src_mac
,
770 struct ether_addr
*dst_mac
, uint16_t count
)
772 struct rte_mbuf
*pkts
[MAX_PKT_BURST
];
775 retval
= generate_packets(src_mac
, dst_mac
, count
, pkts
);
776 if (retval
!= (int)count
)
779 retval
= slave_put_pkts(slave
, pkts
, count
);
780 if (retval
> 0 && retval
!= count
)
781 free_pkts(&pkts
[retval
], count
- retval
);
783 TEST_ASSERT_EQUAL(retval
, count
,
784 "Failed to enqueue packets into slave %u RX queue", slave
->port_id
);
792 struct slave_conf
*slave
;
795 uint16_t expected_pkts_cnt
;
796 struct rte_mbuf
*pkts
[MAX_PKT_BURST
];
800 struct ether_hdr
*hdr
;
802 struct ether_addr src_mac
= { { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
803 struct ether_addr dst_mac
;
804 struct ether_addr bonded_mac
;
806 retval
= initialize_bonded_device_with_slaves(TEST_PROMISC_SLAVE_COUNT
,
808 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bonded device");
810 retval
= bond_handshake();
811 TEST_ASSERT_SUCCESS(retval
, "Initial handshake failed");
813 rte_eth_macaddr_get(test_params
.bonded_port_id
, &bonded_mac
);
814 ether_addr_copy(&bonded_mac
, &dst_mac
);
816 /* Assert that dst address is not bonding address. Do not set the
817 * least significant bit of the zero byte as this would create a
820 dst_mac
.addr_bytes
[0] += 2;
822 /* First try with promiscuous mode enabled.
823 * Add 2 packets to each slave. First with bonding MAC address, second with
824 * different. Check if we received all of them. */
825 rte_eth_promiscuous_enable(test_params
.bonded_port_id
);
827 expected_pkts_cnt
= 0;
828 FOR_EACH_SLAVE(i
, slave
) {
829 retval
= generate_and_put_packets(slave
, &src_mac
, &bonded_mac
, 1);
830 TEST_ASSERT_SUCCESS(retval
, "Failed to enqueue packets to slave %u",
833 retval
= generate_and_put_packets(slave
, &src_mac
, &dst_mac
, 1);
834 TEST_ASSERT_SUCCESS(retval
, "Failed to enqueue packets to slave %u",
837 /* Expect 2 packets per slave */
838 expected_pkts_cnt
+= 2;
841 retval
= rte_eth_rx_burst(test_params
.bonded_port_id
, 0, pkts
,
844 if (retval
== expected_pkts_cnt
) {
845 int cnt
[2] = { 0, 0 };
847 for (i
= 0; i
< expected_pkts_cnt
; i
++) {
848 hdr
= rte_pktmbuf_mtod(pkts
[i
], struct ether_hdr
*);
849 cnt
[is_same_ether_addr(&hdr
->d_addr
, &bonded_mac
)]++;
852 free_pkts(pkts
, expected_pkts_cnt
);
854 /* For division by 2 expected_pkts_cnt must be even */
855 RTE_VERIFY((expected_pkts_cnt
& 1) == 0);
856 TEST_ASSERT(cnt
[0] == expected_pkts_cnt
/ 2 &&
857 cnt
[1] == expected_pkts_cnt
/ 2,
858 "Expected %u packets with the same MAC and %u with different but "
859 "got %u with the same and %u with different MAC",
860 expected_pkts_cnt
/ 2, expected_pkts_cnt
/ 2, cnt
[1], cnt
[0]);
861 } else if (retval
> 0)
862 free_pkts(pkts
, retval
);
864 TEST_ASSERT_EQUAL(retval
, expected_pkts_cnt
,
865 "Expected %u packets but received only %d", expected_pkts_cnt
, retval
);
867 /* Now, disable promiscuous mode. When promiscuous mode is disabled we
868 * expect to receive only packets that are directed to bonding port. */
869 rte_eth_promiscuous_disable(test_params
.bonded_port_id
);
871 expected_pkts_cnt
= 0;
872 FOR_EACH_SLAVE(i
, slave
) {
873 retval
= generate_and_put_packets(slave
, &src_mac
, &bonded_mac
, 1);
874 TEST_ASSERT_SUCCESS(retval
, "Failed to enqueue packets to slave %u",
877 retval
= generate_and_put_packets(slave
, &src_mac
, &dst_mac
, 1);
878 TEST_ASSERT_SUCCESS(retval
, "Failed to enqueue packets to slave %u",
881 /* Expect only one packet per slave */
882 expected_pkts_cnt
+= 1;
885 retval
= rte_eth_rx_burst(test_params
.bonded_port_id
, 0, pkts
,
888 if (retval
== expected_pkts_cnt
) {
891 for (i
= 0; i
< expected_pkts_cnt
; i
++) {
892 hdr
= rte_pktmbuf_mtod(pkts
[i
], struct ether_hdr
*);
893 eq_cnt
+= is_same_ether_addr(&hdr
->d_addr
, &bonded_mac
);
896 free_pkts(pkts
, expected_pkts_cnt
);
897 TEST_ASSERT_EQUAL(eq_cnt
, expected_pkts_cnt
, "Packet address mismatch");
898 } else if (retval
> 0)
899 free_pkts(pkts
, retval
);
901 TEST_ASSERT_EQUAL(retval
, expected_pkts_cnt
,
902 "Expected %u packets but received only %d", expected_pkts_cnt
, retval
);
904 /* Link down test: simulate link down for first slave. */
905 delay
= bond_get_update_timeout_ms();
907 uint8_t slave_down_id
= INVALID_PORT_ID
;
909 /* Find first slave and make link down on it*/
910 FOR_EACH_SLAVE(i
, slave
) {
911 rte_eth_dev_set_link_down(slave
->port_id
);
912 slave_down_id
= slave
->port_id
;
916 RTE_VERIFY(slave_down_id
!= INVALID_PORT_ID
);
918 /* Give some time to rearrange bonding */
919 for (i
= 0; i
< 3; i
++) {
924 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
926 /* Put packet to each slave */
927 FOR_EACH_SLAVE(i
, slave
) {
930 dst_mac
.addr_bytes
[ETHER_ADDR_LEN
- 1] = slave
->port_id
;
931 retval
= generate_and_put_packets(slave
, &src_mac
, &dst_mac
, 1);
932 TEST_ASSERT_SUCCESS(retval
, "Failed to generate test packet burst.");
934 src_mac
.addr_bytes
[ETHER_ADDR_LEN
- 1] = slave
->port_id
;
935 retval
= generate_and_put_packets(slave
, &src_mac
, &bonded_mac
, 1);
936 TEST_ASSERT_SUCCESS(retval
, "Failed to generate test packet burst.");
938 retval
= bond_rx(pkts
, RTE_DIM(pkts
));
942 free_pkts(pkts
, retval
);
944 while (rte_ring_dequeue(slave
->rx_queue
, (void **)&pkt
) == 0)
945 rte_pktmbuf_free(pkt
);
947 if (slave_down_id
== slave
->port_id
)
948 TEST_ASSERT_EQUAL(retval
, 0, "Packets received unexpectedly.");
950 TEST_ASSERT_NOT_EQUAL(retval
, 0,
951 "Expected to receive some packets on slave %u.",
953 rte_eth_dev_start(slave
->port_id
);
955 for (j
= 0; j
< 5; j
++) {
956 TEST_ASSERT(bond_handshake_reply(slave
) >= 0,
957 "Handshake after link up");
959 if (bond_handshake_done(slave
) == 1)
963 TEST_ASSERT(j
< 5, "Failed to aggregate slave after link up");
966 remove_slaves_and_stop_bonded_device();
971 test_mode4_tx_burst(void)
973 struct slave_conf
*slave
;
976 uint16_t exp_pkts_cnt
, pkts_cnt
= 0;
977 struct rte_mbuf
*pkts
[MAX_PKT_BURST
];
981 struct ether_addr dst_mac
= { { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 } };
982 struct ether_addr bonded_mac
;
984 retval
= initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT
, 0);
985 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bonded device");
987 retval
= bond_handshake();
988 TEST_ASSERT_SUCCESS(retval
, "Initial handshake failed");
990 rte_eth_macaddr_get(test_params
.bonded_port_id
, &bonded_mac
);
993 for (pkts_cnt
= 0; pkts_cnt
< RTE_DIM(pkts
); pkts_cnt
++) {
994 dst_mac
.addr_bytes
[ETHER_ADDR_LEN
- 1] = pkts_cnt
;
995 retval
= generate_packets(&bonded_mac
, &dst_mac
, 1, &pkts
[pkts_cnt
]);
998 free_pkts(pkts
, pkts_cnt
);
1000 TEST_ASSERT_EQUAL(retval
, 1, "Failed to generate packet %u", pkts_cnt
);
1002 exp_pkts_cnt
= pkts_cnt
;
1004 /* Transmit packets on bonded device */
1005 retval
= bond_tx(pkts
, pkts_cnt
);
1006 if (retval
> 0 && retval
< pkts_cnt
)
1007 free_pkts(&pkts
[retval
], pkts_cnt
- retval
);
1009 TEST_ASSERT_EQUAL(retval
, pkts_cnt
, "TX on bonded device failed");
1011 /* Check if packets were transmitted properly. Every slave should have
1012 * at least one packet, and sum must match. Under normal operation
1013 * there should be no LACP nor MARKER frames. */
1015 FOR_EACH_SLAVE(i
, slave
) {
1016 uint16_t normal_cnt
, slow_cnt
;
1018 retval
= slave_get_pkts(slave
, pkts
, RTE_DIM(pkts
));
1022 for (j
= 0; j
< retval
; j
++) {
1023 if (make_lacp_reply(slave
, pkts
[j
]) == 1)
1029 free_pkts(pkts
, normal_cnt
+ slow_cnt
);
1030 TEST_ASSERT_EQUAL(slow_cnt
, 0,
1031 "slave %u unexpectedly transmitted %d SLOW packets", slave
->port_id
,
1034 TEST_ASSERT_NOT_EQUAL(normal_cnt
, 0,
1035 "slave %u did not transmitted any packets", slave
->port_id
);
1037 pkts_cnt
+= normal_cnt
;
1040 TEST_ASSERT_EQUAL(exp_pkts_cnt
, pkts_cnt
,
1041 "Expected %u packets but transmitted only %d", exp_pkts_cnt
, pkts_cnt
);
1044 * simulate link down for first slave. */
1045 delay
= bond_get_update_timeout_ms();
1047 uint8_t slave_down_id
= INVALID_PORT_ID
;
1049 FOR_EACH_SLAVE(i
, slave
) {
1050 rte_eth_dev_set_link_down(slave
->port_id
);
1051 slave_down_id
= slave
->port_id
;
1055 RTE_VERIFY(slave_down_id
!= INVALID_PORT_ID
);
1057 /* Give some time to rearrange bonding. */
1058 for (i
= 0; i
< 3; i
++) {
1060 rte_delay_ms(delay
);
1063 TEST_ASSERT_SUCCESS(bond_handshake(), "Handshake after link down failed");
1065 /* Prepare burst. */
1066 for (pkts_cnt
= 0; pkts_cnt
< RTE_DIM(pkts
); pkts_cnt
++) {
1067 dst_mac
.addr_bytes
[ETHER_ADDR_LEN
- 1] = pkts_cnt
;
1068 retval
= generate_packets(&bonded_mac
, &dst_mac
, 1, &pkts
[pkts_cnt
]);
1071 free_pkts(pkts
, pkts_cnt
);
1073 TEST_ASSERT_EQUAL(retval
, 1, "Failed to generate test packet %u",
1076 exp_pkts_cnt
= pkts_cnt
;
1078 /* Transmit packets on bonded device. */
1079 retval
= bond_tx(pkts
, pkts_cnt
);
1080 if (retval
> 0 && retval
< pkts_cnt
)
1081 free_pkts(&pkts
[retval
], pkts_cnt
- retval
);
1083 TEST_ASSERT_EQUAL(retval
, pkts_cnt
, "TX on bonded device failed");
1085 /* Check if packets was transmitted properly. Every slave should have
1086 * at least one packet, and sum must match. Under normal operation
1087 * there should be no LACP nor MARKER frames. */
1089 FOR_EACH_SLAVE(i
, slave
) {
1090 uint16_t normal_cnt
, slow_cnt
;
1092 retval
= slave_get_pkts(slave
, pkts
, RTE_DIM(pkts
));
1096 for (j
= 0; j
< retval
; j
++) {
1097 if (make_lacp_reply(slave
, pkts
[j
]) == 1)
1103 free_pkts(pkts
, normal_cnt
+ slow_cnt
);
1105 if (slave_down_id
== slave
->port_id
) {
1106 TEST_ASSERT_EQUAL(normal_cnt
+ slow_cnt
, 0,
1107 "slave %u enexpectedly transmitted %u packets",
1108 normal_cnt
+ slow_cnt
, slave
->port_id
);
1110 TEST_ASSERT_EQUAL(slow_cnt
, 0,
1111 "slave %u unexpectedly transmitted %d SLOW packets",
1112 slave
->port_id
, slow_cnt
);
1114 TEST_ASSERT_NOT_EQUAL(normal_cnt
, 0,
1115 "slave %u did not transmitted any packets", slave
->port_id
);
1118 pkts_cnt
+= normal_cnt
;
1121 TEST_ASSERT_EQUAL(exp_pkts_cnt
, pkts_cnt
,
1122 "Expected %u packets but transmitted only %d", exp_pkts_cnt
, pkts_cnt
);
1124 return remove_slaves_and_stop_bonded_device();
1128 init_marker(struct rte_mbuf
*pkt
, struct slave_conf
*slave
)
1130 struct marker_header
*marker_hdr
= rte_pktmbuf_mtod(pkt
,
1131 struct marker_header
*);
1133 /* Copy multicast destination address */
1134 ether_addr_copy(&slow_protocol_mac_addr
, &marker_hdr
->eth_hdr
.d_addr
);
1136 /* Init source address */
1137 ether_addr_copy(&parnter_mac_default
, &marker_hdr
->eth_hdr
.s_addr
);
1138 marker_hdr
->eth_hdr
.s_addr
.addr_bytes
[ETHER_ADDR_LEN
-1] = slave
->port_id
;
1140 marker_hdr
->eth_hdr
.ether_type
= rte_cpu_to_be_16(ETHER_TYPE_SLOW
);
1142 marker_hdr
->marker
.subtype
= SLOW_SUBTYPE_MARKER
;
1143 marker_hdr
->marker
.version_number
= 1;
1144 marker_hdr
->marker
.tlv_type_marker
= MARKER_TLV_TYPE_INFO
;
1145 marker_hdr
->marker
.info_length
=
1146 offsetof(struct marker
, reserved_90
) -
1147 offsetof(struct marker
, requester_port
);
1148 RTE_VERIFY(marker_hdr
->marker
.info_length
== 16);
1149 marker_hdr
->marker
.requester_port
= slave
->port_id
+ 1;
1150 marker_hdr
->marker
.tlv_type_terminator
= TLV_TYPE_TERMINATOR_INFORMATION
;
1151 marker_hdr
->marker
.terminator_length
= 0;
1155 test_mode4_marker(void)
1157 struct slave_conf
*slave
;
1158 struct rte_mbuf
*pkts
[MAX_PKT_BURST
];
1159 struct rte_mbuf
*marker_pkt
;
1160 struct marker_header
*marker_hdr
;
1166 const uint16_t ethtype_slow_be
= rte_be_to_cpu_16(ETHER_TYPE_SLOW
);
1168 retval
= initialize_bonded_device_with_slaves(TEST_MARKER_SLAVE_COUT
,
1170 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bonded device");
1172 /* Test LACP handshake function */
1173 retval
= bond_handshake();
1174 TEST_ASSERT_SUCCESS(retval
, "Initial handshake failed");
1176 delay
= bond_get_update_timeout_ms();
1177 FOR_EACH_SLAVE(i
, slave
) {
1178 marker_pkt
= rte_pktmbuf_alloc(test_params
.mbuf_pool
);
1179 TEST_ASSERT_NOT_NULL(marker_pkt
, "Failed to allocate marker packet");
1180 init_marker(marker_pkt
, slave
);
1182 retval
= slave_put_pkts(slave
, &marker_pkt
, 1);
1184 rte_pktmbuf_free(marker_pkt
);
1186 TEST_ASSERT_EQUAL(retval
, 1,
1187 "Failed to send marker packet to slave %u", slave
->port_id
);
1189 for (j
= 0; j
< 20; ++j
) {
1190 rte_delay_ms(delay
);
1191 retval
= rte_eth_rx_burst(test_params
.bonded_port_id
, 0, pkts
,
1195 free_pkts(pkts
, retval
);
1197 TEST_ASSERT_EQUAL(retval
, 0, "Received packets unexpectedly");
1199 retval
= rte_eth_tx_burst(test_params
.bonded_port_id
, 0, NULL
, 0);
1200 TEST_ASSERT_EQUAL(retval
, 0,
1201 "Requested TX of 0 packets but %d transmitted", retval
);
1203 /* Check if LACP packet was send by state machines
1204 First and only packet must be a maker response */
1205 retval
= slave_get_pkts(slave
, pkts
, MAX_PKT_BURST
);
1209 free_pkts(pkts
, retval
);
1211 TEST_ASSERT_EQUAL(retval
, 1, "failed to get slave packets");
1214 marker_hdr
= rte_pktmbuf_mtod(pkts
[0], struct marker_header
*);
1215 /* Check if it's slow packet*/
1216 if (marker_hdr
->eth_hdr
.ether_type
!= ethtype_slow_be
)
1218 /* Check if it's marker packet */
1219 else if (marker_hdr
->marker
.subtype
!= SLOW_SUBTYPE_MARKER
)
1221 else if (marker_hdr
->marker
.tlv_type_marker
!= MARKER_TLV_TYPE_RESP
)
1224 free_pkts(pkts
, nb_pkts
);
1226 TEST_ASSERT_NOT_EQUAL(retval
, -1, "Unexpected protocol type");
1227 TEST_ASSERT_NOT_EQUAL(retval
, -2, "Unexpected sub protocol type");
1228 TEST_ASSERT_NOT_EQUAL(retval
, -3, "Unexpected marker type");
1232 TEST_ASSERT(j
< 20, "Marker response not found");
1235 retval
= remove_slaves_and_stop_bonded_device();
1236 TEST_ASSERT_SUCCESS(retval
, "Test cleanup failed.");
1238 return TEST_SUCCESS
;
1242 test_mode4_expired(void)
1244 struct slave_conf
*slave
, *exp_slave
= NULL
;
1245 struct rte_mbuf
*pkts
[MAX_PKT_BURST
];
1252 struct rte_eth_bond_8023ad_conf conf
;
1254 retval
= initialize_bonded_device_with_slaves(TEST_EXPIRED_SLAVE_COUNT
,
1256 /* Set custom timeouts to make test last shorter. */
1257 rte_eth_bond_8023ad_conf_get(test_params
.bonded_port_id
, &conf
);
1258 conf
.fast_periodic_ms
= 100;
1259 conf
.slow_periodic_ms
= 600;
1260 conf
.short_timeout_ms
= 300;
1261 conf
.long_timeout_ms
= 900;
1262 conf
.aggregate_wait_timeout_ms
= 200;
1263 conf
.tx_period_ms
= 100;
1264 old_delay
= conf
.update_timeout_ms
;
1265 conf
.update_timeout_ms
= 10;
1266 rte_eth_bond_8023ad_setup(test_params
.bonded_port_id
, &conf
);
1268 /* Wait for new settings to be applied. */
1269 for (i
= 0; i
< old_delay
/conf
.update_timeout_ms
* 2; i
++) {
1270 FOR_EACH_SLAVE(j
, slave
)
1271 bond_handshake_reply(slave
);
1273 rte_delay_ms(conf
.update_timeout_ms
);
1276 retval
= bond_handshake();
1277 TEST_ASSERT_SUCCESS(retval
, "Initial handshake failed");
1279 /* Find first slave */
1280 FOR_EACH_SLAVE(i
, slave
) {
1285 RTE_VERIFY(exp_slave
!= NULL
);
1287 /* When one of partners do not send or respond to LACP frame in
1288 * conf.long_timeout_ms time, internal state machines should detect this
1289 * and transit to expired state. */
1290 for (j
= 0; j
< conf
.long_timeout_ms
/conf
.update_timeout_ms
+ 2; j
++) {
1291 rte_delay_ms(conf
.update_timeout_ms
);
1293 retval
= bond_tx(NULL
, 0);
1294 TEST_ASSERT_EQUAL(retval
, 0, "Unexpectedly received %d packets",
1297 FOR_EACH_SLAVE(i
, slave
) {
1298 retval
= bond_handshake_reply(slave
);
1299 TEST_ASSERT(retval
>= 0, "Handshake failed");
1301 /* Remove replay for slave that suppose to be expired. */
1302 if (slave
== exp_slave
) {
1303 while (rte_ring_count(slave
->rx_queue
) > 0) {
1306 rte_ring_dequeue(slave
->rx_queue
, &pkt
);
1307 rte_pktmbuf_free(pkt
);
1312 retval
= bond_rx(pkts
, RTE_DIM(pkts
));
1314 free_pkts(pkts
, retval
);
1316 TEST_ASSERT_EQUAL(retval
, 0, "Unexpectedly received %d packets",
1320 /* After test only expected slave should be in EXPIRED state */
1321 FOR_EACH_SLAVE(i
, slave
) {
1322 if (slave
== exp_slave
)
1323 TEST_ASSERT(slave
->lacp_parnter_state
& STATE_EXPIRED
,
1324 "Slave %u should be in expired.", slave
->port_id
);
1326 TEST_ASSERT_EQUAL(bond_handshake_done(slave
), 1,
1327 "Slave %u should be operational.", slave
->port_id
);
1330 retval
= remove_slaves_and_stop_bonded_device();
1331 TEST_ASSERT_SUCCESS(retval
, "Test cleanup failed.");
1333 return TEST_SUCCESS
;
1337 test_mode4_ext_ctrl(void)
1340 * configure bonded interface without the external sm enabled
1341 * . try to transmit lacpdu (should fail)
1342 * . try to set collecting and distributing flags (should fail)
1343 * reconfigure w/external sm
1344 * . transmit one lacpdu on each slave using new api
1345 * . make sure each slave receives one lacpdu using the callback api
1346 * . transmit one data pdu on each slave (should fail)
1347 * . enable distribution and collection, send one data pdu each again
1351 struct slave_conf
*slave
= NULL
;
1354 struct rte_mbuf
*lacp_tx_buf
[SLAVE_COUNT
];
1355 struct ether_addr src_mac
, dst_mac
;
1356 struct lacpdu_header lacpdu
= {
1358 .subtype
= SLOW_SUBTYPE_LACP
,
1362 ether_addr_copy(&parnter_system
, &src_mac
);
1363 ether_addr_copy(&slow_protocol_mac_addr
, &dst_mac
);
1365 initialize_eth_header(&lacpdu
.eth_hdr
, &src_mac
, &dst_mac
,
1366 ETHER_TYPE_SLOW
, 0, 0);
1368 for (i
= 0; i
< SLAVE_COUNT
; i
++) {
1369 lacp_tx_buf
[i
] = rte_pktmbuf_alloc(test_params
.mbuf_pool
);
1370 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf
[i
], char *),
1371 &lacpdu
, sizeof(lacpdu
));
1372 rte_pktmbuf_pkt_len(lacp_tx_buf
[i
]) = sizeof(lacpdu
);
1375 retval
= initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT
, 0);
1376 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bonded device");
1378 FOR_EACH_SLAVE(i
, slave
) {
1379 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_slowtx(
1380 test_params
.bonded_port_id
,
1381 slave
->port_id
, lacp_tx_buf
[i
]),
1382 "Slave should not allow manual LACP xmit");
1383 TEST_ASSERT_FAIL(rte_eth_bond_8023ad_ext_collect(
1384 test_params
.bonded_port_id
,
1386 "Slave should not allow external state controls");
1389 free_pkts(lacp_tx_buf
, RTE_DIM(lacp_tx_buf
));
1391 retval
= remove_slaves_and_stop_bonded_device();
1392 TEST_ASSERT_SUCCESS(retval
, "Bonded device cleanup failed.");
1394 return TEST_SUCCESS
;
1399 test_mode4_ext_lacp(void)
1402 struct slave_conf
*slave
= NULL
;
1403 uint8_t all_slaves_done
= 0, i
;
1405 const unsigned int delay
= bond_get_update_timeout_ms();
1407 struct rte_mbuf
*lacp_tx_buf
[SLAVE_COUNT
];
1408 struct rte_mbuf
*buf
[SLAVE_COUNT
];
1409 struct ether_addr src_mac
, dst_mac
;
1410 struct lacpdu_header lacpdu
= {
1412 .subtype
= SLOW_SUBTYPE_LACP
,
1416 ether_addr_copy(&parnter_system
, &src_mac
);
1417 ether_addr_copy(&slow_protocol_mac_addr
, &dst_mac
);
1419 initialize_eth_header(&lacpdu
.eth_hdr
, &src_mac
, &dst_mac
,
1420 ETHER_TYPE_SLOW
, 0, 0);
1422 for (i
= 0; i
< SLAVE_COUNT
; i
++) {
1423 lacp_tx_buf
[i
] = rte_pktmbuf_alloc(test_params
.mbuf_pool
);
1424 rte_memcpy(rte_pktmbuf_mtod(lacp_tx_buf
[i
], char *),
1425 &lacpdu
, sizeof(lacpdu
));
1426 rte_pktmbuf_pkt_len(lacp_tx_buf
[i
]) = sizeof(lacpdu
);
1429 retval
= initialize_bonded_device_with_slaves(TEST_TX_SLAVE_COUNT
, 1);
1430 TEST_ASSERT_SUCCESS(retval
, "Failed to initialize bonded device");
1432 memset(lacpdu_rx_count
, 0, sizeof(lacpdu_rx_count
));
1434 /* Wait for new settings to be applied. */
1435 for (i
= 0; i
< 30; ++i
)
1436 rte_delay_ms(delay
);
1438 FOR_EACH_SLAVE(i
, slave
) {
1439 retval
= rte_eth_bond_8023ad_ext_slowtx(
1440 test_params
.bonded_port_id
,
1441 slave
->port_id
, lacp_tx_buf
[i
]);
1442 TEST_ASSERT_SUCCESS(retval
,
1443 "Slave should allow manual LACP xmit");
1446 nb_pkts
= bond_tx(NULL
, 0);
1447 TEST_ASSERT_EQUAL(nb_pkts
, 0, "Packets transmitted unexpectedly");
1449 FOR_EACH_SLAVE(i
, slave
) {
1450 nb_pkts
= slave_get_pkts(slave
, buf
, RTE_DIM(buf
));
1451 TEST_ASSERT_EQUAL(nb_pkts
, 1, "found %u packets on slave %d\n",
1453 slave_put_pkts(slave
, buf
, nb_pkts
);
1456 nb_pkts
= bond_rx(buf
, RTE_DIM(buf
));
1457 free_pkts(buf
, nb_pkts
);
1458 TEST_ASSERT_EQUAL(nb_pkts
, 0, "Packets received unexpectedly");
1460 /* wait for the periodic callback to run */
1461 for (i
= 0; i
< 30 && all_slaves_done
== 0; ++i
) {
1462 uint8_t s
, total
= 0;
1464 rte_delay_ms(delay
);
1465 FOR_EACH_SLAVE(s
, slave
) {
1466 total
+= lacpdu_rx_count
[slave
->port_id
];
1469 if (total
>= SLAVE_COUNT
)
1470 all_slaves_done
= 1;
1473 FOR_EACH_SLAVE(i
, slave
) {
1474 TEST_ASSERT_EQUAL(lacpdu_rx_count
[slave
->port_id
], 1,
1475 "Slave port %u should have received 1 lacpdu (count=%u)",
1477 lacpdu_rx_count
[slave
->port_id
]);
1480 retval
= remove_slaves_and_stop_bonded_device();
1481 TEST_ASSERT_SUCCESS(retval
, "Test cleanup failed.");
1483 return TEST_SUCCESS
;
1487 check_environment(void)
1489 struct slave_conf
*port
;
1490 uint8_t i
, env_state
;
1491 uint16_t slaves
[RTE_DIM(test_params
.slave_ports
)];
1495 FOR_EACH_PORT(i
, port
) {
1496 if (rte_ring_count(port
->rx_queue
) != 0)
1499 if (rte_ring_count(port
->tx_queue
) != 0)
1502 if (port
->bonded
!= 0)
1505 if (port
->lacp_parnter_state
!= 0)
1512 slaves_count
= rte_eth_bond_slaves_get(test_params
.bonded_port_id
,
1513 slaves
, RTE_DIM(slaves
));
1515 if (slaves_count
!= 0)
1518 TEST_ASSERT_EQUAL(env_state
, 0,
1519 "Environment not clean (port %u):%s%s%s%s%s",
1521 env_state
& 0x01 ? " slave rx queue not clean" : "",
1522 env_state
& 0x02 ? " slave tx queue not clean" : "",
1523 env_state
& 0x04 ? " port marked as enslaved" : "",
1524 env_state
& 0x80 ? " slave state is not reset" : "",
1525 env_state
& 0x10 ? " slave count not equal 0" : ".");
1528 return TEST_SUCCESS
;
1532 test_mode4_executor(int (*test_func
)(void))
1534 struct slave_conf
*port
;
1539 /* Check if environment is clean. Fail to launch a test if there was
1540 * a critical error before that prevented to reset environment. */
1541 TEST_ASSERT_SUCCESS(check_environment(),
1542 "Refusing to launch test in dirty environment.");
1544 RTE_VERIFY(test_func
!= NULL
);
1545 test_result
= (*test_func
)();
1547 /* If test succeed check if environment wast left in good condition. */
1548 if (test_result
== TEST_SUCCESS
)
1549 test_result
= check_environment();
1551 /* Reset environment in case test failed to do that. */
1552 if (test_result
!= TEST_SUCCESS
) {
1553 TEST_ASSERT_SUCCESS(remove_slaves_and_stop_bonded_device(),
1554 "Failed to stop bonded device");
1556 FOR_EACH_PORT(i
, port
) {
1557 while (rte_ring_count(port
->rx_queue
) != 0) {
1558 if (rte_ring_dequeue(port
->rx_queue
, &pkt
) == 0)
1559 rte_pktmbuf_free(pkt
);
1562 while (rte_ring_count(port
->tx_queue
) != 0) {
1563 if (rte_ring_dequeue(port
->tx_queue
, &pkt
) == 0)
1564 rte_pktmbuf_free(pkt
);
1573 test_mode4_agg_mode_selection_wrapper(void){
1574 return test_mode4_executor(&test_mode4_agg_mode_selection
);
1578 test_mode4_lacp_wrapper(void)
1580 return test_mode4_executor(&test_mode4_lacp
);
1584 test_mode4_marker_wrapper(void)
1586 return test_mode4_executor(&test_mode4_marker
);
1590 test_mode4_rx_wrapper(void)
1592 return test_mode4_executor(&test_mode4_rx
);
1596 test_mode4_tx_burst_wrapper(void)
1598 return test_mode4_executor(&test_mode4_tx_burst
);
1602 test_mode4_expired_wrapper(void)
1604 return test_mode4_executor(&test_mode4_expired
);
1608 test_mode4_ext_ctrl_wrapper(void)
1610 return test_mode4_executor(&test_mode4_ext_ctrl
);
1614 test_mode4_ext_lacp_wrapper(void)
1616 return test_mode4_executor(&test_mode4_ext_lacp
);
1619 static struct unit_test_suite link_bonding_mode4_test_suite
= {
1620 .suite_name
= "Link Bonding mode 4 Unit Test Suite",
1621 .setup
= test_setup
,
1622 .teardown
= testsuite_teardown
,
1623 .unit_test_cases
= {
1624 TEST_CASE_NAMED("test_mode4_agg_mode_selection",
1625 test_mode4_agg_mode_selection_wrapper
),
1626 TEST_CASE_NAMED("test_mode4_lacp", test_mode4_lacp_wrapper
),
1627 TEST_CASE_NAMED("test_mode4_rx", test_mode4_rx_wrapper
),
1628 TEST_CASE_NAMED("test_mode4_tx_burst", test_mode4_tx_burst_wrapper
),
1629 TEST_CASE_NAMED("test_mode4_marker", test_mode4_marker_wrapper
),
1630 TEST_CASE_NAMED("test_mode4_expired", test_mode4_expired_wrapper
),
1631 TEST_CASE_NAMED("test_mode4_ext_ctrl",
1632 test_mode4_ext_ctrl_wrapper
),
1633 TEST_CASE_NAMED("test_mode4_ext_lacp",
1634 test_mode4_ext_lacp_wrapper
),
1636 TEST_CASES_END() /**< NULL terminate unit test array */
1641 test_link_bonding_mode4(void)
1643 return unit_test_suite_runner(&link_bonding_mode4_test_suite
);
1646 REGISTER_TEST_COMMAND(link_bonding_mode4_autotest
, test_link_bonding_mode4
);