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
19 from yardstick.network_services.vnf_generic.vnf.sample_vnf import DpdkVnfSetupEnvHelper
20 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper
22 LOG = logging.getLogger(__name__)
24 # UDP_Replay should work the same on all systems, we can provide the binary
25 REPLAY_PIPELINE_COMMAND = (
26 """sudo {tool_path} -c {cpu_mask_hex} -n 4 -w {whitelist} -- """
27 """{hw_csum} -p {ports_len_hex} --config='{config}'"""
29 # {tool_path} -p {ports_len_hex} -f {cfg_file} -s {script}'
32 class UdpReplaySetupEnvHelper(DpdkVnfSetupEnvHelper):
34 APP_NAME = "UDP_Replay"
37 class UdpReplayResourceHelper(ClientResourceHelper):
41 class UdpReplayApproxVnf(SampleVNF):
43 APP_NAME = "UDP_Replay"
44 APP_WORD = "UDP_Replay"
45 VNF_PROMPT = 'Replay>'
47 VNF_TYPE = 'UdpReplay'
49 HW_OFFLOADING_NFVI_TYPES = {'baremetal', 'sriov'}
51 PIPELINE_COMMAND = REPLAY_PIPELINE_COMMAND
53 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
54 if resource_helper_type is None:
55 resource_helper_type = UdpReplayResourceHelper
57 if setup_env_helper_type is None:
58 setup_env_helper_type = UdpReplaySetupEnvHelper
60 super(UdpReplayApproxVnf, self).__init__(name, vnfd, setup_env_helper_type,
63 def _start_server(self):
64 super(UdpReplayApproxVnf, self)._start_server()
65 self.resource_helper.start()
67 def scale(self, flavor=""):
68 """ scale vnfbased on flavor input """
69 raise NotImplementedError
72 self.generate_port_pairs()
73 super(UdpReplayApproxVnf, self)._deploy()
75 def _build_pipeline_kwargs(self):
76 all_ports = [i for i, _ in enumerate(self.vnfd_helper.interfaces)]
77 number_of_ports = len(all_ports)
79 tool_path = self.ssh_helper.provision_tool(tool_file=self.APP_NAME)
80 ports_mask = 2 ** number_of_ports - 1
81 ports_mask_hex = hex(ports_mask)
82 cpu_mask_hex = hex(2 ** (number_of_ports + 1) - 1)
84 if (not self.scenario_helper.options.get('hw_csum', False) or
85 self.nfvi_context.attrs.get('nfvi_type') not in self.HW_OFFLOADING_NFVI_TYPES):
86 hw_csum = '--no-hw-csum'
88 config_value = "".join(str((port, 0, port + 1)) for port in all_ports)
90 whitelist = " -w ".join(self.setup_helper.bound_pci)
91 self.pipeline_kwargs = {
92 'ports_len_hex': ports_mask_hex,
93 'tool_path': tool_path,
95 'whitelist': whitelist,
96 'cpu_mask_hex': cpu_mask_hex,
97 'config': config_value,
100 def _build_config(self):
101 self._build_pipeline_kwargs()
102 return self.PIPELINE_COMMAND.format(**self.pipeline_kwargs)
104 def collect_kpi(self):
106 return sum(int(i) for i in split_stats[offset::5])
108 number_of_ports = len(self.vnfd_helper.interfaces)
110 stats = self.get_stats()
111 stats_words = stats.split()
112 split_stats = stats_words[stats_words.index('0'):][:number_of_ports * 5]
114 "packets_in": get_sum(1),
115 "packets_fwd": get_sum(2),
116 "packets_dropped": get_sum(3) + get_sum(4),
120 LOG.debug("UDP Replay collect KPIs %s", result)
125 Method for checking the statistics
128 UDP Replay statistics
130 cmd = 'UDP_Replay stats'
131 out = self.vnf_execute(cmd)