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.
19 from copy import deepcopy
21 from yardstick.tests import STL_MOCKS
23 STLClient = mock.MagicMock()
24 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
28 from yardstick.network_services.traffic_profile.trex_traffic_profile \
30 from yardstick.network_services.traffic_profile.ixia_rfc2544 import \
32 from yardstick.network_services.traffic_profile import ixia_rfc2544
35 class TestIXIARFC2544Profile(unittest.TestCase):
38 "schema": "isb:traffic_profile:0.1",
40 "description": "Fixed traffic profile to run UDP traffic",
42 "traffic_type": "FixedTraffic",
43 "frame_rate": 100, # pps
50 'description': 'Traffic profile to run RFC2544 latency',
53 'traffic_type': 'IXIARFC2544Profile',
55 IXIARFC2544Profile.DOWNLINK: {
67 'dstip4': '1.1.1.1-1.15.255.255',
70 'srcip4': '90.90.1.1-90.105.255.255',
76 IXIARFC2544Profile.UPLINK: {
88 'dstip4': '9.9.1.1-90.105.255.255',
91 'srcip4': '1.1.1.1-1.15.255.255',
97 'schema': 'isb:traffic_profile:0.1'}
99 def test_get_ixia_traffic_profile_error(self):
100 traffic_generator = mock.Mock(autospec=TrexProfile)
101 traffic_generator.my_ports = [0, 1]
102 traffic_generator.uplink_ports = [-1]
103 traffic_generator.downlink_ports = [1]
104 traffic_generator.client = \
105 mock.Mock(return_value=True)
107 IXIARFC2544Profile.UPLINK: {
113 "dstmac": "00:00:00:00:00:03",
114 "framesPerSecond": True,
116 "srcmac": "00:00:00:00:00:01"
120 "dstip4": "152.16.40.20",
122 "srcip4": "152.16.100.20",
127 "dstip4": "152.16.40.20",
129 "srcip4": "152.16.100.20",
135 "dstip4": "152.16.100.20",
137 "srcip4": "152.16.40.20",
144 "traffic_type": "continuous"
146 IXIARFC2544Profile.DOWNLINK: {
152 "dstmac": "00:00:00:00:00:04",
153 "framesPerSecond": True,
155 "srcmac": "00:00:00:00:00:01"
160 "dstip4": "152.16.100.20",
162 "srcip4": "152.16.40.20",
168 "dstip4": "152.16.100.20",
170 "srcip4": "152.16.40.20",
176 "dstip4": "152.16.100.20",
178 "srcip4": "152.16.40.20",
185 "traffic_type": "continuous"
188 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
190 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
191 r_f_c2544_profile.rate = 100
192 mac = {"src_mac_0": "00:00:00:00:00:01",
193 "src_mac_1": "00:00:00:00:00:02",
194 "src_mac_2": "00:00:00:00:00:02",
195 "dst_mac_0": "00:00:00:00:00:03",
196 "dst_mac_1": "00:00:00:00:00:04",
197 "dst_mac_2": "00:00:00:00:00:04"}
198 result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
199 self.assertIsNotNone(result)
201 def test_get_ixia_traffic_profile(self):
202 traffic_generator = mock.Mock(autospec=TrexProfile)
203 traffic_generator.my_ports = [0, 1]
204 traffic_generator.uplink_ports = [-1]
205 traffic_generator.downlink_ports = [1]
206 traffic_generator.client = \
207 mock.Mock(return_value=True)
209 IXIARFC2544Profile.UPLINK: {
215 "dstmac": "00:00:00:00:00:03",
216 "framesPerSecond": True,
218 "srcmac": "00:00:00:00:00:01"
222 "dstip4": "152.16.40.20",
224 "srcip4": "152.16.100.20",
229 "dstip4": "152.16.40.20",
231 "srcip4": "152.16.100.20",
237 "dstip4": "152.16.100.20",
239 "srcip4": "152.16.40.20",
247 "traffic_type": "continuous"
249 IXIARFC2544Profile.DOWNLINK: {
255 "dstmac": "00:00:00:00:00:04",
256 "framesPerSecond": True,
258 "srcmac": "00:00:00:00:00:01"
263 "dstip4": "152.16.100.20",
265 "srcip4": "152.16.40.20",
270 "dstip4": "152.16.100.20",
272 "srcip4": "152.16.40.20",
277 "dstip4": "152.16.100.20",
279 "srcip4": "152.16.40.20",
287 "traffic_type": "continuous"
290 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
292 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
293 r_f_c2544_profile.rate = 100
294 mac = {"src_mac_0": "00:00:00:00:00:01",
295 "src_mac_1": "00:00:00:00:00:02",
296 "src_mac_2": "00:00:00:00:00:02",
297 "dst_mac_0": "00:00:00:00:00:03",
298 "dst_mac_1": "00:00:00:00:00:04",
299 "dst_mac_2": "00:00:00:00:00:04"}
300 result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
301 self.assertIsNotNone(result)
303 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
304 def test_get_ixia_traffic_profile_v6(self, *args):
305 traffic_generator = mock.Mock(autospec=TrexProfile)
306 traffic_generator.my_ports = [0, 1]
307 traffic_generator.uplink_ports = [-1]
308 traffic_generator.downlink_ports = [1]
309 traffic_generator.client = \
310 mock.Mock(return_value=True)
312 IXIARFC2544Profile.UPLINK: {
318 "dstmac": "00:00:00:00:00:03",
319 "framesPerSecond": True,
321 "srcmac": "00:00:00:00:00:01"
325 "dstip4": "152.16.40.20",
327 "srcip4": "152.16.100.20",
332 "dstip4": "152.16.40.20",
334 "srcip4": "152.16.100.20",
340 "dstip4": "152.16.100.20",
342 "srcip4": "152.16.40.20",
349 "traffic_type": "continuous"
351 IXIARFC2544Profile.DOWNLINK: {
357 "dstmac": "00:00:00:00:00:04",
358 "framesPerSecond": True,
360 "srcmac": "00:00:00:00:00:01"
365 "dstip4": "152.16.100.20",
367 "srcip4": "152.16.40.20",
373 "dstip4": "152.16.100.20",
375 "srcip4": "152.16.40.20",
381 "dstip4": "152.16.100.20",
383 "srcip4": "152.16.40.20",
390 "traffic_type": "continuous"
393 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
395 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
396 r_f_c2544_profile.rate = 100
397 mac = {"src_mac_0": "00:00:00:00:00:01",
398 "src_mac_1": "00:00:00:00:00:02",
399 "src_mac_2": "00:00:00:00:00:02",
400 "dst_mac_0": "00:00:00:00:00:03",
401 "dst_mac_1": "00:00:00:00:00:04",
402 "dst_mac_2": "00:00:00:00:00:04"}
403 profile_data = {'description': 'Traffic profile to run RFC2544',
406 {'traffic_type': 'IXIARFC2544Profile',
408 IXIARFC2544Profile.DOWNLINK:
410 {'outer_l2': {'framesize':
411 {'64B': '100', '1518B': '0',
412 '128B': '0', '1400B': '0',
413 '256B': '0', '373b': '0',
415 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
416 'proto': 'udp', 'count': '1',
417 'srcip4': '90.90.1.1-90.105.255.255',
418 'dscp': 0, 'ttl': 32},
419 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
420 'proto': 'udp', 'count': '1',
421 'srcip6': '90.90.1.1-90.105.255.255',
422 'dscp': 0, 'ttl': 32},
423 'outer_l4': {'srcport': '2001',
424 'dsrport': '1234'}}},
425 IXIARFC2544Profile.UPLINK: {'ipv4':
426 {'outer_l2': {'framesize':
427 {'64B': '100', '1518B': '0',
428 '128B': '0', '1400B': '0',
429 '256B': '0', '373b': '0',
432 {'dstip4': '9.9.1.1-90.105.255.255',
433 'proto': 'udp', 'count': '1',
434 'srcip4': '1.1.1.1-1.15.255.255',
435 'dscp': 0, 'ttl': 32},
437 {'dstip6': '9.9.1.1-90.105.255.255',
438 'proto': 'udp', 'count': '1',
439 'srcip6': '1.1.1.1-1.15.255.255',
440 'dscp': 0, 'ttl': 32},
442 'outer_l4': {'dstport': '2001',
443 'srcport': '1234'}}},
444 'schema': 'isb:traffic_profile:0.1'}
445 result = r_f_c2544_profile._get_ixia_traffic_profile(profile_data, mac)
446 self.assertIsNotNone(result)
448 def test__get_ixia_traffic_profile_default_args(self):
449 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
452 result = r_f_c2544_profile._get_ixia_traffic_profile({})
453 self.assertDictEqual(result, expected)
455 def test__ixia_traffic_generate(self):
456 traffic_generator = mock.Mock(autospec=TrexProfile)
457 traffic_generator.networks = {
459 "downlink_0": ["xe1"],
461 traffic_generator.client = \
462 mock.Mock(return_value=True)
463 traffic = {IXIARFC2544Profile.DOWNLINK: {'iload': 10},
464 IXIARFC2544Profile.UPLINK: {'iload': 10}}
465 ixia_obj = mock.MagicMock()
466 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
467 r_f_c2544_profile.rate = 100
468 result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj)
469 self.assertIsNone(result)
471 def test_execute(self):
472 traffic_generator = mock.Mock(autospec=TrexProfile)
473 traffic_generator.networks = {
475 "downlink_0": ["xe1"],
477 traffic_generator.client = \
478 mock.Mock(return_value=True)
479 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
480 r_f_c2544_profile.first_run = True
481 r_f_c2544_profile.params = {IXIARFC2544Profile.DOWNLINK: {'iload': 10},
482 IXIARFC2544Profile.UPLINK: {'iload': 10}}
484 r_f_c2544_profile.get_streams = mock.Mock()
485 r_f_c2544_profile.full_profile = {}
486 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
487 r_f_c2544_profile.get_multiplier = mock.Mock()
488 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
489 ixia_obj = mock.MagicMock()
490 self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator, ixia_obj))
492 def test_update_traffic_profile(self):
493 traffic_generator = mock.Mock(autospec=TrexProfile)
494 traffic_generator.networks = {
495 "uplink_0": ["xe0"], # private, one value for intfs
496 "downlink_0": ["xe1", "xe2"], # public, two values for intfs
497 "downlink_1": ["xe3"], # not in TRAFFIC PROFILE
498 "tenant_0": ["xe4"], # not public or private
501 ports_expected = [8, 3, 5]
502 traffic_generator.vnfd_helper.port_num.side_effect = ports_expected
503 traffic_generator.client.return_value = True
505 traffic_profile = deepcopy(self.TRAFFIC_PROFILE)
506 traffic_profile.update({
508 "downlink_0": ["xe1", "xe2"],
511 r_f_c2544_profile = IXIARFC2544Profile(traffic_profile)
512 r_f_c2544_profile.full_profile = {}
513 r_f_c2544_profile.get_streams = mock.Mock()
516 r_f_c2544_profile.update_traffic_profile(traffic_generator))
517 self.assertEqual(r_f_c2544_profile.ports, ports_expected)
519 def test_get_drop_percentage(self):
520 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
521 r_f_c2544_profile.params = self.PROFILE
522 ixia_obj = mock.MagicMock()
523 r_f_c2544_profile.execute = mock.Mock()
524 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
525 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
526 r_f_c2544_profile.get_multiplier = mock.Mock()
527 r_f_c2544_profile.tmp_throughput = 0
528 r_f_c2544_profile.tmp_drop = 0
529 r_f_c2544_profile.full_profile = {}
531 for ifname in range(1):
532 name = "xe{}".format(ifname)
533 samples[name] = {"rx_throughput_fps": 20,
534 "tx_throughput_fps": 20,
535 "rx_throughput_mbps": 10,
536 "tx_throughput_mbps": 10,
543 self.assertIsNotNone(
544 r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
547 def test_get_drop_percentage_update(self):
548 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
549 r_f_c2544_profile.params = self.PROFILE
550 ixia_obj = mock.MagicMock()
551 r_f_c2544_profile.execute = mock.Mock()
552 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
553 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
554 r_f_c2544_profile.get_multiplier = mock.Mock()
555 r_f_c2544_profile.tmp_throughput = 0
556 r_f_c2544_profile.tmp_drop = 0
557 r_f_c2544_profile.full_profile = {}
559 for ifname in range(1):
560 name = "xe{}".format(ifname)
561 samples[name] = {"rx_throughput_fps": 20,
562 "tx_throughput_fps": 20,
563 "rx_throughput_mbps": 10,
564 "tx_throughput_mbps": 10,
571 self.assertIsNotNone(
572 r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
575 def test_get_drop_percentage_div_zero(self):
576 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
577 r_f_c2544_profile.params = self.PROFILE
578 ixia_obj = mock.MagicMock()
579 r_f_c2544_profile.execute = mock.Mock()
580 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
581 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
582 r_f_c2544_profile.get_multiplier = mock.Mock()
583 r_f_c2544_profile.tmp_throughput = 0
584 r_f_c2544_profile.tmp_drop = 0
585 r_f_c2544_profile.full_profile = {}
587 for ifname in range(1):
588 name = "xe{}".format(ifname)
589 samples[name] = {"rx_throughput_fps": 20,
590 "tx_throughput_fps": 20,
591 "rx_throughput_mbps": 10,
592 "tx_throughput_mbps": 10,
599 r_f_c2544_profile.tmp_throughput = 0
600 self.assertIsNotNone(
601 r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
604 def test_get_multiplier(self):
605 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
606 r_f_c2544_profile.max_rate = 100
607 r_f_c2544_profile.min_rate = 100
608 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
610 def test_start_ixia_latency(self):
611 traffic_generator = mock.Mock(autospec=TrexProfile)
612 traffic_generator.networks = {
614 "downlink_0": ["xe1"],
616 traffic_generator.client = \
617 mock.Mock(return_value=True)
618 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
619 r_f_c2544_profile.max_rate = 100
620 r_f_c2544_profile.min_rate = 100
621 ixia_obj = mock.MagicMock()
622 r_f_c2544_profile._get_ixia_traffic_profile = \
623 mock.Mock(return_value={})
624 r_f_c2544_profile.full_profile = {}
625 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
627 r_f_c2544_profile.start_ixia_latency(traffic_generator, ixia_obj))