Yardstick TC082: move sample test case perf.yaml
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / udp_replay.py
1 # Copyright (c) 2016-2017 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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
15 from __future__ import absolute_import
16 import logging
17
18 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
19
20 LOG = logging.getLogger(__name__)
21
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}'"""
26 )
27 # {tool_path} -p {ports_len_hex} -f {cfg_file} -s {script}'
28
29
30 class UdpReplayApproxVnf(SampleVNF):
31
32     APP_NAME = "UDP_Replay"
33     APP_WORD = "UDP_Replay"
34     PIPELINE_COMMAND = REPLAY_PIPELINE_COMMAND
35     VNF_PROMPT = 'Replay>'
36
37     CSUM_MAP = {
38         'baremetal': '',
39         'sriov': '',
40     }
41
42     def scale(self, flavor=""):
43         """ scale vnfbased on flavor input """
44         raise NotImplementedError
45
46     def _build_config(self):
47         pass
48
49     def _deploy(self):
50         self.generate_port_pairs()
51         super(UdpReplayApproxVnf, self)._deploy()
52
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)
60
61         whitelist = " -w ".join(self.bound_pci)
62         self.pipeline_kwargs = {
63             'ports_len_hex': ports_mask_hex,
64             'tool_path': tool_path,
65             'hw_csum': hw_csum,
66             'whitelist': whitelist,
67             'cpu_mask_hex': cpu_mask_hex,
68             'config': config_value,
69         }
70
71     def collect_kpi(self):
72         def get_sum(offset):
73             return sum(int(i) for i in split_stats[offset::5])
74
75         stats = self.get_stats()
76         stats_words = stats.split()
77         split_stats = stats_words[stats_words.index('0'):][:len(self.all_ports) * 5]
78         result = {
79             "packets_in": get_sum(1),
80             "packets_fwd": get_sum(2),
81             "packets_dropped": get_sum(3) + get_sum(4),
82             "collect_stats": {},
83         }
84
85         LOG.debug("UDP Replay collect KPIs %s", result)
86         return result
87
88     def get_stats(self):
89         """
90         Method for checking the statistics
91
92         :return:
93            UDP Replay statistics
94         """
95         cmd = 'UDP_Replay stats'
96         out = self.vnf_execute(cmd)
97         return out