1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 #include <stdint.h> 5 #include <string.h> 6 #include <stdlib.h> 7 #include <stdarg.h> 8 #include <inttypes.h> 9 #include <stdio.h> 10 #include <termios.h> 11 #include <errno.h> 12 #include <sys/queue.h> 13 14 #include <rte_common.h> 15 #include <rte_memory.h> 16 #include <rte_eal.h> 17 #include <rte_branch_prediction.h> 18 #include <rte_launch.h> 19 #include <rte_log.h> 20 #include <rte_per_lcore.h> 21 #include <rte_lcore.h> 22 #include <rte_ring.h> 23 #include <rte_debug.h> 24 #include <rte_mempool.h> 25 #include <rte_string_fns.h> 26 27 #include <cmdline_rdline.h> 28 #include <cmdline_parse.h> 29 #include <cmdline_parse_string.h> 30 #include <cmdline_socket.h> 31 #include <cmdline.h> 32 #include "mp_commands.h" 33 34 /**********************************************************/ 35 36 struct cmd_send_result { 37 cmdline_fixed_string_t action; 38 cmdline_fixed_string_t message; 39 }; 40 41 static void cmd_send_parsed(void *parsed_result, 42 __rte_unused struct cmdline *cl, 43 __rte_unused void *data) 44 { 45 void *msg = NULL; 46 struct cmd_send_result *res = parsed_result; 47 48 if (rte_mempool_get(message_pool, &msg) < 0) 49 rte_panic("Failed to get message buffer\n"); 50 strlcpy((char *)msg, res->message, STR_TOKEN_SIZE); 51 if (rte_ring_enqueue(send_ring, msg) < 0) { 52 printf("Failed to send message - message discarded\n"); 53 rte_mempool_put(message_pool, msg); 54 } 55 } 56 57 cmdline_parse_token_string_t cmd_send_action = 58 TOKEN_STRING_INITIALIZER(struct cmd_send_result, action, "send"); 59 cmdline_parse_token_string_t cmd_send_message = 60 TOKEN_STRING_INITIALIZER(struct cmd_send_result, message, NULL); 61 62 cmdline_parse_inst_t cmd_send = { 63 .f = cmd_send_parsed, /* function to call */ 64 .data = NULL, /* 2nd arg of func */ 65 .help_str = "send a string to another process", 66 .tokens = { /* token list, NULL terminated */ 67 (void *)&cmd_send_action, 68 (void *)&cmd_send_message, 69 NULL, 70 }, 71 }; 72 73 /**********************************************************/ 74 75 struct cmd_quit_result { 76 cmdline_fixed_string_t quit; 77 }; 78 79 static void cmd_quit_parsed(__rte_unused void *parsed_result, 80 struct cmdline *cl, 81 __rte_unused void *data) 82 { 83 quit = 1; 84 cmdline_quit(cl); 85 } 86 87 cmdline_parse_token_string_t cmd_quit_quit = 88 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 89 90 cmdline_parse_inst_t cmd_quit = { 91 .f = cmd_quit_parsed, /* function to call */ 92 .data = NULL, /* 2nd arg of func */ 93 .help_str = "close the application", 94 .tokens = { /* token list, NULL terminated */ 95 (void *)&cmd_quit_quit, 96 NULL, 97 }, 98 }; 99 100 /**********************************************************/ 101 102 struct cmd_help_result { 103 cmdline_fixed_string_t help; 104 }; 105 106 static void cmd_help_parsed(__rte_unused void *parsed_result, 107 struct cmdline *cl, 108 __rte_unused void *data) 109 { 110 cmdline_printf(cl, "Simple demo example of multi-process in RTE\n\n" 111 "This is a readline-like interface that can be used to\n" 112 "send commands to the simple app. Commands supported are:\n\n" 113 "- send [string]\n" "- help\n" "- quit\n\n"); 114 } 115 116 cmdline_parse_token_string_t cmd_help_help = 117 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help"); 118 119 cmdline_parse_inst_t cmd_help = { 120 .f = cmd_help_parsed, /* function to call */ 121 .data = NULL, /* 2nd arg of func */ 122 .help_str = "show help", 123 .tokens = { /* token list, NULL terminated */ 124 (void *)&cmd_help_help, 125 NULL, 126 }, 127 }; 128 129 /****** CONTEXT (list of instruction) */ 130 cmdline_parse_ctx_t simple_mp_ctx[] = { 131 (cmdline_parse_inst_t *)&cmd_send, 132 (cmdline_parse_inst_t *)&cmd_quit, 133 (cmdline_parse_inst_t *)&cmd_help, 134 NULL, 135 }; 136