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.
20 from yardstick.network_services.traffic_profile import ixia_rfc2544
21 from yardstick.network_services.traffic_profile import trex_traffic_profile
24 class TestIXIARFC2544Profile(unittest.TestCase):
27 "schema": "isb:traffic_profile:0.1",
29 "description": "Fixed traffic profile to run UDP traffic",
31 "traffic_type": "FixedTraffic",
32 "frame_rate": 100, # pps
39 'description': 'Traffic profile to run RFC2544 latency',
42 'traffic_type': 'IXIARFC2544Profile',
44 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
56 'dstip4': '1.1.1.1-1.15.255.255',
59 'srcip4': '90.90.1.1-90.105.255.255',
65 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
77 'dstip4': '9.9.1.1-90.105.255.255',
80 'srcip4': '1.1.1.1-1.15.255.255',
86 'schema': 'isb:traffic_profile:0.1'}
88 def test_get_ixia_traffic_profile_error(self):
89 traffic_generator = mock.Mock(
90 autospec=trex_traffic_profile.TrexProfile)
91 traffic_generator.my_ports = [0, 1]
92 traffic_generator.uplink_ports = [-1]
93 traffic_generator.downlink_ports = [1]
94 traffic_generator.client = \
95 mock.Mock(return_value=True)
97 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
103 "dstmac": "00:00:00:00:00:03",
104 "framesPerSecond": True,
106 "srcmac": "00:00:00:00:00:01"
110 "dstip4": "152.16.40.20",
112 "srcip4": "152.16.100.20",
117 "dstip4": "152.16.40.20",
119 "srcip4": "152.16.100.20",
125 "dstip4": "152.16.100.20",
127 "srcip4": "152.16.40.20",
134 "traffic_type": "continuous"
136 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
142 "dstmac": "00:00:00:00:00:04",
143 "framesPerSecond": True,
145 "srcmac": "00:00:00:00:00:01"
150 "dstip4": "152.16.100.20",
152 "srcip4": "152.16.40.20",
158 "dstip4": "152.16.100.20",
160 "srcip4": "152.16.40.20",
166 "dstip4": "152.16.100.20",
168 "srcip4": "152.16.40.20",
175 "traffic_type": "continuous"
178 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
180 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
181 self.TRAFFIC_PROFILE)
182 r_f_c2544_profile.rate = 100
183 mac = {"src_mac_0": "00:00:00:00:00:01",
184 "src_mac_1": "00:00:00:00:00:02",
185 "src_mac_2": "00:00:00:00:00:02",
186 "dst_mac_0": "00:00:00:00:00:03",
187 "dst_mac_1": "00:00:00:00:00:04",
188 "dst_mac_2": "00:00:00:00:00:04"}
189 result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
190 self.assertIsNotNone(result)
192 def test_get_ixia_traffic_profile(self):
193 traffic_generator = mock.Mock(
194 autospec=trex_traffic_profile.TrexProfile)
195 traffic_generator.my_ports = [0, 1]
196 traffic_generator.uplink_ports = [-1]
197 traffic_generator.downlink_ports = [1]
198 traffic_generator.client = \
199 mock.Mock(return_value=True)
201 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
207 "dstmac": "00:00:00:00:00:03",
208 "framesPerSecond": True,
210 "srcmac": "00:00:00:00:00:01"
214 "dstip4": "152.16.40.20",
216 "srcip4": "152.16.100.20",
221 "dstip4": "152.16.40.20",
223 "srcip4": "152.16.100.20",
229 "dstip4": "152.16.100.20",
231 "srcip4": "152.16.40.20",
239 "traffic_type": "continuous"
241 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
247 "dstmac": "00:00:00:00:00:04",
248 "framesPerSecond": True,
250 "srcmac": "00:00:00:00:00:01"
255 "dstip4": "152.16.100.20",
257 "srcip4": "152.16.40.20",
262 "dstip4": "152.16.100.20",
264 "srcip4": "152.16.40.20",
269 "dstip4": "152.16.100.20",
271 "srcip4": "152.16.40.20",
279 "traffic_type": "continuous"
282 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
284 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
285 self.TRAFFIC_PROFILE)
286 r_f_c2544_profile.rate = 100
287 mac = {"src_mac_0": "00:00:00:00:00:01",
288 "src_mac_1": "00:00:00:00:00:02",
289 "src_mac_2": "00:00:00:00:00:02",
290 "dst_mac_0": "00:00:00:00:00:03",
291 "dst_mac_1": "00:00:00:00:00:04",
292 "dst_mac_2": "00:00:00:00:00:04"}
293 result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
294 self.assertIsNotNone(result)
296 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
297 def test_get_ixia_traffic_profile_v6(self, *args):
298 traffic_generator = mock.Mock(
299 autospec=trex_traffic_profile.TrexProfile)
300 traffic_generator.my_ports = [0, 1]
301 traffic_generator.uplink_ports = [-1]
302 traffic_generator.downlink_ports = [1]
303 traffic_generator.client = \
304 mock.Mock(return_value=True)
306 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
312 "dstmac": "00:00:00:00:00:03",
313 "framesPerSecond": True,
315 "srcmac": "00:00:00:00:00:01"
319 "dstip4": "152.16.40.20",
321 "srcip4": "152.16.100.20",
326 "dstip4": "152.16.40.20",
328 "srcip4": "152.16.100.20",
334 "dstip4": "152.16.100.20",
336 "srcip4": "152.16.40.20",
343 "traffic_type": "continuous"
345 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
351 "dstmac": "00:00:00:00:00:04",
352 "framesPerSecond": True,
354 "srcmac": "00:00:00:00:00:01"
359 "dstip4": "152.16.100.20",
361 "srcip4": "152.16.40.20",
367 "dstip4": "152.16.100.20",
369 "srcip4": "152.16.40.20",
375 "dstip4": "152.16.100.20",
377 "srcip4": "152.16.40.20",
384 "traffic_type": "continuous"
387 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
389 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
390 self.TRAFFIC_PROFILE)
391 r_f_c2544_profile.rate = 100
392 mac = {"src_mac_0": "00:00:00:00:00:01",
393 "src_mac_1": "00:00:00:00:00:02",
394 "src_mac_2": "00:00:00:00:00:02",
395 "dst_mac_0": "00:00:00:00:00:03",
396 "dst_mac_1": "00:00:00:00:00:04",
397 "dst_mac_2": "00:00:00:00:00:04"}
398 profile_data = {'description': 'Traffic profile to run RFC2544',
401 {'traffic_type': 'IXIARFC2544Profile',
403 ixia_rfc2544.IXIARFC2544Profile.DOWNLINK:
405 {'outer_l2': {'framesize':
406 {'64B': '100', '1518B': '0',
407 '128B': '0', '1400B': '0',
408 '256B': '0', '373b': '0',
410 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
411 'proto': 'udp', 'count': '1',
412 'srcip4': '90.90.1.1-90.105.255.255',
413 'dscp': 0, 'ttl': 32},
414 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
415 'proto': 'udp', 'count': '1',
416 'srcip6': '90.90.1.1-90.105.255.255',
417 'dscp': 0, 'ttl': 32},
418 'outer_l4': {'srcport': '2001',
419 'dsrport': '1234'}}},
420 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {'ipv4':
421 {'outer_l2': {'framesize':
422 {'64B': '100', '1518B': '0',
423 '128B': '0', '1400B': '0',
424 '256B': '0', '373b': '0',
427 {'dstip4': '9.9.1.1-90.105.255.255',
428 'proto': 'udp', 'count': '1',
429 'srcip4': '1.1.1.1-1.15.255.255',
430 'dscp': 0, 'ttl': 32},
432 {'dstip6': '9.9.1.1-90.105.255.255',
433 'proto': 'udp', 'count': '1',
434 'srcip6': '1.1.1.1-1.15.255.255',
435 'dscp': 0, 'ttl': 32},
437 'outer_l4': {'dstport': '2001',
438 'srcport': '1234'}}},
439 'schema': 'isb:traffic_profile:0.1'}
440 result = r_f_c2544_profile._get_ixia_traffic_profile(profile_data, mac)
441 self.assertIsNotNone(result)
443 def test__init__(self):
444 t_profile_data = copy.deepcopy(self.TRAFFIC_PROFILE)
445 t_profile_data['traffic_profile']['frame_rate'] = 12345678
446 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(t_profile_data)
447 self.assertEqual(12345678, r_f_c2544_profile.rate)
449 def test__get_ixia_traffic_profile_default_args(self):
450 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
451 self.TRAFFIC_PROFILE)
454 result = r_f_c2544_profile._get_ixia_traffic_profile({})
455 self.assertDictEqual(result, expected)
457 def test__ixia_traffic_generate(self):
458 traffic_generator = mock.Mock(
459 autospec=trex_traffic_profile.TrexProfile)
460 traffic_generator.networks = {
462 "downlink_0": ["xe1"],
464 traffic_generator.client = \
465 mock.Mock(return_value=True)
466 traffic = {ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {'iload': 10},
467 ixia_rfc2544.IXIARFC2544Profile.UPLINK: {'iload': 10}}
468 ixia_obj = mock.MagicMock()
469 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
470 self.TRAFFIC_PROFILE)
471 r_f_c2544_profile.rate = 100
472 result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj)
473 self.assertIsNone(result)
475 def test_execute_traffic_first_run(self):
476 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
477 rfc2544_profile.first_run = True
478 rfc2544_profile.rate = 50
479 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
481 mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \
483 mock.patch.object(rfc2544_profile, 'update_traffic_profile') \
485 mock_get_tp.return_value = 'fake_tprofile'
486 output = rfc2544_profile.execute_traffic(mock.ANY,
489 self.assertTrue(output)
490 self.assertFalse(rfc2544_profile.first_run)
491 self.assertEqual(50, rfc2544_profile.max_rate)
492 self.assertEqual(0, rfc2544_profile.min_rate)
493 mock_get_tp.assert_called_once()
494 mock_tgenerate.assert_called_once()
495 mock_update_tp.assert_called_once()
497 def test_execute_traffic_not_first_run(self):
498 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
499 rfc2544_profile.first_run = False
500 rfc2544_profile.max_rate = 70
501 rfc2544_profile.min_rate = 0
502 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
504 mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \
506 mock_get_tp.return_value = 'fake_tprofile'
507 rfc2544_profile.full_profile = mock.ANY
508 output = rfc2544_profile.execute_traffic(mock.ANY,
511 self.assertFalse(output)
512 self.assertEqual(35.0, rfc2544_profile.rate)
513 mock_get_tp.assert_called_once()
514 mock_tgenerate.assert_called_once()
516 def test_update_traffic_profile(self):
517 traffic_generator = mock.Mock(
518 autospec=trex_traffic_profile.TrexProfile)
519 traffic_generator.networks = {
520 "uplink_0": ["xe0"], # private, one value for intfs
521 "downlink_0": ["xe1", "xe2"], # public, two values for intfs
522 "downlink_1": ["xe3"], # not in TRAFFIC PROFILE
523 "tenant_0": ["xe4"], # not public or private
526 ports_expected = [8, 3, 5]
527 traffic_generator.vnfd_helper.port_num.side_effect = ports_expected
528 traffic_generator.client.return_value = True
530 traffic_profile = copy.deepcopy(self.TRAFFIC_PROFILE)
531 traffic_profile.update({
533 "downlink_0": ["xe1", "xe2"],
536 r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(traffic_profile)
537 r_f_c2544_profile.full_profile = {}
538 r_f_c2544_profile.get_streams = mock.Mock()
541 r_f_c2544_profile.update_traffic_profile(traffic_generator))
542 self.assertEqual(r_f_c2544_profile.ports, ports_expected)
544 def test_get_drop_percentage_completed(self):
545 samples = {'iface_name_1':
546 {'RxThroughput': 10, 'TxThroughput': 10,
547 'in_packets': 1000, 'out_packets': 1000},
549 {'RxThroughput': 11, 'TxThroughput': 13,
550 'in_packets': 1005, 'out_packets': 1007}
552 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
553 completed, samples = rfc2544_profile.get_drop_percentage(samples, 0, 1)
554 self.assertTrue(completed)
555 self.assertEqual(23.0, samples['TxThroughput'])
556 self.assertEqual(21.0, samples['RxThroughput'])
557 self.assertEqual(0.1, samples['DropPercentage'])
559 def test_get_drop_percentage_over_drop_percentage(self):
560 samples = {'iface_name_1':
561 {'RxThroughput': 10, 'TxThroughput': 10,
562 'in_packets': 1000, 'out_packets': 1000},
564 {'RxThroughput': 11, 'TxThroughput': 13,
565 'in_packets': 1005, 'out_packets': 1007}
567 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
568 rfc2544_profile.rate = 1000
569 completed, samples = rfc2544_profile.get_drop_percentage(
571 self.assertFalse(completed)
572 self.assertEqual(23.0, samples['TxThroughput'])
573 self.assertEqual(21.0, samples['RxThroughput'])
574 self.assertEqual(0.1, samples['DropPercentage'])
575 self.assertEqual(rfc2544_profile.rate, rfc2544_profile.max_rate)
577 def test_get_drop_percentage_under_drop_percentage(self):
578 samples = {'iface_name_1':
579 {'RxThroughput': 10, 'TxThroughput': 10,
580 'in_packets': 1000, 'out_packets': 1000},
582 {'RxThroughput': 11, 'TxThroughput': 13,
583 'in_packets': 1005, 'out_packets': 1007}
585 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
586 rfc2544_profile.rate = 1000
587 completed, samples = rfc2544_profile.get_drop_percentage(
589 self.assertFalse(completed)
590 self.assertEqual(23.0, samples['TxThroughput'])
591 self.assertEqual(21.0, samples['RxThroughput'])
592 self.assertEqual(0.1, samples['DropPercentage'])
593 self.assertEqual(rfc2544_profile.rate, rfc2544_profile.min_rate)
595 @mock.patch.object(ixia_rfc2544.LOG, 'info')
596 def test_get_drop_percentage_not_flow(self, *args):
597 samples = {'iface_name_1':
598 {'RxThroughput': 0, 'TxThroughput': 10,
599 'in_packets': 1000, 'out_packets': 0},
601 {'RxThroughput': 0, 'TxThroughput': 13,
602 'in_packets': 1005, 'out_packets': 0}
604 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
605 rfc2544_profile.rate = 1000
606 completed, samples = rfc2544_profile.get_drop_percentage(
608 self.assertFalse(completed)
609 self.assertEqual(23.0, samples['TxThroughput'])
610 self.assertEqual(0, samples['RxThroughput'])
611 self.assertEqual(100, samples['DropPercentage'])
612 self.assertEqual(rfc2544_profile.rate, rfc2544_profile.max_rate)
614 def test_get_drop_percentage_first_run(self):
615 samples = {'iface_name_1':
616 {'RxThroughput': 10, 'TxThroughput': 10,
617 'in_packets': 1000, 'out_packets': 1000},
619 {'RxThroughput': 11, 'TxThroughput': 13,
620 'in_packets': 1005, 'out_packets': 1007}
622 rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
623 completed, samples = rfc2544_profile.get_drop_percentage(
624 samples, 0, 1, first_run=True)
625 self.assertTrue(completed)
626 self.assertEqual(23.0, samples['TxThroughput'])
627 self.assertEqual(21.0, samples['RxThroughput'])
628 self.assertEqual(0.1, samples['DropPercentage'])
629 self.assertEqual(33.45, rfc2544_profile.rate)