1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2016 Intel Corporation 3 */ 4 5 #include <stdio.h> 6 #include <stdlib.h> 7 #include <stdint.h> 8 #include <inttypes.h> 9 #include <sys/types.h> 10 #include <string.h> 11 #include <sys/queue.h> 12 #include <stdarg.h> 13 #include <signal.h> 14 #include <errno.h> 15 #include <getopt.h> 16 #include <unistd.h> 17 18 #include <rte_common.h> 19 #include <rte_byteorder.h> 20 #include <rte_log.h> 21 #include <rte_memory.h> 22 #include <rte_memcpy.h> 23 #include <rte_eal.h> 24 #include <rte_per_lcore.h> 25 #include <rte_launch.h> 26 #include <rte_cycles.h> 27 #include <rte_prefetch.h> 28 #include <rte_lcore.h> 29 #include <rte_branch_prediction.h> 30 #include <rte_interrupts.h> 31 #include <rte_pci.h> 32 #include <rte_random.h> 33 #include <rte_debug.h> 34 #include <rte_ether.h> 35 #include <rte_ethdev.h> 36 #include <rte_mempool.h> 37 #include <rte_mbuf.h> 38 #include <rte_ip.h> 39 #include <rte_tcp.h> 40 #include <rte_lpm.h> 41 #include <rte_lpm6.h> 42 43 #include "main.h" 44 45 bool force_quit; 46 47 static void 48 signal_handler(int signum) 49 { 50 if (signum == SIGINT || signum == SIGTERM) 51 force_quit = true; 52 } 53 54 int 55 main(int argc, char **argv) 56 { 57 uint32_t lcore; 58 uint32_t i; 59 int ret; 60 61 /* Init EAL */ 62 ret = rte_eal_init(argc, argv); 63 if (ret < 0) 64 return -1; 65 argc -= ret; 66 argv += ret; 67 68 force_quit = false; 69 signal(SIGINT, signal_handler); 70 signal(SIGTERM, signal_handler); 71 72 /* Parse application arguments (after the EAL ones) */ 73 ret = app_parse_args(argc, argv); 74 if (ret < 0) { 75 app_print_usage(); 76 return -1; 77 } 78 79 /* Init */ 80 app_init(); 81 82 /* Launch per-lcore init on every lcore */ 83 rte_eal_mp_remote_launch(app_lcore_main_loop, NULL, CALL_MAIN); 84 RTE_LCORE_FOREACH_WORKER(lcore) { 85 if (rte_eal_wait_lcore(lcore) < 0) 86 return -1; 87 } 88 89 /* Close ports */ 90 for (i = 0; i < app.n_ports; i++) { 91 uint16_t port; 92 int ret; 93 94 port = app.ports[i]; 95 printf("Closing port %d...", port); 96 ret = rte_eth_dev_stop(port); 97 if (ret != 0) 98 printf("rte_eth_dev_stop: err=%d, port=%u\n", 99 ret, port); 100 rte_eth_dev_close(port); 101 printf("Done\n"); 102 } 103 104 /* Clean up the EAL */ 105 rte_eal_cleanup(); 106 107 return 0; 108 } 109 110 int 111 app_lcore_main_loop(__rte_unused void *arg) 112 { 113 unsigned lcore; 114 115 lcore = rte_lcore_id(); 116 117 if (lcore == app.core_rx) { 118 switch (app.pipeline_type) { 119 case e_APP_PIPELINE_ACL: 120 app_main_loop_rx(); 121 return 0; 122 123 default: 124 app_main_loop_rx_metadata(); 125 return 0; 126 } 127 } 128 129 if (lcore == app.core_worker) { 130 switch (app.pipeline_type) { 131 case e_APP_PIPELINE_STUB: 132 app_main_loop_worker_pipeline_stub(); 133 return 0; 134 135 case e_APP_PIPELINE_HASH_KEY8_EXT: 136 case e_APP_PIPELINE_HASH_KEY8_LRU: 137 case e_APP_PIPELINE_HASH_KEY16_EXT: 138 case e_APP_PIPELINE_HASH_KEY16_LRU: 139 case e_APP_PIPELINE_HASH_KEY32_EXT: 140 case e_APP_PIPELINE_HASH_KEY32_LRU: 141 case e_APP_PIPELINE_HASH_SPEC_KEY8_EXT: 142 case e_APP_PIPELINE_HASH_SPEC_KEY8_LRU: 143 case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT: 144 case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU: 145 case e_APP_PIPELINE_HASH_SPEC_KEY32_EXT: 146 case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU: 147 /* cases for cuckoo hash table types */ 148 case e_APP_PIPELINE_HASH_CUCKOO_KEY8: 149 case e_APP_PIPELINE_HASH_CUCKOO_KEY16: 150 case e_APP_PIPELINE_HASH_CUCKOO_KEY32: 151 case e_APP_PIPELINE_HASH_CUCKOO_KEY48: 152 case e_APP_PIPELINE_HASH_CUCKOO_KEY64: 153 case e_APP_PIPELINE_HASH_CUCKOO_KEY80: 154 case e_APP_PIPELINE_HASH_CUCKOO_KEY96: 155 case e_APP_PIPELINE_HASH_CUCKOO_KEY112: 156 case e_APP_PIPELINE_HASH_CUCKOO_KEY128: 157 app_main_loop_worker_pipeline_hash(); 158 return 0; 159 160 case e_APP_PIPELINE_ACL: 161 #ifndef RTE_LIB_ACL 162 rte_exit(EXIT_FAILURE, "ACL not present in build\n"); 163 #else 164 app_main_loop_worker_pipeline_acl(); 165 return 0; 166 #endif 167 168 case e_APP_PIPELINE_LPM: 169 app_main_loop_worker_pipeline_lpm(); 170 return 0; 171 172 case e_APP_PIPELINE_LPM_IPV6: 173 app_main_loop_worker_pipeline_lpm_ipv6(); 174 return 0; 175 176 case e_APP_PIPELINE_NONE: 177 default: 178 app_main_loop_worker(); 179 return 0; 180 } 181 } 182 183 if (lcore == app.core_tx) { 184 app_main_loop_tx(); 185 return 0; 186 } 187 188 return 0; 189 } 190