* [spp] [PATCH 0/4] Port management with resource UID
@ 2018-10-09 10:48 ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 1/4] shared: add parsing " ogawa.yasufumi
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:48 UTC (permalink / raw)
To: spp, ferruh.yigit, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Resource UID (called resource ID previously) consists of port type and
port ID was introduced to specify a port. For example, users can patch
ports as following.
spp > sec 1; patch phy:0 ring:0 # instead of 'patch 0 1'
However, add and del commands are still remained using old style of
resource UID.
spp > sec 1; add ring 0 # should be updated to 'add ring:0'
This series of patches is to update the usage of resource UID.
* Add a common function parse_resource_uid() to extract port type and ID
from resource UID.
* Update spp_nfv and spp_vm to use parse_resource_uid().
* Update add and del command in SPP controller to use the latest style
of resource UID.
Yasufumi Ogawa (4):
shared: add parsing resource UID
spp_nfv: change to use parse_resource_uid
spp_vm: change to use parse_resource_uid
controller: unify accepting resource UID format
src/controller/shell.py | 16 ++++--
src/nfv/nfv.c | 143 ++++++++++++++----------------------------------
src/shared/common.c | 24 ++++++++
src/shared/common.h | 1 +
src/vm/main.c | 103 ++++++++++------------------------
5 files changed, 104 insertions(+), 183 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [spp] [PATCH 1/4] shared: add parsing resource UID
2018-10-09 10:48 [spp] [PATCH 0/4] Port management with resource UID ogawa.yasufumi
@ 2018-10-09 10:48 ` ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 2/4] spp_nfv: change to use parse_resource_uid ogawa.yasufumi
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:48 UTC (permalink / raw)
To: spp, ferruh.yigit, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Resource UID is defined as a combination of port type and ID, and
separated with ':' such as 'ring:0'. This patch is to add a utility
function parse_resource_uid() to extract port type and ID.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/shared/common.c | 24 ++++++++++++++++++++++++
src/shared/common.h | 1 +
2 files changed, 25 insertions(+)
diff --git a/src/shared/common.c b/src/shared/common.c
index 56f89df..56ef8c5 100644
--- a/src/shared/common.c
+++ b/src/shared/common.c
@@ -217,6 +217,30 @@ parse_server(char **server_ip, int *server_port, char *server_addr)
return 0;
}
+/**
+ * Retieve port type and ID from resource UID. For example, resource UID
+ * 'ring:0' is parsed to retrieve port tyep 'ring' and ID '0'.
+ */
+int
+parse_resource_uid(char *str, char **port_type, int *port_id)
+{
+ char *token;
+ char delim[] = ":";
+ char *endp;
+
+ *port_type = strtok(str, delim);
+
+ token = strtok(NULL, delim);
+ *port_id = strtol(token, &endp, 10);
+
+ if (*endp) {
+ RTE_LOG(ERR, APP, "Bad integer value: %s\n", str);
+ return -1;
+ }
+
+ return 0;
+}
+
int
spp_atoi(const char *str, int *val)
{
diff --git a/src/shared/common.h b/src/shared/common.h
index 52a9a65..1580b08 100644
--- a/src/shared/common.h
+++ b/src/shared/common.h
@@ -196,6 +196,7 @@ void get_sec_stats_json(char *str, const char *running_stat,
struct port *ports_fwd_array,
struct port_map *port_map);
+int parse_resource_uid(char *str, char **port_type, int *port_id);
int spp_atoi(const char *str, int *val);
#define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
--
2.7.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [spp] [PATCH 2/4] spp_nfv: change to use parse_resource_uid
2018-10-09 10:48 [spp] [PATCH 0/4] Port management with resource UID ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 1/4] shared: add parsing " ogawa.yasufumi
@ 2018-10-09 10:48 ` ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 3/4] spp_vm: " ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 4/4] controller: unify accepting resource UID format ogawa.yasufumi
3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:48 UTC (permalink / raw)
To: spp, ferruh.yigit, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
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 <ogawa.yasufumi@lab.ntt.co.jp>
---
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [spp] [PATCH 3/4] spp_vm: change to use parse_resource_uid
2018-10-09 10:48 [spp] [PATCH 0/4] Port management with resource UID ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 1/4] shared: add parsing " ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 2/4] spp_nfv: change to use parse_resource_uid ogawa.yasufumi
@ 2018-10-09 10:48 ` ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 4/4] controller: unify accepting resource UID format ogawa.yasufumi
3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:48 UTC (permalink / raw)
To: spp, ferruh.yigit, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
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 <ogawa.yasufumi@lab.ntt.co.jp>
---
src/vm/main.c | 103 +++++++++++++++++-----------------------------------------
1 file changed, 29 insertions(+), 74 deletions(-)
diff --git a/src/vm/main.c b/src/vm/main.c
index 4f3511b..c32faaf 100644
--- a/src/vm/main.c
+++ b/src/vm/main.c
@@ -44,23 +44,6 @@ static enum port_type get_port_type(char *portname)
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)
{
@@ -242,22 +225,19 @@ 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;
+ parse_resource_uid(res_uid, &p_type, &p_id);
- if (!strcmp(token_list[1], "ring")) {
+ if (!strcmp(p_type, "ring")) {
char name[RTE_ETH_NAME_MAX_LEN];
- if (spp_atoi(token_list[2], &id) < 0)
- return 0;
-
- RTE_LOG(DEBUG, APP, "Del ring id %d\n", id);
- 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;
@@ -360,30 +340,32 @@ add_ring_pmd(int ring_id)
return ring_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], "ring")) {
- if (spp_atoi(token_list[2], &id) < 0)
- return 0;
+ parse_resource_uid(res_uid, &p_type, &p_id);
+ if (!strcmp(p_type, "ring")) {
type = RING;
- port_id = add_ring_pmd(id);
+ port_id = add_ring_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;
@@ -449,7 +431,7 @@ parse_command(char *str)
} else if (strncmp(token_list[0], "add", 3) == 0) {
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");
@@ -467,41 +449,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;
- }
- }
-
- 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;
- }
- }
+ char *p_type;
+ int p_id;
+
+ 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;
@@ -512,7 +467,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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [spp] [PATCH 4/4] controller: unify accepting resource UID format
2018-10-09 10:48 [spp] [PATCH 0/4] Port management with resource UID ogawa.yasufumi
` (2 preceding siblings ...)
2018-10-09 10:48 ` [spp] [PATCH 3/4] spp_vm: " ogawa.yasufumi
@ 2018-10-09 10:48 ` ogawa.yasufumi
3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:48 UTC (permalink / raw)
To: spp, ferruh.yigit, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Delimiter of resource UID is different between patch command and add/del
commands.
spp > sec 1;add ring 0 # separated with ' '
spp > sec 1;patch ring:0 ring:1 # separated with ':'
It should be same format because confusing. This update is to change
add/del commands to use delimiter ':'.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/shell.py | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 2808440..09b9e86 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -249,7 +249,7 @@ class Shell(cmd.Cmd, object):
def is_patched_ids_valid(self, id1, id2, delim=':'):
"""Check if port IDs are valid
- Supported format is port ID of integer or resource ID such as
+ Supported format is port ID of integer or resource UID such as
'phy:0' or 'ring:1'. Default delimiter ':' can be overwritten
by giving 'delim' option.
"""
@@ -279,17 +279,21 @@ class Shell(cmd.Cmd, object):
if length == 1:
if cmdlist[0] in level1:
valid = 1
+
elif length == 2:
if cmdlist[0] == 'patch':
if cmdlist[1] in patch_args:
valid = 1
+
+ elif cmdlist[0] == 'add' or cmdlist[0] == 'del':
+ p_type, p_id = cmdlist[1].split(':')
+ if p_type in add_del_args:
+ if str.isdigit(p_id):
+ valid = 1
+
elif length == 3:
if cmdlist[0] in level2:
- if cmdlist[0] == 'add' or cmdlist[0] == 'del':
- if cmdlist[1] in add_del_args:
- if str.isdigit(cmdlist[2]):
- valid = 1
- elif cmdlist[0] == 'patch':
+ if cmdlist[0] == 'patch':
if self.is_patched_ids_valid(cmdlist[1], cmdlist[2]):
valid = 1
--
2.7.4
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-10-09 10:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-09 10:48 [spp] [PATCH 0/4] Port management with resource UID ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 1/4] shared: add parsing " ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 2/4] spp_nfv: change to use parse_resource_uid ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 3/4] spp_vm: " ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 4/4] controller: unify accepting resource UID format ogawa.yasufumi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).