1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include <rte_string_fns.h>
12 #include <rte_byteorder.h>
15 #include <rte_common.h>
19 #define BIT_SIZEOF(x) (sizeof(x) * CHAR_BIT)
21 #define LEN RTE_ACL_MAX_CATEGORIES
23 RTE_ACL_RULE_DEF(acl_ipv4vlan_rule, RTE_ACL_IPV4VLAN_NUM_FIELDS);
25 struct rte_acl_param acl_param = {
27 .socket_id = SOCKET_ID_ANY,
28 .rule_size = RTE_ACL_IPV4VLAN_RULE_SZ,
29 .max_rule_num = 0x30000,
32 struct rte_acl_ipv4vlan_rule acl_rule = {
33 .data = { .priority = 1, .category_mask = 0xff },
35 .src_port_high = UINT16_MAX,
37 .dst_port_high = UINT16_MAX,
40 const uint32_t ipv4_7tuple_layout[RTE_ACL_IPV4VLAN_NUM] = {
41 offsetof(struct ipv4_7tuple, proto),
42 offsetof(struct ipv4_7tuple, vlan),
43 offsetof(struct ipv4_7tuple, ip_src),
44 offsetof(struct ipv4_7tuple, ip_dst),
45 offsetof(struct ipv4_7tuple, port_src),
49 /* byteswap to cpu or network order */
51 bswap_test_data(struct ipv4_7tuple *data, int len, int to_be)
55 for (i = 0; i < len; i++) {
58 /* swap all bytes so that they are in network order */
59 data[i].ip_dst = rte_cpu_to_be_32(data[i].ip_dst);
60 data[i].ip_src = rte_cpu_to_be_32(data[i].ip_src);
61 data[i].port_dst = rte_cpu_to_be_16(data[i].port_dst);
62 data[i].port_src = rte_cpu_to_be_16(data[i].port_src);
63 data[i].vlan = rte_cpu_to_be_16(data[i].vlan);
64 data[i].domain = rte_cpu_to_be_16(data[i].domain);
66 data[i].ip_dst = rte_be_to_cpu_32(data[i].ip_dst);
67 data[i].ip_src = rte_be_to_cpu_32(data[i].ip_src);
68 data[i].port_dst = rte_be_to_cpu_16(data[i].port_dst);
69 data[i].port_src = rte_be_to_cpu_16(data[i].port_src);
70 data[i].vlan = rte_be_to_cpu_16(data[i].vlan);
71 data[i].domain = rte_be_to_cpu_16(data[i].domain);
77 acl_ipv4vlan_check_rule(const struct rte_acl_ipv4vlan_rule *rule)
79 if (rule->src_port_low > rule->src_port_high ||
80 rule->dst_port_low > rule->dst_port_high ||
81 rule->src_mask_len > BIT_SIZEOF(rule->src_addr) ||
82 rule->dst_mask_len > BIT_SIZEOF(rule->dst_addr))
88 acl_ipv4vlan_convert_rule(const struct rte_acl_ipv4vlan_rule *ri,
89 struct acl_ipv4vlan_rule *ro)
93 ro->field[RTE_ACL_IPV4VLAN_PROTO_FIELD].value.u8 = ri->proto;
94 ro->field[RTE_ACL_IPV4VLAN_VLAN1_FIELD].value.u16 = ri->vlan;
95 ro->field[RTE_ACL_IPV4VLAN_VLAN2_FIELD].value.u16 = ri->domain;
96 ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].value.u32 = ri->src_addr;
97 ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].value.u32 = ri->dst_addr;
98 ro->field[RTE_ACL_IPV4VLAN_SRCP_FIELD].value.u16 = ri->src_port_low;
99 ro->field[RTE_ACL_IPV4VLAN_DSTP_FIELD].value.u16 = ri->dst_port_low;
101 ro->field[RTE_ACL_IPV4VLAN_PROTO_FIELD].mask_range.u8 = ri->proto_mask;
102 ro->field[RTE_ACL_IPV4VLAN_VLAN1_FIELD].mask_range.u16 = ri->vlan_mask;
103 ro->field[RTE_ACL_IPV4VLAN_VLAN2_FIELD].mask_range.u16 =
105 ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].mask_range.u32 =
107 ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].mask_range.u32 = ri->dst_mask_len;
108 ro->field[RTE_ACL_IPV4VLAN_SRCP_FIELD].mask_range.u16 =
110 ro->field[RTE_ACL_IPV4VLAN_DSTP_FIELD].mask_range.u16 =
115 * Add ipv4vlan rules to an existing ACL context.
116 * This function is not multi-thread safe.
119 * ACL context to add patterns to.
121 * Array of rules to add to the ACL context.
122 * Note that all fields in rte_acl_ipv4vlan_rule structures are expected
123 * to be in host byte order.
125 * Number of elements in the input array of rules.
127 * - -ENOMEM if there is no space in the ACL context for these rules.
128 * - -EINVAL if the parameters are invalid.
129 * - Zero if operation completed successfully.
132 rte_acl_ipv4vlan_add_rules(struct rte_acl_ctx *ctx,
133 const struct rte_acl_ipv4vlan_rule *rules,
138 struct acl_ipv4vlan_rule rv;
140 if (ctx == NULL || rules == NULL)
143 /* check input rules. */
144 for (i = 0; i != num; i++) {
145 rc = acl_ipv4vlan_check_rule(rules + i);
147 RTE_LOG(ERR, ACL, "%s: rule #%u is invalid\n",
153 /* perform conversion to the internal format and add to the context. */
154 for (i = 0, rc = 0; i != num && rc == 0; i++) {
155 acl_ipv4vlan_convert_rule(rules + i, &rv);
156 rc = rte_acl_add_rules(ctx, (struct rte_acl_rule *)&rv, 1);
163 acl_ipv4vlan_config(struct rte_acl_config *cfg,
164 const uint32_t layout[RTE_ACL_IPV4VLAN_NUM],
165 uint32_t num_categories)
167 static const struct rte_acl_field_def
168 ipv4_defs[RTE_ACL_IPV4VLAN_NUM_FIELDS] = {
170 .type = RTE_ACL_FIELD_TYPE_BITMASK,
171 .size = sizeof(uint8_t),
172 .field_index = RTE_ACL_IPV4VLAN_PROTO_FIELD,
173 .input_index = RTE_ACL_IPV4VLAN_PROTO,
176 .type = RTE_ACL_FIELD_TYPE_BITMASK,
177 .size = sizeof(uint16_t),
178 .field_index = RTE_ACL_IPV4VLAN_VLAN1_FIELD,
179 .input_index = RTE_ACL_IPV4VLAN_VLAN,
182 .type = RTE_ACL_FIELD_TYPE_BITMASK,
183 .size = sizeof(uint16_t),
184 .field_index = RTE_ACL_IPV4VLAN_VLAN2_FIELD,
185 .input_index = RTE_ACL_IPV4VLAN_VLAN,
188 .type = RTE_ACL_FIELD_TYPE_MASK,
189 .size = sizeof(uint32_t),
190 .field_index = RTE_ACL_IPV4VLAN_SRC_FIELD,
191 .input_index = RTE_ACL_IPV4VLAN_SRC,
194 .type = RTE_ACL_FIELD_TYPE_MASK,
195 .size = sizeof(uint32_t),
196 .field_index = RTE_ACL_IPV4VLAN_DST_FIELD,
197 .input_index = RTE_ACL_IPV4VLAN_DST,
200 .type = RTE_ACL_FIELD_TYPE_RANGE,
201 .size = sizeof(uint16_t),
202 .field_index = RTE_ACL_IPV4VLAN_SRCP_FIELD,
203 .input_index = RTE_ACL_IPV4VLAN_PORTS,
206 .type = RTE_ACL_FIELD_TYPE_RANGE,
207 .size = sizeof(uint16_t),
208 .field_index = RTE_ACL_IPV4VLAN_DSTP_FIELD,
209 .input_index = RTE_ACL_IPV4VLAN_PORTS,
213 memcpy(&cfg->defs, ipv4_defs, sizeof(ipv4_defs));
214 cfg->num_fields = RTE_DIM(ipv4_defs);
216 cfg->defs[RTE_ACL_IPV4VLAN_PROTO_FIELD].offset =
217 layout[RTE_ACL_IPV4VLAN_PROTO];
218 cfg->defs[RTE_ACL_IPV4VLAN_VLAN1_FIELD].offset =
219 layout[RTE_ACL_IPV4VLAN_VLAN];
220 cfg->defs[RTE_ACL_IPV4VLAN_VLAN2_FIELD].offset =
221 layout[RTE_ACL_IPV4VLAN_VLAN] +
222 cfg->defs[RTE_ACL_IPV4VLAN_VLAN1_FIELD].size;
223 cfg->defs[RTE_ACL_IPV4VLAN_SRC_FIELD].offset =
224 layout[RTE_ACL_IPV4VLAN_SRC];
225 cfg->defs[RTE_ACL_IPV4VLAN_DST_FIELD].offset =
226 layout[RTE_ACL_IPV4VLAN_DST];
227 cfg->defs[RTE_ACL_IPV4VLAN_SRCP_FIELD].offset =
228 layout[RTE_ACL_IPV4VLAN_PORTS];
229 cfg->defs[RTE_ACL_IPV4VLAN_DSTP_FIELD].offset =
230 layout[RTE_ACL_IPV4VLAN_PORTS] +
231 cfg->defs[RTE_ACL_IPV4VLAN_SRCP_FIELD].size;
233 cfg->num_categories = num_categories;
237 * Analyze set of ipv4vlan rules and build required internal
238 * run-time structures.
239 * This function is not multi-thread safe.
242 * ACL context to build.
244 * Layout of input data to search through.
245 * @param num_categories
246 * Maximum number of categories to use in that build.
248 * - -ENOMEM if couldn't allocate enough memory.
249 * - -EINVAL if the parameters are invalid.
250 * - Negative error code if operation failed.
251 * - Zero if operation completed successfully.
254 rte_acl_ipv4vlan_build(struct rte_acl_ctx *ctx,
255 const uint32_t layout[RTE_ACL_IPV4VLAN_NUM],
256 uint32_t num_categories)
258 struct rte_acl_config cfg;
260 if (ctx == NULL || layout == NULL)
263 memset(&cfg, 0, sizeof(cfg));
264 acl_ipv4vlan_config(&cfg, layout, num_categories);
265 return rte_acl_build(ctx, &cfg);
269 * Test scalar and SSE ACL lookup.
272 test_classify_run(struct rte_acl_ctx *acx, struct ipv4_7tuple test_data[],
276 uint32_t result, count;
277 uint32_t results[dim * RTE_ACL_MAX_CATEGORIES];
278 const uint8_t *data[dim];
279 /* swap all bytes in the data to network order */
280 bswap_test_data(test_data, dim, 1);
282 /* store pointers to test data */
283 for (i = 0; i < (int) dim; i++)
284 data[i] = (uint8_t *)&test_data[i];
287 * these will run quite a few times, it's necessary to test code paths
288 * from num=0 to num>8
290 for (count = 0; count <= dim; count++) {
291 ret = rte_acl_classify(acx, data, results,
292 count, RTE_ACL_MAX_CATEGORIES);
294 printf("Line %i: SSE classify failed!\n", __LINE__);
298 /* check if we allow everything we should allow */
299 for (i = 0; i < (int) count; i++) {
301 results[i * RTE_ACL_MAX_CATEGORIES + ACL_ALLOW];
302 if (result != test_data[i].allow) {
303 printf("Line %i: Error in allow results at %i "
304 "(expected %"PRIu32" got %"PRIu32")!\n",
305 __LINE__, i, test_data[i].allow,
312 /* check if we deny everything we should deny */
313 for (i = 0; i < (int) count; i++) {
314 result = results[i * RTE_ACL_MAX_CATEGORIES + ACL_DENY];
315 if (result != test_data[i].deny) {
316 printf("Line %i: Error in deny results at %i "
317 "(expected %"PRIu32" got %"PRIu32")!\n",
318 __LINE__, i, test_data[i].deny,
326 /* make a quick check for scalar */
327 ret = rte_acl_classify_alg(acx, data, results,
328 dim, RTE_ACL_MAX_CATEGORIES,
329 RTE_ACL_CLASSIFY_SCALAR);
331 printf("Line %i: scalar classify failed!\n", __LINE__);
335 /* check if we allow everything we should allow */
336 for (i = 0; i < (int) dim; i++) {
337 result = results[i * RTE_ACL_MAX_CATEGORIES + ACL_ALLOW];
338 if (result != test_data[i].allow) {
339 printf("Line %i: Error in allow results at %i "
340 "(expected %"PRIu32" got %"PRIu32")!\n",
341 __LINE__, i, test_data[i].allow,
348 /* check if we deny everything we should deny */
349 for (i = 0; i < (int) dim; i++) {
350 result = results[i * RTE_ACL_MAX_CATEGORIES + ACL_DENY];
351 if (result != test_data[i].deny) {
352 printf("Line %i: Error in deny results at %i "
353 "(expected %"PRIu32" got %"PRIu32")!\n",
354 __LINE__, i, test_data[i].deny,
364 /* swap data back to cpu order so that next time tests don't fail */
365 bswap_test_data(test_data, dim, 0);
370 test_classify_buid(struct rte_acl_ctx *acx,
371 const struct rte_acl_ipv4vlan_rule *rules, uint32_t num)
375 /* add rules to the context */
376 ret = rte_acl_ipv4vlan_add_rules(acx, rules, num);
378 printf("Line %i: Adding rules to ACL context failed!\n",
383 /* try building the context */
384 ret = rte_acl_ipv4vlan_build(acx, ipv4_7tuple_layout,
385 RTE_ACL_MAX_CATEGORIES);
387 printf("Line %i: Building ACL context failed!\n", __LINE__);
394 #define TEST_CLASSIFY_ITER 4
397 * Test scalar and SSE ACL lookup.
402 struct rte_acl_ctx *acx;
405 acx = rte_acl_create(&acl_param);
407 printf("Line %i: Error creating ACL context!\n", __LINE__);
412 for (i = 0; i != TEST_CLASSIFY_ITER; i++) {
417 rte_acl_reset_rules(acx);
419 ret = test_classify_buid(acx, acl_test_rules,
420 RTE_DIM(acl_test_rules));
422 printf("Line %i, iter: %d: "
423 "Adding rules to ACL context failed!\n",
428 ret = test_classify_run(acx, acl_test_data,
429 RTE_DIM(acl_test_data));
431 printf("Line %i, iter: %d: %s failed!\n",
432 __LINE__, i, __func__);
436 /* reset rules and make sure that classify still works ok. */
437 rte_acl_reset_rules(acx);
438 ret = test_classify_run(acx, acl_test_data,
439 RTE_DIM(acl_test_data));
441 printf("Line %i, iter: %d: %s failed!\n",
442 __LINE__, i, __func__);
452 test_build_ports_range(void)
454 static const struct rte_acl_ipv4vlan_rule test_rules[] = {
456 /* match all packets. */
459 .category_mask = ACL_ALLOW_MASK,
463 .src_port_high = UINT16_MAX,
465 .dst_port_high = UINT16_MAX,
468 /* match all packets with dst ports [54-65280]. */
471 .category_mask = ACL_ALLOW_MASK,
475 .src_port_high = UINT16_MAX,
477 .dst_port_high = 65280,
480 /* match all packets with dst ports [0-52]. */
483 .category_mask = ACL_ALLOW_MASK,
487 .src_port_high = UINT16_MAX,
492 /* match all packets with dst ports [53]. */
495 .category_mask = ACL_ALLOW_MASK,
499 .src_port_high = UINT16_MAX,
504 /* match all packets with dst ports [65279-65535]. */
507 .category_mask = ACL_ALLOW_MASK,
511 .src_port_high = UINT16_MAX,
512 .dst_port_low = 65279,
513 .dst_port_high = UINT16_MAX,
517 static struct ipv4_7tuple test_data[] = {
520 .ip_src = RTE_IPV4(10, 1, 1, 1),
521 .ip_dst = RTE_IPV4(192, 168, 0, 33),
527 .ip_src = RTE_IPV4(127, 84, 33, 1),
528 .ip_dst = RTE_IPV4(1, 2, 3, 4),
534 struct rte_acl_ctx *acx;
536 uint32_t results[RTE_DIM(test_data)];
537 const uint8_t *data[RTE_DIM(test_data)];
539 acx = rte_acl_create(&acl_param);
541 printf("Line %i: Error creating ACL context!\n", __LINE__);
545 /* swap all bytes in the data to network order */
546 bswap_test_data(test_data, RTE_DIM(test_data), 1);
548 /* store pointers to test data */
549 for (i = 0; i != RTE_DIM(test_data); i++)
550 data[i] = (uint8_t *)&test_data[i];
552 for (i = 0; i != RTE_DIM(test_rules); i++) {
554 ret = test_classify_buid(acx, test_rules, i + 1);
556 printf("Line %i, iter: %d: "
557 "Adding rules to ACL context failed!\n",
561 ret = rte_acl_classify(acx, data, results,
564 printf("Line %i, iter: %d: classify failed!\n",
570 for (j = 0; j != RTE_DIM(results); j++) {
571 if (results[j] != test_data[j].allow) {
572 printf("Line %i: Error in allow results at %i "
573 "(expected %"PRIu32" got %"PRIu32")!\n",
574 __LINE__, j, test_data[j].allow,
581 bswap_test_data(test_data, RTE_DIM(test_data), 0);
588 convert_rule(const struct rte_acl_ipv4vlan_rule *ri,
589 struct acl_ipv4vlan_rule *ro)
593 ro->field[RTE_ACL_IPV4VLAN_PROTO_FIELD].value.u8 = ri->proto;
594 ro->field[RTE_ACL_IPV4VLAN_VLAN1_FIELD].value.u16 = ri->vlan;
595 ro->field[RTE_ACL_IPV4VLAN_VLAN2_FIELD].value.u16 = ri->domain;
596 ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].value.u32 = ri->src_addr;
597 ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].value.u32 = ri->dst_addr;
598 ro->field[RTE_ACL_IPV4VLAN_SRCP_FIELD].value.u16 = ri->src_port_low;
599 ro->field[RTE_ACL_IPV4VLAN_DSTP_FIELD].value.u16 = ri->dst_port_low;
601 ro->field[RTE_ACL_IPV4VLAN_PROTO_FIELD].mask_range.u8 = ri->proto_mask;
602 ro->field[RTE_ACL_IPV4VLAN_VLAN1_FIELD].mask_range.u16 = ri->vlan_mask;
603 ro->field[RTE_ACL_IPV4VLAN_VLAN2_FIELD].mask_range.u16 =
605 ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].mask_range.u32 =
607 ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].mask_range.u32 = ri->dst_mask_len;
608 ro->field[RTE_ACL_IPV4VLAN_SRCP_FIELD].mask_range.u16 =
610 ro->field[RTE_ACL_IPV4VLAN_DSTP_FIELD].mask_range.u16 =
615 * Convert IPV4 source and destination from RTE_ACL_FIELD_TYPE_MASK to
616 * RTE_ACL_FIELD_TYPE_BITMASK.
619 convert_rule_1(const struct rte_acl_ipv4vlan_rule *ri,
620 struct acl_ipv4vlan_rule *ro)
624 convert_rule(ri, ro);
625 v = ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].mask_range.u32;
626 ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].mask_range.u32 =
627 RTE_ACL_MASKLEN_TO_BITMASK(v, sizeof(v));
628 v = ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].mask_range.u32;
629 ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].mask_range.u32 =
630 RTE_ACL_MASKLEN_TO_BITMASK(v, sizeof(v));
634 * Convert IPV4 source and destination from RTE_ACL_FIELD_TYPE_MASK to
635 * RTE_ACL_FIELD_TYPE_RANGE.
638 convert_rule_2(const struct rte_acl_ipv4vlan_rule *ri,
639 struct acl_ipv4vlan_rule *ro)
641 uint32_t hi, lo, mask;
643 convert_rule(ri, ro);
645 mask = ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].mask_range.u32;
646 mask = RTE_ACL_MASKLEN_TO_BITMASK(mask, sizeof(mask));
647 lo = ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].value.u32 & mask;
649 ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].value.u32 = lo;
650 ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD].mask_range.u32 = hi;
652 mask = ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].mask_range.u32;
653 mask = RTE_ACL_MASKLEN_TO_BITMASK(mask, sizeof(mask));
654 lo = ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].value.u32 & mask;
656 ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].value.u32 = lo;
657 ro->field[RTE_ACL_IPV4VLAN_DST_FIELD].mask_range.u32 = hi;
661 * Convert rte_acl_ipv4vlan_rule: swap VLAN and PORTS rule fields.
664 convert_rule_3(const struct rte_acl_ipv4vlan_rule *ri,
665 struct acl_ipv4vlan_rule *ro)
667 struct rte_acl_field t1, t2;
669 convert_rule(ri, ro);
671 t1 = ro->field[RTE_ACL_IPV4VLAN_VLAN1_FIELD];
672 t2 = ro->field[RTE_ACL_IPV4VLAN_VLAN2_FIELD];
674 ro->field[RTE_ACL_IPV4VLAN_VLAN1_FIELD] =
675 ro->field[RTE_ACL_IPV4VLAN_SRCP_FIELD];
676 ro->field[RTE_ACL_IPV4VLAN_VLAN2_FIELD] =
677 ro->field[RTE_ACL_IPV4VLAN_DSTP_FIELD];
679 ro->field[RTE_ACL_IPV4VLAN_SRCP_FIELD] = t1;
680 ro->field[RTE_ACL_IPV4VLAN_DSTP_FIELD] = t2;
684 * Convert rte_acl_ipv4vlan_rule: swap SRC and DST IPv4 address rules.
687 convert_rule_4(const struct rte_acl_ipv4vlan_rule *ri,
688 struct acl_ipv4vlan_rule *ro)
690 struct rte_acl_field t;
692 convert_rule(ri, ro);
694 t = ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD];
695 ro->field[RTE_ACL_IPV4VLAN_SRC_FIELD] =
696 ro->field[RTE_ACL_IPV4VLAN_DST_FIELD];
698 ro->field[RTE_ACL_IPV4VLAN_DST_FIELD] = t;
702 ipv4vlan_config(struct rte_acl_config *cfg,
703 const uint32_t layout[RTE_ACL_IPV4VLAN_NUM],
704 uint32_t num_categories)
706 static const struct rte_acl_field_def
707 ipv4_defs[RTE_ACL_IPV4VLAN_NUM_FIELDS] = {
709 .type = RTE_ACL_FIELD_TYPE_BITMASK,
710 .size = sizeof(uint8_t),
711 .field_index = RTE_ACL_IPV4VLAN_PROTO_FIELD,
712 .input_index = RTE_ACL_IPV4VLAN_PROTO,
715 .type = RTE_ACL_FIELD_TYPE_BITMASK,
716 .size = sizeof(uint16_t),
717 .field_index = RTE_ACL_IPV4VLAN_VLAN1_FIELD,
718 .input_index = RTE_ACL_IPV4VLAN_VLAN,
721 .type = RTE_ACL_FIELD_TYPE_BITMASK,
722 .size = sizeof(uint16_t),
723 .field_index = RTE_ACL_IPV4VLAN_VLAN2_FIELD,
724 .input_index = RTE_ACL_IPV4VLAN_VLAN,
727 .type = RTE_ACL_FIELD_TYPE_MASK,
728 .size = sizeof(uint32_t),
729 .field_index = RTE_ACL_IPV4VLAN_SRC_FIELD,
730 .input_index = RTE_ACL_IPV4VLAN_SRC,
733 .type = RTE_ACL_FIELD_TYPE_MASK,
734 .size = sizeof(uint32_t),
735 .field_index = RTE_ACL_IPV4VLAN_DST_FIELD,
736 .input_index = RTE_ACL_IPV4VLAN_DST,
739 .type = RTE_ACL_FIELD_TYPE_RANGE,
740 .size = sizeof(uint16_t),
741 .field_index = RTE_ACL_IPV4VLAN_SRCP_FIELD,
742 .input_index = RTE_ACL_IPV4VLAN_PORTS,
745 .type = RTE_ACL_FIELD_TYPE_RANGE,
746 .size = sizeof(uint16_t),
747 .field_index = RTE_ACL_IPV4VLAN_DSTP_FIELD,
748 .input_index = RTE_ACL_IPV4VLAN_PORTS,
752 memcpy(&cfg->defs, ipv4_defs, sizeof(ipv4_defs));
753 cfg->num_fields = RTE_DIM(ipv4_defs);
755 cfg->defs[RTE_ACL_IPV4VLAN_PROTO_FIELD].offset =
756 layout[RTE_ACL_IPV4VLAN_PROTO];
757 cfg->defs[RTE_ACL_IPV4VLAN_VLAN1_FIELD].offset =
758 layout[RTE_ACL_IPV4VLAN_VLAN];
759 cfg->defs[RTE_ACL_IPV4VLAN_VLAN2_FIELD].offset =
760 layout[RTE_ACL_IPV4VLAN_VLAN] +
761 cfg->defs[RTE_ACL_IPV4VLAN_VLAN1_FIELD].size;
762 cfg->defs[RTE_ACL_IPV4VLAN_SRC_FIELD].offset =
763 layout[RTE_ACL_IPV4VLAN_SRC];
764 cfg->defs[RTE_ACL_IPV4VLAN_DST_FIELD].offset =
765 layout[RTE_ACL_IPV4VLAN_DST];
766 cfg->defs[RTE_ACL_IPV4VLAN_SRCP_FIELD].offset =
767 layout[RTE_ACL_IPV4VLAN_PORTS];
768 cfg->defs[RTE_ACL_IPV4VLAN_DSTP_FIELD].offset =
769 layout[RTE_ACL_IPV4VLAN_PORTS] +
770 cfg->defs[RTE_ACL_IPV4VLAN_SRCP_FIELD].size;
772 cfg->num_categories = num_categories;
776 convert_rules(struct rte_acl_ctx *acx,
777 void (*convert)(const struct rte_acl_ipv4vlan_rule *,
778 struct acl_ipv4vlan_rule *),
779 const struct rte_acl_ipv4vlan_rule *rules, uint32_t num)
783 struct acl_ipv4vlan_rule r;
785 for (i = 0; i != num; i++) {
786 convert(rules + i, &r);
787 rc = rte_acl_add_rules(acx, (struct rte_acl_rule *)&r, 1);
789 printf("Line %i: Adding rule %u to ACL context "
790 "failed with error code: %d\n",
800 convert_config(struct rte_acl_config *cfg)
802 ipv4vlan_config(cfg, ipv4_7tuple_layout, RTE_ACL_MAX_CATEGORIES);
806 * Convert rte_acl_ipv4vlan_rule to use RTE_ACL_FIELD_TYPE_BITMASK.
809 convert_config_1(struct rte_acl_config *cfg)
811 ipv4vlan_config(cfg, ipv4_7tuple_layout, RTE_ACL_MAX_CATEGORIES);
812 cfg->defs[RTE_ACL_IPV4VLAN_SRC_FIELD].type = RTE_ACL_FIELD_TYPE_BITMASK;
813 cfg->defs[RTE_ACL_IPV4VLAN_DST_FIELD].type = RTE_ACL_FIELD_TYPE_BITMASK;
817 * Convert rte_acl_ipv4vlan_rule to use RTE_ACL_FIELD_TYPE_RANGE.
820 convert_config_2(struct rte_acl_config *cfg)
822 ipv4vlan_config(cfg, ipv4_7tuple_layout, RTE_ACL_MAX_CATEGORIES);
823 cfg->defs[RTE_ACL_IPV4VLAN_SRC_FIELD].type = RTE_ACL_FIELD_TYPE_RANGE;
824 cfg->defs[RTE_ACL_IPV4VLAN_DST_FIELD].type = RTE_ACL_FIELD_TYPE_RANGE;
828 * Convert rte_acl_ipv4vlan_rule: swap VLAN and PORTS rule definitions.
831 convert_config_3(struct rte_acl_config *cfg)
833 struct rte_acl_field_def t1, t2;
835 ipv4vlan_config(cfg, ipv4_7tuple_layout, RTE_ACL_MAX_CATEGORIES);
837 t1 = cfg->defs[RTE_ACL_IPV4VLAN_VLAN1_FIELD];
838 t2 = cfg->defs[RTE_ACL_IPV4VLAN_VLAN2_FIELD];
840 /* swap VLAN1 and SRCP rule definition. */
841 cfg->defs[RTE_ACL_IPV4VLAN_VLAN1_FIELD] =
842 cfg->defs[RTE_ACL_IPV4VLAN_SRCP_FIELD];
843 cfg->defs[RTE_ACL_IPV4VLAN_VLAN1_FIELD].field_index = t1.field_index;
844 cfg->defs[RTE_ACL_IPV4VLAN_VLAN1_FIELD].input_index = t1.input_index;
846 /* swap VLAN2 and DSTP rule definition. */
847 cfg->defs[RTE_ACL_IPV4VLAN_VLAN2_FIELD] =
848 cfg->defs[RTE_ACL_IPV4VLAN_DSTP_FIELD];
849 cfg->defs[RTE_ACL_IPV4VLAN_VLAN2_FIELD].field_index = t2.field_index;
850 cfg->defs[RTE_ACL_IPV4VLAN_VLAN2_FIELD].input_index = t2.input_index;
852 cfg->defs[RTE_ACL_IPV4VLAN_SRCP_FIELD].type = t1.type;
853 cfg->defs[RTE_ACL_IPV4VLAN_SRCP_FIELD].size = t1.size;
854 cfg->defs[RTE_ACL_IPV4VLAN_SRCP_FIELD].offset = t1.offset;
856 cfg->defs[RTE_ACL_IPV4VLAN_DSTP_FIELD].type = t2.type;
857 cfg->defs[RTE_ACL_IPV4VLAN_DSTP_FIELD].size = t2.size;
858 cfg->defs[RTE_ACL_IPV4VLAN_DSTP_FIELD].offset = t2.offset;
862 * Convert rte_acl_ipv4vlan_rule: swap SRC and DST ip address rule definitions.
865 convert_config_4(struct rte_acl_config *cfg)
867 struct rte_acl_field_def t;
869 ipv4vlan_config(cfg, ipv4_7tuple_layout, RTE_ACL_MAX_CATEGORIES);
871 t = cfg->defs[RTE_ACL_IPV4VLAN_SRC_FIELD];
873 cfg->defs[RTE_ACL_IPV4VLAN_SRC_FIELD] =
874 cfg->defs[RTE_ACL_IPV4VLAN_DST_FIELD];
875 cfg->defs[RTE_ACL_IPV4VLAN_SRC_FIELD].field_index = t.field_index;
876 cfg->defs[RTE_ACL_IPV4VLAN_SRC_FIELD].input_index = t.input_index;
878 cfg->defs[RTE_ACL_IPV4VLAN_DST_FIELD].type = t.type;
879 cfg->defs[RTE_ACL_IPV4VLAN_DST_FIELD].size = t.size;
880 cfg->defs[RTE_ACL_IPV4VLAN_DST_FIELD].offset = t.offset;
885 build_convert_rules(struct rte_acl_ctx *acx,
886 void (*config)(struct rte_acl_config *),
889 struct rte_acl_config cfg;
891 memset(&cfg, 0, sizeof(cfg));
893 cfg.max_size = max_size;
894 return rte_acl_build(acx, &cfg);
898 test_convert_rules(const char *desc,
899 void (*config)(struct rte_acl_config *),
900 void (*convert)(const struct rte_acl_ipv4vlan_rule *,
901 struct acl_ipv4vlan_rule *))
903 struct rte_acl_ctx *acx;
906 static const size_t mem_sizes[] = {0, -1};
908 printf("running %s(%s)\n", __func__, desc);
910 acx = rte_acl_create(&acl_param);
912 printf("Line %i: Error creating ACL context!\n", __LINE__);
916 rc = convert_rules(acx, convert, acl_test_rules,
917 RTE_DIM(acl_test_rules));
919 printf("Line %i: Error converting ACL rules!\n", __LINE__);
921 for (i = 0; rc == 0 && i != RTE_DIM(mem_sizes); i++) {
923 rc = build_convert_rules(acx, config, mem_sizes[i]);
925 printf("Line %i: Error @ build_convert_rules(%zu)!\n",
926 __LINE__, mem_sizes[i]);
930 rc = test_classify_run(acx, acl_test_data,
931 RTE_DIM(acl_test_data));
933 printf("%s failed at line %i, max_size=%zu\n",
934 __func__, __LINE__, mem_sizes[i]);
944 static const struct {
946 void (*config)(struct rte_acl_config *);
947 void (*convert)(const struct rte_acl_ipv4vlan_rule *,
948 struct acl_ipv4vlan_rule *);
949 } convert_param[] = {
951 "acl_ipv4vlan_tuple",
956 "acl_ipv4vlan_tuple, RTE_ACL_FIELD_TYPE_BITMASK type "
962 "acl_ipv4vlan_tuple, RTE_ACL_FIELD_TYPE_RANGE type "
968 "acl_ipv4vlan_tuple: swap VLAN and PORTs order",
973 "acl_ipv4vlan_tuple: swap SRC and DST IPv4 order",
982 for (i = 0; i != RTE_DIM(convert_param); i++) {
983 rc = test_convert_rules(convert_param[i].desc,
984 convert_param[i].config,
985 convert_param[i].convert);
987 printf("%s for test-case: %s failed, error code: %d;\n",
988 __func__, convert_param[i].desc, rc);
997 * Test wrong layout behavior
998 * This test supplies the ACL context with invalid layout, which results in
999 * ACL matching the wrong stuff. However, it should match the wrong stuff
1000 * the right way. We switch around source and destination addresses,
1001 * source and destination ports, and protocol will point to first byte of
1005 test_invalid_layout(void)
1007 struct rte_acl_ctx *acx;
1010 uint32_t results[RTE_DIM(invalid_layout_data)];
1011 const uint8_t *data[RTE_DIM(invalid_layout_data)];
1013 const uint32_t layout[RTE_ACL_IPV4VLAN_NUM] = {
1014 /* proto points to destination port's first byte */
1015 offsetof(struct ipv4_7tuple, port_dst),
1017 0, /* VLAN not used */
1019 /* src and dst addresses are swapped */
1020 offsetof(struct ipv4_7tuple, ip_dst),
1021 offsetof(struct ipv4_7tuple, ip_src),
1024 * we can't swap ports here, so we will swap
1027 offsetof(struct ipv4_7tuple, port_src),
1030 acx = rte_acl_create(&acl_param);
1032 printf("Line %i: Error creating ACL context!\n", __LINE__);
1036 /* putting a lot of rules into the context results in greater
1037 * coverage numbers. it doesn't matter if they are identical */
1038 for (i = 0; i < 1000; i++) {
1039 /* add rules to the context */
1040 ret = rte_acl_ipv4vlan_add_rules(acx, invalid_layout_rules,
1041 RTE_DIM(invalid_layout_rules));
1043 printf("Line %i: Adding rules to ACL context failed!\n",
1050 /* try building the context */
1051 ret = rte_acl_ipv4vlan_build(acx, layout, 1);
1053 printf("Line %i: Building ACL context failed!\n", __LINE__);
1058 /* swap all bytes in the data to network order */
1059 bswap_test_data(invalid_layout_data, RTE_DIM(invalid_layout_data), 1);
1062 for (i = 0; i < (int) RTE_DIM(invalid_layout_data); i++) {
1063 data[i] = (uint8_t *)&invalid_layout_data[i];
1066 /* classify tuples */
1067 ret = rte_acl_classify_alg(acx, data, results,
1068 RTE_DIM(results), 1, RTE_ACL_CLASSIFY_SCALAR);
1070 printf("Line %i: SSE classify failed!\n", __LINE__);
1075 for (i = 0; i < (int) RTE_DIM(results); i++) {
1076 if (results[i] != invalid_layout_data[i].allow) {
1077 printf("Line %i: Wrong results at %i "
1078 "(result=%u, should be %u)!\n",
1079 __LINE__, i, results[i],
1080 invalid_layout_data[i].allow);
1085 /* classify tuples (scalar) */
1086 ret = rte_acl_classify_alg(acx, data, results, RTE_DIM(results), 1,
1087 RTE_ACL_CLASSIFY_SCALAR);
1090 printf("Line %i: Scalar classify failed!\n", __LINE__);
1095 for (i = 0; i < (int) RTE_DIM(results); i++) {
1096 if (results[i] != invalid_layout_data[i].allow) {
1097 printf("Line %i: Wrong results at %i "
1098 "(result=%u, should be %u)!\n",
1099 __LINE__, i, results[i],
1100 invalid_layout_data[i].allow);
1107 /* swap data back to cpu order so that next time tests don't fail */
1108 bswap_test_data(invalid_layout_data, RTE_DIM(invalid_layout_data), 0);
1113 /* swap data back to cpu order so that next time tests don't fail */
1114 bswap_test_data(invalid_layout_data, RTE_DIM(invalid_layout_data), 0);
1122 * Test creating and finding ACL contexts, and adding rules
1125 test_create_find_add(void)
1127 struct rte_acl_param param;
1128 struct rte_acl_ctx *acx, *acx2, *tmp;
1129 struct rte_acl_ipv4vlan_rule rules[LEN];
1131 const uint32_t layout[RTE_ACL_IPV4VLAN_NUM] = {0};
1133 const char *acx_name = "acx";
1134 const char *acx2_name = "acx2";
1137 /* create two contexts */
1138 memcpy(¶m, &acl_param, sizeof(param));
1139 param.max_rule_num = 2;
1141 param.name = acx_name;
1142 acx = rte_acl_create(¶m);
1144 printf("Line %i: Error creating %s!\n", __LINE__, acx_name);
1148 param.name = acx2_name;
1149 acx2 = rte_acl_create(¶m);
1150 if (acx2 == NULL || acx2 == acx) {
1151 printf("Line %i: Error creating %s!\n", __LINE__, acx2_name);
1156 /* try to create third one, with an existing name */
1157 param.name = acx_name;
1158 tmp = rte_acl_create(¶m);
1160 printf("Line %i: Creating context with existing name "
1168 param.name = acx2_name;
1169 tmp = rte_acl_create(¶m);
1171 printf("Line %i: Creating context with existing "
1172 "name test 2 failed!\n",
1179 /* try to find existing ACL contexts */
1180 tmp = rte_acl_find_existing(acx_name);
1182 printf("Line %i: Finding %s failed!\n", __LINE__, acx_name);
1188 tmp = rte_acl_find_existing(acx2_name);
1190 printf("Line %i: Finding %s failed!\n", __LINE__, acx2_name);
1196 /* try to find non-existing context */
1197 tmp = rte_acl_find_existing("invalid");
1199 printf("Line %i: Non-existent ACL context found!\n", __LINE__);
1207 /* create valid (but severely limited) acx */
1208 memcpy(¶m, &acl_param, sizeof(param));
1209 param.max_rule_num = LEN;
1211 acx = rte_acl_create(¶m);
1213 printf("Line %i: Error creating %s!\n", __LINE__, param.name);
1217 /* create dummy acl */
1218 for (i = 0; i < LEN; i++) {
1219 memcpy(&rules[i], &acl_rule,
1220 sizeof(struct rte_acl_ipv4vlan_rule));
1222 rules[i].data.userdata = i + 1;
1223 /* one rule per category */
1224 rules[i].data.category_mask = 1 << i;
1227 /* try filling up the context */
1228 ret = rte_acl_ipv4vlan_add_rules(acx, rules, LEN);
1230 printf("Line %i: Adding %i rules to ACL context failed!\n",
1235 /* try adding to a (supposedly) full context */
1236 ret = rte_acl_ipv4vlan_add_rules(acx, rules, 1);
1238 printf("Line %i: Adding rules to full ACL context should"
1239 "have failed!\n", __LINE__);
1243 /* try building the context */
1244 ret = rte_acl_ipv4vlan_build(acx, layout, RTE_ACL_MAX_CATEGORIES);
1246 printf("Line %i: Building ACL context failed!\n", __LINE__);
1261 * test various invalid rules
1264 test_invalid_rules(void)
1266 struct rte_acl_ctx *acx;
1269 struct rte_acl_ipv4vlan_rule rule;
1271 acx = rte_acl_create(&acl_param);
1273 printf("Line %i: Error creating ACL context!\n", __LINE__);
1277 /* test inverted high/low source and destination ports.
1278 * originally, there was a problem with memory consumption when using
1281 /* create dummy acl */
1282 memcpy(&rule, &acl_rule, sizeof(struct rte_acl_ipv4vlan_rule));
1283 rule.data.userdata = 1;
1284 rule.dst_port_low = 0xfff0;
1285 rule.dst_port_high = 0x0010;
1287 /* add rules to context and try to build it */
1288 ret = rte_acl_ipv4vlan_add_rules(acx, &rule, 1);
1290 printf("Line %i: Adding rules to ACL context "
1291 "should have failed!\n", __LINE__);
1295 rule.dst_port_low = 0x0;
1296 rule.dst_port_high = 0xffff;
1297 rule.src_port_low = 0xfff0;
1298 rule.src_port_high = 0x0010;
1300 /* add rules to context and try to build it */
1301 ret = rte_acl_ipv4vlan_add_rules(acx, &rule, 1);
1303 printf("Line %i: Adding rules to ACL context "
1304 "should have failed!\n", __LINE__);
1308 rule.dst_port_low = 0x0;
1309 rule.dst_port_high = 0xffff;
1310 rule.src_port_low = 0x0;
1311 rule.src_port_high = 0xffff;
1313 rule.dst_mask_len = 33;
1315 /* add rules to context and try to build it */
1316 ret = rte_acl_ipv4vlan_add_rules(acx, &rule, 1);
1318 printf("Line %i: Adding rules to ACL context "
1319 "should have failed!\n", __LINE__);
1323 rule.dst_mask_len = 0;
1324 rule.src_mask_len = 33;
1326 /* add rules to context and try to build it */
1327 ret = rte_acl_ipv4vlan_add_rules(acx, &rule, 1);
1329 printf("Line %i: Adding rules to ACL context "
1330 "should have failed!\n", __LINE__);
1345 * test functions by passing invalid or
1346 * non-workable parameters.
1348 * we do very limited testing of classify functions here
1349 * because those are performance-critical and
1350 * thus don't do much parameter checking.
1353 test_invalid_parameters(void)
1355 struct rte_acl_param param;
1356 struct rte_acl_ctx *acx;
1357 struct rte_acl_ipv4vlan_rule rule;
1360 uint32_t layout[RTE_ACL_IPV4VLAN_NUM] = {0};
1368 acx = rte_acl_create(NULL);
1370 printf("Line %i: ACL context creation with NULL param "
1371 "should have failed!\n", __LINE__);
1376 /* zero rule size */
1377 memcpy(¶m, &acl_param, sizeof(param));
1378 param.rule_size = 0;
1380 acx = rte_acl_create(¶m);
1382 printf("Line %i: ACL context creation with zero rule len "
1383 "failed!\n", __LINE__);
1388 /* zero max rule num */
1389 memcpy(¶m, &acl_param, sizeof(param));
1390 param.max_rule_num = 0;
1392 acx = rte_acl_create(¶m);
1394 printf("Line %i: ACL context creation with zero rule num "
1395 "failed!\n", __LINE__);
1400 if (rte_eal_has_hugepages()) {
1401 /* invalid NUMA node */
1402 memcpy(¶m, &acl_param, sizeof(param));
1403 param.socket_id = RTE_MAX_NUMA_NODES + 1;
1405 acx = rte_acl_create(¶m);
1407 printf("Line %i: ACL context creation with invalid "
1408 "NUMA should have failed!\n", __LINE__);
1415 memcpy(¶m, &acl_param, sizeof(param));
1418 acx = rte_acl_create(¶m);
1420 printf("Line %i: ACL context creation with NULL name "
1421 "should have failed!\n", __LINE__);
1427 * rte_acl_find_existing
1430 acx = rte_acl_find_existing(NULL);
1432 printf("Line %i: NULL ACL context found!\n", __LINE__);
1438 * rte_acl_ipv4vlan_add_rules
1441 /* initialize everything */
1442 memcpy(¶m, &acl_param, sizeof(param));
1443 acx = rte_acl_create(¶m);
1445 printf("Line %i: ACL context creation failed!\n", __LINE__);
1449 memcpy(&rule, &acl_rule, sizeof(rule));
1452 result = rte_acl_ipv4vlan_add_rules(NULL, &rule, 1);
1454 printf("Line %i: Adding rules with NULL ACL context "
1455 "should have failed!\n", __LINE__);
1461 result = rte_acl_ipv4vlan_add_rules(acx, NULL, 1);
1463 printf("Line %i: Adding NULL rule to ACL context "
1464 "should have failed!\n", __LINE__);
1469 /* zero count (should succeed) */
1470 result = rte_acl_ipv4vlan_add_rules(acx, &rule, 0);
1472 printf("Line %i: Adding 0 rules to ACL context failed!\n",
1478 /* free ACL context */
1483 * rte_acl_ipv4vlan_build
1486 /* reinitialize context */
1487 memcpy(¶m, &acl_param, sizeof(param));
1488 acx = rte_acl_create(¶m);
1490 printf("Line %i: ACL context creation failed!\n", __LINE__);
1495 result = rte_acl_ipv4vlan_build(NULL, layout, 1);
1497 printf("Line %i: Building with NULL context "
1498 "should have failed!\n", __LINE__);
1504 result = rte_acl_ipv4vlan_build(acx, NULL, 1);
1506 printf("Line %i: Building with NULL layout "
1507 "should have failed!\n", __LINE__);
1512 /* zero categories (should not fail) */
1513 result = rte_acl_ipv4vlan_build(acx, layout, 0);
1515 printf("Line %i: Building with 0 categories should fail!\n",
1521 /* SSE classify test */
1523 /* cover zero categories in classify (should not fail) */
1524 result = rte_acl_classify(acx, NULL, NULL, 0, 0);
1526 printf("Line %i: SSE classify with zero categories "
1527 "failed!\n", __LINE__);
1532 /* cover invalid but positive categories in classify */
1533 result = rte_acl_classify(acx, NULL, NULL, 0, 3);
1535 printf("Line %i: SSE classify with 3 categories "
1536 "should have failed!\n", __LINE__);
1541 /* scalar classify test */
1543 /* cover zero categories in classify (should not fail) */
1544 result = rte_acl_classify_alg(acx, NULL, NULL, 0, 0,
1545 RTE_ACL_CLASSIFY_SCALAR);
1547 printf("Line %i: Scalar classify with zero categories "
1548 "failed!\n", __LINE__);
1553 /* cover invalid but positive categories in classify */
1554 result = rte_acl_classify(acx, NULL, NULL, 0, 3);
1556 printf("Line %i: Scalar classify with 3 categories "
1557 "should have failed!\n", __LINE__);
1562 /* free ACL context */
1567 * make sure void functions don't crash with NULL parameters
1578 * Various tests that don't test much but improve coverage
1583 struct rte_acl_param param;
1584 struct rte_acl_ctx *acx;
1586 /* create context */
1587 memcpy(¶m, &acl_param, sizeof(param));
1589 acx = rte_acl_create(¶m);
1591 printf("Line %i: Error creating ACL context!\n", __LINE__);
1595 /* dump context with rules - useful for coverage */
1596 rte_acl_list_dump();
1606 get_u32_range_max(void)
1611 for (i = 0; i != RTE_DIM(acl_u32_range_test_rules); i++)
1612 max = RTE_MAX(max, acl_u32_range_test_rules[i].src_mask_len);
1617 get_u32_range_min(void)
1622 for (i = 0; i != RTE_DIM(acl_u32_range_test_rules); i++)
1623 min = RTE_MIN(min, acl_u32_range_test_rules[i].src_addr);
1627 static const struct rte_acl_ipv4vlan_rule *
1628 find_u32_range_rule(uint32_t val)
1632 for (i = 0; i != RTE_DIM(acl_u32_range_test_rules); i++) {
1633 if (val >= acl_u32_range_test_rules[i].src_addr &&
1634 val <= acl_u32_range_test_rules[i].src_mask_len)
1635 return acl_u32_range_test_rules + i;
1641 fill_u32_range_data(struct ipv4_7tuple tdata[], uint32_t start, uint32_t num)
1644 const struct rte_acl_ipv4vlan_rule *r;
1646 for (i = 0; i != num; i++) {
1647 tdata[i].ip_src = start + i;
1648 r = find_u32_range_rule(start + i);
1650 tdata[i].allow = r->data.userdata;
1655 test_u32_range(void)
1658 uint32_t i, k, max, min;
1659 struct rte_acl_ctx *acx;
1660 struct acl_ipv4vlan_rule r;
1661 struct ipv4_7tuple test_data[64];
1663 acx = rte_acl_create(&acl_param);
1665 printf("%s#%i: Error creating ACL context!\n",
1666 __func__, __LINE__);
1670 for (i = 0; i != RTE_DIM(acl_u32_range_test_rules); i++) {
1671 convert_rule(&acl_u32_range_test_rules[i], &r);
1672 rc = rte_acl_add_rules(acx, (struct rte_acl_rule *)&r, 1);
1674 printf("%s#%i: Adding rule to ACL context "
1675 "failed with error code: %d\n",
1676 __func__, __LINE__, rc);
1682 rc = build_convert_rules(acx, convert_config_2, 0);
1684 printf("%s#%i Error @ build_convert_rules!\n",
1685 __func__, __LINE__);
1690 max = get_u32_range_max();
1691 min = get_u32_range_min();
1693 max = RTE_MAX(max, max + 1);
1694 min = RTE_MIN(min, min - 1);
1696 printf("%s#%d starting range test from %u to %u\n",
1697 __func__, __LINE__, min, max);
1699 for (i = min; i <= max; i += k) {
1701 k = RTE_MIN(max - i + 1, RTE_DIM(test_data));
1703 memset(test_data, 0, sizeof(test_data));
1704 fill_u32_range_data(test_data, i, k);
1706 rc = test_classify_run(acx, test_data, k);
1708 printf("%s#%d failed at [%u, %u) interval\n",
1709 __func__, __LINE__, i, i + k);
1721 if (test_invalid_parameters() < 0)
1723 if (test_invalid_rules() < 0)
1725 if (test_create_find_add() < 0)
1727 if (test_invalid_layout() < 0)
1729 if (test_misc() < 0)
1731 if (test_classify() < 0)
1733 if (test_build_ports_range() < 0)
1735 if (test_convert() < 0)
1737 if (test_u32_range() < 0)
1743 REGISTER_TEST_COMMAND(acl_autotest, test_acl);