3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from __future__ import absolute_import
22 SSH_HELPER = "yardstick.ssh.SSH"
25 'stl': mock.MagicMock(),
26 'stl.trex_stl_lib': mock.MagicMock(),
27 'stl.trex_stl_lib.base64': mock.MagicMock(),
28 'stl.trex_stl_lib.binascii': mock.MagicMock(),
29 'stl.trex_stl_lib.collections': mock.MagicMock(),
30 'stl.trex_stl_lib.copy': mock.MagicMock(),
31 'stl.trex_stl_lib.datetime': mock.MagicMock(),
32 'stl.trex_stl_lib.functools': mock.MagicMock(),
33 'stl.trex_stl_lib.imp': mock.MagicMock(),
34 'stl.trex_stl_lib.inspect': mock.MagicMock(),
35 'stl.trex_stl_lib.json': mock.MagicMock(),
36 'stl.trex_stl_lib.linecache': mock.MagicMock(),
37 'stl.trex_stl_lib.math': mock.MagicMock(),
38 'stl.trex_stl_lib.os': mock.MagicMock(),
39 'stl.trex_stl_lib.platform': mock.MagicMock(),
40 'stl.trex_stl_lib.pprint': mock.MagicMock(),
41 'stl.trex_stl_lib.random': mock.MagicMock(),
42 'stl.trex_stl_lib.re': mock.MagicMock(),
43 'stl.trex_stl_lib.scapy': mock.MagicMock(),
44 'stl.trex_stl_lib.socket': mock.MagicMock(),
45 'stl.trex_stl_lib.string': mock.MagicMock(),
46 'stl.trex_stl_lib.struct': mock.MagicMock(),
47 'stl.trex_stl_lib.sys': mock.MagicMock(),
48 'stl.trex_stl_lib.threading': mock.MagicMock(),
49 'stl.trex_stl_lib.time': mock.MagicMock(),
50 'stl.trex_stl_lib.traceback': mock.MagicMock(),
51 'stl.trex_stl_lib.trex_stl_async_client': mock.MagicMock(),
52 'stl.trex_stl_lib.trex_stl_client': mock.MagicMock(),
53 'stl.trex_stl_lib.trex_stl_exceptions': mock.MagicMock(),
54 'stl.trex_stl_lib.trex_stl_ext': mock.MagicMock(),
55 'stl.trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(),
56 'stl.trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(),
57 'stl.trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(),
58 'stl.trex_stl_lib.trex_stl_port': mock.MagicMock(),
59 'stl.trex_stl_lib.trex_stl_stats': mock.MagicMock(),
60 'stl.trex_stl_lib.trex_stl_streams': mock.MagicMock(),
61 'stl.trex_stl_lib.trex_stl_types': mock.MagicMock(),
62 'stl.trex_stl_lib.types': mock.MagicMock(),
63 'stl.trex_stl_lib.utils': mock.MagicMock(),
64 'stl.trex_stl_lib.utils.argparse': mock.MagicMock(),
65 'stl.trex_stl_lib.utils.collections': mock.MagicMock(),
66 'stl.trex_stl_lib.utils.common': mock.MagicMock(),
67 'stl.trex_stl_lib.utils.json': mock.MagicMock(),
68 'stl.trex_stl_lib.utils.os': mock.MagicMock(),
69 'stl.trex_stl_lib.utils.parsing_opts': mock.MagicMock(),
70 'stl.trex_stl_lib.utils.pwd': mock.MagicMock(),
71 'stl.trex_stl_lib.utils.random': mock.MagicMock(),
72 'stl.trex_stl_lib.utils.re': mock.MagicMock(),
73 'stl.trex_stl_lib.utils.string': mock.MagicMock(),
74 'stl.trex_stl_lib.utils.sys': mock.MagicMock(),
75 'stl.trex_stl_lib.utils.text_opts': mock.MagicMock(),
76 'stl.trex_stl_lib.utils.text_tables': mock.MagicMock(),
77 'stl.trex_stl_lib.utils.texttable': mock.MagicMock(),
78 'stl.trex_stl_lib.warnings': mock.MagicMock(),
79 'stl.trex_stl_lib.yaml': mock.MagicMock(),
80 'stl.trex_stl_lib.zlib': mock.MagicMock(),
81 'stl.trex_stl_lib.zmq': mock.MagicMock(),
84 STLClient = mock.MagicMock()
85 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
89 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex import TrexTrafficGenRFC, \
91 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
92 from yardstick.network_services.traffic_profile.base import TrafficProfile
93 from tests.unit.network_services.vnf_generic.vnf.test_base import FileAbsPath, mock_ssh
95 MODULE_PATH = FileAbsPath(__file__)
96 get_file_abspath = MODULE_PATH.get_path
99 class TestTrexRfcResouceHelper(unittest.TestCase):
101 @mock.patch('yardstick.network_services.helpers.samplevnf_helper.MultiPortConfig')
102 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
103 @mock.patch(SSH_HELPER)
104 def test__run_traffic_once(self, ssh, *_):
107 mock_traffic_profile = mock.MagicMock(autospec=TrafficProfile,
108 **{'get_drop_percentage.return_value': {}})
109 sut = TrexRfcResourceHelper(mock.MagicMock(), mock.MagicMock())
110 sut.client = mock.MagicMock()
111 sut._run_traffic_once(mock_traffic_profile)
114 class TestTrexTrafficGenRFC(unittest.TestCase):
117 'short-name': 'VpeVnf',
122 'network': '152.16.100.20',
123 'netmask': '255.255.255.0',
124 'gateway': '152.16.100.20',
128 'network': '152.16.40.20',
129 'netmask': '255.255.255.0',
130 'gateway': '152.16.40.20',
134 'description': 'VPE approximation using DPDK',
135 'name': 'vpevnf-baremetal',
138 'network': '0064:ff9b:0:0:0:0:9810:6414',
140 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
144 'network': '0064:ff9b:0:0:0:0:9810:2814',
146 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
150 'id': 'vpevnf-baremetal',
151 'external-interface': [
153 'virtual-interface': {
155 'dst_mac': '00:00:00:00:00:04',
156 'vpci': '0000:05:00.0',
157 'local_ip': '152.16.100.19',
158 'type': 'PCI-PASSTHROUGH',
159 'netmask': '255.255.255.0',
160 'vld_id': 'private_1',
161 'dpdk_port_num': '0',
162 'bandwidth': '10 Gbps',
164 'dst_ip': '152.16.100.20',
165 'local_iface_name': 'xe0',
166 'local_mac': '00:00:00:00:00:01',
168 'vnfd-connection-point-ref': 'xe0',
172 'virtual-interface': {
174 'dst_mac': '00:00:00:00:00:03',
175 'vpci': '0000:05:00.1',
176 'local_ip': '152.16.40.19',
177 'type': 'PCI-PASSTHROUGH',
179 'netmask': '255.255.255.0',
180 'vld_id': 'public_1',
181 'dpdk_port_num': '1',
182 'bandwidth': '10 Gbps',
183 'dst_ip': '152.16.40.20',
184 'local_iface_name': 'xe1',
185 'local_mac': '00:00:00:00:00:02'
187 'vnfd-connection-point-ref': 'xe1',
193 'description': 'Vpe approximation using DPDK',
195 'vdu-id': 'vpevnf-baremetal',
208 'connection-point': [
218 'id': 'VpeApproxVnf',
223 'vnfd:vnfd-catalog': {
231 "schema": "isb:traffic_profile:0.1",
233 "description": "Fixed traffic profile to run UDP traffic",
235 "traffic_type": "FixedTraffic",
236 "frame_rate": 100, # pps
247 'allowed_drop_rate': '0.8 - 1',
256 'flow': 'ipv4_1flow_Packets_vpe.yaml',
257 'imix': 'imix_voice.yaml',
264 'traffic_profile': 'ipv4_throughput_vpe.yaml',
267 'tg__1': 'trafficgen_1.yardstick',
268 'vnf__1': 'vnf.yardstick',
270 'topology': 'vpe_vnf_topology.yaml',
274 'nfvi_type': 'baremetal',
277 'file': '/etc/yardstick/nodes/pod.yaml',
279 'schema': 'yardstick:task:0.1',
282 @mock.patch(SSH_HELPER)
283 def test___init__(self, ssh):
285 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
286 self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value)
288 @mock.patch(SSH_HELPER)
289 def test_collect_kpi(self, ssh):
291 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
292 self.assertIsNone(trex_traffic_gen.collect_kpi())
294 @mock.patch(SSH_HELPER)
295 def test_listen_traffic(self, ssh):
297 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
298 self.assertIsNone(trex_traffic_gen.listen_traffic({}))
300 @mock.patch(SSH_HELPER)
301 def test_instantiate(self, ssh):
304 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
305 mock_traffic_profile.get_traffic_definition.return_value = "64"
306 mock_traffic_profile.params = self.TRAFFIC_PROFILE
308 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
309 trex_traffic_gen._start_server = mock.Mock(return_value=0)
310 trex_traffic_gen.resource_helper = mock.MagicMock()
312 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
313 "topology": 'nsb_test_case.yaml',
318 'allowed_drop_rate': '0.8 - 1',
321 'rules': 'acl_1rule.yaml',
325 'worker_config': '1C/1T',
331 tg_rfc2544_trex.WAIT_TIME = 3
332 scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]})
333 self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
335 @mock.patch(SSH_HELPER)
336 def test_instantiate_error(self, ssh):
337 mock_ssh(ssh, exec_result=(1, "", ""))
339 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
340 mock_traffic_profile.get_traffic_definition.return_value = "64"
341 mock_traffic_profile.params = self.TRAFFIC_PROFILE
343 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
344 trex_traffic_gen.resource_helper = mock.MagicMock()
346 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
351 "topology": 'nsb_test_case.yaml',
356 'allowed_drop_rate': '0.8 - 1',
359 'rules': 'acl_1rule.yaml',
363 'worker_config': '1C/1T',
369 trex_traffic_gen.instantiate(scenario_cfg, {})
371 @mock.patch(SSH_HELPER)
372 def test__start_server(self, ssh):
374 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
375 trex_traffic_gen.resource_helper = mock.MagicMock()
376 self.assertIsNone(trex_traffic_gen._start_server())
378 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
379 @mock.patch(SSH_HELPER)
380 def test__generate_trex_cfg(self, ssh, _):
383 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
384 trex_traffic_gen.ssh_helper = mock.MagicMock()
385 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
386 self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg())
388 def test_scale(self):
389 with mock.patch(SSH_HELPER) as ssh:
390 ssh_mock = mock.Mock(autospec=ssh.SSH)
391 ssh_mock.execute = mock.Mock(return_value=(0, "", ""))
392 ssh_mock.run = mock.Mock(return_value=(0, "", ""))
393 ssh.from_node.return_value = ssh_mock
394 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
395 trex_traffic_gen.scale('')
397 def test_terminate(self):
398 with mock.patch(SSH_HELPER) as ssh:
399 ssh_mock = mock.Mock(autospec=ssh.SSH)
400 ssh_mock.execute = mock.Mock(return_value=(0, "", ""))
401 ssh.from_node.return_value = ssh_mock
402 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
403 trex_traffic_gen.resource_helper = mock.MagicMock()
404 self.assertIsNone(trex_traffic_gen.terminate())