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 #ifdef RTE_EXEC_ENV_WINDOWS
17 test_flow_classify(void)
19 printf("flow_classify not supported on Windows, skipping test\n");
26 #include <rte_common.h>
27 #include <rte_table_acl.h>
29 #include <rte_flow_classify.h>
31 #include "packet_burst_generator.h"
32 #include "test_flow_classify.h"
35 #define FLOW_CLASSIFY_MAX_RULE_NUM 100
36 #define MAX_PKT_BURST 32
38 #define MEMPOOL_CACHE_SIZE 256
42 /* test UDP, TCP and SCTP packets */
43 static struct rte_mempool *mbufpool[NB_SOCKETS];
44 static struct rte_mbuf *bufs[MAX_PKT_BURST];
46 static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = {
47 /* first input field - always one byte long. */
49 .type = RTE_ACL_FIELD_TYPE_BITMASK,
50 .size = sizeof(uint8_t),
51 .field_index = PROTO_FIELD_IPV4,
52 .input_index = PROTO_INPUT_IPV4,
53 .offset = sizeof(struct rte_ether_hdr) +
54 offsetof(struct rte_ipv4_hdr, next_proto_id),
56 /* next input field (IPv4 source 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 = SRC_FIELD_IPV4,
62 .input_index = SRC_INPUT_IPV4,
63 .offset = sizeof(struct rte_ether_hdr) +
64 offsetof(struct rte_ipv4_hdr, src_addr),
66 /* next input field (IPv4 destination address) - 4 consecutive bytes. */
68 /* rte_flow uses a bit mask for IPv4 addresses */
69 .type = RTE_ACL_FIELD_TYPE_BITMASK,
70 .size = sizeof(uint32_t),
71 .field_index = DST_FIELD_IPV4,
72 .input_index = DST_INPUT_IPV4,
73 .offset = sizeof(struct rte_ether_hdr) +
74 offsetof(struct rte_ipv4_hdr, dst_addr),
77 * Next 2 fields (src & dst ports) form 4 consecutive bytes.
78 * They share the same input index.
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 = SRCP_FIELD_IPV4,
85 .input_index = SRCP_DESTP_INPUT_IPV4,
86 .offset = sizeof(struct rte_ether_hdr) +
87 sizeof(struct rte_ipv4_hdr) +
88 offsetof(struct rte_tcp_hdr, src_port),
91 /* rte_flow uses a bit mask for protocol ports */
92 .type = RTE_ACL_FIELD_TYPE_BITMASK,
93 .size = sizeof(uint16_t),
94 .field_index = DSTP_FIELD_IPV4,
95 .input_index = SRCP_DESTP_INPUT_IPV4,
96 .offset = sizeof(struct rte_ether_hdr) +
97 sizeof(struct rte_ipv4_hdr) +
98 offsetof(struct rte_tcp_hdr, dst_port),
102 /* parameters for rte_flow_classify_validate and rte_flow_classify_create */
105 * "eth / ipv4 src spec 2.2.2.3 src mask 255.255.255.00 dst spec 2.2.2.7
106 * dst mask 255.255.255.00 / udp src is 32 dst is 33 / end"
108 static struct rte_flow_item_ipv4 ipv4_udp_spec_1 = {
109 { { .version_ihl = 0}, 0, 0, 0, 0, 0, IPPROTO_UDP, 0,
110 RTE_IPV4(2, 2, 2, 3), RTE_IPV4(2, 2, 2, 7)}
112 static const struct rte_flow_item_ipv4 ipv4_mask_24 = {
114 .next_proto_id = 0xff,
115 .src_addr = 0xffffff00,
116 .dst_addr = 0xffffff00,
119 static struct rte_flow_item_udp udp_spec_1 = {
123 static struct rte_flow_item eth_item = { RTE_FLOW_ITEM_TYPE_ETH,
125 static struct rte_flow_item eth_item_bad = { -1, 0, 0, 0 };
127 static struct rte_flow_item ipv4_udp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
128 &ipv4_udp_spec_1, 0, &ipv4_mask_24};
129 static struct rte_flow_item ipv4_udp_item_bad = { RTE_FLOW_ITEM_TYPE_IPV4,
132 static struct rte_flow_item udp_item_1 = { RTE_FLOW_ITEM_TYPE_UDP,
133 &udp_spec_1, 0, &rte_flow_item_udp_mask};
134 static struct rte_flow_item udp_item_bad = { RTE_FLOW_ITEM_TYPE_UDP,
137 static struct rte_flow_item end_item = { RTE_FLOW_ITEM_TYPE_END,
141 * "eth / ipv4 src spec 1.2.3.4 src mask 255.255.255.00 dst spec 5.6.7.8
142 * dst mask 255.255.255.00 / tcp src is 16 dst is 17 / end"
144 static struct rte_flow_item_ipv4 ipv4_tcp_spec_1 = {
145 { { .version_ihl = 0}, 0, 0, 0, 0, 0, IPPROTO_TCP, 0,
146 RTE_IPV4(1, 2, 3, 4), RTE_IPV4(5, 6, 7, 8)}
149 static struct rte_flow_item_tcp tcp_spec_1 = {
150 { 16, 17, 0, 0, 0, 0, 0, 0, 0}
153 static struct rte_flow_item ipv4_tcp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
154 &ipv4_tcp_spec_1, 0, &ipv4_mask_24};
156 static struct rte_flow_item tcp_item_1 = { RTE_FLOW_ITEM_TYPE_TCP,
157 &tcp_spec_1, 0, &rte_flow_item_tcp_mask};
159 /* test SCTP 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 / sctp src is 16 dst is 17/ end"
163 static struct rte_flow_item_ipv4 ipv4_sctp_spec_1 = {
164 { { .version_ihl = 0}, 0, 0, 0, 0, 0, IPPROTO_SCTP, 0,
165 RTE_IPV4(11, 12, 13, 14), RTE_IPV4(15, 16, 17, 18)}
168 static struct rte_flow_item_sctp sctp_spec_1 = {
172 static struct rte_flow_item ipv4_sctp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
173 &ipv4_sctp_spec_1, 0, &ipv4_mask_24};
175 static struct rte_flow_item sctp_item_1 = { RTE_FLOW_ITEM_TYPE_SCTP,
176 &sctp_spec_1, 0, &rte_flow_item_sctp_mask};
180 * "actions count / end"
182 static struct rte_flow_query_count count = {
189 static struct rte_flow_action count_action = { RTE_FLOW_ACTION_TYPE_COUNT,
191 static struct rte_flow_action count_action_bad = { -1, 0};
193 static struct rte_flow_action end_action = { RTE_FLOW_ACTION_TYPE_END, 0};
195 static struct rte_flow_action actions[2];
197 /* test attributes */
198 static struct rte_flow_attr attr;
201 static struct rte_flow_error error;
204 static struct rte_flow_item pattern[4];
206 /* flow classify data for UDP burst */
207 static struct rte_flow_classify_ipv4_5tuple_stats udp_ntuple_stats;
208 static struct rte_flow_classify_stats udp_classify_stats = {
209 .stats = (void *)&udp_ntuple_stats
212 /* flow classify data for TCP burst */
213 static struct rte_flow_classify_ipv4_5tuple_stats tcp_ntuple_stats;
214 static struct rte_flow_classify_stats tcp_classify_stats = {
215 .stats = (void *)&tcp_ntuple_stats
218 /* flow classify data for SCTP burst */
219 static struct rte_flow_classify_ipv4_5tuple_stats sctp_ntuple_stats;
220 static struct rte_flow_classify_stats sctp_classify_stats = {
221 .stats = (void *)&sctp_ntuple_stats
224 struct flow_classifier_acl *cls;
226 struct flow_classifier_acl {
227 struct rte_flow_classifier *cls;
228 } __rte_cache_aligned;
231 * test functions by passing invalid or
232 * non-workable parameters.
235 test_invalid_parameters(void)
237 struct rte_flow_classify_rule *rule;
240 ret = rte_flow_classify_validate(NULL, NULL, NULL, NULL, NULL);
242 printf("Line %i: rte_flow_classify_validate",
244 printf(" with NULL param should have failed!\n");
248 rule = rte_flow_classify_table_entry_add(NULL, NULL, NULL, NULL,
251 printf("Line %i: flow_classifier_table_entry_add", __LINE__);
252 printf(" with NULL param should have failed!\n");
256 ret = rte_flow_classify_table_entry_delete(NULL, NULL);
258 printf("Line %i: rte_flow_classify_table_entry_delete",
260 printf(" with NULL param should have failed!\n");
264 ret = rte_flow_classifier_query(NULL, NULL, 0, NULL, NULL);
266 printf("Line %i: flow_classifier_query", __LINE__);
267 printf(" with NULL param should have failed!\n");
271 rule = rte_flow_classify_table_entry_add(NULL, NULL, NULL, NULL,
274 printf("Line %i: flow_classify_table_entry_add ", __LINE__);
275 printf("with NULL param should have failed!\n");
279 ret = rte_flow_classify_table_entry_delete(NULL, NULL);
281 printf("Line %i: rte_flow_classify_table_entry_delete",
283 printf("with NULL param should have failed!\n");
287 ret = rte_flow_classifier_query(NULL, NULL, 0, NULL, NULL);
289 printf("Line %i: flow_classifier_query", __LINE__);
290 printf(" with NULL param should have failed!\n");
297 test_valid_parameters(void)
299 struct rte_flow_classify_rule *rule;
304 * set up parameters for rte_flow_classify_validate,
305 * rte_flow_classify_table_entry_add and
306 * rte_flow_classify_table_entry_delete
311 pattern[0] = eth_item;
312 pattern[1] = ipv4_udp_item_1;
313 pattern[2] = udp_item_1;
314 pattern[3] = end_item;
315 actions[0] = count_action;
316 actions[1] = end_action;
318 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
321 printf("Line %i: rte_flow_classify_validate",
323 printf(" should not have failed!\n");
326 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
327 actions, &key_found, &error);
330 printf("Line %i: flow_classify_table_entry_add", __LINE__);
331 printf(" should not have failed!\n");
335 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
337 printf("Line %i: rte_flow_classify_table_entry_delete",
339 printf(" should not have failed!\n");
346 test_invalid_patterns(void)
348 struct rte_flow_classify_rule *rule;
353 * set up parameters for rte_flow_classify_validate,
354 * rte_flow_classify_table_entry_add and
355 * rte_flow_classify_table_entry_delete
360 pattern[0] = eth_item_bad;
361 pattern[1] = ipv4_udp_item_1;
362 pattern[2] = udp_item_1;
363 pattern[3] = end_item;
364 actions[0] = count_action;
365 actions[1] = end_action;
367 pattern[0] = eth_item;
368 pattern[1] = ipv4_udp_item_bad;
370 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
373 printf("Line %i: rte_flow_classify_validate", __LINE__);
374 printf(" should have failed!\n");
378 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
379 actions, &key_found, &error);
381 printf("Line %i: flow_classify_table_entry_add", __LINE__);
382 printf(" should have failed!\n");
386 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
388 printf("Line %i: rte_flow_classify_table_entry_delete",
390 printf(" should have failed!\n");
394 pattern[1] = ipv4_udp_item_1;
395 pattern[2] = udp_item_bad;
396 pattern[3] = end_item;
398 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
401 printf("Line %i: rte_flow_classify_validate", __LINE__);
402 printf(" should have failed!\n");
406 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
407 actions, &key_found, &error);
409 printf("Line %i: flow_classify_table_entry_add", __LINE__);
410 printf(" should have failed!\n");
414 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
416 printf("Line %i: rte_flow_classify_table_entry_delete",
418 printf(" should have failed!\n");
425 test_invalid_actions(void)
427 struct rte_flow_classify_rule *rule;
432 * set up parameters for rte_flow_classify_validate,
433 * rte_flow_classify_table_entry_add and
434 * rte_flow_classify_table_entry_delete
439 pattern[0] = eth_item;
440 pattern[1] = ipv4_udp_item_1;
441 pattern[2] = udp_item_1;
442 pattern[3] = end_item;
443 actions[0] = count_action_bad;
444 actions[1] = end_action;
446 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
449 printf("Line %i: rte_flow_classify_validate", __LINE__);
450 printf(" should have failed!\n");
454 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
455 actions, &key_found, &error);
457 printf("Line %i: flow_classify_table_entry_add", __LINE__);
458 printf(" should have failed!\n");
462 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
464 printf("Line %i: rte_flow_classify_table_entry_delete",
466 printf(" should have failed!\n");
474 init_ipv4_udp_traffic(struct rte_mempool *mp,
475 struct rte_mbuf **pkts_burst, uint32_t burst_size)
477 struct rte_ether_hdr pkt_eth_hdr;
478 struct rte_ipv4_hdr pkt_ipv4_hdr;
479 struct rte_udp_hdr pkt_udp_hdr;
480 uint32_t src_addr = IPV4_ADDR(2, 2, 2, 3);
481 uint32_t dst_addr = IPV4_ADDR(2, 2, 2, 7);
482 uint16_t src_port = 32;
483 uint16_t dst_port = 33;
486 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
487 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
489 printf("Set up IPv4 UDP traffic\n");
490 initialize_eth_header(&pkt_eth_hdr,
491 (struct rte_ether_addr *)src_mac,
492 (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPV4, 0, 0);
493 pktlen = (uint16_t)(sizeof(struct rte_ether_hdr));
494 printf("ETH pktlen %u\n", pktlen);
496 pktlen = initialize_ipv4_header(&pkt_ipv4_hdr, src_addr, dst_addr,
498 printf("ETH + IPv4 pktlen %u\n", pktlen);
500 pktlen = initialize_udp_header(&pkt_udp_hdr, src_port, dst_port,
502 printf("ETH + IPv4 + UDP pktlen %u\n\n", pktlen);
504 return generate_packet_burst(mp, pkts_burst, &pkt_eth_hdr,
506 &pkt_udp_hdr, burst_size,
507 PACKET_BURST_GEN_PKT_LEN, 1);
511 init_ipv4_tcp_traffic(struct rte_mempool *mp,
512 struct rte_mbuf **pkts_burst, uint32_t burst_size)
514 struct rte_ether_hdr pkt_eth_hdr;
515 struct rte_ipv4_hdr pkt_ipv4_hdr;
516 struct rte_tcp_hdr pkt_tcp_hdr;
517 uint32_t src_addr = IPV4_ADDR(1, 2, 3, 4);
518 uint32_t dst_addr = IPV4_ADDR(5, 6, 7, 8);
519 uint16_t src_port = 16;
520 uint16_t dst_port = 17;
523 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
524 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
526 printf("Set up IPv4 TCP traffic\n");
527 initialize_eth_header(&pkt_eth_hdr,
528 (struct rte_ether_addr *)src_mac,
529 (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPV4, 0, 0);
530 pktlen = (uint16_t)(sizeof(struct rte_ether_hdr));
531 printf("ETH pktlen %u\n", pktlen);
533 pktlen = initialize_ipv4_header_proto(&pkt_ipv4_hdr, src_addr,
534 dst_addr, pktlen, IPPROTO_TCP);
535 printf("ETH + IPv4 pktlen %u\n", pktlen);
537 pktlen = initialize_tcp_header(&pkt_tcp_hdr, src_port, dst_port,
539 printf("ETH + IPv4 + TCP pktlen %u\n\n", pktlen);
541 return generate_packet_burst_proto(mp, pkts_burst, &pkt_eth_hdr,
542 0, &pkt_ipv4_hdr, 1, IPPROTO_TCP,
543 &pkt_tcp_hdr, burst_size,
544 PACKET_BURST_GEN_PKT_LEN, 1);
548 init_ipv4_sctp_traffic(struct rte_mempool *mp,
549 struct rte_mbuf **pkts_burst, uint32_t burst_size)
551 struct rte_ether_hdr pkt_eth_hdr;
552 struct rte_ipv4_hdr pkt_ipv4_hdr;
553 struct rte_sctp_hdr pkt_sctp_hdr;
554 uint32_t src_addr = IPV4_ADDR(11, 12, 13, 14);
555 uint32_t dst_addr = IPV4_ADDR(15, 16, 17, 18);
556 uint16_t src_port = 10;
557 uint16_t dst_port = 11;
560 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
561 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
563 printf("Set up IPv4 SCTP traffic\n");
564 initialize_eth_header(&pkt_eth_hdr,
565 (struct rte_ether_addr *)src_mac,
566 (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPV4, 0, 0);
567 pktlen = (uint16_t)(sizeof(struct rte_ether_hdr));
568 printf("ETH pktlen %u\n", pktlen);
570 pktlen = initialize_ipv4_header_proto(&pkt_ipv4_hdr, src_addr,
571 dst_addr, pktlen, IPPROTO_SCTP);
572 printf("ETH + IPv4 pktlen %u\n", pktlen);
574 pktlen = initialize_sctp_header(&pkt_sctp_hdr, src_port, dst_port,
576 printf("ETH + IPv4 + SCTP pktlen %u\n\n", pktlen);
578 return generate_packet_burst_proto(mp, pkts_burst, &pkt_eth_hdr,
579 0, &pkt_ipv4_hdr, 1, IPPROTO_SCTP,
580 &pkt_sctp_hdr, burst_size,
581 PACKET_BURST_GEN_PKT_LEN, 1);
589 unsigned int lcore_id;
592 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
593 if (rte_lcore_is_enabled(lcore_id) == 0)
596 socketid = rte_lcore_to_socket_id(lcore_id);
597 if (socketid >= NB_SOCKETS) {
599 "Socket %d of lcore %u is out of range %d\n",
600 socketid, lcore_id, NB_SOCKETS);
604 if (mbufpool[socketid] == NULL) {
605 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
607 rte_pktmbuf_pool_create(s, NB_MBUF,
608 MEMPOOL_CACHE_SIZE, 0, MBUF_SIZE,
610 if (mbufpool[socketid]) {
611 printf("Allocated mbuf pool on socket %d\n",
614 printf("Cannot init mbuf pool on socket %d\n",
627 struct rte_flow_error error;
628 struct rte_flow_classify_rule *rule;
633 ret = init_ipv4_udp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
634 if (ret != MAX_PKT_BURST) {
635 printf("Line %i: init_udp_ipv4_traffic has failed!\n",
640 for (i = 0; i < MAX_PKT_BURST; i++)
641 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
644 * set up parameters for rte_flow_classify_validate,
645 * rte_flow_classify_table_entry_add and
646 * rte_flow_classify_table_entry_delete
651 pattern[0] = eth_item;
652 pattern[1] = ipv4_udp_item_1;
653 pattern[2] = udp_item_1;
654 pattern[3] = end_item;
655 actions[0] = count_action;
656 actions[1] = end_action;
658 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
661 printf("Line %i: rte_flow_classify_validate", __LINE__);
662 printf(" should not have failed!\n");
666 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
667 actions, &key_found, &error);
669 printf("Line %i: flow_classify_table_entry_add", __LINE__);
670 printf(" should not have failed!\n");
674 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
675 rule, &udp_classify_stats);
677 printf("Line %i: flow_classifier_query", __LINE__);
678 printf(" should not have failed!\n");
682 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
684 printf("Line %i: rte_flow_classify_table_entry_delete",
686 printf(" should not have failed!\n");
695 struct rte_flow_classify_rule *rule;
700 ret = init_ipv4_tcp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
701 if (ret != MAX_PKT_BURST) {
702 printf("Line %i: init_ipv4_tcp_traffic has failed!\n",
707 for (i = 0; i < MAX_PKT_BURST; i++)
708 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
711 * set up parameters for rte_flow_classify_validate,
712 * rte_flow_classify_table_entry_add and
713 * rte_flow_classify_table_entry_delete
718 pattern[0] = eth_item;
719 pattern[1] = ipv4_tcp_item_1;
720 pattern[2] = tcp_item_1;
721 pattern[3] = end_item;
722 actions[0] = count_action;
723 actions[1] = end_action;
725 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
728 printf("Line %i: flow_classifier_query", __LINE__);
729 printf(" should not have failed!\n");
733 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
734 actions, &key_found, &error);
736 printf("Line %i: flow_classify_table_entry_add", __LINE__);
737 printf(" should not have failed!\n");
741 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
742 rule, &tcp_classify_stats);
744 printf("Line %i: flow_classifier_query", __LINE__);
745 printf(" should not have failed!\n");
749 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
751 printf("Line %i: rte_flow_classify_table_entry_delete",
753 printf(" should not have failed!\n");
760 test_query_sctp(void)
762 struct rte_flow_classify_rule *rule;
767 ret = init_ipv4_sctp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
768 if (ret != MAX_PKT_BURST) {
769 printf("Line %i: init_ipv4_tcp_traffic has failed!\n",
774 for (i = 0; i < MAX_PKT_BURST; i++)
775 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
778 * set up parameters rte_flow_classify_validate,
779 * rte_flow_classify_table_entry_add and
780 * rte_flow_classify_table_entry_delete
785 pattern[0] = eth_item;
786 pattern[1] = ipv4_sctp_item_1;
787 pattern[2] = sctp_item_1;
788 pattern[3] = end_item;
789 actions[0] = count_action;
790 actions[1] = end_action;
792 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
795 printf("Line %i: flow_classifier_query", __LINE__);
796 printf(" should not have failed!\n");
800 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
801 actions, &key_found, &error);
803 printf("Line %i: flow_classify_table_entry_add", __LINE__);
804 printf(" should not have failed!\n");
808 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
809 rule, &sctp_classify_stats);
811 printf("Line %i: flow_classifier_query", __LINE__);
812 printf(" should not have failed!\n");
816 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
818 printf("Line %i: rte_flow_classify_table_entry_delete",
820 printf(" should not have failed!\n");
827 test_flow_classify(void)
829 struct rte_table_acl_params table_acl_params;
830 struct rte_flow_classify_table_params cls_table_params;
831 struct rte_flow_classifier_params cls_params;
835 /* Memory allocation */
836 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct flow_classifier_acl));
837 cls = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
839 cls_params.name = "flow_classifier";
840 cls_params.socket_id = 0;
841 cls->cls = rte_flow_classifier_create(&cls_params);
842 if (cls->cls == NULL) {
843 printf("Line %i: flow classifier create has failed!\n",
849 /* initialise ACL table params */
850 table_acl_params.n_rule_fields = RTE_DIM(ipv4_defs);
851 table_acl_params.name = "table_acl_ipv4_5tuple";
852 table_acl_params.n_rules = FLOW_CLASSIFY_MAX_RULE_NUM;
853 memcpy(table_acl_params.field_format, ipv4_defs, sizeof(ipv4_defs));
855 /* initialise table create params */
856 cls_table_params.ops = &rte_table_acl_ops;
857 cls_table_params.arg_create = &table_acl_params;
858 cls_table_params.type = RTE_FLOW_CLASSIFY_TABLE_ACL_IP4_5TUPLE;
860 ret = rte_flow_classify_table_create(cls->cls, &cls_table_params);
862 printf("Line %i: f_create has failed!\n", __LINE__);
863 rte_flow_classifier_free(cls->cls);
867 printf("Created table_acl for for IPv4 five tuple packets\n");
869 ret = init_mbufpool();
871 printf("Line %i: init_mbufpool has failed!\n", __LINE__);
875 if (test_invalid_parameters() < 0)
877 if (test_valid_parameters() < 0)
879 if (test_invalid_patterns() < 0)
881 if (test_invalid_actions() < 0)
883 if (test_query_udp() < 0)
885 if (test_query_tcp() < 0)
887 if (test_query_sctp() < 0)
893 #endif /* !RTE_EXEC_ENV_WINDOWS */
895 REGISTER_TEST_COMMAND(flow_classify_autotest, test_flow_classify);