1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
5 #ifndef __INCLUDE_RTE_PIPELINE_H__
6 #define __INCLUDE_RTE_PIPELINE_H__
16 * This tool is part of the DPDK Packet Framework tool suite and provides
17 * a standard methodology (logically similar to OpenFlow) for rapid development
18 * of complex packet processing pipelines out of ports, tables and actions.
20 * <B>Basic operation.</B> A pipeline is constructed by connecting its input
21 * ports to its output ports through a chain of lookup tables. As result of
22 * lookup operation into the current table, one of the table entries (or the
23 * default table entry, in case of lookup miss) is identified to provide the
24 * actions to be executed on the current packet and the associated action
25 * meta-data. The behavior of user actions is defined through the configurable
26 * table action handler, while the reserved actions define the next hop for the
27 * current packet (either another table, an output port or packet drop) and are
28 * handled transparently by the framework.
30 * <B>Initialization and run-time flows.</B> Once all the pipeline elements
31 * (input ports, tables, output ports) have been created, input ports connected
32 * to tables, table action handlers configured, tables populated with the
33 * initial set of entries (actions and action meta-data) and input ports
34 * enabled, the pipeline runs automatically, pushing packets from input ports
35 * to tables and output ports. At each table, the identified user actions are
36 * being executed, resulting in action meta-data (stored in the table entry)
37 * and packet meta-data (stored with the packet descriptor) being updated. The
38 * pipeline tables can have further updates and input ports can be disabled or
39 * enabled later on as required.
41 * <B>Multi-core scaling.</B> Typically, each CPU core will run its own
42 * pipeline instance. Complex application-level pipelines can be implemented by
43 * interconnecting multiple CPU core-level pipelines in tree-like topologies,
44 * as the same port devices (e.g. SW rings) can serve as output ports for the
45 * pipeline running on CPU core A, as well as input ports for the pipeline
46 * running on CPU core B. This approach enables the application development
47 * using the pipeline (CPU cores connected serially), cluster/run-to-completion
48 * (CPU cores connected in parallel) or mixed (pipeline of CPU core clusters)
51 * <B>Thread safety.</B> It is possible to have multiple pipelines running on
52 * the same CPU core, but it is not allowed (for thread safety reasons) to have
53 * multiple CPU cores running the same pipeline instance.
60 #include <rte_table.h>
61 #include <rte_common.h>
69 /** Opaque data type for pipeline */
72 /** Parameters for pipeline creation */
73 struct rte_pipeline_params {
77 /** CPU socket ID where memory for the pipeline and its elements (ports
78 and tables) should be allocated */
81 /** Offset within packet meta-data to port_id to be used by action
82 "Send packet to output port read from packet meta-data". Has to be
84 uint32_t offset_port_id;
87 /** Pipeline port in stats. */
88 struct rte_pipeline_port_in_stats {
90 struct rte_port_in_stats stats;
92 /** Number of packets dropped by action handler. */
93 uint64_t n_pkts_dropped_by_ah;
97 /** Pipeline port out stats. */
98 struct rte_pipeline_port_out_stats {
99 /** Port out stats. */
100 struct rte_port_out_stats stats;
102 /** Number of packets dropped by action handler. */
103 uint64_t n_pkts_dropped_by_ah;
106 /** Pipeline table stats. */
107 struct rte_pipeline_table_stats {
109 struct rte_table_stats stats;
111 /** Number of packets dropped by lookup hit action handler. */
112 uint64_t n_pkts_dropped_by_lkp_hit_ah;
114 /** Number of packets dropped by lookup miss action handler. */
115 uint64_t n_pkts_dropped_by_lkp_miss_ah;
117 /** Number of packets dropped by pipeline in behalf of this
118 * table based on action specified in table entry. */
119 uint64_t n_pkts_dropped_lkp_hit;
121 /** Number of packets dropped by pipeline in behalf of this
122 * table based on action specified in table entry. */
123 uint64_t n_pkts_dropped_lkp_miss;
130 * Parameters for pipeline creation
132 * Handle to pipeline instance on success or NULL otherwise
134 struct rte_pipeline *rte_pipeline_create(struct rte_pipeline_params *params);
140 * Handle to pipeline instance
142 * 0 on success, error code otherwise
144 int rte_pipeline_free(struct rte_pipeline *p);
147 * Pipeline consistency check
150 * Handle to pipeline instance
152 * 0 on success, error code otherwise
154 int rte_pipeline_check(struct rte_pipeline *p);
160 * Handle to pipeline instance
162 * Number of packets read and processed
164 int rte_pipeline_run(struct rte_pipeline *p);
170 * Handle to pipeline instance
172 * 0 on success, error code otherwise
174 int rte_pipeline_flush(struct rte_pipeline *p);
180 /** Reserved actions */
181 enum rte_pipeline_action {
182 /** Drop the packet */
183 RTE_PIPELINE_ACTION_DROP = 0,
185 /** Send packet to output port */
186 RTE_PIPELINE_ACTION_PORT,
188 /** Send packet to output port read from packet meta-data */
189 RTE_PIPELINE_ACTION_PORT_META,
191 /** Send packet to table */
192 RTE_PIPELINE_ACTION_TABLE,
194 /** Number of reserved actions */
202 /** Maximum number of tables allowed for any given pipeline instance. The
203 value of this parameter cannot be changed. */
204 #define RTE_PIPELINE_TABLE_MAX 64
207 * Head format for the table entry of any pipeline table. For any given
208 * pipeline table, all table entries should have the same size and format. For
209 * any given pipeline table, the table entry has to start with a head of this
210 * structure, which contains the reserved actions and their associated
211 * meta-data, and then optionally continues with user actions and their
212 * associated meta-data. As all the currently defined reserved actions are
213 * mutually exclusive, only one reserved action can be set per table entry.
215 struct rte_pipeline_table_entry {
216 /** Reserved action */
217 enum rte_pipeline_action action;
221 /** Output port ID (meta-data for "Send packet to output port"
224 /** Table ID (meta-data for "Send packet to table" action) */
227 /** Start of table entry area for user defined actions and meta-data */
228 __extension__ uint8_t action_data[0];
232 * Pipeline table action handler on lookup hit
234 * The action handler can decide to drop packets by resetting the associated
235 * packet bit in the pkts_mask parameter. In this case, the action handler is
236 * required not to free the packet buffer, which will be freed eventually by
240 * Handle to pipeline instance
242 * Burst of input packets specified as array of up to 64 pointers to struct
245 * 64-bit bitmask specifying which packets in the input burst are valid. When
246 * pkts_mask bit n is set, then element n of pkts array is pointing to a
247 * valid packet and element n of entries array is pointing to a valid table
248 * entry associated with the packet, with the association typically done by
249 * the table lookup operation. Otherwise, element n of pkts array and element
250 * n of entries array will not be accessed.
252 * Set of table entries specified as array of up to 64 pointers to struct
253 * rte_pipeline_table_entry
255 * Opaque parameter registered by the user at the pipeline table creation
258 * 0 on success, error code otherwise
260 typedef int (*rte_pipeline_table_action_handler_hit)(
261 struct rte_pipeline *p,
262 struct rte_mbuf **pkts,
264 struct rte_pipeline_table_entry **entries,
268 * Pipeline table action handler on lookup miss
270 * The action handler can decide to drop packets by resetting the associated
271 * packet bit in the pkts_mask parameter. In this case, the action handler is
272 * required not to free the packet buffer, which will be freed eventually by
276 * Handle to pipeline instance
278 * Burst of input packets specified as array of up to 64 pointers to struct
281 * 64-bit bitmask specifying which packets in the input burst are valid. When
282 * pkts_mask bit n is set, then element n of pkts array is pointing to a
283 * valid packet. Otherwise, element n of pkts array will not be accessed.
285 * Single table entry associated with all the valid packets from the input
286 * burst, specified as pointer to struct rte_pipeline_table_entry.
287 * This entry is the pipeline table default entry that is associated by the
288 * table lookup operation with the input packets that have resulted in lookup
291 * Opaque parameter registered by the user at the pipeline table creation
294 * 0 on success, error code otherwise
296 typedef int (*rte_pipeline_table_action_handler_miss)(
297 struct rte_pipeline *p,
298 struct rte_mbuf **pkts,
300 struct rte_pipeline_table_entry *entry,
303 /** Parameters for pipeline table creation. Action handlers have to be either
304 both enabled or both disabled (they can be disabled by setting them to
306 struct rte_pipeline_table_params {
307 /** Table operations (specific to each table type) */
308 struct rte_table_ops *ops;
309 /** Opaque param to be passed to the table create operation when
312 /** Callback function to execute the user actions on input packets in
313 case of lookup hit */
314 rte_pipeline_table_action_handler_hit f_action_hit;
315 /** Callback function to execute the user actions on input packets in
316 case of lookup miss */
317 rte_pipeline_table_action_handler_miss f_action_miss;
319 /** Opaque parameter to be passed to lookup hit and/or lookup miss
320 action handlers when invoked */
322 /** Memory size to be reserved per table entry for storing the user
323 actions and their meta-data */
324 uint32_t action_data_size;
328 * Pipeline table create
331 * Handle to pipeline instance
333 * Parameters for pipeline table creation
335 * Table ID. Valid only within the scope of table IDs of the current
336 * pipeline. Only returned after a successful invocation.
338 * 0 on success, error code otherwise
340 int rte_pipeline_table_create(struct rte_pipeline *p,
341 struct rte_pipeline_table_params *params,
345 * Pipeline table default entry add
347 * The contents of the table default entry is updated with the provided actions
348 * and meta-data. When the default entry is not configured (by using this
349 * function), the built-in default entry has the action "Drop" and meta-data
353 * Handle to pipeline instance
355 * Table ID (returned by previous invocation of pipeline table create)
356 * @param default_entry
357 * New contents for the table default entry
358 * @param default_entry_ptr
359 * On successful invocation, pointer to the default table entry which can be
360 * used for further read-write accesses to this table entry. This pointer
361 * is valid until the default entry is deleted or re-added.
363 * 0 on success, error code otherwise
365 int rte_pipeline_table_default_entry_add(struct rte_pipeline *p,
367 struct rte_pipeline_table_entry *default_entry,
368 struct rte_pipeline_table_entry **default_entry_ptr);
371 * Pipeline table default entry delete
373 * The new contents of the table default entry is set to reserved action "Drop
374 * the packet" with meta-data cleared (i.e. set to all-zeros).
377 * Handle to pipeline instance
379 * Table ID (returned by previous invocation of pipeline table create)
381 * On successful invocation, when entry points to a valid buffer, the
382 * previous contents of the table default entry (as it was just before the
383 * delete operation) is copied to this buffer
385 * 0 on success, error code otherwise
387 int rte_pipeline_table_default_entry_delete(struct rte_pipeline *p,
389 struct rte_pipeline_table_entry *entry);
392 * Pipeline table entry add
395 * Handle to pipeline instance
397 * Table ID (returned by previous invocation of pipeline table create)
401 * New contents for the table entry identified by key
403 * On successful invocation, set to TRUE (value different than 0) if key was
404 * already present in the table before the add operation and to FALSE (value
407 * On successful invocation, pointer to the table entry associated with key.
408 * This can be used for further read-write accesses to this table entry and
409 * is valid until the key is deleted from the table or re-added (usually for
410 * associating different actions and/or action meta-data to the current key)
412 * 0 on success, error code otherwise
414 int rte_pipeline_table_entry_add(struct rte_pipeline *p,
417 struct rte_pipeline_table_entry *entry,
419 struct rte_pipeline_table_entry **entry_ptr);
422 * Pipeline table entry delete
425 * Handle to pipeline instance
427 * Table ID (returned by previous invocation of pipeline table create)
431 * On successful invocation, set to TRUE (value different than 0) if key was
432 * found in the table before the delete operation and to FALSE (value 0) if
435 * On successful invocation, when key is found in the table and entry points
436 * to a valid buffer, the table entry contents (as it was before the delete
437 * was performed) is copied to this buffer
439 * 0 on success, error code otherwise
441 int rte_pipeline_table_entry_delete(struct rte_pipeline *p,
445 struct rte_pipeline_table_entry *entry);
448 * Pipeline table entry add bulk
451 * Handle to pipeline instance
453 * Table ID (returned by previous invocation of pipeline table create)
455 * Array containing table entry keys
457 * Array containing new contents for every table entry identified by key
459 * Number of keys to add
461 * On successful invocation, key_found for every item in the array is set to
462 * TRUE (value different than 0) if key was already present in the table
463 * before the add operation and to FALSE (value 0) if not
465 * On successful invocation, array *entries_ptr stores pointer to every table
466 * entry associated with key. This can be used for further read-write accesses
467 * to this table entry and is valid until the key is deleted from the table or
468 * re-added (usually for associating different actions and/or action meta-data
469 * to the current key)
471 * 0 on success, error code otherwise
473 int rte_pipeline_table_entry_add_bulk(struct rte_pipeline *p,
476 struct rte_pipeline_table_entry **entries,
479 struct rte_pipeline_table_entry **entries_ptr);
482 * Pipeline table entry delete bulk
485 * Handle to pipeline instance
487 * Table ID (returned by previous invocation of pipeline table create)
489 * Array containing table entry keys
491 * Number of keys to delete
493 * On successful invocation, key_found for every item in the array is set to
494 * TRUE (value different than 0) if key was found in the table before the
495 * delete operation and to FALSE (value 0) if not
497 * If entries pointer is NULL, this pointer is ignored for every entry found.
498 * Else, after successful invocation, if specific key is found in the table
499 * and entry points to a valid buffer, the table entry contents (as it was
500 * before the delete was performed) is copied to this buffer.
502 * 0 on success, error code otherwise
504 int rte_pipeline_table_entry_delete_bulk(struct rte_pipeline *p,
509 struct rte_pipeline_table_entry **entries);
512 * Read pipeline table stats.
514 * This function reads table statistics identified by *table_id* of given
518 * Handle to pipeline instance.
520 * Port ID what stats will be returned.
524 * If not 0 clear stats after reading.
526 * 0 on success, error code otherwise
528 int rte_pipeline_table_stats_read(struct rte_pipeline *p, uint32_t table_id,
529 struct rte_pipeline_table_stats *stats, int clear);
535 /** Maximum number of input ports allowed for any given pipeline instance. The
536 value of this parameter cannot be changed. */
537 #define RTE_PIPELINE_PORT_IN_MAX 64
540 * Pipeline input port action handler
542 * The action handler can decide to drop packets by resetting the associated
543 * packet bit in the pkts_mask parameter. In this case, the action handler is
544 * required not to free the packet buffer, which will be freed eventually by
548 * Handle to pipeline instance
550 * Burst of input packets specified as array of up to 64 pointers to struct
553 * Number of packets in the input burst. This parameter specifies that
554 * elements 0 to (n-1) of pkts array are valid.
556 * Opaque parameter registered by the user at the pipeline table creation
559 * 0 on success, error code otherwise
561 typedef int (*rte_pipeline_port_in_action_handler)(
562 struct rte_pipeline *p,
563 struct rte_mbuf **pkts,
567 /** Parameters for pipeline input port creation */
568 struct rte_pipeline_port_in_params {
569 /** Input port operations (specific to each table type) */
570 struct rte_port_in_ops *ops;
571 /** Opaque parameter to be passed to create operation when invoked */
574 /** Callback function to execute the user actions on input packets.
575 Disabled if set to NULL. */
576 rte_pipeline_port_in_action_handler f_action;
577 /** Opaque parameter to be passed to the action handler when invoked */
580 /** Recommended burst size for the RX operation(in number of pkts) */
585 * Pipeline input port create
588 * Handle to pipeline instance
590 * Parameters for pipeline input port creation
592 * Input port ID. Valid only within the scope of input port IDs of the
593 * current pipeline. Only returned after a successful invocation.
595 * 0 on success, error code otherwise
597 int rte_pipeline_port_in_create(struct rte_pipeline *p,
598 struct rte_pipeline_port_in_params *params,
602 * Pipeline input port connect to table
605 * Handle to pipeline instance
607 * Port ID (returned by previous invocation of pipeline input port create)
609 * Table ID (returned by previous invocation of pipeline table create)
611 * 0 on success, error code otherwise
613 int rte_pipeline_port_in_connect_to_table(struct rte_pipeline *p,
618 * Pipeline input port enable
621 * Handle to pipeline instance
623 * Port ID (returned by previous invocation of pipeline input port create)
625 * 0 on success, error code otherwise
627 int rte_pipeline_port_in_enable(struct rte_pipeline *p,
631 * Pipeline input port disable
634 * Handle to pipeline instance
636 * Port ID (returned by previous invocation of pipeline input port create)
638 * 0 on success, error code otherwise
640 int rte_pipeline_port_in_disable(struct rte_pipeline *p,
644 * Read pipeline port in stats.
646 * This function reads port in statistics identified by *port_id* of given
650 * Handle to pipeline instance.
652 * Port ID what stats will be returned.
656 * If not 0 clear stats after reading.
658 * 0 on success, error code otherwise
660 int rte_pipeline_port_in_stats_read(struct rte_pipeline *p, uint32_t port_id,
661 struct rte_pipeline_port_in_stats *stats, int clear);
667 /** Maximum number of output ports allowed for any given pipeline instance. The
668 value of this parameter cannot be changed. */
669 #define RTE_PIPELINE_PORT_OUT_MAX 64
672 * Pipeline output port action handler
674 * The action handler can decide to drop packets by resetting the associated
675 * packet bit in the pkts_mask parameter. In this case, the action handler is
676 * required not to free the packet buffer, which will be freed eventually by
680 * Handle to pipeline instance
682 * Burst of input packets specified as array of up to 64 pointers to struct
685 * 64-bit bitmask specifying which packets in the input burst are valid. When
686 * pkts_mask bit n is set, then element n of pkts array is pointing to a
687 * valid packet. Otherwise, element n of pkts array will not be accessed.
689 * Opaque parameter registered by the user at the pipeline table creation
692 * 0 on success, error code otherwise
694 typedef int (*rte_pipeline_port_out_action_handler)(
695 struct rte_pipeline *p,
696 struct rte_mbuf **pkts,
700 /** Parameters for pipeline output port creation. The action handlers have to
701 be either both enabled or both disabled (by setting them to NULL). When
702 enabled, the pipeline selects between them at different moments, based on the
703 number of packets that have to be sent to the same output port. */
704 struct rte_pipeline_port_out_params {
705 /** Output port operations (specific to each table type) */
706 struct rte_port_out_ops *ops;
707 /** Opaque parameter to be passed to create operation when invoked */
710 /** Callback function executing the user actions on bust of input
712 rte_pipeline_port_out_action_handler f_action;
713 /** Opaque parameter to be passed to the action handler when invoked */
718 * Pipeline output port create
721 * Handle to pipeline instance
723 * Parameters for pipeline output port creation
725 * Output port ID. Valid only within the scope of output port IDs of the
726 * current pipeline. Only returned after a successful invocation.
728 * 0 on success, error code otherwise
730 int rte_pipeline_port_out_create(struct rte_pipeline *p,
731 struct rte_pipeline_port_out_params *params,
735 * Read pipeline port out stats.
737 * This function reads port out statistics identified by *port_id* of given
741 * Handle to pipeline instance.
743 * Port ID what stats will be returned.
747 * If not 0 clear stats after reading.
749 * 0 on success, error code otherwise
751 int rte_pipeline_port_out_stats_read(struct rte_pipeline *p, uint32_t port_id,
752 struct rte_pipeline_port_out_stats *stats, int clear);
755 * Functions to be called as part of the port IN/OUT or table action handlers
759 * Action handler packet insert to output port
761 * This function can be called by any input/output port or table action handler
762 * to send a packet out through one of the pipeline output ports. This packet is
763 * generated by the action handler, i.e. this packet is not part of the burst of
764 * packets read from one of the pipeline input ports and currently processed by
765 * the pipeline (this packet is not an element of the pkts array input parameter
766 * of the action handler).
769 * Handle to pipeline instance
771 * Output port ID (returned by previous invocation of pipeline output port
772 * create) to send the packet specified by pkt
774 * New packet generated by the action handler
776 * 0 on success, error code otherwise
778 int rte_pipeline_port_out_packet_insert(struct rte_pipeline *p,
780 struct rte_mbuf *pkt);
782 #define rte_pipeline_ah_port_out_packet_insert \
783 rte_pipeline_port_out_packet_insert
786 * Action handler packet hijack
788 * This function can be called by any input/output port or table action handler
789 * to hijack selected packets from the burst of packets read from one of the
790 * pipeline input ports and currently processed by the pipeline. The hijacked
791 * packets are removed from any further pipeline processing, with the action
792 * handler now having the full ownership for these packets.
794 * The action handler can further send the hijacked packets out through any
795 * pipeline output port by calling the rte_pipeline_ah_port_out_packet_insert()
796 * function. The action handler can also drop these packets by calling the
797 * rte_pktmbuf_free() function, although a better alternative is provided by
798 * the action handler using the rte_pipeline_ah_packet_drop() function.
801 * Handle to pipeline instance
803 * 64-bit bitmask specifying which of the packets handed over for processing
804 * to the action handler is to be hijacked by the action handler. When
805 * pkts_mask bit n is set, then element n of the pkts array (input argument to
806 * the action handler) is hijacked.
808 * 0 on success, error code otherwise
810 int rte_pipeline_ah_packet_hijack(struct rte_pipeline *p,
814 * Action handler packet drop
816 * This function is called by the pipeline action handlers (port in/out, table)
817 * to drop the packets selected using packet mask.
819 * This function can be called by any input/output port or table action handler
820 * to drop selected packets from the burst of packets read from one of the
821 * pipeline input ports and currently processed by the pipeline. The dropped
822 * packets are removed from any further pipeline processing and the packet
823 * buffers are eventually freed to their buffer pool.
825 * This function updates the drop statistics counters correctly, therefore the
826 * recommended approach for dropping packets by the action handlers is to call
827 * this function as opposed to the action handler hijacking the packets first
828 * and then dropping them invisibly to the pipeline (by using the
829 * rte_pktmbuf_free() function).
832 * Handle to pipeline instance
834 * 64-bit bitmask specifying which of the packets handed over for processing
835 * to the action handler is to be dropped by the action handler. When
836 * pkts_mask bit n is set, then element n of the pkts array (input argument to
837 * the action handler) is dropped.
839 * 0 on success, error code otherwise
841 int rte_pipeline_ah_packet_drop(struct rte_pipeline *p,