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.network_services.traffic_profile import base as tp_base
19 from yardstick.network_services.vnf_generic.vnf import sample_vnf
20 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
21 from yardstick.benchmark.contexts import base as ctx_base
24 class TestTrexRfcResouceHelper(unittest.TestCase):
26 def test__run_traffic_once(self):
27 mock_setup_helper = mock.Mock()
28 mock_traffic_profile = mock.Mock()
29 mock_traffic_profile.config.duration = 3
30 mock_traffic_profile.execute_traffic.return_value = ('fake_ports',
32 mock_traffic_profile.get_drop_percentage.return_value = 'percentage'
33 rfc_rh = tg_rfc2544_trex.TrexRfcResourceHelper(mock_setup_helper)
34 rfc_rh.TRANSIENT_PERIOD = 0
35 rfc_rh.rfc2544_helper = mock.Mock()
37 with mock.patch.object(rfc_rh, '_get_samples') as mock_get_samples:
38 rfc_rh._run_traffic_once(mock_traffic_profile)
40 mock_traffic_profile.execute_traffic.assert_called_once_with(rfc_rh)
41 mock_traffic_profile.stop_traffic.assert_called_once_with(rfc_rh)
42 mock_traffic_profile.stop_traffic.assert_called_once()
43 mock_get_samples.assert_has_calls([
44 mock.call('fake_ports', port_pg_id='port_pg_id_map'),
45 mock.call('fake_ports', port_pg_id='port_pg_id_map')])
48 class TestTrexTrafficGenRFC(unittest.TestCase):
51 'short-name': 'VpeVnf',
56 'network': '152.16.100.20',
57 'netmask': '255.255.255.0',
58 'gateway': '152.16.100.20',
62 'network': '152.16.40.20',
63 'netmask': '255.255.255.0',
64 'gateway': '152.16.40.20',
68 'description': 'VPE approximation using DPDK',
69 'name': 'vpevnf-baremetal',
72 'network': '0064:ff9b:0:0:0:0:9810:6414',
74 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
78 'network': '0064:ff9b:0:0:0:0:9810:2814',
80 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
84 'id': 'vpevnf-baremetal',
85 'external-interface': [
87 'virtual-interface': {
89 'dst_mac': '00:00:00:00:00:04',
90 'vpci': '0000:05:00.0',
91 'local_ip': '152.16.100.19',
92 'type': 'PCI-PASSTHROUGH',
93 'netmask': '255.255.255.0',
96 'bandwidth': '10 Gbps',
98 'dst_ip': '152.16.100.20',
99 'local_iface_name': 'xe0',
100 'local_mac': '00:00:00:00:00:01',
102 'vnfd-connection-point-ref': 'xe0',
106 'virtual-interface': {
108 'dst_mac': '00:00:00:00:00:03',
109 'vpci': '0000:05:00.1',
110 'local_ip': '152.16.40.19',
111 'type': 'PCI-PASSTHROUGH',
113 'netmask': '255.255.255.0',
114 'vld_id': 'downlink_0',
116 'bandwidth': '10 Gbps',
117 'dst_ip': '152.16.40.20',
118 'local_iface_name': 'xe1',
119 'local_mac': '00:00:00:00:00:02'
121 'vnfd-connection-point-ref': 'xe1',
127 'description': 'Vpe approximation using DPDK',
129 'vdu-id': 'vpevnf-baremetal',
142 'connection-point': [
152 'id': 'VpeApproxVnf',
157 'vnfd:vnfd-catalog': {
165 "schema": "isb:traffic_profile:0.1",
167 "description": "Fixed traffic profile to run UDP traffic",
169 "traffic_type": "FixedTraffic",
170 "frame_rate": 100, # pps
181 'allowed_drop_rate': '0.8 - 1',
190 'flow': 'ipv4_1flow_Packets_vpe.yaml',
191 'imix': 'imix_voice.yaml',
198 'traffic_profile': 'ipv4_throughput_vpe.yaml',
201 'tg__1': 'trafficgen_1.yardstick',
202 'vnf__1': 'vnf.yardstick',
204 'topology': 'vpe_vnf_topology.yaml',
208 'nfvi_type': 'baremetal',
211 'file': '/etc/yardstick/nodes/pod.yaml',
213 'schema': 'yardstick:task:0.1',
217 self._mock_ssh_helper = mock.patch.object(sample_vnf, 'VnfSshHelper')
218 self.mock_ssh_helper = self._mock_ssh_helper.start()
219 self.addCleanup(self._stop_mocks)
221 def _stop_mocks(self):
222 self._mock_ssh_helper.stop()
224 def test___init__(self):
225 trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0)
226 self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value)
228 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
229 def test_collect_kpi(self, *args):
230 trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0)
231 trex_traffic_gen.scenario_helper.scenario_cfg = {
232 'nodes': {trex_traffic_gen.name: "mock"}
235 'physical_node': 'mock_node',
238 self.assertEqual(trex_traffic_gen.collect_kpi(), expected)
240 @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
241 def test_instantiate(self, *args):
242 mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
243 mock_traffic_profile.get_traffic_definition.return_value = "64"
244 mock_traffic_profile.params = self.TRAFFIC_PROFILE
246 trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0)
247 trex_traffic_gen._start_server = mock.Mock(return_value=0)
248 trex_traffic_gen.resource_helper = mock.MagicMock()
249 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
252 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
253 "topology": 'nsb_test_case.yaml',
258 'allowed_drop_rate': '0.8 - 1',
261 'rules': 'acl_1rule.yaml',
265 'worker_config': '1C/1T',
271 tg_rfc2544_trex.WAIT_TIME = 3
272 scenario_cfg.update({"nodes": {"tg_1": {}, "vnf1": {}}})
273 self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
275 @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
276 def test_instantiate_error(self, *args):
277 mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
278 mock_traffic_profile.get_traffic_definition.return_value = "64"
279 mock_traffic_profile.params = self.TRAFFIC_PROFILE
281 trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0)
282 trex_traffic_gen.resource_helper = mock.MagicMock()
283 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
285 "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
290 "topology": 'nsb_test_case.yaml',
295 'allowed_drop_rate': '0.8 - 1',
298 'rules': 'acl_1rule.yaml',
302 'worker_config': '1C/1T',
308 trex_traffic_gen.instantiate(scenario_cfg, {})