# 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__) 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 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._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=None, local_opts=None, remote_opts=None): """Creates veth-pair port between 'switch_name' and 'remote_switch_name' """ if switch_name is None or remote_switch_name is None: return bridge = self._bridges[switch_name] remote_bridge = self._bridges[remote_switch_name] pcount = str(self._get_port_count('type=patch')) # NOTE ::: What if interface name longer than allowed width?? local_port_name = switch_name + '-' + remote_switch_name + '-' + pcount remote_port_name = remote_switch_name + '-' + switch_name + '-' + pcount local_params = ['--', 'set', 'Interface', local_port_name, 'type=patch', 'options:peer=' + remote_port_name] remote_params = ['--', 'set', 'Interface', remote_port_name, 'type=patch', 'options:peer=' + local_port_name] if local_opts is not None: local_params = local_params + local_opts if remote_opts is not None: remote_params = remote_params + remote_opts local_of_port = bridge.add_port(local_port_name, local_params) remote_of_port = remote_bridge.add_port(remote_port_name, remote_params) return [(local_port_name, local_of_port), (remote_port_name, remote_of_port)] def add_tunnel_port(self, switch_name, remote_ip, tunnel_type='vxlan', params=None): """Creates tunneling port """ bridge = self._bridges[switch_name] pcount = str(self._get_port_count('type=' + tunnel_type)) port_name = tunnel_type + pcount local_params = ['--', 'set', 'Interface', port_name, 'type=' + tunnel_type, 'options:remote_ip=' + remote_ip] if params is not None: local_params = local_params + params of_port = bridge.add_port(port_name, local_params) return (port_name, of_port) 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, cache='off'): """See IVswitch for general description """ bridge = self._bridges[switch_name] bridge.add_flow(flow, cache=cache) def del_flow
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build ignore

package main

// Class is the Unicode BiDi class. Each rune has a single class.
type Class uint

const (
	L       Class = iota // LeftToRight
	R                    // RightToLeft
	EN                   // EuropeanNumber
	ES                   // EuropeanSeparator
	ET                   // EuropeanTerminator
	AN                   // ArabicNumber
	CS                   // CommonSeparator
	B                    // ParagraphSeparator
	S                    // SegmentSeparator
	WS                   // WhiteSpace
	ON                   // OtherNeutral
	BN                   // BoundaryNeutral
	NSM                  // NonspacingMark
	AL                   // ArabicLetter
	Control              // Control LRO - PDI

	numClass

	LRO // LeftToRightOverride
	RLO // RightToLeftOverride
	LRE // LeftToRightEmbedding
	RLE // Ri