Soft Patch Panel
 help / color / mirror / Atom feed
From: x-fn-spp@sl.ntt-tx.co.jp
To: spp@dpdk.org
Subject: [spp] [PATCH 29/57] spp_vf: replace unsupported jansson api
Date: Thu, 28 Dec 2017 13:55:36 +0900	[thread overview]
Message-ID: <201712280456.vBS4u9Qj011233@imss03.silk.ntt-tx.co.jp> (raw)
In-Reply-To: <4aae78ff-3b6c-cdfe-a8b7-24ec08b73935@lab.ntt.co.jp>

From: Hiroyuki Nakamura <nakamura.hioryuki@po.ntt-tx.co.jp>

* Stop using the json_path_get function and replace it with our own
  spp_config_get_path_obj function.
* The json_path_get function is only available at branch of
  Jansson project, and it can not be provided in most of
  the pkgs(deb,rpm). This change made
  for build convenience.

Signed-off-by: Kentaro Watanabe <watanabe.kentaro.z01@as.ntt-tx.co.jp>
Signed-off-by: Yasufum Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/vf/spp_config.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++-------
 src/vf/spp_config.h |  9 +++++++
 2 files changed, 68 insertions(+), 9 deletions(-)

diff --git a/src/vf/spp_config.c b/src/vf/spp_config.c
index 4ad4f87..6d8e380 100644
--- a/src/vf/spp_config.c
+++ b/src/vf/spp_config.c
@@ -25,13 +25,63 @@
 #define JSONPATH_TX_TABLE   "$.tx_port_table"
 
 /*
+ * Instead of json_path_get
+ */
+json_t *
+spp_config_get_path_obj(const json_t *json, const char *path)
+{
+	const json_t *obj, *array_obj;
+	json_t *new_obj = NULL;
+	char buf[SPP_CONFIG_PATH_LEN];
+	char *str, *token, *bracket, *endptr;
+	int index = 0;
+
+	if (unlikely(path[0] != '$') || unlikely(path[1] != '.') ||
+			unlikely(strlen(path) >= SPP_CONFIG_PATH_LEN))
+		return NULL;
+
+	strcpy(buf, path);
+	obj = json;
+	str = buf+1;
+	while(str != NULL) {
+		token = str+1;
+		str = strpbrk(token, ".");
+		if (str != NULL)
+			*str = '\0';
+
+		bracket = strpbrk(token, "[");
+		if (bracket != NULL)
+			*bracket = '\0';
+
+		new_obj = json_object_get(obj, token);
+		if (new_obj == NULL)
+			return NULL;
+
+		if (bracket != NULL) {
+			index = strtol(bracket+1, &endptr, 0);
+			if (unlikely(str == endptr) || unlikely(*endptr != ']'))
+				return NULL;
+
+			array_obj = new_obj;
+			new_obj = json_array_get(array_obj, index);
+			if (new_obj == NULL)
+				return NULL;
+		}
+
+		obj = new_obj;
+	}
+
+	return new_obj;
+}
+
+/*
  * Get integer data from config
  */
 static int
 config_get_int_value(const json_t *obj, const char *path, int *value)
 {
 	/* 指定パラメータのJsonオブジェクト取得 */
-	json_t *tmp_obj = json_path_get(obj, path);
+	json_t *tmp_obj = spp_config_get_path_obj(obj, path);
 	if (unlikely(tmp_obj == NULL)) {
 		/* 必須でないデータを取得する場合を考慮し、DEBUGログとする。 */
 		RTE_LOG(DEBUG, APP, "No parameter. (path = %s)\n", path);
@@ -58,7 +108,7 @@ static int
 config_get_str_value(const json_t *obj, const char *path, char *value)
 {
 	/* 指定パラメータのJsonオブジェクト取得 */
-	json_t *tmp_obj = json_path_get(obj, path);
+	json_t *tmp_obj = spp_config_get_path_obj(obj, path);
 	if (unlikely(tmp_obj == NULL)) {
 		RTE_LOG(DEBUG, APP, "No parameter. (path = %s)\n", path);
 		return -1;
@@ -204,7 +254,7 @@ config_load_classifier_table(const json_t *obj,
 		struct spp_config_classifier_table *classifier_table)
 {
 	/* classifier_table用オブジェクト取得 */
-	json_t *classifier_obj = json_path_get(obj, JSONPATH_CLASSIFIER_TABLE);
+	json_t *classifier_obj = spp_config_get_path_obj(obj, JSONPATH_CLASSIFIER_TABLE);
 	if (unlikely(classifier_obj == NULL)) {
 		RTE_LOG(INFO, APP, "No classifier table.\n");
 		return 0;
@@ -219,7 +269,7 @@ config_load_classifier_table(const json_t *obj,
 	}
 
 	/* table用オブジェクト取得 */
-	json_t *array_obj = json_path_get(classifier_obj, JSONPATH_TABLE);
+	json_t *array_obj = spp_config_get_path_obj(classifier_obj, JSONPATH_TABLE);
 	if (unlikely(!array_obj)) {
 		RTE_LOG(ERR, APP, "Json object get failed. (path = %s)\n",
 				JSONPATH_TABLE);
@@ -338,7 +388,7 @@ config_set_rx_port(enum spp_core_type type, json_t *obj,
 	if (type == SPP_CONFIG_MERGE) {
 		/* Merge */
 		/* 受信ポート用オブジェクト取得 */
-		json_t *array_obj = json_path_get(obj, JSONPATH_RX_PORT);
+		json_t *array_obj = spp_config_get_path_obj(obj, JSONPATH_RX_PORT);
 		if (unlikely(!array_obj)) {
 			RTE_LOG(ERR, APP, "Json object get failed. (path = %s, route = merge)\n",
 				JSONPATH_RX_PORT);
@@ -454,7 +504,7 @@ config_set_tx_port(enum spp_core_type type, json_t *obj,
 		}
 	} else {
 		/* Classifier */
-		json_t *table_obj = json_path_get(obj, JSONPATH_TX_TABLE);
+		json_t *table_obj = spp_config_get_path_obj(obj, JSONPATH_TX_TABLE);
 		if (unlikely(table_obj != NULL)) {
 			/* Classifier Tableから取得 */
 			functions->num_tx_port = classifier_table->num_table;
@@ -473,7 +523,7 @@ config_set_tx_port(enum spp_core_type type, json_t *obj,
 		{
 			/* tx_portパラメータより取得 */
 			/* 送信ポート用オブジェクト取得 */
-			json_t *array_obj = json_path_get(obj, JSONPATH_TX_PORT);
+			json_t *array_obj = spp_config_get_path_obj(obj, JSONPATH_TX_PORT);
 			if (unlikely(array_obj == NULL)) {
 				RTE_LOG(ERR, APP, "Json object get failed. (path = %s, route = classifier)\n",
 					JSONPATH_TX_PORT);
@@ -545,7 +595,7 @@ config_load_proc_info(const json_t *obj, int node_id, struct spp_config_area *co
 	struct spp_config_classifier_table *classifier_table = &config->classifier_table;
 
 	/* proc_table用オブジェクト取得 */
-	json_t *proc_table_obj = json_path_get(obj, JSONPATH_PROC_TABLE);
+	json_t *proc_table_obj = spp_config_get_path_obj(obj, JSONPATH_PROC_TABLE);
 	if (unlikely(proc_table_obj == NULL)) {
 		RTE_LOG(ERR, APP, "Json object get failed. (path = %s)\n",
 				JSONPATH_PROC_TABLE);
@@ -599,7 +649,7 @@ config_load_proc_info(const json_t *obj, int node_id, struct spp_config_area *co
 	}
 
 	/* functions用オブジェクト取得 */
-	json_t *array_obj = json_path_get(proc_obj, JSONPATH_FUNCTIONS);
+	json_t *array_obj = spp_config_get_path_obj(proc_obj, JSONPATH_FUNCTIONS);
 	if (unlikely(!array_obj)) {
 		RTE_LOG(ERR, APP, "Json object get failed. (path = %s)\n",
 				JSONPATH_FUNCTIONS);
diff --git a/src/vf/spp_config.h b/src/vf/spp_config.h
index 37414cf..7945807 100644
--- a/src/vf/spp_config.h
+++ b/src/vf/spp_config.h
@@ -1,6 +1,7 @@
 #ifndef __SPP_CONFIG_H__
 #define __SPP_CONFIG_H__
 
+#include <jansson.h>
 #include "common.h"
 
 #define SPP_CONFIG_FILE_PATH "/usr/local/etc/spp/spp.json"
@@ -12,6 +13,7 @@
 #define SPP_CONFIG_STR_LEN 32
 #define SPP_CONFIG_MAC_TABLE_MAX 16
 #define SPP_CONFIG_CORE_MAX 64
+#define SPP_CONFIG_PATH_LEN 1024
 
 /*
  * Process type for each CORE
@@ -81,6 +83,13 @@ struct spp_config_area {
 };
 
 /*
+ * Instead of json_path_get
+ * OK : Json object address
+ * NG : NULL
+ */
+json_t *spp_config_get_path_obj(const json_t *json, const char *path);
+
+/*
  * Change mac address string to int64
  * OK : int64 that store mac address
  * NG : -1
-- 
1.9.1

  parent reply	other threads:[~2017-12-28  4:56 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-25  4:41 [spp] Proposal - spp_vf(SR-IOV like feature) addition to SPP Nakamura Hioryuki
2017-12-26  1:54 ` Yasufumi Ogawa
2017-12-28  4:55   ` [spp] [PATCH 01/57] spp_vf: add vf functions x-fn-spp
2017-12-28  8:49     ` Yasufumi Ogawa
2017-12-28  4:55   ` [spp] [PATCH 02/57] spp_vf: support multi process x-fn-spp
2018-02-07 16:50     ` Ferruh Yigit
2018-02-08  1:21       ` Yasufumi Ogawa
2018-02-08  6:44       ` [spp] [spp 02168] " Nakamura Hioryuki
2017-12-28  4:55   ` [spp] [PATCH 03/57] spp_vf: comment out check of using cores x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 04/57] spp_vf: modify classifier for upd command x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 05/57] spp_vf: add procedure that mac address is null x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 06/57] spp_vf: change config format for upd command x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 07/57] spp_vf: fix compiler warning in classifier_mac.c x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 08/57] spp_vf: modify data struct for upd command x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 09/57] spp_vf: add functions of command acceptance x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 10/57] spp_vf: add command acceptance calling x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 11/57] spp_vf: fix compiler warning in command_proc.c x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 12/57] " x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 13/57] spp_vf: refactor command acceptance/decode x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 14/57] spp_vf: fix return value overwrite problem x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 15/57] spp_vf: initialize message buffer x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 16/57] spp_vf: add const keyword to parameter x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 17/57] spp_vf: fix wrong comparison operator x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 18/57] spp_vf: fix wrong variable to be assigned x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 19/57] spp_vf: refactor parsing server ip address x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 20/57] spp_vf: fix error in command decode x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 21/57] spp_vf: fix comparison operator in spp_vf.c x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 22/57] spp_vf: check upper limit to the number of process x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 23/57] spp_vf: display usage message x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 24/57] spp_vf: split command processing source file x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 25/57] spp_vf: add new log and line break x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 26/57] spp_vf: support get-process-id command x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 27/57] spp_vf: update socket creation procedure x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 28/57] spp_vf: change log level and add line break x-fn-spp
2017-12-28  4:55   ` x-fn-spp [this message]
2017-12-28  4:55   ` [spp] [PATCH 30/57] spp_vf: change order of command result in json object x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 31/57] spp_vf: use prediction keywords x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 32/57] spp_vf: fix wrong comparison x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 33/57] spp_vf: update sending error status x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 34/57] spp_vf: modify conditional statement x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 35/57] spp_vf: add proc on receiving l2 multicast x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 36/57] spp_vf: extend limit on number of usable cores x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 37/57] spp_vf: add restart procedure for vhost client x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 38/57] spp_vf: fix classifier mbuf handling x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 39/57] spp_vf: add status command x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 40/57] spp_vf: add output source information in error log x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 41/57] spp_vf: change function names x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 42/57] spp_vf: change how to request commands x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 43/57] spp_vf: update command decode procedure x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 44/57] spp_vf: remove debug log output procedures x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 45/57] spp_vf: improve command_decoder program code x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 46/57] spp_vf: fix a bug in status command x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 47/57] spp_vf: add spp_vf.py instead of spp.py x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 48/57] spp_vf: refactor for commnets in spp_vf.c x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 49/57] spp_vf: refactor comments in classifier_mac.c x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 50/57] spp_vf: refactor comments in spp_forward.c x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 51/57] spp_vf: refactor for commnets in spp_config.c x-fn-spp
2017-12-28  4:55   ` [spp] [PATCH 52/57] spp_vf: refactor no self-explanatory comments x-fn-spp
2017-12-28  4:56   ` [spp] [PATCH 53/57] spp_vf: correct typo of function name x-fn-spp
2017-12-28  4:56   ` [spp] [PATCH 54/57] spp_vf: support new command x-fn-spp
2017-12-28  4:56   ` [spp] [PATCH 55/57] spp_vf: add display of status command x-fn-spp
2017-12-28  4:56   ` [spp] [PATCH 56/57] spp_vf: fix " x-fn-spp
2017-12-28  4:56   ` [spp] [PATCH 57/57] spp_vf: fix l2 multicast packet forwarding x-fn-spp
2018-01-15 11:04 ` [spp] Proposal - spp_vf(SR-IOV like feature) addition to SPP Ferruh Yigit
2018-01-16  5:16   ` [spp] [PATCH 01/30] doc: add setup guide x-fn-spp
2018-01-19  0:52     ` Yasufumi Ogawa
2018-01-22 14:37       ` Ferruh Yigit
2018-01-23  0:25         ` Yasufumi Ogawa
2018-01-16  5:16   ` [spp] [PATCH 02/30] doc: add how_to_use.md x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 03/30] doc: add config_manual.md x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 04/30] doc: add spp_vf.md x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 05/30] doc: revise spp_vf.md x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 06/30] doc: add config section x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 07/30] doc: update jp setup manual x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 08/30] doc: modify figure in spp_vf_overview x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 09/30] doc: fix " x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 10/30] doc: fix figure in overview x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 11/30] doc: add sample usage x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 12/30] doc: revice path descs x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 13/30] doc: add network configuration diagram x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 14/30] doc: update user account x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 15/30] doc: update descriptions for todo x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 16/30] doc: add description for explanation section x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 17/30] doc: add spp_sample_usage_svg in docs/spp_vf/ x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 18/30] doc: add explanation for terminating spp app x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 19/30] doc: add explanations on options of spp x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 20/30] doc: update description for the latest spp version x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 21/30] doc: update description on dpdk version x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 22/30] doc: fix vm setup procedure for network config x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 23/30] doc: update jansson installation procedure x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 24/30] doc: fix required network configuration x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 25/30] doc: add how to use vhost-user support x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 26/30] doc: add references to hugepages and isolcpus x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 27/30] doc: remove description on classifier_table x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 28/30] doc: fix typos and erros in texts x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 29/30] doc: update sample config section x-fn-spp
2018-01-16  5:16   ` [spp] [PATCH 30/30] doc: align figure title position x-fn-spp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201712280456.vBS4u9Qj011233@imss03.silk.ntt-tx.co.jp \
    --to=x-fn-spp@sl.ntt-tx.co.jp \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).