From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0728.ocn.ad.jp (mogw0728.ocn.ad.jp [153.149.232.29]) by dpdk.org (Postfix) with ESMTP id EEBCF1B6E0 for ; Mon, 29 Jan 2018 13:44:10 +0100 (CET) Received: from mf-smf-ucb028c1 (mf-smf-ucb028c1.ocn.ad.jp [153.153.66.172]) by mogw0728.ocn.ad.jp (Postfix) with ESMTP id 84D83E0023A; Mon, 29 Jan 2018 21:44:08 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb028 ([153.149.230.162]) by mf-smf-ucb028c1 with ESMTP id g8nAe49bbxhbHg8nAelTuq; Mon, 29 Jan 2018 21:44:08 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.134]) by ntt.pod01.mv-mta-ucb028 with id 4Ck81x0042ud8JZ01Ck8iN; Mon, 29 Jan 2018 12:44:08 +0000 Received: from localhost.localdomain (sp49-97-108-252.msc.spmode.ne.jp [49.97.108.252]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Mon, 29 Jan 2018 21:44:08 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, geminoa@juno.ocn.ne.jp Cc: ogawa.yasufumi@lab.ntt.co.jp Date: Mon, 29 Jan 2018 21:44:01 +0900 Message-Id: <20180129122506.75403-1-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 X-Account-Key: account3 X-UIDL: 8765.NR8hYCcPkCs1vk7LF8KJ2tYNwBc= X-Mozilla-Status: 0000 Received: from mzcmta022.ocn.ad.jp (LHLO mzcmta022.ocn.ad.jp) (180.8.110.197) by mzcstore251.ocn.ad.jp with LMTP; Mon, 29 Jan 2018 21:24:46 +0900 (JST) Received: from mfgw692.ocn.ad.jp (mfgw692.ocn.ad.jp [153.153.63.102]) by mzcmta022.ocn.ad.jp (Postfix) with ESMTP id B314BD0AAF for ; Mon, 29 Jan 2018 21:24:46 +0900 (JST) Received-SPF: softfail (mf-ofc-ucb069: domain of transitioning dose not designate client-ip as permitted sender) client-ip=153.149.234.31; envelope-from=; helo=mogw0830.ocn.ad.jp; Authentication-Results: mf-ofc-ucb069; spf=softfail smtp.mailfrom=ogawa.yasufumi@lab.ntt.co.jp Received: from mogw0830.ocn.ad.jp (mogw0830.ocn.ad.jp [153.149.234.31]) by mfgw692.ocn.ad.jp (Postfix) with ESMTP id D7032A8026B for ; Mon, 29 Jan 2018 21:24:45 +0900 (JST) Received: from mf-smf-ucb027c3 (mf-smf-ucb027c3.ocn.ad.jp [153.153.66.171]) by mogw0830.ocn.ad.jp (Postfix) with ESMTP id B44A340023B; Mon, 29 Jan 2018 21:24:45 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb026 ([153.149.142.100]) by mf-smf-ucb027c3 with ESMTP id g8UNet5UGTK7Hg8UPe7LGx; Mon, 29 Jan 2018 21:24:45 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.133]) by ntt.pod01.mv-mta-ucb026 with id 4CQl1x0042tKTyH01CQl9M; Mon, 29 Jan 2018 12:24:45 +0000 Received: from localhost.localdomain (sp49-97-108-252.msc.spmode.ne.jp [49.97.108.252]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Mon, 29 Jan 2018 21:24:45 +0900 (JST) X-Mailer: git-send-email 2.13.1 Subject: [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID 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: Mon, 29 Jan 2018 12:44:11 -0000 From: ogawa.yasufumi@lab.ntt.co.jp From: Yasufumi Ogawa In spp, port ID is assigned as a number incrementally and the number of ID can be different from each sec processes. It depends on the order of adding ports. It is confusing to users for patching because each of sec processes has different port IDs but they refer the same resource. It might cause a mistake. This update enables users to patch ports with a combination of port type and number to identify resources as following. spp> sec 1;patch phy:0 ring:0 Signed-off-by: Yasufumi Ogawa --- src/nfv/nfv.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c index 5972657..d62626c 100644 --- a/src/nfv/nfv.c +++ b/src/nfv/nfv.c @@ -59,6 +59,48 @@ struct port_info *ports; static struct port ports_fwd_array[RTE_MAX_ETHPORTS]; +/* 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 = NULL, .port_type = UNDEF, }, +}; + +/* Return a type of port as a enum member of porttype_map structure. */ +static enum port_type get_port_type(char *portname) +{ + for (int 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; +} + +/* + * 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 */ @@ -555,10 +597,43 @@ parse_command(char *str) if (max_token <= 2) return 0; - if (spp_atoi(token_list[1], &in_port) < 0) - 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; + } + } + + 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; + } + } - if (spp_atoi(token_list[2], &out_port) < 0) + if (in_port < 0 || out_port < 0) return 0; add_patch(in_port, out_port); -- 2.7.4