app/crypto-perf: support lookaside IPsec
[dpdk.git] / examples / l3fwd-acl / main.c
index 16e9530..add5e3c 100644 (file)
@@ -20,7 +20,6 @@
 #include <rte_memcpy.h>
 #include <rte_eal.h>
 #include <rte_launch.h>
-#include <rte_atomic.h>
 #include <rte_cycles.h>
 #include <rte_prefetch.h>
 #include <rte_lcore.h>
@@ -146,6 +145,40 @@ static struct rte_mempool *pktmbuf_pool[NB_SOCKETS];
 /* ethernet addresses of ports */
 static struct rte_ether_hdr port_l2hdr[RTE_MAX_ETHPORTS];
 
+static const struct {
+       const char *name;
+       enum rte_acl_classify_alg alg;
+} acl_alg[] = {
+       {
+               .name = "scalar",
+               .alg = RTE_ACL_CLASSIFY_SCALAR,
+       },
+       {
+               .name = "sse",
+               .alg = RTE_ACL_CLASSIFY_SSE,
+       },
+       {
+               .name = "avx2",
+               .alg = RTE_ACL_CLASSIFY_AVX2,
+       },
+       {
+               .name = "neon",
+               .alg = RTE_ACL_CLASSIFY_NEON,
+       },
+       {
+               .name = "altivec",
+               .alg = RTE_ACL_CLASSIFY_ALTIVEC,
+       },
+       {
+               .name = "avx512x16",
+               .alg = RTE_ACL_CLASSIFY_AVX512X16,
+       },
+       {
+               .name = "avx512x32",
+               .alg = RTE_ACL_CLASSIFY_AVX512X32,
+       },
+};
+
 /***********************start of ACL part******************************/
 #ifdef DO_RFC_1812_CHECKS
 static inline int
@@ -161,13 +194,24 @@ send_single_packet(struct rte_mbuf *m, uint16_t port);
 #define ACL_LEAD_CHAR          ('@')
 #define ROUTE_LEAD_CHAR                ('R')
 #define COMMENT_LEAD_CHAR      ('#')
-#define OPTION_CONFIG          "config"
-#define OPTION_NONUMA          "no-numa"
-#define OPTION_ENBJMO          "enable-jumbo"
-#define OPTION_RULE_IPV4       "rule_ipv4"
-#define OPTION_RULE_IPV6       "rule_ipv6"
-#define OPTION_SCALAR          "scalar"
-#define OPTION_ETH_DEST                "eth-dest"
+
+enum {
+#define OPT_CONFIG      "config"
+       OPT_CONFIG_NUM = 256,
+#define OPT_NONUMA      "no-numa"
+       OPT_NONUMA_NUM,
+#define OPT_ENBJMO      "enable-jumbo"
+       OPT_ENBJMO_NUM,
+#define OPT_RULE_IPV4   "rule_ipv4"
+       OPT_RULE_IPV4_NUM,
+#define OPT_RULE_IPV6  "rule_ipv6"
+       OPT_RULE_IPV6_NUM,
+#define OPT_ALG         "alg"
+       OPT_ALG_NUM,
+#define OPT_ETH_DEST    "eth-dest"
+       OPT_ETH_DEST_NUM,
+};
+
 #define ACL_DENY_SIGNATURE     0xf0000000
 #define RTE_LOGTYPE_L3FWDACL   RTE_LOGTYPE_USER3
 #define acl_log(format, ...)   RTE_LOG(ERR, L3FWDACL, format, ##__VA_ARGS__)
@@ -441,7 +485,7 @@ static struct {
 static struct{
        const char *rule_ipv4_name;
        const char *rule_ipv6_name;
-       int scalar;
+       enum rte_acl_classify_alg alg;
 } parm_config;
 
 const char cb_port_delim[] = ":";
@@ -1094,13 +1138,58 @@ add_rules(const char *rule_path,
        return 0;
 }
 
+static int
+usage_acl_alg(char *buf, size_t sz)
+{
+       uint32_t i, n, rc, tn;
+
+       n = 0;
+       tn = 0;
+       for (i = 0; i < RTE_DIM(acl_alg); i++) {
+               rc = snprintf(buf + n, sz - n,
+                       i == RTE_DIM(acl_alg) - 1 ? "%s" : "%s|",
+                       acl_alg[i].name);
+               tn += rc;
+               if (rc < sz - n)
+                       n += rc;
+       }
+
+       return tn;
+}
+
+static const char *
+str_acl_alg(enum rte_acl_classify_alg alg)
+{
+       uint32_t i;
+
+       for (i = 0; i != RTE_DIM(acl_alg); i++) {
+               if (alg == acl_alg[i].alg)
+                       return acl_alg[i].name;
+       }
+
+       return "default";
+}
+
+static enum rte_acl_classify_alg
+parse_acl_alg(const char *alg)
+{
+       uint32_t i;
+
+       for (i = 0; i != RTE_DIM(acl_alg); i++) {
+               if (strcmp(alg, acl_alg[i].name) == 0)
+                       return acl_alg[i].alg;
+       }
+
+       return RTE_ACL_CLASSIFY_DEFAULT;
+}
+
 static void
 dump_acl_config(void)
 {
        printf("ACL option are:\n");
-       printf(OPTION_RULE_IPV4": %s\n", parm_config.rule_ipv4_name);
-       printf(OPTION_RULE_IPV6": %s\n", parm_config.rule_ipv6_name);
-       printf(OPTION_SCALAR": %d\n", parm_config.scalar);
+       printf(OPT_RULE_IPV4": %s\n", parm_config.rule_ipv4_name);
+       printf(OPT_RULE_IPV6": %s\n", parm_config.rule_ipv6_name);
+       printf(OPT_ALG": %s\n", str_acl_alg(parm_config.alg));
 }
 
 static int
@@ -1141,8 +1230,8 @@ setup_acl(struct rte_acl_rule *route_base,
        if ((context = rte_acl_create(&acl_param)) == NULL)
                rte_exit(EXIT_FAILURE, "Failed to create ACL context\n");
 
-       if (parm_config.scalar && rte_acl_set_ctx_classify(context,
-                       RTE_ACL_CLASSIFY_SCALAR) != 0)
+       if (parm_config.alg != RTE_ACL_CLASSIFY_DEFAULT &&
+                       rte_acl_set_ctx_classify(context, parm_config.alg) != 0)
                rte_exit(EXIT_FAILURE,
                        "Failed to setup classify method for  ACL context\n");
 
@@ -1285,7 +1374,8 @@ send_single_packet(struct rte_mbuf *m, uint16_t port)
 
        /* update src and dst mac*/
        eh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
-       memcpy(eh, &port_l2hdr[port], sizeof(eh->d_addr) + sizeof(eh->s_addr));
+       memcpy(eh, &port_l2hdr[port],
+                       sizeof(eh->dst_addr) + sizeof(eh->src_addr));
 
        qconf = &lcore_conf[lcore_id];
        rte_eth_tx_buffer(port, qconf->tx_queue_id[port],
@@ -1525,29 +1615,32 @@ init_lcore_rx_queues(void)
 static void
 print_usage(const char *prgname)
 {
+       char alg[PATH_MAX];
+
+       usage_acl_alg(alg, sizeof(alg));
        printf("%s [EAL options] -- -p PORTMASK -P"
-               "--"OPTION_RULE_IPV4"=FILE"
-               "--"OPTION_RULE_IPV6"=FILE"
-               "  [--"OPTION_CONFIG" (port,queue,lcore)[,(port,queue,lcore]]"
-               "  [--"OPTION_ENBJMO" [--max-pkt-len PKTLEN]]\n"
+               "--"OPT_RULE_IPV4"=FILE"
+               "--"OPT_RULE_IPV6"=FILE"
+               "  [--"OPT_CONFIG" (port,queue,lcore)[,(port,queue,lcore]]"
+               "  [--"OPT_ENBJMO" [--max-pkt-len PKTLEN]]\n"
                "  -p PORTMASK: hexadecimal bitmask of ports to configure\n"
                "  -P : enable promiscuous mode\n"
-               "  --"OPTION_CONFIG": (port,queue,lcore): "
+               "  --"OPT_CONFIG": (port,queue,lcore): "
                "rx queues configuration\n"
-               "  --"OPTION_NONUMA": optional, disable numa awareness\n"
-               "  --"OPTION_ENBJMO": enable jumbo frame"
+               "  --"OPT_NONUMA": optional, disable numa awareness\n"
+               "  --"OPT_ENBJMO": enable jumbo frame"
                " which max packet len is PKTLEN in decimal (64-9600)\n"
-               "  --"OPTION_RULE_IPV4"=FILE: specify the ipv4 rules entries "
+               "  --"OPT_RULE_IPV4"=FILE: specify the ipv4 rules entries "
                "file. "
                "Each rule occupy one line. "
                "2 kinds of rules are supported. "
                "One is ACL entry at while line leads with character '%c', "
                "another is route entry at while line leads with "
                "character '%c'.\n"
-               "  --"OPTION_RULE_IPV6"=FILE: specify the ipv6 rules "
+               "  --"OPT_RULE_IPV6"=FILE: specify the ipv6 rules "
                "entries file.\n"
-               "  --"OPTION_SCALAR": Use scalar function to do lookup\n",
-               prgname, ACL_LEAD_CHAR, ROUTE_LEAD_CHAR);
+               "  --"OPT_ALG": ACL classify method to use, one of: %s\n",
+               prgname, ACL_LEAD_CHAR, ROUTE_LEAD_CHAR, alg);
 }
 
 static int
@@ -1650,8 +1743,9 @@ parse_eth_dest(const char *optarg)
                return "port value exceeds RTE_MAX_ETHPORTS("
                        RTE_STR(RTE_MAX_ETHPORTS) ")";
 
-       if (cmdline_parse_etheraddr(NULL, port_end, &port_l2hdr[portid].d_addr,
-                       sizeof(port_l2hdr[portid].d_addr)) < 0)
+       if (cmdline_parse_etheraddr(NULL, port_end,
+                       &port_l2hdr[portid].dst_addr,
+                       sizeof(port_l2hdr[portid].dst_addr)) < 0)
                return "Invalid ethernet address";
        return NULL;
 }
@@ -1665,14 +1759,14 @@ parse_args(int argc, char **argv)
        int option_index;
        char *prgname = argv[0];
        static struct option lgopts[] = {
-               {OPTION_CONFIG, 1, 0, 0},
-               {OPTION_NONUMA, 0, 0, 0},
-               {OPTION_ENBJMO, 0, 0, 0},
-               {OPTION_RULE_IPV4, 1, 0, 0},
-               {OPTION_RULE_IPV6, 1, 0, 0},
-               {OPTION_SCALAR, 0, 0, 0},
-               {OPTION_ETH_DEST, 1, 0, 0},
-               {NULL, 0, 0, 0}
+               {OPT_CONFIG,    1, NULL, OPT_CONFIG_NUM    },
+               {OPT_NONUMA,    0, NULL, OPT_NONUMA_NUM    },
+               {OPT_ENBJMO,    0, NULL, OPT_ENBJMO_NUM    },
+               {OPT_RULE_IPV4, 1, NULL, OPT_RULE_IPV4_NUM },
+               {OPT_RULE_IPV6, 1, NULL, OPT_RULE_IPV6_NUM },
+               {OPT_ALG,       1, NULL, OPT_ALG_NUM       },
+               {OPT_ETH_DEST,  1, NULL, OPT_ETH_DEST_NUM  },
+               {NULL,          0, 0,    0                 }
        };
 
        argvopt = argv;
@@ -1690,96 +1784,94 @@ parse_args(int argc, char **argv)
                                return -1;
                        }
                        break;
+
                case 'P':
                        printf("Promiscuous mode selected\n");
                        promiscuous_on = 1;
                        break;
 
                /* long options */
-               case 0:
-                       if (!strncmp(lgopts[option_index].name,
-                                       OPTION_CONFIG,
-                                       sizeof(OPTION_CONFIG))) {
-                               ret = parse_config(optarg);
-                               if (ret) {
-                                       printf("invalid config\n");
-                                       print_usage(prgname);
-                                       return -1;
-                               }
+               case OPT_CONFIG_NUM:
+                       ret = parse_config(optarg);
+                       if (ret) {
+                               printf("invalid config\n");
+                               print_usage(prgname);
+                               return -1;
                        }
+                       break;
 
-                       if (!strncmp(lgopts[option_index].name,
-                                       OPTION_NONUMA,
-                                       sizeof(OPTION_NONUMA))) {
-                               printf("numa is disabled\n");
-                               numa_on = 0;
-                       }
+               case OPT_NONUMA_NUM:
+                       printf("numa is disabled\n");
+                       numa_on = 0;
+                       break;
 
-                       if (!strncmp(lgopts[option_index].name,
-                                       OPTION_ENBJMO, sizeof(OPTION_ENBJMO))) {
-                               struct option lenopts = {
-                                       "max-pkt-len",
-                                       required_argument,
-                                       0,
-                                       0
-                               };
-
-                               printf("jumbo frame is enabled\n");
-                               port_conf.rxmode.offloads |=
-                                               DEV_RX_OFFLOAD_JUMBO_FRAME;
-                               port_conf.txmode.offloads |=
-                                               DEV_TX_OFFLOAD_MULTI_SEGS;
-
-                               /*
-                                * if no max-pkt-len set, then use the
-                                * default value RTE_ETHER_MAX_LEN
-                                */
-                               if (0 == getopt_long(argc, argvopt, "",
-                                               &lenopts, &option_index)) {
-                                       ret = parse_max_pkt_len(optarg);
-                                       if ((ret < 64) ||
-                                               (ret > MAX_JUMBO_PKT_LEN)) {
-                                               printf("invalid packet "
-                                                       "length\n");
-                                               print_usage(prgname);
-                                               return -1;
-                                       }
-                                       port_conf.rxmode.max_rx_pkt_len = ret;
+               case OPT_ENBJMO_NUM:
+               {
+                       struct option lenopts = {
+                               "max-pkt-len",
+                               required_argument,
+                               0,
+                               0
+                       };
+
+                       printf("jumbo frame is enabled\n");
+                       port_conf.rxmode.offloads |=
+                                       DEV_RX_OFFLOAD_JUMBO_FRAME;
+                       port_conf.txmode.offloads |=
+                                       DEV_TX_OFFLOAD_MULTI_SEGS;
+
+                       /*
+                        * if no max-pkt-len set, then use the
+                        * default value RTE_ETHER_MAX_LEN
+                        */
+                       if (getopt_long(argc, argvopt, "",
+                                       &lenopts, &option_index) == 0) {
+                               ret = parse_max_pkt_len(optarg);
+                               if ((ret < 64) ||
+                                       (ret > MAX_JUMBO_PKT_LEN)) {
+                                       printf("invalid packet "
+                                               "length\n");
+                                       print_usage(prgname);
+                                       return -1;
                                }
-                               printf("set jumbo frame max packet length "
-                                       "to %u\n",
-                                       (unsigned int)
-                                       port_conf.rxmode.max_rx_pkt_len);
+                               port_conf.rxmode.max_rx_pkt_len = ret;
                        }
+                       printf("set jumbo frame max packet length "
+                               "to %u\n",
+                               (unsigned int)
+                               port_conf.rxmode.max_rx_pkt_len);
+                       break;
+               }
+               case OPT_RULE_IPV4_NUM:
+                       parm_config.rule_ipv4_name = optarg;
+                       break;
 
-                       if (!strncmp(lgopts[option_index].name,
-                                       OPTION_RULE_IPV4,
-                                       sizeof(OPTION_RULE_IPV4)))
-                               parm_config.rule_ipv4_name = optarg;
+               case OPT_RULE_IPV6_NUM:
+                       parm_config.rule_ipv6_name = optarg;
+                       break;
 
-                       if (!strncmp(lgopts[option_index].name,
-                                       OPTION_RULE_IPV6,
-                                       sizeof(OPTION_RULE_IPV6))) {
-                               parm_config.rule_ipv6_name = optarg;
+               case OPT_ALG_NUM:
+                       parm_config.alg = parse_acl_alg(optarg);
+                       if (parm_config.alg ==
+                                       RTE_ACL_CLASSIFY_DEFAULT) {
+                               printf("unknown %s value:\"%s\"\n",
+                                       OPT_ALG, optarg);
+                               print_usage(prgname);
+                               return -1;
                        }
+                       break;
 
-                       if (!strncmp(lgopts[option_index].name,
-                                       OPTION_SCALAR, sizeof(OPTION_SCALAR)))
-                               parm_config.scalar = 1;
-
-                       if (!strncmp(lgopts[option_index].name, OPTION_ETH_DEST,
-                                       sizeof(OPTION_ETH_DEST))) {
-                               const char *serr = parse_eth_dest(optarg);
-                               if (serr != NULL) {
-                                       printf("invalid %s value:\"%s\": %s\n",
-                                               OPTION_ETH_DEST, optarg, serr);
-                                       print_usage(prgname);
-                                       return -1;
-                               }
+               case OPT_ETH_DEST_NUM:
+               {
+                       const char *serr = parse_eth_dest(optarg);
+                       if (serr != NULL) {
+                               printf("invalid %s value:\"%s\": %s\n",
+                                       OPT_ETH_DEST, optarg, serr);
+                               print_usage(prgname);
+                               return -1;
                        }
-
                        break;
-
+               }
                default:
                        print_usage(prgname);
                        return -1;
@@ -1911,8 +2003,9 @@ set_default_dest_mac(void)
        uint32_t i;
 
        for (i = 0; i != RTE_DIM(port_l2hdr); i++) {
-               port_l2hdr[i].d_addr.addr_bytes[0] = RTE_ETHER_LOCAL_ADMIN_ADDR;
-               port_l2hdr[i].d_addr.addr_bytes[5] = i;
+               port_l2hdr[i].dst_addr.addr_bytes[0] =
+                               RTE_ETHER_LOCAL_ADMIN_ADDR;
+               port_l2hdr[i].dst_addr.addr_bytes[5] = i;
        }
 }
 
@@ -2018,14 +2111,14 @@ main(int argc, char **argv)
                                "rte_eth_dev_adjust_nb_rx_tx_desc: err=%d, port=%d\n",
                                ret, portid);
 
-               ret = rte_eth_macaddr_get(portid, &port_l2hdr[portid].s_addr);
+               ret = rte_eth_macaddr_get(portid, &port_l2hdr[portid].src_addr);
                if (ret < 0)
                        rte_exit(EXIT_FAILURE,
                                "rte_eth_macaddr_get: err=%d, port=%d\n",
                                ret, portid);
 
-               print_ethaddr("Dst MAC:", &port_l2hdr[portid].d_addr);
-               print_ethaddr(", Src MAC:", &port_l2hdr[portid].s_addr);
+               print_ethaddr("Dst MAC:", &port_l2hdr[portid].dst_addr);
+               print_ethaddr(", Src MAC:", &port_l2hdr[portid].src_addr);
                printf(", ");
 
                /* init memory */
@@ -2161,11 +2254,14 @@ main(int argc, char **argv)
        check_all_ports_link_status(enabled_port_mask);
 
        /* launch per-lcore init on every lcore */
-       rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);
-       RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+       rte_eal_mp_remote_launch(main_loop, NULL, CALL_MAIN);
+       RTE_LCORE_FOREACH_WORKER(lcore_id) {
                if (rte_eal_wait_lcore(lcore_id) < 0)
                        return -1;
        }
 
+       /* clean up the EAL */
+       rte_eal_cleanup();
+
        return 0;
 }