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 ether_hdr) +
43 offsetof(struct 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 ether_hdr) +
53 offsetof(struct 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 ether_hdr) +
63 offsetof(struct 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 ether_hdr) +
76 sizeof(struct ipv4_hdr) +
77 offsetof(struct 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 ether_hdr) +
86 sizeof(struct ipv4_hdr) +
87 offsetof(struct 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, IPv4(2, 2, 2, 3), IPv4(2, 2, 2, 7)}
100 static const struct rte_flow_item_ipv4 ipv4_mask_24 = {
102 .next_proto_id = 0xff,
103 .src_addr = 0xffffff00,
104 .dst_addr = 0xffffff00,
107 static struct rte_flow_item_udp udp_spec_1 = {
111 static struct rte_flow_item eth_item = { RTE_FLOW_ITEM_TYPE_ETH,
113 static struct rte_flow_item eth_item_bad = { -1, 0, 0, 0 };
115 static struct rte_flow_item ipv4_udp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
116 &ipv4_udp_spec_1, 0, &ipv4_mask_24};
117 static struct rte_flow_item ipv4_udp_item_bad = { RTE_FLOW_ITEM_TYPE_IPV4,
120 static struct rte_flow_item udp_item_1 = { RTE_FLOW_ITEM_TYPE_UDP,
121 &udp_spec_1, 0, &rte_flow_item_udp_mask};
122 static struct rte_flow_item udp_item_bad = { RTE_FLOW_ITEM_TYPE_UDP,
125 static struct rte_flow_item end_item = { RTE_FLOW_ITEM_TYPE_END,
127 static struct rte_flow_item end_item_bad = { -1, 0, 0, 0 };
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, IPv4(1, 2, 3, 4), IPv4(5, 6, 7, 8)}
137 static struct rte_flow_item_tcp tcp_spec_1 = {
138 { 16, 17, 0, 0, 0, 0, 0, 0, 0}
141 static struct rte_flow_item ipv4_tcp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
142 &ipv4_tcp_spec_1, 0, &ipv4_mask_24};
144 static struct rte_flow_item tcp_item_1 = { RTE_FLOW_ITEM_TYPE_TCP,
145 &tcp_spec_1, 0, &rte_flow_item_tcp_mask};
147 /* test SCTP pattern:
148 * "eth / ipv4 src spec 1.2.3.4 src mask 255.255.255.00 dst spec 5.6.7.8
149 * dst mask 255.255.255.00 / sctp src is 16 dst is 17/ end"
151 static struct rte_flow_item_ipv4 ipv4_sctp_spec_1 = {
152 { 0, 0, 0, 0, 0, 0, IPPROTO_SCTP, 0, IPv4(11, 12, 13, 14),
153 IPv4(15, 16, 17, 18)}
156 static struct rte_flow_item_sctp sctp_spec_1 = {
160 static struct rte_flow_item ipv4_sctp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
161 &ipv4_sctp_spec_1, 0, &ipv4_mask_24};
163 static struct rte_flow_item sctp_item_1 = { RTE_FLOW_ITEM_TYPE_SCTP,
164 &sctp_spec_1, 0, &rte_flow_item_sctp_mask};
168 * "actions count / end"
170 static struct rte_flow_query_count count = {
177 static struct rte_flow_action count_action = { RTE_FLOW_ACTION_TYPE_COUNT,
179 static struct rte_flow_action count_action_bad = { -1, 0};
181 static struct rte_flow_action end_action = { RTE_FLOW_ACTION_TYPE_END, 0};
182 static struct rte_flow_action end_action_bad = { -1, 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_bad;
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");
459 actions[0] = count_action;
460 actions[1] = end_action_bad;
462 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
465 printf("Line %i: rte_flow_classify_validate", __LINE__);
466 printf(" should have failed!\n");
470 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
471 actions, &key_found, &error);
473 printf("Line %i: flow_classify_table_entry_add", __LINE__);
474 printf(" should have failed!\n");
478 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
480 printf("Line %i: rte_flow_classify_table_entry_delete",
482 printf("should have failed!\n");
489 init_ipv4_udp_traffic(struct rte_mempool *mp,
490 struct rte_mbuf **pkts_burst, uint32_t burst_size)
492 struct ether_hdr pkt_eth_hdr;
493 struct ipv4_hdr pkt_ipv4_hdr;
494 struct udp_hdr pkt_udp_hdr;
495 uint32_t src_addr = IPV4_ADDR(2, 2, 2, 3);
496 uint32_t dst_addr = IPV4_ADDR(2, 2, 2, 7);
497 uint16_t src_port = 32;
498 uint16_t dst_port = 33;
501 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
502 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
504 printf("Set up IPv4 UDP traffic\n");
505 initialize_eth_header(&pkt_eth_hdr,
506 (struct ether_addr *)src_mac,
507 (struct ether_addr *)dst_mac, ETHER_TYPE_IPv4, 0, 0);
508 pktlen = (uint16_t)(sizeof(struct ether_hdr));
509 printf("ETH pktlen %u\n", pktlen);
511 pktlen = initialize_ipv4_header(&pkt_ipv4_hdr, src_addr, dst_addr,
513 printf("ETH + IPv4 pktlen %u\n", pktlen);
515 pktlen = initialize_udp_header(&pkt_udp_hdr, src_port, dst_port,
517 printf("ETH + IPv4 + UDP pktlen %u\n\n", pktlen);
519 return generate_packet_burst(mp, pkts_burst, &pkt_eth_hdr,
521 &pkt_udp_hdr, burst_size,
522 PACKET_BURST_GEN_PKT_LEN, 1);
526 init_ipv4_tcp_traffic(struct rte_mempool *mp,
527 struct rte_mbuf **pkts_burst, uint32_t burst_size)
529 struct ether_hdr pkt_eth_hdr;
530 struct ipv4_hdr pkt_ipv4_hdr;
531 struct tcp_hdr pkt_tcp_hdr;
532 uint32_t src_addr = IPV4_ADDR(1, 2, 3, 4);
533 uint32_t dst_addr = IPV4_ADDR(5, 6, 7, 8);
534 uint16_t src_port = 16;
535 uint16_t dst_port = 17;
538 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
539 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
541 printf("Set up IPv4 TCP traffic\n");
542 initialize_eth_header(&pkt_eth_hdr,
543 (struct ether_addr *)src_mac,
544 (struct ether_addr *)dst_mac, ETHER_TYPE_IPv4, 0, 0);
545 pktlen = (uint16_t)(sizeof(struct ether_hdr));
546 printf("ETH pktlen %u\n", pktlen);
548 pktlen = initialize_ipv4_header_proto(&pkt_ipv4_hdr, src_addr,
549 dst_addr, pktlen, IPPROTO_TCP);
550 printf("ETH + IPv4 pktlen %u\n", pktlen);
552 pktlen = initialize_tcp_header(&pkt_tcp_hdr, src_port, dst_port,
554 printf("ETH + IPv4 + TCP pktlen %u\n\n", pktlen);
556 return generate_packet_burst_proto(mp, pkts_burst, &pkt_eth_hdr,
557 0, &pkt_ipv4_hdr, 1, IPPROTO_TCP,
558 &pkt_tcp_hdr, burst_size,
559 PACKET_BURST_GEN_PKT_LEN, 1);
563 init_ipv4_sctp_traffic(struct rte_mempool *mp,
564 struct rte_mbuf **pkts_burst, uint32_t burst_size)
566 struct ether_hdr pkt_eth_hdr;
567 struct ipv4_hdr pkt_ipv4_hdr;
568 struct sctp_hdr pkt_sctp_hdr;
569 uint32_t src_addr = IPV4_ADDR(11, 12, 13, 14);
570 uint32_t dst_addr = IPV4_ADDR(15, 16, 17, 18);
571 uint16_t src_port = 10;
572 uint16_t dst_port = 11;
575 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
576 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
578 printf("Set up IPv4 SCTP traffic\n");
579 initialize_eth_header(&pkt_eth_hdr,
580 (struct ether_addr *)src_mac,
581 (struct ether_addr *)dst_mac, ETHER_TYPE_IPv4, 0, 0);
582 pktlen = (uint16_t)(sizeof(struct ether_hdr));
583 printf("ETH pktlen %u\n", pktlen);
585 pktlen = initialize_ipv4_header_proto(&pkt_ipv4_hdr, src_addr,
586 dst_addr, pktlen, IPPROTO_SCTP);
587 printf("ETH + IPv4 pktlen %u\n", pktlen);
589 pktlen = initialize_sctp_header(&pkt_sctp_hdr, src_port, dst_port,
591 printf("ETH + IPv4 + SCTP pktlen %u\n\n", pktlen);
593 return generate_packet_burst_proto(mp, pkts_burst, &pkt_eth_hdr,
594 0, &pkt_ipv4_hdr, 1, IPPROTO_SCTP,
595 &pkt_sctp_hdr, burst_size,
596 PACKET_BURST_GEN_PKT_LEN, 1);
604 unsigned int lcore_id;
607 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
608 if (rte_lcore_is_enabled(lcore_id) == 0)
611 socketid = rte_lcore_to_socket_id(lcore_id);
612 if (socketid >= NB_SOCKETS) {
614 "Socket %d of lcore %u is out of range %d\n",
615 socketid, lcore_id, NB_SOCKETS);
619 if (mbufpool[socketid] == NULL) {
620 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
622 rte_pktmbuf_pool_create(s, NB_MBUF,
623 MEMPOOL_CACHE_SIZE, 0, MBUF_SIZE,
625 if (mbufpool[socketid]) {
626 printf("Allocated mbuf pool on socket %d\n",
629 printf("Cannot init mbuf pool on socket %d\n",
642 struct rte_flow_error error;
643 struct rte_flow_classify_rule *rule;
648 ret = init_ipv4_udp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
649 if (ret != MAX_PKT_BURST) {
650 printf("Line %i: init_udp_ipv4_traffic has failed!\n",
655 for (i = 0; i < MAX_PKT_BURST; i++)
656 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
659 * set up parameters for rte_flow_classify_validate,
660 * rte_flow_classify_table_entry_add and
661 * rte_flow_classify_table_entry_delete
666 pattern[0] = eth_item;
667 pattern[1] = ipv4_udp_item_1;
668 pattern[2] = udp_item_1;
669 pattern[3] = end_item;
670 actions[0] = count_action;
671 actions[1] = end_action;
673 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
676 printf("Line %i: rte_flow_classify_validate", __LINE__);
677 printf(" should not have failed!\n");
681 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
682 actions, &key_found, &error);
684 printf("Line %i: flow_classify_table_entry_add", __LINE__);
685 printf(" should not have failed!\n");
689 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
690 rule, &udp_classify_stats);
692 printf("Line %i: flow_classifier_query", __LINE__);
693 printf(" should not have failed!\n");
697 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
699 printf("Line %i: rte_flow_classify_table_entry_delete",
701 printf(" should not have failed!\n");
710 struct rte_flow_classify_rule *rule;
715 ret = init_ipv4_tcp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
716 if (ret != MAX_PKT_BURST) {
717 printf("Line %i: init_ipv4_tcp_traffic has failed!\n",
722 for (i = 0; i < MAX_PKT_BURST; i++)
723 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
726 * set up parameters for rte_flow_classify_validate,
727 * rte_flow_classify_table_entry_add and
728 * rte_flow_classify_table_entry_delete
733 pattern[0] = eth_item;
734 pattern[1] = ipv4_tcp_item_1;
735 pattern[2] = tcp_item_1;
736 pattern[3] = end_item;
737 actions[0] = count_action;
738 actions[1] = end_action;
740 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
743 printf("Line %i: flow_classifier_query", __LINE__);
744 printf(" should not have failed!\n");
748 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
749 actions, &key_found, &error);
751 printf("Line %i: flow_classify_table_entry_add", __LINE__);
752 printf(" should not have failed!\n");
756 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
757 rule, &tcp_classify_stats);
759 printf("Line %i: flow_classifier_query", __LINE__);
760 printf(" should not have failed!\n");
764 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
766 printf("Line %i: rte_flow_classify_table_entry_delete",
768 printf(" should not have failed!\n");
775 test_query_sctp(void)
777 struct rte_flow_classify_rule *rule;
782 ret = init_ipv4_sctp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
783 if (ret != MAX_PKT_BURST) {
784 printf("Line %i: init_ipv4_tcp_traffic has failed!\n",
789 for (i = 0; i < MAX_PKT_BURST; i++)
790 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
793 * set up parameters rte_flow_classify_validate,
794 * rte_flow_classify_table_entry_add and
795 * rte_flow_classify_table_entry_delete
800 pattern[0] = eth_item;
801 pattern[1] = ipv4_sctp_item_1;
802 pattern[2] = sctp_item_1;
803 pattern[3] = end_item;
804 actions[0] = count_action;
805 actions[1] = end_action;
807 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
810 printf("Line %i: flow_classifier_query", __LINE__);
811 printf(" should not have failed!\n");
815 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
816 actions, &key_found, &error);
818 printf("Line %i: flow_classify_table_entry_add", __LINE__);
819 printf(" should not have failed!\n");
823 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
824 rule, &sctp_classify_stats);
826 printf("Line %i: flow_classifier_query", __LINE__);
827 printf(" should not have failed!\n");
831 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
833 printf("Line %i: rte_flow_classify_table_entry_delete",
835 printf(" should not have failed!\n");
842 test_flow_classify(void)
844 struct rte_table_acl_params table_acl_params;
845 struct rte_flow_classify_table_params cls_table_params;
846 struct rte_flow_classifier_params cls_params;
850 /* Memory allocation */
851 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct flow_classifier_acl));
852 cls = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
854 cls_params.name = "flow_classifier";
855 cls_params.socket_id = 0;
856 cls->cls = rte_flow_classifier_create(&cls_params);
858 /* initialise ACL table params */
859 table_acl_params.n_rule_fields = RTE_DIM(ipv4_defs);
860 table_acl_params.name = "table_acl_ipv4_5tuple";
861 table_acl_params.n_rules = FLOW_CLASSIFY_MAX_RULE_NUM;
862 memcpy(table_acl_params.field_format, ipv4_defs, sizeof(ipv4_defs));
864 /* initialise table create params */
865 cls_table_params.ops = &rte_table_acl_ops;
866 cls_table_params.arg_create = &table_acl_params;
867 cls_table_params.type = RTE_FLOW_CLASSIFY_TABLE_ACL_IP4_5TUPLE;
869 ret = rte_flow_classify_table_create(cls->cls, &cls_table_params);
871 printf("Line %i: f_create has failed!\n", __LINE__);
872 rte_flow_classifier_free(cls->cls);
876 printf("Created table_acl for for IPv4 five tuple packets\n");
878 ret = init_mbufpool();
880 printf("Line %i: init_mbufpool has failed!\n", __LINE__);
884 if (test_invalid_parameters() < 0)
886 if (test_valid_parameters() < 0)
888 if (test_invalid_patterns() < 0)
890 if (test_invalid_actions() < 0)
892 if (test_query_udp() < 0)
894 if (test_query_tcp() < 0)
896 if (test_query_sctp() < 0)
902 REGISTER_TEST_COMMAND(flow_classify_autotest, test_flow_classify);