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