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(self.PROFILE, mac)
183 self.assertIsNotNone(result)
185 def test_get_ixia_traffic_profile(self):
186 traffic_generator = mock.Mock(autospec=TrexProfile)
187 traffic_generator.my_ports = [0, 1]
188 traffic_generator.uplink_ports = [-1]
189 traffic_generator.downlink_ports = [1]
190 traffic_generator.client = \
191 mock.Mock(return_value=True)
193 IXIARFC2544Profile.UPLINK: {
199 "dstmac": "00:00:00:00:00:03",
200 "framesPerSecond": True,
202 "srcmac": "00:00:00:00:00:01"
206 "dstip4": "152.16.40.20",
208 "srcip4": "152.16.100.20",
213 "dstip4": "152.16.40.20",
215 "srcip4": "152.16.100.20",
222 "dstip4": "152.16.100.20",
224 "srcip4": "152.16.40.20",
232 "traffic_type": "continuous"
234 IXIARFC2544Profile.DOWNLINK: {
240 "dstmac": "00:00:00:00:00:04",
241 "framesPerSecond": True,
243 "srcmac": "00:00:00:00:00:01"
248 "dstip4": "152.16.100.20",
250 "srcip4": "152.16.40.20",
256 "dstip4": "152.16.100.20",
258 "srcip4": "152.16.40.20",
264 "dstip4": "152.16.100.20",
266 "srcip4": "152.16.40.20",
274 "traffic_type": "continuous"
277 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
279 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
280 r_f_c2544_profile.rate = 100
281 mac = {"src_mac_0": "00:00:00:00:00:01",
282 "src_mac_1": "00:00:00:00:00:02",
283 "src_mac_2": "00:00:00:00:00:02",
284 "dst_mac_0": "00:00:00:00:00:03",
285 "dst_mac_1": "00:00:00:00:00:04",
286 "dst_mac_2": "00:00:00:00:00:04"}
287 result = r_f_c2544_profile._get_ixia_traffic_profile(self.PROFILE, mac)
288 self.assertIsNotNone(result)
290 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
291 def test_get_ixia_traffic_profile_v6(self, *args):
292 traffic_generator = mock.Mock(autospec=TrexProfile)
293 traffic_generator.my_ports = [0, 1]
294 traffic_generator.uplink_ports = [-1]
295 traffic_generator.downlink_ports = [1]
296 traffic_generator.client = \
297 mock.Mock(return_value=True)
299 IXIARFC2544Profile.UPLINK: {
305 "dstmac": "00:00:00:00:00:03",
306 "framesPerSecond": True,
308 "srcmac": "00:00:00:00:00:01"
312 "dstip4": "152.16.40.20",
314 "srcip4": "152.16.100.20",
319 "dstip4": "152.16.40.20",
321 "srcip4": "152.16.100.20",
327 "dstip4": "152.16.100.20",
329 "srcip4": "152.16.40.20",
336 "traffic_type": "continuous"
338 IXIARFC2544Profile.DOWNLINK: {
344 "dstmac": "00:00:00:00:00:04",
345 "framesPerSecond": True,
347 "srcmac": "00:00:00:00:00:01"
352 "dstip4": "152.16.100.20",
354 "srcip4": "152.16.40.20",
360 "dstip4": "152.16.100.20",
362 "srcip4": "152.16.40.20",
368 "dstip4": "152.16.100.20",
370 "srcip4": "152.16.40.20",
377 "traffic_type": "continuous"
380 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
382 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
383 r_f_c2544_profile.rate = 100
384 mac = {"src_mac_0": "00:00:00:00:00:01",
385 "src_mac_1": "00:00:00:00:00:02",
386 "src_mac_2": "00:00:00:00:00:02",
387 "dst_mac_0": "00:00:00:00:00:03",
388 "dst_mac_1": "00:00:00:00:00:04",
389 "dst_mac_2": "00:00:00:00:00:04"}
390 profile_data = {'description': 'Traffic profile to run RFC2544',
393 {'traffic_type': 'IXIARFC2544Profile',
395 IXIARFC2544Profile.DOWNLINK:
397 {'outer_l2': {'framesize':
398 {'64B': '100', '1518B': '0',
399 '128B': '0', '1400B': '0',
400 '256B': '0', '373b': '0',
402 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
403 'proto': 'udp', 'count': '1',
404 'srcip4': '90.90.1.1-90.105.255.255',
405 'dscp': 0, 'ttl': 32},
406 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
407 'proto': 'udp', 'count': '1',
408 'srcip6': '90.90.1.1-90.105.255.255',
409 'dscp': 0, 'ttl': 32},
410 'outer_l4': {'srcport': '2001',
411 'dsrport': '1234'}}},
412 IXIARFC2544Profile.UPLINK: {'ipv4':
413 {'outer_l2': {'framesize':
414 {'64B': '100', '1518B': '0',
415 '128B': '0', '1400B': '0',
416 '256B': '0', '373b': '0',
419 {'dstip4': '9.9.1.1-90.105.255.255',
420 'proto': 'udp', 'count': '1',
421 'srcip4': '1.1.1.1-1.15.255.255',
422 'dscp': 0, 'ttl': 32},
424 {'dstip6': '9.9.1.1-90.105.255.255',
425 'proto': 'udp', 'count': '1',
426 'srcip6': '1.1.1.1-1.15.255.255',
427 'dscp': 0, 'ttl': 32},
429 'outer_l4': {'dstport': '2001',
430 'srcport': '1234'}}},
431 'schema': 'isb:traffic_profile:0.1'}
432 result = r_f_c2544_profile._get_ixia_traffic_profile(profile_data, mac)
433 self.assertIsNotNone(result)
435 def test__get_ixia_traffic_profile_default_args(self):
436 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
439 result = r_f_c2544_profile._get_ixia_traffic_profile({})
440 self.assertDictEqual(result, expected)
442 def test__ixia_traffic_generate(self):
443 traffic_generator = mock.Mock(autospec=TrexProfile)
444 traffic_generator.networks = {
446 "downlink_0": ["xe1"],
448 traffic_generator.client = \
449 mock.Mock(return_value=True)
450 traffic = {IXIARFC2544Profile.DOWNLINK: {'iload': 10},
451 IXIARFC2544Profile.UPLINK: {'iload': 10}}
452 ixia_obj = mock.MagicMock()
453 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
454 r_f_c2544_profile.rate = 100
455 result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj)
456 self.assertIsNone(result)
458 def test_execute(self):
459 traffic_generator = mock.Mock(autospec=TrexProfile)
460 traffic_generator.networks = {
462 "downlink_0": ["xe1"],
464 traffic_generator.client = \
465 mock.Mock(return_value=True)
466 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
467 r_f_c2544_profile.first_run = True
468 r_f_c2544_profile.params = {IXIARFC2544Profile.DOWNLINK: {'iload': 10},
469 IXIARFC2544Profile.UPLINK: {'iload': 10}}
471 r_f_c2544_profile.get_streams = mock.Mock()
472 r_f_c2544_profile.full_profile = {}
473 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
474 r_f_c2544_profile.get_multiplier = mock.Mock()
475 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
476 ixia_obj = mock.MagicMock()
477 self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator, ixia_obj))
479 def test_update_traffic_profile(self):
480 traffic_generator = mock.Mock(autospec=TrexProfile)
481 traffic_generator.networks = {
482 "uplink_0": ["xe0"], # private, one value for intfs
483 "downlink_0": ["xe1", "xe2"], # public, two values for intfs
484 "downlink_1": ["xe3"], # not in TRAFFIC PROFILE
485 "tenant_0": ["xe4"], # not public or private
488 ports_expected = [8, 3, 5]
489 traffic_generator.vnfd_helper.port_num.side_effect = ports_expected
490 traffic_generator.client.return_value = True
492 traffic_profile = deepcopy(self.TRAFFIC_PROFILE)
493 traffic_profile.update({
495 "downlink_0": ["xe1", "xe2"],
498 r_f_c2544_profile = IXIARFC2544Profile(traffic_profile)
499 r_f_c2544_profile.full_profile = {}
500 r_f_c2544_profile.get_streams = mock.Mock()
502 self.assertIsNone(r_f_c2544_profile.update_traffic_profile(traffic_generator))
503 self.assertEqual(r_f_c2544_profile.ports, ports_expected)
505 def test_get_drop_percentage(self):
506 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
507 r_f_c2544_profile.params = self.PROFILE
508 ixia_obj = mock.MagicMock()
509 r_f_c2544_profile.execute = mock.Mock()
510 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
511 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
512 r_f_c2544_profile.get_multiplier = mock.Mock()
513 r_f_c2544_profile.tmp_throughput = 0
514 r_f_c2544_profile.tmp_drop = 0
515 r_f_c2544_profile.full_profile = {}
517 for ifname in range(1):
518 name = "xe{}".format(ifname)
519 samples[name] = {"rx_throughput_fps": 20,
520 "tx_throughput_fps": 20,
521 "rx_throughput_mbps": 10,
522 "tx_throughput_mbps": 10,
529 self.assertIsNotNone(
530 r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
533 def test_get_drop_percentage_update(self):
534 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
535 r_f_c2544_profile.params = self.PROFILE
536 ixia_obj = mock.MagicMock()
537 r_f_c2544_profile.execute = mock.Mock()
538 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
539 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
540 r_f_c2544_profile.get_multiplier = mock.Mock()
541 r_f_c2544_profile.tmp_throughput = 0
542 r_f_c2544_profile.tmp_drop = 0
543 r_f_c2544_profile.full_profile = {}
545 for ifname in range(1):
546 name = "xe{}".format(ifname)
547 samples[name] = {"rx_throughput_fps": 20,
548 "tx_throughput_fps": 20,
549 "rx_throughput_mbps": 10,
550 "tx_throughput_mbps": 10,
557 self.assertIsNotNone(
558 r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
561 def test_get_drop_percentage_div_zero(self):
562 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
563 r_f_c2544_profile.params = self.PROFILE
564 ixia_obj = mock.MagicMock()
565 r_f_c2544_profile.execute = mock.Mock()
566 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
567 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
568 r_f_c2544_profile.get_multiplier = mock.Mock()
569 r_f_c2544_profile.tmp_throughput = 0
570 r_f_c2544_profile.tmp_drop = 0
571 r_f_c2544_profile.full_profile = {}
573 for ifname in range(1):
574 name = "xe{}".format(ifname)
575 samples[name] = {"rx_throughput_fps": 20,
576 "tx_throughput_fps": 20,
577 "rx_throughput_mbps": 10,
578 "tx_throughput_mbps": 10,
585 r_f_c2544_profile.tmp_throughput = 0
586 self.assertIsNotNone(
587 r_f_c2544_profile.get_drop_percentage(samples, tol_min, tolerance,
590 def test_get_multiplier(self):
591 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
592 r_f_c2544_profile.max_rate = 100
593 r_f_c2544_profile.min_rate = 100
594 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
596 def test_start_ixia_latency(self):
597 traffic_generator = mock.Mock(autospec=TrexProfile)
598 traffic_generator.networks = {
600 "downlink_0": ["xe1"],
602 traffic_generator.client = \
603 mock.Mock(return_value=True)
604 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
605 r_f_c2544_profile.max_rate = 100
606 r_f_c2544_profile.min_rate = 100
607 ixia_obj = mock.MagicMock()
608 r_f_c2544_profile._get_ixia_traffic_profile = \
609 mock.Mock(return_value={})
610 r_f_c2544_profile.full_profile = {}
611 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
614 r_f_c2544_profile.start_ixia_latency(traffic_generator, ixia_obj))
617 if __name__ == '__main__':