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 tests.unit import STL_MOCKS
21 from 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 result = "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
339 "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
340 "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
341 "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
342 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
343 udp_replay_approx_vnf.q_in = mock.MagicMock()
344 udp_replay_approx_vnf.q_out = mock.MagicMock()
345 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
346 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
347 udp_replay_approx_vnf.get_stats = mock.Mock(return_value=result)
348 result = {'collect_stats': {}, 'packets_dropped': 0,
349 'packets_fwd': 14748451, 'packets_in': 14748472}
350 self.assertEqual(result, udp_replay_approx_vnf.collect_kpi())
352 @mock.patch(SSH_HELPER)
353 def test_get_stats(self, ssh, *args):
356 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
357 udp_replay_approx_vnf.q_in = mock.MagicMock()
358 udp_replay_approx_vnf.q_out = mock.MagicMock()
359 udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
361 "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
363 udp_replay_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
365 self.assertEqual(mock_result,
366 udp_replay_approx_vnf.get_stats())
368 def _get_file_abspath(self, filename):
369 curr_path = os.path.dirname(os.path.abspath(__file__))
370 file_path = os.path.join(curr_path, filename)
373 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
374 @mock.patch(SSH_HELPER)
375 def test__build_config(self, ssh, mock_context, *args):
378 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
379 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
380 udp_replay_approx_vnf.nfvi_context = mock_context
381 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
382 udp_replay_approx_vnf.setup_helper.bound_pci = []
383 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
384 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
385 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
387 cmd_line = udp_replay_approx_vnf._build_config()
390 "sudo tool_path --log-level=5 -c 0x7 -n 4 -w -- -p 0x3 --config='(0,0,1),(1,0,2)'"
391 self.assertEqual(cmd_line, expected)
393 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
394 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
395 @mock.patch(SSH_HELPER)
396 def test__build_pipeline_kwargs(self, ssh, mock_context, *args):
398 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
399 udp_replay_approx_vnf.nfvi_context = mock_context
400 udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
401 udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3']
402 udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
403 udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
404 udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
405 udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
407 udp_replay_approx_vnf._build_pipeline_kwargs()
409 self.assertEqual(udp_replay_approx_vnf.pipeline_kwargs, {
410 'config': '(0,0,1),(1,0,2)',
411 'cpu_mask_hex': '0x7',
413 'port_mask_hex': '0x3',
414 'tool_path': 'tool_path',
415 'whitelist': '0000:00:0.1 -w 0000:00:0.3'
418 @mock.patch(SSH_HELPER)
419 def test_run_udp_replay(self, ssh, *args):
422 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
423 udp_replay_approx_vnf._build_config = mock.MagicMock()
424 udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
425 udp_replay_approx_vnf.scenario_helper = mock.MagicMock()
427 udp_replay_approx_vnf._run()
429 udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
431 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
432 @mock.patch(SSH_HELPER)
433 def test_instantiate(self, ssh, *args):
436 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
437 udp_replay_approx_vnf.q_out.put("Replay>")
438 udp_replay_approx_vnf.WAIT_TIME = 0
439 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
441 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
442 udp_replay_approx_vnf.deploy_vnfs = mock.MagicMock()
443 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
445 udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1)
446 udp_replay_approx_vnf._vnf_process.exitcode = 0
448 self.assertEqual(udp_replay_approx_vnf.wait_for_instantiate(), 0)
450 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
451 @mock.patch('yardstick.ssh.SSH')
452 @mock.patch(SSH_HELPER)
453 def test_instantiate_panic(self, *args):
454 udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
455 udp_replay_approx_vnf.WAIT_TIME = 0
456 udp_replay_approx_vnf.q_out.put("some text PANIC some text")
457 udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
459 udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
460 self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
461 with self.assertRaises(RuntimeError):
462 udp_replay_approx_vnf.wait_for_instantiate()