From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 86D32A2EFC for ; Mon, 14 Oct 2019 20:45:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 800771C11B; Mon, 14 Oct 2019 20:45:40 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 7187E1C11B for ; Mon, 14 Oct 2019 20:45:39 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id t3so10581533pga.8 for ; Mon, 14 Oct 2019 11:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=oy4Z2i1/Na4y2iRuMXGgUufeCmuzGoUD9Z6SX+M1mNc=; b=Secq3Luec0eh6uoXBV+5TKP2Rs+U6UCnHdE5FQD90sHaZiGk6uIC5Poho7hpXz3ptX hbeRjMUIAqbQIgtLFC0Iq6m/dtUHUIpL8+McDXi0J5em9EfO1UnnCD8tjCY0pUEur77j k9GrQkcqZRErU+teNe3E9G0AsFFfAbJ9NIfFoX6OUUqHA7CqVXF7H+A8+iybSEm+DtAj ucJTtEq4qvTS965fOULW3HXvJIF+ZRSGqFzg2+/Cl++zupxlhdjKL9vqsaE9NJkoRprY pd83QxBELI0zsqnWJP7qhZkMFfy+tEzMctYCVenCDOTOZkOhHXPjxFTlJqDPx7XwxWOk JSsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=oy4Z2i1/Na4y2iRuMXGgUufeCmuzGoUD9Z6SX+M1mNc=; b=aZX4F7x1yb5dzjsxnMOoCjlQwa73XD11v3nR4V540QtxkIcrHqHaAt+MiBM9rPJ/dQ nqmJ6MG2oE0cn3SPXeKYt5zYCRmdVJtijAAm7j98iK+wcezFd6EpxoGBTuDVtiQ5RS+B N8QA6SlCzFKGoUMwCnQMAc4JTMMmgLtTKX+VnAUSm7lPZLAoqvYQTWXUjeINab+5rDnj KimT5kkYa/ddNhp2C6LfE5jQUbL1pxPvn/sjFuedorNb7sWQqv5JIjDDVB3ngMbgQvxz G0MK7rZrgmsxsMiOmfhWMrRMZ11fAhIl1QW7k8JzjvAVUr+eiKC5rOXWXVgihhmzINZS 0Rlw== X-Gm-Message-State: APjAAAWvDMLOyPmkEKwo492PWlCbuwah3MUv8x8cjH/3A4Pdt5ncq5OQ H+et6TBG/3Oa/VwRPxo41hfGNcUKuM0= X-Google-Smtp-Source: APXvYqyRN/cIVyXcic7Y6xzTGTECI7moJCOQYugBm3N0InfsZ4k4q2n0+/P2nJE3wxw3hxhwn5xDdw== X-Received: by 2002:a65:4907:: with SMTP id p7mr34990769pgs.429.1571078738286; Mon, 14 Oct 2019 11:45:38 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c8c2:de00:9046:90d6:77b7:3115]) by smtp.gmail.com with ESMTPSA id 207sm24013804pfu.129.2019.10.14.11.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 11:45:37 -0700 (PDT) From: Yasufumi Ogawa To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Tue, 15 Oct 2019 03:45:33 +0900 Message-Id: <20191014184533.27001-1-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [spp] [PATCH] spp_nfv: move funcs for managing ports to shared X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: spp-bounces@dpdk.org Sender: "spp" This update is to move structs and functions for managing ports to shared lib because enable to be used from other processes including spp_primary. Signed-off-by: Yasufumi Ogawa --- src/nfv/Makefile | 2 +- src/nfv/init.h | 34 -------- src/nfv/main.c | 12 +-- src/nfv/params.h | 16 ---- src/shared/basic_forwarder.h | 6 +- src/shared/port_manager.c | 158 +++++++++++++++++++++++++++++++++++ src/shared/port_manager.h | 117 ++++---------------------- 7 files changed, 185 insertions(+), 160 deletions(-) create mode 100644 src/shared/port_manager.c diff --git a/src/nfv/Makefile b/src/nfv/Makefile index a8b5629..c3d2806 100644 --- a/src/nfv/Makefile +++ b/src/nfv/Makefile @@ -14,7 +14,7 @@ APP = spp_nfv # all source are stored in SRCS-y SRCS-y := main.c nfv_status.c -SRCS-y += ../shared/common.c ../shared/basic_forwarder.c +SRCS-y += ../shared/common.c ../shared/basic_forwarder.c ../shared/port_manager.c SRCS-y += ../shared/secondary/common.c SRCS-y += ../shared/secondary/utils.c ../shared/secondary/add_port.c diff --git a/src/nfv/init.h b/src/nfv/init.h index 0702082..7d28755 100644 --- a/src/nfv/init.h +++ b/src/nfv/init.h @@ -6,39 +6,5 @@ #ifndef _NFV_INIT_H_ #define _NFV_INIT_H_ -static void -forward_array_init_one(unsigned int i) -{ - ports_fwd_array[i].in_port_id = PORT_RESET; - ports_fwd_array[i].out_port_id = PORT_RESET; -} - -/* initialize forward array with default value*/ -static void -forward_array_init(void) -{ - unsigned int i; - - /* initialize port forward array*/ - for (i = 0; i < RTE_MAX_ETHPORTS; i++) - forward_array_init_one(i); -} - -static void -port_map_init_one(unsigned int i) -{ - port_map[i].id = PORT_RESET; - port_map[i].port_type = UNDEF; - port_map[i].stats = &port_map[i].default_stats; -} - -static void -port_map_init(void) -{ - unsigned int i; - - for (i = 0; i < RTE_MAX_ETHPORTS; i++) - port_map_init_one(i); -} #endif diff --git a/src/nfv/main.c b/src/nfv/main.c index ac82139..047d4c1 100644 --- a/src/nfv/main.c +++ b/src/nfv/main.c @@ -30,13 +30,13 @@ static sig_atomic_t on = 1; uint8_t lcore_id_used[RTE_MAX_LCORE] = {}; +/* + * Long options mapped to a short option. + * + * First long only option value must be >= 256, so that we won't + * conflict with short options. + */ enum { - /* - * Long options mapped to a short option. - * - * First long only option value must be >= 256, so that we won't - * conflict with short options. - */ CMD_LINE_OPT_MIN_NUM = 256, CMD_OPT_ENABLE_VHOST_CLI, }; diff --git a/src/nfv/params.h b/src/nfv/params.h index 7197baf..7529452 100644 --- a/src/nfv/params.h +++ b/src/nfv/params.h @@ -6,22 +6,6 @@ #ifndef _NFV_PARAMS_H_ #define _NFV_PARAMS_H_ -/* It is used to convert port name from string type to enum */ -struct porttype_map { - const char *port_name; - enum port_type port_type; -}; - -struct porttype_map portmap[] = { - { .port_name = "phy", .port_type = PHY, }, - { .port_name = "ring", .port_type = RING, }, - { .port_name = "vhost", .port_type = VHOST, }, - { .port_name = "pcap", .port_type = PCAP, }, - { .port_name = "nullpmd", .port_type = NULLPMD, }, - { .port_name = "tap", .port_type = TAP, }, - { .port_name = NULL, .port_type = UNDEF, }, -}; - /* the port details */ struct port_info *ports; diff --git a/src/shared/basic_forwarder.h b/src/shared/basic_forwarder.h index 173cab3..2e8225d 100644 --- a/src/shared/basic_forwarder.h +++ b/src/shared/basic_forwarder.h @@ -2,8 +2,10 @@ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation */ -#ifndef __SHARED_FORWARDER_H__ -#define __SHARED_FORWARDER_H__ +#ifndef __SHARED_BASIC_FORWARDER_H__ +#define __SHARED_BASIC_FORWARDER_H__ + +#include "shared/common.h" struct port_map port_map[RTE_MAX_ETHPORTS]; struct port ports_fwd_array[RTE_MAX_ETHPORTS]; diff --git a/src/shared/port_manager.c b/src/shared/port_manager.c new file mode 100644 index 0000000..98d89c2 --- /dev/null +++ b/src/shared/port_manager.c @@ -0,0 +1,158 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation + */ + +#include "shared/port_manager.h" + +struct porttype_map portmap[] = { + { .port_name = "phy", .port_type = PHY, }, + { .port_name = "ring", .port_type = RING, }, + { .port_name = "vhost", .port_type = VHOST, }, + { .port_name = "pcap", .port_type = PCAP, }, + { .port_name = "nullpmd", .port_type = NULLPMD, }, + { .port_name = "tap", .port_type = TAP, }, + { .port_name = NULL, .port_type = UNDEF, }, +}; + +void +forward_array_init_one(unsigned int i) +{ + ports_fwd_array[i].in_port_id = PORT_RESET; + ports_fwd_array[i].out_port_id = PORT_RESET; +} + +/* initialize forward array with default value */ +void +forward_array_init(void) +{ + unsigned int i; + + /* initialize port forward array*/ + for (i = 0; i < RTE_MAX_ETHPORTS; i++) + forward_array_init_one(i); +} + +void +forward_array_reset(void) +{ + unsigned int i; + + /* initialize port forward array*/ + for (i = 0; i < RTE_MAX_ETHPORTS; i++) { + if (ports_fwd_array[i].in_port_id != PORT_RESET) { + ports_fwd_array[i].out_port_id = PORT_RESET; + RTE_LOG(INFO, SHARED, "Port ID %d\n", i); + RTE_LOG(INFO, SHARED, "out_port_id %d\n", + ports_fwd_array[i].out_port_id); + } + } +} + +void +port_map_init_one(unsigned int i) +{ + port_map[i].id = PORT_RESET; + port_map[i].port_type = UNDEF; + port_map[i].stats = &port_map[i].default_stats; +} + +void +port_map_init(void) +{ + unsigned int i; + + for (i = 0; i < RTE_MAX_ETHPORTS; i++) + port_map_init_one(i); +} + +/* Return -1 as an error if given patch is invalid */ +int +add_patch(uint16_t in_port, uint16_t out_port) +{ + if (!is_valid_port(in_port) || !is_valid_port(out_port)) + return -1; + + /* Populate in port data */ + ports_fwd_array[in_port].in_port_id = in_port; + ports_fwd_array[in_port].rx_func = &rte_eth_rx_burst; + ports_fwd_array[in_port].tx_func = &rte_eth_tx_burst; + ports_fwd_array[in_port].out_port_id = out_port; + + /* Populate out port data */ + ports_fwd_array[out_port].in_port_id = out_port; + ports_fwd_array[out_port].rx_func = &rte_eth_rx_burst; + ports_fwd_array[out_port].tx_func = &rte_eth_tx_burst; + + RTE_LOG(DEBUG, SHARED, "STATUS: in port %d in_port_id %d\n", in_port, + ports_fwd_array[in_port].in_port_id); + RTE_LOG(DEBUG, SHARED, "STATUS: in port %d patch out port id %d\n", + in_port, ports_fwd_array[in_port].out_port_id); + RTE_LOG(DEBUG, SHARED, "STATUS: outport %d in_port_id %d\n", out_port, + ports_fwd_array[out_port].in_port_id); + + return 0; +} + +/* + * Return actual port ID which is assigned by system internally, or PORT_RESET + * if port is not found. + */ +uint16_t +find_port_id(int id, enum port_type type) +{ + uint16_t port_id = PORT_RESET; + uint16_t i; + + for (i = 0; i < RTE_MAX_ETHPORTS; i++) { + if (port_map[i].port_type != type) + continue; + + if (port_map[i].id == id) { + port_id = i; + break; + } + } + + return port_id; +} + +/* Return 0 if invalid */ +int +is_valid_port(uint16_t port_id) +{ + if (port_id > RTE_MAX_ETHPORTS) + return 0; + + return port_map[port_id].id != PORT_RESET; +} + +void +forward_array_remove(int port_id) +{ + unsigned int i; + + /* Update ports_fwd_array */ + forward_array_init_one(port_id); + + for (i = 0; i < RTE_MAX_ETHPORTS; i++) { + if (ports_fwd_array[i].in_port_id == PORT_RESET) + continue; + + if (ports_fwd_array[i].out_port_id == port_id) { + ports_fwd_array[i].out_port_id = PORT_RESET; + break; + } + } +} + +/* Return a type of port as a enum member of porttype_map structure. */ +enum port_type get_port_type(char *portname) +{ + int i; + for (i = 0; portmap[i].port_name != NULL; i++) { + const char *port_name = portmap[i].port_name; + if (strncmp(portname, port_name, strlen(port_name)) == 0) + return portmap[i].port_type; + } + return UNDEF; +} diff --git a/src/shared/port_manager.h b/src/shared/port_manager.h index 9756864..c529998 100644 --- a/src/shared/port_manager.h +++ b/src/shared/port_manager.h @@ -10,112 +10,27 @@ #include "shared/basic_forwarder.h" -static void -forward_array_remove(int port_id) -{ - unsigned int i; +/* It is used to convert port name from string type to enum */ +struct porttype_map { + const char *port_name; + enum port_type port_type; +}; - /* Update ports_fwd_array */ - forward_array_init_one(port_id); +/* initialize forward array with default value */ +void forward_array_init_one(unsigned int i); +void forward_array_init(void); +void forward_array_reset(void); +void forward_array_remove(int port_id); - for (i = 0; i < RTE_MAX_ETHPORTS; i++) { - if (ports_fwd_array[i].in_port_id == PORT_RESET) - continue; +void port_map_init_one(unsigned int i); +void port_map_init(void); - if (ports_fwd_array[i].out_port_id == port_id) { - ports_fwd_array[i].out_port_id = PORT_RESET; - break; - } - } -} +enum port_type get_port_type(char *portname); -/* Return 0 if invalid */ -static int -is_valid_port(uint16_t port_id) -{ - if (port_id > RTE_MAX_ETHPORTS) - return 0; +int add_patch(uint16_t in_port, uint16_t out_port); - return port_map[port_id].id != PORT_RESET; -} +uint16_t find_port_id(int id, enum port_type type); -/* - * Return actual port ID which is assigned by system internally, or PORT_RESET - * if port is not found. - */ -static uint16_t -find_port_id(int id, enum port_type type) -{ - uint16_t port_id = PORT_RESET; - uint16_t i; - - for (i = 0; i < RTE_MAX_ETHPORTS; i++) { - if (port_map[i].port_type != type) - continue; - - if (port_map[i].id == id) { - port_id = i; - break; - } - } - - return port_id; -} - -/* Return -1 as an error if given patch is invalid */ -static int -add_patch(uint16_t in_port, uint16_t out_port) -{ - if (!is_valid_port(in_port) || !is_valid_port(out_port)) - return -1; - - /* Populate in port data */ - ports_fwd_array[in_port].in_port_id = in_port; - ports_fwd_array[in_port].rx_func = &rte_eth_rx_burst; - ports_fwd_array[in_port].tx_func = &rte_eth_tx_burst; - ports_fwd_array[in_port].out_port_id = out_port; - - /* Populate out port data */ - ports_fwd_array[out_port].in_port_id = out_port; - ports_fwd_array[out_port].rx_func = &rte_eth_rx_burst; - ports_fwd_array[out_port].tx_func = &rte_eth_tx_burst; - - RTE_LOG(DEBUG, SHARED, "STATUS: in port %d in_port_id %d\n", in_port, - ports_fwd_array[in_port].in_port_id); - RTE_LOG(DEBUG, SHARED, "STATUS: in port %d patch out port id %d\n", - in_port, ports_fwd_array[in_port].out_port_id); - RTE_LOG(DEBUG, SHARED, "STATUS: outport %d in_port_id %d\n", out_port, - ports_fwd_array[out_port].in_port_id); - - return 0; -} - -static void -forward_array_reset(void) -{ - unsigned int i; - - /* initialize port forward array*/ - for (i = 0; i < RTE_MAX_ETHPORTS; i++) { - if (ports_fwd_array[i].in_port_id != PORT_RESET) { - ports_fwd_array[i].out_port_id = PORT_RESET; - RTE_LOG(INFO, SHARED, "Port ID %d\n", i); - RTE_LOG(INFO, SHARED, "out_port_id %d\n", - ports_fwd_array[i].out_port_id); - } - } -} - -/* Return a type of port as a enum member of porttype_map structure. */ -static enum port_type get_port_type(char *portname) -{ - int i; - for (i = 0; portmap[i].port_name != NULL; i++) { - const char *port_name = portmap[i].port_name; - if (strncmp(portname, port_name, strlen(port_name)) == 0) - return portmap[i].port_type; - } - return UNDEF; -} +int is_valid_port(uint16_t port_id); #endif // __SHARED_PORT_MANAGER_H__ -- 2.17.1