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
22 from yardstick.benchmark.contexts import base as ctx_base
25 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.udp_replay import UdpReplayApproxVnf
33 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper
36 TEST_FILE_YAML = 'nsb_test_case.yaml'
42 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
43 class TestUdpReplayApproxVnf(unittest.TestCase):
46 'short-name': 'UdpReplayVnf',
49 'description': 'UDPReplay approximation using DPDK',
52 'netmask': '255.255.255.0',
54 'network': '152.16.100.20',
55 'gateway': '152.16.100.20',
58 'netmask': '255.255.255.0',
60 'network': '152.16.40.20',
61 'gateway': '152.16.40.20',
64 'external-interface': [
66 'virtual-interface': {
67 'dst_mac': '00:00:00:00:00:04',
69 'local_iface_name': 'xe0',
70 'bandwidth': '10 Gbps',
71 'local_ip': '152.16.100.19',
72 'local_mac': '00:00:00:00:00:02',
73 'vpci': '0000:05:00.0',
75 'netmask': '255.255.255.0',
76 'dst_ip': '152.16.100.20',
77 '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',
97 'vld_id': 'downlink_0',
100 'vnfd-connection-point-ref': 'xe1',
108 'network': '0064:ff9b:0:0:0:0:9810:6414',
109 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
114 'network': '0064:ff9b:0:0:0:0:9810:2814',
115 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
118 'id': 'udpreplayvnf-baremetal',
119 'name': 'udpreplayvnf-baremetal',
122 'description': 'UDPReplay approximation using DPDK',
125 'vdu-id': 'udpreplay-baremetal',
138 'connection-point': [
148 'id': 'UdpReplayApproxVnf',
156 "allowed_drop_rate": "0.8 - 1",
159 "rules": "acl_1rule.yaml",
163 "worker_config": "1C/1T",
169 "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7",
170 "tc": "tc_ipv4_1Mflow_64B_packetsize",
172 "object": "NetworkServiceTestCase",
174 "output_filename": "/tmp/yardstick.out",
175 "runner_id": 74476, "duration": 400,
178 "traffic_profile": "ipv4_throughput_acl.yaml",
180 "flow": "ipv4_Packets_acl.yaml",
181 "imix": "imix_voice.yaml"
185 "tg__2": "trafficgen_2.yardstick",
186 "tg__1": "trafficgen_1.yardstick",
187 "vnf__1": "vnf.yardstick"
189 "topology": "udpreplay-tg-topology-baremetal.yaml"
195 "vnfd-id-ref": "vnf__1",
199 "local_iface_name": "ens786f0",
200 "vld_id": UdpReplayApproxVnf.UPLINK,
201 "netmask": "255.255.255.0",
202 "vpci": "0000:05:00.0",
203 "local_ip": "152.16.100.19",
205 "dst_ip": "152.16.100.20",
206 "local_mac": "00:00:00:00:00:02",
207 "dst_mac": "00:00:00:00:00:04",
211 "local_iface_name": "ens786f1",
212 "vld_id": UdpReplayApproxVnf.DOWNLINK,
213 "netmask": "255.255.255.0",
214 "vpci": "0000:05:00.1",
215 "local_ip": "152.16.40.19",
217 "dst_ip": "152.16.40.20",
218 "local_mac": "00:00:00:00:00:01",
219 "dst_mac": "00:00:00:00:00:03",
229 "gateway": "0064:ff9b:0:0:0:0:9810:6414",
230 "network": "0064:ff9b:0:0:0:0:9810:6414"
235 "gateway": "0064:ff9b:0:0:0:0:9810:2814",
236 "network": "0064:ff9b:0:0:0:0:9810:2814"
240 "VNF model": "udp_replay.yaml",
241 "name": "vnf.yardstick",
242 "member-vnf-index": "2",
245 "netmask": "255.255.255.0",
247 "gateway": "152.16.100.20",
248 "network": "152.16.100.20"
251 "netmask": "255.255.255.0",
253 "gateway": "152.16.40.20",
254 "network": "152.16.40.20"
259 "trafficgen_2.yardstick": {
260 "member-vnf-index": "3",
261 "role": "TrafficGen",
262 "name": "trafficgen_2.yardstick",
263 "vnfd-id-ref": "tg__2",
267 "local_iface_name": "ens513f0",
268 "vld_id": UdpReplayApproxVnf.DOWNLINK,
269 "netmask": "255.255.255.0",
270 "vpci": "0000:02:00.0",
271 "local_ip": "152.16.40.20",
273 "dst_ip": "152.16.40.19",
274 "local_mac": "00:00:00:00:00:03",
275 "dst_mac": "00:00:00:00:00:01",
279 "local_iface_name": "ens513f1",
280 "netmask": "255.255.255.0",
281 "network": "202.16.100.0",
282 "local_ip": "202.16.100.20",
284 "local_mac": "00:1e:67:d0:60:5d",
285 "vpci": "0000:02:00.1",
290 "VNF model": "l3fwd_vnf.yaml",
293 "trafficgen_1.yardstick": {
294 "member-vnf-index": "1",
295 "role": "TrafficGen",
296 "name": "trafficgen_1.yardstick",
297 "vnfd-id-ref": "tg__1",
301 "local_iface_name": "ens785f0",
302 "vld_id": UdpReplayApproxVnf.UPLINK,
303 "netmask": "255.255.255.0",
304 "vpci": "0000:05:00.0",
305 "local_ip": "152.16.100.20",
307 "dst_ip": "152.16.100.19",
308 "local_mac": "00:00:00:00:00:04",
309 "dst_mac": "00:00:00:00:00:02",
313 "local_ip": "152.16.100.21",
315 "vpci": "0000:05:00.1",
317 "local_iface_name": "ens785f1",
318 "netmask": "255.255.255.0",
319 "local_mac": "00:00:00:00:00:01"
323 "VNF model": "tg_rfc2544_tpl.yaml",
329 def test___init__(self, *args):
330 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
331 self.assertIsNone(udp_replay_approx_vnf._vnf_process)
333 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
334 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
335 @mock.patch(SSH_HELPER)
336 def test_collect_kpi(self, ssh, *args):
340 get_stats_ret_val = \
341 "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
342 "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
343 "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
344 "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
345 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
346 udp_replay_approx_vnf.scenario_helper.scenario_cfg = {
347 'nodes': {udp_replay_approx_vnf.name: "mock"}
349 udp_replay_approx_vnf.q_in = mock.MagicMock()
350 udp_replay_approx_vnf.q_out = mock.MagicMock()
351 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
352 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
353 udp_replay_approx_vnf.get_stats = mock.Mock(return_value=get_stats_ret_val)
355 'physical_node': 'mock_node',
357 'packets_dropped': 0,
358 'packets_fwd': 14748451,
359 'packets_in': 14748472
361 self.assertEqual(result, udp_replay_approx_vnf.collect_kpi())
363 @mock.patch(SSH_HELPER)
364 def test_get_stats(self, ssh, *args):
367 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
368 udp_replay_approx_vnf.q_in = mock.MagicMock()
369 udp_replay_approx_vnf.q_out = mock.MagicMock()
370 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
372 "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
374 udp_replay_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
376 self.assertEqual(mock_result,
377 udp_replay_approx_vnf.get_stats())
379 def _get_file_abspath(self, filename):
380 curr_path = os.path.dirname(os.path.abspath(__file__))
381 file_path = os.path.join(curr_path, filename)
384 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
385 @mock.patch(SSH_HELPER)
386 def test__build_config(self, ssh, mock_get_ctx, *args):
389 nfvi_context = mock.Mock()
390 nfvi_context.attrs = {'nfvi_type': 'baremetal'}
391 mock_get_ctx.return_value = nfvi_context
393 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
394 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
395 udp_replay_approx_vnf.nfvi_context = mock_get_ctx
396 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
397 udp_replay_approx_vnf.setup_helper.bound_pci = []
398 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
399 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
400 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
402 cmd_line = udp_replay_approx_vnf._build_config()
405 "sudo tool_path --log-level=5 -c 0x7 -n 4 -w -- -p 0x3 --config='(0,0,1),(1,0,2)'"
406 self.assertEqual(cmd_line, expected)
408 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
409 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
410 @mock.patch(SSH_HELPER)
411 def test__build_pipeline_kwargs(self, ssh, mock_get_ctx, *args):
414 nfvi_context = mock.Mock()
415 nfvi_context.attrs = {'nfvi_type': "baremetal"}
416 mock_get_ctx.return_value = nfvi_context
418 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
419 udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3']
420 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
421 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
422 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
423 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
425 udp_replay_approx_vnf._build_pipeline_kwargs()
427 self.assertEqual(udp_replay_approx_vnf.pipeline_kwargs, {
428 'config': '(0,0,1),(1,0,2)',
429 'cpu_mask_hex': '0x7',
431 'port_mask_hex': '0x3',
432 'tool_path': 'tool_path',
433 'whitelist': '0000:00:0.1 -w 0000:00:0.3'
436 @mock.patch(SSH_HELPER)
437 def test_run_udp_replay(self, ssh, *args):
440 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
441 udp_replay_approx_vnf._build_config = mock.MagicMock()
442 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
443 udp_replay_approx_vnf.scenario_helper = mock.MagicMock()
445 udp_replay_approx_vnf._run()
447 udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
449 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
450 @mock.patch(SSH_HELPER)
451 def test_instantiate(self, ssh, *args):
454 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
455 udp_replay_approx_vnf.q_out.put("Replay>")
456 udp_replay_approx_vnf.WAIT_TIME = 0
457 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
459 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
460 udp_replay_approx_vnf.deploy_vnfs = mock.MagicMock()
461 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
463 udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1)
464 udp_replay_approx_vnf._vnf_process.exitcode = 0
466 self.assertEqual(udp_replay_approx_vnf.wait_for_instantiate(), 0)
468 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
469 @mock.patch('yardstick.ssh.SSH')
470 @mock.patch(SSH_HELPER)
471 def test_instantiate_panic(self, *args):
472 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
473 udp_replay_approx_vnf.WAIT_TIME = 0
474 udp_replay_approx_vnf.q_out.put("some text PANIC some text")
475 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
477 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
478 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
479 with self.assertRaises(RuntimeError):
480 udp_replay_approx_vnf.wait_for_instantiate()