1 # Copyright (c) 2016-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.
20 from yardstick.tests import STL_MOCKS
21 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
24 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
26 STLClient = mock.MagicMock()
27 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
31 from yardstick.network_services.vnf_generic.vnf.udp_replay import UdpReplayApproxVnf
32 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper
35 TEST_FILE_YAML = 'nsb_test_case.yaml'
41 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
42 class TestUdpReplayApproxVnf(unittest.TestCase):
45 'short-name': 'UdpReplayVnf',
48 'description': 'UDPReplay approximation using DPDK',
51 'netmask': '255.255.255.0',
53 'network': '152.16.100.20',
54 'gateway': '152.16.100.20',
57 'netmask': '255.255.255.0',
59 'network': '152.16.40.20',
60 'gateway': '152.16.40.20',
63 'external-interface': [
65 'virtual-interface': {
66 'dst_mac': '00:00:00:00:00:04',
68 'local_iface_name': 'xe0',
69 'bandwidth': '10 Gbps',
70 'local_ip': '152.16.100.19',
71 'local_mac': '00:00:00:00:00:02',
72 'vpci': '0000:05:00.0',
74 'netmask': '255.255.255.0',
75 'dst_ip': '152.16.100.20',
76 'type': 'PCI-PASSTHROUGH',
80 'vnfd-connection-point-ref': 'xe0',
84 'virtual-interface': {
85 'dst_mac': '00:00:00:00:00:03',
87 'local_iface_name': 'xe1',
88 'bandwidth': '10 Gbps',
89 'local_ip': '152.16.40.19',
90 'local_mac': '00:00:00:00:00:01',
91 'vpci': '0000:05:00.1',
93 'netmask': '255.255.255.0',
94 'dst_ip': '152.16.40.20',
95 'type': 'PCI-PASSTHROUGH',
96 'vld_id': 'downlink_0',
99 'vnfd-connection-point-ref': 'xe1',
107 'network': '0064:ff9b:0:0:0:0:9810:6414',
108 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
113 'network': '0064:ff9b:0:0:0:0:9810:2814',
114 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
117 'id': 'udpreplayvnf-baremetal',
118 'name': 'udpreplayvnf-baremetal',
121 'description': 'UDPReplay approximation using DPDK',
124 'vdu-id': 'udpreplay-baremetal',
137 'connection-point': [
147 'id': 'UdpReplayApproxVnf',
155 "allowed_drop_rate": "0.8 - 1",
158 "rules": "acl_1rule.yaml",
162 "worker_config": "1C/1T",
168 "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7",
169 "tc": "tc_ipv4_1Mflow_64B_packetsize",
171 "object": "NetworkServiceTestCase",
173 "output_filename": "/tmp/yardstick.out",
174 "runner_id": 74476, "duration": 400,
177 "traffic_profile": "ipv4_throughput_acl.yaml",
179 "flow": "ipv4_Packets_acl.yaml",
180 "imix": "imix_voice.yaml"
184 "tg__2": "trafficgen_2.yardstick",
185 "tg__1": "trafficgen_1.yardstick",
186 "vnf__1": "vnf.yardstick"
188 "topology": "udpreplay-tg-topology-baremetal.yaml"
194 "vnfd-id-ref": "vnf__1",
198 "local_iface_name": "ens786f0",
199 "vld_id": UdpReplayApproxVnf.UPLINK,
200 "netmask": "255.255.255.0",
201 "vpci": "0000:05:00.0",
202 "local_ip": "152.16.100.19",
204 "dst_ip": "152.16.100.20",
205 "local_mac": "00:00:00:00:00:02",
206 "dst_mac": "00:00:00:00:00:04",
210 "local_iface_name": "ens786f1",
211 "vld_id": UdpReplayApproxVnf.DOWNLINK,
212 "netmask": "255.255.255.0",
213 "vpci": "0000:05:00.1",
214 "local_ip": "152.16.40.19",
216 "dst_ip": "152.16.40.20",
217 "local_mac": "00:00:00:00:00:01",
218 "dst_mac": "00:00:00:00:00:03",
228 "gateway": "0064:ff9b:0:0:0:0:9810:6414",
229 "network": "0064:ff9b:0:0:0:0:9810:6414"
234 "gateway": "0064:ff9b:0:0:0:0:9810:2814",
235 "network": "0064:ff9b:0:0:0:0:9810:2814"
239 "VNF model": "udp_replay.yaml",
240 "name": "vnf.yardstick",
241 "member-vnf-index": "2",
244 "netmask": "255.255.255.0",
246 "gateway": "152.16.100.20",
247 "network": "152.16.100.20"
250 "netmask": "255.255.255.0",
252 "gateway": "152.16.40.20",
253 "network": "152.16.40.20"
258 "trafficgen_2.yardstick": {
259 "member-vnf-index": "3",
260 "role": "TrafficGen",
261 "name": "trafficgen_2.yardstick",
262 "vnfd-id-ref": "tg__2",
266 "local_iface_name": "ens513f0",
267 "vld_id": UdpReplayApproxVnf.DOWNLINK,
268 "netmask": "255.255.255.0",
269 "vpci": "0000:02:00.0",
270 "local_ip": "152.16.40.20",
272 "dst_ip": "152.16.40.19",
273 "local_mac": "00:00:00:00:00:03",
274 "dst_mac": "00:00:00:00:00:01",
278 "local_iface_name": "ens513f1",
279 "netmask": "255.255.255.0",
280 "network": "202.16.100.0",
281 "local_ip": "202.16.100.20",
283 "local_mac": "00:1e:67:d0:60:5d",
284 "vpci": "0000:02:00.1",
289 "VNF model": "l3fwd_vnf.yaml",
292 "trafficgen_1.yardstick": {
293 "member-vnf-index": "1",
294 "role": "TrafficGen",
295 "name": "trafficgen_1.yardstick",
296 "vnfd-id-ref": "tg__1",
300 "local_iface_name": "ens785f0",
301 "vld_id": UdpReplayApproxVnf.UPLINK,
302 "netmask": "255.255.255.0",
303 "vpci": "0000:05:00.0",
304 "local_ip": "152.16.100.20",
306 "dst_ip": "152.16.100.19",
307 "local_mac": "00:00:00:00:00:04",
308 "dst_mac": "00:00:00:00:00:02",
312 "local_ip": "152.16.100.21",
314 "vpci": "0000:05:00.1",
316 "local_iface_name": "ens785f1",
317 "netmask": "255.255.255.0",
318 "local_mac": "00:00:00:00:00:01"
322 "VNF model": "tg_rfc2544_tpl.yaml",
328 def test___init__(self, *args):
329 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
330 self.assertIsNone(udp_replay_approx_vnf._vnf_process)
332 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
333 @mock.patch(SSH_HELPER)
334 def test_collect_kpi(self, ssh, *args):
338 get_stats_ret_val = \
339 "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
340 "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
341 "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
342 "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
343 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
344 udp_replay_approx_vnf.q_in = mock.MagicMock()
345 udp_replay_approx_vnf.q_out = mock.MagicMock()
346 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
347 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
348 udp_replay_approx_vnf.get_stats = mock.Mock(return_value=get_stats_ret_val)
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()