examples/pipeline: packet framework sample
[dpdk.git] / examples / ip_pipeline / main.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <stdint.h>
37 #include <inttypes.h>
38 #include <sys/types.h>
39 #include <string.h>
40 #include <sys/queue.h>
41 #include <stdarg.h>
42 #include <errno.h>
43 #include <getopt.h>
44 #include <unistd.h>
45
46 #include <rte_common.h>
47 #include <rte_byteorder.h>
48 #include <rte_log.h>
49 #include <rte_memory.h>
50 #include <rte_memcpy.h>
51 #include <rte_memzone.h>
52 #include <rte_tailq.h>
53 #include <rte_eal.h>
54 #include <rte_per_lcore.h>
55 #include <rte_launch.h>
56 #include <rte_atomic.h>
57 #include <rte_cycles.h>
58 #include <rte_prefetch.h>
59 #include <rte_lcore.h>
60 #include <rte_per_lcore.h>
61 #include <rte_branch_prediction.h>
62 #include <rte_interrupts.h>
63 #include <rte_pci.h>
64 #include <rte_random.h>
65 #include <rte_debug.h>
66 #include <rte_ether.h>
67 #include <rte_ethdev.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_mbuf.h>
71 #include <rte_ip.h>
72 #include <rte_tcp.h>
73 #include <rte_lpm.h>
74 #include <rte_lpm6.h>
75
76 #include "main.h"
77
78 int
79 MAIN(int argc, char **argv)
80 {
81         int ret;
82
83         /* Init EAL */
84         ret = rte_eal_init(argc, argv);
85         if (ret < 0)
86                 return -1;
87         argc -= ret;
88         argv += ret;
89
90         /* Parse application arguments (after the EAL ones) */
91         ret = app_parse_args(argc, argv);
92         if (ret < 0) {
93                 app_print_usage(argv[0]);
94                 return -1;
95         }
96
97         /* Init */
98         app_init();
99
100         /* Launch per-lcore init on every lcore */
101         rte_eal_mp_remote_launch(app_lcore_main_loop, NULL, CALL_MASTER);
102
103         return 0;
104 }
105
106 int
107 app_lcore_main_loop(__attribute__((unused)) void *arg)
108 {
109         uint32_t core_id, i;
110
111         core_id = rte_lcore_id();
112
113         for (i = 0; i < app.n_cores; i++) {
114                 struct app_core_params *p = &app.cores[i];
115
116                 if (p->core_id != core_id)
117                         continue;
118
119                 switch (p->core_type) {
120                 case APP_CORE_MASTER:
121                         app_ping();
122                         app_main_loop_cmdline();
123                         return 0;
124                 case APP_CORE_RX:
125                         app_main_loop_pipeline_rx();
126                         /* app_main_loop_rx(); */
127                         return 0;
128                 case APP_CORE_TX:
129                         app_main_loop_pipeline_tx();
130                         /* app_main_loop_tx(); */
131                         return 0;
132                 case APP_CORE_PT:
133                         /* app_main_loop_pipeline_passthrough(); */
134                         app_main_loop_passthrough();
135                         return 0;
136                 case APP_CORE_FC:
137                         app_main_loop_pipeline_flow_classification();
138                         return 0;
139                 case APP_CORE_FW:
140                 case APP_CORE_RT:
141                         app_main_loop_pipeline_routing();
142                         return 0;
143
144 #ifdef RTE_LIBRTE_ACL
145                         app_main_loop_pipeline_firewall();
146                         return 0;
147 #else
148                         rte_exit(EXIT_FAILURE, "ACL not present in build\n");
149 #endif
150
151 #ifdef RTE_MBUF_SCATTER_GATHER
152                 case APP_CORE_IPV4_FRAG:
153                         app_main_loop_pipeline_ipv4_frag();
154                         return 0;
155                 case APP_CORE_IPV4_RAS:
156                         app_main_loop_pipeline_ipv4_ras();
157                         return 0;
158 #else
159                         rte_exit(EXIT_FAILURE,
160                                 "mbuf chaining not present in build\n");
161 #endif
162
163                 default:
164                         rte_panic("%s: Invalid core type for core %u\n",
165                                 __func__, i);
166                 }
167         }
168
169         rte_panic("%s: Algorithmic error\n", __func__);
170         return -1;
171 }