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.trex_traffic_profile import \
21 LOG = logging.getLogger(__name__)
24 class IXIARFC2544Profile(TrexProfile):
29 def _get_ixia_traffic_profile(self, profile_data, mac=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)],
70 src_key: ip[src_key].split("-")[0],
71 dst_key: ip[dst_key].split("-")[0],
75 'outer_l4': value['outer_l4'],
82 def _ixia_traffic_generate(self, 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.update_frame(traffic)
87 ixia_obj.add_ip_header(traffic, 4)
88 ixia_obj.ix_start_traffic()
90 self.tmp_throughput = 0
92 def update_traffic_profile(self, traffic_generator):
94 for vld_id, intfs in sorted(traffic_generator.networks.items()):
95 if not vld_id.startswith((self.UPLINK, self.DOWNLINK)):
97 profile_data = self.params.get(vld_id)
100 self.profile_data = profile_data
101 self.get_streams(self.profile_data)
102 self.full_profile.update({vld_id: self.profile_data})
104 yield traffic_generator.vnfd_helper.port_num(intf)
106 self.ports = [port for port in port_generator()]
108 def execute_traffic(self, traffic_generator, ixia_obj, mac=None):
112 self.full_profile = {}
114 self.update_traffic_profile(traffic_generator)
116 self._get_ixia_traffic_profile(self.full_profile, mac)
117 self.max_rate = self.rate
119 self.get_multiplier()
120 self._ixia_traffic_generate(traffic, ixia_obj)
122 def get_multiplier(self):
123 self.rate = round((self.max_rate + self.min_rate) / 2.0, 2)
124 multiplier = round(self.rate / self.pps, 2)
125 return str(multiplier)
127 def start_ixia_latency(self, traffic_generator, ixia_obj, mac=None):
130 self.update_traffic_profile(traffic_generator)
132 self._get_ixia_traffic_profile(self.full_profile, mac)
133 self._ixia_traffic_generate(traffic, ixia_obj)
135 def get_drop_percentage(self, samples, tol_min, tolerance, ixia_obj,
141 in_packets = sum([samples[iface]['in_packets'] for iface in samples])
142 out_packets = sum([samples[iface]['out_packets'] for iface in samples])
144 sum([samples[iface]['RxThroughput'] for iface in samples])
146 sum([samples[iface]['TxThroughput'] for iface in samples])
147 packet_drop = abs(out_packets - in_packets)
149 drop_percent = round((packet_drop / float(out_packets)) * 100, 2)
150 except ZeroDivisionError:
151 LOG.info('No traffic is flowing')
152 samples['TxThroughput'] = round(tx_throughput / 1.0, 2)
153 samples['RxThroughput'] = round(rx_throughput / 1.0, 2)
154 samples['CurrentDropPercentage'] = drop_percent
155 samples['Throughput'] = self.tmp_throughput
156 samples['DropPercentage'] = self.tmp_drop
157 if drop_percent > tolerance and self.tmp_throughput == 0:
158 samples['Throughput'] = round(rx_throughput / 1.0, 2)
159 samples['DropPercentage'] = drop_percent
161 max_supported_rate = out_packets / 30.0
162 self.rate = max_supported_rate
163 self.first_run = False
164 if drop_percent <= tolerance:
166 if drop_percent > tolerance:
167 self.max_rate = self.rate
168 elif drop_percent < tol_min:
169 self.min_rate = self.rate
170 if drop_percent >= self.tmp_drop:
171 self.tmp_drop = drop_percent
172 self.tmp_throughput = round((rx_throughput / 1.0), 2)
173 samples['Throughput'] = round(rx_throughput / 1.0, 2)
174 samples['DropPercentage'] = drop_percent
176 samples['Throughput'] = round(rx_throughput / 1.0, 2)
177 samples['DropPercentage'] = drop_percent
178 return status, samples
179 self.get_multiplier()
180 traffic = self._get_ixia_traffic_profile(self.full_profile, mac)
181 self._ixia_traffic_generate(traffic, ixia_obj)
182 return status, samples