13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 24bbf8e30SJasvinder Singh * Copyright(c) 2010-2018 Intel Corporation 377a33467SCristian Dumitrescu */ 477a33467SCristian Dumitrescu 5fbc74e66SJasvinder Singh #include <stdio.h> 6*72b452c5SDmitry Kozlyuk #include <stdlib.h> 7fbc74e66SJasvinder Singh #include <string.h> 8fbc74e66SJasvinder Singh #include <fcntl.h> 9fbc74e66SJasvinder Singh #include <unistd.h> 10fbc74e66SJasvinder Singh #include <getopt.h> 1177a33467SCristian Dumitrescu 12a8bd581dSJasvinder Singh #include <rte_launch.h> 13fbc74e66SJasvinder Singh #include <rte_eal.h> 1477a33467SCristian Dumitrescu 154bbf8e30SJasvinder Singh #include "cli.h" 164bbf8e30SJasvinder Singh #include "conn.h" 179a408cc8SJasvinder Singh #include "kni.h" 18bd9b67a1SFan Zhang #include "cryptodev.h" 19133c2c65SJasvinder Singh #include "link.h" 206bfe74f8SJasvinder Singh #include "mempool.h" 21d75c371eSJasvinder Singh #include "pipeline.h" 228245472cSJasvinder Singh #include "swq.h" 232f74ae28SJasvinder Singh #include "tap.h" 24c0b668e0SJasvinder Singh #include "thread.h" 2525961ff3SJasvinder Singh #include "tmgr.h" 264bbf8e30SJasvinder Singh 274bbf8e30SJasvinder Singh static const char usage[] = 284bbf8e30SJasvinder Singh "%s EAL_ARGS -- [-h HOST] [-p PORT] [-s SCRIPT]\n"; 294bbf8e30SJasvinder Singh 304bbf8e30SJasvinder Singh static const char welcome[] = 314bbf8e30SJasvinder Singh "\n" 324bbf8e30SJasvinder Singh "Welcome to IP Pipeline!\n" 334bbf8e30SJasvinder Singh "\n"; 344bbf8e30SJasvinder Singh 354bbf8e30SJasvinder Singh static const char prompt[] = "pipeline> "; 364bbf8e30SJasvinder Singh 374bbf8e30SJasvinder Singh static struct app_params { 384bbf8e30SJasvinder Singh struct conn_params conn; 394bbf8e30SJasvinder Singh char *script_name; 404bbf8e30SJasvinder Singh } app = { 414bbf8e30SJasvinder Singh .conn = { 424bbf8e30SJasvinder Singh .welcome = welcome, 434bbf8e30SJasvinder Singh .prompt = prompt, 444bbf8e30SJasvinder Singh .addr = "0.0.0.0", 454bbf8e30SJasvinder Singh .port = 8086, 464bbf8e30SJasvinder Singh .buf_size = 1024 * 1024, 474bbf8e30SJasvinder Singh .msg_in_len_max = 1024, 484bbf8e30SJasvinder Singh .msg_out_len_max = 1024 * 1024, 494bbf8e30SJasvinder Singh .msg_handle = cli_process, 504bbf8e30SJasvinder Singh }, 514bbf8e30SJasvinder Singh .script_name = NULL, 524bbf8e30SJasvinder Singh }; 534bbf8e30SJasvinder Singh 544bbf8e30SJasvinder Singh static int 554bbf8e30SJasvinder Singh parse_args(int argc, char **argv) 564bbf8e30SJasvinder Singh { 574bbf8e30SJasvinder Singh char *app_name = argv[0]; 584bbf8e30SJasvinder Singh struct option lgopts[] = { 594bbf8e30SJasvinder Singh { NULL, 0, 0, 0 } 604bbf8e30SJasvinder Singh }; 614bbf8e30SJasvinder Singh int opt, option_index; 624bbf8e30SJasvinder Singh int h_present, p_present, s_present, n_args, i; 634bbf8e30SJasvinder Singh 644bbf8e30SJasvinder Singh /* Skip EAL input args */ 654bbf8e30SJasvinder Singh n_args = argc; 664bbf8e30SJasvinder Singh for (i = 0; i < n_args; i++) 674bbf8e30SJasvinder Singh if (strcmp(argv[i], "--") == 0) { 684bbf8e30SJasvinder Singh argc -= i; 694bbf8e30SJasvinder Singh argv += i; 704bbf8e30SJasvinder Singh break; 714bbf8e30SJasvinder Singh } 724bbf8e30SJasvinder Singh 734bbf8e30SJasvinder Singh if (i == n_args) 744bbf8e30SJasvinder Singh return 0; 754bbf8e30SJasvinder Singh 764bbf8e30SJasvinder Singh /* Parse args */ 774bbf8e30SJasvinder Singh h_present = 0; 784bbf8e30SJasvinder Singh p_present = 0; 794bbf8e30SJasvinder Singh s_present = 0; 804bbf8e30SJasvinder Singh 814bbf8e30SJasvinder Singh while ((opt = getopt_long(argc, argv, "h:p:s:", lgopts, &option_index)) 824bbf8e30SJasvinder Singh != EOF) 834bbf8e30SJasvinder Singh switch (opt) { 844bbf8e30SJasvinder Singh case 'h': 854bbf8e30SJasvinder Singh if (h_present) { 864bbf8e30SJasvinder Singh printf("Error: Multiple -h arguments\n"); 874bbf8e30SJasvinder Singh return -1; 884bbf8e30SJasvinder Singh } 894bbf8e30SJasvinder Singh h_present = 1; 904bbf8e30SJasvinder Singh 914bbf8e30SJasvinder Singh if (!strlen(optarg)) { 924bbf8e30SJasvinder Singh printf("Error: Argument for -h not provided\n"); 934bbf8e30SJasvinder Singh return -1; 944bbf8e30SJasvinder Singh } 954bbf8e30SJasvinder Singh 964bbf8e30SJasvinder Singh app.conn.addr = strdup(optarg); 974bbf8e30SJasvinder Singh if (app.conn.addr == NULL) { 984bbf8e30SJasvinder Singh printf("Error: Not enough memory\n"); 994bbf8e30SJasvinder Singh return -1; 1004bbf8e30SJasvinder Singh } 1014bbf8e30SJasvinder Singh break; 1024bbf8e30SJasvinder Singh 1034bbf8e30SJasvinder Singh case 'p': 1044bbf8e30SJasvinder Singh if (p_present) { 1054bbf8e30SJasvinder Singh printf("Error: Multiple -p arguments\n"); 1064bbf8e30SJasvinder Singh return -1; 1074bbf8e30SJasvinder Singh } 1084bbf8e30SJasvinder Singh p_present = 1; 1094bbf8e30SJasvinder Singh 1104bbf8e30SJasvinder Singh if (!strlen(optarg)) { 1114bbf8e30SJasvinder Singh printf("Error: Argument for -p not provided\n"); 1124bbf8e30SJasvinder Singh return -1; 1134bbf8e30SJasvinder Singh } 1144bbf8e30SJasvinder Singh 1154bbf8e30SJasvinder Singh app.conn.port = (uint16_t) atoi(optarg); 1164bbf8e30SJasvinder Singh break; 1174bbf8e30SJasvinder Singh 1184bbf8e30SJasvinder Singh case 's': 1194bbf8e30SJasvinder Singh if (s_present) { 1204bbf8e30SJasvinder Singh printf("Error: Multiple -s arguments\n"); 1214bbf8e30SJasvinder Singh return -1; 1224bbf8e30SJasvinder Singh } 1234bbf8e30SJasvinder Singh s_present = 1; 1244bbf8e30SJasvinder Singh 1254bbf8e30SJasvinder Singh if (!strlen(optarg)) { 1264bbf8e30SJasvinder Singh printf("Error: Argument for -s not provided\n"); 1274bbf8e30SJasvinder Singh return -1; 1284bbf8e30SJasvinder Singh } 1294bbf8e30SJasvinder Singh 1304bbf8e30SJasvinder Singh app.script_name = strdup(optarg); 1314bbf8e30SJasvinder Singh if (app.script_name == NULL) { 1324bbf8e30SJasvinder Singh printf("Error: Not enough memory\n"); 1334bbf8e30SJasvinder Singh return -1; 1344bbf8e30SJasvinder Singh } 1354bbf8e30SJasvinder Singh break; 1364bbf8e30SJasvinder Singh 1374bbf8e30SJasvinder Singh default: 1384bbf8e30SJasvinder Singh printf(usage, app_name); 1394bbf8e30SJasvinder Singh return -1; 1404bbf8e30SJasvinder Singh } 1414bbf8e30SJasvinder Singh 1424bbf8e30SJasvinder Singh optind = 1; /* reset getopt lib */ 1434bbf8e30SJasvinder Singh 1444bbf8e30SJasvinder Singh return 0; 1454bbf8e30SJasvinder Singh } 1464bbf8e30SJasvinder Singh 14777a33467SCristian Dumitrescu int 14898a16481SDavid Marchand main(int argc, char **argv) 14977a33467SCristian Dumitrescu { 1504bbf8e30SJasvinder Singh struct conn *conn; 151fbc74e66SJasvinder Singh int status; 15277a33467SCristian Dumitrescu 1534bbf8e30SJasvinder Singh /* Parse application arguments */ 1544bbf8e30SJasvinder Singh status = parse_args(argc, argv); 1554bbf8e30SJasvinder Singh if (status < 0) 1564bbf8e30SJasvinder Singh return status; 1574bbf8e30SJasvinder Singh 158fbc74e66SJasvinder Singh /* EAL */ 159fbc74e66SJasvinder Singh status = rte_eal_init(argc, argv); 160fbc74e66SJasvinder Singh if (status < 0) { 161fbc74e66SJasvinder Singh printf("Error: EAL initialization failed (%d)\n", status); 162fbc74e66SJasvinder Singh return status; 163fbc74e66SJasvinder Singh }; 16477a33467SCristian Dumitrescu 1654bbf8e30SJasvinder Singh /* Connectivity */ 1664bbf8e30SJasvinder Singh conn = conn_init(&app.conn); 1674bbf8e30SJasvinder Singh if (conn == NULL) { 1684bbf8e30SJasvinder Singh printf("Error: Connectivity initialization failed (%d)\n", 1694bbf8e30SJasvinder Singh status); 1704bbf8e30SJasvinder Singh return status; 1714bbf8e30SJasvinder Singh }; 1724bbf8e30SJasvinder Singh 1736bfe74f8SJasvinder Singh /* Mempool */ 1746bfe74f8SJasvinder Singh status = mempool_init(); 1756bfe74f8SJasvinder Singh if (status) { 1766bfe74f8SJasvinder Singh printf("Error: Mempool initialization failed (%d)\n", status); 1776bfe74f8SJasvinder Singh return status; 1786bfe74f8SJasvinder Singh } 1796bfe74f8SJasvinder Singh 180133c2c65SJasvinder Singh /* Link */ 181133c2c65SJasvinder Singh status = link_init(); 182133c2c65SJasvinder Singh if (status) { 183133c2c65SJasvinder Singh printf("Error: Link initialization failed (%d)\n", status); 184133c2c65SJasvinder Singh return status; 185133c2c65SJasvinder Singh } 186133c2c65SJasvinder Singh 1878245472cSJasvinder Singh /* SWQ */ 1888245472cSJasvinder Singh status = swq_init(); 1898245472cSJasvinder Singh if (status) { 1908245472cSJasvinder Singh printf("Error: SWQ initialization failed (%d)\n", status); 1918245472cSJasvinder Singh return status; 1928245472cSJasvinder Singh } 1938245472cSJasvinder Singh 19425961ff3SJasvinder Singh /* Traffic Manager */ 19525961ff3SJasvinder Singh status = tmgr_init(); 19625961ff3SJasvinder Singh if (status) { 19725961ff3SJasvinder Singh printf("Error: TMGR initialization failed (%d)\n", status); 19825961ff3SJasvinder Singh return status; 19925961ff3SJasvinder Singh } 20025961ff3SJasvinder Singh 2012f74ae28SJasvinder Singh /* TAP */ 2022f74ae28SJasvinder Singh status = tap_init(); 2032f74ae28SJasvinder Singh if (status) { 2042f74ae28SJasvinder Singh printf("Error: TAP initialization failed (%d)\n", status); 2052f74ae28SJasvinder Singh return status; 2062f74ae28SJasvinder Singh } 2072f74ae28SJasvinder Singh 2089a408cc8SJasvinder Singh /* KNI */ 2099a408cc8SJasvinder Singh status = kni_init(); 2109a408cc8SJasvinder Singh if (status) { 2119a408cc8SJasvinder Singh printf("Error: KNI initialization failed (%d)\n", status); 2129a408cc8SJasvinder Singh return status; 2139a408cc8SJasvinder Singh } 2149a408cc8SJasvinder Singh 215bd9b67a1SFan Zhang /* Sym Crypto */ 216bd9b67a1SFan Zhang status = cryptodev_init(); 217bd9b67a1SFan Zhang if (status) { 218bd9b67a1SFan Zhang printf("Error: Cryptodev initialization failed (%d)\n", 219bd9b67a1SFan Zhang status); 220bd9b67a1SFan Zhang return status; 221bd9b67a1SFan Zhang } 222bd9b67a1SFan Zhang 22371937434SJasvinder Singh /* Action */ 22471937434SJasvinder Singh status = port_in_action_profile_init(); 22571937434SJasvinder Singh if (status) { 22671937434SJasvinder Singh printf("Error: Input port action profile initialization failed (%d)\n", status); 22771937434SJasvinder Singh return status; 22871937434SJasvinder Singh } 22971937434SJasvinder Singh 23071937434SJasvinder Singh status = table_action_profile_init(); 23171937434SJasvinder Singh if (status) { 23271937434SJasvinder Singh printf("Error: Action profile initialization failed (%d)\n", 23371937434SJasvinder Singh status); 23471937434SJasvinder Singh return status; 23571937434SJasvinder Singh } 23671937434SJasvinder Singh 237d75c371eSJasvinder Singh /* Pipeline */ 238d75c371eSJasvinder Singh status = pipeline_init(); 239d75c371eSJasvinder Singh if (status) { 240d75c371eSJasvinder Singh printf("Error: Pipeline initialization failed (%d)\n", status); 241d75c371eSJasvinder Singh return status; 242d75c371eSJasvinder Singh } 243d75c371eSJasvinder Singh 244c0b668e0SJasvinder Singh /* Thread */ 245c0b668e0SJasvinder Singh status = thread_init(); 246c0b668e0SJasvinder Singh if (status) { 247c0b668e0SJasvinder Singh printf("Error: Thread initialization failed (%d)\n", status); 248c0b668e0SJasvinder Singh return status; 249c0b668e0SJasvinder Singh } 250c0b668e0SJasvinder Singh 251a8bd581dSJasvinder Singh rte_eal_mp_remote_launch( 252a8bd581dSJasvinder Singh thread_main, 253a8bd581dSJasvinder Singh NULL, 254cb056611SStephen Hemminger SKIP_MAIN); 255a8bd581dSJasvinder Singh 2564bbf8e30SJasvinder Singh /* Script */ 2574bbf8e30SJasvinder Singh if (app.script_name) 2584bbf8e30SJasvinder Singh cli_script_process(app.script_name, 2594bbf8e30SJasvinder Singh app.conn.msg_in_len_max, 2604bbf8e30SJasvinder Singh app.conn.msg_out_len_max); 2614bbf8e30SJasvinder Singh 2624bbf8e30SJasvinder Singh /* Dispatch loop */ 2634bbf8e30SJasvinder Singh for ( ; ; ) { 2644bbf8e30SJasvinder Singh conn_poll_for_conn(conn); 2654bbf8e30SJasvinder Singh 2664bbf8e30SJasvinder Singh conn_poll_for_msg(conn); 2679a408cc8SJasvinder Singh 2689a408cc8SJasvinder Singh kni_handle_request(); 2694bbf8e30SJasvinder Singh } 27077a33467SCristian Dumitrescu } 271