15074e1d5SCristian Dumitrescu /* SPDX-License-Identifier: BSD-3-Clause 25074e1d5SCristian Dumitrescu * Copyright(c) 2020 Intel Corporation 35074e1d5SCristian Dumitrescu */ 45074e1d5SCristian Dumitrescu 572b452c5SDmitry Kozlyuk #include <ctype.h> 65074e1d5SCristian Dumitrescu #include <stdio.h> 75074e1d5SCristian Dumitrescu #include <stdint.h> 85074e1d5SCristian Dumitrescu #include <stdlib.h> 95074e1d5SCristian Dumitrescu #include <string.h> 106bc14d9fSCristian Dumitrescu #include <unistd.h> 115074e1d5SCristian Dumitrescu 125074e1d5SCristian Dumitrescu #include <rte_common.h> 135074e1d5SCristian Dumitrescu #include <rte_ethdev.h> 14607dd517SCristian Dumitrescu #include <rte_ring.h> 155074e1d5SCristian Dumitrescu #include <rte_swx_port_ethdev.h> 1677a41301SCristian Dumitrescu #include <rte_swx_port_ring.h> 175074e1d5SCristian Dumitrescu #include <rte_swx_port_source_sink.h> 18e2b8dc52SVenkata Suresh Kumar P #include <rte_swx_port_fd.h> 195074e1d5SCristian Dumitrescu #include <rte_swx_pipeline.h> 205074e1d5SCristian Dumitrescu #include <rte_swx_ctl.h> 213b0cc5fbSCristian Dumitrescu #include <rte_swx_ipsec.h> 225074e1d5SCristian Dumitrescu 235074e1d5SCristian Dumitrescu #include "cli.h" 245074e1d5SCristian Dumitrescu 255074e1d5SCristian Dumitrescu #include "obj.h" 265074e1d5SCristian Dumitrescu #include "thread.h" 275074e1d5SCristian Dumitrescu 285074e1d5SCristian Dumitrescu #ifndef CMD_MAX_TOKENS 295074e1d5SCristian Dumitrescu #define CMD_MAX_TOKENS 256 305074e1d5SCristian Dumitrescu #endif 315074e1d5SCristian Dumitrescu 326bc14d9fSCristian Dumitrescu #ifndef MAX_LINE_SIZE 336bc14d9fSCristian Dumitrescu #define MAX_LINE_SIZE 2048 346bc14d9fSCristian Dumitrescu #endif 356bc14d9fSCristian Dumitrescu 365074e1d5SCristian Dumitrescu #define MSG_OUT_OF_MEMORY "Not enough memory.\n" 375074e1d5SCristian Dumitrescu #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n" 385074e1d5SCristian Dumitrescu #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n" 395074e1d5SCristian Dumitrescu #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n" 405074e1d5SCristian Dumitrescu #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n" 415074e1d5SCristian Dumitrescu #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n" 425074e1d5SCristian Dumitrescu #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n" 435074e1d5SCristian Dumitrescu #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n" 445074e1d5SCristian Dumitrescu #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n" 455074e1d5SCristian Dumitrescu #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n" 465074e1d5SCristian Dumitrescu #define MSG_CMD_FAIL "Command \"%s\" failed.\n" 475074e1d5SCristian Dumitrescu 485074e1d5SCristian Dumitrescu #define skip_white_spaces(pos) \ 495074e1d5SCristian Dumitrescu ({ \ 505074e1d5SCristian Dumitrescu __typeof__(pos) _p = (pos); \ 515074e1d5SCristian Dumitrescu for ( ; isspace(*_p); _p++) \ 525074e1d5SCristian Dumitrescu ; \ 535074e1d5SCristian Dumitrescu _p; \ 545074e1d5SCristian Dumitrescu }) 555074e1d5SCristian Dumitrescu 565074e1d5SCristian Dumitrescu static int 575074e1d5SCristian Dumitrescu parser_read_uint64(uint64_t *value, const char *p) 585074e1d5SCristian Dumitrescu { 595074e1d5SCristian Dumitrescu char *next; 605074e1d5SCristian Dumitrescu uint64_t val; 615074e1d5SCristian Dumitrescu 625074e1d5SCristian Dumitrescu p = skip_white_spaces(p); 635074e1d5SCristian Dumitrescu if (!isdigit(*p)) 645074e1d5SCristian Dumitrescu return -EINVAL; 655074e1d5SCristian Dumitrescu 660d644eb6SChurchill Khangar val = strtoul(p, &next, 0); 675074e1d5SCristian Dumitrescu if (p == next) 685074e1d5SCristian Dumitrescu return -EINVAL; 695074e1d5SCristian Dumitrescu 705074e1d5SCristian Dumitrescu p = next; 715074e1d5SCristian Dumitrescu switch (*p) { 725074e1d5SCristian Dumitrescu case 'T': 735074e1d5SCristian Dumitrescu val *= 1024ULL; 745074e1d5SCristian Dumitrescu /* fall through */ 755074e1d5SCristian Dumitrescu case 'G': 765074e1d5SCristian Dumitrescu val *= 1024ULL; 775074e1d5SCristian Dumitrescu /* fall through */ 785074e1d5SCristian Dumitrescu case 'M': 795074e1d5SCristian Dumitrescu val *= 1024ULL; 805074e1d5SCristian Dumitrescu /* fall through */ 815074e1d5SCristian Dumitrescu case 'k': 825074e1d5SCristian Dumitrescu case 'K': 835074e1d5SCristian Dumitrescu val *= 1024ULL; 845074e1d5SCristian Dumitrescu p++; 855074e1d5SCristian Dumitrescu break; 865074e1d5SCristian Dumitrescu } 875074e1d5SCristian Dumitrescu 885074e1d5SCristian Dumitrescu p = skip_white_spaces(p); 895074e1d5SCristian Dumitrescu if (*p != '\0') 905074e1d5SCristian Dumitrescu return -EINVAL; 915074e1d5SCristian Dumitrescu 925074e1d5SCristian Dumitrescu *value = val; 935074e1d5SCristian Dumitrescu return 0; 945074e1d5SCristian Dumitrescu } 955074e1d5SCristian Dumitrescu 965074e1d5SCristian Dumitrescu static int 975074e1d5SCristian Dumitrescu parser_read_uint32(uint32_t *value, const char *p) 985074e1d5SCristian Dumitrescu { 995074e1d5SCristian Dumitrescu uint64_t val = 0; 1005074e1d5SCristian Dumitrescu int ret = parser_read_uint64(&val, p); 1015074e1d5SCristian Dumitrescu 1025074e1d5SCristian Dumitrescu if (ret < 0) 1035074e1d5SCristian Dumitrescu return ret; 1045074e1d5SCristian Dumitrescu 1055074e1d5SCristian Dumitrescu if (val > UINT32_MAX) 1065074e1d5SCristian Dumitrescu return -ERANGE; 1075074e1d5SCristian Dumitrescu 1085074e1d5SCristian Dumitrescu *value = val; 1095074e1d5SCristian Dumitrescu return 0; 1105074e1d5SCristian Dumitrescu } 1115074e1d5SCristian Dumitrescu 1125074e1d5SCristian Dumitrescu #define PARSE_DELIMITER " \f\n\r\t\v" 1135074e1d5SCristian Dumitrescu 1145074e1d5SCristian Dumitrescu static int 1155074e1d5SCristian Dumitrescu parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens) 1165074e1d5SCristian Dumitrescu { 1175074e1d5SCristian Dumitrescu uint32_t i; 1185074e1d5SCristian Dumitrescu 1195074e1d5SCristian Dumitrescu if ((string == NULL) || 1205074e1d5SCristian Dumitrescu (tokens == NULL) || 1215074e1d5SCristian Dumitrescu (*n_tokens < 1)) 1225074e1d5SCristian Dumitrescu return -EINVAL; 1235074e1d5SCristian Dumitrescu 1245074e1d5SCristian Dumitrescu for (i = 0; i < *n_tokens; i++) { 1255074e1d5SCristian Dumitrescu tokens[i] = strtok_r(string, PARSE_DELIMITER, &string); 1265074e1d5SCristian Dumitrescu if (tokens[i] == NULL) 1275074e1d5SCristian Dumitrescu break; 1285074e1d5SCristian Dumitrescu } 1295074e1d5SCristian Dumitrescu 1305074e1d5SCristian Dumitrescu if ((i == *n_tokens) && strtok_r(string, PARSE_DELIMITER, &string)) 1315074e1d5SCristian Dumitrescu return -E2BIG; 1325074e1d5SCristian Dumitrescu 1335074e1d5SCristian Dumitrescu *n_tokens = i; 1345074e1d5SCristian Dumitrescu return 0; 1355074e1d5SCristian Dumitrescu } 1365074e1d5SCristian Dumitrescu 1375074e1d5SCristian Dumitrescu static int 1385074e1d5SCristian Dumitrescu is_comment(char *in) 1395074e1d5SCristian Dumitrescu { 1405074e1d5SCristian Dumitrescu if ((strlen(in) && index("!#%;", in[0])) || 1415074e1d5SCristian Dumitrescu (strncmp(in, "//", 2) == 0) || 1425074e1d5SCristian Dumitrescu (strncmp(in, "--", 2) == 0)) 1435074e1d5SCristian Dumitrescu return 1; 1445074e1d5SCristian Dumitrescu 1455074e1d5SCristian Dumitrescu return 0; 1465074e1d5SCristian Dumitrescu } 1475074e1d5SCristian Dumitrescu 14883f58a7bSCristian Dumitrescu static void 14983f58a7bSCristian Dumitrescu table_entry_free(struct rte_swx_table_entry *entry) 15083f58a7bSCristian Dumitrescu { 15183f58a7bSCristian Dumitrescu if (!entry) 15283f58a7bSCristian Dumitrescu return; 15383f58a7bSCristian Dumitrescu 15483f58a7bSCristian Dumitrescu free(entry->key); 15583f58a7bSCristian Dumitrescu free(entry->key_mask); 15683f58a7bSCristian Dumitrescu free(entry->action_data); 15783f58a7bSCristian Dumitrescu free(entry); 15883f58a7bSCristian Dumitrescu } 15983f58a7bSCristian Dumitrescu 16083f58a7bSCristian Dumitrescu static struct rte_swx_table_entry * 16183f58a7bSCristian Dumitrescu parse_table_entry(struct rte_swx_ctl_pipeline *p, 16283f58a7bSCristian Dumitrescu char *table_name, 16383f58a7bSCristian Dumitrescu char **tokens, 16483f58a7bSCristian Dumitrescu uint32_t n_tokens) 16583f58a7bSCristian Dumitrescu { 16683f58a7bSCristian Dumitrescu struct rte_swx_table_entry *entry; 16783f58a7bSCristian Dumitrescu char *line; 16883f58a7bSCristian Dumitrescu uint32_t i; 16983f58a7bSCristian Dumitrescu 17083f58a7bSCristian Dumitrescu /* Buffer allocation. */ 17183f58a7bSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 17283f58a7bSCristian Dumitrescu if (!line) 17383f58a7bSCristian Dumitrescu return NULL; 17483f58a7bSCristian Dumitrescu 17583f58a7bSCristian Dumitrescu /* Copy tokens to buffer. Since the tokens were initially part of a buffer of size 17683f58a7bSCristian Dumitrescu * MAX_LINE_LENGTH, it is guaranteed that putting back some of them into a buffer of the 17783f58a7bSCristian Dumitrescu * same size separated by a single space will not result in buffer overrun. 17883f58a7bSCristian Dumitrescu */ 17983f58a7bSCristian Dumitrescu line[0] = 0; 18083f58a7bSCristian Dumitrescu for (i = 0; i < n_tokens; i++) { 18183f58a7bSCristian Dumitrescu if (i) 18283f58a7bSCristian Dumitrescu strcat(line, " "); 18383f58a7bSCristian Dumitrescu 18483f58a7bSCristian Dumitrescu strcat(line, tokens[i]); 18583f58a7bSCristian Dumitrescu } 18683f58a7bSCristian Dumitrescu 18783f58a7bSCristian Dumitrescu /* Read the table entry from the input buffer. */ 18883f58a7bSCristian Dumitrescu entry = rte_swx_ctl_pipeline_table_entry_read(p, table_name, line, NULL); 18983f58a7bSCristian Dumitrescu 19083f58a7bSCristian Dumitrescu /* Buffer free. */ 19183f58a7bSCristian Dumitrescu free(line); 19283f58a7bSCristian Dumitrescu 19383f58a7bSCristian Dumitrescu return entry; 19483f58a7bSCristian Dumitrescu } 19583f58a7bSCristian Dumitrescu 1965074e1d5SCristian Dumitrescu static const char cmd_mempool_help[] = 19702d36ef6SCristian Dumitrescu "mempool <mempool_name> " 19802d36ef6SCristian Dumitrescu "meta <mbuf_private_size> " 19902d36ef6SCristian Dumitrescu "pkt <pkt_buffer_size> " 20002d36ef6SCristian Dumitrescu "pool <pool_size> " 20102d36ef6SCristian Dumitrescu "cache <cache_size> " 20202d36ef6SCristian Dumitrescu "numa <numa_node>\n"; 2035074e1d5SCristian Dumitrescu 2045074e1d5SCristian Dumitrescu static void 2055074e1d5SCristian Dumitrescu cmd_mempool(char **tokens, 2065074e1d5SCristian Dumitrescu uint32_t n_tokens, 2075074e1d5SCristian Dumitrescu char *out, 2085074e1d5SCristian Dumitrescu size_t out_size, 20902d36ef6SCristian Dumitrescu void *obj __rte_unused) 2105074e1d5SCristian Dumitrescu { 21102d36ef6SCristian Dumitrescu struct rte_mempool *mp; 21202d36ef6SCristian Dumitrescu char *mempool_name; 21302d36ef6SCristian Dumitrescu uint32_t mbuf_private_size, pkt_buffer_size, pool_size, cache_size, numa_node; 2145074e1d5SCristian Dumitrescu 21502d36ef6SCristian Dumitrescu if (n_tokens != 12) { 2165074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2175074e1d5SCristian Dumitrescu return; 2185074e1d5SCristian Dumitrescu } 2195074e1d5SCristian Dumitrescu 22002d36ef6SCristian Dumitrescu mempool_name = tokens[1]; 2215074e1d5SCristian Dumitrescu 22202d36ef6SCristian Dumitrescu if (strcmp(tokens[2], "meta")) { 22302d36ef6SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meta"); 2245074e1d5SCristian Dumitrescu return; 2255074e1d5SCristian Dumitrescu } 2265074e1d5SCristian Dumitrescu 22702d36ef6SCristian Dumitrescu if (parser_read_uint32(&mbuf_private_size, tokens[3])) { 22802d36ef6SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "mbuf_private_size"); 2295074e1d5SCristian Dumitrescu return; 2305074e1d5SCristian Dumitrescu } 2315074e1d5SCristian Dumitrescu 23202d36ef6SCristian Dumitrescu if (strcmp(tokens[4], "pkt")) { 23302d36ef6SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkt"); 23402d36ef6SCristian Dumitrescu return; 23502d36ef6SCristian Dumitrescu } 23602d36ef6SCristian Dumitrescu 23702d36ef6SCristian Dumitrescu if (parser_read_uint32(&pkt_buffer_size, tokens[5])) { 23802d36ef6SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pkt_buffer_size"); 23902d36ef6SCristian Dumitrescu return; 24002d36ef6SCristian Dumitrescu } 24102d36ef6SCristian Dumitrescu 24202d36ef6SCristian Dumitrescu if (strcmp(tokens[6], "pool")) { 2435074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool"); 2445074e1d5SCristian Dumitrescu return; 2455074e1d5SCristian Dumitrescu } 2465074e1d5SCristian Dumitrescu 24702d36ef6SCristian Dumitrescu if (parser_read_uint32(&pool_size, tokens[7])) { 2485074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pool_size"); 2495074e1d5SCristian Dumitrescu return; 2505074e1d5SCristian Dumitrescu } 2515074e1d5SCristian Dumitrescu 25202d36ef6SCristian Dumitrescu if (strcmp(tokens[8], "cache")) { 2535074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache"); 2545074e1d5SCristian Dumitrescu return; 2555074e1d5SCristian Dumitrescu } 2565074e1d5SCristian Dumitrescu 25702d36ef6SCristian Dumitrescu if (parser_read_uint32(&cache_size, tokens[9])) { 2585074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cache_size"); 2595074e1d5SCristian Dumitrescu return; 2605074e1d5SCristian Dumitrescu } 2615074e1d5SCristian Dumitrescu 26202d36ef6SCristian Dumitrescu if (strcmp(tokens[10], "numa")) { 26302d36ef6SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa"); 2645074e1d5SCristian Dumitrescu return; 2655074e1d5SCristian Dumitrescu } 2665074e1d5SCristian Dumitrescu 26702d36ef6SCristian Dumitrescu if (parser_read_uint32(&numa_node, tokens[11])) { 26802d36ef6SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node"); 2695074e1d5SCristian Dumitrescu return; 2705074e1d5SCristian Dumitrescu } 2715074e1d5SCristian Dumitrescu 27202d36ef6SCristian Dumitrescu mp = rte_pktmbuf_pool_create(mempool_name, 27302d36ef6SCristian Dumitrescu pool_size, 27402d36ef6SCristian Dumitrescu cache_size, 27502d36ef6SCristian Dumitrescu mbuf_private_size, 27602d36ef6SCristian Dumitrescu pkt_buffer_size, 27702d36ef6SCristian Dumitrescu numa_node); 27802d36ef6SCristian Dumitrescu if (!mp) { 2795074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 2805074e1d5SCristian Dumitrescu return; 2815074e1d5SCristian Dumitrescu } 2825074e1d5SCristian Dumitrescu } 2835074e1d5SCristian Dumitrescu 284f31c80f8SCristian Dumitrescu static const char cmd_ethdev_help[] = 285f31c80f8SCristian Dumitrescu "ethdev <ethdev_name>\n" 2865074e1d5SCristian Dumitrescu " rxq <n_queues> <queue_size> <mempool_name>\n" 2875074e1d5SCristian Dumitrescu " txq <n_queues> <queue_size>\n" 2885074e1d5SCristian Dumitrescu " promiscuous on | off\n" 2895074e1d5SCristian Dumitrescu " [rss <qid_0> ... <qid_n>]\n"; 2905074e1d5SCristian Dumitrescu 2915074e1d5SCristian Dumitrescu static void 292f31c80f8SCristian Dumitrescu cmd_ethdev(char **tokens, 2935074e1d5SCristian Dumitrescu uint32_t n_tokens, 2945074e1d5SCristian Dumitrescu char *out, 2955074e1d5SCristian Dumitrescu size_t out_size, 29678dffe31SCristian Dumitrescu void *obj __rte_unused) 2975074e1d5SCristian Dumitrescu { 29878dffe31SCristian Dumitrescu struct ethdev_params p; 29978dffe31SCristian Dumitrescu struct ethdev_params_rss rss; 3005074e1d5SCristian Dumitrescu char *name; 30178dffe31SCristian Dumitrescu int status; 3025074e1d5SCristian Dumitrescu 3035074e1d5SCristian Dumitrescu memset(&p, 0, sizeof(p)); 30478dffe31SCristian Dumitrescu memset(&rss, 0, sizeof(rss)); 3055074e1d5SCristian Dumitrescu 30678dffe31SCristian Dumitrescu if (n_tokens < 11 || n_tokens > 12 + ETHDEV_RXQ_RSS_MAX) { 3075074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 3085074e1d5SCristian Dumitrescu return; 3095074e1d5SCristian Dumitrescu } 3105074e1d5SCristian Dumitrescu name = tokens[1]; 3115074e1d5SCristian Dumitrescu 312f31c80f8SCristian Dumitrescu if (strcmp(tokens[2], "rxq") != 0) { 3135074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq"); 3145074e1d5SCristian Dumitrescu return; 3155074e1d5SCristian Dumitrescu } 3165074e1d5SCristian Dumitrescu 317f31c80f8SCristian Dumitrescu if (parser_read_uint32(&p.rx.n_queues, tokens[3]) != 0) { 3185074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_queues"); 3195074e1d5SCristian Dumitrescu return; 3205074e1d5SCristian Dumitrescu } 321f31c80f8SCristian Dumitrescu if (parser_read_uint32(&p.rx.queue_size, tokens[4]) != 0) { 3225074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "queue_size"); 3235074e1d5SCristian Dumitrescu return; 3245074e1d5SCristian Dumitrescu } 3255074e1d5SCristian Dumitrescu 326f31c80f8SCristian Dumitrescu p.rx.mempool_name = tokens[5]; 3275074e1d5SCristian Dumitrescu 328f31c80f8SCristian Dumitrescu if (strcmp(tokens[6], "txq") != 0) { 3295074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq"); 3305074e1d5SCristian Dumitrescu return; 3315074e1d5SCristian Dumitrescu } 3325074e1d5SCristian Dumitrescu 333f31c80f8SCristian Dumitrescu if (parser_read_uint32(&p.tx.n_queues, tokens[7]) != 0) { 3345074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_queues"); 3355074e1d5SCristian Dumitrescu return; 3365074e1d5SCristian Dumitrescu } 3375074e1d5SCristian Dumitrescu 338f31c80f8SCristian Dumitrescu if (parser_read_uint32(&p.tx.queue_size, tokens[8]) != 0) { 3395074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "queue_size"); 3405074e1d5SCristian Dumitrescu return; 3415074e1d5SCristian Dumitrescu } 3425074e1d5SCristian Dumitrescu 343f31c80f8SCristian Dumitrescu if (strcmp(tokens[9], "promiscuous") != 0) { 3445074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous"); 3455074e1d5SCristian Dumitrescu return; 3465074e1d5SCristian Dumitrescu } 3475074e1d5SCristian Dumitrescu 348f31c80f8SCristian Dumitrescu if (strcmp(tokens[10], "on") == 0) 3495074e1d5SCristian Dumitrescu p.promiscuous = 1; 350f31c80f8SCristian Dumitrescu else if (strcmp(tokens[10], "off") == 0) 3515074e1d5SCristian Dumitrescu p.promiscuous = 0; 3525074e1d5SCristian Dumitrescu else { 3535074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off"); 3545074e1d5SCristian Dumitrescu return; 3555074e1d5SCristian Dumitrescu } 3565074e1d5SCristian Dumitrescu 3575074e1d5SCristian Dumitrescu /* RSS */ 3585074e1d5SCristian Dumitrescu p.rx.rss = NULL; 359f31c80f8SCristian Dumitrescu if (n_tokens > 11) { 3605074e1d5SCristian Dumitrescu uint32_t queue_id, i; 3615074e1d5SCristian Dumitrescu 362f31c80f8SCristian Dumitrescu if (strcmp(tokens[11], "rss") != 0) { 3635074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss"); 3645074e1d5SCristian Dumitrescu return; 3655074e1d5SCristian Dumitrescu } 3665074e1d5SCristian Dumitrescu 3675074e1d5SCristian Dumitrescu p.rx.rss = &rss; 3685074e1d5SCristian Dumitrescu 3695074e1d5SCristian Dumitrescu rss.n_queues = 0; 370f31c80f8SCristian Dumitrescu for (i = 12; i < n_tokens; i++) { 3715074e1d5SCristian Dumitrescu if (parser_read_uint32(&queue_id, tokens[i]) != 0) { 3725074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 3735074e1d5SCristian Dumitrescu "queue_id"); 3745074e1d5SCristian Dumitrescu return; 3755074e1d5SCristian Dumitrescu } 3765074e1d5SCristian Dumitrescu 3775074e1d5SCristian Dumitrescu rss.queue_id[rss.n_queues] = queue_id; 3785074e1d5SCristian Dumitrescu rss.n_queues++; 3795074e1d5SCristian Dumitrescu } 3805074e1d5SCristian Dumitrescu } 3815074e1d5SCristian Dumitrescu 38278dffe31SCristian Dumitrescu status = ethdev_config(name, &p); 38378dffe31SCristian Dumitrescu if (status) { 3845074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 3855074e1d5SCristian Dumitrescu return; 3865074e1d5SCristian Dumitrescu } 3875074e1d5SCristian Dumitrescu } 3885074e1d5SCristian Dumitrescu 3895074e1d5SCristian Dumitrescu static void 39078dffe31SCristian Dumitrescu ethdev_show(uint16_t port_id, char **out, size_t *out_size) 3915074e1d5SCristian Dumitrescu { 39278dffe31SCristian Dumitrescu char name[RTE_ETH_NAME_MAX_LEN]; 39378dffe31SCristian Dumitrescu struct rte_eth_dev_info info; 3945074e1d5SCristian Dumitrescu struct rte_eth_stats stats; 39578dffe31SCristian Dumitrescu struct rte_ether_addr addr; 39678dffe31SCristian Dumitrescu struct rte_eth_link link; 39778dffe31SCristian Dumitrescu uint32_t length; 39878dffe31SCristian Dumitrescu uint16_t mtu = 0; 3995074e1d5SCristian Dumitrescu 40078dffe31SCristian Dumitrescu if (!rte_eth_dev_is_valid_port(port_id)) 4015074e1d5SCristian Dumitrescu return; 4025074e1d5SCristian Dumitrescu 40378dffe31SCristian Dumitrescu rte_eth_dev_get_name_by_port(port_id, name); 40478dffe31SCristian Dumitrescu rte_eth_dev_info_get(port_id, &info); 40578dffe31SCristian Dumitrescu rte_eth_stats_get(port_id, &stats); 40678dffe31SCristian Dumitrescu rte_eth_macaddr_get(port_id, &addr); 40778dffe31SCristian Dumitrescu rte_eth_link_get(port_id, &link); 40878dffe31SCristian Dumitrescu rte_eth_dev_get_mtu(port_id, &mtu); 4095074e1d5SCristian Dumitrescu 41078dffe31SCristian Dumitrescu snprintf(*out, *out_size, 4115074e1d5SCristian Dumitrescu "%s: flags=<%s> mtu %u\n" 412c2c4f87bSAman Deep Singh "\tether " RTE_ETHER_ADDR_PRT_FMT " rxqueues %u txqueues %u\n" 4135074e1d5SCristian Dumitrescu "\tport# %u speed %s\n" 4145074e1d5SCristian Dumitrescu "\tRX packets %" PRIu64" bytes %" PRIu64"\n" 4155074e1d5SCristian Dumitrescu "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n" 4165074e1d5SCristian Dumitrescu "\tTX packets %" PRIu64" bytes %" PRIu64"\n" 41778dffe31SCristian Dumitrescu "\tTX errors %" PRIu64"\n\n", 41878dffe31SCristian Dumitrescu name, 41978dffe31SCristian Dumitrescu link.link_status ? "UP" : "DOWN", 4205074e1d5SCristian Dumitrescu mtu, 42178dffe31SCristian Dumitrescu RTE_ETHER_ADDR_BYTES(&addr), 42278dffe31SCristian Dumitrescu info.nb_rx_queues, 42378dffe31SCristian Dumitrescu info.nb_tx_queues, 42478dffe31SCristian Dumitrescu port_id, 42578dffe31SCristian Dumitrescu rte_eth_link_speed_to_str(link.link_speed), 4265074e1d5SCristian Dumitrescu stats.ipackets, 4275074e1d5SCristian Dumitrescu stats.ibytes, 4285074e1d5SCristian Dumitrescu stats.ierrors, 4295074e1d5SCristian Dumitrescu stats.imissed, 4305074e1d5SCristian Dumitrescu stats.rx_nombuf, 4315074e1d5SCristian Dumitrescu stats.opackets, 4325074e1d5SCristian Dumitrescu stats.obytes, 4335074e1d5SCristian Dumitrescu stats.oerrors); 43478dffe31SCristian Dumitrescu 43578dffe31SCristian Dumitrescu length = strlen(*out); 43678dffe31SCristian Dumitrescu *out_size -= length; 43778dffe31SCristian Dumitrescu *out += length; 4385074e1d5SCristian Dumitrescu } 4395074e1d5SCristian Dumitrescu 44078dffe31SCristian Dumitrescu 44178dffe31SCristian Dumitrescu static char cmd_ethdev_show_help[] = 44278dffe31SCristian Dumitrescu "ethdev show [ <ethdev_name> ]\n"; 44378dffe31SCristian Dumitrescu 4445074e1d5SCristian Dumitrescu static void 445f31c80f8SCristian Dumitrescu cmd_ethdev_show(char **tokens, 4465074e1d5SCristian Dumitrescu uint32_t n_tokens, 4475074e1d5SCristian Dumitrescu char *out, 4485074e1d5SCristian Dumitrescu size_t out_size, 44978dffe31SCristian Dumitrescu void *obj __rte_unused) 4505074e1d5SCristian Dumitrescu { 45178dffe31SCristian Dumitrescu uint16_t port_id; 4525074e1d5SCristian Dumitrescu 4535074e1d5SCristian Dumitrescu if (n_tokens != 2 && n_tokens != 3) { 4545074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 4555074e1d5SCristian Dumitrescu return; 4565074e1d5SCristian Dumitrescu } 4575074e1d5SCristian Dumitrescu 45878dffe31SCristian Dumitrescu /* Single device. */ 45978dffe31SCristian Dumitrescu if (n_tokens == 3) { 46078dffe31SCristian Dumitrescu int status; 4615074e1d5SCristian Dumitrescu 46278dffe31SCristian Dumitrescu status = rte_eth_dev_get_port_by_name(tokens[2], &port_id); 46378dffe31SCristian Dumitrescu if (status) 46478dffe31SCristian Dumitrescu snprintf(out, out_size, "Error: Invalid Ethernet device name.\n"); 4655074e1d5SCristian Dumitrescu 46678dffe31SCristian Dumitrescu ethdev_show(port_id, &out, &out_size); 4675074e1d5SCristian Dumitrescu return; 4685074e1d5SCristian Dumitrescu } 46978dffe31SCristian Dumitrescu 47078dffe31SCristian Dumitrescu /* All devices. */ 47178dffe31SCristian Dumitrescu for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) 47278dffe31SCristian Dumitrescu if (rte_eth_dev_is_valid_port(port_id)) 47378dffe31SCristian Dumitrescu ethdev_show(port_id, &out, &out_size); 4745074e1d5SCristian Dumitrescu } 4755074e1d5SCristian Dumitrescu 47677a41301SCristian Dumitrescu static const char cmd_ring_help[] = 47777a41301SCristian Dumitrescu "ring <ring_name> size <size> numa <numa_node>\n"; 47877a41301SCristian Dumitrescu 47977a41301SCristian Dumitrescu static void 48077a41301SCristian Dumitrescu cmd_ring(char **tokens, 48177a41301SCristian Dumitrescu uint32_t n_tokens, 48277a41301SCristian Dumitrescu char *out, 48377a41301SCristian Dumitrescu size_t out_size, 484607dd517SCristian Dumitrescu void *obj __rte_unused) 48577a41301SCristian Dumitrescu { 486607dd517SCristian Dumitrescu struct rte_ring *r; 48777a41301SCristian Dumitrescu char *name; 488607dd517SCristian Dumitrescu uint32_t size, numa_node; 48977a41301SCristian Dumitrescu 49077a41301SCristian Dumitrescu if (n_tokens != 6) { 49177a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 49277a41301SCristian Dumitrescu return; 49377a41301SCristian Dumitrescu } 49477a41301SCristian Dumitrescu 49577a41301SCristian Dumitrescu name = tokens[1]; 49677a41301SCristian Dumitrescu 497607dd517SCristian Dumitrescu if (strcmp(tokens[2], "size")) { 49877a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size"); 49977a41301SCristian Dumitrescu return; 50077a41301SCristian Dumitrescu } 50177a41301SCristian Dumitrescu 502607dd517SCristian Dumitrescu if (parser_read_uint32(&size, tokens[3])) { 50377a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "size"); 50477a41301SCristian Dumitrescu return; 50577a41301SCristian Dumitrescu } 50677a41301SCristian Dumitrescu 507607dd517SCristian Dumitrescu if (strcmp(tokens[4], "numa")) { 50877a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa"); 50977a41301SCristian Dumitrescu return; 51077a41301SCristian Dumitrescu } 51177a41301SCristian Dumitrescu 512607dd517SCristian Dumitrescu if (parser_read_uint32(&numa_node, tokens[5])) { 51377a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node"); 51477a41301SCristian Dumitrescu return; 51577a41301SCristian Dumitrescu } 51677a41301SCristian Dumitrescu 517607dd517SCristian Dumitrescu r = rte_ring_create( 518607dd517SCristian Dumitrescu name, 519607dd517SCristian Dumitrescu size, 520607dd517SCristian Dumitrescu (int)numa_node, 521607dd517SCristian Dumitrescu RING_F_SP_ENQ | RING_F_SC_DEQ); 522607dd517SCristian Dumitrescu if (!r) { 52377a41301SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 52477a41301SCristian Dumitrescu return; 52577a41301SCristian Dumitrescu } 52677a41301SCristian Dumitrescu } 52777a41301SCristian Dumitrescu 5281b41a527SCristian Dumitrescu static const char cmd_cryptodev_help[] = 5291b41a527SCristian Dumitrescu "cryptodev <cryptodev_name> queues <n_queue_pairs> qsize <queue_size>\n"; 5301b41a527SCristian Dumitrescu 5311b41a527SCristian Dumitrescu static void 5321b41a527SCristian Dumitrescu cmd_cryptodev(char **tokens, 5331b41a527SCristian Dumitrescu uint32_t n_tokens, 5341b41a527SCristian Dumitrescu char *out, 5351b41a527SCristian Dumitrescu size_t out_size, 5361b41a527SCristian Dumitrescu void *obj __rte_unused) 5371b41a527SCristian Dumitrescu { 5381b41a527SCristian Dumitrescu struct cryptodev_params params; 5391b41a527SCristian Dumitrescu char *cryptodev_name; 5401b41a527SCristian Dumitrescu int status; 5411b41a527SCristian Dumitrescu 5421b41a527SCristian Dumitrescu if (n_tokens != 6) { 5431b41a527SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 5441b41a527SCristian Dumitrescu return; 5451b41a527SCristian Dumitrescu } 5461b41a527SCristian Dumitrescu 5471b41a527SCristian Dumitrescu if (strcmp(tokens[0], "cryptodev")) { 5481b41a527SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cryptodev"); 5491b41a527SCristian Dumitrescu return; 5501b41a527SCristian Dumitrescu } 5511b41a527SCristian Dumitrescu 5521b41a527SCristian Dumitrescu cryptodev_name = tokens[1]; 5531b41a527SCristian Dumitrescu 5541b41a527SCristian Dumitrescu if (strcmp(tokens[2], "queues")) { 5551b41a527SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "queues"); 5561b41a527SCristian Dumitrescu return; 5571b41a527SCristian Dumitrescu } 5581b41a527SCristian Dumitrescu 5591b41a527SCristian Dumitrescu if (parser_read_uint32(¶ms.n_queue_pairs, tokens[3])) { 5601b41a527SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_queue_pairs"); 5611b41a527SCristian Dumitrescu return; 5621b41a527SCristian Dumitrescu } 5631b41a527SCristian Dumitrescu 5641b41a527SCristian Dumitrescu if (strcmp(tokens[4], "qsize")) { 5651b41a527SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize"); 5661b41a527SCristian Dumitrescu return; 5671b41a527SCristian Dumitrescu } 5681b41a527SCristian Dumitrescu 5691b41a527SCristian Dumitrescu 5701b41a527SCristian Dumitrescu if (parser_read_uint32(¶ms.queue_size, tokens[5])) { 5711b41a527SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "queue_size"); 5721b41a527SCristian Dumitrescu return; 5731b41a527SCristian Dumitrescu } 5741b41a527SCristian Dumitrescu 5751b41a527SCristian Dumitrescu status = cryptodev_config(cryptodev_name, ¶ms); 5761b41a527SCristian Dumitrescu if (status) 5771b41a527SCristian Dumitrescu snprintf(out, out_size, "Crypto device configuration failed (%d).\n", status); 5781b41a527SCristian Dumitrescu } 5791b41a527SCristian Dumitrescu 5809043f66aSCristian Dumitrescu static const char cmd_pipeline_codegen_help[] = 5819043f66aSCristian Dumitrescu "pipeline codegen <spec_file> <code_file>\n"; 5829043f66aSCristian Dumitrescu 5839043f66aSCristian Dumitrescu static void 5849043f66aSCristian Dumitrescu cmd_pipeline_codegen(char **tokens, 5859043f66aSCristian Dumitrescu uint32_t n_tokens, 5869043f66aSCristian Dumitrescu char *out, 5879043f66aSCristian Dumitrescu size_t out_size, 5889043f66aSCristian Dumitrescu void *obj __rte_unused) 5899043f66aSCristian Dumitrescu { 5909043f66aSCristian Dumitrescu FILE *spec_file = NULL; 5919043f66aSCristian Dumitrescu FILE *code_file = NULL; 5929043f66aSCristian Dumitrescu uint32_t err_line; 5939043f66aSCristian Dumitrescu const char *err_msg; 5949043f66aSCristian Dumitrescu int status; 5959043f66aSCristian Dumitrescu 5969043f66aSCristian Dumitrescu if (n_tokens != 4) { 5979043f66aSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 5989043f66aSCristian Dumitrescu return; 5999043f66aSCristian Dumitrescu } 6009043f66aSCristian Dumitrescu 6019043f66aSCristian Dumitrescu spec_file = fopen(tokens[2], "r"); 6029043f66aSCristian Dumitrescu if (!spec_file) { 6039043f66aSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[2]); 6049043f66aSCristian Dumitrescu return; 6059043f66aSCristian Dumitrescu } 6069043f66aSCristian Dumitrescu 6079043f66aSCristian Dumitrescu code_file = fopen(tokens[3], "w"); 6089043f66aSCristian Dumitrescu if (!code_file) { 6099043f66aSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[3]); 610ab492f94SHarshad Narayane fclose(spec_file); 6119043f66aSCristian Dumitrescu return; 6129043f66aSCristian Dumitrescu } 6139043f66aSCristian Dumitrescu 6149043f66aSCristian Dumitrescu status = rte_swx_pipeline_codegen(spec_file, 6159043f66aSCristian Dumitrescu code_file, 6169043f66aSCristian Dumitrescu &err_line, 6179043f66aSCristian Dumitrescu &err_msg); 6189043f66aSCristian Dumitrescu 6199043f66aSCristian Dumitrescu fclose(spec_file); 6209043f66aSCristian Dumitrescu fclose(code_file); 6219043f66aSCristian Dumitrescu 6229043f66aSCristian Dumitrescu if (status) { 6239043f66aSCristian Dumitrescu snprintf(out, out_size, "Error %d at line %u: %s\n.", 6249043f66aSCristian Dumitrescu status, err_line, err_msg); 6259043f66aSCristian Dumitrescu return; 6269043f66aSCristian Dumitrescu } 6279043f66aSCristian Dumitrescu } 6286bc14d9fSCristian Dumitrescu 6296bc14d9fSCristian Dumitrescu static const char cmd_pipeline_libbuild_help[] = 6306bc14d9fSCristian Dumitrescu "pipeline libbuild <code_file> <lib_file>\n"; 6316bc14d9fSCristian Dumitrescu 6326bc14d9fSCristian Dumitrescu static void 6336bc14d9fSCristian Dumitrescu cmd_pipeline_libbuild(char **tokens, 6346bc14d9fSCristian Dumitrescu uint32_t n_tokens, 6356bc14d9fSCristian Dumitrescu char *out, 6366bc14d9fSCristian Dumitrescu size_t out_size, 6376bc14d9fSCristian Dumitrescu void *obj __rte_unused) 6386bc14d9fSCristian Dumitrescu { 6396bc14d9fSCristian Dumitrescu char *code_file, *lib_file, *obj_file = NULL, *log_file = NULL; 6406bc14d9fSCristian Dumitrescu char *install_dir, *cwd = NULL, *buffer = NULL; 6416bc14d9fSCristian Dumitrescu size_t length; 6426bc14d9fSCristian Dumitrescu int status = 0; 6436bc14d9fSCristian Dumitrescu 6446bc14d9fSCristian Dumitrescu if (n_tokens != 4) { 6456bc14d9fSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 6466bc14d9fSCristian Dumitrescu goto free; 6476bc14d9fSCristian Dumitrescu } 6486bc14d9fSCristian Dumitrescu 6496bc14d9fSCristian Dumitrescu install_dir = getenv("RTE_INSTALL_DIR"); 6506bc14d9fSCristian Dumitrescu if (!install_dir) { 6516bc14d9fSCristian Dumitrescu cwd = malloc(MAX_LINE_SIZE); 6526bc14d9fSCristian Dumitrescu if (!cwd) { 6536bc14d9fSCristian Dumitrescu snprintf(out, out_size, MSG_OUT_OF_MEMORY); 6546bc14d9fSCristian Dumitrescu goto free; 6556bc14d9fSCristian Dumitrescu } 6566bc14d9fSCristian Dumitrescu 6576bc14d9fSCristian Dumitrescu install_dir = getcwd(cwd, MAX_LINE_SIZE); 6586bc14d9fSCristian Dumitrescu if (!install_dir) { 6596bc14d9fSCristian Dumitrescu snprintf(out, out_size, "Error: Path too long.\n"); 6606bc14d9fSCristian Dumitrescu goto free; 6616bc14d9fSCristian Dumitrescu } 6626bc14d9fSCristian Dumitrescu } 6636bc14d9fSCristian Dumitrescu 6646bc14d9fSCristian Dumitrescu snprintf(out, out_size, "Using DPDK source code from \"%s\".\n", install_dir); 6656bc14d9fSCristian Dumitrescu out_size -= strlen(out); 6666bc14d9fSCristian Dumitrescu out += strlen(out); 6676bc14d9fSCristian Dumitrescu 6686bc14d9fSCristian Dumitrescu code_file = tokens[2]; 6696bc14d9fSCristian Dumitrescu length = strnlen(code_file, MAX_LINE_SIZE); 6706bc14d9fSCristian Dumitrescu if ((length < 3) || 6716bc14d9fSCristian Dumitrescu (code_file[length - 2] != '.') || 6726bc14d9fSCristian Dumitrescu (code_file[length - 1] != 'c')) { 6736bc14d9fSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "code_file"); 6746bc14d9fSCristian Dumitrescu goto free; 6756bc14d9fSCristian Dumitrescu } 6766bc14d9fSCristian Dumitrescu 6776bc14d9fSCristian Dumitrescu lib_file = tokens[3]; 6786bc14d9fSCristian Dumitrescu length = strnlen(lib_file, MAX_LINE_SIZE); 6796bc14d9fSCristian Dumitrescu if ((length < 4) || 6806bc14d9fSCristian Dumitrescu (lib_file[length - 3] != '.') || 6816bc14d9fSCristian Dumitrescu (lib_file[length - 2] != 's') || 6826bc14d9fSCristian Dumitrescu (lib_file[length - 1] != 'o')) { 6836bc14d9fSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "lib_file"); 6846bc14d9fSCristian Dumitrescu goto free; 6856bc14d9fSCristian Dumitrescu } 6866bc14d9fSCristian Dumitrescu 6876bc14d9fSCristian Dumitrescu obj_file = malloc(length); 6886bc14d9fSCristian Dumitrescu log_file = malloc(length + 2); 6896bc14d9fSCristian Dumitrescu if (!obj_file || !log_file) { 6906bc14d9fSCristian Dumitrescu snprintf(out, out_size, MSG_OUT_OF_MEMORY); 6916bc14d9fSCristian Dumitrescu goto free; 6926bc14d9fSCristian Dumitrescu } 6936bc14d9fSCristian Dumitrescu 6946bc14d9fSCristian Dumitrescu memcpy(obj_file, lib_file, length - 2); 6956bc14d9fSCristian Dumitrescu obj_file[length - 2] = 'o'; 6966bc14d9fSCristian Dumitrescu obj_file[length - 1] = 0; 6976bc14d9fSCristian Dumitrescu 6986bc14d9fSCristian Dumitrescu memcpy(log_file, lib_file, length - 2); 6996bc14d9fSCristian Dumitrescu log_file[length - 2] = 'l'; 7006bc14d9fSCristian Dumitrescu log_file[length - 1] = 'o'; 7016bc14d9fSCristian Dumitrescu log_file[length] = 'g'; 7026bc14d9fSCristian Dumitrescu log_file[length + 1] = 0; 7036bc14d9fSCristian Dumitrescu 7046bc14d9fSCristian Dumitrescu buffer = malloc(MAX_LINE_SIZE); 7056bc14d9fSCristian Dumitrescu if (!buffer) { 7066bc14d9fSCristian Dumitrescu snprintf(out, out_size, MSG_OUT_OF_MEMORY); 707b42f3e2fSHarshad Narayane goto free; 7086bc14d9fSCristian Dumitrescu } 7096bc14d9fSCristian Dumitrescu 7106bc14d9fSCristian Dumitrescu snprintf(buffer, 7116bc14d9fSCristian Dumitrescu MAX_LINE_SIZE, 7126bc14d9fSCristian Dumitrescu "gcc -c -O3 -fpic -Wno-deprecated-declarations -o %s %s " 7136bc14d9fSCristian Dumitrescu "-I %s/lib/pipeline " 7146bc14d9fSCristian Dumitrescu "-I %s/lib/eal/include " 7156bc14d9fSCristian Dumitrescu "-I %s/lib/eal/x86/include " 7166bc14d9fSCristian Dumitrescu "-I %s/lib/eal/include/generic " 7176bc14d9fSCristian Dumitrescu "-I %s/lib/meter " 7186bc14d9fSCristian Dumitrescu "-I %s/lib/port " 7196bc14d9fSCristian Dumitrescu "-I %s/lib/table " 7206bc14d9fSCristian Dumitrescu "-I %s/lib/pipeline " 7216bc14d9fSCristian Dumitrescu "-I %s/config " 7226bc14d9fSCristian Dumitrescu "-I %s/build " 7236bc14d9fSCristian Dumitrescu "-I %s/lib/eal/linux/include " 7246bc14d9fSCristian Dumitrescu ">%s 2>&1 " 7256bc14d9fSCristian Dumitrescu "&& " 7266bc14d9fSCristian Dumitrescu "gcc -shared %s -o %s " 7276bc14d9fSCristian Dumitrescu ">>%s 2>&1", 7286bc14d9fSCristian Dumitrescu obj_file, 7296bc14d9fSCristian Dumitrescu code_file, 7306bc14d9fSCristian Dumitrescu install_dir, 7316bc14d9fSCristian Dumitrescu install_dir, 7326bc14d9fSCristian Dumitrescu install_dir, 7336bc14d9fSCristian Dumitrescu install_dir, 7346bc14d9fSCristian Dumitrescu install_dir, 7356bc14d9fSCristian Dumitrescu install_dir, 7366bc14d9fSCristian Dumitrescu install_dir, 7376bc14d9fSCristian Dumitrescu install_dir, 7386bc14d9fSCristian Dumitrescu install_dir, 7396bc14d9fSCristian Dumitrescu install_dir, 7406bc14d9fSCristian Dumitrescu install_dir, 7416bc14d9fSCristian Dumitrescu log_file, 7426bc14d9fSCristian Dumitrescu obj_file, 7436bc14d9fSCristian Dumitrescu lib_file, 7446bc14d9fSCristian Dumitrescu log_file); 7456bc14d9fSCristian Dumitrescu 7466bc14d9fSCristian Dumitrescu status = system(buffer); 7476bc14d9fSCristian Dumitrescu if (status) { 7486bc14d9fSCristian Dumitrescu snprintf(out, 7496bc14d9fSCristian Dumitrescu out_size, 7506bc14d9fSCristian Dumitrescu "Library build failed, see file \"%s\" for details.\n", 7516bc14d9fSCristian Dumitrescu log_file); 7526bc14d9fSCristian Dumitrescu goto free; 7536bc14d9fSCristian Dumitrescu } 7546bc14d9fSCristian Dumitrescu 7556bc14d9fSCristian Dumitrescu free: 7566bc14d9fSCristian Dumitrescu free(cwd); 7576bc14d9fSCristian Dumitrescu free(obj_file); 7586bc14d9fSCristian Dumitrescu free(log_file); 7596bc14d9fSCristian Dumitrescu free(buffer); 7606bc14d9fSCristian Dumitrescu } 7616bc14d9fSCristian Dumitrescu 7625074e1d5SCristian Dumitrescu static const char cmd_pipeline_build_help[] = 76368b95704SCristian Dumitrescu "pipeline <pipeline_name> build lib <lib_file> io <iospec_file> numa <numa_node>\n"; 7645074e1d5SCristian Dumitrescu 7655074e1d5SCristian Dumitrescu static void 7665074e1d5SCristian Dumitrescu cmd_pipeline_build(char **tokens, 7675074e1d5SCristian Dumitrescu uint32_t n_tokens, 7685074e1d5SCristian Dumitrescu char *out, 7695074e1d5SCristian Dumitrescu size_t out_size, 77068b95704SCristian Dumitrescu void *obj __rte_unused) 7715074e1d5SCristian Dumitrescu { 77268b95704SCristian Dumitrescu struct rte_swx_pipeline *p = NULL; 77368b95704SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl = NULL; 77468b95704SCristian Dumitrescu char *pipeline_name, *lib_file_name, *iospec_file_name; 77568b95704SCristian Dumitrescu FILE *iospec_file = NULL; 77668b95704SCristian Dumitrescu uint32_t numa_node = 0; 77768b95704SCristian Dumitrescu int status = 0; 7785074e1d5SCristian Dumitrescu 77968b95704SCristian Dumitrescu /* Parsing. */ 78068b95704SCristian Dumitrescu if (n_tokens != 9) { 7815074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 7825074e1d5SCristian Dumitrescu return; 7835074e1d5SCristian Dumitrescu } 7845074e1d5SCristian Dumitrescu 78568b95704SCristian Dumitrescu pipeline_name = tokens[1]; 78668b95704SCristian Dumitrescu 78768b95704SCristian Dumitrescu if (strcmp(tokens[2], "build")) { 78868b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "build"); 7895074e1d5SCristian Dumitrescu return; 7905074e1d5SCristian Dumitrescu } 7915074e1d5SCristian Dumitrescu 79268b95704SCristian Dumitrescu if (strcmp(tokens[3], "lib")) { 79368b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "lib"); 7945074e1d5SCristian Dumitrescu return; 7955074e1d5SCristian Dumitrescu } 7965074e1d5SCristian Dumitrescu 79768b95704SCristian Dumitrescu lib_file_name = tokens[4]; 79868b95704SCristian Dumitrescu 79968b95704SCristian Dumitrescu if (strcmp(tokens[5], "io")) { 80068b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "io"); 80168b95704SCristian Dumitrescu return; 80268b95704SCristian Dumitrescu } 80368b95704SCristian Dumitrescu 80468b95704SCristian Dumitrescu iospec_file_name = tokens[6]; 80568b95704SCristian Dumitrescu 80668b95704SCristian Dumitrescu if (strcmp(tokens[7], "numa")) { 80768b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa"); 80868b95704SCristian Dumitrescu return; 80968b95704SCristian Dumitrescu } 81068b95704SCristian Dumitrescu 81168b95704SCristian Dumitrescu if (parser_read_uint32(&numa_node, tokens[8])) { 81268b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node"); 81368b95704SCristian Dumitrescu return; 81468b95704SCristian Dumitrescu } 81568b95704SCristian Dumitrescu 81668b95704SCristian Dumitrescu /* I/O spec file open. */ 81768b95704SCristian Dumitrescu iospec_file = fopen(iospec_file_name, "r"); 81868b95704SCristian Dumitrescu if (!iospec_file) { 81968b95704SCristian Dumitrescu snprintf(out, out_size, "Cannot open file \"%s\".\n", iospec_file_name); 82068b95704SCristian Dumitrescu return; 82168b95704SCristian Dumitrescu } 82268b95704SCristian Dumitrescu 82368b95704SCristian Dumitrescu status = rte_swx_pipeline_build_from_lib(&p, 82468b95704SCristian Dumitrescu pipeline_name, 82568b95704SCristian Dumitrescu lib_file_name, 82668b95704SCristian Dumitrescu iospec_file, 82768b95704SCristian Dumitrescu (int)numa_node); 8285074e1d5SCristian Dumitrescu if (status) { 82968b95704SCristian Dumitrescu snprintf(out, out_size, "Pipeline build failed (%d).", status); 83068b95704SCristian Dumitrescu goto free; 8315074e1d5SCristian Dumitrescu } 8325074e1d5SCristian Dumitrescu 83368b95704SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_create(p); 83468b95704SCristian Dumitrescu if (!ctl) { 8355074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline control create failed."); 83668b95704SCristian Dumitrescu goto free; 8375074e1d5SCristian Dumitrescu } 83868b95704SCristian Dumitrescu 83968b95704SCristian Dumitrescu free: 84068b95704SCristian Dumitrescu if (status) 84168b95704SCristian Dumitrescu rte_swx_pipeline_free(p); 84268b95704SCristian Dumitrescu 84368b95704SCristian Dumitrescu if (iospec_file) 84468b95704SCristian Dumitrescu fclose(iospec_file); 8455074e1d5SCristian Dumitrescu } 8465074e1d5SCristian Dumitrescu 84775129cebSChurchill Khangar static int 84875129cebSChurchill Khangar pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p, 84975129cebSChurchill Khangar const char *table_name, 85075129cebSChurchill Khangar FILE *file, 85175129cebSChurchill Khangar uint32_t *file_line_number) 85275129cebSChurchill Khangar { 85375129cebSChurchill Khangar char *line = NULL; 85475129cebSChurchill Khangar uint32_t line_id = 0; 85575129cebSChurchill Khangar int status = 0; 85675129cebSChurchill Khangar 85775129cebSChurchill Khangar /* Buffer allocation. */ 85875129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 85975129cebSChurchill Khangar if (!line) 86075129cebSChurchill Khangar return -ENOMEM; 86175129cebSChurchill Khangar 86275129cebSChurchill Khangar /* File read. */ 86375129cebSChurchill Khangar for (line_id = 1; ; line_id++) { 86475129cebSChurchill Khangar struct rte_swx_table_entry *entry; 86575129cebSChurchill Khangar int is_blank_or_comment; 86675129cebSChurchill Khangar 86775129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 86875129cebSChurchill Khangar break; 86975129cebSChurchill Khangar 87075129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 87175129cebSChurchill Khangar table_name, 87275129cebSChurchill Khangar line, 87375129cebSChurchill Khangar &is_blank_or_comment); 87475129cebSChurchill Khangar if (!entry) { 87575129cebSChurchill Khangar if (is_blank_or_comment) 87675129cebSChurchill Khangar continue; 87775129cebSChurchill Khangar 87875129cebSChurchill Khangar status = -EINVAL; 87975129cebSChurchill Khangar goto error; 88075129cebSChurchill Khangar } 88175129cebSChurchill Khangar 88275129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_add(p, 88375129cebSChurchill Khangar table_name, 88475129cebSChurchill Khangar entry); 88575129cebSChurchill Khangar table_entry_free(entry); 88675129cebSChurchill Khangar if (status) 88775129cebSChurchill Khangar goto error; 88875129cebSChurchill Khangar } 88975129cebSChurchill Khangar 89075129cebSChurchill Khangar error: 89175129cebSChurchill Khangar free(line); 89275129cebSChurchill Khangar *file_line_number = line_id; 89375129cebSChurchill Khangar return status; 89475129cebSChurchill Khangar } 89575129cebSChurchill Khangar 89675129cebSChurchill Khangar static const char cmd_pipeline_table_add_help[] = 89775129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> add <file_name>\n"; 8985074e1d5SCristian Dumitrescu 8995074e1d5SCristian Dumitrescu static void 90075129cebSChurchill Khangar cmd_pipeline_table_add(char **tokens, 9015074e1d5SCristian Dumitrescu uint32_t n_tokens, 9025074e1d5SCristian Dumitrescu char *out, 9035074e1d5SCristian Dumitrescu size_t out_size, 904b9559f94SCristian Dumitrescu void *obj __rte_unused) 9055074e1d5SCristian Dumitrescu { 906b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 90775129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 90875129cebSChurchill Khangar FILE *file = NULL; 90975129cebSChurchill Khangar uint32_t file_line_number = 0; 9105074e1d5SCristian Dumitrescu int status; 9115074e1d5SCristian Dumitrescu 91275129cebSChurchill Khangar if (n_tokens != 6) { 9135074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 9145074e1d5SCristian Dumitrescu return; 9155074e1d5SCristian Dumitrescu } 9165074e1d5SCristian Dumitrescu 9175074e1d5SCristian Dumitrescu pipeline_name = tokens[1]; 918b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 919b9559f94SCristian Dumitrescu if (!ctl) { 9205074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 9215074e1d5SCristian Dumitrescu return; 9225074e1d5SCristian Dumitrescu } 9235074e1d5SCristian Dumitrescu 92475129cebSChurchill Khangar table_name = tokens[3]; 92575129cebSChurchill Khangar 92675129cebSChurchill Khangar file_name = tokens[5]; 92775129cebSChurchill Khangar file = fopen(file_name, "r"); 92875129cebSChurchill Khangar if (!file) { 92975129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 93075129cebSChurchill Khangar return; 93175129cebSChurchill Khangar } 93275129cebSChurchill Khangar 933b9559f94SCristian Dumitrescu status = pipeline_table_entries_add(ctl, 93475129cebSChurchill Khangar table_name, 93575129cebSChurchill Khangar file, 93675129cebSChurchill Khangar &file_line_number); 93775129cebSChurchill Khangar if (status) 93875129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 93975129cebSChurchill Khangar file_name, 94075129cebSChurchill Khangar file_line_number); 94175129cebSChurchill Khangar 94275129cebSChurchill Khangar fclose(file); 94375129cebSChurchill Khangar } 94475129cebSChurchill Khangar 94575129cebSChurchill Khangar static int 94675129cebSChurchill Khangar pipeline_table_entries_delete(struct rte_swx_ctl_pipeline *p, 94775129cebSChurchill Khangar const char *table_name, 94875129cebSChurchill Khangar FILE *file, 94975129cebSChurchill Khangar uint32_t *file_line_number) 95075129cebSChurchill Khangar { 95175129cebSChurchill Khangar char *line = NULL; 95275129cebSChurchill Khangar uint32_t line_id = 0; 95375129cebSChurchill Khangar int status = 0; 95475129cebSChurchill Khangar 95575129cebSChurchill Khangar /* Buffer allocation. */ 95675129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 95775129cebSChurchill Khangar if (!line) 95875129cebSChurchill Khangar return -ENOMEM; 95975129cebSChurchill Khangar 96075129cebSChurchill Khangar /* File read. */ 96175129cebSChurchill Khangar for (line_id = 1; ; line_id++) { 96275129cebSChurchill Khangar struct rte_swx_table_entry *entry; 96375129cebSChurchill Khangar int is_blank_or_comment; 96475129cebSChurchill Khangar 96575129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 96675129cebSChurchill Khangar break; 96775129cebSChurchill Khangar 96875129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 96975129cebSChurchill Khangar table_name, 97075129cebSChurchill Khangar line, 97175129cebSChurchill Khangar &is_blank_or_comment); 97275129cebSChurchill Khangar if (!entry) { 97375129cebSChurchill Khangar if (is_blank_or_comment) 97475129cebSChurchill Khangar continue; 97575129cebSChurchill Khangar 97675129cebSChurchill Khangar status = -EINVAL; 97775129cebSChurchill Khangar goto error; 97875129cebSChurchill Khangar } 97975129cebSChurchill Khangar 98075129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_delete(p, 98175129cebSChurchill Khangar table_name, 98275129cebSChurchill Khangar entry); 98375129cebSChurchill Khangar table_entry_free(entry); 98475129cebSChurchill Khangar if (status) 98575129cebSChurchill Khangar goto error; 98675129cebSChurchill Khangar } 98775129cebSChurchill Khangar 98875129cebSChurchill Khangar error: 98975129cebSChurchill Khangar *file_line_number = line_id; 99075129cebSChurchill Khangar free(line); 99175129cebSChurchill Khangar return status; 99275129cebSChurchill Khangar } 99375129cebSChurchill Khangar 99475129cebSChurchill Khangar static const char cmd_pipeline_table_delete_help[] = 99575129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> delete <file_name>\n"; 99675129cebSChurchill Khangar 99775129cebSChurchill Khangar static void 99875129cebSChurchill Khangar cmd_pipeline_table_delete(char **tokens, 99975129cebSChurchill Khangar uint32_t n_tokens, 100075129cebSChurchill Khangar char *out, 100175129cebSChurchill Khangar size_t out_size, 1002b9559f94SCristian Dumitrescu void *obj __rte_unused) 100375129cebSChurchill Khangar { 1004b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 100575129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 100675129cebSChurchill Khangar FILE *file = NULL; 100775129cebSChurchill Khangar uint32_t file_line_number = 0; 100875129cebSChurchill Khangar int status; 100975129cebSChurchill Khangar 101075129cebSChurchill Khangar if (n_tokens != 6) { 101175129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 101275129cebSChurchill Khangar return; 101375129cebSChurchill Khangar } 101475129cebSChurchill Khangar 101575129cebSChurchill Khangar pipeline_name = tokens[1]; 1016b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1017b9559f94SCristian Dumitrescu if (!ctl) { 101875129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 10195074e1d5SCristian Dumitrescu return; 10205074e1d5SCristian Dumitrescu } 10215074e1d5SCristian Dumitrescu 10225074e1d5SCristian Dumitrescu table_name = tokens[3]; 10235074e1d5SCristian Dumitrescu 102475129cebSChurchill Khangar file_name = tokens[5]; 102575129cebSChurchill Khangar file = fopen(file_name, "r"); 102675129cebSChurchill Khangar if (!file) { 102775129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 10285074e1d5SCristian Dumitrescu return; 10295074e1d5SCristian Dumitrescu } 10305074e1d5SCristian Dumitrescu 1031b9559f94SCristian Dumitrescu status = pipeline_table_entries_delete(ctl, 103275129cebSChurchill Khangar table_name, 103375129cebSChurchill Khangar file, 103475129cebSChurchill Khangar &file_line_number); 103575129cebSChurchill Khangar if (status) 103675129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 103775129cebSChurchill Khangar file_name, 103875129cebSChurchill Khangar file_line_number); 10395074e1d5SCristian Dumitrescu 104075129cebSChurchill Khangar fclose(file); 10415074e1d5SCristian Dumitrescu } 10425074e1d5SCristian Dumitrescu 104375129cebSChurchill Khangar static int 104475129cebSChurchill Khangar pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *p, 104575129cebSChurchill Khangar const char *table_name, 104675129cebSChurchill Khangar FILE *file, 104775129cebSChurchill Khangar uint32_t *file_line_number) 104875129cebSChurchill Khangar { 104975129cebSChurchill Khangar char *line = NULL; 105075129cebSChurchill Khangar uint32_t line_id = 0; 105175129cebSChurchill Khangar int status = 0; 10525074e1d5SCristian Dumitrescu 10535074e1d5SCristian Dumitrescu /* Buffer allocation. */ 105475129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 105575129cebSChurchill Khangar if (!line) 105675129cebSChurchill Khangar return -ENOMEM; 10575074e1d5SCristian Dumitrescu 105875129cebSChurchill Khangar /* File read. */ 10595074e1d5SCristian Dumitrescu for (line_id = 1; ; line_id++) { 10605074e1d5SCristian Dumitrescu struct rte_swx_table_entry *entry; 1061cff9a717SCristian Dumitrescu int is_blank_or_comment; 10625074e1d5SCristian Dumitrescu 106375129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 10645074e1d5SCristian Dumitrescu break; 10655074e1d5SCristian Dumitrescu 106675129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 10675074e1d5SCristian Dumitrescu table_name, 1068cff9a717SCristian Dumitrescu line, 1069cff9a717SCristian Dumitrescu &is_blank_or_comment); 10705074e1d5SCristian Dumitrescu if (!entry) { 1071cff9a717SCristian Dumitrescu if (is_blank_or_comment) 1072cff9a717SCristian Dumitrescu continue; 1073cff9a717SCristian Dumitrescu 107475129cebSChurchill Khangar status = -EINVAL; 10755074e1d5SCristian Dumitrescu goto error; 10765074e1d5SCristian Dumitrescu } 10775074e1d5SCristian Dumitrescu 107875129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_default_entry_add(p, 10795074e1d5SCristian Dumitrescu table_name, 10805074e1d5SCristian Dumitrescu entry); 1081275ebefeSCristian Dumitrescu table_entry_free(entry); 108275129cebSChurchill Khangar if (status) 10835074e1d5SCristian Dumitrescu goto error; 10845074e1d5SCristian Dumitrescu } 108575129cebSChurchill Khangar 108675129cebSChurchill Khangar error: 108775129cebSChurchill Khangar *file_line_number = line_id; 108875129cebSChurchill Khangar free(line); 108975129cebSChurchill Khangar return status; 10905074e1d5SCristian Dumitrescu } 10915074e1d5SCristian Dumitrescu 109275129cebSChurchill Khangar static const char cmd_pipeline_table_default_help[] = 109375129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> default <file_name>\n"; 10945074e1d5SCristian Dumitrescu 109575129cebSChurchill Khangar static void 109675129cebSChurchill Khangar cmd_pipeline_table_default(char **tokens, 109775129cebSChurchill Khangar uint32_t n_tokens, 109875129cebSChurchill Khangar char *out, 109975129cebSChurchill Khangar size_t out_size, 1100b9559f94SCristian Dumitrescu void *obj __rte_unused) 110175129cebSChurchill Khangar { 1102b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 110375129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 110475129cebSChurchill Khangar FILE *file = NULL; 110575129cebSChurchill Khangar uint32_t file_line_number = 0; 110675129cebSChurchill Khangar int status; 11075074e1d5SCristian Dumitrescu 110875129cebSChurchill Khangar if (n_tokens != 6) { 110975129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 111075129cebSChurchill Khangar return; 111175129cebSChurchill Khangar } 11125074e1d5SCristian Dumitrescu 111375129cebSChurchill Khangar pipeline_name = tokens[1]; 1114b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1115b9559f94SCristian Dumitrescu if (!ctl) { 111675129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 111775129cebSChurchill Khangar return; 111875129cebSChurchill Khangar } 111975129cebSChurchill Khangar 112075129cebSChurchill Khangar table_name = tokens[3]; 112175129cebSChurchill Khangar 112275129cebSChurchill Khangar file_name = tokens[5]; 112375129cebSChurchill Khangar file = fopen(file_name, "r"); 112475129cebSChurchill Khangar if (!file) { 112575129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 112675129cebSChurchill Khangar return; 112775129cebSChurchill Khangar } 112875129cebSChurchill Khangar 1129b9559f94SCristian Dumitrescu status = pipeline_table_default_entry_add(ctl, 11305074e1d5SCristian Dumitrescu table_name, 113175129cebSChurchill Khangar file, 113275129cebSChurchill Khangar &file_line_number); 113375129cebSChurchill Khangar if (status) 113475129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 113575129cebSChurchill Khangar file_name, 113675129cebSChurchill Khangar file_line_number); 1137cff9a717SCristian Dumitrescu 113875129cebSChurchill Khangar fclose(file); 11395074e1d5SCristian Dumitrescu } 11405074e1d5SCristian Dumitrescu 114175129cebSChurchill Khangar static const char cmd_pipeline_table_show_help[] = 1142a4c1146cSCristian Dumitrescu "pipeline <pipeline_name> table <table_name> show [filename]\n"; 114375129cebSChurchill Khangar 114475129cebSChurchill Khangar static void 114575129cebSChurchill Khangar cmd_pipeline_table_show(char **tokens, 114675129cebSChurchill Khangar uint32_t n_tokens, 114775129cebSChurchill Khangar char *out, 114875129cebSChurchill Khangar size_t out_size, 1149b9559f94SCristian Dumitrescu void *obj __rte_unused) 115075129cebSChurchill Khangar { 1151b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 115275129cebSChurchill Khangar char *pipeline_name, *table_name; 1153a4c1146cSCristian Dumitrescu FILE *file = NULL; 115475129cebSChurchill Khangar int status; 115575129cebSChurchill Khangar 1156a4c1146cSCristian Dumitrescu if (n_tokens != 5 && n_tokens != 6) { 115775129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 115875129cebSChurchill Khangar return; 11595074e1d5SCristian Dumitrescu } 11605074e1d5SCristian Dumitrescu 116175129cebSChurchill Khangar pipeline_name = tokens[1]; 1162b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1163b9559f94SCristian Dumitrescu if (!ctl) { 116475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 116575129cebSChurchill Khangar return; 11665074e1d5SCristian Dumitrescu } 11675074e1d5SCristian Dumitrescu 116875129cebSChurchill Khangar table_name = tokens[3]; 1169a4c1146cSCristian Dumitrescu file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout; 1170a4c1146cSCristian Dumitrescu if (!file) { 1171a4c1146cSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]); 1172a4c1146cSCristian Dumitrescu return; 1173a4c1146cSCristian Dumitrescu } 1174a4c1146cSCristian Dumitrescu 1175b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_table_fprintf(file, ctl, table_name); 117675129cebSChurchill Khangar if (status) 117775129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "table_name"); 1178a4c1146cSCristian Dumitrescu 1179a4c1146cSCristian Dumitrescu if (file) 1180a4c1146cSCristian Dumitrescu fclose(file); 11815074e1d5SCristian Dumitrescu } 118275129cebSChurchill Khangar 1183598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_add_help[] = 1184598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group add\n"; 1185598fe0ddSCristian Dumitrescu 1186598fe0ddSCristian Dumitrescu static void 1187598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(char **tokens, 1188598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1189598fe0ddSCristian Dumitrescu char *out, 1190598fe0ddSCristian Dumitrescu size_t out_size, 1191b9559f94SCristian Dumitrescu void *obj __rte_unused) 1192598fe0ddSCristian Dumitrescu { 1193b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 1194598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name; 1195598fe0ddSCristian Dumitrescu uint32_t group_id; 1196598fe0ddSCristian Dumitrescu int status; 1197598fe0ddSCristian Dumitrescu 1198598fe0ddSCristian Dumitrescu if (n_tokens != 6) { 1199598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1200598fe0ddSCristian Dumitrescu return; 1201598fe0ddSCristian Dumitrescu } 1202598fe0ddSCristian Dumitrescu 1203598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1204b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1205b9559f94SCristian Dumitrescu if (!ctl) { 1206598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1207598fe0ddSCristian Dumitrescu return; 1208598fe0ddSCristian Dumitrescu } 1209598fe0ddSCristian Dumitrescu 1210598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1211598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1212598fe0ddSCristian Dumitrescu return; 1213598fe0ddSCristian Dumitrescu } 1214598fe0ddSCristian Dumitrescu 1215598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1216598fe0ddSCristian Dumitrescu 1217598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1218598fe0ddSCristian Dumitrescu strcmp(tokens[5], "add")) { 1219598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group add"); 1220598fe0ddSCristian Dumitrescu return; 1221598fe0ddSCristian Dumitrescu } 1222598fe0ddSCristian Dumitrescu 1223b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_add(ctl, 1224598fe0ddSCristian Dumitrescu selector_name, 1225598fe0ddSCristian Dumitrescu &group_id); 1226598fe0ddSCristian Dumitrescu if (status) 1227598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 1228598fe0ddSCristian Dumitrescu else 1229598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Group ID: %u\n", group_id); 1230598fe0ddSCristian Dumitrescu } 1231598fe0ddSCristian Dumitrescu 1232598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_delete_help[] = 1233598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group delete <group_id>\n"; 1234598fe0ddSCristian Dumitrescu 1235598fe0ddSCristian Dumitrescu static void 1236598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(char **tokens, 1237598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1238598fe0ddSCristian Dumitrescu char *out, 1239598fe0ddSCristian Dumitrescu size_t out_size, 1240b9559f94SCristian Dumitrescu void *obj __rte_unused) 1241598fe0ddSCristian Dumitrescu { 1242b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 1243598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name; 1244598fe0ddSCristian Dumitrescu uint32_t group_id; 1245598fe0ddSCristian Dumitrescu int status; 1246598fe0ddSCristian Dumitrescu 1247598fe0ddSCristian Dumitrescu if (n_tokens != 7) { 1248598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1249598fe0ddSCristian Dumitrescu return; 1250598fe0ddSCristian Dumitrescu } 1251598fe0ddSCristian Dumitrescu 1252598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1253b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1254b9559f94SCristian Dumitrescu if (!ctl) { 1255598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1256598fe0ddSCristian Dumitrescu return; 1257598fe0ddSCristian Dumitrescu } 1258598fe0ddSCristian Dumitrescu 1259598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1260598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1261598fe0ddSCristian Dumitrescu return; 1262598fe0ddSCristian Dumitrescu } 1263598fe0ddSCristian Dumitrescu 1264598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1265598fe0ddSCristian Dumitrescu 1266598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1267598fe0ddSCristian Dumitrescu strcmp(tokens[5], "delete")) { 1268598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group delete"); 1269598fe0ddSCristian Dumitrescu return; 1270598fe0ddSCristian Dumitrescu } 1271598fe0ddSCristian Dumitrescu 1272598fe0ddSCristian Dumitrescu if (parser_read_uint32(&group_id, tokens[6]) != 0) { 1273598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "group_id"); 1274598fe0ddSCristian Dumitrescu return; 1275598fe0ddSCristian Dumitrescu } 1276598fe0ddSCristian Dumitrescu 1277b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_delete(ctl, 1278598fe0ddSCristian Dumitrescu selector_name, 1279598fe0ddSCristian Dumitrescu group_id); 1280598fe0ddSCristian Dumitrescu if (status) 1281598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 1282598fe0ddSCristian Dumitrescu } 1283598fe0ddSCristian Dumitrescu 1284598fe0ddSCristian Dumitrescu #define GROUP_MEMBER_INFO_TOKENS_MAX 6 1285598fe0ddSCristian Dumitrescu 1286598fe0ddSCristian Dumitrescu static int 1287598fe0ddSCristian Dumitrescu token_is_comment(const char *token) 1288598fe0ddSCristian Dumitrescu { 1289598fe0ddSCristian Dumitrescu if ((token[0] == '#') || 1290598fe0ddSCristian Dumitrescu (token[0] == ';') || 1291598fe0ddSCristian Dumitrescu ((token[0] == '/') && (token[1] == '/'))) 1292598fe0ddSCristian Dumitrescu return 1; /* TRUE. */ 1293598fe0ddSCristian Dumitrescu 1294598fe0ddSCristian Dumitrescu return 0; /* FALSE. */ 1295598fe0ddSCristian Dumitrescu } 1296598fe0ddSCristian Dumitrescu 1297598fe0ddSCristian Dumitrescu static int 1298598fe0ddSCristian Dumitrescu pipeline_selector_group_member_read(const char *string, 1299598fe0ddSCristian Dumitrescu uint32_t *group_id, 1300598fe0ddSCristian Dumitrescu uint32_t *member_id, 1301598fe0ddSCristian Dumitrescu uint32_t *weight, 1302598fe0ddSCristian Dumitrescu int *is_blank_or_comment) 1303598fe0ddSCristian Dumitrescu { 1304598fe0ddSCristian Dumitrescu char *token_array[GROUP_MEMBER_INFO_TOKENS_MAX], **tokens; 1305598fe0ddSCristian Dumitrescu char *s0 = NULL, *s; 130600b67591SAli Alnubani uint32_t n_tokens = 0, group_id_val = 0, member_id_val = 0, weight_val = 0; 1307598fe0ddSCristian Dumitrescu int blank_or_comment = 0; 1308598fe0ddSCristian Dumitrescu 1309598fe0ddSCristian Dumitrescu /* Check input arguments. */ 1310598fe0ddSCristian Dumitrescu if (!string || !string[0]) 1311598fe0ddSCristian Dumitrescu goto error; 1312598fe0ddSCristian Dumitrescu 1313598fe0ddSCristian Dumitrescu /* Memory allocation. */ 1314598fe0ddSCristian Dumitrescu s0 = strdup(string); 1315598fe0ddSCristian Dumitrescu if (!s0) 1316598fe0ddSCristian Dumitrescu goto error; 1317598fe0ddSCristian Dumitrescu 1318598fe0ddSCristian Dumitrescu /* Parse the string into tokens. */ 1319598fe0ddSCristian Dumitrescu for (s = s0; ; ) { 1320598fe0ddSCristian Dumitrescu char *token; 1321598fe0ddSCristian Dumitrescu 1322598fe0ddSCristian Dumitrescu token = strtok_r(s, " \f\n\r\t\v", &s); 1323598fe0ddSCristian Dumitrescu if (!token || token_is_comment(token)) 1324598fe0ddSCristian Dumitrescu break; 1325598fe0ddSCristian Dumitrescu 1326cfcc7bf8SCristian Dumitrescu if (n_tokens >= GROUP_MEMBER_INFO_TOKENS_MAX) 1327598fe0ddSCristian Dumitrescu goto error; 1328598fe0ddSCristian Dumitrescu 1329598fe0ddSCristian Dumitrescu token_array[n_tokens] = token; 1330598fe0ddSCristian Dumitrescu n_tokens++; 1331598fe0ddSCristian Dumitrescu } 1332598fe0ddSCristian Dumitrescu 1333598fe0ddSCristian Dumitrescu if (!n_tokens) { 1334598fe0ddSCristian Dumitrescu blank_or_comment = 1; 1335598fe0ddSCristian Dumitrescu goto error; 1336598fe0ddSCristian Dumitrescu } 1337598fe0ddSCristian Dumitrescu 1338598fe0ddSCristian Dumitrescu tokens = token_array; 1339598fe0ddSCristian Dumitrescu 1340598fe0ddSCristian Dumitrescu if (n_tokens < 4 || 1341598fe0ddSCristian Dumitrescu strcmp(tokens[0], "group") || 1342598fe0ddSCristian Dumitrescu strcmp(tokens[2], "member")) 1343598fe0ddSCristian Dumitrescu goto error; 1344598fe0ddSCristian Dumitrescu 1345598fe0ddSCristian Dumitrescu /* 1346598fe0ddSCristian Dumitrescu * Group ID. 1347598fe0ddSCristian Dumitrescu */ 1348598fe0ddSCristian Dumitrescu if (parser_read_uint32(&group_id_val, tokens[1]) != 0) 1349598fe0ddSCristian Dumitrescu goto error; 1350598fe0ddSCristian Dumitrescu *group_id = group_id_val; 1351598fe0ddSCristian Dumitrescu 1352598fe0ddSCristian Dumitrescu /* 1353598fe0ddSCristian Dumitrescu * Member ID. 1354598fe0ddSCristian Dumitrescu */ 1355598fe0ddSCristian Dumitrescu if (parser_read_uint32(&member_id_val, tokens[3]) != 0) 1356598fe0ddSCristian Dumitrescu goto error; 1357598fe0ddSCristian Dumitrescu *member_id = member_id_val; 1358598fe0ddSCristian Dumitrescu 1359598fe0ddSCristian Dumitrescu tokens += 4; 1360598fe0ddSCristian Dumitrescu n_tokens -= 4; 1361598fe0ddSCristian Dumitrescu 1362598fe0ddSCristian Dumitrescu /* 1363598fe0ddSCristian Dumitrescu * Weight. 1364598fe0ddSCristian Dumitrescu */ 1365598fe0ddSCristian Dumitrescu if (n_tokens && !strcmp(tokens[0], "weight")) { 1366598fe0ddSCristian Dumitrescu if (n_tokens < 2) 1367598fe0ddSCristian Dumitrescu goto error; 1368598fe0ddSCristian Dumitrescu 1369598fe0ddSCristian Dumitrescu if (parser_read_uint32(&weight_val, tokens[1]) != 0) 1370598fe0ddSCristian Dumitrescu goto error; 1371598fe0ddSCristian Dumitrescu *weight = weight_val; 1372598fe0ddSCristian Dumitrescu 1373598fe0ddSCristian Dumitrescu tokens += 2; 1374598fe0ddSCristian Dumitrescu n_tokens -= 2; 1375598fe0ddSCristian Dumitrescu } 1376598fe0ddSCristian Dumitrescu 1377598fe0ddSCristian Dumitrescu if (n_tokens) 1378598fe0ddSCristian Dumitrescu goto error; 1379598fe0ddSCristian Dumitrescu 1380598fe0ddSCristian Dumitrescu free(s0); 1381598fe0ddSCristian Dumitrescu return 0; 1382598fe0ddSCristian Dumitrescu 1383598fe0ddSCristian Dumitrescu error: 1384598fe0ddSCristian Dumitrescu free(s0); 1385598fe0ddSCristian Dumitrescu if (is_blank_or_comment) 1386598fe0ddSCristian Dumitrescu *is_blank_or_comment = blank_or_comment; 1387598fe0ddSCristian Dumitrescu return -EINVAL; 1388598fe0ddSCristian Dumitrescu } 1389598fe0ddSCristian Dumitrescu 1390598fe0ddSCristian Dumitrescu static int 1391598fe0ddSCristian Dumitrescu pipeline_selector_group_members_add(struct rte_swx_ctl_pipeline *p, 1392598fe0ddSCristian Dumitrescu const char *selector_name, 1393598fe0ddSCristian Dumitrescu FILE *file, 1394598fe0ddSCristian Dumitrescu uint32_t *file_line_number) 1395598fe0ddSCristian Dumitrescu { 1396598fe0ddSCristian Dumitrescu char *line = NULL; 1397598fe0ddSCristian Dumitrescu uint32_t line_id = 0; 1398598fe0ddSCristian Dumitrescu int status = 0; 1399598fe0ddSCristian Dumitrescu 1400598fe0ddSCristian Dumitrescu /* Buffer allocation. */ 1401598fe0ddSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 1402598fe0ddSCristian Dumitrescu if (!line) 1403598fe0ddSCristian Dumitrescu return -ENOMEM; 1404598fe0ddSCristian Dumitrescu 1405598fe0ddSCristian Dumitrescu /* File read. */ 1406598fe0ddSCristian Dumitrescu for (line_id = 1; ; line_id++) { 1407598fe0ddSCristian Dumitrescu uint32_t group_id, member_id, weight; 1408598fe0ddSCristian Dumitrescu int is_blank_or_comment; 1409598fe0ddSCristian Dumitrescu 1410598fe0ddSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL) 1411598fe0ddSCristian Dumitrescu break; 1412598fe0ddSCristian Dumitrescu 1413598fe0ddSCristian Dumitrescu status = pipeline_selector_group_member_read(line, 1414598fe0ddSCristian Dumitrescu &group_id, 1415598fe0ddSCristian Dumitrescu &member_id, 1416598fe0ddSCristian Dumitrescu &weight, 1417598fe0ddSCristian Dumitrescu &is_blank_or_comment); 1418598fe0ddSCristian Dumitrescu if (status) { 1419598fe0ddSCristian Dumitrescu if (is_blank_or_comment) 1420598fe0ddSCristian Dumitrescu continue; 1421598fe0ddSCristian Dumitrescu 1422598fe0ddSCristian Dumitrescu goto error; 1423598fe0ddSCristian Dumitrescu } 1424598fe0ddSCristian Dumitrescu 1425598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_member_add(p, 1426598fe0ddSCristian Dumitrescu selector_name, 1427598fe0ddSCristian Dumitrescu group_id, 1428598fe0ddSCristian Dumitrescu member_id, 1429598fe0ddSCristian Dumitrescu weight); 1430598fe0ddSCristian Dumitrescu if (status) 1431598fe0ddSCristian Dumitrescu goto error; 1432598fe0ddSCristian Dumitrescu } 1433598fe0ddSCristian Dumitrescu 1434598fe0ddSCristian Dumitrescu error: 1435598fe0ddSCristian Dumitrescu free(line); 1436598fe0ddSCristian Dumitrescu *file_line_number = line_id; 1437598fe0ddSCristian Dumitrescu return status; 1438598fe0ddSCristian Dumitrescu } 1439598fe0ddSCristian Dumitrescu 1440598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_add_help[] = 1441598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member add <file_name>"; 1442598fe0ddSCristian Dumitrescu 1443598fe0ddSCristian Dumitrescu static void 1444598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(char **tokens, 1445598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1446598fe0ddSCristian Dumitrescu char *out, 1447598fe0ddSCristian Dumitrescu size_t out_size, 1448b9559f94SCristian Dumitrescu void *obj __rte_unused) 1449598fe0ddSCristian Dumitrescu { 1450b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 1451598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name, *file_name; 1452598fe0ddSCristian Dumitrescu FILE *file = NULL; 1453598fe0ddSCristian Dumitrescu uint32_t file_line_number = 0; 1454598fe0ddSCristian Dumitrescu int status; 1455598fe0ddSCristian Dumitrescu 1456598fe0ddSCristian Dumitrescu if (n_tokens != 8) { 1457598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1458598fe0ddSCristian Dumitrescu return; 1459598fe0ddSCristian Dumitrescu } 1460598fe0ddSCristian Dumitrescu 1461598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1462b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1463b9559f94SCristian Dumitrescu if (!ctl) { 1464598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1465598fe0ddSCristian Dumitrescu return; 1466598fe0ddSCristian Dumitrescu } 1467598fe0ddSCristian Dumitrescu 1468598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1469598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1470598fe0ddSCristian Dumitrescu return; 1471598fe0ddSCristian Dumitrescu } 1472598fe0ddSCristian Dumitrescu 1473598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1474598fe0ddSCristian Dumitrescu 1475598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1476598fe0ddSCristian Dumitrescu strcmp(tokens[5], "member") || 1477598fe0ddSCristian Dumitrescu strcmp(tokens[6], "add")) { 1478598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member add"); 1479598fe0ddSCristian Dumitrescu return; 1480598fe0ddSCristian Dumitrescu } 1481598fe0ddSCristian Dumitrescu 1482598fe0ddSCristian Dumitrescu file_name = tokens[7]; 1483598fe0ddSCristian Dumitrescu file = fopen(file_name, "r"); 1484598fe0ddSCristian Dumitrescu if (!file) { 1485598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name); 1486598fe0ddSCristian Dumitrescu return; 1487598fe0ddSCristian Dumitrescu } 1488598fe0ddSCristian Dumitrescu 1489b9559f94SCristian Dumitrescu status = pipeline_selector_group_members_add(ctl, 1490598fe0ddSCristian Dumitrescu selector_name, 1491598fe0ddSCristian Dumitrescu file, 1492598fe0ddSCristian Dumitrescu &file_line_number); 1493598fe0ddSCristian Dumitrescu if (status) 1494598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 1495598fe0ddSCristian Dumitrescu file_name, 1496598fe0ddSCristian Dumitrescu file_line_number); 1497598fe0ddSCristian Dumitrescu 1498598fe0ddSCristian Dumitrescu fclose(file); 1499598fe0ddSCristian Dumitrescu } 1500598fe0ddSCristian Dumitrescu 1501598fe0ddSCristian Dumitrescu static int 1502598fe0ddSCristian Dumitrescu pipeline_selector_group_members_delete(struct rte_swx_ctl_pipeline *p, 1503598fe0ddSCristian Dumitrescu const char *selector_name, 1504598fe0ddSCristian Dumitrescu FILE *file, 1505598fe0ddSCristian Dumitrescu uint32_t *file_line_number) 1506598fe0ddSCristian Dumitrescu { 1507598fe0ddSCristian Dumitrescu char *line = NULL; 1508598fe0ddSCristian Dumitrescu uint32_t line_id = 0; 1509598fe0ddSCristian Dumitrescu int status = 0; 1510598fe0ddSCristian Dumitrescu 1511598fe0ddSCristian Dumitrescu /* Buffer allocation. */ 1512598fe0ddSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 1513598fe0ddSCristian Dumitrescu if (!line) 1514598fe0ddSCristian Dumitrescu return -ENOMEM; 1515598fe0ddSCristian Dumitrescu 1516598fe0ddSCristian Dumitrescu /* File read. */ 1517598fe0ddSCristian Dumitrescu for (line_id = 1; ; line_id++) { 1518598fe0ddSCristian Dumitrescu uint32_t group_id, member_id, weight; 1519598fe0ddSCristian Dumitrescu int is_blank_or_comment; 1520598fe0ddSCristian Dumitrescu 1521598fe0ddSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL) 1522598fe0ddSCristian Dumitrescu break; 1523598fe0ddSCristian Dumitrescu 1524598fe0ddSCristian Dumitrescu status = pipeline_selector_group_member_read(line, 1525598fe0ddSCristian Dumitrescu &group_id, 1526598fe0ddSCristian Dumitrescu &member_id, 1527598fe0ddSCristian Dumitrescu &weight, 1528598fe0ddSCristian Dumitrescu &is_blank_or_comment); 1529598fe0ddSCristian Dumitrescu if (status) { 1530598fe0ddSCristian Dumitrescu if (is_blank_or_comment) 1531598fe0ddSCristian Dumitrescu continue; 1532598fe0ddSCristian Dumitrescu 1533598fe0ddSCristian Dumitrescu goto error; 1534598fe0ddSCristian Dumitrescu } 1535598fe0ddSCristian Dumitrescu 1536598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_member_delete(p, 1537598fe0ddSCristian Dumitrescu selector_name, 1538598fe0ddSCristian Dumitrescu group_id, 1539598fe0ddSCristian Dumitrescu member_id); 1540598fe0ddSCristian Dumitrescu if (status) 1541598fe0ddSCristian Dumitrescu goto error; 1542598fe0ddSCristian Dumitrescu } 1543598fe0ddSCristian Dumitrescu 1544598fe0ddSCristian Dumitrescu error: 1545598fe0ddSCristian Dumitrescu free(line); 1546598fe0ddSCristian Dumitrescu *file_line_number = line_id; 1547598fe0ddSCristian Dumitrescu return status; 1548598fe0ddSCristian Dumitrescu } 1549598fe0ddSCristian Dumitrescu 1550598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_delete_help[] = 1551598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member delete <file_name>"; 1552598fe0ddSCristian Dumitrescu 1553598fe0ddSCristian Dumitrescu static void 1554598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(char **tokens, 1555598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1556598fe0ddSCristian Dumitrescu char *out, 1557598fe0ddSCristian Dumitrescu size_t out_size, 1558b9559f94SCristian Dumitrescu void *obj __rte_unused) 1559598fe0ddSCristian Dumitrescu { 1560b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 1561598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name, *file_name; 1562598fe0ddSCristian Dumitrescu FILE *file = NULL; 1563598fe0ddSCristian Dumitrescu uint32_t file_line_number = 0; 1564598fe0ddSCristian Dumitrescu int status; 1565598fe0ddSCristian Dumitrescu 1566598fe0ddSCristian Dumitrescu if (n_tokens != 8) { 1567598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1568598fe0ddSCristian Dumitrescu return; 1569598fe0ddSCristian Dumitrescu } 1570598fe0ddSCristian Dumitrescu 1571598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1572b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1573b9559f94SCristian Dumitrescu if (!ctl) { 1574598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1575598fe0ddSCristian Dumitrescu return; 1576598fe0ddSCristian Dumitrescu } 1577598fe0ddSCristian Dumitrescu 1578598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1579598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1580598fe0ddSCristian Dumitrescu return; 1581598fe0ddSCristian Dumitrescu } 1582598fe0ddSCristian Dumitrescu 1583598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1584598fe0ddSCristian Dumitrescu 1585598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1586598fe0ddSCristian Dumitrescu strcmp(tokens[5], "member") || 1587598fe0ddSCristian Dumitrescu strcmp(tokens[6], "delete")) { 1588598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member delete"); 1589598fe0ddSCristian Dumitrescu return; 1590598fe0ddSCristian Dumitrescu } 1591598fe0ddSCristian Dumitrescu 1592598fe0ddSCristian Dumitrescu file_name = tokens[7]; 1593598fe0ddSCristian Dumitrescu file = fopen(file_name, "r"); 1594598fe0ddSCristian Dumitrescu if (!file) { 1595598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name); 1596598fe0ddSCristian Dumitrescu return; 1597598fe0ddSCristian Dumitrescu } 1598598fe0ddSCristian Dumitrescu 1599b9559f94SCristian Dumitrescu status = pipeline_selector_group_members_delete(ctl, 1600598fe0ddSCristian Dumitrescu selector_name, 1601598fe0ddSCristian Dumitrescu file, 1602598fe0ddSCristian Dumitrescu &file_line_number); 1603598fe0ddSCristian Dumitrescu if (status) 1604598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 1605598fe0ddSCristian Dumitrescu file_name, 1606598fe0ddSCristian Dumitrescu file_line_number); 1607598fe0ddSCristian Dumitrescu 1608598fe0ddSCristian Dumitrescu fclose(file); 1609598fe0ddSCristian Dumitrescu } 1610598fe0ddSCristian Dumitrescu 1611598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_show_help[] = 1612a4c1146cSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> show [filename]\n"; 1613598fe0ddSCristian Dumitrescu 1614598fe0ddSCristian Dumitrescu static void 1615598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(char **tokens, 1616598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1617598fe0ddSCristian Dumitrescu char *out, 1618598fe0ddSCristian Dumitrescu size_t out_size, 1619b9559f94SCristian Dumitrescu void *obj __rte_unused) 1620598fe0ddSCristian Dumitrescu { 1621b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 1622598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name; 1623a4c1146cSCristian Dumitrescu FILE *file = NULL; 1624598fe0ddSCristian Dumitrescu int status; 1625598fe0ddSCristian Dumitrescu 1626a4c1146cSCristian Dumitrescu if (n_tokens != 5 && n_tokens != 6) { 1627598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1628598fe0ddSCristian Dumitrescu return; 1629598fe0ddSCristian Dumitrescu } 1630598fe0ddSCristian Dumitrescu 1631598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1632b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1633b9559f94SCristian Dumitrescu if (!ctl) { 1634598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1635598fe0ddSCristian Dumitrescu return; 1636598fe0ddSCristian Dumitrescu } 1637598fe0ddSCristian Dumitrescu 1638598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1639a4c1146cSCristian Dumitrescu 1640a4c1146cSCristian Dumitrescu file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout; 1641a4c1146cSCristian Dumitrescu if (!file) { 1642a4c1146cSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]); 1643a4c1146cSCristian Dumitrescu return; 1644a4c1146cSCristian Dumitrescu } 1645a4c1146cSCristian Dumitrescu 1646b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_fprintf(file, ctl, selector_name); 1647598fe0ddSCristian Dumitrescu if (status) 1648598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "selector_name"); 1649a4c1146cSCristian Dumitrescu 1650a4c1146cSCristian Dumitrescu if (file) 1651a4c1146cSCristian Dumitrescu fclose(file); 1652598fe0ddSCristian Dumitrescu } 1653598fe0ddSCristian Dumitrescu 16548bd4862fSCristian Dumitrescu static int 16558bd4862fSCristian Dumitrescu pipeline_learner_default_entry_add(struct rte_swx_ctl_pipeline *p, 16568bd4862fSCristian Dumitrescu const char *learner_name, 16578bd4862fSCristian Dumitrescu FILE *file, 16588bd4862fSCristian Dumitrescu uint32_t *file_line_number) 16598bd4862fSCristian Dumitrescu { 16608bd4862fSCristian Dumitrescu char *line = NULL; 16618bd4862fSCristian Dumitrescu uint32_t line_id = 0; 16628bd4862fSCristian Dumitrescu int status = 0; 16638bd4862fSCristian Dumitrescu 16648bd4862fSCristian Dumitrescu /* Buffer allocation. */ 16658bd4862fSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 16668bd4862fSCristian Dumitrescu if (!line) 16678bd4862fSCristian Dumitrescu return -ENOMEM; 16688bd4862fSCristian Dumitrescu 16698bd4862fSCristian Dumitrescu /* File read. */ 16708bd4862fSCristian Dumitrescu for (line_id = 1; ; line_id++) { 16718bd4862fSCristian Dumitrescu struct rte_swx_table_entry *entry; 16728bd4862fSCristian Dumitrescu int is_blank_or_comment; 16738bd4862fSCristian Dumitrescu 16748bd4862fSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL) 16758bd4862fSCristian Dumitrescu break; 16768bd4862fSCristian Dumitrescu 16778bd4862fSCristian Dumitrescu entry = rte_swx_ctl_pipeline_learner_default_entry_read(p, 16788bd4862fSCristian Dumitrescu learner_name, 16798bd4862fSCristian Dumitrescu line, 16808bd4862fSCristian Dumitrescu &is_blank_or_comment); 16818bd4862fSCristian Dumitrescu if (!entry) { 16828bd4862fSCristian Dumitrescu if (is_blank_or_comment) 16838bd4862fSCristian Dumitrescu continue; 16848bd4862fSCristian Dumitrescu 16858bd4862fSCristian Dumitrescu status = -EINVAL; 16868bd4862fSCristian Dumitrescu goto error; 16878bd4862fSCristian Dumitrescu } 16888bd4862fSCristian Dumitrescu 16898bd4862fSCristian Dumitrescu status = rte_swx_ctl_pipeline_learner_default_entry_add(p, 16908bd4862fSCristian Dumitrescu learner_name, 16918bd4862fSCristian Dumitrescu entry); 16928bd4862fSCristian Dumitrescu table_entry_free(entry); 16938bd4862fSCristian Dumitrescu if (status) 16948bd4862fSCristian Dumitrescu goto error; 16958bd4862fSCristian Dumitrescu } 16968bd4862fSCristian Dumitrescu 16978bd4862fSCristian Dumitrescu error: 16988bd4862fSCristian Dumitrescu *file_line_number = line_id; 16998bd4862fSCristian Dumitrescu free(line); 17008bd4862fSCristian Dumitrescu return status; 17018bd4862fSCristian Dumitrescu } 17028bd4862fSCristian Dumitrescu 17038bd4862fSCristian Dumitrescu static const char cmd_pipeline_learner_default_help[] = 17048bd4862fSCristian Dumitrescu "pipeline <pipeline_name> learner <learner_name> default <file_name>\n"; 17058bd4862fSCristian Dumitrescu 17068bd4862fSCristian Dumitrescu static void 17078bd4862fSCristian Dumitrescu cmd_pipeline_learner_default(char **tokens, 17088bd4862fSCristian Dumitrescu uint32_t n_tokens, 17098bd4862fSCristian Dumitrescu char *out, 17108bd4862fSCristian Dumitrescu size_t out_size, 1711b9559f94SCristian Dumitrescu void *obj __rte_unused) 17128bd4862fSCristian Dumitrescu { 1713b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 17148bd4862fSCristian Dumitrescu char *pipeline_name, *learner_name, *file_name; 17158bd4862fSCristian Dumitrescu FILE *file = NULL; 17168bd4862fSCristian Dumitrescu uint32_t file_line_number = 0; 17178bd4862fSCristian Dumitrescu int status; 17188bd4862fSCristian Dumitrescu 17198bd4862fSCristian Dumitrescu if (n_tokens != 6) { 17208bd4862fSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 17218bd4862fSCristian Dumitrescu return; 17228bd4862fSCristian Dumitrescu } 17238bd4862fSCristian Dumitrescu 17248bd4862fSCristian Dumitrescu pipeline_name = tokens[1]; 1725b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1726b9559f94SCristian Dumitrescu if (!ctl) { 17278bd4862fSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 17288bd4862fSCristian Dumitrescu return; 17298bd4862fSCristian Dumitrescu } 17308bd4862fSCristian Dumitrescu 17318bd4862fSCristian Dumitrescu learner_name = tokens[3]; 17328bd4862fSCristian Dumitrescu 17338bd4862fSCristian Dumitrescu file_name = tokens[5]; 17348bd4862fSCristian Dumitrescu file = fopen(file_name, "r"); 17358bd4862fSCristian Dumitrescu if (!file) { 17368bd4862fSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name); 17378bd4862fSCristian Dumitrescu return; 17388bd4862fSCristian Dumitrescu } 17398bd4862fSCristian Dumitrescu 1740b9559f94SCristian Dumitrescu status = pipeline_learner_default_entry_add(ctl, 17418bd4862fSCristian Dumitrescu learner_name, 17428bd4862fSCristian Dumitrescu file, 17438bd4862fSCristian Dumitrescu &file_line_number); 17448bd4862fSCristian Dumitrescu if (status) 17458bd4862fSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 17468bd4862fSCristian Dumitrescu file_name, 17478bd4862fSCristian Dumitrescu file_line_number); 17488bd4862fSCristian Dumitrescu 17498bd4862fSCristian Dumitrescu fclose(file); 17508bd4862fSCristian Dumitrescu } 17518bd4862fSCristian Dumitrescu 175275129cebSChurchill Khangar static const char cmd_pipeline_commit_help[] = 175375129cebSChurchill Khangar "pipeline <pipeline_name> commit\n"; 175475129cebSChurchill Khangar 175575129cebSChurchill Khangar static void 175675129cebSChurchill Khangar cmd_pipeline_commit(char **tokens, 175775129cebSChurchill Khangar uint32_t n_tokens, 175875129cebSChurchill Khangar char *out, 175975129cebSChurchill Khangar size_t out_size, 1760b9559f94SCristian Dumitrescu void *obj __rte_unused) 176175129cebSChurchill Khangar { 1762b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 176375129cebSChurchill Khangar char *pipeline_name; 176475129cebSChurchill Khangar int status; 176575129cebSChurchill Khangar 176675129cebSChurchill Khangar if (n_tokens != 3) { 176775129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 176875129cebSChurchill Khangar return; 176975129cebSChurchill Khangar } 177075129cebSChurchill Khangar 177175129cebSChurchill Khangar pipeline_name = tokens[1]; 1772b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1773b9559f94SCristian Dumitrescu if (!ctl) { 177475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 177575129cebSChurchill Khangar return; 17765074e1d5SCristian Dumitrescu } 17775074e1d5SCristian Dumitrescu 1778b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_commit(ctl, 1); 177975129cebSChurchill Khangar if (status) 178075129cebSChurchill Khangar snprintf(out, out_size, "Commit failed. " 178175129cebSChurchill Khangar "Use \"commit\" to retry or \"abort\" to discard the pending work.\n"); 17825074e1d5SCristian Dumitrescu } 17835074e1d5SCristian Dumitrescu 178475129cebSChurchill Khangar static const char cmd_pipeline_abort_help[] = 178575129cebSChurchill Khangar "pipeline <pipeline_name> abort\n"; 17865074e1d5SCristian Dumitrescu 178775129cebSChurchill Khangar static void 178875129cebSChurchill Khangar cmd_pipeline_abort(char **tokens, 178975129cebSChurchill Khangar uint32_t n_tokens, 179075129cebSChurchill Khangar char *out, 179175129cebSChurchill Khangar size_t out_size, 1792b9559f94SCristian Dumitrescu void *obj __rte_unused) 179375129cebSChurchill Khangar { 1794b9559f94SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 179575129cebSChurchill Khangar char *pipeline_name; 17965074e1d5SCristian Dumitrescu 179775129cebSChurchill Khangar if (n_tokens != 3) { 179875129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 17995074e1d5SCristian Dumitrescu return; 180075129cebSChurchill Khangar } 18015074e1d5SCristian Dumitrescu 180275129cebSChurchill Khangar pipeline_name = tokens[1]; 1803b9559f94SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 1804b9559f94SCristian Dumitrescu if (!ctl) { 180575129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 180675129cebSChurchill Khangar return; 180775129cebSChurchill Khangar } 180875129cebSChurchill Khangar 1809b9559f94SCristian Dumitrescu rte_swx_ctl_pipeline_abort(ctl); 18105074e1d5SCristian Dumitrescu } 18115074e1d5SCristian Dumitrescu 181264cfcebdSCristian Dumitrescu static const char cmd_pipeline_regrd_help[] = 181383f58a7bSCristian Dumitrescu "pipeline <pipeline_name> regrd <register_array_name>\n" 181483f58a7bSCristian Dumitrescu "index <index>\n" 181583f58a7bSCristian Dumitrescu " | table <table_name> match <field0> ...\n"; 181664cfcebdSCristian Dumitrescu 181764cfcebdSCristian Dumitrescu static void 181864cfcebdSCristian Dumitrescu cmd_pipeline_regrd(char **tokens, 181964cfcebdSCristian Dumitrescu uint32_t n_tokens, 182064cfcebdSCristian Dumitrescu char *out, 182164cfcebdSCristian Dumitrescu size_t out_size, 1822b9559f94SCristian Dumitrescu void *obj __rte_unused) 182364cfcebdSCristian Dumitrescu { 1824b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 182583f58a7bSCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 182683f58a7bSCristian Dumitrescu const char *pipeline_name, *name; 182764cfcebdSCristian Dumitrescu uint64_t value; 182864cfcebdSCristian Dumitrescu int status; 182964cfcebdSCristian Dumitrescu 183083f58a7bSCristian Dumitrescu if (n_tokens < 5) { 183164cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 183264cfcebdSCristian Dumitrescu return; 183364cfcebdSCristian Dumitrescu } 183464cfcebdSCristian Dumitrescu 183583f58a7bSCristian Dumitrescu pipeline_name = tokens[1]; 183683f58a7bSCristian Dumitrescu p = rte_swx_pipeline_find(pipeline_name); 183783f58a7bSCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 183883f58a7bSCristian Dumitrescu if (!p || !ctl) { 183964cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 184064cfcebdSCristian Dumitrescu return; 184164cfcebdSCristian Dumitrescu } 184264cfcebdSCristian Dumitrescu 184364cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regrd")) { 184464cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd"); 184564cfcebdSCristian Dumitrescu return; 184664cfcebdSCristian Dumitrescu } 184764cfcebdSCristian Dumitrescu 184864cfcebdSCristian Dumitrescu name = tokens[3]; 184964cfcebdSCristian Dumitrescu 185083f58a7bSCristian Dumitrescu /* index. */ 185183f58a7bSCristian Dumitrescu if (!strcmp(tokens[4], "index")) { 1852327820afSAli Alnubani uint32_t idx = 0; 185383f58a7bSCristian Dumitrescu 185483f58a7bSCristian Dumitrescu if (n_tokens != 6) { 185583f58a7bSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 185683f58a7bSCristian Dumitrescu return; 185783f58a7bSCristian Dumitrescu } 185883f58a7bSCristian Dumitrescu 185983f58a7bSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[5])) { 186064cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index"); 186164cfcebdSCristian Dumitrescu return; 186264cfcebdSCristian Dumitrescu } 186364cfcebdSCristian Dumitrescu 1864b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value); 186564cfcebdSCristian Dumitrescu if (status) { 186664cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 186764cfcebdSCristian Dumitrescu return; 186864cfcebdSCristian Dumitrescu } 186964cfcebdSCristian Dumitrescu 187064cfcebdSCristian Dumitrescu snprintf(out, out_size, "0x%" PRIx64 "\n", value); 187183f58a7bSCristian Dumitrescu return; 187283f58a7bSCristian Dumitrescu } 187383f58a7bSCristian Dumitrescu 187483f58a7bSCristian Dumitrescu /* table. */ 187583f58a7bSCristian Dumitrescu if (!strcmp(tokens[4], "table")) { 187683f58a7bSCristian Dumitrescu struct rte_swx_table_entry *entry; 187783f58a7bSCristian Dumitrescu char *table_name; 187883f58a7bSCristian Dumitrescu 187983f58a7bSCristian Dumitrescu if (n_tokens < 8) { 188083f58a7bSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 188183f58a7bSCristian Dumitrescu return; 188283f58a7bSCristian Dumitrescu } 188383f58a7bSCristian Dumitrescu 188483f58a7bSCristian Dumitrescu table_name = tokens[5]; 188583f58a7bSCristian Dumitrescu 188683f58a7bSCristian Dumitrescu if (strcmp(tokens[6], "match")) { 188783f58a7bSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); 188883f58a7bSCristian Dumitrescu return; 188983f58a7bSCristian Dumitrescu } 189083f58a7bSCristian Dumitrescu 189183f58a7bSCristian Dumitrescu entry = parse_table_entry(ctl, table_name, &tokens[6], n_tokens - 6); 189283f58a7bSCristian Dumitrescu if (!entry) { 189383f58a7bSCristian Dumitrescu snprintf(out, out_size, "Invalid match tokens.\n"); 189483f58a7bSCristian Dumitrescu return; 189583f58a7bSCristian Dumitrescu } 189683f58a7bSCristian Dumitrescu 189783f58a7bSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_read_with_key(p, 189883f58a7bSCristian Dumitrescu name, 189983f58a7bSCristian Dumitrescu table_name, 190083f58a7bSCristian Dumitrescu entry->key, 190183f58a7bSCristian Dumitrescu &value); 190283f58a7bSCristian Dumitrescu table_entry_free(entry); 190383f58a7bSCristian Dumitrescu if (status) { 190483f58a7bSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 190583f58a7bSCristian Dumitrescu return; 190683f58a7bSCristian Dumitrescu } 190783f58a7bSCristian Dumitrescu 190883f58a7bSCristian Dumitrescu snprintf(out, out_size, "0x%" PRIx64 "\n", value); 190983f58a7bSCristian Dumitrescu return; 191083f58a7bSCristian Dumitrescu } 191183f58a7bSCristian Dumitrescu 191283f58a7bSCristian Dumitrescu /* anything else. */ 191383f58a7bSCristian Dumitrescu snprintf(out, out_size, "Invalid token %s\n.", tokens[4]); 191483f58a7bSCristian Dumitrescu return; 191564cfcebdSCristian Dumitrescu } 191664cfcebdSCristian Dumitrescu 191764cfcebdSCristian Dumitrescu static const char cmd_pipeline_regwr_help[] = 191883f58a7bSCristian Dumitrescu "pipeline <pipeline_name> regwr <register_array_name> value <value>\n" 191983f58a7bSCristian Dumitrescu "index <index>\n" 192083f58a7bSCristian Dumitrescu " | table <table_name> match <field0> ...\n"; 192164cfcebdSCristian Dumitrescu 192264cfcebdSCristian Dumitrescu static void 192364cfcebdSCristian Dumitrescu cmd_pipeline_regwr(char **tokens, 192464cfcebdSCristian Dumitrescu uint32_t n_tokens, 192564cfcebdSCristian Dumitrescu char *out, 192664cfcebdSCristian Dumitrescu size_t out_size, 1927b9559f94SCristian Dumitrescu void *obj __rte_unused) 192864cfcebdSCristian Dumitrescu { 1929b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 193083f58a7bSCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 193183f58a7bSCristian Dumitrescu const char *pipeline_name, *name; 193283f58a7bSCristian Dumitrescu uint64_t value = 0; 193364cfcebdSCristian Dumitrescu int status; 193464cfcebdSCristian Dumitrescu 193583f58a7bSCristian Dumitrescu if (n_tokens < 7) { 193664cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 193764cfcebdSCristian Dumitrescu return; 193864cfcebdSCristian Dumitrescu } 193964cfcebdSCristian Dumitrescu 194083f58a7bSCristian Dumitrescu pipeline_name = tokens[1]; 194183f58a7bSCristian Dumitrescu p = rte_swx_pipeline_find(pipeline_name); 194283f58a7bSCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 194383f58a7bSCristian Dumitrescu if (!p || !ctl) { 194464cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 194564cfcebdSCristian Dumitrescu return; 194664cfcebdSCristian Dumitrescu } 194764cfcebdSCristian Dumitrescu 194864cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regwr")) { 194964cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr"); 195064cfcebdSCristian Dumitrescu return; 195164cfcebdSCristian Dumitrescu } 195264cfcebdSCristian Dumitrescu 195364cfcebdSCristian Dumitrescu name = tokens[3]; 195464cfcebdSCristian Dumitrescu 195583f58a7bSCristian Dumitrescu if (strcmp(tokens[4], "value")) { 195683f58a7bSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "value"); 195764cfcebdSCristian Dumitrescu return; 195864cfcebdSCristian Dumitrescu } 195964cfcebdSCristian Dumitrescu 196064cfcebdSCristian Dumitrescu if (parser_read_uint64(&value, tokens[5])) { 196164cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "value"); 196264cfcebdSCristian Dumitrescu return; 196364cfcebdSCristian Dumitrescu } 196464cfcebdSCristian Dumitrescu 196583f58a7bSCristian Dumitrescu /* index. */ 196683f58a7bSCristian Dumitrescu if (!strcmp(tokens[6], "index")) { 1967327820afSAli Alnubani uint32_t idx = 0; 196883f58a7bSCristian Dumitrescu 196983f58a7bSCristian Dumitrescu if (n_tokens != 8) { 197083f58a7bSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 197183f58a7bSCristian Dumitrescu return; 197283f58a7bSCristian Dumitrescu } 197383f58a7bSCristian Dumitrescu 197483f58a7bSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[7])) { 197583f58a7bSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index"); 197683f58a7bSCristian Dumitrescu return; 197783f58a7bSCristian Dumitrescu } 197883f58a7bSCristian Dumitrescu 1979b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value); 198064cfcebdSCristian Dumitrescu if (status) { 198164cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 198264cfcebdSCristian Dumitrescu return; 198364cfcebdSCristian Dumitrescu } 198483f58a7bSCristian Dumitrescu 198583f58a7bSCristian Dumitrescu snprintf(out, out_size, "0x%" PRIx64 "\n", value); 198683f58a7bSCristian Dumitrescu return; 198783f58a7bSCristian Dumitrescu } 198883f58a7bSCristian Dumitrescu 198983f58a7bSCristian Dumitrescu /* table. */ 199083f58a7bSCristian Dumitrescu if (!strcmp(tokens[6], "table")) { 199183f58a7bSCristian Dumitrescu struct rte_swx_table_entry *entry; 199283f58a7bSCristian Dumitrescu char *table_name; 199383f58a7bSCristian Dumitrescu 199483f58a7bSCristian Dumitrescu if (n_tokens < 10) { 199583f58a7bSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 199683f58a7bSCristian Dumitrescu return; 199783f58a7bSCristian Dumitrescu } 199883f58a7bSCristian Dumitrescu 199983f58a7bSCristian Dumitrescu table_name = tokens[7]; 200083f58a7bSCristian Dumitrescu 200183f58a7bSCristian Dumitrescu if (strcmp(tokens[8], "match")) { 200283f58a7bSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); 200383f58a7bSCristian Dumitrescu return; 200483f58a7bSCristian Dumitrescu } 200583f58a7bSCristian Dumitrescu 200683f58a7bSCristian Dumitrescu entry = parse_table_entry(ctl, table_name, &tokens[8], n_tokens - 8); 200783f58a7bSCristian Dumitrescu if (!entry) { 200883f58a7bSCristian Dumitrescu snprintf(out, out_size, "Invalid match tokens.\n"); 200983f58a7bSCristian Dumitrescu return; 201083f58a7bSCristian Dumitrescu } 201183f58a7bSCristian Dumitrescu 201283f58a7bSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_write_with_key(p, 201383f58a7bSCristian Dumitrescu name, 201483f58a7bSCristian Dumitrescu table_name, 201583f58a7bSCristian Dumitrescu entry->key, 201683f58a7bSCristian Dumitrescu value); 201783f58a7bSCristian Dumitrescu table_entry_free(entry); 201883f58a7bSCristian Dumitrescu if (status) { 201983f58a7bSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 202083f58a7bSCristian Dumitrescu return; 202183f58a7bSCristian Dumitrescu } 202283f58a7bSCristian Dumitrescu 202383f58a7bSCristian Dumitrescu return; 202483f58a7bSCristian Dumitrescu } 202583f58a7bSCristian Dumitrescu 202683f58a7bSCristian Dumitrescu /* anything else. */ 202783f58a7bSCristian Dumitrescu snprintf(out, out_size, "Invalid token %s\n.", tokens[6]); 202883f58a7bSCristian Dumitrescu return; 202964cfcebdSCristian Dumitrescu } 203064cfcebdSCristian Dumitrescu 2031f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_add_help[] = 2032f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> add " 2033f38913b7SCristian Dumitrescu "cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n"; 2034f38913b7SCristian Dumitrescu 2035f38913b7SCristian Dumitrescu static void 2036f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(char **tokens, 2037f38913b7SCristian Dumitrescu uint32_t n_tokens, 2038f38913b7SCristian Dumitrescu char *out, 2039f38913b7SCristian Dumitrescu size_t out_size, 2040b9559f94SCristian Dumitrescu void *obj __rte_unused) 2041f38913b7SCristian Dumitrescu { 2042f38913b7SCristian Dumitrescu struct rte_meter_trtcm_params params; 2043b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 2044f38913b7SCristian Dumitrescu const char *profile_name; 2045f38913b7SCristian Dumitrescu int status; 2046f38913b7SCristian Dumitrescu 2047f38913b7SCristian Dumitrescu if (n_tokens != 14) { 2048f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2049f38913b7SCristian Dumitrescu return; 2050f38913b7SCristian Dumitrescu } 2051f38913b7SCristian Dumitrescu 2052b9559f94SCristian Dumitrescu p = rte_swx_pipeline_find(tokens[1]); 2053b9559f94SCristian Dumitrescu if (!p) { 2054f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2055f38913b7SCristian Dumitrescu return; 2056f38913b7SCristian Dumitrescu } 2057f38913b7SCristian Dumitrescu 2058f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2059f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2060f38913b7SCristian Dumitrescu return; 2061f38913b7SCristian Dumitrescu } 2062f38913b7SCristian Dumitrescu 2063f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) { 2064f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 2065f38913b7SCristian Dumitrescu return; 2066f38913b7SCristian Dumitrescu } 2067f38913b7SCristian Dumitrescu 2068f38913b7SCristian Dumitrescu profile_name = tokens[4]; 2069f38913b7SCristian Dumitrescu 2070f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "add")) { 2071f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add"); 2072f38913b7SCristian Dumitrescu return; 2073f38913b7SCristian Dumitrescu } 2074f38913b7SCristian Dumitrescu 2075f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "cir")) { 2076f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir"); 2077f38913b7SCristian Dumitrescu return; 2078f38913b7SCristian Dumitrescu } 2079f38913b7SCristian Dumitrescu 2080f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cir, tokens[7])) { 2081f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cir"); 2082f38913b7SCristian Dumitrescu return; 2083f38913b7SCristian Dumitrescu } 2084f38913b7SCristian Dumitrescu 2085f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "pir")) { 2086f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir"); 2087f38913b7SCristian Dumitrescu return; 2088f38913b7SCristian Dumitrescu } 2089f38913b7SCristian Dumitrescu 2090f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pir, tokens[9])) { 2091f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pir"); 2092f38913b7SCristian Dumitrescu return; 2093f38913b7SCristian Dumitrescu } 2094f38913b7SCristian Dumitrescu 2095f38913b7SCristian Dumitrescu if (strcmp(tokens[10], "cbs")) { 2096f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs"); 2097f38913b7SCristian Dumitrescu return; 2098f38913b7SCristian Dumitrescu } 2099f38913b7SCristian Dumitrescu 2100f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cbs, tokens[11])) { 2101f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cbs"); 2102f38913b7SCristian Dumitrescu return; 2103f38913b7SCristian Dumitrescu } 2104f38913b7SCristian Dumitrescu 2105f38913b7SCristian Dumitrescu if (strcmp(tokens[12], "pbs")) { 2106f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs"); 2107f38913b7SCristian Dumitrescu return; 2108f38913b7SCristian Dumitrescu } 2109f38913b7SCristian Dumitrescu 2110f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pbs, tokens[13])) { 2111f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pbs"); 2112f38913b7SCristian Dumitrescu return; 2113f38913b7SCristian Dumitrescu } 2114f38913b7SCristian Dumitrescu 2115b9559f94SCristian Dumitrescu status = rte_swx_ctl_meter_profile_add(p, profile_name, ¶ms); 2116f38913b7SCristian Dumitrescu if (status) { 2117f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 2118f38913b7SCristian Dumitrescu return; 2119f38913b7SCristian Dumitrescu } 2120f38913b7SCristian Dumitrescu } 2121f38913b7SCristian Dumitrescu 2122f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_delete_help[] = 2123f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> delete\n"; 2124f38913b7SCristian Dumitrescu 2125f38913b7SCristian Dumitrescu static void 2126f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(char **tokens, 2127f38913b7SCristian Dumitrescu uint32_t n_tokens, 2128f38913b7SCristian Dumitrescu char *out, 2129f38913b7SCristian Dumitrescu size_t out_size, 2130b9559f94SCristian Dumitrescu void *obj __rte_unused) 2131f38913b7SCristian Dumitrescu { 2132b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 2133f38913b7SCristian Dumitrescu const char *profile_name; 2134f38913b7SCristian Dumitrescu int status; 2135f38913b7SCristian Dumitrescu 2136f38913b7SCristian Dumitrescu if (n_tokens != 6) { 2137f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2138f38913b7SCristian Dumitrescu return; 2139f38913b7SCristian Dumitrescu } 2140f38913b7SCristian Dumitrescu 2141b9559f94SCristian Dumitrescu p = rte_swx_pipeline_find(tokens[1]); 2142b9559f94SCristian Dumitrescu if (!p) { 2143f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2144f38913b7SCristian Dumitrescu return; 2145f38913b7SCristian Dumitrescu } 2146f38913b7SCristian Dumitrescu 2147f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2148f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2149f38913b7SCristian Dumitrescu return; 2150f38913b7SCristian Dumitrescu } 2151f38913b7SCristian Dumitrescu 2152f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) { 2153f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 2154f38913b7SCristian Dumitrescu return; 2155f38913b7SCristian Dumitrescu } 2156f38913b7SCristian Dumitrescu 2157f38913b7SCristian Dumitrescu profile_name = tokens[4]; 2158f38913b7SCristian Dumitrescu 2159f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "delete")) { 2160f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete"); 2161f38913b7SCristian Dumitrescu return; 2162f38913b7SCristian Dumitrescu } 2163f38913b7SCristian Dumitrescu 2164b9559f94SCristian Dumitrescu status = rte_swx_ctl_meter_profile_delete(p, profile_name); 2165f38913b7SCristian Dumitrescu if (status) { 2166f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 2167f38913b7SCristian Dumitrescu return; 2168f38913b7SCristian Dumitrescu } 2169f38913b7SCristian Dumitrescu } 2170f38913b7SCristian Dumitrescu 2171f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_reset_help[] = 217212eda78dSCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> reset\n" 217312eda78dSCristian Dumitrescu "index from <index0> to <index1>\n" 217412eda78dSCristian Dumitrescu " | table <table_name> match <field0> ...\n"; 2175f38913b7SCristian Dumitrescu 2176f38913b7SCristian Dumitrescu static void 2177f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(char **tokens, 2178f38913b7SCristian Dumitrescu uint32_t n_tokens, 2179f38913b7SCristian Dumitrescu char *out, 2180f38913b7SCristian Dumitrescu size_t out_size, 2181b9559f94SCristian Dumitrescu void *obj __rte_unused) 2182f38913b7SCristian Dumitrescu { 2183b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 218412eda78dSCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 218512eda78dSCristian Dumitrescu const char *pipeline_name, *name; 2186f38913b7SCristian Dumitrescu 218712eda78dSCristian Dumitrescu if (n_tokens < 6) { 2188f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2189f38913b7SCristian Dumitrescu return; 2190f38913b7SCristian Dumitrescu } 2191f38913b7SCristian Dumitrescu 219212eda78dSCristian Dumitrescu pipeline_name = tokens[1]; 219312eda78dSCristian Dumitrescu p = rte_swx_pipeline_find(pipeline_name); 219412eda78dSCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 219512eda78dSCristian Dumitrescu if (!p || !ctl) { 2196f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2197f38913b7SCristian Dumitrescu return; 2198f38913b7SCristian Dumitrescu } 2199f38913b7SCristian Dumitrescu 2200f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2201f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2202f38913b7SCristian Dumitrescu return; 2203f38913b7SCristian Dumitrescu } 2204f38913b7SCristian Dumitrescu 2205f38913b7SCristian Dumitrescu name = tokens[3]; 2206f38913b7SCristian Dumitrescu 220712eda78dSCristian Dumitrescu if (strcmp(tokens[4], "reset")) { 220812eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset"); 220912eda78dSCristian Dumitrescu return; 221012eda78dSCristian Dumitrescu } 221112eda78dSCristian Dumitrescu 221212eda78dSCristian Dumitrescu /* index. */ 221312eda78dSCristian Dumitrescu if (!strcmp(tokens[5], "index")) { 221412eda78dSCristian Dumitrescu uint32_t idx0 = 0, idx1 = 0; 221512eda78dSCristian Dumitrescu 221612eda78dSCristian Dumitrescu if (n_tokens != 10) { 221712eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 221812eda78dSCristian Dumitrescu return; 221912eda78dSCristian Dumitrescu } 222012eda78dSCristian Dumitrescu 222112eda78dSCristian Dumitrescu if (strcmp(tokens[6], "from")) { 2222f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 2223f38913b7SCristian Dumitrescu return; 2224f38913b7SCristian Dumitrescu } 2225f38913b7SCristian Dumitrescu 222612eda78dSCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[7])) { 2227f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 2228f38913b7SCristian Dumitrescu return; 2229f38913b7SCristian Dumitrescu } 2230f38913b7SCristian Dumitrescu 223112eda78dSCristian Dumitrescu if (strcmp(tokens[8], "to")) { 2232f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 2233f38913b7SCristian Dumitrescu return; 2234f38913b7SCristian Dumitrescu } 2235f38913b7SCristian Dumitrescu 223612eda78dSCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) { 2237f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 2238f38913b7SCristian Dumitrescu return; 2239f38913b7SCristian Dumitrescu } 2240f38913b7SCristian Dumitrescu 2241f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 2242f38913b7SCristian Dumitrescu int status; 2243f38913b7SCristian Dumitrescu 2244b9559f94SCristian Dumitrescu status = rte_swx_ctl_meter_reset(p, name, idx0); 2245f38913b7SCristian Dumitrescu if (status) { 2246f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0); 2247f38913b7SCristian Dumitrescu return; 2248f38913b7SCristian Dumitrescu } 2249f38913b7SCristian Dumitrescu } 225012eda78dSCristian Dumitrescu 225112eda78dSCristian Dumitrescu return; 225212eda78dSCristian Dumitrescu } 225312eda78dSCristian Dumitrescu 225412eda78dSCristian Dumitrescu /* table. */ 225512eda78dSCristian Dumitrescu if (!strcmp(tokens[5], "table")) { 225612eda78dSCristian Dumitrescu struct rte_swx_table_entry *entry; 225712eda78dSCristian Dumitrescu char *table_name; 225812eda78dSCristian Dumitrescu int status; 225912eda78dSCristian Dumitrescu 226012eda78dSCristian Dumitrescu if (n_tokens < 9) { 226112eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 226212eda78dSCristian Dumitrescu return; 226312eda78dSCristian Dumitrescu } 226412eda78dSCristian Dumitrescu 226512eda78dSCristian Dumitrescu table_name = tokens[6]; 226612eda78dSCristian Dumitrescu 226712eda78dSCristian Dumitrescu if (strcmp(tokens[7], "match")) { 226812eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); 226912eda78dSCristian Dumitrescu return; 227012eda78dSCristian Dumitrescu } 227112eda78dSCristian Dumitrescu 227212eda78dSCristian Dumitrescu entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7); 227312eda78dSCristian Dumitrescu if (!entry) { 227412eda78dSCristian Dumitrescu snprintf(out, out_size, "Invalid match tokens.\n"); 227512eda78dSCristian Dumitrescu return; 227612eda78dSCristian Dumitrescu } 227712eda78dSCristian Dumitrescu 227812eda78dSCristian Dumitrescu status = rte_swx_ctl_meter_reset_with_key(p, name, table_name, entry->key); 227912eda78dSCristian Dumitrescu table_entry_free(entry); 228012eda78dSCristian Dumitrescu if (status) { 228112eda78dSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 228212eda78dSCristian Dumitrescu return; 228312eda78dSCristian Dumitrescu } 228412eda78dSCristian Dumitrescu 228512eda78dSCristian Dumitrescu return; 228612eda78dSCristian Dumitrescu } 228712eda78dSCristian Dumitrescu 228812eda78dSCristian Dumitrescu /* anything else. */ 228912eda78dSCristian Dumitrescu snprintf(out, out_size, "Invalid token %s\n.", tokens[5]); 229012eda78dSCristian Dumitrescu return; 2291f38913b7SCristian Dumitrescu } 2292f38913b7SCristian Dumitrescu 2293f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_set_help[] = 229412eda78dSCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> set profile <profile_name>\n" 229512eda78dSCristian Dumitrescu "index from <index0> to <index1>\n" 229612eda78dSCristian Dumitrescu " | table <table_name> match <field0> ...\n"; 2297f38913b7SCristian Dumitrescu 2298f38913b7SCristian Dumitrescu static void 2299f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(char **tokens, 2300f38913b7SCristian Dumitrescu uint32_t n_tokens, 2301f38913b7SCristian Dumitrescu char *out, 2302f38913b7SCristian Dumitrescu size_t out_size, 2303b9559f94SCristian Dumitrescu void *obj __rte_unused) 2304f38913b7SCristian Dumitrescu { 2305b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 230612eda78dSCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 230712eda78dSCristian Dumitrescu const char *pipeline_name, *name, *profile_name; 2308f38913b7SCristian Dumitrescu 230912eda78dSCristian Dumitrescu if (n_tokens < 8) { 2310f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2311f38913b7SCristian Dumitrescu return; 2312f38913b7SCristian Dumitrescu } 2313f38913b7SCristian Dumitrescu 231412eda78dSCristian Dumitrescu pipeline_name = tokens[1]; 231512eda78dSCristian Dumitrescu p = rte_swx_pipeline_find(pipeline_name); 231612eda78dSCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 231712eda78dSCristian Dumitrescu if (!p || !ctl) { 2318f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2319f38913b7SCristian Dumitrescu return; 2320f38913b7SCristian Dumitrescu } 2321f38913b7SCristian Dumitrescu 2322f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2323f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2324f38913b7SCristian Dumitrescu return; 2325f38913b7SCristian Dumitrescu } 2326f38913b7SCristian Dumitrescu 2327f38913b7SCristian Dumitrescu name = tokens[3]; 2328f38913b7SCristian Dumitrescu 232912eda78dSCristian Dumitrescu if (strcmp(tokens[4], "set")) { 2330f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set"); 2331f38913b7SCristian Dumitrescu return; 2332f38913b7SCristian Dumitrescu } 2333f38913b7SCristian Dumitrescu 233412eda78dSCristian Dumitrescu if (strcmp(tokens[5], "profile")) { 2335f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 2336f38913b7SCristian Dumitrescu return; 2337f38913b7SCristian Dumitrescu } 2338f38913b7SCristian Dumitrescu 233912eda78dSCristian Dumitrescu profile_name = tokens[6]; 234012eda78dSCristian Dumitrescu 234112eda78dSCristian Dumitrescu /* index. */ 234212eda78dSCristian Dumitrescu if (!strcmp(tokens[7], "index")) { 234312eda78dSCristian Dumitrescu uint32_t idx0 = 0, idx1 = 0; 234412eda78dSCristian Dumitrescu 234512eda78dSCristian Dumitrescu if (n_tokens != 12) { 234612eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 234712eda78dSCristian Dumitrescu return; 234812eda78dSCristian Dumitrescu } 234912eda78dSCristian Dumitrescu 235012eda78dSCristian Dumitrescu if (strcmp(tokens[8], "from")) { 235112eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 235212eda78dSCristian Dumitrescu return; 235312eda78dSCristian Dumitrescu } 235412eda78dSCristian Dumitrescu 235512eda78dSCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[9])) { 235612eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 235712eda78dSCristian Dumitrescu return; 235812eda78dSCristian Dumitrescu } 235912eda78dSCristian Dumitrescu 236012eda78dSCristian Dumitrescu if (strcmp(tokens[10], "to")) { 236112eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 236212eda78dSCristian Dumitrescu return; 236312eda78dSCristian Dumitrescu } 236412eda78dSCristian Dumitrescu 236512eda78dSCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[11]) || (idx1 < idx0)) { 236612eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 236712eda78dSCristian Dumitrescu return; 236812eda78dSCristian Dumitrescu } 2369f38913b7SCristian Dumitrescu 2370f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 2371f38913b7SCristian Dumitrescu int status; 2372f38913b7SCristian Dumitrescu 2373b9559f94SCristian Dumitrescu status = rte_swx_ctl_meter_set(p, name, idx0, profile_name); 2374f38913b7SCristian Dumitrescu if (status) { 2375f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0); 2376f38913b7SCristian Dumitrescu return; 2377f38913b7SCristian Dumitrescu } 2378f38913b7SCristian Dumitrescu } 237912eda78dSCristian Dumitrescu 238012eda78dSCristian Dumitrescu return; 238112eda78dSCristian Dumitrescu } 238212eda78dSCristian Dumitrescu 238312eda78dSCristian Dumitrescu /* table. */ 238412eda78dSCristian Dumitrescu if (!strcmp(tokens[7], "table")) { 238512eda78dSCristian Dumitrescu struct rte_swx_table_entry *entry; 238612eda78dSCristian Dumitrescu char *table_name; 238712eda78dSCristian Dumitrescu int status; 238812eda78dSCristian Dumitrescu 238912eda78dSCristian Dumitrescu if (n_tokens < 11) { 239012eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 239112eda78dSCristian Dumitrescu return; 239212eda78dSCristian Dumitrescu } 239312eda78dSCristian Dumitrescu 239412eda78dSCristian Dumitrescu table_name = tokens[8]; 239512eda78dSCristian Dumitrescu 239612eda78dSCristian Dumitrescu if (strcmp(tokens[9], "match")) { 239712eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); 239812eda78dSCristian Dumitrescu return; 239912eda78dSCristian Dumitrescu } 240012eda78dSCristian Dumitrescu 240112eda78dSCristian Dumitrescu entry = parse_table_entry(ctl, table_name, &tokens[9], n_tokens - 9); 240212eda78dSCristian Dumitrescu if (!entry) { 240312eda78dSCristian Dumitrescu snprintf(out, out_size, "Invalid match tokens.\n"); 240412eda78dSCristian Dumitrescu return; 240512eda78dSCristian Dumitrescu } 240612eda78dSCristian Dumitrescu 240712eda78dSCristian Dumitrescu status = rte_swx_ctl_meter_set_with_key(p, 240812eda78dSCristian Dumitrescu name, 240912eda78dSCristian Dumitrescu table_name, 241012eda78dSCristian Dumitrescu entry->key, 241112eda78dSCristian Dumitrescu profile_name); 241212eda78dSCristian Dumitrescu table_entry_free(entry); 241312eda78dSCristian Dumitrescu if (status) { 241412eda78dSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 241512eda78dSCristian Dumitrescu return; 241612eda78dSCristian Dumitrescu } 241712eda78dSCristian Dumitrescu 241812eda78dSCristian Dumitrescu return; 241912eda78dSCristian Dumitrescu } 242012eda78dSCristian Dumitrescu 242112eda78dSCristian Dumitrescu /* anything else. */ 242212eda78dSCristian Dumitrescu snprintf(out, out_size, "Invalid token %s\n.", tokens[7]); 242312eda78dSCristian Dumitrescu return; 2424f38913b7SCristian Dumitrescu } 2425f38913b7SCristian Dumitrescu 2426f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_stats_help[] = 242712eda78dSCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> stats\n" 242812eda78dSCristian Dumitrescu "index from <index0> to <index1>\n" 242912eda78dSCristian Dumitrescu " | table <table_name> match <field0> ...\n"; 2430f38913b7SCristian Dumitrescu 2431f38913b7SCristian Dumitrescu static void 2432f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(char **tokens, 2433f38913b7SCristian Dumitrescu uint32_t n_tokens, 2434f38913b7SCristian Dumitrescu char *out, 2435f38913b7SCristian Dumitrescu size_t out_size, 2436b9559f94SCristian Dumitrescu void *obj __rte_unused) 2437f38913b7SCristian Dumitrescu { 2438f38913b7SCristian Dumitrescu struct rte_swx_ctl_meter_stats stats; 2439b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 244012eda78dSCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl; 244112eda78dSCristian Dumitrescu const char *pipeline_name, *name; 2442f38913b7SCristian Dumitrescu 244312eda78dSCristian Dumitrescu if (n_tokens < 6) { 2444f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2445f38913b7SCristian Dumitrescu return; 2446f38913b7SCristian Dumitrescu } 2447f38913b7SCristian Dumitrescu 244812eda78dSCristian Dumitrescu pipeline_name = tokens[1]; 244912eda78dSCristian Dumitrescu p = rte_swx_pipeline_find(pipeline_name); 245012eda78dSCristian Dumitrescu ctl = rte_swx_ctl_pipeline_find(pipeline_name); 245112eda78dSCristian Dumitrescu if (!p || !ctl) { 2452f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2453f38913b7SCristian Dumitrescu return; 2454f38913b7SCristian Dumitrescu } 2455f38913b7SCristian Dumitrescu 2456f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2457f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2458f38913b7SCristian Dumitrescu return; 2459f38913b7SCristian Dumitrescu } 2460f38913b7SCristian Dumitrescu 2461f38913b7SCristian Dumitrescu name = tokens[3]; 2462f38913b7SCristian Dumitrescu 246312eda78dSCristian Dumitrescu if (strcmp(tokens[4], "stats")) { 246412eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); 246512eda78dSCristian Dumitrescu return; 246612eda78dSCristian Dumitrescu } 246712eda78dSCristian Dumitrescu 246812eda78dSCristian Dumitrescu /* index. */ 246912eda78dSCristian Dumitrescu if (!strcmp(tokens[5], "index")) { 247012eda78dSCristian Dumitrescu uint32_t idx0 = 0, idx1 = 0; 247112eda78dSCristian Dumitrescu 247212eda78dSCristian Dumitrescu if (n_tokens != 10) { 247312eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 247412eda78dSCristian Dumitrescu return; 247512eda78dSCristian Dumitrescu } 247612eda78dSCristian Dumitrescu 247712eda78dSCristian Dumitrescu if (strcmp(tokens[6], "from")) { 2478f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 2479f38913b7SCristian Dumitrescu return; 2480f38913b7SCristian Dumitrescu } 2481f38913b7SCristian Dumitrescu 248212eda78dSCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[7])) { 2483f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 2484f38913b7SCristian Dumitrescu return; 2485f38913b7SCristian Dumitrescu } 2486f38913b7SCristian Dumitrescu 248712eda78dSCristian Dumitrescu if (strcmp(tokens[8], "to")) { 2488f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 2489f38913b7SCristian Dumitrescu return; 2490f38913b7SCristian Dumitrescu } 2491f38913b7SCristian Dumitrescu 249212eda78dSCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) { 2493f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 2494f38913b7SCristian Dumitrescu return; 2495f38913b7SCristian Dumitrescu } 2496f38913b7SCristian Dumitrescu 2497f38913b7SCristian Dumitrescu /* Table header. */ 2498f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 2499f38913b7SCristian Dumitrescu "-------", 2500f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------", 2501f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------"); 2502f38913b7SCristian Dumitrescu out_size -= strlen(out); 2503f38913b7SCristian Dumitrescu out += strlen(out); 2504f38913b7SCristian Dumitrescu 2505f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n", 2506f38913b7SCristian Dumitrescu "METER #", 2507f38913b7SCristian Dumitrescu "GREEN (packets)", "YELLOW (packets)", "RED (packets)", 2508f38913b7SCristian Dumitrescu "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)"); 2509f38913b7SCristian Dumitrescu out_size -= strlen(out); 2510f38913b7SCristian Dumitrescu out += strlen(out); 2511f38913b7SCristian Dumitrescu 2512f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 2513f38913b7SCristian Dumitrescu "-------", 2514f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------", 2515f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------"); 2516f38913b7SCristian Dumitrescu out_size -= strlen(out); 2517f38913b7SCristian Dumitrescu out += strlen(out); 2518f38913b7SCristian Dumitrescu 2519f38913b7SCristian Dumitrescu /* Table rows. */ 2520f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 2521f38913b7SCristian Dumitrescu int status; 2522f38913b7SCristian Dumitrescu 2523b9559f94SCristian Dumitrescu status = rte_swx_ctl_meter_stats_read(p, name, idx0, &stats); 2524f38913b7SCristian Dumitrescu if (status) { 252512eda78dSCristian Dumitrescu snprintf(out, out_size, "Meter stats error at index %u.\n", idx0); 2526f38913b7SCristian Dumitrescu out_size -= strlen(out); 2527f38913b7SCristian Dumitrescu out += strlen(out); 2528f38913b7SCristian Dumitrescu return; 2529f38913b7SCristian Dumitrescu } 2530f38913b7SCristian Dumitrescu 2531f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 2532f38913b7SCristian Dumitrescu " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n", 2533f38913b7SCristian Dumitrescu idx0, 2534f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_GREEN], 2535f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_YELLOW], 2536f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_RED], 2537f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_GREEN], 2538f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_YELLOW], 2539f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_RED]); 2540f38913b7SCristian Dumitrescu out_size -= strlen(out); 2541f38913b7SCristian Dumitrescu out += strlen(out); 2542f38913b7SCristian Dumitrescu } 254312eda78dSCristian Dumitrescu 254412eda78dSCristian Dumitrescu return; 254512eda78dSCristian Dumitrescu } 254612eda78dSCristian Dumitrescu 254712eda78dSCristian Dumitrescu /* table. */ 254812eda78dSCristian Dumitrescu if (!strcmp(tokens[5], "table")) { 254912eda78dSCristian Dumitrescu struct rte_swx_table_entry *entry; 255012eda78dSCristian Dumitrescu char *table_name; 255112eda78dSCristian Dumitrescu int status; 255212eda78dSCristian Dumitrescu 255312eda78dSCristian Dumitrescu if (n_tokens < 9) { 255412eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 255512eda78dSCristian Dumitrescu return; 255612eda78dSCristian Dumitrescu } 255712eda78dSCristian Dumitrescu 255812eda78dSCristian Dumitrescu table_name = tokens[6]; 255912eda78dSCristian Dumitrescu 256012eda78dSCristian Dumitrescu if (strcmp(tokens[7], "match")) { 256112eda78dSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); 256212eda78dSCristian Dumitrescu return; 256312eda78dSCristian Dumitrescu } 256412eda78dSCristian Dumitrescu 256512eda78dSCristian Dumitrescu entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7); 256612eda78dSCristian Dumitrescu if (!entry) { 256712eda78dSCristian Dumitrescu snprintf(out, out_size, "Invalid match tokens.\n"); 256812eda78dSCristian Dumitrescu return; 256912eda78dSCristian Dumitrescu } 257012eda78dSCristian Dumitrescu 257112eda78dSCristian Dumitrescu status = rte_swx_ctl_meter_stats_read_with_key(p, 257212eda78dSCristian Dumitrescu name, 257312eda78dSCristian Dumitrescu table_name, 257412eda78dSCristian Dumitrescu entry->key, 257512eda78dSCristian Dumitrescu &stats); 257612eda78dSCristian Dumitrescu table_entry_free(entry); 257712eda78dSCristian Dumitrescu if (status) { 257812eda78dSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 257912eda78dSCristian Dumitrescu return; 258012eda78dSCristian Dumitrescu } 258112eda78dSCristian Dumitrescu 258212eda78dSCristian Dumitrescu /* Table header. */ 258312eda78dSCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 258412eda78dSCristian Dumitrescu "-------", 258512eda78dSCristian Dumitrescu "----------------", "----------------", "----------------", 258612eda78dSCristian Dumitrescu "----------------", "----------------", "----------------"); 258712eda78dSCristian Dumitrescu out_size -= strlen(out); 258812eda78dSCristian Dumitrescu out += strlen(out); 258912eda78dSCristian Dumitrescu 259012eda78dSCristian Dumitrescu snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n", 259112eda78dSCristian Dumitrescu "METER #", 259212eda78dSCristian Dumitrescu "GREEN (packets)", "YELLOW (packets)", "RED (packets)", 259312eda78dSCristian Dumitrescu "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)"); 259412eda78dSCristian Dumitrescu out_size -= strlen(out); 259512eda78dSCristian Dumitrescu out += strlen(out); 259612eda78dSCristian Dumitrescu 259712eda78dSCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 259812eda78dSCristian Dumitrescu "-------", 259912eda78dSCristian Dumitrescu "----------------", "----------------", "----------------", 260012eda78dSCristian Dumitrescu "----------------", "----------------", "----------------"); 260112eda78dSCristian Dumitrescu out_size -= strlen(out); 260212eda78dSCristian Dumitrescu out += strlen(out); 260312eda78dSCristian Dumitrescu 260412eda78dSCristian Dumitrescu /* Table row. */ 260512eda78dSCristian Dumitrescu snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 260612eda78dSCristian Dumitrescu " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n", 260712eda78dSCristian Dumitrescu 0, 260812eda78dSCristian Dumitrescu stats.n_pkts[RTE_COLOR_GREEN], 260912eda78dSCristian Dumitrescu stats.n_pkts[RTE_COLOR_YELLOW], 261012eda78dSCristian Dumitrescu stats.n_pkts[RTE_COLOR_RED], 261112eda78dSCristian Dumitrescu stats.n_bytes[RTE_COLOR_GREEN], 261212eda78dSCristian Dumitrescu stats.n_bytes[RTE_COLOR_YELLOW], 261312eda78dSCristian Dumitrescu stats.n_bytes[RTE_COLOR_RED]); 261412eda78dSCristian Dumitrescu out_size -= strlen(out); 261512eda78dSCristian Dumitrescu out += strlen(out); 261612eda78dSCristian Dumitrescu 261712eda78dSCristian Dumitrescu return; 261812eda78dSCristian Dumitrescu } 261912eda78dSCristian Dumitrescu 262012eda78dSCristian Dumitrescu /* anything else. */ 262112eda78dSCristian Dumitrescu snprintf(out, out_size, "Invalid token %s\n.", tokens[5]); 262212eda78dSCristian Dumitrescu return; 2623f38913b7SCristian Dumitrescu } 2624f38913b7SCristian Dumitrescu 2625*8ba342ceSCristian Dumitrescu static const char cmd_pipeline_rss_help[] = 2626*8ba342ceSCristian Dumitrescu "pipeline <pipeline_name> rss <rss_obj_name> key <key_byte0> ...\n"; 2627*8ba342ceSCristian Dumitrescu 2628*8ba342ceSCristian Dumitrescu static void 2629*8ba342ceSCristian Dumitrescu cmd_pipeline_rss(char **tokens, 2630*8ba342ceSCristian Dumitrescu uint32_t n_tokens, 2631*8ba342ceSCristian Dumitrescu char *out, 2632*8ba342ceSCristian Dumitrescu size_t out_size, 2633*8ba342ceSCristian Dumitrescu void *obj __rte_unused) 2634*8ba342ceSCristian Dumitrescu { 2635*8ba342ceSCristian Dumitrescu uint8_t rss_key[CMD_MAX_TOKENS]; 2636*8ba342ceSCristian Dumitrescu struct rte_swx_pipeline *p; 2637*8ba342ceSCristian Dumitrescu const char *rss_obj_name; 2638*8ba342ceSCristian Dumitrescu uint32_t rss_key_size, i; 2639*8ba342ceSCristian Dumitrescu int status; 2640*8ba342ceSCristian Dumitrescu 2641*8ba342ceSCristian Dumitrescu if (n_tokens < 6) { 2642*8ba342ceSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2643*8ba342ceSCristian Dumitrescu return; 2644*8ba342ceSCristian Dumitrescu } 2645*8ba342ceSCristian Dumitrescu 2646*8ba342ceSCristian Dumitrescu p = rte_swx_pipeline_find(tokens[1]); 2647*8ba342ceSCristian Dumitrescu if (!p) { 2648*8ba342ceSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2649*8ba342ceSCristian Dumitrescu return; 2650*8ba342ceSCristian Dumitrescu } 2651*8ba342ceSCristian Dumitrescu 2652*8ba342ceSCristian Dumitrescu if (strcmp(tokens[2], "rss")) { 2653*8ba342ceSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss"); 2654*8ba342ceSCristian Dumitrescu return; 2655*8ba342ceSCristian Dumitrescu } 2656*8ba342ceSCristian Dumitrescu 2657*8ba342ceSCristian Dumitrescu rss_obj_name = tokens[3]; 2658*8ba342ceSCristian Dumitrescu 2659*8ba342ceSCristian Dumitrescu if (strcmp(tokens[4], "key")) { 2660*8ba342ceSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key"); 2661*8ba342ceSCristian Dumitrescu return; 2662*8ba342ceSCristian Dumitrescu } 2663*8ba342ceSCristian Dumitrescu 2664*8ba342ceSCristian Dumitrescu tokens += 5; 2665*8ba342ceSCristian Dumitrescu n_tokens -= 5; 2666*8ba342ceSCristian Dumitrescu rss_key_size = n_tokens; 2667*8ba342ceSCristian Dumitrescu 2668*8ba342ceSCristian Dumitrescu for (i = 0; i < rss_key_size; i++) { 2669*8ba342ceSCristian Dumitrescu uint32_t key_byte; 2670*8ba342ceSCristian Dumitrescu 2671*8ba342ceSCristian Dumitrescu if (parser_read_uint32(&key_byte, tokens[i]) || (key_byte >= UINT8_MAX)) { 2672*8ba342ceSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "key byte"); 2673*8ba342ceSCristian Dumitrescu return; 2674*8ba342ceSCristian Dumitrescu } 2675*8ba342ceSCristian Dumitrescu 2676*8ba342ceSCristian Dumitrescu rss_key[i] = (uint8_t)key_byte; 2677*8ba342ceSCristian Dumitrescu } 2678*8ba342ceSCristian Dumitrescu 2679*8ba342ceSCristian Dumitrescu status = rte_swx_ctl_pipeline_rss_key_write(p, rss_obj_name, rss_key_size, rss_key); 2680*8ba342ceSCristian Dumitrescu if (status) { 2681*8ba342ceSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 2682*8ba342ceSCristian Dumitrescu return; 2683*8ba342ceSCristian Dumitrescu } 2684*8ba342ceSCristian Dumitrescu } 2685*8ba342ceSCristian Dumitrescu 26865074e1d5SCristian Dumitrescu static const char cmd_pipeline_stats_help[] = 26875074e1d5SCristian Dumitrescu "pipeline <pipeline_name> stats\n"; 26885074e1d5SCristian Dumitrescu 26895074e1d5SCristian Dumitrescu static void 26905074e1d5SCristian Dumitrescu cmd_pipeline_stats(char **tokens, 26915074e1d5SCristian Dumitrescu uint32_t n_tokens, 26925074e1d5SCristian Dumitrescu char *out, 26935074e1d5SCristian Dumitrescu size_t out_size, 2694b9559f94SCristian Dumitrescu void *obj __rte_unused) 26955074e1d5SCristian Dumitrescu { 26965074e1d5SCristian Dumitrescu struct rte_swx_ctl_pipeline_info info; 2697b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 26985074e1d5SCristian Dumitrescu uint32_t i; 26995074e1d5SCristian Dumitrescu int status; 27005074e1d5SCristian Dumitrescu 27015074e1d5SCristian Dumitrescu if (n_tokens != 3) { 27025074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 27035074e1d5SCristian Dumitrescu return; 27045074e1d5SCristian Dumitrescu } 27055074e1d5SCristian Dumitrescu 2706b9559f94SCristian Dumitrescu p = rte_swx_pipeline_find(tokens[1]); 2707b9559f94SCristian Dumitrescu if (!p) { 27085074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 27095074e1d5SCristian Dumitrescu return; 27105074e1d5SCristian Dumitrescu } 27115074e1d5SCristian Dumitrescu 27125074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "stats")) { 27135074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); 27145074e1d5SCristian Dumitrescu return; 27155074e1d5SCristian Dumitrescu } 27165074e1d5SCristian Dumitrescu 2717b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_info_get(p, &info); 27185074e1d5SCristian Dumitrescu if (status) { 27195074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline info get error."); 27205074e1d5SCristian Dumitrescu return; 27215074e1d5SCristian Dumitrescu } 27225074e1d5SCristian Dumitrescu 27235074e1d5SCristian Dumitrescu snprintf(out, out_size, "Input ports:\n"); 27245074e1d5SCristian Dumitrescu out_size -= strlen(out); 27255074e1d5SCristian Dumitrescu out += strlen(out); 27265074e1d5SCristian Dumitrescu 27275074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_in; i++) { 27285074e1d5SCristian Dumitrescu struct rte_swx_port_in_stats stats; 27295074e1d5SCristian Dumitrescu 2730b9559f94SCristian Dumitrescu rte_swx_ctl_pipeline_port_in_stats_read(p, i, &stats); 27315074e1d5SCristian Dumitrescu 27325074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:" 27335074e1d5SCristian Dumitrescu " packets %" PRIu64 27345074e1d5SCristian Dumitrescu " bytes %" PRIu64 27355074e1d5SCristian Dumitrescu " empty %" PRIu64 "\n", 27365074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes, stats.n_empty); 27375074e1d5SCristian Dumitrescu out_size -= strlen(out); 27385074e1d5SCristian Dumitrescu out += strlen(out); 27395074e1d5SCristian Dumitrescu } 27405074e1d5SCristian Dumitrescu 2741742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nOutput ports:\n"); 27425074e1d5SCristian Dumitrescu out_size -= strlen(out); 27435074e1d5SCristian Dumitrescu out += strlen(out); 27445074e1d5SCristian Dumitrescu 27455074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_out; i++) { 27465074e1d5SCristian Dumitrescu struct rte_swx_port_out_stats stats; 27475074e1d5SCristian Dumitrescu 2748b9559f94SCristian Dumitrescu rte_swx_ctl_pipeline_port_out_stats_read(p, i, &stats); 27495074e1d5SCristian Dumitrescu 275096b37959SCristian Dumitrescu if (i != info.n_ports_out - 1) 275117225455SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:", i); 275296b37959SCristian Dumitrescu else 275317225455SCristian Dumitrescu snprintf(out, out_size, "\tDROP:"); 275417225455SCristian Dumitrescu 275517225455SCristian Dumitrescu out_size -= strlen(out); 275617225455SCristian Dumitrescu out += strlen(out); 275717225455SCristian Dumitrescu 275817225455SCristian Dumitrescu snprintf(out, 275917225455SCristian Dumitrescu out_size, 276096b37959SCristian Dumitrescu " packets %" PRIu64 276117225455SCristian Dumitrescu " bytes %" PRIu64 276267f707b3SCristian Dumitrescu " packets dropped %" PRIu64 276367f707b3SCristian Dumitrescu " bytes dropped %" PRIu64 276417225455SCristian Dumitrescu " clone %" PRIu64 276517225455SCristian Dumitrescu " clonerr %" PRIu64 "\n", 276617225455SCristian Dumitrescu stats.n_pkts, 276717225455SCristian Dumitrescu stats.n_bytes, 276867f707b3SCristian Dumitrescu stats.n_pkts_drop, 276967f707b3SCristian Dumitrescu stats.n_bytes_drop, 277017225455SCristian Dumitrescu stats.n_pkts_clone, 277117225455SCristian Dumitrescu stats.n_pkts_clone_err); 277296b37959SCristian Dumitrescu 27735074e1d5SCristian Dumitrescu out_size -= strlen(out); 27745074e1d5SCristian Dumitrescu out += strlen(out); 27755074e1d5SCristian Dumitrescu } 2776742b0a57SCristian Dumitrescu 2777742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nTables:\n"); 2778742b0a57SCristian Dumitrescu out_size -= strlen(out); 2779742b0a57SCristian Dumitrescu out += strlen(out); 2780742b0a57SCristian Dumitrescu 2781742b0a57SCristian Dumitrescu for (i = 0; i < info.n_tables; i++) { 2782742b0a57SCristian Dumitrescu struct rte_swx_ctl_table_info table_info; 2783742b0a57SCristian Dumitrescu uint64_t n_pkts_action[info.n_actions]; 2784742b0a57SCristian Dumitrescu struct rte_swx_table_stats stats = { 2785742b0a57SCristian Dumitrescu .n_pkts_hit = 0, 2786742b0a57SCristian Dumitrescu .n_pkts_miss = 0, 2787742b0a57SCristian Dumitrescu .n_pkts_action = n_pkts_action, 2788742b0a57SCristian Dumitrescu }; 2789742b0a57SCristian Dumitrescu uint32_t j; 2790742b0a57SCristian Dumitrescu 2791b9559f94SCristian Dumitrescu status = rte_swx_ctl_table_info_get(p, i, &table_info); 2792742b0a57SCristian Dumitrescu if (status) { 2793742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table info get error."); 2794742b0a57SCristian Dumitrescu return; 2795742b0a57SCristian Dumitrescu } 2796742b0a57SCristian Dumitrescu 2797b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_table_stats_read(p, table_info.name, &stats); 2798742b0a57SCristian Dumitrescu if (status) { 2799742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table stats read error."); 2800742b0a57SCristian Dumitrescu return; 2801742b0a57SCristian Dumitrescu } 2802742b0a57SCristian Dumitrescu 2803742b0a57SCristian Dumitrescu snprintf(out, out_size, "\tTable %s:\n" 2804742b0a57SCristian Dumitrescu "\t\tHit (packets): %" PRIu64 "\n" 2805742b0a57SCristian Dumitrescu "\t\tMiss (packets): %" PRIu64 "\n", 2806742b0a57SCristian Dumitrescu table_info.name, 2807742b0a57SCristian Dumitrescu stats.n_pkts_hit, 2808742b0a57SCristian Dumitrescu stats.n_pkts_miss); 2809742b0a57SCristian Dumitrescu out_size -= strlen(out); 2810742b0a57SCristian Dumitrescu out += strlen(out); 2811742b0a57SCristian Dumitrescu 2812742b0a57SCristian Dumitrescu for (j = 0; j < info.n_actions; j++) { 2813742b0a57SCristian Dumitrescu struct rte_swx_ctl_action_info action_info; 2814742b0a57SCristian Dumitrescu 2815b9559f94SCristian Dumitrescu status = rte_swx_ctl_action_info_get(p, j, &action_info); 2816742b0a57SCristian Dumitrescu if (status) { 2817742b0a57SCristian Dumitrescu snprintf(out, out_size, "Action info get error."); 2818742b0a57SCristian Dumitrescu return; 2819742b0a57SCristian Dumitrescu } 2820742b0a57SCristian Dumitrescu 2821742b0a57SCristian Dumitrescu snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n", 2822742b0a57SCristian Dumitrescu action_info.name, 2823742b0a57SCristian Dumitrescu stats.n_pkts_action[j]); 2824742b0a57SCristian Dumitrescu out_size -= strlen(out); 2825742b0a57SCristian Dumitrescu out += strlen(out); 2826742b0a57SCristian Dumitrescu } 2827742b0a57SCristian Dumitrescu } 28288bd4862fSCristian Dumitrescu 28298bd4862fSCristian Dumitrescu snprintf(out, out_size, "\nLearner tables:\n"); 28308bd4862fSCristian Dumitrescu out_size -= strlen(out); 28318bd4862fSCristian Dumitrescu out += strlen(out); 28328bd4862fSCristian Dumitrescu 28338bd4862fSCristian Dumitrescu for (i = 0; i < info.n_learners; i++) { 28348bd4862fSCristian Dumitrescu struct rte_swx_ctl_learner_info learner_info; 28358bd4862fSCristian Dumitrescu uint64_t n_pkts_action[info.n_actions]; 28368bd4862fSCristian Dumitrescu struct rte_swx_learner_stats stats = { 28378bd4862fSCristian Dumitrescu .n_pkts_hit = 0, 28388bd4862fSCristian Dumitrescu .n_pkts_miss = 0, 28398bd4862fSCristian Dumitrescu .n_pkts_action = n_pkts_action, 28408bd4862fSCristian Dumitrescu }; 28418bd4862fSCristian Dumitrescu uint32_t j; 28428bd4862fSCristian Dumitrescu 2843b9559f94SCristian Dumitrescu status = rte_swx_ctl_learner_info_get(p, i, &learner_info); 28448bd4862fSCristian Dumitrescu if (status) { 28458bd4862fSCristian Dumitrescu snprintf(out, out_size, "Learner table info get error."); 28468bd4862fSCristian Dumitrescu return; 28478bd4862fSCristian Dumitrescu } 28488bd4862fSCristian Dumitrescu 2849b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_learner_stats_read(p, learner_info.name, &stats); 28508bd4862fSCristian Dumitrescu if (status) { 28518bd4862fSCristian Dumitrescu snprintf(out, out_size, "Learner table stats read error."); 28528bd4862fSCristian Dumitrescu return; 28538bd4862fSCristian Dumitrescu } 28548bd4862fSCristian Dumitrescu 28558bd4862fSCristian Dumitrescu snprintf(out, out_size, "\tLearner table %s:\n" 28568bd4862fSCristian Dumitrescu "\t\tHit (packets): %" PRIu64 "\n" 28578bd4862fSCristian Dumitrescu "\t\tMiss (packets): %" PRIu64 "\n" 28588bd4862fSCristian Dumitrescu "\t\tLearn OK (packets): %" PRIu64 "\n" 28598bd4862fSCristian Dumitrescu "\t\tLearn error (packets): %" PRIu64 "\n" 286080dd28afSCristian Dumitrescu "\t\tRearm (packets): %" PRIu64 "\n" 28618bd4862fSCristian Dumitrescu "\t\tForget (packets): %" PRIu64 "\n", 28628bd4862fSCristian Dumitrescu learner_info.name, 28638bd4862fSCristian Dumitrescu stats.n_pkts_hit, 28648bd4862fSCristian Dumitrescu stats.n_pkts_miss, 28658bd4862fSCristian Dumitrescu stats.n_pkts_learn_ok, 28668bd4862fSCristian Dumitrescu stats.n_pkts_learn_err, 286780dd28afSCristian Dumitrescu stats.n_pkts_rearm, 28688bd4862fSCristian Dumitrescu stats.n_pkts_forget); 28698bd4862fSCristian Dumitrescu out_size -= strlen(out); 28708bd4862fSCristian Dumitrescu out += strlen(out); 28718bd4862fSCristian Dumitrescu 28728bd4862fSCristian Dumitrescu for (j = 0; j < info.n_actions; j++) { 28738bd4862fSCristian Dumitrescu struct rte_swx_ctl_action_info action_info; 28748bd4862fSCristian Dumitrescu 2875b9559f94SCristian Dumitrescu status = rte_swx_ctl_action_info_get(p, j, &action_info); 28768bd4862fSCristian Dumitrescu if (status) { 28778bd4862fSCristian Dumitrescu snprintf(out, out_size, "Action info get error."); 28788bd4862fSCristian Dumitrescu return; 28798bd4862fSCristian Dumitrescu } 28808bd4862fSCristian Dumitrescu 28818bd4862fSCristian Dumitrescu snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n", 28828bd4862fSCristian Dumitrescu action_info.name, 28838bd4862fSCristian Dumitrescu stats.n_pkts_action[j]); 28848bd4862fSCristian Dumitrescu out_size -= strlen(out); 28858bd4862fSCristian Dumitrescu out += strlen(out); 28868bd4862fSCristian Dumitrescu } 28878bd4862fSCristian Dumitrescu } 28885074e1d5SCristian Dumitrescu } 28895074e1d5SCristian Dumitrescu 289017225455SCristian Dumitrescu static const char cmd_pipeline_mirror_session_help[] = 289117225455SCristian Dumitrescu "pipeline <pipeline_name> mirror session <session_id> port <port_id> clone fast | slow " 289217225455SCristian Dumitrescu "truncate <truncation_length>\n"; 289317225455SCristian Dumitrescu 289417225455SCristian Dumitrescu static void 289517225455SCristian Dumitrescu cmd_pipeline_mirror_session(char **tokens, 289617225455SCristian Dumitrescu uint32_t n_tokens, 289717225455SCristian Dumitrescu char *out, 289817225455SCristian Dumitrescu size_t out_size, 2899b9559f94SCristian Dumitrescu void *obj __rte_unused) 290017225455SCristian Dumitrescu { 290117225455SCristian Dumitrescu struct rte_swx_pipeline_mirroring_session_params params; 2902b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 290377dd857dSAli Alnubani uint32_t session_id = 0; 290417225455SCristian Dumitrescu int status; 290517225455SCristian Dumitrescu 290617225455SCristian Dumitrescu if (n_tokens != 11) { 290717225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 290817225455SCristian Dumitrescu return; 290917225455SCristian Dumitrescu } 291017225455SCristian Dumitrescu 291117225455SCristian Dumitrescu if (strcmp(tokens[0], "pipeline")) { 291217225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 291317225455SCristian Dumitrescu return; 291417225455SCristian Dumitrescu } 291517225455SCristian Dumitrescu 2916b9559f94SCristian Dumitrescu p = rte_swx_pipeline_find(tokens[1]); 2917b9559f94SCristian Dumitrescu if (!p) { 291817225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 291917225455SCristian Dumitrescu return; 292017225455SCristian Dumitrescu } 292117225455SCristian Dumitrescu 292217225455SCristian Dumitrescu if (strcmp(tokens[2], "mirror")) { 292317225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mirror"); 292417225455SCristian Dumitrescu return; 292517225455SCristian Dumitrescu } 292617225455SCristian Dumitrescu 292717225455SCristian Dumitrescu if (strcmp(tokens[3], "session")) { 292817225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "session"); 292917225455SCristian Dumitrescu return; 293017225455SCristian Dumitrescu } 293117225455SCristian Dumitrescu 293217225455SCristian Dumitrescu if (parser_read_uint32(&session_id, tokens[4])) { 293317225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "session_id"); 293417225455SCristian Dumitrescu return; 293517225455SCristian Dumitrescu } 293617225455SCristian Dumitrescu 293717225455SCristian Dumitrescu if (strcmp(tokens[5], "port")) { 293817225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port"); 293917225455SCristian Dumitrescu return; 294017225455SCristian Dumitrescu } 294117225455SCristian Dumitrescu 294217225455SCristian Dumitrescu if (parser_read_uint32(¶ms.port_id, tokens[6])) { 294317225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id"); 294417225455SCristian Dumitrescu return; 294517225455SCristian Dumitrescu } 294617225455SCristian Dumitrescu 294717225455SCristian Dumitrescu if (strcmp(tokens[7], "clone")) { 294817225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "clone"); 294917225455SCristian Dumitrescu return; 295017225455SCristian Dumitrescu } 295117225455SCristian Dumitrescu 295217225455SCristian Dumitrescu if (!strcmp(tokens[8], "fast")) 295317225455SCristian Dumitrescu params.fast_clone = 1; 295417225455SCristian Dumitrescu else if (!strcmp(tokens[8], "slow")) 295517225455SCristian Dumitrescu params.fast_clone = 0; 295617225455SCristian Dumitrescu else { 295717225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "clone"); 295817225455SCristian Dumitrescu return; 295917225455SCristian Dumitrescu } 296017225455SCristian Dumitrescu 296117225455SCristian Dumitrescu if (strcmp(tokens[9], "truncate")) { 296217225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "truncate"); 296317225455SCristian Dumitrescu return; 296417225455SCristian Dumitrescu } 296517225455SCristian Dumitrescu 296617225455SCristian Dumitrescu if (parser_read_uint32(¶ms.truncation_length, tokens[10])) { 296717225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "truncation_length"); 296817225455SCristian Dumitrescu return; 296917225455SCristian Dumitrescu } 297017225455SCristian Dumitrescu 2971b9559f94SCristian Dumitrescu status = rte_swx_ctl_pipeline_mirroring_session_set(p, session_id, ¶ms); 297217225455SCristian Dumitrescu if (status) { 297317225455SCristian Dumitrescu snprintf(out, out_size, "Command failed!\n"); 297417225455SCristian Dumitrescu return; 297517225455SCristian Dumitrescu } 297617225455SCristian Dumitrescu } 297717225455SCristian Dumitrescu 29783b0cc5fbSCristian Dumitrescu static const char cmd_ipsec_create_help[] = 29793b0cc5fbSCristian Dumitrescu "ipsec <ipsec_instance_name> create " 29803b0cc5fbSCristian Dumitrescu "in <ring_in_name> out <ring_out_name> " 29813b0cc5fbSCristian Dumitrescu "cryptodev <crypto_dev_name> cryptoq <crypto_dev_queue_pair_id> " 29823b0cc5fbSCristian Dumitrescu "bsz <ring_rd_bsz> <ring_wr_bsz> <crypto_wr_bsz> <crypto_rd_bsz> " 29833b0cc5fbSCristian Dumitrescu "samax <n_sa_max> " 29843b0cc5fbSCristian Dumitrescu "numa <numa_node>\n"; 29853b0cc5fbSCristian Dumitrescu 29863b0cc5fbSCristian Dumitrescu static void 29873b0cc5fbSCristian Dumitrescu cmd_ipsec_create(char **tokens, 29883b0cc5fbSCristian Dumitrescu uint32_t n_tokens, 29893b0cc5fbSCristian Dumitrescu char *out, 29903b0cc5fbSCristian Dumitrescu size_t out_size, 29913b0cc5fbSCristian Dumitrescu void *obj __rte_unused) 29923b0cc5fbSCristian Dumitrescu { 29933b0cc5fbSCristian Dumitrescu struct rte_swx_ipsec_params p; 29943b0cc5fbSCristian Dumitrescu struct rte_swx_ipsec *ipsec; 29953b0cc5fbSCristian Dumitrescu char *ipsec_instance_name; 29963b0cc5fbSCristian Dumitrescu uint32_t numa_node; 29973b0cc5fbSCristian Dumitrescu int status; 29983b0cc5fbSCristian Dumitrescu 29993b0cc5fbSCristian Dumitrescu if (n_tokens != 20) { 30003b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 30013b0cc5fbSCristian Dumitrescu return; 30023b0cc5fbSCristian Dumitrescu } 30033b0cc5fbSCristian Dumitrescu 30043b0cc5fbSCristian Dumitrescu ipsec_instance_name = tokens[1]; 30053b0cc5fbSCristian Dumitrescu 30063b0cc5fbSCristian Dumitrescu if (strcmp(tokens[2], "create")) { 30073b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "create"); 30083b0cc5fbSCristian Dumitrescu return; 30093b0cc5fbSCristian Dumitrescu } 30103b0cc5fbSCristian Dumitrescu 30113b0cc5fbSCristian Dumitrescu if (strcmp(tokens[3], "in")) { 30123b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in"); 30133b0cc5fbSCristian Dumitrescu return; 30143b0cc5fbSCristian Dumitrescu } 30153b0cc5fbSCristian Dumitrescu 30163b0cc5fbSCristian Dumitrescu p.ring_in_name = tokens[4]; 30173b0cc5fbSCristian Dumitrescu 30183b0cc5fbSCristian Dumitrescu if (strcmp(tokens[5], "out")) { 30193b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out"); 30203b0cc5fbSCristian Dumitrescu return; 30213b0cc5fbSCristian Dumitrescu } 30223b0cc5fbSCristian Dumitrescu 30233b0cc5fbSCristian Dumitrescu p.ring_out_name = tokens[6]; 30243b0cc5fbSCristian Dumitrescu 30253b0cc5fbSCristian Dumitrescu if (strcmp(tokens[7], "cryptodev")) { 30263b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cryptodev"); 30273b0cc5fbSCristian Dumitrescu return; 30283b0cc5fbSCristian Dumitrescu } 30293b0cc5fbSCristian Dumitrescu 30303b0cc5fbSCristian Dumitrescu p.crypto_dev_name = tokens[8]; 30313b0cc5fbSCristian Dumitrescu 30323b0cc5fbSCristian Dumitrescu if (strcmp(tokens[9], "cryptoq")) { 30333b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cryptoq"); 30343b0cc5fbSCristian Dumitrescu return; 30353b0cc5fbSCristian Dumitrescu } 30363b0cc5fbSCristian Dumitrescu 30373b0cc5fbSCristian Dumitrescu if (parser_read_uint32(&p.crypto_dev_queue_pair_id, tokens[10])) { 30383b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "crypto_dev_queue_pair_id"); 30393b0cc5fbSCristian Dumitrescu return; 30403b0cc5fbSCristian Dumitrescu } 30413b0cc5fbSCristian Dumitrescu 30423b0cc5fbSCristian Dumitrescu if (strcmp(tokens[11], "bsz")) { 30433b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 30443b0cc5fbSCristian Dumitrescu return; 30453b0cc5fbSCristian Dumitrescu } 30463b0cc5fbSCristian Dumitrescu 30473b0cc5fbSCristian Dumitrescu if (parser_read_uint32(&p.bsz.ring_rd, tokens[12])) { 30483b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "ring_rd_bsz"); 30493b0cc5fbSCristian Dumitrescu return; 30503b0cc5fbSCristian Dumitrescu } 30513b0cc5fbSCristian Dumitrescu 30523b0cc5fbSCristian Dumitrescu if (parser_read_uint32(&p.bsz.ring_wr, tokens[13])) { 30533b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "ring_wr_bsz"); 30543b0cc5fbSCristian Dumitrescu return; 30553b0cc5fbSCristian Dumitrescu } 30563b0cc5fbSCristian Dumitrescu 30573b0cc5fbSCristian Dumitrescu if (parser_read_uint32(&p.bsz.crypto_wr, tokens[14])) { 30583b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "crypto_wr_bsz"); 30593b0cc5fbSCristian Dumitrescu return; 30603b0cc5fbSCristian Dumitrescu } 30613b0cc5fbSCristian Dumitrescu 30623b0cc5fbSCristian Dumitrescu if (parser_read_uint32(&p.bsz.crypto_rd, tokens[15])) { 30633b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "crypto_rd_bsz"); 30643b0cc5fbSCristian Dumitrescu return; 30653b0cc5fbSCristian Dumitrescu } 30663b0cc5fbSCristian Dumitrescu 30673b0cc5fbSCristian Dumitrescu if (strcmp(tokens[16], "samax")) { 30683b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "samax"); 30693b0cc5fbSCristian Dumitrescu return; 30703b0cc5fbSCristian Dumitrescu } 30713b0cc5fbSCristian Dumitrescu 30723b0cc5fbSCristian Dumitrescu if (parser_read_uint32(&p.n_sa_max, tokens[17])) { 30733b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_sa_max"); 30743b0cc5fbSCristian Dumitrescu return; 30753b0cc5fbSCristian Dumitrescu } 30763b0cc5fbSCristian Dumitrescu 30773b0cc5fbSCristian Dumitrescu if (strcmp(tokens[18], "numa")) { 30783b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa"); 30793b0cc5fbSCristian Dumitrescu return; 30803b0cc5fbSCristian Dumitrescu } 30813b0cc5fbSCristian Dumitrescu 30823b0cc5fbSCristian Dumitrescu if (parser_read_uint32(&numa_node, tokens[19])) { 30833b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node"); 30843b0cc5fbSCristian Dumitrescu return; 30853b0cc5fbSCristian Dumitrescu } 30863b0cc5fbSCristian Dumitrescu 30873b0cc5fbSCristian Dumitrescu status = rte_swx_ipsec_create(&ipsec, 30883b0cc5fbSCristian Dumitrescu ipsec_instance_name, 30893b0cc5fbSCristian Dumitrescu &p, 30903b0cc5fbSCristian Dumitrescu (int)numa_node); 30913b0cc5fbSCristian Dumitrescu if (status) 30923b0cc5fbSCristian Dumitrescu snprintf(out, out_size, "IPsec instance creation failed (%d).\n", status); 30933b0cc5fbSCristian Dumitrescu } 30943b0cc5fbSCristian Dumitrescu 30953b0cc5fbSCristian Dumitrescu static const char cmd_ipsec_sa_add_help[] = 30963b0cc5fbSCristian Dumitrescu "ipsec <ipsec_instance_name> sa add <file_name>\n"; 30973b0cc5fbSCristian Dumitrescu 30983b0cc5fbSCristian Dumitrescu static void 30993b0cc5fbSCristian Dumitrescu cmd_ipsec_sa_add(char **tokens, 31003b0cc5fbSCristian Dumitrescu uint32_t n_tokens, 31013b0cc5fbSCristian Dumitrescu char *out, 31023b0cc5fbSCristian Dumitrescu size_t out_size, 31033b0cc5fbSCristian Dumitrescu void *obj __rte_unused) 31043b0cc5fbSCristian Dumitrescu { 31053b0cc5fbSCristian Dumitrescu struct rte_swx_ipsec *ipsec; 31063b0cc5fbSCristian Dumitrescu char *ipsec_instance_name, *file_name, *line = NULL; 31073b0cc5fbSCristian Dumitrescu FILE *file = NULL; 31083b0cc5fbSCristian Dumitrescu uint32_t line_id = 0; 31093b0cc5fbSCristian Dumitrescu 31103b0cc5fbSCristian Dumitrescu if (n_tokens != 5) { 31113b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 31123b0cc5fbSCristian Dumitrescu return; 31133b0cc5fbSCristian Dumitrescu } 31143b0cc5fbSCristian Dumitrescu 31153b0cc5fbSCristian Dumitrescu ipsec_instance_name = tokens[1]; 31163b0cc5fbSCristian Dumitrescu ipsec = rte_swx_ipsec_find(ipsec_instance_name); 31173b0cc5fbSCristian Dumitrescu if (!ipsec) { 31183b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "ipsec_instance_name"); 31193b0cc5fbSCristian Dumitrescu goto free; 31203b0cc5fbSCristian Dumitrescu } 31213b0cc5fbSCristian Dumitrescu 31223b0cc5fbSCristian Dumitrescu if (strcmp(tokens[2], "sa")) { 31233b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "sa"); 31243b0cc5fbSCristian Dumitrescu goto free; 31253b0cc5fbSCristian Dumitrescu } 31263b0cc5fbSCristian Dumitrescu 31273b0cc5fbSCristian Dumitrescu if (strcmp(tokens[3], "add")) { 31283b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add"); 31293b0cc5fbSCristian Dumitrescu goto free; 31303b0cc5fbSCristian Dumitrescu } 31313b0cc5fbSCristian Dumitrescu 31323b0cc5fbSCristian Dumitrescu file_name = tokens[4]; 31333b0cc5fbSCristian Dumitrescu file = fopen(file_name, "r"); 31343b0cc5fbSCristian Dumitrescu if (!file) { 31353b0cc5fbSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name); 31363b0cc5fbSCristian Dumitrescu goto free; 31373b0cc5fbSCristian Dumitrescu } 31383b0cc5fbSCristian Dumitrescu 31393b0cc5fbSCristian Dumitrescu /* Buffer allocation. */ 31403b0cc5fbSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 31413b0cc5fbSCristian Dumitrescu if (!line) { 31423b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_OUT_OF_MEMORY); 31433b0cc5fbSCristian Dumitrescu goto free; 31443b0cc5fbSCristian Dumitrescu } 31453b0cc5fbSCristian Dumitrescu 31463b0cc5fbSCristian Dumitrescu /* File read. */ 31473b0cc5fbSCristian Dumitrescu for (line_id = 1; ; line_id++) { 31483b0cc5fbSCristian Dumitrescu struct rte_swx_ipsec_sa_params *sa; 31493b0cc5fbSCristian Dumitrescu const char *err_msg; 31503b0cc5fbSCristian Dumitrescu uint32_t sa_id = 0; 31513b0cc5fbSCristian Dumitrescu int is_blank_or_comment, status = 0; 31523b0cc5fbSCristian Dumitrescu 31533b0cc5fbSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL) 31543b0cc5fbSCristian Dumitrescu break; 31553b0cc5fbSCristian Dumitrescu 31563b0cc5fbSCristian Dumitrescu /* Read SA from file. */ 31573b0cc5fbSCristian Dumitrescu sa = rte_swx_ipsec_sa_read(ipsec, line, &is_blank_or_comment, &err_msg); 31583b0cc5fbSCristian Dumitrescu if (!sa) { 31593b0cc5fbSCristian Dumitrescu if (is_blank_or_comment) 31603b0cc5fbSCristian Dumitrescu continue; 31613b0cc5fbSCristian Dumitrescu 31623b0cc5fbSCristian Dumitrescu snprintf(out, out_size, "Invalid SA in file \"%s\" at line %u: \"%s\"\n", 31633b0cc5fbSCristian Dumitrescu file_name, line_id, err_msg); 31643b0cc5fbSCristian Dumitrescu goto free; 31653b0cc5fbSCristian Dumitrescu } 31663b0cc5fbSCristian Dumitrescu 31673b0cc5fbSCristian Dumitrescu snprintf(out, out_size, "%s", line); 31683b0cc5fbSCristian Dumitrescu out_size -= strlen(out); 31693b0cc5fbSCristian Dumitrescu out += strlen(out); 31703b0cc5fbSCristian Dumitrescu 31713b0cc5fbSCristian Dumitrescu /* Add the SA to the IPsec instance. Free the SA. */ 31723b0cc5fbSCristian Dumitrescu status = rte_swx_ipsec_sa_add(ipsec, sa, &sa_id); 31733b0cc5fbSCristian Dumitrescu if (status) 31743b0cc5fbSCristian Dumitrescu snprintf(out, out_size, "\t: Error (%d)\n", status); 31753b0cc5fbSCristian Dumitrescu else 31763b0cc5fbSCristian Dumitrescu snprintf(out, out_size, "\t: OK (SA ID = %u)\n", sa_id); 31773b0cc5fbSCristian Dumitrescu out_size -= strlen(out); 31783b0cc5fbSCristian Dumitrescu out += strlen(out); 31793b0cc5fbSCristian Dumitrescu 31803b0cc5fbSCristian Dumitrescu free(sa); 31813b0cc5fbSCristian Dumitrescu if (status) 31823b0cc5fbSCristian Dumitrescu goto free; 31833b0cc5fbSCristian Dumitrescu } 31843b0cc5fbSCristian Dumitrescu 31853b0cc5fbSCristian Dumitrescu free: 31863b0cc5fbSCristian Dumitrescu if (file) 31873b0cc5fbSCristian Dumitrescu fclose(file); 31883b0cc5fbSCristian Dumitrescu free(line); 31893b0cc5fbSCristian Dumitrescu } 31903b0cc5fbSCristian Dumitrescu 31913b0cc5fbSCristian Dumitrescu static const char cmd_ipsec_sa_delete_help[] = 31923b0cc5fbSCristian Dumitrescu "ipsec <ipsec_instance_name> sa delete <sa_id>\n"; 31933b0cc5fbSCristian Dumitrescu 31943b0cc5fbSCristian Dumitrescu static void 31953b0cc5fbSCristian Dumitrescu cmd_ipsec_sa_delete(char **tokens, 31963b0cc5fbSCristian Dumitrescu uint32_t n_tokens, 31973b0cc5fbSCristian Dumitrescu char *out, 31983b0cc5fbSCristian Dumitrescu size_t out_size, 31993b0cc5fbSCristian Dumitrescu void *obj __rte_unused) 32003b0cc5fbSCristian Dumitrescu { 32013b0cc5fbSCristian Dumitrescu struct rte_swx_ipsec *ipsec; 32023b0cc5fbSCristian Dumitrescu char *ipsec_instance_name; 32033b0cc5fbSCristian Dumitrescu uint32_t sa_id; 32043b0cc5fbSCristian Dumitrescu 32053b0cc5fbSCristian Dumitrescu if (n_tokens != 5) { 32063b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 32073b0cc5fbSCristian Dumitrescu return; 32083b0cc5fbSCristian Dumitrescu } 32093b0cc5fbSCristian Dumitrescu 32103b0cc5fbSCristian Dumitrescu ipsec_instance_name = tokens[1]; 32113b0cc5fbSCristian Dumitrescu ipsec = rte_swx_ipsec_find(ipsec_instance_name); 32123b0cc5fbSCristian Dumitrescu if (!ipsec) { 32133b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "ipsec_instance_name"); 32143b0cc5fbSCristian Dumitrescu return; 32153b0cc5fbSCristian Dumitrescu } 32163b0cc5fbSCristian Dumitrescu 32173b0cc5fbSCristian Dumitrescu if (strcmp(tokens[2], "sa")) { 32183b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "sa"); 32193b0cc5fbSCristian Dumitrescu return; 32203b0cc5fbSCristian Dumitrescu } 32213b0cc5fbSCristian Dumitrescu 32223b0cc5fbSCristian Dumitrescu if (strcmp(tokens[3], "delete")) { 32233b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete"); 32243b0cc5fbSCristian Dumitrescu return; 32253b0cc5fbSCristian Dumitrescu } 32263b0cc5fbSCristian Dumitrescu 32273b0cc5fbSCristian Dumitrescu if (parser_read_uint32(&sa_id, tokens[4])) { 32283b0cc5fbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "sa_id"); 32293b0cc5fbSCristian Dumitrescu return; 32303b0cc5fbSCristian Dumitrescu } 32313b0cc5fbSCristian Dumitrescu 32323b0cc5fbSCristian Dumitrescu rte_swx_ipsec_sa_delete(ipsec, sa_id); 32333b0cc5fbSCristian Dumitrescu } 32343b0cc5fbSCristian Dumitrescu 323541f5dfcbSCristian Dumitrescu static const char cmd_pipeline_enable_help[] = 323641f5dfcbSCristian Dumitrescu "pipeline <pipeline_name> enable thread <thread_id>\n"; 32375074e1d5SCristian Dumitrescu 32385074e1d5SCristian Dumitrescu static void 323941f5dfcbSCristian Dumitrescu cmd_pipeline_enable(char **tokens, 32405074e1d5SCristian Dumitrescu uint32_t n_tokens, 32415074e1d5SCristian Dumitrescu char *out, 32425074e1d5SCristian Dumitrescu size_t out_size, 3243b9559f94SCristian Dumitrescu void *obj __rte_unused) 32445074e1d5SCristian Dumitrescu { 32455074e1d5SCristian Dumitrescu char *pipeline_name; 3246b9559f94SCristian Dumitrescu struct rte_swx_pipeline *p; 32475074e1d5SCristian Dumitrescu uint32_t thread_id; 32485074e1d5SCristian Dumitrescu int status; 32495074e1d5SCristian Dumitrescu 32505074e1d5SCristian Dumitrescu if (n_tokens != 5) { 32515074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 32525074e1d5SCristian Dumitrescu return; 32535074e1d5SCristian Dumitrescu } 32545074e1d5SCristian Dumitrescu 325541f5dfcbSCristian Dumitrescu pipeline_name = tokens[1]; 3256b9559f94SCristian Dumitrescu p = rte_swx_pipeline_find(pipeline_name); 3257b9559f94SCristian Dumitrescu if (!p) { 32585074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 32595074e1d5SCristian Dumitrescu return; 32605074e1d5SCristian Dumitrescu } 32615074e1d5SCristian Dumitrescu 326241f5dfcbSCristian Dumitrescu if (strcmp(tokens[2], "enable") != 0) { 326341f5dfcbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable"); 326441f5dfcbSCristian Dumitrescu return; 326541f5dfcbSCristian Dumitrescu } 326641f5dfcbSCristian Dumitrescu 326741f5dfcbSCristian Dumitrescu if (strcmp(tokens[3], "thread") != 0) { 326841f5dfcbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread"); 326941f5dfcbSCristian Dumitrescu return; 327041f5dfcbSCristian Dumitrescu } 327141f5dfcbSCristian Dumitrescu 327241f5dfcbSCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[4]) != 0) { 327341f5dfcbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 327441f5dfcbSCristian Dumitrescu return; 327541f5dfcbSCristian Dumitrescu } 327641f5dfcbSCristian Dumitrescu 327741f5dfcbSCristian Dumitrescu status = pipeline_enable(p, thread_id); 327841f5dfcbSCristian Dumitrescu if (status) { 327941f5dfcbSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, "pipeline enable"); 328041f5dfcbSCristian Dumitrescu return; 328141f5dfcbSCristian Dumitrescu } 328241f5dfcbSCristian Dumitrescu } 328341f5dfcbSCristian Dumitrescu 328441f5dfcbSCristian Dumitrescu static const char cmd_pipeline_disable_help[] = 328541f5dfcbSCristian Dumitrescu "pipeline <pipeline_name> disable\n"; 328641f5dfcbSCristian Dumitrescu 328741f5dfcbSCristian Dumitrescu static void 328841f5dfcbSCristian Dumitrescu cmd_pipeline_disable(char **tokens, 328941f5dfcbSCristian Dumitrescu uint32_t n_tokens, 329041f5dfcbSCristian Dumitrescu char *out, 329141f5dfcbSCristian Dumitrescu size_t out_size, 329241f5dfcbSCristian Dumitrescu void *obj __rte_unused) 329341f5dfcbSCristian Dumitrescu { 329441f5dfcbSCristian Dumitrescu struct rte_swx_pipeline *p; 329541f5dfcbSCristian Dumitrescu char *pipeline_name; 329641f5dfcbSCristian Dumitrescu 329741f5dfcbSCristian Dumitrescu if (n_tokens != 3) { 329841f5dfcbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 329941f5dfcbSCristian Dumitrescu return; 330041f5dfcbSCristian Dumitrescu } 330141f5dfcbSCristian Dumitrescu 330241f5dfcbSCristian Dumitrescu pipeline_name = tokens[1]; 330341f5dfcbSCristian Dumitrescu p = rte_swx_pipeline_find(pipeline_name); 330441f5dfcbSCristian Dumitrescu if (!p) { 330541f5dfcbSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 330641f5dfcbSCristian Dumitrescu return; 330741f5dfcbSCristian Dumitrescu } 330841f5dfcbSCristian Dumitrescu 330941f5dfcbSCristian Dumitrescu if (strcmp(tokens[2], "disable") != 0) { 33105074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable"); 33115074e1d5SCristian Dumitrescu return; 33125074e1d5SCristian Dumitrescu } 33135074e1d5SCristian Dumitrescu 331441f5dfcbSCristian Dumitrescu pipeline_disable(p); 33155074e1d5SCristian Dumitrescu } 33165074e1d5SCristian Dumitrescu 33176d99096cSCristian Dumitrescu static const char cmd_block_enable_help[] = 33186d99096cSCristian Dumitrescu "block type <block_type> instance <block_name> enable thread <thread_id>\n"; 33196d99096cSCristian Dumitrescu 33206d99096cSCristian Dumitrescu static void 33216d99096cSCristian Dumitrescu cmd_block_enable(char **tokens, 33226d99096cSCristian Dumitrescu uint32_t n_tokens, 33236d99096cSCristian Dumitrescu char *out, 33246d99096cSCristian Dumitrescu size_t out_size, 33256d99096cSCristian Dumitrescu void *obj __rte_unused) 33266d99096cSCristian Dumitrescu { 33276d99096cSCristian Dumitrescu char *block_type, *block_name; 33286d99096cSCristian Dumitrescu block_run_f block_func = NULL; 33296d99096cSCristian Dumitrescu void *block = NULL; 33306d99096cSCristian Dumitrescu uint32_t thread_id; 33316d99096cSCristian Dumitrescu int status; 33326d99096cSCristian Dumitrescu 33336d99096cSCristian Dumitrescu if (n_tokens != 8) { 33346d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 33356d99096cSCristian Dumitrescu return; 33366d99096cSCristian Dumitrescu } 33376d99096cSCristian Dumitrescu 33386d99096cSCristian Dumitrescu if (strcmp(tokens[1], "type") != 0) { 33396d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "type"); 33406d99096cSCristian Dumitrescu return; 33416d99096cSCristian Dumitrescu } 33426d99096cSCristian Dumitrescu 33436d99096cSCristian Dumitrescu block_type = tokens[2]; 33446d99096cSCristian Dumitrescu 33456d99096cSCristian Dumitrescu if (strcmp(tokens[3], "instance") != 0) { 33466d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "instance"); 33476d99096cSCristian Dumitrescu return; 33486d99096cSCristian Dumitrescu } 33496d99096cSCristian Dumitrescu 33506d99096cSCristian Dumitrescu block_name = tokens[4]; 33516d99096cSCristian Dumitrescu 33526d99096cSCristian Dumitrescu if (strcmp(tokens[5], "enable") != 0) { 33536d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable"); 33546d99096cSCristian Dumitrescu return; 33556d99096cSCristian Dumitrescu } 33566d99096cSCristian Dumitrescu 33576d99096cSCristian Dumitrescu if (strcmp(tokens[6], "thread") != 0) { 33586d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread"); 33596d99096cSCristian Dumitrescu return; 33606d99096cSCristian Dumitrescu } 33616d99096cSCristian Dumitrescu 33626d99096cSCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[7]) != 0) { 33636d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 33646d99096cSCristian Dumitrescu return; 33656d99096cSCristian Dumitrescu } 33666d99096cSCristian Dumitrescu 33676d99096cSCristian Dumitrescu if (!strcmp(block_type, "ipsec")) { 33686d99096cSCristian Dumitrescu struct rte_swx_ipsec *ipsec; 33696d99096cSCristian Dumitrescu 33706d99096cSCristian Dumitrescu ipsec = rte_swx_ipsec_find(block_name); 33716d99096cSCristian Dumitrescu if (!ipsec) { 33726d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "block_name"); 33736d99096cSCristian Dumitrescu return; 33746d99096cSCristian Dumitrescu } 33756d99096cSCristian Dumitrescu 33766d99096cSCristian Dumitrescu block_func = (block_run_f)rte_swx_ipsec_run; 33776d99096cSCristian Dumitrescu block = (void *)ipsec; 33786d99096cSCristian Dumitrescu } else { 33796d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "block_type"); 33806d99096cSCristian Dumitrescu return; 33816d99096cSCristian Dumitrescu } 33826d99096cSCristian Dumitrescu 33836d99096cSCristian Dumitrescu status = block_enable(block_func, block, thread_id); 33846d99096cSCristian Dumitrescu if (status) { 33856d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, "block enable"); 33866d99096cSCristian Dumitrescu return; 33876d99096cSCristian Dumitrescu } 33886d99096cSCristian Dumitrescu } 33896d99096cSCristian Dumitrescu 33906d99096cSCristian Dumitrescu static const char cmd_block_disable_help[] = 33916d99096cSCristian Dumitrescu "block type <block_type> instance <block_name> disable\n"; 33926d99096cSCristian Dumitrescu 33936d99096cSCristian Dumitrescu static void 33946d99096cSCristian Dumitrescu cmd_block_disable(char **tokens, 33956d99096cSCristian Dumitrescu uint32_t n_tokens, 33966d99096cSCristian Dumitrescu char *out, 33976d99096cSCristian Dumitrescu size_t out_size, 33986d99096cSCristian Dumitrescu void *obj __rte_unused) 33996d99096cSCristian Dumitrescu { 34006d99096cSCristian Dumitrescu char *block_type, *block_name; 34016d99096cSCristian Dumitrescu void *block = NULL; 34026d99096cSCristian Dumitrescu 34036d99096cSCristian Dumitrescu if (n_tokens != 6) { 34046d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 34056d99096cSCristian Dumitrescu return; 34066d99096cSCristian Dumitrescu } 34076d99096cSCristian Dumitrescu 34086d99096cSCristian Dumitrescu if (strcmp(tokens[1], "type") != 0) { 34096d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "type"); 34106d99096cSCristian Dumitrescu return; 34116d99096cSCristian Dumitrescu } 34126d99096cSCristian Dumitrescu 34136d99096cSCristian Dumitrescu block_type = tokens[2]; 34146d99096cSCristian Dumitrescu 34156d99096cSCristian Dumitrescu if (strcmp(tokens[3], "instance") != 0) { 34166d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "instance"); 34176d99096cSCristian Dumitrescu return; 34186d99096cSCristian Dumitrescu } 34196d99096cSCristian Dumitrescu 34206d99096cSCristian Dumitrescu block_name = tokens[4]; 34216d99096cSCristian Dumitrescu 34226d99096cSCristian Dumitrescu if (strcmp(tokens[5], "disable") != 0) { 34236d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable"); 34246d99096cSCristian Dumitrescu return; 34256d99096cSCristian Dumitrescu } 34266d99096cSCristian Dumitrescu 34276d99096cSCristian Dumitrescu if (!strcmp(block_type, "ipsec")) { 34286d99096cSCristian Dumitrescu struct rte_swx_ipsec *ipsec; 34296d99096cSCristian Dumitrescu 34306d99096cSCristian Dumitrescu ipsec = rte_swx_ipsec_find(block_name); 34316d99096cSCristian Dumitrescu if (!ipsec) { 34326d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "block_name"); 34336d99096cSCristian Dumitrescu return; 34346d99096cSCristian Dumitrescu } 34356d99096cSCristian Dumitrescu 34366d99096cSCristian Dumitrescu block = (void *)ipsec; 34376d99096cSCristian Dumitrescu } else { 34386d99096cSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "block_type"); 34396d99096cSCristian Dumitrescu return; 34406d99096cSCristian Dumitrescu } 34416d99096cSCristian Dumitrescu 34426d99096cSCristian Dumitrescu block_disable(block); 34436d99096cSCristian Dumitrescu } 34446d99096cSCristian Dumitrescu 34455074e1d5SCristian Dumitrescu static void 34465074e1d5SCristian Dumitrescu cmd_help(char **tokens, 34475074e1d5SCristian Dumitrescu uint32_t n_tokens, 34485074e1d5SCristian Dumitrescu char *out, 34495074e1d5SCristian Dumitrescu size_t out_size, 34505074e1d5SCristian Dumitrescu void *arg __rte_unused) 34515074e1d5SCristian Dumitrescu { 34525074e1d5SCristian Dumitrescu tokens++; 34535074e1d5SCristian Dumitrescu n_tokens--; 34545074e1d5SCristian Dumitrescu 34555074e1d5SCristian Dumitrescu if (n_tokens == 0) { 34565074e1d5SCristian Dumitrescu snprintf(out, out_size, 34577fef9ef1SYogesh Jangra "Type 'help <command>' for command details.\n\n" 34587fef9ef1SYogesh Jangra "List of commands:\n" 34597fef9ef1SYogesh Jangra "\tmempool\n" 3460f31c80f8SCristian Dumitrescu "\tethdev\n" 346178dffe31SCristian Dumitrescu "\tethdev show\n" 3462607dd517SCristian Dumitrescu "\tring\n" 34631b41a527SCristian Dumitrescu "\tcryptodev\n" 34649043f66aSCristian Dumitrescu "\tpipeline codegen\n" 34656bc14d9fSCristian Dumitrescu "\tpipeline libbuild\n" 34667fef9ef1SYogesh Jangra "\tpipeline build\n" 346775129cebSChurchill Khangar "\tpipeline table add\n" 346875129cebSChurchill Khangar "\tpipeline table delete\n" 346975129cebSChurchill Khangar "\tpipeline table default\n" 347075129cebSChurchill Khangar "\tpipeline table show\n" 3471598fe0ddSCristian Dumitrescu "\tpipeline selector group add\n" 3472598fe0ddSCristian Dumitrescu "\tpipeline selector group delete\n" 3473598fe0ddSCristian Dumitrescu "\tpipeline selector group member add\n" 3474598fe0ddSCristian Dumitrescu "\tpipeline selector group member delete\n" 3475598fe0ddSCristian Dumitrescu "\tpipeline selector show\n" 34768bd4862fSCristian Dumitrescu "\tpipeline learner default\n" 347775129cebSChurchill Khangar "\tpipeline commit\n" 347875129cebSChurchill Khangar "\tpipeline abort\n" 347964cfcebdSCristian Dumitrescu "\tpipeline regrd\n" 348064cfcebdSCristian Dumitrescu "\tpipeline regwr\n" 3481f38913b7SCristian Dumitrescu "\tpipeline meter profile add\n" 3482f38913b7SCristian Dumitrescu "\tpipeline meter profile delete\n" 3483f38913b7SCristian Dumitrescu "\tpipeline meter reset\n" 3484f38913b7SCristian Dumitrescu "\tpipeline meter set\n" 3485f38913b7SCristian Dumitrescu "\tpipeline meter stats\n" 3486*8ba342ceSCristian Dumitrescu "\tpipeline rss\n" 34877fef9ef1SYogesh Jangra "\tpipeline stats\n" 348817225455SCristian Dumitrescu "\tpipeline mirror session\n" 348941f5dfcbSCristian Dumitrescu "\tpipeline enable\n" 349041f5dfcbSCristian Dumitrescu "\tpipeline disable\n\n" 34913b0cc5fbSCristian Dumitrescu "\tipsec create\n" 34923b0cc5fbSCristian Dumitrescu "\tipsec sa add\n" 34933b0cc5fbSCristian Dumitrescu "\tipsec sa delete\n" 34946d99096cSCristian Dumitrescu "\tblock enable\n" 34956d99096cSCristian Dumitrescu "\tblock disable\n" 349641f5dfcbSCristian Dumitrescu ); 34975074e1d5SCristian Dumitrescu return; 34985074e1d5SCristian Dumitrescu } 34995074e1d5SCristian Dumitrescu 35005074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 35015074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_mempool_help); 35025074e1d5SCristian Dumitrescu return; 35035074e1d5SCristian Dumitrescu } 35045074e1d5SCristian Dumitrescu 350578dffe31SCristian Dumitrescu if (!strcmp(tokens[0], "ethdev")) { 350678dffe31SCristian Dumitrescu if (n_tokens == 1) { 3507f31c80f8SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ethdev_help); 35085074e1d5SCristian Dumitrescu return; 35095074e1d5SCristian Dumitrescu } 35105074e1d5SCristian Dumitrescu 351178dffe31SCristian Dumitrescu if (n_tokens == 2 && !strcmp(tokens[1], "show")) { 351278dffe31SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ethdev_show_help); 351378dffe31SCristian Dumitrescu return; 351478dffe31SCristian Dumitrescu } 351578dffe31SCristian Dumitrescu } 351678dffe31SCristian Dumitrescu 351777a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 351877a41301SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ring_help); 351977a41301SCristian Dumitrescu return; 352077a41301SCristian Dumitrescu } 352177a41301SCristian Dumitrescu 35221b41a527SCristian Dumitrescu if (!strcmp(tokens[0], "cryptodev")) { 35231b41a527SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help); 35241b41a527SCristian Dumitrescu return; 35251b41a527SCristian Dumitrescu } 35261b41a527SCristian Dumitrescu 35275074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 35289043f66aSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "codegen") == 0)) { 35299043f66aSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_codegen_help); 35309043f66aSCristian Dumitrescu return; 35319043f66aSCristian Dumitrescu } 35329043f66aSCristian Dumitrescu 35339043f66aSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 35346bc14d9fSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "libbuild") == 0)) { 35356bc14d9fSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_libbuild_help); 35366bc14d9fSCristian Dumitrescu return; 35376bc14d9fSCristian Dumitrescu } 35386bc14d9fSCristian Dumitrescu 35396bc14d9fSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 35407fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) { 35415074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help); 35425074e1d5SCristian Dumitrescu return; 35435074e1d5SCristian Dumitrescu } 35445074e1d5SCristian Dumitrescu 35455074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 35467fef9ef1SYogesh Jangra (n_tokens == 3) && 35477fef9ef1SYogesh Jangra (strcmp(tokens[1], "table") == 0) && 354875129cebSChurchill Khangar (strcmp(tokens[2], "add") == 0)) { 35495074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 355075129cebSChurchill Khangar cmd_pipeline_table_add_help); 355175129cebSChurchill Khangar return; 355275129cebSChurchill Khangar } 355375129cebSChurchill Khangar 355475129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 355575129cebSChurchill Khangar (n_tokens == 3) && 355675129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 355775129cebSChurchill Khangar (strcmp(tokens[2], "delete") == 0)) { 355875129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 355975129cebSChurchill Khangar cmd_pipeline_table_delete_help); 356075129cebSChurchill Khangar return; 356175129cebSChurchill Khangar } 356275129cebSChurchill Khangar 356375129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 356475129cebSChurchill Khangar (n_tokens == 3) && 356575129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 356675129cebSChurchill Khangar (strcmp(tokens[2], "default") == 0)) { 356775129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 356875129cebSChurchill Khangar cmd_pipeline_table_default_help); 356975129cebSChurchill Khangar return; 357075129cebSChurchill Khangar } 357175129cebSChurchill Khangar 357275129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 357375129cebSChurchill Khangar (n_tokens == 3) && 357475129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 357575129cebSChurchill Khangar (strcmp(tokens[2], "show") == 0)) { 357675129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 357775129cebSChurchill Khangar cmd_pipeline_table_show_help); 357875129cebSChurchill Khangar return; 357975129cebSChurchill Khangar } 358075129cebSChurchill Khangar 358175129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 3582598fe0ddSCristian Dumitrescu (n_tokens == 4) && 3583598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3584598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 3585598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "add") == 0)) { 3586598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3587598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add_help); 3588598fe0ddSCristian Dumitrescu return; 3589598fe0ddSCristian Dumitrescu } 3590598fe0ddSCristian Dumitrescu 3591598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 3592598fe0ddSCristian Dumitrescu (n_tokens == 4) && 3593598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3594598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 3595598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "delete") == 0)) { 3596598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3597598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete_help); 3598598fe0ddSCristian Dumitrescu return; 3599598fe0ddSCristian Dumitrescu } 3600598fe0ddSCristian Dumitrescu 3601598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 3602598fe0ddSCristian Dumitrescu (n_tokens == 5) && 3603598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3604598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 3605598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "member") == 0) && 3606598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "add") == 0)) { 3607598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3608598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add_help); 3609598fe0ddSCristian Dumitrescu return; 3610598fe0ddSCristian Dumitrescu } 3611598fe0ddSCristian Dumitrescu 3612598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 3613598fe0ddSCristian Dumitrescu (n_tokens == 5) && 3614598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3615598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 3616598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "member") == 0) && 3617598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "delete") == 0)) { 3618598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3619598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete_help); 3620598fe0ddSCristian Dumitrescu return; 3621598fe0ddSCristian Dumitrescu } 3622598fe0ddSCristian Dumitrescu 3623598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 3624598fe0ddSCristian Dumitrescu (n_tokens == 3) && 3625598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3626598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "show") == 0)) { 3627598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3628598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show_help); 3629598fe0ddSCristian Dumitrescu return; 3630598fe0ddSCristian Dumitrescu } 3631598fe0ddSCristian Dumitrescu 3632598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 36338bd4862fSCristian Dumitrescu (n_tokens == 3) && 36348bd4862fSCristian Dumitrescu (strcmp(tokens[1], "learner") == 0) && 36358bd4862fSCristian Dumitrescu (strcmp(tokens[2], "default") == 0)) { 36368bd4862fSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 36378bd4862fSCristian Dumitrescu cmd_pipeline_learner_default_help); 36388bd4862fSCristian Dumitrescu return; 36398bd4862fSCristian Dumitrescu } 36408bd4862fSCristian Dumitrescu 36418bd4862fSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 364275129cebSChurchill Khangar (n_tokens == 2) && 364375129cebSChurchill Khangar (strcmp(tokens[1], "commit") == 0)) { 364475129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 364575129cebSChurchill Khangar cmd_pipeline_commit_help); 364675129cebSChurchill Khangar return; 364775129cebSChurchill Khangar } 364875129cebSChurchill Khangar 364975129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 365075129cebSChurchill Khangar (n_tokens == 2) && 365175129cebSChurchill Khangar (strcmp(tokens[1], "abort") == 0)) { 365275129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 365375129cebSChurchill Khangar cmd_pipeline_abort_help); 36545074e1d5SCristian Dumitrescu return; 36555074e1d5SCristian Dumitrescu } 36565074e1d5SCristian Dumitrescu 36575074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 365864cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) { 365964cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help); 366064cfcebdSCristian Dumitrescu return; 366164cfcebdSCristian Dumitrescu } 366264cfcebdSCristian Dumitrescu 366364cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 366464cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) { 366564cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help); 366664cfcebdSCristian Dumitrescu return; 366764cfcebdSCristian Dumitrescu } 366864cfcebdSCristian Dumitrescu 3669f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3670f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter") 3671f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile") 3672f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "add")) { 3673f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help); 3674f38913b7SCristian Dumitrescu return; 3675f38913b7SCristian Dumitrescu } 3676f38913b7SCristian Dumitrescu 3677f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3678f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter") 3679f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile") 3680f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "delete")) { 3681f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help); 3682f38913b7SCristian Dumitrescu return; 3683f38913b7SCristian Dumitrescu } 3684f38913b7SCristian Dumitrescu 3685f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3686f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 3687f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "reset")) { 3688f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help); 3689f38913b7SCristian Dumitrescu return; 3690f38913b7SCristian Dumitrescu } 3691f38913b7SCristian Dumitrescu 3692f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3693f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 3694f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "set")) { 3695f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help); 3696f38913b7SCristian Dumitrescu return; 3697f38913b7SCristian Dumitrescu } 3698f38913b7SCristian Dumitrescu 3699f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3700f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 3701f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "stats")) { 3702f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help); 3703f38913b7SCristian Dumitrescu return; 3704f38913b7SCristian Dumitrescu } 3705f38913b7SCristian Dumitrescu 3706*8ba342ceSCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3707*8ba342ceSCristian Dumitrescu (n_tokens == 2) && !strcmp(tokens[1], "rss")) { 3708*8ba342ceSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_rss_help); 3709*8ba342ceSCristian Dumitrescu return; 3710*8ba342ceSCristian Dumitrescu } 3711*8ba342ceSCristian Dumitrescu 371264cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 37137fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) { 37145074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help); 37155074e1d5SCristian Dumitrescu return; 37165074e1d5SCristian Dumitrescu } 37175074e1d5SCristian Dumitrescu 371817225455SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 371917225455SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "mirror") 372017225455SCristian Dumitrescu && !strcmp(tokens[2], "session")) { 372117225455SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_mirror_session_help); 372217225455SCristian Dumitrescu return; 372317225455SCristian Dumitrescu } 372417225455SCristian Dumitrescu 372541f5dfcbSCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 372641f5dfcbSCristian Dumitrescu (n_tokens == 2) && !strcmp(tokens[1], "enable")) { 372741f5dfcbSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_enable_help); 372841f5dfcbSCristian Dumitrescu return; 372941f5dfcbSCristian Dumitrescu } 373041f5dfcbSCristian Dumitrescu 373141f5dfcbSCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 373241f5dfcbSCristian Dumitrescu (n_tokens == 2) && !strcmp(tokens[1], "disable")) { 373341f5dfcbSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_disable_help); 373441f5dfcbSCristian Dumitrescu return; 373541f5dfcbSCristian Dumitrescu } 373641f5dfcbSCristian Dumitrescu 37373b0cc5fbSCristian Dumitrescu if (!strcmp(tokens[0], "ipsec") && 37383b0cc5fbSCristian Dumitrescu (n_tokens == 2) && !strcmp(tokens[1], "create")) { 37393b0cc5fbSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ipsec_create_help); 37403b0cc5fbSCristian Dumitrescu return; 37413b0cc5fbSCristian Dumitrescu } 37423b0cc5fbSCristian Dumitrescu 37433b0cc5fbSCristian Dumitrescu if (!strcmp(tokens[0], "ipsec") && 37443b0cc5fbSCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "sa") 37453b0cc5fbSCristian Dumitrescu && !strcmp(tokens[2], "add")) { 37463b0cc5fbSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ipsec_sa_add_help); 37473b0cc5fbSCristian Dumitrescu return; 37483b0cc5fbSCristian Dumitrescu } 37493b0cc5fbSCristian Dumitrescu 37503b0cc5fbSCristian Dumitrescu if (!strcmp(tokens[0], "ipsec") && 37513b0cc5fbSCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "sa") 37523b0cc5fbSCristian Dumitrescu && !strcmp(tokens[2], "delete")) { 37533b0cc5fbSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ipsec_sa_delete_help); 37543b0cc5fbSCristian Dumitrescu return; 37553b0cc5fbSCristian Dumitrescu } 37563b0cc5fbSCristian Dumitrescu 37576d99096cSCristian Dumitrescu if (!strcmp(tokens[0], "block") && 37586d99096cSCristian Dumitrescu (n_tokens == 2) && !strcmp(tokens[1], "enable")) { 37596d99096cSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_block_enable_help); 37606d99096cSCristian Dumitrescu return; 37616d99096cSCristian Dumitrescu } 37626d99096cSCristian Dumitrescu 37636d99096cSCristian Dumitrescu if (!strcmp(tokens[0], "block") && 37646d99096cSCristian Dumitrescu (n_tokens == 2) && !strcmp(tokens[1], "disable")) { 37656d99096cSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_block_disable_help); 37666d99096cSCristian Dumitrescu return; 37676d99096cSCristian Dumitrescu } 37686d99096cSCristian Dumitrescu 37695074e1d5SCristian Dumitrescu snprintf(out, out_size, "Invalid command\n"); 37705074e1d5SCristian Dumitrescu } 37715074e1d5SCristian Dumitrescu 37725074e1d5SCristian Dumitrescu void 37735074e1d5SCristian Dumitrescu cli_process(char *in, char *out, size_t out_size, void *obj) 37745074e1d5SCristian Dumitrescu { 37755074e1d5SCristian Dumitrescu char *tokens[CMD_MAX_TOKENS]; 37765074e1d5SCristian Dumitrescu uint32_t n_tokens = RTE_DIM(tokens); 37775074e1d5SCristian Dumitrescu int status; 37785074e1d5SCristian Dumitrescu 37795074e1d5SCristian Dumitrescu if (is_comment(in)) 37805074e1d5SCristian Dumitrescu return; 37815074e1d5SCristian Dumitrescu 37825074e1d5SCristian Dumitrescu status = parse_tokenize_string(in, tokens, &n_tokens); 37835074e1d5SCristian Dumitrescu if (status) { 37845074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_TOO_MANY, ""); 37855074e1d5SCristian Dumitrescu return; 37865074e1d5SCristian Dumitrescu } 37875074e1d5SCristian Dumitrescu 37885074e1d5SCristian Dumitrescu if (n_tokens == 0) 37895074e1d5SCristian Dumitrescu return; 37905074e1d5SCristian Dumitrescu 37915074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "help") == 0) { 37925074e1d5SCristian Dumitrescu cmd_help(tokens, n_tokens, out, out_size, obj); 37935074e1d5SCristian Dumitrescu return; 37945074e1d5SCristian Dumitrescu } 37955074e1d5SCristian Dumitrescu 37965074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 37975074e1d5SCristian Dumitrescu cmd_mempool(tokens, n_tokens, out, out_size, obj); 37985074e1d5SCristian Dumitrescu return; 37995074e1d5SCristian Dumitrescu } 38005074e1d5SCristian Dumitrescu 3801f31c80f8SCristian Dumitrescu if (strcmp(tokens[0], "ethdev") == 0) { 3802821848f5SCristian Dumitrescu if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) { 3803f31c80f8SCristian Dumitrescu cmd_ethdev_show(tokens, n_tokens, out, out_size, obj); 38045074e1d5SCristian Dumitrescu return; 38055074e1d5SCristian Dumitrescu } 38065074e1d5SCristian Dumitrescu 3807f31c80f8SCristian Dumitrescu cmd_ethdev(tokens, n_tokens, out, out_size, obj); 38085074e1d5SCristian Dumitrescu return; 38095074e1d5SCristian Dumitrescu } 38105074e1d5SCristian Dumitrescu 381177a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 381277a41301SCristian Dumitrescu cmd_ring(tokens, n_tokens, out, out_size, obj); 381377a41301SCristian Dumitrescu return; 381477a41301SCristian Dumitrescu } 381577a41301SCristian Dumitrescu 38161b41a527SCristian Dumitrescu if (!strcmp(tokens[0], "cryptodev")) { 38171b41a527SCristian Dumitrescu cmd_cryptodev(tokens, n_tokens, out, out_size, obj); 38181b41a527SCristian Dumitrescu return; 38191b41a527SCristian Dumitrescu } 38201b41a527SCristian Dumitrescu 38215074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "pipeline") == 0) { 38225074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 38239043f66aSCristian Dumitrescu (strcmp(tokens[1], "codegen") == 0)) { 38249043f66aSCristian Dumitrescu cmd_pipeline_codegen(tokens, n_tokens, out, out_size, 38259043f66aSCristian Dumitrescu obj); 38269043f66aSCristian Dumitrescu return; 38279043f66aSCristian Dumitrescu } 38289043f66aSCristian Dumitrescu 38299043f66aSCristian Dumitrescu if ((n_tokens >= 3) && 38306bc14d9fSCristian Dumitrescu (strcmp(tokens[1], "libbuild") == 0)) { 38316bc14d9fSCristian Dumitrescu cmd_pipeline_libbuild(tokens, n_tokens, out, out_size, 38326bc14d9fSCristian Dumitrescu obj); 38336bc14d9fSCristian Dumitrescu return; 38346bc14d9fSCristian Dumitrescu } 38356bc14d9fSCristian Dumitrescu 38366bc14d9fSCristian Dumitrescu if ((n_tokens >= 3) && 38375074e1d5SCristian Dumitrescu (strcmp(tokens[2], "build") == 0)) { 38385074e1d5SCristian Dumitrescu cmd_pipeline_build(tokens, n_tokens, out, out_size, 38395074e1d5SCristian Dumitrescu obj); 38405074e1d5SCristian Dumitrescu return; 38415074e1d5SCristian Dumitrescu } 38425074e1d5SCristian Dumitrescu 384375129cebSChurchill Khangar if ((n_tokens >= 5) && 384475129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 384575129cebSChurchill Khangar (strcmp(tokens[4], "add") == 0)) { 384675129cebSChurchill Khangar cmd_pipeline_table_add(tokens, n_tokens, out, 384775129cebSChurchill Khangar out_size, obj); 384875129cebSChurchill Khangar return; 384975129cebSChurchill Khangar } 385075129cebSChurchill Khangar 385175129cebSChurchill Khangar if ((n_tokens >= 5) && 385275129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 385375129cebSChurchill Khangar (strcmp(tokens[4], "delete") == 0)) { 385475129cebSChurchill Khangar cmd_pipeline_table_delete(tokens, n_tokens, out, 385575129cebSChurchill Khangar out_size, obj); 385675129cebSChurchill Khangar return; 385775129cebSChurchill Khangar } 385875129cebSChurchill Khangar 385975129cebSChurchill Khangar if ((n_tokens >= 5) && 386075129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 386175129cebSChurchill Khangar (strcmp(tokens[4], "default") == 0)) { 386275129cebSChurchill Khangar cmd_pipeline_table_default(tokens, n_tokens, out, 386375129cebSChurchill Khangar out_size, obj); 386475129cebSChurchill Khangar return; 386575129cebSChurchill Khangar } 386675129cebSChurchill Khangar 386775129cebSChurchill Khangar if ((n_tokens >= 5) && 386875129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 386975129cebSChurchill Khangar (strcmp(tokens[4], "show") == 0)) { 387075129cebSChurchill Khangar cmd_pipeline_table_show(tokens, n_tokens, out, 387175129cebSChurchill Khangar out_size, obj); 387275129cebSChurchill Khangar return; 387375129cebSChurchill Khangar } 387475129cebSChurchill Khangar 3875598fe0ddSCristian Dumitrescu if ((n_tokens >= 6) && 3876598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3877598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3878598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "add") == 0)) { 3879598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(tokens, n_tokens, out, 3880598fe0ddSCristian Dumitrescu out_size, obj); 3881598fe0ddSCristian Dumitrescu return; 3882598fe0ddSCristian Dumitrescu } 3883598fe0ddSCristian Dumitrescu 3884598fe0ddSCristian Dumitrescu if ((n_tokens >= 6) && 3885598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3886598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3887598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "delete") == 0)) { 3888598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(tokens, n_tokens, out, 3889598fe0ddSCristian Dumitrescu out_size, obj); 3890598fe0ddSCristian Dumitrescu return; 3891598fe0ddSCristian Dumitrescu } 3892598fe0ddSCristian Dumitrescu 3893598fe0ddSCristian Dumitrescu if ((n_tokens >= 7) && 3894598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3895598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3896598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "member") == 0) && 3897598fe0ddSCristian Dumitrescu (strcmp(tokens[6], "add") == 0)) { 3898598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(tokens, n_tokens, out, 3899598fe0ddSCristian Dumitrescu out_size, obj); 3900598fe0ddSCristian Dumitrescu return; 3901598fe0ddSCristian Dumitrescu } 3902598fe0ddSCristian Dumitrescu 3903598fe0ddSCristian Dumitrescu if ((n_tokens >= 7) && 3904598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3905598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3906598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "member") == 0) && 3907598fe0ddSCristian Dumitrescu (strcmp(tokens[6], "delete") == 0)) { 3908598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(tokens, n_tokens, out, 3909598fe0ddSCristian Dumitrescu out_size, obj); 3910598fe0ddSCristian Dumitrescu return; 3911598fe0ddSCristian Dumitrescu } 3912598fe0ddSCristian Dumitrescu 3913598fe0ddSCristian Dumitrescu if ((n_tokens >= 5) && 3914598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3915598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "show") == 0)) { 3916598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(tokens, n_tokens, out, 3917598fe0ddSCristian Dumitrescu out_size, obj); 3918598fe0ddSCristian Dumitrescu return; 3919598fe0ddSCristian Dumitrescu } 3920598fe0ddSCristian Dumitrescu 39218bd4862fSCristian Dumitrescu if ((n_tokens >= 5) && 39228bd4862fSCristian Dumitrescu (strcmp(tokens[2], "learner") == 0) && 39238bd4862fSCristian Dumitrescu (strcmp(tokens[4], "default") == 0)) { 39248bd4862fSCristian Dumitrescu cmd_pipeline_learner_default(tokens, n_tokens, out, 39258bd4862fSCristian Dumitrescu out_size, obj); 39268bd4862fSCristian Dumitrescu return; 39278bd4862fSCristian Dumitrescu } 39288bd4862fSCristian Dumitrescu 39295074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 393075129cebSChurchill Khangar (strcmp(tokens[2], "commit") == 0)) { 393175129cebSChurchill Khangar cmd_pipeline_commit(tokens, n_tokens, out, 393275129cebSChurchill Khangar out_size, obj); 393375129cebSChurchill Khangar return; 393475129cebSChurchill Khangar } 393575129cebSChurchill Khangar 393675129cebSChurchill Khangar if ((n_tokens >= 3) && 393775129cebSChurchill Khangar (strcmp(tokens[2], "abort") == 0)) { 393875129cebSChurchill Khangar cmd_pipeline_abort(tokens, n_tokens, out, 39395074e1d5SCristian Dumitrescu out_size, obj); 39405074e1d5SCristian Dumitrescu return; 39415074e1d5SCristian Dumitrescu } 39425074e1d5SCristian Dumitrescu 39435074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 394464cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regrd") == 0)) { 394564cfcebdSCristian Dumitrescu cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj); 394664cfcebdSCristian Dumitrescu return; 394764cfcebdSCristian Dumitrescu } 394864cfcebdSCristian Dumitrescu 394964cfcebdSCristian Dumitrescu if ((n_tokens >= 3) && 395064cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regwr") == 0)) { 395164cfcebdSCristian Dumitrescu cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj); 395264cfcebdSCristian Dumitrescu return; 395364cfcebdSCristian Dumitrescu } 395464cfcebdSCristian Dumitrescu 3955f38913b7SCristian Dumitrescu if ((n_tokens >= 6) && 3956f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3957f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) && 3958f38913b7SCristian Dumitrescu (strcmp(tokens[5], "add") == 0)) { 3959f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj); 3960f38913b7SCristian Dumitrescu return; 3961f38913b7SCristian Dumitrescu } 3962f38913b7SCristian Dumitrescu 3963f38913b7SCristian Dumitrescu if ((n_tokens >= 6) && 3964f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3965f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) && 3966f38913b7SCristian Dumitrescu (strcmp(tokens[5], "delete") == 0)) { 3967f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj); 3968f38913b7SCristian Dumitrescu return; 3969f38913b7SCristian Dumitrescu } 3970f38913b7SCristian Dumitrescu 397112eda78dSCristian Dumitrescu if (n_tokens >= 9 && !strcmp(tokens[2], "meter") && !strcmp(tokens[4], "reset")) { 3972f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj); 3973f38913b7SCristian Dumitrescu return; 3974f38913b7SCristian Dumitrescu } 3975f38913b7SCristian Dumitrescu 397612eda78dSCristian Dumitrescu if (n_tokens >= 9 && !strcmp(tokens[2], "meter") && !strcmp(tokens[4], "set")) { 3977f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj); 3978f38913b7SCristian Dumitrescu return; 3979f38913b7SCristian Dumitrescu } 3980f38913b7SCristian Dumitrescu 398112eda78dSCristian Dumitrescu if (n_tokens >= 9 && !strcmp(tokens[2], "meter") && !strcmp(tokens[4], "stats")) { 3982f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj); 3983f38913b7SCristian Dumitrescu return; 3984f38913b7SCristian Dumitrescu } 3985f38913b7SCristian Dumitrescu 3986*8ba342ceSCristian Dumitrescu if (n_tokens >= 3 && !strcmp(tokens[2], "rss")) { 3987*8ba342ceSCristian Dumitrescu cmd_pipeline_rss(tokens, n_tokens, out, out_size, obj); 3988*8ba342ceSCristian Dumitrescu return; 3989*8ba342ceSCristian Dumitrescu } 3990*8ba342ceSCristian Dumitrescu 399164cfcebdSCristian Dumitrescu if ((n_tokens >= 3) && 39925074e1d5SCristian Dumitrescu (strcmp(tokens[2], "stats") == 0)) { 39935074e1d5SCristian Dumitrescu cmd_pipeline_stats(tokens, n_tokens, out, out_size, 39945074e1d5SCristian Dumitrescu obj); 39955074e1d5SCristian Dumitrescu return; 39965074e1d5SCristian Dumitrescu } 399717225455SCristian Dumitrescu 399817225455SCristian Dumitrescu if ((n_tokens >= 4) && 399917225455SCristian Dumitrescu (strcmp(tokens[2], "mirror") == 0) && 400017225455SCristian Dumitrescu (strcmp(tokens[3], "session") == 0)) { 400117225455SCristian Dumitrescu cmd_pipeline_mirror_session(tokens, n_tokens, out, out_size, obj); 400217225455SCristian Dumitrescu return; 400317225455SCristian Dumitrescu } 400441f5dfcbSCristian Dumitrescu 400541f5dfcbSCristian Dumitrescu if (n_tokens >= 3 && !strcmp(tokens[2], "enable")) { 400641f5dfcbSCristian Dumitrescu cmd_pipeline_enable(tokens, n_tokens, out, out_size, obj); 400741f5dfcbSCristian Dumitrescu return; 400841f5dfcbSCristian Dumitrescu } 400941f5dfcbSCristian Dumitrescu 401041f5dfcbSCristian Dumitrescu if (n_tokens >= 3 && !strcmp(tokens[2], "disable")) { 401141f5dfcbSCristian Dumitrescu cmd_pipeline_disable(tokens, n_tokens, out, out_size, obj); 401241f5dfcbSCristian Dumitrescu return; 401341f5dfcbSCristian Dumitrescu } 40145074e1d5SCristian Dumitrescu } 40155074e1d5SCristian Dumitrescu 40163b0cc5fbSCristian Dumitrescu if (!strcmp(tokens[0], "ipsec")) { 40173b0cc5fbSCristian Dumitrescu if (n_tokens >= 3 && !strcmp(tokens[2], "create")) { 40183b0cc5fbSCristian Dumitrescu cmd_ipsec_create(tokens, n_tokens, out, out_size, obj); 40193b0cc5fbSCristian Dumitrescu return; 40203b0cc5fbSCristian Dumitrescu } 40213b0cc5fbSCristian Dumitrescu 40223b0cc5fbSCristian Dumitrescu if (n_tokens >= 4 && !strcmp(tokens[2], "sa") && !strcmp(tokens[3], "add")) { 40233b0cc5fbSCristian Dumitrescu cmd_ipsec_sa_add(tokens, n_tokens, out, out_size, obj); 40243b0cc5fbSCristian Dumitrescu return; 40253b0cc5fbSCristian Dumitrescu } 40263b0cc5fbSCristian Dumitrescu 40273b0cc5fbSCristian Dumitrescu if (n_tokens >= 4 && !strcmp(tokens[2], "sa") && !strcmp(tokens[3], "delete")) { 40283b0cc5fbSCristian Dumitrescu cmd_ipsec_sa_delete(tokens, n_tokens, out, out_size, obj); 40293b0cc5fbSCristian Dumitrescu return; 40303b0cc5fbSCristian Dumitrescu } 40313b0cc5fbSCristian Dumitrescu } 40323b0cc5fbSCristian Dumitrescu 40336d99096cSCristian Dumitrescu if (!strcmp(tokens[0], "block")) { 40346d99096cSCristian Dumitrescu if (n_tokens >= 6 && !strcmp(tokens[5], "enable")) { 40356d99096cSCristian Dumitrescu cmd_block_enable(tokens, n_tokens, out, out_size, obj); 40366d99096cSCristian Dumitrescu return; 40376d99096cSCristian Dumitrescu } 40386d99096cSCristian Dumitrescu 40396d99096cSCristian Dumitrescu if (n_tokens >= 6 && !strcmp(tokens[5], "disable")) { 40406d99096cSCristian Dumitrescu cmd_block_disable(tokens, n_tokens, out, out_size, obj); 40416d99096cSCristian Dumitrescu return; 40426d99096cSCristian Dumitrescu } 40436d99096cSCristian Dumitrescu } 40446d99096cSCristian Dumitrescu 40455074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]); 40465074e1d5SCristian Dumitrescu } 40475074e1d5SCristian Dumitrescu 40485074e1d5SCristian Dumitrescu int 40495074e1d5SCristian Dumitrescu cli_script_process(const char *file_name, 40505074e1d5SCristian Dumitrescu size_t msg_in_len_max, 40515074e1d5SCristian Dumitrescu size_t msg_out_len_max, 40525074e1d5SCristian Dumitrescu void *obj) 40535074e1d5SCristian Dumitrescu { 40545074e1d5SCristian Dumitrescu char *msg_in = NULL, *msg_out = NULL; 40555074e1d5SCristian Dumitrescu FILE *f = NULL; 40565074e1d5SCristian Dumitrescu 40575074e1d5SCristian Dumitrescu /* Check input arguments */ 40585074e1d5SCristian Dumitrescu if ((file_name == NULL) || 40595074e1d5SCristian Dumitrescu (strlen(file_name) == 0) || 40605074e1d5SCristian Dumitrescu (msg_in_len_max == 0) || 40615074e1d5SCristian Dumitrescu (msg_out_len_max == 0)) 40625074e1d5SCristian Dumitrescu return -EINVAL; 40635074e1d5SCristian Dumitrescu 40645074e1d5SCristian Dumitrescu msg_in = malloc(msg_in_len_max + 1); 40655074e1d5SCristian Dumitrescu msg_out = malloc(msg_out_len_max + 1); 40665074e1d5SCristian Dumitrescu if ((msg_in == NULL) || 40675074e1d5SCristian Dumitrescu (msg_out == NULL)) { 40685074e1d5SCristian Dumitrescu free(msg_out); 40695074e1d5SCristian Dumitrescu free(msg_in); 40705074e1d5SCristian Dumitrescu return -ENOMEM; 40715074e1d5SCristian Dumitrescu } 40725074e1d5SCristian Dumitrescu 40735074e1d5SCristian Dumitrescu /* Open input file */ 40745074e1d5SCristian Dumitrescu f = fopen(file_name, "r"); 40755074e1d5SCristian Dumitrescu if (f == NULL) { 40765074e1d5SCristian Dumitrescu free(msg_out); 40775074e1d5SCristian Dumitrescu free(msg_in); 40785074e1d5SCristian Dumitrescu return -EIO; 40795074e1d5SCristian Dumitrescu } 40805074e1d5SCristian Dumitrescu 40815074e1d5SCristian Dumitrescu /* Read file */ 40825074e1d5SCristian Dumitrescu for ( ; ; ) { 40835074e1d5SCristian Dumitrescu if (fgets(msg_in, msg_in_len_max + 1, f) == NULL) 40845074e1d5SCristian Dumitrescu break; 40855074e1d5SCristian Dumitrescu 40865074e1d5SCristian Dumitrescu printf("%s", msg_in); 40875074e1d5SCristian Dumitrescu msg_out[0] = 0; 40885074e1d5SCristian Dumitrescu 40895074e1d5SCristian Dumitrescu cli_process(msg_in, 40905074e1d5SCristian Dumitrescu msg_out, 40915074e1d5SCristian Dumitrescu msg_out_len_max, 40925074e1d5SCristian Dumitrescu obj); 40935074e1d5SCristian Dumitrescu 40945074e1d5SCristian Dumitrescu if (strlen(msg_out)) 40955074e1d5SCristian Dumitrescu printf("%s", msg_out); 40965074e1d5SCristian Dumitrescu } 40975074e1d5SCristian Dumitrescu 40985074e1d5SCristian Dumitrescu /* Close file */ 40995074e1d5SCristian Dumitrescu fclose(f); 41005074e1d5SCristian Dumitrescu free(msg_out); 41015074e1d5SCristian Dumitrescu free(msg_in); 41025074e1d5SCristian Dumitrescu return 0; 41035074e1d5SCristian Dumitrescu } 4104