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 (port >= rte_eth_dev_count())
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)
262 const uint8_t nb_ports = rte_eth_dev_count();
267 ret = rte_flow_classify_table_entry_delete(cls_app->cls,
270 printf("table_entry_delete failed [7] %d\n\n", ret);
272 printf("table_entry_delete succeeded [7]\n\n");
275 * Check that the port is on the same NUMA node as the polling thread
276 * for best performance.
278 for (port = 0; port < nb_ports; port++)
279 if (rte_eth_dev_socket_id(port) > 0 &&
280 rte_eth_dev_socket_id(port) != (int)rte_socket_id()) {
282 printf("WARNING: port %u is on remote NUMA node\n",
284 printf("to polling thread.\n");
285 printf("Performance will not be optimal.\n");
287 printf("\nCore %u forwarding packets. ", rte_lcore_id());
288 printf("[Ctrl+C to quit]\n");
290 /* Run until the application is quit or killed. */
293 * Receive packets on a port, classify them and forward them
294 * on the paired port.
295 * The mapping is 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2, etc.
297 for (port = 0; port < nb_ports; port++) {
298 /* Get burst of RX packets, from first port of pair. */
299 struct rte_mbuf *bufs[BURST_SIZE];
300 const uint16_t nb_rx = rte_eth_rx_burst(port, 0,
303 if (unlikely(nb_rx == 0))
306 for (i = 0; i < MAX_NUM_CLASSIFY; i++) {
308 ret = rte_flow_classifier_query(
310 bufs, nb_rx, rules[i],
314 "rule [%d] query failed ret [%d]\n\n",
318 "rule[%d] count=%"PRIu64"\n",
319 i, ntuple_stats.counter1);
321 printf("proto = %d\n",
322 ntuple_stats.ipv4_5tuple.proto);
327 /* Send burst of TX packets, to second port of pair. */
328 const uint16_t nb_tx = rte_eth_tx_burst(port ^ 1, 0,
331 /* Free any unsent packets. */
332 if (unlikely(nb_tx < nb_rx)) {
335 for (buf = nb_tx; buf < nb_rx; buf++)
336 rte_pktmbuf_free(bufs[buf]);
343 * Parse IPv4 5 tuple rules file, ipv4_rules_file.txt.
345 * <src_ipv4_addr>'/'<masklen> <space> \
346 * <dst_ipv4_addr>'/'<masklen> <space> \
347 * <src_port> <space> ":" <src_port_mask> <space> \
348 * <dst_port> <space> ":" <dst_port_mask> <space> \
349 * <proto>'/'<proto_mask> <space> \
354 get_cb_field(char **in, uint32_t *fd, int base, unsigned long lim,
361 val = strtoul(*in, &end, base);
362 if (errno != 0 || end[0] != dlm || val > lim)
370 parse_ipv4_net(char *in, uint32_t *addr, uint32_t *mask_len)
372 uint32_t a, b, c, d, m;
374 if (get_cb_field(&in, &a, 0, UINT8_MAX, '.'))
376 if (get_cb_field(&in, &b, 0, UINT8_MAX, '.'))
378 if (get_cb_field(&in, &c, 0, UINT8_MAX, '.'))
380 if (get_cb_field(&in, &d, 0, UINT8_MAX, '/'))
382 if (get_cb_field(&in, &m, 0, sizeof(uint32_t) * CHAR_BIT, 0))
385 addr[0] = IPv4(a, b, c, d);
391 parse_ipv4_5tuple_rule(char *str, struct rte_eth_ntuple_filter *ntuple_filter)
394 char *s, *sp, *in[CB_FLD_NUM];
395 static const char *dlm = " \t\n";
396 int dim = CB_FLD_NUM;
400 for (i = 0; i != dim; i++, s = NULL) {
401 in[i] = strtok_r(s, dlm, &sp);
406 ret = parse_ipv4_net(in[CB_FLD_SRC_ADDR],
407 &ntuple_filter->src_ip,
408 &ntuple_filter->src_ip_mask);
410 flow_classify_log("failed to read source address/mask: %s\n",
411 in[CB_FLD_SRC_ADDR]);
415 ret = parse_ipv4_net(in[CB_FLD_DST_ADDR],
416 &ntuple_filter->dst_ip,
417 &ntuple_filter->dst_ip_mask);
419 flow_classify_log("failed to read source address/mask: %s\n",
420 in[CB_FLD_DST_ADDR]);
424 if (get_cb_field(&in[CB_FLD_SRC_PORT], &temp, 0, UINT16_MAX, 0))
426 ntuple_filter->src_port = (uint16_t)temp;
428 if (strncmp(in[CB_FLD_SRC_PORT_DLM], cb_port_delim,
429 sizeof(cb_port_delim)) != 0)
432 if (get_cb_field(&in[CB_FLD_SRC_PORT_MASK], &temp, 0, UINT16_MAX, 0))
434 ntuple_filter->src_port_mask = (uint16_t)temp;
436 if (get_cb_field(&in[CB_FLD_DST_PORT], &temp, 0, UINT16_MAX, 0))
438 ntuple_filter->dst_port = (uint16_t)temp;
440 if (strncmp(in[CB_FLD_DST_PORT_DLM], cb_port_delim,
441 sizeof(cb_port_delim)) != 0)
444 if (get_cb_field(&in[CB_FLD_DST_PORT_MASK], &temp, 0, UINT16_MAX, 0))
446 ntuple_filter->dst_port_mask = (uint16_t)temp;
448 if (get_cb_field(&in[CB_FLD_PROTO], &temp, 0, UINT8_MAX, '/'))
450 ntuple_filter->proto = (uint8_t)temp;
452 if (get_cb_field(&in[CB_FLD_PROTO], &temp, 0, UINT8_MAX, 0))
454 ntuple_filter->proto_mask = (uint8_t)temp;
456 if (get_cb_field(&in[CB_FLD_PRIORITY], &temp, 0, UINT16_MAX, 0))
458 ntuple_filter->priority = (uint16_t)temp;
459 if (ntuple_filter->priority > FLOW_CLASSIFY_MAX_PRIORITY)
465 /* Bypass comment and empty lines */
467 is_bypass_line(char *buff)
472 if (buff[0] == COMMENT_LEAD_CHAR)
475 while (buff[i] != '\0') {
476 if (!isspace(buff[i]))
484 convert_depth_to_bitmask(uint32_t depth_val)
486 uint32_t bitmask = 0;
489 for (i = depth_val, j = 0; i > 0; i--, j++)
490 bitmask |= (1 << (31 - j));
495 add_classify_rule(struct rte_eth_ntuple_filter *ntuple_filter,
496 struct flow_classifier *cls_app)
500 struct rte_flow_error error;
501 struct rte_flow_item_ipv4 ipv4_spec;
502 struct rte_flow_item_ipv4 ipv4_mask;
503 struct rte_flow_item ipv4_udp_item;
504 struct rte_flow_item ipv4_tcp_item;
505 struct rte_flow_item ipv4_sctp_item;
506 struct rte_flow_item_udp udp_spec;
507 struct rte_flow_item_udp udp_mask;
508 struct rte_flow_item udp_item;
509 struct rte_flow_item_tcp tcp_spec;
510 struct rte_flow_item_tcp tcp_mask;
511 struct rte_flow_item tcp_item;
512 struct rte_flow_item_sctp sctp_spec;
513 struct rte_flow_item_sctp sctp_mask;
514 struct rte_flow_item sctp_item;
515 struct rte_flow_item pattern_ipv4_5tuple[4];
516 struct rte_flow_classify_rule *rule;
519 if (num_classify_rules >= MAX_NUM_CLASSIFY) {
521 "\nINFO: classify rule capacity %d reached\n",
526 /* set up parameters for validate and add */
527 memset(&ipv4_spec, 0, sizeof(ipv4_spec));
528 ipv4_spec.hdr.next_proto_id = ntuple_filter->proto;
529 ipv4_spec.hdr.src_addr = ntuple_filter->src_ip;
530 ipv4_spec.hdr.dst_addr = ntuple_filter->dst_ip;
531 ipv4_proto = ipv4_spec.hdr.next_proto_id;
533 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
534 ipv4_mask.hdr.next_proto_id = ntuple_filter->proto_mask;
535 ipv4_mask.hdr.src_addr = ntuple_filter->src_ip_mask;
536 ipv4_mask.hdr.src_addr =
537 convert_depth_to_bitmask(ipv4_mask.hdr.src_addr);
538 ipv4_mask.hdr.dst_addr = ntuple_filter->dst_ip_mask;
539 ipv4_mask.hdr.dst_addr =
540 convert_depth_to_bitmask(ipv4_mask.hdr.dst_addr);
542 switch (ipv4_proto) {
544 ipv4_udp_item.type = RTE_FLOW_ITEM_TYPE_IPV4;
545 ipv4_udp_item.spec = &ipv4_spec;
546 ipv4_udp_item.mask = &ipv4_mask;
547 ipv4_udp_item.last = NULL;
549 udp_spec.hdr.src_port = ntuple_filter->src_port;
550 udp_spec.hdr.dst_port = ntuple_filter->dst_port;
551 udp_spec.hdr.dgram_len = 0;
552 udp_spec.hdr.dgram_cksum = 0;
554 udp_mask.hdr.src_port = ntuple_filter->src_port_mask;
555 udp_mask.hdr.dst_port = ntuple_filter->dst_port_mask;
556 udp_mask.hdr.dgram_len = 0;
557 udp_mask.hdr.dgram_cksum = 0;
559 udp_item.type = RTE_FLOW_ITEM_TYPE_UDP;
560 udp_item.spec = &udp_spec;
561 udp_item.mask = &udp_mask;
562 udp_item.last = NULL;
564 attr.priority = ntuple_filter->priority;
565 pattern_ipv4_5tuple[1] = ipv4_udp_item;
566 pattern_ipv4_5tuple[2] = udp_item;
569 ipv4_tcp_item.type = RTE_FLOW_ITEM_TYPE_IPV4;
570 ipv4_tcp_item.spec = &ipv4_spec;
571 ipv4_tcp_item.mask = &ipv4_mask;
572 ipv4_tcp_item.last = NULL;
574 memset(&tcp_spec, 0, sizeof(tcp_spec));
575 tcp_spec.hdr.src_port = ntuple_filter->src_port;
576 tcp_spec.hdr.dst_port = ntuple_filter->dst_port;
578 memset(&tcp_mask, 0, sizeof(tcp_mask));
579 tcp_mask.hdr.src_port = ntuple_filter->src_port_mask;
580 tcp_mask.hdr.dst_port = ntuple_filter->dst_port_mask;
582 tcp_item.type = RTE_FLOW_ITEM_TYPE_TCP;
583 tcp_item.spec = &tcp_spec;
584 tcp_item.mask = &tcp_mask;
585 tcp_item.last = NULL;
587 attr.priority = ntuple_filter->priority;
588 pattern_ipv4_5tuple[1] = ipv4_tcp_item;
589 pattern_ipv4_5tuple[2] = tcp_item;
592 ipv4_sctp_item.type = RTE_FLOW_ITEM_TYPE_IPV4;
593 ipv4_sctp_item.spec = &ipv4_spec;
594 ipv4_sctp_item.mask = &ipv4_mask;
595 ipv4_sctp_item.last = NULL;
597 sctp_spec.hdr.src_port = ntuple_filter->src_port;
598 sctp_spec.hdr.dst_port = ntuple_filter->dst_port;
599 sctp_spec.hdr.cksum = 0;
600 sctp_spec.hdr.tag = 0;
602 sctp_mask.hdr.src_port = ntuple_filter->src_port_mask;
603 sctp_mask.hdr.dst_port = ntuple_filter->dst_port_mask;
604 sctp_mask.hdr.cksum = 0;
605 sctp_mask.hdr.tag = 0;
607 sctp_item.type = RTE_FLOW_ITEM_TYPE_SCTP;
608 sctp_item.spec = &sctp_spec;
609 sctp_item.mask = &sctp_mask;
610 sctp_item.last = NULL;
612 attr.priority = ntuple_filter->priority;
613 pattern_ipv4_5tuple[1] = ipv4_sctp_item;
614 pattern_ipv4_5tuple[2] = sctp_item;
621 pattern_ipv4_5tuple[0] = eth_item;
622 pattern_ipv4_5tuple[3] = end_item;
623 actions[0] = count_action;
624 actions[1] = end_action;
626 /* Validate and add rule */
627 ret = rte_flow_classify_validate(cls_app->cls, &attr,
628 pattern_ipv4_5tuple, actions, &error);
630 printf("table entry validate failed ipv4_proto = %u\n",
635 rule = rte_flow_classify_table_entry_add(
636 cls_app->cls, &attr, pattern_ipv4_5tuple,
637 actions, &key_found, &error);
639 printf("table entry add failed ipv4_proto = %u\n",
645 rules[num_classify_rules] = rule;
646 num_classify_rules++;
651 add_rules(const char *rule_path, struct flow_classifier *cls_app)
656 unsigned int total_num = 0;
657 struct rte_eth_ntuple_filter ntuple_filter;
660 fh = fopen(rule_path, "rb");
662 rte_exit(EXIT_FAILURE, "%s: fopen %s failed\n", __func__,
665 ret = fseek(fh, 0, SEEK_SET);
667 rte_exit(EXIT_FAILURE, "%s: fseek %d failed\n", __func__,
671 while (fgets(buff, LINE_MAX, fh) != NULL) {
674 if (is_bypass_line(buff))
677 if (total_num >= FLOW_CLASSIFY_MAX_RULE_NUM - 1) {
678 printf("\nINFO: classify rule capacity %d reached\n",
683 if (parse_ipv4_5tuple_rule(buff, &ntuple_filter) != 0)
684 rte_exit(EXIT_FAILURE,
685 "%s Line %u: parse rules error\n",
688 if (add_classify_rule(&ntuple_filter, cls_app) != 0)
689 rte_exit(EXIT_FAILURE, "add rule error\n");
700 print_usage(const char *prgname)
702 printf("%s usage:\n", prgname);
703 printf("[EAL options] -- --"OPTION_RULE_IPV4"=FILE: ");
704 printf("specify the ipv4 rules file.\n");
705 printf("Each rule occupies one line in the file.\n");
708 /* Parse the argument given in the command line of the application */
710 parse_args(int argc, char **argv)
715 char *prgname = argv[0];
716 static struct option lgopts[] = {
717 {OPTION_RULE_IPV4, 1, 0, 0},
723 while ((opt = getopt_long(argc, argvopt, "",
724 lgopts, &option_index)) != EOF) {
729 if (!strncmp(lgopts[option_index].name,
731 sizeof(OPTION_RULE_IPV4)))
732 parm_config.rule_ipv4_name = optarg;
735 print_usage(prgname);
741 argv[optind-1] = prgname;
744 optind = 1; /* reset getopt lib */
749 * The main function, which does initialization and calls the lcore_main
753 main(int argc, char *argv[])
755 struct rte_mempool *mbuf_pool;
760 struct rte_table_acl_params table_acl_params;
761 struct rte_flow_classify_table_params cls_table_params;
762 struct flow_classifier *cls_app;
763 struct rte_flow_classifier_params cls_params;
766 /* Initialize the Environment Abstraction Layer (EAL). */
767 ret = rte_eal_init(argc, argv);
769 rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
774 /* parse application arguments (after the EAL ones) */
775 ret = parse_args(argc, argv);
777 rte_exit(EXIT_FAILURE, "Invalid flow_classify parameters\n");
779 /* Check that there is an even number of ports to send/receive on. */
780 nb_ports = rte_eth_dev_count();
781 if (nb_ports < 2 || (nb_ports & 1))
782 rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");
784 /* Creates a new mempool in memory to hold the mbufs. */
785 mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports,
786 MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
788 if (mbuf_pool == NULL)
789 rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
791 /* Initialize all ports. */
792 for (portid = 0; portid < nb_ports; portid++)
793 if (port_init(portid, mbuf_pool) != 0)
794 rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n",
797 if (rte_lcore_count() > 1)
798 printf("\nWARNING: Too many lcores enabled. Only 1 used.\n");
800 socket_id = rte_eth_dev_socket_id(0);
802 /* Memory allocation */
803 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct flow_classifier_acl));
804 cls_app = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
806 rte_exit(EXIT_FAILURE, "Cannot allocate classifier memory\n");
808 cls_params.name = "flow_classifier";
809 cls_params.socket_id = socket_id;
811 cls_app->cls = rte_flow_classifier_create(&cls_params);
812 if (cls_app->cls == NULL) {
814 rte_exit(EXIT_FAILURE, "Cannot create classifier\n");
817 /* initialise ACL table params */
818 table_acl_params.name = "table_acl_ipv4_5tuple";
819 table_acl_params.n_rules = FLOW_CLASSIFY_MAX_RULE_NUM;
820 table_acl_params.n_rule_fields = RTE_DIM(ipv4_defs);
821 memcpy(table_acl_params.field_format, ipv4_defs, sizeof(ipv4_defs));
823 /* initialise table create params */
824 cls_table_params.ops = &rte_table_acl_ops;
825 cls_table_params.arg_create = &table_acl_params;
826 cls_table_params.type = RTE_FLOW_CLASSIFY_TABLE_ACL_IP4_5TUPLE;
828 ret = rte_flow_classify_table_create(cls_app->cls, &cls_table_params);
830 rte_flow_classifier_free(cls_app->cls);
832 rte_exit(EXIT_FAILURE, "Failed to create classifier table\n");
835 /* read file of IPv4 5 tuple rules and initialize parameters
836 * for rte_flow_classify_validate and rte_flow_classify_table_entry_add
839 if (add_rules(parm_config.rule_ipv4_name, cls_app)) {
840 rte_flow_classifier_free(cls_app->cls);
842 rte_exit(EXIT_FAILURE, "Failed to add rules\n");
845 /* Call lcore_main on the master core only. */