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
27 STLClient = mock.MagicMock()
28 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
32 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaTrafficGen
33 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaRfc2544Helper
34 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaResourceHelper
35 from yardstick.network_services.traffic_profile.base import TrafficProfile
37 TEST_FILE_YAML = 'nsb_test_case.yaml'
43 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen")
44 class TestIxiaResourceHelper(unittest.TestCase):
46 def test___init___with_custom_rfc_helper(self, mock_ix_nextgen):
47 class MyRfcHelper(IxiaRfc2544Helper):
50 ixia_resource_helper = IxiaResourceHelper(mock.Mock(), MyRfcHelper)
51 self.assertIsInstance(ixia_resource_helper.rfc_helper, MyRfcHelper)
53 def test_stop_collect_with_client(self, mock_ix_nextgen):
54 mock_client = mock.Mock()
56 ixia_resource_helper = IxiaResourceHelper(mock.Mock())
58 ixia_resource_helper.client = mock_client
59 ixia_resource_helper.stop_collect()
60 self.assertEqual(mock_client.ix_stop_traffic.call_count, 1)
63 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen")
64 class TestIXIATrafficGen(unittest.TestCase):
65 VNFD = {'vnfd:vnfd-catalog':
67 [{'short-name': 'VpeVnf',
70 [{'network': '152.16.100.20',
71 'netmask': '255.255.255.0',
72 'gateway': '152.16.100.20',
74 {'network': '152.16.40.20',
75 'netmask': '255.255.255.0',
76 'gateway': '152.16.40.20',
78 'description': 'VPE approximation using DPDK',
79 'name': 'vpevnf-baremetal',
81 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
83 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
85 {'network': '0064:ff9b:0:0:0:0:9810:2814',
87 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
89 'id': 'vpevnf-baremetal',
91 [{'virtual-interface':
92 {'dst_mac': '00:00:00:00:00:04',
93 'vpci': '0000:05:00.0',
94 'local_ip': '152.16.100.19',
95 'type': 'PCI-PASSTHROUGH',
96 'netmask': '255.255.255.0',
98 'bandwidth': '10 Gbps',
100 'dst_ip': '152.16.100.20',
101 'local_iface_name': 'xe0',
102 'local_mac': '00:00:00:00:00:02'},
103 'vnfd-connection-point-ref': 'xe0',
105 {'virtual-interface':
106 {'dst_mac': '00:00:00:00:00:03',
107 'vpci': '0000:05:00.1',
108 'local_ip': '152.16.40.19',
109 'type': 'PCI-PASSTHROUGH',
111 'netmask': '255.255.255.0',
112 'dpdk_port_num': '1',
113 'bandwidth': '10 Gbps',
114 'dst_ip': '152.16.40.20',
115 'local_iface_name': 'xe1',
116 'local_mac': '00:00:00:00:00:01'},
117 'vnfd-connection-point-ref': 'xe1',
119 'description': 'Vpe approximation using DPDK',
121 {'vdu-id': 'vpevnf-baremetal',
127 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
128 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
129 {'type': 'VPORT', 'name': 'xe1'}],
130 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
133 "schema": "isb:traffic_profile:0.1",
135 "description": "Fixed traffic profile to run UDP traffic",
137 "traffic_type": "FixedTraffic",
138 "frame_rate": 100, # pps
142 TC_YAML = {'scenarios': [{'tc_options':
143 {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
144 'runner': {'duration': 400,
145 'interval': 35, 'type': 'Duration'},
147 {'flow': 'ipv4_1flow_Packets_vpe.yaml',
148 'imix': 'imix_voice.yaml'},
149 'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
150 'traffic_profile': 'ipv4_throughput_vpe.yaml',
152 'nodes': {'tg__1': 'trafficgen_1.yardstick',
153 'vnf__1': 'vnf.yardstick'},
154 'topology': 'vpe_vnf_topology.yaml'}],
155 'context': {'nfvi_type': 'baremetal', 'type': 'Node',
157 'file': '/etc/yardstick/nodes/pod.yaml'},
158 'schema': 'yardstick:task:0.1'}
160 def test___init__(self, mock_ixnextgen):
161 with mock.patch("yardstick.ssh.SSH") as ssh:
162 ssh_mock = mock.Mock(autospec=ssh.SSH)
164 mock.Mock(return_value=(0, "", ""))
165 ssh.from_node.return_value = ssh_mock
166 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
167 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
169 def test_listen_traffic(self, mock_ixnextgen):
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 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
177 self.assertEqual(None, ixnet_traffic_gen.listen_traffic({}))
179 def test_instantiate(self, mock_ixnextgen):
180 with mock.patch("yardstick.ssh.SSH") as ssh:
181 ssh_mock = mock.Mock(autospec=ssh.SSH)
183 mock.Mock(return_value=(0, "", ""))
185 mock.Mock(return_value=(0, "", ""))
186 ssh.from_node.return_value = ssh_mock
187 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
188 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
189 scenario_cfg = {'tc': "nsb_test_case", "topology": "",
190 'ixia_profile': "ixload.cfg"}
191 scenario_cfg.update({'options': {'packetsize': 64,
193 'rfc2544': {'allowed_drop_rate': '0.8 - 1'},
194 'vnf__1': {'rules': 'acl_1rule.yaml',
195 'vnf_config': {'lb_config': 'SW',
199 'worker_threads': 1}}
201 ixnet_traffic_gen.topology = ""
202 ixnet_traffic_gen.get_ixobj = mock.MagicMock()
203 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
204 ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock()
207 ixnet_traffic_gen.instantiate(scenario_cfg, {}))
209 def test_collect_kpi(self, mock_ixnextgen):
210 with mock.patch("yardstick.ssh.SSH") as ssh:
211 ssh_mock = mock.Mock(autospec=ssh.SSH)
213 mock.Mock(return_value=(0, "", ""))
214 ssh.from_node.return_value = ssh_mock
215 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
216 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
217 ixnet_traffic_gen.data = {}
218 restult = ixnet_traffic_gen.collect_kpi()
219 self.assertEqual({}, restult)
221 def test_terminate(self, mock_ixnextgen):
222 with mock.patch("yardstick.ssh.SSH") as ssh:
223 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
224 ssh_mock = mock.Mock(autospec=ssh.SSH)
226 mock.Mock(return_value=(0, "", ""))
227 ssh.from_node.return_value = ssh_mock
228 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
229 ixnet_traffic_gen._terminated = mock.MagicMock()
230 ixnet_traffic_gen._terminated.value = 0
231 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
232 ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
233 ixnet_traffic_gen._traffic_process = mock.MagicMock()
234 ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
235 self.assertEqual(None, ixnet_traffic_gen.terminate())
237 def _get_file_abspath(self, filename):
238 curr_path = os.path.dirname(os.path.abspath(__file__))
239 file_path = os.path.join(curr_path, filename)
242 def test_scale(self, mock_ix_nextgen):
243 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
244 sut = IxiaTrafficGen('vnf1', vnfd)
247 def test__check_status(self, mock_ix_nextgen):
248 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
249 sut = IxiaTrafficGen('vnf1', vnfd)
252 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.time")
253 @mock.patch("yardstick.ssh.SSH")
254 def test_traffic_runner(self, mock_ixnextgen, mock_ssh, mock_time):
255 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
256 mock_traffic_profile.get_traffic_definition.return_value = "64"
257 mock_traffic_profile.params = self.TRAFFIC_PROFILE
259 mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH)
260 mock_ssh_instance.execute.return_value = 0, "", ""
261 mock_ssh_instance.run.return_value = 0, "", ""
263 mock_ssh.from_node.return_value = mock_ssh_instance
265 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
266 vnfd["mgmt-interface"].update({
268 "ixchassis": "1.1.1.1",
269 "py_bin_path": "/root",
275 for ifname in range(1):
276 name = "xe{}".format(ifname)
284 "Valid_Frames_Rx": 1000,
290 samples.update({"CurrentDropPercentage": 0.0})
295 "Rx_Rate_Kbps": [20, 20],
296 "Tx_Rate_Kbps": [20, 20],
297 "Rx_Rate_Mbps": [10, 10],
298 "Tx_Rate_Mbps": [10, 10],
299 "CurrentDropPercentage": [0, 0],
300 "RxThroughput": [10, 10],
301 "TxThroughput": [10, 10],
302 "Frames_Tx": [1000, 1000],
303 "in_packets": [1000, 1000],
304 "Valid_Frames_Rx": [1000, 1000],
305 "out_packets": [1000, 1000],
309 mock_traffic_profile.execute.return_value = ['Completed', samples]
310 mock_traffic_profile.get_drop_percentage.return_value = ['Completed', samples]
312 sut = IxiaTrafficGen(name, vnfd)
313 sut.tg_port_pairs = [[[0], [1]]]
314 sut.vnf_port_pairs = [[[0], [1]]]
315 sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
318 sut.ssh_helper = mock.Mock()
319 sut._traffic_process = mock.MagicMock()
320 sut.generate_port_pairs = mock.Mock()
322 sut._ixia_traffic_gen = mock.MagicMock()
323 sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res
325 sut.resource_helper.client = mock.MagicMock()
326 sut.resource_helper.client_started = mock.MagicMock()
327 sut.resource_helper.client_started.value = 1
328 sut.resource_helper.rfc_helper.iteration.value = 11
330 sut.scenario_helper.scenario_cfg = {
335 'allowed_drop_rate': '0.8 - 1',
339 'rules': 'acl_1rule.yaml',
343 'worker_config': '1C/1T',
348 'ixia_profile': '/path/to/profile',
349 'task_path': '/path/to/task'
352 with mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True) as mock_open:
353 mock_open.return_value = mock.MagicMock()
354 result = sut._traffic_runner(mock_traffic_profile)
355 self.assertIsNone(result)