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 import ssh
22 from yardstick.benchmark.contexts import base as ctx_base
23 from yardstick.common import utils
24 from yardstick.network_services.vnf_generic.vnf import tg_ixload
25 from yardstick.network_services.traffic_profile.base import TrafficProfile
31 class TestIxLoadTrafficGen(unittest.TestCase):
32 VNFD = {'vnfd:vnfd-catalog':
34 [{'short-name': 'VpeVnf',
37 [{'network': '152.16.100.20',
38 'netmask': '255.255.255.0',
39 'gateway': '152.16.100.20',
41 {'network': '152.16.40.20',
42 'netmask': '255.255.255.0',
43 'gateway': '152.16.40.20',
45 'description': 'VPE approximation using DPDK',
46 'name': 'vpevnf-baremetal',
48 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
50 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
52 {'network': '0064:ff9b:0:0:0:0:9810:2814',
54 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
56 'id': 'vpevnf-baremetal',
58 [{'virtual-interface':
59 {'dst_mac': '00:00:00:00:00:04',
60 'vpci': '0000:05:00.0',
61 'local_ip': '152.16.100.19',
62 'type': 'PCI-PASSTHROUGH',
63 'netmask': '255.255.255.0',
65 'bandwidth': '10 Gbps',
67 'dst_ip': '152.16.100.20',
68 'local_iface_name': 'xe0',
69 'local_mac': '00:00:00:00:00:02'},
70 'vnfd-connection-point-ref': 'xe0',
73 {'dst_mac': '00:00:00:00:00:03',
74 'vpci': '0000:05:00.1',
75 'local_ip': '152.16.40.19',
76 'type': 'PCI-PASSTHROUGH',
78 'netmask': '255.255.255.0',
80 'bandwidth': '10 Gbps',
81 'dst_ip': '152.16.40.20',
82 'local_iface_name': 'xe1',
83 'local_mac': '00:00:00:00:00:01'},
84 'vnfd-connection-point-ref': 'xe1',
86 'description': 'Vpe approximation using DPDK',
88 {'vdu-id': 'vpevnf-baremetal',
94 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
95 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
96 {'type': 'VPORT', 'name': 'xe1'}],
97 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
100 "schema": "isb:traffic_profile:0.1",
102 "description": "Fixed traffic profile to run UDP traffic",
104 "traffic_type": "FixedTraffic",
105 "frame_rate": 100, # pps
110 self._mock_call = mock.patch.object(subprocess, "call")
111 self.mock_call = self._mock_call.start()
112 self._mock_open = mock.patch.object(tg_ixload, 'open')
113 self.mock_open = self._mock_open.start()
114 self.addCleanup(self._stop_mock)
116 def _stop_mock(self):
117 self._mock_call.stop()
118 self._mock_open.stop()
120 @mock.patch.object(ssh, 'SSH')
121 def test___init__(self, *args):
122 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
123 ixload_traffic_gen = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
124 self.assertIsNone(ixload_traffic_gen.resource_helper.data)
126 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server',
127 return_value='mock_node')
128 @mock.patch.object(ssh, 'SSH')
129 def test_collect_kpi(self, *args):
130 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
131 ixload_traffic_gen = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
132 ixload_traffic_gen.scenario_helper.scenario_cfg = {
133 'nodes': {ixload_traffic_gen.name: "mock"}
135 ixload_traffic_gen.data = {}
136 result = ixload_traffic_gen.collect_kpi()
139 'physical_node': 'mock_node',
141 self.assertEqual(expected, result)
143 @mock.patch.object(ssh, 'SSH')
144 def test_listen_traffic(self, *args):
145 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
146 ixload_traffic_gen = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
147 self.assertIsNone(ixload_traffic_gen.listen_traffic({}))
149 @mock.patch.object(utils, 'find_relative_file')
150 @mock.patch.object(utils, 'makedirs')
151 @mock.patch.object(ctx_base.Context, 'get_context_from_server')
152 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
153 @mock.patch.object(ssh, 'SSH')
154 def test_instantiate(self, mock_shutil, *args):
155 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
156 ixload_traffic_gen = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
157 scenario_cfg = {'tc': "nsb_test_case",
158 'ixia_profile': "ixload.cfg",
159 'task_path': "/path/to/task"}
160 ixload_traffic_gen.RESULTS_MOUNT = "/tmp/result"
161 mock_shutil.copy = mock.Mock()
162 scenario_cfg.update({'options': {'packetsize': 64, 'traffic_type': 4,
163 'rfc2544': {'allowed_drop_rate': '0.8 - 1'},
164 'vnf__1': {'rules': 'acl_1rule.yaml',
165 'vnf_config': {'lb_config': 'SW',
169 'worker_threads': 1}}
171 scenario_cfg.update({
172 'nodes': {ixload_traffic_gen.name: "mock"}
174 with mock.patch.object(six.moves.builtins, 'open',
175 create=True) as mock_open:
176 mock_open.return_value = mock.MagicMock()
177 ixload_traffic_gen.instantiate(scenario_cfg, {})
179 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open")
180 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min")
181 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max")
182 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len")
183 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
184 @mock.patch.object(ssh, 'SSH')
185 def test_run_traffic(self, *args):
186 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
187 mock_traffic_profile.get_traffic_definition.return_value = "64"
188 mock_traffic_profile.params = self.TRAFFIC_PROFILE
189 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
190 vnfd["mgmt-interface"].update({"tg-config": {}})
191 vnfd["mgmt-interface"]["tg-config"].update({"ixchassis":
193 vnfd["mgmt-interface"]["tg-config"].update({"py_bin_path":
195 sut = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
196 sut.connection = mock.Mock()
197 sut.connection.run = mock.Mock()
198 sut._traffic_runner = mock.Mock(return_value=0)
199 result = sut.run_traffic(mock_traffic_profile)
200 self.assertIsNone(result)
202 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open")
203 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min")
204 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max")
205 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len")
206 @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
207 @mock.patch.object(ssh, 'SSH')
208 def test_run_traffic_csv(self, *args):
209 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
210 mock_traffic_profile.get_traffic_definition.return_value = "64"
211 mock_traffic_profile.params = self.TRAFFIC_PROFILE
212 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
213 vnfd["mgmt-interface"].update({"tg-config": {}})
214 vnfd["mgmt-interface"]["tg-config"].update({"ixchassis":
216 vnfd["mgmt-interface"]["tg-config"].update({"py_bin_path":
218 sut = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
219 sut.connection = mock.Mock()
220 sut.connection.run = mock.Mock()
221 sut._traffic_runner = mock.Mock(return_value=0)
222 sut.rel_bin_path = mock.Mock(return_value="/tmp/*.csv")
223 result = sut.run_traffic(mock_traffic_profile)
224 self.assertIsNone(result)
226 @mock.patch.object(ssh, 'SSH')
227 def test_terminate(self, *args):
228 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
229 ixload_traffic_gen = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
230 self.assertIsNone(ixload_traffic_gen.terminate())
232 @mock.patch.object(ssh, 'SSH')
233 def test_parse_csv_read(self, mock_ssh):
234 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
236 'HTTP Total Throughput (Kbps)': 1,
237 'HTTP Simulated Users': 2,
238 'HTTP Concurrent Connections': '3',
239 'HTTP Connection Rate': 4.3,
240 'HTTP Transaction Rate': True,
242 http_reader = [kpi_data]
244 mock_ssh_type = mock.Mock(autospec=mock_ssh.SSH)
245 mock_ssh_type.execute.return_value = 0, "", ""
246 mock_ssh.from_node.return_value = mock_ssh_type
248 ixload_traffic_gen = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
249 result = ixload_traffic_gen.resource_helper.result
251 ixload_traffic_gen.resource_helper.parse_csv_read(http_reader)
252 for key_left, key_right in (
253 tg_ixload.IxLoadResourceHelper.KPI_LIST.items()):
254 self.assertEqual(result[key_left][-1], int(kpi_data[key_right]))
256 @mock.patch.object(ssh, 'SSH')
257 def test_parse_csv_read_value_error(self, mock_ssh, *args):
258 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
260 'HTTP Total Throughput (Kbps)': 1,
261 'HTTP Simulated Users': 2,
262 'HTTP Concurrent Connections': "not a number",
263 'HTTP Connection Rate': 4,
264 'HTTP Transaction Rate': 5,
267 mock_ssh_type = mock.Mock(autospec=mock_ssh.SSH)
268 mock_ssh_type.execute.return_value = 0, "", ""
269 mock_ssh.from_node.return_value = mock_ssh_type
271 ixload_traffic_gen = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
272 init_value = ixload_traffic_gen.resource_helper.result
274 ixload_traffic_gen.resource_helper.parse_csv_read(http_reader)
275 self.assertDictEqual(ixload_traffic_gen.resource_helper.result, init_value)
277 @mock.patch.object(ssh, 'SSH')
278 def test_parse_csv_read_error(self, mock_ssh, *args):
279 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
281 'HTTP Total Throughput (Kbps)': 1,
282 'HTTP Simulated Users': 2,
283 'HTTP Concurrent Connections': 3,
284 'HTTP Transaction Rate': 5,
287 mock_ssh_type = mock.Mock(autospec=mock_ssh.SSH)
288 mock_ssh_type.execute.return_value = 0, "", ""
289 mock_ssh.from_node.return_value = mock_ssh_type
291 ixload_traffic_gen = tg_ixload.IxLoadTrafficGen(NAME, vnfd)
293 with self.assertRaises(KeyError):
294 ixload_traffic_gen.resource_helper.parse_csv_read(http_reader)