1af75078fSIntel /*- 2af75078fSIntel * BSD LICENSE 3af75078fSIntel * 4*e9d48c00SBruce Richardson * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. 5af75078fSIntel * All rights reserved. 6af75078fSIntel * 7af75078fSIntel * Redistribution and use in source and binary forms, with or without 8af75078fSIntel * modification, are permitted provided that the following conditions 9af75078fSIntel * are met: 10af75078fSIntel * 11af75078fSIntel * * Redistributions of source code must retain the above copyright 12af75078fSIntel * notice, this list of conditions and the following disclaimer. 13af75078fSIntel * * Redistributions in binary form must reproduce the above copyright 14af75078fSIntel * notice, this list of conditions and the following disclaimer in 15af75078fSIntel * the documentation and/or other materials provided with the 16af75078fSIntel * distribution. 17af75078fSIntel * * Neither the name of Intel Corporation nor the names of its 18af75078fSIntel * contributors may be used to endorse or promote products derived 19af75078fSIntel * from this software without specific prior written permission. 20af75078fSIntel * 21af75078fSIntel * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22af75078fSIntel * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23af75078fSIntel * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24af75078fSIntel * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25af75078fSIntel * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26af75078fSIntel * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27af75078fSIntel * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28af75078fSIntel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29af75078fSIntel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30af75078fSIntel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31af75078fSIntel * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32af75078fSIntel */ 33af75078fSIntel #include <stdint.h> 34af75078fSIntel #include <string.h> 35af75078fSIntel #include <stdlib.h> 36af75078fSIntel #include <stdarg.h> 37af75078fSIntel #include <inttypes.h> 38af75078fSIntel #include <stdio.h> 39af75078fSIntel #include <termios.h> 40af75078fSIntel #include <errno.h> 41af75078fSIntel #include <sys/queue.h> 42af75078fSIntel 43af75078fSIntel #include <rte_common.h> 44af75078fSIntel #include <rte_memory.h> 45af75078fSIntel #include <rte_memzone.h> 46af75078fSIntel #include <rte_tailq.h> 47af75078fSIntel #include <rte_eal.h> 48af75078fSIntel #include <rte_atomic.h> 49af75078fSIntel #include <rte_branch_prediction.h> 50af75078fSIntel #include <rte_launch.h> 51af75078fSIntel #include <rte_log.h> 52af75078fSIntel #include <rte_per_lcore.h> 53af75078fSIntel #include <rte_lcore.h> 54af75078fSIntel #include <rte_ring.h> 55af75078fSIntel #include <rte_debug.h> 56af75078fSIntel #include <rte_mempool.h> 57af75078fSIntel #include <rte_string_fns.h> 58af75078fSIntel 59af75078fSIntel #include <cmdline_rdline.h> 60af75078fSIntel #include <cmdline_parse.h> 61af75078fSIntel #include <cmdline_parse_string.h> 62af75078fSIntel #include <cmdline_socket.h> 63af75078fSIntel #include <cmdline.h> 64af75078fSIntel #include "mp_commands.h" 65af75078fSIntel 66af75078fSIntel /**********************************************************/ 67af75078fSIntel 68af75078fSIntel struct cmd_send_result { 69af75078fSIntel cmdline_fixed_string_t action; 70af75078fSIntel cmdline_fixed_string_t message; 71af75078fSIntel }; 72af75078fSIntel 73af75078fSIntel static void cmd_send_parsed(void *parsed_result, 74af75078fSIntel __attribute__((unused)) struct cmdline *cl, 75af75078fSIntel __attribute__((unused)) void *data) 76af75078fSIntel { 77a974564bSIntel void *msg = NULL; 78af75078fSIntel struct cmd_send_result *res = parsed_result; 79af75078fSIntel 80af75078fSIntel if (rte_mempool_get(message_pool, &msg) < 0) 81af75078fSIntel rte_panic("Failed to get message buffer\n"); 82af75078fSIntel rte_snprintf((char *)msg, string_size, "%s", res->message); 83af75078fSIntel if (rte_ring_enqueue(send_ring, msg) < 0) { 84af75078fSIntel printf("Failed to send message - message discarded\n"); 85af75078fSIntel rte_mempool_put(message_pool, msg); 86af75078fSIntel } 87af75078fSIntel } 88af75078fSIntel 89af75078fSIntel cmdline_parse_token_string_t cmd_send_action = 90af75078fSIntel TOKEN_STRING_INITIALIZER(struct cmd_send_result, action, "send"); 91af75078fSIntel cmdline_parse_token_string_t cmd_send_message = 92af75078fSIntel TOKEN_STRING_INITIALIZER(struct cmd_send_result, message, NULL); 93af75078fSIntel 94af75078fSIntel cmdline_parse_inst_t cmd_send = { 95af75078fSIntel .f = cmd_send_parsed, /* function to call */ 96af75078fSIntel .data = NULL, /* 2nd arg of func */ 97af75078fSIntel .help_str = "send a string to another process", 98af75078fSIntel .tokens = { /* token list, NULL terminated */ 99af75078fSIntel (void *)&cmd_send_action, 100af75078fSIntel (void *)&cmd_send_message, 101af75078fSIntel NULL, 102af75078fSIntel }, 103af75078fSIntel }; 104af75078fSIntel 105af75078fSIntel /**********************************************************/ 106af75078fSIntel 107af75078fSIntel struct cmd_quit_result { 108af75078fSIntel cmdline_fixed_string_t quit; 109af75078fSIntel }; 110af75078fSIntel 111af75078fSIntel static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, 112af75078fSIntel struct cmdline *cl, 113af75078fSIntel __attribute__((unused)) void *data) 114af75078fSIntel { 115af75078fSIntel quit = 1; 116af75078fSIntel cmdline_quit(cl); 117af75078fSIntel } 118af75078fSIntel 119af75078fSIntel cmdline_parse_token_string_t cmd_quit_quit = 120af75078fSIntel TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 121af75078fSIntel 122af75078fSIntel cmdline_parse_inst_t cmd_quit = { 123af75078fSIntel .f = cmd_quit_parsed, /* function to call */ 124af75078fSIntel .data = NULL, /* 2nd arg of func */ 125af75078fSIntel .help_str = "close the application", 126af75078fSIntel .tokens = { /* token list, NULL terminated */ 127af75078fSIntel (void *)&cmd_quit_quit, 128af75078fSIntel NULL, 129af75078fSIntel }, 130af75078fSIntel }; 131af75078fSIntel 132af75078fSIntel /**********************************************************/ 133af75078fSIntel 134af75078fSIntel struct cmd_help_result { 135af75078fSIntel cmdline_fixed_string_t help; 136af75078fSIntel }; 137af75078fSIntel 138af75078fSIntel static void cmd_help_parsed(__attribute__((unused)) void *parsed_result, 139af75078fSIntel struct cmdline *cl, 140af75078fSIntel __attribute__((unused)) void *data) 141af75078fSIntel { 142af75078fSIntel cmdline_printf(cl, "Simple demo example of multi-process in RTE\n\n" 143af75078fSIntel "This is a readline-like interface that can be used to\n" 144af75078fSIntel "send commands to the simple app. Commands supported are:\n\n" 145af75078fSIntel "- send [string]\n" "- help\n" "- quit\n\n"); 146af75078fSIntel } 147af75078fSIntel 148af75078fSIntel cmdline_parse_token_string_t cmd_help_help = 149af75078fSIntel TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help"); 150af75078fSIntel 151af75078fSIntel cmdline_parse_inst_t cmd_help = { 152af75078fSIntel .f = cmd_help_parsed, /* function to call */ 153af75078fSIntel .data = NULL, /* 2nd arg of func */ 154af75078fSIntel .help_str = "show help", 155af75078fSIntel .tokens = { /* token list, NULL terminated */ 156af75078fSIntel (void *)&cmd_help_help, 157af75078fSIntel NULL, 158af75078fSIntel }, 159af75078fSIntel }; 160af75078fSIntel 161af75078fSIntel /****** CONTEXT (list of instruction) */ 162af75078fSIntel cmdline_parse_ctx_t simple_mp_ctx[] = { 163af75078fSIntel (cmdline_parse_inst_t *)&cmd_send, 164af75078fSIntel (cmdline_parse_inst_t *)&cmd_quit, 165af75078fSIntel (cmdline_parse_inst_t *)&cmd_help, 166af75078fSIntel NULL, 167af75078fSIntel }; 168