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
77 #include <rte_compat.h>
78 #include <rte_common.h>
79 #include <rte_meter.h>
85 /* New rte_color is defined and used to deprecate rte_mtr_color soon. */
86 #define rte_mtr_color rte_color
87 #define RTE_MTR_GREEN RTE_COLOR_GREEN
88 #define RTE_MTR_YELLOW RTE_COLOR_YELLOW
89 #define RTE_MTR_RED RTE_COLOR_RED
90 #define RTE_MTR_COLORS RTE_COLORS
93 * Statistics counter type
95 enum rte_mtr_stats_type {
96 /** Number of packets passed as green by the policer. */
97 RTE_MTR_STATS_N_PKTS_GREEN = 1 << 0,
99 /** Number of packets passed as yellow by the policer. */
100 RTE_MTR_STATS_N_PKTS_YELLOW = 1 << 1,
102 /** Number of packets passed as red by the policer. */
103 RTE_MTR_STATS_N_PKTS_RED = 1 << 2,
105 /** Number of packets dropped by the policer. */
106 RTE_MTR_STATS_N_PKTS_DROPPED = 1 << 3,
108 /** Number of bytes passed as green by the policer. */
109 RTE_MTR_STATS_N_BYTES_GREEN = 1 << 4,
111 /** Number of bytes passed as yellow by the policer. */
112 RTE_MTR_STATS_N_BYTES_YELLOW = 1 << 5,
114 /** Number of bytes passed as red by the policer. */
115 RTE_MTR_STATS_N_BYTES_RED = 1 << 6,
117 /** Number of bytes dropped by the policer. */
118 RTE_MTR_STATS_N_BYTES_DROPPED = 1 << 7,
122 * Statistics counters
124 struct rte_mtr_stats {
125 /** Number of packets passed by the policer (per color). */
126 uint64_t n_pkts[RTE_MTR_COLORS];
128 /** Number of bytes passed by the policer (per color). */
129 uint64_t n_bytes[RTE_MTR_COLORS];
131 /** Number of packets dropped by the policer. */
132 uint64_t n_pkts_dropped;
134 /** Number of bytes passed by the policer. */
135 uint64_t n_bytes_dropped;
139 * Traffic metering algorithms
141 enum rte_mtr_algorithm {
142 /** No traffic metering performed, the output color is the same as the
143 * input color for every input packet. The meter of the MTR object is
144 * working in pass-through mode, having same effect as meter disable.
145 * @see rte_mtr_meter_disable()
149 /** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */
150 RTE_MTR_SRTCM_RFC2697,
152 /** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */
153 RTE_MTR_TRTCM_RFC2698,
155 /** Two Rate Three Color Marker (trTCM) - IETF RFC 4115. */
156 RTE_MTR_TRTCM_RFC4115,
162 struct rte_mtr_meter_profile {
163 /** Traffic metering algorithm. */
164 enum rte_mtr_algorithm alg;
168 /** Items only valid when *alg* is set to srTCM - RFC 2697. */
170 /** Committed Information Rate (CIR) (bytes/second). */
173 /** Committed Burst Size (CBS) (bytes). */
176 /** Excess Burst Size (EBS) (bytes). */
180 /** Items only valid when *alg* is set to trTCM - RFC 2698. */
182 /** Committed Information Rate (CIR) (bytes/second). */
185 /** Peak Information Rate (PIR) (bytes/second). */
188 /** Committed Burst Size (CBS) (byes). */
191 /** Peak Burst Size (PBS) (bytes). */
195 /** Items only valid when *alg* is set to trTCM - RFC 4115. */
197 /** Committed Information Rate (CIR) (bytes/second). */
200 /** Excess Information Rate (EIR) (bytes/second). */
203 /** Committed Burst Size (CBS) (byes). */
206 /** Excess Burst Size (EBS) (bytes). */
215 enum rte_mtr_policer_action {
216 /** Recolor the packet as green. */
217 MTR_POLICER_ACTION_COLOR_GREEN = 0,
219 /** Recolor the packet as yellow. */
220 MTR_POLICER_ACTION_COLOR_YELLOW,
222 /** Recolor the packet as red. */
223 MTR_POLICER_ACTION_COLOR_RED,
225 /** Drop the packet. */
226 MTR_POLICER_ACTION_DROP,
230 * Parameters for each traffic metering & policing object
232 * @see enum rte_mtr_stats_type
234 struct rte_mtr_params {
235 /** Meter profile ID. */
236 uint32_t meter_profile_id;
238 /** Meter input color in case of MTR object chaining. When non-zero: if
239 * a previous MTR object is enabled in the same flow, then the color
240 * determined by the latest MTR object in the same flow is used as the
241 * input color by the current MTR object, otherwise the current MTR
242 * object uses the *dscp_table* to determine the input color. When zero:
243 * the color determined by any previous MTR object in same flow is
244 * ignored by the current MTR object, which uses the *dscp_table* to
245 * determine the input color.
247 int use_prev_mtr_color;
249 /** Meter input color. When non-NULL: it points to a pre-allocated and
250 * pre-populated table with exactly 64 elements providing the input
251 * color for each value of the IPv4/IPv6 Differentiated Services Code
252 * Point (DSCP) input packet field. When NULL: it is equivalent to
253 * setting this parameter to an all-green populated table (i.e. table
254 * with all the 64 elements set to green color). The color blind mode
255 * is configured by setting *use_prev_mtr_color* to 0 and *dscp_table*
256 * to either NULL or to an all-green populated table. When
257 * *use_prev_mtr_color* is non-zero value or when *dscp_table* contains
258 * at least one yellow or red color element, then the color aware mode
261 enum rte_mtr_color *dscp_table;
263 /** Non-zero to enable the meter, zero to disable the meter at the time
264 * of MTR object creation. Ignored when the meter profile indicated by
265 * *meter_profile_id* is set to NONE.
266 * @see rte_mtr_meter_disable()
270 /** Policer actions (per meter output color). */
271 enum rte_mtr_policer_action action[RTE_MTR_COLORS];
273 /** Set of stats counters to be enabled.
274 * @see enum rte_mtr_stats_type
282 struct rte_mtr_capabilities {
283 /** Maximum number of MTR objects. */
286 /** Maximum number of MTR objects that can be shared by multiple flows.
287 * The value of zero indicates that shared MTR objects are not
288 * supported. The maximum value is *n_max*.
290 uint32_t n_shared_max;
292 /** When non-zero, this flag indicates that all the MTR objects that
293 * cannot be shared by multiple flows have identical capability set.
297 /** When non-zero, this flag indicates that all the MTR objects that
298 * can be shared by multiple flows have identical capability set.
300 int shared_identical;
302 /** Maximum number of flows that can share the same MTR object. The
303 * value of zero is invalid. The value of 1 means that shared MTR
304 * objects not supported.
306 uint32_t shared_n_flows_per_mtr_max;
308 /** Maximum number of MTR objects that can be part of the same flow. The
309 * value of zero is invalid. The value of 1 indicates that MTR object
310 * chaining is not supported. The maximum value is *n_max*.
312 uint32_t chaining_n_mtrs_per_flow_max;
315 * When non-zero, it indicates that the packet color identified by one
316 * MTR object can be used as the packet input color by any subsequent
317 * MTR object from the same flow. When zero, it indicates that the color
318 * determined by one MTR object is always ignored by any subsequent MTR
319 * object from the same flow. Only valid when MTR chaining is supported,
320 * i.e. *chaining_n_mtrs_per_flow_max* is greater than 1. When non-zero,
321 * it also means that the color aware mode is supported by at least one
322 * metering algorithm.
324 int chaining_use_prev_mtr_color_supported;
327 * When non-zero, it indicates that the packet color identified by one
328 * MTR object is always used as the packet input color by any subsequent
329 * MTR object that is part of the same flow. When zero, it indicates
330 * that whether the color determined by one MTR object is either ignored
331 * or used as the packet input color by any subsequent MTR object from
332 * the same flow is individually configurable for each MTR object. Only
333 * valid when *chaining_use_prev_mtr_color_supported* is non-zero.
335 int chaining_use_prev_mtr_color_enforced;
337 /** Maximum number of MTR objects that can have their meter configured
338 * to run the srTCM RFC 2697 algorithm. The value of 0 indicates this
339 * metering algorithm is not supported. The maximum value is *n_max*.
341 uint32_t meter_srtcm_rfc2697_n_max;
343 /** Maximum number of MTR objects that can have their meter configured
344 * to run the trTCM RFC 2698 algorithm. The value of 0 indicates this
345 * metering algorithm is not supported. The maximum value is *n_max*.
347 uint32_t meter_trtcm_rfc2698_n_max;
349 /** Maximum number of MTR objects that can have their meter configured
350 * to run the trTCM RFC 4115 algorithm. The value of 0 indicates this
351 * metering algorithm is not supported. The maximum value is *n_max*.
353 uint32_t meter_trtcm_rfc4115_n_max;
355 /** Maximum traffic rate that can be metered by a single MTR object. For
356 * srTCM RFC 2697, this is the maximum CIR rate. For trTCM RFC 2698,
357 * this is the maximum PIR rate. For trTCM RFC 4115, this is the maximum
358 * value for the sum of PIR and EIR rates.
360 uint64_t meter_rate_max;
363 * When non-zero, it indicates that color aware mode is supported for
364 * the srTCM RFC 2697 metering algorithm.
366 int color_aware_srtcm_rfc2697_supported;
369 * When non-zero, it indicates that color aware mode is supported for
370 * the trTCM RFC 2698 metering algorithm.
372 int color_aware_trtcm_rfc2698_supported;
375 * When non-zero, it indicates that color aware mode is supported for
376 * the trTCM RFC 4115 metering algorithm.
378 int color_aware_trtcm_rfc4115_supported;
380 /** When non-zero, it indicates that the policer packet recolor actions
382 * @see enum rte_mtr_policer_action
384 int policer_action_recolor_supported;
386 /** When non-zero, it indicates that the policer packet drop action is
388 * @see enum rte_mtr_policer_action
390 int policer_action_drop_supported;
392 /** Set of supported statistics counter types.
393 * @see enum rte_mtr_stats_type
399 * Verbose error types.
401 * Most of them provide the type of the object referenced by struct
402 * rte_mtr_error::cause.
404 enum rte_mtr_error_type {
405 RTE_MTR_ERROR_TYPE_NONE, /**< No error. */
406 RTE_MTR_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
407 RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
408 RTE_MTR_ERROR_TYPE_METER_PROFILE,
409 RTE_MTR_ERROR_TYPE_MTR_ID,
410 RTE_MTR_ERROR_TYPE_MTR_PARAMS,
411 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
412 RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW,
413 RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED,
414 RTE_MTR_ERROR_TYPE_STATS_MASK,
415 RTE_MTR_ERROR_TYPE_STATS,
416 RTE_MTR_ERROR_TYPE_SHARED,
420 * Verbose error structure definition.
422 * This object is normally allocated by applications and set by PMDs, the
423 * message points to a constant string which does not need to be freed by
424 * the application, however its pointer can be considered valid only as long
425 * as its associated DPDK port remains configured. Closing the underlying
426 * device or unloading the PMD invalidates it.
428 * Both cause and message may be NULL regardless of the error type.
430 struct rte_mtr_error {
431 enum rte_mtr_error_type type; /**< Cause field and error type. */
432 const void *cause; /**< Object responsible for the error. */
433 const char *message; /**< Human-readable error message. */
437 * MTR capabilities get
440 * The port identifier of the Ethernet device.
442 * MTR capabilities. Needs to be pre-allocated and valid.
444 * Error details. Filled in only on error, when not NULL.
446 * 0 on success, non-zero error code otherwise.
448 int __rte_experimental
449 rte_mtr_capabilities_get(uint16_t port_id,
450 struct rte_mtr_capabilities *cap,
451 struct rte_mtr_error *error);
456 * Create a new meter profile with ID set to *meter_profile_id*. The new profile
457 * is used to create one or several MTR objects.
460 * The port identifier of the Ethernet device.
461 * @param[in] meter_profile_id
462 * ID for the new meter profile. Needs to be unused by any of the existing
463 * meter profiles added for the current port.
465 * Meter profile parameters. Needs to be pre-allocated and valid.
467 * Error details. Filled in only on error, when not NULL.
469 * 0 on success, non-zero error code otherwise.
471 int __rte_experimental
472 rte_mtr_meter_profile_add(uint16_t port_id,
473 uint32_t meter_profile_id,
474 struct rte_mtr_meter_profile *profile,
475 struct rte_mtr_error *error);
478 * Meter profile delete
480 * Delete an existing meter profile. This operation fails when there is
481 * currently at least one user (i.e. MTR object) of this profile.
484 * The port identifier of the Ethernet device.
485 * @param[in] meter_profile_id
486 * Meter profile ID. Needs to be the valid.
488 * Error details. Filled in only on error, when not NULL.
490 * 0 on success, non-zero error code otherwise.
492 int __rte_experimental
493 rte_mtr_meter_profile_delete(uint16_t port_id,
494 uint32_t meter_profile_id,
495 struct rte_mtr_error *error);
500 * Create a new MTR object for the current port. This object is run as part of
501 * associated flow action for traffic metering and policing.
504 * The port identifier of the Ethernet device.
506 * MTR object ID. Needs to be unused by any of the existing MTR objects.
507 * created for the current port.
509 * MTR object params. Needs to be pre-allocated and valid.
511 * Non-zero when this MTR object can be shared by multiple flows, zero when
512 * this MTR object can be used by a single flow.
514 * Error details. Filled in only on error, when not NULL.
516 * 0 on success, non-zero error code otherwise.
518 * @see enum rte_flow_action_type::RTE_FLOW_ACTION_TYPE_METER
520 int __rte_experimental
521 rte_mtr_create(uint16_t port_id,
523 struct rte_mtr_params *params,
525 struct rte_mtr_error *error);
530 * Delete an existing MTR object. This operation fails when there is currently
531 * at least one user (i.e. flow) of this MTR object.
534 * The port identifier of the Ethernet device.
536 * MTR object ID. Needs to be valid.
537 * created for the current port.
539 * Error details. Filled in only on error, when not NULL.
541 * 0 on success, non-zero error code otherwise.
543 int __rte_experimental
544 rte_mtr_destroy(uint16_t port_id,
546 struct rte_mtr_error *error);
549 * MTR object meter disable
551 * Disable the meter of an existing MTR object. In disabled state, the meter of
552 * the current MTR object works in pass-through mode, meaning that for each
553 * input packet the meter output color is always the same as the input color. In
554 * particular, when the meter of the current MTR object is configured in color
555 * blind mode, the input color is always green, so the meter output color is
556 * also always green. Note that the policer and the statistics of the current
557 * MTR object are working as usual while the meter is disabled. No action is
558 * taken and this function returns successfully when the meter of the current
559 * MTR object is already disabled.
562 * The port identifier of the Ethernet device.
566 * Error details. Filled in only on error, when not NULL.
568 * 0 on success, non-zero error code otherwise.
570 int __rte_experimental
571 rte_mtr_meter_disable(uint16_t port_id,
573 struct rte_mtr_error *error);
576 * MTR object meter enable
578 * Enable the meter of an existing MTR object. If the MTR object has its meter
579 * already enabled, then no action is taken and this function returns
583 * The port identifier of the Ethernet device.
587 * Error details. Filled in only on error, when not NULL.
589 * 0 on success, non-zero error code otherwise.
591 int __rte_experimental
592 rte_mtr_meter_enable(uint16_t port_id,
594 struct rte_mtr_error *error);
597 * MTR object meter profile update
600 * The port identifier of the Ethernet device.
602 * MTR object ID. Needs to be valid.
603 * @param[in] meter_profile_id
604 * Meter profile ID for the current MTR object. Needs to be valid.
606 * Error details. Filled in only on error, when not NULL.
608 * 0 on success, non-zero error code otherwise.
610 int __rte_experimental
611 rte_mtr_meter_profile_update(uint16_t port_id,
613 uint32_t meter_profile_id,
614 struct rte_mtr_error *error);
617 * MTR object DSCP table update
620 * The port identifier of the Ethernet device.
622 * MTR object ID. Needs to be valid.
623 * @param[in] dscp_table
624 * When non-NULL: it points to a pre-allocated and pre-populated table with
625 * exactly 64 elements providing the input color for each value of the
626 * IPv4/IPv6 Differentiated Services Code Point (DSCP) input packet field.
627 * When NULL: it is equivalent to setting this parameter to an “all-green”
628 * populated table (i.e. table with all the 64 elements set to green color).
630 * Error details. Filled in only on error, when not NULL.
632 * 0 on success, non-zero error code otherwise.
634 int __rte_experimental
635 rte_mtr_meter_dscp_table_update(uint16_t port_id,
637 enum rte_mtr_color *dscp_table,
638 struct rte_mtr_error *error);
641 * MTR object policer actions update
644 * The port identifier of the Ethernet device.
646 * MTR object ID. Needs to be valid.
647 * @param[in] action_mask
648 * Bit mask indicating which policer actions need to be updated. One or more
649 * policer actions can be updated in a single function invocation. To update
650 * the policer action associated with color C, bit (1 << C) needs to be set in
651 * *action_mask* and element at position C in the *actions* array needs to be
654 * Pre-allocated and pre-populated array of policer actions.
656 * Error details. Filled in only on error, when not NULL.
658 * 0 on success, non-zero error code otherwise.
660 int __rte_experimental
661 rte_mtr_policer_actions_update(uint16_t port_id,
663 uint32_t action_mask,
664 enum rte_mtr_policer_action *actions,
665 struct rte_mtr_error *error);
668 * MTR object enabled statistics counters update
671 * The port identifier of the Ethernet device.
673 * MTR object ID. Needs to be valid.
674 * @param[in] stats_mask
675 * Mask of statistics counter types to be enabled for the current MTR object.
676 * Any statistics counter type not included in this set is to be disabled for
677 * the current MTR object.
679 * Error details. Filled in only on error, when not NULL.
681 * 0 on success, non-zero error code otherwise.
683 * @see enum rte_mtr_stats_type
685 int __rte_experimental
686 rte_mtr_stats_update(uint16_t port_id,
689 struct rte_mtr_error *error);
692 * MTR object statistics counters read
695 * The port identifier of the Ethernet device.
697 * MTR object ID. Needs to be valid.
699 * When non-NULL, it contains the current value for the statistics counters
700 * enabled for the current MTR object.
701 * @param[out] stats_mask
702 * When non-NULL, it contains the mask of statistics counter types that are
703 * currently enabled for this MTR object, indicating which of the counters
704 * retrieved with the *stats* structure are valid.
706 * When this parameter has a non-zero value, the statistics counters are
707 * cleared (i.e. set to zero) immediately after they have been read,
708 * otherwise the statistics counters are left untouched.
710 * Error details. Filled in only on error, when not NULL.
712 * 0 on success, non-zero error code otherwise.
714 * @see enum rte_mtr_stats_type
716 int __rte_experimental
717 rte_mtr_stats_read(uint16_t port_id,
719 struct rte_mtr_stats *stats,
720 uint64_t *stats_mask,
722 struct rte_mtr_error *error);
728 #endif /* __INCLUDE_RTE_MTR_H__ */