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.
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 def test__ixia_traffic_generate(self):
491 traffic_generator = mock.Mock(
492 autospec=trex_traffic_profile.TrexProfile)
493 traffic_generator.networks = {
495 "downlink_0": ["xe1"],
497 traffic_generator.client = \
498 mock.Mock(return_value=True)
499 traffic = {ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {'iload': 10},
500 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {'iload': 10}}
501 ixia_obj = mock.MagicMock()
502 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
503 self.TRAFFIC_PROFILE)
504 r_f_c2544_profile.rate = 100
505 result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj)
506 self.assertIsNone(result)
508 def test_execute_traffic_first_run(self):
509 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
510 rfc2544_profile.first_run = True
511 rfc2544_profile.rate = 50
512 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
514 mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \
516 mock_get_tp.return_value = 'fake_tprofile'
517 output = rfc2544_profile.execute_traffic(mock.ANY,
520 self.assertTrue(output)
521 self.assertFalse(rfc2544_profile.first_run)
522 self.assertEqual(50, rfc2544_profile.max_rate)
523 self.assertEqual(0, rfc2544_profile.min_rate)
524 mock_get_tp.assert_called_once()
525 mock_tgenerate.assert_called_once()
527 def test_execute_traffic_not_first_run(self):
528 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
529 rfc2544_profile.first_run = False
530 rfc2544_profile.max_rate = 70
531 rfc2544_profile.min_rate = 0
532 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
534 mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \
536 mock_get_tp.return_value = 'fake_tprofile'
537 rfc2544_profile.full_profile = mock.ANY
538 output = rfc2544_profile.execute_traffic(mock.ANY,
541 self.assertFalse(output)
542 self.assertEqual(35.0, rfc2544_profile.rate)
543 mock_get_tp.assert_called_once()
544 mock_tgenerate.assert_called_once()
546 def test_update_traffic_profile(self):
547 traffic_generator = mock.Mock(
548 autospec=trex_traffic_profile.TrexProfile)
549 traffic_generator.networks = {
550 "uplink_0": ["xe0"], # private, one value for intfs
551 "downlink_0": ["xe1", "xe2"], # public, two values for intfs
552 "downlink_1": ["xe3"], # not in TRAFFIC PROFILE
553 "tenant_0": ["xe4"], # not public or private
556 ports_expected = [8, 3, 5]
557 traffic_generator.vnfd_helper.port_num.side_effect = ports_expected
558 traffic_generator.client.return_value = True
560 traffic_profile = copy.deepcopy(self.TRAFFIC_PROFILE)
561 traffic_profile.update({
563 "downlink_0": ["xe1", "xe2"],
566 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(traffic_profile)
567 r_f_c2544_profile.full_profile = {}
568 r_f_c2544_profile.get_streams = mock.Mock()
571 r_f_c2544_profile.update_traffic_profile(traffic_generator))
572 self.assertEqual(r_f_c2544_profile.ports, ports_expected)
574 def test_get_drop_percentage_completed(self):
575 samples = {'iface_name_1':
576 {'in_packets': 1000, 'out_packets': 1000,
577 'Store-Forward_Avg_latency_ns': 20,
578 'Store-Forward_Min_latency_ns': 15,
579 'Store-Forward_Max_latency_ns': 25},
581 {'in_packets': 1005, 'out_packets': 1007,
582 'Store-Forward_Avg_latency_ns': 23,
583 'Store-Forward_Min_latency_ns': 13,
584 'Store-Forward_Max_latency_ns': 28}
586 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
587 completed, samples = rfc2544_profile.get_drop_percentage(
589 self.assertTrue(completed)
590 self.assertEqual(66.9, samples['TxThroughput'])
591 self.assertEqual(66.833, samples['RxThroughput'])
592 self.assertEqual(0.099651, samples['DropPercentage'])
593 self.assertEqual(21.5, samples['latency_ns_avg'])
594 self.assertEqual(14.0, samples['latency_ns_min'])
595 self.assertEqual(26.5, samples['latency_ns_max'])
597 def test_get_drop_percentage_over_drop_percentage(self):
598 samples = {'iface_name_1':
599 {'in_packets': 1000, 'out_packets': 1000,
600 'Store-Forward_Avg_latency_ns': 20,
601 'Store-Forward_Min_latency_ns': 15,
602 'Store-Forward_Max_latency_ns': 25},
604 {'in_packets': 1005, 'out_packets': 1007,
605 'Store-Forward_Avg_latency_ns': 20,
606 'Store-Forward_Min_latency_ns': 15,
607 'Store-Forward_Max_latency_ns': 25}
609 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
610 rfc2544_profile.rate = 1000
611 completed, samples = rfc2544_profile.get_drop_percentage(
613 self.assertFalse(completed)
614 self.assertEqual(66.9, samples['TxThroughput'])
615 self.assertEqual(66.833, samples['RxThroughput'])
616 self.assertEqual(0.099651, samples['DropPercentage'])
617 self.assertEqual(rfc2544_profile.rate, rfc2544_profile.max_rate)
619 def test_get_drop_percentage_under_drop_percentage(self):
620 samples = {'iface_name_1':
621 {'in_packets': 1000, 'out_packets': 1000,
622 'Store-Forward_Avg_latency_ns': 20,
623 'Store-Forward_Min_latency_ns': 15,
624 'Store-Forward_Max_latency_ns': 25},
626 {'in_packets': 1005, 'out_packets': 1007,
627 'Store-Forward_Avg_latency_ns': 20,
628 'Store-Forward_Min_latency_ns': 15,
629 'Store-Forward_Max_latency_ns': 25}
631 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
632 rfc2544_profile.rate = 1000
633 completed, samples = rfc2544_profile.get_drop_percentage(
635 self.assertFalse(completed)
636 self.assertEqual(66.9, samples['TxThroughput'])
637 self.assertEqual(66.833, samples['RxThroughput'])
638 self.assertEqual(0.099651, samples['DropPercentage'])
639 self.assertEqual(rfc2544_profile.rate, rfc2544_profile.min_rate)
641 @mock.patch.object(ixia_rfc2544.LOG, 'info')
642 def test_get_drop_percentage_not_flow(self, *args):
643 samples = {'iface_name_1':
644 {'in_packets': 1000, 'out_packets': 0,
645 'Store-Forward_Avg_latency_ns': 20,
646 'Store-Forward_Min_latency_ns': 15,
647 'Store-Forward_Max_latency_ns': 25},
649 {'in_packets': 1005, 'out_packets': 0,
650 'Store-Forward_Avg_latency_ns': 20,
651 'Store-Forward_Min_latency_ns': 15,
652 'Store-Forward_Max_latency_ns': 25}
654 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
655 rfc2544_profile.rate = 1000
656 completed, samples = rfc2544_profile.get_drop_percentage(
658 self.assertFalse(completed)
659 self.assertEqual(0.0, samples['TxThroughput'])
660 self.assertEqual(66.833, samples['RxThroughput'])
661 self.assertEqual(100, samples['DropPercentage'])
662 self.assertEqual(rfc2544_profile.rate, rfc2544_profile.max_rate)
664 def test_get_drop_percentage_first_run(self):
665 samples = {'iface_name_1':
666 {'in_packets': 1000, 'out_packets': 1000,
667 'Store-Forward_Avg_latency_ns': 20,
668 'Store-Forward_Min_latency_ns': 15,
669 'Store-Forward_Max_latency_ns': 25},
671 {'in_packets': 1005, 'out_packets': 1007,
672 'Store-Forward_Avg_latency_ns': 20,
673 'Store-Forward_Min_latency_ns': 15,
674 'Store-Forward_Max_latency_ns': 25}
676 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
677 completed, samples = rfc2544_profile.get_drop_percentage(
678 samples, 0, 1, 4, first_run=True)
679 self.assertTrue(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(33.45, rfc2544_profile.rate)
686 class TestIXIARFC2544PppoeScenarioProfile(unittest.TestCase):
689 "schema": "nsb:traffic_profile:0.1",
691 "description": "Fixed traffic profile to run UDP traffic",
693 "traffic_type": "FixedTraffic",
695 'uplink_0': {'ipv4': {'port': 'xe0', 'id': 1}},
696 'downlink_0': {'ipv4': {'port': 'xe2', 'id': 2}},
697 'uplink_1': {'ipv4': {'port': 'xe1', 'id': 3}},
698 'downlink_1': {'ipv4': {'port': 'xe2', 'id': 4}}
702 self.ixia_tp = ixia_rfc2544.IXIARFC2544PppoeScenarioProfile(
703 self.TRAFFIC_PROFILE)
705 def test___init__(self):
706 self.assertIsInstance(self.ixia_tp.full_profile,
707 collections.OrderedDict)
709 def test__get_flow_groups_params(self):
710 expected_tp = collections.OrderedDict([
711 ('uplink_0', {'ipv4': {'id': 1, 'port': 'xe0'}}),
712 ('downlink_0', {'ipv4': {'id': 2, 'port': 'xe2'}}),
713 ('uplink_1', {'ipv4': {'id': 3, 'port': 'xe1'}}),
714 ('downlink_1', {'ipv4': {'id': 4, 'port': 'xe2'}})])
716 self.ixia_tp._get_flow_groups_params()
717 self.assertDictEqual(self.ixia_tp.full_profile, expected_tp)