1 # Copyright 2015 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 """VSPERF Vanilla OVS implementation
19 from conf import settings
20 from vswitches.vswitch import IVSwitch
21 from src.ovs import VSwitchd, OFBridge
22 from tools.module_manager import ModuleManager, KernelModuleInsertMode
24 VSWITCHD_CONST_ARGS = ['--', '--log-file']
26 class OvsVanilla(IVSwitch):
27 """VSwitch Vanilla implementation
29 This is wrapper for functionality implemented in src.ovs.
31 The method docstrings document only considerations specific to this
32 implementation. For generic information of the nature of the methods,
33 see the interface definition.
36 _logger = logging.getLogger()
37 _ports = settings.getValue('VSWITCH_VANILLA_PHY_PORT_NAMES')
41 #vswitchd_args = VSWITCHD_CONST_ARGS
42 vswitchd_args = ["unix:%s" % VSwitchd.getDbSockPath()]
43 vswitchd_args += settings.getValue('VSWITCHD_VANILLA_ARGS')
44 self._vswitchd = VSwitchd(vswitchd_args=vswitchd_args,
45 expected_cmd="db.sock: connected")
47 self._module_manager = ModuleManager(KernelModuleInsertMode.MODPROBE)
50 """See IVswitch for general description
52 Activates kernel modules, ovsdb and vswitchd.
54 self._module_manager.insert_modules(
55 settings.getValue('VSWITCH_VANILLA_KERNEL_MODULES'))
56 self._logger.info("Starting Vswitchd...")
57 self._vswitchd.start()
58 self._logger.info("Vswitchd...Started.")
61 """See IVswitch for general description
63 Kills ovsdb and vswitchd and removes kernel modules.
66 self._module_manager.remove_modules()
68 def add_switch(self, switch_name):
69 """See IVswitch for general description
71 bridge = OFBridge(switch_name)
73 bridge.set_db_attribute('Open_vSwitch', '.',
74 'other_config:max-idle', '60000')
75 self._bridges[switch_name] = bridge
77 def del_switch(self, switch_name):
78 """See IVswitch for general description
80 bridge = self._bridges[switch_name]
81 self._bridges.pop(switch_name)
84 def add_phy_port(self, switch_name):
86 Method adds port based on configured VSWITCH_VANILLA_PHY_PORT_NAMES
87 stored in config file.
89 See IVswitch for general description
91 if self._current_id == len(self._ports):
92 self._logger.error("Can't add port! There are only " +
93 len(self._ports) + " ports " +
97 bridge = self._bridges[switch_name]
98 port_name = self._ports[self._current_id]
100 of_port = bridge.add_port(port_name, params)
101 self._current_id += 1
102 return (port_name, of_port)
104 def add_vport(self, switch_name):
105 """See IVswitch for general description"""
106 raise NotImplementedError("Not implemented for Vanilla OVS.")
108 def get_ports(self, switch_name):
109 """See IVswitch for general description
111 bridge = self._bridges[switch_name]
112 ports = list(bridge.get_ports().items())
113 return [(name, of_port) for (name, (of_port, _)) in ports]
115 def del_port(self, switch_name, port_name):
116 """See IVswitch for general description
118 bridge = self._bridges[switch_name]
119 bridge.del_port(port_name)
121 def add_flow(self, switch_name, flow):
122 """See IVswitch for general description
124 bridge = self._bridges[switch_name]
125 bridge.add_flow(flow)
127 def del_flow(self, switch_name, flow=None):
128 """See IVswitch for general description
131 bridge = self._bridges[switch_name]
132 bridge.del_flow(flow)