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
19 from __future__ import division
24 'stl': mock.MagicMock(),
25 'stl.trex_stl_lib': mock.MagicMock(),
26 'stl.trex_stl_lib.base64': mock.MagicMock(),
27 'stl.trex_stl_lib.binascii': mock.MagicMock(),
28 'stl.trex_stl_lib.collections': mock.MagicMock(),
29 'stl.trex_stl_lib.copy': mock.MagicMock(),
30 'stl.trex_stl_lib.datetime': mock.MagicMock(),
31 'stl.trex_stl_lib.functools': mock.MagicMock(),
32 'stl.trex_stl_lib.imp': mock.MagicMock(),
33 'stl.trex_stl_lib.inspect': mock.MagicMock(),
34 'stl.trex_stl_lib.json': mock.MagicMock(),
35 'stl.trex_stl_lib.linecache': mock.MagicMock(),
36 'stl.trex_stl_lib.math': mock.MagicMock(),
37 'stl.trex_stl_lib.os': mock.MagicMock(),
38 'stl.trex_stl_lib.platform': mock.MagicMock(),
39 'stl.trex_stl_lib.pprint': mock.MagicMock(),
40 'stl.trex_stl_lib.random': mock.MagicMock(),
41 'stl.trex_stl_lib.re': mock.MagicMock(),
42 'stl.trex_stl_lib.scapy': mock.MagicMock(),
43 'stl.trex_stl_lib.socket': mock.MagicMock(),
44 'stl.trex_stl_lib.string': mock.MagicMock(),
45 'stl.trex_stl_lib.struct': mock.MagicMock(),
46 'stl.trex_stl_lib.sys': mock.MagicMock(),
47 'stl.trex_stl_lib.threading': mock.MagicMock(),
48 'stl.trex_stl_lib.time': mock.MagicMock(),
49 'stl.trex_stl_lib.traceback': mock.MagicMock(),
50 'stl.trex_stl_lib.trex_stl_async_client': mock.MagicMock(),
51 'stl.trex_stl_lib.trex_stl_client': mock.MagicMock(),
52 'stl.trex_stl_lib.trex_stl_exceptions': mock.MagicMock(),
53 'stl.trex_stl_lib.trex_stl_ext': mock.MagicMock(),
54 'stl.trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(),
55 'stl.trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(),
56 'stl.trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(),
57 'stl.trex_stl_lib.trex_stl_port': mock.MagicMock(),
58 'stl.trex_stl_lib.trex_stl_stats': mock.MagicMock(),
59 'stl.trex_stl_lib.trex_stl_streams': mock.MagicMock(),
60 'stl.trex_stl_lib.trex_stl_types': mock.MagicMock(),
61 'stl.trex_stl_lib.types': mock.MagicMock(),
62 'stl.trex_stl_lib.utils': mock.MagicMock(),
63 'stl.trex_stl_lib.utils.argparse': mock.MagicMock(),
64 'stl.trex_stl_lib.utils.collections': mock.MagicMock(),
65 'stl.trex_stl_lib.utils.common': mock.MagicMock(),
66 'stl.trex_stl_lib.utils.json': mock.MagicMock(),
67 'stl.trex_stl_lib.utils.os': mock.MagicMock(),
68 'stl.trex_stl_lib.utils.parsing_opts': mock.MagicMock(),
69 'stl.trex_stl_lib.utils.pwd': mock.MagicMock(),
70 'stl.trex_stl_lib.utils.random': mock.MagicMock(),
71 'stl.trex_stl_lib.utils.re': mock.MagicMock(),
72 'stl.trex_stl_lib.utils.string': mock.MagicMock(),
73 'stl.trex_stl_lib.utils.sys': mock.MagicMock(),
74 'stl.trex_stl_lib.utils.text_opts': mock.MagicMock(),
75 'stl.trex_stl_lib.utils.text_tables': mock.MagicMock(),
76 'stl.trex_stl_lib.utils.texttable': mock.MagicMock(),
77 'stl.trex_stl_lib.warnings': mock.MagicMock(),
78 'stl.trex_stl_lib.yaml': mock.MagicMock(),
79 'stl.trex_stl_lib.zlib': mock.MagicMock(),
80 'stl.trex_stl_lib.zmq': mock.MagicMock(),
83 STLClient = mock.MagicMock()
84 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
88 from yardstick.network_services.traffic_profile.traffic_profile \
90 from yardstick.network_services.traffic_profile.rfc2544 import \
94 class TestRFC2544Profile(unittest.TestCase):
96 "schema": "isb:traffic_profile:0.1",
98 "description": "Fixed traffic profile to run UDP traffic",
100 "traffic_type": "FixedTraffic",
101 "frame_rate": 100, # pps
105 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
107 'traffic_profile': {'traffic_type': 'RFC2544Profile',
110 {'outer_l2': {'framesize':
111 {'64B': '100', '1518B': '0',
112 '128B': '0', '1400B': '0',
113 '256B': '0', '373b': '0',
115 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
117 'srcip4': '90.90.1.1-90.105.255.255',
118 'dscp': 0, 'ttl': 32},
119 'outer_l4': {'srcport': '2001',
120 'dsrport': '1234'}}},
121 'private_1': {'ipv4':
122 {'outer_l2': {'framesize':
123 {'64B': '100', '1518B': '0',
124 '128B': '0', '1400B': '0',
125 '256B': '0', '373b': '0',
127 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
129 'srcip4': '1.1.1.1-1.15.255.255',
130 'dscp': 0, 'ttl': 32},
131 'outer_l4': {'dstport': '2001',
132 'srcport': '1234'}}},
133 'schema': 'isb:traffic_profile:0.1'}
135 def test___init__(self):
136 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
137 assert r_f_c2544_profile.rate
139 def test_execute(self):
140 traffic_generator = mock.Mock(autospec=TrexProfile)
141 traffic_generator.my_ports = [0, 1]
142 traffic_generator.priv_ports = [-1]
143 traffic_generator.pub_ports = [1]
144 traffic_generator.client = \
145 mock.Mock(return_value=True)
146 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
147 r_f_c2544_profile.params = self.PROFILE
148 r_f_c2544_profile.first_run = True
149 self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator))
151 def test_get_drop_percentage(self):
152 traffic_generator = mock.Mock(autospec=TrexProfile)
153 traffic_generator.my_ports = [0, 1]
154 traffic_generator.priv_ports = [0]
155 traffic_generator.pub_ports = [1]
156 traffic_generator.client = mock.Mock(return_value=True)
158 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
159 r_f_c2544_profile.params = self.PROFILE
160 r_f_c2544_profile.register_generator(traffic_generator)
161 self.assertIsNone(r_f_c2544_profile.execute(traffic_generator))
164 for ifname in range(1):
165 name = "xe{}".format(ifname)
167 "rx_throughput_fps": 20,
168 "tx_throughput_fps": 20,
169 "rx_throughput_mbps": 10,
170 "tx_throughput_mbps": 10,
176 'DropPercentage': 0.0,
177 'RxThroughput': 100 / 3.0,
178 'TxThroughput': 100 / 3.0,
179 'CurrentDropPercentage': 0.0,
180 'Throughput': 66.66666666666667,
182 'tx_throughput_fps': 20,
185 'rx_throughput_mbps': 10,
186 'tx_throughput_mbps': 10,
187 'rx_throughput_fps': 20,
190 traffic_generator.generate_samples = mock.MagicMock(return_value=samples)
191 traffic_generator.RUN_DURATION = 30
192 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
193 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
194 result = r_f_c2544_profile.get_drop_percentage(traffic_generator)
195 self.assertDictEqual(result, expected)
197 def test_get_drop_percentage_update(self):
198 traffic_generator = mock.Mock(autospec=RFC2544Profile)
199 traffic_generator.my_ports = [0, 1]
200 traffic_generator.priv_ports = [0]
201 traffic_generator.pub_ports = [1]
202 traffic_generator.client = mock.Mock(return_value=True)
204 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
205 r_f_c2544_profile.params = self.PROFILE
206 r_f_c2544_profile.register_generator(traffic_generator)
207 self.assertIsNone(r_f_c2544_profile.execute())
210 for ifname in range(1):
211 name = "xe{}".format(ifname)
213 "rx_throughput_fps": 20,
214 "tx_throughput_fps": 20,
215 "rx_throughput_mbps": 10,
216 "tx_throughput_mbps": 10,
223 'DropPercentage': 0.1996,
224 'RxThroughput': 33.333333333333336,
225 'TxThroughput': 33.4,
226 'CurrentDropPercentage': 0.1996,
227 'Throughput': 66.66666666666667,
229 'tx_throughput_fps': 20,
232 'rx_throughput_mbps': 10,
233 'tx_throughput_mbps': 10,
234 'rx_throughput_fps': 20,
237 traffic_generator.generate_samples = mock.MagicMock(return_value=samples)
238 traffic_generator.RUN_DURATION = 30
239 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
240 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
241 result = r_f_c2544_profile.get_drop_percentage(traffic_generator)
242 self.assertDictEqual(expected, result)
244 def test_get_drop_percentage_div_zero(self):
245 traffic_generator = mock.Mock(autospec=TrexProfile)
246 traffic_generator.my_ports = [0, 1]
247 traffic_generator.priv_ports = [0]
248 traffic_generator.pub_ports = [1]
249 traffic_generator.client = \
250 mock.Mock(return_value=True)
251 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
252 r_f_c2544_profile.params = self.PROFILE
253 self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator))
255 for ifname in range(1):
256 name = "xe{}".format(ifname)
257 samples[name] = {"rx_throughput_fps": 20,
258 "tx_throughput_fps": 20,
259 "rx_throughput_mbps": 10,
260 "tx_throughput_mbps": 10,
265 r_f_c2544_profile.throughput_max = 0
267 'DropPercentage': 100.0, 'RxThroughput': 100 / 3.0,
268 'TxThroughput': 0.0, 'CurrentDropPercentage': 100.0,
269 'Throughput': 66.66666666666667,
271 'tx_throughput_fps': 20, 'in_packets': 1000,
272 'out_packets': 0, 'rx_throughput_mbps': 10,
273 'tx_throughput_mbps': 10, 'rx_throughput_fps': 20
276 traffic_generator.generate_samples = mock.MagicMock(return_value=samples)
277 traffic_generator.RUN_DURATION = 30
278 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
279 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
280 self.assertDictEqual(expected,
281 r_f_c2544_profile.get_drop_percentage(traffic_generator))
283 def test_get_multiplier(self):
284 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
285 r_f_c2544_profile.max_rate = 100
286 r_f_c2544_profile.min_rate = 100
287 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
289 def test_calculate_pps(self):
290 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
291 r_f_c2544_profile.rate = 100
292 r_f_c2544_profile.pps = 100
293 samples = {'Throughput': 4549093.33}
294 self.assertEqual((2274546.67, 1.0),
295 r_f_c2544_profile.calculate_pps(samples))
297 def test_create_single_stream(self):
298 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
299 r_f_c2544_profile._create_single_packet = mock.MagicMock()
300 r_f_c2544_profile.pg_id = 1
301 self.assertIsNotNone(
302 r_f_c2544_profile.create_single_stream(64, 2274546.67))
304 def test_create_single_stream_no_pg_id(self):
305 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
306 r_f_c2544_profile._create_single_packet = mock.MagicMock()
307 r_f_c2544_profile.pg_id = 0
308 self.assertIsNotNone(
309 r_f_c2544_profile.create_single_stream(64, 2274546.67))
311 def test_execute_latency(self):
312 traffic_generator = mock.Mock(autospec=TrexProfile)
313 traffic_generator.my_ports = [0, 1]
314 traffic_generator.priv_ports = [-1]
315 traffic_generator.pub_ports = [1]
316 traffic_generator.client = \
317 mock.Mock(return_value=True)
318 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
319 r_f_c2544_profile.params = self.PROFILE
320 r_f_c2544_profile.first_run = True
322 for ifname in range(1):
323 name = "xe{}".format(ifname)
324 samples[name] = {"rx_throughput_fps": 20,
325 "tx_throughput_fps": 20,
326 "rx_throughput_mbps": 10,
327 "tx_throughput_mbps": 10,
331 samples['Throughput'] = 4549093.33
332 r_f_c2544_profile.calculate_pps = mock.Mock(return_value=[2274546.67,
335 self.assertEqual(None,
336 r_f_c2544_profile.execute_latency(traffic_generator,
340 if __name__ == '__main__':