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.
15 from __future__ import absolute_import
18 from yardstick.network_services.traffic_profile.traffic_profile import \
21 LOG = logging.getLogger(__name__)
24 class IXIARFC2544Profile(TrexProfile):
29 def _get_ixia_traffic_profile(self, profile_data, mac=None, xfile=None, static_traffic=None):
34 for traffickey, values in profile_data.items():
35 if not traffickey.startswith((self.UPLINK, self.DOWNLINK)):
39 # values should be single-item dict, so just grab the first item
41 key, value = next(iter(values.items()))
43 result[traffickey] = {}
46 port_id = value.get('id', 1)
47 port_index = port_id - 1
49 ip = value['outer_l3v6']
51 ip = value['outer_l3v4']
52 src_key, dst_key = 'srcip4', 'dstip4'
54 src_key, dst_key = 'srcip6', 'dstip6'
56 result[traffickey] = {
61 'framesize': value['outer_l2']['framesize'],
62 'framesPerSecond': True,
63 'srcmac': mac['src_mac_{}'.format(port_index)],
64 'dstmac': mac['dst_mac_{}'.format(port_index)],
75 'outer_l4': value['outer_l4'],
82 def _ixia_traffic_generate(self, traffic_generator, traffic, ixia_obj):
83 for key, value in traffic.items():
84 if key.startswith((self.UPLINK, self.DOWNLINK)):
85 value["iload"] = str(self.rate)
86 ixia_obj.ix_update_frame(traffic)
87 ixia_obj.ix_update_ether(traffic)
88 ixia_obj.add_ip_header(traffic, 4)
89 ixia_obj.ix_start_traffic()
91 self.tmp_throughput = 0
93 def update_traffic_profile(self, traffic_generator):
95 for vld_id, intfs in sorted(traffic_generator.networks.items()):
96 if not vld_id.startswith((self.UPLINK, self.DOWNLINK)):
98 profile_data = self.params.get(vld_id)
101 self.profile_data = profile_data
102 self.get_streams(self.profile_data)
103 self.full_profile.update({vld_id: self.profile_data})
105 yield traffic_generator.vnfd_helper.port_num(intf)
107 self.ports = [port for port in port_generator()]
109 def execute_traffic(self, traffic_generator, ixia_obj, mac=None, xfile=None):
113 self.full_profile = {}
115 self.update_traffic_profile(traffic_generator)
117 self._get_ixia_traffic_profile(self.full_profile, mac, xfile)
118 self.max_rate = self.rate
120 self.get_multiplier()
121 self._ixia_traffic_generate(traffic_generator, traffic, ixia_obj)
123 def get_multiplier(self):
124 self.rate = round((self.max_rate + self.min_rate) / 2.0, 2)
125 multiplier = round(self.rate / self.pps, 2)
126 return str(multiplier)
128 def start_ixia_latency(self, traffic_generator, ixia_obj,
129 mac=None, xfile=None):
132 self.update_traffic_profile(traffic_generator)
134 self._get_ixia_traffic_profile(self.full_profile, mac, xfile)
135 self._ixia_traffic_generate(traffic_generator, traffic, ixia_obj)
137 def get_drop_percentage(self, traffic_generator, samples, tol_min,
138 tolerance, ixia_obj, mac=None, xfile=None):
143 in_packets = sum([samples[iface]['in_packets'] for iface in samples])
144 out_packets = sum([samples[iface]['out_packets'] for iface in samples])
146 sum([samples[iface]['RxThroughput'] for iface in samples])
148 sum([samples[iface]['TxThroughput'] for iface in samples])
149 packet_drop = abs(out_packets - in_packets)
151 drop_percent = round((packet_drop / float(out_packets)) * 100, 2)
152 except ZeroDivisionError:
153 LOG.info('No traffic is flowing')
154 samples['TxThroughput'] = round(tx_throughput / 1.0, 2)
155 samples['RxThroughput'] = round(rx_throughput / 1.0, 2)
156 samples['CurrentDropPercentage'] = drop_percent
157 samples['Throughput'] = self.tmp_throughput
158 samples['DropPercentage'] = self.tmp_drop
159 if drop_percent > tolerance and self.tmp_throughput == 0:
160 samples['Throughput'] = round(rx_throughput / 1.0, 2)
161 samples['DropPercentage'] = drop_percent
163 max_supported_rate = out_packets / 30.0
164 self.rate = max_supported_rate
165 self.first_run = False
166 if drop_percent <= tolerance:
168 if drop_percent > tolerance:
169 self.max_rate = self.rate
170 elif drop_percent < tol_min:
171 self.min_rate = self.rate
172 if drop_percent >= self.tmp_drop:
173 self.tmp_drop = drop_percent
174 self.tmp_throughput = round((rx_throughput / 1.0), 2)
175 samples['Throughput'] = round(rx_throughput / 1.0, 2)
176 samples['DropPercentage'] = drop_percent
178 samples['Throughput'] = round(rx_throughput / 1.0, 2)
179 samples['DropPercentage'] = drop_percent
180 return status, samples
181 self.get_multiplier()
182 traffic = self._get_ixia_traffic_profile(self.full_profile, mac, xfile)
183 self._ixia_traffic_generate(traffic_generator, traffic, ixia_obj)
184 return status, samples