1 # Copyright (c) 2016-2019 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.
19 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
20 from yardstick.benchmark.contexts import base as ctx_base
21 from yardstick.network_services.vnf_generic.vnf.udp_replay import UdpReplayApproxVnf
22 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper
25 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
27 TEST_FILE_YAML = 'nsb_test_case.yaml'
32 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
33 class TestUdpReplayApproxVnf(unittest.TestCase):
36 'short-name': 'UdpReplayVnf',
39 'description': 'UDPReplay approximation using DPDK',
42 'netmask': '255.255.255.0',
44 'network': '152.16.100.20',
45 'gateway': '152.16.100.20',
48 'netmask': '255.255.255.0',
50 'network': '152.16.40.20',
51 'gateway': '152.16.40.20',
54 'external-interface': [
56 'virtual-interface': {
57 'dst_mac': '00:00:00:00:00:04',
59 'local_iface_name': 'xe0',
60 'bandwidth': '10 Gbps',
61 'local_ip': '152.16.100.19',
62 'local_mac': '00:00:00:00:00:02',
63 'vpci': '0000:05:00.0',
65 'netmask': '255.255.255.0',
66 'dst_ip': '152.16.100.20',
67 'type': 'PCI-PASSTHROUGH',
71 'vnfd-connection-point-ref': 'xe0',
75 'virtual-interface': {
76 'dst_mac': '00:00:00:00:00:03',
78 'local_iface_name': 'xe1',
79 'bandwidth': '10 Gbps',
80 'local_ip': '152.16.40.19',
81 'local_mac': '00:00:00:00:00:01',
82 'vpci': '0000:05:00.1',
84 'netmask': '255.255.255.0',
85 'dst_ip': '152.16.40.20',
86 'type': 'PCI-PASSTHROUGH',
87 'vld_id': 'downlink_0',
90 'vnfd-connection-point-ref': 'xe1',
98 'network': '0064:ff9b:0:0:0:0:9810:6414',
99 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
104 'network': '0064:ff9b:0:0:0:0:9810:2814',
105 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
108 'id': 'udpreplayvnf-baremetal',
109 'name': 'udpreplayvnf-baremetal',
112 'description': 'UDPReplay approximation using DPDK',
115 'vdu-id': 'udpreplay-baremetal',
128 'connection-point': [
138 'id': 'UdpReplayApproxVnf',
146 "allowed_drop_rate": "0.8 - 1",
149 "rules": "acl_1rule.yaml",
153 "worker_config": "1C/1T",
159 "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7",
160 "tc": "tc_ipv4_1Mflow_64B_packetsize",
162 "object": "NetworkServiceTestCase",
164 "output_filename": "/tmp/yardstick.out",
165 "runner_id": 74476, "duration": 400,
168 "traffic_profile": "ipv4_throughput_acl.yaml",
170 "flow": "ipv4_Packets_acl.yaml",
171 "imix": "imix_voice.yaml"
175 "tg__2": "trafficgen_2.yardstick",
176 "tg__1": "trafficgen_1.yardstick",
177 "vnf__1": "vnf.yardstick"
179 "topology": "udpreplay-tg-topology-baremetal.yaml"
185 "vnfd-id-ref": "vnf__1",
189 "local_iface_name": "ens786f0",
190 "vld_id": UdpReplayApproxVnf.UPLINK,
191 "netmask": "255.255.255.0",
192 "vpci": "0000:05:00.0",
193 "local_ip": "152.16.100.19",
195 "dst_ip": "152.16.100.20",
196 "local_mac": "00:00:00:00:00:02",
197 "dst_mac": "00:00:00:00:00:04",
201 "local_iface_name": "ens786f1",
202 "vld_id": UdpReplayApproxVnf.DOWNLINK,
203 "netmask": "255.255.255.0",
204 "vpci": "0000:05:00.1",
205 "local_ip": "152.16.40.19",
207 "dst_ip": "152.16.40.20",
208 "local_mac": "00:00:00:00:00:01",
209 "dst_mac": "00:00:00:00:00:03",
219 "gateway": "0064:ff9b:0:0:0:0:9810:6414",
220 "network": "0064:ff9b:0:0:0:0:9810:6414"
225 "gateway": "0064:ff9b:0:0:0:0:9810:2814",
226 "network": "0064:ff9b:0:0:0:0:9810:2814"
230 "VNF model": "udp_replay.yaml",
231 "name": "vnf.yardstick",
232 "member-vnf-index": "2",
235 "netmask": "255.255.255.0",
237 "gateway": "152.16.100.20",
238 "network": "152.16.100.20"
241 "netmask": "255.255.255.0",
243 "gateway": "152.16.40.20",
244 "network": "152.16.40.20"
249 "trafficgen_2.yardstick": {
250 "member-vnf-index": "3",
251 "role": "TrafficGen",
252 "name": "trafficgen_2.yardstick",
253 "vnfd-id-ref": "tg__2",
257 "local_iface_name": "ens513f0",
258 "vld_id": UdpReplayApproxVnf.DOWNLINK,
259 "netmask": "255.255.255.0",
260 "vpci": "0000:02:00.0",
261 "local_ip": "152.16.40.20",
263 "dst_ip": "152.16.40.19",
264 "local_mac": "00:00:00:00:00:03",
265 "dst_mac": "00:00:00:00:00:01",
269 "local_iface_name": "ens513f1",
270 "netmask": "255.255.255.0",
271 "network": "202.16.100.0",
272 "local_ip": "202.16.100.20",
274 "local_mac": "00:1e:67:d0:60:5d",
275 "vpci": "0000:02:00.1",
280 "VNF model": "l3fwd_vnf.yaml",
283 "trafficgen_1.yardstick": {
284 "member-vnf-index": "1",
285 "role": "TrafficGen",
286 "name": "trafficgen_1.yardstick",
287 "vnfd-id-ref": "tg__1",
291 "local_iface_name": "ens785f0",
292 "vld_id": UdpReplayApproxVnf.UPLINK,
293 "netmask": "255.255.255.0",
294 "vpci": "0000:05:00.0",
295 "local_ip": "152.16.100.20",
297 "dst_ip": "152.16.100.19",
298 "local_mac": "00:00:00:00:00:04",
299 "dst_mac": "00:00:00:00:00:02",
303 "local_ip": "152.16.100.21",
305 "vpci": "0000:05:00.1",
307 "local_iface_name": "ens785f1",
308 "netmask": "255.255.255.0",
309 "local_mac": "00:00:00:00:00:01"
313 "VNF model": "tg_rfc2544_tpl.yaml",
319 def test___init__(self, *args):
320 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
321 self.assertIsNone(udp_replay_approx_vnf._vnf_process)
323 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
324 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
325 @mock.patch(SSH_HELPER)
326 def test_collect_kpi(self, ssh, *args):
330 get_stats_ret_val = \
331 "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
332 "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
333 "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
334 "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
335 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
336 udp_replay_approx_vnf.scenario_helper.scenario_cfg = {
337 'nodes': {udp_replay_approx_vnf.name: "mock"}
339 udp_replay_approx_vnf.q_in = mock.MagicMock()
340 udp_replay_approx_vnf.q_out = mock.MagicMock()
341 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
342 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
343 udp_replay_approx_vnf.get_stats = mock.Mock(return_value=get_stats_ret_val)
345 'physical_node': 'mock_node',
347 'packets_dropped': 0,
348 'packets_fwd': 14748451,
349 'packets_in': 14748472
351 self.assertEqual(result, udp_replay_approx_vnf.collect_kpi())
353 @mock.patch(SSH_HELPER)
354 def test_get_stats(self, ssh, *args):
357 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
358 udp_replay_approx_vnf.q_in = mock.MagicMock()
359 udp_replay_approx_vnf.q_out = mock.MagicMock()
360 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
362 "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
364 udp_replay_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
366 self.assertEqual(mock_result,
367 udp_replay_approx_vnf.get_stats())
369 def _get_file_abspath(self, filename):
370 curr_path = os.path.dirname(os.path.abspath(__file__))
371 file_path = os.path.join(curr_path, filename)
374 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
375 @mock.patch(SSH_HELPER)
376 def test__build_config(self, ssh, mock_get_ctx, *args):
379 nfvi_context = mock.Mock()
380 nfvi_context.attrs = {'nfvi_type': 'baremetal'}
381 mock_get_ctx.return_value = nfvi_context
383 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
384 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
385 udp_replay_approx_vnf.nfvi_context = mock_get_ctx
386 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
387 udp_replay_approx_vnf.setup_helper.bound_pci = []
388 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
389 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
390 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
392 cmd_line = udp_replay_approx_vnf._build_config()
395 "sudo tool_path --log-level=5 -c 0x7 -n 4 -w -- -p 0x3 --config='(0,0,1),(1,0,2)'"
396 self.assertEqual(cmd_line, expected)
398 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
399 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
400 @mock.patch(SSH_HELPER)
401 def test__build_pipeline_kwargs(self, ssh, mock_get_ctx, *args):
404 nfvi_context = mock.Mock()
405 nfvi_context.attrs = {'nfvi_type': "baremetal"}
406 mock_get_ctx.return_value = nfvi_context
408 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
409 udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3']
410 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
411 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
412 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
413 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
415 udp_replay_approx_vnf._build_pipeline_kwargs()
417 self.assertEqual(udp_replay_approx_vnf.pipeline_kwargs, {
418 'config': '(0,0,1),(1,0,2)',
419 'cpu_mask_hex': '0x7',
421 'port_mask_hex': '0x3',
422 'tool_path': 'tool_path',
423 'whitelist': '0000:00:0.1 -w 0000:00:0.3'
426 @mock.patch(SSH_HELPER)
427 def test_run_udp_replay(self, ssh, *args):
430 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
431 udp_replay_approx_vnf._build_config = mock.MagicMock()
432 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
433 udp_replay_approx_vnf.scenario_helper = mock.MagicMock()
435 udp_replay_approx_vnf._run()
437 udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
439 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
440 @mock.patch(SSH_HELPER)
441 def test_instantiate(self, ssh, *args):
444 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
445 udp_replay_approx_vnf.q_out.put("Replay>")
446 udp_replay_approx_vnf.WAIT_TIME = 0
447 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
449 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
450 udp_replay_approx_vnf.deploy_vnfs = mock.MagicMock()
451 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
453 udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1)
454 udp_replay_approx_vnf._vnf_process.exitcode = 0
456 self.assertEqual(udp_replay_approx_vnf.wait_for_instantiate(), 0)
458 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
459 @mock.patch('yardstick.ssh.SSH')
460 @mock.patch(SSH_HELPER)
461 def test_instantiate_panic(self, *args):
462 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
463 udp_replay_approx_vnf.WAIT_TIME = 0
464 udp_replay_approx_vnf.q_out.put("some text PANIC some text")
465 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
467 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
468 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
469 with self.assertRaises(RuntimeError):
470 udp_replay_approx_vnf.wait_for_instantiate()