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 VSwitch implementation using DPDK and vhost ports
19 from conf import settings
20 from vswitches.ovs import IVSwitchOvs
21 from src.ovs import VSwitchd
22 from src.dpdk import dpdk
24 class OvsDpdkVhost(IVSwitchOvs):
25 """ Open vSwitch with DPDK support
27 Generic OVS wrapper functionality in src.ovs is maximally used. This
28 class wraps DPDK system configuration along with DPDK specific OVS
31 The method docstrings document only considerations specific to this
32 implementation. For generic information of the nature of the methods,
37 super(OvsDpdkVhost, self).__init__()
38 self._logger = logging.getLogger(__name__)
40 self._vswitchd_args = ['--dpdk']
41 self._vswitchd_args += settings.getValue('VSWITCHD_DPDK_ARGS')
42 if settings.getValue('VNF').endswith('Cuse'):
43 self._logger.info("Inserting VHOST Cuse modules into kernel...")
44 dpdk.insert_vhost_modules()
46 self._vswitchd = VSwitchd(vswitchd_args=self._vswitchd_args,
48 r'EAL: Master l*core \d+ is ready')
51 """See IVswitch for general description
53 Activates DPDK kernel modules, ovsdb and vswitchd.
56 super(OvsDpdkVhost, self).start()
59 """See IVswitch for general description
61 Kills ovsdb and vswitchd and removes DPDK kernel modules.
63 super(OvsDpdkVhost, self).stop()
65 dpdk.remove_vhost_modules()
67 def add_switch(self, switch_name, params=None):
68 """See IVswitch for general description
70 switch_params = ['--', 'set', 'bridge', switch_name, 'datapath_type=netdev']
72 switch_params = switch_params + params
74 super(OvsDpdkVhost, self).add_switch(switch_name, switch_params)
76 if settings.getValue('VSWITCH_AFFINITIZATION_ON') == 1:
77 # Sets the PMD core mask to VSWITCH_PMD_CPU_MASK
78 # for CPU core affinitization
79 self._bridges[switch_name].set_db_attribute('Open_vSwitch', '.',
80 'other_config:pmd-cpu-mask',
81 settings.getValue('VSWITCH_PMD_CPU_MASK'))
83 def add_phy_port(self, switch_name):
84 """See IVswitch for general description
86 Creates a port of type dpdk.
87 The new port is named dpdk<n> where n is an integer starting from 0.
89 bridge = self._bridges[switch_name]
90 dpdk_count = self._get_port_count('type=dpdk')
91 port_name = 'dpdk' + str(dpdk_count)
92 params = ['--', 'set', 'Interface', port_name, 'type=dpdk']
93 of_port = bridge.add_port(port_name, params)
95 return (port_name, of_port)
97 def add_vport(self, switch_name):
98 """See IVswitch for general description
100 Creates a port of type dpdkvhost
101 The new port is named dpdkvhost<n> where n is an integer starting
104 bridge = self._bridges[switch_name]
105 # Changed dpdkvhost to dpdkvhostuser to be able to run in Qemu 2.2
106 if settings.getValue('VNF').endswith('Cuse'):
107 vhost_count = self._get_port_count('type=dpdkvhostcuse')
108 port_name = 'dpdkvhostcuse' + str(vhost_count)
109 params = ['--', 'set', 'Interface', port_name, 'type=dpdkvhostcuse']
111 vhost_count = self._get_port_count('type=dpdkvhostuser')
112 port_name = 'dpdkvhostuser' + str(vhost_count)
113 params = ['--', 'set', 'Interface', port_name, 'type=dpdkvhostuser']
115 of_port = bridge.add_port(port_name, params)
117 return (port_name, of_port)