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
26 SSH_HELPER = "yardstick.ssh.SSH"
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()
256 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
257 "topology": 'nsb_test_case.yaml',
262 'allowed_drop_rate': '0.8 - 1',
265 'rules': 'acl_1rule.yaml',
269 'worker_config': '1C/1T',
275 tg_rfc2544_trex.WAIT_TIME = 3
276 scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]})
277 self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
279 @mock.patch(SSH_HELPER)
280 def test_instantiate_error(self, ssh):
281 mock_ssh(ssh, exec_result=(1, "", ""))
283 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
284 mock_traffic_profile.get_traffic_definition.return_value = "64"
285 mock_traffic_profile.params = self.TRAFFIC_PROFILE
287 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
288 trex_traffic_gen.resource_helper = mock.MagicMock()
290 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
295 "topology": 'nsb_test_case.yaml',
300 'allowed_drop_rate': '0.8 - 1',
303 'rules': 'acl_1rule.yaml',
307 'worker_config': '1C/1T',
313 trex_traffic_gen.instantiate(scenario_cfg, {})
315 @mock.patch(SSH_HELPER)
316 def test__start_server(self, ssh):
318 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
319 trex_traffic_gen.resource_helper = mock.MagicMock()
320 self.assertIsNone(trex_traffic_gen._start_server())
322 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
323 @mock.patch(SSH_HELPER)
324 def test__generate_trex_cfg(self, ssh, _):
327 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
328 trex_traffic_gen.ssh_helper = mock.MagicMock()
329 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
330 self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg())
332 def test_scale(self):
333 with mock.patch(SSH_HELPER) as ssh:
334 ssh_mock = mock.Mock(autospec=ssh.SSH)
335 ssh_mock.execute = mock.Mock(return_value=(0, "", ""))
336 ssh_mock.run = mock.Mock(return_value=(0, "", ""))
337 ssh.from_node.return_value = ssh_mock
338 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
339 trex_traffic_gen.scale('')
341 def test_terminate(self):
342 with mock.patch(SSH_HELPER) as ssh:
343 ssh_mock = mock.Mock(autospec=ssh.SSH)
344 ssh_mock.execute = mock.Mock(return_value=(0, "", ""))
345 ssh.from_node.return_value = ssh_mock
346 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
347 trex_traffic_gen.resource_helper = mock.MagicMock()
348 self.assertIsNone(trex_traffic_gen.terminate())