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.
21 from yardstick.benchmark import contexts
22 from yardstick.benchmark.contexts import base as ctx_base
23 from yardstick.network_services.libs.ixia_libs.ixnet import ixnet_api
24 from yardstick.network_services.traffic_profile import base as tp_base
25 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_ixia
28 TEST_FILE_YAML = 'nsb_test_case.yaml'
33 class TestIxiaResourceHelper(unittest.TestCase):
36 self._mock_IxNextgen = mock.patch.object(ixnet_api, 'IxNextgen')
37 self.mock_IxNextgen = self._mock_IxNextgen.start()
38 self.addCleanup(self._stop_mocks)
40 def _stop_mocks(self):
41 self._mock_IxNextgen.stop()
43 def test___init___with_custom_rfc_helper(self):
44 class MyRfcHelper(tg_rfc2544_ixia.IxiaRfc2544Helper):
47 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(
48 mock.Mock(), MyRfcHelper)
49 self.assertIsInstance(ixia_resource_helper.rfc_helper, MyRfcHelper)
51 def test_stop_collect_with_client(self):
52 mock_client = mock.Mock()
53 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
54 ixia_resource_helper.client = mock_client
55 ixia_resource_helper.stop_collect()
56 self.assertEqual(1, ixia_resource_helper._terminated.value)
58 def test_run_traffic(self):
59 mock_tprofile = mock.Mock()
60 mock_tprofile.get_drop_percentage.return_value = True, 'fake_samples'
61 ixia_rhelper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
62 ixia_rhelper.rfc_helper = mock.Mock()
63 ixia_rhelper.vnfd_helper = mock.Mock()
64 ixia_rhelper.vnfd_helper.port_pairs.all_ports = []
65 with mock.patch.object(ixia_rhelper, 'generate_samples'), \
66 mock.patch.object(ixia_rhelper, '_build_ports'), \
67 mock.patch.object(ixia_rhelper, '_initialize_client'):
68 ixia_rhelper.run_traffic(mock_tprofile)
70 self.assertEqual('fake_samples', ixia_rhelper._queue.get())
73 @mock.patch.object(tg_rfc2544_ixia, 'ixnet_api')
74 class TestIXIATrafficGen(unittest.TestCase):
75 VNFD = {'vnfd:vnfd-catalog':
77 [{'short-name': 'VpeVnf',
80 [{'network': '152.16.100.20',
81 'netmask': '255.255.255.0',
82 'gateway': '152.16.100.20',
84 {'network': '152.16.40.20',
85 'netmask': '255.255.255.0',
86 'gateway': '152.16.40.20',
88 'description': 'VPE approximation using DPDK',
89 'name': 'vpevnf-baremetal',
91 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
93 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
95 {'network': '0064:ff9b:0:0:0:0:9810:2814',
97 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
99 'id': 'vpevnf-baremetal',
100 'external-interface':
101 [{'virtual-interface':
102 {'dst_mac': '00:00:00:00:00:04',
103 'vpci': '0000:05:00.0',
104 'local_ip': '152.16.100.19',
105 'type': 'PCI-PASSTHROUGH',
106 'netmask': '255.255.255.0',
108 'bandwidth': '10 Gbps',
110 'dst_ip': '152.16.100.20',
111 'local_iface_name': 'xe0',
112 'local_mac': '00:00:00:00:00:02'},
113 'vnfd-connection-point-ref': 'xe0',
115 {'virtual-interface':
116 {'dst_mac': '00:00:00:00:00:03',
117 'vpci': '0000:05:00.1',
118 'local_ip': '152.16.40.19',
119 'type': 'PCI-PASSTHROUGH',
121 'netmask': '255.255.255.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:01'},
127 'vnfd-connection-point-ref': 'xe1',
129 'description': 'Vpe approximation using DPDK',
131 {'vdu-id': 'vpevnf-baremetal',
137 {'kpi': ['packets_in', 'packets_fwd',
139 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
140 {'type': 'VPORT', 'name': 'xe1'}],
141 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
144 "schema": "isb:traffic_profile:0.1",
146 "description": "Fixed traffic profile to run UDP traffic",
148 "traffic_type": "FixedTraffic",
149 "frame_rate": 100, # pps
153 TC_YAML = {'scenarios': [{'tc_options':
154 {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
155 'runner': {'duration': 400,
156 'interval': 35, 'type': 'Duration'},
158 {'flow': 'ipv4_1flow_Packets_vpe.yaml',
159 'imix': 'imix_voice.yaml'},
160 'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
161 'traffic_profile': 'ipv4_throughput_vpe.yaml',
163 'nodes': {'tg__1': 'trafficgen_1.yardstick',
164 'vnf__1': 'vnf.yardstick'},
165 'topology': 'vpe_vnf_topology.yaml'}],
166 'context': {'nfvi_type': 'baremetal',
167 'type': contexts.CONTEXT_NODE,
169 'file': '/etc/yardstick/nodes/pod.yaml'},
170 'schema': 'yardstick:task:0.1'}
172 def test___init__(self, *args):
173 with mock.patch("yardstick.ssh.SSH") as ssh:
174 ssh_mock = mock.Mock(autospec=ssh.SSH)
176 mock.Mock(return_value=(0, "", ""))
177 ssh.from_node.return_value = ssh_mock
178 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
179 # NOTE(ralonsoh): check the object returned.
180 tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd, 'task_id')
182 def test_listen_traffic(self, *args):
183 with mock.patch("yardstick.ssh.SSH") as ssh:
184 ssh_mock = mock.Mock(autospec=ssh.SSH)
186 mock.Mock(return_value=(0, "", ""))
187 ssh.from_node.return_value = ssh_mock
188 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
189 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
191 self.assertIsNone(ixnet_traffic_gen.listen_traffic({}))
193 @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
194 def test_instantiate(self, *args):
195 with mock.patch("yardstick.ssh.SSH") as ssh:
196 ssh_mock = mock.Mock(autospec=ssh.SSH)
198 mock.Mock(return_value=(0, "", ""))
200 mock.Mock(return_value=(0, "", ""))
201 ssh.from_node.return_value = ssh_mock
202 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
203 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
205 scenario_cfg = {'tc': "nsb_test_case", "topology": "",
206 'ixia_profile': "ixload.cfg"}
213 'allowed_drop_rate': '0.8 - 1'},
215 'rules': 'acl_1rule.yaml',
219 'worker_config': '1C/1T',
220 'worker_threads': 1}}}})
221 scenario_cfg.update({
222 'nodes': {ixnet_traffic_gen.name: "mock"}
224 ixnet_traffic_gen.topology = ""
225 ixnet_traffic_gen.get_ixobj = mock.MagicMock()
226 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
227 ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock()
230 ixnet_traffic_gen.instantiate(scenario_cfg, {}))
232 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
233 def test_collect_kpi(self, *args):
234 with mock.patch("yardstick.ssh.SSH") as ssh:
235 ssh_mock = mock.Mock(autospec=ssh.SSH)
237 mock.Mock(return_value=(0, "", ""))
238 ssh.from_node.return_value = ssh_mock
240 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
241 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
243 ixnet_traffic_gen.scenario_helper.scenario_cfg = {
244 'nodes': {ixnet_traffic_gen.name: "mock"}
246 ixnet_traffic_gen.data = {}
247 restult = ixnet_traffic_gen.collect_kpi()
249 expected = {'collect_stats': {},
250 'physical_node': 'mock_node'}
252 self.assertEqual(expected, restult)
254 def test_terminate(self, *args):
255 with mock.patch("yardstick.ssh.SSH") as ssh:
256 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
257 ssh_mock = mock.Mock(autospec=ssh.SSH)
259 mock.Mock(return_value=(0, "", ""))
260 ssh.from_node.return_value = ssh_mock
261 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
263 ixnet_traffic_gen._terminated = mock.MagicMock()
264 ixnet_traffic_gen._terminated.value = 0
265 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
266 ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
267 ixnet_traffic_gen._traffic_process = mock.MagicMock()
268 ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
269 self.assertIsNone(ixnet_traffic_gen.terminate())
271 def _get_file_abspath(self, filename):
272 curr_path = os.path.dirname(os.path.abspath(__file__))
273 file_path = os.path.join(curr_path, filename)
276 def test__check_status(self, *args):
277 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
278 sut = tg_rfc2544_ixia.IxiaTrafficGen('vnf1', vnfd, 'task_id')
281 @mock.patch("yardstick.ssh.SSH")
282 def test_traffic_runner(self, mock_ssh, *args):
283 mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
284 mock_traffic_profile.get_traffic_definition.return_value = "64"
285 mock_traffic_profile.params = self.TRAFFIC_PROFILE
286 # traffic_profile.ports is standardized on port_num
287 mock_traffic_profile.ports = [0, 1]
289 mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH)
290 mock_ssh_instance.execute.return_value = 0, "", ""
291 mock_ssh_instance.run.return_value = 0, "", ""
293 mock_ssh.from_node.return_value = mock_ssh_instance
295 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
296 vnfd["mgmt-interface"].update({
298 "ixchassis": "1.1.1.1",
299 "py_bin_path": "/root",
305 for ifname in range(1):
306 name = "xe{}".format(ifname)
314 "Valid_Frames_Rx": 1000,
320 samples.update({"CurrentDropPercentage": 0.0})
325 "Rx_Rate_Kbps": [20, 20],
326 "Tx_Rate_Kbps": [20, 20],
327 "Rx_Rate_Mbps": [10, 10],
328 "Tx_Rate_Mbps": [10, 10],
329 "CurrentDropPercentage": [0, 0],
330 "RxThroughput": [10, 10],
331 "TxThroughput": [10, 10],
332 "Frames_Tx": [1000, 1000],
333 "in_packets": [1000, 1000],
334 "Valid_Frames_Rx": [1000, 1000],
335 "out_packets": [1000, 1000],
339 mock_traffic_profile.execute_traffic.return_value = [
340 'Completed', samples]
341 mock_traffic_profile.get_drop_percentage.return_value = [
342 'Completed', samples]
344 sut = tg_rfc2544_ixia.IxiaTrafficGen(name, vnfd, 'task_id')
345 sut.vnf_port_pairs = [[[0], [1]]]
346 sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
349 sut.ssh_helper = mock.Mock()
350 sut._traffic_process = mock.MagicMock()
351 sut.generate_port_pairs = mock.Mock()
353 sut._ixia_traffic_gen = mock.MagicMock()
354 sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res
356 sut.resource_helper.client = mock.MagicMock()
357 sut.resource_helper.client_started = mock.MagicMock()
358 sut.resource_helper.client_started.value = 1
359 sut.resource_helper.rfc_helper.iteration.value = 11
361 sut.scenario_helper.scenario_cfg = {
366 'allowed_drop_rate': '0.8 - 1',
370 'rules': 'acl_1rule.yaml',
374 'worker_config': '1C/1T',
379 'ixia_profile': '/path/to/profile',
380 'task_path': '/path/to/task'
383 @mock.patch.object(six.moves.builtins, 'open', create=True)
384 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open',
385 mock.mock_open(), create=True)
386 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception')
387 def _traffic_runner(*args):
388 sut._setup_mq_producer = mock.Mock(return_value='mq_producer')
389 result = sut._traffic_runner(mock_traffic_profile, mock.ANY)
390 self.assertIsNone(result)