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'
27 STLClient = mock.MagicMock()
28 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
32 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex import TrexTrafficGenRFC, \
34 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
35 from yardstick.network_services.traffic_profile.base import TrafficProfile
36 from tests.unit.network_services.vnf_generic.vnf.test_base import FileAbsPath, mock_ssh
38 MODULE_PATH = FileAbsPath(__file__)
39 get_file_abspath = MODULE_PATH.get_path
42 class TestTrexRfcResouceHelper(unittest.TestCase):
44 @mock.patch('yardstick.network_services.helpers.samplevnf_helper.MultiPortConfig')
45 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
46 @mock.patch(SSH_HELPER)
47 def test__run_traffic_once(self, ssh, *_):
50 mock_traffic_profile = mock.MagicMock(autospec=TrafficProfile,
51 **{'get_drop_percentage.return_value': {}})
52 sut = TrexRfcResourceHelper(mock.MagicMock(), mock.MagicMock())
53 sut.client = mock.MagicMock()
54 sut._run_traffic_once(mock_traffic_profile)
57 class TestTrexTrafficGenRFC(unittest.TestCase):
60 'short-name': 'VpeVnf',
65 'network': '152.16.100.20',
66 'netmask': '255.255.255.0',
67 'gateway': '152.16.100.20',
71 'network': '152.16.40.20',
72 'netmask': '255.255.255.0',
73 'gateway': '152.16.40.20',
77 'description': 'VPE approximation using DPDK',
78 'name': 'vpevnf-baremetal',
81 'network': '0064:ff9b:0:0:0:0:9810:6414',
83 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
87 'network': '0064:ff9b:0:0:0:0:9810:2814',
89 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
93 'id': 'vpevnf-baremetal',
94 'external-interface': [
96 'virtual-interface': {
98 'dst_mac': '00:00:00:00:00:04',
99 'vpci': '0000:05:00.0',
100 'local_ip': '152.16.100.19',
101 'type': 'PCI-PASSTHROUGH',
102 'netmask': '255.255.255.0',
103 'vld_id': 'uplink_0',
105 'bandwidth': '10 Gbps',
107 'dst_ip': '152.16.100.20',
108 'local_iface_name': 'xe0',
109 'local_mac': '00:00:00:00:00:01',
111 'vnfd-connection-point-ref': 'xe0',
115 'virtual-interface': {
117 'dst_mac': '00:00:00:00:00:03',
118 'vpci': '0000:05:00.1',
119 'local_ip': '152.16.40.19',
120 'type': 'PCI-PASSTHROUGH',
122 'netmask': '255.255.255.0',
123 'vld_id': 'downlink_0',
125 'bandwidth': '10 Gbps',
126 'dst_ip': '152.16.40.20',
127 'local_iface_name': 'xe1',
128 'local_mac': '00:00:00:00:00:02'
130 'vnfd-connection-point-ref': 'xe1',
136 'description': 'Vpe approximation using DPDK',
138 'vdu-id': 'vpevnf-baremetal',
151 'connection-point': [
161 'id': 'VpeApproxVnf',
166 'vnfd:vnfd-catalog': {
174 "schema": "isb:traffic_profile:0.1",
176 "description": "Fixed traffic profile to run UDP traffic",
178 "traffic_type": "FixedTraffic",
179 "frame_rate": 100, # pps
190 'allowed_drop_rate': '0.8 - 1',
199 'flow': 'ipv4_1flow_Packets_vpe.yaml',
200 'imix': 'imix_voice.yaml',
207 'traffic_profile': 'ipv4_throughput_vpe.yaml',
210 'tg__1': 'trafficgen_1.yardstick',
211 'vnf__1': 'vnf.yardstick',
213 'topology': 'vpe_vnf_topology.yaml',
217 'nfvi_type': 'baremetal',
220 'file': '/etc/yardstick/nodes/pod.yaml',
222 'schema': 'yardstick:task:0.1',
225 @mock.patch(SSH_HELPER)
226 def test___init__(self, ssh):
228 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
229 self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value)
231 @mock.patch(SSH_HELPER)
232 def test_collect_kpi(self, ssh):
234 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
235 self.assertEqual(trex_traffic_gen.collect_kpi(), {})
237 @mock.patch(SSH_HELPER)
238 def test_listen_traffic(self, ssh):
240 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
241 self.assertIsNone(trex_traffic_gen.listen_traffic({}))
243 @mock.patch(SSH_HELPER)
244 def test_instantiate(self, ssh):
247 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
248 mock_traffic_profile.get_traffic_definition.return_value = "64"
249 mock_traffic_profile.params = self.TRAFFIC_PROFILE
251 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
252 trex_traffic_gen._start_server = mock.Mock(return_value=0)
253 trex_traffic_gen.resource_helper = mock.MagicMock()
254 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
257 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
258 "topology": 'nsb_test_case.yaml',
263 'allowed_drop_rate': '0.8 - 1',
266 'rules': 'acl_1rule.yaml',
270 'worker_config': '1C/1T',
276 tg_rfc2544_trex.WAIT_TIME = 3
277 scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]})
278 self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
280 @mock.patch(SSH_HELPER)
281 def test_instantiate_error(self, ssh):
282 mock_ssh(ssh, exec_result=(1, "", ""))
284 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
285 mock_traffic_profile.get_traffic_definition.return_value = "64"
286 mock_traffic_profile.params = self.TRAFFIC_PROFILE
288 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
289 trex_traffic_gen.resource_helper = mock.MagicMock()
290 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
292 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
297 "topology": 'nsb_test_case.yaml',
302 'allowed_drop_rate': '0.8 - 1',
305 'rules': 'acl_1rule.yaml',
309 'worker_config': '1C/1T',
315 trex_traffic_gen.instantiate(scenario_cfg, {})
317 @mock.patch(SSH_HELPER)
318 def test__start_server(self, ssh):
320 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
321 trex_traffic_gen.resource_helper = mock.MagicMock()
322 self.assertIsNone(trex_traffic_gen._start_server())
324 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
325 @mock.patch(SSH_HELPER)
326 def test__generate_trex_cfg(self, ssh, _):
329 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
330 trex_traffic_gen.ssh_helper = mock.MagicMock()
331 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
332 self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg())
334 def test_terminate(self):
335 with mock.patch(SSH_HELPER) as ssh:
336 ssh_mock = mock.Mock(autospec=ssh.SSH)
337 ssh_mock.execute = mock.Mock(return_value=(0, "", ""))
338 ssh.from_node.return_value = ssh_mock
339 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
340 trex_traffic_gen.resource_helper = mock.MagicMock()
341 self.assertIsNone(trex_traffic_gen.terminate())