Imported Upstream version 16.04
[deb_dpdk.git] / examples / ip_pipeline / pipeline / pipeline_routing_be.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 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 #ifndef __INCLUDE_PIPELINE_ROUTING_BE_H__
35 #define __INCLUDE_PIPELINE_ROUTING_BE_H__
36
37 #include <rte_ether.h>
38
39 #include "pipeline_common_be.h"
40
41 /*
42  * Pipeline argument parsing
43  */
44 #ifndef PIPELINE_ROUTING_N_ROUTES_DEFAULT
45 #define PIPELINE_ROUTING_N_ROUTES_DEFAULT                  4096
46 #endif
47
48 enum pipeline_routing_encap {
49         PIPELINE_ROUTING_ENCAP_ETHERNET = 0,
50         PIPELINE_ROUTING_ENCAP_ETHERNET_QINQ,
51         PIPELINE_ROUTING_ENCAP_ETHERNET_MPLS,
52 };
53
54 struct pipeline_routing_params {
55         /* routing */
56         uint32_t n_routes;
57
58         /* routing packet encapsulation */
59         enum pipeline_routing_encap encap;
60         uint32_t qinq_sched;
61         uint32_t mpls_color_mark;
62
63         /* arp */
64         uint32_t n_arp_entries;
65
66         /* packet buffer offsets */
67         uint32_t ip_hdr_offset;
68         uint32_t arp_key_offset;
69         uint32_t color_offset;
70
71         /* debug */
72         uint32_t dbg_ah_disable;
73 };
74
75 int
76 pipeline_routing_parse_args(struct pipeline_routing_params *p,
77         struct pipeline_params *params);
78
79 /*
80  * Route
81  */
82 enum pipeline_routing_route_key_type {
83         PIPELINE_ROUTING_ROUTE_IPV4,
84 };
85
86 struct pipeline_routing_route_key_ipv4 {
87         uint32_t ip;
88         uint32_t depth;
89 };
90
91 struct pipeline_routing_route_key {
92         enum pipeline_routing_route_key_type type;
93         union {
94                 struct pipeline_routing_route_key_ipv4 ipv4;
95         } key;
96 };
97
98 enum pipeline_routing_route_flags {
99         PIPELINE_ROUTING_ROUTE_LOCAL = 1 << 0, /* 0 = remote; 1 = local */
100         PIPELINE_ROUTING_ROUTE_ARP = 1 << 1, /* 0 = ARP OFF; 1 = ARP ON */
101         PIPELINE_ROUTING_ROUTE_QINQ = 1 << 2, /* 0 = QINQ OFF; 1 = QINQ ON */
102         PIPELINE_ROUTING_ROUTE_MPLS = 1 << 3, /* 0 = MPLS OFF; 1 = MPLS ON */
103 };
104
105 #define PIPELINE_ROUTING_MPLS_LABELS_MAX         4
106
107 struct pipeline_routing_route_data {
108         uint32_t flags;
109         uint32_t port_id; /* Output port ID */
110
111         union {
112                 /* Next hop IP (valid only when ARP is enabled) */
113                 uint32_t ip;
114
115                 /* Next hop MAC address (valid only when ARP disabled */
116                 struct ether_addr macaddr;
117         } ethernet;
118
119         union {
120                 struct {
121                         uint16_t svlan;
122                         uint16_t cvlan;
123                 } qinq;
124
125                 struct {
126                         uint32_t labels[PIPELINE_ROUTING_MPLS_LABELS_MAX];
127                         uint32_t n_labels;
128                 } mpls;
129         } l2;
130 };
131
132 /*
133  * ARP
134  */
135 enum pipeline_routing_arp_key_type {
136         PIPELINE_ROUTING_ARP_IPV4,
137 };
138
139 struct pipeline_routing_arp_key_ipv4 {
140         uint32_t port_id;
141         uint32_t ip;
142 };
143
144 struct pipeline_routing_arp_key {
145         enum pipeline_routing_arp_key_type type;
146         union {
147                 struct pipeline_routing_arp_key_ipv4 ipv4;
148         } key;
149 };
150
151 /*
152  * Messages
153  */
154 enum pipeline_routing_msg_req_type {
155         PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD,
156         PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL,
157         PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD_DEFAULT,
158         PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL_DEFAULT,
159         PIPELINE_ROUTING_MSG_REQ_ARP_ADD,
160         PIPELINE_ROUTING_MSG_REQ_ARP_DEL,
161         PIPELINE_ROUTING_MSG_REQ_ARP_ADD_DEFAULT,
162         PIPELINE_ROUTING_MSG_REQ_ARP_DEL_DEFAULT,
163         PIPELINE_ROUTING_MSG_REQS
164 };
165
166 /*
167  * MSG ROUTE ADD
168  */
169 struct pipeline_routing_route_add_msg_req {
170         enum pipeline_msg_req_type type;
171         enum pipeline_routing_msg_req_type subtype;
172
173         /* key */
174         struct pipeline_routing_route_key key;
175
176         /* data */
177         struct pipeline_routing_route_data data;
178 };
179
180 struct pipeline_routing_route_add_msg_rsp {
181         int status;
182         int key_found;
183         void *entry_ptr;
184 };
185
186 /*
187  * MSG ROUTE DELETE
188  */
189 struct pipeline_routing_route_delete_msg_req {
190         enum pipeline_msg_req_type type;
191         enum pipeline_routing_msg_req_type subtype;
192
193         /* key */
194         struct pipeline_routing_route_key key;
195 };
196
197 struct pipeline_routing_route_delete_msg_rsp {
198         int status;
199         int key_found;
200 };
201
202 /*
203  * MSG ROUTE ADD DEFAULT
204  */
205 struct pipeline_routing_route_add_default_msg_req {
206         enum pipeline_msg_req_type type;
207         enum pipeline_routing_msg_req_type subtype;
208
209         /* data */
210         uint32_t port_id;
211 };
212
213 struct pipeline_routing_route_add_default_msg_rsp {
214         int status;
215         void *entry_ptr;
216 };
217
218 /*
219  * MSG ROUTE DELETE DEFAULT
220  */
221 struct pipeline_routing_route_delete_default_msg_req {
222         enum pipeline_msg_req_type type;
223         enum pipeline_routing_msg_req_type subtype;
224 };
225
226 struct pipeline_routing_route_delete_default_msg_rsp {
227         int status;
228 };
229
230 /*
231  * MSG ARP ADD
232  */
233 struct pipeline_routing_arp_add_msg_req {
234         enum pipeline_msg_req_type type;
235         enum pipeline_routing_msg_req_type subtype;
236
237         /* key */
238         struct pipeline_routing_arp_key key;
239
240         /* data */
241         struct ether_addr macaddr;
242 };
243
244 struct pipeline_routing_arp_add_msg_rsp {
245         int status;
246         int key_found;
247         void *entry_ptr;
248 };
249
250 /*
251  * MSG ARP DELETE
252  */
253 struct pipeline_routing_arp_delete_msg_req {
254         enum pipeline_msg_req_type type;
255         enum pipeline_routing_msg_req_type subtype;
256
257         /* key */
258         struct pipeline_routing_arp_key key;
259 };
260
261 struct pipeline_routing_arp_delete_msg_rsp {
262         int status;
263         int key_found;
264 };
265
266 /*
267  * MSG ARP ADD DEFAULT
268  */
269 struct pipeline_routing_arp_add_default_msg_req {
270         enum pipeline_msg_req_type type;
271         enum pipeline_routing_msg_req_type subtype;
272
273         /* data */
274         uint32_t port_id;
275 };
276
277 struct pipeline_routing_arp_add_default_msg_rsp {
278         int status;
279         void *entry_ptr;
280 };
281
282 /*
283  * MSG ARP DELETE DEFAULT
284  */
285 struct pipeline_routing_arp_delete_default_msg_req {
286         enum pipeline_msg_req_type type;
287         enum pipeline_routing_msg_req_type subtype;
288 };
289
290 struct pipeline_routing_arp_delete_default_msg_rsp {
291         int status;
292 };
293
294 extern struct pipeline_be_ops pipeline_routing_be_ops;
295
296 #endif