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.
16 from __future__ import absolute_import
17 from __future__ import division
21 from copy import deepcopy
23 from tests.unit import STL_MOCKS
25 STLClient = mock.MagicMock()
26 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
30 from yardstick.network_services.traffic_profile.trex_traffic_profile \
32 from yardstick.network_services.traffic_profile.ixia_rfc2544 import \
34 from yardstick.network_services.traffic_profile import ixia_rfc2544
37 class TestIXIARFC2544Profile(unittest.TestCase):
40 "schema": "isb:traffic_profile:0.1",
42 "description": "Fixed traffic profile to run UDP traffic",
44 "traffic_type": "FixedTraffic",
45 "frame_rate": 100, # pps
51 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
53 'traffic_profile': {'traffic_type': 'IXIARFC2544Profile',
55 IXIARFC2544Profile.DOWNLINK: {'ipv4':
56 {'outer_l2': {'framesize':
57 {'64B': '100', '1518B': '0',
58 '128B': '0', '1400B': '0',
59 '256B': '0', '373b': '0',
61 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
62 'proto': 'udp', 'count': '1',
63 'srcip4': '90.90.1.1-90.105.255.255',
64 'dscp': 0, 'ttl': 32},
65 'outer_l4': {'srcport': '2001',
67 IXIARFC2544Profile.UPLINK: {'ipv4':
68 {'outer_l2': {'framesize':
69 {'64B': '100', '1518B': '0',
70 '128B': '0', '1400B': '0',
71 '256B': '0', '373b': '0',
73 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
74 'proto': 'udp', 'count': '1',
75 'srcip4': '1.1.1.1-1.15.255.255',
76 'dscp': 0, 'ttl': 32},
77 'outer_l4': {'dstport': '2001',
79 'schema': 'isb:traffic_profile:0.1'}
81 def test_get_ixia_traffic_profile_error(self):
82 traffic_generator = mock.Mock(autospec=TrexProfile)
83 traffic_generator.my_ports = [0, 1]
84 traffic_generator.uplink_ports = [-1]
85 traffic_generator.downlink_ports = [1]
86 traffic_generator.client = \
87 mock.Mock(return_value=True)
89 IXIARFC2544Profile.UPLINK: {
95 "dstmac": "00:00:00:00:00:03",
96 "framesPerSecond": True,
98 "srcmac": "00:00:00:00:00:01"
102 "dstip4": "152.16.40.20",
104 "srcip4": "152.16.100.20",
109 "dstip4": "152.16.40.20",
111 "srcip4": "152.16.100.20",
117 "dstip4": "152.16.100.20",
119 "srcip4": "152.16.40.20",
126 "traffic_type": "continuous"
128 IXIARFC2544Profile.DOWNLINK: {
134 "dstmac": "00:00:00:00:00:04",
135 "framesPerSecond": True,
137 "srcmac": "00:00:00:00:00:01"
142 "dstip4": "152.16.100.20",
144 "srcip4": "152.16.40.20",
150 "dstip4": "152.16.100.20",
152 "srcip4": "152.16.40.20",
158 "dstip4": "152.16.100.20",
160 "srcip4": "152.16.40.20",
167 "traffic_type": "continuous"
170 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
172 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
173 r_f_c2544_profile.rate = 100
174 mac = {"src_mac_0": "00:00:00:00:00:01",
175 "src_mac_1": "00:00:00:00:00:02",
176 "src_mac_2": "00:00:00:00:00:02",
177 "dst_mac_0": "00:00:00:00:00:03",
178 "dst_mac_1": "00:00:00:00:00:04",
179 "dst_mac_2": "00:00:00:00:00:04"}
180 result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
181 self.assertIsNotNone(result)
183 def test_get_ixia_traffic_profile(self):
184 traffic_generator = mock.Mock(autospec=TrexProfile)
185 traffic_generator.my_ports = [0, 1]
186 traffic_generator.uplink_ports = [-1]
187 traffic_generator.downlink_ports = [1]
188 traffic_generator.client = \
189 mock.Mock(return_value=True)
191 IXIARFC2544Profile.UPLINK: {
197 "dstmac": "00:00:00:00:00:03",
198 "framesPerSecond": True,
200 "srcmac": "00:00:00:00:00:01"
204 "dstip4": "152.16.40.20",
206 "srcip4": "152.16.100.20",
211 "dstip4": "152.16.40.20",
213 "srcip4": "152.16.100.20",
220 "dstip4": "152.16.100.20",
222 "srcip4": "152.16.40.20",
230 "traffic_type": "continuous"
232 IXIARFC2544Profile.DOWNLINK: {
238 "dstmac": "00:00:00:00:00:04",
239 "framesPerSecond": True,
241 "srcmac": "00:00:00:00:00:01"
246 "dstip4": "152.16.100.20",
248 "srcip4": "152.16.40.20",
254 "dstip4": "152.16.100.20",
256 "srcip4": "152.16.40.20",
262 "dstip4": "152.16.100.20",
264 "srcip4": "152.16.40.20",
272 "traffic_type": "continuous"
275 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
277 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
278 r_f_c2544_profile.rate = 100
279 mac = {"src_mac_0": "00:00:00:00:00:01",
280 "src_mac_1": "00:00:00:00:00:02",
281 "src_mac_2": "00:00:00:00:00:02",
282 "dst_mac_0": "00:00:00:00:00:03",
283 "dst_mac_1": "00:00:00:00:00:04",
284 "dst_mac_2": "00:00:00:00:00:04"}
285 result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
286 self.assertIsNotNone(result)
288 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
289 def test_get_ixia_traffic_profile_v6(self, *args):
290 traffic_generator = mock.Mock(autospec=TrexProfile)
291 traffic_generator.my_ports = [0, 1]
292 traffic_generator.uplink_ports = [-1]
293 traffic_generator.downlink_ports = [1]
294 traffic_generator.client = \
295 mock.Mock(return_value=True)
297 IXIARFC2544Profile.UPLINK: {
303 "dstmac": "00:00:00:00:00:03",
304 "framesPerSecond": True,
306 "srcmac": "00:00:00:00:00:01"
310 "dstip4": "152.16.40.20",
312 "srcip4": "152.16.100.20",
317 "dstip4": "152.16.40.20",
319 "srcip4": "152.16.100.20",
325 "dstip4": "152.16.100.20",
327 "srcip4": "152.16.40.20",
334 "traffic_type": "continuous"
336 IXIARFC2544Profile.DOWNLINK: {
342 "dstmac": "00:00:00:00:00:04",
343 "framesPerSecond": True,
345 "srcmac": "00:00:00:00:00:01"
350 "dstip4": "152.16.100.20",
352 "srcip4": "152.16.40.20",
358 "dstip4": "152.16.100.20",
360 "srcip4": "152.16.40.20",
366 "dstip4": "152.16.100.20",
368 "srcip4": "152.16.40.20",
375 "traffic_type": "continuous"
378 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
380 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
381 r_f_c2544_profile.rate = 100
382 mac = {"src_mac_0": "00:00:00:00:00:01",
383 "src_mac_1": "00:00:00:00:00:02",
384 "src_mac_2": "00:00:00:00:00:02",
385 "dst_mac_0": "00:00:00:00:00:03",
386 "dst_mac_1": "00:00:00:00:00:04",
387 "dst_mac_2": "00:00:00:00:00:04"}
388 profile_data = {'description': 'Traffic profile to run RFC2544',
391 {'traffic_type': 'IXIARFC2544Profile',
393 IXIARFC2544Profile.DOWNLINK:
395 {'outer_l2': {'framesize':
396 {'64B': '100', '1518B': '0',
397 '128B': '0', '1400B': '0',
398 '256B': '0', '373b': '0',
400 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
401 'proto': 'udp', 'count': '1',
402 'srcip4': '90.90.1.1-90.105.255.255',
403 'dscp': 0, 'ttl': 32},
404 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
405 'proto': 'udp', 'count': '1',
406 'srcip6': '90.90.1.1-90.105.255.255',
407 'dscp': 0, 'ttl': 32},
408 'outer_l4': {'srcport': '2001',
409 'dsrport': '1234'}}},
410 IXIARFC2544Profile.UPLINK: {'ipv4':
411 {'outer_l2': {'framesize':
412 {'64B': '100', '1518B': '0',
413 '128B': '0', '1400B': '0',
414 '256B': '0', '373b': '0',
417 {'dstip4': '9.9.1.1-90.105.255.255',
418 'proto': 'udp', 'count': '1',
419 'srcip4': '1.1.1.1-1.15.255.255',
420 'dscp': 0, 'ttl': 32},
422 {'dstip6': '9.9.1.1-90.105.255.255',
423 'proto': 'udp', 'count': '1',
424 'srcip6': '1.1.1.1-1.15.255.255',
425 'dscp': 0, 'ttl': 32},
427 'outer_l4': {'dstport': '2001',
428 'srcport': '1234'}}},
429 'schema': 'isb:traffic_profile:0.1'}
430 result = r_f_c2544_profile._get_ixia_traffic_profile(profile_data, mac)
431 self.assertIsNotNone(result)
433 def test__get_ixia_traffic_profile_default_args(self):
434 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
437 result = r_f_c2544_profile._get_ixia_traffic_profile({})
438 self.assertDictEqual(result, expected)
440 def test__ixia_traffic_generate(self):
441 traffic_generator = mock.Mock(autospec=TrexProfile)
442 traffic_generator.networks = {
444 "downlink_0": ["xe1"],
446 traffic_generator.client = \
447 mock.Mock(return_value=True)
448 traffic = {IXIARFC2544Profile.DOWNLINK: {'iload': 10},
449 IXIARFC2544Profile.UPLINK: {'iload': 10}}
450 ixia_obj = mock.MagicMock()
451 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
452 r_f_c2544_profile.rate = 100
453 result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj)
454 self.assertIsNone(result)
456 def test_execute(self):
457 traffic_generator = mock.Mock(autospec=TrexProfile)
458 traffic_generator.networks = {
460 "downlink_0": ["xe1"],
462 traffic_generator.client = \
463 mock.Mock(return_value=True)
464 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
465 r_f_c2544_profile.first_run = True
466 r_f_c2544_profile.params = {IXIARFC2544Profile.DOWNLINK: {'iload': 10},
467 IXIARFC2544Profile.UPLINK: {'iload': 10}}
469 r_f_c2544_profile.get_streams = mock.Mock()
470 r_f_c2544_profile.full_profile = {}
471 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
472 r_f_c2544_profile.get_multiplier = mock.Mock()
473 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
474 ixia_obj = mock.MagicMock()
475 self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator, ixia_obj))
477 def test_update_traffic_profile(self):
478 traffic_generator = mock.Mock(autospec=TrexProfile)
479 traffic_generator.networks = {
480 "uplink_0": ["xe0"], # private, one value for intfs
481 "downlink_0": ["xe1", "xe2"], # public, two values for intfs
482 "downlink_1": ["xe3"], # not in TRAFFIC PROFILE
483 "tenant_0": ["xe4"], # not public or private
486 ports_expected = [8, 3, 5]
487 traffic_generator.vnfd_helper.port_num.side_effect = ports_expected
488 traffic_generator.client.return_value = True
490 traffic_profile = deepcopy(self.TRAFFIC_PROFILE)
491 traffic_profile.update({
493 "downlink_0": ["xe1", "xe2"],
496 r_f_c2544_profile = IXIARFC2544Profile(traffic_profile)
497 r_f_c2544_profile.full_profile = {}
498 r_f_c2544_profile.get_streams = mock.Mock()
500 self.assertIsNone(r_f_c2544_profile.update_traffic_profile(traffic_generator))
501 self.assertEqual(r_f_c2544_profile.ports, ports_expected)
503 def test_get_drop_percentage(self):
504 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
505 r_f_c2544_profile.params = self.PROFILE
506 ixia_obj = mock.MagicMock()
507 r_f_c2544_profile.execute = mock.Mock()
508 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
509 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
510 r_f_c2544_profile.get_multiplier = mock.Mock()
511 r_f_c2544_profile.tmp_throughput = 0
512 r_f_c2544_profile.tmp_drop = 0
513 r_f_c2544_profile.full_profile = {}
515 for ifname in range(1):
516 name = "xe{}".format(ifname)
517 samples[name] = {"rx_throughput_fps": 20,
518 "tx_throughput_fps": 20,
519 "rx_throughput_mbps": 10,
520 "tx_throughput_mbps": 10,
527 self.assertIsNotNone(
528 r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
531 def test_get_drop_percentage_update(self):
532 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
533 r_f_c2544_profile.params = self.PROFILE
534 ixia_obj = mock.MagicMock()
535 r_f_c2544_profile.execute = mock.Mock()
536 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
537 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
538 r_f_c2544_profile.get_multiplier = mock.Mock()
539 r_f_c2544_profile.tmp_throughput = 0
540 r_f_c2544_profile.tmp_drop = 0
541 r_f_c2544_profile.full_profile = {}
543 for ifname in range(1):
544 name = "xe{}".format(ifname)
545 samples[name] = {"rx_throughput_fps": 20,
546 "tx_throughput_fps": 20,
547 "rx_throughput_mbps": 10,
548 "tx_throughput_mbps": 10,
555 self.assertIsNotNone(
556 r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
559 def test_get_drop_percentage_div_zero(self):
560 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
561 r_f_c2544_profile.params = self.PROFILE
562 ixia_obj = mock.MagicMock()
563 r_f_c2544_profile.execute = mock.Mock()
564 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
565 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
566 r_f_c2544_profile.get_multiplier = mock.Mock()
567 r_f_c2544_profile.tmp_throughput = 0
568 r_f_c2544_profile.tmp_drop = 0
569 r_f_c2544_profile.full_profile = {}
571 for ifname in range(1):
572 name = "xe{}".format(ifname)
573 samples[name] = {"rx_throughput_fps": 20,
574 "tx_throughput_fps": 20,
575 "rx_throughput_mbps": 10,
576 "tx_throughput_mbps": 10,
583 r_f_c2544_profile.tmp_throughput = 0
584 self.assertIsNotNone(
585 r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
588 def test_get_multiplier(self):
589 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
590 r_f_c2544_profile.max_rate = 100
591 r_f_c2544_profile.min_rate = 100
592 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
594 def test_start_ixia_latency(self):
595 traffic_generator = mock.Mock(autospec=TrexProfile)
596 traffic_generator.networks = {
598 "downlink_0": ["xe1"],
600 traffic_generator.client = \
601 mock.Mock(return_value=True)
602 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
603 r_f_c2544_profile.max_rate = 100
604 r_f_c2544_profile.min_rate = 100
605 ixia_obj = mock.MagicMock()
606 r_f_c2544_profile._get_ixia_traffic_profile = \
607 mock.Mock(return_value={})
608 r_f_c2544_profile.full_profile = {}
609 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
611 r_f_c2544_profile.start_ixia_latency(traffic_generator, ixia_obj))