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 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 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,
128 static struct rte_flow_item end_item_bad = { -1, 0, 0, 0 };
131 * "eth / ipv4 src spec 1.2.3.4 src mask 255.255.255.00 dst spec 5.6.7.8
132 * dst mask 255.255.255.00 / tcp src is 16 dst is 17 / end"
134 static struct rte_flow_item_ipv4 ipv4_tcp_spec_1 = {
135 { 0, 0, 0, 0, 0, 0, IPPROTO_TCP, 0,
136 RTE_IPv4(1, 2, 3, 4), RTE_IPv4(5, 6, 7, 8)}
139 static struct rte_flow_item_tcp tcp_spec_1 = {
140 { 16, 17, 0, 0, 0, 0, 0, 0, 0}
143 static struct rte_flow_item ipv4_tcp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
144 &ipv4_tcp_spec_1, 0, &ipv4_mask_24};
146 static struct rte_flow_item tcp_item_1 = { RTE_FLOW_ITEM_TYPE_TCP,
147 &tcp_spec_1, 0, &rte_flow_item_tcp_mask};
149 /* test SCTP pattern:
150 * "eth / ipv4 src spec 1.2.3.4 src mask 255.255.255.00 dst spec 5.6.7.8
151 * dst mask 255.255.255.00 / sctp src is 16 dst is 17/ end"
153 static struct rte_flow_item_ipv4 ipv4_sctp_spec_1 = {
154 { 0, 0, 0, 0, 0, 0, IPPROTO_SCTP, 0, RTE_IPv4(11, 12, 13, 14),
155 RTE_IPv4(15, 16, 17, 18)}
158 static struct rte_flow_item_sctp sctp_spec_1 = {
162 static struct rte_flow_item ipv4_sctp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,
163 &ipv4_sctp_spec_1, 0, &ipv4_mask_24};
165 static struct rte_flow_item sctp_item_1 = { RTE_FLOW_ITEM_TYPE_SCTP,
166 &sctp_spec_1, 0, &rte_flow_item_sctp_mask};
170 * "actions count / end"
172 static struct rte_flow_query_count count = {
179 static struct rte_flow_action count_action = { RTE_FLOW_ACTION_TYPE_COUNT,
181 static struct rte_flow_action count_action_bad = { -1, 0};
183 static struct rte_flow_action end_action = { RTE_FLOW_ACTION_TYPE_END, 0};
184 static struct rte_flow_action end_action_bad = { -1, 0};
186 static struct rte_flow_action actions[2];
188 /* test attributes */
189 static struct rte_flow_attr attr;
192 static struct rte_flow_error error;
195 static struct rte_flow_item pattern[4];
197 /* flow classify data for UDP burst */
198 static struct rte_flow_classify_ipv4_5tuple_stats udp_ntuple_stats;
199 static struct rte_flow_classify_stats udp_classify_stats = {
200 .stats = (void *)&udp_ntuple_stats
203 /* flow classify data for TCP burst */
204 static struct rte_flow_classify_ipv4_5tuple_stats tcp_ntuple_stats;
205 static struct rte_flow_classify_stats tcp_classify_stats = {
206 .stats = (void *)&tcp_ntuple_stats
209 /* flow classify data for SCTP burst */
210 static struct rte_flow_classify_ipv4_5tuple_stats sctp_ntuple_stats;
211 static struct rte_flow_classify_stats sctp_classify_stats = {
212 .stats = (void *)&sctp_ntuple_stats
215 struct flow_classifier_acl *cls;
217 struct flow_classifier_acl {
218 struct rte_flow_classifier *cls;
219 } __rte_cache_aligned;
222 * test functions by passing invalid or
223 * non-workable parameters.
226 test_invalid_parameters(void)
228 struct rte_flow_classify_rule *rule;
231 ret = rte_flow_classify_validate(NULL, NULL, NULL, NULL, NULL);
233 printf("Line %i: rte_flow_classify_validate",
235 printf(" with NULL param should have failed!\n");
239 rule = rte_flow_classify_table_entry_add(NULL, NULL, NULL, NULL,
242 printf("Line %i: flow_classifier_table_entry_add", __LINE__);
243 printf(" with NULL param should have failed!\n");
247 ret = rte_flow_classify_table_entry_delete(NULL, NULL);
249 printf("Line %i: rte_flow_classify_table_entry_delete",
251 printf(" with NULL param should have failed!\n");
255 ret = rte_flow_classifier_query(NULL, NULL, 0, NULL, NULL);
257 printf("Line %i: flow_classifier_query", __LINE__);
258 printf(" with NULL param should have failed!\n");
262 rule = rte_flow_classify_table_entry_add(NULL, NULL, NULL, NULL,
265 printf("Line %i: flow_classify_table_entry_add ", __LINE__);
266 printf("with NULL param should have failed!\n");
270 ret = rte_flow_classify_table_entry_delete(NULL, NULL);
272 printf("Line %i: rte_flow_classify_table_entry_delete",
274 printf("with NULL param should have failed!\n");
278 ret = rte_flow_classifier_query(NULL, NULL, 0, NULL, NULL);
280 printf("Line %i: flow_classifier_query", __LINE__);
281 printf(" with NULL param should have failed!\n");
288 test_valid_parameters(void)
290 struct rte_flow_classify_rule *rule;
295 * set up parameters for rte_flow_classify_validate,
296 * rte_flow_classify_table_entry_add and
297 * rte_flow_classify_table_entry_delete
302 pattern[0] = eth_item;
303 pattern[1] = ipv4_udp_item_1;
304 pattern[2] = udp_item_1;
305 pattern[3] = end_item;
306 actions[0] = count_action;
307 actions[1] = end_action;
309 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
312 printf("Line %i: rte_flow_classify_validate",
314 printf(" should not have failed!\n");
317 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
318 actions, &key_found, &error);
321 printf("Line %i: flow_classify_table_entry_add", __LINE__);
322 printf(" should not have failed!\n");
326 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
328 printf("Line %i: rte_flow_classify_table_entry_delete",
330 printf(" should not have failed!\n");
337 test_invalid_patterns(void)
339 struct rte_flow_classify_rule *rule;
344 * set up parameters for rte_flow_classify_validate,
345 * rte_flow_classify_table_entry_add and
346 * rte_flow_classify_table_entry_delete
351 pattern[0] = eth_item_bad;
352 pattern[1] = ipv4_udp_item_1;
353 pattern[2] = udp_item_1;
354 pattern[3] = end_item;
355 actions[0] = count_action;
356 actions[1] = end_action;
358 pattern[0] = eth_item;
359 pattern[1] = ipv4_udp_item_bad;
361 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
364 printf("Line %i: rte_flow_classify_validate", __LINE__);
365 printf(" should have failed!\n");
369 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
370 actions, &key_found, &error);
372 printf("Line %i: flow_classify_table_entry_add", __LINE__);
373 printf(" should have failed!\n");
377 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
379 printf("Line %i: rte_flow_classify_table_entry_delete",
381 printf(" should have failed!\n");
385 pattern[1] = ipv4_udp_item_1;
386 pattern[2] = udp_item_bad;
387 pattern[3] = end_item_bad;
389 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
392 printf("Line %i: rte_flow_classify_validate", __LINE__);
393 printf(" should have failed!\n");
397 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
398 actions, &key_found, &error);
400 printf("Line %i: flow_classify_table_entry_add", __LINE__);
401 printf(" should have failed!\n");
405 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
407 printf("Line %i: rte_flow_classify_table_entry_delete",
409 printf(" should have failed!\n");
416 test_invalid_actions(void)
418 struct rte_flow_classify_rule *rule;
423 * set up parameters for rte_flow_classify_validate,
424 * rte_flow_classify_table_entry_add and
425 * rte_flow_classify_table_entry_delete
430 pattern[0] = eth_item;
431 pattern[1] = ipv4_udp_item_1;
432 pattern[2] = udp_item_1;
433 pattern[3] = end_item;
434 actions[0] = count_action_bad;
435 actions[1] = end_action;
437 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
440 printf("Line %i: rte_flow_classify_validate", __LINE__);
441 printf(" should have failed!\n");
445 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
446 actions, &key_found, &error);
448 printf("Line %i: flow_classify_table_entry_add", __LINE__);
449 printf(" should have failed!\n");
453 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
455 printf("Line %i: rte_flow_classify_table_entry_delete",
457 printf(" should have failed!\n");
461 actions[0] = count_action;
462 actions[1] = end_action_bad;
464 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
467 printf("Line %i: rte_flow_classify_validate", __LINE__);
468 printf(" should have failed!\n");
472 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
473 actions, &key_found, &error);
475 printf("Line %i: flow_classify_table_entry_add", __LINE__);
476 printf(" should have failed!\n");
480 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
482 printf("Line %i: rte_flow_classify_table_entry_delete",
484 printf("should have failed!\n");
491 init_ipv4_udp_traffic(struct rte_mempool *mp,
492 struct rte_mbuf **pkts_burst, uint32_t burst_size)
494 struct rte_ether_hdr pkt_eth_hdr;
495 struct rte_ipv4_hdr pkt_ipv4_hdr;
496 struct udp_hdr pkt_udp_hdr;
497 uint32_t src_addr = IPV4_ADDR(2, 2, 2, 3);
498 uint32_t dst_addr = IPV4_ADDR(2, 2, 2, 7);
499 uint16_t src_port = 32;
500 uint16_t dst_port = 33;
503 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
504 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
506 printf("Set up IPv4 UDP traffic\n");
507 initialize_eth_header(&pkt_eth_hdr,
508 (struct rte_ether_addr *)src_mac,
509 (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPv4, 0, 0);
510 pktlen = (uint16_t)(sizeof(struct rte_ether_hdr));
511 printf("ETH pktlen %u\n", pktlen);
513 pktlen = initialize_ipv4_header(&pkt_ipv4_hdr, src_addr, dst_addr,
515 printf("ETH + IPv4 pktlen %u\n", pktlen);
517 pktlen = initialize_udp_header(&pkt_udp_hdr, src_port, dst_port,
519 printf("ETH + IPv4 + UDP pktlen %u\n\n", pktlen);
521 return generate_packet_burst(mp, pkts_burst, &pkt_eth_hdr,
523 &pkt_udp_hdr, burst_size,
524 PACKET_BURST_GEN_PKT_LEN, 1);
528 init_ipv4_tcp_traffic(struct rte_mempool *mp,
529 struct rte_mbuf **pkts_burst, uint32_t burst_size)
531 struct rte_ether_hdr pkt_eth_hdr;
532 struct rte_ipv4_hdr pkt_ipv4_hdr;
533 struct tcp_hdr pkt_tcp_hdr;
534 uint32_t src_addr = IPV4_ADDR(1, 2, 3, 4);
535 uint32_t dst_addr = IPV4_ADDR(5, 6, 7, 8);
536 uint16_t src_port = 16;
537 uint16_t dst_port = 17;
540 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
541 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
543 printf("Set up IPv4 TCP traffic\n");
544 initialize_eth_header(&pkt_eth_hdr,
545 (struct rte_ether_addr *)src_mac,
546 (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPv4, 0, 0);
547 pktlen = (uint16_t)(sizeof(struct rte_ether_hdr));
548 printf("ETH pktlen %u\n", pktlen);
550 pktlen = initialize_ipv4_header_proto(&pkt_ipv4_hdr, src_addr,
551 dst_addr, pktlen, IPPROTO_TCP);
552 printf("ETH + IPv4 pktlen %u\n", pktlen);
554 pktlen = initialize_tcp_header(&pkt_tcp_hdr, src_port, dst_port,
556 printf("ETH + IPv4 + TCP pktlen %u\n\n", pktlen);
558 return generate_packet_burst_proto(mp, pkts_burst, &pkt_eth_hdr,
559 0, &pkt_ipv4_hdr, 1, IPPROTO_TCP,
560 &pkt_tcp_hdr, burst_size,
561 PACKET_BURST_GEN_PKT_LEN, 1);
565 init_ipv4_sctp_traffic(struct rte_mempool *mp,
566 struct rte_mbuf **pkts_burst, uint32_t burst_size)
568 struct rte_ether_hdr pkt_eth_hdr;
569 struct rte_ipv4_hdr pkt_ipv4_hdr;
570 struct sctp_hdr pkt_sctp_hdr;
571 uint32_t src_addr = IPV4_ADDR(11, 12, 13, 14);
572 uint32_t dst_addr = IPV4_ADDR(15, 16, 17, 18);
573 uint16_t src_port = 10;
574 uint16_t dst_port = 11;
577 static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
578 static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
580 printf("Set up IPv4 SCTP traffic\n");
581 initialize_eth_header(&pkt_eth_hdr,
582 (struct rte_ether_addr *)src_mac,
583 (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPv4, 0, 0);
584 pktlen = (uint16_t)(sizeof(struct rte_ether_hdr));
585 printf("ETH pktlen %u\n", pktlen);
587 pktlen = initialize_ipv4_header_proto(&pkt_ipv4_hdr, src_addr,
588 dst_addr, pktlen, IPPROTO_SCTP);
589 printf("ETH + IPv4 pktlen %u\n", pktlen);
591 pktlen = initialize_sctp_header(&pkt_sctp_hdr, src_port, dst_port,
593 printf("ETH + IPv4 + SCTP pktlen %u\n\n", pktlen);
595 return generate_packet_burst_proto(mp, pkts_burst, &pkt_eth_hdr,
596 0, &pkt_ipv4_hdr, 1, IPPROTO_SCTP,
597 &pkt_sctp_hdr, burst_size,
598 PACKET_BURST_GEN_PKT_LEN, 1);
606 unsigned int lcore_id;
609 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
610 if (rte_lcore_is_enabled(lcore_id) == 0)
613 socketid = rte_lcore_to_socket_id(lcore_id);
614 if (socketid >= NB_SOCKETS) {
616 "Socket %d of lcore %u is out of range %d\n",
617 socketid, lcore_id, NB_SOCKETS);
621 if (mbufpool[socketid] == NULL) {
622 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
624 rte_pktmbuf_pool_create(s, NB_MBUF,
625 MEMPOOL_CACHE_SIZE, 0, MBUF_SIZE,
627 if (mbufpool[socketid]) {
628 printf("Allocated mbuf pool on socket %d\n",
631 printf("Cannot init mbuf pool on socket %d\n",
644 struct rte_flow_error error;
645 struct rte_flow_classify_rule *rule;
650 ret = init_ipv4_udp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
651 if (ret != MAX_PKT_BURST) {
652 printf("Line %i: init_udp_ipv4_traffic has failed!\n",
657 for (i = 0; i < MAX_PKT_BURST; i++)
658 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
661 * set up parameters for rte_flow_classify_validate,
662 * rte_flow_classify_table_entry_add and
663 * rte_flow_classify_table_entry_delete
668 pattern[0] = eth_item;
669 pattern[1] = ipv4_udp_item_1;
670 pattern[2] = udp_item_1;
671 pattern[3] = end_item;
672 actions[0] = count_action;
673 actions[1] = end_action;
675 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
678 printf("Line %i: rte_flow_classify_validate", __LINE__);
679 printf(" should not have failed!\n");
683 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
684 actions, &key_found, &error);
686 printf("Line %i: flow_classify_table_entry_add", __LINE__);
687 printf(" should not have failed!\n");
691 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
692 rule, &udp_classify_stats);
694 printf("Line %i: flow_classifier_query", __LINE__);
695 printf(" should not have failed!\n");
699 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
701 printf("Line %i: rte_flow_classify_table_entry_delete",
703 printf(" should not have failed!\n");
712 struct rte_flow_classify_rule *rule;
717 ret = init_ipv4_tcp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
718 if (ret != MAX_PKT_BURST) {
719 printf("Line %i: init_ipv4_tcp_traffic has failed!\n",
724 for (i = 0; i < MAX_PKT_BURST; i++)
725 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
728 * set up parameters for rte_flow_classify_validate,
729 * rte_flow_classify_table_entry_add and
730 * rte_flow_classify_table_entry_delete
735 pattern[0] = eth_item;
736 pattern[1] = ipv4_tcp_item_1;
737 pattern[2] = tcp_item_1;
738 pattern[3] = end_item;
739 actions[0] = count_action;
740 actions[1] = end_action;
742 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
745 printf("Line %i: flow_classifier_query", __LINE__);
746 printf(" should not have failed!\n");
750 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
751 actions, &key_found, &error);
753 printf("Line %i: flow_classify_table_entry_add", __LINE__);
754 printf(" should not have failed!\n");
758 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
759 rule, &tcp_classify_stats);
761 printf("Line %i: flow_classifier_query", __LINE__);
762 printf(" should not have failed!\n");
766 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
768 printf("Line %i: rte_flow_classify_table_entry_delete",
770 printf(" should not have failed!\n");
777 test_query_sctp(void)
779 struct rte_flow_classify_rule *rule;
784 ret = init_ipv4_sctp_traffic(mbufpool[0], bufs, MAX_PKT_BURST);
785 if (ret != MAX_PKT_BURST) {
786 printf("Line %i: init_ipv4_tcp_traffic has failed!\n",
791 for (i = 0; i < MAX_PKT_BURST; i++)
792 bufs[i]->packet_type = RTE_PTYPE_L3_IPV4;
795 * set up parameters rte_flow_classify_validate,
796 * rte_flow_classify_table_entry_add and
797 * rte_flow_classify_table_entry_delete
802 pattern[0] = eth_item;
803 pattern[1] = ipv4_sctp_item_1;
804 pattern[2] = sctp_item_1;
805 pattern[3] = end_item;
806 actions[0] = count_action;
807 actions[1] = end_action;
809 ret = rte_flow_classify_validate(cls->cls, &attr, pattern,
812 printf("Line %i: flow_classifier_query", __LINE__);
813 printf(" should not have failed!\n");
817 rule = rte_flow_classify_table_entry_add(cls->cls, &attr, pattern,
818 actions, &key_found, &error);
820 printf("Line %i: flow_classify_table_entry_add", __LINE__);
821 printf(" should not have failed!\n");
825 ret = rte_flow_classifier_query(cls->cls, bufs, MAX_PKT_BURST,
826 rule, &sctp_classify_stats);
828 printf("Line %i: flow_classifier_query", __LINE__);
829 printf(" should not have failed!\n");
833 ret = rte_flow_classify_table_entry_delete(cls->cls, rule);
835 printf("Line %i: rte_flow_classify_table_entry_delete",
837 printf(" should not have failed!\n");
844 test_flow_classify(void)
846 struct rte_table_acl_params table_acl_params;
847 struct rte_flow_classify_table_params cls_table_params;
848 struct rte_flow_classifier_params cls_params;
852 /* Memory allocation */
853 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct flow_classifier_acl));
854 cls = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
856 cls_params.name = "flow_classifier";
857 cls_params.socket_id = 0;
858 cls->cls = rte_flow_classifier_create(&cls_params);
860 /* initialise ACL table params */
861 table_acl_params.n_rule_fields = RTE_DIM(ipv4_defs);
862 table_acl_params.name = "table_acl_ipv4_5tuple";
863 table_acl_params.n_rules = FLOW_CLASSIFY_MAX_RULE_NUM;
864 memcpy(table_acl_params.field_format, ipv4_defs, sizeof(ipv4_defs));
866 /* initialise table create params */
867 cls_table_params.ops = &rte_table_acl_ops;
868 cls_table_params.arg_create = &table_acl_params;
869 cls_table_params.type = RTE_FLOW_CLASSIFY_TABLE_ACL_IP4_5TUPLE;
871 ret = rte_flow_classify_table_create(cls->cls, &cls_table_params);
873 printf("Line %i: f_create has failed!\n", __LINE__);
874 rte_flow_classifier_free(cls->cls);
878 printf("Created table_acl for for IPv4 five tuple packets\n");
880 ret = init_mbufpool();
882 printf("Line %i: init_mbufpool has failed!\n", __LINE__);
886 if (test_invalid_parameters() < 0)
888 if (test_valid_parameters() < 0)
890 if (test_invalid_patterns() < 0)
892 if (test_invalid_actions() < 0)
894 if (test_query_udp() < 0)
896 if (test_query_tcp() < 0)
898 if (test_query_sctp() < 0)
904 REGISTER_TEST_COMMAND(flow_classify_autotest, test_flow_classify);