# Copyright 2015-2017 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 Open vSwitch base class """ import logging import os import re import time import datetime import random import pexpect from conf import settings from src.ovs import OFBridge, flow_key, flow_match from vswitches.vswitch import IVSwitch from tools import tasks from tools.module_manager import ModuleManager # pylint: disable=too-many-public-methods class IVSwitchOvs(IVSwitch, tasks.Process): """Open vSwitch base class implementation The method docstrings document only considerations specific to this implementation. For generic information of the nature of the methods, see the interface. """ _proc_name = 'ovs-vswitchd' def __init__(self): """See IVswitch for general description """ self._logfile = os.path.join(settings.getValue('LOG_DIR'), settings.getValue('LOG_FILE_VSWITCHD')) self._ovsdb_pidfile_path = os.path.join(settings.getValue('TOOLS')['ovs_var_tmp'], "ovsdb-server.pid") self._vswitchd_pidfile_path = os.path.join(settings.getValue('TOOLS')['ovs_var_tmp'], "{}.pid".format(self._proc_name)) self._logger = logging.getLogger(__name__) # sign '|' must be escaped or avoided, otherwise it is handled as 'or' by regex self._expect = r'bridge.INFO.{}'.format(self._proc_name) self._timeout = 30 self._bridges = {} self._vswitchd_args = ['--pidfile=' + self._vswitchd_pidfile_path, '--overwrite-pidfile', '--log-file=' + self._logfile] self._cmd = [] self._cmd_template = ['sudo', '-E', settings.getValue('TOOLS')['ovs-vswitchd']] self._stamp = None self._module_manager = ModuleManager() def start(self): """ Start ``ovsdb-server`` and ``ovs-vswitchd`` instance. :raises: pexpect.EOF, pexpect.TIMEOUT """ self._logger.info("Starting vswitchd...") # insert kernel modules if required if 'vswitch_modules' in settings.getValue('TOOLS'): self._module_manager.insert_modules(settings.getValue('TOOLS')['vswitch_modules']) self._cmd = self._cmd_template + self._vswitchd_args # DB must be started before vswitchd self._reset_ovsdb() self._start_ovsdb() # DB must be up before vswitchd config is altered or vswitchd started time.sleep(3) self.configure() try: tasks.Process.start(self) self.relinquish() except (pexpect.EOF, pexpect.TIMEOUT) as exc: logging.error("Exception during VSwitch start.") self._kill_ovsdb() raise exc self._logger.info("Vswitchd...Started.") def restart(self): """ Restart ``ovs-vswitchd`` instance. ``ovsdb-server`` is not restarted. :raises: pexpect.EOF, pexpect.TIMEOUT """ self._logger.info("Restarting vswitchd...") if os.path.isfile(self._vswitchd_pidfile_path): self._logger.info('Killing ovs-vswitchd...') with open(self._vswitchd_pidfile_path, "r") as pidfile: vswitchd_pid = pidfile.read().strip() tasks.terminate_task(vswitchd_pid, logger=self._logger) try: tasks.Process.start(self) self.relinquish() except (pexpect.EOF, pexpect.TIMEOUT) as exc: logging.error("Exception during VSwitch start.") self._kill_ovsdb() raise exc self._logger.info("Vswitchd...Started.") def configure(self): """ Configure vswitchd through ovsdb if needed """ pass # Method could be a function # pylint: disable=no-self-use def get_version(self): """See IVswitch for general description """ # OVS version can be read offline return [] def stop(self): """See IVswitch for general description """ self._logger.info("Terminating vswitchd...") self.kill() self._bridges = {} self._logger.info("Vswitchd...Terminated.") def add_switch(self, switch_name, params=None): """See IVswitch for general description """ bridge = OFBridge(switch_name) bridge.create(params) bridge.set_db_attribute('Open_vSwitch', '.', 'other_config:max-idle', settings.getValue('VSWITCH_FLOW_TIMEOUT')) 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): """See IVswitch for general description """ raise NotImplementedError def add_vport(self, switch_name): """See IVswitch for general description """ raise NotImplementedError def add_veth_pair_port(self, switch_name=None, remote_switch_name=N
.. This work is licensed under a Creative Commons Attribution 4.0 International License.
.. http://creativecommons.org/licenses/by/4.0
.. (c) <optionally add copywriters name>
====================
<feature> user guide
====================
.. The feature user guide should provide an OPNFV user with enough information to
.. use the features provided by the feature project in the supported scenarios.
.. This guide should walk a user through the usage of the features once a scenario
.. has been deployed and is active according to the installation guide provided
.. by the installer project.
.. toctree::
:maxdepth: 3
.. The feature.userguide.rst file should contain the text for this document
.. additional documents can be added to this directory and added in the right order
.. to this file as a list below.
./feature.userguide.rst