1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
10 #include <rte_string_fns.h>
12 #include <rte_byteorder.h>
15 #include <rte_common.h>
16 #include <rte_table_acl.h>
18 #include <rte_flow_classify.h>
20 #include "packet_burst_generator.h"
21 #include "test_flow_classify.h"
24 #define FLOW_CLASSIFY_MAX_RULE_NUM 100
25 #define MAX_PKT_BURST 32
27 #define MEMPOOL_CACHE_SIZE 256
31 /* test UDP, TCP and SCTP packets */
32 static struct rte_mempool *mbufpool[NB_SOCKETS];
33 static struct rte_mbuf *bufs[MAX_PKT_BURST];
35 static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = {
36 /* first input field - always one byte long. */
38 .type = RTE_ACL_FIELD_TYPE_BITMASK,
39 .size = sizeof(uint8_t),
40 .field_index = PROTO_FIELD_IPV4,
41 .input_index = PROTO_INPUT_IPV4,
42 .offset = sizeof(struct rte_ether_hdr) +
43 offsetof(struct rte_ipv4_hdr, next_proto_id),
45 /* next input field (IPv4 source address) - 4 consecutive bytes. */
47 /* rte_flow uses a bit mask for IPv4 addresses */
48 .type = RTE_ACL_FIELD_TYPE_BITMASK,
49 .size = sizeof(uint32_t),
50 .field_index = SRC_FIELD_IPV4,
51 .input_index = SRC_INPUT_IPV4,
52 .offset = sizeof(struct rte_ether_hdr) +
53 offsetof(struct rte_ipv4_hdr, src_addr),
55 /* next input field (IPv4 destination address) - 4 consecutive bytes. */
57 /* rte_flow uses a bit mask for IPv4 addresses */
58 .type = RTE_ACL_FIELD_TYPE_BITMASK,
59 .size = sizeof(uint32_t),
60 .field_index = DST_FIELD_IPV4,
61 .input_index = DST_INPUT_IPV4,
62 .offset = sizeof(struct rte_ether_hdr) +
63 offsetof(struct rte_ipv4_hdr, dst_addr),
66 * Next 2 fields (src & dst ports) form 4 consecutive bytes.
67 * They share the same input index.
70 /* rte_flow uses a bit mask for protocol ports */
71 .type = RTE_ACL_FIELD_TYPE_BITMASK,
72 .size = sizeof(uint16_t),
73 .field_index = SRCP_FIELD_IPV4,
74 .input_index = SRCP_DESTP_INPUT_IPV4,
75 .offset = sizeof(struct rte_ether_hdr) +
76 sizeof(struct rte_ipv4_hdr) +
77 offsetof(struct rte_tcp_hdr, src_port),
80 /* rte_flow uses a bit mask for protocol ports */
81 .type = RTE_ACL_FIELD_TYPE_BITMASK,
82 .size = sizeof(uint16_t),
83 .field_index = DSTP_FIELD_IPV4,
84 .input_index = SRCP_DESTP_INPUT_IPV4,
85 .offset = sizeof(struct rte_ether_hdr) +
86 sizeof(struct rte_ipv4_hdr) +
87 offsetof(struct rte_tcp_hdr, dst_port),
91 /* parameters for rte_flow_classify_validate and rte_flow_classify_create */
94 * "eth / ipv4 src spec 2.2.2.3 src mask 255.255.255.00 dst spec 2.2.2.7
95 * dst mask 255.255.255.00 / udp src is 32 dst is 33 / end"
97 static struct rte_flow_item_ipv4 ipv4_udp_spec_1 = {
98 { 0, 0, 0, 0, 0, 0, IPPROTO_UDP, 0,
99 RTE_IPV4(2, 2, 2, 3), RTE_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,
130 * "eth / ipv4 src spec 1.2.3.4 src mask 255.255.255.00 dst spec 5.6.7.8
131 * dst mask 255.255.255.00 / tcp src is 16 dst is 17 / end"
133 static struct rte_flow_item_ipv4 ipv4_tcp_spec_1 = {
134 { 0, 0, 0, 0, 0, 0, IPPROTO_TCP, 0,
135 RTE_IPV4(1, 2, 3, 4), RTE_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, RTE_IPV4(11, 12, 13, 14),
154 RTE_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 static 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};
184 static struct rte_flow_action actions[2];
186 /* test attributes */
187 static struct rte_flow_attr attr;
190 static struct rte_flow_error error;
193 static struct rte_flow_item pattern[4];
195 /* flow classify data for UDP burst */
196 static struct rte_flow_classify_ipv4_5tuple_stats udp_ntuple_stats;
197 static struct rte_flow_classify_stats udp_classify_stats = {
198 .stats = (void *)&udp_ntuple_stats
201 /* flow classify data for TCP burst */
202 static struct rte_flow_classify_ipv4_5tuple_stats tcp_ntuple_stats;
203 static struct rte_flow_classify_stats tcp_classify_stats = {
204 .stats = (void *)&tcp_ntuple_stats
207 /* flow classify data for SCTP burst */
208 static struct rte_flow_classify_ipv4_5tuple_stats sctp_ntuple_stats;
209 static struct rte_flow_classify_stats sctp_classify_stats = {
210 .stats = (void *)&sctp_ntuple_stats
213 struct flow_classifier_acl *cls;
215 struct flow_classifier_acl {
216 struct rte_flow_classifier *cls;
217 } __rte_cache_aligned;
220 * test functions by passing invalid or
221 * non-workable parameters.
224 test_invalid_parameters(void)
226 struct rte_flow_classify_rule *rule;
229 ret = rte_flow_classify_validate(NULL, NULL, NULL, NULL, NULL);
231 printf("Line %i: rte_flow_classify_validate",
233 printf(" with NULL param should have failed!\n");
237 rule = rte_flow_classify_table_entry_add(NULL, NULL, NULL, NULL,
240 printf("Line %i: flow_classifier_table_entry_add", __LINE__);
241 printf(" with NULL param should have failed!\n");
245 ret = rte_flow_classify_table_entry_delete(NULL, NULL);
247 printf("Line %i: rte_flow_classify_table_entry_delete",
249 printf(" with NULL param should have failed!\n");
253 ret = rte_flow_classifier_query(NULL, NULL, 0, NULL, NULL);
255 printf("Line %i: flow_classifier_query", __LINE__);
256 printf(" with NULL param should have failed!\n");
260 rule = rte_flow_classify_table_entry_add(NULL, NULL, NULL, NULL,
263 printf("Line %i: flow_classify_table_entry_add ", __LINE__);
264 printf("with NULL param should have failed!\n");
268 ret = rte_flow_classify_table_entry_delete(NULL, NULL);
270 printf("Line %i: rte_flow_classify_table_entry_delete",
272 printf("with NULL param should have failed!\n");
276 ret = rte_flow_classifier_query(NULL, NULL, 0, NULL, NULL);
278 printf("Line %i: flow_classifier_query", __LINE__);
279 printf(" with NULL param should have failed!\n");
286 test_valid_parameters(void)
288 struct rte_flow_classify_rule *rule;
293 * set up parameters for rte_flow_classify_validate,
294 * rte_flow_classify_table_entry_add and
295 * rte_flow_classify_table_entry_delete
300 pattern[0] = eth_item;
301 pattern[1] = ipv4_udp_item_1;
302 pattern[2] = udp_item_1;
303 pattern[3] = end_item;
304 actions[0] = count_action;
305 actions[1] = end_action;
307 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
310 printf("Line %i: rte_flow_classify_validate",
312 printf(" should not have failed!\n");
315 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
316 actions, &key_found, &error);
319 printf("Line %i: flow_classify_table_entry_add", __LINE__);
320 printf(" should not have failed!\n");
324 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
326 printf("Line %i: rte_flow_classify_table_entry_delete",
328 printf(" should not have failed!\n");
335 test_invalid_patterns(void)
337 struct rte_flow_classify_rule *rule;
342 * set up parameters for rte_flow_classify_validate,
343 * rte_flow_classify_table_entry_add and
344 * rte_flow_classify_table_entry_delete
349 pattern[0] = eth_item_bad;
350 pattern[1] = ipv4_udp_item_1;
351 pattern[2] = udp_item_1;
352 pattern[3] = end_item;
353 actions[0] = count_action;
354 actions[1] = end_action;
356 pattern[0] = eth_item;
357 pattern[1] = ipv4_udp_item_bad;
359 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
362 printf("Line %i: rte_flow_classify_validate", __LINE__);
363 printf(" should have failed!\n");
367 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
368 actions, &key_found, &error);
370 printf("Line %i: flow_classify_table_entry_add", __LINE__);
371 printf(" should have failed!\n");
375 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
377 printf("Line %i: rte_flow_classify_table_entry_delete",
379 printf(" should have failed!\n");
383 pattern[1] = ipv4_udp_item_1;
384 pattern[2] = udp_item_bad;
385 pattern[3] = end_item;
387 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
390 printf("Line %i: rte_flow_classify_validate", __LINE__);
391 printf(" should have failed!\n");
395 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
396 actions, &key_found, &error);
398 printf("Line %i: flow_classify_table_entry_add", __LINE__);
399 printf(" should have failed!\n");
403 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
405 printf("Line %i: rte_flow_classify_table_entry_delete",
407 printf(" should have failed!\n");
414 test_invalid_actions(void)
416 struct rte_flow_classify_rule *rule;
421 * set up parameters for rte_flow_classify_validate,
422 * rte_flow_classify_table_entry_add and
423 * rte_flow_classify_table_entry_delete
428 pattern[0] = eth_item;
429 pattern[1] = ipv4_udp_item_1;
430 pattern[2] = udp_item_1;
431 pattern[3] = end_item;
432 actions[0] = count_action_bad;
433 actions[1] = end_action;
435 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
438 printf("Line %i: rte_flow_classify_validate", __LINE__);
439 printf(" should have failed!\n");
443 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
444 actions, &key_found, &error);
446 printf("Line %i: flow_classify_table_entry_add", __LINE__);
447 printf(" should have failed!\n");
451 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
453 printf("Line %i: rte_flow_classify_table_entry_delete",
455 printf(" should have failed!\n");
463 init_ipv4_udp_traffic(struct rte_mempool *mp,
464 struct rte_mbuf **pkts_burst, uint32_t burst_size)
466 struct rte_ether_hdr pkt_eth_hdr;
467 struct rte_ipv4_hdr pkt_ipv4_hdr;
468 struct rte_udp_hdr pkt_udp_hdr;
469 uint32_t src_addr = IPV4_ADDR(2, 2, 2, 3);
470 uint32_t dst_addr = IPV4_ADDR(2, 2, 2, 7);
471 uint16_t src_port = 32;
472 uint16_t dst_port = 33;
475 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
476 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
478 printf("Set up IPv4 UDP traffic\n");
479 initialize_eth_header(&pkt_eth_hdr,
480 (struct rte_ether_addr *)src_mac,
481 (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPV4, 0, 0);
482 pktlen = (uint16_t)(sizeof(struct rte_ether_hdr));
483 printf("ETH pktlen %u\n", pktlen);
485 pktlen = initialize_ipv4_header(&pkt_ipv4_hdr, src_addr, dst_addr,
487 printf("ETH + IPv4 pktlen %u\n", pktlen);
489 pktlen = initialize_udp_header(&pkt_udp_hdr, src_port, dst_port,
491 printf("ETH + IPv4 + UDP pktlen %u\n\n", pktlen);
493 return generate_packet_burst(mp, pkts_burst, &pkt_eth_hdr,
495 &pkt_udp_hdr, burst_size,
496 PACKET_BURST_GEN_PKT_LEN, 1);
500 init_ipv4_tcp_traffic(struct rte_mempool *mp,
501 struct rte_mbuf **pkts_burst, uint32_t burst_size)
503 struct rte_ether_hdr pkt_eth_hdr;
504 struct rte_ipv4_hdr pkt_ipv4_hdr;
505 struct rte_tcp_hdr pkt_tcp_hdr;
506 uint32_t src_addr = IPV4_ADDR(1, 2, 3, 4);
507 uint32_t dst_addr = IPV4_ADDR(5, 6, 7, 8);
508 uint16_t src_port = 16;
509 uint16_t dst_port = 17;
512 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
513 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
515 printf("Set up IPv4 TCP traffic\n");
516 initialize_eth_header(&pkt_eth_hdr,
517 (struct rte_ether_addr *)src_mac,
518 (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPV4, 0, 0);
519 pktlen = (uint16_t)(sizeof(struct rte_ether_hdr));
520 printf("ETH pktlen %u\n", pktlen);
522 pktlen = initialize_ipv4_header_proto(&pkt_ipv4_hdr, src_addr,
523 dst_addr, pktlen, IPPROTO_TCP);
524 printf("ETH + IPv4 pktlen %u\n", pktlen);
526 pktlen = initialize_tcp_header(&pkt_tcp_hdr, src_port, dst_port,
528 printf("ETH + IPv4 + TCP pktlen %u\n\n", pktlen);
530 return generate_packet_burst_proto(mp, pkts_burst, &pkt_eth_hdr,
531 0, &pkt_ipv4_hdr, 1, IPPROTO_TCP,
532 &pkt_tcp_hdr, burst_size,
533 PACKET_BURST_GEN_PKT_LEN, 1);
537 init_ipv4_sctp_traffic(struct rte_mempool *mp,
538 struct rte_mbuf **pkts_burst, uint32_t burst_size)
540 struct rte_ether_hdr pkt_eth_hdr;
541 struct rte_ipv4_hdr pkt_ipv4_hdr;
542 struct rte_sctp_hdr pkt_sctp_hdr;
543 uint32_t src_addr = IPV4_ADDR(11, 12, 13, 14);
544 uint32_t dst_addr = IPV4_ADDR(15, 16, 17, 18);
545 uint16_t src_port = 10;
546 uint16_t dst_port = 11;
549 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
550 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
552 printf("Set up IPv4 SCTP traffic\n");
553 initialize_eth_header(&pkt_eth_hdr,
554 (struct rte_ether_addr *)src_mac,
555 (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPV4, 0, 0);
556 pktlen = (uint16_t)(sizeof(struct rte_ether_hdr));
557 printf("ETH pktlen %u\n", pktlen);
559 pktlen = initialize_ipv4_header_proto(&pkt_ipv4_hdr, src_addr,
560 dst_addr, pktlen, IPPROTO_SCTP);
561 printf("ETH + IPv4 pktlen %u\n", pktlen);
563 pktlen = initialize_sctp_header(&pkt_sctp_hdr, src_port, dst_port,
565 printf("ETH + IPv4 + SCTP pktlen %u\n\n", pktlen);
567 return generate_packet_burst_proto(mp, pkts_burst, &pkt_eth_hdr,
568 0, &pkt_ipv4_hdr, 1, IPPROTO_SCTP,
569 &pkt_sctp_hdr, burst_size,
570 PACKET_BURST_GEN_PKT_LEN, 1);
578 unsigned int lcore_id;
581 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
582 if (rte_lcore_is_enabled(lcore_id) == 0)
585 socketid = rte_lcore_to_socket_id(lcore_id);
586 if (socketid >= NB_SOCKETS) {
588 "Socket %d of lcore %u is out of range %d\n",
589 socketid, lcore_id, NB_SOCKETS);
593 if (mbufpool[socketid] == NULL) {
594 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
596 rte_pktmbuf_pool_create(s, NB_MBUF,
597 MEMPOOL_CACHE_SIZE, 0, MBUF_SIZE,
599 if (mbufpool[socketid]) {
600 printf("Allocated mbuf pool on socket %d\n",
603 printf("Cannot init mbuf pool on socket %d\n",
616 struct rte_flow_error error;
617 struct rte_flow_classify_rule *rule;
622 ret = init_ipv4_udp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
623 if (ret != MAX_PKT_BURST) {
624 printf("Line %i: init_udp_ipv4_traffic has failed!\n",
629 for (i = 0; i < MAX_PKT_BURST; i++)
630 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
633 * set up parameters for rte_flow_classify_validate,
634 * rte_flow_classify_table_entry_add and
635 * rte_flow_classify_table_entry_delete
640 pattern[0] = eth_item;
641 pattern[1] = ipv4_udp_item_1;
642 pattern[2] = udp_item_1;
643 pattern[3] = end_item;
644 actions[0] = count_action;
645 actions[1] = end_action;
647 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
650 printf("Line %i: rte_flow_classify_validate", __LINE__);
651 printf(" should not have failed!\n");
655 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
656 actions, &key_found, &error);
658 printf("Line %i: flow_classify_table_entry_add", __LINE__);
659 printf(" should not have failed!\n");
663 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
664 rule, &udp_classify_stats);
666 printf("Line %i: flow_classifier_query", __LINE__);
667 printf(" should not have failed!\n");
671 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
673 printf("Line %i: rte_flow_classify_table_entry_delete",
675 printf(" should not have failed!\n");
684 struct rte_flow_classify_rule *rule;
689 ret = init_ipv4_tcp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
690 if (ret != MAX_PKT_BURST) {
691 printf("Line %i: init_ipv4_tcp_traffic has failed!\n",
696 for (i = 0; i < MAX_PKT_BURST; i++)
697 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
700 * set up parameters for rte_flow_classify_validate,
701 * rte_flow_classify_table_entry_add and
702 * rte_flow_classify_table_entry_delete
707 pattern[0] = eth_item;
708 pattern[1] = ipv4_tcp_item_1;
709 pattern[2] = tcp_item_1;
710 pattern[3] = end_item;
711 actions[0] = count_action;
712 actions[1] = end_action;
714 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
717 printf("Line %i: flow_classifier_query", __LINE__);
718 printf(" should not have failed!\n");
722 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
723 actions, &key_found, &error);
725 printf("Line %i: flow_classify_table_entry_add", __LINE__);
726 printf(" should not have failed!\n");
730 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
731 rule, &tcp_classify_stats);
733 printf("Line %i: flow_classifier_query", __LINE__);
734 printf(" should not have failed!\n");
738 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
740 printf("Line %i: rte_flow_classify_table_entry_delete",
742 printf(" should not have failed!\n");
749 test_query_sctp(void)
751 struct rte_flow_classify_rule *rule;
756 ret = init_ipv4_sctp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
757 if (ret != MAX_PKT_BURST) {
758 printf("Line %i: init_ipv4_tcp_traffic has failed!\n",
763 for (i = 0; i < MAX_PKT_BURST; i++)
764 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
767 * set up parameters rte_flow_classify_validate,
768 * rte_flow_classify_table_entry_add and
769 * rte_flow_classify_table_entry_delete
774 pattern[0] = eth_item;
775 pattern[1] = ipv4_sctp_item_1;
776 pattern[2] = sctp_item_1;
777 pattern[3] = end_item;
778 actions[0] = count_action;
779 actions[1] = end_action;
781 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
784 printf("Line %i: flow_classifier_query", __LINE__);
785 printf(" should not have failed!\n");
789 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
790 actions, &key_found, &error);
792 printf("Line %i: flow_classify_table_entry_add", __LINE__);
793 printf(" should not have failed!\n");
797 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
798 rule, &sctp_classify_stats);
800 printf("Line %i: flow_classifier_query", __LINE__);
801 printf(" should not have failed!\n");
805 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
807 printf("Line %i: rte_flow_classify_table_entry_delete",
809 printf(" should not have failed!\n");
816 test_flow_classify(void)
818 struct rte_table_acl_params table_acl_params;
819 struct rte_flow_classify_table_params cls_table_params;
820 struct rte_flow_classifier_params cls_params;
824 /* Memory allocation */
825 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct flow_classifier_acl));
826 cls = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
828 cls_params.name = "flow_classifier";
829 cls_params.socket_id = 0;
830 cls->cls = rte_flow_classifier_create(&cls_params);
832 /* initialise ACL table params */
833 table_acl_params.n_rule_fields = RTE_DIM(ipv4_defs);
834 table_acl_params.name = "table_acl_ipv4_5tuple";
835 table_acl_params.n_rules = FLOW_CLASSIFY_MAX_RULE_NUM;
836 memcpy(table_acl_params.field_format, ipv4_defs, sizeof(ipv4_defs));
838 /* initialise table create params */
839 cls_table_params.ops = &rte_table_acl_ops;
840 cls_table_params.arg_create = &table_acl_params;
841 cls_table_params.type = RTE_FLOW_CLASSIFY_TABLE_ACL_IP4_5TUPLE;
843 ret = rte_flow_classify_table_create(cls->cls, &cls_table_params);
845 printf("Line %i: f_create has failed!\n", __LINE__);
846 rte_flow_classifier_free(cls->cls);
850 printf("Created table_acl for for IPv4 five tuple packets\n");
852 ret = init_mbufpool();
854 printf("Line %i: init_mbufpool has failed!\n", __LINE__);
858 if (test_invalid_parameters() < 0)
860 if (test_valid_parameters() < 0)
862 if (test_invalid_patterns() < 0)
864 if (test_invalid_actions() < 0)
866 if (test_query_udp() < 0)
868 if (test_query_tcp() < 0)
870 if (test_query_sctp() < 0)
876 REGISTER_TEST_COMMAND(flow_classify_autotest, test_flow_classify);