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
24 from tests.unit import STL_MOCKS
25 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
28 STLClient = mock.MagicMock()
29 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
33 from yardstick.network_services.vnf_generic.vnf.udp_replay import UdpReplayApproxVnf
34 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper
36 from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
38 TEST_FILE_YAML = 'nsb_test_case.yaml'
44 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
45 class TestUdpReplayApproxVnf(unittest.TestCase):
48 'short-name': 'UdpReplayVnf',
51 'description': 'UDPReplay approximation using DPDK',
54 'netmask': '255.255.255.0',
56 'network': '152.16.100.20',
57 'gateway': '152.16.100.20',
60 'netmask': '255.255.255.0',
62 'network': '152.16.40.20',
63 'gateway': '152.16.40.20',
66 'external-interface': [
68 'virtual-interface': {
69 'dst_mac': '00:00:00:00:00:04',
71 'local_iface_name': 'xe0',
72 'bandwidth': '10 Gbps',
73 'local_ip': '152.16.100.19',
74 'local_mac': '00:00:00:00:00:02',
75 'vpci': '0000:05:00.0',
77 'netmask': '255.255.255.0',
78 'dst_ip': '152.16.100.20',
79 'type': 'PCI-PASSTHROUGH',
81 'vnfd-connection-point-ref': 'xe0',
85 'virtual-interface': {
86 'dst_mac': '00:00:00:00:00:03',
88 'local_iface_name': 'xe1',
89 'bandwidth': '10 Gbps',
90 'local_ip': '152.16.40.19',
91 'local_mac': '00:00:00:00:00:01',
92 'vpci': '0000:05:00.1',
94 'netmask': '255.255.255.0',
95 'dst_ip': '152.16.40.20',
96 'type': 'PCI-PASSTHROUGH',
98 'vnfd-connection-point-ref': 'xe1',
106 'network': '0064:ff9b:0:0:0:0:9810:6414',
107 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
112 'network': '0064:ff9b:0:0:0:0:9810:2814',
113 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
116 'id': 'udpreplayvnf-baremetal',
117 'name': 'udpreplayvnf-baremetal',
120 'description': 'UDPReplay approximation using DPDK',
123 'vdu-id': 'udpreplay-baremetal',
136 'connection-point': [
146 'id': 'UdpReplayApproxVnf',
154 "allowed_drop_rate": "0.8 - 1",
157 "rules": "acl_1rule.yaml",
161 "worker_config": "1C/1T",
167 "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7",
168 "tc": "tc_ipv4_1Mflow_64B_packetsize",
170 "object": "NetworkServiceTestCase",
172 "output_filename": "/tmp/yardstick.out",
173 "runner_id": 74476, "duration": 400,
176 "traffic_profile": "ipv4_throughput_acl.yaml",
178 "flow": "ipv4_Packets_acl.yaml",
179 "imix": "imix_voice.yaml"
183 "tg__2": "trafficgen_2.yardstick",
184 "tg__1": "trafficgen_1.yardstick",
185 "vnf__1": "vnf.yardstick"
187 "topology": "udpreplay-tg-topology-baremetal.yaml"
193 "vnfd-id-ref": "vnf__1",
197 "local_iface_name": "ens786f0",
199 "netmask": "255.255.255.0",
200 "vpci": "0000:05:00.0",
201 "local_ip": "152.16.100.19",
203 "dst_ip": "152.16.100.20",
204 "local_mac": "00:00:00:00:00:02",
205 "dst_mac": "00:00:00:00:00:04",
209 "local_iface_name": "ens786f1",
211 "netmask": "255.255.255.0",
212 "vpci": "0000:05:00.1",
213 "local_ip": "152.16.40.19",
215 "dst_ip": "152.16.40.20",
216 "local_mac": "00:00:00:00:00:01",
217 "dst_mac": "00:00:00:00:00:03",
227 "gateway": "0064:ff9b:0:0:0:0:9810:6414",
228 "network": "0064:ff9b:0:0:0:0:9810:6414"
233 "gateway": "0064:ff9b:0:0:0:0:9810:2814",
234 "network": "0064:ff9b:0:0:0:0:9810:2814"
238 "VNF model": "udp_replay.yaml",
239 "name": "vnf.yardstick",
240 "member-vnf-index": "2",
243 "netmask": "255.255.255.0",
245 "gateway": "152.16.100.20",
246 "network": "152.16.100.20"
249 "netmask": "255.255.255.0",
251 "gateway": "152.16.40.20",
252 "network": "152.16.40.20"
257 "trafficgen_2.yardstick": {
258 "member-vnf-index": "3",
259 "role": "TrafficGen",
260 "name": "trafficgen_2.yardstick",
261 "vnfd-id-ref": "tg__2",
265 "local_iface_name": "ens513f0",
267 "netmask": "255.255.255.0",
268 "vpci": "0000:02:00.0",
269 "local_ip": "152.16.40.20",
271 "dst_ip": "152.16.40.19",
272 "local_mac": "00:00:00:00:00:03",
273 "dst_mac": "00:00:00:00:00:01",
277 "local_iface_name": "ens513f1",
278 "netmask": "255.255.255.0",
279 "network": "202.16.100.0",
280 "local_ip": "202.16.100.20",
282 "local_mac": "00:1e:67:d0:60:5d",
283 "vpci": "0000:02:00.1",
288 "VNF model": "l3fwd_vnf.yaml",
291 "trafficgen_1.yardstick": {
292 "member-vnf-index": "1",
293 "role": "TrafficGen",
294 "name": "trafficgen_1.yardstick",
295 "vnfd-id-ref": "tg__1",
299 "local_iface_name": "ens785f0",
301 "netmask": "255.255.255.0",
302 "vpci": "0000:05:00.0",
303 "local_ip": "152.16.100.20",
305 "dst_ip": "152.16.100.19",
306 "local_mac": "00:00:00:00:00:04",
307 "dst_mac": "00:00:00:00:00:02",
311 "local_ip": "152.16.100.21",
313 "vpci": "0000:05:00.1",
315 "local_iface_name": "ens785f1",
316 "netmask": "255.255.255.0",
317 "local_mac": "00:00:00:00:00:01"
321 "VNF model": "tg_rfc2544_tpl.yaml",
327 def test___init__(self, _):
328 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
329 self.assertIsNone(udp_replay_approx_vnf._vnf_process)
331 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
332 @mock.patch(SSH_HELPER)
333 def test_collect_kpi(self, ssh, mock_time, _):
337 result = "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
338 "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
339 "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
340 "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
341 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
342 udp_replay_approx_vnf.q_in = mock.MagicMock()
343 udp_replay_approx_vnf.q_out = mock.MagicMock()
344 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
345 udp_replay_approx_vnf.all_ports = [0, 1]
346 udp_replay_approx_vnf.get_stats = mock.Mock(return_value=result)
347 result = {'collect_stats': {}, 'packets_dropped': 0,
348 'packets_fwd': 14748451, 'packets_in': 14748472}
349 self.assertEqual(result, udp_replay_approx_vnf.collect_kpi())
351 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
352 @mock.patch(SSH_HELPER)
353 def test_vnf_execute_command(self, ssh, mock_time, _):
356 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
358 self.assertEqual("", udp_replay_approx_vnf.vnf_execute(cmd))
360 @mock.patch(SSH_HELPER)
361 def test_get_stats(self, ssh, _):
364 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
365 udp_replay_approx_vnf.q_in = mock.MagicMock()
366 udp_replay_approx_vnf.q_out = mock.MagicMock()
367 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
369 "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
371 udp_replay_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
373 self.assertEqual(mock_result,
374 udp_replay_approx_vnf.get_stats())
376 def _get_file_abspath(self, filename):
377 curr_path = os.path.dirname(os.path.abspath(__file__))
378 file_path = os.path.join(curr_path, filename)
381 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
382 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
383 @mock.patch(SSH_HELPER)
384 def test__build_config(self, ssh, mock_context, *_):
387 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
388 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
389 udp_replay_approx_vnf.nfvi_context = mock_context
390 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
391 udp_replay_approx_vnf.setup_helper.bound_pci = []
392 udp_replay_approx_vnf.all_ports = [0, 1]
393 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
394 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
395 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
397 cmd_line = udp_replay_approx_vnf._build_config()
399 expected = "sudo tool_path -c 0x7 -n 4 -w -- -p 0x3 --config='(0, 0, 1)(1, 0, 2)'"
400 self.assertEqual(cmd_line, expected)
402 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
403 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
404 @mock.patch(SSH_HELPER)
405 def test__build_pipeline_kwargs(self, ssh, mock_context, *_):
408 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
409 udp_replay_approx_vnf._build_config = mock.MagicMock()
410 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
411 udp_replay_approx_vnf.nfvi_context = mock_context
412 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
413 udp_replay_approx_vnf.setup_helper.bound_pci = []
414 udp_replay_approx_vnf.all_ports = [0, 1]
415 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
416 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
417 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
419 udp_replay_approx_vnf._build_pipeline_kwargs()
421 self.assertEqual(udp_replay_approx_vnf.pipeline_kwargs, {
422 'config': '(0, 0, 1)(1, 0, 2)',
423 'cpu_mask_hex': '0x7',
425 'ports_len_hex': '0x3',
426 'tool_path': 'tool_path',
430 @mock.patch(SSH_HELPER)
431 def test_run_udp_replay(self, ssh, _):
434 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
435 udp_replay_approx_vnf._build_config = mock.MagicMock()
436 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
438 udp_replay_approx_vnf._run()
440 udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
442 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
443 @mock.patch(SSH_HELPER)
444 def test_instantiate(self, ssh, *_):
447 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
448 udp_replay_approx_vnf.q_out.put("Replay>")
449 udp_replay_approx_vnf.WAIT_TIME = 0
450 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
452 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG,
455 udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1)
456 udp_replay_approx_vnf._vnf_process.exitcode = 0
458 self.assertEquals(udp_replay_approx_vnf.wait_for_instantiate(), 0)
460 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
461 @mock.patch('yardstick.ssh.SSH')
462 @mock.patch(SSH_HELPER)
463 def test_instantiate_panic(self, ssh, resource_ssh, *_):
464 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
465 udp_replay_approx_vnf.WAIT_TIME = 0
466 udp_replay_approx_vnf.q_out.put("some text PANIC some text")
467 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
469 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
470 with self.assertRaises(RuntimeError):
471 udp_replay_approx_vnf.wait_for_instantiate()
473 def test_scale(self, _):
474 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
477 self.assertRaises(NotImplementedError, udp_replay_approx_vnf.scale, flavor)
479 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
480 @mock.patch(SSH_HELPER)
481 def test_terminate(self, ssh, mock_time, _):
484 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
485 udp_replay_approx_vnf._vnf_process = mock.MagicMock()
486 udp_replay_approx_vnf._vnf_process.terminate = mock.Mock()
487 udp_replay_approx_vnf.used_drivers = {"01:01.0": "i40e",
489 udp_replay_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
490 self.assertEqual(None, udp_replay_approx_vnf.terminate())
492 if __name__ == '__main__':