Merge "yardstick setup ansible, including load_images"
[yardstick.git] / tests / unit / network_services / traffic_profile / test_ixia_rfc2544.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016-2017 Intel Corporation
4 #
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
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 #
17
18 from __future__ import absolute_import
19 from __future__ import division
20 import unittest
21 import mock
22
23 STL_MOCKS = {
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(),
81 }
82
83 STLClient = mock.MagicMock()
84 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
85 stl_patch.start()
86
87 if stl_patch:
88     from yardstick.network_services.traffic_profile.traffic_profile \
89         import TrexProfile
90     from yardstick.network_services.traffic_profile.ixia_rfc2544 import \
91         IXIARFC2544Profile
92     from yardstick.network_services.traffic_profile import ixia_rfc2544
93
94
95 class TestIXIARFC2544Profile(unittest.TestCase):
96     TRAFFIC_PROFILE = {
97         "schema": "isb:traffic_profile:0.1",
98         "name": "fixed",
99         "description": "Fixed traffic profile to run UDP traffic",
100         "traffic_profile": {
101             "traffic_type": "FixedTraffic",
102             "frame_rate": 100,  # pps
103             "flow_number": 10,
104             "frame_size": 64}}
105
106     PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
107                'name': 'rfc2544',
108                'traffic_profile': {'traffic_type': 'IXIARFC2544Profile',
109                                    'frame_rate': 100},
110                'public': {'ipv4':
111                           {'outer_l2': {'framesize':
112                                         {'64B': '100', '1518B': '0',
113                                          '128B': '0', '1400B': '0',
114                                          '256B': '0', '373b': '0',
115                                          '570B': '0'}},
116                            'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
117                                           'proto': 'udp',
118                                           'srcip4': '90.90.1.1-90.105.255.255',
119                                           'dscp': 0, 'ttl': 32},
120                            'outer_l4': {'srcport': '2001',
121                                         'dsrport': '1234'}}},
122                'private': {'ipv4':
123                            {'outer_l2': {'framesize':
124                                          {'64B': '100', '1518B': '0',
125                                           '128B': '0', '1400B': '0',
126                                           '256B': '0', '373b': '0',
127                                           '570B': '0'}},
128                             'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
129                                            'proto': 'udp',
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'}
135
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)
143         STATIC_TRAFFIC = {
144             "private": {
145                 "id": 1,
146                 "bidir": "False",
147                 "duration": 60,
148                 "iload": "100",
149                 "outer_l2": {
150                     "dstmac": "00:00:00:00:00:03",
151                     "framesPerSecond": True,
152                     "framesize": 64,
153                     "srcmac": "00:00:00:00:00:01"
154                 },
155                 "outer_l3": {
156                     "dscp": 0,
157                     "dstip4": "152.16.40.20",
158                     "proto": "udp",
159                     "srcip4": "152.16.100.20",
160                     "ttl": 32
161                 },
162                 "outer_l3v4": {
163                     "dscp": 0,
164                     "dstip4": "152.16.40.20",
165                     "proto": "udp",
166                     "srcip4": "152.16.100.20",
167                     "ttl": 32
168                 },
169                 "outer_l3v6": {
170                     "count": 1024,
171                     "dscp": 0,
172                     "dstip4": "152.16.100.20",
173                     "proto": "udp",
174                     "srcip4": "152.16.40.20",
175                     "ttl": 32
176                 },
177                 "outer_l4": {
178                     "dstport": "2001",
179                     "srcport": "1234"
180                 },
181                 "traffic_type": "continuous"
182             },
183             "public": {
184                 "id": 2,
185                 "bidir": "False",
186                 "duration": 60,
187                 "iload": "100",
188                 "outer_l2": {
189                     "dstmac": "00:00:00:00:00:04",
190                     "framesPerSecond": True,
191                     "framesize": 64,
192                     "srcmac": "00:00:00:00:00:01"
193                 },
194                 "outer_l3": {
195                     "count": 1024,
196                     "dscp": 0,
197                     "dstip4": "152.16.100.20",
198                     "proto": "udp",
199                     "srcip4": "152.16.40.20",
200                     "ttl": 32
201                 },
202                 "outer_l3v4": {
203                     "count": 1024,
204                     "dscp": 0,
205                     "dstip4": "152.16.100.20",
206                     "proto": "udp",
207                     "srcip4": "152.16.40.20",
208                     "ttl": 32
209                 },
210                 "outer_l3v6": {
211                     "count": 1024,
212                     "dscp": 0,
213                     "dstip4": "152.16.100.20",
214                     "proto": "udp",
215                     "srcip4": "152.16.40.20",
216                     "ttl": 32
217                 },
218                 "outer_l4": {
219                     "dstport": "1234",
220                     "srcport": "2001"
221                 },
222                 "traffic_type": "continuous"
223             }
224         }
225         ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
226
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)
238
239
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)
248         STATIC_TRAFFIC = {
249             "private": {
250                 "id": 1,
251                 "bidir": "False",
252                 "duration": 60,
253                 "iload": "100",
254                 "outer_l2": {
255                     "dstmac": "00:00:00:00:00:03",
256                     "framesPerSecond": True,
257                     "framesize": 64,
258                     "srcmac": "00:00:00:00:00:01"
259                 },
260                 "outer_l3": {
261                     "dscp": 0,
262                     "dstip4": "152.16.40.20",
263                     "proto": "udp",
264                     "srcip4": "152.16.100.20",
265                     "ttl": 32
266                 },
267                 "outer_l3v4": {
268                     "dscp": 0,
269                     "dstip4": "152.16.40.20",
270                     "proto": "udp",
271                     "srcip4": "152.16.100.20",
272                     "ttl": 32
273                 },
274                 "outer_l3v6": {
275                     "count": 1024,
276                     "dscp": 0,
277                     "dstip4": "152.16.100.20",
278                     "proto": "udp",
279                     "srcip4": "152.16.40.20",
280                     "ttl": 32
281                 },
282                 "outer_l4": {
283                     "dstport": "2001",
284                     "srcport": "1234"
285                 },
286                 "traffic_type": "continuous"
287             },
288             "public": {
289                 "id": 2,
290                 "bidir": "False",
291                 "duration": 60,
292                 "iload": "100",
293                 "outer_l2": {
294                     "dstmac": "00:00:00:00:00:04",
295                     "framesPerSecond": True,
296                     "framesize": 64,
297                     "srcmac": "00:00:00:00:00:01"
298                 },
299                 "outer_l3": {
300                     "count": 1024,
301                     "dscp": 0,
302                     "dstip4": "152.16.100.20",
303                     "proto": "udp",
304                     "srcip4": "152.16.40.20",
305                     "ttl": 32
306                 },
307                 "outer_l3v4": {
308                     "count": 1024,
309                     "dscp": 0,
310                     "dstip4": "152.16.100.20",
311                     "proto": "udp",
312                     "srcip4": "152.16.40.20",
313                     "ttl": 32
314                 },
315                 "outer_l3v6": {
316                     "count": 1024,
317                     "dscp": 0,
318                     "dstip4": "152.16.100.20",
319                     "proto": "udp",
320                     "srcip4": "152.16.40.20",
321                     "ttl": 32
322                 },
323                 "outer_l4": {
324                     "dstport": "1234",
325                     "srcport": "2001"
326                 },
327                 "traffic_type": "continuous"
328             }
329         }
330         ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
331
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)
343
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)
352         STATIC_TRAFFIC = {
353             "private": {
354                 "id": 1,
355                 "bidir": "False",
356                 "duration": 60,
357                 "iload": "100",
358                 "outer_l2": {
359                     "dstmac": "00:00:00:00:00:03",
360                     "framesPerSecond": True,
361                     "framesize": 64,
362                     "srcmac": "00:00:00:00:00:01"
363                 },
364                 "outer_l3": {
365                     "dscp": 0,
366                     "dstip4": "152.16.40.20",
367                     "proto": "udp",
368                     "srcip4": "152.16.100.20",
369                     "ttl": 32
370                 },
371                 "outer_l3v4": {
372                     "dscp": 0,
373                     "dstip4": "152.16.40.20",
374                     "proto": "udp",
375                     "srcip4": "152.16.100.20",
376                     "ttl": 32
377                 },
378                 "outer_l3v6": {
379                     "count": 1024,
380                     "dscp": 0,
381                     "dstip4": "152.16.100.20",
382                     "proto": "udp",
383                     "srcip4": "152.16.40.20",
384                     "ttl": 32
385                 },
386                 "outer_l4": {
387                     "dstport": "2001",
388                     "srcport": "1234"
389                 },
390                 "traffic_type": "continuous"
391             },
392             "public": {
393                 "id": 2,
394                 "bidir": "False",
395                 "duration": 60,
396                 "iload": "100",
397                 "outer_l2": {
398                     "dstmac": "00:00:00:00:00:04",
399                     "framesPerSecond": True,
400                     "framesize": 64,
401                     "srcmac": "00:00:00:00:00:01"
402                 },
403                 "outer_l3": {
404                     "count": 1024,
405                     "dscp": 0,
406                     "dstip4": "152.16.100.20",
407                     "proto": "udp",
408                     "srcip4": "152.16.40.20",
409                     "ttl": 32
410                 },
411                 "outer_l3v4": {
412                     "count": 1024,
413                     "dscp": 0,
414                     "dstip4": "152.16.100.20",
415                     "proto": "udp",
416                     "srcip4": "152.16.40.20",
417                     "ttl": 32
418                 },
419                 "outer_l3v6": {
420                     "count": 1024,
421                     "dscp": 0,
422                     "dstip4": "152.16.100.20",
423                     "proto": "udp",
424                     "srcip4": "152.16.40.20",
425                     "ttl": 32
426                 },
427                 "outer_l4": {
428                     "dstport": "1234",
429                     "srcport": "2001"
430                 },
431                 "traffic_type": "continuous"
432             }
433         }
434         ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
435
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',
445                         'name': 'rfc2544',
446                         'traffic_profile':
447                         {'traffic_type': 'IXIARFC2544Profile',
448                          'frame_rate': 100},
449                         'public':
450                         {'ipv4':
451                          {'outer_l2': {'framesize':
452                                        {'64B': '100', '1518B': '0',
453                                         '128B': '0', '1400B': '0',
454                                         '256B': '0', '373b': '0',
455                                         '570B': '0'}},
456                           'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
457                                          'proto': 'udp',
458                                          'srcip6': '90.90.1.1-90.105.255.255',
459                                          'dscp': 0, 'ttl': 32},
460                           'outer_l4': {'srcport': '2001',
461                                        'dsrport': '1234'}}},
462                         'private': {'ipv4':
463                                     {'outer_l2': {'framesize':
464                                                   {'64B': '100', '1518B': '0',
465                                                    '128B': '0', '1400B': '0',
466                                                    '256B': '0', '373b': '0',
467                                                    '570B': '0'}},
468                                      'outer_l3v6':
469                                      {'dstip6': '9.9.1.1-90.105.255.255',
470                                       'proto': 'udp',
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)
479
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,
493                                                           traffic, ixia_obj)
494         self.assertIsNone(result)
495
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}}
507
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,
515                                                          ixia_obj))
516
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 = {}
534         samples = {}
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,
541                              "RxThroughput": 10,
542                              "TxThroughput": 10,
543                              "in_packets": 1000,
544                              "out_packets": 1000}
545         tol_min = 100.0
546         tolerance = 0.0
547         self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
548                              traffic_generator, samples,
549                              tol_min, tolerance, ixia_obj))
550
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 = {}
568         samples = {}
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,
575                              "RxThroughput": 10,
576                              "TxThroughput": 10,
577                              "in_packets": 1000,
578                              "out_packets": 1002}
579         tol_min = 0.0
580         tolerance = 1.0
581         self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage(
582                              traffic_generator, samples,
583                              tol_min, tolerance, ixia_obj))
584
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 = {}
602         samples = {}
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,
609                              "RxThroughput": 10,
610                              "TxThroughput": 10,
611                              "in_packets": 1000,
612                              "out_packets": 0}
613         tol_min = 0.0
614         tolerance = 0.0
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))
619
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())
625
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()
641         self.assertEqual(
642             None,
643             r_f_c2544_profile.start_ixia_latency(traffic_generator,
644                                                  ixia_obj))
645
646
647 if __name__ == '__main__':
648     unittest.main()