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
23 LOG = logging.getLogger(__name__)
25 # UDP_Replay should work the same on all systems, we can provide the binary
27 # we can't match the prompt regexp due to extra noise
28 # yardstick.ssh ssh.py:302 DEBUG stdout: UDP_Replay: lcore 0 has nothing to do
29 # eplUDP_Replay: -- lcoreid=1 portid=0 rxqueueid=0
32 # try decreasing log level to RTE_LOG_NOTICE (5)
33 REPLAY_PIPELINE_COMMAND = (
34 """sudo {tool_path} --log-level=5 -c {cpu_mask_hex} -n 4 -w {whitelist} -- """
35 """{hw_csum} -p {port_mask_hex} --config='{config}'"""
37 # {tool_path} -p {port_mask_hex} -f {cfg_file} -s {script}'
40 class UdpReplaySetupEnvHelper(DpdkVnfSetupEnvHelper):
42 APP_NAME = "UDP_Replay"
45 class UdpReplayResourceHelper(ClientResourceHelper):
49 class UdpReplayApproxVnf(SampleVNF):
51 APP_NAME = "UDP_Replay"
52 APP_WORD = "UDP_Replay"
56 VNF_TYPE = 'UdpReplay'
58 HW_OFFLOADING_NFVI_TYPES = {'baremetal', 'sriov'}
60 PIPELINE_COMMAND = REPLAY_PIPELINE_COMMAND
62 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
63 if resource_helper_type is None:
64 resource_helper_type = UdpReplayResourceHelper
66 if setup_env_helper_type is None:
67 setup_env_helper_type = UdpReplaySetupEnvHelper
69 super(UdpReplayApproxVnf, self).__init__(name, vnfd, setup_env_helper_type,
72 def _build_pipeline_kwargs(self):
73 ports = self.vnfd_helper.port_pairs.all_ports
74 number_of_ports = len(ports)
76 tool_path = self.ssh_helper.provision_tool(tool_file=self.APP_NAME)
77 port_nums = self.vnfd_helper.port_nums(ports)
78 ports_mask_hex = hex(sum(2 ** num for num in port_nums))
79 # one core extra for master
80 cpu_mask_hex = hex(2 ** (number_of_ports + 1) - 1)
82 if (not self.scenario_helper.options.get('hw_csum', False) or
83 self.nfvi_context.attrs.get('nfvi_type') not in self.HW_OFFLOADING_NFVI_TYPES):
84 hw_csum = '--no-hw-csum'
86 # tuples of (FLD_PORT, FLD_QUEUE, FLD_LCORE)
87 # [--config (port,queue,lcore)[,(port,queue,lcore]]"
88 # start with lcore = 1 since we use lcore=0 for master
89 config_value = ",".join(
90 str((self.vnfd_helper.port_num(port), 0, core)).replace(" ", "") for core, port in
91 enumerate(self.vnfd_helper.port_pairs.all_ports, 1))
93 whitelist = " -w ".join(self.setup_helper.bound_pci)
94 self.pipeline_kwargs = {
95 'port_mask_hex': ports_mask_hex,
96 'tool_path': tool_path,
98 'whitelist': whitelist,
99 'cpu_mask_hex': cpu_mask_hex,
100 'config': config_value,
103 def _build_config(self):
104 self._build_pipeline_kwargs()
105 return self.PIPELINE_COMMAND.format(**self.pipeline_kwargs)
107 def collect_kpi(self):
109 return sum(int(i) for i in split_stats[offset::5])
111 number_of_ports = len(self.vnfd_helper.port_pairs.all_ports)
113 stats = self.get_stats()
114 stats_words = stats.split()
115 split_stats = stats_words[stats_words.index('0'):][:number_of_ports * 5]
117 "packets_in": get_sum(1),
118 "packets_fwd": get_sum(2),
119 "packets_dropped": get_sum(3) + get_sum(4),
120 'collect_stats': self.resource_helper.collect_kpi(),
123 LOG.debug("UDP Replay collect KPIs %s", result)
128 Method for checking the statistics
131 UDP Replay statistics
133 cmd = 'UDP_Replay stats'
134 out = self.vnf_execute(cmd)