CSIT-209 Add option enable-vhost-user into startup config
[csit.git] / resources / libraries / python / VppConfigGenerator.py
index 9663fdc..f255266 100644 (file)
@@ -58,6 +58,7 @@ dpdk {{
   }}
 {pciconfig}
 {nomultiseg}
+{enablevhostuser}
 }}
 """
 # End VPP configuration template.
@@ -69,33 +70,37 @@ class VppConfigGenerator(object):
     def __init__(self):
         self._nodeconfig = {}
 
-    def add_pci_device(self, node, pci_device=None):
+    def add_pci_all_devices(self, node):
+        """Add all PCI devices from topology file to startup config
+
+        :param node: DUT node
+        :type node: dict
+        :return: nothing
+        """
+        for port in node['interfaces'].keys():
+            pci_addr = Topology.get_interface_pci_addr(node, port)
+            if pci_addr:
+                self.add_pci_device(node, pci_addr)
+
+
+    def add_pci_device(self, node, *pci_devices):
         """Add PCI device configuration for node.
 
         :param node: DUT node.
-        :param pci_device: PCI device (format 0000:00:00.0 or 00:00.0).
-        If none given, all PCI devices for this node as per topology will be
-        added.
+        :param pci_device: PCI devices (format 0000:00:00.0 or 00:00.0)
         :type node: dict
-        :type pci_device: str
+        :type pci_devices: tuple
         :return: nothing
         """
         if node['type'] != NodeType.DUT:
             raise ValueError('Node type is not a DUT')
 
-        if pci_device is None:
-            # No PCI device was given. Add all device from topology.
-            for port in node['interfaces'].values():
-                port_name = port.get('name')
-                pci_addr = Topology.get_interface_pci_addr(node, port_name)
-                if pci_addr:
-                    self.add_pci_device(node, pci_addr)
-        else:
-            # Specific device was given.
-            hostname = Topology.get_node_hostname(node)
-
-            pattern = re.compile("^[0-9A-Fa-f]{4}:[0-9A-Fa-f]{2}:"
-                                 "[0-9A-Fa-f]{2}\\.[0-9A-Fa-f]$")
+        # Specific device was given.
+        hostname = Topology.get_node_hostname(node)
+
+        pattern = re.compile("^[0-9A-Fa-f]{4}:[0-9A-Fa-f]{2}:"
+                             "[0-9A-Fa-f]{2}\\.[0-9A-Fa-f]$")
+        for pci_device in pci_devices:
             if not pattern.match(pci_device):
                 raise ValueError('PCI address {} to be added to host {} '
                                  'is not in valid format xxxx:xx:xx.x'.
@@ -205,6 +210,25 @@ class VppConfigGenerator(object):
         logger.debug('Setting hostname {} config with {}'.\
             format(hostname, "no-multi-seg"))
 
+    def add_enable_vhost_user_config(self, node):
+        """Add enable-vhost-user configuration for node.
+
+        :param node: DUT node.
+        :type node: dict
+        :return: nothing
+        """
+        if node['type'] != NodeType.DUT:
+            raise ValueError('Node type is not a DUT')
+        hostname = Topology.get_node_hostname(node)
+        if not hostname in self._nodeconfig:
+            self._nodeconfig[hostname] = {}
+        if not 'enable_vhost_user' in self._nodeconfig[hostname]:
+            self._nodeconfig[hostname]['enable_vhost_user'] = []
+        self._nodeconfig[hostname]['enable_vhost_user'].append(
+            "enable-vhost-user")
+        logger.debug('Setting hostname {} config with {}'.\
+            format(hostname, "enable-vhost-user"))
+
     def remove_all_pci_devices(self, node):
         """Remove PCI device configuration from node.
 
@@ -295,6 +319,21 @@ class VppConfigGenerator(object):
         logger.debug('Clearing No Multi Seg config for hostname {}.'.\
             format(hostname))
 
+    def remove_enable_vhost_user_config(self, node):
+        """Remove enable-vhost-user configuration from node.
+
+        :param node: DUT node.
+        :type node: dict
+        :return: nothing
+        """
+        if node['type'] != NodeType.DUT:
+            raise ValueError('Node type is not a DUT')
+        hostname = Topology.get_node_hostname(node)
+        if hostname in self._nodeconfig:
+            self._nodeconfig[hostname]['enable_vhost_user'] = []
+        logger.debug('Clearing enable-vhost-user config for hostname {}.'.\
+            format(hostname))
+
     def apply_config(self, node, waittime=5, retries=12):
         """Generate and apply VPP configuration for node.
 
@@ -320,6 +359,7 @@ class VppConfigGenerator(object):
         rxqueuesconfig = ""
         txqueuesconfig = ""
         nomultiseg = ""
+        enablevhostuser = ""
 
         if hostname in self._nodeconfig:
             cfg = self._nodeconfig[hostname]
@@ -342,13 +382,16 @@ class VppConfigGenerator(object):
             if 'no_multi_seg_config' in cfg:
                 nomultiseg = "  " + "\n  ".join(cfg['no_multi_seg_config'])
 
+            if 'enable_vhost_user' in cfg:
+                enablevhostuser = "  " + "\n  ".join(cfg['enable_vhost_user'])
+
         vppconfig = VPP_CONFIG_TEMPLATE.format(cpuconfig=cpuconfig,
                                                pciconfig=pciconfig,
                                                socketmemconfig=socketmemconfig,
-                                               heapsizeconfig=heapsizeconfig,
                                                rxqueuesconfig=rxqueuesconfig,
                                                txqueuesconfig=txqueuesconfig,
-                                               nomultiseg = nomultiseg)
+                                               nomultiseg=nomultiseg,
+                                               enablevhostuser=enablevhostuser)
 
         logger.debug('Writing VPP config to host {}: "{}"'.format(hostname,
                                                                   vppconfig))