1 # Copyright (c) 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.
16 from __future__ import absolute_import
21 from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
22 from tests.unit import STL_MOCKS
24 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
27 STLClient = mock.MagicMock()
28 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
32 from yardstick.network_services.vnf_generic.vnf.tg_prox import ProxTrafficGen
33 from yardstick.network_services.traffic_profile.base import TrafficProfile
36 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
37 class TestProxTrafficGen(unittest.TestCase):
39 'short-name': 'ProxVnf',
44 'network': '152.16.100.20',
45 'netmask': '255.255.255.0',
46 'gateway': '152.16.100.20',
50 'network': '152.16.40.20',
51 'netmask': '255.255.255.0',
52 'gateway': '152.16.40.20',
56 'description': 'PROX approximation using DPDK',
57 'name': 'proxvnf-baremetal',
60 'network': '0064:ff9b:0:0:0:0:9810:6414',
62 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
66 'network': '0064:ff9b:0:0:0:0:9810:2814',
68 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
72 'id': 'proxvnf-baremetal',
73 'external-interface': [
75 'virtual-interface': {
76 'dst_mac': '00:00:00:00:00:04',
77 'vpci': '0000:05:00.0',
78 'local_ip': '152.16.100.19',
79 'type': 'PCI-PASSTHROUGH',
81 'netmask': '255.255.255.0',
83 'bandwidth': '10 Gbps',
85 'dst_ip': '152.16.100.20',
86 'local_iface_name': 'xe0',
87 'local_mac': '00:00:00:00:00:02',
89 'vnfd-connection-point-ref': 'xe0',
93 'virtual-interface': {
94 'dst_mac': '00:00:00:00:00:03',
95 'vpci': '0000:05:00.1',
96 'local_ip': '152.16.40.19',
97 'type': 'PCI-PASSTHROUGH',
100 'netmask': '255.255.255.0',
102 'bandwidth': '10 Gbps',
103 'dst_ip': '152.16.40.20',
104 'local_iface_name': 'xe1',
105 'local_mac': '00:00:00:00:00:01',
107 'vnfd-connection-point-ref': 'xe1',
113 'description': 'PROX approximation using DPDK',
115 'vdu-id': 'proxvnf-baremetal',
128 'connection-point': [
138 'id': 'ProxApproxVnf',
143 'vnfd:vnfd-catalog': {
153 'tg__1': 'trafficgen_1.yardstick',
154 'vnf__1': 'vnf.yardstick'},
156 'duration': 600, 'type': 'Duration'},
157 'topology': 'prox-tg-topology-2.yaml',
158 'traffic_profile': '../../traffic_profiles/prox_binsearch.yaml',
161 'tg__1': {'prox_args': {'-e': '',
163 'prox_config': 'configs/l3-gen-2.cfg',
165 '/root/dppd-PROX-v035/build/prox'},
167 'prox_args': {'-t': ''},
168 'prox_config': 'configs/l3-swap-2.cfg',
169 'prox_path': '/root/dppd-PROX-v035/build/prox'}}}
174 'member-vnf-index': '3',
175 'role': 'TrafficGen',
176 'name': 'trafficgen_2.yardstick',
177 'vnfd-id-ref': 'tg__2',
181 'local_iface_name': 'ens513f0',
182 'vld_id': ProxTrafficGen.DOWNLINK,
183 'netmask': '255.255.255.0',
184 'local_ip': '152.16.40.20',
185 'dst_mac': '00:00:00:00:00:01',
186 'local_mac': '00:00:00:00:00:03',
187 'dst_ip': '152.16.40.19',
189 'vpci': '0000:02:00.0',
193 'local_iface_name': 'ens513f1',
194 'netmask': '255.255.255.0',
195 'network': '202.16.100.0',
196 'local_ip': '202.16.100.20',
197 'local_mac': '00:1e:67:d0:60:5d',
199 'vpci': '0000:02:00.1',
204 'VNF model': 'l3fwd_vnf.yaml',
208 'member-vnf-index': '1',
209 'role': 'TrafficGen',
210 'name': 'trafficgen_1.yardstick',
211 'vnfd-id-ref': 'tg__1',
215 'local_iface_name': 'ens785f0',
216 'vld_id': ProxTrafficGen.UPLINK,
217 'netmask': '255.255.255.0',
218 'local_ip': '152.16.100.20',
219 'dst_mac': '00:00:00:00:00:02',
220 'local_mac': '00:00:00:00:00:04',
221 'dst_ip': '152.16.100.19',
223 'vpci': '0000:05:00.0',
227 'local_iface_name': 'ens785f1',
228 'netmask': '255.255.255.0',
229 'local_ip': '152.16.100.21',
230 'local_mac': '00:00:00:00:00:01',
232 'vpci': '0000:05:00.1',
237 'VNF model': 'tg_rfc2544_tpl.yaml',
241 'name': 'vnf.yardstick',
242 'vnfd-id-ref': 'vnf__1',
246 'local_iface_name': 'ens786f0',
247 'vld_id': ProxTrafficGen.UPLINK,
248 'netmask': '255.255.255.0',
249 'local_ip': '152.16.100.19',
250 'dst_mac': '00:00:00:00:00:04',
251 'local_mac': '00:00:00:00:00:02',
252 'dst_ip': '152.16.100.20',
254 'vpci': '0000:05:00.0',
258 'local_iface_name': 'ens786f1',
259 'vld_id': ProxTrafficGen.DOWNLINK,
260 'netmask': '255.255.255.0',
261 'local_ip': '152.16.40.19',
262 'dst_mac': '00:00:00:00:00:03',
263 'local_mac': '00:00:00:00:00:01',
264 'dst_ip': '152.16.40.20',
266 'vpci': '0000:05:00.1',
272 'netmask': '255.255.255.0',
273 'gateway': '152.16.100.20',
274 'network': '152.16.100.20',
278 'netmask': '255.255.255.0',
279 'gateway': '152.16.40.20',
280 'network': '152.16.40.20',
284 'member-vnf-index': '2',
291 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
292 'network': '0064:ff9b:0:0:0:0:9810:6414',
297 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
298 'network': '0064:ff9b:0:0:0:0:9810:2814',
303 'VNF model': 'prox_vnf.yaml',
309 'description': 'Binary search for max no-drop throughput over given packet sizes',
310 'name': 'prox_binsearch',
311 'schema': 'nsb:traffic_profile:0.1',
315 'packet_sizes': [64, 65],
316 'test_precision': 1.0,
317 'tolerated_loss': 0.0,
318 'traffic_type': 'ProxBinSearchProfile',
319 'upper_bound': 100.0}}
321 @mock.patch(SSH_HELPER)
322 def test___init__(self, ssh, mock_time):
324 prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0)
325 self.assertIsNone(prox_traffic_gen._tg_process)
326 self.assertIsNone(prox_traffic_gen._traffic_process)
328 @mock.patch(SSH_HELPER)
329 def test_collect_kpi(self, ssh, mock_time):
332 prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0)
333 prox_traffic_gen._vnf_wrapper.resource_helper.resource = mock.MagicMock(
334 **{"check_if_sa_running.return_value": [False]})
335 prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="")
336 self.assertEqual({}, prox_traffic_gen.collect_kpi())
338 @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.CpuSysCores')
339 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
340 @mock.patch(SSH_HELPER)
341 def bad_test_instantiate(self, ssh, mock_find, mock_cpu_sys_cores, mock_time):
344 mock_cpu_sys_cores.get_core_socket.return_value = {'0': '01234'}
346 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
347 mock_traffic_profile.get_traffic_definition.return_value = "64"
348 mock_traffic_profile.params = self.TRAFFIC_PROFILE
350 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
351 prox_traffic_gen = ProxTrafficGen(NAME, vnfd)
352 ssh_helper = mock.MagicMock(
353 **{"execute.return_value": (0, "", ""), "bin_path": ""})
354 prox_traffic_gen.ssh_helper = ssh_helper
355 prox_traffic_gen.setup_helper.dpdk_bind_helper.ssh_helper = ssh_helper
356 prox_traffic_gen.setup_helper._setup_resources = mock.MagicMock()
357 prox_traffic_gen.setup_hugepages = mock.MagicMock()
358 prox_traffic_gen.generate_prox_config_file = mock.MagicMock()
359 prox_traffic_gen.upload_prox_config = mock.MagicMock()
360 prox_traffic_gen.setup_helper._find_used_drivers = mock.MagicMock()
361 prox_traffic_gen.setup_helper.used_drivers = {}
362 prox_traffic_gen.setup_helper.bound_pci = []
363 prox_traffic_gen._start_server = mock.Mock(return_value=0)
364 prox_traffic_gen._tg_process = mock.MagicMock()
365 prox_traffic_gen._tg_process.start = mock.Mock()
366 prox_traffic_gen._tg_process.exitcode = 0
367 prox_traffic_gen._tg_process._is_alive = mock.Mock(return_value=1)
368 prox_traffic_gen.ssh_helper = mock.MagicMock()
369 prox_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
372 'options': {'tg__1': {'prox_args': {'-e': '',
374 'prox_config': 'configs/l3-gen-2.cfg',
375 'prox_path': '/root/dppd-PROX-v035/build/prox'},
376 'vnf__1': {'prox_args': {'-t': ''},
377 'prox_config': 'configs/l3-swap-2.cfg',
378 'prox_path': '/root/dppd-PROX-v035/build/prox'}
381 prox_traffic_gen.instantiate(scenario_cfg, {})
383 @mock.patch(SSH_HELPER)
384 def test__traffic_runner(self, ssh, mock_time):
387 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
388 mock_traffic_profile.get_traffic_definition.return_value = "64"
389 mock_traffic_profile.execute_traffic.return_value = "64"
390 mock_traffic_profile.params = self.TRAFFIC_PROFILE
392 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
393 sut = ProxTrafficGen(NAME, vnfd)
394 sut._get_socket = mock.MagicMock()
395 sut.ssh_helper = mock.Mock()
396 sut.ssh_helper.run = mock.Mock()
397 sut.setup_helper.prox_config_dict = {}
398 sut._vpci_ascending = ["0000:05:00.0", "0000:05:00.1"]
399 sut._connect_client = mock.Mock(autospec=STLClient)
400 sut._connect_client.get_stats = mock.Mock(return_value="0")
401 sut._traffic_runner(mock_traffic_profile)
403 @mock.patch(SSH_HELPER)
404 def test_scale(self, ssh, mock_time):
405 mock_ssh(ssh, exec_result=(1, "", ""))
406 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
407 prox_traffic_gen = ProxTrafficGen(NAME, vnfd)
408 with self.assertRaises(NotImplementedError):
409 prox_traffic_gen.scale('')
411 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket')
412 @mock.patch(SSH_HELPER)
413 def test_listen_traffic(self, ssh, mock_socket, mock_time):
415 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
416 prox_traffic_gen = ProxTrafficGen(NAME, vnfd)
417 self.assertIsNone(prox_traffic_gen.listen_traffic(mock.Mock()))
419 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket')
420 @mock.patch(SSH_HELPER)
421 def test_terminate(self, ssh, mock_socket, mock_time):
423 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
424 prox_traffic_gen = ProxTrafficGen(NAME, vnfd)
425 prox_traffic_gen._terminated = mock.MagicMock()
426 prox_traffic_gen._traffic_process = mock.MagicMock()
427 prox_traffic_gen._traffic_process.terminate = mock.Mock()
428 prox_traffic_gen.ssh_helper = mock.MagicMock()
429 prox_traffic_gen.setup_helper = mock.MagicMock()
430 prox_traffic_gen._vnf_wrapper.setup_helper = mock.MagicMock()
431 prox_traffic_gen.resource_helper = mock.MagicMock()
432 self.assertEqual(None, prox_traffic_gen.terminate())