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.
22 from tests.unit import STL_MOCKS
24 STLClient = mock.MagicMock()
25 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
29 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaTrafficGen
30 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaRfc2544Helper
31 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaResourceHelper
32 from yardstick.network_services.traffic_profile.base import TrafficProfile
34 TEST_FILE_YAML = 'nsb_test_case.yaml'
39 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen")
40 class TestIxiaResourceHelper(unittest.TestCase):
41 def test___init___with_custom_rfc_helper(self, *args):
42 class MyRfcHelper(IxiaRfc2544Helper):
45 ixia_resource_helper = IxiaResourceHelper(mock.Mock(), MyRfcHelper)
46 self.assertIsInstance(ixia_resource_helper.rfc_helper, MyRfcHelper)
48 def test_stop_collect_with_client(self, *args):
49 mock_client = mock.Mock()
51 ixia_resource_helper = IxiaResourceHelper(mock.Mock())
53 ixia_resource_helper.client = mock_client
54 ixia_resource_helper.stop_collect()
55 self.assertEqual(mock_client.ix_stop_traffic.call_count, 1)
58 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen")
59 class TestIXIATrafficGen(unittest.TestCase):
60 VNFD = {'vnfd:vnfd-catalog':
62 [{'short-name': 'VpeVnf',
65 [{'network': '152.16.100.20',
66 'netmask': '255.255.255.0',
67 'gateway': '152.16.100.20',
69 {'network': '152.16.40.20',
70 'netmask': '255.255.255.0',
71 'gateway': '152.16.40.20',
73 'description': 'VPE approximation using DPDK',
74 'name': 'vpevnf-baremetal',
76 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
78 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
80 {'network': '0064:ff9b:0:0:0:0:9810:2814',
82 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
84 'id': 'vpevnf-baremetal',
86 [{'virtual-interface':
87 {'dst_mac': '00:00:00:00:00:04',
88 'vpci': '0000:05:00.0',
89 'local_ip': '152.16.100.19',
90 'type': 'PCI-PASSTHROUGH',
91 'netmask': '255.255.255.0',
93 'bandwidth': '10 Gbps',
95 'dst_ip': '152.16.100.20',
96 'local_iface_name': 'xe0',
97 'local_mac': '00:00:00:00:00:02'},
98 'vnfd-connection-point-ref': 'xe0',
100 {'virtual-interface':
101 {'dst_mac': '00:00:00:00:00:03',
102 'vpci': '0000:05:00.1',
103 'local_ip': '152.16.40.19',
104 'type': 'PCI-PASSTHROUGH',
106 'netmask': '255.255.255.0',
108 'bandwidth': '10 Gbps',
109 'dst_ip': '152.16.40.20',
110 'local_iface_name': 'xe1',
111 'local_mac': '00:00:00:00:00:01'},
112 'vnfd-connection-point-ref': 'xe1',
114 'description': 'Vpe approximation using DPDK',
116 {'vdu-id': 'vpevnf-baremetal',
122 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
123 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
124 {'type': 'VPORT', 'name': 'xe1'}],
125 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
128 "schema": "isb:traffic_profile:0.1",
130 "description": "Fixed traffic profile to run UDP traffic",
132 "traffic_type": "FixedTraffic",
133 "frame_rate": 100, # pps
137 TC_YAML = {'scenarios': [{'tc_options':
138 {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
139 'runner': {'duration': 400,
140 'interval': 35, 'type': 'Duration'},
142 {'flow': 'ipv4_1flow_Packets_vpe.yaml',
143 'imix': 'imix_voice.yaml'},
144 'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
145 'traffic_profile': 'ipv4_throughput_vpe.yaml',
147 'nodes': {'tg__1': 'trafficgen_1.yardstick',
148 'vnf__1': 'vnf.yardstick'},
149 'topology': 'vpe_vnf_topology.yaml'}],
150 'context': {'nfvi_type': 'baremetal', 'type': 'Node',
152 'file': '/etc/yardstick/nodes/pod.yaml'},
153 'schema': 'yardstick:task:0.1'}
155 def test___init__(self, *args):
156 with mock.patch("yardstick.ssh.SSH") as ssh:
157 ssh_mock = mock.Mock(autospec=ssh.SSH)
159 mock.Mock(return_value=(0, "", ""))
160 ssh.from_node.return_value = ssh_mock
161 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
162 # NOTE(ralonsoh): check the object returned.
163 IxiaTrafficGen(NAME, vnfd)
165 def test_listen_traffic(self, *args):
166 with mock.patch("yardstick.ssh.SSH") as ssh:
167 ssh_mock = mock.Mock(autospec=ssh.SSH)
169 mock.Mock(return_value=(0, "", ""))
170 ssh.from_node.return_value = ssh_mock
171 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
172 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
173 self.assertEqual(None, ixnet_traffic_gen.listen_traffic({}))
175 def test_instantiate(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, "", ""))
181 mock.Mock(return_value=(0, "", ""))
182 ssh.from_node.return_value = ssh_mock
183 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
184 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
185 scenario_cfg = {'tc': "nsb_test_case", "topology": "",
186 'ixia_profile': "ixload.cfg"}
187 scenario_cfg.update({'options': {'packetsize': 64,
189 'rfc2544': {'allowed_drop_rate': '0.8 - 1'},
190 'vnf__1': {'rules': 'acl_1rule.yaml',
191 'vnf_config': {'lb_config': 'SW',
195 'worker_threads': 1}}
197 ixnet_traffic_gen.topology = ""
198 ixnet_traffic_gen.get_ixobj = mock.MagicMock()
199 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
200 ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock()
203 ixnet_traffic_gen.instantiate(scenario_cfg, {}))
205 def test_collect_kpi(self, *args):
206 with mock.patch("yardstick.ssh.SSH") as ssh:
207 ssh_mock = mock.Mock(autospec=ssh.SSH)
209 mock.Mock(return_value=(0, "", ""))
210 ssh.from_node.return_value = ssh_mock
211 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
212 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
213 ixnet_traffic_gen.data = {}
214 restult = ixnet_traffic_gen.collect_kpi()
215 self.assertEqual({}, restult)
217 def test_terminate(self, *args):
218 with mock.patch("yardstick.ssh.SSH") as ssh:
219 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
220 ssh_mock = mock.Mock(autospec=ssh.SSH)
222 mock.Mock(return_value=(0, "", ""))
223 ssh.from_node.return_value = ssh_mock
224 ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
225 ixnet_traffic_gen._terminated = mock.MagicMock()
226 ixnet_traffic_gen._terminated.value = 0
227 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
228 ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
229 ixnet_traffic_gen._traffic_process = mock.MagicMock()
230 ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
231 self.assertEqual(None, ixnet_traffic_gen.terminate())
233 def _get_file_abspath(self, filename):
234 curr_path = os.path.dirname(os.path.abspath(__file__))
235 file_path = os.path.join(curr_path, filename)
238 def test__check_status(self, *args):
239 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
240 sut = IxiaTrafficGen('vnf1', vnfd)
243 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.time")
244 @mock.patch("yardstick.ssh.SSH")
245 def test_traffic_runner(self, mock_ssh, *args):
246 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
247 mock_traffic_profile.get_traffic_definition.return_value = "64"
248 mock_traffic_profile.params = self.TRAFFIC_PROFILE
249 # traffic_profile.ports is standardized on port_num
250 mock_traffic_profile.ports = [0, 1]
252 mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH)
253 mock_ssh_instance.execute.return_value = 0, "", ""
254 mock_ssh_instance.run.return_value = 0, "", ""
256 mock_ssh.from_node.return_value = mock_ssh_instance
258 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
259 vnfd["mgmt-interface"].update({
261 "ixchassis": "1.1.1.1",
262 "py_bin_path": "/root",
268 for ifname in range(1):
269 name = "xe{}".format(ifname)
277 "Valid_Frames_Rx": 1000,
283 samples.update({"CurrentDropPercentage": 0.0})
288 "Rx_Rate_Kbps": [20, 20],
289 "Tx_Rate_Kbps": [20, 20],
290 "Rx_Rate_Mbps": [10, 10],
291 "Tx_Rate_Mbps": [10, 10],
292 "CurrentDropPercentage": [0, 0],
293 "RxThroughput": [10, 10],
294 "TxThroughput": [10, 10],
295 "Frames_Tx": [1000, 1000],
296 "in_packets": [1000, 1000],
297 "Valid_Frames_Rx": [1000, 1000],
298 "out_packets": [1000, 1000],
302 mock_traffic_profile.execute_traffic.return_value = ['Completed', samples]
303 mock_traffic_profile.get_drop_percentage.return_value = ['Completed', samples]
305 sut = IxiaTrafficGen(name, vnfd)
306 sut.vnf_port_pairs = [[[0], [1]]]
307 sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
310 sut.ssh_helper = mock.Mock()
311 sut._traffic_process = mock.MagicMock()
312 sut.generate_port_pairs = mock.Mock()
314 sut._ixia_traffic_gen = mock.MagicMock()
315 sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res
317 sut.resource_helper.client = mock.MagicMock()
318 sut.resource_helper.client_started = mock.MagicMock()
319 sut.resource_helper.client_started.value = 1
320 sut.resource_helper.rfc_helper.iteration.value = 11
322 sut.scenario_helper.scenario_cfg = {
327 'allowed_drop_rate': '0.8 - 1',
331 'rules': 'acl_1rule.yaml',
335 'worker_config': '1C/1T',
340 'ixia_profile': '/path/to/profile',
341 'task_path': '/path/to/task'
344 @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True)
345 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open',
346 mock.mock_open(), create=True)
347 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception')
348 def _traffic_runner(*args):
349 result = sut._traffic_runner(mock_traffic_profile)
350 self.assertIsNone(result)