1 # Copyright (c) 2016-2019 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.
21 from yardstick.network_services.traffic_profile import ixia_rfc2544
22 from yardstick.network_services.traffic_profile import trex_traffic_profile
25 class TestIXIARFC2544Profile(unittest.TestCase):
28 "schema": "isb:traffic_profile:0.1",
30 "description": "Fixed traffic profile to run UDP traffic",
32 "traffic_type": "FixedTraffic",
33 "frame_rate": 100, # pps
40 'description': 'Traffic profile to run RFC2544 latency',
43 'traffic_type': 'IXIARFC2544Profile',
45 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
57 'dstip4': '1.1.1.1-1.15.255.255',
60 'srcip4': '90.90.1.1-90.105.255.255',
66 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
78 'dstip4': '9.9.1.1-90.105.255.255',
81 'srcip4': '1.1.1.1-1.15.255.255',
87 'schema': 'isb:traffic_profile:0.1'}
89 def test_get_ixia_traffic_profile_error(self):
90 traffic_generator = mock.Mock(
91 autospec=trex_traffic_profile.TrexProfile)
92 traffic_generator.my_ports = [0, 1]
93 traffic_generator.uplink_ports = [-1]
94 traffic_generator.downlink_ports = [1]
95 traffic_generator.client = \
96 mock.Mock(return_value=True)
98 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
104 "dstmac": "00:00:00:00:00:03",
105 "framesPerSecond": True,
107 "srcmac": "00:00:00:00:00:01"
111 "dstip4": "152.16.40.20",
113 "srcip4": "152.16.100.20",
118 "dstip4": "152.16.40.20",
120 "srcip4": "152.16.100.20",
126 "dstip4": "152.16.100.20",
128 "srcip4": "152.16.40.20",
135 "traffic_type": "continuous"
137 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
143 "dstmac": "00:00:00:00:00:04",
144 "framesPerSecond": True,
146 "srcmac": "00:00:00:00:00:01"
151 "dstip4": "152.16.100.20",
153 "srcip4": "152.16.40.20",
159 "dstip4": "152.16.100.20",
161 "srcip4": "152.16.40.20",
167 "dstip4": "152.16.100.20",
169 "srcip4": "152.16.40.20",
176 "traffic_type": "continuous"
179 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
181 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
182 self.TRAFFIC_PROFILE)
183 r_f_c2544_profile.rate = 100
184 mac = {"src_mac_0": "00:00:00:00:00:01",
185 "src_mac_1": "00:00:00:00:00:02",
186 "src_mac_2": "00:00:00:00:00:02",
187 "dst_mac_0": "00:00:00:00:00:03",
188 "dst_mac_1": "00:00:00:00:00:04",
189 "dst_mac_2": "00:00:00:00:00:04"}
190 result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
191 self.assertIsNotNone(result)
193 def test_get_ixia_traffic_profile(self):
194 traffic_generator = mock.Mock(
195 autospec=trex_traffic_profile.TrexProfile)
196 traffic_generator.my_ports = [0, 1]
197 traffic_generator.uplink_ports = [-1]
198 traffic_generator.downlink_ports = [1]
199 traffic_generator.client = \
200 mock.Mock(return_value=True)
202 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
208 "dstmac": "00:00:00:00:00:03",
209 "framesPerSecond": True,
211 "srcmac": "00:00:00:00:00:01"
215 "dstip4": "152.16.40.20",
217 "srcip4": "152.16.100.20",
222 "dstip4": "152.16.40.20",
224 "srcip4": "152.16.100.20",
230 "dstip4": "152.16.100.20",
232 "srcip4": "152.16.40.20",
240 "traffic_type": "continuous"
242 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
248 "dstmac": "00:00:00:00:00:04",
249 "framesPerSecond": True,
251 "srcmac": "00:00:00:00:00:01"
256 "dstip4": "152.16.100.20",
258 "srcip4": "152.16.40.20",
263 "dstip4": "152.16.100.20",
265 "srcip4": "152.16.40.20",
270 "dstip4": "152.16.100.20",
272 "srcip4": "152.16.40.20",
280 "traffic_type": "continuous"
283 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
285 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
286 self.TRAFFIC_PROFILE)
287 r_f_c2544_profile.rate = 100
288 mac = {"src_mac_0": "00:00:00:00:00:01",
289 "src_mac_1": "00:00:00:00:00:02",
290 "src_mac_2": "00:00:00:00:00:02",
291 "dst_mac_0": "00:00:00:00:00:03",
292 "dst_mac_1": "00:00:00:00:00:04",
293 "dst_mac_2": "00:00:00:00:00:04"}
294 result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
295 self.assertIsNotNone(result)
297 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
298 def test_get_ixia_traffic_profile_v6(self, *args):
299 traffic_generator = mock.Mock(
300 autospec=trex_traffic_profile.TrexProfile)
301 traffic_generator.my_ports = [0, 1]
302 traffic_generator.uplink_ports = [-1]
303 traffic_generator.downlink_ports = [1]
304 traffic_generator.client = \
305 mock.Mock(return_value=True)
307 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
313 "dstmac": "00:00:00:00:00:03",
314 "framesPerSecond": True,
316 "srcmac": "00:00:00:00:00:01"
320 "dstip4": "152.16.40.20",
322 "srcip4": "152.16.100.20",
327 "dstip4": "152.16.40.20",
329 "srcip4": "152.16.100.20",
335 "dstip4": "152.16.100.20",
337 "srcip4": "152.16.40.20",
344 "traffic_type": "continuous"
346 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
352 "dstmac": "00:00:00:00:00:04",
353 "framesPerSecond": True,
355 "srcmac": "00:00:00:00:00:01"
360 "dstip4": "152.16.100.20",
362 "srcip4": "152.16.40.20",
368 "dstip4": "152.16.100.20",
370 "srcip4": "152.16.40.20",
376 "dstip4": "152.16.100.20",
378 "srcip4": "152.16.40.20",
385 "traffic_type": "continuous"
388 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
390 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
391 self.TRAFFIC_PROFILE)
392 r_f_c2544_profile.rate = 100
393 mac = {"src_mac_0": "00:00:00:00:00:01",
394 "src_mac_1": "00:00:00:00:00:02",
395 "src_mac_2": "00:00:00:00:00:02",
396 "dst_mac_0": "00:00:00:00:00:03",
397 "dst_mac_1": "00:00:00:00:00:04",
398 "dst_mac_2": "00:00:00:00:00:04"}
399 profile_data = {'description': 'Traffic profile to run RFC2544',
402 {'traffic_type': 'IXIARFC2544Profile',
404 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK:
406 {'outer_l2': {'framesize':
407 {'64B': '100', '1518B': '0',
408 '128B': '0', '1400B': '0',
409 '256B': '0', '373b': '0',
411 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
412 'proto': 'udp', 'count': '1',
413 'srcip4': '90.90.1.1-90.105.255.255',
414 'dscp': 0, 'ttl': 32},
415 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
416 'proto': 'udp', 'count': '1',
417 'srcip6': '90.90.1.1-90.105.255.255',
418 'dscp': 0, 'ttl': 32},
419 'outer_l4': {'srcport': '2001',
420 'dsrport': '1234'}}},
421 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {'ipv4':
422 {'outer_l2': {'framesize':
423 {'64B': '100', '1518B': '0',
424 '128B': '0', '1400B': '0',
425 '256B': '0', '373b': '0',
428 {'dstip4': '9.9.1.1-90.105.255.255',
429 'proto': 'udp', 'count': '1',
430 'srcip4': '1.1.1.1-1.15.255.255',
431 'dscp': 0, 'ttl': 32},
433 {'dstip6': '9.9.1.1-90.105.255.255',
434 'proto': 'udp', 'count': '1',
435 'srcip6': '1.1.1.1-1.15.255.255',
436 'dscp': 0, 'ttl': 32},
438 'outer_l4': {'dstport': '2001',
439 'srcport': '1234'}}},
440 'schema': 'isb:traffic_profile:0.1'}
441 result = r_f_c2544_profile._get_ixia_traffic_profile(profile_data, mac)
442 self.assertIsNotNone(result)
444 def test__init__(self):
445 t_profile_data = copy.deepcopy(self.TRAFFIC_PROFILE)
446 t_profile_data['traffic_profile']['frame_rate'] = 12345678
447 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(t_profile_data)
448 self.assertEqual(12345678, r_f_c2544_profile.rate)
450 def test__get_ip_and_mask_range(self):
451 ip_range = '1.2.0.2-1.2.255.254'
452 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
453 self.TRAFFIC_PROFILE)
454 ip, mask = r_f_c2544_profile._get_ip_and_mask(ip_range)
455 self.assertEqual('1.2.0.2', ip)
456 self.assertEqual(16, mask)
458 def test__get_ip_and_mask_single(self):
459 ip_range = '192.168.1.10'
460 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
461 self.TRAFFIC_PROFILE)
462 ip, mask = r_f_c2544_profile._get_ip_and_mask(ip_range)
463 self.assertEqual('192.168.1.10', ip)
464 self.assertIsNone(mask)
466 def test__get_fixed_and_mask_range(self):
468 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
469 self.TRAFFIC_PROFILE)
470 fixed, mask = r_f_c2544_profile._get_fixed_and_mask(fixed_mask)
471 self.assertEqual(8, fixed)
472 self.assertEqual(48, mask)
474 def test__get_fixed_and_mask_single(self):
476 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
477 self.TRAFFIC_PROFILE)
478 fixed, mask = r_f_c2544_profile._get_fixed_and_mask(fixed_mask)
479 self.assertEqual(1234, fixed)
480 self.assertEqual(0, mask)
482 def test__get_ixia_traffic_profile_default_args(self):
483 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
484 self.TRAFFIC_PROFILE)
487 result = r_f_c2544_profile._get_ixia_traffic_profile({})
488 self.assertDictEqual(result, expected)
490 @mock.patch.object(ixia_rfc2544.IXIARFC2544Profile,
491 '_update_traffic_tracking_options')
492 def test__ixia_traffic_generate(self, mock_upd_tracking_opts):
493 traffic_generator = mock.Mock(
494 autospec=trex_traffic_profile.TrexProfile)
495 traffic_generator.networks = {
497 "downlink_0": ["xe1"],
499 traffic_generator.client = \
500 mock.Mock(return_value=True)
501 traffic = {ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {'iload': 10},
502 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {'iload': 10}}
503 ixia_obj = mock.MagicMock()
504 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
505 self.TRAFFIC_PROFILE)
506 r_f_c2544_profile.rate = 100
507 result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj,
509 self.assertIsNone(result)
510 mock_upd_tracking_opts.assert_called_once_with(traffic_generator)
512 def test__update_traffic_tracking_options(self):
513 mock_traffic_gen = mock.Mock()
514 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
515 rfc2544_profile._update_traffic_tracking_options(mock_traffic_gen)
516 mock_traffic_gen.update_tracking_options.assert_called_once()
518 def test__get_framesize(self):
520 'uplink_0': {'outer_l2': {'framesize': {'64B': 100}}},
521 'downlink_0': {'outer_l2': {'framesize': {'64B': 100}}},
522 'uplink_1': {'outer_l2': {'framesize': {'64B': 100}}},
523 'downlink_1': {'outer_l2': {'framesize': {'64B': 100}}}
525 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
526 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
528 mock_get_tp.return_value = traffic_profile
529 result = rfc2544_profile._get_framesize()
530 self.assertEqual(result, '64B')
532 def test__get_framesize_IMIX_traffic(self):
534 'uplink_0': {'outer_l2': {'framesize': {'64B': 50,
536 'downlink_0': {'outer_l2': {'framesize': {'64B': 50,
538 'uplink_1': {'outer_l2': {'framesize': {'64B': 50,
540 'downlink_1': {'outer_l2': {'framesize': {'64B': 50,
543 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
544 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
546 mock_get_tp.return_value = traffic_profile
547 result = rfc2544_profile._get_framesize()
548 self.assertEqual(result, 'IMIX')
550 def test__get_framesize_zero_pkt_size_weight(self):
552 'uplink_0': {'outer_l2': {'framesize': {'64B': 0}}},
553 'downlink_0': {'outer_l2': {'framesize': {'64B': 0}}},
554 'uplink_1': {'outer_l2': {'framesize': {'64B': 0}}},
555 'downlink_1': {'outer_l2': {'framesize': {'64B': 0}}}
557 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
558 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
560 mock_get_tp.return_value = traffic_profile
561 result = rfc2544_profile._get_framesize()
562 self.assertEqual(result, '')
564 def test_execute_traffic_first_run(self):
565 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
566 rfc2544_profile.first_run = True
567 rfc2544_profile.rate = 50
568 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
570 mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \
572 mock_get_tp.return_value = 'fake_tprofile'
573 output = rfc2544_profile.execute_traffic(mock.ANY,
576 self.assertTrue(output)
577 self.assertFalse(rfc2544_profile.first_run)
578 self.assertEqual(50, rfc2544_profile.max_rate)
579 self.assertEqual(0, rfc2544_profile.min_rate)
580 mock_get_tp.assert_called_once()
581 mock_tgenerate.assert_called_once()
583 def test_execute_traffic_not_first_run(self):
584 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
585 rfc2544_profile.first_run = False
586 rfc2544_profile.max_rate = 70
587 rfc2544_profile.min_rate = 0
588 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
590 mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \
592 mock_get_tp.return_value = 'fake_tprofile'
593 rfc2544_profile.full_profile = mock.ANY
594 output = rfc2544_profile.execute_traffic(mock.ANY,
597 self.assertFalse(output)
598 self.assertEqual(35.0, rfc2544_profile.rate)
599 mock_get_tp.assert_called_once()
600 mock_tgenerate.assert_called_once()
602 def test_update_traffic_profile(self):
603 traffic_generator = mock.Mock(
604 autospec=trex_traffic_profile.TrexProfile)
605 traffic_generator.networks = {
606 "uplink_0": ["xe0"], # private, one value for intfs
607 "downlink_0": ["xe1", "xe2"], # public, two values for intfs
608 "downlink_1": ["xe3"], # not in TRAFFIC PROFILE
609 "tenant_0": ["xe4"], # not public or private
612 ports_expected = [8, 3, 5]
613 traffic_generator.vnfd_helper.port_num.side_effect = ports_expected
614 traffic_generator.client.return_value = True
616 traffic_profile = copy.deepcopy(self.TRAFFIC_PROFILE)
617 traffic_profile.update({
619 "downlink_0": ["xe1", "xe2"],
622 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(traffic_profile)
623 r_f_c2544_profile.full_profile = {}
624 r_f_c2544_profile.get_streams = mock.Mock()
627 r_f_c2544_profile.update_traffic_profile(traffic_generator))
628 self.assertEqual(r_f_c2544_profile.ports, ports_expected)
630 def test_get_drop_percentage_completed(self):
631 samples = {'iface_name_1':
632 {'in_packets': 1000, 'out_packets': 1000,
633 'in_bytes': 64000, 'out_bytes': 64000,
634 'Store-Forward_Avg_latency_ns': 20,
635 'Store-Forward_Min_latency_ns': 15,
636 'Store-Forward_Max_latency_ns': 25},
638 {'in_packets': 1005, 'out_packets': 1007,
639 'in_bytes': 64320, 'out_bytes': 64448,
640 'Store-Forward_Avg_latency_ns': 23,
641 'Store-Forward_Min_latency_ns': 13,
642 'Store-Forward_Max_latency_ns': 28}
644 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
645 rfc2544_profile.rate = 100.0
646 rfc2544_profile._get_next_rate = mock.Mock(return_value=100.0)
647 rfc2544_profile._get_framesize = mock.Mock(return_value='64B')
648 completed, samples = rfc2544_profile.get_drop_percentage(
649 samples, 0, 1, 4, 0.1)
650 self.assertTrue(completed)
651 self.assertEqual(66.9, samples['TxThroughput'])
652 self.assertEqual(66.833, samples['RxThroughput'])
653 self.assertEqual(0.099651, samples['DropPercentage'])
654 self.assertEqual(21.5, samples['latency_ns_avg'])
655 self.assertEqual(14.0, samples['latency_ns_min'])
656 self.assertEqual(26.5, samples['latency_ns_max'])
657 self.assertEqual(100.0, samples['Rate'])
658 self.assertEqual('64B', samples['PktSize'])
660 def test_get_drop_percentage_over_drop_percentage(self):
661 samples = {'iface_name_1':
662 {'in_packets': 1000, 'out_packets': 1000,
663 'in_bytes': 64000, 'out_bytes': 64000,
664 'Store-Forward_Avg_latency_ns': 20,
665 'Store-Forward_Min_latency_ns': 15,
666 'Store-Forward_Max_latency_ns': 25},
668 {'in_packets': 1005, 'out_packets': 1007,
669 'in_bytes': 64320, 'out_bytes': 64448,
670 'Store-Forward_Avg_latency_ns': 20,
671 'Store-Forward_Min_latency_ns': 15,
672 'Store-Forward_Max_latency_ns': 25}
674 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
675 rfc2544_profile.rate = 1000
676 rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0)
677 completed, samples = rfc2544_profile.get_drop_percentage(
678 samples, 0, 0.05, 4, 0.1)
679 self.assertFalse(completed)
680 self.assertEqual(66.9, samples['TxThroughput'])
681 self.assertEqual(66.833, samples['RxThroughput'])
682 self.assertEqual(0.099651, samples['DropPercentage'])
683 self.assertEqual(rfc2544_profile.rate, rfc2544_profile.max_rate)
685 def test_get_drop_percentage_under_drop_percentage(self):
686 samples = {'iface_name_1':
687 {'in_packets': 1000, 'out_packets': 1000,
688 'in_bytes': 64000, 'out_bytes': 64000,
689 'Store-Forward_Avg_latency_ns': 20,
690 'Store-Forward_Min_latency_ns': 15,
691 'Store-Forward_Max_latency_ns': 25},
693 {'in_packets': 1005, 'out_packets': 1007,
694 'in_bytes': 64320, 'out_bytes': 64448,
695 'Store-Forward_Avg_latency_ns': 20,
696 'Store-Forward_Min_latency_ns': 15,
697 'Store-Forward_Max_latency_ns': 25}
699 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
700 rfc2544_profile.rate = 1000
701 rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0)
702 completed, samples = rfc2544_profile.get_drop_percentage(
703 samples, 0.2, 1, 4, 0.1)
704 self.assertFalse(completed)
705 self.assertEqual(66.9, samples['TxThroughput'])
706 self.assertEqual(66.833, samples['RxThroughput'])
707 self.assertEqual(0.099651, samples['DropPercentage'])
708 self.assertEqual(rfc2544_profile.rate, rfc2544_profile.min_rate)
710 @mock.patch.object(ixia_rfc2544.LOG, 'info')
711 def test_get_drop_percentage_not_flow(self, *args):
712 samples = {'iface_name_1':
713 {'in_packets': 1000, 'out_packets': 0,
714 'in_bytes': 64000, 'out_bytes': 0,
715 'Store-Forward_Avg_latency_ns': 20,
716 'Store-Forward_Min_latency_ns': 15,
717 'Store-Forward_Max_latency_ns': 25},
719 {'in_packets': 1005, 'out_packets': 0,
720 'in_bytes': 64320, 'out_bytes': 0,
721 'Store-Forward_Avg_latency_ns': 20,
722 'Store-Forward_Min_latency_ns': 15,
723 'Store-Forward_Max_latency_ns': 25}
725 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
726 rfc2544_profile.rate = 1000
727 rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0)
728 completed, samples = rfc2544_profile.get_drop_percentage(
729 samples, 0.2, 1, 4, 0.1)
730 self.assertFalse(completed)
731 self.assertEqual(0.0, samples['TxThroughput'])
732 self.assertEqual(66.833, samples['RxThroughput'])
733 self.assertEqual(100, samples['DropPercentage'])
734 self.assertEqual(rfc2544_profile.rate, rfc2544_profile.max_rate)
736 def test_get_drop_percentage_first_run(self):
737 samples = {'iface_name_1':
738 {'in_packets': 1000, 'out_packets': 1000,
739 'in_bytes': 64000, 'out_bytes': 64000,
740 'Store-Forward_Avg_latency_ns': 20,
741 'Store-Forward_Min_latency_ns': 15,
742 'Store-Forward_Max_latency_ns': 25},
744 {'in_packets': 1005, 'out_packets': 1007,
745 'in_bytes': 64320, 'out_bytes': 64448,
746 'Store-Forward_Avg_latency_ns': 20,
747 'Store-Forward_Min_latency_ns': 15,
748 'Store-Forward_Max_latency_ns': 25}
750 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
751 rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0)
752 completed, samples = rfc2544_profile.get_drop_percentage(
753 samples, 0, 1, 4, 0.1, first_run=True)
754 self.assertTrue(completed)
755 self.assertEqual(66.9, samples['TxThroughput'])
756 self.assertEqual(66.833, samples['RxThroughput'])
757 self.assertEqual(0.099651, samples['DropPercentage'])
758 self.assertEqual(33.45, rfc2544_profile.rate)
760 def test_get_drop_percentage_resolution(self):
761 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
762 rfc2544_profile._get_next_rate = mock.Mock(return_value=0.1)
763 samples = {'iface_name_1':
764 {'in_packets': 1000, 'out_packets': 1000,
765 'in_bytes': 64000, 'out_bytes': 64000,
766 'Store-Forward_Avg_latency_ns': 20,
767 'Store-Forward_Min_latency_ns': 15,
768 'Store-Forward_Max_latency_ns': 25},
770 {'in_packets': 1005, 'out_packets': 1007,
771 'in_bytes': 64320, 'out_bytes': 64448,
772 'Store-Forward_Avg_latency_ns': 20,
773 'Store-Forward_Min_latency_ns': 15,
774 'Store-Forward_Max_latency_ns': 25}
776 rfc2544_profile.rate = 0.19
777 completed, _ = rfc2544_profile.get_drop_percentage(
778 samples, 0, 0.05, 4, 0.1)
779 self.assertTrue(completed)
781 samples = {'iface_name_1':
782 {'in_packets': 1000, 'out_packets': 1000,
783 'in_bytes': 64000, 'out_bytes': 64000,
784 'Store-Forward_Avg_latency_ns': 20,
785 'Store-Forward_Min_latency_ns': 15,
786 'Store-Forward_Max_latency_ns': 25},
788 {'in_packets': 1005, 'out_packets': 1007,
789 'in_bytes': 64320, 'out_bytes': 64448,
790 'Store-Forward_Avg_latency_ns': 20,
791 'Store-Forward_Min_latency_ns': 15,
792 'Store-Forward_Max_latency_ns': 25}
794 rfc2544_profile.rate = 0.5
795 completed, _ = rfc2544_profile.get_drop_percentage(
796 samples, 0, 0.05, 4, 0.1)
797 self.assertFalse(completed)
800 class TestIXIARFC2544PppoeScenarioProfile(unittest.TestCase):
803 "schema": "nsb:traffic_profile:0.1",
805 "description": "Fixed traffic profile to run UDP traffic",
807 "traffic_type": "FixedTraffic",
809 'uplink_0': {'ipv4': {'port': 'xe0', 'id': 1}},
810 'downlink_0': {'ipv4': {'port': 'xe2', 'id': 2}},
811 'uplink_1': {'ipv4': {'port': 'xe1', 'id': 3}},
812 'downlink_1': {'ipv4': {'port': 'xe2', 'id': 4}}
816 self.ixia_tp = ixia_rfc2544.IXIARFC2544PppoeScenarioProfile(
817 self.TRAFFIC_PROFILE)
818 self.ixia_tp.rate = 100.0
819 self.ixia_tp._get_next_rate = mock.Mock(return_value=50.0)
821 def test___init__(self):
822 self.assertIsInstance(self.ixia_tp.full_profile,
823 collections.OrderedDict)
825 def test__get_flow_groups_params(self):
826 expected_tp = collections.OrderedDict([
827 ('uplink_0', {'ipv4': {'id': 1, 'port': 'xe0'}}),
828 ('downlink_0', {'ipv4': {'id': 2, 'port': 'xe2'}}),
829 ('uplink_1', {'ipv4': {'id': 3, 'port': 'xe1'}}),
830 ('downlink_1', {'ipv4': {'id': 4, 'port': 'xe2'}})])
832 self.ixia_tp._get_flow_groups_params()
833 self.assertDictEqual(self.ixia_tp.full_profile, expected_tp)
835 @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
836 '_get_flow_groups_params')
837 def test_update_traffic_profile(self, mock_get_flow_groups_params):
840 'downlink_0': 'data2',
842 'downlink_1': 'data4'
844 ports = ['xe0', 'xe1', 'xe2', 'xe3']
845 mock_traffic_gen = mock.Mock()
846 mock_traffic_gen.networks = networks
847 mock_traffic_gen.vnfd_helper.port_num.side_effect = ports
848 self.ixia_tp.update_traffic_profile(mock_traffic_gen)
849 mock_get_flow_groups_params.assert_called_once()
850 self.assertEqual(self.ixia_tp.ports, ports)
852 def test__get_prio_flows_drop_percentage(self):
858 'Store-Forward_Avg_latency_ns': 10,
859 'Store-Forward_Min_latency_ns': 10,
860 'Store-Forward_Max_latency_ns': 10}}
862 result = self.ixia_tp._get_prio_flows_drop_percentage(input_stats)
863 self.assertIsNotNone(result['0'].get('DropPercentage'))
864 self.assertEqual(result['0'].get('DropPercentage'), 50.0)
866 def test__get_prio_flows_drop_percentage_traffic_not_flowing(self):
871 'Store-Forward_Avg_latency_ns': 0,
872 'Store-Forward_Min_latency_ns': 0,
873 'Store-Forward_Max_latency_ns': 0}}
875 result = self.ixia_tp._get_prio_flows_drop_percentage(input_stats)
876 self.assertIsNotNone(result['0'].get('DropPercentage'))
877 self.assertEqual(result['0'].get('DropPercentage'), 100)
879 def test__get_summary_pppoe_subs_counters(self):
885 'sessions_not_started': 0,
886 'sessions_total': 4},
891 'sessions_not_started': 0,
898 'sessions_not_started': 0,
902 res = self.ixia_tp._get_summary_pppoe_subs_counters(input_stats)
903 self.assertDictEqual(res, expected_stats)
905 @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
906 '_get_prio_flows_drop_percentage')
907 @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
908 '_get_summary_pppoe_subs_counters')
909 def test_get_drop_percentage(self, mock_get_pppoe_subs,
910 mock_sum_prio_drop_rate):
918 'Store-Forward_Avg_latency_ns': 10,
919 'Store-Forward_Min_latency_ns': 10,
920 'Store-Forward_Max_latency_ns': 10}},
926 'Store-Forward_Avg_latency_ns': 10,
927 'Store-Forward_Min_latency_ns': 10,
928 'Store-Forward_Max_latency_ns': 10}}
930 mock_get_pppoe_subs.return_value = {'sessions_up': 1}
931 mock_sum_prio_drop_rate.return_value = {'0': {'DropPercentage': 0.0}}
933 self.ixia_tp._get_framesize = mock.Mock(return_value='64B')
934 status, res = self.ixia_tp.get_drop_percentage(
935 samples, tol_min=0.0, tolerance=0.0001, precision=0,
936 resolution=0.1, first_run=True)
937 self.assertIsNotNone(res.get('DropPercentage'))
938 self.assertIsNotNone(res.get('priority'))
939 self.assertIsNotNone(res.get('sessions_up'))
940 self.assertEqual(res['DropPercentage'], 0.0)
941 self.assertEqual(res['Rate'], 100.0)
942 self.assertEqual(res['PktSize'], '64B')
943 self.assertTrue(status)
944 mock_sum_prio_drop_rate.assert_called_once()
945 mock_get_pppoe_subs.assert_called_once()
947 @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
948 '_get_prio_flows_drop_percentage')
949 @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
950 '_get_summary_pppoe_subs_counters')
951 def test_get_drop_percentage_failed_status(self, mock_get_pppoe_subs,
952 mock_sum_prio_drop_rate):
960 'Store-Forward_Avg_latency_ns': 10,
961 'Store-Forward_Min_latency_ns': 10,
962 'Store-Forward_Max_latency_ns': 10}},
968 'Store-Forward_Avg_latency_ns': 10,
969 'Store-Forward_Min_latency_ns': 10,
970 'Store-Forward_Max_latency_ns': 10}}
972 mock_get_pppoe_subs.return_value = {'sessions_up': 1}
973 mock_sum_prio_drop_rate.return_value = {'0': {'DropPercentage': 0.0}}
975 status, res = self.ixia_tp.get_drop_percentage(
976 samples, tol_min=0.0, tolerance=0.0001, precision=0,
977 resolution=0.1, first_run=True)
978 self.assertIsNotNone(res.get('DropPercentage'))
979 self.assertIsNotNone(res.get('priority'))
980 self.assertIsNotNone(res.get('sessions_up'))
981 self.assertEqual(res['DropPercentage'], 10.0)
982 self.assertFalse(status)
983 mock_sum_prio_drop_rate.assert_called_once()
984 mock_get_pppoe_subs.assert_called_once()
986 @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
987 '_get_prio_flows_drop_percentage')
988 @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
989 '_get_summary_pppoe_subs_counters')
990 def test_get_drop_percentage_priority_flow_check(self, mock_get_pppoe_subs,
991 mock_sum_prio_drop_rate):
999 'Store-Forward_Avg_latency_ns': 10,
1000 'Store-Forward_Min_latency_ns': 10,
1001 'Store-Forward_Max_latency_ns': 10}},
1007 'Store-Forward_Avg_latency_ns': 10,
1008 'Store-Forward_Min_latency_ns': 10,
1009 'Store-Forward_Max_latency_ns': 10
1012 mock_get_pppoe_subs.return_value = {'sessions_up': 1}
1013 mock_sum_prio_drop_rate.return_value = {'0': {'DropPercentage': 0.0}}
1015 tc_rfc2544_opts = {'priority': '0',
1016 'allowed_drop_rate': '0.0001 - 0.0001'}
1017 status, res = self.ixia_tp.get_drop_percentage(
1018 samples, tol_min=15.0000, tolerance=15.0001, precision=0,
1019 resolution=0.1, first_run=True, tc_rfc2544_opts=tc_rfc2544_opts)
1020 self.assertIsNotNone(res.get('DropPercentage'))
1021 self.assertIsNotNone(res.get('priority'))
1022 self.assertIsNotNone(res.get('sessions_up'))
1023 self.assertTrue(status)
1024 mock_sum_prio_drop_rate.assert_called_once()
1025 mock_get_pppoe_subs.assert_called_once()