net/iavf: add GTPU in default hash
[dpdk.git] / app / test-flow-perf / flow_gen.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  *
4  * The file contains the implementations of the method to
5  * fill items, actions & attributes in their corresponding
6  * arrays, and then generate rte_flow rule.
7  *
8  * After the generation. The rule goes to validation then
9  * creation state and then return the results.
10  */
11
12 #include <stdint.h>
13
14 #include "flow_gen.h"
15 #include "items_gen.h"
16 #include "actions_gen.h"
17 #include "config.h"
18
19 static void
20 fill_attributes(struct rte_flow_attr *attr,
21         uint64_t flow_attrs, uint16_t group)
22 {
23         if (flow_attrs & INGRESS)
24                 attr->ingress = 1;
25         if (flow_attrs & EGRESS)
26                 attr->egress = 1;
27         if (flow_attrs & TRANSFER)
28                 attr->transfer = 1;
29         attr->group = group;
30 }
31
32 struct rte_flow *
33 generate_flow(uint16_t port_id,
34         uint16_t group,
35         uint64_t flow_attrs,
36         uint64_t flow_items,
37         uint64_t flow_actions,
38         uint16_t next_table,
39         uint32_t outer_ip_src,
40         uint16_t hairpinq,
41         struct rte_flow_error *error)
42 {
43         struct rte_flow_attr attr;
44         struct rte_flow_item items[MAX_ITEMS_NUM];
45         struct rte_flow_action actions[MAX_ACTIONS_NUM];
46         struct rte_flow *flow = NULL;
47
48         memset(items, 0, sizeof(items));
49         memset(actions, 0, sizeof(actions));
50         memset(&attr, 0, sizeof(struct rte_flow_attr));
51
52         fill_attributes(&attr, flow_attrs, group);
53
54         fill_actions(actions, flow_actions,
55                 outer_ip_src, next_table, hairpinq);
56
57         fill_items(items, flow_items, outer_ip_src);
58
59         flow = rte_flow_create(port_id, &attr, items, actions, error);
60         return flow;
61 }