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.
16 from __future__ import absolute_import
21 from tests.unit import STL_MOCKS
22 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
25 STLClient = mock.MagicMock()
26 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
30 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex import TrexTrafficGenRFC, \
32 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
33 from yardstick.network_services.traffic_profile.base import TrafficProfile
34 from tests.unit.network_services.vnf_generic.vnf.test_base import FileAbsPath, mock_ssh
36 MODULE_PATH = FileAbsPath(__file__)
37 get_file_abspath = MODULE_PATH.get_path
40 class TestTrexRfcResouceHelper(unittest.TestCase):
42 @mock.patch('yardstick.network_services.helpers.samplevnf_helper.MultiPortConfig')
43 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
44 @mock.patch(SSH_HELPER)
45 def test__run_traffic_once(self, ssh, *_):
48 mock_traffic_profile = mock.MagicMock(autospec=TrafficProfile,
49 **{'get_drop_percentage.return_value': {}})
50 sut = TrexRfcResourceHelper(mock.MagicMock(), mock.MagicMock())
51 sut.client = mock.MagicMock()
52 sut._run_traffic_once(mock_traffic_profile)
55 class TestTrexTrafficGenRFC(unittest.TestCase):
58 'short-name': 'VpeVnf',
63 'network': '152.16.100.20',
64 'netmask': '255.255.255.0',
65 'gateway': '152.16.100.20',
69 'network': '152.16.40.20',
70 'netmask': '255.255.255.0',
71 'gateway': '152.16.40.20',
75 'description': 'VPE approximation using DPDK',
76 'name': 'vpevnf-baremetal',
79 'network': '0064:ff9b:0:0:0:0:9810:6414',
81 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
85 'network': '0064:ff9b:0:0:0:0:9810:2814',
87 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
91 'id': 'vpevnf-baremetal',
92 'external-interface': [
94 'virtual-interface': {
96 'dst_mac': '00:00:00:00:00:04',
97 'vpci': '0000:05:00.0',
98 'local_ip': '152.16.100.19',
99 'type': 'PCI-PASSTHROUGH',
100 'netmask': '255.255.255.0',
101 'vld_id': 'uplink_0',
103 'bandwidth': '10 Gbps',
105 'dst_ip': '152.16.100.20',
106 'local_iface_name': 'xe0',
107 'local_mac': '00:00:00:00:00:01',
109 'vnfd-connection-point-ref': 'xe0',
113 'virtual-interface': {
115 'dst_mac': '00:00:00:00:00:03',
116 'vpci': '0000:05:00.1',
117 'local_ip': '152.16.40.19',
118 'type': 'PCI-PASSTHROUGH',
120 'netmask': '255.255.255.0',
121 'vld_id': 'downlink_0',
123 'bandwidth': '10 Gbps',
124 'dst_ip': '152.16.40.20',
125 'local_iface_name': 'xe1',
126 'local_mac': '00:00:00:00:00:02'
128 'vnfd-connection-point-ref': 'xe1',
134 'description': 'Vpe approximation using DPDK',
136 'vdu-id': 'vpevnf-baremetal',
149 'connection-point': [
159 'id': 'VpeApproxVnf',
164 'vnfd:vnfd-catalog': {
172 "schema": "isb:traffic_profile:0.1",
174 "description": "Fixed traffic profile to run UDP traffic",
176 "traffic_type": "FixedTraffic",
177 "frame_rate": 100, # pps
188 'allowed_drop_rate': '0.8 - 1',
197 'flow': 'ipv4_1flow_Packets_vpe.yaml',
198 'imix': 'imix_voice.yaml',
205 'traffic_profile': 'ipv4_throughput_vpe.yaml',
208 'tg__1': 'trafficgen_1.yardstick',
209 'vnf__1': 'vnf.yardstick',
211 'topology': 'vpe_vnf_topology.yaml',
215 'nfvi_type': 'baremetal',
218 'file': '/etc/yardstick/nodes/pod.yaml',
220 'schema': 'yardstick:task:0.1',
223 @mock.patch(SSH_HELPER)
224 def test___init__(self, ssh):
226 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
227 self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value)
229 @mock.patch(SSH_HELPER)
230 def test_collect_kpi(self, ssh):
232 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
233 self.assertEqual(trex_traffic_gen.collect_kpi(), {})
235 @mock.patch(SSH_HELPER)
236 def test_listen_traffic(self, ssh):
238 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
239 self.assertIsNone(trex_traffic_gen.listen_traffic({}))
241 @mock.patch(SSH_HELPER)
242 def test_instantiate(self, ssh):
245 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
246 mock_traffic_profile.get_traffic_definition.return_value = "64"
247 mock_traffic_profile.params = self.TRAFFIC_PROFILE
249 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
250 trex_traffic_gen._start_server = mock.Mock(return_value=0)
251 trex_traffic_gen.resource_helper = mock.MagicMock()
252 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
255 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
256 "topology": 'nsb_test_case.yaml',
261 'allowed_drop_rate': '0.8 - 1',
264 'rules': 'acl_1rule.yaml',
268 'worker_config': '1C/1T',
274 tg_rfc2544_trex.WAIT_TIME = 3
275 scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]})
276 self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
278 @mock.patch(SSH_HELPER)
279 def test_instantiate_error(self, ssh):
280 mock_ssh(ssh, exec_result=(1, "", ""))
282 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
283 mock_traffic_profile.get_traffic_definition.return_value = "64"
284 mock_traffic_profile.params = self.TRAFFIC_PROFILE
286 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
287 trex_traffic_gen.resource_helper = mock.MagicMock()
288 trex_traffic_gen.setup_helper.setup_vnf_environment = 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_terminate(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.from_node.return_value = ssh_mock
337 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
338 trex_traffic_gen.resource_helper = mock.MagicMock()
339 self.assertIsNone(trex_traffic_gen.terminate())