searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

RTE_FLOW实现说明

2023-10-27 09:40:23
9
0

通过rte_flow特性可以将特性报文重新流分类至特定CPU,实现对特殊流量的控制需求。

DPDK rte_flow 可以通过rte_flow_validate下发特定的元组,将匹配的流量指定到指定的队列中,以ipv4的结构为例,可以通过rte_flow_item_ipv4指定报文的源IP及目的IP,

rte_flow_item_ipv4说明:

struct rte_flow_item_ipv4 {
    struct rte_ipv4_hdr hdr; /**< IPv4 header definition. */
};

struct rte_ipv4_hdr {
uint8_t  version_ihl;/**< version and header length */
uint8_t  type_of_service;/**< type of service */
rte_be16_t total_length;/**< length of packet */
rte_be16_t packet_id;/**< packet ID */
rte_be16_t fragment_offset;/**< fragmentation offset */
uint8_t  time_to_live;/**< time to live */
uint8_t  next_proto_id;/**< protocol ID */
rte_be16_t hdr_checksum;/**< header checksum */
rte_be32_t src_addr;/**< source address */
rte_be32_t dst_addr;/**< destination address */
} __attribute__((__packed__));
 
实例代码:
 
memset(&ip_spec, 0, sizeof(struct rte_flow_item_ipv4));
memset(&ip_mask, 0, sizeof(struct rte_flow_item_ipv4));
ip_spec.hdr.dst_addr = htonl(dest_ip);
ip_mask.hdr.dst_addr = dest_mask;
ip_spec.hdr.src_addr = htonl(src_ip);
ip_mask.hdr.src_addr = src_mask;
pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
pattern[1].spec = &ip_spec;
pattern[1].mask = &ip_mask;
 
/* the final level must be always type end */
pattern[2].type = RTE_FLOW_ITEM_TYPE_END;
 
res = rte_flow_validate(port_id, &attr, pattern, action, error);
0条评论
0 / 1000
k****m
3文章数
0粉丝数
k****m
3 文章 | 0 粉丝
k****m
3文章数
0粉丝数
k****m
3 文章 | 0 粉丝
原创

RTE_FLOW实现说明

2023-10-27 09:40:23
9
0

通过rte_flow特性可以将特性报文重新流分类至特定CPU,实现对特殊流量的控制需求。

DPDK rte_flow 可以通过rte_flow_validate下发特定的元组,将匹配的流量指定到指定的队列中,以ipv4的结构为例,可以通过rte_flow_item_ipv4指定报文的源IP及目的IP,

rte_flow_item_ipv4说明:

struct rte_flow_item_ipv4 {
    struct rte_ipv4_hdr hdr; /**< IPv4 header definition. */
};

struct rte_ipv4_hdr {
uint8_t  version_ihl;/**< version and header length */
uint8_t  type_of_service;/**< type of service */
rte_be16_t total_length;/**< length of packet */
rte_be16_t packet_id;/**< packet ID */
rte_be16_t fragment_offset;/**< fragmentation offset */
uint8_t  time_to_live;/**< time to live */
uint8_t  next_proto_id;/**< protocol ID */
rte_be16_t hdr_checksum;/**< header checksum */
rte_be32_t src_addr;/**< source address */
rte_be32_t dst_addr;/**< destination address */
} __attribute__((__packed__));
 
实例代码:
 
memset(&ip_spec, 0, sizeof(struct rte_flow_item_ipv4));
memset(&ip_mask, 0, sizeof(struct rte_flow_item_ipv4));
ip_spec.hdr.dst_addr = htonl(dest_ip);
ip_mask.hdr.dst_addr = dest_mask;
ip_spec.hdr.src_addr = htonl(src_ip);
ip_mask.hdr.src_addr = src_mask;
pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
pattern[1].spec = &ip_spec;
pattern[1].mask = &ip_mask;
 
/* the final level must be always type end */
pattern[2].type = RTE_FLOW_ITEM_TYPE_END;
 
res = rte_flow_validate(port_id, &attr, pattern, action, error);
文章来自个人专栏
运维工具
3 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0