examples/ip_pipeline: add port enable and disable commands
[dpdk.git] / examples / ip_pipeline / cli.c
index e96f3a6..c3adc17 100644 (file)
@@ -17,6 +17,7 @@
 #include "pipeline.h"
 #include "swq.h"
 #include "tap.h"
+#include "thread.h"
 #include "tmgr.h"
 
 #ifndef CMD_MAX_TOKENS
@@ -1936,6 +1937,185 @@ cmd_pipeline_port_in_table(char **tokens,
        }
 }
 
+/**
+ * pipeline <pipeline_name> port in <port_id> enable
+ */
+static void
+cmd_pipeline_port_in_enable(char **tokens,
+       uint32_t n_tokens,
+       char *out,
+       size_t out_size)
+{
+       char *pipeline_name;
+       uint32_t port_id;
+       int status;
+
+       if (n_tokens != 6) {
+               snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+               return;
+       }
+
+       pipeline_name = tokens[1];
+
+       if (strcmp(tokens[2], "port") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
+               return;
+       }
+
+       if (strcmp(tokens[3], "in") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
+               return;
+       }
+
+       if (parser_read_uint32(&port_id, tokens[4]) != 0) {
+               snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
+               return;
+       }
+
+       if (strcmp(tokens[5], "enable") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
+               return;
+       }
+
+       status = pipeline_port_in_enable(pipeline_name, port_id);
+       if (status) {
+               snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
+               return;
+       }
+}
+
+/**
+ * pipeline <pipeline_name> port in <port_id> disable
+ */
+static void
+cmd_pipeline_port_in_disable(char **tokens,
+       uint32_t n_tokens,
+       char *out,
+       size_t out_size)
+{
+       char *pipeline_name;
+       uint32_t port_id;
+       int status;
+
+       if (n_tokens != 6) {
+               snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+               return;
+       }
+
+       pipeline_name = tokens[1];
+
+       if (strcmp(tokens[2], "port") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
+               return;
+       }
+
+       if (strcmp(tokens[3], "in") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
+               return;
+       }
+
+       if (parser_read_uint32(&port_id, tokens[4]) != 0) {
+               snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
+               return;
+       }
+
+       if (strcmp(tokens[5], "disable") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
+               return;
+       }
+
+       status = pipeline_port_in_disable(pipeline_name, port_id);
+       if (status) {
+               snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
+               return;
+       }
+}
+
+/**
+ * thread <thread_id> pipeline <pipeline_name> enable
+ */
+static void
+cmd_thread_pipeline_enable(char **tokens,
+       uint32_t n_tokens,
+       char *out,
+       size_t out_size)
+{
+       char *pipeline_name;
+       uint32_t thread_id;
+       int status;
+
+       if (n_tokens != 5) {
+               snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+               return;
+       }
+
+       if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
+               snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
+               return;
+       }
+
+       if (strcmp(tokens[2], "pipeline") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
+               return;
+       }
+
+       pipeline_name = tokens[3];
+
+       if (strcmp(tokens[4], "enable") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
+               return;
+       }
+
+       status = thread_pipeline_enable(thread_id, pipeline_name);
+       if (status) {
+               snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
+               return;
+       }
+}
+
+/**
+ * thread <thread_id> pipeline <pipeline_name> disable
+ */
+static void
+cmd_thread_pipeline_disable(char **tokens,
+       uint32_t n_tokens,
+       char *out,
+       size_t out_size)
+{
+       char *pipeline_name;
+       uint32_t thread_id;
+       int status;
+
+       if (n_tokens != 5) {
+               snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+               return;
+       }
+
+       if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
+               snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
+               return;
+       }
+
+       if (strcmp(tokens[2], "pipeline") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
+               return;
+       }
+
+       pipeline_name = tokens[3];
+
+       if (strcmp(tokens[4], "disable") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
+               return;
+       }
+
+       status = thread_pipeline_disable(thread_id, pipeline_name);
+       if (status) {
+               snprintf(out, out_size, MSG_CMD_FAIL,
+                       "thread pipeline disable");
+               return;
+       }
+}
+
 void
 cli_process(char *in, char *out, size_t out_size)
 {
@@ -2062,6 +2242,40 @@ cli_process(char *in, char *out, size_t out_size)
                                out, out_size);
                        return;
                }
+
+               if ((n_tokens >= 6) &&
+                       (strcmp(tokens[2], "port") == 0) &&
+                       (strcmp(tokens[3], "in") == 0) &&
+                       (strcmp(tokens[5], "enable") == 0)) {
+                       cmd_pipeline_port_in_enable(tokens, n_tokens,
+                               out, out_size);
+                       return;
+               }
+
+               if ((n_tokens >= 6) &&
+                       (strcmp(tokens[2], "port") == 0) &&
+                       (strcmp(tokens[3], "in") == 0) &&
+                       (strcmp(tokens[5], "disable") == 0)) {
+                       cmd_pipeline_port_in_disable(tokens, n_tokens,
+                               out, out_size);
+                       return;
+               }
+       }
+
+       if (strcmp(tokens[0], "thread") == 0) {
+               if ((n_tokens >= 5) &&
+                       (strcmp(tokens[4], "enable") == 0)) {
+                       cmd_thread_pipeline_enable(tokens, n_tokens,
+                               out, out_size);
+                       return;
+               }
+
+               if ((n_tokens >= 5) &&
+                       (strcmp(tokens[4], "disable") == 0)) {
+                       cmd_thread_pipeline_disable(tokens, n_tokens,
+                               out, out_size);
+                       return;
+               }
        }
 
        snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);