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.
19 from yardstick.common import utils
20 from yardstick.benchmark.contexts import base as ctx_base
21 from yardstick.network_services.vnf_generic.vnf.vfw_vnf import FWApproxVnf
22 from yardstick.network_services.nfvi.resource import ResourceProfile
23 from yardstick.network_services.vnf_generic.vnf.vfw_vnf import FWApproxSetupEnvHelper
24 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
27 TEST_FILE_YAML = 'nsb_test_case.yaml'
28 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
33 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
34 class TestFWApproxVnf(unittest.TestCase):
35 VNFD = {'vnfd:vnfd-catalog':
37 [{'short-name': 'VpeVnf',
40 [{'network': '152.16.100.20',
41 'netmask': '255.255.255.0',
42 'gateway': '152.16.100.20',
44 {'network': '152.16.40.20',
45 'netmask': '255.255.255.0',
46 'gateway': '152.16.40.20',
48 'description': 'VPE approximation using DPDK',
49 'name': 'vpevnf-baremetal',
51 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
53 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
55 {'network': '0064:ff9b:0:0:0:0:9810:2814',
57 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
59 'id': 'vpevnf-baremetal',
61 [{'virtual-interface':
62 {'dst_mac': '00:00:00:00:00:04',
63 'vpci': '0000:05:00.0',
64 'local_ip': '152.16.100.19',
65 'type': 'PCI-PASSTHROUGH',
66 'netmask': '255.255.255.0',
68 'bandwidth': '10 Gbps',
70 'dst_ip': '152.16.100.20',
71 'local_iface_name': 'xe0',
72 'local_mac': '00:00:00:00:00:02'},
73 'vnfd-connection-point-ref': 'xe0',
76 {'dst_mac': '00:00:00:00:00:03',
77 'vpci': '0000:05:00.1',
78 'local_ip': '152.16.40.19',
79 'type': 'PCI-PASSTHROUGH',
81 'netmask': '255.255.255.0',
83 'bandwidth': '10 Gbps',
84 'dst_ip': '152.16.40.20',
85 'local_iface_name': 'xe1',
86 'local_mac': '00:00:00:00:00:01'},
87 'vnfd-connection-point-ref': 'xe1',
89 'description': 'Vpe approximation using DPDK',
91 {'vdu-id': 'vpevnf-baremetal',
97 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
98 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
99 {'type': 'VPORT', 'name': 'xe1'}],
100 'id': 'FWApproxVnf', 'name': 'VPEVnfSsh'}]}}
102 scenario_cfg = {'options': {'packetsize': 64, 'traffic_type': 4,
103 'rfc2544': {'allowed_drop_rate': '0.8 - 1'},
104 'vnf__1': {'rules': 'acl_1rule.yaml',
105 'vnf_config': {'lb_config': 'SW',
109 'worker_threads': 1}}
111 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7',
113 'tc': 'tc_ipv4_1Mflow_64B_packetsize',
114 'runner': {'object': 'NetworkServiceTestCase',
116 'output_filename': '/tmp/yardstick.out',
117 'runner_id': 74476, 'duration': 400,
119 'traffic_profile': 'ipv4_throughput_vfw.yaml',
120 'traffic_options': {'flow': 'ipv4_Packets_vfw.yaml',
121 'imix': 'imix_voice.yaml'},
123 'nodes': {'tg__2': 'trafficgen_2.yardstick',
124 'tg__1': 'trafficgen_1.yardstick',
125 'vnf__1': 'vnf.yardstick'},
126 'topology': 'vpe-tg-topology-baremetal.yaml'}
128 context_cfg = {'nodes': {'tg__2':
129 {'member-vnf-index': '3',
130 'role': 'TrafficGen',
131 'name': 'trafficgen_2.yardstick',
132 'vnfd-id-ref': 'tg__2',
135 {'xe0': {'local_iface_name': 'ens513f0',
136 'vld_id': FWApproxVnf.DOWNLINK,
137 'netmask': '255.255.255.0',
138 'local_ip': '152.16.40.20',
139 'dst_mac': '00:00:00:00:00:01',
140 'local_mac': '00:00:00:00:00:03',
141 'dst_ip': '152.16.40.19',
143 'vpci': '0000:02:00.0',
145 'xe1': {'local_iface_name': 'ens513f1',
146 'netmask': '255.255.255.0',
147 'network': '202.16.100.0',
148 'local_ip': '202.16.100.20',
149 'local_mac': '00:1e:67:d0:60:5d',
151 'vpci': '0000:02:00.1',
152 'dpdk_port_num': 1}},
154 'VNF model': 'l3fwd_vnf.yaml',
157 {'member-vnf-index': '1',
158 'role': 'TrafficGen',
159 'name': 'trafficgen_1.yardstick',
160 'vnfd-id-ref': 'tg__1',
163 {'xe0': {'local_iface_name': 'ens785f0',
164 'vld_id': FWApproxVnf.UPLINK,
165 'netmask': '255.255.255.0',
166 'local_ip': '152.16.100.20',
167 'dst_mac': '00:00:00:00:00:02',
168 'local_mac': '00:00:00:00:00:04',
169 'dst_ip': '152.16.100.19',
171 'vpci': '0000:05:00.0',
173 'xe1': {'local_iface_name': 'ens785f1',
174 'netmask': '255.255.255.0',
175 'local_ip': '152.16.100.21',
176 'local_mac': '00:00:00:00:00:01',
178 'vpci': '0000:05:00.1',
179 'dpdk_port_num': 1}},
181 'VNF model': 'tg_rfc2544_tpl.yaml',
184 {'name': 'vnf.yardstick',
185 'vnfd-id-ref': 'vnf__1',
188 {'xe0': {'local_iface_name': 'ens786f0',
189 'vld_id': FWApproxVnf.UPLINK,
190 'netmask': '255.255.255.0',
191 'local_ip': '152.16.100.19',
192 'dst_mac': '00:00:00:00:00:04',
193 'local_mac': '00:00:00:00:00:02',
194 'dst_ip': '152.16.100.20',
196 'vpci': '0000:05:00.0',
198 'xe1': {'local_iface_name': 'ens786f1',
199 'vld_id': FWApproxVnf.DOWNLINK,
200 'netmask': '255.255.255.0',
201 'local_ip': '152.16.40.19',
202 'dst_mac': '00:00:00:00:00:03',
203 'local_mac': '00:00:00:00:00:01',
204 'dst_ip': '152.16.40.20',
206 'vpci': '0000:05:00.1',
207 'dpdk_port_num': 1}},
209 [{'netmask': '255.255.255.0',
210 'gateway': '152.16.100.20',
211 'network': '152.16.100.20',
213 {'netmask': '255.255.255.0',
214 'gateway': '152.16.40.20',
215 'network': '152.16.40.20',
217 'member-vnf-index': '2',
223 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
224 'network': '0064:ff9b:0:0:0:0:9810:6414',
227 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
228 'network': '0064:ff9b:0:0:0:0:9810:2814',
231 'VNF model': 'vfw_vnf.yaml'}}}
233 def test___init__(self, *args):
234 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
235 vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
236 self.assertIsNone(vfw_approx_vnf._vnf_process)
242 {"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}}
243 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
244 "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}
245 Action ID: 00, packetCount: 2954633, byteCount: 177277980
246 Action ID: 01, packetCount: 3052547, byteCount: 183152820
252 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
253 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
254 @mock.patch(SSH_HELPER)
255 def test_collect_kpi(self, ssh, *args):
257 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
258 vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
259 vfw_approx_vnf.scenario_helper.scenario_cfg = {
260 'nodes': {vfw_approx_vnf.name: "mock"}
262 vfw_approx_vnf.q_in = mock.MagicMock()
263 vfw_approx_vnf.q_out = mock.MagicMock()
264 vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
265 vfw_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
266 vfw_approx_vnf.resource_helper = mock.MagicMock(
267 **{'collect_kpi.return_value': {"core": {}}})
268 vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
270 'physical_node': 'mock_node',
271 'packets_dropped': 0,
272 'packets_fwd': 6007180,
273 'packets_in': 6007180,
274 'collect_stats': {'core': {}},
276 self.assertEqual(result, vfw_approx_vnf.collect_kpi())
278 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
279 @mock.patch(SSH_HELPER)
280 def test_vnf_execute_command(self, ssh, *args):
283 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
284 vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
285 vfw_approx_vnf.q_in = mock.MagicMock()
286 vfw_approx_vnf.q_out = mock.MagicMock()
287 vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
289 self.assertEqual(vfw_approx_vnf.vnf_execute(cmd), "")
291 @mock.patch(SSH_HELPER)
292 def test_get_stats(self, ssh, *args):
295 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
296 vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
297 vfw_approx_vnf.q_in = mock.MagicMock()
298 vfw_approx_vnf.q_out = mock.MagicMock()
299 vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
300 vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
301 self.assertEqual(self.STATS, vfw_approx_vnf.get_stats())
303 def _get_file_abspath(self, filename):
304 curr_path = os.path.dirname(os.path.abspath(__file__))
305 file_path = os.path.join(curr_path, filename)
308 @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.hex")
309 @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.eval")
310 @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.open")
311 @mock.patch(SSH_HELPER)
312 def test_run_vfw(self, ssh, *args):
315 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
316 vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
317 vfw_approx_vnf._build_config = mock.MagicMock()
318 vfw_approx_vnf.queue_wrapper = mock.MagicMock()
319 vfw_approx_vnf.ssh_helper = mock.MagicMock()
320 vfw_approx_vnf.ssh_helper.run = mock.MagicMock()
321 vfw_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
322 vfw_approx_vnf.vnf_cfg = {'lb_config': 'SW',
324 'worker_config': '1C/1T',
326 vfw_approx_vnf.all_options = {'traffic_type': '4',
327 'topology': 'nsb_test_case.yaml'}
328 vfw_approx_vnf._run()
329 vfw_approx_vnf.ssh_helper.run.assert_called_once()
331 @mock.patch.object(utils, 'find_relative_file')
332 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
333 @mock.patch(SSH_HELPER)
334 def test_instantiate(self, ssh, *args):
337 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
338 vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
339 vfw_approx_vnf.ssh_helper = ssh
340 vfw_approx_vnf.deploy_helper = mock.MagicMock()
341 vfw_approx_vnf.resource_helper = mock.MagicMock()
342 vfw_approx_vnf._build_config = mock.MagicMock()
343 self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
345 self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
346 self.assertIsNone(vfw_approx_vnf.instantiate(self.scenario_cfg, self.context_cfg))
349 class TestFWApproxSetupEnvHelper(unittest.TestCase):
351 @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.open')
352 @mock.patch.object(utils, 'find_relative_file')
353 @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig')
354 @mock.patch.object(utils, 'open_relative_file')
355 def test_build_config(self, *args):
356 vnfd_helper = mock.Mock()
357 ssh_helper = mock.Mock()
358 scenario_helper = mock.Mock()
359 scenario_helper.vnf_cfg = {'lb_config': 'HW'}
360 scenario_helper.options = {}
361 scenario_helper.all_options = {}
363 vfw_approx_setup_helper = FWApproxSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
364 vfw_approx_setup_helper.get_flows_config = mock.Mock()
366 vfw_approx_setup_helper.ssh_helper.provision_tool = mock.Mock(return_value='tool_path')
367 vfw_approx_setup_helper.ssh_helper.all_ports = mock.Mock()
368 vfw_approx_setup_helper.vnfd_helper.port_nums = mock.Mock(return_value=[0, 1])
369 expected = 'sudo tool_path -p 0x3 -f /tmp/vfw_config -s /tmp/vfw_script --hwlb 3'
370 self.assertEqual(vfw_approx_setup_helper.build_config(), expected)
371 vfw_approx_setup_helper.get_flows_config.assert_called_once()