4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 #ifndef TEST_FLOW_CLASSIFY_H_
35 #define TEST_FLOW_CLASSIFY_H_
37 #define MAX_PKT_BURST (32)
38 #define NB_SOCKETS (1)
39 #define MEMPOOL_CACHE_SIZE (256)
40 #define MBUF_SIZE (512)
43 /* test UDP, TCP and SCTP packets */
44 static struct rte_mempool *mbufpool[NB_SOCKETS];
45 static struct rte_mbuf *bufs[MAX_PKT_BURST];
47 /* ACL field definitions for IPv4 5 tuple rule */
65 static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = {
66 /* first input field - always one byte long. */
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),
75 /* next input field (IPv4 source address) - 4 consecutive bytes. */
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),
85 /* next input field (IPv4 destination address) - 4 consecutive bytes. */
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),
96 * Next 2 fields (src & dst ports) form 4 consecutive bytes.
97 * They share the same input index.
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),
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),
121 /* parameters for rte_flow_classify_validate and rte_flow_classify_create */
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"
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)}
130 static const struct rte_flow_item_ipv4 ipv4_mask_24 = {
132 .next_proto_id = 0xff,
133 .src_addr = 0xffffff00,
134 .dst_addr = 0xffffff00,
137 static struct rte_flow_item_udp udp_spec_1 = {
141 static struct rte_flow_item eth_item = { RTE_FLOW_ITEM_TYPE_ETH,
143 static struct rte_flow_item eth_item_bad = { -1, 0, 0, 0 };
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,
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,
155 static struct rte_flow_item end_item = { RTE_FLOW_ITEM_TYPE_END,
157 static struct rte_flow_item end_item_bad = { -1, 0, 0, 0 };
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"
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)}
167 static struct rte_flow_item_tcp tcp_spec_1 = {
168 { 16, 17, 0, 0, 0, 0, 0, 0, 0}
171 static struct rte_flow_item ipv4_tcp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
172 &ipv4_tcp_spec_1, 0, &ipv4_mask_24};
174 static struct rte_flow_item tcp_item_1 = { RTE_FLOW_ITEM_TYPE_TCP,
175 &tcp_spec_1, 0, &rte_flow_item_tcp_mask};
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"
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)}
186 static struct rte_flow_item_sctp sctp_spec_1 = {
190 static struct rte_flow_item ipv4_sctp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
191 &ipv4_sctp_spec_1, 0, &ipv4_mask_24};
193 static struct rte_flow_item sctp_item_1 = { RTE_FLOW_ITEM_TYPE_SCTP,
194 &sctp_spec_1, 0, &rte_flow_item_sctp_mask};
198 * "actions count / end"
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};
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};
206 static struct rte_flow_action actions[2];
208 /* test attributes */
209 static struct rte_flow_attr attr;
212 static struct rte_flow_error error;
215 static struct rte_flow_item pattern[4];
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
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
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
234 #endif /* TEST_FLOW_CLASSIFY_H_ */