flow: code refactor

This is the code refactor for vnet/flow infra and the dpdk_plugin flow
implementation. The main works of the refactor are:
1. Added two base flow type: VNET_FLOW_TYPE_IP4 and VNET_FLOW_TYPE_IP6
   as the base the flow type
2. All the other flows are derived from the base flow types
3. Removed some flow types that are not currently supported by
   the hardware, and VPP won't leverage them either:
   IP4_GTPU_IP4, IP4_GTPU_IP6, IP6_GTPC, IP6_GTPU,
   IP6_GTPU_IP4, IP6_GTPU_IP6
4. Re-implemented the vnet/flow cli as well as the dpdk_plugin
   implementation
5. refine cli prompt
6. refine display info in command "show flow entry"

Type: refactor

Signed-off-by: Chenmin Sun <chenmin.sun@intel.com>
Change-Id: Ica5e61c5881adc73b28335fd83e36ec1cb420c96
This commit is contained in:
Chenmin Sun
2020-07-27 17:40:17 +08:00
committed by Damjan Marion
parent 29f3c7d2ec
commit 34bfa50b61
7 changed files with 597 additions and 758 deletions

View File

@ -26,86 +26,75 @@
#define foreach_flow_type \
/* l2 flow*/ \
_(ETHERNET, ethernet, "ethernet") \
/* l3 IP flow */ \
_(IP4, ip4, "ipv4") \
_(IP6, ip6, "ipv6") \
/* IP tunnel flow */ \
_(IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \
_(IP4_IPSEC_ESP, ip4_ipsec_esp, "ipv4-ipsec-esp") \
_(IP4_IPSEC_AH, ip4_ipsec_ah, "ipv4-ipsec-ah") \
/* l4 flow*/ \
_(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
_(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
_(IP4_N_TUPLE_TAGGED, ip4_n_tuple_tagged, "ipv4-n-tuple-tagged") \
_(IP6_N_TUPLE_TAGGED, ip6_n_tuple_tagged, "ipv6-n-tuple-tagged") \
/* IP tunnel flow */ \
_(IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \
_(IP4_IPSEC_ESP, ip4_ipsec_esp, "ipv4-ipsec-esp") \
_(IP4_IPSEC_AH, ip4_ipsec_ah, "ipv4-ipsec-ah") \
/* L4 tunnel flow*/ \
_(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
_(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
_(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
_(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
_(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
_(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
_(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
_(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
_(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
_(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
_(IP4_GTPU, ip4_gtpu, "ipv4-gtpu")
#define foreach_flow_entry_ethernet \
_fe(ethernet_header_t, eth_hdr)
#define foreach_flow_entry_ip4_n_tuple \
#define foreach_flow_entry_ip4 \
_fe(ip4_address_and_mask_t, src_addr) \
_fe(ip4_address_and_mask_t, dst_addr) \
_fe(ip_port_and_mask_t, src_port) \
_fe(ip_port_and_mask_t, dst_port) \
_fe(ip_protocol_t, protocol)
_fe(ip_prot_and_mask_t, protocol)
#define foreach_flow_entry_ip6_n_tuple \
#define foreach_flow_entry_ip6 \
_fe(ip6_address_and_mask_t, src_addr) \
_fe(ip6_address_and_mask_t, dst_addr) \
_fe(ip_port_and_mask_t, src_port) \
_fe(ip_port_and_mask_t, dst_port) \
_fe(ip_protocol_t, protocol)
#define foreach_flow_entry_ip4_n_tuple_tagged \
_fe(ip4_address_and_mask_t, src_addr) \
_fe(ip4_address_and_mask_t, dst_addr) \
_fe(ip_port_and_mask_t, src_port) \
_fe(ip_port_and_mask_t, dst_port) \
_fe(ip_protocol_t, protocol)
#define foreach_flow_entry_ip6_n_tuple_tagged \
_fe(ip6_address_and_mask_t, src_addr) \
_fe(ip6_address_and_mask_t, dst_addr) \
_fe(ip_port_and_mask_t, src_port) \
_fe(ip_port_and_mask_t, dst_port) \
_fe(ip_protocol_t, protocol)
_fe(ip_prot_and_mask_t, protocol)
#define foreach_flow_entry_ip4_l2tpv3oip \
_fe(ip4_address_and_mask_t, src_addr) \
_fe(ip4_address_and_mask_t, dst_addr) \
_fe(ip_protocol_t, protocol) \
foreach_flow_entry_ip4 \
_fe(u32, session_id)
#define foreach_flow_entry_ip4_ipsec_esp \
_fe(ip4_address_and_mask_t, src_addr) \
_fe(ip4_address_and_mask_t, dst_addr) \
_fe(ip_protocol_t, protocol) \
foreach_flow_entry_ip4 \
_fe(u32, spi)
#define foreach_flow_entry_ip4_ipsec_ah \
_fe(ip4_address_and_mask_t, src_addr) \
_fe(ip4_address_and_mask_t, dst_addr) \
_fe(ip_protocol_t, protocol) \
foreach_flow_entry_ip4 \
_fe(u32, spi)
#define foreach_flow_entry_ip4_n_tuple \
foreach_flow_entry_ip4 \
_fe(ip_port_and_mask_t, src_port) \
_fe(ip_port_and_mask_t, dst_port)
#define foreach_flow_entry_ip6_n_tuple \
foreach_flow_entry_ip6 \
_fe(ip_port_and_mask_t, src_port) \
_fe(ip_port_and_mask_t, dst_port)
#define foreach_flow_entry_ip4_n_tuple_tagged \
foreach_flow_entry_ip4 \
_fe(ip_port_and_mask_t, src_port) \
_fe(ip_port_and_mask_t, dst_port)
#define foreach_flow_entry_ip6_n_tuple_tagged \
foreach_flow_entry_ip6 \
_fe(ip_port_and_mask_t, src_port) \
_fe(ip_port_and_mask_t, dst_port)
#define foreach_flow_entry_ip4_vxlan \
_fe(ip4_address_t, src_addr) \
_fe(ip4_address_t, dst_addr) \
_fe(u16, dst_port) \
foreach_flow_entry_ip4_n_tuple \
_fe(u16, vni)
#define foreach_flow_entry_ip6_vxlan \
_fe(ip6_address_t, src_addr) \
_fe(ip6_address_t, dst_addr) \
_fe(u16, dst_port) \
foreach_flow_entry_ip6_n_tuple \
_fe(u16, vni)
#define foreach_flow_entry_ip4_gtpc \
@ -116,34 +105,6 @@
foreach_flow_entry_ip4_n_tuple \
_fe(u32, teid)
#define foreach_flow_entry_ip4_gtpu_ip4 \
foreach_flow_entry_ip4_gtpu \
_fe(ip4_address_and_mask_t, inner_src_addr) \
_fe(ip4_address_and_mask_t, inner_dst_addr)
#define foreach_flow_entry_ip4_gtpu_ip6 \
foreach_flow_entry_ip4_gtpu \
_fe(ip6_address_and_mask_t, inner_src_addr) \
_fe(ip6_address_and_mask_t, inner_dst_addr)
#define foreach_flow_entry_ip6_gtpc \
foreach_flow_entry_ip6_n_tuple \
_fe(u32, teid)
#define foreach_flow_entry_ip6_gtpu \
foreach_flow_entry_ip6_n_tuple \
_fe(u32, teid)
#define foreach_flow_entry_ip6_gtpu_ip4 \
foreach_flow_entry_ip6_gtpu \
_fe(ip4_address_and_mask_t, inner_src_addr) \
_fe(ip4_address_and_mask_t, inner_dst_addr)
#define foreach_flow_entry_ip6_gtpu_ip6 \
foreach_flow_entry_ip6_gtpu \
_fe(ip6_address_and_mask_t, inner_src_addr) \
_fe(ip6_address_and_mask_t, inner_dst_addr)
#define foreach_flow_action \
_(0, COUNT, "count") \
_(1, MARK, "mark") \
@ -160,7 +121,6 @@ typedef enum
#undef _
} vnet_flow_action_t;
#define foreach_flow_error \
_( -1, NOT_SUPPORTED, "not supported") \
_( -2, ALREADY_DONE, "already done") \
@ -215,6 +175,14 @@ typedef struct
u16 port, mask;
} ip_port_and_mask_t;
typedef struct
{
ip_protocol_t prot;
/* ip protocol mask should be either 0 or 0xFF */
/* other values are meanless */
u8 mask;
} ip_prot_and_mask_t;
typedef enum
{
VNET_FLOW_TYPE_UNKNOWN,

View File

@ -65,6 +65,14 @@ ipv6_addr_and_mask_convert (vl_api_ip6_address_and_mask_t * vl_api_addr,
clib_memcpy (vnet_addr, vl_api_addr, sizeof (*vnet_addr));
}
static inline void
protocol_and_mask_convert (vl_api_ip_prot_and_mask_t * vl_api_protocol,
ip_prot_and_mask_t * vnet_protocol)
{
vnet_protocol->prot = (ip_protocol_t) vl_api_protocol->prot;
vnet_protocol->mask = vl_api_protocol->mask;
}
static inline void
port_and_mask_convert (vl_api_ip_port_and_mask_t * vl_api_port,
ip_port_and_mask_t * vnet_port)
@ -79,11 +87,10 @@ ipv4_n_tuple_flow_convert (vl_api_flow_ip4_n_tuple_t * vl_api_flow,
{
ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr);
ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr);
protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol);
port_and_mask_convert (&vl_api_flow->src_port, &f->src_port);
port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port);
f->protocol = (ip_protocol_t) vl_api_flow->protocol;
}
static void
@ -92,11 +99,10 @@ ipv6_n_tuple_flow_convert (vl_api_flow_ip6_n_tuple_t * vl_api_flow,
{
ipv6_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr);
ipv6_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr);
protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol);
port_and_mask_convert (&vl_api_flow->src_port, &f->src_port);
port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port);
f->protocol = (ip_protocol_t) vl_api_flow->protocol;
}
static inline void
@ -124,7 +130,7 @@ ipv4_l2tpv3oip_flow_convert (vl_api_flow_ip4_l2tpv3oip_t * vl_api_flow,
ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr);
ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr);
f->protocol = (ip_protocol_t) vl_api_flow->protocol;
protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol);
f->session_id = ntohl (vl_api_flow->session_id);
}
@ -135,7 +141,7 @@ ipv4_ipsec_esp_flow_convert (vl_api_flow_ip4_ipsec_esp_t * vl_api_flow,
ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr);
ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr);
f->protocol = (ip_protocol_t) vl_api_flow->protocol;
protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol);
f->spi = ntohl (vl_api_flow->spi);
}
@ -146,7 +152,7 @@ ipv4_ipsec_ah_flow_convert (vl_api_flow_ip4_ipsec_ah_t * vl_api_flow,
ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr);
ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr);
f->protocol = (ip_protocol_t) vl_api_flow->protocol;
protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol);
f->spi = ntohl (vl_api_flow->spi);
}
@ -160,7 +166,7 @@ ipv4_gtpu_flow_convert (vl_api_flow_ip4_gtpu_t * vl_api_flow,
port_and_mask_convert (&vl_api_flow->src_port, &f->src_port);
port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port);
f->protocol = (ip_protocol_t) vl_api_flow->protocol;
protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol);
f->teid = ntohl (vl_api_flow->teid);
}
@ -174,7 +180,7 @@ ipv4_gtpc_flow_convert (vl_api_flow_ip4_gtpc_t * vl_api_flow,
port_and_mask_convert (&vl_api_flow->src_port, &f->src_port);
port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port);
f->protocol = (ip_protocol_t) vl_api_flow->protocol;
protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol);
f->teid = ntohl (vl_api_flow->teid);
}
@ -235,12 +241,10 @@ vl_api_flow_add_t_handler (vl_api_flow_add_t * mp)
rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
goto out;
break;
}
rv = vnet_flow_add (vnm, &flow, &flow_index);
goto out;
out:
/* *INDENT-OFF* */
REPLY_MACRO2(VL_API_FLOW_ADD_REPLY,

File diff suppressed because it is too large Load Diff

View File

@ -14,20 +14,22 @@
* limitations under the License.
*/
option version = "0.0.1";
option version = "0.0.2";
import "vnet/ethernet/ethernet_types.api";
import "vnet/ip/ip_types.api";
enum flow_type
{
FLOW_TYPE_ETHERNET = 1,
FLOW_TYPE_IP4,
FLOW_TYPE_IP6,
FLOW_TYPE_IP4_L2TPV3OIP,
FLOW_TYPE_IP4_IPSEC_ESP,
FLOW_TYPE_IP4_IPSEC_AH,
FLOW_TYPE_IP4_N_TUPLE,
FLOW_TYPE_IP6_N_TUPLE,
FLOW_TYPE_IP4_N_TUPLE_TAGGED,
FLOW_TYPE_IP6_N_TUPLE_TAGGED,
FLOW_TYPE_IP4_L2TPV3OIP,
FLOW_TYPE_IP4_IPSEC_ESP,
FLOW_TYPE_IP4_IPSEC_AH,
FLOW_TYPE_IP4_VXLAN,
FLOW_TYPE_IP6_VXLAN,
FLOW_TYPE_IP4_GTPC,
@ -50,6 +52,12 @@ typedef ip_port_and_mask
u16 mask;
};
typedef ip_prot_and_mask
{
vl_api_ip_proto_t prot;
u8 mask;
};
typedef flow_ethernet
{
i32 foo;
@ -58,14 +66,30 @@ typedef flow_ethernet
u16 type;
};
typedef flow_ip4
{
i32 foo;
vl_api_ip4_address_and_mask_t src_addr;
vl_api_ip4_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
};
typedef flow_ip6
{
i32 foo;
vl_api_ip6_address_and_mask_t src_addr;
vl_api_ip6_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
};
typedef flow_ip4_n_tuple
{
i32 foo;
vl_api_ip4_address_and_mask_t src_addr;
vl_api_ip4_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
vl_api_ip_proto_t protocol;
};
typedef flow_ip6_n_tuple
@ -73,9 +97,9 @@ typedef flow_ip6_n_tuple
i32 foo;
vl_api_ip6_address_and_mask_t src_addr;
vl_api_ip6_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
vl_api_ip_proto_t protocol;
};
typedef flow_ip4_n_tuple_tagged
@ -83,9 +107,9 @@ typedef flow_ip4_n_tuple_tagged
i32 foo;
vl_api_ip4_address_and_mask_t src_addr;
vl_api_ip4_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
vl_api_ip_proto_t protocol;
};
typedef flow_ip6_n_tuple_tagged
@ -93,9 +117,9 @@ typedef flow_ip6_n_tuple_tagged
i32 foo;
vl_api_ip6_address_and_mask_t src_addr;
vl_api_ip6_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
vl_api_ip_proto_t protocol;
};
typedef flow_ip4_l2tpv3oip
@ -103,9 +127,7 @@ typedef flow_ip4_l2tpv3oip
i32 foo;
vl_api_ip4_address_and_mask_t src_addr;
vl_api_ip4_address_and_mask_t dst_addr;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
vl_api_ip_proto_t protocol;
vl_api_ip_prot_and_mask_t protocol;
u32 session_id;
};
@ -114,9 +136,7 @@ typedef flow_ip4_ipsec_esp
i32 foo;
vl_api_ip4_address_and_mask_t src_addr;
vl_api_ip4_address_and_mask_t dst_addr;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
vl_api_ip_proto_t protocol;
vl_api_ip_prot_and_mask_t protocol;
u32 spi;
};
@ -125,27 +145,29 @@ typedef flow_ip4_ipsec_ah
i32 foo;
vl_api_ip4_address_and_mask_t src_addr;
vl_api_ip4_address_and_mask_t dst_addr;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
vl_api_ip_proto_t protocol;
vl_api_ip_prot_and_mask_t protocol;
u32 spi;
};
typedef flow_ip4_vxlan
{
i32 foo;
vl_api_ip4_address_t src_addr;
vl_api_ip4_address_t dst_addr;
u16 dst_port;
vl_api_ip4_address_and_mask_t src_addr;
vl_api_ip4_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
u16 vni;
};
typedef flow_ip6_vxlan
{
i32 foo;
vl_api_ip6_address_t src_addr;
vl_api_ip6_address_t dst_addr;
u16 dst_port;
vl_api_ip6_address_and_mask_t src_addr;
vl_api_ip6_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
u16 vni;
};
@ -154,9 +176,9 @@ typedef flow_ip4_gtpc
i32 foo;
vl_api_ip4_address_and_mask_t src_addr;
vl_api_ip4_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
vl_api_ip_proto_t protocol;
u32 teid;
};
@ -165,22 +187,24 @@ typedef flow_ip4_gtpu
i32 foo;
vl_api_ip4_address_and_mask_t src_addr;
vl_api_ip4_address_and_mask_t dst_addr;
vl_api_ip_prot_and_mask_t protocol;
vl_api_ip_port_and_mask_t src_port;
vl_api_ip_port_and_mask_t dst_port;
vl_api_ip_proto_t protocol;
u32 teid;
};
union flow
{
vl_api_flow_ethernet_t ethernet;
vl_api_flow_ip4_t ip4;
vl_api_flow_ip6_t ip6;
vl_api_flow_ip4_l2tpv3oip_t ip4_l2tpv3oip;
vl_api_flow_ip4_ipsec_esp_t ip4_ipsec_esp;
vl_api_flow_ip4_ipsec_ah_t ip4_ipsec_ah;
vl_api_flow_ip4_n_tuple_t ip4_n_tuple;
vl_api_flow_ip6_n_tuple_t ip6_n_tuple;
vl_api_flow_ip4_n_tuple_tagged_t ip4_n_tuple_tagged;
vl_api_flow_ip6_n_tuple_tagged_t ip6_n_tuple_tagged;
vl_api_flow_ip4_l2tpv3oip_t ip4_l2tpv3oip;
vl_api_flow_ip4_ipsec_esp_t ip4_ipsec_esp;
vl_api_flow_ip4_ipsec_ah_t ip4_ipsec_ah;
vl_api_flow_ip4_vxlan_t ip4_vxlan;
vl_api_flow_ip6_vxlan_t ip6_vxlan;
vl_api_flow_ip4_gtpc_t ip4_gtpc;