Report failure when tap port is not mapped to real dpdk port. 66/71166/3
authorXavier Simonart <xavier.simonart@intel.com>
Tue, 22 Sep 2020 10:42:06 +0000 (12:42 +0200)
committerXavier Simonart <xavier.simonart@intel.com>
Fri, 16 Oct 2020 12:32:53 +0000 (14:32 +0200)
When using "vdev=" in port section, a tap device and an additional dpdk
port are created. In most cases, we still want to use a real DPDK device
(i.e. bound to an interface such as virtio or a PF or a VF).
PROX will now report by default an error when the used [port] is not a
DPDK bound device.
An additional parameter "virtual=yes" can be added in the port section
in case one want to disable this error checking (e.g. specify additional
parameter for the vdev device).
This patch also fixes a potential endianess issue when configuring IP
addresses.

Change-Id: Iffdd9552308be3b77cfe2067630647acac2c01fe
Signed-off-by: Xavier Simonart <xavier.simonart@intel.com>
VNFs/DPPD-PROX/handle_master.c
VNFs/DPPD-PROX/prox_args.c
VNFs/DPPD-PROX/prox_port_cfg.c
VNFs/DPPD-PROX/prox_port_cfg.h

index b55db77..ddaab52 100644 (file)
@@ -169,7 +169,7 @@ void master_init_vdev(struct task_base *tbase, uint8_t port_id, uint8_t core_id,
                src.sin_family = AF_INET;
                src.sin_port = rte_cpu_to_be_16(PROX_PSEUDO_PKT_PORT);
                for (int vlan_id = 0; vlan_id < prox_port_cfg[vdev_port].n_vlans; vlan_id++) {
-                       src.sin_addr.s_addr = prox_port_cfg[vdev_port].ip_addr[vlan_id].ip;
+                       src.sin_addr.s_addr = rte_be_to_cpu_32(prox_port_cfg[vdev_port].ip_addr[vlan_id].ip);
                        int fd = socket(AF_INET,  SOCK_DGRAM, 0);
                        PROX_PANIC(fd < 0, "Failed to open socket(AF_INET,  SOCK_DGRAM, 0)\n");
                        prox_port_cfg[vdev_port].fds[vlan_id] = fd;
index d6c1639..aa87100 100644 (file)
@@ -582,6 +582,13 @@ static int get_port_cfg(unsigned sindex, char *str, void *data)
                }
                return 0;
        }
+       else if (STR_EQ(str, "virtual")) {
+               uint32_t val;
+               if (parse_bool(&val, pkey)) {
+                       return -1;
+               }
+               cfg->virtual = val;
+       }
        else if (STR_EQ(str, "vdev")) {
                prox_strncpy(cfg->vdev, pkey, MAX_NAME_SIZE);
        }
index 859c437..60809f1 100644 (file)
@@ -173,13 +173,14 @@ static inline uint32_t get_netmask(uint8_t prefix)
                return rte_cpu_to_be_32(~((1 << (32 - prefix)) - 1));
 }
 
-static void set_ip_address(char *devname, uint32_t *ip, uint8_t prefix)
+static void set_ip_address(char *devname, uint32_t ip, uint8_t prefix)
 {
        struct ifreq ifreq;
        struct sockaddr_in in_addr;
        int fd, rc;
        uint32_t netmask = get_netmask(prefix);
        plog_info("Setting netmask to %x\n", netmask);
+       uint32_t ip_cpu = rte_be_to_cpu_32(ip);
 
        fd = socket(AF_INET, SOCK_DGRAM, 0);
 
@@ -187,12 +188,12 @@ static void set_ip_address(char *devname, uint32_t *ip, uint8_t prefix)
        memset(&in_addr, 0, sizeof(struct sockaddr_in));
 
        in_addr.sin_family = AF_INET;
-       in_addr.sin_addr = *(struct in_addr *)ip;
+       in_addr.sin_addr = *(struct in_addr *)&ip_cpu;
 
        strncpy(ifreq.ifr_name, devname, IFNAMSIZ);
        ifreq.ifr_addr = *(struct sockaddr *)&in_addr;
        rc = ioctl(fd, SIOCSIFADDR, &ifreq);
-       PROX_PANIC(rc < 0, "Failed to set IP address %x on device %s: error = %d (%s)\n", *ip, devname, errno, strerror(errno));
+       PROX_PANIC(rc < 0, "Failed to set IP address %x on device %s: error = %d (%s)\n", ip_cpu, devname, errno, strerror(errno));
 
        in_addr.sin_addr = *(struct in_addr *)&netmask;
        ifreq.ifr_netmask = *(struct sockaddr *)&in_addr;
@@ -209,6 +210,11 @@ void init_rte_dev(int use_dummy_devices)
        struct rte_eth_dev_info dev_info;
        const struct rte_pci_device *pci_dev;
 
+       for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
+               if (prox_port_cfg[port_id].active && (prox_port_cfg[port_id].virtual == 0) && (port_id >= prox_rte_eth_dev_count_avail())) {
+                       PROX_PANIC(1, "port %u used but only %u available\n", port_id, prox_rte_eth_dev_count_avail());
+               }
+       }
        for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
                if (!prox_port_cfg[port_id].active) {
                        continue;
@@ -257,7 +263,7 @@ void init_rte_dev(int use_dummy_devices)
                        prox_port_cfg[port_id].dpdk_mapping = vdev_port_id;
                        uint32_t i = 0;
                        while ((i < PROX_MAX_VLAN_TAGS) && (prox_port_cfg[port_id].ip_addr[i].ip)) {
-                               prox_port_cfg[vdev_port_id].ip_addr[i].ip = rte_be_to_cpu_32(prox_port_cfg[port_id].ip_addr[i].ip);
+                               prox_port_cfg[vdev_port_id].ip_addr[i].ip = prox_port_cfg[port_id].ip_addr[i].ip;
                                prox_port_cfg[vdev_port_id].ip_addr[i].prefix = prox_port_cfg[port_id].ip_addr[i].prefix;
                                i++;
                        }
@@ -824,7 +830,7 @@ static void init_port(struct prox_port_cfg *port_cfg)
 
        if (prox_port_cfg[port_id].is_vdev) {
                for (int vlan_id = 0; vlan_id < prox_port_cfg[port_id].n_vlans; vlan_id++) {
-                       set_ip_address(prox_port_cfg[port_id].names[vlan_id], &prox_port_cfg[port_id].ip_addr[vlan_id].ip, prox_port_cfg[port_id].ip_addr[vlan_id].prefix);
+                       set_ip_address(prox_port_cfg[port_id].names[vlan_id], prox_port_cfg[port_id].ip_addr[vlan_id].ip, prox_port_cfg[port_id].ip_addr[vlan_id].prefix);
                }
        }
        /* Getting link status can be done without waiting if Link
index 738ce86..5035920 100644 (file)
@@ -88,6 +88,7 @@ struct prox_port_cfg {
        int fds[PROX_MAX_VLAN_TAGS];
        uint32_t vlan_tags[PROX_MAX_VLAN_TAGS];
        uint8_t is_vdev;
+       uint8_t virtual;
        uint8_t all_rx_queues;
        uint16_t n_vlans;
 };