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 7E3CC1B4C6 for ; Tue, 9 Oct 2018 12:48:59 +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 w99AmvMi017771; Tue, 9 Oct 2018 19:48:57 +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 DBE82125; Tue, 9 Oct 2018 19:48:57 +0900 (JST) Received: from localhost.localdomain (unknown [129.60.13.51]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id C58B2119; Tue, 9 Oct 2018 19:48:57 +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:44 +0900 Message-Id: <20181009104847.42502-2-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 1/4] shared: add parsing 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 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 --- 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