[18/21] net/softnic: add the pipeline meter CLI commands

Message ID 20220804165839.1074817-19-cristian.dumitrescu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Andrew Rybchenko
Headers
Series net/softnic: replace the legacy pipeline with SWX pipeline |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Cristian Dumitrescu Aug. 4, 2022, 4:58 p.m. UTC
  Add CLI commands for pipeline meter configuration.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Yogesh Jangra <yogesh.jangra@intel.com>
---
 drivers/net/softnic/rte_eth_softnic_cli.c | 423 ++++++++++++++++++++++
 1 file changed, 423 insertions(+)
  

Patch

diff --git a/drivers/net/softnic/rte_eth_softnic_cli.c b/drivers/net/softnic/rte_eth_softnic_cli.c
index b419c67cb8..449e750e41 100644
--- a/drivers/net/softnic/rte_eth_softnic_cli.c
+++ b/drivers/net/softnic/rte_eth_softnic_cli.c
@@ -1522,6 +1522,395 @@  cmd_softnic_pipeline_regwr(struct pmd_internals *softnic,
 	}
 }
 
+/**
+ * pipeline <pipeline_name> meter profile <profile_name> add cir <cir> pir <pir> cbs <cbs> pbs <pbs>
+ */
+static void
+cmd_softnic_pipeline_meter_profile_add(struct pmd_internals *softnic,
+	char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size)
+{
+	struct rte_meter_trtcm_params params;
+	struct pipeline *p;
+	const char *profile_name;
+	int status;
+
+	if (n_tokens != 14) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = softnic_pipeline_find(softnic, tokens[1]);
+	if (!p) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	if (strcmp(tokens[3], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[4];
+
+	if (strcmp(tokens[5], "add")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
+		return;
+	}
+
+	if (strcmp(tokens[6], "cir")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
+		return;
+	}
+
+	if (parser_read_uint64(&params.cir, tokens[7])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "cir");
+		return;
+	}
+
+	if (strcmp(tokens[8], "pir")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
+		return;
+	}
+
+	if (parser_read_uint64(&params.pir, tokens[9])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pir");
+		return;
+	}
+
+	if (strcmp(tokens[10], "cbs")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
+		return;
+	}
+
+	if (parser_read_uint64(&params.cbs, tokens[11])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
+		return;
+	}
+
+	if (strcmp(tokens[12], "pbs")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
+		return;
+	}
+
+	if (parser_read_uint64(&params.pbs, tokens[13])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
+		return;
+	}
+
+	status = rte_swx_ctl_meter_profile_add(p->p, profile_name, &params);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
+/**
+ * pipeline <pipeline_name> meter profile <profile_name> delete
+ */
+static void
+cmd_softnic_pipeline_meter_profile_delete(struct pmd_internals *softnic,
+	char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size)
+{
+	struct pipeline *p;
+	const char *profile_name;
+	int status;
+
+	if (n_tokens != 6) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = softnic_pipeline_find(softnic, tokens[1]);
+	if (!p) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	if (strcmp(tokens[3], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[4];
+
+	if (strcmp(tokens[5], "delete")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
+		return;
+	}
+
+	status = rte_swx_ctl_meter_profile_delete(p->p, profile_name);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
+/**
+ * pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> reset
+ */
+static void
+cmd_softnic_pipeline_meter_reset(struct pmd_internals *softnic,
+	char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size)
+{
+	struct pipeline *p;
+	const char *name;
+	uint32_t idx0 = 0, idx1 = 0;
+
+	if (n_tokens != 9) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = softnic_pipeline_find(softnic, tokens[1]);
+	if (!p) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "reset")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
+		return;
+	}
+
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_reset(p->p, name, idx0);
+		if (status) {
+			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			return;
+		}
+	}
+}
+
+/**
+ * pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> set
+ * 	profile <profile_name>
+ */
+static void
+cmd_softnic_pipeline_meter_set(struct pmd_internals *softnic,
+	char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size)
+{
+	struct pipeline *p;
+	const char *name, *profile_name;
+	uint32_t idx0 = 0, idx1 = 0;
+
+	if (n_tokens != 11) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = softnic_pipeline_find(softnic, tokens[1]);
+	if (!p) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "set")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
+		return;
+	}
+
+	if (strcmp(tokens[9], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[10];
+
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name);
+		if (status) {
+			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			return;
+		}
+	}
+}
+
+/**
+ * pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> stats
+ */
+static void
+cmd_softnic_pipeline_meter_stats(struct pmd_internals *softnic,
+	char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size)
+{
+	struct rte_swx_ctl_meter_stats stats;
+	struct pipeline *p;
+	const char *name;
+	uint32_t idx0 = 0, idx1 = 0;
+
+	if (n_tokens != 9) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = softnic_pipeline_find(softnic, tokens[1]);
+	if (!p) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "stats")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
+		return;
+	}
+
+	/* Table header. */
+	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
+		 "-------",
+		 "----------------", "----------------", "----------------",
+		 "----------------", "----------------", "----------------");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n",
+		 "METER #",
+		 "GREEN (packets)", "YELLOW (packets)", "RED (packets)",
+		 "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
+		 "-------",
+		 "----------------", "----------------", "----------------",
+		 "----------------", "----------------", "----------------");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	/* Table rows. */
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats);
+		if (status) {
+			snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
+			out_size -= strlen(out);
+			out += strlen(out);
+			return;
+		}
+
+		snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
+			 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
+			 idx0,
+			 stats.n_pkts[RTE_COLOR_GREEN],
+			 stats.n_pkts[RTE_COLOR_YELLOW],
+			 stats.n_pkts[RTE_COLOR_RED],
+			 stats.n_bytes[RTE_COLOR_GREEN],
+			 stats.n_bytes[RTE_COLOR_YELLOW],
+			 stats.n_bytes[RTE_COLOR_RED]);
+		out_size -= strlen(out);
+		out += strlen(out);
+	}
+}
+
 /**
  * thread <thread_id> pipeline <pipeline_name> enable [ period <timer_period_ms> ]
  */
@@ -1768,6 +2157,40 @@  softnic_cli_process(char *in, char *out, size_t out_size, void *arg)
 			cmd_softnic_pipeline_regwr(softnic, tokens, n_tokens, out, out_size);
 			return;
 		}
+
+		if ((n_tokens >= 6) &&
+			!strcmp(tokens[2], "meter") &&
+			!strcmp(tokens[3], "profile") &&
+			!strcmp(tokens[5], "add")) {
+			cmd_softnic_pipeline_meter_profile_add(softnic, tokens, n_tokens,
+				out, out_size);
+			return;
+		}
+
+		if ((n_tokens >= 6) &&
+			!strcmp(tokens[2], "meter") &&
+			!strcmp(tokens[3], "profile") &&
+			!strcmp(tokens[5], "delete")) {
+			cmd_softnic_pipeline_meter_profile_delete(softnic, tokens, n_tokens,
+				out, out_size);
+			return;
+		}
+
+		if ((n_tokens >= 9) && !strcmp(tokens[2], "meter") && !strcmp(tokens[8], "reset")) {
+			cmd_softnic_pipeline_meter_reset(softnic, tokens, n_tokens, out, out_size);
+			return;
+		}
+
+		if ((n_tokens >= 9) && !strcmp(tokens[2], "meter") && !strcmp(tokens[8], "set")) {
+			cmd_softnic_pipeline_meter_set(softnic, tokens, n_tokens, out, out_size);
+			return;
+		}
+
+		if ((n_tokens >= 9) && !strcmp(tokens[2], "meter") && !strcmp(tokens[8], "stats")) {
+			cmd_softnic_pipeline_meter_stats(softnic, tokens, n_tokens, out, out_size);
+			return;
+		}
+
 	}
 
 	if (strcmp(tokens[0], "thread") == 0) {