create a flow rule that sends packets with matching src and dest ip to selected queue.
46{
47
48 struct rte_flow_attr attr;
49 struct rte_flow_item pattern[MAX_PATTERN_NUM];
50 struct rte_flow_action action[MAX_ACTION_NUM];
51 struct rte_flow *flow = NULL;
52 struct rte_flow_action_queue queue = { .index = rx_q };
53 struct rte_flow_item_ipv4 ip_spec;
54 struct rte_flow_item_ipv4 ip_mask;
55
56 int res;
57
58 memset(pattern, 0, sizeof(pattern));
59 memset(action, 0, sizeof(action));
60
61
62 memset(&attr, 0, sizeof(struct rte_flow_attr));
63 attr.ingress = 1;
64
65
66
67
68
69 action[0].type = RTE_FLOW_ACTION_TYPE_QUEUE;
70 action[0].conf = &queue;
71 action[1].type = RTE_FLOW_ACTION_TYPE_END;
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 memset(&ip_spec, 0, sizeof(struct rte_flow_item_ipv4));
89 memset(&ip_mask, 0, sizeof(struct rte_flow_item_ipv4));
90 ip_spec.hdr.dst_addr = htonl(dest_ip);
91 ip_mask.hdr.dst_addr = 0;
92 ip_spec.hdr.src_addr = htonl(src_ip);
93 ip_mask.hdr.src_addr = src_mask;
94
95 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
96
97 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
98 pattern[1].spec = &ip_spec;
99 pattern[1].mask = &ip_mask;
100
101
102 pattern[2].type = RTE_FLOW_ITEM_TYPE_END;
103
104
105 res = rte_flow_validate(port_id, &attr, pattern, action,
error);
106 if (not res) {
107 flow = rte_flow_create(port_id, &attr, pattern, action,
error);
108 }
109
110 return flow;
111}