Added initial VLAN support with vdev devices
[samplevnf.git] / VNFs / DPPD-PROX / prox_args.c
index d77eab1..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.
@@ -263,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;
@@ -338,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
@@ -514,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);
        }
@@ -531,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;
@@ -539,6 +556,12 @@ 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;
@@ -554,10 +577,23 @@ static int get_port_cfg(unsigned sindex, char *str, void *data)
                if (parse_bool(&val, pkey)) {
                        return -1;
                }
+#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)
@@ -586,8 +622,8 @@ static int get_port_cfg(unsigned sindex, char *str, void *data)
                        // 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 + ETHER_HDR_LEN + ETHER_CRC_LEN;
-                       if (cfg->port_conf.rxmode.max_rx_pkt_len > ETHER_MAX_LEN) {
+                       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;
                        }
                }
@@ -853,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")) {
@@ -1262,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));
        }
@@ -1350,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);
@@ -1387,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")) {
@@ -1428,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;
@@ -1450,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=");
@@ -1525,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;
        }
@@ -1627,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;
@@ -1656,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)
@@ -1721,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) {