- :param node: DUT node.
- :param pci_device: PCI devices (format 0000:00:00.0 or 00:00.0)
- :type node: dict
- :type pci_devices: tuple
- :return: nothing
- """
- if node['type'] != NodeType.DUT:
- raise ValueError('Node type is not a DUT')
-
- # 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'.
- format(pci_device, hostname))
-
- if hostname not in self._nodeconfig:
- self._nodeconfig[hostname] = {}
- if 'pci_addrs' not in self._nodeconfig[hostname]:
- self._nodeconfig[hostname]['pci_addrs'] = []
- self._nodeconfig[hostname]['pci_addrs'].append(pci_device)
- logger.debug('Adding PCI device {1} to {0}'.format(hostname,
- pci_device))
-
- def add_cpu_config(self, node, cpu_config):
- """Add CPU configuration for node.
-
- :param node: DUT node.
- :param cpu_config: CPU configuration option, as a string.
- :type node: dict
- :type cpu_config: str
- :return: nothing
- """
- if node['type'] != NodeType.DUT:
- raise ValueError('Node type is not a DUT')
- hostname = Topology.get_node_hostname(node)
- if hostname not in self._nodeconfig:
- self._nodeconfig[hostname] = {}
- if 'cpu_config' not in self._nodeconfig[hostname]:
- self._nodeconfig[hostname]['cpu_config'] = []
- self._nodeconfig[hostname]['cpu_config'].append(cpu_config)
- logger.debug('Adding {} to hostname {} CPU config'.format(hostname,
- cpu_config))
-
- def add_socketmem_config(self, node, socketmem_config):
- """Add Socket Memory configuration for node.
-
- :param node: DUT node.
- :param socketmem_config: Socket Memory configuration option,
- as a string.
- :type node: dict
- :type socketmem_config: str
- :return: nothing
- """
- if node['type'] != NodeType.DUT:
- raise ValueError('Node type is not a DUT')
- hostname = Topology.get_node_hostname(node)
- if hostname not in self._nodeconfig:
- self._nodeconfig[hostname] = {}
- self._nodeconfig[hostname]['socketmem_config'] = socketmem_config
- logger.debug('Setting hostname {} Socket Memory config to {}'.
- format(hostname, socketmem_config))
-
- def add_heapsize_config(self, node, heapsize_config):
- """Add Heap Size configuration for node.
-
- :param node: DUT node.
- :param heapsize_config: Heap Size configuration, as a string.
- :type node: dict
- :type heapsize_config: str
- :return: nothing
- """
- if node['type'] != NodeType.DUT:
- raise ValueError('Node type is not a DUT')
- hostname = Topology.get_node_hostname(node)
- if hostname not in self._nodeconfig:
- self._nodeconfig[hostname] = {}
- self._nodeconfig[hostname]['heapsize_config'] = heapsize_config
- logger.debug('Setting hostname {} Heap Size config to {}'.
- format(hostname, heapsize_config))
-
- def add_rxqueues_config(self, node, rxqueues_config):
- """Add Rx Queues configuration for node.
-
- :param node: DUT node.
- :param rxqueues_config: Rxqueues configuration, as a string.
- :type node: dict
- :type rxqueues_config: str
- :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 'rxqueues_config' in self._nodeconfig[hostname]:
- self._nodeconfig[hostname]['rxqueues_config'] = []
- self._nodeconfig[hostname]['rxqueues_config'].append(rxqueues_config)
- logger.debug('Setting hostname {} rxqueues config to {}'.\
- format(hostname, rxqueues_config))
-
- def add_no_multi_seg_config(self, node):
- """Add No Multi Seg 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 'no_multi_seg_config' in self._nodeconfig[hostname]:
- self._nodeconfig[hostname]['no_multi_seg_config'] = []
- self._nodeconfig[hostname]['no_multi_seg_config'].append(
- "no-multi-seg")
- 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 add_cryptodev_config(self, node, count):
- """Add cryptodev configuration for node.
-
- :param node: DUT node.
- :param count: Number of crypto device to add.
- :type node: dict
- :type count: int
+ def get_config_str(self):
+ """Get dumped startup configuration in VPP config format.
+
+ :returns: Startup configuration in VPP config format.
+ :rtype: str
+ """
+ self.dump_config(self._nodeconfig)
+ return self._vpp_config
+
+ def add_config_item(self, config, value, path):
+ """Add startup configuration item.
+
+ :param config: Startup configuration of node.
+ :param value: Value to insert.
+ :param path: Path where to insert item.
+ :type config: dict
+ :type value: str
+ :type path: list
+ """
+ if len(path) == 1:
+ config[path[0]] = value
+ return
+ if path[0] not in config:
+ config[path[0]] = dict()
+ elif isinstance(config[path[0]], str):
+ config[path[0]] = dict() if config[path[0]] == u"" \
+ else {config[path[0]]: u""}
+ self.add_config_item(config[path[0]], value, path[1:])
+
+ def dump_config(self, obj, level=-1):
+ """Dump the startup configuration in VPP config format.
+
+ :param obj: Python Object to print.
+ :param level: Nested level for indentation.
+ :type obj: Obj
+ :type level: int