Added initial VLAN support with vdev devices
[samplevnf.git] / VNFs / DPPD-PROX / prox_args.c
index fd8ea52..9e12eb6 100644 (file)
@@ -1,5 +1,5 @@
 /*
-// Copyright (c) 2010-2017 Intel Corporation
+// Copyright (c) 2010-2020 Intel Corporation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
 #include "defaults.h"
 #include "prox_lua.h"
 #include "cqm.h"
+#include "prox_compat.h"
 
 #define MAX_RTE_ARGV 64
 #define MAX_ARG_LEN  64
@@ -262,7 +263,7 @@ static int get_lua_cfg(__attribute__((unused)) unsigned sindex, __attribute__((u
        struct lua_State *l = prox_lua();
 
        char str_cpy[1024];
-       strncpy(str_cpy, str, sizeof(str_cpy));
+       prox_strncpy(str_cpy, str, sizeof(str_cpy));
        uint32_t len = strlen(str_cpy);
        str_cpy[len++] = '\n';
        str_cpy[len++] = 0;
@@ -337,6 +338,12 @@ static int get_global_cfg(__attribute__((unused))unsigned sindex, char *str, voi
        if (STR_EQ(str, "enable bypass")) {
                return parse_flag(&pset->flags, DSF_ENABLE_BYPASS, pkey);
        }
+       if (STR_EQ(str, "poll timeout")) {
+               return parse_int(&pset->poll_timeout, pkey);
+       }
+       if (STR_EQ(str, "heartbeat timeout")) {
+               return parse_int(&pset->heartbeat_timeout, pkey);
+       }
 
        if (STR_EQ(str, "cpe table map")) {
                /* The config defined ports through 0, 1, 2 ... which
@@ -513,7 +520,7 @@ static int get_port_cfg(unsigned sindex, char *str, void *data)
        }
        else if (STR_EQ(str, "name")) {
                uint32_t val;
-               strncpy(cfg->name, pkey, MAX_NAME_SIZE);
+               prox_strncpy(cfg->name, pkey, MAX_NAME_SIZE);
                PROX_ASSERT(cur_if < PROX_MAX_PORTS);
                return add_port_name(cur_if, pkey);
        }
@@ -530,6 +537,17 @@ static int get_port_cfg(unsigned sindex, char *str, void *data)
                }
                cfg->promiscuous = val;
        }
+       else if (STR_EQ(str, "multicast")) {
+               uint32_t val;
+               if (cfg->nb_mc_addr >= NB_MCAST_ADDR) {
+                       plog_err("too many multicast addresses\n");
+                       return -1;
+               }
+               if (parse_mac(&cfg->mc_addr[cfg->nb_mc_addr], pkey)) {
+                       return -1;
+               }
+               cfg->nb_mc_addr++ ;
+       }
        else if (STR_EQ(str, "lsc")) {
                cfg->lsc_set_explicitely = 1;
                uint32_t val;
@@ -538,13 +556,79 @@ static int get_port_cfg(unsigned sindex, char *str, void *data)
                }
                cfg->lsc_val = val;
        }
+       else if (STR_EQ(str, "local ipv4")) {
+               return parse_ip(&cfg->ip, pkey);
+       }
+       else if (STR_EQ(str, "vdev")) {
+               prox_strncpy(cfg->vdev, pkey, MAX_NAME_SIZE);
+       }
+#if RTE_VERSION >= RTE_VERSION_NUM(18,8,0,1)
+       else if (STR_EQ(str, "disable tx offload")) {
+               uint32_t val;
+               if (parse_int(&val, pkey)) {
+                       return -1;
+               }
+               if (val)
+                       cfg->disabled_tx_offload = val;
+       }
+#endif
        else if (STR_EQ(str, "strip crc")) {
                uint32_t val;
                if (parse_bool(&val, pkey)) {
                        return -1;
                }
-               cfg->port_conf.rxmode.hw_strip_crc = val;
+#if defined(DEV_RX_OFFLOAD_CRC_STRIP)
+               if (val)
+                       cfg->requested_rx_offload |= DEV_RX_OFFLOAD_CRC_STRIP;
+               else
+                       cfg->requested_rx_offload &= ~DEV_RX_OFFLOAD_CRC_STRIP;
+#else
+#if defined (DEV_RX_OFFLOAD_KEEP_CRC)
+               if (val)
+                       cfg->requested_rx_offload &= ~DEV_RX_OFFLOAD_KEEP_CRC;
+               else
+#endif
+                       cfg->requested_rx_offload |= DEV_RX_OFFLOAD_KEEP_CRC;
+#endif
+
+       }
+       else if (STR_EQ(str, "vlan tag")) {
+               return parse_int(&cfg->vlan_tag, pkey);
        }
+       else if (STR_EQ(str, "vlan")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(18,8,0,1)
+               uint32_t val;
+               if (parse_bool(&val, pkey)) {
+                       return -1;
+               }
+               if (val) {
+                       cfg->requested_rx_offload |= DEV_RX_OFFLOAD_VLAN_STRIP;
+                       cfg->requested_tx_offload |= DEV_TX_OFFLOAD_VLAN_INSERT;
+               } else {
+                       cfg->requested_rx_offload &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
+                       cfg->requested_tx_offload &= ~DEV_TX_OFFLOAD_VLAN_INSERT;
+               }
+#else
+               plog_warn("vlan option not supported : update DPDK at least to 18.08 to support this option\n");
+#endif
+       }
+       else if (STR_EQ(str, "mtu size")) {
+               uint32_t val;
+               if (parse_int(&val, pkey)) {
+                       return -1;
+               }
+               if (val) {
+                       cfg->mtu = val;
+                       // A frame of 1526 bytes (1500 bytes mtu, 14 bytes hdr, 4 bytes crc and 8 bytes vlan)
+                       // should not be considered as a jumbo frame. However rte_ethdev.c considers that
+                       // the max_rx_pkt_len for a non jumbo frame is 1518
+                       cfg->port_conf.rxmode.max_rx_pkt_len = cfg->mtu + PROX_RTE_ETHER_HDR_LEN + PROX_RTE_ETHER_CRC_LEN;
+                       if (cfg->port_conf.rxmode.max_rx_pkt_len > PROX_RTE_ETHER_MAX_LEN) {
+                               cfg->requested_rx_offload |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+                       }
+               }
+       }
+
        else if (STR_EQ(str, "rss")) {
                uint32_t val;
                if (parse_bool(&val, pkey)) {
@@ -805,9 +889,6 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
        if (STR_EQ(str, "fast path handle arp")) {
                return parse_flag(&targ->runtime_flags, TASK_FP_HANDLE_ARP, pkey);
        }
-       if (STR_EQ(str, "multiple arp")) {
-               return parse_flag(&targ->flags, TASK_MULTIPLE_MAC, pkey);
-       }
 
        /* Using tx port name, only a _single_ port can be assigned to a task. */
        if (STR_EQ(str, "tx port")) {
@@ -958,7 +1039,8 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                                return -1;
                        }
                        if (targ->pkt_size == sizeof(targ->pkt_inline)) {
-                               set_errf("Inline packet definition can't be longer than 1518");
+                               set_errf("Inline packet definition can't be longer than %u", sizeof(targ->pkt_inline));
+                               return -1;
                        }
 
                        targ->pkt_inline[targ->pkt_size++] = byte;
@@ -1203,7 +1285,6 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
        }
 
        else if (STR_EQ(str, "mbuf size")) {
-               targ->mbuf_size_set_explicitely = 1;
                return parse_int(&targ->mbuf_size, pkey);
        }
        if (STR_EQ(str, "memcache size")) {
@@ -1214,6 +1295,9 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                return parse_int(&targ->byte_offset, pkey);
        }
 
+       if (STR_EQ(str, "realtime scheduling")) {
+               return parse_flag(&lconf->flags, LCONF_FLAG_SCHED_RR, pkey);
+       }
        if (STR_EQ(str, "name")) {
                return parse_str(lconf->name, pkey, sizeof(lconf->name));
        }
@@ -1252,8 +1336,10 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                }
                if (strcmp(sub_mode_str, "l3") == 0) {
                        prox_cfg.flags |= DSF_CTRL_PLANE_ENABLED;
-                       targ->task_init->flag_features |= TASK_FEATURE_L3;
-                       strcpy(targ->task_init->sub_mode_str, "l3");
+                       targ->flags |= TASK_ARG_L3;
+                       strcpy(targ->sub_mode_str, "l3");
+               } else {
+                       strcpy(targ->sub_mode_str, targ->task_init->sub_mode_str);
                }
                return 0;
        }
@@ -1290,7 +1376,7 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                        }
                        else if (STR_EQ(pkey, "packet"))
                                return 0;
-                       else if (STR_EQ(pkey, "packet")) {
+                       else if (STR_EQ(pkey, "hw")) {
                                targ->flags |= TASK_ARG_HW_SRC_MAC;
                                return 0;
                        } else {
@@ -1300,11 +1386,29 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                targ->flags |= TASK_ARG_SRC_MAC_SET;
                return 0;
        }
+       if (STR_EQ(str, "igmp ipv4")) { /* IGMP Group */
+               return parse_ip(&targ->igmp_address, pkey);
+       }
        if (STR_EQ(str, "gateway ipv4")) { /* Gateway IP address used when generating */
+               if ((targ->flags & TASK_ARG_L3) == 0)
+                       plog_warn("gateway ipv4 configured but L3 sub mode not enabled\n");
+               if (targ->local_ipv4)
+                       targ->local_prefix = 32;
                return parse_ip(&targ->gateway_ipv4, pkey);
        }
        if (STR_EQ(str, "local ipv4")) { /* source IP address to be used for packets */
-               return parse_ip(&targ->local_ipv4, pkey);
+               struct ip4_subnet cidr;
+               if (parse_ip4_cidr(&cidr, pkey) != 0) {
+                       if (targ->gateway_ipv4)
+                               targ->local_prefix = 32;
+                       else
+                               targ->local_prefix = 0;
+                       return parse_ip(&targ->local_ipv4, pkey);
+               } else {
+                       targ->local_ipv4 = cidr.ip;
+                       targ->local_prefix = cidr.prefix;
+                       return 0;
+               }
        }
        if (STR_EQ(str, "remote ipv4")) { /* source IP address to be used for packets */
                return parse_ip(&targ->remote_ipv4, pkey);
@@ -1312,6 +1416,10 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
         if (STR_EQ(str, "local ipv6")) { /* source IPv6 address to be used for packets */
                 return parse_ip6(&targ->local_ipv6, pkey);
         }
+       if (STR_EQ(str, "arp timeout"))
+               return parse_int(&targ->arp_timeout, pkey);
+       if (STR_EQ(str, "arp update time"))
+               return parse_int(&targ->arp_update_time, pkey);
        if (STR_EQ(str, "number of packets"))
                return parse_int(&targ->n_pkts, pkey);
        if (STR_EQ(str, "pipes")) {
@@ -1333,30 +1441,60 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                if (err) {
                        return -1;
                }
-
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               targ->qos_conf.subport_params[0].qsize[0] = val;
+               targ->qos_conf.subport_params[0].qsize[1] = val;
+               targ->qos_conf.subport_params[0].qsize[2] = val;
+               targ->qos_conf.subport_params[0].qsize[3] = val;
+#else
                targ->qos_conf.port_params.qsize[0] = val;
                targ->qos_conf.port_params.qsize[1] = val;
                targ->qos_conf.port_params.qsize[2] = val;
                targ->qos_conf.port_params.qsize[3] = val;
+#endif
                return 0;
        }
        if (STR_EQ(str, "subport tb rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.subport_params[0].tb_rate, pkey);
+#else
                return parse_int(&targ->qos_conf.subport_params[0].tb_rate, pkey);
+#endif
        }
        if (STR_EQ(str, "subport tb size")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.subport_params[0].tb_size, pkey);
+#else
                return parse_int(&targ->qos_conf.subport_params[0].tb_size, pkey);
+#endif
        }
        if (STR_EQ(str, "subport tc 0 rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.subport_params[0].tc_rate[0], pkey);
+#else
                return parse_int(&targ->qos_conf.subport_params[0].tc_rate[0], pkey);
+#endif
        }
        if (STR_EQ(str, "subport tc 1 rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.subport_params[0].tc_rate[1], pkey);
+#else
                return parse_int(&targ->qos_conf.subport_params[0].tc_rate[1], pkey);
+#endif
        }
        if (STR_EQ(str, "subport tc 2 rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.subport_params[0].tc_rate[2], pkey);
+#else
                return parse_int(&targ->qos_conf.subport_params[0].tc_rate[2], pkey);
+#endif
        }
        if (STR_EQ(str, "subport tc 3 rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.subport_params[0].tc_rate[3], pkey);
+#else
                return parse_int(&targ->qos_conf.subport_params[0].tc_rate[3], pkey);
+#endif
        }
 
        if (STR_EQ(str, "subport tc rate")) {
@@ -1374,13 +1512,25 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                return 0;
        }
        if (STR_EQ(str, "subport tc period")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.subport_params[0].tc_period, pkey);
+#else
                return parse_int(&targ->qos_conf.subport_params[0].tc_period, pkey);
+#endif
        }
        if (STR_EQ(str, "pipe tb rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.pipe_params[0].tb_rate, pkey);
+#else
                return parse_int(&targ->qos_conf.pipe_params[0].tb_rate, pkey);
+#endif
        }
        if (STR_EQ(str, "pipe tb size")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.pipe_params[0].tb_size, pkey);
+#else
                return parse_int(&targ->qos_conf.pipe_params[0].tb_size, pkey);
+#endif
        }
        if (STR_EQ(str, "pipe tc rate")) {
                uint32_t val;
@@ -1396,19 +1546,39 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                return 0;
        }
        if (STR_EQ(str, "pipe tc 0 rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.pipe_params[0].tc_rate[0], pkey);
+#else
                return parse_int(&targ->qos_conf.pipe_params[0].tc_rate[0], pkey);
+#endif
        }
        if (STR_EQ(str, "pipe tc 1 rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.pipe_params[0].tc_rate[1], pkey);
+#else
                return parse_int(&targ->qos_conf.pipe_params[0].tc_rate[1], pkey);
+#endif
        }
        if (STR_EQ(str, "pipe tc 2 rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.pipe_params[0].tc_rate[2], pkey);
+#else
                return parse_int(&targ->qos_conf.pipe_params[0].tc_rate[2], pkey);
+#endif
        }
        if (STR_EQ(str, "pipe tc 3 rate")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.pipe_params[0].tc_rate[3], pkey);
+#else
                return parse_int(&targ->qos_conf.pipe_params[0].tc_rate[3], pkey);
+#endif
        }
        if (STR_EQ(str, "pipe tc period")) {
+#if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
+               return parse_u64(&targ->qos_conf.pipe_params[0].tc_period, pkey);
+#else
                return parse_int(&targ->qos_conf.pipe_params[0].tc_period, pkey);
+#endif
        }
        if (STR_EQ(str, "police action")) {
                char *in = strstr(pkey, " io=");
@@ -1471,6 +1641,10 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                if (err) {
                        return -1;
                }
+               if (queue_id >= RTE_SCHED_BE_QUEUES_PER_PIPE) {
+                       set_errf("queue_id must be < %d", RTE_SCHED_BE_QUEUES_PER_PIPE);
+                       return -1;
+               }
                targ->qos_conf.pipe_params[0].wrr_weights[queue_id] = val;
                return 0;
        }
@@ -1517,6 +1691,11 @@ static int get_core_cfg(unsigned sindex, char *str, void *data)
                 return 0;
         }
 
+       if (STR_EQ(str, "irq debug")) {
+               parse_int(&targ->irq_debug, pkey);
+               return 0;
+       }
+
        set_errf("Option '%s' is not known", str);
        /* fail on unknown keys */
        return -1;
@@ -1568,14 +1747,14 @@ int prox_parse_args(int argc, char **argv)
                                }
                        }
 
-                       strncpy(prox_cfg.name, cfg_file + offset, MAX_NAME_SIZE);
+                       prox_strncpy(prox_cfg.name, cfg_file + offset, MAX_NAME_SIZE);
                        break;
                case 'v':
                        plog_set_lvl(atoi(optarg));
                        break;
                case 'l':
                        prox_cfg.log_name_pid = 0;
-                       strncpy(prox_cfg.log_name, optarg, MAX_NAME_SIZE);
+                       prox_strncpy(prox_cfg.log_name, optarg, MAX_NAME_SIZE);
                        break;
                case 'p':
                        prox_cfg.log_name_pid = 1;
@@ -1597,7 +1776,7 @@ int prox_parse_args(int argc, char **argv)
                case 'r':
                        if (!str_is_number(optarg) || strlen(optarg) > 11)
                                return -1;
-                       strncpy(prox_cfg.update_interval_str, optarg, sizeof(prox_cfg.update_interval_str));
+                       prox_strncpy(prox_cfg.update_interval_str, optarg, sizeof(prox_cfg.update_interval_str));
                        break;
                case 'o':
                        if (prox_cfg.flags & DSF_DAEMON)
@@ -1662,7 +1841,7 @@ int prox_parse_args(int argc, char **argv)
                            (tmp2 = strchr(tmp, '='))) {
                                *tmp2 = 0;
                                tmp3[0] = '$';
-                               strncpy(tmp3 + 1, tmp, 63);
+                               prox_strncpy(tmp3 + 1, tmp, 63);
                                plog_info("\tAdding variable: %s = %s\n", tmp3, tmp2 + 1);
                                ret = add_var(tmp3, tmp2 + 1, 1);
                                if (ret == -2) {
@@ -1953,7 +2132,7 @@ int prox_setup_rte(const char *prog_name)
        }
 
        if (rte_cfg.no_output) {
-               rte_set_log_level(0);
+               rte_log_set_global_level(0);
        }
        /* init EAL */
        plog_info("\tEAL command line:");