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 copy import deepcopy
25 from tests.unit import STL_MOCKS
27 STLClient = mock.MagicMock()
28 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
32 from yardstick.network_services.traffic_profile.traffic_profile \
34 from yardstick.network_services.traffic_profile.ixia_rfc2544 import \
36 from yardstick.network_services.traffic_profile import ixia_rfc2544
39 class TestIXIARFC2544Profile(unittest.TestCase):
42 "schema": "isb:traffic_profile:0.1",
44 "description": "Fixed traffic profile to run UDP traffic",
46 "traffic_type": "FixedTraffic",
47 "frame_rate": 100, # pps
53 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
55 'traffic_profile': {'traffic_type': 'IXIARFC2544Profile',
57 IXIARFC2544Profile.DOWNLINK: {'ipv4':
58 {'outer_l2': {'framesize':
59 {'64B': '100', '1518B': '0',
60 '128B': '0', '1400B': '0',
61 '256B': '0', '373b': '0',
63 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
64 'proto': 'udp', 'count': '1',
65 'srcip4': '90.90.1.1-90.105.255.255',
66 'dscp': 0, 'ttl': 32},
67 'outer_l4': {'srcport': '2001',
69 IXIARFC2544Profile.UPLINK: {'ipv4':
70 {'outer_l2': {'framesize':
71 {'64B': '100', '1518B': '0',
72 '128B': '0', '1400B': '0',
73 '256B': '0', '373b': '0',
75 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
76 'proto': 'udp', 'count': '1',
77 'srcip4': '1.1.1.1-1.15.255.255',
78 'dscp': 0, 'ttl': 32},
79 'outer_l4': {'dstport': '2001',
81 'schema': 'isb:traffic_profile:0.1'}
83 def test_get_ixia_traffic_profile_error(self):
84 traffic_generator = mock.Mock(autospec=TrexProfile)
85 traffic_generator.my_ports = [0, 1]
86 traffic_generator.uplink_ports = [-1]
87 traffic_generator.downlink_ports = [1]
88 traffic_generator.client = \
89 mock.Mock(return_value=True)
91 IXIARFC2544Profile.UPLINK: {
97 "dstmac": "00:00:00:00:00:03",
98 "framesPerSecond": True,
100 "srcmac": "00:00:00:00:00:01"
104 "dstip4": "152.16.40.20",
106 "srcip4": "152.16.100.20",
111 "dstip4": "152.16.40.20",
113 "srcip4": "152.16.100.20",
119 "dstip4": "152.16.100.20",
121 "srcip4": "152.16.40.20",
128 "traffic_type": "continuous"
130 IXIARFC2544Profile.DOWNLINK: {
136 "dstmac": "00:00:00:00:00:04",
137 "framesPerSecond": True,
139 "srcmac": "00:00:00:00:00:01"
144 "dstip4": "152.16.100.20",
146 "srcip4": "152.16.40.20",
152 "dstip4": "152.16.100.20",
154 "srcip4": "152.16.40.20",
160 "dstip4": "152.16.100.20",
162 "srcip4": "152.16.40.20",
169 "traffic_type": "continuous"
172 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
174 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
175 r_f_c2544_profile.rate = 100
176 mac = {"src_mac_0": "00:00:00:00:00:01",
177 "src_mac_1": "00:00:00:00:00:02",
178 "src_mac_2": "00:00:00:00:00:02",
179 "dst_mac_0": "00:00:00:00:00:03",
180 "dst_mac_1": "00:00:00:00:00:04",
181 "dst_mac_2": "00:00:00:00:00:04"}
182 result = r_f_c2544_profile._get_ixia_traffic_profile(
183 self.PROFILE, mac, xfile="tmp",
184 static_traffic=STATIC_TRAFFIC)
185 self.assertIsNotNone(result)
187 def test_get_ixia_traffic_profile(self):
188 traffic_generator = mock.Mock(autospec=TrexProfile)
189 traffic_generator.my_ports = [0, 1]
190 traffic_generator.uplink_ports = [-1]
191 traffic_generator.downlink_ports = [1]
192 traffic_generator.client = \
193 mock.Mock(return_value=True)
195 IXIARFC2544Profile.UPLINK: {
201 "dstmac": "00:00:00:00:00:03",
202 "framesPerSecond": True,
204 "srcmac": "00:00:00:00:00:01"
208 "dstip4": "152.16.40.20",
210 "srcip4": "152.16.100.20",
215 "dstip4": "152.16.40.20",
217 "srcip4": "152.16.100.20",
224 "dstip4": "152.16.100.20",
226 "srcip4": "152.16.40.20",
235 "traffic_type": "continuous"
237 IXIARFC2544Profile.DOWNLINK: {
243 "dstmac": "00:00:00:00:00:04",
244 "framesPerSecond": True,
246 "srcmac": "00:00:00:00:00:01"
251 "dstip4": "152.16.100.20",
253 "srcip4": "152.16.40.20",
259 "dstip4": "152.16.100.20",
261 "srcip4": "152.16.40.20",
268 "dstip4": "152.16.100.20",
270 "srcip4": "152.16.40.20",
279 "traffic_type": "continuous"
282 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
284 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
285 r_f_c2544_profile.rate = 100
286 mac = {"src_mac_0": "00:00:00:00:00:01",
287 "src_mac_1": "00:00:00:00:00:02",
288 "src_mac_2": "00:00:00:00:00:02",
289 "dst_mac_0": "00:00:00:00:00:03",
290 "dst_mac_1": "00:00:00:00:00:04",
291 "dst_mac_2": "00:00:00:00:00:04"}
292 result = r_f_c2544_profile._get_ixia_traffic_profile(
293 self.PROFILE, mac, xfile="tmp", static_traffic=STATIC_TRAFFIC)
294 self.assertIsNotNone(result)
296 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
297 def test_get_ixia_traffic_profile_v6(self, mock_open):
298 traffic_generator = mock.Mock(autospec=TrexProfile)
299 traffic_generator.my_ports = [0, 1]
300 traffic_generator.uplink_ports = [-1]
301 traffic_generator.downlink_ports = [1]
302 traffic_generator.client = \
303 mock.Mock(return_value=True)
305 IXIARFC2544Profile.UPLINK: {
311 "dstmac": "00:00:00:00:00:03",
312 "framesPerSecond": True,
314 "srcmac": "00:00:00:00:00:01"
318 "dstip4": "152.16.40.20",
320 "srcip4": "152.16.100.20",
325 "dstip4": "152.16.40.20",
327 "srcip4": "152.16.100.20",
333 "dstip4": "152.16.100.20",
335 "srcip4": "152.16.40.20",
342 "traffic_type": "continuous"
344 IXIARFC2544Profile.DOWNLINK: {
350 "dstmac": "00:00:00:00:00:04",
351 "framesPerSecond": True,
353 "srcmac": "00:00:00:00:00:01"
358 "dstip4": "152.16.100.20",
360 "srcip4": "152.16.40.20",
366 "dstip4": "152.16.100.20",
368 "srcip4": "152.16.40.20",
374 "dstip4": "152.16.100.20",
376 "srcip4": "152.16.40.20",
383 "traffic_type": "continuous"
386 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
388 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
389 r_f_c2544_profile.rate = 100
390 mac = {"src_mac_0": "00:00:00:00:00:01",
391 "src_mac_1": "00:00:00:00:00:02",
392 "src_mac_2": "00:00:00:00:00:02",
393 "dst_mac_0": "00:00:00:00:00:03",
394 "dst_mac_1": "00:00:00:00:00:04",
395 "dst_mac_2": "00:00:00:00:00:04"}
396 profile_data = {'description': 'Traffic profile to run RFC2544',
399 {'traffic_type': 'IXIARFC2544Profile',
401 IXIARFC2544Profile.DOWNLINK:
403 {'outer_l2': {'framesize':
404 {'64B': '100', '1518B': '0',
405 '128B': '0', '1400B': '0',
406 '256B': '0', '373b': '0',
408 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
409 'proto': 'udp', 'count': '1',
410 'srcip4': '90.90.1.1-90.105.255.255',
411 'dscp': 0, 'ttl': 32},
412 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
413 'proto': 'udp', 'count': '1',
414 'srcip6': '90.90.1.1-90.105.255.255',
415 'dscp': 0, 'ttl': 32},
416 'outer_l4': {'srcport': '2001',
417 'dsrport': '1234'}}},
418 IXIARFC2544Profile.UPLINK: {'ipv4':
419 {'outer_l2': {'framesize':
420 {'64B': '100', '1518B': '0',
421 '128B': '0', '1400B': '0',
422 '256B': '0', '373b': '0',
425 {'dstip4': '9.9.1.1-90.105.255.255',
426 'proto': 'udp', 'count': '1',
427 'srcip4': '1.1.1.1-1.15.255.255',
428 'dscp': 0, 'ttl': 32},
430 {'dstip6': '9.9.1.1-90.105.255.255',
431 'proto': 'udp', 'count': '1',
432 'srcip6': '1.1.1.1-1.15.255.255',
433 'dscp': 0, 'ttl': 32},
435 'outer_l4': {'dstport': '2001',
436 'srcport': '1234'}}},
437 'schema': 'isb:traffic_profile:0.1'}
438 result = r_f_c2544_profile._get_ixia_traffic_profile(
439 profile_data, mac, static_traffic=STATIC_TRAFFIC)
440 self.assertIsNotNone(result)
442 def test__get_ixia_traffic_profile_default_args(self):
443 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
446 result = r_f_c2544_profile._get_ixia_traffic_profile({})
447 self.assertDictEqual(result, expected)
449 def test__ixia_traffic_generate(self):
450 traffic_generator = mock.Mock(autospec=TrexProfile)
451 traffic_generator.networks = {
453 "downlink_0": ["xe1"],
455 traffic_generator.client = \
456 mock.Mock(return_value=True)
457 traffic = {IXIARFC2544Profile.DOWNLINK: {'iload': 10},
458 IXIARFC2544Profile.UPLINK: {'iload': 10}}
459 ixia_obj = mock.MagicMock()
460 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
461 r_f_c2544_profile.rate = 100
462 result = r_f_c2544_profile._ixia_traffic_generate(traffic_generator,
464 self.assertIsNone(result)
466 def test_execute(self):
467 traffic_generator = mock.Mock(autospec=TrexProfile)
468 traffic_generator.networks = {
470 "downlink_0": ["xe1"],
472 traffic_generator.client = \
473 mock.Mock(return_value=True)
474 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
475 r_f_c2544_profile.first_run = True
476 r_f_c2544_profile.params = {IXIARFC2544Profile.DOWNLINK: {'iload': 10},
477 IXIARFC2544Profile.UPLINK: {'iload': 10}}
479 r_f_c2544_profile.get_streams = mock.Mock()
480 r_f_c2544_profile.full_profile = {}
481 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
482 r_f_c2544_profile.get_multiplier = mock.Mock()
483 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
484 ixia_obj = mock.MagicMock()
485 self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator, ixia_obj))
487 def test_update_traffic_profile(self):
488 traffic_generator = mock.Mock(autospec=TrexProfile)
489 traffic_generator.networks = {
490 "uplink_0": ["xe0"], # private, one value for intfs
491 "downlink_0": ["xe1", "xe2"], # public, two values for intfs
492 "downlink_1": ["xe3"], # not in TRAFFIC PROFILE
493 "tenant_0": ["xe4"], # not public or private
496 ports_expected = [8, 3, 5]
497 traffic_generator.vnfd_helper.port_num.side_effect = ports_expected
498 traffic_generator.client.return_value = True
500 traffic_profile = deepcopy(self.TRAFFIC_PROFILE)
501 traffic_profile.update({
503 "downlink_0": ["xe1", "xe2"],
506 r_f_c2544_profile = IXIARFC2544Profile(traffic_profile)
507 r_f_c2544_profile.full_profile = {}
508 r_f_c2544_profile.get_streams = mock.Mock()
510 self.assertIsNone(r_f_c2544_profile.update_traffic_profile(traffic_generator))
511 self.assertEqual(r_f_c2544_profile.ports, ports_expected)
513 def test_get_drop_percentage(self):
514 traffic_generator = mock.Mock(autospec=TrexProfile)
515 traffic_generator.networks = {
517 "downlink_0": ["xe1"],
519 traffic_generator.client = \
520 mock.Mock(return_value=True)
521 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
522 r_f_c2544_profile.params = self.PROFILE
523 ixia_obj = mock.MagicMock()
524 r_f_c2544_profile.execute = mock.Mock()
525 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
526 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
527 r_f_c2544_profile.get_multiplier = mock.Mock()
528 r_f_c2544_profile.tmp_throughput = 0
529 r_f_c2544_profile.tmp_drop = 0
530 r_f_c2544_profile.full_profile = {}
532 for ifname in range(1):
533 name = "xe{}".format(ifname)
534 samples[name] = {"rx_throughput_fps": 20,
535 "tx_throughput_fps": 20,
536 "rx_throughput_mbps": 10,
537 "tx_throughput_mbps": 10,
544 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
545 traffic_generator, samples,
546 tol_min, tolerance, ixia_obj))
548 def test_get_drop_percentage_update(self):
549 traffic_generator = mock.Mock(autospec=TrexProfile)
550 traffic_generator.my_ports = [0, 1]
551 traffic_generator.uplink_ports = [0]
552 traffic_generator.downlink_ports = [1]
553 traffic_generator.client = \
554 mock.Mock(return_value=True)
555 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
556 r_f_c2544_profile.params = self.PROFILE
557 ixia_obj = mock.MagicMock()
558 r_f_c2544_profile.execute = mock.Mock()
559 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
560 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
561 r_f_c2544_profile.get_multiplier = mock.Mock()
562 r_f_c2544_profile.tmp_throughput = 0
563 r_f_c2544_profile.tmp_drop = 0
564 r_f_c2544_profile.full_profile = {}
566 for ifname in range(1):
567 name = "xe{}".format(ifname)
568 samples[name] = {"rx_throughput_fps": 20,
569 "tx_throughput_fps": 20,
570 "rx_throughput_mbps": 10,
571 "tx_throughput_mbps": 10,
578 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
579 traffic_generator, samples,
580 tol_min, tolerance, ixia_obj))
582 def test_get_drop_percentage_div_zero(self):
583 traffic_generator = mock.Mock(autospec=TrexProfile)
584 traffic_generator.my_ports = [0, 1]
585 traffic_generator.uplink_ports = [0]
586 traffic_generator.downlink_ports = [1]
587 traffic_generator.client = \
588 mock.Mock(return_value=True)
589 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
590 r_f_c2544_profile.params = self.PROFILE
591 ixia_obj = mock.MagicMock()
592 r_f_c2544_profile.execute = mock.Mock()
593 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
594 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
595 r_f_c2544_profile.get_multiplier = mock.Mock()
596 r_f_c2544_profile.tmp_throughput = 0
597 r_f_c2544_profile.tmp_drop = 0
598 r_f_c2544_profile.full_profile = {}
600 for ifname in range(1):
601 name = "xe{}".format(ifname)
602 samples[name] = {"rx_throughput_fps": 20,
603 "tx_throughput_fps": 20,
604 "rx_throughput_mbps": 10,
605 "tx_throughput_mbps": 10,
612 r_f_c2544_profile.tmp_throughput = 0
613 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
614 traffic_generator, samples,
615 tol_min, tolerance, ixia_obj))
617 def test_get_multiplier(self):
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 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
623 def test_start_ixia_latency(self):
624 traffic_generator = mock.Mock(autospec=TrexProfile)
625 traffic_generator.networks = {
627 "downlink_0": ["xe1"],
629 traffic_generator.client = \
630 mock.Mock(return_value=True)
631 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
632 r_f_c2544_profile.max_rate = 100
633 r_f_c2544_profile.min_rate = 100
634 ixia_obj = mock.MagicMock()
635 r_f_c2544_profile._get_ixia_traffic_profile = \
636 mock.Mock(return_value={})
637 r_f_c2544_profile.full_profile = {}
638 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
641 r_f_c2544_profile.start_ixia_latency(traffic_generator,
645 if __name__ == '__main__':