3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from __future__ import absolute_import
24 from tests.unit import STL_MOCKS
26 STLClient = mock.MagicMock()
27 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
31 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaTrafficGen
32 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaRfc2544Helper
33 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaResourceHelper
34 from yardstick.network_services.traffic_profile.base import TrafficProfile
36 TEST_FILE_YAML = 'nsb_test_case.yaml'
41 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen")
42 class TestIxiaResourceHelper(unittest.TestCase):
43 def test___init___with_custom_rfc_helper(self, mock_ix_nextgen):
44 class MyRfcHelper(IxiaRfc2544Helper):
47 ixia_resource_helper = IxiaResourceHelper(mock.Mock(), MyRfcHelper)
48 self.assertIsInstance(ixia_resource_helper.rfc_helper, MyRfcHelper)
50 def test_stop_collect_with_client(self, mock_ix_nextgen):
51 mock_client = mock.Mock()
53 ixia_resource_helper = IxiaResourceHelper(mock.Mock())
55 ixia_resource_helper.client = mock_client
56 ixia_resource_helper.stop_collect()
57 self.assertEqual(mock_client.ix_stop_traffic.call_count, 1)
60 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen")
61 class TestIXIATrafficGen(unittest.TestCase):
62 VNFD = {'vnfd:vnfd-catalog':
64 [{'short-name': 'VpeVnf',
67 [{'network': '152.16.100.20',
68 'netmask': '255.255.255.0',
69 'gateway': '152.16.100.20',
71 {'network': '152.16.40.20',
72 'netmask': '255.255.255.0',
73 'gateway': '152.16.40.20',
75 'description': 'VPE approximation using DPDK',
76 'name': 'vpevnf-baremetal',
78 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
80 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
82 {'network': '0064:ff9b:0:0:0:0:9810:2814',
84 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
86 'id': 'vpevnf-baremetal',
88 [{'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',
95 'bandwidth': '10 Gbps',
97 'dst_ip': '152.16.100.20',
98 'local_iface_name': 'xe0',
99 'local_mac': '00:00:00:00:00:02'},
100 'vnfd-connection-point-ref': 'xe0',
102 {'virtual-interface':
103 {'dst_mac': '00:00:00:00:00:03',
104 'vpci': '0000:05:00.1',
105 'local_ip': '152.16.40.19',
106 'type': 'PCI-PASSTHROUGH',
108 'netmask': '255.255.255.0',
110 'bandwidth': '10 Gbps',
111 'dst_ip': '152.16.40.20',
112 'local_iface_name': 'xe1',
113 'local_mac': '00:00:00:00:00:01'},
114 'vnfd-connection-point-ref': 'xe1',
116 'description': 'Vpe approximation using DPDK',
118 {'vdu-id': 'vpevnf-baremetal',
124 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
125 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
126 {'type': 'VPORT', 'name': 'xe1'}],
127 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
130 "schema": "isb:traffic_profile:0.1",
132 "description": "Fixed traffic profile to run UDP traffic",
134 "traffic_type": "FixedTraffic",
135 "frame_rate": 100, # pps
139 TC_YAML = {'scenarios': [{'tc_options':
140 {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
141 'runner': {'duration': 400,
142 'interval': 35, 'type': 'Duration'},
144 {'flow': 'ipv4_1flow_Packets_vpe.yaml',
145 'imix': 'imix_voice.yaml'},
146 'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
147 'traffic_profile': 'ipv4_throughput_vpe.yaml',
149 'nodes': {'tg__1': 'trafficgen_1.yardstick',
150 'vnf__1': 'vnf.yardstick'},
151 'topology': 'vpe_vnf_topology.yaml'}],
152 'context': {'nfvi_type': 'baremetal', 'type': 'Node',
154 'file': '/etc/yardstick/nodes/pod.yaml'},
155 'schema': 'yardstick:task:0.1'}
157 def test___init__(self, mock_ixnextgen):
158 with mock.patch("yardstick.ssh.SSH") as ssh:
159 ssh_mock = mock.Mock(autospec=ssh.SSH)
161 mock.Mock(return_value=(0, "", ""))
162 ssh.from_node.return_value = ssh_mock
163 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
164 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
166 def test_listen_traffic(self, mock_ixnextgen):
167 with mock.patch("yardstick.ssh.SSH") as ssh:
168 ssh_mock = mock.Mock(autospec=ssh.SSH)
170 mock.Mock(return_value=(0, "", ""))
171 ssh.from_node.return_value = ssh_mock
172 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
173 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
174 self.assertEqual(None, ixnet_traffic_gen.listen_traffic({}))
176 def test_instantiate(self, mock_ixnextgen):
177 with mock.patch("yardstick.ssh.SSH") as ssh:
178 ssh_mock = mock.Mock(autospec=ssh.SSH)
180 mock.Mock(return_value=(0, "", ""))
182 mock.Mock(return_value=(0, "", ""))
183 ssh.from_node.return_value = ssh_mock
184 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
185 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
186 scenario_cfg = {'tc': "nsb_test_case", "topology": "",
187 'ixia_profile': "ixload.cfg"}
188 scenario_cfg.update({'options': {'packetsize': 64,
190 'rfc2544': {'allowed_drop_rate': '0.8 - 1'},
191 'vnf__1': {'rules': 'acl_1rule.yaml',
192 'vnf_config': {'lb_config': 'SW',
196 'worker_threads': 1}}
198 ixnet_traffic_gen.topology = ""
199 ixnet_traffic_gen.get_ixobj = mock.MagicMock()
200 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
201 ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock()
204 ixnet_traffic_gen.instantiate(scenario_cfg, {}))
206 def test_collect_kpi(self, mock_ixnextgen):
207 with mock.patch("yardstick.ssh.SSH") as ssh:
208 ssh_mock = mock.Mock(autospec=ssh.SSH)
210 mock.Mock(return_value=(0, "", ""))
211 ssh.from_node.return_value = ssh_mock
212 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
213 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
214 ixnet_traffic_gen.data = {}
215 restult = ixnet_traffic_gen.collect_kpi()
216 self.assertEqual({}, restult)
218 def test_terminate(self, mock_ixnextgen):
219 with mock.patch("yardstick.ssh.SSH") as ssh:
220 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
221 ssh_mock = mock.Mock(autospec=ssh.SSH)
223 mock.Mock(return_value=(0, "", ""))
224 ssh.from_node.return_value = ssh_mock
225 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
226 ixnet_traffic_gen._terminated = mock.MagicMock()
227 ixnet_traffic_gen._terminated.value = 0
228 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
229 ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
230 ixnet_traffic_gen._traffic_process = mock.MagicMock()
231 ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
232 self.assertEqual(None, ixnet_traffic_gen.terminate())
234 def _get_file_abspath(self, filename):
235 curr_path = os.path.dirname(os.path.abspath(__file__))
236 file_path = os.path.join(curr_path, filename)
239 def test_scale(self, mock_ix_nextgen):
240 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
241 sut = IxiaTrafficGen('vnf1', vnfd)
244 def test__check_status(self, mock_ix_nextgen):
245 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
246 sut = IxiaTrafficGen('vnf1', vnfd)
249 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.time")
250 @mock.patch("yardstick.ssh.SSH")
251 def test_traffic_runner(self, mock_ixnextgen, mock_ssh, mock_time):
252 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
253 mock_traffic_profile.get_traffic_definition.return_value = "64"
254 mock_traffic_profile.params = self.TRAFFIC_PROFILE
255 # traffic_profile.ports is standardized on port_num
256 mock_traffic_profile.ports = [0, 1]
258 mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH)
259 mock_ssh_instance.execute.return_value = 0, "", ""
260 mock_ssh_instance.run.return_value = 0, "", ""
262 mock_ssh.from_node.return_value = mock_ssh_instance
264 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
265 vnfd["mgmt-interface"].update({
267 "ixchassis": "1.1.1.1",
268 "py_bin_path": "/root",
274 for ifname in range(1):
275 name = "xe{}".format(ifname)
283 "Valid_Frames_Rx": 1000,
289 samples.update({"CurrentDropPercentage": 0.0})
294 "Rx_Rate_Kbps": [20, 20],
295 "Tx_Rate_Kbps": [20, 20],
296 "Rx_Rate_Mbps": [10, 10],
297 "Tx_Rate_Mbps": [10, 10],
298 "CurrentDropPercentage": [0, 0],
299 "RxThroughput": [10, 10],
300 "TxThroughput": [10, 10],
301 "Frames_Tx": [1000, 1000],
302 "in_packets": [1000, 1000],
303 "Valid_Frames_Rx": [1000, 1000],
304 "out_packets": [1000, 1000],
308 mock_traffic_profile.execute_traffic.return_value = ['Completed', samples]
309 mock_traffic_profile.get_drop_percentage.return_value = ['Completed', samples]
311 sut = IxiaTrafficGen(name, vnfd)
312 sut.vnf_port_pairs = [[[0], [1]]]
313 sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
316 sut.ssh_helper = mock.Mock()
317 sut._traffic_process = mock.MagicMock()
318 sut.generate_port_pairs = mock.Mock()
320 sut._ixia_traffic_gen = mock.MagicMock()
321 sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res
323 sut.resource_helper.client = mock.MagicMock()
324 sut.resource_helper.client_started = mock.MagicMock()
325 sut.resource_helper.client_started.value = 1
326 sut.resource_helper.rfc_helper.iteration.value = 11
328 sut.scenario_helper.scenario_cfg = {
333 'allowed_drop_rate': '0.8 - 1',
337 'rules': 'acl_1rule.yaml',
341 'worker_config': '1C/1T',
346 'ixia_profile': '/path/to/profile',
347 'task_path': '/path/to/task'
350 @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True)
351 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open',
352 mock.mock_open(), create=True)
353 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception')
354 def _traffic_runner(*args):
355 result = sut._traffic_runner(mock_traffic_profile)
356 self.assertIsNone(result)