Raw Ethernet Programming: VXLAN Steering - Code Example

Version 5

    This post shows how to steer packets using the VXLAN tunnel ID, when developing Raw Ethernet over verbs.

    This feature is available starting with MLNX_OFED Rel. 3.4.




    In order to steer traffic according to a VXLAN tunnel ID, you need to use the ibv_exp_flow_attr and ibv_exp_cmd_create_flow calls. At the end of the struct, the application appends several specs for each feature, as described here:

    struct ibv_exp_flow_attr {

            enum ibv_exp_flow_attr_type type;

            uint16_t size;

            uint16_t priority;

            uint8_t num_of_specs;

            uint8_t port;

            uint32_t flags;

            /* Following are the optional layers according to the user request

             * struct ibv_exp_flow_spec_xxx [L2]

             * struct ibv_exp_flow_spec_yyy [L3/L4]


            uint64_t reserved; /* reserved for future growth (must be 0) */



    The flow steering creation is made through the ibv_exp_flow_attr container struct, which includes the specification control header followed by the flow specification itself.



    The number of specifications to add is 4. Use the first as the Vxlan spec (tunnel), which is described below. The following specifications to add are the L2, L3, and L4 specs.


    You can also mask a range of tunnel IDs to be steered by using the filler mask.


    This following example provides the ibv_exp_flow_tunnel_filter struct definition:

    struct ibv_exp_flow_tunnel_filter {

            uint32_t tunnel_id;



    This following example specifies the VXLAN tunnel definition.

    struct ibv_exp_flow_spec_tunnel {

            enum ibv_exp_flow_spec_type  type;

            uint16_t  size;

            struct ibv_exp_flow_tunnel_filter val;

            struct ibv_exp_flow_tunnel_filter mask;




    • Type: Specifies that you need to use IBV_EXP_FLOW_SPEC_VXLAN_TUNNEL to define the spec as an Vxlan spec.
    • Size: Identifies the size of the ibv_exp_kern_spec_tunnel.
    • Tunnel_id: Indicates that the tunnel ID as in the VXLAN header.