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
26 TEST_FILE_YAML = 'nsb_test_case.yaml'
31 class TestIxiaResourceHelper(unittest.TestCase):
34 self._mock_IxNextgen = mock.patch.object(ixnet_api, 'IxNextgen')
35 self.mock_IxNextgen = self._mock_IxNextgen.start()
36 self.addCleanup(self._stop_mocks)
38 def _stop_mocks(self):
39 self._mock_IxNextgen.stop()
41 def test___init___with_custom_rfc_helper(self):
42 class MyRfcHelper(tg_rfc2544_ixia.IxiaRfc2544Helper):
45 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(
46 mock.Mock(), MyRfcHelper)
47 self.assertIsInstance(ixia_resource_helper.rfc_helper, MyRfcHelper)
49 def test_stop_collect_with_client(self):
50 mock_client = mock.Mock()
51 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
52 ixia_resource_helper.client = mock_client
53 ixia_resource_helper.stop_collect()
54 self.assertEqual(1, ixia_resource_helper._terminated.value)
56 def test_run_traffic(self):
57 mock_tprofile = mock.Mock()
58 mock_tprofile.get_drop_percentage.return_value = True, 'fake_samples'
59 ixia_rhelper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
60 ixia_rhelper.rfc_helper = mock.Mock()
61 ixia_rhelper.vnfd_helper = mock.Mock()
62 ixia_rhelper.vnfd_helper.port_pairs.all_ports = []
63 with mock.patch.object(ixia_rhelper, 'generate_samples'), \
64 mock.patch.object(ixia_rhelper, '_build_ports'), \
65 mock.patch.object(ixia_rhelper, '_initialize_client'):
66 ixia_rhelper.run_traffic(mock_tprofile)
68 self.assertEqual('fake_samples', ixia_rhelper._queue.get())
71 @mock.patch.object(tg_rfc2544_ixia, 'ixnet_api')
72 class TestIXIATrafficGen(unittest.TestCase):
73 VNFD = {'vnfd:vnfd-catalog':
75 [{'short-name': 'VpeVnf',
78 [{'network': '152.16.100.20',
79 'netmask': '255.255.255.0',
80 'gateway': '152.16.100.20',
82 {'network': '152.16.40.20',
83 'netmask': '255.255.255.0',
84 'gateway': '152.16.40.20',
86 'description': 'VPE approximation using DPDK',
87 'name': 'vpevnf-baremetal',
89 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
91 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
93 {'network': '0064:ff9b:0:0:0:0:9810:2814',
95 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
97 'id': 'vpevnf-baremetal',
99 [{'virtual-interface':
100 {'dst_mac': '00:00:00:00:00:04',
101 'vpci': '0000:05:00.0',
102 'local_ip': '152.16.100.19',
103 'type': 'PCI-PASSTHROUGH',
104 'netmask': '255.255.255.0',
106 'bandwidth': '10 Gbps',
108 'dst_ip': '152.16.100.20',
109 'local_iface_name': 'xe0',
110 'local_mac': '00:00:00:00:00:02'},
111 'vnfd-connection-point-ref': 'xe0',
113 {'virtual-interface':
114 {'dst_mac': '00:00:00:00:00:03',
115 'vpci': '0000:05:00.1',
116 'local_ip': '152.16.40.19',
117 'type': 'PCI-PASSTHROUGH',
119 'netmask': '255.255.255.0',
121 'bandwidth': '10 Gbps',
122 'dst_ip': '152.16.40.20',
123 'local_iface_name': 'xe1',
124 'local_mac': '00:00:00:00:00:01'},
125 'vnfd-connection-point-ref': 'xe1',
127 'description': 'Vpe approximation using DPDK',
129 {'vdu-id': 'vpevnf-baremetal',
135 {'kpi': ['packets_in', 'packets_fwd',
137 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
138 {'type': 'VPORT', 'name': 'xe1'}],
139 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
142 "schema": "isb:traffic_profile:0.1",
144 "description": "Fixed traffic profile to run UDP traffic",
146 "traffic_type": "FixedTraffic",
147 "frame_rate": 100, # pps
151 TC_YAML = {'scenarios': [{'tc_options':
152 {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
153 'runner': {'duration': 400,
154 'interval': 35, 'type': 'Duration'},
156 {'flow': 'ipv4_1flow_Packets_vpe.yaml',
157 'imix': 'imix_voice.yaml'},
158 'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
159 'traffic_profile': 'ipv4_throughput_vpe.yaml',
161 'nodes': {'tg__1': 'trafficgen_1.yardstick',
162 'vnf__1': 'vnf.yardstick'},
163 'topology': 'vpe_vnf_topology.yaml'}],
164 'context': {'nfvi_type': 'baremetal', 'type': 'Node',
166 'file': '/etc/yardstick/nodes/pod.yaml'},
167 'schema': 'yardstick:task:0.1'}
169 def test___init__(self, *args):
170 with mock.patch("yardstick.ssh.SSH") as ssh:
171 ssh_mock = mock.Mock(autospec=ssh.SSH)
173 mock.Mock(return_value=(0, "", ""))
174 ssh.from_node.return_value = ssh_mock
175 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
176 # NOTE(ralonsoh): check the object returned.
177 tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
179 def test_listen_traffic(self, *args):
180 with mock.patch("yardstick.ssh.SSH") as ssh:
181 ssh_mock = mock.Mock(autospec=ssh.SSH)
183 mock.Mock(return_value=(0, "", ""))
184 ssh.from_node.return_value = ssh_mock
185 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
186 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
187 self.assertIsNone(ixnet_traffic_gen.listen_traffic({}))
189 def test_instantiate(self, *args):
190 with mock.patch("yardstick.ssh.SSH") as ssh:
191 ssh_mock = mock.Mock(autospec=ssh.SSH)
193 mock.Mock(return_value=(0, "", ""))
195 mock.Mock(return_value=(0, "", ""))
196 ssh.from_node.return_value = ssh_mock
197 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
198 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
199 scenario_cfg = {'tc': "nsb_test_case", "topology": "",
200 'ixia_profile': "ixload.cfg"}
207 'allowed_drop_rate': '0.8 - 1'},
209 'rules': 'acl_1rule.yaml',
213 'worker_config': '1C/1T',
214 'worker_threads': 1}}}})
215 ixnet_traffic_gen.topology = ""
216 ixnet_traffic_gen.get_ixobj = mock.MagicMock()
217 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
218 ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock()
221 ixnet_traffic_gen.instantiate(scenario_cfg, {}))
223 def test_collect_kpi(self, *args):
224 with mock.patch("yardstick.ssh.SSH") as ssh:
225 ssh_mock = mock.Mock(autospec=ssh.SSH)
227 mock.Mock(return_value=(0, "", ""))
228 ssh.from_node.return_value = ssh_mock
229 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
230 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
231 ixnet_traffic_gen.data = {}
232 restult = ixnet_traffic_gen.collect_kpi()
233 self.assertEqual({}, restult)
235 def test_terminate(self, *args):
236 with mock.patch("yardstick.ssh.SSH") as ssh:
237 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
238 ssh_mock = mock.Mock(autospec=ssh.SSH)
240 mock.Mock(return_value=(0, "", ""))
241 ssh.from_node.return_value = ssh_mock
242 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
243 ixnet_traffic_gen._terminated = mock.MagicMock()
244 ixnet_traffic_gen._terminated.value = 0
245 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
246 ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
247 ixnet_traffic_gen._traffic_process = mock.MagicMock()
248 ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
249 self.assertIsNone(ixnet_traffic_gen.terminate())
251 def _get_file_abspath(self, filename):
252 curr_path = os.path.dirname(os.path.abspath(__file__))
253 file_path = os.path.join(curr_path, filename)
256 def test__check_status(self, *args):
257 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
258 sut = tg_rfc2544_ixia.IxiaTrafficGen('vnf1', vnfd)
261 @mock.patch("yardstick.ssh.SSH")
262 def test_traffic_runner(self, mock_ssh, *args):
263 mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
264 mock_traffic_profile.get_traffic_definition.return_value = "64"
265 mock_traffic_profile.params = self.TRAFFIC_PROFILE
266 # traffic_profile.ports is standardized on port_num
267 mock_traffic_profile.ports = [0, 1]
269 mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH)
270 mock_ssh_instance.execute.return_value = 0, "", ""
271 mock_ssh_instance.run.return_value = 0, "", ""
273 mock_ssh.from_node.return_value = mock_ssh_instance
275 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
276 vnfd["mgmt-interface"].update({
278 "ixchassis": "1.1.1.1",
279 "py_bin_path": "/root",
285 for ifname in range(1):
286 name = "xe{}".format(ifname)
294 "Valid_Frames_Rx": 1000,
300 samples.update({"CurrentDropPercentage": 0.0})
305 "Rx_Rate_Kbps": [20, 20],
306 "Tx_Rate_Kbps": [20, 20],
307 "Rx_Rate_Mbps": [10, 10],
308 "Tx_Rate_Mbps": [10, 10],
309 "CurrentDropPercentage": [0, 0],
310 "RxThroughput": [10, 10],
311 "TxThroughput": [10, 10],
312 "Frames_Tx": [1000, 1000],
313 "in_packets": [1000, 1000],
314 "Valid_Frames_Rx": [1000, 1000],
315 "out_packets": [1000, 1000],
319 mock_traffic_profile.execute_traffic.return_value = [
320 'Completed', samples]
321 mock_traffic_profile.get_drop_percentage.return_value = [
322 'Completed', samples]
324 sut = tg_rfc2544_ixia.IxiaTrafficGen(name, vnfd)
325 sut.vnf_port_pairs = [[[0], [1]]]
326 sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
329 sut.ssh_helper = mock.Mock()
330 sut._traffic_process = mock.MagicMock()
331 sut.generate_port_pairs = mock.Mock()
333 sut._ixia_traffic_gen = mock.MagicMock()
334 sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res
336 sut.resource_helper.client = mock.MagicMock()
337 sut.resource_helper.client_started = mock.MagicMock()
338 sut.resource_helper.client_started.value = 1
339 sut.resource_helper.rfc_helper.iteration.value = 11
341 sut.scenario_helper.scenario_cfg = {
346 'allowed_drop_rate': '0.8 - 1',
350 'rules': 'acl_1rule.yaml',
354 'worker_config': '1C/1T',
359 'ixia_profile': '/path/to/profile',
360 'task_path': '/path/to/task'
363 @mock.patch.object(six.moves.builtins, 'open', create=True)
364 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open',
365 mock.mock_open(), create=True)
366 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception')
367 def _traffic_runner(*args):
368 result = sut._traffic_runner(mock_traffic_profile)
369 self.assertIsNone(result)