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
23 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
25 from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
26 from tests.unit import STL_MOCKS
31 STLClient = mock.MagicMock()
32 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
36 from yardstick.network_services.vnf_generic.vnf.tg_trex import \
37 TrexTrafficGen, TrexResourceHelper
38 from yardstick.network_services.traffic_profile.base import TrafficProfile
41 class TestTrexTrafficGen(unittest.TestCase):
42 VNFD = {'vnfd:vnfd-catalog':
44 [{'short-name': 'VpeVnf',
47 [{'network': '152.16.100.20',
48 'netmask': '255.255.255.0',
49 'gateway': '152.16.100.20',
51 {'network': '152.16.40.20',
52 'netmask': '255.255.255.0',
53 'gateway': '152.16.40.20',
55 'description': 'VPE approximation using DPDK',
56 'name': 'vpevnf-baremetal',
58 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
60 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
62 {'network': '0064:ff9b:0:0:0:0:9810:2814',
64 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
66 'id': 'vpevnf-baremetal',
68 [{'virtual-interface':
69 {'dst_mac': '00:00:00:00:00:04',
70 'vpci': '0000:05:00.0',
71 'local_ip': '152.16.100.19',
72 'type': 'PCI-PASSTHROUGH',
73 'netmask': '255.255.255.0',
75 'bandwidth': '10 Gbps',
77 'dst_ip': '152.16.100.20',
78 'local_iface_name': 'xe0',
79 'local_mac': '00:00:00:00:00:02'},
80 'vnfd-connection-point-ref': 'xe0',
83 {'dst_mac': '00:00:00:00:00:03',
84 'vpci': '0000:05:00.1',
85 'local_ip': '152.16.40.19',
86 'type': 'PCI-PASSTHROUGH',
88 'netmask': '255.255.255.0',
90 'bandwidth': '10 Gbps',
91 'dst_ip': '152.16.40.20',
92 'local_iface_name': 'xe1',
93 'local_mac': '00:00:00:00:00:01'},
94 'vnfd-connection-point-ref': 'xe1',
96 'description': 'Vpe approximation using DPDK',
98 {'vdu-id': 'vpevnf-baremetal',
104 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
105 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
106 {'type': 'VPORT', 'name': 'xe1'}],
107 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
110 "schema": "isb:traffic_profile:0.1",
112 "description": "Fixed traffic profile to run UDP traffic",
114 "traffic_type": "FixedTraffic",
115 "frame_rate": 100, # pps
126 "allowed_drop_rate": "0.8 - 1",
129 "rules": "acl_1rule.yaml",
133 "worker_config": "1C/1T",
138 "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7",
139 "tc": "tc_ipv4_1Mflow_64B_packetsize",
141 "object": "NetworkServiceTestCase",
143 "output_filename": "/tmp/yardstick.out",
144 "runner_id": 74476, "duration": 400,
147 "traffic_profile": "ipv4_throughput_acl.yaml",
149 "flow": "ipv4_Packets_acl.yaml",
150 "imix": "imix_voice.yaml"
154 "tg__2": "trafficgen_2.yardstick",
155 "tg__1": "trafficgen_1.yardstick",
156 "vnf__1": "vnf.yardstick"
158 "topology": "udpreplay-tg-topology-baremetal.yaml"
164 "vnfd-id-ref": "vnf__1",
168 "local_iface_name": "ens786f0",
170 "netmask": "255.255.255.0",
171 "vpci": "0000:05:00.0",
172 "local_ip": "152.16.100.19",
174 "dst_ip": "152.16.100.20",
175 "local_mac": "00:00:00:00:00:02",
176 "dst_mac": "00:00:00:00:00:04",
180 "local_iface_name": "ens786f1",
182 "netmask": "255.255.255.0",
183 "vpci": "0000:05:00.1",
184 "local_ip": "152.16.40.19",
186 "dst_ip": "152.16.40.20",
187 "local_mac": "00:00:00:00:00:01",
188 "dst_mac": "00:00:00:00:00:03",
198 "gateway": "0064:ff9b:0:0:0:0:9810:6414",
199 "network": "0064:ff9b:0:0:0:0:9810:6414"
204 "gateway": "0064:ff9b:0:0:0:0:9810:2814",
205 "network": "0064:ff9b:0:0:0:0:9810:2814"
209 "VNF model": "udp_replay.yaml",
210 "name": "vnf.yardstick",
211 "member-vnf-index": "2",
214 "netmask": "255.255.255.0",
216 "gateway": "152.16.100.20",
217 "network": "152.16.100.20"
220 "netmask": "255.255.255.0",
222 "gateway": "152.16.40.20",
223 "network": "152.16.40.20"
228 "trafficgen_2.yardstick": {
229 "member-vnf-index": "3",
230 "role": "TrafficGen",
231 "name": "trafficgen_2.yardstick",
232 "vnfd-id-ref": "tg__2",
236 "local_iface_name": "ens513f0",
238 "netmask": "255.255.255.0",
239 "vpci": "0000:02:00.0",
240 "local_ip": "152.16.40.20",
242 "dst_ip": "152.16.40.19",
243 "local_mac": "00:00:00:00:00:03",
244 "dst_mac": "00:00:00:00:00:01",
248 "local_iface_name": "ens513f1",
249 "netmask": "255.255.255.0",
250 "network": "202.16.100.0",
251 "local_ip": "202.16.100.20",
253 "local_mac": "00:1e:67:d0:60:5d",
254 "vpci": "0000:02:00.1",
259 "VNF model": "l3fwd_vnf.yaml",
262 "trafficgen_1.yardstick": {
263 "member-vnf-index": "1",
264 "role": "TrafficGen",
265 "name": "trafficgen_1.yardstick",
266 "vnfd-id-ref": "tg__1",
270 "local_iface_name": "ens785f0",
272 "netmask": "255.255.255.0",
273 "vpci": "0000:05:00.0",
274 "local_ip": "152.16.100.20",
276 "dst_ip": "152.16.100.19",
277 "local_mac": "00:00:00:00:00:04",
278 "dst_mac": "00:00:00:00:00:02",
282 "local_ip": "152.16.100.21",
284 "vpci": "0000:05:00.1",
286 "local_iface_name": "ens785f1",
287 "netmask": "255.255.255.0",
288 "local_mac": "00:00:00:00:00:01"
292 "VNF model": "tg_rfc2544_tpl.yaml",
300 @mock.patch(SSH_HELPER)
301 def test___init__(self, ssh):
303 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
304 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
305 self.assertIsInstance(trex_traffic_gen.resource_helper, TrexResourceHelper)
307 @mock.patch(SSH_HELPER)
308 def test_collect_kpi(self, ssh):
310 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
311 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
312 trex_traffic_gen.resource_helper._queue.put({})
313 result = trex_traffic_gen.collect_kpi()
314 self.assertEqual({}, result)
316 @mock.patch(SSH_HELPER)
317 def test_listen_traffic(self, ssh):
319 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
320 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
321 self.assertIsNone(trex_traffic_gen.listen_traffic({}))
323 @mock.patch(SSH_HELPER)
324 def test_instantiate(self, ssh):
327 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
328 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
329 trex_traffic_gen._start_server = mock.Mock(return_value=0)
330 trex_traffic_gen._tg_process = mock.MagicMock()
331 trex_traffic_gen._tg_process.start = mock.Mock()
332 trex_traffic_gen._tg_process.exitcode = 0
333 trex_traffic_gen._tg_process._is_alive = mock.Mock(return_value=1)
334 trex_traffic_gen.ssh_helper = mock.MagicMock()
335 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
336 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
338 self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
340 @mock.patch(SSH_HELPER)
341 def test_instantiate_error(self, ssh):
342 mock_ssh(ssh, exec_result=(1, "", ""))
344 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
345 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
346 trex_traffic_gen._start_server = mock.Mock(return_value=0)
347 trex_traffic_gen._tg_process = mock.MagicMock()
348 trex_traffic_gen._tg_process.start = mock.Mock()
349 trex_traffic_gen._tg_process._is_alive = mock.Mock(return_value=0)
350 trex_traffic_gen.ssh_helper = mock.MagicMock()
351 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
352 trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
353 self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
355 @mock.patch(SSH_HELPER)
356 def test__start_server(self, ssh):
358 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
359 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
360 trex_traffic_gen.ssh_helper = mock.MagicMock()
361 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
362 self.assertIsNone(trex_traffic_gen._start_server())
364 @mock.patch(SSH_HELPER)
365 def test__traffic_runner(self, ssh):
368 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
369 mock_traffic_profile.get_traffic_definition.return_value = "64"
370 mock_traffic_profile.execute.return_value = "64"
371 mock_traffic_profile.params = self.TRAFFIC_PROFILE
373 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
374 self.sut = TrexTrafficGen(NAME, vnfd)
375 self.sut.ssh_helper = mock.Mock()
376 self.sut.ssh_helper.run = mock.Mock()
377 self.sut._vpci_ascending = ["0000:05:00.0", "0000:05:00.1"]
378 self.sut._connect_client = mock.Mock(autospec=STLClient)
379 self.sut._connect_client.get_stats = mock.Mock(return_value="0")
380 self.sut.resource_helper.RUN_DURATION = 0
381 self.sut.resource_helper.QUEUE_WAIT_TIME = 0
382 self.sut._traffic_runner(mock_traffic_profile)
384 @mock.patch(SSH_HELPER)
385 def test__generate_trex_cfg(self, ssh):
387 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
388 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
389 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
390 self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg())
392 @mock.patch(SSH_HELPER)
393 def test_run_traffic(self, ssh):
396 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
397 mock_traffic_profile.get_traffic_definition.return_value = "64"
398 mock_traffic_profile.params = self.TRAFFIC_PROFILE
400 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
401 self.sut = TrexTrafficGen(NAME, vnfd)
402 self.sut.ssh_helper = mock.Mock()
403 self.sut.ssh_helper.run = mock.Mock()
404 self.sut._traffic_runner = mock.Mock(return_value=0)
405 self.sut.resource_helper.client_started.value = 1
406 result = self.sut.run_traffic(mock_traffic_profile)
407 self.sut._traffic_process.terminate()
408 self.assertIsNotNone(result)
410 @mock.patch(SSH_HELPER)
411 def test_scale(self, ssh):
412 mock_ssh(ssh, exec_result=(1, "", ""))
413 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
414 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
415 trex_traffic_gen.scale('')
417 @mock.patch(SSH_HELPER)
418 def test_terminate(self, ssh):
420 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
421 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
422 trex_traffic_gen.ssh_helper = mock.MagicMock()
423 trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
424 self.assertIsNone(trex_traffic_gen.terminate())
426 @mock.patch(SSH_HELPER)
427 def test__connect_client(self, ssh):
429 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
430 trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
431 client = mock.Mock(autospec=STLClient)
432 client.connect = mock.Mock(return_value=0)
433 self.assertIsNotNone(trex_traffic_gen.resource_helper._connect(client))
435 if __name__ == '__main__':