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.
22 from tests.unit import STL_MOCKS
23 from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
26 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
37 TEST_FILE_YAML = 'nsb_test_case.yaml'
43 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
44 class TestUdpReplayApproxVnf(unittest.TestCase):
47 'short-name': 'UdpReplayVnf',
50 'description': 'UDPReplay approximation using DPDK',
53 'netmask': '255.255.255.0',
55 'network': '152.16.100.20',
56 'gateway': '152.16.100.20',
59 'netmask': '255.255.255.0',
61 'network': '152.16.40.20',
62 'gateway': '152.16.40.20',
65 'external-interface': [
67 'virtual-interface': {
68 'dst_mac': '00:00:00:00:00:04',
70 'local_iface_name': 'xe0',
71 'bandwidth': '10 Gbps',
72 'local_ip': '152.16.100.19',
73 'local_mac': '00:00:00:00:00:02',
74 'vpci': '0000:05:00.0',
76 'netmask': '255.255.255.0',
77 'dst_ip': '152.16.100.20',
78 'type': 'PCI-PASSTHROUGH',
82 'vnfd-connection-point-ref': 'xe0',
86 'virtual-interface': {
87 'dst_mac': '00:00:00:00:00:03',
89 'local_iface_name': 'xe1',
90 'bandwidth': '10 Gbps',
91 'local_ip': '152.16.40.19',
92 'local_mac': '00:00:00:00:00:01',
93 'vpci': '0000:05:00.1',
95 'netmask': '255.255.255.0',
96 'dst_ip': '152.16.40.20',
97 'type': 'PCI-PASSTHROUGH',
98 'vld_id': 'downlink_0',
101 'vnfd-connection-point-ref': 'xe1',
109 'network': '0064:ff9b:0:0:0:0:9810:6414',
110 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
115 'network': '0064:ff9b:0:0:0:0:9810:2814',
116 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
119 'id': 'udpreplayvnf-baremetal',
120 'name': 'udpreplayvnf-baremetal',
123 'description': 'UDPReplay approximation using DPDK',
126 'vdu-id': 'udpreplay-baremetal',
139 'connection-point': [
149 'id': 'UdpReplayApproxVnf',
157 "allowed_drop_rate": "0.8 - 1",
160 "rules": "acl_1rule.yaml",
164 "worker_config": "1C/1T",
170 "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7",
171 "tc": "tc_ipv4_1Mflow_64B_packetsize",
173 "object": "NetworkServiceTestCase",
175 "output_filename": "/tmp/yardstick.out",
176 "runner_id": 74476, "duration": 400,
179 "traffic_profile": "ipv4_throughput_acl.yaml",
181 "flow": "ipv4_Packets_acl.yaml",
182 "imix": "imix_voice.yaml"
186 "tg__2": "trafficgen_2.yardstick",
187 "tg__1": "trafficgen_1.yardstick",
188 "vnf__1": "vnf.yardstick"
190 "topology": "udpreplay-tg-topology-baremetal.yaml"
196 "vnfd-id-ref": "vnf__1",
200 "local_iface_name": "ens786f0",
201 "vld_id": UdpReplayApproxVnf.UPLINK,
202 "netmask": "255.255.255.0",
203 "vpci": "0000:05:00.0",
204 "local_ip": "152.16.100.19",
206 "dst_ip": "152.16.100.20",
207 "local_mac": "00:00:00:00:00:02",
208 "dst_mac": "00:00:00:00:00:04",
212 "local_iface_name": "ens786f1",
213 "vld_id": UdpReplayApproxVnf.DOWNLINK,
214 "netmask": "255.255.255.0",
215 "vpci": "0000:05:00.1",
216 "local_ip": "152.16.40.19",
218 "dst_ip": "152.16.40.20",
219 "local_mac": "00:00:00:00:00:01",
220 "dst_mac": "00:00:00:00:00:03",
230 "gateway": "0064:ff9b:0:0:0:0:9810:6414",
231 "network": "0064:ff9b:0:0:0:0:9810:6414"
236 "gateway": "0064:ff9b:0:0:0:0:9810:2814",
237 "network": "0064:ff9b:0:0:0:0:9810:2814"
241 "VNF model": "udp_replay.yaml",
242 "name": "vnf.yardstick",
243 "member-vnf-index": "2",
246 "netmask": "255.255.255.0",
248 "gateway": "152.16.100.20",
249 "network": "152.16.100.20"
252 "netmask": "255.255.255.0",
254 "gateway": "152.16.40.20",
255 "network": "152.16.40.20"
260 "trafficgen_2.yardstick": {
261 "member-vnf-index": "3",
262 "role": "TrafficGen",
263 "name": "trafficgen_2.yardstick",
264 "vnfd-id-ref": "tg__2",
268 "local_iface_name": "ens513f0",
269 "vld_id": UdpReplayApproxVnf.DOWNLINK,
270 "netmask": "255.255.255.0",
271 "vpci": "0000:02:00.0",
272 "local_ip": "152.16.40.20",
274 "dst_ip": "152.16.40.19",
275 "local_mac": "00:00:00:00:00:03",
276 "dst_mac": "00:00:00:00:00:01",
280 "local_iface_name": "ens513f1",
281 "netmask": "255.255.255.0",
282 "network": "202.16.100.0",
283 "local_ip": "202.16.100.20",
285 "local_mac": "00:1e:67:d0:60:5d",
286 "vpci": "0000:02:00.1",
291 "VNF model": "l3fwd_vnf.yaml",
294 "trafficgen_1.yardstick": {
295 "member-vnf-index": "1",
296 "role": "TrafficGen",
297 "name": "trafficgen_1.yardstick",
298 "vnfd-id-ref": "tg__1",
302 "local_iface_name": "ens785f0",
303 "vld_id": UdpReplayApproxVnf.UPLINK,
304 "netmask": "255.255.255.0",
305 "vpci": "0000:05:00.0",
306 "local_ip": "152.16.100.20",
308 "dst_ip": "152.16.100.19",
309 "local_mac": "00:00:00:00:00:04",
310 "dst_mac": "00:00:00:00:00:02",
314 "local_ip": "152.16.100.21",
316 "vpci": "0000:05:00.1",
318 "local_iface_name": "ens785f1",
319 "netmask": "255.255.255.0",
320 "local_mac": "00:00:00:00:00:01"
324 "VNF model": "tg_rfc2544_tpl.yaml",
330 def test___init__(self, *args):
331 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
332 self.assertIsNone(udp_replay_approx_vnf._vnf_process)
334 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
335 @mock.patch(SSH_HELPER)
336 def test_collect_kpi(self, ssh, *args):
340 result = "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
341 "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
342 "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
343 "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
344 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
345 udp_replay_approx_vnf.q_in = mock.MagicMock()
346 udp_replay_approx_vnf.q_out = mock.MagicMock()
347 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
348 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
349 udp_replay_approx_vnf.get_stats = mock.Mock(return_value=result)
350 result = {'collect_stats': {}, 'packets_dropped': 0,
351 'packets_fwd': 14748451, 'packets_in': 14748472}
352 self.assertEqual(result, udp_replay_approx_vnf.collect_kpi())
354 @mock.patch(SSH_HELPER)
355 def test_get_stats(self, ssh, *args):
358 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
359 udp_replay_approx_vnf.q_in = mock.MagicMock()
360 udp_replay_approx_vnf.q_out = mock.MagicMock()
361 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
363 "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
365 udp_replay_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
367 self.assertEqual(mock_result,
368 udp_replay_approx_vnf.get_stats())
370 def _get_file_abspath(self, filename):
371 curr_path = os.path.dirname(os.path.abspath(__file__))
372 file_path = os.path.join(curr_path, filename)
375 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
376 @mock.patch(SSH_HELPER)
377 def test__build_config(self, ssh, mock_context, *args):
380 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
381 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
382 udp_replay_approx_vnf.nfvi_context = mock_context
383 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
384 udp_replay_approx_vnf.setup_helper.bound_pci = []
385 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
386 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
387 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
389 cmd_line = udp_replay_approx_vnf._build_config()
392 "sudo tool_path --log-level=5 -c 0x7 -n 4 -w -- -p 0x3 --config='(0,0,1),(1,0,2)'"
393 self.assertEqual(cmd_line, expected)
395 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
396 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
397 @mock.patch(SSH_HELPER)
398 def test__build_pipeline_kwargs(self, ssh, mock_context, *args):
400 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
401 udp_replay_approx_vnf.nfvi_context = mock_context
402 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
403 udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3']
404 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
405 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
406 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
407 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
409 udp_replay_approx_vnf._build_pipeline_kwargs()
411 self.assertEqual(udp_replay_approx_vnf.pipeline_kwargs, {
412 'config': '(0,0,1),(1,0,2)',
413 'cpu_mask_hex': '0x7',
415 'port_mask_hex': '0x3',
416 'tool_path': 'tool_path',
417 'whitelist': '0000:00:0.1 -w 0000:00:0.3'
420 @mock.patch(SSH_HELPER)
421 def test_run_udp_replay(self, ssh, *args):
424 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
425 udp_replay_approx_vnf._build_config = mock.MagicMock()
426 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
427 udp_replay_approx_vnf.scenario_helper = mock.MagicMock()
429 udp_replay_approx_vnf._run()
431 udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
433 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
434 @mock.patch(SSH_HELPER)
435 def test_instantiate(self, ssh, *args):
438 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
439 udp_replay_approx_vnf.q_out.put("Replay>")
440 udp_replay_approx_vnf.WAIT_TIME = 0
441 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
443 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
444 udp_replay_approx_vnf.deploy_vnfs = mock.MagicMock()
445 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
447 udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1)
448 udp_replay_approx_vnf._vnf_process.exitcode = 0
450 self.assertEqual(udp_replay_approx_vnf.wait_for_instantiate(), 0)
452 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
453 @mock.patch('yardstick.ssh.SSH')
454 @mock.patch(SSH_HELPER)
455 def test_instantiate_panic(self, *args):
456 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
457 udp_replay_approx_vnf.WAIT_TIME = 0
458 udp_replay_approx_vnf.q_out.put("some text PANIC some text")
459 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
461 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
462 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
463 with self.assertRaises(RuntimeError):
464 udp_replay_approx_vnf.wait_for_instantiate()
466 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
467 @mock.patch(SSH_HELPER)
468 def test_terminate(self, ssh, *args):
471 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
472 udp_replay_approx_vnf._vnf_process = mock.MagicMock()
473 udp_replay_approx_vnf._vnf_process.terminate = mock.Mock()
474 udp_replay_approx_vnf.used_drivers = {"01:01.0": "i40e", "01:01.1": "i40e"}
475 udp_replay_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
476 self.assertEqual(None, udp_replay_approx_vnf.terminate())