bpf: allow self-xor operation
[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         uint8_t i;
24         for (i = 0; i < MAX_ATTRS_NUM; i++) {
25                 if (flow_attrs[i] == 0)
26                         break;
27                 if (flow_attrs[i] & INGRESS)
28                         attr->ingress = 1;
29                 else if (flow_attrs[i] & EGRESS)
30                         attr->egress = 1;
31                 else if (flow_attrs[i] & TRANSFER)
32                         attr->transfer = 1;
33         }
34         attr->group = group;
35 }
36
37 struct rte_flow *
38 generate_flow(uint16_t port_id,
39         uint16_t group,
40         uint64_t *flow_attrs,
41         uint64_t *flow_items,
42         uint64_t *flow_actions,
43         uint16_t next_table,
44         uint32_t outer_ip_src,
45         uint16_t hairpinq,
46         uint64_t encap_data,
47         uint64_t decap_data,
48         uint8_t core_idx,
49         bool unique_data,
50         struct rte_flow_error *error)
51 {
52         struct rte_flow_attr attr;
53         struct rte_flow_item items[MAX_ITEMS_NUM];
54         struct rte_flow_action actions[MAX_ACTIONS_NUM];
55         struct rte_flow *flow = NULL;
56
57         memset(items, 0, sizeof(items));
58         memset(actions, 0, sizeof(actions));
59         memset(&attr, 0, sizeof(struct rte_flow_attr));
60
61         fill_attributes(&attr, flow_attrs, group);
62
63         fill_actions(actions, flow_actions,
64                 outer_ip_src, next_table, hairpinq,
65                 encap_data, decap_data, core_idx,
66                 unique_data);
67
68         fill_items(items, flow_items, outer_ip_src, core_idx);
69
70         flow = rte_flow_create(port_id, &attr, items, actions, error);
71         return flow;
72 }