Test changing the link, speed, duplex, etc. status of the KNI interface with rte_kni_update_link().
Signed-off-by: Dan Gora <d...@adax.com> --- test/test/test_kni.c | 131 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/test/test/test_kni.c b/test/test/test_kni.c index 3dcadcebd..138bc9686 100644 --- a/test/test/test_kni.c +++ b/test/test/test_kni.c @@ -118,6 +118,133 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu) port_id, kni_pkt_mtu); return 0; } + +static int +test_kni_link_change(void) +{ + struct rte_eth_link link; + int ret; + int pid; + + pid = fork(); + if (pid < 0) { + printf("Error: Failed to fork a process\n"); + return -1; + } + + if (pid == 0) { + printf("Starting KNI Link status change tests.\n"); + if (system(IFCONFIG TEST_KNI_PORT" up") == -1) { + ret = -1; + goto error; + } + + link.link_speed = 10; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_AUTONEG; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/10Mbps/AutoNeg/Full ret=%d.\n", ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 0; + link.link_status = ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to Down ret=%d.\n", + ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 1000; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_AUTONEG; + link.link_duplex = ETH_LINK_HALF_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/1Gbps/AutoNeg/Half ret=%d.\n", ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 0; + link.link_status = ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to Down ret=%d.\n", + ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 40000; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/40Gbps/Fixed/Full ret=%d.\n", ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 0; + link.link_status = ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to Down ret=%d.\n", + ret); + goto error; + } + rte_delay_ms(1000); + + link.link_speed = 100000; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/100Gbps/Fixed/Full ret=%d.\n", ret); + goto error; + } + rte_delay_ms(1000); + +error: + if (system(IFCONFIG TEST_KNI_PORT" down") == -1) + ret = -1; + + printf("KNI Link status change tests: %s.\n", + (ret == 0) ? "Passed" : "Failed"); + exit(ret); + } else { + int p_ret, status; + + while (1) { + p_ret = waitpid(pid, &status, WNOHANG); + if (p_ret != 0) { + if (WIFEXITED(status)) + return WEXITSTATUS(status); + return -1; + } + rte_delay_ms(10); + rte_kni_handle_request(test_kni_ctx); + } + } +} /** * This loop fully tests the basic functions of KNI. e.g. transmitting, * receiving to, from kernel space, and kernel requests. @@ -401,6 +528,10 @@ test_kni_processing(uint16_t port_id, struct rte_mempool *mp) goto fail_kni; } + ret = test_kni_link_change(); + if (ret != 0) + goto fail_kni; + rte_eal_mp_remote_launch(test_kni_loop, NULL, CALL_MASTER); RTE_LCORE_FOREACH_SLAVE(i) { if (rte_eal_wait_lcore(i) < 0) { -- 2.19.0