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.
21 from tests.unit import STL_MOCKS
24 STLClient = mock.MagicMock()
25 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
29 from yardstick.network_services.traffic_profile.trex_traffic_profile \
31 from yardstick.network_services.traffic_profile.rfc2544 import \
35 class TestRFC2544Profile(unittest.TestCase):
37 "schema": "isb:traffic_profile:0.1",
39 "description": "Fixed traffic profile to run UDP traffic",
41 "traffic_type": "FixedTraffic",
42 "frame_rate": 100, # pps
46 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
48 'traffic_profile': {'traffic_type': 'RFC2544Profile',
50 'downlink_0': {'ipv4':
51 {'outer_l2': {'framesize':
52 {'64B': '100', '1518B': '0',
53 '128B': '0', '1400B': '0',
54 '256B': '0', '373b': '0',
56 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
58 'srcip4': '90.90.1.1-90.105.255.255',
59 'dscp': 0, 'ttl': 32, 'count': 1},
60 'outer_l4': {'srcport': '2001',
61 'dsrport': '1234', 'count': 1}}},
63 {'outer_l2': {'framesize':
64 {'64B': '100', '1518B': '0',
65 '128B': '0', '1400B': '0',
66 '256B': '0', '373b': '0',
68 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
70 'srcip4': '1.1.1.1-1.15.255.255',
71 'dscp': 0, 'ttl': 32, 'count': 1},
72 'outer_l4': {'dstport': '2001',
73 'srcport': '1234', 'count': 1}}},
74 'schema': 'isb:traffic_profile:0.1'}
76 def test___init__(self):
77 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
78 assert r_f_c2544_profile.rate
80 def test_execute(self):
81 traffic_generator = mock.Mock(autospec=TrexProfile)
82 traffic_generator.networks = {
84 "downlink_0": ["xe1"],
86 traffic_generator.client.return_value = True
87 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
88 r_f_c2544_profile.params = self.PROFILE
89 r_f_c2544_profile.first_run = True
90 self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator))
92 def test_get_drop_percentage(self):
93 traffic_generator = mock.Mock(autospec=TrexProfile)
94 traffic_generator.networks = {
96 "downlink_0": ["xe1"],
98 traffic_generator.client.return_value = True
100 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
101 r_f_c2544_profile.params = self.PROFILE
102 r_f_c2544_profile.register_generator(traffic_generator)
103 self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator))
106 for ifname in range(1):
107 name = "xe{}".format(ifname)
109 "rx_throughput_fps": 20,
110 "tx_throughput_fps": 20,
111 "rx_throughput_mbps": 10,
112 "tx_throughput_mbps": 10,
118 'DropPercentage': 0.0,
119 'RxThroughput': 100 / 3.0,
120 'TxThroughput': 100 / 3.0,
121 'CurrentDropPercentage': 0.0,
122 'Throughput': 66.66666666666667,
124 'tx_throughput_fps': 20,
127 'rx_throughput_mbps': 10,
128 'tx_throughput_mbps': 10,
129 'rx_throughput_fps': 20,
132 traffic_generator.generate_samples.return_value = samples
133 traffic_generator.RUN_DURATION = 30
134 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
135 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
136 result = r_f_c2544_profile.get_drop_percentage(traffic_generator)
137 self.assertDictEqual(result, expected)
139 def test_get_drop_percentage_update(self):
140 traffic_generator = mock.Mock(autospec=RFC2544Profile)
141 traffic_generator.networks = {
143 "downlink_0": ["xe1"],
145 traffic_generator.client = mock.Mock(return_value=True)
147 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
148 r_f_c2544_profile.params = self.PROFILE
149 r_f_c2544_profile.register_generator(traffic_generator)
150 self.assertIsNone(r_f_c2544_profile.execute_traffic())
153 for ifname in range(1):
154 name = "xe{}".format(ifname)
156 "rx_throughput_fps": 20,
157 "tx_throughput_fps": 20,
158 "rx_throughput_mbps": 10,
159 "tx_throughput_mbps": 10,
164 'DropPercentage': 0.1996,
165 'RxThroughput': 33.333333333333336,
166 'TxThroughput': 33.4,
167 'CurrentDropPercentage': 0.1996,
168 'Throughput': 66.66666666666667,
170 'tx_throughput_fps': 20,
173 'rx_throughput_mbps': 10,
174 'tx_throughput_mbps': 10,
175 'rx_throughput_fps': 20,
178 traffic_generator.generate_samples = mock.MagicMock(
179 return_value=samples)
180 traffic_generator.RUN_DURATION = 30
181 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
182 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
183 result = r_f_c2544_profile.get_drop_percentage(traffic_generator)
184 self.assertDictEqual(expected, result)
186 def test_get_drop_percentage_div_zero(self):
187 traffic_generator = mock.Mock(autospec=TrexProfile)
188 traffic_generator.networks = {
190 "downlink_0": ["xe1"],
192 traffic_generator.client = \
193 mock.Mock(return_value=True)
194 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
195 r_f_c2544_profile.params = self.PROFILE
196 self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator))
198 for ifname in range(1):
199 name = "xe{}".format(ifname)
200 samples[name] = {"rx_throughput_fps": 20,
201 "tx_throughput_fps": 20,
202 "rx_throughput_mbps": 10,
203 "tx_throughput_mbps": 10,
206 r_f_c2544_profile.throughput_max = 0
208 'DropPercentage': 100.0, 'RxThroughput': 100 / 3.0,
209 'TxThroughput': 0.0, 'CurrentDropPercentage': 100.0,
210 'Throughput': 66.66666666666667,
212 'tx_throughput_fps': 20, 'in_packets': 1000,
213 'out_packets': 0, 'rx_throughput_mbps': 10,
214 'tx_throughput_mbps': 10, 'rx_throughput_fps': 20
217 traffic_generator.generate_samples = mock.Mock(return_value=samples)
218 traffic_generator.RUN_DURATION = 30
219 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
220 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
221 self.assertDictEqual(expected,
222 r_f_c2544_profile.get_drop_percentage(traffic_generator))
224 def test_get_multiplier(self):
225 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
226 r_f_c2544_profile.max_rate = 100
227 r_f_c2544_profile.min_rate = 100
228 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
230 def test_calculate_pps(self):
231 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
232 r_f_c2544_profile.rate = 100
233 r_f_c2544_profile.pps = 100
234 samples = {'Throughput': 4549093.33}
235 self.assertEqual((2274546.67, 1.0),
236 r_f_c2544_profile.calculate_pps(samples))
238 def test_create_single_stream(self):
239 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
240 r_f_c2544_profile._create_single_packet = mock.MagicMock()
241 r_f_c2544_profile.pg_id = 1
242 self.assertIsNotNone(
243 r_f_c2544_profile.create_single_stream(64, 2274546.67))
245 def test_create_single_stream_no_pg_id(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 = 0
249 self.assertIsNotNone(
250 r_f_c2544_profile.create_single_stream(64, 2274546.67))
252 def test_execute_latency(self):
253 traffic_generator = mock.Mock(autospec=TrexProfile)
254 traffic_generator.networks = {
255 "private_0": ["xe0"],
258 traffic_generator.client = \
259 mock.Mock(return_value=True)
260 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
261 r_f_c2544_profile.params = self.PROFILE
262 r_f_c2544_profile.first_run = True
264 for ifname in range(1):
265 name = "xe{}".format(ifname)
266 samples[name] = {"rx_throughput_fps": 20,
267 "tx_throughput_fps": 20,
268 "rx_throughput_mbps": 10,
269 "tx_throughput_mbps": 10,
273 samples['Throughput'] = 4549093.33
274 r_f_c2544_profile.calculate_pps = mock.Mock(return_value=[2274546.67,
277 self.assertIsNone(r_f_c2544_profile.execute_latency(traffic_generator,