1 # Copyright 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.
14 """ Vsperf specific scenario definition """
16 from __future__ import absolute_import
22 import yardstick.ssh as ssh
23 from yardstick.benchmark.scenarios import base
25 LOG = logging.getLogger(__name__)
28 class Vsperf(base.Scenario):
29 """Execute vsperf with defined parameters
32 traffic_type - to specify the type of traffic executed by traffic generator
33 the valid values are "rfc2544", "continuous", "back2back"
36 frame_size - a frame size for which test should be executed;
37 Multiple frame sizes can be tested by modification of sequence runner
38 section inside TC YAML definition.
41 bidirectional - speficies if traffic will be uni (False) or bi-directional
45 iload - specifies frame rate
48 multistream - the number of simulated streams
51 stream_type - specifies network layer used for multistream simulation
52 the valid values are "L4", "L3" and "L2"
55 test_params - specifies a string with a list of vsperf configuration
56 parameters, which will be passed to the '--test-params' CLI argument;
57 Parameters should be stated in the form of 'param=value' and separated
58 by a semicolon. Please check VSPERF documentation for details about
59 available configuration parameters and their data types.
60 In case that both 'test_params' and 'conf_file' are specified,
61 then values from 'test_params' will override values defined
62 in the configuration file.
65 conf_file - path to the vsperf configuration file, which will be uploaded
67 In case that both 'test_params' and 'conf_file' are specified,
68 then values from 'test_params' will override values defined
69 in configuration file.
72 setup_script - path to the setup script, which will be executed during
73 setup and teardown phases
76 trafficgen_port1 - specifies device name of 1st interface connected to
80 trafficgen_port2 - specifies device name of 2nd interface connected to
84 external_bridge - specifies name of external bridge configured in OVS
89 __scenario_type__ = "Vsperf"
91 def __init__(self, scenario_cfg, context_cfg):
92 self.scenario_cfg = scenario_cfg
93 self.context_cfg = context_cfg
94 self.setup_done = False
96 self.tg_port1 = self.scenario_cfg['options'].get('trafficgen_port1',
98 self.tg_port2 = self.scenario_cfg['options'].get('trafficgen_port2',
100 self.br_ex = self.scenario_cfg['options'].get('external_bridge',
102 self.vsperf_conf = self.scenario_cfg['options'].get('conf_file', None)
104 self.vsperf_conf = os.path.expanduser(self.vsperf_conf)
106 self.setup_script = self.scenario_cfg['options'].get('setup_script',
108 if self.setup_script:
109 self.setup_script = os.path.expanduser(self.setup_script)
111 self.test_params = self.scenario_cfg['options'].get('test-params',
116 vsperf = self.context_cfg['host']
118 # add trafficgen interfaces to the external bridge
120 subprocess.call('sudo bash -c "ovs-vsctl add-port %s %s"' %
121 (self.br_ex, self.tg_port1), shell=True)
123 subprocess.call('sudo bash -c "ovs-vsctl add-port %s %s"' %
124 (self.br_ex, self.tg_port2), shell=True)
126 # copy vsperf conf to VM
127 self.client = ssh.SSH.from_node(vsperf, defaults={
128 "user": "ubuntu", "password": "ubuntu"
130 # traffic generation could last long
131 self.client.wait(timeout=1800)
133 # copy script to host
134 self.client._put_file_shell(self.vsperf_conf, '~/vsperf.conf')
136 # execute external setup script
137 if self.setup_script:
138 cmd = "%s setup" % (self.setup_script)
139 LOG.info("Execute setup script \"%s\"", cmd)
140 subprocess.call(cmd, shell=True)
142 self.setup_done = True
144 def run(self, result):
145 """ execute the vsperf benchmark and return test results
146 within result dictionary
148 def add_test_params(options, option, default_value):
149 """return parameter and its value as a string to be passed
150 to the VSPERF inside --test-params argument
153 options - dictionary with scenario options
154 option - a name of option to be added to the string
155 default_value - value to be used in case that option
156 is not defined inside scenario options
158 if option in options:
159 return "%s=%s" % (option, options[option])
160 elif default_value is not None:
161 return "%s=%s" % (option, default_value)
165 if not self.setup_done:
168 # remove results from previous tests
169 self.client.execute("rm -rf /tmp/results*")
172 options = self.scenario_cfg['options']
174 test_params.append(add_test_params(options, "traffic_type", "rfc2544"))
175 test_params.append(add_test_params(options, "bidirectional", "False"))
176 test_params.append(add_test_params(options, "iload", 100))
177 test_params.append(add_test_params(options, "multistream", None))
178 test_params.append(add_test_params(options, "stream_type", None))
179 if 'frame_size' in options:
180 test_params.append("%s=(%s,)" % ('TRAFFICGEN_PKT_SIZES',
181 options['frame_size']))
182 if 'test_params' in options:
183 test_params.append(options['test_params'])
185 # filter empty parameters and escape quotes and double quotes
186 test_params = [tp.replace('"', '\\"').replace("'", "\\'")
187 for tp in test_params if tp]
190 cmd = "source ~/vsperfenv/bin/activate ; cd vswitchperf ; "
191 cmd += "./vsperf --mode trafficgen "
193 cmd += "--conf-file ~/vsperf.conf "
194 cmd += "--test-params=\"%s\"" % (';'.join(test_params))
195 LOG.debug("Executing command: %s", cmd)
199 cmd = "cat /tmp/results*/result.csv"
200 LOG.debug("Executing command: %s", cmd)
201 _, stdout, _ = self.client.execute(cmd, raise_on_error=True)
203 # convert result.csv to JSON format
204 reader = csv.DictReader(stdout.split('\r\n'), strict=True)
206 result.update(next(reader))
207 except StopIteration:
210 # sla check; go through all defined SLAs and check if values measured
211 # by VSPERF are higher then those defined by SLAs
212 if 'sla' in self.scenario_cfg and \
213 'metrics' in self.scenario_cfg['sla']:
214 for metric in self.scenario_cfg['sla']['metrics'].split(','):
215 self.verify_SLA(metric in result,
216 '%s was not collected by VSPERF' % metric)
217 self.verify_SLA(metric in self.scenario_cfg['sla'],
218 '%s is not defined in SLA' % metric)
219 vs_res = float(result[metric])
220 sla_res = float(self.scenario_cfg['sla'][metric])
221 self.verify_SLA(vs_res >= sla_res,
222 'VSPERF_%s(%f) < SLA_%s(%f)'
223 % (metric, vs_res, metric, sla_res))
226 """cleanup after the test execution"""
227 # remove trafficgen interfaces from the external bridge
229 subprocess.call('sudo bash -c "ovs-vsctl del-port %s %s"' %
230 (self.br_ex, self.tg_port1), shell=True)
232 subprocess.call('sudo bash -c "ovs-vsctl del-port %s %s"' %
233 (self.br_ex, self.tg_port2), shell=True)
235 # execute external setup script
236 if self.setup_script:
237 cmd = "%s teardown" % (self.setup_script)
238 LOG.info("Execute setup script \"%s\"", cmd)
239 subprocess.call(cmd, shell=True)
241 self.setup_done = False