+ 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]] = {}
+ 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
+ :returns: nothing
+ """
+ indent = ' '
+ if level >= 0:
+ self._vpp_config += '{}{{\n'.format((level) * indent)
+ if isinstance(obj, dict):
+ for key, val in obj.items():
+ if hasattr(val, '__iter__'):
+ self._vpp_config += '{}{}\n'.format((level + 1) * indent,
+ key)
+ self.dump_config(val, level + 1)
+ else:
+ self._vpp_config += '{}{} {}\n'.format((level + 1) * indent,
+ key, val)
+ else:
+ for val in obj:
+ self._vpp_config += '{}{}\n'.format((level + 1) * indent, val)
+ if level >= 0:
+ self._vpp_config += '{}}}\n'.format(level * indent)
+
+ def add_unix_log(self, value=None):
+ """Add UNIX log configuration.
+
+ :param value: Log file.
+ :type value: str
+ """
+ path = ['unix', 'log']
+ if value is None:
+ value = self._vpp_logfile
+ self.add_config_item(self._nodeconfig, value, path)
+
+ def add_unix_cli_listen(self, value='localhost:5002'):
+ """Add UNIX cli-listen configuration.
+
+ :param value: CLI listen address and port or path to CLI socket.
+ :type value: str
+ """
+ path = ['unix', 'cli-listen']
+ self.add_config_item(self._nodeconfig, value, path)
+
+ def add_unix_gid(self, value='vpp'):
+ """Add UNIX gid configuration.
+
+ :param value: Gid.
+ :type value: str
+ """
+ path = ['unix', 'gid']
+ self.add_config_item(self._nodeconfig, value, path)
+
+ def add_unix_nodaemon(self):
+ """Add UNIX nodaemon configuration."""
+ path = ['unix', 'nodaemon']
+ self.add_config_item(self._nodeconfig, '', path)