1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
10 #include <rte_ethdev.h>
11 #include <rte_cycles.h>
12 #include <rte_lcore.h>
15 #include <rte_flow_classify.h>
16 #include <rte_table_acl.h>
18 #define RX_RING_SIZE 1024
19 #define TX_RING_SIZE 1024
21 #define NUM_MBUFS 8191
22 #define MBUF_CACHE_SIZE 250
25 #define MAX_NUM_CLASSIFY 30
26 #define FLOW_CLASSIFY_MAX_RULE_NUM 91
27 #define FLOW_CLASSIFY_MAX_PRIORITY 8
28 #define FLOW_CLASSIFIER_NAME_SIZE 64
30 #define COMMENT_LEAD_CHAR ('#')
31 #define OPTION_RULE_IPV4 "rule_ipv4"
32 #define RTE_LOGTYPE_FLOW_CLASSIFY RTE_LOGTYPE_USER3
33 #define flow_classify_log(format, ...) \
34 RTE_LOG(ERR, FLOW_CLASSIFY, format, ##__VA_ARGS__)
36 #define uint32_t_to_char(ip, a, b, c, d) do {\
37 *a = (unsigned char)(ip >> 24 & 0xff);\
38 *b = (unsigned char)(ip >> 16 & 0xff);\
39 *c = (unsigned char)(ip >> 8 & 0xff);\
40 *d = (unsigned char)(ip & 0xff);\
58 const char *rule_ipv4_name;
60 const char cb_port_delim[] = ":";
62 static const struct rte_eth_conf port_conf_default = {
64 .max_rx_pkt_len = ETHER_MAX_LEN,
65 .ignore_offload_bitfield = 1,
69 struct flow_classifier {
70 struct rte_flow_classifier *cls;
73 struct flow_classifier_acl {
74 struct flow_classifier cls;
75 } __rte_cache_aligned;
77 /* ACL field definitions for IPv4 5 tuple rule */
95 static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = {
96 /* first input field - always one byte long. */
98 .type = RTE_ACL_FIELD_TYPE_BITMASK,
99 .size = sizeof(uint8_t),
100 .field_index = PROTO_FIELD_IPV4,
101 .input_index = PROTO_INPUT_IPV4,
102 .offset = sizeof(struct ether_hdr) +
103 offsetof(struct ipv4_hdr, next_proto_id),
105 /* next input field (IPv4 source address) - 4 consecutive bytes. */
107 /* rte_flow uses a bit mask for IPv4 addresses */
108 .type = RTE_ACL_FIELD_TYPE_BITMASK,
109 .size = sizeof(uint32_t),
110 .field_index = SRC_FIELD_IPV4,
111 .input_index = SRC_INPUT_IPV4,
112 .offset = sizeof(struct ether_hdr) +
113 offsetof(struct ipv4_hdr, src_addr),
115 /* next input field (IPv4 destination address) - 4 consecutive bytes. */
117 /* rte_flow uses a bit mask for IPv4 addresses */
118 .type = RTE_ACL_FIELD_TYPE_BITMASK,
119 .size = sizeof(uint32_t),
120 .field_index = DST_FIELD_IPV4,
121 .input_index = DST_INPUT_IPV4,
122 .offset = sizeof(struct ether_hdr) +
123 offsetof(struct ipv4_hdr, dst_addr),
126 * Next 2 fields (src & dst ports) form 4 consecutive bytes.
127 * They share the same input index.
130 /* rte_flow uses a bit mask for protocol ports */
131 .type = RTE_ACL_FIELD_TYPE_BITMASK,
132 .size = sizeof(uint16_t),
133 .field_index = SRCP_FIELD_IPV4,
134 .input_index = SRCP_DESTP_INPUT_IPV4,
135 .offset = sizeof(struct ether_hdr) +
136 sizeof(struct ipv4_hdr) +
137 offsetof(struct tcp_hdr, src_port),
140 /* rte_flow uses a bit mask for protocol ports */
141 .type = RTE_ACL_FIELD_TYPE_BITMASK,
142 .size = sizeof(uint16_t),
143 .field_index = DSTP_FIELD_IPV4,
144 .input_index = SRCP_DESTP_INPUT_IPV4,
145 .offset = sizeof(struct ether_hdr) +
146 sizeof(struct ipv4_hdr) +
147 offsetof(struct tcp_hdr, dst_port),
151 /* flow classify data */
152 static int num_classify_rules;
153 static struct rte_flow_classify_rule *rules[MAX_NUM_CLASSIFY];
154 static struct rte_flow_classify_ipv4_5tuple_stats ntuple_stats;
155 static struct rte_flow_classify_stats classify_stats = {
156 .stats = (void **)&ntuple_stats
159 /* parameters for rte_flow_classify_validate and
160 * rte_flow_classify_table_entry_add functions
163 static struct rte_flow_item eth_item = { RTE_FLOW_ITEM_TYPE_ETH,
165 static struct rte_flow_item end_item = { RTE_FLOW_ITEM_TYPE_END,
169 * "actions count / end"
171 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 end_action = { RTE_FLOW_ACTION_TYPE_END, 0};
181 static struct rte_flow_action actions[2];
183 /* sample attributes */
184 static struct rte_flow_attr attr;
186 /* flow_classify.c: * Based on DPDK skeleton forwarding example. */
189 * Initializes a given port using global settings and with the RX buffers
190 * coming from the mbuf_pool passed as a parameter.
193 port_init(uint8_t port, struct rte_mempool *mbuf_pool)
195 struct rte_eth_conf port_conf = port_conf_default;
196 struct ether_addr addr;
197 const uint16_t rx_rings = 1, tx_rings = 1;
200 struct rte_eth_dev_info dev_info;
201 struct rte_eth_txconf txconf;
203 if (!rte_eth_dev_is_valid_port(port))
206 rte_eth_dev_info_get(port, &dev_info);
207 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
208 port_conf.txmode.offloads |=
209 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
211 /* Configure the Ethernet device. */
212 retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
216 /* Allocate and set up 1 RX queue per Ethernet port. */
217 for (q = 0; q < rx_rings; q++) {
218 retval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE,
219 rte_eth_dev_socket_id(port), NULL, mbuf_pool);
224 txconf = dev_info.default_txconf;
225 txconf.txq_flags = ETH_TXQ_FLAGS_IGNORE;
226 txconf.offloads = port_conf.txmode.offloads;
227 /* Allocate and set up 1 TX queue per Ethernet port. */
228 for (q = 0; q < tx_rings; q++) {
229 retval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE,
230 rte_eth_dev_socket_id(port), &txconf);
235 /* Start the Ethernet port. */
236 retval = rte_eth_dev_start(port);
240 /* Display the port MAC address. */
241 rte_eth_macaddr_get(port, &addr);
242 printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
243 " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
245 addr.addr_bytes[0], addr.addr_bytes[1],
246 addr.addr_bytes[2], addr.addr_bytes[3],
247 addr.addr_bytes[4], addr.addr_bytes[5]);
249 /* Enable RX in promiscuous mode for the Ethernet device. */
250 rte_eth_promiscuous_enable(port);
256 * The lcore main. This is the main thread that does the work, reading from
257 * an input port classifying the packets and writing to an output port.
259 static __attribute__((noreturn)) void
260 lcore_main(struct flow_classifier *cls_app)
266 ret = rte_flow_classify_table_entry_delete(cls_app->cls,
269 printf("table_entry_delete failed [7] %d\n\n", ret);
271 printf("table_entry_delete succeeded [7]\n\n");
274 * Check that the port is on the same NUMA node as the polling thread
275 * for best performance.
277 RTE_ETH_FOREACH_DEV(port)
278 if (rte_eth_dev_socket_id(port) > 0 &&
279 rte_eth_dev_socket_id(port) != (int)rte_socket_id()) {
281 printf("WARNING: port %u is on remote NUMA node\n",
283 printf("to polling thread.\n");
284 printf("Performance will not be optimal.\n");
286 printf("\nCore %u forwarding packets. ", rte_lcore_id());
287 printf("[Ctrl+C to quit]\n");
289 /* Run until the application is quit or killed. */
292 * Receive packets on a port, classify them and forward them
293 * on the paired port.
294 * The mapping is 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2, etc.
296 RTE_ETH_FOREACH_DEV(port) {
297 /* Get burst of RX packets, from first port of pair. */
298 struct rte_mbuf *bufs[BURST_SIZE];
299 const uint16_t nb_rx = rte_eth_rx_burst(port, 0,
302 if (unlikely(nb_rx == 0))
305 for (i = 0; i < MAX_NUM_CLASSIFY; i++) {
307 ret = rte_flow_classifier_query(
309 bufs, nb_rx, rules[i],
313 "rule [%d] query failed ret [%d]\n\n",
317 "rule[%d] count=%"PRIu64"\n",
318 i, ntuple_stats.counter1);
320 printf("proto = %d\n",
321 ntuple_stats.ipv4_5tuple.proto);
326 /* Send burst of TX packets, to second port of pair. */
327 const uint16_t nb_tx = rte_eth_tx_burst(port ^ 1, 0,
330 /* Free any unsent packets. */
331 if (unlikely(nb_tx < nb_rx)) {
334 for (buf = nb_tx; buf < nb_rx; buf++)
335 rte_pktmbuf_free(bufs[buf]);
342 * Parse IPv4 5 tuple rules file, ipv4_rules_file.txt.
344 * <src_ipv4_addr>'/'<masklen> <space> \
345 * <dst_ipv4_addr>'/'<masklen> <space> \
346 * <src_port> <space> ":" <src_port_mask> <space> \
347 * <dst_port> <space> ":" <dst_port_mask> <space> \
348 * <proto>'/'<proto_mask> <space> \
353 get_cb_field(char **in, uint32_t *fd, int base, unsigned long lim,
360 val = strtoul(*in, &end, base);
361 if (errno != 0 || end[0] != dlm || val > lim)
369 parse_ipv4_net(char *in, uint32_t *addr, uint32_t *mask_len)
371 uint32_t a, b, c, d, m;
373 if (get_cb_field(&in, &a, 0, UINT8_MAX, '.'))
375 if (get_cb_field(&in, &b, 0, UINT8_MAX, '.'))
377 if (get_cb_field(&in, &c, 0, UINT8_MAX, '.'))
379 if (get_cb_field(&in, &d, 0, UINT8_MAX, '/'))
381 if (get_cb_field(&in, &m, 0, sizeof(uint32_t) * CHAR_BIT, 0))
384 addr[0] = IPv4(a, b, c, d);
390 parse_ipv4_5tuple_rule(char *str, struct rte_eth_ntuple_filter *ntuple_filter)
393 char *s, *sp, *in[CB_FLD_NUM];
394 static const char *dlm = " \t\n";
395 int dim = CB_FLD_NUM;
399 for (i = 0; i != dim; i++, s = NULL) {
400 in[i] = strtok_r(s, dlm, &sp);
405 ret = parse_ipv4_net(in[CB_FLD_SRC_ADDR],
406 &ntuple_filter->src_ip,
407 &ntuple_filter->src_ip_mask);
409 flow_classify_log("failed to read source address/mask: %s\n",
410 in[CB_FLD_SRC_ADDR]);
414 ret = parse_ipv4_net(in[CB_FLD_DST_ADDR],
415 &ntuple_filter->dst_ip,
416 &ntuple_filter->dst_ip_mask);
418 flow_classify_log("failed to read source address/mask: %s\n",
419 in[CB_FLD_DST_ADDR]);
423 if (get_cb_field(&in[CB_FLD_SRC_PORT], &temp, 0, UINT16_MAX, 0))
425 ntuple_filter->src_port = (uint16_t)temp;
427 if (strncmp(in[CB_FLD_SRC_PORT_DLM], cb_port_delim,
428 sizeof(cb_port_delim)) != 0)
431 if (get_cb_field(&in[CB_FLD_SRC_PORT_MASK], &temp, 0, UINT16_MAX, 0))
433 ntuple_filter->src_port_mask = (uint16_t)temp;
435 if (get_cb_field(&in[CB_FLD_DST_PORT], &temp, 0, UINT16_MAX, 0))
437 ntuple_filter->dst_port = (uint16_t)temp;
439 if (strncmp(in[CB_FLD_DST_PORT_DLM], cb_port_delim,
440 sizeof(cb_port_delim)) != 0)
443 if (get_cb_field(&in[CB_FLD_DST_PORT_MASK], &temp, 0, UINT16_MAX, 0))
445 ntuple_filter->dst_port_mask = (uint16_t)temp;
447 if (get_cb_field(&in[CB_FLD_PROTO], &temp, 0, UINT8_MAX, '/'))
449 ntuple_filter->proto = (uint8_t)temp;
451 if (get_cb_field(&in[CB_FLD_PROTO], &temp, 0, UINT8_MAX, 0))
453 ntuple_filter->proto_mask = (uint8_t)temp;
455 if (get_cb_field(&in[CB_FLD_PRIORITY], &temp, 0, UINT16_MAX, 0))
457 ntuple_filter->priority = (uint16_t)temp;
458 if (ntuple_filter->priority > FLOW_CLASSIFY_MAX_PRIORITY)
464 /* Bypass comment and empty lines */
466 is_bypass_line(char *buff)
471 if (buff[0] == COMMENT_LEAD_CHAR)
474 while (buff[i] != '\0') {
475 if (!isspace(buff[i]))
483 convert_depth_to_bitmask(uint32_t depth_val)
485 uint32_t bitmask = 0;
488 for (i = depth_val, j = 0; i > 0; i--, j++)
489 bitmask |= (1 << (31 - j));
494 add_classify_rule(struct rte_eth_ntuple_filter *ntuple_filter,
495 struct flow_classifier *cls_app)
499 struct rte_flow_error error;
500 struct rte_flow_item_ipv4 ipv4_spec;
501 struct rte_flow_item_ipv4 ipv4_mask;
502 struct rte_flow_item ipv4_udp_item;
503 struct rte_flow_item ipv4_tcp_item;
504 struct rte_flow_item ipv4_sctp_item;
505 struct rte_flow_item_udp udp_spec;
506 struct rte_flow_item_udp udp_mask;
507 struct rte_flow_item udp_item;
508 struct rte_flow_item_tcp tcp_spec;
509 struct rte_flow_item_tcp tcp_mask;
510 struct rte_flow_item tcp_item;
511 struct rte_flow_item_sctp sctp_spec;
512 struct rte_flow_item_sctp sctp_mask;
513 struct rte_flow_item sctp_item;
514 struct rte_flow_item pattern_ipv4_5tuple[4];
515 struct rte_flow_classify_rule *rule;
518 if (num_classify_rules >= MAX_NUM_CLASSIFY) {
520 "\nINFO: classify rule capacity %d reached\n",
525 /* set up parameters for validate and add */
526 memset(&ipv4_spec, 0, sizeof(ipv4_spec));
527 ipv4_spec.hdr.next_proto_id = ntuple_filter->proto;
528 ipv4_spec.hdr.src_addr = ntuple_filter->src_ip;
529 ipv4_spec.hdr.dst_addr = ntuple_filter->dst_ip;
530 ipv4_proto = ipv4_spec.hdr.next_proto_id;
532 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
533 ipv4_mask.hdr.next_proto_id = ntuple_filter->proto_mask;
534 ipv4_mask.hdr.src_addr = ntuple_filter->src_ip_mask;
535 ipv4_mask.hdr.src_addr =
536 convert_depth_to_bitmask(ipv4_mask.hdr.src_addr);
537 ipv4_mask.hdr.dst_addr = ntuple_filter->dst_ip_mask;
538 ipv4_mask.hdr.dst_addr =
539 convert_depth_to_bitmask(ipv4_mask.hdr.dst_addr);
541 switch (ipv4_proto) {
543 ipv4_udp_item.type = RTE_FLOW_ITEM_TYPE_IPV4;
544 ipv4_udp_item.spec = &ipv4_spec;
545 ipv4_udp_item.mask = &ipv4_mask;
546 ipv4_udp_item.last = NULL;
548 udp_spec.hdr.src_port = ntuple_filter->src_port;
549 udp_spec.hdr.dst_port = ntuple_filter->dst_port;
550 udp_spec.hdr.dgram_len = 0;
551 udp_spec.hdr.dgram_cksum = 0;
553 udp_mask.hdr.src_port = ntuple_filter->src_port_mask;
554 udp_mask.hdr.dst_port = ntuple_filter->dst_port_mask;
555 udp_mask.hdr.dgram_len = 0;
556 udp_mask.hdr.dgram_cksum = 0;
558 udp_item.type = RTE_FLOW_ITEM_TYPE_UDP;
559 udp_item.spec = &udp_spec;
560 udp_item.mask = &udp_mask;
561 udp_item.last = NULL;
563 attr.priority = ntuple_filter->priority;
564 pattern_ipv4_5tuple[1] = ipv4_udp_item;
565 pattern_ipv4_5tuple[2] = udp_item;
568 ipv4_tcp_item.type = RTE_FLOW_ITEM_TYPE_IPV4;
569 ipv4_tcp_item.spec = &ipv4_spec;
570 ipv4_tcp_item.mask = &ipv4_mask;
571 ipv4_tcp_item.last = NULL;
573 memset(&tcp_spec, 0, sizeof(tcp_spec));
574 tcp_spec.hdr.src_port = ntuple_filter->src_port;
575 tcp_spec.hdr.dst_port = ntuple_filter->dst_port;
577 memset(&tcp_mask, 0, sizeof(tcp_mask));
578 tcp_mask.hdr.src_port = ntuple_filter->src_port_mask;
579 tcp_mask.hdr.dst_port = ntuple_filter->dst_port_mask;
581 tcp_item.type = RTE_FLOW_ITEM_TYPE_TCP;
582 tcp_item.spec = &tcp_spec;
583 tcp_item.mask = &tcp_mask;
584 tcp_item.last = NULL;
586 attr.priority = ntuple_filter->priority;
587 pattern_ipv4_5tuple[1] = ipv4_tcp_item;
588 pattern_ipv4_5tuple[2] = tcp_item;
591 ipv4_sctp_item.type = RTE_FLOW_ITEM_TYPE_IPV4;
592 ipv4_sctp_item.spec = &ipv4_spec;
593 ipv4_sctp_item.mask = &ipv4_mask;
594 ipv4_sctp_item.last = NULL;
596 sctp_spec.hdr.src_port = ntuple_filter->src_port;
597 sctp_spec.hdr.dst_port = ntuple_filter->dst_port;
598 sctp_spec.hdr.cksum = 0;
599 sctp_spec.hdr.tag = 0;
601 sctp_mask.hdr.src_port = ntuple_filter->src_port_mask;
602 sctp_mask.hdr.dst_port = ntuple_filter->dst_port_mask;
603 sctp_mask.hdr.cksum = 0;
604 sctp_mask.hdr.tag = 0;
606 sctp_item.type = RTE_FLOW_ITEM_TYPE_SCTP;
607 sctp_item.spec = &sctp_spec;
608 sctp_item.mask = &sctp_mask;
609 sctp_item.last = NULL;
611 attr.priority = ntuple_filter->priority;
612 pattern_ipv4_5tuple[1] = ipv4_sctp_item;
613 pattern_ipv4_5tuple[2] = sctp_item;
620 pattern_ipv4_5tuple[0] = eth_item;
621 pattern_ipv4_5tuple[3] = end_item;
622 actions[0] = count_action;
623 actions[1] = end_action;
625 /* Validate and add rule */
626 ret = rte_flow_classify_validate(cls_app->cls, &attr,
627 pattern_ipv4_5tuple, actions, &error);
629 printf("table entry validate failed ipv4_proto = %u\n",
634 rule = rte_flow_classify_table_entry_add(
635 cls_app->cls, &attr, pattern_ipv4_5tuple,
636 actions, &key_found, &error);
638 printf("table entry add failed ipv4_proto = %u\n",
644 rules[num_classify_rules] = rule;
645 num_classify_rules++;
650 add_rules(const char *rule_path, struct flow_classifier *cls_app)
655 unsigned int total_num = 0;
656 struct rte_eth_ntuple_filter ntuple_filter;
659 fh = fopen(rule_path, "rb");
661 rte_exit(EXIT_FAILURE, "%s: fopen %s failed\n", __func__,
664 ret = fseek(fh, 0, SEEK_SET);
666 rte_exit(EXIT_FAILURE, "%s: fseek %d failed\n", __func__,
670 while (fgets(buff, LINE_MAX, fh) != NULL) {
673 if (is_bypass_line(buff))
676 if (total_num >= FLOW_CLASSIFY_MAX_RULE_NUM - 1) {
677 printf("\nINFO: classify rule capacity %d reached\n",
682 if (parse_ipv4_5tuple_rule(buff, &ntuple_filter) != 0)
683 rte_exit(EXIT_FAILURE,
684 "%s Line %u: parse rules error\n",
687 if (add_classify_rule(&ntuple_filter, cls_app) != 0)
688 rte_exit(EXIT_FAILURE, "add rule error\n");
699 print_usage(const char *prgname)
701 printf("%s usage:\n", prgname);
702 printf("[EAL options] -- --"OPTION_RULE_IPV4"=FILE: ");
703 printf("specify the ipv4 rules file.\n");
704 printf("Each rule occupies one line in the file.\n");
707 /* Parse the argument given in the command line of the application */
709 parse_args(int argc, char **argv)
714 char *prgname = argv[0];
715 static struct option lgopts[] = {
716 {OPTION_RULE_IPV4, 1, 0, 0},
722 while ((opt = getopt_long(argc, argvopt, "",
723 lgopts, &option_index)) != EOF) {
728 if (!strncmp(lgopts[option_index].name,
730 sizeof(OPTION_RULE_IPV4)))
731 parm_config.rule_ipv4_name = optarg;
734 print_usage(prgname);
740 argv[optind-1] = prgname;
743 optind = 1; /* reset getopt lib */
748 * The main function, which does initialization and calls the lcore_main
752 main(int argc, char *argv[])
754 struct rte_mempool *mbuf_pool;
759 struct rte_table_acl_params table_acl_params;
760 struct rte_flow_classify_table_params cls_table_params;
761 struct flow_classifier *cls_app;
762 struct rte_flow_classifier_params cls_params;
765 /* Initialize the Environment Abstraction Layer (EAL). */
766 ret = rte_eal_init(argc, argv);
768 rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
773 /* parse application arguments (after the EAL ones) */
774 ret = parse_args(argc, argv);
776 rte_exit(EXIT_FAILURE, "Invalid flow_classify parameters\n");
778 /* Check that there is an even number of ports to send/receive on. */
779 nb_ports = rte_eth_dev_count_avail();
780 if (nb_ports < 2 || (nb_ports & 1))
781 rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");
783 /* Creates a new mempool in memory to hold the mbufs. */
784 mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports,
785 MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
787 if (mbuf_pool == NULL)
788 rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
790 /* Initialize all ports. */
791 RTE_ETH_FOREACH_DEV(portid)
792 if (port_init(portid, mbuf_pool) != 0)
793 rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n",
796 if (rte_lcore_count() > 1)
797 printf("\nWARNING: Too many lcores enabled. Only 1 used.\n");
799 socket_id = rte_eth_dev_socket_id(0);
801 /* Memory allocation */
802 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct flow_classifier_acl));
803 cls_app = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
805 rte_exit(EXIT_FAILURE, "Cannot allocate classifier memory\n");
807 cls_params.name = "flow_classifier";
808 cls_params.socket_id = socket_id;
810 cls_app->cls = rte_flow_classifier_create(&cls_params);
811 if (cls_app->cls == NULL) {
813 rte_exit(EXIT_FAILURE, "Cannot create classifier\n");
816 /* initialise ACL table params */
817 table_acl_params.name = "table_acl_ipv4_5tuple";
818 table_acl_params.n_rules = FLOW_CLASSIFY_MAX_RULE_NUM;
819 table_acl_params.n_rule_fields = RTE_DIM(ipv4_defs);
820 memcpy(table_acl_params.field_format, ipv4_defs, sizeof(ipv4_defs));
822 /* initialise table create params */
823 cls_table_params.ops = &rte_table_acl_ops;
824 cls_table_params.arg_create = &table_acl_params;
825 cls_table_params.type = RTE_FLOW_CLASSIFY_TABLE_ACL_IP4_5TUPLE;
827 ret = rte_flow_classify_table_create(cls_app->cls, &cls_table_params);
829 rte_flow_classifier_free(cls_app->cls);
831 rte_exit(EXIT_FAILURE, "Failed to create classifier table\n");
834 /* read file of IPv4 5 tuple rules and initialize parameters
835 * for rte_flow_classify_validate and rte_flow_classify_table_entry_add
838 if (add_rules(parm_config.rule_ipv4_name, cls_app)) {
839 rte_flow_classifier_free(cls_app->cls);
841 rte_exit(EXIT_FAILURE, "Failed to add rules\n");
844 /* Call lcore_main on the master core only. */