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