flow_classify: remove table id parameter from API
[dpdk.git] / test / test / test_flow_classify.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef TEST_FLOW_CLASSIFY_H_
6 #define TEST_FLOW_CLASSIFY_H_
7
8 #define MAX_PKT_BURST      (32)
9 #define NB_SOCKETS         (1)
10 #define MEMPOOL_CACHE_SIZE (256)
11 #define MBUF_SIZE          (512)
12 #define NB_MBUF            (512)
13
14 /* test UDP, TCP and SCTP packets */
15 static struct rte_mempool *mbufpool[NB_SOCKETS];
16 static struct rte_mbuf *bufs[MAX_PKT_BURST];
17
18 /* ACL field definitions for IPv4 5 tuple rule */
19
20 enum {
21         PROTO_FIELD_IPV4,
22         SRC_FIELD_IPV4,
23         DST_FIELD_IPV4,
24         SRCP_FIELD_IPV4,
25         DSTP_FIELD_IPV4,
26         NUM_FIELDS_IPV4
27 };
28
29 enum {
30         PROTO_INPUT_IPV4,
31         SRC_INPUT_IPV4,
32         DST_INPUT_IPV4,
33         SRCP_DESTP_INPUT_IPV4
34 };
35
36 static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = {
37         /* first input field - always one byte long. */
38         {
39                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
40                 .size = sizeof(uint8_t),
41                 .field_index = PROTO_FIELD_IPV4,
42                 .input_index = PROTO_INPUT_IPV4,
43                 .offset = sizeof(struct ether_hdr) +
44                         offsetof(struct ipv4_hdr, next_proto_id),
45         },
46         /* next input field (IPv4 source address) - 4 consecutive bytes. */
47         {
48                 /* rte_flow uses a bit mask for IPv4 addresses */
49                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
50                 .size = sizeof(uint32_t),
51                 .field_index = SRC_FIELD_IPV4,
52                 .input_index = SRC_INPUT_IPV4,
53                 .offset = sizeof(struct ether_hdr) +
54                         offsetof(struct ipv4_hdr, src_addr),
55         },
56         /* next input field (IPv4 destination address) - 4 consecutive bytes. */
57         {
58                 /* rte_flow uses a bit mask for IPv4 addresses */
59                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
60                 .size = sizeof(uint32_t),
61                 .field_index = DST_FIELD_IPV4,
62                 .input_index = DST_INPUT_IPV4,
63                 .offset = sizeof(struct ether_hdr) +
64                         offsetof(struct ipv4_hdr, dst_addr),
65         },
66         /*
67          * Next 2 fields (src & dst ports) form 4 consecutive bytes.
68          * They share the same input index.
69          */
70         {
71                 /* rte_flow uses a bit mask for protocol ports */
72                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
73                 .size = sizeof(uint16_t),
74                 .field_index = SRCP_FIELD_IPV4,
75                 .input_index = SRCP_DESTP_INPUT_IPV4,
76                 .offset = sizeof(struct ether_hdr) +
77                         sizeof(struct ipv4_hdr) +
78                         offsetof(struct tcp_hdr, src_port),
79         },
80         {
81                 /* rte_flow uses a bit mask for protocol ports */
82                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
83                 .size = sizeof(uint16_t),
84                 .field_index = DSTP_FIELD_IPV4,
85                 .input_index = SRCP_DESTP_INPUT_IPV4,
86                 .offset = sizeof(struct ether_hdr) +
87                         sizeof(struct ipv4_hdr) +
88                         offsetof(struct tcp_hdr, dst_port),
89         },
90 };
91
92 /* parameters for rte_flow_classify_validate and rte_flow_classify_create */
93
94 /* test UDP pattern:
95  * "eth / ipv4 src spec 2.2.2.3 src mask 255.255.255.00 dst spec 2.2.2.7
96  *  dst mask 255.255.255.00 / udp src is 32 dst is 33 / end"
97  */
98 static struct rte_flow_item_ipv4 ipv4_udp_spec_1 = {
99         { 0, 0, 0, 0, 0, 0, IPPROTO_UDP, 0, IPv4(2, 2, 2, 3), IPv4(2, 2, 2, 7)}
100 };
101 static const struct rte_flow_item_ipv4 ipv4_mask_24 = {
102         .hdr = {
103                 .next_proto_id = 0xff,
104                 .src_addr = 0xffffff00,
105                 .dst_addr = 0xffffff00,
106         },
107 };
108 static struct rte_flow_item_udp udp_spec_1 = {
109         { 32, 33, 0, 0 }
110 };
111
112 static struct rte_flow_item  eth_item = { RTE_FLOW_ITEM_TYPE_ETH,
113         0, 0, 0 };
114 static struct rte_flow_item  eth_item_bad = { -1, 0, 0, 0 };
115
116 static struct rte_flow_item  ipv4_udp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
117         &ipv4_udp_spec_1, 0, &ipv4_mask_24};
118 static struct rte_flow_item  ipv4_udp_item_bad = { RTE_FLOW_ITEM_TYPE_IPV4,
119         NULL, 0, NULL};
120
121 static struct rte_flow_item  udp_item_1 = { RTE_FLOW_ITEM_TYPE_UDP,
122         &udp_spec_1, 0, &rte_flow_item_udp_mask};
123 static struct rte_flow_item  udp_item_bad = { RTE_FLOW_ITEM_TYPE_UDP,
124         NULL, 0, NULL};
125
126 static struct rte_flow_item  end_item = { RTE_FLOW_ITEM_TYPE_END,
127         0, 0, 0 };
128 static struct rte_flow_item  end_item_bad = { -1, 0, 0, 0 };
129
130 /* test TCP pattern:
131  * "eth / ipv4 src spec 1.2.3.4 src mask 255.255.255.00 dst spec 5.6.7.8
132  *  dst mask 255.255.255.00 / tcp src is 16 dst is 17 / end"
133  */
134 static struct rte_flow_item_ipv4 ipv4_tcp_spec_1 = {
135         { 0, 0, 0, 0, 0, 0, IPPROTO_TCP, 0, IPv4(1, 2, 3, 4), IPv4(5, 6, 7, 8)}
136 };
137
138 static struct rte_flow_item_tcp tcp_spec_1 = {
139         { 16, 17, 0, 0, 0, 0, 0, 0, 0}
140 };
141
142 static struct rte_flow_item  ipv4_tcp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
143         &ipv4_tcp_spec_1, 0, &ipv4_mask_24};
144
145 static struct rte_flow_item  tcp_item_1 = { RTE_FLOW_ITEM_TYPE_TCP,
146         &tcp_spec_1, 0, &rte_flow_item_tcp_mask};
147
148 /* test SCTP pattern:
149  * "eth / ipv4 src spec 1.2.3.4 src mask 255.255.255.00 dst spec 5.6.7.8
150  *  dst mask 255.255.255.00 / sctp src is 16 dst is 17/ end"
151  */
152 static struct rte_flow_item_ipv4 ipv4_sctp_spec_1 = {
153         { 0, 0, 0, 0, 0, 0, IPPROTO_SCTP, 0, IPv4(11, 12, 13, 14),
154         IPv4(15, 16, 17, 18)}
155 };
156
157 static struct rte_flow_item_sctp sctp_spec_1 = {
158         { 10, 11, 0, 0}
159 };
160
161 static struct rte_flow_item  ipv4_sctp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
162         &ipv4_sctp_spec_1, 0, &ipv4_mask_24};
163
164 static struct rte_flow_item  sctp_item_1 = { RTE_FLOW_ITEM_TYPE_SCTP,
165         &sctp_spec_1, 0, &rte_flow_item_sctp_mask};
166
167
168 /* test actions:
169  * "actions count / end"
170  */
171 struct rte_flow_query_count count = {
172         .reset = 1,
173         .hits_set = 1,
174         .bytes_set = 1,
175         .hits = 0,
176         .bytes = 0,
177 };
178 static struct rte_flow_action count_action = { RTE_FLOW_ACTION_TYPE_COUNT,
179         &count};
180 static struct rte_flow_action count_action_bad = { -1, 0};
181
182 static struct rte_flow_action end_action = { RTE_FLOW_ACTION_TYPE_END, 0};
183 static struct rte_flow_action end_action_bad =  { -1, 0};
184
185 static struct rte_flow_action actions[2];
186
187 /* test attributes */
188 static struct rte_flow_attr attr;
189
190 /* test error */
191 static struct rte_flow_error error;
192
193 /* test pattern */
194 static struct rte_flow_item  pattern[4];
195
196 /* flow classify data for UDP burst */
197 static struct rte_flow_classify_ipv4_5tuple_stats udp_ntuple_stats;
198 static struct rte_flow_classify_stats udp_classify_stats = {
199                 .stats = (void *)&udp_ntuple_stats
200 };
201
202 /* flow classify data for TCP burst */
203 static struct rte_flow_classify_ipv4_5tuple_stats tcp_ntuple_stats;
204 static struct rte_flow_classify_stats tcp_classify_stats = {
205                 .stats = (void *)&tcp_ntuple_stats
206 };
207
208 /* flow classify data for SCTP burst */
209 static struct rte_flow_classify_ipv4_5tuple_stats sctp_ntuple_stats;
210 static struct rte_flow_classify_stats sctp_classify_stats = {
211                 .stats = (void *)&sctp_ntuple_stats
212 };
213 #endif /* TEST_FLOW_CLASSIFY_H_ */