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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
20 * The DPO can be considered to be like is a base class that is specialised
21 * by other objects to provide concreate actions
23 * The VLIB graph nodes are graph of DPO types, the DPO graph is a graph of
30 #include <vnet/vnet.h>
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
44 * @brief Invalid index - used when no index is known
45 * blazoned capitals INVALID speak volumes where ~0 does not.
47 #define INDEX_INVALID ((index_t)(~0))
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.
60 typedef enum dpo_proto_t_
70 } __attribute__((packed)) dpo_proto_t;
72 #define DPO_PROTO_NUM (DPO_PROTO_MPLS+1)
73 #define DPO_PROTO_NONE (DPO_PROTO_NUM+1)
75 #define DPO_PROTOS { \
76 [DPO_PROTO_IP4] = "ip4", \
77 [DPO_PROTO_IP6] = "ip6", \
78 [DPO_PROTO_ETHERNET] = "ethernet", \
79 [DPO_PROTO_MPLS] = "mpls", \
82 #define FOR_EACH_DPO_PROTO(_proto) \
83 for (_proto = DPO_PROTO_IP4; \
84 _proto <= DPO_PROTO_MPLS; \
88 * @brief Common types of data-path objects
89 * New types can be dynamically added using dpo_register_new_type()
91 typedef enum dpo_type_t_ {
93 * A non-zero value first so we can spot unitialisation errors
99 * @brief load-balancing over a choice of [un]equal cost paths
103 DPO_ADJACENCY_INCOMPLETE,
104 DPO_ADJACENCY_MIDCHAIN,
112 } __attribute__((packed)) dpo_type_t;
114 #define DPO_TYPE_NUM DPO_LAST
116 #define DPO_TYPES { \
117 [DPO_FIRST] = "dpo-invalid", \
118 [DPO_DROP] = "dpo-drop", \
119 [DPO_PUNT] = "dpo-punt", \
120 [DPO_ADJACENCY] = "dpo-adjacency", \
121 [DPO_ADJACENCY_INCOMPLETE] = "dpo-adjacency-incomplete", \
122 [DPO_ADJACENCY_MIDCHAIN] = "dpo-adjacency-midcahin", \
123 [DPO_ADJACENCY_GLEAN] = "dpo-glean", \
124 [DPO_RECEIVE] = "dpo-receive", \
125 [DPO_LOOKUP] = "dpo-lookup", \
126 [DPO_LOAD_BALANCE] = "dpo-load-balance", \
127 [DPO_LISP_CP] = "dpo-lisp-cp", \
128 [DPO_CLASSIFY] = "dpo-classify", \
129 [DPO_MPLS_LABEL] = "dpo-mpls-label", \
133 * @brief The identity of a DPO is a combination of its type and its
134 * instance number/index of objects of that type
136 typedef struct dpo_id_t_ {
140 dpo_type_t dpoi_type;
142 * the data-path protocol of the type.
144 dpo_proto_t dpoi_proto;
146 * The next VLIB node to follow.
150 * the index of objects of that type
153 } __attribute__ ((aligned(sizeof(u64)))) dpo_id_t;
155 _Static_assert(sizeof(dpo_id_t) <= sizeof(u64),
156 "DPO ID is greater than sizeof u64 "
157 "atomic updates need to be revisited");
160 * @brief An initialiser for DPos declared on the stack.
165 * @brief Return true if the DPO object is valid, i.e. has been initialised.
168 dpo_id_is_valid (const dpo_id_t *dpoi)
170 return (dpoi->dpoi_type != DPO_FIRST &&
171 dpoi->dpoi_index != INDEX_INVALID);
176 * Take a reference counting lock on the DPO
178 extern void dpo_lock(dpo_id_t *dpo);
182 * Release a reference counting lock on the DPO
184 extern void dpo_unlock(dpo_id_t *dpo);
187 * @brief Set/create a DPO ID
188 * The DPO will be locked.
191 * The DPO object to configure
194 * The dpo_type_t of the DPO
197 * The dpo_proto_t of the DPO
200 * The type specific index of the DPO
202 extern void dpo_set(dpo_id_t *dpo,
208 * @brief reset a DPO ID
209 * The DPO will be unlocked.
212 * The DPO object to reset
214 extern void dpo_reset(dpo_id_t *dpo);
217 * @brief compare two DPOs for equality
219 extern int dpo_cmp(const dpo_id_t *dpo1,
220 const dpo_id_t *dpo2);
224 * atomic copy a data-plane object.
225 * This is safe to use when the dst DPO is currently switching packets
227 extern void dpo_copy(dpo_id_t *dst,
228 const dpo_id_t *src);
231 * @brief Return TRUE is the DPO is any type of adjacency
233 extern int dpo_is_adj(const dpo_id_t *dpo);
236 * @biref Format a DPO_id_t oject
238 extern u8 *format_dpo_id(u8 * s, va_list * args);
241 * @biref format a DPO type
243 extern u8 *format_dpo_type(u8 * s, va_list * args);
246 * @brief format a DPO protocol
248 extern u8 *format_dpo_proto(u8 * s, va_list * args);
252 * Set and stack a DPO.
253 * The DPO passed is set to the parent DPO and the necessary
254 * VLIB graph arcs are created. The child_type and child_proto
255 * are used to get the VLID nodes from which the arcs are added.
264 * This is the DPO to stack and set.
267 * The parent DPO to stack onto.
269 extern void dpo_stack(dpo_type_t child_type,
270 dpo_proto_t child_proto,
272 const dpo_id_t *parent_dpo);
276 * Set and stack a DPO.
277 * The DPO passed is set to the parent DPO and the necessary
278 * VLIB graph arcs are created, from the child_node passed.
281 * The VLIB grpah node index to create an arc from to the parent
284 * This is the DPO to stack and set.
287 * The parent DPO to stack onto.
289 extern void dpo_stack_from_node(u32 child_node,
291 const dpo_id_t *parent);
294 * @brief A lock function registered for a DPO type
296 typedef void (*dpo_lock_fn_t)(dpo_id_t *dpo);
299 * @brief An unlock function registered for a DPO type
301 typedef void (*dpo_unlock_fn_t)(dpo_id_t *dpo);
304 * @brief An memory usage show command
306 typedef void (*dpo_mem_show_t)(void);
309 * @brief A virtual function table regisitered for a DPO type
311 typedef struct dpo_vft_t_
314 * A reference counting lock function
316 dpo_lock_fn_t dv_lock;
318 * A reference counting unlock function
320 dpo_lock_fn_t dv_unlock;
324 format_function_t *dv_format;
326 * A show memory usage function
328 dpo_mem_show_t dv_mem_show;
333 * @brief For a given DPO type Register:
334 * - a virtual function table
335 * - a NULL terminated array of graph nodes from which that object type
336 * will originate packets, i.e. the nodes in which the object type will be
337 * the parent DPO in the DP graph. The ndoes are per-data-path protocol
341 * The type being registered.
344 * The virtual function table to register for the type.
347 * The string description of the per-protocol VLIB graph nodes.
349 extern void dpo_register(dpo_type_t type,
350 const dpo_vft_t *vft,
351 const char * const * const * nodes);
354 * @brief Create and register a new DPO type.
356 * This can be used by plugins to create new DPO types that are not listed
360 * The virtual function table to register for the type.
363 * The string description of the per-protocol VLIB graph nodes.
365 * @return The new dpo_type_t
367 extern dpo_type_t dpo_register_new_type(const dpo_vft_t *vft,
368 const char * const * const * nodes);