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',
59 'proto': 'udp', 'count': '1',
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',
71 'proto': 'udp', 'count': '1',
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",
220 "dstip4": "152.16.100.20",
222 "srcip4": "152.16.40.20",
231 "traffic_type": "continuous"
239 "dstmac": "00:00:00:00:00:04",
240 "framesPerSecond": True,
242 "srcmac": "00:00:00:00:00:01"
247 "dstip4": "152.16.100.20",
249 "srcip4": "152.16.40.20",
255 "dstip4": "152.16.100.20",
257 "srcip4": "152.16.40.20",
264 "dstip4": "152.16.100.20",
266 "srcip4": "152.16.40.20",
275 "traffic_type": "continuous"
278 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
280 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
281 r_f_c2544_profile.rate = 100
282 mac = {"src_mac_0": "00:00:00:00:00:01",
283 "src_mac_1": "00:00:00:00:00:02",
284 "src_mac_2": "00:00:00:00:00:02",
285 "dst_mac_0": "00:00:00:00:00:03",
286 "dst_mac_1": "00:00:00:00:00:04",
287 "dst_mac_2": "00:00:00:00:00:04"}
288 result = r_f_c2544_profile._get_ixia_traffic_profile(
289 self.PROFILE, mac, xfile="tmp", static_traffic=STATIC_TRAFFIC)
290 self.assertIsNotNone(result)
292 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
293 def test_get_ixia_traffic_profile_v6(self, mock_open):
294 traffic_generator = mock.Mock(autospec=TrexProfile)
295 traffic_generator.my_ports = [0, 1]
296 traffic_generator.priv_ports = [-1]
297 traffic_generator.pub_ports = [1]
298 traffic_generator.client = \
299 mock.Mock(return_value=True)
307 "dstmac": "00:00:00:00:00:03",
308 "framesPerSecond": True,
310 "srcmac": "00:00:00:00:00:01"
314 "dstip4": "152.16.40.20",
316 "srcip4": "152.16.100.20",
321 "dstip4": "152.16.40.20",
323 "srcip4": "152.16.100.20",
329 "dstip4": "152.16.100.20",
331 "srcip4": "152.16.40.20",
338 "traffic_type": "continuous"
346 "dstmac": "00:00:00:00:00:04",
347 "framesPerSecond": True,
349 "srcmac": "00:00:00:00:00:01"
354 "dstip4": "152.16.100.20",
356 "srcip4": "152.16.40.20",
362 "dstip4": "152.16.100.20",
364 "srcip4": "152.16.40.20",
370 "dstip4": "152.16.100.20",
372 "srcip4": "152.16.40.20",
379 "traffic_type": "continuous"
382 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
384 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
385 r_f_c2544_profile.rate = 100
386 mac = {"src_mac_0": "00:00:00:00:00:01",
387 "src_mac_1": "00:00:00:00:00:02",
388 "src_mac_2": "00:00:00:00:00:02",
389 "dst_mac_0": "00:00:00:00:00:03",
390 "dst_mac_1": "00:00:00:00:00:04",
391 "dst_mac_2": "00:00:00:00:00:04"}
392 profile_data = {'description': 'Traffic profile to run RFC2544',
395 {'traffic_type': 'IXIARFC2544Profile',
399 {'outer_l2': {'framesize':
400 {'64B': '100', '1518B': '0',
401 '128B': '0', '1400B': '0',
402 '256B': '0', '373b': '0',
404 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
405 'proto': 'udp', 'count': '1',
406 'srcip4': '90.90.1.1-90.105.255.255',
407 'dscp': 0, 'ttl': 32},
408 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
409 'proto': 'udp', 'count': '1',
410 'srcip6': '90.90.1.1-90.105.255.255',
411 'dscp': 0, 'ttl': 32},
412 'outer_l4': {'srcport': '2001',
413 'dsrport': '1234'}}},
415 {'outer_l2': {'framesize':
416 {'64B': '100', '1518B': '0',
417 '128B': '0', '1400B': '0',
418 '256B': '0', '373b': '0',
421 {'dstip4': '9.9.1.1-90.105.255.255',
422 'proto': 'udp', 'count': '1',
423 'srcip4': '1.1.1.1-1.15.255.255',
424 'dscp': 0, 'ttl': 32},
426 {'dstip6': '9.9.1.1-90.105.255.255',
427 'proto': 'udp', 'count': '1',
428 'srcip6': '1.1.1.1-1.15.255.255',
429 'dscp': 0, 'ttl': 32},
431 'outer_l4': {'dstport': '2001',
432 'srcport': '1234'}}},
433 'schema': 'isb:traffic_profile:0.1'}
434 result = r_f_c2544_profile._get_ixia_traffic_profile(
435 profile_data, mac, static_traffic=STATIC_TRAFFIC)
436 self.assertIsNotNone(result)
438 def test__ixia_traffic_generate(self):
439 traffic_generator = mock.Mock(autospec=TrexProfile)
440 traffic_generator.my_ports = [0, 1]
441 traffic_generator.priv_ports = [-1]
442 traffic_generator.pub_ports = [1]
443 traffic_generator.client = \
444 mock.Mock(return_value=True)
445 traffic = {"public": {'iload': 10},
446 "private": {'iload': 10}}
447 ixia_obj = mock.MagicMock()
448 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
449 r_f_c2544_profile.rate = 100
450 result = r_f_c2544_profile._ixia_traffic_generate(traffic_generator,
452 self.assertIsNone(result)
455 def test_execute(self):
456 traffic_generator = mock.Mock(autospec=TrexProfile)
457 traffic_generator.my_ports = [0, 1]
458 traffic_generator.priv_ports = [-1]
459 traffic_generator.pub_ports = [1]
460 traffic_generator.client = \
461 mock.Mock(return_value=True)
462 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
463 r_f_c2544_profile.first_run = True
464 r_f_c2544_profile.params = {"public": {'iload': 10},
465 "private": {'iload': 10}}
467 r_f_c2544_profile.get_streams = mock.Mock()
468 r_f_c2544_profile.full_profile = {}
469 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
470 r_f_c2544_profile.get_multiplier = mock.Mock()
471 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
472 ixia_obj = mock.MagicMock()
473 self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator,
476 def test_get_drop_percentage(self):
477 traffic_generator = mock.Mock(autospec=TrexProfile)
478 traffic_generator.my_ports = [0, 1]
479 traffic_generator.priv_ports = [0]
480 traffic_generator.pub_ports = [1]
481 traffic_generator.client = \
482 mock.Mock(return_value=True)
483 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
484 r_f_c2544_profile.params = self.PROFILE
485 ixia_obj = mock.MagicMock()
486 r_f_c2544_profile.execute = mock.Mock()
487 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
488 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
489 r_f_c2544_profile.get_multiplier = mock.Mock()
490 r_f_c2544_profile.tmp_throughput = 0
491 r_f_c2544_profile.tmp_drop = 0
492 r_f_c2544_profile.full_profile = {}
494 for ifname in range(1):
495 name = "xe{}".format(ifname)
496 samples[name] = {"rx_throughput_fps": 20,
497 "tx_throughput_fps": 20,
498 "rx_throughput_mbps": 10,
499 "tx_throughput_mbps": 10,
506 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
507 traffic_generator, samples,
508 tol_min, tolerance, ixia_obj))
510 def test_get_drop_percentage_update(self):
511 traffic_generator = mock.Mock(autospec=TrexProfile)
512 traffic_generator.my_ports = [0, 1]
513 traffic_generator.priv_ports = [0]
514 traffic_generator.pub_ports = [1]
515 traffic_generator.client = \
516 mock.Mock(return_value=True)
517 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
518 r_f_c2544_profile.params = self.PROFILE
519 ixia_obj = mock.MagicMock()
520 r_f_c2544_profile.execute = mock.Mock()
521 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
522 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
523 r_f_c2544_profile.get_multiplier = mock.Mock()
524 r_f_c2544_profile.tmp_throughput = 0
525 r_f_c2544_profile.tmp_drop = 0
526 r_f_c2544_profile.full_profile = {}
528 for ifname in range(1):
529 name = "xe{}".format(ifname)
530 samples[name] = {"rx_throughput_fps": 20,
531 "tx_throughput_fps": 20,
532 "rx_throughput_mbps": 10,
533 "tx_throughput_mbps": 10,
540 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
541 traffic_generator, samples,
542 tol_min, tolerance, ixia_obj))
544 def test_get_drop_percentage_div_zero(self):
545 traffic_generator = mock.Mock(autospec=TrexProfile)
546 traffic_generator.my_ports = [0, 1]
547 traffic_generator.priv_ports = [0]
548 traffic_generator.pub_ports = [1]
549 traffic_generator.client = \
550 mock.Mock(return_value=True)
551 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
552 r_f_c2544_profile.params = self.PROFILE
553 ixia_obj = mock.MagicMock()
554 r_f_c2544_profile.execute = mock.Mock()
555 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
556 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
557 r_f_c2544_profile.get_multiplier = mock.Mock()
558 r_f_c2544_profile.tmp_throughput = 0
559 r_f_c2544_profile.tmp_drop = 0
560 r_f_c2544_profile.full_profile = {}
562 for ifname in range(1):
563 name = "xe{}".format(ifname)
564 samples[name] = {"rx_throughput_fps": 20,
565 "tx_throughput_fps": 20,
566 "rx_throughput_mbps": 10,
567 "tx_throughput_mbps": 10,
574 r_f_c2544_profile.tmp_throughput = 0
575 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
576 traffic_generator, samples,
577 tol_min, tolerance, ixia_obj))
579 def test_get_multiplier(self):
580 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
581 r_f_c2544_profile.max_rate = 100
582 r_f_c2544_profile.min_rate = 100
583 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
585 def test_start_ixia_latency(self):
586 traffic_generator = mock.Mock(autospec=TrexProfile)
587 traffic_generator.my_ports = [0, 1]
588 traffic_generator.priv_ports = [0]
589 traffic_generator.pub_ports = [1]
590 traffic_generator.client = \
591 mock.Mock(return_value=True)
592 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
593 r_f_c2544_profile.max_rate = 100
594 r_f_c2544_profile.min_rate = 100
595 ixia_obj = mock.MagicMock()
596 r_f_c2544_profile._get_ixia_traffic_profile = \
597 mock.Mock(return_value={})
598 r_f_c2544_profile.full_profile = {}
599 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
602 r_f_c2544_profile.start_ixia_latency(traffic_generator,
606 if __name__ == '__main__':