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
22 import multiprocessing
23 from multiprocessing import Queue
25 from stl.trex_stl_lib.trex_stl_client import STLClient
26 from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex import \
28 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
29 from yardstick.network_services.traffic_profile.base import TrafficProfile
32 class TestTrexTrafficGenRFC(unittest.TestCase):
33 VNFD = {'vnfd:vnfd-catalog':
35 [{'short-name': 'VpeVnf',
38 [{'network': '152.16.100.20',
39 'netmask': '255.255.255.0',
40 'gateway': '152.16.100.20',
42 {'network': '152.16.40.20',
43 'netmask': '255.255.255.0',
44 'gateway': '152.16.40.20',
46 'description': 'VPE approximation using DPDK',
47 'name': 'vpevnf-baremetal',
49 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
51 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
53 {'network': '0064:ff9b:0:0:0:0:9810:2814',
55 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
57 'id': 'vpevnf-baremetal',
59 [{'virtual-interface':
60 {'dst_mac': '00:00:00:00:00:04',
61 'vpci': '0000:05:00.0',
62 'local_ip': '152.16.100.19',
63 'type': 'PCI-PASSTHROUGH',
64 'netmask': '255.255.255.0',
66 'bandwidth': '10 Gbps',
68 'dst_ip': '152.16.100.20',
69 'local_iface_name': 'xe0',
70 'local_mac': '00:00:00:00:00:01'},
71 'vnfd-connection-point-ref': 'xe0',
74 {'dst_mac': '00:00:00:00:00:03',
75 'vpci': '0000:05:00.1',
76 'local_ip': '152.16.40.19',
77 'type': 'PCI-PASSTHROUGH',
79 'netmask': '255.255.255.0',
81 'bandwidth': '10 Gbps',
82 'dst_ip': '152.16.40.20',
83 'local_iface_name': 'xe1',
84 'local_mac': '00:00:00:00:00:02'},
85 'vnfd-connection-point-ref': 'xe1',
87 'description': 'Vpe approximation using DPDK',
89 {'vdu-id': 'vpevnf-baremetal',
95 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
96 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
97 {'type': 'VPORT', 'name': 'xe1'}],
98 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
101 "schema": "isb:traffic_profile:0.1",
103 "description": "Fixed traffic profile to run UDP traffic",
105 "traffic_type": "FixedTraffic",
106 "frame_rate": 100, # pps
110 TC_YAML = {'scenarios': [{'tc_options':
111 {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
112 'runner': {'duration': 400,
113 'interval': 35, 'type': 'Duration'},
115 {'flow': 'ipv4_1flow_Packets_vpe.yaml',
116 'imix': 'imix_voice.yaml'},
117 'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
118 'traffic_profile': 'ipv4_throughput_vpe.yaml',
120 'nodes': {'tg__1': 'trafficgen_1.yardstick',
121 'vnf__1': 'vnf.yardstick'},
122 'topology': 'vpe_vnf_topology.yaml'}],
123 'context': {'nfvi_type': 'baremetal', 'type': 'Node',
125 'file': '/etc/yardstick/nodes/pod.yaml'},
126 'schema': 'yardstick:task:0.1'}
128 def test___init__(self):
129 with mock.patch("yardstick.ssh.SSH") as ssh:
130 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
131 ssh_mock = mock.Mock(autospec=ssh.SSH)
133 mock.Mock(return_value=(0, "", ""))
134 ssh.return_value = ssh_mock
135 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
136 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
137 self.assertIsNotNone(trex_traffic_gen._terminated)
139 def test_collect_kpi(self):
140 with mock.patch("yardstick.ssh.SSH") as ssh:
141 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
142 ssh_mock = mock.Mock(autospec=ssh.SSH)
144 mock.Mock(return_value=(0, "", ""))
145 ssh.return_value = ssh_mock
146 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
147 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
148 restult = trex_traffic_gen.collect_kpi()
149 self.assertEqual({}, restult)
151 def test_listen_traffic(self):
152 with mock.patch("yardstick.ssh.SSH") as ssh:
153 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
154 ssh_mock = mock.Mock(autospec=ssh.SSH)
156 mock.Mock(return_value=(0, "", ""))
157 ssh.return_value = ssh_mock
158 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
159 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
160 self.assertEqual(None, trex_traffic_gen.listen_traffic({}))
162 def test_instantiate(self):
163 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
164 mock_traffic_profile.get_traffic_definition.return_value = "64"
165 mock_traffic_profile.params = self.TRAFFIC_PROFILE
166 with mock.patch("yardstick.ssh.SSH") as ssh:
167 ssh_mock = mock.Mock(autospec=ssh.SSH)
169 mock.Mock(return_value=(0, "", ""))
171 mock.Mock(return_value=(0, "", ""))
172 ssh.return_value = ssh_mock
173 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
174 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
175 trex_traffic_gen._start_server = mock.Mock(return_value=0)
176 scenario_cfg = {"tc": "tc_baremetal_rfc2544_ipv4_1flow_64B"}
177 self.assertEqual(0, trex_traffic_gen.instantiate(scenario_cfg, {}))
179 def test_instantiate_error(self):
180 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
181 mock_traffic_profile.get_traffic_definition.return_value = "64"
182 mock_traffic_profile.params = self.TRAFFIC_PROFILE
183 with mock.patch("yardstick.ssh.SSH") as ssh:
184 ssh_mock = mock.Mock(autospec=ssh.SSH)
186 mock.Mock(return_value=(1, "", ""))
188 mock.Mock(return_value=(0, "", ""))
189 ssh.return_value = ssh_mock
190 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
191 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
192 scenario_cfg = {"tc": "tc_baremetal_rfc2544_ipv4_1flow_64B"}
193 self.assertRaises(RuntimeError,
194 trex_traffic_gen.instantiate, scenario_cfg, {})
196 def test__get_rfc_tolerance(self):
197 with mock.patch("yardstick.ssh.SSH") as ssh:
198 ssh_mock = mock.Mock(autospec=ssh.SSH)
200 mock.Mock(return_value=(0, "", ""))
202 mock.Mock(return_value=(0, "", ""))
203 ssh.return_value = ssh_mock
204 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
205 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
206 self.assertEqual([0.8, 1.0],
207 trex_traffic_gen._get_rfc_tolerance(self.TC_YAML))
208 self.TC_YAML["scenarios"][0]["tc_options"]['rfc2544']['allowed_drop_rate'] = '0.8'
209 self.assertEqual([0.8, 0.8],
210 trex_traffic_gen._get_rfc_tolerance(self.TC_YAML))
212 def test__start_server(self):
213 with mock.patch("yardstick.ssh.SSH") as ssh:
214 ssh_mock = mock.Mock(autospec=ssh.SSH)
216 mock.Mock(return_value=(0, "", ""))
218 mock.Mock(return_value=(0, "", ""))
219 ssh.return_value = ssh_mock
220 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
221 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
222 self.assertEqual(None, trex_traffic_gen._start_server())
224 def _get_file_abspath(self, filename):
225 curr_path = os.path.dirname(os.path.abspath(__file__))
226 file_path = os.path.join(curr_path, filename)
229 def test__traffic_runner(self):
230 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
231 mock_traffic_profile.get_traffic_definition.return_value = "64"
232 mock_traffic_profile.execute.return_value = "64"
233 mock_traffic_profile.get_drop_percentage.return_value = "64"
234 mock_traffic_profile.params = self.TRAFFIC_PROFILE
235 with mock.patch("yardstick.ssh.SSH") as ssh:
236 ssh_mock = mock.Mock(autospec=ssh.SSH)
238 mock.Mock(return_value=(0, "", ""))
240 mock.Mock(return_value=(0, "", ""))
241 ssh.return_value = ssh_mock
242 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
243 self.sut = TrexTrafficGenRFC(vnfd)
244 self.sut.connection = mock.Mock()
245 self.sut.connection.run = mock.Mock()
247 client_started = multiprocessing.Value('i', 1)
248 self.sut._vpci_ascending = ["0000:05:00.0", "0000:05:00.1"]
249 self.sut._connect_client = mock.Mock(autospec=STLClient)
250 self.sut._connect_client.get_stats = mock.Mock(return_value="0")
251 self.sut.tc_file_name = \
252 self._get_file_abspath(
253 "tc_baremetal_rfc2544_ipv4_1flow_64B.yaml")
254 tg_rfc2544_trex.DURATION = 1
255 tg_rfc2544_trex.WAIT_TIME = 1
256 self.sut._traffic_runner(mock_traffic_profile, q, client_started,
257 self.sut._terminated)
259 def test__split_mac_address_into_list(self):
260 with mock.patch("yardstick.ssh.SSH") as ssh:
261 ssh_mock = mock.Mock(autospec=ssh.SSH)
263 mock.Mock(return_value=(0, "", ""))
264 ssh.return_value = ssh_mock
265 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
266 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
267 result = ['0x00', '0x00', '0x00', '0x00', '0x00', '0x01']
268 self.assertEqual(result,
269 trex_traffic_gen._split_mac_address_into_list(
270 "00:00:00:00:00:01"))
272 def test__generate_trex_cfg(self):
273 with mock.patch("yardstick.ssh.SSH") as ssh:
274 ssh_mock = mock.Mock(autospec=ssh.SSH)
276 mock.Mock(return_value=(0, "", ""))
278 mock.Mock(return_value=(0, "", ""))
279 ssh.return_value = ssh_mock
280 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
281 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
282 tg_rfc2544_trex.WAIT_TIME = 1
283 self.assertEqual(None, trex_traffic_gen._generate_trex_cfg(vnfd))
285 def test_run_traffic(self):
286 mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
287 mock_traffic_profile.get_traffic_definition.return_value = "64"
288 mock_traffic_profile.params = self.TRAFFIC_PROFILE
289 with mock.patch("yardstick.ssh.SSH") as ssh:
290 ssh_mock = mock.Mock(autospec=ssh.SSH)
292 mock.Mock(return_value=(0, "", ""))
294 mock.Mock(return_value=(0, "", ""))
295 ssh.return_value = ssh_mock
296 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
297 self.sut = TrexTrafficGenRFC(vnfd)
298 self.sut.connection = mock.Mock()
299 self.sut.connection.run = mock.Mock()
300 self.sut._traffic_runner = mock.Mock(return_value=0)
301 client_started = multiprocessing.Value('i', 1)
302 result = self.sut.run_traffic(mock_traffic_profile, client_started)
303 self.sut._traffic_process.terminate()
304 self.assertEqual(True, result)
306 def test_scale(self):
307 with mock.patch("yardstick.ssh.SSH") as ssh:
308 ssh_mock = mock.Mock(autospec=ssh.SSH)
310 mock.Mock(return_value=(0, "", ""))
312 mock.Mock(return_value=(0, "", ""))
313 ssh.return_value = ssh_mock
314 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
316 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
317 self.assertRaises(NotImplementedError,
318 trex_traffic_gen.scale, flavor)
320 def test_terminate(self):
321 with mock.patch("yardstick.ssh.SSH") as ssh:
322 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
323 ssh_mock = mock.Mock(autospec=ssh.SSH)
325 mock.Mock(return_value=(0, "", ""))
326 ssh.return_value = ssh_mock
327 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
328 self.assertEqual(None, trex_traffic_gen.terminate())
330 def test__connect_client(self):
331 with mock.patch("yardstick.ssh.SSH") as ssh:
332 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
333 ssh_mock = mock.Mock(autospec=ssh.SSH)
335 mock.Mock(return_value=(0, "", ""))
336 ssh.return_value = ssh_mock
337 trex_traffic_gen = TrexTrafficGenRFC(vnfd)
338 client = mock.Mock(autospec=STLClient)
339 client.connect = mock.Mock(return_value=0)
340 self.assertIsNotNone(trex_traffic_gen._connect_client(client))