From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bcmv-tmail01.ecl.ntt.co.jp (bcmv-tmail01.ecl.ntt.co.jp [124.146.185.148]) by dpdk.org (Postfix) with ESMTP id 622611B4C6 for ; Tue, 9 Oct 2018 12:49:00 +0200 (CEST) Received: from bcmv-ns01.ecl.ntt.co.jp (bcmv-ns01.ecl.ntt.co.jp [129.60.83.123]) by bcmv-tmail01.ecl.ntt.co.jp (8.14.4/8.14.4) with ESMTP id w99AmwQ9017774; Tue, 9 Oct 2018 19:48:58 +0900 Received: from bcmv-ns01.ecl.ntt.co.jp (localhost [127.0.0.1]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id B41B3125; Tue, 9 Oct 2018 19:48:58 +0900 (JST) Received: from localhost.localdomain (unknown [129.60.13.51]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id 9CB0B119; Tue, 9 Oct 2018 19:48:58 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Tue, 9 Oct 2018 19:48:45 +0900 Message-Id: <20181009104847.42502-3-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20181009104847.42502-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20181009104847.42502-1-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH 2/4] spp_nfv: change to use parse_resource_uid 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: , X-List-Received-Date: Tue, 09 Oct 2018 10:49:00 -0000 From: Yasufumi Ogawa To simplify parsing resource UID, replace spp_split() to parse_resource_uid(). spp_split() is removed because it is not needed anymore. Signed-off-by: Yasufumi Ogawa --- src/nfv/nfv.c | 143 ++++++++++++++++------------------------------------------ 1 file changed, 40 insertions(+), 103 deletions(-) diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c index f036f62..0ccabac 100644 --- a/src/nfv/nfv.c +++ b/src/nfv/nfv.c @@ -57,24 +57,6 @@ static enum port_type get_port_type(char *portname) } /* - * Split a token into words with given separator and return the number of - * splitted words. - */ -static int spp_split(char *splitted_words[], char *token, const char *sep) -{ - int cnt = 0; - splitted_words[cnt] = strtok(token, sep); - while (splitted_words[cnt] != NULL) { - RTE_LOG(DEBUG, APP, "token %d = %s\n", - cnt, splitted_words[cnt]); - cnt++; - splitted_words[cnt] = strtok(NULL, sep); - } - return cnt; -} - - -/* * print a usage message */ static void @@ -303,53 +285,42 @@ find_port_id(int id, enum port_type type) } static int -do_del(char *token_list[], int max_token) +do_del(char *res_uid) { int port_id = PORT_RESET; - int id; + char *p_type; + int p_id; - if (max_token <= 2) - return -1; - - if (!strcmp(token_list[1], "vhost")) { - if (spp_atoi(token_list[2], &id) < 0) - return 0; + parse_resource_uid(res_uid, &p_type, &p_id); - port_id = find_port_id(id, VHOST); + if (!strcmp(p_type, "vhost")) { + port_id = find_port_id(p_id, VHOST); if (port_id < 0) return -1; - } else if (!strcmp(token_list[1], "ring")) { + } else if (!strcmp(p_type, "ring")) { char name[RTE_ETH_NAME_MAX_LEN]; - if (spp_atoi(token_list[2], &id) < 0) - return 0; - - port_id = find_port_id(id, RING); + RTE_LOG(DEBUG, APP, "Del ring id %d\n", p_id); + port_id = find_port_id(p_id, RING); if (port_id < 0) return -1; rte_eth_dev_detach(port_id, name); - } else if (!strcmp(token_list[1], "pcap")) { + } else if (!strcmp(p_type, "pcap")) { char name[RTE_ETH_NAME_MAX_LEN]; - if (spp_atoi(token_list[2], &id) < 0) - return 0; - - port_id = find_port_id(id, PCAP); + port_id = find_port_id(p_id, PCAP); if (port_id < 0) return -1; rte_eth_dev_detach(port_id, name); - } else if (!strcmp(token_list[1], "nullpmd")) { + } else if (!strcmp(p_type, "nullpmd")) { char name[RTE_ETH_NAME_MAX_LEN]; - if (spp_atoi(token_list[2], &id) < 0) - return 0; - - port_id = find_port_id(id, NULLPMD); + port_id = find_port_id(p_id, NULLPMD); if (port_id < 0) return -1; @@ -667,51 +638,44 @@ add_null_pmd(int index) return null_pmd_port_id; } +/** + * Add a port to this process. Port is described with resource UID which is a + * combination of port type and ID like as 'ring:0'. + */ static int -do_add(char *token_list[], int max_token) +do_add(char *res_uid) { enum port_type type = UNDEF; int port_id = PORT_RESET; - int id; - if (max_token <= 2) - return -1; + char *p_type; + int p_id; - if (!strcmp(token_list[1], "vhost")) { - if (spp_atoi(token_list[2], &id) < 0) - return 0; + parse_resource_uid(res_uid, &p_type, &p_id); + if (!strcmp(p_type, "vhost")) { type = VHOST; - port_id = add_vhost_pmd(id); - - } else if (!strcmp(token_list[1], "ring")) { - if (spp_atoi(token_list[2], &id) < 0) - return 0; + port_id = add_vhost_pmd(p_id); + } else if (!strcmp(p_type, "ring")) { type = RING; - port_id = add_ring_pmd(id); - - } else if (!strcmp(token_list[1], "pcap")) { - if (spp_atoi(token_list[2], &id) < 0) - return 0; + port_id = add_ring_pmd(p_id); + } else if (!strcmp(p_type, "pcap")) { type = PCAP; - port_id = add_pcap_pmd(id); - - } else if (!strcmp(token_list[1], "nullpmd")) { - if (spp_atoi(token_list[2], &id) < 0) - return 0; + port_id = add_pcap_pmd(p_id); + } else if (!strcmp(p_type, "nullpmd")) { type = NULLPMD; - port_id = add_null_pmd(id); + port_id = add_null_pmd(p_id); } if (port_id < 0) return -1; - port_map[port_id].id = id; + port_map[port_id].id = p_id; port_map[port_id].port_type = type; - port_map[port_id].stats = &ports->client_stats[id]; + port_map[port_id].stats = &ports->client_stats[p_id]; /* Update ports_fwd_array with port id */ ports_fwd_array[port_id].in_port_id = port_id; @@ -777,7 +741,7 @@ parse_command(char *str) } else if (!strcmp(token_list[0], "add")) { RTE_LOG(DEBUG, APP, "add\n"); - do_add(token_list, max_token); + do_add(token_list[1]); } else if (!strcmp(token_list[0], "patch")) { RTE_LOG(DEBUG, APP, "patch\n"); @@ -795,41 +759,14 @@ parse_command(char *str) if (max_token <= 2) return 0; - if (spp_atoi(token_list[1], &in_port) < 0) { - char *param_list[MAX_PARAMETER] = { 0 }; - int param_count = spp_split( - param_list, token_list[1], ":"); - if (param_count == 2) { - int in_port_id; - if (spp_atoi( - param_list[1], &in_port_id) < 0) - return 0; - in_port = find_port_id( - in_port_id, - get_port_type(param_list[0])); - } else { - return 0; - } - } + char *p_type; + int p_id; - if (spp_atoi(token_list[2], &out_port) < 0) { - char *param_list[MAX_PARAMETER] = { 0 }; - int param_count = spp_split( - param_list, - token_list[2], ":"); - if (param_count == 2) { - int out_port_id; - if (spp_atoi( - param_list[1], - &out_port_id) < 0) - return 0; - out_port = find_port_id( - out_port_id, - get_port_type(param_list[0])); - } else { - return 0; - } - } + parse_resource_uid(token_list[1], &p_type, &p_id); + in_port = find_port_id(p_id, get_port_type(p_type)); + + parse_resource_uid(token_list[2], &p_type, &p_id); + out_port = find_port_id(p_id, get_port_type(p_type)); if (in_port < 0 || out_port < 0) return 0; @@ -841,7 +778,7 @@ parse_command(char *str) RTE_LOG(DEBUG, APP, "del\n"); cmd = STOP; - do_del(token_list, max_token); + do_del(token_list[1]); } return ret; -- 2.7.4