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
24 'stl': mock.MagicMock(),
25 'stl.trex_stl_lib': mock.MagicMock(),
26 'stl.trex_stl_lib.base64': mock.MagicMock(),
27 'stl.trex_stl_lib.binascii': mock.MagicMock(),
28 'stl.trex_stl_lib.collections': mock.MagicMock(),
29 'stl.trex_stl_lib.copy': mock.MagicMock(),
30 'stl.trex_stl_lib.datetime': mock.MagicMock(),
31 'stl.trex_stl_lib.functools': mock.MagicMock(),
32 'stl.trex_stl_lib.imp': mock.MagicMock(),
33 'stl.trex_stl_lib.inspect': mock.MagicMock(),
34 'stl.trex_stl_lib.json': mock.MagicMock(),
35 'stl.trex_stl_lib.linecache': mock.MagicMock(),
36 'stl.trex_stl_lib.math': mock.MagicMock(),
37 'stl.trex_stl_lib.os': mock.MagicMock(),
38 'stl.trex_stl_lib.platform': mock.MagicMock(),
39 'stl.trex_stl_lib.pprint': mock.MagicMock(),
40 'stl.trex_stl_lib.random': mock.MagicMock(),
41 'stl.trex_stl_lib.re': mock.MagicMock(),
42 'stl.trex_stl_lib.scapy': mock.MagicMock(),
43 'stl.trex_stl_lib.socket': mock.MagicMock(),
44 'stl.trex_stl_lib.string': mock.MagicMock(),
45 'stl.trex_stl_lib.struct': mock.MagicMock(),
46 'stl.trex_stl_lib.sys': mock.MagicMock(),
47 'stl.trex_stl_lib.threading': mock.MagicMock(),
48 'stl.trex_stl_lib.time': mock.MagicMock(),
49 'stl.trex_stl_lib.traceback': mock.MagicMock(),
50 'stl.trex_stl_lib.trex_stl_async_client': mock.MagicMock(),
51 'stl.trex_stl_lib.trex_stl_client': mock.MagicMock(),
52 'stl.trex_stl_lib.trex_stl_exceptions': mock.MagicMock(),
53 'stl.trex_stl_lib.trex_stl_ext': mock.MagicMock(),
54 'stl.trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(),
55 'stl.trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(),
56 'stl.trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(),
57 'stl.trex_stl_lib.trex_stl_port': mock.MagicMock(),
58 'stl.trex_stl_lib.trex_stl_stats': mock.MagicMock(),
59 'stl.trex_stl_lib.trex_stl_streams': mock.MagicMock(),
60 'stl.trex_stl_lib.trex_stl_types': mock.MagicMock(),
61 'stl.trex_stl_lib.types': mock.MagicMock(),
62 'stl.trex_stl_lib.utils': mock.MagicMock(),
63 'stl.trex_stl_lib.utils.argparse': mock.MagicMock(),
64 'stl.trex_stl_lib.utils.collections': mock.MagicMock(),
65 'stl.trex_stl_lib.utils.common': mock.MagicMock(),
66 'stl.trex_stl_lib.utils.json': mock.MagicMock(),
67 'stl.trex_stl_lib.utils.os': mock.MagicMock(),
68 'stl.trex_stl_lib.utils.parsing_opts': mock.MagicMock(),
69 'stl.trex_stl_lib.utils.pwd': mock.MagicMock(),
70 'stl.trex_stl_lib.utils.random': mock.MagicMock(),
71 'stl.trex_stl_lib.utils.re': mock.MagicMock(),
72 'stl.trex_stl_lib.utils.string': mock.MagicMock(),
73 'stl.trex_stl_lib.utils.sys': mock.MagicMock(),
74 'stl.trex_stl_lib.utils.text_opts': mock.MagicMock(),
75 'stl.trex_stl_lib.utils.text_tables': mock.MagicMock(),
76 'stl.trex_stl_lib.utils.texttable': mock.MagicMock(),
77 'stl.trex_stl_lib.warnings': mock.MagicMock(),
78 'stl.trex_stl_lib.yaml': mock.MagicMock(),
79 'stl.trex_stl_lib.zlib': mock.MagicMock(),
80 'stl.trex_stl_lib.zmq': mock.MagicMock(),
83 STLClient = mock.MagicMock()
84 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
88 from yardstick.network_services.traffic_profile.traffic_profile \
90 from yardstick.network_services.traffic_profile.ixia_rfc2544 import \
92 from yardstick.network_services.traffic_profile import ixia_rfc2544
95 class TestIXIARFC2544Profile(unittest.TestCase):
97 "schema": "isb:traffic_profile:0.1",
99 "description": "Fixed traffic profile to run UDP traffic",
101 "traffic_type": "FixedTraffic",
102 "frame_rate": 100, # pps
106 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
108 'traffic_profile': {'traffic_type': 'IXIARFC2544Profile',
111 {'outer_l2': {'framesize':
112 {'64B': '100', '1518B': '0',
113 '128B': '0', '1400B': '0',
114 '256B': '0', '373b': '0',
116 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
118 'srcip4': '90.90.1.1-90.105.255.255',
119 'dscp': 0, 'ttl': 32},
120 'outer_l4': {'srcport': '2001',
121 'dsrport': '1234'}}},
123 {'outer_l2': {'framesize':
124 {'64B': '100', '1518B': '0',
125 '128B': '0', '1400B': '0',
126 '256B': '0', '373b': '0',
128 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
130 'srcip4': '1.1.1.1-1.15.255.255',
131 'dscp': 0, 'ttl': 32},
132 'outer_l4': {'dstport': '2001',
133 'srcport': '1234'}}},
134 'schema': 'isb:traffic_profile:0.1'}
136 def test_get_ixia_traffic_profile_error(self):
137 traffic_generator = mock.Mock(autospec=TrexProfile)
138 traffic_generator.my_ports = [0, 1]
139 traffic_generator.priv_ports = [-1]
140 traffic_generator.pub_ports = [1]
141 traffic_generator.client = \
142 mock.Mock(return_value=True)
150 "dstmac": "00:00:00:00:00:03",
151 "framesPerSecond": True,
153 "srcmac": "00:00:00:00:00:01"
157 "dstip4": "152.16.40.20",
159 "srcip4": "152.16.100.20",
164 "dstip4": "152.16.40.20",
166 "srcip4": "152.16.100.20",
172 "dstip4": "152.16.100.20",
174 "srcip4": "152.16.40.20",
181 "traffic_type": "continuous"
189 "dstmac": "00:00:00:00:00:04",
190 "framesPerSecond": True,
192 "srcmac": "00:00:00:00:00:01"
197 "dstip4": "152.16.100.20",
199 "srcip4": "152.16.40.20",
205 "dstip4": "152.16.100.20",
207 "srcip4": "152.16.40.20",
213 "dstip4": "152.16.100.20",
215 "srcip4": "152.16.40.20",
222 "traffic_type": "continuous"
225 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
227 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
228 r_f_c2544_profile.rate = 100
229 mac = {"src_mac_0": "00:00:00:00:00:01",
230 "src_mac_1": "00:00:00:00:00:02",
231 "src_mac_2": "00:00:00:00:00:02",
232 "dst_mac_0": "00:00:00:00:00:03",
233 "dst_mac_1": "00:00:00:00:00:04",
234 "dst_mac_2": "00:00:00:00:00:04"}
235 self.assertRaises(IOError, r_f_c2544_profile._get_ixia_traffic_profile,
236 self.PROFILE, mac, xfile="tmp",
237 static_traffic=STATIC_TRAFFIC)
240 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
241 def test_get_ixia_traffic_profile(self, mock_open):
242 traffic_generator = mock.Mock(autospec=TrexProfile)
243 traffic_generator.my_ports = [0, 1]
244 traffic_generator.priv_ports = [-1]
245 traffic_generator.pub_ports = [1]
246 traffic_generator.client = \
247 mock.Mock(return_value=True)
255 "dstmac": "00:00:00:00:00:03",
256 "framesPerSecond": True,
258 "srcmac": "00:00:00:00:00:01"
262 "dstip4": "152.16.40.20",
264 "srcip4": "152.16.100.20",
269 "dstip4": "152.16.40.20",
271 "srcip4": "152.16.100.20",
277 "dstip4": "152.16.100.20",
279 "srcip4": "152.16.40.20",
286 "traffic_type": "continuous"
294 "dstmac": "00:00:00:00:00:04",
295 "framesPerSecond": True,
297 "srcmac": "00:00:00:00:00:01"
302 "dstip4": "152.16.100.20",
304 "srcip4": "152.16.40.20",
310 "dstip4": "152.16.100.20",
312 "srcip4": "152.16.40.20",
318 "dstip4": "152.16.100.20",
320 "srcip4": "152.16.40.20",
327 "traffic_type": "continuous"
330 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
332 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
333 r_f_c2544_profile.rate = 100
334 mac = {"src_mac_0": "00:00:00:00:00:01",
335 "src_mac_1": "00:00:00:00:00:02",
336 "src_mac_2": "00:00:00:00:00:02",
337 "dst_mac_0": "00:00:00:00:00:03",
338 "dst_mac_1": "00:00:00:00:00:04",
339 "dst_mac_2": "00:00:00:00:00:04"}
340 result = r_f_c2544_profile._get_ixia_traffic_profile(
341 self.PROFILE, mac, xfile="tmp", static_traffic=STATIC_TRAFFIC)
342 self.assertIsNotNone(result)
344 @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
345 def test_get_ixia_traffic_profile_v6(self, mock_open):
346 traffic_generator = mock.Mock(autospec=TrexProfile)
347 traffic_generator.my_ports = [0, 1]
348 traffic_generator.priv_ports = [-1]
349 traffic_generator.pub_ports = [1]
350 traffic_generator.client = \
351 mock.Mock(return_value=True)
359 "dstmac": "00:00:00:00:00:03",
360 "framesPerSecond": True,
362 "srcmac": "00:00:00:00:00:01"
366 "dstip4": "152.16.40.20",
368 "srcip4": "152.16.100.20",
373 "dstip4": "152.16.40.20",
375 "srcip4": "152.16.100.20",
381 "dstip4": "152.16.100.20",
383 "srcip4": "152.16.40.20",
390 "traffic_type": "continuous"
398 "dstmac": "00:00:00:00:00:04",
399 "framesPerSecond": True,
401 "srcmac": "00:00:00:00:00:01"
406 "dstip4": "152.16.100.20",
408 "srcip4": "152.16.40.20",
414 "dstip4": "152.16.100.20",
416 "srcip4": "152.16.40.20",
422 "dstip4": "152.16.100.20",
424 "srcip4": "152.16.40.20",
431 "traffic_type": "continuous"
434 ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
436 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
437 r_f_c2544_profile.rate = 100
438 mac = {"src_mac_0": "00:00:00:00:00:01",
439 "src_mac_1": "00:00:00:00:00:02",
440 "src_mac_2": "00:00:00:00:00:02",
441 "dst_mac_0": "00:00:00:00:00:03",
442 "dst_mac_1": "00:00:00:00:00:04",
443 "dst_mac_2": "00:00:00:00:00:04"}
444 profile_data = {'description': 'Traffic profile to run RFC2544',
447 {'traffic_type': 'IXIARFC2544Profile',
451 {'outer_l2': {'framesize':
452 {'64B': '100', '1518B': '0',
453 '128B': '0', '1400B': '0',
454 '256B': '0', '373b': '0',
456 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
458 'srcip6': '90.90.1.1-90.105.255.255',
459 'dscp': 0, 'ttl': 32},
460 'outer_l4': {'srcport': '2001',
461 'dsrport': '1234'}}},
463 {'outer_l2': {'framesize':
464 {'64B': '100', '1518B': '0',
465 '128B': '0', '1400B': '0',
466 '256B': '0', '373b': '0',
469 {'dstip6': '9.9.1.1-90.105.255.255',
471 'srcip6': '1.1.1.1-1.15.255.255',
472 'dscp': 0, 'ttl': 32},
473 'outer_l4': {'dstport': '2001',
474 'srcport': '1234'}}},
475 'schema': 'isb:traffic_profile:0.1'}
476 result = r_f_c2544_profile._get_ixia_traffic_profile(
477 profile_data, mac, static_traffic=STATIC_TRAFFIC)
478 self.assertIsNotNone(result)
480 def test__ixia_traffic_generate(self):
481 traffic_generator = mock.Mock(autospec=TrexProfile)
482 traffic_generator.my_ports = [0, 1]
483 traffic_generator.priv_ports = [-1]
484 traffic_generator.pub_ports = [1]
485 traffic_generator.client = \
486 mock.Mock(return_value=True)
487 traffic = {"public": {'iload': 10},
488 "private": {'iload': 10}}
489 ixia_obj = mock.MagicMock()
490 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
491 r_f_c2544_profile.rate = 100
492 result = r_f_c2544_profile._ixia_traffic_generate(traffic_generator,
494 self.assertIsNone(result)
496 def test_execute(self):
497 traffic_generator = mock.Mock(autospec=TrexProfile)
498 traffic_generator.my_ports = [0, 1]
499 traffic_generator.priv_ports = [-1]
500 traffic_generator.pub_ports = [1]
501 traffic_generator.client = \
502 mock.Mock(return_value=True)
503 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
504 r_f_c2544_profile.first_run = True
505 r_f_c2544_profile.params = {"public": {'iload': 10},
506 "private": {'iload': 10}}
508 r_f_c2544_profile.get_streams = mock.Mock()
509 r_f_c2544_profile.full_profile = {}
510 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
511 r_f_c2544_profile.get_multiplier = mock.Mock()
512 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
513 ixia_obj = mock.MagicMock()
514 self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator,
517 def test_get_drop_percentage(self):
518 traffic_generator = mock.Mock(autospec=TrexProfile)
519 traffic_generator.my_ports = [0, 1]
520 traffic_generator.priv_ports = [0]
521 traffic_generator.pub_ports = [1]
522 traffic_generator.client = \
523 mock.Mock(return_value=True)
524 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
525 r_f_c2544_profile.params = self.PROFILE
526 ixia_obj = mock.MagicMock()
527 r_f_c2544_profile.execute = mock.Mock()
528 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
529 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
530 r_f_c2544_profile.get_multiplier = mock.Mock()
531 r_f_c2544_profile.tmp_throughput = 0
532 r_f_c2544_profile.tmp_drop = 0
533 r_f_c2544_profile.full_profile = {}
535 for ifname in range(1):
536 name = "xe{}".format(ifname)
537 samples[name] = {"rx_throughput_fps": 20,
538 "tx_throughput_fps": 20,
539 "rx_throughput_mbps": 10,
540 "tx_throughput_mbps": 10,
547 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
548 traffic_generator, samples,
549 tol_min, tolerance, ixia_obj))
551 def test_get_drop_percentage_update(self):
552 traffic_generator = mock.Mock(autospec=TrexProfile)
553 traffic_generator.my_ports = [0, 1]
554 traffic_generator.priv_ports = [0]
555 traffic_generator.pub_ports = [1]
556 traffic_generator.client = \
557 mock.Mock(return_value=True)
558 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
559 r_f_c2544_profile.params = self.PROFILE
560 ixia_obj = mock.MagicMock()
561 r_f_c2544_profile.execute = mock.Mock()
562 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
563 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
564 r_f_c2544_profile.get_multiplier = mock.Mock()
565 r_f_c2544_profile.tmp_throughput = 0
566 r_f_c2544_profile.tmp_drop = 0
567 r_f_c2544_profile.full_profile = {}
569 for ifname in range(1):
570 name = "xe{}".format(ifname)
571 samples[name] = {"rx_throughput_fps": 20,
572 "tx_throughput_fps": 20,
573 "rx_throughput_mbps": 10,
574 "tx_throughput_mbps": 10,
581 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
582 traffic_generator, samples,
583 tol_min, tolerance, ixia_obj))
585 def test_get_drop_percentage_div_zero(self):
586 traffic_generator = mock.Mock(autospec=TrexProfile)
587 traffic_generator.my_ports = [0, 1]
588 traffic_generator.priv_ports = [0]
589 traffic_generator.pub_ports = [1]
590 traffic_generator.client = \
591 mock.Mock(return_value=True)
592 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
593 r_f_c2544_profile.params = self.PROFILE
594 ixia_obj = mock.MagicMock()
595 r_f_c2544_profile.execute = mock.Mock()
596 r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock()
597 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
598 r_f_c2544_profile.get_multiplier = mock.Mock()
599 r_f_c2544_profile.tmp_throughput = 0
600 r_f_c2544_profile.tmp_drop = 0
601 r_f_c2544_profile.full_profile = {}
603 for ifname in range(1):
604 name = "xe{}".format(ifname)
605 samples[name] = {"rx_throughput_fps": 20,
606 "tx_throughput_fps": 20,
607 "rx_throughput_mbps": 10,
608 "tx_throughput_mbps": 10,
615 r_f_c2544_profile.tmp_throughput = 0
616 self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
617 traffic_generator, samples,
618 tol_min, tolerance, ixia_obj))
620 def test_get_multiplier(self):
621 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
622 r_f_c2544_profile.max_rate = 100
623 r_f_c2544_profile.min_rate = 100
624 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
626 def test_start_ixia_latency(self):
627 traffic_generator = mock.Mock(autospec=TrexProfile)
628 traffic_generator.my_ports = [0, 1]
629 traffic_generator.priv_ports = [0]
630 traffic_generator.pub_ports = [1]
631 traffic_generator.client = \
632 mock.Mock(return_value=True)
633 r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE)
634 r_f_c2544_profile.max_rate = 100
635 r_f_c2544_profile.min_rate = 100
636 ixia_obj = mock.MagicMock()
637 r_f_c2544_profile._get_ixia_traffic_profile = \
638 mock.Mock(return_value={})
639 r_f_c2544_profile.full_profile = {}
640 r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
643 r_f_c2544_profile.start_ixia_latency(traffic_generator,
647 if __name__ == '__main__':