Rate This Document
Findability
Accuracy
Completeness
Readability

flexda_custom_construct_key

Function

Constructs and issues a key to a hardware flow table.

Syntax

int flexda_custom_construct_key ( void *ctx, const struct flexda_custom_info_t *info, struct rte_flow_item *hw_key)

Parameters

Parameter

Type

Input/Output

Description

ctx

void *

Input

Pointer to the custom context. It also stores the extracted header information.

info

struct flexda_custom_info_t *

Input

Information provided by dpak-ovs for flexda-ovs to read. For details, see Table 1.

hw_key

struct rte_flow_item *

Input

Address where the hardware flow table key is assembled.

Return value

int

Output

The function returns 0 upon successful execution; otherwise, it returns an error code.

Table 1 struct flexda_custom_info_t

Attribute Type

Attribute Name

Description

uint16_t

input_port_id

Source input port of the current packet in OVS offload.

dp_packet *

pkt

Current packet in OVS offload.

rte_flow_action *

src_actions

Actions of the current software flow table in OVS offload.

Example

int flexda_custom_construct_key(void *ctx, flexda_custom_info_t info, struct rte_flow_item *hw_key)
{
    struct custom_packet_ctx *custom_ctx = (struct custom_packet_ctx *)ctx;
    struct flexda_sub_hdr *out_header = &custom_ctx->out_header;
    struct rte_flow_item_eth *eth = NULL;
    struct rte_flow_item_port_id *port_id = NULL;
    // Control the key construction process based on context conditions. The constructed key must match the key definitions specified for the table in Hydra code.
    if (custom_ctx->vlan_poped == 1) { // vlan rx
        // Issue the VLAN ID key. First, call the memory API to allocate memory. After the key data is written, call the key insertion API. Then, the memory management permission is handed over to the framework and it does not need to be released.
        struct rte_flow_item_vlan *vlan = flexda_calloc(1, sizeof(struct rte_flow_item_vlan));
        vlan->tci = custom_ctx->out_header.l2.vlan.vlan_id;
        flexda_insert_rte_key(hw_key, -1, vlan, RTE_FLOW_ITEM_TYPE_VLAN);
        // Issue the VLAN eth_type key. Use the key insertion API that matches the custom key types defined in Hydra, and provide the length and type enumeration values that meet the Hydra code requirements.
        uint16_t *encap = flexda_calloc(1, sizeof(uint16_t));
        *encap = custom_ctx->out_header.l2.vlan.encap;
        flexda_insert_hydra_key(hw_key, -1, encap, sizeof(uint16_t), HYDRA_ITEM_MYMAINPIPE_GENEVE_EXACT_INNER_ETH_TYPE);
        return 0;
    }
    return -EINVAL;
}