summaryrefslogtreecommitdiff
path: root/test/test
diff options
context:
space:
mode:
authorDan Gora <dg@adax.com>2018-10-24 19:26:27 -0300
committerThomas Monjalon <thomas@monjalon.net>2018-10-26 19:46:15 +0200
commitc6fd54f28c24ba0b3912a1746c4a2b810ffa89c4 (patch)
tree931d9cf5198e0ea83f590b4920186c92ab4775d1 /test/test
parentfd5f33323e5a698941db03908d5bd1fa91016b7e (diff)
downloaddpdk-c6fd54f28c24ba0b3912a1746c4a2b810ffa89c4.zip
dpdk-c6fd54f28c24ba0b3912a1746c4a2b810ffa89c4.tar.gz
dpdk-c6fd54f28c24ba0b3912a1746c4a2b810ffa89c4.tar.xz
kni: add function to set link state on kernel interface
Add a new API function to KNI, rte_kni_update_link() to allow DPDK applications to update the link status for KNI network interfaces in the linux kernel. Signed-off-by: Dan Gora <dg@adax.com> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
Diffstat (limited to 'test/test')
-rw-r--r--test/test/test_kni.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/test/test_kni.c b/test/test/test_kni.c
index cf64c0b..e382069 100644
--- a/test/test/test_kni.c
+++ b/test/test/test_kni.c
@@ -118,6 +118,79 @@ 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)
+{
+ 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;
+ }
+
+ ret = rte_kni_update_link(test_kni_ctx, 1);
+ if (ret < 0) {
+ printf("Failed to change link state to Up ret=%d.\n",
+ ret);
+ goto error;
+ }
+ rte_delay_ms(1000);
+ printf("KNI: Set LINKUP, previous state=%d\n", ret);
+
+ ret = rte_kni_update_link(test_kni_ctx, 0);
+ if (ret != 1) {
+ printf(
+ "Failed! Previous link state should be 1, returned %d.\n",
+ ret);
+ goto error;
+ }
+ rte_delay_ms(1000);
+ printf("KNI: Set LINKDOWN, previous state=%d\n", ret);
+
+ ret = rte_kni_update_link(test_kni_ctx, 1);
+ if (ret != 0) {
+ printf(
+ "Failed! Previous link state should be 0, returned %d.\n",
+ ret);
+ goto error;
+ }
+ printf("KNI: Set LINKUP, previous state=%d\n", ret);
+
+ ret = 0;
+ 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 +474,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) {