1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #ifndef TEST_FLOW_CLASSIFY_H_
6 #define TEST_FLOW_CLASSIFY_H_
8 #define MAX_PKT_BURST (32)
10 #define MEMPOOL_CACHE_SIZE (256)
11 #define MBUF_SIZE (512)
14 /* test UDP, TCP and SCTP packets */
15 static struct rte_mempool *mbufpool[NB_SOCKETS];
16 static struct rte_mbuf *bufs[MAX_PKT_BURST];
18 /* ACL field definitions for IPv4 5 tuple rule */
36 static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = {
37 /* first input field - always one byte long. */
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),
46 /* next input field (IPv4 source address) - 4 consecutive bytes. */
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),
56 /* next input field (IPv4 destination address) - 4 consecutive bytes. */
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),
67 * Next 2 fields (src & dst ports) form 4 consecutive bytes.
68 * They share the same input index.
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),
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),
92 /* parameters for rte_flow_classify_validate and rte_flow_classify_create */
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"
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)}
101 static const struct rte_flow_item_ipv4 ipv4_mask_24 = {
103 .next_proto_id = 0xff,
104 .src_addr = 0xffffff00,
105 .dst_addr = 0xffffff00,
108 static struct rte_flow_item_udp udp_spec_1 = {
112 static struct rte_flow_item eth_item = { RTE_FLOW_ITEM_TYPE_ETH,
114 static struct rte_flow_item eth_item_bad = { -1, 0, 0, 0 };
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,
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,
126 static struct rte_flow_item end_item = { RTE_FLOW_ITEM_TYPE_END,
128 static struct rte_flow_item end_item_bad = { -1, 0, 0, 0 };
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"
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)}
138 static struct rte_flow_item_tcp tcp_spec_1 = {
139 { 16, 17, 0, 0, 0, 0, 0, 0, 0}
142 static struct rte_flow_item ipv4_tcp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
143 &ipv4_tcp_spec_1, 0, &ipv4_mask_24};
145 static struct rte_flow_item tcp_item_1 = { RTE_FLOW_ITEM_TYPE_TCP,
146 &tcp_spec_1, 0, &rte_flow_item_tcp_mask};
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"
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)}
157 static struct rte_flow_item_sctp sctp_spec_1 = {
161 static struct rte_flow_item ipv4_sctp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
162 &ipv4_sctp_spec_1, 0, &ipv4_mask_24};
164 static struct rte_flow_item sctp_item_1 = { RTE_FLOW_ITEM_TYPE_SCTP,
165 &sctp_spec_1, 0, &rte_flow_item_sctp_mask};
169 * "actions count / end"
171 struct rte_flow_query_count count = {
178 static struct rte_flow_action count_action = { RTE_FLOW_ACTION_TYPE_COUNT,
180 static struct rte_flow_action count_action_bad = { -1, 0};
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};
185 static struct rte_flow_action actions[2];
187 /* test attributes */
188 static struct rte_flow_attr attr;
191 static struct rte_flow_error error;
194 static struct rte_flow_item pattern[4];
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
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
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
213 #endif /* TEST_FLOW_CLASSIFY_H_ */