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 yardstick.tests import STL_MOCKS
21 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
23 from yardstick.common import utils
26 STLClient = mock.MagicMock()
27 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
31 from yardstick.network_services.vnf_generic.vnf.vfw_vnf import FWApproxVnf
32 from yardstick.network_services.nfvi.resource import ResourceProfile
33 from yardstick.network_services.vnf_generic.vnf.vfw_vnf import FWApproxSetupEnvHelper
36 TEST_FILE_YAML = 'nsb_test_case.yaml'
37 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 TestFWApproxVnf(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': 'FWApproxVnf', '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_vfw.yaml',
129 'traffic_options': {'flow': 'ipv4_Packets_vfw.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': FWApproxVnf.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': FWApproxVnf.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': FWApproxVnf.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': FWApproxVnf.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': 'vfw_vnf.yaml'}}}
242 def test___init__(self, *args):
243 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
244 vfw_approx_vnf = FWApproxVnf(name, vnfd)
245 self.assertIsNone(vfw_approx_vnf._vnf_process)
251 {"VFW_counters" : {"id" : "PIPELINE4", " pkts_received": 6007180, " pkts_fw_forwarded": 6007180, " pkts_drop_fw": 0, " pkts_acl_forwarded": 6007180, "pkts_drop_without_rule" : 0, "average_pkts_in_batch" : 31, "average_internal_time_in_clocks" : 17427, "average_external_time_in_clocks" : 261120, "total_time_measures" : 189829, "ct_packets_forwarded" : 6007148, "ct_packets_dropped" : 0, "bytes_processed ": 360430800, "ct_sessions" : {"active" : 130050, "open_attempt" : 130050, "re-open_attempt" : 0, "established" : 0, "closed" : 0, "timeout" : 0}, "ct_drops" : {"out_of_window" : 0, "invalid_conn" : 0, "invalid_state_transition" : 0 "RST" : 0}}
252 VFW TOTAL: pkts_received: 6007180, "pkts_fw_forwarded": 6007180, "pkts_drop_fw": 0, "fw_drops" : {"TTL_zero" : 0, "bad_size" : 0, "fragmented_packet" : 0, "unsupported_packet_types" : 0, "no_arp_entry" : 6007180}, "pkts_acl_forwarded": 6007180, "pkts_drop_without_rule": 0, "packets_last_sec" : 0, "average_packets_per_sec" : 0, "bytes_last_sec" : 0, "average_bytes_per_sec" : 0, "bytes_processed ": 360430800
253 "CT TOTAL: ct_packets_forwarded" : 6007180, " ct_packets_dropped" : 0, "ct_sessions" : {"active" : 130050, "open_attempt" : 130050, "re-open_attempt" : 0, "established" : 0, "closed" : 0, "timeout" : 0}, "ct_drops" : {"out_of_window" : 0, "invalid_conn" : 0, "invalid_state_transition" : 0 "RST" : 0}
254 Action ID: 00, packetCount: 2954633, byteCount: 177277980
255 Action ID: 01, packetCount: 3052547, byteCount: 183152820
261 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
262 @mock.patch(SSH_HELPER)
263 def test_collect_kpi(self, ssh, *args):
266 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
267 vfw_approx_vnf = FWApproxVnf(name, vnfd)
268 vfw_approx_vnf.q_in = mock.MagicMock()
269 vfw_approx_vnf.q_out = mock.MagicMock()
270 vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
271 vfw_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
272 vfw_approx_vnf.resource_helper = mock.MagicMock(
273 **{'collect_kpi.return_value': {"core": {}}})
274 vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
276 'packets_dropped': 0,
277 'packets_fwd': 6007180,
278 'packets_in': 6007180,
279 'collect_stats': {'core': {}},
281 self.assertEqual(result, vfw_approx_vnf.collect_kpi())
283 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
284 @mock.patch(SSH_HELPER)
285 def test_vnf_execute_command(self, ssh, *args):
288 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
289 vfw_approx_vnf = FWApproxVnf(name, vnfd)
290 vfw_approx_vnf.q_in = mock.MagicMock()
291 vfw_approx_vnf.q_out = mock.MagicMock()
292 vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
294 self.assertEqual(vfw_approx_vnf.vnf_execute(cmd), "")
296 @mock.patch(SSH_HELPER)
297 def test_get_stats(self, ssh, *args):
300 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
301 vfw_approx_vnf = FWApproxVnf(name, vnfd)
302 vfw_approx_vnf.q_in = mock.MagicMock()
303 vfw_approx_vnf.q_out = mock.MagicMock()
304 vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
305 vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
306 self.assertEqual(self.STATS, vfw_approx_vnf.get_stats())
308 def _get_file_abspath(self, filename):
309 curr_path = os.path.dirname(os.path.abspath(__file__))
310 file_path = os.path.join(curr_path, filename)
313 @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.hex")
314 @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.eval")
315 @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.open")
316 @mock.patch(SSH_HELPER)
317 def test_run_vfw(self, ssh, *args):
320 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
321 vfw_approx_vnf = FWApproxVnf(name, vnfd)
322 vfw_approx_vnf._build_config = mock.MagicMock()
323 vfw_approx_vnf.queue_wrapper = mock.MagicMock()
324 vfw_approx_vnf.ssh_helper = mock.MagicMock()
325 vfw_approx_vnf.ssh_helper.run = mock.MagicMock()
326 vfw_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
327 vfw_approx_vnf.vnf_cfg = {'lb_config': 'SW',
329 'worker_config': '1C/1T',
331 vfw_approx_vnf.all_options = {'traffic_type': '4',
332 'topology': 'nsb_test_case.yaml'}
333 vfw_approx_vnf._run()
334 vfw_approx_vnf.ssh_helper.run.assert_called_once()
336 @mock.patch.object(utils, 'find_relative_file')
337 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
338 @mock.patch(SSH_HELPER)
339 def test_instantiate(self, ssh, *args):
342 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
343 vfw_approx_vnf = FWApproxVnf(name, vnfd)
344 vfw_approx_vnf.ssh_helper = ssh
345 vfw_approx_vnf.deploy_helper = mock.MagicMock()
346 vfw_approx_vnf.resource_helper = mock.MagicMock()
347 vfw_approx_vnf._build_config = mock.MagicMock()
348 self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
350 self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
351 self.assertIsNone(vfw_approx_vnf.instantiate(self.scenario_cfg, self.context_cfg))
354 class TestFWApproxSetupEnvHelper(unittest.TestCase):
356 @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.open')
357 @mock.patch.object(utils, 'find_relative_file')
358 @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig')
359 @mock.patch.object(utils, 'open_relative_file')
360 def test_build_config(self, *args):
361 vnfd_helper = mock.Mock()
362 ssh_helper = mock.Mock()
363 scenario_helper = mock.Mock()
364 scenario_helper.vnf_cfg = {'lb_config': 'HW'}
365 scenario_helper.options = {}
366 scenario_helper.all_options = {}
368 vfw_approx_setup_helper = FWApproxSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
369 vfw_approx_setup_helper.get_flows_config = mock.Mock()
371 vfw_approx_setup_helper.ssh_helper.provision_tool = mock.Mock(return_value='tool_path')
372 vfw_approx_setup_helper.ssh_helper.all_ports = mock.Mock()
373 vfw_approx_setup_helper.vnfd_helper.port_nums = mock.Mock(return_value=[0, 1])
374 expected = 'sudo tool_path -p 0x3 -f /tmp/vfw_config -s /tmp/vfw_script --hwlb 3'
375 self.assertEqual(vfw_approx_setup_helper.build_config(), expected)
376 vfw_approx_setup_helper.get_flows_config.assert_called_once()