1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 Intel Corporation
4 * Copyright 2017 Cavium
7 #ifndef __INCLUDE_RTE_MTR_H__
8 #define __INCLUDE_RTE_MTR_H__
12 * RTE Generic Traffic Metering and Policing API
14 * This interface provides the ability to configure the traffic metering and
15 * policing (MTR) in a generic way.
17 * The processing done for each input packet hitting a MTR object is:
18 * A) Traffic metering: The packet is assigned a color (the meter output
19 * color), based on the previous history of the flow reflected in the
20 * current state of the MTR object, according to the specific traffic
21 * metering algorithm. The traffic metering algorithm can typically work
22 * in color aware mode, in which case the input packet already has an
23 * initial color (the input color), or in color blind mode, which is
24 * equivalent to considering all input packets initially colored as green.
25 * B) Policing: There is a separate policer action configured for each meter
26 * output color, which can:
28 * b) Keep the same packet color: the policer output color matches the
29 * meter output color (essentially a no-op action).
30 * c) Recolor the packet: the policer output color is different than
31 * the meter output color.
32 * The policer output color is the output color of the packet, which is
33 * set in the packet meta-data (i.e. struct rte_mbuf::sched::color).
34 * C) Statistics: The set of counters maintained for each MTR object is
35 * configurable and subject to the implementation support. This set
36 * includes the number of packets and bytes dropped or passed for each
39 * Once successfully created, an MTR object is linked to one or several flows
40 * through the meter action of the flow API.
41 * A) Whether an MTR object is private to a flow or potentially shared by
42 * several flows has to be specified at creation time.
43 * B) Several meter actions can be potentially registered for the same flow.
46 * @b EXPERIMENTAL: this API may change without prior notice
49 #include <rte_compat.h>
50 #include <rte_common.h>
51 #include <rte_meter.h>
58 * Statistics counter type
60 enum rte_mtr_stats_type {
61 /** Number of packets passed as green by the policer. */
62 RTE_MTR_STATS_N_PKTS_GREEN = 1 << 0,
64 /** Number of packets passed as yellow by the policer. */
65 RTE_MTR_STATS_N_PKTS_YELLOW = 1 << 1,
67 /** Number of packets passed as red by the policer. */
68 RTE_MTR_STATS_N_PKTS_RED = 1 << 2,
70 /** Number of packets dropped by the policer. */
71 RTE_MTR_STATS_N_PKTS_DROPPED = 1 << 3,
73 /** Number of bytes passed as green by the policer. */
74 RTE_MTR_STATS_N_BYTES_GREEN = 1 << 4,
76 /** Number of bytes passed as yellow by the policer. */
77 RTE_MTR_STATS_N_BYTES_YELLOW = 1 << 5,
79 /** Number of bytes passed as red by the policer. */
80 RTE_MTR_STATS_N_BYTES_RED = 1 << 6,
82 /** Number of bytes dropped by the policer. */
83 RTE_MTR_STATS_N_BYTES_DROPPED = 1 << 7,
89 struct rte_mtr_stats {
90 /** Number of packets passed by the policer (per color). */
91 uint64_t n_pkts[RTE_COLORS];
93 /** Number of bytes passed by the policer (per color). */
94 uint64_t n_bytes[RTE_COLORS];
96 /** Number of packets dropped by the policer. */
97 uint64_t n_pkts_dropped;
99 /** Number of bytes passed by the policer. */
100 uint64_t n_bytes_dropped;
104 * Traffic metering algorithms
106 enum rte_mtr_algorithm {
107 /** No traffic metering performed, the output color is the same as the
108 * input color for every input packet. The meter of the MTR object is
109 * working in pass-through mode, having same effect as meter disable.
110 * @see rte_mtr_meter_disable()
114 /** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */
115 RTE_MTR_SRTCM_RFC2697,
117 /** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */
118 RTE_MTR_TRTCM_RFC2698,
120 /** Two Rate Three Color Marker (trTCM) - IETF RFC 4115. */
121 RTE_MTR_TRTCM_RFC4115,
127 struct rte_mtr_meter_profile {
128 /** Traffic metering algorithm. */
129 enum rte_mtr_algorithm alg;
133 /** Items only valid when *alg* is set to srTCM - RFC 2697. */
135 /** Committed Information Rate (CIR) (bytes/second). */
138 /** Committed Burst Size (CBS) (bytes). */
141 /** Excess Burst Size (EBS) (bytes). */
145 /** Items only valid when *alg* is set to trTCM - RFC 2698. */
147 /** Committed Information Rate (CIR) (bytes/second). */
150 /** Peak Information Rate (PIR) (bytes/second). */
153 /** Committed Burst Size (CBS) (byes). */
156 /** Peak Burst Size (PBS) (bytes). */
160 /** Items only valid when *alg* is set to trTCM - RFC 4115. */
162 /** Committed Information Rate (CIR) (bytes/second). */
165 /** Excess Information Rate (EIR) (bytes/second). */
168 /** Committed Burst Size (CBS) (byes). */
171 /** Excess Burst Size (EBS) (bytes). */
180 enum rte_mtr_policer_action {
181 /** Recolor the packet as green. */
182 MTR_POLICER_ACTION_COLOR_GREEN = 0,
184 /** Recolor the packet as yellow. */
185 MTR_POLICER_ACTION_COLOR_YELLOW,
187 /** Recolor the packet as red. */
188 MTR_POLICER_ACTION_COLOR_RED,
190 /** Drop the packet. */
191 MTR_POLICER_ACTION_DROP,
195 * Parameters for each traffic metering & policing object
197 * @see enum rte_mtr_stats_type
199 struct rte_mtr_params {
200 /** Meter profile ID. */
201 uint32_t meter_profile_id;
203 /** Meter input color in case of MTR object chaining. When non-zero: if
204 * a previous MTR object is enabled in the same flow, then the color
205 * determined by the latest MTR object in the same flow is used as the
206 * input color by the current MTR object, otherwise the current MTR
207 * object uses the *dscp_table* to determine the input color. When zero:
208 * the color determined by any previous MTR object in same flow is
209 * ignored by the current MTR object, which uses the *dscp_table* to
210 * determine the input color.
212 int use_prev_mtr_color;
214 /** Meter input color. When non-NULL: it points to a pre-allocated and
215 * pre-populated table with exactly 64 elements providing the input
216 * color for each value of the IPv4/IPv6 Differentiated Services Code
217 * Point (DSCP) input packet field. When NULL: it is equivalent to
218 * setting this parameter to an all-green populated table (i.e. table
219 * with all the 64 elements set to green color). The color blind mode
220 * is configured by setting *use_prev_mtr_color* to 0 and *dscp_table*
221 * to either NULL or to an all-green populated table. When
222 * *use_prev_mtr_color* is non-zero value or when *dscp_table* contains
223 * at least one yellow or red color element, then the color aware mode
226 enum rte_color *dscp_table;
228 /** Non-zero to enable the meter, zero to disable the meter at the time
229 * of MTR object creation. Ignored when the meter profile indicated by
230 * *meter_profile_id* is set to NONE.
231 * @see rte_mtr_meter_disable()
235 /** Policer actions (per meter output color). */
236 enum rte_mtr_policer_action action[RTE_COLORS];
238 /** Set of stats counters to be enabled.
239 * @see enum rte_mtr_stats_type
247 struct rte_mtr_capabilities {
248 /** Maximum number of MTR objects. */
251 /** Maximum number of MTR objects that can be shared by multiple flows.
252 * The value of zero indicates that shared MTR objects are not
253 * supported. The maximum value is *n_max*.
255 uint32_t n_shared_max;
257 /** When non-zero, this flag indicates that all the MTR objects that
258 * cannot be shared by multiple flows have identical capability set.
262 /** When non-zero, this flag indicates that all the MTR objects that
263 * can be shared by multiple flows have identical capability set.
265 int shared_identical;
267 /** Maximum number of flows that can share the same MTR object. The
268 * value of zero is invalid. The value of 1 means that shared MTR
269 * objects not supported.
271 uint32_t shared_n_flows_per_mtr_max;
273 /** Maximum number of MTR objects that can be part of the same flow. The
274 * value of zero is invalid. The value of 1 indicates that MTR object
275 * chaining is not supported. The maximum value is *n_max*.
277 uint32_t chaining_n_mtrs_per_flow_max;
280 * When non-zero, it indicates that the packet color identified by one
281 * MTR object can be used as the packet input color by any subsequent
282 * MTR object from the same flow. When zero, it indicates that the color
283 * determined by one MTR object is always ignored by any subsequent MTR
284 * object from the same flow. Only valid when MTR chaining is supported,
285 * i.e. *chaining_n_mtrs_per_flow_max* is greater than 1. When non-zero,
286 * it also means that the color aware mode is supported by at least one
287 * metering algorithm.
289 int chaining_use_prev_mtr_color_supported;
292 * When non-zero, it indicates that the packet color identified by one
293 * MTR object is always used as the packet input color by any subsequent
294 * MTR object that is part of the same flow. When zero, it indicates
295 * that whether the color determined by one MTR object is either ignored
296 * or used as the packet input color by any subsequent MTR object from
297 * the same flow is individually configurable for each MTR object. Only
298 * valid when *chaining_use_prev_mtr_color_supported* is non-zero.
300 int chaining_use_prev_mtr_color_enforced;
302 /** Maximum number of MTR objects that can have their meter configured
303 * to run the srTCM RFC 2697 algorithm. The value of 0 indicates this
304 * metering algorithm is not supported. The maximum value is *n_max*.
306 uint32_t meter_srtcm_rfc2697_n_max;
308 /** Maximum number of MTR objects that can have their meter configured
309 * to run the trTCM RFC 2698 algorithm. The value of 0 indicates this
310 * metering algorithm is not supported. The maximum value is *n_max*.
312 uint32_t meter_trtcm_rfc2698_n_max;
314 /** Maximum number of MTR objects that can have their meter configured
315 * to run the trTCM RFC 4115 algorithm. The value of 0 indicates this
316 * metering algorithm is not supported. The maximum value is *n_max*.
318 uint32_t meter_trtcm_rfc4115_n_max;
320 /** Maximum traffic rate that can be metered by a single MTR object. For
321 * srTCM RFC 2697, this is the maximum CIR rate. For trTCM RFC 2698,
322 * this is the maximum PIR rate. For trTCM RFC 4115, this is the maximum
323 * value for the sum of PIR and EIR rates.
325 uint64_t meter_rate_max;
328 * When non-zero, it indicates that color aware mode is supported for
329 * the srTCM RFC 2697 metering algorithm.
331 int color_aware_srtcm_rfc2697_supported;
334 * When non-zero, it indicates that color aware mode is supported for
335 * the trTCM RFC 2698 metering algorithm.
337 int color_aware_trtcm_rfc2698_supported;
340 * When non-zero, it indicates that color aware mode is supported for
341 * the trTCM RFC 4115 metering algorithm.
343 int color_aware_trtcm_rfc4115_supported;
345 /** When non-zero, it indicates that the policer packet recolor actions
347 * @see enum rte_mtr_policer_action
349 int policer_action_recolor_supported;
351 /** When non-zero, it indicates that the policer packet drop action is
353 * @see enum rte_mtr_policer_action
355 int policer_action_drop_supported;
357 /** Set of supported statistics counter types.
358 * @see enum rte_mtr_stats_type
364 * Verbose error types.
366 * Most of them provide the type of the object referenced by struct
367 * rte_mtr_error::cause.
369 enum rte_mtr_error_type {
370 RTE_MTR_ERROR_TYPE_NONE, /**< No error. */
371 RTE_MTR_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
372 RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
373 RTE_MTR_ERROR_TYPE_METER_PROFILE,
374 RTE_MTR_ERROR_TYPE_MTR_ID,
375 RTE_MTR_ERROR_TYPE_MTR_PARAMS,
376 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
377 RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW,
378 RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED,
379 RTE_MTR_ERROR_TYPE_STATS_MASK,
380 RTE_MTR_ERROR_TYPE_STATS,
381 RTE_MTR_ERROR_TYPE_SHARED,
385 * Verbose error structure definition.
387 * This object is normally allocated by applications and set by PMDs, the
388 * message points to a constant string which does not need to be freed by
389 * the application, however its pointer can be considered valid only as long
390 * as its associated DPDK port remains configured. Closing the underlying
391 * device or unloading the PMD invalidates it.
393 * Both cause and message may be NULL regardless of the error type.
395 struct rte_mtr_error {
396 enum rte_mtr_error_type type; /**< Cause field and error type. */
397 const void *cause; /**< Object responsible for the error. */
398 const char *message; /**< Human-readable error message. */
402 * MTR capabilities get
405 * The port identifier of the Ethernet device.
407 * MTR capabilities. Needs to be pre-allocated and valid.
409 * Error details. Filled in only on error, when not NULL.
411 * 0 on success, non-zero error code otherwise.
415 rte_mtr_capabilities_get(uint16_t port_id,
416 struct rte_mtr_capabilities *cap,
417 struct rte_mtr_error *error);
422 * Create a new meter profile with ID set to *meter_profile_id*. The new profile
423 * is used to create one or several MTR objects.
426 * The port identifier of the Ethernet device.
427 * @param[in] meter_profile_id
428 * ID for the new meter profile. Needs to be unused by any of the existing
429 * meter profiles added for the current port.
431 * Meter profile parameters. Needs to be pre-allocated and valid.
433 * Error details. Filled in only on error, when not NULL.
435 * 0 on success, non-zero error code otherwise.
439 rte_mtr_meter_profile_add(uint16_t port_id,
440 uint32_t meter_profile_id,
441 struct rte_mtr_meter_profile *profile,
442 struct rte_mtr_error *error);
445 * Meter profile delete
447 * Delete an existing meter profile. This operation fails when there is
448 * currently at least one user (i.e. MTR object) of this profile.
451 * The port identifier of the Ethernet device.
452 * @param[in] meter_profile_id
453 * Meter profile ID. Needs to be the valid.
455 * Error details. Filled in only on error, when not NULL.
457 * 0 on success, non-zero error code otherwise.
461 rte_mtr_meter_profile_delete(uint16_t port_id,
462 uint32_t meter_profile_id,
463 struct rte_mtr_error *error);
468 * Create a new MTR object for the current port. This object is run as part of
469 * associated flow action for traffic metering and policing.
472 * The port identifier of the Ethernet device.
474 * MTR object ID. Needs to be unused by any of the existing MTR objects.
475 * created for the current port.
477 * MTR object params. Needs to be pre-allocated and valid.
479 * Non-zero when this MTR object can be shared by multiple flows, zero when
480 * this MTR object can be used by a single flow.
482 * Error details. Filled in only on error, when not NULL.
484 * 0 on success, non-zero error code otherwise.
486 * @see enum rte_flow_action_type::RTE_FLOW_ACTION_TYPE_METER
490 rte_mtr_create(uint16_t port_id,
492 struct rte_mtr_params *params,
494 struct rte_mtr_error *error);
499 * Delete an existing MTR object. This operation fails when there is currently
500 * at least one user (i.e. flow) of this MTR object.
503 * The port identifier of the Ethernet device.
505 * MTR object ID. Needs to be valid.
506 * created for the current port.
508 * Error details. Filled in only on error, when not NULL.
510 * 0 on success, non-zero error code otherwise.
514 rte_mtr_destroy(uint16_t port_id,
516 struct rte_mtr_error *error);
519 * MTR object meter disable
521 * Disable the meter of an existing MTR object. In disabled state, the meter of
522 * the current MTR object works in pass-through mode, meaning that for each
523 * input packet the meter output color is always the same as the input color. In
524 * particular, when the meter of the current MTR object is configured in color
525 * blind mode, the input color is always green, so the meter output color is
526 * also always green. Note that the policer and the statistics of the current
527 * MTR object are working as usual while the meter is disabled. No action is
528 * taken and this function returns successfully when the meter of the current
529 * MTR object is already disabled.
532 * The port identifier of the Ethernet device.
536 * Error details. Filled in only on error, when not NULL.
538 * 0 on success, non-zero error code otherwise.
542 rte_mtr_meter_disable(uint16_t port_id,
544 struct rte_mtr_error *error);
547 * MTR object meter enable
549 * Enable the meter of an existing MTR object. If the MTR object has its meter
550 * already enabled, then no action is taken and this function returns
554 * The port identifier of the Ethernet device.
558 * Error details. Filled in only on error, when not NULL.
560 * 0 on success, non-zero error code otherwise.
564 rte_mtr_meter_enable(uint16_t port_id,
566 struct rte_mtr_error *error);
569 * MTR object meter profile update
572 * The port identifier of the Ethernet device.
574 * MTR object ID. Needs to be valid.
575 * @param[in] meter_profile_id
576 * Meter profile ID for the current MTR object. Needs to be valid.
578 * Error details. Filled in only on error, when not NULL.
580 * 0 on success, non-zero error code otherwise.
584 rte_mtr_meter_profile_update(uint16_t port_id,
586 uint32_t meter_profile_id,
587 struct rte_mtr_error *error);
590 * MTR object DSCP table update
593 * The port identifier of the Ethernet device.
595 * MTR object ID. Needs to be valid.
596 * @param[in] dscp_table
597 * When non-NULL: it points to a pre-allocated and pre-populated table with
598 * exactly 64 elements providing the input color for each value of the
599 * IPv4/IPv6 Differentiated Services Code Point (DSCP) input packet field.
600 * When NULL: it is equivalent to setting this parameter to an “all-green”
601 * populated table (i.e. table with all the 64 elements set to green color).
603 * Error details. Filled in only on error, when not NULL.
605 * 0 on success, non-zero error code otherwise.
609 rte_mtr_meter_dscp_table_update(uint16_t port_id,
611 enum rte_color *dscp_table,
612 struct rte_mtr_error *error);
615 * MTR object policer actions update
618 * The port identifier of the Ethernet device.
620 * MTR object ID. Needs to be valid.
621 * @param[in] action_mask
622 * Bit mask indicating which policer actions need to be updated. One or more
623 * policer actions can be updated in a single function invocation. To update
624 * the policer action associated with color C, bit (1 << C) needs to be set in
625 * *action_mask* and element at position C in the *actions* array needs to be
628 * Pre-allocated and pre-populated array of policer actions.
630 * Error details. Filled in only on error, when not NULL.
632 * 0 on success, non-zero error code otherwise.
636 rte_mtr_policer_actions_update(uint16_t port_id,
638 uint32_t action_mask,
639 enum rte_mtr_policer_action *actions,
640 struct rte_mtr_error *error);
643 * MTR object enabled statistics counters update
646 * The port identifier of the Ethernet device.
648 * MTR object ID. Needs to be valid.
649 * @param[in] stats_mask
650 * Mask of statistics counter types to be enabled for the current MTR object.
651 * Any statistics counter type not included in this set is to be disabled for
652 * the current MTR object.
654 * Error details. Filled in only on error, when not NULL.
656 * 0 on success, non-zero error code otherwise.
658 * @see enum rte_mtr_stats_type
662 rte_mtr_stats_update(uint16_t port_id,
665 struct rte_mtr_error *error);
668 * MTR object statistics counters read
671 * The port identifier of the Ethernet device.
673 * MTR object ID. Needs to be valid.
675 * When non-NULL, it contains the current value for the statistics counters
676 * enabled for the current MTR object.
677 * @param[out] stats_mask
678 * When non-NULL, it contains the mask of statistics counter types that are
679 * currently enabled for this MTR object, indicating which of the counters
680 * retrieved with the *stats* structure are valid.
682 * When this parameter has a non-zero value, the statistics counters are
683 * cleared (i.e. set to zero) immediately after they have been read,
684 * otherwise the statistics counters are left untouched.
686 * Error details. Filled in only on error, when not NULL.
688 * 0 on success, non-zero error code otherwise.
690 * @see enum rte_mtr_stats_type
694 rte_mtr_stats_read(uint16_t port_id,
696 struct rte_mtr_stats *stats,
697 uint64_t *stats_mask,
699 struct rte_mtr_error *error);
705 #endif /* __INCLUDE_RTE_MTR_H__ */