177a33467SCristian Dumitrescu /*- 277a33467SCristian Dumitrescu * BSD LICENSE 377a33467SCristian Dumitrescu * 477a33467SCristian Dumitrescu * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. 577a33467SCristian Dumitrescu * All rights reserved. 677a33467SCristian Dumitrescu * 777a33467SCristian Dumitrescu * Redistribution and use in source and binary forms, with or without 877a33467SCristian Dumitrescu * modification, are permitted provided that the following conditions 977a33467SCristian Dumitrescu * are met: 1077a33467SCristian Dumitrescu * 1177a33467SCristian Dumitrescu * * Redistributions of source code must retain the above copyright 1277a33467SCristian Dumitrescu * notice, this list of conditions and the following disclaimer. 1377a33467SCristian Dumitrescu * * Redistributions in binary form must reproduce the above copyright 1477a33467SCristian Dumitrescu * notice, this list of conditions and the following disclaimer in 1577a33467SCristian Dumitrescu * the documentation and/or other materials provided with the 1677a33467SCristian Dumitrescu * distribution. 1777a33467SCristian Dumitrescu * * Neither the name of Intel Corporation nor the names of its 1877a33467SCristian Dumitrescu * contributors may be used to endorse or promote products derived 1977a33467SCristian Dumitrescu * from this software without specific prior written permission. 2077a33467SCristian Dumitrescu * 2177a33467SCristian Dumitrescu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2277a33467SCristian Dumitrescu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2377a33467SCristian Dumitrescu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2477a33467SCristian Dumitrescu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2577a33467SCristian Dumitrescu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2677a33467SCristian Dumitrescu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2777a33467SCristian Dumitrescu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2877a33467SCristian Dumitrescu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2977a33467SCristian Dumitrescu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3077a33467SCristian Dumitrescu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3177a33467SCristian Dumitrescu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3277a33467SCristian Dumitrescu */ 3377a33467SCristian Dumitrescu 3477a33467SCristian Dumitrescu #include <stdio.h> 3577a33467SCristian Dumitrescu #include <stdlib.h> 3677a33467SCristian Dumitrescu #include <stdint.h> 3777a33467SCristian Dumitrescu #include <inttypes.h> 3877a33467SCristian Dumitrescu #include <sys/types.h> 3977a33467SCristian Dumitrescu #include <string.h> 4077a33467SCristian Dumitrescu #include <sys/queue.h> 4177a33467SCristian Dumitrescu #include <stdarg.h> 4277a33467SCristian Dumitrescu #include <errno.h> 4377a33467SCristian Dumitrescu #include <getopt.h> 4477a33467SCristian Dumitrescu #include <unistd.h> 4577a33467SCristian Dumitrescu 4677a33467SCristian Dumitrescu #include <rte_common.h> 4777a33467SCristian Dumitrescu #include <rte_byteorder.h> 4877a33467SCristian Dumitrescu #include <rte_log.h> 4977a33467SCristian Dumitrescu #include <rte_memory.h> 5077a33467SCristian Dumitrescu #include <rte_memcpy.h> 5177a33467SCristian Dumitrescu #include <rte_memzone.h> 5277a33467SCristian Dumitrescu #include <rte_tailq.h> 5377a33467SCristian Dumitrescu #include <rte_eal.h> 5477a33467SCristian Dumitrescu #include <rte_per_lcore.h> 5577a33467SCristian Dumitrescu #include <rte_launch.h> 5677a33467SCristian Dumitrescu #include <rte_atomic.h> 5777a33467SCristian Dumitrescu #include <rte_cycles.h> 5877a33467SCristian Dumitrescu #include <rte_prefetch.h> 5977a33467SCristian Dumitrescu #include <rte_lcore.h> 6077a33467SCristian Dumitrescu #include <rte_per_lcore.h> 6177a33467SCristian Dumitrescu #include <rte_branch_prediction.h> 6277a33467SCristian Dumitrescu #include <rte_interrupts.h> 6377a33467SCristian Dumitrescu #include <rte_pci.h> 6477a33467SCristian Dumitrescu #include <rte_random.h> 6577a33467SCristian Dumitrescu #include <rte_debug.h> 6677a33467SCristian Dumitrescu #include <rte_ether.h> 6777a33467SCristian Dumitrescu #include <rte_ethdev.h> 6877a33467SCristian Dumitrescu #include <rte_ring.h> 6977a33467SCristian Dumitrescu #include <rte_mempool.h> 7077a33467SCristian Dumitrescu #include <rte_mbuf.h> 7177a33467SCristian Dumitrescu #include <rte_ip.h> 7277a33467SCristian Dumitrescu #include <rte_tcp.h> 7377a33467SCristian Dumitrescu #include <rte_lpm.h> 7477a33467SCristian Dumitrescu #include <rte_lpm6.h> 7577a33467SCristian Dumitrescu 7677a33467SCristian Dumitrescu #include "main.h" 7777a33467SCristian Dumitrescu 7877a33467SCristian Dumitrescu int 79*98a16481SDavid Marchand main(int argc, char **argv) 8077a33467SCristian Dumitrescu { 8177a33467SCristian Dumitrescu int ret; 8277a33467SCristian Dumitrescu 8377a33467SCristian Dumitrescu /* Init EAL */ 8477a33467SCristian Dumitrescu ret = rte_eal_init(argc, argv); 8577a33467SCristian Dumitrescu if (ret < 0) 8677a33467SCristian Dumitrescu return -1; 8777a33467SCristian Dumitrescu argc -= ret; 8877a33467SCristian Dumitrescu argv += ret; 8977a33467SCristian Dumitrescu 9077a33467SCristian Dumitrescu /* Parse application arguments (after the EAL ones) */ 9177a33467SCristian Dumitrescu ret = app_parse_args(argc, argv); 9277a33467SCristian Dumitrescu if (ret < 0) { 9377a33467SCristian Dumitrescu app_print_usage(argv[0]); 9477a33467SCristian Dumitrescu return -1; 9577a33467SCristian Dumitrescu } 9677a33467SCristian Dumitrescu 9777a33467SCristian Dumitrescu /* Init */ 9877a33467SCristian Dumitrescu app_init(); 9977a33467SCristian Dumitrescu 10077a33467SCristian Dumitrescu /* Launch per-lcore init on every lcore */ 10177a33467SCristian Dumitrescu rte_eal_mp_remote_launch(app_lcore_main_loop, NULL, CALL_MASTER); 10277a33467SCristian Dumitrescu 10377a33467SCristian Dumitrescu return 0; 10477a33467SCristian Dumitrescu } 10577a33467SCristian Dumitrescu 10677a33467SCristian Dumitrescu int 10777a33467SCristian Dumitrescu app_lcore_main_loop(__attribute__((unused)) void *arg) 10877a33467SCristian Dumitrescu { 10977a33467SCristian Dumitrescu uint32_t core_id, i; 11077a33467SCristian Dumitrescu 11177a33467SCristian Dumitrescu core_id = rte_lcore_id(); 11277a33467SCristian Dumitrescu 11377a33467SCristian Dumitrescu for (i = 0; i < app.n_cores; i++) { 11477a33467SCristian Dumitrescu struct app_core_params *p = &app.cores[i]; 11577a33467SCristian Dumitrescu 11677a33467SCristian Dumitrescu if (p->core_id != core_id) 11777a33467SCristian Dumitrescu continue; 11877a33467SCristian Dumitrescu 11977a33467SCristian Dumitrescu switch (p->core_type) { 12077a33467SCristian Dumitrescu case APP_CORE_MASTER: 12177a33467SCristian Dumitrescu app_ping(); 12277a33467SCristian Dumitrescu app_main_loop_cmdline(); 12377a33467SCristian Dumitrescu return 0; 12477a33467SCristian Dumitrescu case APP_CORE_RX: 12577a33467SCristian Dumitrescu app_main_loop_pipeline_rx(); 12677a33467SCristian Dumitrescu /* app_main_loop_rx(); */ 12777a33467SCristian Dumitrescu return 0; 12877a33467SCristian Dumitrescu case APP_CORE_TX: 12977a33467SCristian Dumitrescu app_main_loop_pipeline_tx(); 13077a33467SCristian Dumitrescu /* app_main_loop_tx(); */ 13177a33467SCristian Dumitrescu return 0; 13277a33467SCristian Dumitrescu case APP_CORE_PT: 13377a33467SCristian Dumitrescu /* app_main_loop_pipeline_passthrough(); */ 13477a33467SCristian Dumitrescu app_main_loop_passthrough(); 13577a33467SCristian Dumitrescu return 0; 13677a33467SCristian Dumitrescu case APP_CORE_FC: 13777a33467SCristian Dumitrescu app_main_loop_pipeline_flow_classification(); 13877a33467SCristian Dumitrescu return 0; 13977a33467SCristian Dumitrescu case APP_CORE_FW: 14077a33467SCristian Dumitrescu case APP_CORE_RT: 14177a33467SCristian Dumitrescu app_main_loop_pipeline_routing(); 14277a33467SCristian Dumitrescu return 0; 14377a33467SCristian Dumitrescu 14477a33467SCristian Dumitrescu #ifdef RTE_LIBRTE_ACL 14577a33467SCristian Dumitrescu app_main_loop_pipeline_firewall(); 14677a33467SCristian Dumitrescu return 0; 14777a33467SCristian Dumitrescu #else 14877a33467SCristian Dumitrescu rte_exit(EXIT_FAILURE, "ACL not present in build\n"); 14977a33467SCristian Dumitrescu #endif 15077a33467SCristian Dumitrescu 15162814bc2SOlivier Matz #ifdef RTE_MBUF_REFCNT 15277a33467SCristian Dumitrescu case APP_CORE_IPV4_FRAG: 15377a33467SCristian Dumitrescu app_main_loop_pipeline_ipv4_frag(); 15477a33467SCristian Dumitrescu return 0; 15577a33467SCristian Dumitrescu case APP_CORE_IPV4_RAS: 15677a33467SCristian Dumitrescu app_main_loop_pipeline_ipv4_ras(); 15777a33467SCristian Dumitrescu return 0; 15877a33467SCristian Dumitrescu #else 15977a33467SCristian Dumitrescu rte_exit(EXIT_FAILURE, 16077a33467SCristian Dumitrescu "mbuf chaining not present in build\n"); 16177a33467SCristian Dumitrescu #endif 16277a33467SCristian Dumitrescu 16377a33467SCristian Dumitrescu default: 16477a33467SCristian Dumitrescu rte_panic("%s: Invalid core type for core %u\n", 16577a33467SCristian Dumitrescu __func__, i); 16677a33467SCristian Dumitrescu } 16777a33467SCristian Dumitrescu } 16877a33467SCristian Dumitrescu 16977a33467SCristian Dumitrescu rte_panic("%s: Algorithmic error\n", __func__); 17077a33467SCristian Dumitrescu return -1; 17177a33467SCristian Dumitrescu } 172