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.common import utils
22 from yardstick.benchmark import contexts
23 from yardstick.benchmark.contexts import base as ctx_base
24 from yardstick.network_services.libs.ixia_libs.ixnet import ixnet_api
25 from yardstick.network_services.traffic_profile import base as tp_base
26 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_ixia
29 TEST_FILE_YAML = 'nsb_test_case.yaml'
34 class TestIxiaResourceHelper(unittest.TestCase):
37 self._mock_IxNextgen = mock.patch.object(ixnet_api, 'IxNextgen')
38 self.mock_IxNextgen = self._mock_IxNextgen.start()
39 self.addCleanup(self._stop_mocks)
41 def _stop_mocks(self):
42 self._mock_IxNextgen.stop()
44 def test___init___with_custom_rfc_helper(self):
45 class MyRfcHelper(tg_rfc2544_ixia.IxiaRfc2544Helper):
48 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(
49 mock.Mock(), MyRfcHelper)
50 self.assertIsInstance(ixia_resource_helper.rfc_helper, MyRfcHelper)
52 def test_stop_collect_with_client(self):
53 mock_client = mock.Mock()
54 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
55 ixia_resource_helper.client = mock_client
56 ixia_resource_helper.stop_collect()
57 self.assertEqual(1, ixia_resource_helper._terminated.value)
59 def test_run_traffic(self):
60 mock_tprofile = mock.Mock()
61 mock_tprofile.config.duration = 10
62 mock_tprofile.get_drop_percentage.return_value = True, 'fake_samples'
63 ixia_rhelper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
64 ixia_rhelper.rfc_helper = mock.Mock()
65 ixia_rhelper.vnfd_helper = mock.Mock()
66 ixia_rhelper.vnfd_helper.port_pairs.all_ports = []
67 with mock.patch.object(ixia_rhelper, 'generate_samples'), \
68 mock.patch.object(ixia_rhelper, '_build_ports'), \
69 mock.patch.object(ixia_rhelper, '_initialize_client'), \
70 mock.patch.object(utils, 'wait_until_true'):
71 ixia_rhelper.run_traffic(mock_tprofile)
73 self.assertEqual('fake_samples', ixia_rhelper._queue.get())
76 @mock.patch.object(tg_rfc2544_ixia, 'ixnet_api')
77 class TestIXIATrafficGen(unittest.TestCase):
78 VNFD = {'vnfd:vnfd-catalog':
80 [{'short-name': 'VpeVnf',
83 [{'network': '152.16.100.20',
84 'netmask': '255.255.255.0',
85 'gateway': '152.16.100.20',
87 {'network': '152.16.40.20',
88 'netmask': '255.255.255.0',
89 'gateway': '152.16.40.20',
91 'description': 'VPE approximation using DPDK',
92 'name': 'vpevnf-baremetal',
94 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
96 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
98 {'network': '0064:ff9b:0:0:0:0:9810:2814',
100 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
102 'id': 'vpevnf-baremetal',
103 'external-interface':
104 [{'virtual-interface':
105 {'dst_mac': '00:00:00:00:00:04',
106 'vpci': '0000:05:00.0',
107 'local_ip': '152.16.100.19',
108 'type': 'PCI-PASSTHROUGH',
109 'netmask': '255.255.255.0',
111 'bandwidth': '10 Gbps',
113 'dst_ip': '152.16.100.20',
114 'local_iface_name': 'xe0',
115 'local_mac': '00:00:00:00:00:02'},
116 'vnfd-connection-point-ref': 'xe0',
118 {'virtual-interface':
119 {'dst_mac': '00:00:00:00:00:03',
120 'vpci': '0000:05:00.1',
121 'local_ip': '152.16.40.19',
122 'type': 'PCI-PASSTHROUGH',
124 'netmask': '255.255.255.0',
126 'bandwidth': '10 Gbps',
127 'dst_ip': '152.16.40.20',
128 'local_iface_name': 'xe1',
129 'local_mac': '00:00:00:00:00:01'},
130 'vnfd-connection-point-ref': 'xe1',
132 'description': 'Vpe approximation using DPDK',
134 {'vdu-id': 'vpevnf-baremetal',
140 {'kpi': ['packets_in', 'packets_fwd',
142 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
143 {'type': 'VPORT', 'name': 'xe1'}],
144 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
147 "schema": "isb:traffic_profile:0.1",
149 "description": "Fixed traffic profile to run UDP traffic",
151 "traffic_type": "FixedTraffic",
152 "frame_rate": 100, # pps
156 TC_YAML = {'scenarios': [{'tc_options':
157 {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
158 'runner': {'duration': 400,
159 'interval': 35, 'type': 'Duration'},
161 {'flow': 'ipv4_1flow_Packets_vpe.yaml',
162 'imix': 'imix_voice.yaml'},
163 'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
164 'traffic_profile': 'ipv4_throughput_vpe.yaml',
166 'nodes': {'tg__1': 'trafficgen_1.yardstick',
167 'vnf__1': 'vnf.yardstick'},
168 'topology': 'vpe_vnf_topology.yaml'}],
169 'context': {'nfvi_type': 'baremetal',
170 'type': contexts.CONTEXT_NODE,
172 'file': '/etc/yardstick/nodes/pod.yaml'},
173 'schema': 'yardstick:task:0.1'}
175 def test___init__(self, *args):
176 with mock.patch("yardstick.ssh.SSH") as ssh:
177 ssh_mock = mock.Mock(autospec=ssh.SSH)
179 mock.Mock(return_value=(0, "", ""))
180 ssh.from_node.return_value = ssh_mock
181 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
182 # NOTE(ralonsoh): check the object returned.
183 tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd, 'task_id')
185 def test_listen_traffic(self, *args):
186 with mock.patch("yardstick.ssh.SSH") as ssh:
187 ssh_mock = mock.Mock(autospec=ssh.SSH)
189 mock.Mock(return_value=(0, "", ""))
190 ssh.from_node.return_value = ssh_mock
191 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
192 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
194 self.assertIsNone(ixnet_traffic_gen.listen_traffic({}))
196 @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
197 def test_instantiate(self, *args):
198 with mock.patch("yardstick.ssh.SSH") as ssh:
199 ssh_mock = mock.Mock(autospec=ssh.SSH)
201 mock.Mock(return_value=(0, "", ""))
203 mock.Mock(return_value=(0, "", ""))
204 ssh.from_node.return_value = ssh_mock
205 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
206 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
208 scenario_cfg = {'tc': "nsb_test_case", "topology": "",
209 'ixia_profile': "ixload.cfg"}
216 'allowed_drop_rate': '0.8 - 1'},
218 'rules': 'acl_1rule.yaml',
222 'worker_config': '1C/1T',
223 'worker_threads': 1}}}})
224 scenario_cfg.update({
225 'nodes': {ixnet_traffic_gen.name: "mock"}
227 ixnet_traffic_gen.topology = ""
228 ixnet_traffic_gen.get_ixobj = mock.MagicMock()
229 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
230 ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock()
233 ixnet_traffic_gen.instantiate(scenario_cfg, {}))
235 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
236 def test_collect_kpi(self, *args):
237 with mock.patch("yardstick.ssh.SSH") as ssh:
238 ssh_mock = mock.Mock(autospec=ssh.SSH)
240 mock.Mock(return_value=(0, "", ""))
241 ssh.from_node.return_value = ssh_mock
243 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
244 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
246 ixnet_traffic_gen.scenario_helper.scenario_cfg = {
247 'nodes': {ixnet_traffic_gen.name: "mock"}
249 ixnet_traffic_gen.data = {}
250 restult = ixnet_traffic_gen.collect_kpi()
252 expected = {'collect_stats': {},
253 'physical_node': 'mock_node'}
255 self.assertEqual(expected, restult)
257 def test_terminate(self, *args):
258 with mock.patch("yardstick.ssh.SSH") as ssh:
259 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
260 ssh_mock = mock.Mock(autospec=ssh.SSH)
262 mock.Mock(return_value=(0, "", ""))
263 ssh.from_node.return_value = ssh_mock
264 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
266 ixnet_traffic_gen._terminated = mock.MagicMock()
267 ixnet_traffic_gen._terminated.value = 0
268 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
269 ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
270 ixnet_traffic_gen._traffic_process = mock.MagicMock()
271 ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
272 self.assertIsNone(ixnet_traffic_gen.terminate())
274 def _get_file_abspath(self, filename):
275 curr_path = os.path.dirname(os.path.abspath(__file__))
276 file_path = os.path.join(curr_path, filename)
279 def test__check_status(self, *args):
280 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
281 sut = tg_rfc2544_ixia.IxiaTrafficGen('vnf1', vnfd, 'task_id')
284 @mock.patch("yardstick.ssh.SSH")
285 def test_traffic_runner(self, mock_ssh, *args):
286 mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
287 mock_traffic_profile.get_traffic_definition.return_value = "64"
288 mock_traffic_profile.params = self.TRAFFIC_PROFILE
289 # traffic_profile.ports is standardized on port_num
290 mock_traffic_profile.ports = [0, 1]
292 mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH)
293 mock_ssh_instance.execute.return_value = 0, "", ""
294 mock_ssh_instance.run.return_value = 0, "", ""
296 mock_ssh.from_node.return_value = mock_ssh_instance
298 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
299 vnfd["mgmt-interface"].update({
301 "ixchassis": "1.1.1.1",
302 "py_bin_path": "/root",
308 for ifname in range(1):
309 name = "xe{}".format(ifname)
317 "Valid_Frames_Rx": 1000,
323 samples.update({"CurrentDropPercentage": 0.0})
328 "Rx_Rate_Kbps": [20, 20],
329 "Tx_Rate_Kbps": [20, 20],
330 "Rx_Rate_Mbps": [10, 10],
331 "Tx_Rate_Mbps": [10, 10],
332 "CurrentDropPercentage": [0, 0],
333 "RxThroughput": [10, 10],
334 "TxThroughput": [10, 10],
335 "Frames_Tx": [1000, 1000],
336 "in_packets": [1000, 1000],
337 "Valid_Frames_Rx": [1000, 1000],
338 "out_packets": [1000, 1000],
342 mock_traffic_profile.execute_traffic.return_value = [
343 'Completed', samples]
344 mock_traffic_profile.get_drop_percentage.return_value = [
345 'Completed', samples]
347 sut = tg_rfc2544_ixia.IxiaTrafficGen(name, vnfd, 'task_id')
348 sut.vnf_port_pairs = [[[0], [1]]]
349 sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
352 sut.ssh_helper = mock.Mock()
353 sut._traffic_process = mock.MagicMock()
354 sut.generate_port_pairs = mock.Mock()
356 sut._ixia_traffic_gen = mock.MagicMock()
357 sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res
359 sut.resource_helper.client = mock.MagicMock()
360 sut.resource_helper.client_started = mock.MagicMock()
361 sut.resource_helper.client_started.value = 1
362 sut.resource_helper.rfc_helper.iteration.value = 11
364 sut.scenario_helper.scenario_cfg = {
369 'allowed_drop_rate': '0.8 - 1',
373 'rules': 'acl_1rule.yaml',
377 'worker_config': '1C/1T',
382 'ixia_profile': '/path/to/profile',
383 'task_path': '/path/to/task'
386 @mock.patch.object(six.moves.builtins, 'open', create=True)
387 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open',
388 mock.mock_open(), create=True)
389 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception')
390 def _traffic_runner(*args):
391 sut._setup_mq_producer = mock.Mock(return_value='mq_producer')
392 result = sut._traffic_runner(mock_traffic_profile, mock.ANY)
393 self.assertIsNone(result)