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