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.tests import STL_MOCKS
20 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
23 STLClient = mock.MagicMock()
24 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
28 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex import TrexTrafficGenRFC, \
30 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
31 from yardstick.network_services.traffic_profile.base import TrafficProfile
32 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base \
33 import FileAbsPath, mock_ssh
35 MODULE_PATH = FileAbsPath(__file__)
36 get_file_abspath = MODULE_PATH.get_path
39 class TestTrexRfcResouceHelper(unittest.TestCase):
41 @mock.patch('yardstick.network_services.helpers.samplevnf_helper.MultiPortConfig')
42 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
43 @mock.patch(SSH_HELPER)
44 def test__run_traffic_once(self, ssh, *_):
47 mock_traffic_profile = mock.MagicMock(autospec=TrafficProfile,
48 **{'get_drop_percentage.return_value': {}})
49 sut = TrexRfcResourceHelper(mock.MagicMock(), mock.MagicMock())
50 sut.client = mock.MagicMock()
51 sut._run_traffic_once(mock_traffic_profile)
54 class TestTrexTrafficGenRFC(unittest.TestCase):
57 'short-name': 'VpeVnf',
62 'network': '152.16.100.20',
63 'netmask': '255.255.255.0',
64 'gateway': '152.16.100.20',
68 'network': '152.16.40.20',
69 'netmask': '255.255.255.0',
70 'gateway': '152.16.40.20',
74 'description': 'VPE approximation using DPDK',
75 'name': 'vpevnf-baremetal',
78 'network': '0064:ff9b:0:0:0:0:9810:6414',
80 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
84 'network': '0064:ff9b:0:0:0:0:9810:2814',
86 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
90 'id': 'vpevnf-baremetal',
91 'external-interface': [
93 'virtual-interface': {
95 'dst_mac': '00:00:00:00:00:04',
96 'vpci': '0000:05:00.0',
97 'local_ip': '152.16.100.19',
98 'type': 'PCI-PASSTHROUGH',
99 'netmask': '255.255.255.0',
100 'vld_id': 'uplink_0',
102 'bandwidth': '10 Gbps',
104 'dst_ip': '152.16.100.20',
105 'local_iface_name': 'xe0',
106 'local_mac': '00:00:00:00:00:01',
108 'vnfd-connection-point-ref': 'xe0',
112 'virtual-interface': {
114 'dst_mac': '00:00:00:00:00:03',
115 'vpci': '0000:05:00.1',
116 'local_ip': '152.16.40.19',
117 'type': 'PCI-PASSTHROUGH',
119 'netmask': '255.255.255.0',
120 'vld_id': 'downlink_0',
122 'bandwidth': '10 Gbps',
123 'dst_ip': '152.16.40.20',
124 'local_iface_name': 'xe1',
125 'local_mac': '00:00:00:00:00:02'
127 'vnfd-connection-point-ref': 'xe1',
133 'description': 'Vpe approximation using DPDK',
135 'vdu-id': 'vpevnf-baremetal',
148 'connection-point': [
158 'id': 'VpeApproxVnf',
163 'vnfd:vnfd-catalog': {
171 "schema": "isb:traffic_profile:0.1",
173 "description": "Fixed traffic profile to run UDP traffic",
175 "traffic_type": "FixedTraffic",
176 "frame_rate": 100, # pps
187 'allowed_drop_rate': '0.8 - 1',
196 'flow': 'ipv4_1flow_Packets_vpe.yaml',
197 'imix': 'imix_voice.yaml',
204 'traffic_profile': 'ipv4_throughput_vpe.yaml',
207 'tg__1': 'trafficgen_1.yardstick',
208 'vnf__1': 'vnf.yardstick',
210 'topology': 'vpe_vnf_topology.yaml',
214 'nfvi_type': 'baremetal',
217 'file': '/etc/yardstick/nodes/pod.yaml',
219 'schema': 'yardstick:task:0.1',
222 @mock.patch(SSH_HELPER)
223 def test___init__(self, ssh):
225 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
226 self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value)
228 @mock.patch(SSH_HELPER)
229 def test_collect_kpi(self, ssh):
231 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
232 self.assertEqual(trex_traffic_gen.collect_kpi(), {})
234 @mock.patch(SSH_HELPER)
235 def test_listen_traffic(self, ssh):
237 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
238 self.assertIsNone(trex_traffic_gen.listen_traffic({}))
240 @mock.patch(SSH_HELPER)
241 def test_instantiate(self, ssh):
244 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
245 mock_traffic_profile.get_traffic_definition.return_value = "64"
246 mock_traffic_profile.params = self.TRAFFIC_PROFILE
248 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
249 trex_traffic_gen._start_server = mock.Mock(return_value=0)
250 trex_traffic_gen.resource_helper = mock.MagicMock()
251 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
254 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
255 "topology": 'nsb_test_case.yaml',
260 'allowed_drop_rate': '0.8 - 1',
263 'rules': 'acl_1rule.yaml',
267 'worker_config': '1C/1T',
273 tg_rfc2544_trex.WAIT_TIME = 3
274 scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]})
275 self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
277 @mock.patch(SSH_HELPER)
278 def test_instantiate_error(self, ssh):
279 mock_ssh(ssh, exec_result=(1, "", ""))
281 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
282 mock_traffic_profile.get_traffic_definition.return_value = "64"
283 mock_traffic_profile.params = self.TRAFFIC_PROFILE
285 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
286 trex_traffic_gen.resource_helper = mock.MagicMock()
287 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
289 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
294 "topology": 'nsb_test_case.yaml',
299 'allowed_drop_rate': '0.8 - 1',
302 'rules': 'acl_1rule.yaml',
306 'worker_config': '1C/1T',
312 trex_traffic_gen.instantiate(scenario_cfg, {})
314 @mock.patch(SSH_HELPER)
315 def test__start_server(self, ssh):
317 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
318 trex_traffic_gen.resource_helper = mock.MagicMock()
319 self.assertIsNone(trex_traffic_gen._start_server())
321 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time")
322 @mock.patch(SSH_HELPER)
323 def test__generate_trex_cfg(self, ssh, _):
326 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
327 trex_traffic_gen.ssh_helper = mock.MagicMock()
328 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
329 self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg())
331 def test_terminate(self):
332 with mock.patch(SSH_HELPER) as ssh:
333 ssh_mock = mock.Mock(autospec=ssh.SSH)
334 ssh_mock.execute = mock.Mock(return_value=(0, "", ""))
335 ssh.from_node.return_value = ssh_mock
336 trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
337 trex_traffic_gen.resource_helper = mock.MagicMock()
338 self.assertIsNone(trex_traffic_gen.terminate())