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
23 from tests.unit import STL_MOCKS
25 STLClient = mock.MagicMock()
26 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
30 from yardstick.network_services.traffic_profile.traffic_profile \
32 from yardstick.network_services.traffic_profile.ixia_rfc2544 import \
34 from yardstick.network_services.traffic_profile import ixia_rfc2544
37 class TestIXIARFC2544Profile(unittest.TestCase):
39 "schema": "isb:traffic_profile:0.1",
41 "description": "Fixed traffic profile to run UDP traffic",
43 "traffic_type": "FixedTraffic",
44 "frame_rate": 100, # pps
48 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
50 'traffic_profile': {'traffic_type': 'IXIARFC2544Profile',
53 {'outer_l2': {'framesize':
54 {'64B': '100', '1518B': '0',
55 '128B': '0', '1400B': '0',
56 '256B': '0', '373b': '0',
58 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
60 'srcip4': '90.90.1.1-90.105.255.255',
61 'dscp': 0, 'ttl': 32},
62 'outer_l4': {'srcport': '2001',
65 {'outer_l2': {'framesize':
66 {'64B': '100', '1518B': '0',
67 '128B': '0', '1400B': '0',
68 '256B': '0', '373b': '0',
70 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
72 'srcip4': '1.1.1.1-1.15.255.255',
73 'dscp': 0, 'ttl': 32},
74 'outer_l4': {'dstport': '2001',
76 'schema': 'isb:traffic_profile:0.1'}
78 def test_get_ixia_traffic_profile_error(self):
79 traffic_generator = mock.Mock(autospec=TrexProfile)
80 traffic_generator.my_ports = [0, 1]
81 traffic_generator.priv_ports = [-1]
82 traffic_generator.pub_ports = [1]
83 traffic_generator.client = \
84 mock.Mock(return_value=True)
92 "dstmac": "00:00:00:00:00:03",
93 "framesPerSecond": True,
95 "srcmac": "00:00:00:00:00:01"
99 "dstip4": "152.16.40.20",
101 "srcip4": "152.16.100.20",
106 "dstip4": "152.16.40.20",
108 "srcip4": "152.16.100.20",
114 "dstip4": "152.16.100.20",
116 "srcip4": "152.16.40.20",
123 "traffic_type": "continuous"
131 "dstmac": "00:00:00:00:00:04",
132 "framesPerSecond": True,
134 "srcmac": "00:00:00:00:00:01"
139 "dstip4": "152.16.100.20",
141 "srcip4": "152.16.40.20",
147 "dstip4": "152.16.100.20",
149 "srcip4": "152.16.40.20",
155 "dstip4": "152.16.100.20",
157 "srcip4": "152.16.40.20",
164 "traffic_type": "continuous"
167 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
169 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
170 r_f_c2544_profile.rate = 100
171 mac = {"src_mac_0": "00:00:00:00:00:01",
172 "src_mac_1": "00:00:00:00:00:02",
173 "src_mac_2": "00:00:00:00:00:02",
174 "dst_mac_0": "00:00:00:00:00:03",
175 "dst_mac_1": "00:00:00:00:00:04",
176 "dst_mac_2": "00:00:00:00:00:04"}
177 self.assertRaises(IOError, r_f_c2544_profile._get_ixia_traffic_profile,
178 self.PROFILE, mac, xfile="tmp",
179 static_traffic=STATIC_TRAFFIC)
182 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
183 def test_get_ixia_traffic_profile(self, mock_open):
184 traffic_generator = mock.Mock(autospec=TrexProfile)
185 traffic_generator.my_ports = [0, 1]
186 traffic_generator.priv_ports = [-1]
187 traffic_generator.pub_ports = [1]
188 traffic_generator.client = \
189 mock.Mock(return_value=True)
197 "dstmac": "00:00:00:00:00:03",
198 "framesPerSecond": True,
200 "srcmac": "00:00:00:00:00:01"
204 "dstip4": "152.16.40.20",
206 "srcip4": "152.16.100.20",
211 "dstip4": "152.16.40.20",
213 "srcip4": "152.16.100.20",
219 "dstip4": "152.16.100.20",
221 "srcip4": "152.16.40.20",
228 "traffic_type": "continuous"
236 "dstmac": "00:00:00:00:00:04",
237 "framesPerSecond": True,
239 "srcmac": "00:00:00:00:00:01"
244 "dstip4": "152.16.100.20",
246 "srcip4": "152.16.40.20",
252 "dstip4": "152.16.100.20",
254 "srcip4": "152.16.40.20",
260 "dstip4": "152.16.100.20",
262 "srcip4": "152.16.40.20",
269 "traffic_type": "continuous"
272 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
274 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
275 r_f_c2544_profile.rate = 100
276 mac = {"src_mac_0": "00:00:00:00:00:01",
277 "src_mac_1": "00:00:00:00:00:02",
278 "src_mac_2": "00:00:00:00:00:02",
279 "dst_mac_0": "00:00:00:00:00:03",
280 "dst_mac_1": "00:00:00:00:00:04",
281 "dst_mac_2": "00:00:00:00:00:04"}
282 result = r_f_c2544_profile._get_ixia_traffic_profile(
283 self.PROFILE, mac, xfile="tmp", static_traffic=STATIC_TRAFFIC)
284 self.assertIsNotNone(result)
286 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
287 def test_get_ixia_traffic_profile_v6(self, mock_open):
288 traffic_generator = mock.Mock(autospec=TrexProfile)
289 traffic_generator.my_ports = [0, 1]
290 traffic_generator.priv_ports = [-1]
291 traffic_generator.pub_ports = [1]
292 traffic_generator.client = \
293 mock.Mock(return_value=True)
301 "dstmac": "00:00:00:00:00:03",
302 "framesPerSecond": True,
304 "srcmac": "00:00:00:00:00:01"
308 "dstip4": "152.16.40.20",
310 "srcip4": "152.16.100.20",
315 "dstip4": "152.16.40.20",
317 "srcip4": "152.16.100.20",
323 "dstip4": "152.16.100.20",
325 "srcip4": "152.16.40.20",
332 "traffic_type": "continuous"
340 "dstmac": "00:00:00:00:00:04",
341 "framesPerSecond": True,
343 "srcmac": "00:00:00:00:00:01"
348 "dstip4": "152.16.100.20",
350 "srcip4": "152.16.40.20",
356 "dstip4": "152.16.100.20",
358 "srcip4": "152.16.40.20",
364 "dstip4": "152.16.100.20",
366 "srcip4": "152.16.40.20",
373 "traffic_type": "continuous"
376 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
378 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
379 r_f_c2544_profile.rate = 100
380 mac = {"src_mac_0": "00:00:00:00:00:01",
381 "src_mac_1": "00:00:00:00:00:02",
382 "src_mac_2": "00:00:00:00:00:02",
383 "dst_mac_0": "00:00:00:00:00:03",
384 "dst_mac_1": "00:00:00:00:00:04",
385 "dst_mac_2": "00:00:00:00:00:04"}
386 profile_data = {'description': 'Traffic profile to run RFC2544',
389 {'traffic_type': 'IXIARFC2544Profile',
393 {'outer_l2': {'framesize':
394 {'64B': '100', '1518B': '0',
395 '128B': '0', '1400B': '0',
396 '256B': '0', '373b': '0',
398 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
400 'srcip6': '90.90.1.1-90.105.255.255',
401 'dscp': 0, 'ttl': 32},
402 'outer_l4': {'srcport': '2001',
403 'dsrport': '1234'}}},
405 {'outer_l2': {'framesize':
406 {'64B': '100', '1518B': '0',
407 '128B': '0', '1400B': '0',
408 '256B': '0', '373b': '0',
411 {'dstip6': '9.9.1.1-90.105.255.255',
413 'srcip6': '1.1.1.1-1.15.255.255',
414 'dscp': 0, 'ttl': 32},
415 'outer_l4': {'dstport': '2001',
416 'srcport': '1234'}}},
417 'schema': 'isb:traffic_profile:0.1'}
418 result = r_f_c2544_profile._get_ixia_traffic_profile(
419 profile_data, mac, static_traffic=STATIC_TRAFFIC)
420 self.assertIsNotNone(result)
422 def test__ixia_traffic_generate(self):
423 traffic_generator = mock.Mock(autospec=TrexProfile)
424 traffic_generator.my_ports = [0, 1]
425 traffic_generator.priv_ports = [-1]
426 traffic_generator.pub_ports = [1]
427 traffic_generator.client = \
428 mock.Mock(return_value=True)
429 traffic = {"public": {'iload': 10},
430 "private": {'iload': 10}}
431 ixia_obj = mock.MagicMock()
432 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
433 r_f_c2544_profile.rate = 100
434 result = r_f_c2544_profile._ixia_traffic_generate(traffic_generator,
436 self.assertIsNone(result)
439 def test_execute(self):
440 traffic_generator = mock.Mock(autospec=TrexProfile)
441 traffic_generator.my_ports = [0, 1]
442 traffic_generator.priv_ports = [-1]
443 traffic_generator.pub_ports = [1]
444 traffic_generator.client = \
445 mock.Mock(return_value=True)
446 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
447 r_f_c2544_profile.first_run = True
448 r_f_c2544_profile.params = {"public": {'iload': 10},
449 "private": {'iload': 10}}
451 r_f_c2544_profile.get_streams = mock.Mock()
452 r_f_c2544_profile.full_profile = {}
453 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
454 r_f_c2544_profile.get_multiplier = mock.Mock()
455 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
456 ixia_obj = mock.MagicMock()
457 self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator,
460 def test_get_drop_percentage(self):
461 traffic_generator = mock.Mock(autospec=TrexProfile)
462 traffic_generator.my_ports = [0, 1]
463 traffic_generator.priv_ports = [0]
464 traffic_generator.pub_ports = [1]
465 traffic_generator.client = \
466 mock.Mock(return_value=True)
467 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
468 r_f_c2544_profile.params = self.PROFILE
469 ixia_obj = mock.MagicMock()
470 r_f_c2544_profile.execute = mock.Mock()
471 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
472 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
473 r_f_c2544_profile.get_multiplier = mock.Mock()
474 r_f_c2544_profile.tmp_throughput = 0
475 r_f_c2544_profile.tmp_drop = 0
476 r_f_c2544_profile.full_profile = {}
478 for ifname in range(1):
479 name = "xe{}".format(ifname)
480 samples[name] = {"rx_throughput_fps": 20,
481 "tx_throughput_fps": 20,
482 "rx_throughput_mbps": 10,
483 "tx_throughput_mbps": 10,
490 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
491 traffic_generator, samples,
492 tol_min, tolerance, ixia_obj))
494 def test_get_drop_percentage_update(self):
495 traffic_generator = mock.Mock(autospec=TrexProfile)
496 traffic_generator.my_ports = [0, 1]
497 traffic_generator.priv_ports = [0]
498 traffic_generator.pub_ports = [1]
499 traffic_generator.client = \
500 mock.Mock(return_value=True)
501 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
502 r_f_c2544_profile.params = self.PROFILE
503 ixia_obj = mock.MagicMock()
504 r_f_c2544_profile.execute = mock.Mock()
505 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
506 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
507 r_f_c2544_profile.get_multiplier = mock.Mock()
508 r_f_c2544_profile.tmp_throughput = 0
509 r_f_c2544_profile.tmp_drop = 0
510 r_f_c2544_profile.full_profile = {}
512 for ifname in range(1):
513 name = "xe{}".format(ifname)
514 samples[name] = {"rx_throughput_fps": 20,
515 "tx_throughput_fps": 20,
516 "rx_throughput_mbps": 10,
517 "tx_throughput_mbps": 10,
524 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
525 traffic_generator, samples,
526 tol_min, tolerance, ixia_obj))
528 def test_get_drop_percentage_div_zero(self):
529 traffic_generator = mock.Mock(autospec=TrexProfile)
530 traffic_generator.my_ports = [0, 1]
531 traffic_generator.priv_ports = [0]
532 traffic_generator.pub_ports = [1]
533 traffic_generator.client = \
534 mock.Mock(return_value=True)
535 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
536 r_f_c2544_profile.params = self.PROFILE
537 ixia_obj = mock.MagicMock()
538 r_f_c2544_profile.execute = mock.Mock()
539 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
540 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
541 r_f_c2544_profile.get_multiplier = mock.Mock()
542 r_f_c2544_profile.tmp_throughput = 0
543 r_f_c2544_profile.tmp_drop = 0
544 r_f_c2544_profile.full_profile = {}
546 for ifname in range(1):
547 name = "xe{}".format(ifname)
548 samples[name] = {"rx_throughput_fps": 20,
549 "tx_throughput_fps": 20,
550 "rx_throughput_mbps": 10,
551 "tx_throughput_mbps": 10,
558 r_f_c2544_profile.tmp_throughput = 0
559 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
560 traffic_generator, samples,
561 tol_min, tolerance, ixia_obj))
563 def test_get_multiplier(self):
564 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
565 r_f_c2544_profile.max_rate = 100
566 r_f_c2544_profile.min_rate = 100
567 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
569 def test_start_ixia_latency(self):
570 traffic_generator = mock.Mock(autospec=TrexProfile)
571 traffic_generator.my_ports = [0, 1]
572 traffic_generator.priv_ports = [0]
573 traffic_generator.pub_ports = [1]
574 traffic_generator.client = \
575 mock.Mock(return_value=True)
576 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
577 r_f_c2544_profile.max_rate = 100
578 r_f_c2544_profile.min_rate = 100
579 ixia_obj = mock.MagicMock()
580 r_f_c2544_profile._get_ixia_traffic_profile = \
581 mock.Mock(return_value={})
582 r_f_c2544_profile.full_profile = {}
583 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
586 r_f_c2544_profile.start_ixia_latency(traffic_generator,
590 if __name__ == '__main__':