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.
14 """ RFC2544 Throughput implemenation """
16 from __future__ import absolute_import
17 from __future__ import division
20 from yardstick.network_services.traffic_profile.traffic_profile \
23 LOGGING = logging.getLogger(__name__)
26 class RFC2544Profile(TrexProfile):
27 """ This class handles rfc2544 implemenation. """
29 def __init__(self, traffic_generator):
30 super(RFC2544Profile, self).__init__(traffic_generator)
35 self.tmp_throughput = None
36 self.profile_data = None
38 def execute(self, traffic_generator):
39 ''' Generate the stream and run traffic on the given ports '''
41 self.profile_data = self.params.get('private', '')
42 ports = [traffic_generator.my_ports[0]]
43 traffic_generator.client.add_streams(self.get_streams(),
45 profile_data = self.params.get('public', '')
47 self.profile_data = profile_data
48 ports.append(traffic_generator.my_ports[1])
49 traffic_generator.client.add_streams(self.get_streams(),
52 self.max_rate = self.rate
54 traffic_generator.client.start(ports=ports,
55 mult=self.get_multiplier(),
56 duration=30, force=True)
58 self.tmp_throughput = 0
60 def get_multiplier(self):
61 ''' Get the rate at which next iternation to run '''
62 self.rate = round((self.max_rate + self.min_rate) / 2.0, 2)
63 multiplier = round(self.rate / self.pps, 2)
64 return str(multiplier)
66 def get_drop_percentage(self, traffic_generator,
67 samples, tol_min, tolerance):
68 ''' Calculate the drop percentage and run the traffic '''
69 in_packets = sum([samples[iface]['in_packets'] for iface in samples])
70 out_packets = sum([samples[iface]['out_packets'] for iface in samples])
71 packet_drop = abs(out_packets - in_packets)
74 drop_percent = round((packet_drop / float(out_packets)) * 100, 2)
75 except ZeroDivisionError:
76 LOGGING.info('No traffic is flowing')
77 samples['TxThroughput'] = out_packets / 30
78 samples['RxThroughput'] = in_packets / 30
79 samples['CurrentDropPercentage'] = drop_percent
80 samples['Throughput'] = self.tmp_throughput
81 samples['DropPercentage'] = self.tmp_drop
82 if drop_percent > tolerance and self.tmp_throughput == 0:
83 samples['Throughput'] = (in_packets / 30)
84 samples['DropPercentage'] = drop_percent
86 max_supported_rate = out_packets / 30
87 self.rate = max_supported_rate
88 self.first_run = False
89 if drop_percent > tolerance:
90 self.max_rate = self.rate
91 elif drop_percent < tol_min:
92 self.min_rate = self.rate
93 if drop_percent >= self.tmp_drop:
94 self.tmp_drop = drop_percent
95 self.tmp_throughput = (in_packets / 30)
96 samples['Throughput'] = (in_packets / 30)
97 samples['DropPercentage'] = drop_percent
99 samples['Throughput'] = (in_packets / 30)
100 samples['DropPercentage'] = drop_percent
102 traffic_generator.client.clear_stats(ports=traffic_generator.my_ports)
103 traffic_generator.client.start(ports=traffic_generator.my_ports,
104 mult=self.get_multiplier(),
105 duration=30, force=True)