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.nfvi.resource import ResourceProfile
35 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper
37 from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
39 TEST_FILE_YAML = 'nsb_test_case.yaml'
45 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
46 class TestUdpReplayApproxVnf(unittest.TestCase):
49 'short-name': 'UdpReplayVnf',
52 'description': 'UDPReplay approximation using DPDK',
55 'netmask': '255.255.255.0',
57 'network': '152.16.100.20',
58 'gateway': '152.16.100.20',
61 'netmask': '255.255.255.0',
63 'network': '152.16.40.20',
64 'gateway': '152.16.40.20',
67 'external-interface': [
69 'virtual-interface': {
70 'dst_mac': '00:00:00:00:00:04',
72 'local_iface_name': 'xe0',
73 'bandwidth': '10 Gbps',
74 'local_ip': '152.16.100.19',
75 'local_mac': '00:00:00:00:00:02',
76 'vpci': '0000:05:00.0',
78 'netmask': '255.255.255.0',
79 'dst_ip': '152.16.100.20',
80 'type': 'PCI-PASSTHROUGH',
84 'vnfd-connection-point-ref': 'xe0',
88 'virtual-interface': {
89 'dst_mac': '00:00:00:00:00:03',
91 'local_iface_name': 'xe1',
92 'bandwidth': '10 Gbps',
93 'local_ip': '152.16.40.19',
94 'local_mac': '00:00:00:00:00:01',
95 'vpci': '0000:05:00.1',
97 'netmask': '255.255.255.0',
98 'dst_ip': '152.16.40.20',
99 'type': 'PCI-PASSTHROUGH',
100 'vld_id': 'downlink_0',
103 'vnfd-connection-point-ref': 'xe1',
111 'network': '0064:ff9b:0:0:0:0:9810:6414',
112 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
117 'network': '0064:ff9b:0:0:0:0:9810:2814',
118 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
121 'id': 'udpreplayvnf-baremetal',
122 'name': 'udpreplayvnf-baremetal',
125 'description': 'UDPReplay approximation using DPDK',
128 'vdu-id': 'udpreplay-baremetal',
141 'connection-point': [
151 'id': 'UdpReplayApproxVnf',
159 "allowed_drop_rate": "0.8 - 1",
162 "rules": "acl_1rule.yaml",
166 "worker_config": "1C/1T",
172 "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7",
173 "tc": "tc_ipv4_1Mflow_64B_packetsize",
175 "object": "NetworkServiceTestCase",
177 "output_filename": "/tmp/yardstick.out",
178 "runner_id": 74476, "duration": 400,
181 "traffic_profile": "ipv4_throughput_acl.yaml",
183 "flow": "ipv4_Packets_acl.yaml",
184 "imix": "imix_voice.yaml"
188 "tg__2": "trafficgen_2.yardstick",
189 "tg__1": "trafficgen_1.yardstick",
190 "vnf__1": "vnf.yardstick"
192 "topology": "udpreplay-tg-topology-baremetal.yaml"
198 "vnfd-id-ref": "vnf__1",
202 "local_iface_name": "ens786f0",
203 "vld_id": UdpReplayApproxVnf.UPLINK,
204 "netmask": "255.255.255.0",
205 "vpci": "0000:05:00.0",
206 "local_ip": "152.16.100.19",
208 "dst_ip": "152.16.100.20",
209 "local_mac": "00:00:00:00:00:02",
210 "dst_mac": "00:00:00:00:00:04",
214 "local_iface_name": "ens786f1",
215 "vld_id": UdpReplayApproxVnf.DOWNLINK,
216 "netmask": "255.255.255.0",
217 "vpci": "0000:05:00.1",
218 "local_ip": "152.16.40.19",
220 "dst_ip": "152.16.40.20",
221 "local_mac": "00:00:00:00:00:01",
222 "dst_mac": "00:00:00:00:00:03",
232 "gateway": "0064:ff9b:0:0:0:0:9810:6414",
233 "network": "0064:ff9b:0:0:0:0:9810:6414"
238 "gateway": "0064:ff9b:0:0:0:0:9810:2814",
239 "network": "0064:ff9b:0:0:0:0:9810:2814"
243 "VNF model": "udp_replay.yaml",
244 "name": "vnf.yardstick",
245 "member-vnf-index": "2",
248 "netmask": "255.255.255.0",
250 "gateway": "152.16.100.20",
251 "network": "152.16.100.20"
254 "netmask": "255.255.255.0",
256 "gateway": "152.16.40.20",
257 "network": "152.16.40.20"
262 "trafficgen_2.yardstick": {
263 "member-vnf-index": "3",
264 "role": "TrafficGen",
265 "name": "trafficgen_2.yardstick",
266 "vnfd-id-ref": "tg__2",
270 "local_iface_name": "ens513f0",
271 "vld_id": UdpReplayApproxVnf.DOWNLINK,
272 "netmask": "255.255.255.0",
273 "vpci": "0000:02:00.0",
274 "local_ip": "152.16.40.20",
276 "dst_ip": "152.16.40.19",
277 "local_mac": "00:00:00:00:00:03",
278 "dst_mac": "00:00:00:00:00:01",
282 "local_iface_name": "ens513f1",
283 "netmask": "255.255.255.0",
284 "network": "202.16.100.0",
285 "local_ip": "202.16.100.20",
287 "local_mac": "00:1e:67:d0:60:5d",
288 "vpci": "0000:02:00.1",
293 "VNF model": "l3fwd_vnf.yaml",
296 "trafficgen_1.yardstick": {
297 "member-vnf-index": "1",
298 "role": "TrafficGen",
299 "name": "trafficgen_1.yardstick",
300 "vnfd-id-ref": "tg__1",
304 "local_iface_name": "ens785f0",
305 "vld_id": UdpReplayApproxVnf.UPLINK,
306 "netmask": "255.255.255.0",
307 "vpci": "0000:05:00.0",
308 "local_ip": "152.16.100.20",
310 "dst_ip": "152.16.100.19",
311 "local_mac": "00:00:00:00:00:04",
312 "dst_mac": "00:00:00:00:00:02",
316 "local_ip": "152.16.100.21",
318 "vpci": "0000:05:00.1",
320 "local_iface_name": "ens785f1",
321 "netmask": "255.255.255.0",
322 "local_mac": "00:00:00:00:00:01"
326 "VNF model": "tg_rfc2544_tpl.yaml",
332 def test___init__(self, _):
333 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
334 self.assertIsNone(udp_replay_approx_vnf._vnf_process)
336 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
337 @mock.patch(SSH_HELPER)
338 def test_collect_kpi(self, ssh, mock_time, _):
342 result = "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
343 "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
344 "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
345 "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
346 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
347 udp_replay_approx_vnf.q_in = mock.MagicMock()
348 udp_replay_approx_vnf.q_out = mock.MagicMock()
349 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
350 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
351 udp_replay_approx_vnf.get_stats = mock.Mock(return_value=result)
352 result = {'collect_stats': {}, 'packets_dropped': 0,
353 'packets_fwd': 14748451, 'packets_in': 14748472}
354 self.assertEqual(result, udp_replay_approx_vnf.collect_kpi())
356 @mock.patch(SSH_HELPER)
357 def test_get_stats(self, ssh, _):
360 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
361 udp_replay_approx_vnf.q_in = mock.MagicMock()
362 udp_replay_approx_vnf.q_out = mock.MagicMock()
363 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
365 "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
367 udp_replay_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
369 self.assertEqual(mock_result,
370 udp_replay_approx_vnf.get_stats())
372 def _get_file_abspath(self, filename):
373 curr_path = os.path.dirname(os.path.abspath(__file__))
374 file_path = os.path.join(curr_path, filename)
377 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
378 @mock.patch(SSH_HELPER)
379 def test__build_config(self, ssh, mock_context, *_):
382 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
383 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
384 udp_replay_approx_vnf.nfvi_context = mock_context
385 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
386 udp_replay_approx_vnf.setup_helper.bound_pci = []
387 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
388 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
389 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
391 cmd_line = udp_replay_approx_vnf._build_config()
394 "sudo tool_path --log-level=5 -c 0x7 -n 4 -w -- -p 0x3 --config='(0,0,1),(1,0,2)'"
395 self.assertEqual(cmd_line, expected)
397 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
398 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
399 @mock.patch(SSH_HELPER)
400 def test__build_pipeline_kwargs(self, ssh, mock_context, *_):
402 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
403 udp_replay_approx_vnf.nfvi_context = mock_context
404 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
405 udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3']
406 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
407 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
408 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
409 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
411 udp_replay_approx_vnf._build_pipeline_kwargs()
413 self.assertEqual(udp_replay_approx_vnf.pipeline_kwargs, {
414 'config': '(0,0,1),(1,0,2)',
415 'cpu_mask_hex': '0x7',
417 'port_mask_hex': '0x3',
418 'tool_path': 'tool_path',
419 'whitelist': '0000:00:0.1 -w 0000:00:0.3'
422 @mock.patch(SSH_HELPER)
423 def test_run_udp_replay(self, ssh, _):
426 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
427 udp_replay_approx_vnf._build_config = mock.MagicMock()
428 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
429 udp_replay_approx_vnf.scenario_helper = mock.MagicMock()
431 udp_replay_approx_vnf._run()
433 udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
435 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
436 @mock.patch(SSH_HELPER)
437 def test_instantiate(self, ssh, *_):
440 resource = mock.Mock(autospec=ResourceProfile)
442 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
443 udp_replay_approx_vnf.q_out.put("Replay>")
444 udp_replay_approx_vnf.WAIT_TIME = 0
445 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
447 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
449 udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1)
450 udp_replay_approx_vnf._vnf_process.exitcode = 0
452 self.assertEquals(udp_replay_approx_vnf.wait_for_instantiate(), 0)
454 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
455 @mock.patch('yardstick.ssh.SSH')
456 @mock.patch(SSH_HELPER)
457 def test_instantiate_panic(self, ssh, resource_ssh, *_):
458 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
459 udp_replay_approx_vnf.WAIT_TIME = 0
460 udp_replay_approx_vnf.q_out.put("some text PANIC some text")
461 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
463 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
464 with self.assertRaises(RuntimeError):
465 udp_replay_approx_vnf.wait_for_instantiate()
467 def test_scale(self, _):
468 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
471 self.assertRaises(NotImplementedError, udp_replay_approx_vnf.scale, flavor)
473 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
474 @mock.patch(SSH_HELPER)
475 def test_terminate(self, ssh, mock_time, _):
478 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
479 udp_replay_approx_vnf._vnf_process = mock.MagicMock()
480 udp_replay_approx_vnf._vnf_process.terminate = mock.Mock()
481 udp_replay_approx_vnf.used_drivers = {"01:01.0": "i40e", "01:01.1": "i40e"}
482 udp_replay_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
483 self.assertEqual(None, udp_replay_approx_vnf.terminate())
485 if __name__ == '__main__':