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
24 from yardstick.benchmark.contexts import base as ctx_base
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.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
263 @mock.patch(SSH_HELPER)
264 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.scenario_helper.scenario_cfg = {
269 'nodes': {vfw_approx_vnf.name: "mock"}
271 vfw_approx_vnf.q_in = mock.MagicMock()
272 vfw_approx_vnf.q_out = mock.MagicMock()
273 vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
274 vfw_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
275 vfw_approx_vnf.resource_helper = mock.MagicMock(
276 **{'collect_kpi.return_value': {"core": {}}})
277 vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
279 'physical_node': 'mock_node',
280 'packets_dropped': 0,
281 'packets_fwd': 6007180,
282 'packets_in': 6007180,
283 'collect_stats': {'core': {}},
285 self.assertEqual(result, vfw_approx_vnf.collect_kpi())
287 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
288 @mock.patch(SSH_HELPER)
289 def test_vnf_execute_command(self, ssh, *args):
292 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
293 vfw_approx_vnf = FWApproxVnf(name, vnfd)
294 vfw_approx_vnf.q_in = mock.MagicMock()
295 vfw_approx_vnf.q_out = mock.MagicMock()
296 vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
298 self.assertEqual(vfw_approx_vnf.vnf_execute(cmd), "")
300 @mock.patch(SSH_HELPER)
301 def test_get_stats(self, ssh, *args):
304 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
305 vfw_approx_vnf = FWApproxVnf(name, vnfd)
306 vfw_approx_vnf.q_in = mock.MagicMock()
307 vfw_approx_vnf.q_out = mock.MagicMock()
308 vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
309 vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
310 self.assertEqual(self.STATS, vfw_approx_vnf.get_stats())
312 def _get_file_abspath(self, filename):
313 curr_path = os.path.dirname(os.path.abspath(__file__))
314 file_path = os.path.join(curr_path, filename)
317 @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.hex")
318 @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.eval")
319 @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.open")
320 @mock.patch(SSH_HELPER)
321 def test_run_vfw(self, ssh, *args):
324 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
325 vfw_approx_vnf = FWApproxVnf(name, vnfd)
326 vfw_approx_vnf._build_config = mock.MagicMock()
327 vfw_approx_vnf.queue_wrapper = mock.MagicMock()
328 vfw_approx_vnf.ssh_helper = mock.MagicMock()
329 vfw_approx_vnf.ssh_helper.run = mock.MagicMock()
330 vfw_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
331 vfw_approx_vnf.vnf_cfg = {'lb_config': 'SW',
333 'worker_config': '1C/1T',
335 vfw_approx_vnf.all_options = {'traffic_type': '4',
336 'topology': 'nsb_test_case.yaml'}
337 vfw_approx_vnf._run()
338 vfw_approx_vnf.ssh_helper.run.assert_called_once()
340 @mock.patch.object(utils, 'find_relative_file')
341 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
342 @mock.patch(SSH_HELPER)
343 def test_instantiate(self, ssh, *args):
346 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
347 vfw_approx_vnf = FWApproxVnf(name, vnfd)
348 vfw_approx_vnf.ssh_helper = ssh
349 vfw_approx_vnf.deploy_helper = mock.MagicMock()
350 vfw_approx_vnf.resource_helper = mock.MagicMock()
351 vfw_approx_vnf._build_config = mock.MagicMock()
352 self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
354 self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
355 self.assertIsNone(vfw_approx_vnf.instantiate(self.scenario_cfg, self.context_cfg))
358 class TestFWApproxSetupEnvHelper(unittest.TestCase):
360 @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.open')
361 @mock.patch.object(utils, 'find_relative_file')
362 @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig')
363 @mock.patch.object(utils, 'open_relative_file')
364 def test_build_config(self, *args):
365 vnfd_helper = mock.Mock()
366 ssh_helper = mock.Mock()
367 scenario_helper = mock.Mock()
368 scenario_helper.vnf_cfg = {'lb_config': 'HW'}
369 scenario_helper.options = {}
370 scenario_helper.all_options = {}
372 vfw_approx_setup_helper = FWApproxSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
373 vfw_approx_setup_helper.get_flows_config = mock.Mock()
375 vfw_approx_setup_helper.ssh_helper.provision_tool = mock.Mock(return_value='tool_path')
376 vfw_approx_setup_helper.ssh_helper.all_ports = mock.Mock()
377 vfw_approx_setup_helper.vnfd_helper.port_nums = mock.Mock(return_value=[0, 1])
378 expected = 'sudo tool_path -p 0x3 -f /tmp/vfw_config -s /tmp/vfw_script --hwlb 3'
379 self.assertEqual(vfw_approx_setup_helper.build_config(), expected)
380 vfw_approx_setup_helper.get_flows_config.assert_called_once()