FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
dpo.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @brief
17  * A Data-Path Object is an object that represents actions that are
18  * applied to packets are they are switched through VPP's data-path.
19  *
20  * The DPO can be considered to be like is a base class that is specialised
21  * by other objects to provide concreate actions
22  *
23  * The VLIB graph nodes are graph of DPO types, the DPO graph is a graph of
24  * instances.
25  */
26 
27 #ifndef __DPO_H__
28 #define __DPO_H__
29 
30 #include <vnet/vnet.h>
31 
32 /**
33  * @brief An index for adjacencies.
34  * Alas 'C' is not typesafe enough to b0rk when a u32 is used instead of
35  * an index_t. However, for us humans, we can glean much more intent
36  * from the declaration
37  * foo barindex_t t);
38  * than we can from
39  * foo bar(u32 t);
40  */
41 typedef u32 index_t;
42 
43 /**
44  * @brief Invalid index - used when no index is known
45  * blazoned capitals INVALID speak volumes where ~0 does not.
46  */
47 #define INDEX_INVALID ((index_t)(~0))
48 
49 /**
50  * @brief Data path protocol.
51  * Actions performed on packets in the data-plane can be described and represented
52  * by protocol independent objects, i.e. ADJACENCY, but the spceifics actions
53  * required during ADJACENCY processing can be protocol dependent. For example,
54  * the adjacency rewrite node performs a ip4 checksum calculation, ip6 and MPLS
55  * do not, all 3 perform a TTL decrement. The VLIB graph nodes are thus protocol
56  * dependent, and thus each graph edge/arc is too.
57  * When programming a DPO's next node arc from child to parent it is thus required
58  * to know the parent's data-path protocol so the correct arc index can be used.
59  */
60 typedef enum dpo_proto_t_
61 {
62 #if CLIB_DEBUG > 0
64 #else
65  DPO_PROTO_IP4 = 0,
66 #endif
70 } __attribute__((packed)) dpo_proto_t;
71 
72 #define DPO_PROTO_NUM ((dpo_proto_t)(DPO_PROTO_MPLS+1))
73 #define DPO_PROTO_NONE ((dpo_proto_t)(DPO_PROTO_NUM+1))
74 
75 #define DPO_PROTOS { \
76  [DPO_PROTO_IP4] = "ip4", \
77  [DPO_PROTO_IP6] = "ip6", \
78  [DPO_PROTO_ETHERNET] = "ethernet", \
79  [DPO_PROTO_MPLS] = "mpls", \
80 }
81 
82 #define FOR_EACH_DPO_PROTO(_proto) \
83  for (_proto = DPO_PROTO_IP4; \
84  _proto <= DPO_PROTO_MPLS; \
85  _proto++)
86 
87 /**
88  * @brief Common types of data-path objects
89  * New types can be dynamically added using dpo_register_new_type()
90  */
91 typedef enum dpo_type_t_ {
92  /**
93  * A non-zero value first so we can spot unitialisation errors
94  */
99  /**
100  * @brief load-balancing over a choice of [un]equal cost paths
101  */
113 } __attribute__((packed)) dpo_type_t;
114 
115 #define DPO_TYPE_NUM DPO_LAST
116 
117 #define DPO_TYPES { \
118  [DPO_FIRST] = "dpo-invalid", \
119  [DPO_DROP] = "dpo-drop", \
120  [DPO_IP_NULL] = "dpo-ip-null", \
121  [DPO_PUNT] = "dpo-punt", \
122  [DPO_ADJACENCY] = "dpo-adjacency", \
123  [DPO_ADJACENCY_INCOMPLETE] = "dpo-adjacency-incomplete", \
124  [DPO_ADJACENCY_MIDCHAIN] = "dpo-adjacency-midcahin", \
125  [DPO_ADJACENCY_GLEAN] = "dpo-glean", \
126  [DPO_RECEIVE] = "dpo-receive", \
127  [DPO_LOOKUP] = "dpo-lookup", \
128  [DPO_LOAD_BALANCE] = "dpo-load-balance", \
129  [DPO_LISP_CP] = "dpo-lisp-cp", \
130  [DPO_CLASSIFY] = "dpo-classify", \
131  [DPO_MPLS_LABEL] = "dpo-mpls-label" \
132 }
133 
134 /**
135  * @brief The identity of a DPO is a combination of its type and its
136  * instance number/index of objects of that type
137  */
138 typedef struct dpo_id_t_ {
139  /**
140  * the type
141  */
142  dpo_type_t dpoi_type;
143  /**
144  * the data-path protocol of the type.
145  */
146  dpo_proto_t dpoi_proto;
147  /**
148  * The next VLIB node to follow.
149  */
151  /**
152  * the index of objects of that type
153  */
154  index_t dpoi_index;
155 } __attribute__ ((aligned(sizeof(u64)))) dpo_id_t;
156 
157 STATIC_ASSERT(sizeof(dpo_id_t) <= sizeof(u64),
158  "DPO ID is greater than sizeof u64 "
159  "atomic updates need to be revisited");
160 
161 /**
162  * @brief An initialiser for DPOs declared on the stack.
163  * Thenext node is set to 0 since VLIB graph nodes should set 0 index to drop.
164  */
165 #define DPO_INVALID \
166 { \
167  .dpoi_type = DPO_FIRST, \
168  .dpoi_proto = DPO_PROTO_NONE, \
169  .dpoi_index = INDEX_INVALID, \
170  .dpoi_next_node = 0, \
171 }
172 
173 /**
174  * @brief Return true if the DPO object is valid, i.e. has been initialised.
175  */
176 static inline int
177 dpo_id_is_valid (const dpo_id_t *dpoi)
178 {
179  return (dpoi->dpoi_type != DPO_FIRST &&
180  dpoi->dpoi_index != INDEX_INVALID);
181 }
182 
183 extern dpo_proto_t vnet_link_to_dpo_proto(vnet_link_t linkt);
184 
185 /**
186  * @brief
187  * Take a reference counting lock on the DPO
188  */
189 extern void dpo_lock(dpo_id_t *dpo);
190 
191 /**
192  * @brief
193  * Release a reference counting lock on the DPO
194  */
195 extern void dpo_unlock(dpo_id_t *dpo);
196 
197 /**
198  * @brief Set/create a DPO ID
199  * The DPO will be locked.
200  *
201  * @param dpo
202  * The DPO object to configure
203  *
204  * @param type
205  * The dpo_type_t of the DPO
206  *
207  * @param proto
208  * The dpo_proto_t of the DPO
209  *
210  * @param index
211  * The type specific index of the DPO
212  */
213 extern void dpo_set(dpo_id_t *dpo,
214  dpo_type_t type,
215  dpo_proto_t proto,
216  index_t index);
217 
218 /**
219  * @brief reset a DPO ID
220  * The DPO will be unlocked.
221  *
222  * @param dpo
223  * The DPO object to reset
224  */
225 extern void dpo_reset(dpo_id_t *dpo);
226 
227 /**
228  * @brief compare two DPOs for equality
229  */
230 extern int dpo_cmp(const dpo_id_t *dpo1,
231  const dpo_id_t *dpo2);
232 
233 /**
234  * @brief
235  * atomic copy a data-plane object.
236  * This is safe to use when the dst DPO is currently switching packets
237  */
238 extern void dpo_copy(dpo_id_t *dst,
239  const dpo_id_t *src);
240 
241 /**
242  * @brief Return TRUE is the DPO is any type of adjacency
243  */
244 extern int dpo_is_adj(const dpo_id_t *dpo);
245 
246 /**
247  * @biref Format a DPO_id_t oject
248  */
249 extern u8 *format_dpo_id(u8 * s, va_list * args);
250 
251 /**
252  * @biref format a DPO type
253  */
254 extern u8 *format_dpo_type(u8 * s, va_list * args);
255 
256 /**
257  * @brief format a DPO protocol
258  */
259 extern u8 *format_dpo_proto(u8 * s, va_list * args);
260 
261 /**
262  * @brief
263  * Set and stack a DPO.
264  * The DPO passed is set to the parent DPO and the necessary
265  * VLIB graph arcs are created. The child_type and child_proto
266  * are used to get the VLID nodes from which the arcs are added.
267  *
268  * @param child_type
269  * Child DPO type.
270  *
271  * @param child_proto
272  * Child DPO proto
273  *
274  * @parem dpo
275  * This is the DPO to stack and set.
276  *
277  * @paren parent_dpo
278  * The parent DPO to stack onto.
279  */
280 extern void dpo_stack(dpo_type_t child_type,
281  dpo_proto_t child_proto,
282  dpo_id_t *dpo,
283  const dpo_id_t *parent_dpo);
284 
285 /**
286  * @brief
287  * Set and stack a DPO.
288  * The DPO passed is set to the parent DPO and the necessary
289  * VLIB graph arcs are created, from the child_node passed.
290  *
291  * @param child_node
292  * The VLIB grpah node index to create an arc from to the parent
293  *
294  * @parem dpo
295  * This is the DPO to stack and set.
296  *
297  * @paren parent_dpo
298  * The parent DPO to stack onto.
299  */
300 extern void dpo_stack_from_node(u32 child_node,
301  dpo_id_t *dpo,
302  const dpo_id_t *parent);
303 
304 /**
305  * @brief A lock function registered for a DPO type
306  */
307 typedef void (*dpo_lock_fn_t)(dpo_id_t *dpo);
308 
309 /**
310  * @brief An unlock function registered for a DPO type
311  */
312 typedef void (*dpo_unlock_fn_t)(dpo_id_t *dpo);
313 
314 /**
315  * @brief An memory usage show command
316  */
317 typedef void (*dpo_mem_show_t)(void);
318 
319 /**
320  * @brief A virtual function table regisitered for a DPO type
321  */
322 typedef struct dpo_vft_t_
323 {
324  /**
325  * A reference counting lock function
326  */
328  /**
329  * A reference counting unlock function
330  */
332  /**
333  * A format function
334  */
336  /**
337  * A show memory usage function
338  */
340 } dpo_vft_t;
341 
342 
343 /**
344  * @brief For a given DPO type Register:
345  * - a virtual function table
346  * - a NULL terminated array of graph nodes from which that object type
347  * will originate packets, i.e. the nodes in which the object type will be
348  * the parent DPO in the DP graph. The ndoes are per-data-path protocol
349  * (see above).
350  *
351  * @param type
352  * The type being registered.
353  *
354  * @param vft
355  * The virtual function table to register for the type.
356  *
357  * @param nodes
358  * The string description of the per-protocol VLIB graph nodes.
359  */
360 extern void dpo_register(dpo_type_t type,
361  const dpo_vft_t *vft,
362  const char * const * const * nodes);
363 
364 /**
365  * @brief Create and register a new DPO type.
366  *
367  * This can be used by plugins to create new DPO types that are not listed
368  * in dpo_type_t enum
369  *
370  * @param vft
371  * The virtual function table to register for the type.
372  *
373  * @param nodes
374  * The string description of the per-protocol VLIB graph nodes.
375  *
376  * @return The new dpo_type_t
377  */
378 extern dpo_type_t dpo_register_new_type(const dpo_vft_t *vft,
379  const char * const * const * nodes);
380 
381 #endif
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:327
Definition: dpo.h:98
void(* dpo_lock_fn_t)(dpo_id_t *dpo)
A lock function registered for a DPO type.
Definition: dpo.h:307
A virtual function table regisitered for a DPO type.
Definition: dpo.h:322
dpo_proto_t_
Data path protocol.
Definition: dpo.h:60
static int dpo_id_is_valid(const dpo_id_t *dpoi)
Return true if the DPO object is valid, i.e.
Definition: dpo.h:177
dpo_proto_t dpoi_proto
the data-path protocol of the type.
Definition: dpo.h:146
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
dpo_type_t_
Common types of data-path objects New types can be dynamically added using dpo_register_new_type() ...
Definition: dpo.h:91
void dpo_unlock(dpo_id_t *dpo)
Release a reference counting lock on the DPO.
Definition: dpo.c:278
STATIC_ASSERT(sizeof(dpo_id_t)<=sizeof(u64),"DPO ID is greater than sizeof u64 ""atomic updates need to be revisited")
u8 * format_dpo_proto(u8 *s, va_list *args)
format a DPO protocol
Definition: dpo.c:146
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
Definition: dpo.c:118
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:154
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:138
void dpo_stack(dpo_type_t child_type, dpo_proto_t child_proto, dpo_id_t *dpo, const dpo_id_t *parent_dpo)
Set and stack a DPO.
Definition: dpo.c:398
void(* dpo_mem_show_t)(void)
An memory usage show command.
Definition: dpo.h:317
Definition: dpo.h:112
dpo_type_t dpoi_type
the type
Definition: dpo.h:142
load-balancing over a choice of [un]equal cost paths
Definition: dpo.h:102
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:191
int dpo_cmp(const dpo_id_t *dpo1, const dpo_id_t *dpo2)
compare two DPOs for equality
Definition: dpo.c:208
void dpo_register(dpo_type_t type, const dpo_vft_t *vft, const char *const *const *nodes)
For a given DPO type Register:
Definition: dpo.c:246
void dpo_copy(dpo_id_t *dst, const dpo_id_t *src)
atomic copy a data-plane object.
Definition: dpo.c:221
u8 * format_dpo_type(u8 *s, va_list *args)
format a DPO type
Definition: dpo.c:108
int dpo_is_adj(const dpo_id_t *dpo)
Return TRUE is the DPO is any type of adjacency.
Definition: dpo.c:237
unsigned int u32
Definition: types.h:88
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
A non-zero value first so we can spot unitialisation errors.
Definition: dpo.h:95
void dpo_lock(dpo_id_t *dpo)
Take a reference counting lock on the DPO.
Definition: dpo.c:269
void(* dpo_unlock_fn_t)(dpo_id_t *dpo)
An unlock function registered for a DPO type.
Definition: dpo.h:312
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
dpo_mem_show_t dv_mem_show
A show memory usage function.
Definition: dpo.h:339
unsigned short u16
Definition: types.h:57
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
Definition: dpo.c:258
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:154
format_function_t * dv_format
A format function.
Definition: dpo.h:335
unsigned char u8
Definition: types.h:56
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
dpo_lock_fn_t dv_unlock
A reference counting unlock function.
Definition: dpo.h:331
void dpo_stack_from_node(u32 child_node, dpo_id_t *dpo, const dpo_id_t *parent)
Set and stack a DPO.
Definition: dpo.c:413
dpo_proto_t vnet_link_to_dpo_proto(vnet_link_t linkt)
Definition: dpo.c:88
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:150
Definition: dpo.h:96
struct dpo_vft_t_ dpo_vft_t
A virtual function table regisitered for a DPO type.