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
23 from tests.unit import STL_MOCKS
24 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
28 STLClient = mock.MagicMock()
29 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
33 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex import TrexTrafficGenRFC, \
35 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
36 from yardstick.network_services.traffic_profile.base import TrafficProfile
37 from tests.unit.network_services.vnf_generic.vnf.test_base import FileAbsPath, mock_ssh
39 MODULE_PATH = FileAbsPath(__file__)
40 get_file_abspath = MODULE_PATH.get_path
43 class TestTrexRfcResouceHelper(unittest.TestCase):
45 @mock.patch('yardstick.network_services.helpers.samplevnf_helper.MultiPortConfig')
46 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
47 @mock.patch(SSH_HELPER)
48 def test__run_traffic_once(self, ssh, *_):
51 mock_traffic_profile = mock.MagicMock(autospec=TrafficProfile,
52 **{'get_drop_percentage.return_value': {}})
53 sut = TrexRfcResourceHelper(mock.MagicMock(), mock.MagicMock())
54 sut.client = mock.MagicMock()
55 sut._run_traffic_once(mock_traffic_profile)
58 class TestTrexTrafficGenRFC(unittest.TestCase):
61 'short-name': 'VpeVnf',
66 'network': '152.16.100.20',
67 'netmask': '255.255.255.0',
68 'gateway': '152.16.100.20',
72 'network': '152.16.40.20',
73 'netmask': '255.255.255.0',
74 'gateway': '152.16.40.20',
78 'description': 'VPE approximation using DPDK',
79 'name': 'vpevnf-baremetal',
82 'network': '0064:ff9b:0:0:0:0:9810:6414',
84 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
88 'network': '0064:ff9b:0:0:0:0:9810:2814',
90 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
94 'id': 'vpevnf-baremetal',
95 'external-interface': [
97 'virtual-interface': {
99 'dst_mac': '00:00:00:00:00:04',
100 'vpci': '0000:05:00.0',
101 'local_ip': '152.16.100.19',
102 'type': 'PCI-PASSTHROUGH',
103 'netmask': '255.255.255.0',
104 'vld_id': 'private_1',
105 'dpdk_port_num': '0',
106 'bandwidth': '10 Gbps',
108 'dst_ip': '152.16.100.20',
109 'local_iface_name': 'xe0',
110 'local_mac': '00:00:00:00:00:01',
112 'vnfd-connection-point-ref': 'xe0',
116 'virtual-interface': {
118 'dst_mac': '00:00:00:00:00:03',
119 'vpci': '0000:05:00.1',
120 'local_ip': '152.16.40.19',
121 'type': 'PCI-PASSTHROUGH',
123 'netmask': '255.255.255.0',
124 'vld_id': 'public_1',
125 'dpdk_port_num': '1',
126 'bandwidth': '10 Gbps',
127 'dst_ip': '152.16.40.20',
128 'local_iface_name': 'xe1',
129 'local_mac': '00:00:00:00:00:02'
131 'vnfd-connection-point-ref': 'xe1',
137 'description': 'Vpe approximation using DPDK',
139 'vdu-id': 'vpevnf-baremetal',
152 'connection-point': [
162 'id': 'VpeApproxVnf',
167 'vnfd:vnfd-catalog': {
175 "schema": "isb:traffic_profile:0.1",
177 "description": "Fixed traffic profile to run UDP traffic",
179 "traffic_type": "FixedTraffic",
180 "frame_rate": 100, # pps
191 'allowed_drop_rate': '0.8 - 1',
200 'flow': 'ipv4_1flow_Packets_vpe.yaml',
201 'imix': 'imix_voice.yaml',
208 'traffic_profile': 'ipv4_throughput_vpe.yaml',
211 'tg__1': 'trafficgen_1.yardstick',
212 'vnf__1': 'vnf.yardstick',
214 'topology': 'vpe_vnf_topology.yaml',
218 'nfvi_type': 'baremetal',
221 'file': '/etc/yardstick/nodes/pod.yaml',
223 'schema': 'yardstick:task:0.1',
226 @mock.patch(SSH_HELPER)
227 def test___init__(self, ssh):
229 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
230 self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value)
232 @mock.patch(SSH_HELPER)
233 def test_collect_kpi(self, ssh):
235 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
236 self.assertEqual(trex_traffic_gen.collect_kpi(), {})
238 @mock.patch(SSH_HELPER)
239 def test_listen_traffic(self, ssh):
241 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
242 self.assertIsNone(trex_traffic_gen.listen_traffic({}))
244 @mock.patch(SSH_HELPER)
245 def test_instantiate(self, ssh):
248 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
249 mock_traffic_profile.get_traffic_definition.return_value = "64"
250 mock_traffic_profile.params = self.TRAFFIC_PROFILE
252 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
253 trex_traffic_gen._start_server = mock.Mock(return_value=0)
254 trex_traffic_gen.resource_helper = mock.MagicMock()
255 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
258 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
259 "topology": 'nsb_test_case.yaml',
264 'allowed_drop_rate': '0.8 - 1',
267 'rules': 'acl_1rule.yaml',
271 'worker_config': '1C/1T',
277 tg_rfc2544_trex.WAIT_TIME = 3
278 scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]})
279 self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
281 @mock.patch(SSH_HELPER)
282 def test_instantiate_error(self, ssh):
283 mock_ssh(ssh, exec_result=(1, "", ""))
285 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
286 mock_traffic_profile.get_traffic_definition.return_value = "64"
287 mock_traffic_profile.params = self.TRAFFIC_PROFILE
289 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
290 trex_traffic_gen.resource_helper = mock.MagicMock()
291 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
293 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
298 "topology": 'nsb_test_case.yaml',
303 'allowed_drop_rate': '0.8 - 1',
306 'rules': 'acl_1rule.yaml',
310 'worker_config': '1C/1T',
316 trex_traffic_gen.instantiate(scenario_cfg, {})
318 @mock.patch(SSH_HELPER)
319 def test__start_server(self, ssh):
321 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
322 trex_traffic_gen.resource_helper = mock.MagicMock()
323 self.assertIsNone(trex_traffic_gen._start_server())
325 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
326 @mock.patch(SSH_HELPER)
327 def test__generate_trex_cfg(self, ssh, _):
330 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
331 trex_traffic_gen.ssh_helper = mock.MagicMock()
332 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
333 self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg())
335 def test_scale(self):
336 with mock.patch(SSH_HELPER) as ssh:
337 ssh_mock = mock.Mock(autospec=ssh.SSH)
338 ssh_mock.execute = mock.Mock(return_value=(0, "", ""))
339 ssh_mock.run = mock.Mock(return_value=(0, "", ""))
340 ssh.from_node.return_value = ssh_mock
341 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
342 trex_traffic_gen.scale('')
344 def test_terminate(self):
345 with mock.patch(SSH_HELPER) as ssh:
346 ssh_mock = mock.Mock(autospec=ssh.SSH)
347 ssh_mock.execute = mock.Mock(return_value=(0, "", ""))
348 ssh.from_node.return_value = ssh_mock
349 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
350 trex_traffic_gen.resource_helper = mock.MagicMock()
351 self.assertIsNone(trex_traffic_gen.terminate())