|
| 1 | +.. SPDX-License-Identifier: Marvell-MIT |
| 2 | + Copyright (c) 2024 Marvell. |
| 3 | +
|
| 4 | +************ |
| 5 | +Flow Library |
| 6 | +************ |
| 7 | + |
| 8 | +Introduction |
| 9 | +============ |
| 10 | + |
| 11 | +The Flow Library provides interfaces to configure hardware for identifying the |
| 12 | +traffic and executing actions based on rules defined by the user. |
| 13 | +The library defines APIs for constructing flow rules that include match criteria |
| 14 | +and a set of actions. Once a continuous stream of packets matching the flow is |
| 15 | +received, the flow is offloaded to the hardware. |
| 16 | + |
| 17 | +The flows can be cascaded, allowing a packet to proceed to another flow after a |
| 18 | +flow-defined action is executed |
| 19 | + |
| 20 | +There are some challenges which flow library can meet: |
| 21 | + |
| 22 | +* Optimal performance is achieved when flow rules are offloaded to hardware, however, |
| 23 | + the capacity of TCAM entries, which store these flow rules, is finite. Consequently, |
| 24 | + once the TCAM entries reach their maximum limit, a precipitous decline in performance |
| 25 | + is inevitable. |
| 26 | + |
| 27 | + This TCAM limit can be mitigated via Flow library that manages these flows, making |
| 28 | + decisions on when to install and age out a flow from the hardware. |
| 29 | + |
| 30 | +* This flow library could be instrumental in fulfilling the requirement of managing |
| 31 | + up to 1 million flows through software ACL tables. |
| 32 | + |
| 33 | + |
| 34 | +Flow Rule |
| 35 | +========= |
| 36 | + |
| 37 | +A flow rule is the combination of attributes with a matching pattern and a list of |
| 38 | +actions. |
| 39 | + |
| 40 | +Refer `DPDK Flow Rule Description <https://doc.dpdk.org/guides/prog_guide/rte_flow.html#flow-rule>`_ for more details. |
| 41 | + |
| 42 | +Programming Model |
| 43 | +================= |
| 44 | + |
| 45 | +The Flow Library is designed to provide a generic means for applications to offload |
| 46 | +flows to hardware (HW) or perform ACL lookups in case of HW flow miss for packet |
| 47 | +classification. Applications such as ovs-offload or virtio-l2fwd can subscribe to |
| 48 | +this library. |
| 49 | + |
| 50 | +Initialization |
| 51 | +-------------- |
| 52 | + |
| 53 | +As part of the application initialization sequence, ``dao_flow_init()`` is invoked. |
| 54 | +This function takes struct ``dao_flow_offload_config`` as input, providing details of |
| 55 | +whether the ACL table should be backed by TCAM and the KEX profile to be used for ACL |
| 56 | +lookup. |
| 57 | +This function should be invoked for each port, taking into account that an application |
| 58 | +can have two types of ports: RPM ports, which require hardware flow offloading, and |
| 59 | +virtio ports, which do not have hardware TCAM backing |
| 60 | + |
| 61 | +User flow offloading configuration structure |
| 62 | + |
| 63 | +.. code-block:: c |
| 64 | +
|
| 65 | + struct dao_flow_offload_config { |
| 66 | + /* Different features supported */ |
| 67 | + uint32_t feature; |
| 68 | + /* Key exchange profiles supported */ |
| 69 | + char parse_profile[DAO_FLOW_PROFILE_NAME_MAX]; |
| 70 | + /* Flow aging timeout */ |
| 71 | + uint32_t aging_tmo_sec; |
| 72 | + }; |
| 73 | +
|
| 74 | +Flow initialization API |
| 75 | + |
| 76 | +.. code-block:: c |
| 77 | +
|
| 78 | + int dao_flow_init(uint16_t port_id, struct dao_flow_offload_config *config); |
| 79 | +
|
| 80 | +Arguments: |
| 81 | + ``config``: User provided flow offloading configuration |
| 82 | + |
| 83 | +Sample initialization code: |
| 84 | + |
| 85 | +.. code-block:: c |
| 86 | +
|
| 87 | + struct dao_flow_offload_config config = {0}; |
| 88 | + uint16_t port_id = 0; |
| 89 | +
|
| 90 | + config.feature |= hw_offload_enable ? DAO_FLOW_HW_OFFLOAD_ENABLE : 0; |
| 91 | + rte_strscpy(config.parse_profile, prfl, DAO_FLOW_PROFILE_NAME_MAX); |
| 92 | + config.aging_tmo = 10; |
| 93 | +
|
| 94 | + rc = dao_flow_init(port_id, &config); |
| 95 | + if (rc) { |
| 96 | + dao_err("Error: DAO flow init failed, err %d", rc); |
| 97 | + return; |
| 98 | + } |
| 99 | +
|
| 100 | +Flow Creation |
| 101 | +------------- |
| 102 | + |
| 103 | +``dao_flow_create()`` is used to add a new flow to the ACL table, which is maintained |
| 104 | +per port. At this stage, the flow is added only to the ACL table and nothing goes to |
| 105 | +TCAM. |
| 106 | + |
| 107 | +.. code-block:: c |
| 108 | +
|
| 109 | + struct dao_flow *dao_flow_create(uint16_t port_id, const struct rte_flow_attr *attr, |
| 110 | + const struct rte_flow_item pattern[], |
| 111 | + const struct rte_flow_action actions[], |
| 112 | + struct rte_flow_error *error); |
| 113 | +
|
| 114 | +Arguments: |
| 115 | + ``port_id``: Port identifier of Ethernet device |
| 116 | + ``attr``: Flow rule attributes |
| 117 | + ``pattern``: Pattern specification (list terminated by the END pattern item) |
| 118 | + ``actions``: Associated actions (list terminated by the END action) |
| 119 | + ``error``: Perform verbose error reporting if not NULL |
| 120 | + |
| 121 | +Return value: |
| 122 | + A valid handle in case of success, NULL otherwise and errno is set |
| 123 | + |
| 124 | +Flow Lookup |
| 125 | +----------- |
| 126 | + |
| 127 | +On the arrival of the first packet, the ACL table is looked up via ``dao_flow_lookup()``. |
| 128 | +If no rule is found, the packet takes the exception path (i.e., port representor to OVS |
| 129 | +path in the case of OVS). If a rule is hit, the flow is installed to the HW TCAM |
| 130 | +(provided port has requested for HW offload capability while dao_flow_init()). One hit is |
| 131 | +enough to decide to push the rule to HW. |
| 132 | + |
| 133 | +.. code-block:: c |
| 134 | +
|
| 135 | + int dao_flow_lookup(uint16_t port_id, struct rte_mbuf **objs, uint16_t nb_objs); |
| 136 | +
|
| 137 | +Arguments: |
| 138 | + ``port_id``: Port identifier of Ethernet device |
| 139 | + ``objs``: Array of packet buffers |
| 140 | + ``nb_objs``: No of packet buffers |
| 141 | + |
| 142 | +Return value: |
| 143 | + 0 on success, a negative errno value |
| 144 | + |
| 145 | +Flow Destruction |
| 146 | +---------------- |
| 147 | + |
| 148 | +Applications can call ``dao_flow_destroy()``. This function removes the rule from HW TCAM |
| 149 | +(if installed) and ACL. |
| 150 | + |
| 151 | +.. code-block:: c |
| 152 | +
|
| 153 | + int dao_flow_destroy(uint16_t port_id, struct dao_flow *flow, struct rte_flow_error *error); |
| 154 | +
|
| 155 | +Arguments: |
| 156 | + ``port_id``: Port identifier of Ethernet device |
| 157 | + ``flow``: Flow rule handle to destroy |
| 158 | + ``error``: Perform verbose error reporting if not NULL |
| 159 | + |
| 160 | +Return value: |
| 161 | + 0 on success, a negative errno value |
| 162 | + |
| 163 | +Flow Query |
| 164 | +---------- |
| 165 | + |
| 166 | +This function enables the extraction of flow-specific data, such as counters, which is |
| 167 | +accumulated through special actions that are integral to the flow rule definition. |
| 168 | + |
| 169 | +.. code-block:: c |
| 170 | +
|
| 171 | + int dao_flow_query(uint16_t port_id, struct dao_flow *flow, const struct rte_flow_action *action, void *data, struct rte_flow_error *error); |
| 172 | +
|
| 173 | +Arguments: |
| 174 | + ``port_id``: Port identifier of Ethernet device |
| 175 | + ``flow``: Flow rule handle to query |
| 176 | + ``action``: Action definition as defined in original flow rule |
| 177 | + ``data``: Pointer to storage for the associated query data type |
| 178 | + ``error``: Perform verbose error reporting if not NULL |
| 179 | + |
| 180 | +Return value: |
| 181 | + 0 on success, a negative errno value otherwise and rte_errno is set |
| 182 | + |
| 183 | +Flow Flush |
| 184 | +---------- |
| 185 | + |
| 186 | +In the unlikely event of failure, there may be a requirement to destroy all flow rule |
| 187 | +handles associated with a port. |
| 188 | + |
| 189 | +.. code-block:: c |
| 190 | +
|
| 191 | + int dao_flow_flush(uint16_t port_id, struct rte_flow_error *error); |
| 192 | +
|
| 193 | +Arguments: |
| 194 | + ``port_id``: Port identifier of Ethernet device |
| 195 | + ``error``: Perform verbose error reporting if not NULL |
| 196 | + |
| 197 | +Return value: |
| 198 | + 0 on success, a negative value otherwise. |
| 199 | + |
| 200 | +Flow Information |
| 201 | +---------------- |
| 202 | + |
| 203 | +Dumping internal information about a flow. |
| 204 | + |
| 205 | +.. code-block:: c |
| 206 | +
|
| 207 | + int dao_flow_dev_dump(uint16_t port_id, struct dao_flow *flow, FILE *file, struct rte_flow_error *error); |
| 208 | +
|
| 209 | +Arguments: |
| 210 | + ``port_id``: The port identifier of the Ethernet device |
| 211 | + ``flow``: The pointer of flow rule to dump. Dump all rules if NULL |
| 212 | + ``file``: A pointer to a file for output |
| 213 | + ``error``: Perform verbose error reporting if not NULL |
| 214 | + |
| 215 | +Return value: |
| 216 | + 0 on success, a negative value otherwise. |
0 commit comments