1 # Copyright 2015-2016 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.ovs import IVSwitchOvs
21 from src.ovs import DPCtl
22 from tools.module_manager import ModuleManager
23 from tools import tasks
25 class OvsVanilla(IVSwitchOvs):
28 This is wrapper for functionality implemented in src.ovs.
30 The method docstrings document only considerations specific to this
31 implementation. For generic information of the nature of the methods,
32 see the interface definition.
39 super(OvsVanilla, self).__init__()
40 self._ports = list(nic['device'] for nic in settings.getValue('NICS'))
41 self._logger = logging.getLogger(__name__)
42 self._vswitchd_args += ["unix:%s" % self.get_db_sock_path()]
43 self._vswitchd_args += settings.getValue('VSWITCHD_VANILLA_ARGS')
44 self._module_manager = ModuleManager()
47 """See IVswitch for general description
49 Activates kernel modules, ovsdb and vswitchd.
51 self._module_manager.insert_modules(
52 settings.getValue('VSWITCH_VANILLA_KERNEL_MODULES'))
53 super(OvsVanilla, self).start()
56 """See IVswitch for general description
58 Kills ovsdb and vswitchd and removes kernel modules.
60 # remove all tap interfaces
61 for i in range(self._vport_id):
63 tap_cmd_list = ['sudo', 'ip', 'tuntap', 'del', tapx, 'mode', 'tap']
64 # let's assume, that all VMs have NIC QUEUES enabled or disabled
66 if int(settings.getValue('GUEST_NIC_QUEUES')[0]):
67 tap_cmd_list += ['multi_queue']
68 tasks.run_task(tap_cmd_list, self._logger, 'Deleting ' + tapx, False)
71 super(OvsVanilla, self).stop()
75 self._module_manager.remove_modules()
77 def add_phy_port(self, switch_name):
79 Method adds port based on detected device names.
81 See IVswitch for general description
83 if self._current_id == len(self._ports):
84 self._logger.error("Can't add port! There are only " +
85 len(self._ports) + " ports " +
89 if not self._ports[self._current_id]:
90 self._logger.error("Can't detect device name for NIC %s", self._current_id)
91 raise ValueError("Invalid device name for %s" % self._current_id)
93 bridge = self._bridges[switch_name]
94 port_name = self._ports[self._current_id]
98 tasks.run_task(['sudo', 'ip', 'addr', 'flush', 'dev', port_name],
99 self._logger, 'Remove IP', False)
100 tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', port_name, 'up'],
101 self._logger, 'Bring up ' + port_name, False)
103 of_port = bridge.add_port(port_name, params)
104 self._current_id += 1
105 return (port_name, of_port)
107 def add_vport(self, switch_name):
109 Method adds virtual port into OVS vanilla
111 See IVswitch for general description
113 # Create tap devices for the VM
114 tap_name = 'tap' + str(self._vport_id)
116 tap_cmd_list = ['sudo', 'ip', 'tuntap', 'del', tap_name, 'mode', 'tap']
117 # let's assume, that all VMs have NIC QUEUES enabled or disabled
119 if int(settings.getValue('GUEST_NIC_QUEUES')[0]):
120 tap_cmd_list += ['multi_queue']
121 tasks.run_task(tap_cmd_list, self._logger,
122 'Creating tap device...', False)
124 tap_cmd_list = ['sudo', 'ip', 'tuntap', 'add', tap_name, 'mode', 'tap']
125 # let's assume, that all VMs have NIC QUEUES enabled or disabled
127 if int(settings.getValue('GUEST_NIC_QUEUES')[0]):
128 tap_cmd_list += ['multi_queue']
129 tasks.run_task(tap_cmd_list, self._logger,
130 'Creating tap device...', False)
132 tasks.run_task(['sudo', 'ip', 'addr', 'flush', 'dev', tap_name],
133 self._logger, 'Remove IP', False)
134 tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', tap_name, 'up'],
135 self._logger, 'Bring up ' + tap_name, False)
137 bridge = self._bridges[switch_name]
138 of_port = bridge.add_port(tap_name, [])
139 return (tap_name, of_port)