Vanilla OVS support implementation 12/1112/3
authorMichal Weglicki <michalx.weglicki@intel.com>
Fri, 24 Jul 2015 09:42:38 +0000 (10:42 +0100)
committerMaryam Tahhan <maryam.tahhan@intel.com>
Thu, 6 Aug 2015 09:40:55 +0000 (09:40 +0000)
JIRA: VSPERF-57

This patch implements Vanilla OVS support.It contains:
* New IVswitch implementation: OvsVanilla,
* New configuration contants,
* New mandatory configuration variable: VSWITCH_VANILLA_PHY_PORT_NAMES
for Vanilla OVS has been added,
* Virtual ports are not yet implemented,
* Some kernel modules wrapping methods has been moved from dpdk.py to
tools.
* Fixed bug where ovsdb hasn't been killed at the end of test case run on
some platforms.

Change-Id: I21a0d84dbc4004aae564d5547387a2563f2d1e5b
Signed-off-by: Michal Weglicki <michalx.weglicki@intel.com>
Reviewed-by: Eugene Snider <Eugene.Snider@huawei.com>
Reviewed-by: Gurpreet Singh <gurpreet.singh@spirent.com>
Reviewed-by: Tv Rao <tv.rao@freescale.com>
Reviewed-by: Martin Klozik <martinx.klozik@intel.com>
Reviewed-by: Billy O Mahony <billy.o.mahony@intel.com>
Reviewed-by: Maryam Tahhan <maryam.tahhan@intel.com>
conf/02_vswitch.conf
docs/NEWS.md
src/dpdk/dpdk.py
src/ovs/daemon.py
tools/module_manager.py [new file with mode: 0644]
vswitches/ovs_dpdk_vhost.py
vswitches/ovs_vanilla.py [new file with mode: 0644]

index 8b6a80a..48bf596 100644 (file)
@@ -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'
 
index 892bfab..0e32258 100644 (file)
@@ -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
index 9b3d138..01e1fb6 100644 (file)
@@ -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.
index 323644c..db09635 100644 (file)
@@ -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 (file)
index 0000000..6ed80e9
--- /dev/null
@@ -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
index d2e8907..7b5034c 100644 (file)
@@ -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 (file)
index 0000000..a7d4d20
--- /dev/null
@@ -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)