1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 from yardstick.tests import STL_MOCKS
22 STLClient = mock.MagicMock()
23 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
27 from yardstick.network_services.traffic_profile.trex_traffic_profile \
29 from yardstick.network_services.traffic_profile.rfc2544 import \
33 class TestRFC2544Profile(unittest.TestCase):
35 "schema": "isb:traffic_profile:0.1",
37 "description": "Fixed traffic profile to run UDP traffic",
39 "traffic_type": "FixedTraffic",
40 "frame_rate": 100, # pps
44 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
46 'traffic_profile': {'traffic_type': 'RFC2544Profile',
48 'downlink_0': {'ipv4':
49 {'outer_l2': {'framesize':
50 {'64B': '100', '1518B': '0',
51 '128B': '0', '1400B': '0',
52 '256B': '0', '373b': '0',
54 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
56 'srcip4': '90.90.1.1-90.105.255.255',
57 'dscp': 0, 'ttl': 32, 'count': 1},
58 'outer_l4': {'srcport': '2001',
59 'dsrport': '1234', 'count': 1}}},
61 {'outer_l2': {'framesize':
62 {'64B': '100', '1518B': '0',
63 '128B': '0', '1400B': '0',
64 '256B': '0', '373b': '0',
66 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
68 'srcip4': '1.1.1.1-1.15.255.255',
69 'dscp': 0, 'ttl': 32, 'count': 1},
70 'outer_l4': {'dstport': '2001',
71 'srcport': '1234', 'count': 1}}},
72 'schema': 'isb:traffic_profile:0.1'}
74 def test___init__(self):
75 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
76 self.assertIsNotNone(r_f_c2544_profile.rate)
78 def test_execute(self):
79 traffic_generator = mock.Mock(autospec=TrexProfile)
80 traffic_generator.networks = {
82 "downlink_0": ["xe1"],
84 traffic_generator.client.return_value = True
85 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
86 r_f_c2544_profile.params = self.PROFILE
87 r_f_c2544_profile.first_run = True
88 self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator))
90 def test_get_drop_percentage(self):
91 traffic_generator = mock.Mock(autospec=TrexProfile)
92 traffic_generator.networks = {
94 "downlink_0": ["xe1"],
96 traffic_generator.client.return_value = True
98 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
99 r_f_c2544_profile.params = self.PROFILE
100 r_f_c2544_profile.register_generator(traffic_generator)
101 self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator))
104 for ifname in range(1):
105 name = "xe{}".format(ifname)
107 "rx_throughput_fps": 20,
108 "tx_throughput_fps": 20,
109 "rx_throughput_mbps": 10,
110 "tx_throughput_mbps": 10,
116 'DropPercentage': 0.0,
117 'RxThroughput': 100 / 3.0,
118 'TxThroughput': 100 / 3.0,
119 'CurrentDropPercentage': 0.0,
120 'Throughput': 66.66666666666667,
122 'tx_throughput_fps': 20,
125 'rx_throughput_mbps': 10,
126 'tx_throughput_mbps': 10,
127 'rx_throughput_fps': 20,
130 traffic_generator.generate_samples.return_value = samples
131 traffic_generator.RUN_DURATION = 30
132 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
133 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
134 result = r_f_c2544_profile.get_drop_percentage(traffic_generator)
135 self.assertDictEqual(result, expected)
137 def test_get_drop_percentage_update(self):
138 traffic_generator = mock.Mock(autospec=RFC2544Profile)
139 traffic_generator.networks = {
141 "downlink_0": ["xe1"],
143 traffic_generator.client = mock.Mock(return_value=True)
145 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
146 r_f_c2544_profile.params = self.PROFILE
147 r_f_c2544_profile.register_generator(traffic_generator)
148 self.assertIsNone(r_f_c2544_profile.execute_traffic())
151 for ifname in range(1):
152 name = "xe{}".format(ifname)
154 "rx_throughput_fps": 20,
155 "tx_throughput_fps": 20,
156 "rx_throughput_mbps": 10,
157 "tx_throughput_mbps": 10,
162 'DropPercentage': 0.1996,
163 'RxThroughput': 33.333333333333336,
164 'TxThroughput': 33.4,
165 'CurrentDropPercentage': 0.1996,
166 'Throughput': 66.66666666666667,
168 'tx_throughput_fps': 20,
171 'rx_throughput_mbps': 10,
172 'tx_throughput_mbps': 10,
173 'rx_throughput_fps': 20,
176 traffic_generator.generate_samples = mock.MagicMock(
177 return_value=samples)
178 traffic_generator.RUN_DURATION = 30
179 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
180 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
181 result = r_f_c2544_profile.get_drop_percentage(traffic_generator)
182 self.assertDictEqual(expected, result)
184 def test_get_drop_percentage_div_zero(self):
185 traffic_generator = mock.Mock(autospec=TrexProfile)
186 traffic_generator.networks = {
188 "downlink_0": ["xe1"],
190 traffic_generator.client = \
191 mock.Mock(return_value=True)
192 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
193 r_f_c2544_profile.params = self.PROFILE
195 r_f_c2544_profile.execute_traffic(traffic_generator))
197 for ifname in range(1):
198 name = "xe{}".format(ifname)
199 samples[name] = {"rx_throughput_fps": 20,
200 "tx_throughput_fps": 20,
201 "rx_throughput_mbps": 10,
202 "tx_throughput_mbps": 10,
205 r_f_c2544_profile.throughput_max = 0
207 'DropPercentage': 100.0, 'RxThroughput': 100 / 3.0,
208 'TxThroughput': 0.0, 'CurrentDropPercentage': 100.0,
209 'Throughput': 66.66666666666667,
211 'tx_throughput_fps': 20, 'in_packets': 1000,
212 'out_packets': 0, 'rx_throughput_mbps': 10,
213 'tx_throughput_mbps': 10, 'rx_throughput_fps': 20
216 traffic_generator.generate_samples = mock.Mock(return_value=samples)
217 traffic_generator.RUN_DURATION = 30
218 traffic_generator.rfc2544_helper.tolerance_low = 0.0001
219 traffic_generator.rfc2544_helper.tolerance_high = 0.0001
220 self.assertDictEqual(expected,
221 r_f_c2544_profile.get_drop_percentage(traffic_generator))
223 def test_get_multiplier(self):
224 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
225 r_f_c2544_profile.max_rate = 100
226 r_f_c2544_profile.min_rate = 100
227 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
229 def test_calculate_pps(self):
230 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
231 r_f_c2544_profile.rate = 100
232 r_f_c2544_profile.pps = 100
233 samples = {'Throughput': 4549093.33}
234 self.assertEqual((2274546.67, 1.0),
235 r_f_c2544_profile.calculate_pps(samples))
237 def test_create_single_stream(self):
238 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
239 r_f_c2544_profile._create_single_packet = mock.MagicMock()
240 r_f_c2544_profile.pg_id = 1
241 self.assertIsNotNone(
242 r_f_c2544_profile.create_single_stream(64, 2274546.67))
244 def test_create_single_stream_no_pg_id(self):
245 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
246 r_f_c2544_profile._create_single_packet = mock.MagicMock()
247 r_f_c2544_profile.pg_id = 0
248 self.assertIsNotNone(
249 r_f_c2544_profile.create_single_stream(64, 2274546.67))
251 def test_execute_latency(self):
252 traffic_generator = mock.Mock(autospec=TrexProfile)
253 traffic_generator.networks = {
254 "private_0": ["xe0"],
257 traffic_generator.client = \
258 mock.Mock(return_value=True)
259 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
260 r_f_c2544_profile.params = self.PROFILE
261 r_f_c2544_profile.first_run = True
263 for ifname in range(1):
264 name = "xe{}".format(ifname)
265 samples[name] = {"rx_throughput_fps": 20,
266 "tx_throughput_fps": 20,
267 "rx_throughput_mbps": 10,
268 "tx_throughput_mbps": 10,
272 samples['Throughput'] = 4549093.33
273 r_f_c2544_profile.calculate_pps = mock.Mock(return_value=[2274546.67,
276 self.assertIsNone(r_f_c2544_profile.execute_latency(traffic_generator,