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.network_services.libs.ixia_libs.ixnet import ixnet_api
22 from yardstick.network_services.traffic_profile import base as tp_base
23 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_ixia
24 from yardstick.benchmark.contexts import base as ctx_base
27 TEST_FILE_YAML = 'nsb_test_case.yaml'
32 class TestIxiaResourceHelper(unittest.TestCase):
35 self._mock_IxNextgen = mock.patch.object(ixnet_api, 'IxNextgen')
36 self.mock_IxNextgen = self._mock_IxNextgen.start()
37 self.addCleanup(self._stop_mocks)
39 def _stop_mocks(self):
40 self._mock_IxNextgen.stop()
42 def test___init___with_custom_rfc_helper(self):
43 class MyRfcHelper(tg_rfc2544_ixia.IxiaRfc2544Helper):
46 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(
47 mock.Mock(), MyRfcHelper)
48 self.assertIsInstance(ixia_resource_helper.rfc_helper, MyRfcHelper)
50 def test_stop_collect_with_client(self):
51 mock_client = mock.Mock()
52 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
53 ixia_resource_helper.client = mock_client
54 ixia_resource_helper.stop_collect()
55 self.assertEqual(1, ixia_resource_helper._terminated.value)
57 def test_run_traffic(self):
58 mock_tprofile = mock.Mock()
59 mock_tprofile.get_drop_percentage.return_value = True, 'fake_samples'
60 ixia_rhelper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
61 ixia_rhelper.rfc_helper = mock.Mock()
62 ixia_rhelper.vnfd_helper = mock.Mock()
63 ixia_rhelper.vnfd_helper.port_pairs.all_ports = []
64 with mock.patch.object(ixia_rhelper, 'generate_samples'), \
65 mock.patch.object(ixia_rhelper, '_build_ports'), \
66 mock.patch.object(ixia_rhelper, '_initialize_client'):
67 ixia_rhelper.run_traffic(mock_tprofile)
69 self.assertEqual('fake_samples', ixia_rhelper._queue.get())
72 @mock.patch.object(tg_rfc2544_ixia, 'ixnet_api')
73 class TestIXIATrafficGen(unittest.TestCase):
74 VNFD = {'vnfd:vnfd-catalog':
76 [{'short-name': 'VpeVnf',
79 [{'network': '152.16.100.20',
80 'netmask': '255.255.255.0',
81 'gateway': '152.16.100.20',
83 {'network': '152.16.40.20',
84 'netmask': '255.255.255.0',
85 'gateway': '152.16.40.20',
87 'description': 'VPE approximation using DPDK',
88 'name': 'vpevnf-baremetal',
90 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
92 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
94 {'network': '0064:ff9b:0:0:0:0:9810:2814',
96 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
98 'id': 'vpevnf-baremetal',
100 [{'virtual-interface':
101 {'dst_mac': '00:00:00:00:00:04',
102 'vpci': '0000:05:00.0',
103 'local_ip': '152.16.100.19',
104 'type': 'PCI-PASSTHROUGH',
105 'netmask': '255.255.255.0',
107 'bandwidth': '10 Gbps',
109 'dst_ip': '152.16.100.20',
110 'local_iface_name': 'xe0',
111 'local_mac': '00:00:00:00:00:02'},
112 'vnfd-connection-point-ref': 'xe0',
114 {'virtual-interface':
115 {'dst_mac': '00:00:00:00:00:03',
116 'vpci': '0000:05:00.1',
117 'local_ip': '152.16.40.19',
118 'type': 'PCI-PASSTHROUGH',
120 'netmask': '255.255.255.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:01'},
126 'vnfd-connection-point-ref': 'xe1',
128 'description': 'Vpe approximation using DPDK',
130 {'vdu-id': 'vpevnf-baremetal',
136 {'kpi': ['packets_in', 'packets_fwd',
138 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
139 {'type': 'VPORT', 'name': 'xe1'}],
140 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
143 "schema": "isb:traffic_profile:0.1",
145 "description": "Fixed traffic profile to run UDP traffic",
147 "traffic_type": "FixedTraffic",
148 "frame_rate": 100, # pps
152 TC_YAML = {'scenarios': [{'tc_options':
153 {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
154 'runner': {'duration': 400,
155 'interval': 35, 'type': 'Duration'},
157 {'flow': 'ipv4_1flow_Packets_vpe.yaml',
158 'imix': 'imix_voice.yaml'},
159 'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
160 'traffic_profile': 'ipv4_throughput_vpe.yaml',
162 'nodes': {'tg__1': 'trafficgen_1.yardstick',
163 'vnf__1': 'vnf.yardstick'},
164 'topology': 'vpe_vnf_topology.yaml'}],
165 'context': {'nfvi_type': 'baremetal', 'type': 'Node',
167 'file': '/etc/yardstick/nodes/pod.yaml'},
168 'schema': 'yardstick:task:0.1'}
170 def test___init__(self, *args):
171 with mock.patch("yardstick.ssh.SSH") as ssh:
172 ssh_mock = mock.Mock(autospec=ssh.SSH)
174 mock.Mock(return_value=(0, "", ""))
175 ssh.from_node.return_value = ssh_mock
176 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
177 # NOTE(ralonsoh): check the object returned.
178 tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
180 def test_listen_traffic(self, *args):
181 with mock.patch("yardstick.ssh.SSH") as ssh:
182 ssh_mock = mock.Mock(autospec=ssh.SSH)
184 mock.Mock(return_value=(0, "", ""))
185 ssh.from_node.return_value = ssh_mock
186 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
187 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
188 self.assertIsNone(ixnet_traffic_gen.listen_traffic({}))
190 @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
191 def test_instantiate(self, *args):
192 with mock.patch("yardstick.ssh.SSH") as ssh:
193 ssh_mock = mock.Mock(autospec=ssh.SSH)
195 mock.Mock(return_value=(0, "", ""))
197 mock.Mock(return_value=(0, "", ""))
198 ssh.from_node.return_value = ssh_mock
199 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
200 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
201 scenario_cfg = {'tc': "nsb_test_case", "topology": "",
202 'ixia_profile': "ixload.cfg"}
209 'allowed_drop_rate': '0.8 - 1'},
211 'rules': 'acl_1rule.yaml',
215 'worker_config': '1C/1T',
216 'worker_threads': 1}}}})
217 scenario_cfg.update({
218 'nodes': {ixnet_traffic_gen.name: "mock"}
220 ixnet_traffic_gen.topology = ""
221 ixnet_traffic_gen.get_ixobj = mock.MagicMock()
222 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
223 ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock()
226 ixnet_traffic_gen.instantiate(scenario_cfg, {}))
228 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
229 def test_collect_kpi(self, *args):
230 with mock.patch("yardstick.ssh.SSH") as ssh:
231 ssh_mock = mock.Mock(autospec=ssh.SSH)
233 mock.Mock(return_value=(0, "", ""))
234 ssh.from_node.return_value = ssh_mock
236 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
237 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
238 ixnet_traffic_gen.scenario_helper.scenario_cfg = {
239 'nodes': {ixnet_traffic_gen.name: "mock"}
241 ixnet_traffic_gen.data = {}
242 restult = ixnet_traffic_gen.collect_kpi()
244 expected = {'collect_stats': {},
245 'physical_node': 'mock_node'}
247 self.assertEqual(expected, restult)
249 def test_terminate(self, *args):
250 with mock.patch("yardstick.ssh.SSH") as ssh:
251 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
252 ssh_mock = mock.Mock(autospec=ssh.SSH)
254 mock.Mock(return_value=(0, "", ""))
255 ssh.from_node.return_value = ssh_mock
256 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
257 ixnet_traffic_gen._terminated = mock.MagicMock()
258 ixnet_traffic_gen._terminated.value = 0
259 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
260 ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
261 ixnet_traffic_gen._traffic_process = mock.MagicMock()
262 ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
263 self.assertIsNone(ixnet_traffic_gen.terminate())
265 def _get_file_abspath(self, filename):
266 curr_path = os.path.dirname(os.path.abspath(__file__))
267 file_path = os.path.join(curr_path, filename)
270 def test__check_status(self, *args):
271 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
272 sut = tg_rfc2544_ixia.IxiaTrafficGen('vnf1', vnfd)
275 @mock.patch("yardstick.ssh.SSH")
276 def test_traffic_runner(self, mock_ssh, *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
280 # traffic_profile.ports is standardized on port_num
281 mock_traffic_profile.ports = [0, 1]
283 mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH)
284 mock_ssh_instance.execute.return_value = 0, "", ""
285 mock_ssh_instance.run.return_value = 0, "", ""
287 mock_ssh.from_node.return_value = mock_ssh_instance
289 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
290 vnfd["mgmt-interface"].update({
292 "ixchassis": "1.1.1.1",
293 "py_bin_path": "/root",
299 for ifname in range(1):
300 name = "xe{}".format(ifname)
308 "Valid_Frames_Rx": 1000,
314 samples.update({"CurrentDropPercentage": 0.0})
319 "Rx_Rate_Kbps": [20, 20],
320 "Tx_Rate_Kbps": [20, 20],
321 "Rx_Rate_Mbps": [10, 10],
322 "Tx_Rate_Mbps": [10, 10],
323 "CurrentDropPercentage": [0, 0],
324 "RxThroughput": [10, 10],
325 "TxThroughput": [10, 10],
326 "Frames_Tx": [1000, 1000],
327 "in_packets": [1000, 1000],
328 "Valid_Frames_Rx": [1000, 1000],
329 "out_packets": [1000, 1000],
333 mock_traffic_profile.execute_traffic.return_value = [
334 'Completed', samples]
335 mock_traffic_profile.get_drop_percentage.return_value = [
336 'Completed', samples]
338 sut = tg_rfc2544_ixia.IxiaTrafficGen(name, vnfd)
339 sut.vnf_port_pairs = [[[0], [1]]]
340 sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
343 sut.ssh_helper = mock.Mock()
344 sut._traffic_process = mock.MagicMock()
345 sut.generate_port_pairs = mock.Mock()
347 sut._ixia_traffic_gen = mock.MagicMock()
348 sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res
350 sut.resource_helper.client = mock.MagicMock()
351 sut.resource_helper.client_started = mock.MagicMock()
352 sut.resource_helper.client_started.value = 1
353 sut.resource_helper.rfc_helper.iteration.value = 11
355 sut.scenario_helper.scenario_cfg = {
360 'allowed_drop_rate': '0.8 - 1',
364 'rules': 'acl_1rule.yaml',
368 'worker_config': '1C/1T',
373 'ixia_profile': '/path/to/profile',
374 'task_path': '/path/to/task'
377 @mock.patch.object(six.moves.builtins, 'open', create=True)
378 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open',
379 mock.mock_open(), create=True)
380 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception')
381 def _traffic_runner(*args):
382 result = sut._traffic_runner(mock_traffic_profile)
383 self.assertIsNone(result)