New upstream version 17.11-rc3
[deb_dpdk.git] / test / test / test_flow_classify.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef TEST_FLOW_CLASSIFY_H_
35 #define TEST_FLOW_CLASSIFY_H_
36
37 #define MAX_PKT_BURST      (32)
38 #define NB_SOCKETS         (1)
39 #define MEMPOOL_CACHE_SIZE (256)
40 #define MBUF_SIZE          (512)
41 #define NB_MBUF            (512)
42
43 /* test UDP, TCP and SCTP packets */
44 static struct rte_mempool *mbufpool[NB_SOCKETS];
45 static struct rte_mbuf *bufs[MAX_PKT_BURST];
46
47 /* ACL field definitions for IPv4 5 tuple rule */
48
49 enum {
50         PROTO_FIELD_IPV4,
51         SRC_FIELD_IPV4,
52         DST_FIELD_IPV4,
53         SRCP_FIELD_IPV4,
54         DSTP_FIELD_IPV4,
55         NUM_FIELDS_IPV4
56 };
57
58 enum {
59         PROTO_INPUT_IPV4,
60         SRC_INPUT_IPV4,
61         DST_INPUT_IPV4,
62         SRCP_DESTP_INPUT_IPV4
63 };
64
65 static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = {
66         /* first input field - always one byte long. */
67         {
68                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
69                 .size = sizeof(uint8_t),
70                 .field_index = PROTO_FIELD_IPV4,
71                 .input_index = PROTO_INPUT_IPV4,
72                 .offset = sizeof(struct ether_hdr) +
73                         offsetof(struct ipv4_hdr, next_proto_id),
74         },
75         /* next input field (IPv4 source address) - 4 consecutive bytes. */
76         {
77                 /* rte_flow uses a bit mask for IPv4 addresses */
78                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
79                 .size = sizeof(uint32_t),
80                 .field_index = SRC_FIELD_IPV4,
81                 .input_index = SRC_INPUT_IPV4,
82                 .offset = sizeof(struct ether_hdr) +
83                         offsetof(struct ipv4_hdr, src_addr),
84         },
85         /* next input field (IPv4 destination address) - 4 consecutive bytes. */
86         {
87                 /* rte_flow uses a bit mask for IPv4 addresses */
88                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
89                 .size = sizeof(uint32_t),
90                 .field_index = DST_FIELD_IPV4,
91                 .input_index = DST_INPUT_IPV4,
92                 .offset = sizeof(struct ether_hdr) +
93                         offsetof(struct ipv4_hdr, dst_addr),
94         },
95         /*
96          * Next 2 fields (src & dst ports) form 4 consecutive bytes.
97          * They share the same input index.
98          */
99         {
100                 /* rte_flow uses a bit mask for protocol ports */
101                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
102                 .size = sizeof(uint16_t),
103                 .field_index = SRCP_FIELD_IPV4,
104                 .input_index = SRCP_DESTP_INPUT_IPV4,
105                 .offset = sizeof(struct ether_hdr) +
106                         sizeof(struct ipv4_hdr) +
107                         offsetof(struct tcp_hdr, src_port),
108         },
109         {
110                 /* rte_flow uses a bit mask for protocol ports */
111                 .type = RTE_ACL_FIELD_TYPE_BITMASK,
112                 .size = sizeof(uint16_t),
113                 .field_index = DSTP_FIELD_IPV4,
114                 .input_index = SRCP_DESTP_INPUT_IPV4,
115                 .offset = sizeof(struct ether_hdr) +
116                         sizeof(struct ipv4_hdr) +
117                         offsetof(struct tcp_hdr, dst_port),
118         },
119 };
120
121 /* parameters for rte_flow_classify_validate and rte_flow_classify_create */
122
123 /* test UDP pattern:
124  * "eth / ipv4 src spec 2.2.2.3 src mask 255.255.255.00 dst spec 2.2.2.7
125  *  dst mask 255.255.255.00 / udp src is 32 dst is 33 / end"
126  */
127 static struct rte_flow_item_ipv4 ipv4_udp_spec_1 = {
128         { 0, 0, 0, 0, 0, 0, IPPROTO_UDP, 0, IPv4(2, 2, 2, 3), IPv4(2, 2, 2, 7)}
129 };
130 static const struct rte_flow_item_ipv4 ipv4_mask_24 = {
131         .hdr = {
132                 .next_proto_id = 0xff,
133                 .src_addr = 0xffffff00,
134                 .dst_addr = 0xffffff00,
135         },
136 };
137 static struct rte_flow_item_udp udp_spec_1 = {
138         { 32, 33, 0, 0 }
139 };
140
141 static struct rte_flow_item  eth_item = { RTE_FLOW_ITEM_TYPE_ETH,
142         0, 0, 0 };
143 static struct rte_flow_item  eth_item_bad = { -1, 0, 0, 0 };
144
145 static struct rte_flow_item  ipv4_udp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
146         &ipv4_udp_spec_1, 0, &ipv4_mask_24};
147 static struct rte_flow_item  ipv4_udp_item_bad = { RTE_FLOW_ITEM_TYPE_IPV4,
148         NULL, 0, NULL};
149
150 static struct rte_flow_item  udp_item_1 = { RTE_FLOW_ITEM_TYPE_UDP,
151         &udp_spec_1, 0, &rte_flow_item_udp_mask};
152 static struct rte_flow_item  udp_item_bad = { RTE_FLOW_ITEM_TYPE_UDP,
153         NULL, 0, NULL};
154
155 static struct rte_flow_item  end_item = { RTE_FLOW_ITEM_TYPE_END,
156         0, 0, 0 };
157 static struct rte_flow_item  end_item_bad = { -1, 0, 0, 0 };
158
159 /* test TCP pattern:
160  * "eth / ipv4 src spec 1.2.3.4 src mask 255.255.255.00 dst spec 5.6.7.8
161  *  dst mask 255.255.255.00 / tcp src is 16 dst is 17 / end"
162  */
163 static struct rte_flow_item_ipv4 ipv4_tcp_spec_1 = {
164         { 0, 0, 0, 0, 0, 0, IPPROTO_TCP, 0, IPv4(1, 2, 3, 4), IPv4(5, 6, 7, 8)}
165 };
166
167 static struct rte_flow_item_tcp tcp_spec_1 = {
168         { 16, 17, 0, 0, 0, 0, 0, 0, 0}
169 };
170
171 static struct rte_flow_item  ipv4_tcp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
172         &ipv4_tcp_spec_1, 0, &ipv4_mask_24};
173
174 static struct rte_flow_item  tcp_item_1 = { RTE_FLOW_ITEM_TYPE_TCP,
175         &tcp_spec_1, 0, &rte_flow_item_tcp_mask};
176
177 /* test SCTP pattern:
178  * "eth / ipv4 src spec 1.2.3.4 src mask 255.255.255.00 dst spec 5.6.7.8
179  *  dst mask 255.255.255.00 / sctp src is 16 dst is 17/ end"
180  */
181 static struct rte_flow_item_ipv4 ipv4_sctp_spec_1 = {
182         { 0, 0, 0, 0, 0, 0, IPPROTO_SCTP, 0, IPv4(11, 12, 13, 14),
183         IPv4(15, 16, 17, 18)}
184 };
185
186 static struct rte_flow_item_sctp sctp_spec_1 = {
187         { 10, 11, 0, 0}
188 };
189
190 static struct rte_flow_item  ipv4_sctp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
191         &ipv4_sctp_spec_1, 0, &ipv4_mask_24};
192
193 static struct rte_flow_item  sctp_item_1 = { RTE_FLOW_ITEM_TYPE_SCTP,
194         &sctp_spec_1, 0, &rte_flow_item_sctp_mask};
195
196
197 /* test actions:
198  * "actions count / end"
199  */
200 static struct rte_flow_action count_action = { RTE_FLOW_ACTION_TYPE_COUNT, 0};
201 static struct rte_flow_action count_action_bad = { -1, 0};
202
203 static struct rte_flow_action end_action = { RTE_FLOW_ACTION_TYPE_END, 0};
204 static struct rte_flow_action end_action_bad =  { -1, 0};
205
206 static struct rte_flow_action actions[2];
207
208 /* test attributes */
209 static struct rte_flow_attr attr;
210
211 /* test error */
212 static struct rte_flow_error error;
213
214 /* test pattern */
215 static struct rte_flow_item  pattern[4];
216
217 /* flow classify data for UDP burst */
218 static struct rte_flow_classify_ipv4_5tuple_stats udp_ntuple_stats;
219 static struct rte_flow_classify_stats udp_classify_stats = {
220                 .stats = (void *)&udp_ntuple_stats
221 };
222
223 /* flow classify data for TCP burst */
224 static struct rte_flow_classify_ipv4_5tuple_stats tcp_ntuple_stats;
225 static struct rte_flow_classify_stats tcp_classify_stats = {
226                 .stats = (void *)&tcp_ntuple_stats
227 };
228
229 /* flow classify data for SCTP burst */
230 static struct rte_flow_classify_ipv4_5tuple_stats sctp_ntuple_stats;
231 static struct rte_flow_classify_stats sctp_classify_stats = {
232                 .stats = (void *)&sctp_ntuple_stats
233 };
234 #endif /* TEST_FLOW_CLASSIFY_H_ */