1*41dd9a6bSDavid Young.. SPDX-License-Identifier: BSD-3-Clause 2*41dd9a6bSDavid Young Copyright(c) 2017 Intel Corporation. 3*41dd9a6bSDavid Young 4*41dd9a6bSDavid YoungTraffic Metering and Policing API 5*41dd9a6bSDavid Young================================= 6*41dd9a6bSDavid Young 7*41dd9a6bSDavid Young 8*41dd9a6bSDavid YoungOverview 9*41dd9a6bSDavid Young-------- 10*41dd9a6bSDavid Young 11*41dd9a6bSDavid YoungThis is the generic API for the Quality of Service (QoS) Traffic Metering and 12*41dd9a6bSDavid YoungPolicing (MTR) of Ethernet devices. This API is agnostic of the underlying HW, 13*41dd9a6bSDavid YoungSW or mixed HW-SW implementation. 14*41dd9a6bSDavid Young 15*41dd9a6bSDavid YoungThe main features are: 16*41dd9a6bSDavid Young 17*41dd9a6bSDavid Young* Part of DPDK rte_ethdev API 18*41dd9a6bSDavid Young* Capability query API 19*41dd9a6bSDavid Young* Metering algorithms: RFC 2697 Single Rate Three Color Marker (srTCM), RFC 2698 20*41dd9a6bSDavid Young and RFC 4115 Two Rate Three Color Marker (trTCM) 21*41dd9a6bSDavid Young* Policer actions (per meter output color): recolor, drop 22*41dd9a6bSDavid Young* Statistics (per policer output color) 23*41dd9a6bSDavid Young* Chaining multiple meter objects 24*41dd9a6bSDavid Young* Protocol based input color selection 25*41dd9a6bSDavid Young 26*41dd9a6bSDavid YoungConfiguration steps 27*41dd9a6bSDavid Young------------------- 28*41dd9a6bSDavid Young 29*41dd9a6bSDavid YoungThe metering and policing stage typically sits on top of flow classification, 30*41dd9a6bSDavid Youngwhich is why the MTR objects are enabled through a special "meter" action. 31*41dd9a6bSDavid Young 32*41dd9a6bSDavid YoungThe MTR objects are created and updated in their own name space (``rte_mtr``) 33*41dd9a6bSDavid Youngwithin the ``librte_ethdev`` library. Whether an MTR object is private to a 34*41dd9a6bSDavid Youngflow or potentially shared by several flows has to be specified at its 35*41dd9a6bSDavid Youngcreation time. 36*41dd9a6bSDavid Young 37*41dd9a6bSDavid YoungOnce successfully created, an MTR object is hooked into the RX processing path 38*41dd9a6bSDavid Youngof the Ethernet device by linking it to one or several flows through the 39*41dd9a6bSDavid Youngdedicated "meter" flow action. One or several "meter" actions can be registered 40*41dd9a6bSDavid Youngfor the same flow. An MTR object can only be destroyed if there are no flows 41*41dd9a6bSDavid Youngusing it. 42*41dd9a6bSDavid Young 43*41dd9a6bSDavid YoungRun-time processing 44*41dd9a6bSDavid Young------------------- 45*41dd9a6bSDavid Young 46*41dd9a6bSDavid YoungTraffic metering determines the color for the current packet (green, yellow, 47*41dd9a6bSDavid Youngred) based on the previous history for this flow as maintained by the MTR 48*41dd9a6bSDavid Youngobject. The policer can do nothing, override the color the packet or drop the 49*41dd9a6bSDavid Youngpacket. Statistics counters are maintained for MTR object, as configured. 50*41dd9a6bSDavid Young 51*41dd9a6bSDavid YoungThe processing done for each input packet hitting an MTR object is: 52*41dd9a6bSDavid Young 53*41dd9a6bSDavid Young* Traffic metering: The packet is assigned a color (the meter output color) 54*41dd9a6bSDavid Young based on the previous traffic history reflected in the current state of the 55*41dd9a6bSDavid Young MTR object, according to the specific traffic metering algorithm. The 56*41dd9a6bSDavid Young traffic metering algorithm can typically work in color aware mode, in which 57*41dd9a6bSDavid Young case the input packet already has an initial color (the input color), or in 58*41dd9a6bSDavid Young color blind mode, which is equivalent to considering all input packets 59*41dd9a6bSDavid Young initially colored as green. 60*41dd9a6bSDavid Young 61*41dd9a6bSDavid Young* There is a meter policy API to manage pre-defined policies for meter. 62*41dd9a6bSDavid Young Any rte_flow action list can be configured per color for each policy. 63*41dd9a6bSDavid Young A meter object configured with a policy executes the actions per packet 64*41dd9a6bSDavid Young according to the packet color. 65*41dd9a6bSDavid Young 66*41dd9a6bSDavid Young* Statistics: The set of counters maintained for each MTR object is 67*41dd9a6bSDavid Young configurable and subject to the implementation support. This set includes 68*41dd9a6bSDavid Young the number of packets and bytes dropped or passed for each output color. 69*41dd9a6bSDavid Young 70*41dd9a6bSDavid YoungAPI walk-through 71*41dd9a6bSDavid Young---------------- 72*41dd9a6bSDavid Young 73*41dd9a6bSDavid Young.. _figure_rte_mtr_chaining: 74*41dd9a6bSDavid Young 75*41dd9a6bSDavid Young.. figure:: ../img/rte_mtr_meter_chaining.* 76*41dd9a6bSDavid Young 77*41dd9a6bSDavid Young Meter components 78*41dd9a6bSDavid Young 79*41dd9a6bSDavid YoungThis section will introduce the reader to the critical APIs to use 80*41dd9a6bSDavid Youngthe traffic meter and policing library. 81*41dd9a6bSDavid Young 82*41dd9a6bSDavid YoungIn general, the application performs the following steps to configure the 83*41dd9a6bSDavid Youngtraffic meter and policing library. 84*41dd9a6bSDavid Young 85*41dd9a6bSDavid Young#. Application gets the meter driver capabilities using ``rte_mtr_capabilities_get()``. 86*41dd9a6bSDavid Young#. The application creates the required meter profiles by using the 87*41dd9a6bSDavid Young ``rte_mtr_meter_profile_add()`` API function. 88*41dd9a6bSDavid Young#. The application creates the required meter policies by using the 89*41dd9a6bSDavid Young ``rte_mtr_meter_policy_add()`` API function. 90*41dd9a6bSDavid Young#. The application creates a meter object using the ``rte_mtr_create()`` API 91*41dd9a6bSDavid Young function. One of the previously created meter profile 92*41dd9a6bSDavid Young (``struct rte_mtr_params::meter_profile_id``) and meter policy 93*41dd9a6bSDavid Young (``struct rte_mtr_params::meter_policy_id``) are provided as arguments 94*41dd9a6bSDavid Young at this step. 95*41dd9a6bSDavid Young#. The application enables the meter object execution as part of the flow action 96*41dd9a6bSDavid Young processing by calling the ``rte_flow_create()`` API function with one of the 97*41dd9a6bSDavid Young flow action set to ``RTE_FLOW_ACTION_TYPE_METER`` and the associated 98*41dd9a6bSDavid Young meter object ID set to this meter object. 99*41dd9a6bSDavid Young#. The API allows chaining the meter objects to create complex metering topology 100*41dd9a6bSDavid Young by the following methods. 101*41dd9a6bSDavid Young 102*41dd9a6bSDavid Young * Adding multiple flow actions of the type ``RTE_FLOW_ACTION_TYPE_METER`` to 103*41dd9a6bSDavid Young the same flow. 104*41dd9a6bSDavid Young Each of the meter action typically refers to a different meter object. 105*41dd9a6bSDavid Young 106*41dd9a6bSDavid Young * Adding one (or multiple) actions of the type ``RTE_FLOW_ACTION_TYPE_METER`` 107*41dd9a6bSDavid Young to the list of meter actions (``struct rte_mtr_meter_policy_params::actions``) 108*41dd9a6bSDavid Young specified per color as show in :numref:`figure_rte_mtr_chaining`. 109*41dd9a6bSDavid Young 110*41dd9a6bSDavid Young#. The ``rte_mtr_meter_profile_get()`` and ``rte_mtr_meter_policy_get()`` 111*41dd9a6bSDavid Young API functions are available for getting the object pointers directly. 112*41dd9a6bSDavid Young These pointers allow quick access to profile/policy objects and are 113*41dd9a6bSDavid Young required by the ``RTE_FLOW_ACTION_TYPE_METER_MARK`` action. 114*41dd9a6bSDavid Young This action may omit the policy definition to provide flexibility 115*41dd9a6bSDavid Young to match a color later with the ``RTE_FLOW_ITEM_TYPE_METER_COLOR`` item. 116*41dd9a6bSDavid Young 117*41dd9a6bSDavid YoungProtocol based input color selection 118*41dd9a6bSDavid Young------------------------------------ 119*41dd9a6bSDavid Young 120*41dd9a6bSDavid YoungThe API supports selecting the input color based on the packet content. 121*41dd9a6bSDavid YoungFollowing is the API usage model for the same. 122*41dd9a6bSDavid Young 123*41dd9a6bSDavid Young#. Probe the protocol based input color selection device capabilities using 124*41dd9a6bSDavid Young the following parameters with ``rte_mtr_capabilities_get()`` API. 125*41dd9a6bSDavid Young 126*41dd9a6bSDavid Young * ``struct rte_mtr_capabilities::input_color_proto_mask;`` 127*41dd9a6bSDavid Young * ``struct rte_mtr_capabilities::separate_input_color_table_per_port`` 128*41dd9a6bSDavid Young 129*41dd9a6bSDavid Young#. When creating the meter object using ``rte_mtr_create()``, configure 130*41dd9a6bSDavid Young relevant input color selection parameters such as 131*41dd9a6bSDavid Young 132*41dd9a6bSDavid Young * Fill the tables ``struct rte_mtr_params::dscp_table``, 133*41dd9a6bSDavid Young ``struct rte_mtr_params::vlan_table`` based on input color selected. 134*41dd9a6bSDavid Young 135*41dd9a6bSDavid Young * Update the ``struct rte_mtr_params::default_input_color`` to determine 136*41dd9a6bSDavid Young the default input color in case the input packet does not match 137*41dd9a6bSDavid Young the input color method. 138*41dd9a6bSDavid Young 139*41dd9a6bSDavid Young#. Use the following APIs to configure the meter object 140*41dd9a6bSDavid Young 141*41dd9a6bSDavid Young * Select the input protocol color with ``rte_mtr_color_in_protocol_set()`` API. 142*41dd9a6bSDavid Young 143*41dd9a6bSDavid Young * If needed, update the input color table at runtime using 144*41dd9a6bSDavid Young ``rte_mtr_meter_vlan_table_update()`` and ``rte_mtr_meter_dscp_table_update()`` 145*41dd9a6bSDavid Young APIs. 146*41dd9a6bSDavid Young 147*41dd9a6bSDavid Young * Application can query the configured input color protocol and its associated 148*41dd9a6bSDavid Young priority using ``rte_mtr_color_in_protocol_get()`` and 149*41dd9a6bSDavid Young ``rte_mtr_color_in_protocol_priority_get()`` APIs. 150