FD.io VPP  v16.12-rc0-308-g931be3a
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_MPLS+1)
73 #define DPO_PROTO_NONE (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  */
164 #define DPO_INVALID {0}
165 
166 /**
167  * @brief Return true if the DPO object is valid, i.e. has been initialised.
168  */
169 static inline int
170 dpo_id_is_valid (const dpo_id_t *dpoi)
171 {
172  return (dpoi->dpoi_type != DPO_FIRST &&
173  dpoi->dpoi_index != INDEX_INVALID);
174 }
175 
176 /**
177  * @brief
178  * Take a reference counting lock on the DPO
179  */
180 extern void dpo_lock(dpo_id_t *dpo);
181 
182 /**
183  * @brief
184  * Release a reference counting lock on the DPO
185  */
186 extern void dpo_unlock(dpo_id_t *dpo);
187 
188 /**
189  * @brief Set/create a DPO ID
190  * The DPO will be locked.
191  *
192  * @param dpo
193  * The DPO object to configure
194  *
195  * @param type
196  * The dpo_type_t of the DPO
197  *
198  * @param proto
199  * The dpo_proto_t of the DPO
200  *
201  * @param index
202  * The type specific index of the DPO
203  */
204 extern void dpo_set(dpo_id_t *dpo,
205  dpo_type_t type,
206  dpo_proto_t proto,
207  index_t index);
208 
209 /**
210  * @brief reset a DPO ID
211  * The DPO will be unlocked.
212  *
213  * @param dpo
214  * The DPO object to reset
215  */
216 extern void dpo_reset(dpo_id_t *dpo);
217 
218 /**
219  * @brief compare two DPOs for equality
220  */
221 extern int dpo_cmp(const dpo_id_t *dpo1,
222  const dpo_id_t *dpo2);
223 
224 /**
225  * @brief
226  * atomic copy a data-plane object.
227  * This is safe to use when the dst DPO is currently switching packets
228  */
229 extern void dpo_copy(dpo_id_t *dst,
230  const dpo_id_t *src);
231 
232 /**
233  * @brief Return TRUE is the DPO is any type of adjacency
234  */
235 extern int dpo_is_adj(const dpo_id_t *dpo);
236 
237 /**
238  * @biref Format a DPO_id_t oject
239  */
240 extern u8 *format_dpo_id(u8 * s, va_list * args);
241 
242 /**
243  * @biref format a DPO type
244  */
245 extern u8 *format_dpo_type(u8 * s, va_list * args);
246 
247 /**
248  * @brief format a DPO protocol
249  */
250 extern u8 *format_dpo_proto(u8 * s, va_list * args);
251 
252 /**
253  * @brief
254  * Set and stack a DPO.
255  * The DPO passed is set to the parent DPO and the necessary
256  * VLIB graph arcs are created. The child_type and child_proto
257  * are used to get the VLID nodes from which the arcs are added.
258  *
259  * @param child_type
260  * Child DPO type.
261  *
262  * @param child_proto
263  * Child DPO proto
264  *
265  * @parem dpo
266  * This is the DPO to stack and set.
267  *
268  * @paren parent_dpo
269  * The parent DPO to stack onto.
270  */
271 extern void dpo_stack(dpo_type_t child_type,
272  dpo_proto_t child_proto,
273  dpo_id_t *dpo,
274  const dpo_id_t *parent_dpo);
275 
276 /**
277  * @brief
278  * Set and stack a DPO.
279  * The DPO passed is set to the parent DPO and the necessary
280  * VLIB graph arcs are created, from the child_node passed.
281  *
282  * @param child_node
283  * The VLIB grpah node index to create an arc from to the parent
284  *
285  * @parem dpo
286  * This is the DPO to stack and set.
287  *
288  * @paren parent_dpo
289  * The parent DPO to stack onto.
290  */
291 extern void dpo_stack_from_node(u32 child_node,
292  dpo_id_t *dpo,
293  const dpo_id_t *parent);
294 
295 /**
296  * @brief A lock function registered for a DPO type
297  */
298 typedef void (*dpo_lock_fn_t)(dpo_id_t *dpo);
299 
300 /**
301  * @brief An unlock function registered for a DPO type
302  */
303 typedef void (*dpo_unlock_fn_t)(dpo_id_t *dpo);
304 
305 /**
306  * @brief An memory usage show command
307  */
308 typedef void (*dpo_mem_show_t)(void);
309 
310 /**
311  * @brief A virtual function table regisitered for a DPO type
312  */
313 typedef struct dpo_vft_t_
314 {
315  /**
316  * A reference counting lock function
317  */
319  /**
320  * A reference counting unlock function
321  */
323  /**
324  * A format function
325  */
327  /**
328  * A show memory usage function
329  */
331 } dpo_vft_t;
332 
333 
334 /**
335  * @brief For a given DPO type Register:
336  * - a virtual function table
337  * - a NULL terminated array of graph nodes from which that object type
338  * will originate packets, i.e. the nodes in which the object type will be
339  * the parent DPO in the DP graph. The ndoes are per-data-path protocol
340  * (see above).
341  *
342  * @param type
343  * The type being registered.
344  *
345  * @param vft
346  * The virtual function table to register for the type.
347  *
348  * @param nodes
349  * The string description of the per-protocol VLIB graph nodes.
350  */
351 extern void dpo_register(dpo_type_t type,
352  const dpo_vft_t *vft,
353  const char * const * const * nodes);
354 
355 /**
356  * @brief Create and register a new DPO type.
357  *
358  * This can be used by plugins to create new DPO types that are not listed
359  * in dpo_type_t enum
360  *
361  * @param vft
362  * The virtual function table to register for the type.
363  *
364  * @param nodes
365  * The string description of the per-protocol VLIB graph nodes.
366  *
367  * @return The new dpo_type_t
368  */
369 extern dpo_type_t dpo_register_new_type(const dpo_vft_t *vft,
370  const char * const * const * nodes);
371 
372 #endif
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:318
Definition: dpo.h:98
void(* dpo_lock_fn_t)(dpo_id_t *dpo)
A lock function registered for a DPO type.
Definition: dpo.h:298
A virtual function table regisitered for a DPO type.
Definition: dpo.h:313
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:170
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:253
u8 * format_dpo_proto(u8 *s, va_list *args)
format a DPO protocol
Definition: dpo.c:126
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
Definition: dpo.c:98
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:134
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:373
void(* dpo_mem_show_t)(void)
An memory usage show command.
Definition: dpo.h:308
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:171
int dpo_cmp(const dpo_id_t *dpo1, const dpo_id_t *dpo2)
compare two DPOs for equality
Definition: dpo.c:183
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:221
void dpo_copy(dpo_id_t *dst, const dpo_id_t *src)
atomic copy a data-plane object.
Definition: dpo.c:196
u8 * format_dpo_type(u8 *s, va_list *args)
format a DPO type
Definition: dpo.c:88
int dpo_is_adj(const dpo_id_t *dpo)
Return TRUE is the DPO is any type of adjacency.
Definition: dpo.c:212
unsigned int u32
Definition: types.h:88
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:244
void(* dpo_unlock_fn_t)(dpo_id_t *dpo)
An unlock function registered for a DPO type.
Definition: dpo.h:303
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:330
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:233
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:326
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:322
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:388
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.