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.common.process import check_if_process_failed
19 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
20 from yardstick.network_services.vnf_generic.vnf.sample_vnf import DpdkVnfSetupEnvHelper
21 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper
22 from yardstick.benchmark.contexts import base as ctx_base
24 LOG = logging.getLogger(__name__)
26 # UDP_Replay should work the same on all systems, we can provide the binary
28 # we can't match the prompt regexp due to extra noise
29 # yardstick.ssh ssh.py:302 DEBUG stdout: UDP_Replay: lcore 0 has nothing to do
30 # eplUDP_Replay: -- lcoreid=1 portid=0 rxqueueid=0
33 # try decreasing log level to RTE_LOG_NOTICE (5)
34 REPLAY_PIPELINE_COMMAND = (
35 """sudo {tool_path} --log-level=5 -c {cpu_mask_hex} -n 4 -w {whitelist} -- """
36 """{hw_csum} -p {port_mask_hex} --config='{config}'"""
38 # {tool_path} -p {port_mask_hex} -f {cfg_file} -s {script}'
41 class UdpReplaySetupEnvHelper(DpdkVnfSetupEnvHelper):
43 APP_NAME = "UDP_Replay"
46 class UdpReplayResourceHelper(ClientResourceHelper):
50 class UdpReplayApproxVnf(SampleVNF):
52 APP_NAME = "UDP_Replay"
53 APP_WORD = "UDP_Replay"
57 VNF_TYPE = 'UdpReplay'
59 HW_OFFLOADING_NFVI_TYPES = {'baremetal', 'sriov'}
61 PIPELINE_COMMAND = REPLAY_PIPELINE_COMMAND
63 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
64 if resource_helper_type is None:
65 resource_helper_type = UdpReplayResourceHelper
67 if setup_env_helper_type is None:
68 setup_env_helper_type = UdpReplaySetupEnvHelper
70 super(UdpReplayApproxVnf, self).__init__(name, vnfd, setup_env_helper_type,
73 def _build_pipeline_kwargs(self):
74 ports = self.vnfd_helper.port_pairs.all_ports
75 number_of_ports = len(ports)
77 tool_path = self.ssh_helper.provision_tool(tool_file=self.APP_NAME)
78 port_nums = self.vnfd_helper.port_nums(ports)
79 ports_mask_hex = hex(sum(2 ** num for num in port_nums))
80 # one core extra for master
81 cpu_mask_hex = hex(2 ** (number_of_ports + 1) - 1)
82 nfvi_context = ctx_base.Context.get_context_from_server(
83 self.scenario_helper.nodes[self.name])
85 if (not self.scenario_helper.options.get('hw_csum', False) or
86 nfvi_context.attrs.get('nfvi_type') not in self.HW_OFFLOADING_NFVI_TYPES):
87 hw_csum = '--no-hw-csum'
89 # tuples of (FLD_PORT, FLD_QUEUE, FLD_LCORE)
90 # [--config (port,queue,lcore)[,(port,queue,lcore]]"
91 # start with lcore = 1 since we use lcore=0 for master
92 config_value = ",".join(
93 str((self.vnfd_helper.port_num(port), 0, core)).replace(" ", "") for core, port in
94 enumerate(self.vnfd_helper.port_pairs.all_ports, 1))
96 whitelist = " -w ".join(self.setup_helper.bound_pci)
97 self.pipeline_kwargs = {
98 'port_mask_hex': ports_mask_hex,
99 'tool_path': tool_path,
101 'whitelist': whitelist,
102 'cpu_mask_hex': cpu_mask_hex,
103 'config': config_value,
106 def _build_config(self):
107 self._build_pipeline_kwargs()
108 return self.PIPELINE_COMMAND.format(**self.pipeline_kwargs)
110 def collect_kpi(self):
112 return sum(int(i) for i in split_stats[offset::5])
113 # we can't get KPIs if the VNF is down
114 check_if_process_failed(self._vnf_process)
116 number_of_ports = len(self.vnfd_helper.port_pairs.all_ports)
118 stats = self.get_stats()
119 stats_words = stats.split()
120 split_stats = stats_words[stats_words.index('0'):][:number_of_ports * 5]
122 physical_node = ctx_base.Context.get_physical_node_from_server(
123 self.scenario_helper.nodes[self.name])
126 "physical_node": physical_node,
127 "packets_in": get_sum(1),
128 "packets_fwd": get_sum(2),
129 "packets_dropped": get_sum(3) + get_sum(4),
130 'collect_stats': self.resource_helper.collect_kpi(),
133 LOG.debug("UDP Replay collect KPIs %s", result)
138 Method for checking the statistics
141 UDP Replay statistics
143 cmd = 'UDP_Replay stats'
144 out = self.vnf_execute(cmd)