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.
18 from yardstick.benchmark import contexts
19 from yardstick.benchmark.contexts import base as ctx_base
20 from yardstick.network_services.traffic_profile import base as tp_base
21 from yardstick.network_services.vnf_generic.vnf import sample_vnf
22 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
25 class TestTrexRfcResouceHelper(unittest.TestCase):
27 def test__run_traffic_once(self):
28 mock_setup_helper = mock.Mock()
29 mock_traffic_profile = mock.Mock()
30 mock_traffic_profile.config.duration = 3
31 mock_traffic_profile.execute_traffic.return_value = ('fake_ports',
33 mock_traffic_profile.get_drop_percentage.return_value = (True,
35 rfc_rh = tg_rfc2544_trex.TrexRfcResourceHelper(mock_setup_helper)
36 rfc_rh.TRANSIENT_PERIOD = 0
37 rfc_rh.rfc2544_helper = mock.Mock()
39 with mock.patch.object(rfc_rh, '_get_samples') as mock_get_samples:
40 self.assertTrue(rfc_rh._run_traffic_once(mock_traffic_profile))
42 mock_traffic_profile.execute_traffic.assert_called_once_with(rfc_rh)
43 mock_traffic_profile.stop_traffic.assert_called_once_with(rfc_rh)
44 mock_traffic_profile.stop_traffic.assert_called_once()
45 mock_get_samples.assert_has_calls([
46 mock.call('fake_ports', port_pg_id='port_pg_id_map'),
47 mock.call('fake_ports', port_pg_id='port_pg_id_map')])
50 class TestTrexTrafficGenRFC(unittest.TestCase):
53 'short-name': 'VpeVnf',
58 'network': '152.16.100.20',
59 'netmask': '255.255.255.0',
60 'gateway': '152.16.100.20',
64 'network': '152.16.40.20',
65 'netmask': '255.255.255.0',
66 'gateway': '152.16.40.20',
70 'description': 'VPE approximation using DPDK',
71 'name': 'vpevnf-baremetal',
74 'network': '0064:ff9b:0:0:0:0:9810:6414',
76 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
80 'network': '0064:ff9b:0:0:0:0:9810:2814',
82 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
86 'id': 'vpevnf-baremetal',
87 'external-interface': [
89 'virtual-interface': {
91 'dst_mac': '00:00:00:00:00:04',
92 'vpci': '0000:05:00.0',
93 'local_ip': '152.16.100.19',
94 'type': 'PCI-PASSTHROUGH',
95 'netmask': '255.255.255.0',
98 'bandwidth': '10 Gbps',
100 'dst_ip': '152.16.100.20',
101 'local_iface_name': 'xe0',
102 'local_mac': '00:00:00:00:00:01',
104 'vnfd-connection-point-ref': 'xe0',
108 'virtual-interface': {
110 'dst_mac': '00:00:00:00:00:03',
111 'vpci': '0000:05:00.1',
112 'local_ip': '152.16.40.19',
113 'type': 'PCI-PASSTHROUGH',
115 'netmask': '255.255.255.0',
116 'vld_id': 'downlink_0',
118 'bandwidth': '10 Gbps',
119 'dst_ip': '152.16.40.20',
120 'local_iface_name': 'xe1',
121 'local_mac': '00:00:00:00:00:02'
123 'vnfd-connection-point-ref': 'xe1',
129 'description': 'Vpe approximation using DPDK',
131 'vdu-id': 'vpevnf-baremetal',
144 'connection-point': [
154 'id': 'VpeApproxVnf',
159 'vnfd:vnfd-catalog': {
167 "schema": "isb:traffic_profile:0.1",
169 "description": "Fixed traffic profile to run UDP traffic",
171 "traffic_type": "FixedTraffic",
172 "frame_rate": 100, # pps
183 'allowed_drop_rate': '0.8 - 1',
192 'flow': 'ipv4_1flow_Packets_vpe.yaml',
193 'imix': 'imix_voice.yaml',
200 'traffic_profile': 'ipv4_throughput_vpe.yaml',
203 'tg__1': 'trafficgen_1.yardstick',
204 'vnf__1': 'vnf.yardstick',
206 'topology': 'vpe_vnf_topology.yaml',
210 'nfvi_type': 'baremetal',
211 'type': contexts.CONTEXT_NODE,
213 'file': '/etc/yardstick/nodes/pod.yaml',
215 'schema': 'yardstick:task:0.1',
219 self._mock_ssh_helper = mock.patch.object(sample_vnf, 'VnfSshHelper')
220 self.mock_ssh_helper = self._mock_ssh_helper.start()
221 self.addCleanup(self._stop_mocks)
223 def _stop_mocks(self):
224 self._mock_ssh_helper.stop()
226 def test___init__(self):
227 trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC(
228 'vnf1', self.VNFD_0, 'task_id')
229 self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value)
231 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
232 def test_collect_kpi(self, *args):
233 trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC(
234 'vnf1', self.VNFD_0, 'task_id')
235 trex_traffic_gen.scenario_helper.scenario_cfg = {
236 'nodes': {trex_traffic_gen.name: "mock"}
239 'physical_node': 'mock_node',
242 self.assertEqual(trex_traffic_gen.collect_kpi(), expected)
244 @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
245 def test_instantiate(self, *args):
246 mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
247 mock_traffic_profile.get_traffic_definition.return_value = "64"
248 mock_traffic_profile.params = self.TRAFFIC_PROFILE
250 trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC(
251 'vnf1', self.VNFD_0, 'task_id')
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": {}, "vnf1": {}}})
278 self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
280 @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
281 def test_instantiate_error(self, *args):
282 mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
283 mock_traffic_profile.get_traffic_definition.return_value = "64"
284 mock_traffic_profile.params = self.TRAFFIC_PROFILE
286 trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC(
287 'vnf1', self.VNFD_0, 'task_id')
288 trex_traffic_gen.resource_helper = mock.MagicMock()
289 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
291 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
296 "topology": 'nsb_test_case.yaml',
301 'allowed_drop_rate': '0.8 - 1',
304 'rules': 'acl_1rule.yaml',
308 'worker_config': '1C/1T',
314 trex_traffic_gen.instantiate(scenario_cfg, {})