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.
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,
322 self.assertIsNone(udp_replay_approx_vnf._vnf_process)
324 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
325 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
326 @mock.patch(SSH_HELPER)
327 def test_collect_kpi(self, ssh, *args):
331 get_stats_ret_val = \
332 "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
333 "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
334 "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
335 "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
336 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd, 'task_id')
337 udp_replay_approx_vnf.scenario_helper.scenario_cfg = {
338 'nodes': {udp_replay_approx_vnf.name: "mock"}
340 udp_replay_approx_vnf.q_in = mock.MagicMock()
341 udp_replay_approx_vnf.q_out = mock.MagicMock()
342 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
343 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
344 udp_replay_approx_vnf.get_stats = mock.Mock(return_value=get_stats_ret_val)
346 'physical_node': 'mock_node',
348 'packets_dropped': 0,
349 'packets_fwd': 14748451,
350 '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,
360 udp_replay_approx_vnf.q_in = mock.MagicMock()
361 udp_replay_approx_vnf.q_out = mock.MagicMock()
362 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
364 "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
366 udp_replay_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
368 self.assertEqual(mock_result,
369 udp_replay_approx_vnf.get_stats())
371 def _get_file_abspath(self, filename):
372 curr_path = os.path.dirname(os.path.abspath(__file__))
373 file_path = os.path.join(curr_path, filename)
376 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
377 @mock.patch(SSH_HELPER)
378 def test__build_config(self, ssh, mock_get_ctx, *args):
381 nfvi_context = mock.Mock()
382 nfvi_context.attrs = {'nfvi_type': 'baremetal'}
383 mock_get_ctx.return_value = nfvi_context
385 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
387 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
388 udp_replay_approx_vnf.nfvi_context = mock_get_ctx
389 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
390 udp_replay_approx_vnf.setup_helper.bound_pci = []
391 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
392 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
393 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
395 cmd_line = udp_replay_approx_vnf._build_config()
398 "sudo tool_path --log-level=5 -c 0x7 -n 4 -w -- -p 0x3 --config='(0,0,1),(1,0,2)'"
399 self.assertEqual(cmd_line, expected)
401 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
402 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
403 @mock.patch(SSH_HELPER)
404 def test__build_pipeline_kwargs(self, ssh, mock_get_ctx, *args):
407 nfvi_context = mock.Mock()
408 nfvi_context.attrs = {'nfvi_type': "baremetal"}
409 mock_get_ctx.return_value = nfvi_context
411 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
413 udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3']
414 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
415 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
416 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
417 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
419 udp_replay_approx_vnf._build_pipeline_kwargs()
421 self.assertEqual(udp_replay_approx_vnf.pipeline_kwargs, {
422 'config': '(0,0,1),(1,0,2)',
423 'cpu_mask_hex': '0x7',
425 'port_mask_hex': '0x3',
426 'tool_path': 'tool_path',
427 'whitelist': '0000:00:0.1 -w 0000:00:0.3'
430 @mock.patch(SSH_HELPER)
431 def test_run_udp_replay(self, ssh, *args):
434 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
436 udp_replay_approx_vnf._build_config = mock.MagicMock()
437 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
438 udp_replay_approx_vnf.scenario_helper = mock.MagicMock()
440 udp_replay_approx_vnf._run()
442 udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
444 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
445 @mock.patch(SSH_HELPER)
446 def test_instantiate(self, ssh, *args):
449 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
451 udp_replay_approx_vnf.q_out.put("Replay>")
452 udp_replay_approx_vnf.WAIT_TIME = 0
453 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
455 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
456 udp_replay_approx_vnf.deploy_vnfs = mock.MagicMock()
457 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
459 udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1)
460 udp_replay_approx_vnf._vnf_process.exitcode = 0
462 self.assertEqual(udp_replay_approx_vnf.wait_for_instantiate(), 0)
464 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
465 @mock.patch('yardstick.ssh.SSH')
466 @mock.patch(SSH_HELPER)
467 def test_instantiate_panic(self, *args):
468 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
470 udp_replay_approx_vnf.WAIT_TIME = 0
471 udp_replay_approx_vnf.q_out.put("some text PANIC some text")
472 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
474 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
475 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
476 with self.assertRaises(RuntimeError):
477 udp_replay_approx_vnf.wait_for_instantiate()