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 from tests.unit import STL_MOCKS
27 STLClient = mock.MagicMock()
28 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
32 from yardstick.network_services.traffic_profile.traffic_profile \
34 from yardstick.network_services.traffic_profile.rfc2544 import \
38 class TestRFC2544Profile(unittest.TestCase):
40 "schema": "isb:traffic_profile:0.1",
42 "description": "Fixed traffic profile to run UDP traffic",
44 "traffic_type": "FixedTraffic",
45 "frame_rate": 100, # pps
49 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
51 'traffic_profile': {'traffic_type': 'RFC2544Profile',
54 {'outer_l2': {'framesize':
55 {'64B': '100', '1518B': '0',
56 '128B': '0', '1400B': '0',
57 '256B': '0', '373b': '0',
59 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
61 'srcip4': '90.90.1.1-90.105.255.255',
62 'dscp': 0, 'ttl': 32, 'count': 1},
63 'outer_l4': {'srcport': '2001',
64 'dsrport': '1234', 'count': 1}}},
66 {'outer_l2': {'framesize':
67 {'64B': '100', '1518B': '0',
68 '128B': '0', '1400B': '0',
69 '256B': '0', '373b': '0',
71 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
73 'srcip4': '1.1.1.1-1.15.255.255',
74 'dscp': 0, 'ttl': 32, 'count': 1},
75 'outer_l4': {'dstport': '2001',
76 'srcport': '1234', 'count': 1}}},
77 'schema': 'isb:traffic_profile:0.1'}
79 def test___init__(self):
80 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
81 assert r_f_c2544_profile.rate
83 def test_execute(self):
84 traffic_generator = mock.Mock(autospec=TrexProfile)
85 traffic_generator.networks = {
89 traffic_generator.client = \
90 mock.Mock(return_value=True)
91 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
92 r_f_c2544_profile.params = self.PROFILE
93 r_f_c2544_profile.first_run = True
94 self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator))
96 def test_get_drop_percentage(self):
97 traffic_generator = mock.Mock(autospec=TrexProfile)
98 traffic_generator.networks = {
102 traffic_generator.client = mock.Mock(return_value=True)
104 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
105 r_f_c2544_profile.params = self.PROFILE
106 r_f_c2544_profile.register_generator(traffic_generator)
107 self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator))
110 for ifname in range(1):
111 name = "xe{}".format(ifname)
113 "rx_throughput_fps": 20,
114 "tx_throughput_fps": 20,
115 "rx_throughput_mbps": 10,
116 "tx_throughput_mbps": 10,
122 'DropPercentage': 0.0,
123 'RxThroughput': 100 / 3.0,
124 'TxThroughput': 100 / 3.0,
125 'CurrentDropPercentage': 0.0,
126 'Throughput': 66.66666666666667,
128 'tx_throughput_fps': 20,
131 'rx_throughput_mbps': 10,
132 'tx_throughput_mbps': 10,
133 'rx_throughput_fps': 20,
136 traffic_generator.generate_samples = mock.MagicMock(return_value=samples)
137 traffic_generator.RUN_DURATION = 30
138 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
139 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
140 result = r_f_c2544_profile.get_drop_percentage(traffic_generator)
141 self.assertDictEqual(result, expected)
143 def test_get_drop_percentage_update(self):
144 traffic_generator = mock.Mock(autospec=RFC2544Profile)
145 traffic_generator.networks = {
146 "private_0": ["xe0"],
149 traffic_generator.client = mock.Mock(return_value=True)
151 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
152 r_f_c2544_profile.params = self.PROFILE
153 r_f_c2544_profile.register_generator(traffic_generator)
154 self.assertIsNone(r_f_c2544_profile.execute_traffic())
157 for ifname in range(1):
158 name = "xe{}".format(ifname)
160 "rx_throughput_fps": 20,
161 "tx_throughput_fps": 20,
162 "rx_throughput_mbps": 10,
163 "tx_throughput_mbps": 10,
170 'DropPercentage': 0.1996,
171 'RxThroughput': 33.333333333333336,
172 'TxThroughput': 33.4,
173 'CurrentDropPercentage': 0.1996,
174 'Throughput': 66.66666666666667,
176 'tx_throughput_fps': 20,
179 'rx_throughput_mbps': 10,
180 'tx_throughput_mbps': 10,
181 'rx_throughput_fps': 20,
184 traffic_generator.generate_samples = mock.MagicMock(return_value=samples)
185 traffic_generator.RUN_DURATION = 30
186 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
187 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
188 result = r_f_c2544_profile.get_drop_percentage(traffic_generator)
189 self.assertDictEqual(expected, result)
191 def test_get_drop_percentage_div_zero(self):
192 traffic_generator = mock.Mock(autospec=TrexProfile)
193 traffic_generator.networks = {
194 "private_0": ["xe0"],
197 traffic_generator.client = \
198 mock.Mock(return_value=True)
199 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
200 r_f_c2544_profile.params = self.PROFILE
201 self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator))
203 for ifname in range(1):
204 name = "xe{}".format(ifname)
205 samples[name] = {"rx_throughput_fps": 20,
206 "tx_throughput_fps": 20,
207 "rx_throughput_mbps": 10,
208 "tx_throughput_mbps": 10,
213 r_f_c2544_profile.throughput_max = 0
215 'DropPercentage': 100.0, 'RxThroughput': 100 / 3.0,
216 'TxThroughput': 0.0, 'CurrentDropPercentage': 100.0,
217 'Throughput': 66.66666666666667,
219 'tx_throughput_fps': 20, 'in_packets': 1000,
220 'out_packets': 0, 'rx_throughput_mbps': 10,
221 'tx_throughput_mbps': 10, 'rx_throughput_fps': 20
224 traffic_generator.generate_samples = mock.MagicMock(return_value=samples)
225 traffic_generator.RUN_DURATION = 30
226 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
227 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
228 self.assertDictEqual(expected,
229 r_f_c2544_profile.get_drop_percentage(traffic_generator))
231 def test_get_multiplier(self):
232 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
233 r_f_c2544_profile.max_rate = 100
234 r_f_c2544_profile.min_rate = 100
235 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
237 def test_calculate_pps(self):
238 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
239 r_f_c2544_profile.rate = 100
240 r_f_c2544_profile.pps = 100
241 samples = {'Throughput': 4549093.33}
242 self.assertEqual((2274546.67, 1.0),
243 r_f_c2544_profile.calculate_pps(samples))
245 def test_create_single_stream(self):
246 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
247 r_f_c2544_profile._create_single_packet = mock.MagicMock()
248 r_f_c2544_profile.pg_id = 1
249 self.assertIsNotNone(
250 r_f_c2544_profile.create_single_stream(64, 2274546.67))
252 def test_create_single_stream_no_pg_id(self):
253 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
254 r_f_c2544_profile._create_single_packet = mock.MagicMock()
255 r_f_c2544_profile.pg_id = 0
256 self.assertIsNotNone(
257 r_f_c2544_profile.create_single_stream(64, 2274546.67))
259 def test_execute_latency(self):
260 traffic_generator = mock.Mock(autospec=TrexProfile)
261 traffic_generator.networks = {
262 "private_0": ["xe0"],
265 traffic_generator.client = \
266 mock.Mock(return_value=True)
267 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
268 r_f_c2544_profile.params = self.PROFILE
269 r_f_c2544_profile.first_run = True
271 for ifname in range(1):
272 name = "xe{}".format(ifname)
273 samples[name] = {"rx_throughput_fps": 20,
274 "tx_throughput_fps": 20,
275 "rx_throughput_mbps": 10,
276 "tx_throughput_mbps": 10,
280 samples['Throughput'] = 4549093.33
281 r_f_c2544_profile.calculate_pps = mock.Mock(return_value=[2274546.67,
284 self.assertEqual(None,
285 r_f_c2544_profile.execute_latency(traffic_generator,
289 if __name__ == '__main__':