3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from __future__ import absolute_import
24 from tests.unit import STL_MOCKS
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 import udp_replay
35 TEST_FILE_YAML = 'nsb_test_case.yaml'
41 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
42 class TestAclApproxVnf(unittest.TestCase):
43 VNFD = {'vnfd:vnfd-catalog':
45 [{'short-name': 'VpeVnf',
48 [{'network': '152.16.100.20',
49 'netmask': '255.255.255.0',
50 'gateway': '152.16.100.20',
52 {'network': '152.16.40.20',
53 'netmask': '255.255.255.0',
54 'gateway': '152.16.40.20',
56 'description': 'VPE approximation using DPDK',
57 'name': 'vpevnf-baremetal',
59 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
61 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
63 {'network': '0064:ff9b:0:0:0:0:9810:2814',
65 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
67 'id': 'vpevnf-baremetal',
69 [{'virtual-interface':
70 {'dst_mac': '00:00:00:00:00:04',
71 'vpci': '0000:05:00.0',
72 'local_ip': '152.16.100.19',
73 'type': 'PCI-PASSTHROUGH',
74 'netmask': '255.255.255.0',
76 'bandwidth': '10 Gbps',
78 'dst_ip': '152.16.100.20',
79 'local_iface_name': 'xe0',
80 'local_mac': '00:00:00:00:00:02'},
81 'vnfd-connection-point-ref': 'xe0',
84 {'dst_mac': '00:00:00:00:00:03',
85 'vpci': '0000:05:00.1',
86 'local_ip': '152.16.40.19',
87 'type': 'PCI-PASSTHROUGH',
89 'netmask': '255.255.255.0',
91 'bandwidth': '10 Gbps',
92 'dst_ip': '152.16.40.20',
93 'local_iface_name': 'xe1',
94 'local_mac': '00:00:00:00:00:01'},
95 'vnfd-connection-point-ref': 'xe1',
97 'description': 'Vpe approximation using DPDK',
99 {'vdu-id': 'vpevnf-baremetal',
105 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
106 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
107 {'type': 'VPORT', 'name': 'xe1'}],
108 'id': 'UdpReplayApproxVnf', 'name': 'VPEVnfSsh'}]}}
110 scenario_cfg = {'options': {'packetsize': 64, 'traffic_type': 4,
111 'rfc2544': {'allowed_drop_rate': '0.8 - 1'},
112 'vnf__1': {'rules': 'acl_1rule.yaml',
113 'vnf_config': {'lb_config': 'SW',
117 'worker_threads': 1}}
119 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7',
120 'tc': 'tc_ipv4_1Mflow_64B_packetsize',
121 'runner': {'object': 'NetworkServiceTestCase',
123 'output_filename': '/tmp/yardstick.out',
124 'runner_id': 74476, 'duration': 400,
126 'traffic_profile': 'ipv4_throughput_acl.yaml',
127 'traffic_options': {'flow': 'ipv4_Packets_acl.yaml',
128 'imix': 'imix_voice.yaml'},
130 'nodes': {'tg__2': 'trafficgen_2.yardstick',
131 'tg__1': 'trafficgen_1.yardstick',
132 'vnf__1': 'vnf.yardstick'},
133 'topology': 'vpe-tg-topology-baremetal.yaml'}
135 context_cfg = {'nodes': {'trafficgen_2.yardstick':
136 {'member-vnf-index': '3',
137 'role': 'TrafficGen',
138 'name': 'trafficgen_2.yardstick',
139 'vnfd-id-ref': 'tg__2',
142 {'xe0': {'local_iface_name': 'ens513f0',
144 'netmask': '255.255.255.0',
145 'local_ip': '152.16.40.20',
146 'dst_mac': '00:00:00:00:00:01',
147 'local_mac': '00:00:00:00:00:03',
148 'dst_ip': '152.16.40.19',
150 'vpci': '0000:02:00.0',
152 'xe1': {'local_iface_name': 'ens513f1',
153 'netmask': '255.255.255.0',
154 'network': '202.16.100.0',
155 'local_ip': '202.16.100.20',
156 'local_mac': '00:1e:67:d0:60:5d',
158 'vpci': '0000:02:00.1',
159 'dpdk_port_num': 1}},
161 'VNF model': 'l3fwd_vnf.yaml',
163 'trafficgen_1.yardstick':
164 {'member-vnf-index': '1',
165 'role': 'TrafficGen',
166 'name': 'trafficgen_1.yardstick',
167 'vnfd-id-ref': 'tg__1',
170 {'xe0': {'local_iface_name': 'ens785f0',
172 'netmask': '255.255.255.0',
173 'local_ip': '152.16.100.20',
174 'dst_mac': '00:00:00:00:00:02',
175 'local_mac': '00:00:00:00:00:04',
176 'dst_ip': '152.16.100.19',
178 'vpci': '0000:05:00.0',
180 'xe1': {'local_iface_name': 'ens785f1',
181 'netmask': '255.255.255.0',
182 'local_ip': '152.16.100.21',
183 'local_mac': '00:00:00:00:00:01',
185 'vpci': '0000:05:00.1',
186 'dpdk_port_num': 1}},
188 'VNF model': 'tg_rfc2544_tpl.yaml',
191 {'name': 'vnf.yardstick',
192 'vnfd-id-ref': 'vnf__1',
195 {'xe0': {'local_iface_name': 'ens786f0',
197 'netmask': '255.255.255.0',
198 'local_ip': '152.16.100.19',
199 'dst_mac': '00:00:00:00:00:04',
200 'local_mac': '00:00:00:00:00:02',
201 'dst_ip': '152.16.100.20',
203 'vpci': '0000:05:00.0',
205 'xe1': {'local_iface_name': 'ens786f1',
207 'netmask': '255.255.255.0',
208 'local_ip': '152.16.40.19',
209 'dst_mac': '00:00:00:00:00:03',
210 'local_mac': '00:00:00:00:00:01',
211 'dst_ip': '152.16.40.20',
213 'vpci': '0000:05:00.1',
214 'dpdk_port_num': 1}},
216 [{'netmask': '255.255.255.0',
217 'gateway': '152.16.100.20',
218 'network': '152.16.100.20',
220 {'netmask': '255.255.255.0',
221 'gateway': '152.16.40.20',
222 'network': '152.16.40.20',
224 'member-vnf-index': '2',
230 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
231 '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',
238 'VNF model': 'udp_replay.yaml'}}}
240 def test___init__(self, mock_process):
241 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
242 udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
243 self.assertIsNone(udp_approx_vnf._vnf_process)
245 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
246 def test_collect_kpi(self, mock_time, mock_process):
247 with mock.patch("yardstick.ssh.SSH") as ssh:
248 ssh_mock = mock.Mock(autospec=ssh.SSH)
250 mock.Mock(return_value=(0, "", ""))
251 ssh.from_node.return_value = ssh_mock
252 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
253 result = "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
254 "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
255 "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
256 "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
257 udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
258 udp_approx_vnf.q_in = mock.MagicMock()
259 udp_approx_vnf.q_out = mock.MagicMock()
260 udp_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
261 udp_approx_vnf.all_ports = [0, 1]
262 udp_approx_vnf.interfaces = vnfd["vdu"][0]['external-interface']
263 udp_approx_vnf.get_stats = mock.Mock(return_value=result)
264 result = {'collect_stats': {}, 'packets_dropped': 0,
265 'packets_fwd': 14748451, 'packets_in': 14748472}
266 self.assertEqual(result, udp_approx_vnf.collect_kpi())
268 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
269 def test_vnf_execute_command(self, mock_time, mock_process):
270 with mock.patch("yardstick.ssh.SSH") as ssh:
271 ssh_mock = mock.Mock(autospec=ssh.SSH)
273 mock.Mock(return_value=(0, "", ""))
274 ssh.from_node.return_value = ssh_mock
275 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
276 udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
278 self.assertEqual("", udp_approx_vnf.vnf_execute(cmd))
280 def test_get_stats(self, mock_process):
281 with mock.patch("yardstick.ssh.SSH") as ssh:
282 ssh_mock = mock.Mock(autospec=ssh.SSH)
284 mock.Mock(return_value=(0, "", ""))
285 ssh.from_node.return_value = ssh_mock
286 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
287 udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
288 udp_approx_vnf.q_in = mock.MagicMock()
289 udp_approx_vnf.q_out = mock.MagicMock()
290 udp_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
292 "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
293 udp_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
294 self.assertEqual(mock_result,
295 udp_approx_vnf.get_stats())
297 def _get_file_abspath(self, filename):
298 curr_path = os.path.dirname(os.path.abspath(__file__))
299 file_path = os.path.join(curr_path, filename)
302 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
303 def test__build_pipeline_kwargs(self, mock_open, mock_process):
304 with mock.patch("yardstick.ssh.SSH") as ssh:
305 ssh_mock = mock.Mock(autospec=ssh.SSH)
306 ssh.from_node.return_value = ssh_mock
307 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
308 udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
309 udp_approx_vnf._build_config = mock.MagicMock()
310 udp_approx_vnf.queue_wrapper = mock.MagicMock()
311 udp_approx_vnf.nfvi_type = "baremetal"
312 udp_approx_vnf.bound_pci = []
313 udp_approx_vnf.all_ports = [0, 1]
314 udp_approx_vnf.ssh_helper = mock.MagicMock(
315 **{"provision_tool.return_value": "tool_path"})
316 udp_approx_vnf.vnf_cfg = {'lb_config': 'SW',
318 'worker_config': '1C/1T',
320 udp_approx_vnf.options = {'traffic_type': '4',
321 'topology': 'nsb_test_case.yaml'}
323 udp_approx_vnf._build_pipeline_kwargs()
324 self.assertEqual(udp_approx_vnf.pipeline_kwargs, {
325 'config': '(0, 0, 1)(1, 0, 2)',
326 'cpu_mask_hex': '0x6',
328 'ports_len_hex': '0x3',
329 'tool_path': 'tool_path',
333 @mock.patch("yardstick.network_services.vnf_generic.vnf.udp_replay.hex")
334 @mock.patch("yardstick.network_services.vnf_generic.vnf.udp_replay.eval")
335 @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
336 def test_run_udp_replay(self, mock_open, eval, hex, mock_process):
337 with mock.patch("yardstick.ssh.SSH") as ssh:
338 ssh_mock = mock.Mock(autospec=ssh.SSH)
340 mock.Mock(return_value=(0, "", ""))
342 mock.Mock(return_value=(0, "", ""))
343 ssh.from_node.return_value = ssh_mock
344 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
345 udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
346 udp_approx_vnf._build_config = mock.MagicMock()
347 udp_approx_vnf.queue_wrapper = mock.MagicMock()
348 udp_approx_vnf.ssh_helper = mock.MagicMock()
349 udp_approx_vnf.ssh_helper.run = mock.MagicMock()
350 udp_approx_vnf.vnf_cfg = {'lb_config': 'SW',
352 'worker_config': '1C/1T',
354 udp_approx_vnf.options = {'traffic_type': '4',
355 'topology': 'nsb_test_case.yaml'}
357 udp_approx_vnf._run()
358 udp_approx_vnf.ssh_helper.run.assert_called_once()
360 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
361 def test_instantiate(self, Context, mock_process):
362 with mock.patch("yardstick.ssh.SSH") as ssh:
363 ssh_mock = mock.Mock(autospec=ssh.SSH)
365 mock.Mock(return_value=(0, "", ""))
366 ssh.from_node.return_value = ssh_mock
367 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
368 udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
369 self.scenario_cfg['vnf_options'] = {'cgnapt': {'cfg': "",
371 udp_approx_vnf._run_udp_replay = mock.Mock(return_value=0)
372 udp_approx_vnf._parse_rule_file = mock.Mock(return_value={})
373 udp_approx_vnf.deploy_udp_replay_vnf = mock.Mock(return_value=1)
374 udp_approx_vnf.q_out.put("Replay>")
375 udp_approx_vnf.get_my_ports = mock.Mock(return_value=[0, 1])
376 udp_replay.WAIT_TIME = 3
377 udp_approx_vnf.get_nfvi_type = mock.Mock(return_value="baremetal")
379 udp_approx_vnf._vnf_process = mock.MagicMock()
380 udp_approx_vnf._vnf_process.is_alive = \
381 mock.Mock(return_value=1)
382 self.assertIsNone(udp_approx_vnf.instantiate(self.scenario_cfg,
385 def test_scale(self, mock_process):
386 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
387 udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
389 self.assertRaises(NotImplementedError, udp_approx_vnf.scale, flavor)
391 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
392 def test_terminate(self, mock_time, mock_process):
393 with mock.patch("yardstick.ssh.SSH") as ssh:
394 ssh_mock = mock.Mock(autospec=ssh.SSH)
396 mock.Mock(return_value=(0, "", ""))
397 ssh.from_node.return_value = ssh_mock
398 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
399 udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
400 udp_approx_vnf._vnf_process = mock.MagicMock()
401 udp_approx_vnf._vnf_process.terminate = mock.Mock()
402 udp_approx_vnf.used_drivers = {"01:01.0": "i40e",
404 udp_approx_vnf.execute_command = mock.Mock()
405 udp_approx_vnf.ssh_helper = ssh_mock
406 udp_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
407 self.assertEqual(None, udp_approx_vnf.terminate())
409 if __name__ == '__main__':