summaryrefslogtreecommitdiff
path: root/examples/ip_pipeline/cli.c
diff options
context:
space:
mode:
authorJasvinder Singh <jasvinder.singh@intel.com>2018-03-29 19:31:40 +0100
committerCristian Dumitrescu <cristian.dumitrescu@intel.com>2018-04-05 18:23:49 +0200
commit4bbf8e30aa5e2a621db288062c72aed324cae191 (patch)
tree76ae6d345051f979583eaae15c4d3e4c7b00519a /examples/ip_pipeline/cli.c
parentfbc74e66334f52a00263dd81dd49fe513b6e8967 (diff)
downloaddpdk-4bbf8e30aa5e2a621db288062c72aed324cae191.zip
dpdk-4bbf8e30aa5e2a621db288062c72aed324cae191.tar.gz
dpdk-4bbf8e30aa5e2a621db288062c72aed324cae191.tar.xz
examples/ip_pipeline: add CLI interface
CLI interface allowing connectivity with external agent (e.g. telnet, netcat, Python script, etc) is added to the application. Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Diffstat (limited to 'examples/ip_pipeline/cli.c')
-rw-r--r--examples/ip_pipeline/cli.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c
new file mode 100644
index 0000000..34ada83
--- /dev/null
+++ b/examples/ip_pipeline/cli.c
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2018 Intel Corporation
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rte_common.h>
+
+#include "cli.h"
+
+static int
+is_comment(char *in)
+{
+ if ((strlen(in) && index("!#%;", in[0])) ||
+ (strncmp(in, "//", 2) == 0) ||
+ (strncmp(in, "--", 2) == 0))
+ return 1;
+
+ return 0;
+}
+
+void
+cli_process(char *in, char *out __rte_unused, size_t out_size __rte_unused)
+{
+ if (is_comment(in))
+ return;
+
+}
+
+int
+cli_script_process(const char *file_name,
+ size_t msg_in_len_max,
+ size_t msg_out_len_max)
+{
+ char *msg_in = NULL, *msg_out = NULL;
+ FILE *f = NULL;
+
+ /* Check input arguments */
+ if ((file_name == NULL) ||
+ (strlen(file_name) == 0) ||
+ (msg_in_len_max == 0) ||
+ (msg_out_len_max == 0))
+ return -EINVAL;
+
+ msg_in = malloc(msg_in_len_max + 1);
+ msg_out = malloc(msg_out_len_max + 1);
+ if ((msg_in == NULL) ||
+ (msg_out == NULL)) {
+ free(msg_out);
+ free(msg_in);
+ return -ENOMEM;
+ }
+
+ /* Open input file */
+ f = fopen(file_name, "r");
+ if (f == NULL) {
+ free(msg_out);
+ free(msg_in);
+ return -EIO;
+ }
+
+ /* Read file */
+ for ( ; ; ) {
+ if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
+ break;
+
+ printf("%s", msg_in);
+ msg_out[0] = 0;
+
+ cli_process(msg_in,
+ msg_out,
+ msg_out_len_max);
+
+ if (strlen(msg_out))
+ printf("%s", msg_out);
+ }
+
+ /* Close file */
+ fclose(f);
+ free(msg_out);
+ free(msg_in);
+ return 0;
+}