get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/45977/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 45977,
    "url": "http://patches.dpdk.org/api/patches/45977/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20181003173612.67101-5-kevin.laatz@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20181003173612.67101-5-kevin.laatz@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20181003173612.67101-5-kevin.laatz@intel.com",
    "date": "2018-10-03T17:36:06",
    "name": "[v2,04/10] telemetry: add parser for client socket messages",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "6ed32f20f3f2868befbd594ead30f3c8f1530075",
    "submitter": {
        "id": 921,
        "url": "http://patches.dpdk.org/api/people/921/?format=api",
        "name": "Kevin Laatz",
        "email": "kevin.laatz@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20181003173612.67101-5-kevin.laatz@intel.com/mbox/",
    "series": [
        {
            "id": 1671,
            "url": "http://patches.dpdk.org/api/series/1671/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1671",
            "date": "2018-10-03T17:36:03",
            "name": "introduce telemetry library",
            "version": 2,
            "mbox": "http://patches.dpdk.org/series/1671/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/45977/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/45977/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 804D41B1F6;\n\tWed,  3 Oct 2018 19:36:31 +0200 (CEST)",
            "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n\tby dpdk.org (Postfix) with ESMTP id 81D641B156\n\tfor <dev@dpdk.org>; Wed,  3 Oct 2018 19:36:28 +0200 (CEST)",
            "from orsmga001.jf.intel.com ([10.7.209.18])\n\tby orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t03 Oct 2018 10:36:25 -0700",
            "from silpixa00397517.ir.intel.com (HELO\n\tsilpixa00397517.ger.corp.intel.com) ([10.237.222.54])\n\tby orsmga001.jf.intel.com with ESMTP; 03 Oct 2018 10:36:22 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.54,336,1534834800\"; d=\"scan'208\";a=\"96182450\"",
        "From": "Kevin Laatz <kevin.laatz@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "harry.van.haaren@intel.com, stephen@networkplumber.org,\n\tgaetan.rivet@6wind.com, shreyansh.jain@nxp.com, thomas@monjalon.net, \n\tCiara Power <ciara.power@intel.com>,\n\tBrian Archbold <brian.archbold@intel.com>,\n\tKevin Laatz <kevin.laatz@intel.com>",
        "Date": "Wed,  3 Oct 2018 18:36:06 +0100",
        "Message-Id": "<20181003173612.67101-5-kevin.laatz@intel.com>",
        "X-Mailer": "git-send-email 2.9.5",
        "In-Reply-To": "<20181003173612.67101-1-kevin.laatz@intel.com>",
        "References": "<1535026093-101872-1-git-send-email-ciara.power@intel.com>\n\t<20181003173612.67101-1-kevin.laatz@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2 04/10] telemetry: add parser for client socket\n\tmessages",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "From: Ciara Power <ciara.power@intel.com>\n\nThis patch adds the parser file. This is used to parse any\nmessages that are received on any of the client sockets.\n\nCurrently, the unregister functionality works using the parser.\nFunctionality relating to getting statistic values for certain ports\nwill be added in a subsequent patch, however the parsing involved\nfor that command is added in this patch.\n\nSome of the parser code included is in preparation for future\nfunctionality, that is not implemented yet in this patchset.\n\nSigned-off-by: Ciara Power <ciara.power@intel.com>\nSigned-off-by: Brian Archbold <brian.archbold@intel.com>\nSigned-off-by: Kevin Laatz <kevin.laatz@intel.com>\n---\n lib/librte_telemetry/Makefile                 |   1 +\n lib/librte_telemetry/meson.build              |   4 +-\n lib/librte_telemetry/rte_telemetry.c          |   8 +\n lib/librte_telemetry/rte_telemetry_internal.h |  13 +\n lib/librte_telemetry/rte_telemetry_parser.c   | 569 ++++++++++++++++++++++++++\n lib/librte_telemetry/rte_telemetry_parser.h   |  13 +\n 6 files changed, 606 insertions(+), 2 deletions(-)\n create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c\n create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h",
    "diff": "diff --git a/lib/librte_telemetry/Makefile b/lib/librte_telemetry/Makefile\nindex 0d61361..95c7296 100644\n--- a/lib/librte_telemetry/Makefile\n+++ b/lib/librte_telemetry/Makefile\n@@ -21,6 +21,7 @@ LIBABIVER := 1\n \n # library source files\n SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c\n+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c\n \n # export include files\n SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h\ndiff --git a/lib/librte_telemetry/meson.build b/lib/librte_telemetry/meson.build\nindex 0ccfa36..7450f96 100644\n--- a/lib/librte_telemetry/meson.build\n+++ b/lib/librte_telemetry/meson.build\n@@ -1,8 +1,8 @@\n # SPDX-License-Identifier: BSD-3-Clause\n # Copyright(c) 2018 Intel Corporation\n \n-sources = files('rte_telemetry.c')\n-headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')\n+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')\n+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')\n deps += ['metrics', 'ethdev']\n cflags += '-DALLOW_EXPERIMENTAL_API'\n jansson = cc.find_library('jansson', required: true)\ndiff --git a/lib/librte_telemetry/rte_telemetry.c b/lib/librte_telemetry/rte_telemetry.c\nindex 7726fd4..2e879b7 100644\n--- a/lib/librte_telemetry/rte_telemetry.c\n+++ b/lib/librte_telemetry/rte_telemetry.c\n@@ -16,6 +16,7 @@\n \n #include \"rte_telemetry.h\"\n #include \"rte_telemetry_internal.h\"\n+#include \"rte_telemetry_parser.h\"\n \n #define BUF_SIZE 1024\n #define ACTION_POST 1\n@@ -274,6 +275,7 @@ rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)\n static int32_t\n rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)\n {\n+\tint ret;\n \ttelemetry_client *client;\n \tchar client_buf[BUF_SIZE];\n \tint bytes;\n@@ -284,6 +286,12 @@ rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)\n \n \t\tif (bytes > 0) {\n \t\t\ttelemetry->request_client = client;\n+\t\t\tret = rte_telemetry_parse(telemetry, client_buf);\n+\t\t\tif (ret < 0) {\n+\t\t\t\tTELEMETRY_LOG_WARN(\"Parse socket input failed: %i\",\n+\t\t\t\t\t\tret);\n+\t\t\t\treturn -1;\n+\t\t\t}\n \t\t}\n \t}\n \ndiff --git a/lib/librte_telemetry/rte_telemetry_internal.h b/lib/librte_telemetry/rte_telemetry_internal.h\nindex e3292cf..86a5ba1 100644\n--- a/lib/librte_telemetry/rte_telemetry_internal.h\n+++ b/lib/librte_telemetry/rte_telemetry_internal.h\n@@ -43,6 +43,11 @@ typedef struct telemetry_impl {\n \tint register_fail_count;\n } telemetry_impl;\n \n+enum rte_telemetry_parser_actions {\n+\tACTION_GET = 0,\n+\tACTION_DELETE = 2\n+};\n+\n int32_t\n rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);\n \n@@ -58,4 +63,12 @@ int32_t\n rte_telemetry_unregister_client(struct telemetry_impl *telemetry,\n \tconst char *client_path);\n \n+/**\n+ * This is a wrapper for the ethdev api rte_eth_find_next().\n+ * If rte_eth_find_next() returns the same port id that we passed it,\n+ * then we know that that port is active.\n+ */\n+int32_t\n+rte_telemetry_is_port_active(int port_id);\n+\n #endif\ndiff --git a/lib/librte_telemetry/rte_telemetry_parser.c b/lib/librte_telemetry/rte_telemetry_parser.c\nnew file mode 100644\nindex 0000000..d2065f4\n--- /dev/null\n+++ b/lib/librte_telemetry/rte_telemetry_parser.c\n@@ -0,0 +1,569 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018 Intel Corporation\n+ */\n+\n+#include <stdio.h>\n+#include <stdint.h>\n+#include <string.h>\n+#include <errno.h>\n+#include <jansson.h>\n+\n+#include <rte_metrics.h>\n+#include <rte_common.h>\n+#include <rte_ethdev.h>\n+\n+#include \"rte_telemetry_internal.h\"\n+\n+typedef int (*command_func)(struct telemetry_impl *, int, json_t *);\n+\n+struct rte_telemetry_command {\n+\tchar *text;\n+\tcommand_func fn;\n+} command;\n+\n+static int32_t\n+rte_telemetry_command_clients(struct telemetry_impl *telemetry, int action,\n+\tjson_t *data)\n+{\n+\tint ret;\n+\n+\tif (!telemetry) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (action != ACTION_DELETE) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid action for this command\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tif (!json_is_object(data)) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid data provided for this command\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tjson_t *client_path = json_object_get(data, \"client_path\");\n+\tif (!json_is_string(client_path)) {\n+\t\tTELEMETRY_LOG_WARN(\"Command value is not a string\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tret = rte_telemetry_unregister_client(telemetry,\n+\t\t\tjson_string_value(client_path));\n+\tif (ret < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Could not unregister client\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\treturn 0;\n+\n+einval_fail:\n+\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\tif (ret < 0)\n+\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\treturn -1;\n+}\n+\n+static int32_t\n+rte_telemetry_command_ports(struct telemetry_impl *telemetry, int action,\n+\tjson_t *data)\n+{\n+\tint ret;\n+\n+\tif (!telemetry) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (!json_is_null(data)) {\n+\t\tTELEMETRY_LOG_WARN(\"Data should be NULL JSON object for 'ports' command\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tif (action != ACTION_GET) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid action for this command\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\treturn 0;\n+\n+einval_fail:\n+\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\tif (ret < 0)\n+\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\treturn -1;\n+}\n+\n+static int32_t\n+rte_telemetry_command_ports_details(struct telemetry_impl *telemetry,\n+\tint action, json_t *data)\n+{\n+\tjson_t *value, *port_ids_json = json_object_get(data, \"ports\");\n+\tuint64_t num_port_ids = json_array_size(port_ids_json);\n+\tint ret, port_ids[num_port_ids];\n+\tRTE_SET_USED(port_ids);\n+\tsize_t index;\n+\n+\tif (!telemetry) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (action != ACTION_GET) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid action for this command\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tif (!json_is_object(data)) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid data provided for this command\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tif (!json_is_array(port_ids_json)) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid Port ID array\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tjson_array_foreach(port_ids_json, index, value) {\n+\t\tif (!json_is_integer(value)) {\n+\t\t\tTELEMETRY_LOG_WARN(\"Port ID given is invalid\");\n+\t\t\tgoto einval_fail;\n+\t\t}\n+\t\tport_ids[index] = json_integer_value(value);\n+\t}\n+\n+\treturn 0;\n+\n+einval_fail:\n+\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\tif (ret < 0)\n+\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\treturn -1;\n+}\n+\n+static int32_t\n+rte_telemetry_command_port_stats(struct telemetry_impl *telemetry, int action,\n+\tjson_t *data)\n+{\n+\tint ret;\n+\n+\tif (!telemetry) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (!json_is_null(data)) {\n+\t\tTELEMETRY_LOG_WARN(\"Data should be NULL JSON object for 'port_stats' command\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tif (action != ACTION_GET) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid action for this command\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\treturn 0;\n+\n+einval_fail:\n+\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\tif (ret < 0)\n+\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\treturn -1;\n+}\n+\n+static int32_t\n+rte_telemetry_stat_names_to_ids(struct telemetry_impl *telemetry,\n+\tconst char * const *stat_names, uint32_t *stat_ids,\n+\tuint64_t num_stat_names)\n+{\n+\tstruct rte_metric_name *names;\n+\tint ret, num_metrics;\n+\tuint32_t i, k;\n+\n+\tif (!stat_names) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid stat_names argument\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tif (num_stat_names <= 0) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid num_stat_names argument\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tnum_metrics = rte_metrics_get_names(NULL, 0);\n+\tif (num_metrics < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Cannot get metrics count\");\n+\t\tgoto eperm_fail;\n+\t} else if (num_metrics == 0) {\n+\t\tTELEMETRY_LOG_WARN(\"No metrics have been registered\");\n+\t\tgoto eperm_fail;\n+\t}\n+\n+\tnames = malloc(sizeof(struct rte_metric_name) * num_metrics);\n+\tif (!names) {\n+\t\tTELEMETRY_LOG_ERR(\"Cannot allocate memory for names\");\n+\n+\t\tret = rte_telemetry_send_error_response(telemetry, -ENOMEM);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\n+\t\treturn -1;\n+\t}\n+\n+\tret = rte_metrics_get_names(names, num_metrics);\n+\tif (ret < 0 || ret > num_metrics) {\n+\t\tTELEMETRY_LOG_ERR(\"Cannot get metrics names\");\n+\t\tfree(names);\n+\t\tgoto eperm_fail;\n+\t}\n+\n+\tk = 0;\n+\tfor (i = 0; i < (uint32_t)num_stat_names; i++) {\n+\t\tuint32_t j;\n+\t\tfor (j = 0; j < (uint32_t)num_metrics; j++) {\n+\t\t\tif (strcmp(stat_names[i], names[j].name) == 0) {\n+\t\t\t\tstat_ids[k] = j;\n+\t\t\t\tk++;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tif (k != num_stat_names) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid stat names provided\");\n+\t\tfree(names);\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tfree(names);\n+\treturn 0;\n+\n+einval_fail:\n+\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\tif (ret < 0)\n+\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\treturn -1;\n+\n+eperm_fail:\n+\tret = rte_telemetry_send_error_response(telemetry, -EPERM);\n+\tif (ret < 0)\n+\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\treturn -1;\n+}\n+\n+int32_t\n+rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,\n+\t int action, json_t *data)\n+{\n+\tint ret, num_metrics, i, p;\n+\tstruct rte_metric_name *names;\n+\tuint64_t num_port_ids = 0;\n+\n+\tif (!telemetry) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (action != ACTION_GET) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid action for this command\");\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (json_is_object(data)) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid data provided for this command\");\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tnum_metrics = rte_metrics_get_names(NULL, 0);\n+\tif (num_metrics < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Cannot get metrics count\");\n+\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\n+\t\treturn -1;\n+\t} else if (num_metrics == 0) {\n+\t\tTELEMETRY_LOG_ERR(\"No metrics to display (none have been registered)\");\n+\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EPERM);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\n+\t\treturn -1;\n+\t}\n+\n+\tnames = malloc(sizeof(struct rte_metric_name) * num_metrics);\n+\tif (!names) {\n+\t\tTELEMETRY_LOG_ERR(\"Cannot allocate memory\");\n+\t\tret = rte_telemetry_send_error_response(telemetry,\n+\t\t\t -ENOMEM);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tconst char *stat_names[num_metrics];\n+\tuint32_t stat_ids[num_metrics];\n+\n+\tRTE_ETH_FOREACH_DEV(p) {\n+\t\tnum_port_ids++;\n+\t}\n+\n+\tif (!num_port_ids) {\n+\t\tTELEMETRY_LOG_WARN(\"No active ports\");\n+\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\n+\t\tgoto fail;\n+\t}\n+\n+\tret = rte_metrics_get_names(names, num_metrics);\n+\tfor (i = 0; i < num_metrics; i++)\n+\t\tstat_names[i] = names[i].name;\n+\n+\tret = rte_telemetry_stat_names_to_ids(telemetry, stat_names, stat_ids,\n+\t\tnum_metrics);\n+\tif (ret < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Could not convert stat names to IDs\");\n+\t\tgoto fail;\n+\t}\n+\n+\treturn 0;\n+\n+fail:\n+\tfree(names);\n+\treturn -1;\n+}\n+\n+int32_t\n+rte_telemetry_command_ports_stats_values_by_name(struct telemetry_impl\n+\t*telemetry, int action, json_t *data)\n+{\n+\tint ret;\n+\tjson_t *port_ids_json = json_object_get(data, \"ports\");\n+\tjson_t *stat_names_json = json_object_get(data, \"stats\");\n+\tuint64_t num_port_ids = json_array_size(port_ids_json);\n+\tuint64_t num_stat_names = json_array_size(stat_names_json);\n+\tconst char *stat_names[num_stat_names];\n+\tuint32_t port_ids[num_port_ids], stat_ids[num_stat_names];\n+\tsize_t index;\n+\tjson_t *value;\n+\n+\tif (!telemetry) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (action != ACTION_GET) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid action for this command\");\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (!json_is_object(data)) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid data provided for this command\");\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (!json_is_array(port_ids_json) ||\n+\t\t !json_is_array(stat_names_json)) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid input data array(s)\");\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tjson_array_foreach(port_ids_json, index, value) {\n+\t\tif (!json_is_integer(value)) {\n+\t\t\tTELEMETRY_LOG_WARN(\"Port ID given is not valid\");\n+\t\t\tret = rte_telemetry_send_error_response(telemetry,\n+\t\t\t\t-EINVAL);\n+\t\t\tif (ret < 0)\n+\t\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\t\treturn -1;\n+\t\t}\n+\t\tport_ids[index] = json_integer_value(value);\n+\t\tret = rte_telemetry_is_port_active(port_ids[index]);\n+\t\tif (ret < 1) {\n+\t\t\tret = rte_telemetry_send_error_response(telemetry,\n+\t\t\t\t-EINVAL);\n+\t\t\tif (ret < 0)\n+\t\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\tjson_array_foreach(stat_names_json, index, value) {\n+\t\tif (!json_is_string(value)) {\n+\t\t\tTELEMETRY_LOG_WARN(\"Stat Name given is not a string\");\n+\n+\t\t\tret = rte_telemetry_send_error_response(telemetry,\n+\t\t\t\t\t-EINVAL);\n+\t\t\tif (ret < 0)\n+\t\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\n+\t\t\treturn -1;\n+\t\t}\n+\t\tstat_names[index] = json_string_value(value);\n+\t}\n+\n+\tret = rte_telemetry_stat_names_to_ids(telemetry, stat_names, stat_ids,\n+\t\tnum_stat_names);\n+\tif (ret < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Could not convert stat names to IDs\");\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\n+\n+static int32_t\n+rte_telemetry_parse_command(struct telemetry_impl *telemetry, int action,\n+\tconst char *command, json_t *data)\n+{\n+\tint ret;\n+\tuint32_t i;\n+\n+\tif (!telemetry) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n+\t\treturn -1;\n+\t}\n+\n+\tstruct rte_telemetry_command commands[] = {\n+\t\t{\n+\t\t\t.text = \"clients\",\n+\t\t\t.fn = &rte_telemetry_command_clients\n+\t\t},\n+\t\t{\n+\t\t\t.text = \"ports\",\n+\t\t\t.fn = &rte_telemetry_command_ports\n+\t\t},\n+\t\t{\n+\t\t\t.text = \"ports_details\",\n+\t\t\t.fn = &rte_telemetry_command_ports_details\n+\t\t},\n+\t\t{\n+\t\t\t.text = \"port_stats\",\n+\t\t\t.fn = &rte_telemetry_command_port_stats\n+\t\t},\n+\t\t{\n+\t\t\t.text = \"ports_stats_values_by_name\",\n+\t\t\t.fn = &rte_telemetry_command_ports_stats_values_by_name\n+\t\t},\n+\t\t{\n+\t\t\t.text = \"ports_all_stat_values\",\n+\t\t\t.fn = &rte_telemetry_command_ports_all_stat_values\n+\t\t}\n+\t};\n+\n+\tconst uint32_t num_commands = RTE_DIM(command);\n+\n+\tfor (i = 0; i < num_commands; i++) {\n+\t\tif (strcmp(command, commands[i].text) == 0) {\n+\t\t\tret = commands[i].fn(telemetry, action, data);\n+\t\t\tif (ret < 0) {\n+\t\t\t\tTELEMETRY_LOG_ERR(\"Command Function for %s failed\",\n+\t\t\t\t\tcommands[i].text);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\tTELEMETRY_LOG_WARN(\"\\\"%s\\\" command not found\", command);\n+\n+\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\tif (ret < 0)\n+\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\n+\treturn -1;\n+}\n+\n+int32_t\n+rte_telemetry_parse(struct telemetry_impl *telemetry, char *socket_rx_data)\n+{\n+\tint ret, action_int;\n+\tjson_error_t error;\n+\tjson_t *root, *action, *command, *data;\n+\n+\tif (!telemetry) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n+\t\treturn -1;\n+\t}\n+\n+\troot = json_loads(socket_rx_data, 0, &error);\n+\tif (!root) {\n+\t\tTELEMETRY_LOG_WARN(\"Could not load JSON object from data passed in : %s\",\n+\t\t\t\terror.text);\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EPERM);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -EPERM;\n+\t} else if (!json_is_object(root)) {\n+\t\tTELEMETRY_LOG_WARN(\"JSON Request is not a JSON object\");\n+\t\tjson_decref(root);\n+\t\tgoto einval_fail;\n+\t}\n+\n+\taction = json_object_get(root, \"action\");\n+\tif (!action) {\n+\t\tTELEMETRY_LOG_WARN(\"Request does not have action field\");\n+\t\tgoto einval_fail;\n+\t} else if (!json_is_integer(action)) {\n+\t\tTELEMETRY_LOG_WARN(\"Action value is not an integer\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tcommand = json_object_get(root, \"command\");\n+\tif (!command) {\n+\t\tTELEMETRY_LOG_WARN(\"Request does not have command field\");\n+\t\tgoto einval_fail;\n+\t} else if (!json_is_string(command)) {\n+\t\tTELEMETRY_LOG_WARN(\"Command value is not a string\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\taction_int = json_integer_value(action);\n+\tif (action_int != ACTION_GET && action_int != ACTION_DELETE) {\n+\t\tTELEMETRY_LOG_WARN(\"Invalid action code\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tconst char *command_string = json_string_value(command);\n+\tdata = json_object_get(root, \"data\");\n+\tif (!data) {\n+\t\tTELEMETRY_LOG_WARN(\"Request does not have data field\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tret = rte_telemetry_parse_command(telemetry, action_int, command_string,\n+\t\tdata);\n+\tif (ret < 0) {\n+\t\tTELEMETRY_LOG_WARN(\"Could not parse command\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+\n+einval_fail:\n+\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\tif (ret < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -EPERM;\n+\t}\n+\treturn -EINVAL;\n+}\ndiff --git a/lib/librte_telemetry/rte_telemetry_parser.h b/lib/librte_telemetry/rte_telemetry_parser.h\nnew file mode 100644\nindex 0000000..63e633d\n--- /dev/null\n+++ b/lib/librte_telemetry/rte_telemetry_parser.h\n@@ -0,0 +1,13 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018 Intel Corporation\n+ */\n+\n+#include \"rte_telemetry_internal.h\"\n+\n+#ifndef _RTE_TELEMETRY_PARSER_H_\n+#define _RTE_TELEMETRY_PARSER_H_\n+\n+int32_t\n+rte_telemetry_parse(struct telemetry_impl *telemetry, char *socket_rx_data);\n+\n+#endif\n",
    "prefixes": [
        "v2",
        "04/10"
    ]
}