Branch data Line data Source code
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 : 0 : signal_handler(int signum) 49 : : { 50 : 0 : if (signum == SIGINT || signum == SIGTERM) 51 : 0 : force_quit = true; 52 : 0 : } 53 : : 54 : : int 55 : 0 : main(int argc, char **argv) 56 : : { 57 : : uint32_t lcore; 58 : : uint32_t i; 59 : : int ret; 60 : : 61 : : /* Init EAL */ 62 : 0 : ret = rte_eal_init(argc, argv); 63 : 0 : if (ret < 0) 64 : : return -1; 65 : 0 : argc -= ret; 66 : 0 : argv += ret; 67 : : 68 : 0 : force_quit = false; 69 : 0 : signal(SIGINT, signal_handler); 70 : 0 : signal(SIGTERM, signal_handler); 71 : : 72 : : /* Parse application arguments (after the EAL ones) */ 73 : 0 : ret = app_parse_args(argc, argv); 74 : 0 : if (ret < 0) { 75 : 0 : app_print_usage(); 76 : 0 : return -1; 77 : : } 78 : : 79 : : /* Init */ 80 : 0 : app_init(); 81 : : 82 : : /* Launch per-lcore init on every lcore */ 83 : 0 : rte_eal_mp_remote_launch(app_lcore_main_loop, NULL, CALL_MAIN); 84 : 0 : RTE_LCORE_FOREACH_WORKER(lcore) { 85 : 0 : if (rte_eal_wait_lcore(lcore) < 0) 86 : : return -1; 87 : : } 88 : : 89 : : /* Close ports */ 90 : 0 : for (i = 0; i < app.n_ports; i++) { 91 : : uint16_t port; 92 : : 93 : 0 : port = app.ports[i]; 94 : 0 : printf("Closing port %d...", port); 95 : 0 : ret = rte_eth_dev_stop(port); 96 : 0 : if (ret != 0) 97 : : printf("rte_eth_dev_stop: err=%d, port=%u\n", 98 : : ret, port); 99 : 0 : rte_eth_dev_close(port); 100 : : printf("Done\n"); 101 : : } 102 : : 103 : : /* Clean up the EAL */ 104 : 0 : rte_eal_cleanup(); 105 : : 106 : 0 : return 0; 107 : : } 108 : : 109 : : int 110 : 0 : app_lcore_main_loop(__rte_unused void *arg) 111 : : { 112 : : unsigned lcore; 113 : : 114 : : lcore = rte_lcore_id(); 115 : : 116 : 0 : if (lcore == app.core_rx) { 117 : 0 : switch (app.pipeline_type) { 118 : 0 : case e_APP_PIPELINE_ACL: 119 : 0 : app_main_loop_rx(); 120 : 0 : return 0; 121 : : 122 : 0 : default: 123 : 0 : app_main_loop_rx_metadata(); 124 : 0 : return 0; 125 : : } 126 : : } 127 : : 128 : 0 : if (lcore == app.core_worker) { 129 : 0 : switch (app.pipeline_type) { 130 : 0 : case e_APP_PIPELINE_STUB: 131 : 0 : app_main_loop_worker_pipeline_stub(); 132 : 0 : return 0; 133 : : 134 : 0 : case e_APP_PIPELINE_HASH_KEY8_EXT: 135 : : case e_APP_PIPELINE_HASH_KEY8_LRU: 136 : : case e_APP_PIPELINE_HASH_KEY16_EXT: 137 : : case e_APP_PIPELINE_HASH_KEY16_LRU: 138 : : case e_APP_PIPELINE_HASH_KEY32_EXT: 139 : : case e_APP_PIPELINE_HASH_KEY32_LRU: 140 : : case e_APP_PIPELINE_HASH_SPEC_KEY8_EXT: 141 : : case e_APP_PIPELINE_HASH_SPEC_KEY8_LRU: 142 : : case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT: 143 : : case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU: 144 : : case e_APP_PIPELINE_HASH_SPEC_KEY32_EXT: 145 : : case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU: 146 : : /* cases for cuckoo hash table types */ 147 : : case e_APP_PIPELINE_HASH_CUCKOO_KEY8: 148 : : case e_APP_PIPELINE_HASH_CUCKOO_KEY16: 149 : : case e_APP_PIPELINE_HASH_CUCKOO_KEY32: 150 : : case e_APP_PIPELINE_HASH_CUCKOO_KEY48: 151 : : case e_APP_PIPELINE_HASH_CUCKOO_KEY64: 152 : : case e_APP_PIPELINE_HASH_CUCKOO_KEY80: 153 : : case e_APP_PIPELINE_HASH_CUCKOO_KEY96: 154 : : case e_APP_PIPELINE_HASH_CUCKOO_KEY112: 155 : : case e_APP_PIPELINE_HASH_CUCKOO_KEY128: 156 : 0 : app_main_loop_worker_pipeline_hash(); 157 : 0 : return 0; 158 : : 159 : 0 : case e_APP_PIPELINE_ACL: 160 : : #ifndef RTE_LIB_ACL 161 : : rte_exit(EXIT_FAILURE, "ACL not present in build\n"); 162 : : #else 163 : 0 : app_main_loop_worker_pipeline_acl(); 164 : 0 : return 0; 165 : : #endif 166 : : 167 : 0 : case e_APP_PIPELINE_LPM: 168 : 0 : app_main_loop_worker_pipeline_lpm(); 169 : 0 : return 0; 170 : : 171 : 0 : case e_APP_PIPELINE_LPM_IPV6: 172 : 0 : app_main_loop_worker_pipeline_lpm_ipv6(); 173 : 0 : return 0; 174 : : 175 : 0 : case e_APP_PIPELINE_NONE: 176 : : default: 177 : 0 : app_main_loop_worker(); 178 : 0 : return 0; 179 : : } 180 : : } 181 : : 182 : 0 : if (lcore == app.core_tx) { 183 : 0 : app_main_loop_tx(); 184 : 0 : return 0; 185 : : } 186 : : 187 : : return 0; 188 : : }