4 * Copyright 2017 Intel Corporation
6 * Copyright 2017 Cavium
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef __INCLUDE_RTE_MTR_H__
36 #define __INCLUDE_RTE_MTR_H__
40 * RTE Generic Traffic Metering and Policing API
42 * This interface provides the ability to configure the traffic metering and
43 * policing (MTR) in a generic way.
45 * The processing done for each input packet hitting a MTR object is:
46 * A) Traffic metering: The packet is assigned a color (the meter output
47 * color), based on the previous history of the flow reflected in the
48 * current state of the MTR object, according to the specific traffic
49 * metering algorithm. The traffic metering algorithm can typically work
50 * in color aware mode, in which case the input packet already has an
51 * initial color (the input color), or in color blind mode, which is
52 * equivalent to considering all input packets initially colored as green.
53 * B) Policing: There is a separate policer action configured for each meter
54 * output color, which can:
56 * b) Keep the same packet color: the policer output color matches the
57 * meter output color (essentially a no-op action).
58 * c) Recolor the packet: the policer output color is different than
59 * the meter output color.
60 * The policer output color is the output color of the packet, which is
61 * set in the packet meta-data (i.e. struct rte_mbuf::sched::color).
62 * C) Statistics: The set of counters maintained for each MTR object is
63 * configurable and subject to the implementation support. This set
64 * includes the number of packets and bytes dropped or passed for each
67 * Once successfully created, an MTR object is linked to one or several flows
68 * through the meter action of the flow API.
69 * A) Whether an MTR object is private to a flow or potentially shared by
70 * several flows has to be specified at creation time.
71 * B) Several meter actions can be potentially registered for the same flow.
74 * @b EXPERIMENTAL: this API may change without prior notice
78 #include <rte_common.h>
88 RTE_MTR_GREEN = 0, /**< Green */
89 RTE_MTR_YELLOW, /**< Yellow */
90 RTE_MTR_RED, /**< Red */
91 RTE_MTR_COLORS /**< Number of colors. */
95 * Statistics counter type
97 enum rte_mtr_stats_type {
98 /** Number of packets passed as green by the policer. */
99 RTE_MTR_STATS_N_PKTS_GREEN = 1 << 0,
101 /** Number of packets passed as yellow by the policer. */
102 RTE_MTR_STATS_N_PKTS_YELLOW = 1 << 1,
104 /** Number of packets passed as red by the policer. */
105 RTE_MTR_STATS_N_PKTS_RED = 1 << 2,
107 /** Number of packets dropped by the policer. */
108 RTE_MTR_STATS_N_PKTS_DROPPED = 1 << 3,
110 /** Number of bytes passed as green by the policer. */
111 RTE_MTR_STATS_N_BYTES_GREEN = 1 << 4,
113 /** Number of bytes passed as yellow by the policer. */
114 RTE_MTR_STATS_N_BYTES_YELLOW = 1 << 5,
116 /** Number of bytes passed as red by the policer. */
117 RTE_MTR_STATS_N_BYTES_RED = 1 << 6,
119 /** Number of bytes dropped by the policer. */
120 RTE_MTR_STATS_N_BYTES_DROPPED = 1 << 7,
124 * Statistics counters
126 struct rte_mtr_stats {
127 /** Number of packets passed by the policer (per color). */
128 uint64_t n_pkts[RTE_MTR_COLORS];
130 /** Number of bytes passed by the policer (per color). */
131 uint64_t n_bytes[RTE_MTR_COLORS];
133 /** Number of packets dropped by the policer. */
134 uint64_t n_pkts_dropped;
136 /** Number of bytes passed by the policer. */
137 uint64_t n_bytes_dropped;
141 * Traffic metering algorithms
143 enum rte_mtr_algorithm {
144 /** No traffic metering performed, the output color is the same as the
145 * input color for every input packet. The meter of the MTR object is
146 * working in pass-through mode, having same effect as meter disable.
147 * @see rte_mtr_meter_disable()
151 /** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */
152 RTE_MTR_SRTCM_RFC2697,
154 /** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */
155 RTE_MTR_TRTCM_RFC2698,
157 /** Two Rate Three Color Marker (trTCM) - IETF RFC 4115. */
158 RTE_MTR_TRTCM_RFC4115,
164 struct rte_mtr_meter_profile {
165 /** Traffic metering algorithm. */
166 enum rte_mtr_algorithm alg;
170 /** Items only valid when *alg* is set to srTCM - RFC 2697. */
172 /** Committed Information Rate (CIR) (bytes/second). */
175 /** Committed Burst Size (CBS) (bytes). */
178 /** Excess Burst Size (EBS) (bytes). */
182 /** Items only valid when *alg* is set to trTCM - RFC 2698. */
184 /** Committed Information Rate (CIR) (bytes/second). */
187 /** Peak Information Rate (PIR) (bytes/second). */
190 /** Committed Burst Size (CBS) (byes). */
193 /** Peak Burst Size (PBS) (bytes). */
197 /** Items only valid when *alg* is set to trTCM - RFC 4115. */
199 /** Committed Information Rate (CIR) (bytes/second). */
202 /** Excess Information Rate (EIR) (bytes/second). */
205 /** Committed Burst Size (CBS) (byes). */
208 /** Excess Burst Size (EBS) (bytes). */
217 enum rte_mtr_policer_action {
218 /** Recolor the packet as green. */
219 MTR_POLICER_ACTION_COLOR_GREEN = 0,
221 /** Recolor the packet as yellow. */
222 MTR_POLICER_ACTION_COLOR_YELLOW,
224 /** Recolor the packet as red. */
225 MTR_POLICER_ACTION_COLOR_RED,
227 /** Drop the packet. */
228 MTR_POLICER_ACTION_DROP,
232 * Parameters for each traffic metering & policing object
234 * @see enum rte_mtr_stats_type
236 struct rte_mtr_params {
237 /** Meter profile ID. */
238 uint32_t meter_profile_id;
240 /** Meter input color in case of MTR object chaining. When non-zero: if
241 * a previous MTR object is enabled in the same flow, then the color
242 * determined by the latest MTR object in the same flow is used as the
243 * input color by the current MTR object, otherwise the current MTR
244 * object uses the *dscp_table* to determine the input color. When zero:
245 * the color determined by any previous MTR object in same flow is
246 * ignored by the current MTR object, which uses the *dscp_table* to
247 * determine the input color.
249 int use_prev_mtr_color;
251 /** Meter input color. When non-NULL: it points to a pre-allocated and
252 * pre-populated table with exactly 64 elements providing the input
253 * color for each value of the IPv4/IPv6 Differentiated Services Code
254 * Point (DSCP) input packet field. When NULL: it is equivalent to
255 * setting this parameter to an all-green populated table (i.e. table
256 * with all the 64 elements set to green color). The color blind mode
257 * is configured by setting *use_prev_mtr_color* to 0 and *dscp_table*
258 * to either NULL or to an all-green populated table. When
259 * *use_prev_mtr_color* is non-zero value or when *dscp_table* contains
260 * at least one yellow or red color element, then the color aware mode
263 enum rte_mtr_color *dscp_table;
265 /** Non-zero to enable the meter, zero to disable the meter at the time
266 * of MTR object creation. Ignored when the meter profile indicated by
267 * *meter_profile_id* is set to NONE.
268 * @see rte_mtr_meter_disable()
272 /** Policer actions (per meter output color). */
273 enum rte_mtr_policer_action action[RTE_MTR_COLORS];
275 /** Set of stats counters to be enabled.
276 * @see enum rte_mtr_stats_type
284 struct rte_mtr_capabilities {
285 /** Maximum number of MTR objects. */
288 /** Maximum number of MTR objects that can be shared by multiple flows.
289 * The value of zero indicates that shared MTR objects are not
290 * supported. The maximum value is *n_max*.
292 uint32_t n_shared_max;
294 /** When non-zero, this flag indicates that all the MTR objects that
295 * cannot be shared by multiple flows have identical capability set.
299 /** When non-zero, this flag indicates that all the MTR objects that
300 * can be shared by multiple flows have identical capability set.
302 int shared_identical;
304 /** Maximum number of flows that can share the same MTR object. The
305 * value of zero is invalid. The value of 1 means that shared MTR
306 * objects not supported.
308 uint32_t shared_n_flows_per_mtr_max;
310 /** Maximum number of MTR objects that can be part of the same flow. The
311 * value of zero is invalid. The value of 1 indicates that MTR object
312 * chaining is not supported. The maximum value is *n_max*.
314 uint32_t chaining_n_mtrs_per_flow_max;
317 * When non-zero, it indicates that the packet color identified by one
318 * MTR object can be used as the packet input color by any subsequent
319 * MTR object from the same flow. When zero, it indicates that the color
320 * determined by one MTR object is always ignored by any subsequent MTR
321 * object from the same flow. Only valid when MTR chaining is supported,
322 * i.e. *chaining_n_mtrs_per_flow_max* is greater than 1. When non-zero,
323 * it also means that the color aware mode is supported by at least one
324 * metering algorithm.
326 int chaining_use_prev_mtr_color_supported;
329 * When non-zero, it indicates that the packet color identified by one
330 * MTR object is always used as the packet input color by any subsequent
331 * MTR object that is part of the same flow. When zero, it indicates
332 * that whether the color determined by one MTR object is either ignored
333 * or used as the packet input color by any subsequent MTR object from
334 * the same flow is individually configurable for each MTR object. Only
335 * valid when *chaining_use_prev_mtr_color_supported* is non-zero.
337 int chaining_use_prev_mtr_color_enforced;
339 /** Maximum number of MTR objects that can have their meter configured
340 * to run the srTCM RFC 2697 algorithm. The value of 0 indicates this
341 * metering algorithm is not supported. The maximum value is *n_max*.
343 uint32_t meter_srtcm_rfc2697_n_max;
345 /** Maximum number of MTR objects that can have their meter configured
346 * to run the trTCM RFC 2698 algorithm. The value of 0 indicates this
347 * metering algorithm is not supported. The maximum value is *n_max*.
349 uint32_t meter_trtcm_rfc2698_n_max;
351 /** Maximum number of MTR objects that can have their meter configured
352 * to run the trTCM RFC 4115 algorithm. The value of 0 indicates this
353 * metering algorithm is not supported. The maximum value is *n_max*.
355 uint32_t meter_trtcm_rfc4115_n_max;
357 /** Maximum traffic rate that can be metered by a single MTR object. For
358 * srTCM RFC 2697, this is the maximum CIR rate. For trTCM RFC 2698,
359 * this is the maximum PIR rate. For trTCM RFC 4115, this is the maximum
360 * value for the sum of PIR and EIR rates.
362 uint64_t meter_rate_max;
365 * When non-zero, it indicates that color aware mode is supported for
366 * the srTCM RFC 2697 metering algorithm.
368 int color_aware_srtcm_rfc2697_supported;
371 * When non-zero, it indicates that color aware mode is supported for
372 * the trTCM RFC 2698 metering algorithm.
374 int color_aware_trtcm_rfc2698_supported;
377 * When non-zero, it indicates that color aware mode is supported for
378 * the trTCM RFC 4115 metering algorithm.
380 int color_aware_trtcm_rfc4115_supported;
382 /** When non-zero, it indicates that the policer packet recolor actions
384 * @see enum rte_mtr_policer_action
386 int policer_action_recolor_supported;
388 /** When non-zero, it indicates that the policer packet drop action is
390 * @see enum rte_mtr_policer_action
392 int policer_action_drop_supported;
394 /** Set of supported statistics counter types.
395 * @see enum rte_mtr_stats_type
401 * Verbose error types.
403 * Most of them provide the type of the object referenced by struct
404 * rte_mtr_error::cause.
406 enum rte_mtr_error_type {
407 RTE_MTR_ERROR_TYPE_NONE, /**< No error. */
408 RTE_MTR_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
409 RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
410 RTE_MTR_ERROR_TYPE_METER_PROFILE,
411 RTE_MTR_ERROR_TYPE_MTR_ID,
412 RTE_MTR_ERROR_TYPE_MTR_PARAMS,
413 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
414 RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW,
415 RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED,
416 RTE_MTR_ERROR_TYPE_STATS_MASK,
417 RTE_MTR_ERROR_TYPE_STATS,
418 RTE_MTR_ERROR_TYPE_SHARED,
422 * Verbose error structure definition.
424 * This object is normally allocated by applications and set by PMDs, the
425 * message points to a constant string which does not need to be freed by
426 * the application, however its pointer can be considered valid only as long
427 * as its associated DPDK port remains configured. Closing the underlying
428 * device or unloading the PMD invalidates it.
430 * Both cause and message may be NULL regardless of the error type.
432 struct rte_mtr_error {
433 enum rte_mtr_error_type type; /**< Cause field and error type. */
434 const void *cause; /**< Object responsible for the error. */
435 const char *message; /**< Human-readable error message. */
439 * MTR capabilities get
442 * The port identifier of the Ethernet device.
444 * MTR capabilities. Needs to be pre-allocated and valid.
446 * Error details. Filled in only on error, when not NULL.
448 * 0 on success, non-zero error code otherwise.
451 rte_mtr_capabilities_get(uint16_t port_id,
452 struct rte_mtr_capabilities *cap,
453 struct rte_mtr_error *error);
458 * Create a new meter profile with ID set to *meter_profile_id*. The new profile
459 * is used to create one or several MTR objects.
462 * The port identifier of the Ethernet device.
463 * @param[in] meter_profile_id
464 * ID for the new meter profile. Needs to be unused by any of the existing
465 * meter profiles added for the current port.
467 * Meter profile parameters. Needs to be pre-allocated and valid.
469 * Error details. Filled in only on error, when not NULL.
471 * 0 on success, non-zero error code otherwise.
474 rte_mtr_meter_profile_add(uint16_t port_id,
475 uint32_t meter_profile_id,
476 struct rte_mtr_meter_profile *profile,
477 struct rte_mtr_error *error);
480 * Meter profile delete
482 * Delete an existing meter profile. This operation fails when there is
483 * currently at least one user (i.e. MTR object) of this profile.
486 * The port identifier of the Ethernet device.
487 * @param[in] meter_profile_id
488 * Meter profile ID. Needs to be the valid.
490 * Error details. Filled in only on error, when not NULL.
492 * 0 on success, non-zero error code otherwise.
495 rte_mtr_meter_profile_delete(uint16_t port_id,
496 uint32_t meter_profile_id,
497 struct rte_mtr_error *error);
502 * Create a new MTR object for the current port. This object is run as part of
503 * associated flow action for traffic metering and policing.
506 * The port identifier of the Ethernet device.
508 * MTR object ID. Needs to be unused by any of the existing MTR objects.
509 * created for the current port.
511 * MTR object params. Needs to be pre-allocated and valid.
513 * Non-zero when this MTR object can be shared by multiple flows, zero when
514 * this MTR object can be used by a single flow.
516 * Error details. Filled in only on error, when not NULL.
518 * 0 on success, non-zero error code otherwise.
520 * @see enum rte_flow_action_type::RTE_FLOW_ACTION_TYPE_METER
523 rte_mtr_create(uint16_t port_id,
525 struct rte_mtr_params *params,
527 struct rte_mtr_error *error);
532 * Delete an existing MTR object. This operation fails when there is currently
533 * at least one user (i.e. flow) of this MTR object.
536 * The port identifier of the Ethernet device.
538 * MTR object ID. Needs to be valid.
539 * created for the current port.
541 * Error details. Filled in only on error, when not NULL.
543 * 0 on success, non-zero error code otherwise.
546 rte_mtr_destroy(uint16_t port_id,
548 struct rte_mtr_error *error);
551 * MTR object meter disable
553 * Disable the meter of an existing MTR object. In disabled state, the meter of
554 * the current MTR object works in pass-through mode, meaning that for each
555 * input packet the meter output color is always the same as the input color. In
556 * particular, when the meter of the current MTR object is configured in color
557 * blind mode, the input color is always green, so the meter output color is
558 * also always green. Note that the policer and the statistics of the current
559 * MTR object are working as usual while the meter is disabled. No action is
560 * taken and this function returns successfully when the meter of the current
561 * MTR object is already disabled.
564 * The port identifier of the Ethernet device.
568 * Error details. Filled in only on error, when not NULL.
570 * 0 on success, non-zero error code otherwise.
573 rte_mtr_meter_disable(uint16_t port_id,
575 struct rte_mtr_error *error);
578 * MTR object meter enable
580 * Enable the meter of an existing MTR object. If the MTR object has its meter
581 * already enabled, then no action is taken and this function returns
585 * The port identifier of the Ethernet device.
589 * Error details. Filled in only on error, when not NULL.
591 * 0 on success, non-zero error code otherwise.
594 rte_mtr_meter_enable(uint16_t port_id,
596 struct rte_mtr_error *error);
599 * MTR object meter profile update
602 * The port identifier of the Ethernet device.
604 * MTR object ID. Needs to be valid.
605 * @param[in] meter_profile_id
606 * Meter profile ID for the current MTR object. Needs to be valid.
608 * Error details. Filled in only on error, when not NULL.
610 * 0 on success, non-zero error code otherwise.
613 rte_mtr_meter_profile_update(uint16_t port_id,
615 uint32_t meter_profile_id,
616 struct rte_mtr_error *error);
619 * MTR object DSCP table update
622 * The port identifier of the Ethernet device.
624 * MTR object ID. Needs to be valid.
625 * @param[in] dscp_table
626 * When non-NULL: it points to a pre-allocated and pre-populated table with
627 * exactly 64 elements providing the input color for each value of the
628 * IPv4/IPv6 Differentiated Services Code Point (DSCP) input packet field.
629 * When NULL: it is equivalent to setting this parameter to an “all-green”
630 * populated table (i.e. table with all the 64 elements set to green color).
632 * Error details. Filled in only on error, when not NULL.
634 * 0 on success, non-zero error code otherwise.
637 rte_mtr_meter_dscp_table_update(uint16_t port_id,
639 enum rte_mtr_color *dscp_table,
640 struct rte_mtr_error *error);
643 * MTR object policer actions update
646 * The port identifier of the Ethernet device.
648 * MTR object ID. Needs to be valid.
649 * @param[in] action_mask
650 * Bit mask indicating which policer actions need to be updated. One or more
651 * policer actions can be updated in a single function invocation. To update
652 * the policer action associated with color C, bit (1 << C) needs to be set in
653 * *action_mask* and element at position C in the *actions* array needs to be
656 * Pre-allocated and pre-populated array of policer actions.
658 * Error details. Filled in only on error, when not NULL.
660 * 0 on success, non-zero error code otherwise.
663 rte_mtr_policer_actions_update(uint16_t port_id,
665 uint32_t action_mask,
666 enum rte_mtr_policer_action *actions,
667 struct rte_mtr_error *error);
670 * MTR object enabled statistics counters update
673 * The port identifier of the Ethernet device.
675 * MTR object ID. Needs to be valid.
676 * @param[in] stats_mask
677 * Mask of statistics counter types to be enabled for the current MTR object.
678 * Any statistics counter type not included in this set is to be disabled for
679 * the current MTR object.
681 * Error details. Filled in only on error, when not NULL.
683 * 0 on success, non-zero error code otherwise.
685 * @see enum rte_mtr_stats_type
688 rte_mtr_stats_update(uint16_t port_id,
691 struct rte_mtr_error *error);
694 * MTR object statistics counters read
697 * The port identifier of the Ethernet device.
699 * MTR object ID. Needs to be valid.
701 * When non-NULL, it contains the current value for the statistics counters
702 * enabled for the current MTR object.
703 * @param[out] stats_mask
704 * When non-NULL, it contains the mask of statistics counter types that are
705 * currently enabled for this MTR object, indicating which of the counters
706 * retrieved with the *stats* structure are valid.
708 * When this parameter has a non-zero value, the statistics counters are
709 * cleared (i.e. set to zero) immediately after they have been read,
710 * otherwise the statistics counters are left untouched.
712 * Error details. Filled in only on error, when not NULL.
714 * 0 on success, non-zero error code otherwise.
716 * @see enum rte_mtr_stats_type
719 rte_mtr_stats_read(uint16_t port_id,
721 struct rte_mtr_stats *stats,
722 uint64_t *stats_mask,
724 struct rte_mtr_error *error);
730 #endif /* __INCLUDE_RTE_MTR_H__ */