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.
22 from tests.unit import STL_MOCKS
23 from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
26 STLClient = mock.MagicMock()
27 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
31 from yardstick.network_services.vnf_generic.vnf.acl_vnf import AclApproxVnf
32 from yardstick.network_services.nfvi.resource import ResourceProfile
35 TEST_FILE_YAML = 'nsb_test_case.yaml'
36 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
42 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
43 class TestAclApproxVnf(unittest.TestCase):
44 VNFD = {'vnfd:vnfd-catalog':
46 [{'short-name': 'VpeVnf',
49 [{'network': '152.16.100.20',
50 'netmask': '255.255.255.0',
51 'gateway': '152.16.100.20',
53 {'network': '152.16.40.20',
54 'netmask': '255.255.255.0',
55 'gateway': '152.16.40.20',
57 'description': 'VPE approximation using DPDK',
58 'name': 'vpevnf-baremetal',
60 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
62 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
64 {'network': '0064:ff9b:0:0:0:0:9810:2814',
66 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
68 'id': 'vpevnf-baremetal',
70 [{'virtual-interface':
71 {'dst_mac': '00:00:00:00:00:04',
72 'vpci': '0000:05:00.0',
73 'local_ip': '152.16.100.19',
74 'type': 'PCI-PASSTHROUGH',
75 'netmask': '255.255.255.0',
77 'bandwidth': '10 Gbps',
79 'dst_ip': '152.16.100.20',
80 'local_iface_name': 'xe0',
81 'local_mac': '00:00:00:00:00:02'},
82 'vnfd-connection-point-ref': 'xe0',
85 {'dst_mac': '00:00:00:00:00:03',
86 'vpci': '0000:05:00.1',
87 'local_ip': '152.16.40.19',
88 'type': 'PCI-PASSTHROUGH',
90 'netmask': '255.255.255.0',
92 'bandwidth': '10 Gbps',
93 'dst_ip': '152.16.40.20',
94 'local_iface_name': 'xe1',
95 'local_mac': '00:00:00:00:00:01'},
96 'vnfd-connection-point-ref': 'xe1',
98 'description': 'Vpe approximation using DPDK',
100 {'vdu-id': 'vpevnf-baremetal',
106 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
107 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
108 {'type': 'VPORT', 'name': 'xe1'}],
109 'id': 'AclApproxVnf', 'name': 'VPEVnfSsh'}]}}
111 scenario_cfg = {'options': {'packetsize': 64, 'traffic_type': 4,
112 'rfc2544': {'allowed_drop_rate': '0.8 - 1'},
113 'vnf__1': {'rules': 'acl_1rule.yaml',
114 'vnf_config': {'lb_config': 'SW',
118 'worker_threads': 1}}
120 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7',
122 'tc': 'tc_ipv4_1Mflow_64B_packetsize',
123 'runner': {'object': 'NetworkServiceTestCase',
125 'output_filename': '/tmp/yardstick.out',
126 'runner_id': 74476, 'duration': 400,
128 'traffic_profile': 'ipv4_throughput_acl.yaml',
129 'traffic_options': {'flow': 'ipv4_Packets_acl.yaml',
130 'imix': 'imix_voice.yaml'},
132 'nodes': {'tg__2': 'trafficgen_2.yardstick',
133 'tg__1': 'trafficgen_1.yardstick',
134 'vnf__1': 'vnf.yardstick'},
135 'topology': 'vpe-tg-topology-baremetal.yaml'}
137 context_cfg = {'nodes': {'tg__2':
138 {'member-vnf-index': '3',
139 'role': 'TrafficGen',
140 'name': 'trafficgen_2.yardstick',
141 'vnfd-id-ref': 'tg__2',
144 {'xe0': {'local_iface_name': 'ens513f0',
145 'vld_id': AclApproxVnf.DOWNLINK,
146 'netmask': '255.255.255.0',
147 'local_ip': '152.16.40.20',
148 'dst_mac': '00:00:00:00:00:01',
149 'local_mac': '00:00:00:00:00:03',
150 'dst_ip': '152.16.40.19',
152 'vpci': '0000:02:00.0',
154 'xe1': {'local_iface_name': 'ens513f1',
155 'netmask': '255.255.255.0',
156 'network': '202.16.100.0',
157 'local_ip': '202.16.100.20',
158 'local_mac': '00:1e:67:d0:60:5d',
160 'vpci': '0000:02:00.1',
161 'dpdk_port_num': 1}},
163 'VNF model': 'l3fwd_vnf.yaml',
166 {'member-vnf-index': '1',
167 'role': 'TrafficGen',
168 'name': 'trafficgen_1.yardstick',
169 'vnfd-id-ref': 'tg__1',
172 {'xe0': {'local_iface_name': 'ens785f0',
173 'vld_id': AclApproxVnf.UPLINK,
174 'netmask': '255.255.255.0',
175 'local_ip': '152.16.100.20',
176 'dst_mac': '00:00:00:00:00:02',
177 'local_mac': '00:00:00:00:00:04',
178 'dst_ip': '152.16.100.19',
180 'vpci': '0000:05:00.0',
182 'xe1': {'local_iface_name': 'ens785f1',
183 'netmask': '255.255.255.0',
184 'local_ip': '152.16.100.21',
185 'local_mac': '00:00:00:00:00:01',
187 'vpci': '0000:05:00.1',
188 'dpdk_port_num': 1}},
190 'VNF model': 'tg_rfc2544_tpl.yaml',
193 {'name': 'vnf.yardstick',
194 'vnfd-id-ref': 'vnf__1',
197 {'xe0': {'local_iface_name': 'ens786f0',
198 'vld_id': AclApproxVnf.UPLINK,
199 'netmask': '255.255.255.0',
200 'local_ip': '152.16.100.19',
201 'dst_mac': '00:00:00:00:00:04',
202 'local_mac': '00:00:00:00:00:02',
203 'dst_ip': '152.16.100.20',
205 'vpci': '0000:05:00.0',
207 'xe1': {'local_iface_name': 'ens786f1',
208 'vld_id': AclApproxVnf.DOWNLINK,
209 'netmask': '255.255.255.0',
210 'local_ip': '152.16.40.19',
211 'dst_mac': '00:00:00:00:00:03',
212 'local_mac': '00:00:00:00:00:01',
213 'dst_ip': '152.16.40.20',
215 'vpci': '0000:05:00.1',
216 'dpdk_port_num': 1}},
218 [{'netmask': '255.255.255.0',
219 'gateway': '152.16.100.20',
220 'network': '152.16.100.20',
222 {'netmask': '255.255.255.0',
223 'gateway': '152.16.40.20',
224 'network': '152.16.40.20',
226 'member-vnf-index': '2',
232 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
233 'network': '0064:ff9b:0:0:0:0:9810:6414',
236 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
237 'network': '0064:ff9b:0:0:0:0:9810:2814',
240 'VNF model': 'acl_vnf.yaml'}}}
242 def test___init__(self, *args):
243 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
244 acl_approx_vnf = AclApproxVnf(name, vnfd)
245 self.assertIsNone(acl_approx_vnf._vnf_process)
247 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
248 @mock.patch(SSH_HELPER)
249 def test_collect_kpi(self, ssh, *args):
252 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
253 acl_approx_vnf = AclApproxVnf(name, vnfd)
254 acl_approx_vnf.q_in = mock.MagicMock()
255 acl_approx_vnf.q_out = mock.MagicMock()
256 acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
257 acl_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
258 acl_approx_vnf.vnf_execute = mock.Mock(return_value="")
259 result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0}
260 self.assertEqual(result, acl_approx_vnf.collect_kpi())
262 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
263 @mock.patch(SSH_HELPER)
264 def test_vnf_execute_command(self, ssh, *args):
267 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
268 acl_approx_vnf = AclApproxVnf(name, vnfd)
269 acl_approx_vnf.q_in = mock.MagicMock()
270 acl_approx_vnf.q_out = mock.MagicMock()
271 acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
273 self.assertEqual("", acl_approx_vnf.vnf_execute(cmd))
275 @mock.patch(SSH_HELPER)
276 def test_get_stats(self, ssh, *args):
279 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
280 acl_approx_vnf = AclApproxVnf(name, vnfd)
281 acl_approx_vnf.q_in = mock.MagicMock()
282 acl_approx_vnf.q_out = mock.MagicMock()
283 acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
284 result = "ACL TOTAL: pkts_processed: 100, pkts_drop: 0, spkts_received: 100"
285 acl_approx_vnf.vnf_execute = mock.Mock(return_value=result)
286 self.assertEqual(result, acl_approx_vnf.get_stats())
288 def _get_file_abspath(self, filename):
289 curr_path = os.path.dirname(os.path.abspath(__file__))
290 file_path = os.path.join(curr_path, filename)
293 @mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.hex")
294 @mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.eval")
295 @mock.patch('yardstick.network_services.vnf_generic.vnf.acl_vnf.open')
296 @mock.patch(SSH_HELPER)
297 def test_run_acl(self, ssh, *args):
300 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
301 acl_approx_vnf = AclApproxVnf(name, vnfd)
302 acl_approx_vnf._build_config = mock.MagicMock()
303 acl_approx_vnf.queue_wrapper = mock.MagicMock()
304 acl_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
305 acl_approx_vnf.vnf_cfg = {'lb_config': 'SW',
307 'worker_config': '1C/1T',
309 acl_approx_vnf.all_options = {'traffic_type': '4',
310 'topology': 'nsb_test_case.yaml'}
311 acl_approx_vnf._run()
312 acl_approx_vnf.ssh_helper.run.assert_called_once()
314 @mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.YangModel")
315 @mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.find_relative_file")
316 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
317 @mock.patch(SSH_HELPER)
318 def test_instantiate(self, ssh, *args):
321 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
322 acl_approx_vnf = AclApproxVnf(name, vnfd)
323 acl_approx_vnf.deploy_helper = mock.MagicMock()
324 acl_approx_vnf.resource_helper = mock.MagicMock()
325 acl_approx_vnf._build_config = mock.MagicMock()
326 self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
328 acl_approx_vnf.q_out.put("pipeline>")
329 acl_approx_vnf.WAIT_TIME = 0
330 self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
331 self.assertIsNone(acl_approx_vnf.instantiate(self.scenario_cfg,
334 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
335 @mock.patch(SSH_HELPER)
336 def test_terminate(self, ssh, *args):
339 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
340 acl_approx_vnf = AclApproxVnf(name, vnfd)
341 acl_approx_vnf._vnf_process = mock.MagicMock()
342 acl_approx_vnf._vnf_process.terminate = mock.Mock()
343 acl_approx_vnf.used_drivers = {"01:01.0": "i40e",
345 acl_approx_vnf.vnf_execute = mock.MagicMock()
346 acl_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
347 acl_approx_vnf._resource_collect_stop = mock.Mock()
348 self.assertEqual(None, acl_approx_vnf.terminate())