1 # Copyright 2015-2017 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
20 from conf import settings
21 from vswitches.ovs import IVSwitchOvs
22 from src.ovs import DPCtl
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')
46 """See IVswitch for general description
48 Kills ovsdb and vswitchd and removes kernel modules.
50 # remove all tap interfaces
51 for i in range(self._vport_id):
53 tap_cmd_list = ['sudo', 'ip', 'tuntap', 'del', tapx, 'mode', 'tap']
54 # let's assume, that all VMs have NIC QUEUES enabled or disabled
56 if int(settings.getValue('GUEST_NIC_QUEUES')[0]):
57 tap_cmd_list += ['multi_queue']
58 tasks.run_task(tap_cmd_list, self._logger, 'Deleting ' + tapx, False)
61 # remove datapath before vswitch shutdown
65 super(OvsVanilla, self).stop()
67 # give vswitch time to terminate before modules are removed
69 self._module_manager.remove_modules()
71 def add_phy_port(self, switch_name):
73 Method adds port based on detected device names.
75 See IVswitch for general description
77 if self._current_id == len(self._ports):
78 self._logger.error("Can't add port! There are only " +
79 len(self._ports) + " ports " +
81 raise RuntimeError('Failed to add phy port')
82 if not self._ports[self._current_id]:
83 self._logger.error("Can't detect device name for NIC %s", self._current_id)
84 raise ValueError("Invalid device name for %s" % self._current_id)
86 bridge = self._bridges[switch_name]
87 port_name = self._ports[self._current_id]
91 tasks.run_task(['sudo', 'ip', 'addr', 'flush', 'dev', port_name],
92 self._logger, 'Remove IP', False)
93 tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', port_name, 'up'],
94 self._logger, 'Bring up ' + port_name, False)
96 of_port = bridge.add_port(port_name, params)
98 return (port_name, of_port)
100 def add_vport(self, switch_name):
102 Method adds virtual port into OVS vanilla
104 See IVswitch for general description
106 # Create tap devices for the VM
107 tap_name = 'tap' + str(self._vport_id)
109 tap_cmd_list = ['sudo', 'ip', 'tuntap', 'del', tap_name, 'mode', 'tap']
110 # let's assume, that all VMs have NIC QUEUES enabled or disabled
112 if int(settings.getValue('GUEST_NIC_QUEUES')[0]):
113 tap_cmd_list += ['multi_queue']
114 tasks.run_task(tap_cmd_list, self._logger,
115 'Creating tap device...', False)
117 tap_cmd_list = ['sudo', 'ip', 'tuntap', 'add', tap_name, 'mode', 'tap']
118 # let's assume, that all VMs have NIC QUEUES enabled or disabled
120 if int(settings.getValue('GUEST_NIC_QUEUES')[0]):
121 tap_cmd_list += ['multi_queue']
122 tasks.run_task(tap_cmd_list, self._logger,
123 'Creating tap device...', False)
124 if settings.getValue('VSWITCH_JUMBO_FRAMES_ENABLED'):
125 tasks.run_task(['ifconfig', tap_name, 'mtu',
126 str(settings.getValue('VSWITCH_JUMBO_FRAMES_SIZE'))],
127 self._logger, 'Setting mtu size', False)
129 tasks.run_task(['sudo', 'ip', 'addr', 'flush', 'dev', tap_name],
130 self._logger, 'Remove IP', False)
131 tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', tap_name, 'up'],
132 self._logger, 'Bring up ' + tap_name, False)
134 bridge = self._bridges[switch_name]
135 of_port = bridge.add_port(tap_name, [])
136 return (tap_name, of_port)
138 def add_connection(self, switch_name, port1, port2, bidir=False):
139 """See IVswitch for general description
141 raise NotImplementedError()
143 def del_connection(self, switch_name, port1, port2, bidir=False):
144 """See IVswitch for general description
146 raise NotImplementedError()
148 def dump_connections(self, switch_name):
149 """See IVswitch for general description
151 raise NotImplementedError()