1 # Copyright (c) 2016-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 from __future__ import absolute_import
18 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
20 LOG = logging.getLogger(__name__)
22 # UDP_Replay should work the same on all systems, we can provide the binary
23 REPLAY_PIPELINE_COMMAND = (
24 """sudo {tool_path} -c {cpu_mask_hex} -n 4 -w {whitelist} -- """
25 """{hw_csum} -p {ports_len_hex} --config='{config}'"""
27 # {tool_path} -p {ports_len_hex} -f {cfg_file} -s {script}'
30 class UdpReplayApproxVnf(SampleVNF):
32 APP_NAME = "UDP_Replay"
33 APP_WORD = "UDP_Replay"
34 PIPELINE_COMMAND = REPLAY_PIPELINE_COMMAND
35 VNF_PROMPT = 'Replay>'
42 def scale(self, flavor=""):
43 """ scale vnfbased on flavor input """
44 raise NotImplementedError
46 def _build_config(self):
50 self.generate_port_pairs()
51 super(UdpReplayApproxVnf, self)._deploy()
53 def _build_pipeline_kwargs(self):
54 tool_path = self.ssh_helper.provision_tool(self.APP_NAME)
55 ports_mask = 2 ** len(self.all_ports) - 1
56 ports_mask_hex = hex(ports_mask)
57 cpu_mask_hex = hex(ports_mask * 2)
58 hw_csum = self.CSUM_MAP.get(self.nfvi_type, "--no-hw-csum")
59 config_value = "".join(str((port, 0, port + 1)) for port in self.all_ports)
61 whitelist = " -w ".join(self.bound_pci)
62 self.pipeline_kwargs = {
63 'ports_len_hex': ports_mask_hex,
64 'tool_path': tool_path,
66 'whitelist': whitelist,
67 'cpu_mask_hex': cpu_mask_hex,
68 'config': config_value,
71 def collect_kpi(self):
73 return sum(int(i) for i in split_stats[offset::5])
75 stats = self.get_stats()
76 stats_words = stats.split()
77 split_stats = stats_words[stats_words.index('0'):][:len(self.all_ports) * 5]
79 "packets_in": get_sum(1),
80 "packets_fwd": get_sum(2),
81 "packets_dropped": get_sum(3) + get_sum(4),
85 LOG.debug("UDP Replay collect KPIs %s", result)
90 Method for checking the statistics
95 cmd = 'UDP_Replay stats'
96 out = self.vnf_execute(cmd)