From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by dpdk.org (Postfix) with ESMTP id 9F95A4CA7 for ; Wed, 24 Oct 2018 22:27:36 +0200 (CEST) Received: by mail-qt1-f195.google.com with SMTP id c16-v6so7183235qtj.13 for ; Wed, 24 Oct 2018 13:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GU+Ae+jbMqhbgYDk08eZMjAQViAixUhJ/KkiUwuLcxA=; b=ah3gI/JAF/W+aoG+7VO7/wGd6NWcu3v28oLIbOxPyEb/ytPOTjoXAsYuI7YFdR4pfo KaXSr/HW5jZJ31LFW890LEck6GEGjcJqIJsXwm8UNZwu+26b2kvPX/Lr35adm+FezTci VG7ja0cadLVBXu9Esd35Iv0eAeajEAuxdjhbwISmbEeWDSRR9lV4+dv87SqCf/l/22Ph RU/HlclCZJ9NTYkzmzAq0xw3D2wHT1O0gML/MsXV7Ncpbf+skxn9ZYZnW8mHor2el09i gsbQSR7KRDdS3JwmyAC2QOa+QEWuh6BaT410adUiv0s09HpdjNBlo8tBbP5age19tZYQ krXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=GU+Ae+jbMqhbgYDk08eZMjAQViAixUhJ/KkiUwuLcxA=; b=KzVrOcEdpA72U/Ph0mTQRYcsDkgW/ZP5GD6t0MW/8HwA49Jt6XcMISpb1LoSqudutW rSWKEDAHB3WJlNOdg0Mz9CWgM1HO16REOVU1ay7i/f+Kr4qbyuIW3X3a84auhg9a3cDc nzVVu5UKZNk6zmkmMVbL+t4kwuxBDjhxU0h5vaN1cJ3jI7KYQMf0wg7vU5iQuaG8CUut eB1LdGtVXqpTUj1MuGOlKCMrJDEVY2eZncDC3XMXgJ9Pmz5FS7zx2JL4JqjoXQFVJZCt CU5brRiCb4ELwthSMeAeAQcv/7icawsJhSQG2RcVczsuuLSuYfxwUipGDIW257OZOFlq UPIg== X-Gm-Message-State: AGRZ1gILSBCkmrHkSgJjvnABjJ1W8AG0vk9kioXg/bHqI+mwaZMLDF+c 50EsPPykKgSUjf3SyuEh12+9Fhmr X-Google-Smtp-Source: AJdET5cnqjzQ75nIM5r2hSESqJJotTlQt3M/7EesknJT5piZsRwUsVrtoz0ojmL7+mWmPctUvq1+yg== X-Received: by 2002:a0c:b3cd:: with SMTP id b13mr3931412qvf.29.1540412855588; Wed, 24 Oct 2018 13:27:35 -0700 (PDT) Received: from snappy.local.lan ([179.228.213.114]) by smtp.gmail.com with ESMTPSA id p64-v6sm3509117qkc.96.2018.10.24.13.27.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Oct 2018 13:27:34 -0700 (PDT) Sender: Dan Gora From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Wed, 24 Oct 2018 17:27:15 -0300 Message-Id: <20181024202719.24902-2-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181024202719.24902-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20181024202719.24902-1-dg@adax.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v6 1/5] kni: add API to set link status on kernel interface X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2018 20:27:37 -0000 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 --- lib/librte_kni/rte_kni.c | 41 ++++++++++++++++ lib/librte_kni/rte_kni.h | 20 ++++++++ lib/librte_kni/rte_kni_version.map | 6 +++ test/test/test_kni.c | 77 ++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index b8edd40f4..c9726d4f8 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -717,6 +717,47 @@ rte_kni_unregister_handlers(struct rte_kni *kni) return 0; } + +int __rte_experimental +rte_kni_update_link(struct rte_kni *kni, unsigned int linkup) +{ + char path[64]; + char old_carrier[2]; + const char *new_carrier; + int old_linkup; + int fd, ret; + + if (kni == NULL) + return -1; + + snprintf(path, sizeof(path), "/sys/devices/virtual/net/%s/carrier", + kni->name); + + fd = open(path, O_RDWR); + if (fd == -1) { + RTE_LOG(ERR, KNI, "Failed to open file: %s.\n", path); + return -1; + } + + ret = read(fd, old_carrier, 2); + if (ret < 1) { + close(fd); + return -1; + } + old_linkup = (old_carrier[0] == '1'); + + new_carrier = linkup ? "1" : "0"; + ret = write(fd, new_carrier, 1); + if (ret < 1) { + RTE_LOG(ERR, KNI, "Failed to write file: %s.\n", path); + close(fd); + return -1; + } + + close(fd); + return old_linkup; +} + void rte_kni_close(void) { diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index 601abdfc6..02ca43b4b 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -232,6 +232,26 @@ int rte_kni_register_handlers(struct rte_kni *kni, struct rte_kni_ops *ops); */ int rte_kni_unregister_handlers(struct rte_kni *kni); +/** + * Update link carrier state for KNI port. + * + * Update the linkup/linkdown state of a KNI interface in the kernel. + * + * @param kni + * pointer to struct rte_kni. + * @param linkup + * New link state: + * 0 for linkdown. + * > 0 for linkup. + * + * @return + * On failure: -1 + * Previous link state == linkdown: 0 + * Previous link state == linkup: 1 + */ +int __rte_experimental +rte_kni_update_link(struct rte_kni *kni, unsigned int linkup); + /** * Close KNI device. */ diff --git a/lib/librte_kni/rte_kni_version.map b/lib/librte_kni/rte_kni_version.map index acd515eb0..c877dc6aa 100644 --- a/lib/librte_kni/rte_kni_version.map +++ b/lib/librte_kni/rte_kni_version.map @@ -15,3 +15,9 @@ DPDK_2.0 { local: *; }; + +EXPERIMENTAL { + global: + + rte_kni_update_link; +}; diff --git a/test/test/test_kni.c b/test/test/test_kni.c index cf64c0b27..e38206905 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) { -- 2.19.0