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