diff options
-rw-r--r-- | conf/02_vswitch.conf | 4 | ||||
-rw-r--r-- | docs/NEWS.md | 6 | ||||
-rw-r--r-- | src/dpdk/dpdk.py | 26 | ||||
-rw-r--r-- | src/ovs/daemon.py | 32 | ||||
-rw-r--r-- | tools/module_manager.py | 97 | ||||
-rw-r--r-- | vswitches/ovs_dpdk_vhost.py | 3 | ||||
-rw-r--r-- | vswitches/ovs_vanilla.py | 132 |
7 files changed, 270 insertions, 30 deletions
diff --git a/conf/02_vswitch.conf b/conf/02_vswitch.conf index 8b6a80a0..48bf5964 100644 --- a/conf/02_vswitch.conf +++ b/conf/02_vswitch.conf @@ -38,6 +38,10 @@ BLACKLIST_NICS = ['0000:09:00.0', '0000:09:00.1', '0000:09:00.2', # hardware configuration, like cpu numbering and NUMA. VSWITCHD_DPDK_ARGS = ['-c', '0x4', '-n', '4', '--socket-mem 1024,0'] +VSWITCHD_VANILLA_ARGS = ['--pidfile'] +VSWITCH_VANILLA_PHY_PORT_NAMES = ['', ''] +VSWITCH_VANILLA_KERNEL_MODULES = ['openvswitch'] + # directory where hugepages will be mounted on system init HUGEPAGE_DIR = '/dev/hugepages' diff --git a/docs/NEWS.md b/docs/NEWS.md index 892bfabf..0e322580 100644 --- a/docs/NEWS.md +++ b/docs/NEWS.md @@ -10,6 +10,12 @@ once the community has digested the initial release. ## New * Performance testing with continuous stream +* Vanilla OVS support added. + * Support for non-DPDK OVS build. + * Build and installation support through Makefile will be added via + next patch(Currently it is possible to manually build ovs and + setting it in vsperf configuration files). + * PvP scenario is not yet implemented. * CentOS7 support * Verified on CentOS7 * Install & Quickstart documentation diff --git a/src/dpdk/dpdk.py b/src/dpdk/dpdk.py index 9b3d1385..01e1fb61 100644 --- a/src/dpdk/dpdk.py +++ b/src/dpdk/dpdk.py @@ -27,11 +27,14 @@ import locale from tools import tasks from conf import settings +from tools.module_manager import ModuleManager, KernelModuleInsertMode _LOGGER = logging.getLogger(__name__) RTE_PCI_TOOL = os.path.join( settings.getValue('RTE_SDK'), 'tools', 'dpdk_nic_bind.py') +_DPDK_MODULE_MANAGER = ModuleManager(KernelModuleInsertMode.MODPROBE) + # # system management # @@ -192,16 +195,8 @@ def _is_module_inserted(module): def _insert_modules(): """Ensure required modules are inserted on system. """ - for module in settings.getValue('SYS_MODULES'): - if _is_module_inserted(module): - continue - try: - tasks.run_task(['sudo', 'modprobe', module], _LOGGER, - 'Inserting module \'%s\'...' % module, True) - except subprocess.CalledProcessError: - _LOGGER.error('Unable to insert module \'%s\'.', module) - raise # fail catastrophically + _DPDK_MODULE_MANAGER.insert_modules(settings.getValue('SYS_MODULES')) mod_path_prefix = settings.getValue('OVS_DIR') _insert_module_group('OVS_MODULES', mod_path_prefix) @@ -237,18 +232,7 @@ def _remove_modules(): _remove_module_group('OVS_MODULES') _remove_module_group('DPDK_MODULES') - for module in settings.getValue('SYS_MODULES'): - # first check if module is loaded - if not _is_module_inserted(module): - continue - - try: - tasks.run_task(['sudo', 'rmmod', module], _LOGGER, - 'Removing module \'%s\'...' % module, True) - except subprocess.CalledProcessError: - _LOGGER.error('Unable to remove module \'%s\'.', module) - continue - + _DPDK_MODULE_MANAGER.remove_modules() def _remove_module_group(module_group): """Ensure all modules in a group are removed from the system. diff --git a/src/ovs/daemon.py b/src/ovs/daemon.py index 323644c6..db096353 100644 --- a/src/ovs/daemon.py +++ b/src/ovs/daemon.py @@ -44,12 +44,12 @@ class VSwitchd(tasks.Process): """ _ovsdb_pid = None _logfile = _LOG_FILE_VSWITCHD + _ovsdb_pidfile_path = os.path.join(settings.getValue('LOG_DIR'), + "ovsdb_pidfile.pid") - - _expect = r'EAL: Master l*core \d+ is ready' _proc_name = 'ovs-vswitchd' - def __init__(self, timeout=30, vswitchd_args=None): + def __init__(self, timeout=30, vswitchd_args=None, expected_cmd=None): """Initialise the wrapper with a specific start timeout and extra parameters. @@ -60,8 +60,8 @@ class VSwitchd(tasks.Process): """ self._logger = logging.getLogger(__name__) self._timeout = timeout + self._expect = expected_cmd; vswitchd_args = vswitchd_args or [] - self._cmd = ['sudo', '-E', _OVS_VSWITCHD_BIN] + vswitchd_args # startup/shutdown @@ -72,6 +72,7 @@ class VSwitchd(tasks.Process): :returns: None :raises: pexpect.EOF, pexpect.TIMEOUT """ + self._reset_ovsdb() self._start_ovsdb() # this has to be started first @@ -79,6 +80,7 @@ class VSwitchd(tasks.Process): super(VSwitchd, self).start() self.relinquish() except (pexpect.EOF, pexpect.TIMEOUT) as exc: + logging.error("Exception during VSwitch start.") self._kill_ovsdb() raise exc @@ -125,10 +127,11 @@ class VSwitchd(tasks.Process): self._logger, 'Creating ovsdb configuration database...') - self._ovsdb_pid = tasks.run_background_task( + tasks.run_background_task( ['sudo', _OVSDB_SERVER_BIN, '--remote=punix:%s' % os.path.join(_OVS_VAR_DIR, 'db.sock'), - '--remote=db:Open_vSwitch,Open_vSwitch,manager_options'], + '--remote=db:Open_vSwitch,Open_vSwitch,manager_options', + '--pidfile=' + self._ovsdb_pidfile_path , '--overwrite-pidfile'], self._logger, 'Starting ovsdb-server...') @@ -137,6 +140,19 @@ class VSwitchd(tasks.Process): :returns: None """ - if self._ovsdb_pid: - tasks.run_task(['sudo', 'kill', '-15', str(self._ovsdb_pid)], + with open (self._ovsdb_pidfile_path, "r") as pidfile: + ovsdb_pid = pidfile.read().strip() + + self._logger.info("Killing ovsdb with pid: " + ovsdb_pid) + + if ovsdb_pid: + tasks.run_task(['sudo', 'kill', '-15', str(ovsdb_pid)], self._logger, 'Killing ovsdb-server...') + + @staticmethod + def getDbSockPath(): + """Method returns location of db.sock file + + :returns: path to db.sock file. + """ + return os.path.join(_OVS_VAR_DIR, 'db.sock') diff --git a/tools/module_manager.py b/tools/module_manager.py new file mode 100644 index 00000000..6ed80e93 --- /dev/null +++ b/tools/module_manager.py @@ -0,0 +1,97 @@ +# Copyright 2015 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Simple kernel module manager implementation. +""" + +import subprocess +import logging +from tools import tasks + +class KernelModuleInsertMode(object): + """Module manager type of insert definition. + """ + MODPROBE = 1 + INSMOD = 2 #NOT IMPLEMENTED + +class ModuleManager(object): + """Simple module manager which acts as system wrapper for Kernel Modules. + """ + + _logger = logging.getLogger(__name__) + + def __init__(self, insert_mode=KernelModuleInsertMode.MODPROBE): + """Initializes data and sets insert mode. + + :param insert_mode: insert mode defines how modules are going to + be inserted in system. + """ + self._modules = None + self._insert_mode = insert_mode + + def insert_modules(self, modules): + """Method inserts list of modules using defined insert mode. + + :param modules: list of modules to be inserted. Each element on + list should represent format which is expected + by KernelModuleInsertMode (e.g. for MODPROBE it + would be module name). + + :returns: None + """ + self._modules = modules + for module in modules: + if ModuleManager.is_module_inserted(module): + continue + + try: + if self._insert_mode == KernelModuleInsertMode.MODPROBE: + tasks.run_task(['sudo', 'modprobe', module], self._logger, + 'Inserting module \'%s\'...' % module, True) + else: + self._logger.error( + "Kernel module insert mode NOT IMPLEMENTED.") + raise + + except subprocess.CalledProcessError: + self._logger.error('Unable to insert module \'%s\'.', module) + raise # fail catastrophically + + def remove_modules(self): + """Removes all modules that have been previously instereted. + """ + for module in self._modules: + # first check if module is loaded + if not ModuleManager.is_module_inserted(module): + continue + + try: + tasks.run_task(['sudo', 'rmmod', module], self._logger, + 'Removing module \'%s\'...' % module, True) + except subprocess.CalledProcessError: + self._logger.error('Unable to remove module \'%s\'.', module) + continue + + @staticmethod + def is_module_inserted(module): + """Check if a module is inserted on system. + """ + with open('/proc/modules') as mod_file: + loaded_mods = mod_file.readlines() + + # first check if module is loaded + for line in loaded_mods: + if line.startswith(module): + return True + return False diff --git a/vswitches/ovs_dpdk_vhost.py b/vswitches/ovs_dpdk_vhost.py index d2e8907f..7b5034c5 100644 --- a/vswitches/ovs_dpdk_vhost.py +++ b/vswitches/ovs_dpdk_vhost.py @@ -38,7 +38,8 @@ class OvsDpdkVhost(IVSwitch): vswitchd_args += settings.getValue('VSWITCHD_DPDK_ARGS') vswitchd_args += VSWITCHD_CONST_ARGS - self._vswitchd = VSwitchd(vswitchd_args=vswitchd_args) + self._vswitchd = VSwitchd(vswitchd_args=vswitchd_args, + expected_cmd=r'EAL: Master l*core \d+ is ready') self._bridges = {} def start(self): diff --git a/vswitches/ovs_vanilla.py b/vswitches/ovs_vanilla.py new file mode 100644 index 00000000..a7d4d206 --- /dev/null +++ b/vswitches/ovs_vanilla.py @@ -0,0 +1,132 @@ +# Copyright 2015 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""VSPERF Vanilla OVS implementation +""" + +import logging +from conf import settings +from vswitches.vswitch import IVSwitch +from src.ovs import VSwitchd, OFBridge +from tools.module_manager import ModuleManager, KernelModuleInsertMode + +VSWITCHD_CONST_ARGS = ['--', '--log-file'] + +class OvsVanilla(IVSwitch): + """VSwitch Vanilla implementation + + This is wrapper for functionality implemented in src.ovs. + + The method docstrings document only considerations specific to this + implementation. For generic information of the nature of the methods, + see the interface definition. + """ + + _logger = logging.getLogger() + _ports = settings.getValue('VSWITCH_VANILLA_PHY_PORT_NAMES') + _current_id = 0 + + def __init__(self): + #vswitchd_args = VSWITCHD_CONST_ARGS + vswitchd_args = ["unix:%s" % VSwitchd.getDbSockPath()] + vswitchd_args += settings.getValue('VSWITCHD_VANILLA_ARGS') + self._vswitchd = VSwitchd(vswitchd_args=vswitchd_args, + expected_cmd="db.sock: connected") + self._bridges = {} + self._module_manager = ModuleManager(KernelModuleInsertMode.MODPROBE) + + def start(self): + """See IVswitch for general description + + Activates kernel modules, ovsdb and vswitchd. + """ + self._module_manager.insert_modules( + settings.getValue('VSWITCH_VANILLA_KERNEL_MODULES')) + self._logger.info("Starting Vswitchd...") + self._vswitchd.start() + self._logger.info("Vswitchd...Started.") + + def stop(self): + """See IVswitch for general description + + Kills ovsdb and vswitchd and removes kernel modules. + """ + self._vswitchd.kill() + self._module_manager.remove_modules() + + def add_switch(self, switch_name): + """See IVswitch for general description + """ + bridge = OFBridge(switch_name) + bridge.create() + bridge.set_db_attribute('Open_vSwitch', '.', + 'other_config:max-idle', '60000') + self._bridges[switch_name] = bridge + + def del_switch(self, switch_name): + """See IVswitch for general description + """ + bridge = self._bridges[switch_name] + self._bridges.pop(switch_name) + bridge.destroy() + + def add_phy_port(self, switch_name): + """ + Method adds port based on configured VSWITCH_VANILLA_PHY_PORT_NAMES + stored in config file. + + See IVswitch for general description + """ + if self._current_id == len(self._ports): + self._logger.error("Can't add port! There are only " + + len(self._ports) + " ports " + + "defined in config!") + raise + + bridge = self._bridges[switch_name] + port_name = self._ports[self._current_id] + params = [] + of_port = bridge.add_port(port_name, params) + self._current_id += 1 + return (port_name, of_port) + + def add_vport(self, switch_name): + """See IVswitch for general description""" + raise NotImplementedError("Not implemented for Vanilla OVS.") + + def get_ports(self, switch_name): + """See IVswitch for general description + """ + bridge = self._bridges[switch_name] + ports = list(bridge.get_ports().items()) + return [(name, of_port) for (name, (of_port, _)) in ports] + + def del_port(self, switch_name, port_name): + """See IVswitch for general description + """ + bridge = self._bridges[switch_name] + bridge.del_port(port_name) + + def add_flow(self, switch_name, flow): + """See IVswitch for general description + """ + bridge = self._bridges[switch_name] + bridge.add_flow(flow) + + def del_flow(self, switch_name, flow=None): + """See IVswitch for general description + """ + flow = flow or {} + bridge = self._bridges[switch_name] + bridge.del_flow(flow) |