From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0929.ocn.ad.jp (mogw0929.ocn.ad.jp [153.149.227.35]) by dpdk.org (Postfix) with ESMTP id 9B0D61B6DC for ; Mon, 29 Jan 2018 13:47:28 +0100 (CET) Received: from mf-smf-ucb008.ocn.ad.jp (mf-smf-ucb008.ocn.ad.jp [153.149.227.68]) by mogw0929.ocn.ad.jp (Postfix) with ESMTP id 27FCDC80239; Mon, 29 Jan 2018 21:47:27 +0900 (JST) Received: from mf-smf-ucb008.ocn.ad.jp (mf-smf-ucb008 [153.149.227.68]) by mf-smf-ucb008.ocn.ad.jp (Postfix) with ESMTP id 0E1F31202C5; Mon, 29 Jan 2018 21:47:27 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb028 (mv-mta-ucb028.ocn.ad.jp [153.149.230.162]) by mf-smf-ucb008.ocn.ad.jp (Switch-3.3.4/Switch-3.3.4) with ESMTP id w0TClQUX006753; Mon, 29 Jan 2018 21:47:26 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.166]) by ntt.pod01.mv-mta-ucb028 with id 4CnS1x0053c2f7501CnSfi; Mon, 29 Jan 2018 12:47:26 +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:47:26 +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:47:31 +0900 Message-Id: <20180129122506.75403-3-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 X-Account-Key: account3 X-UIDL: 8764.5LpQDhvHwHykR98s3DTw4BStcBo= X-Mozilla-Status: 0001 Received: from mzcmta028.ocn.ad.jp (LHLO mzcmta028.ocn.ad.jp) (153.149.235.162) by mzcstore251.ocn.ad.jp with LMTP; Mon, 29 Jan 2018 21:24:46 +0900 (JST) Received: from mfgw711.ocn.ad.jp (mfgw711.ocn.ad.jp [153.153.63.100]) by mzcmta028.ocn.ad.jp (Postfix) with ESMTP id 98B5F373005C for ; Mon, 29 Jan 2018 21:24:46 +0900 (JST) Received-SPF: softfail (mf-ofc-ucb071: domain of transitioning dose not designate client-ip as permitted sender) client-ip=153.149.231.27; envelope-from=; helo=mogw1021.ocn.ad.jp; Authentication-Results: mf-ofc-ucb071; spf=softfail smtp.mailfrom=ogawa.yasufumi@lab.ntt.co.jp Received: from mogw1021.ocn.ad.jp (mogw1021.ocn.ad.jp [153.149.231.27]) by mfgw711.ocn.ad.jp (Postfix) with ESMTP id 782BC500287 for ; Mon, 29 Jan 2018 21:24:46 +0900 (JST) Received: from mf-smf-ucb028c3 (mf-smf-ucb028c3.ocn.ad.jp [153.153.66.174]) by mogw1021.ocn.ad.jp (Postfix) with ESMTP id 6BD801180210; Mon, 29 Jan 2018 21:24:46 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb029 ([153.149.230.163]) by mf-smf-ucb028c3 with ESMTP id g8UOemRCdInaig8UQexzTM; Mon, 29 Jan 2018 21:24:46 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.133]) by ntt.pod01.mv-mta-ucb029 with id 4CQm1x0032tKTyH01CQmX9; Mon, 29 Jan 2018 12:24:46 +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:46 +0900 (JST) X-Mailer: git-send-email 2.13.1 In-Reply-To: <20180129122506.75403-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20180129122506.75403-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH 3/3] spp_vm: 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:47:29 -0000 From: ogawa.yasufumi@lab.ntt.co.jp From: Yasufumi Ogawa This patch is same as commit e338799 for spp_nfv. It 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/vm/main.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 5 deletions(-) diff --git a/src/vm/main.c b/src/vm/main.c index c9f1571..52f381f 100644 --- a/src/vm/main.c +++ b/src/vm/main.c @@ -49,6 +49,47 @@ static struct port_map port_map[RTE_MAX_ETHPORTS]; 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; +} + static void forward(void) { @@ -406,7 +447,8 @@ parse_command(char *str) i = sprintf(str, "Client ID %d Running\n", client_id); else i = sprintf(str, "Client ID %d Idling\n", client_id); - print_active_ports(str + i, client_id, ports_fwd_array, port_map); + print_active_ports( + str+i, client_id, ports_fwd_array, port_map); } else if (!strcmp(token_list[0], "_get_client_id")) { memset(str, '\0', MSG_SIZE); @@ -452,10 +494,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[2], &out_port) < 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 (in_port < 0 || out_port < 0) return 0; add_patch(in_port, out_port); -- 2.7.4