4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef __INCLUDE_RTE_PIPELINE_H__
35 #define __INCLUDE_RTE_PIPELINE_H__
45 * This tool is part of the DPDK Packet Framework tool suite and provides
46 * a standard methodology (logically similar to OpenFlow) for rapid development
47 * of complex packet processing pipelines out of ports, tables and actions.
49 * <B>Basic operation.</B> A pipeline is constructed by connecting its input
50 * ports to its output ports through a chain of lookup tables. As result of
51 * lookup operation into the current table, one of the table entries (or the
52 * default table entry, in case of lookup miss) is identified to provide the
53 * actions to be executed on the current packet and the associated action
54 * meta-data. The behavior of user actions is defined through the configurable
55 * table action handler, while the reserved actions define the next hop for the
56 * current packet (either another table, an output port or packet drop) and are
57 * handled transparently by the framework.
59 * <B>Initialization and run-time flows.</B> Once all the pipeline elements
60 * (input ports, tables, output ports) have been created, input ports connected
61 * to tables, table action handlers configured, tables populated with the
62 * initial set of entries (actions and action meta-data) and input ports
63 * enabled, the pipeline runs automatically, pushing packets from input ports
64 * to tables and output ports. At each table, the identified user actions are
65 * being executed, resulting in action meta-data (stored in the table entry)
66 * and packet meta-data (stored with the packet descriptor) being updated. The
67 * pipeline tables can have further updates and input ports can be disabled or
68 * enabled later on as required.
70 * <B>Multi-core scaling.</B> Typically, each CPU core will run its own
71 * pipeline instance. Complex application-level pipelines can be implemented by
72 * interconnecting multiple CPU core-level pipelines in tree-like topologies,
73 * as the same port devices (e.g. SW rings) can serve as output ports for the
74 * pipeline running on CPU core A, as well as input ports for the pipeline
75 * running on CPU core B. This approach enables the application development
76 * using the pipeline (CPU cores connected serially), cluster/run-to-completion
77 * (CPU cores connected in parallel) or mixed (pipeline of CPU core clusters)
80 * <B>Thread safety.</B> It is possible to have multiple pipelines running on
81 * the same CPU core, but it is not allowed (for thread safety reasons) to have
82 * multiple CPU cores running the same pipeline instance.
89 #include <rte_table.h>
90 #include <rte_common.h>
98 /** Opaque data type for pipeline */
101 /** Parameters for pipeline creation */
102 struct rte_pipeline_params {
106 /** CPU socket ID where memory for the pipeline and its elements (ports
107 and tables) should be allocated */
110 /** Offset within packet meta-data to port_id to be used by action
111 "Send packet to output port read from packet meta-data". Has to be
113 uint32_t offset_port_id;
116 /** Pipeline port in stats. */
117 struct rte_pipeline_port_in_stats {
118 /** Port in stats. */
119 struct rte_port_in_stats stats;
121 /** Number of packets dropped by action handler. */
122 uint64_t n_pkts_dropped_by_ah;
126 /** Pipeline port out stats. */
127 struct rte_pipeline_port_out_stats {
128 /** Port out stats. */
129 struct rte_port_out_stats stats;
131 /** Number of packets dropped by action handler. */
132 uint64_t n_pkts_dropped_by_ah;
135 /** Pipeline table stats. */
136 struct rte_pipeline_table_stats {
138 struct rte_table_stats stats;
140 /** Number of packets dropped by lookup hit action handler. */
141 uint64_t n_pkts_dropped_by_lkp_hit_ah;
143 /** Number of packets dropped by lookup miss action handler. */
144 uint64_t n_pkts_dropped_by_lkp_miss_ah;
146 /** Number of packets dropped by pipeline in behalf of this
147 * table based on action specified in table entry. */
148 uint64_t n_pkts_dropped_lkp_hit;
150 /** Number of packets dropped by pipeline in behalf of this
151 * table based on action specified in table entry. */
152 uint64_t n_pkts_dropped_lkp_miss;
159 * Parameters for pipeline creation
161 * Handle to pipeline instance on success or NULL otherwise
163 struct rte_pipeline *rte_pipeline_create(struct rte_pipeline_params *params);
169 * Handle to pipeline instance
171 * 0 on success, error code otherwise
173 int rte_pipeline_free(struct rte_pipeline *p);
176 * Pipeline consistency check
179 * Handle to pipeline instance
181 * 0 on success, error code otherwise
183 int rte_pipeline_check(struct rte_pipeline *p);
189 * Handle to pipeline instance
191 * Number of packets read and processed
193 int rte_pipeline_run(struct rte_pipeline *p);
199 * Handle to pipeline instance
201 * 0 on success, error code otherwise
203 int rte_pipeline_flush(struct rte_pipeline *p);
209 /** Reserved actions */
210 enum rte_pipeline_action {
211 /** Drop the packet */
212 RTE_PIPELINE_ACTION_DROP = 0,
214 /** Send packet to output port */
215 RTE_PIPELINE_ACTION_PORT,
217 /** Send packet to output port read from packet meta-data */
218 RTE_PIPELINE_ACTION_PORT_META,
220 /** Send packet to table */
221 RTE_PIPELINE_ACTION_TABLE,
223 /** Number of reserved actions */
231 /** Maximum number of tables allowed for any given pipeline instance. The
232 value of this parameter cannot be changed. */
233 #define RTE_PIPELINE_TABLE_MAX 64
236 * Head format for the table entry of any pipeline table. For any given
237 * pipeline table, all table entries should have the same size and format. For
238 * any given pipeline table, the table entry has to start with a head of this
239 * structure, which contains the reserved actions and their associated
240 * meta-data, and then optionally continues with user actions and their
241 * associated meta-data. As all the currently defined reserved actions are
242 * mutually exclusive, only one reserved action can be set per table entry.
244 struct rte_pipeline_table_entry {
245 /** Reserved action */
246 enum rte_pipeline_action action;
250 /** Output port ID (meta-data for "Send packet to output port"
253 /** Table ID (meta-data for "Send packet to table" action) */
256 /** Start of table entry area for user defined actions and meta-data */
257 __extension__ uint8_t action_data[0];
261 * Pipeline table action handler on lookup hit
263 * The action handler can decide to drop packets by resetting the associated
264 * packet bit in the pkts_mask parameter. In this case, the action handler is
265 * required not to free the packet buffer, which will be freed eventually by
269 * Handle to pipeline instance
271 * Burst of input packets specified as array of up to 64 pointers to struct
274 * 64-bit bitmask specifying which packets in the input burst are valid. When
275 * pkts_mask bit n is set, then element n of pkts array is pointing to a
276 * valid packet and element n of entries array is pointing to a valid table
277 * entry associated with the packet, with the association typically done by
278 * the table lookup operation. Otherwise, element n of pkts array and element
279 * n of entries array will not be accessed.
281 * Set of table entries specified as array of up to 64 pointers to struct
282 * rte_pipeline_table_entry
284 * Opaque parameter registered by the user at the pipeline table creation
287 * 0 on success, error code otherwise
289 typedef int (*rte_pipeline_table_action_handler_hit)(
290 struct rte_pipeline *p,
291 struct rte_mbuf **pkts,
293 struct rte_pipeline_table_entry **entries,
297 * Pipeline table action handler on lookup miss
299 * The action handler can decide to drop packets by resetting the associated
300 * packet bit in the pkts_mask parameter. In this case, the action handler is
301 * required not to free the packet buffer, which will be freed eventually by
305 * Handle to pipeline instance
307 * Burst of input packets specified as array of up to 64 pointers to struct
310 * 64-bit bitmask specifying which packets in the input burst are valid. When
311 * pkts_mask bit n is set, then element n of pkts array is pointing to a
312 * valid packet. Otherwise, element n of pkts array will not be accessed.
314 * Single table entry associated with all the valid packets from the input
315 * burst, specified as pointer to struct rte_pipeline_table_entry.
316 * This entry is the pipeline table default entry that is associated by the
317 * table lookup operation with the input packets that have resulted in lookup
320 * Opaque parameter registered by the user at the pipeline table creation
323 * 0 on success, error code otherwise
325 typedef int (*rte_pipeline_table_action_handler_miss)(
326 struct rte_pipeline *p,
327 struct rte_mbuf **pkts,
329 struct rte_pipeline_table_entry *entry,
332 /** Parameters for pipeline table creation. Action handlers have to be either
333 both enabled or both disabled (they can be disabled by setting them to
335 struct rte_pipeline_table_params {
336 /** Table operations (specific to each table type) */
337 struct rte_table_ops *ops;
338 /** Opaque param to be passed to the table create operation when
341 /** Callback function to execute the user actions on input packets in
342 case of lookup hit */
343 rte_pipeline_table_action_handler_hit f_action_hit;
344 /** Callback function to execute the user actions on input packets in
345 case of lookup miss */
346 rte_pipeline_table_action_handler_miss f_action_miss;
348 /** Opaque parameter to be passed to lookup hit and/or lookup miss
349 action handlers when invoked */
351 /** Memory size to be reserved per table entry for storing the user
352 actions and their meta-data */
353 uint32_t action_data_size;
357 * Pipeline table create
360 * Handle to pipeline instance
362 * Parameters for pipeline table creation
364 * Table ID. Valid only within the scope of table IDs of the current
365 * pipeline. Only returned after a successful invocation.
367 * 0 on success, error code otherwise
369 int rte_pipeline_table_create(struct rte_pipeline *p,
370 struct rte_pipeline_table_params *params,
374 * Pipeline table default entry add
376 * The contents of the table default entry is updated with the provided actions
377 * and meta-data. When the default entry is not configured (by using this
378 * function), the built-in default entry has the action "Drop" and meta-data
382 * Handle to pipeline instance
384 * Table ID (returned by previous invocation of pipeline table create)
385 * @param default_entry
386 * New contents for the table default entry
387 * @param default_entry_ptr
388 * On successful invocation, pointer to the default table entry which can be
389 * used for further read-write accesses to this table entry. This pointer
390 * is valid until the default entry is deleted or re-added.
392 * 0 on success, error code otherwise
394 int rte_pipeline_table_default_entry_add(struct rte_pipeline *p,
396 struct rte_pipeline_table_entry *default_entry,
397 struct rte_pipeline_table_entry **default_entry_ptr);
400 * Pipeline table default entry delete
402 * The new contents of the table default entry is set to reserved action "Drop
403 * the packet" with meta-data cleared (i.e. set to all-zeros).
406 * Handle to pipeline instance
408 * Table ID (returned by previous invocation of pipeline table create)
410 * On successful invocation, when entry points to a valid buffer, the
411 * previous contents of the table default entry (as it was just before the
412 * delete operation) is copied to this buffer
414 * 0 on success, error code otherwise
416 int rte_pipeline_table_default_entry_delete(struct rte_pipeline *p,
418 struct rte_pipeline_table_entry *entry);
421 * Pipeline table entry add
424 * Handle to pipeline instance
426 * Table ID (returned by previous invocation of pipeline table create)
430 * New contents for the table entry identified by key
432 * On successful invocation, set to TRUE (value different than 0) if key was
433 * already present in the table before the add operation and to FALSE (value
436 * On successful invocation, pointer to the table entry associated with key.
437 * This can be used for further read-write accesses to this table entry and
438 * is valid until the key is deleted from the table or re-added (usually for
439 * associating different actions and/or action meta-data to the current key)
441 * 0 on success, error code otherwise
443 int rte_pipeline_table_entry_add(struct rte_pipeline *p,
446 struct rte_pipeline_table_entry *entry,
448 struct rte_pipeline_table_entry **entry_ptr);
451 * Pipeline table entry delete
454 * Handle to pipeline instance
456 * Table ID (returned by previous invocation of pipeline table create)
460 * On successful invocation, set to TRUE (value different than 0) if key was
461 * found in the table before the delete operation and to FALSE (value 0) if
464 * On successful invocation, when key is found in the table and entry points
465 * to a valid buffer, the table entry contents (as it was before the delete
466 * was performed) is copied to this buffer
468 * 0 on success, error code otherwise
470 int rte_pipeline_table_entry_delete(struct rte_pipeline *p,
474 struct rte_pipeline_table_entry *entry);
477 * Pipeline table entry add bulk
480 * Handle to pipeline instance
482 * Table ID (returned by previous invocation of pipeline table create)
484 * Array containing table entry keys
486 * Array containung new contents for every table entry identified by key
488 * Number of keys to add
490 * On successful invocation, key_found for every item in the array is set to
491 * TRUE (value different than 0) if key was already present in the table
492 * before the add operation and to FALSE (value 0) if not
494 * On successful invocation, array *entries_ptr stores pointer to every table
495 * entry associated with key. This can be used for further read-write accesses
496 * to this table entry and is valid until the key is deleted from the table or
497 * re-added (usually for associating different actions and/or action meta-data
498 * to the current key)
500 * 0 on success, error code otherwise
502 int rte_pipeline_table_entry_add_bulk(struct rte_pipeline *p,
505 struct rte_pipeline_table_entry **entries,
508 struct rte_pipeline_table_entry **entries_ptr);
511 * Pipeline table entry delete bulk
514 * Handle to pipeline instance
516 * Table ID (returned by previous invocation of pipeline table create)
518 * Array containing table entry keys
520 * Number of keys to delete
522 * On successful invocation, key_found for every item in the array is set to
523 * TRUE (value different than 0) if key was found in the table before the
524 * delete operation and to FALSE (value 0) if not
526 * If entries pointer is NULL, this pointer is ignored for every entry found.
527 * Else, after successful invocation, if specific key is found in the table
528 * and entry points to a valid buffer, the table entry contents (as it was
529 * before the delete was performed) is copied to this buffer.
531 * 0 on success, error code otherwise
533 int rte_pipeline_table_entry_delete_bulk(struct rte_pipeline *p,
538 struct rte_pipeline_table_entry **entries);
541 * Read pipeline table stats.
543 * This function reads table statistics identified by *table_id* of given
547 * Handle to pipeline instance.
549 * Port ID what stats will be returned.
553 * If not 0 clear stats after reading.
555 * 0 on success, error code otherwise
557 int rte_pipeline_table_stats_read(struct rte_pipeline *p, uint32_t table_id,
558 struct rte_pipeline_table_stats *stats, int clear);
564 /** Maximum number of input ports allowed for any given pipeline instance. The
565 value of this parameter cannot be changed. */
566 #define RTE_PIPELINE_PORT_IN_MAX 64
569 * Pipeline input port action handler
571 * The action handler can decide to drop packets by resetting the associated
572 * packet bit in the pkts_mask parameter. In this case, the action handler is
573 * required not to free the packet buffer, which will be freed eventually by
577 * Handle to pipeline instance
579 * Burst of input packets specified as array of up to 64 pointers to struct
582 * Number of packets in the input burst. This parameter specifies that
583 * elements 0 to (n-1) of pkts array are valid.
585 * Opaque parameter registered by the user at the pipeline table creation
588 * 0 on success, error code otherwise
590 typedef int (*rte_pipeline_port_in_action_handler)(
591 struct rte_pipeline *p,
592 struct rte_mbuf **pkts,
596 /** Parameters for pipeline input port creation */
597 struct rte_pipeline_port_in_params {
598 /** Input port operations (specific to each table type) */
599 struct rte_port_in_ops *ops;
600 /** Opaque parameter to be passed to create operation when invoked */
603 /** Callback function to execute the user actions on input packets.
604 Disabled if set to NULL. */
605 rte_pipeline_port_in_action_handler f_action;
606 /** Opaque parameter to be passed to the action handler when invoked */
609 /** Recommended burst size for the RX operation(in number of pkts) */
614 * Pipeline input port create
617 * Handle to pipeline instance
619 * Parameters for pipeline input port creation
621 * Input port ID. Valid only within the scope of input port IDs of the
622 * current pipeline. Only returned after a successful invocation.
624 * 0 on success, error code otherwise
626 int rte_pipeline_port_in_create(struct rte_pipeline *p,
627 struct rte_pipeline_port_in_params *params,
631 * Pipeline input port connect to table
634 * Handle to pipeline instance
636 * Port ID (returned by previous invocation of pipeline input port create)
638 * Table ID (returned by previous invocation of pipeline table create)
640 * 0 on success, error code otherwise
642 int rte_pipeline_port_in_connect_to_table(struct rte_pipeline *p,
647 * Pipeline input port enable
650 * Handle to pipeline instance
652 * Port ID (returned by previous invocation of pipeline input port create)
654 * 0 on success, error code otherwise
656 int rte_pipeline_port_in_enable(struct rte_pipeline *p,
660 * Pipeline input port disable
663 * Handle to pipeline instance
665 * Port ID (returned by previous invocation of pipeline input port create)
667 * 0 on success, error code otherwise
669 int rte_pipeline_port_in_disable(struct rte_pipeline *p,
673 * Read pipeline port in stats.
675 * This function reads port in statistics identified by *port_id* of given
679 * Handle to pipeline instance.
681 * Port ID what stats will be returned.
685 * If not 0 clear stats after reading.
687 * 0 on success, error code otherwise
689 int rte_pipeline_port_in_stats_read(struct rte_pipeline *p, uint32_t port_id,
690 struct rte_pipeline_port_in_stats *stats, int clear);
696 /** Maximum number of output ports allowed for any given pipeline instance. The
697 value of this parameter cannot be changed. */
698 #define RTE_PIPELINE_PORT_OUT_MAX 64
701 * Pipeline output port action handler
703 * The action handler can decide to drop packets by resetting the associated
704 * packet bit in the pkts_mask parameter. In this case, the action handler is
705 * required not to free the packet buffer, which will be freed eventually by
709 * Handle to pipeline instance
711 * Burst of input packets specified as array of up to 64 pointers to struct
714 * 64-bit bitmask specifying which packets in the input burst are valid. When
715 * pkts_mask bit n is set, then element n of pkts array is pointing to a
716 * valid packet. Otherwise, element n of pkts array will not be accessed.
718 * Opaque parameter registered by the user at the pipeline table creation
721 * 0 on success, error code otherwise
723 typedef int (*rte_pipeline_port_out_action_handler)(
724 struct rte_pipeline *p,
725 struct rte_mbuf **pkts,
729 /** Parameters for pipeline output port creation. The action handlers have to
730 be either both enabled or both disabled (by setting them to NULL). When
731 enabled, the pipeline selects between them at different moments, based on the
732 number of packets that have to be sent to the same output port. */
733 struct rte_pipeline_port_out_params {
734 /** Output port operations (specific to each table type) */
735 struct rte_port_out_ops *ops;
736 /** Opaque parameter to be passed to create operation when invoked */
739 /** Callback function executing the user actions on bust of input
741 rte_pipeline_port_out_action_handler f_action;
742 /** Opaque parameter to be passed to the action handler when invoked */
747 * Pipeline output port create
750 * Handle to pipeline instance
752 * Parameters for pipeline output port creation
754 * Output port ID. Valid only within the scope of output port IDs of the
755 * current pipeline. Only returned after a successful invocation.
757 * 0 on success, error code otherwise
759 int rte_pipeline_port_out_create(struct rte_pipeline *p,
760 struct rte_pipeline_port_out_params *params,
764 * Read pipeline port out stats.
766 * This function reads port out statistics identified by *port_id* of given
770 * Handle to pipeline instance.
772 * Port ID what stats will be returned.
776 * If not 0 clear stats after reading.
778 * 0 on success, error code otherwise
780 int rte_pipeline_port_out_stats_read(struct rte_pipeline *p, uint32_t port_id,
781 struct rte_pipeline_port_out_stats *stats, int clear);
784 * Functions to be called as part of the port IN/OUT or table action handlers
788 * Action handler packet insert to output port
790 * This function can be called by any input/output port or table action handler
791 * to send a packet out through one of the pipeline output ports. This packet is
792 * generated by the action handler, i.e. this packet is not part of the burst of
793 * packets read from one of the pipeline input ports and currently processed by
794 * the pipeline (this packet is not an element of the pkts array input parameter
795 * of the action handler).
798 * Handle to pipeline instance
800 * Output port ID (returned by previous invocation of pipeline output port
801 * create) to send the packet specified by pkt
803 * New packet generated by the action handler
805 * 0 on success, error code otherwise
807 int rte_pipeline_port_out_packet_insert(struct rte_pipeline *p,
809 struct rte_mbuf *pkt);
811 #define rte_pipeline_ah_port_out_packet_insert \
812 rte_pipeline_port_out_packet_insert
815 * Action handler packet hijack
817 * This function can be called by any input/output port or table action handler
818 * to hijack selected packets from the burst of packets read from one of the
819 * pipeline input ports and currently processed by the pipeline. The hijacked
820 * packets are removed from any further pipeline processing, with the action
821 * handler now having the full ownership for these packets.
823 * The action handler can further send the hijacked packets out through any
824 * pipeline output port by calling the rte_pipeline_ah_port_out_packet_insert()
825 * function. The action handler can also drop these packets by calling the
826 * rte_pktmbuf_free() function, although a better alternative is provided by
827 * the action handler using the rte_pipeline_ah_packet_drop() function.
830 * Handle to pipeline instance
832 * 64-bit bitmask specifying which of the packets handed over for processing
833 * to the action handler is to be hijacked by the action handler. When
834 * pkts_mask bit n is set, then element n of the pkts array (input argument to
835 * the action handler) is hijacked.
837 * 0 on success, error code otherwise
839 int rte_pipeline_ah_packet_hijack(struct rte_pipeline *p,
843 * Action handler packet drop
845 * This function is called by the pipeline action handlers (port in/out, table)
846 * to drop the packets selected using packet mask.
848 * This function can be called by any input/output port or table action handler
849 * to drop selected packets from the burst of packets read from one of the
850 * pipeline input ports and currently processed by the pipeline. The dropped
851 * packets are removed from any further pipeline processing and the packet
852 * buffers are eventually freed to their buffer pool.
854 * This function updates the drop statistics counters correctly, therefore the
855 * recommended approach for dropping packets by the action handlers is to call
856 * this function as opposed to the action handler hijacking the packets first
857 * and then dropping them invisibly to the pipeline (by using the
858 * rte_pktmbuf_free() function).
861 * Handle to pipeline instance
863 * 64-bit bitmask specifying which of the packets handed over for processing
864 * to the action handler is to be dropped by the action handler. When
865 * pkts_mask bit n is set, then element n of the pkts array (input argument to
866 * the action handler) is dropped.
868 * 0 on success, error code otherwise
870 int rte_pipeline_ah_packet_drop(struct rte_pipeline *p,