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_
68 } __attribute__((packed)) dpo_proto_t;
70 #define DPO_PROTO_NUM ((dpo_proto_t)(DPO_PROTO_NSH+1))
71 #define DPO_PROTO_NONE ((dpo_proto_t)(DPO_PROTO_NUM+1))
73 #define DPO_PROTOS { \
74 [DPO_PROTO_IP4] = "ip4", \
75 [DPO_PROTO_IP6] = "ip6", \
76 [DPO_PROTO_ETHERNET] = "ethernet", \
77 [DPO_PROTO_MPLS] = "mpls", \
78 [DPO_PROTO_NSH] = "nsh", \
79 [DPO_PROTO_BIER] = "bier", \
82 #define FOR_EACH_DPO_PROTO(_proto) \
83 for (_proto = DPO_PROTO_IP4; \
84 _proto <= DPO_PROTO_NSH; \
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
100 * @brief load-balancing over a choice of [un]equal cost paths
105 DPO_ADJACENCY_INCOMPLETE,
106 DPO_ADJACENCY_MIDCHAIN,
109 DPO_ADJACENCY_MCAST_MIDCHAIN,
114 DPO_MPLS_DISPOSITION_PIPE,
115 DPO_MPLS_DISPOSITION_UNIFORM,
129 } __attribute__((packed)) dpo_type_t;
131 #define DPO_TYPE_NUM DPO_LAST
133 #define DPO_TYPES { \
134 [DPO_FIRST] = "dpo-invalid", \
135 [DPO_DROP] = "dpo-drop", \
136 [DPO_IP_NULL] = "dpo-ip-null", \
137 [DPO_PUNT] = "dpo-punt", \
138 [DPO_ADJACENCY] = "dpo-adjacency", \
139 [DPO_ADJACENCY_INCOMPLETE] = "dpo-adjacency-incomplete", \
140 [DPO_ADJACENCY_MIDCHAIN] = "dpo-adjacency-midcahin", \
141 [DPO_ADJACENCY_GLEAN] = "dpo-glean", \
142 [DPO_ADJACENCY_MCAST] = "dpo-adj-mcast", \
143 [DPO_ADJACENCY_MCAST_MIDCHAIN] = "dpo-adj-mcast-midchain", \
144 [DPO_RECEIVE] = "dpo-receive", \
145 [DPO_LOOKUP] = "dpo-lookup", \
146 [DPO_LOAD_BALANCE] = "dpo-load-balance", \
147 [DPO_REPLICATE] = "dpo-replicate", \
148 [DPO_LISP_CP] = "dpo-lisp-cp", \
149 [DPO_CLASSIFY] = "dpo-classify", \
150 [DPO_MPLS_DISPOSITION_PIPE] = "dpo-mpls-diposition-pipe", \
151 [DPO_MPLS_DISPOSITION_UNIFORM] = "dpo-mpls-diposition-uniform", \
152 [DPO_MFIB_ENTRY] = "dpo-mfib-entry", \
153 [DPO_INTERFACE_RX] = "dpo-interface-rx", \
154 [DPO_INTERFACE_TX] = "dpo-interface-tx", \
155 [DPO_DVR] = "dpo-dvr", \
156 [DPO_L3_PROXY] = "dpo-l3-proxy", \
157 [DPO_BIER_TABLE] = "bier-table", \
158 [DPO_BIER_FMASK] = "bier-fmask", \
159 [DPO_BIER_IMP] = "bier-imposition", \
160 [DPO_BIER_DISP_ENTRY] = "bier-disp-entry", \
161 [DPO_BIER_DISP_TABLE] = "bier-disp-table", \
162 [DPO_IP6_LL] = "ip6-link-local", \
163 [DPO_PW_CW] = "PW-CW", \
167 * @brief The identity of a DPO is a combination of its type and its
168 * instance number/index of objects of that type
170 typedef struct dpo_id_t_ {
176 dpo_type_t dpoi_type;
178 * the data-path protocol of the type.
180 dpo_proto_t dpoi_proto;
182 * The next VLIB node to follow.
186 * the index of objects of that type
194 STATIC_ASSERT(sizeof(dpo_id_t) <= sizeof(u64),
195 "DPO ID is greater than sizeof u64 "
196 "atomic updates need to be revisited");
199 * @brief An initialiser for DPOs declared on the stack.
200 * Thenext node is set to 0 since VLIB graph nodes should set 0 index to drop.
202 #define DPO_INVALID \
204 .dpoi_type = DPO_FIRST, \
205 .dpoi_proto = DPO_PROTO_NONE, \
206 .dpoi_index = INDEX_INVALID, \
207 .dpoi_next_node = 0, \
211 * @brief Return true if the DPO object is valid, i.e. has been initialised.
214 dpo_id_is_valid (const dpo_id_t *dpoi)
216 return (dpoi->dpoi_type != DPO_FIRST &&
217 dpoi->dpoi_index != INDEX_INVALID);
220 extern dpo_proto_t vnet_link_to_dpo_proto(vnet_link_t linkt);
224 * Take a reference counting lock on the DPO
226 extern void dpo_lock(dpo_id_t *dpo);
230 * Release a reference counting lock on the DPO
232 extern void dpo_unlock(dpo_id_t *dpo);
236 * Make an interpose DPO from an original
238 extern void dpo_mk_interpose(const dpo_id_t *original,
239 const dpo_id_t *parent,
243 * @brief Set/create a DPO ID
244 * The DPO will be locked.
247 * The DPO object to configure
250 * The dpo_type_t of the DPO
253 * The dpo_proto_t of the DPO
256 * The type specific index of the DPO
258 extern void dpo_set(dpo_id_t *dpo,
264 * @brief reset a DPO ID
265 * The DPO will be unlocked.
268 * The DPO object to reset
270 extern void dpo_reset(dpo_id_t *dpo);
273 * @brief compare two DPOs for equality
275 extern int dpo_cmp(const dpo_id_t *dpo1,
276 const dpo_id_t *dpo2);
280 * atomic copy a data-plane object.
281 * This is safe to use when the dst DPO is currently switching packets
283 extern void dpo_copy(dpo_id_t *dst,
284 const dpo_id_t *src);
287 * @brief Return TRUE is the DPO is any type of adjacency
289 extern int dpo_is_adj(const dpo_id_t *dpo);
292 * @brief Format a DPO_id_t oject
294 extern u8 *format_dpo_id(u8 * s, va_list * args);
297 * @brief format a DPO type
299 extern u8 *format_dpo_type(u8 * s, va_list * args);
302 * @brief format a DPO protocol
304 extern u8 *format_dpo_proto(u8 * s, va_list * args);
307 * @brief format a DPO protocol
309 extern vnet_link_t dpo_proto_to_link(dpo_proto_t dp);
313 * Set and stack a DPO.
314 * The DPO passed is set to the parent DPO and the necessary
315 * VLIB graph arcs are created. The child_type and child_proto
316 * are used to get the VLID nodes from which the arcs are added.
325 * This is the DPO to stack and set.
328 * The parent DPO to stack onto.
330 extern void dpo_stack(dpo_type_t child_type,
331 dpo_proto_t child_proto,
333 const dpo_id_t *parent_dpo);
337 * Set and stack a DPO.
338 * The DPO passed is set to the parent DPO and the necessary
339 * VLIB graph arcs are created, from the child_node passed.
342 * The VLIB graph node index to create an arc from to the parent
345 * This is the DPO to stack and set.
348 * The parent DPO to stack onto.
350 extern void dpo_stack_from_node(u32 child_node,
352 const dpo_id_t *parent);
355 * Get a uRPF interface for the DPO
358 * The DPO from which to get the uRPF interface
360 * @return valid SW interface index or ~0
362 extern u32 dpo_get_urpf(const dpo_id_t *dpo);
365 * @brief A lock function registered for a DPO type
367 typedef void (*dpo_lock_fn_t)(dpo_id_t *dpo);
370 * @brief An unlock function registered for a DPO type
372 typedef void (*dpo_unlock_fn_t)(dpo_id_t *dpo);
375 * @brief An memory usage show command
377 typedef void (*dpo_mem_show_t)(void);
380 * @brief Given a DPO instance return a vector of node indices that
381 * the type/instance will use.
383 typedef u32* (*dpo_get_next_node_t)(const dpo_id_t *dpo);
386 * @brief Given a DPO instance return an interface that can
387 * be used in an uRPF check
389 typedef u32 (*dpo_get_urpf_t)(const dpo_id_t *dpo);
392 * @brief Called during FIB interposition when the originally
393 * registered DPO is used to 'clone' an instance for interposition
394 * at a particular location in the FIB graph.
395 * The parent is the next DPO in the chain that the clone will
396 * be used instead of. The clone may then choose to stack itself
399 typedef void (*dpo_mk_interpose_t)(const dpo_id_t *original,
400 const dpo_id_t *parent,
404 * @brief A virtual function table regisitered for a DPO type
406 typedef struct dpo_vft_t_
409 * A reference counting lock function
411 dpo_lock_fn_t dv_lock;
413 * A reference counting unlock function
415 dpo_lock_fn_t dv_unlock;
419 format_function_t *dv_format;
421 * A show memory usage function
423 dpo_mem_show_t dv_mem_show;
425 * A function to get the next VLIB node given an instance
426 * of the DPO. If this is null, then the node's name MUST be
427 * retreiveable from the nodes names array passed in the register
430 dpo_get_next_node_t dv_get_next_node;
434 dpo_get_urpf_t dv_get_urpf;
436 * Signal on an interposed child that the parent has changed
438 dpo_mk_interpose_t dv_mk_interpose;
443 * @brief For a given DPO type Register:
444 * - a virtual function table
445 * - a NULL terminated array of graph nodes from which that object type
446 * will originate packets, i.e. the nodes in which the object type will be
447 * the parent DPO in the DP graph. The ndoes are per-data-path protocol
451 * The type being registered.
454 * The virtual function table to register for the type.
457 * The string description of the per-protocol VLIB graph nodes.
459 extern void dpo_register(dpo_type_t type,
460 const dpo_vft_t *vft,
461 const char * const * const * nodes);
464 * @brief Create and register a new DPO type.
466 * This can be used by plugins to create new DPO types that are not listed
470 * The virtual function table to register for the type.
473 * The string description of the per-protocol VLIB graph nodes.
475 * @return The new dpo_type_t
477 extern dpo_type_t dpo_register_new_type(const dpo_vft_t *vft,
478 const char * const * const * nodes);
481 * @brief Return already stacked up next node index for a given
482 * child_type/child_proto and parent_type/patent_proto.
483 * The VLIB graph arc used is taken from the parent and child types
495 * @param parent_proto
498 * @return The VLIB Graph node index
501 dpo_get_next_node_by_type_and_proto (dpo_type_t child_type,
502 dpo_proto_t child_proto,
503 dpo_type_t parent_type,
504 dpo_proto_t parent_proto);
508 * @brief Barrier sync if a dpo pool is about to expand
511 * vlib_main_t *, invariably &vlib_global_main
516 * @param YESNO (output)
517 * typically a u8, 1 => expand will occur, worker barrier held
518 * 0 => no expand, barrier not held
523 #define dpo_pool_barrier_sync(VM,P,YESNO) \
525 pool_get_aligned_will_expand ((P), YESNO, CLIB_CACHE_LINE_BYTES); \
529 VM = vlib_get_main(); \
530 ASSERT ((VM)->thread_index == 0); \
531 vlib_worker_thread_barrier_sync((VM)); \
536 * @brief Release barrier sync after dpo pool expansion
539 * vlib_main_t pointer, must be &vlib_global_main
542 * typically a u8, 1 => release required
543 * 0 => no release required
547 #define dpo_pool_barrier_release(VM,YESNO) \
548 if ((YESNO)) vlib_worker_thread_barrier_release((VM));