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.
17 from yardstick.common import utils
18 from yardstick.network_services.traffic_profile import base as tp_base
19 from yardstick.network_services.traffic_profile import trex_traffic_profile
22 LOG = logging.getLogger(__name__)
25 class IXIARFC2544Profile(trex_traffic_profile.TrexProfile):
29 DROP_PERCENT_ROUND = 6
32 def __init__(self, yaml_data):
33 super(IXIARFC2544Profile, self).__init__(yaml_data)
34 self.rate = self.config.frame_rate
35 self.rate_unit = self.config.rate_unit
37 def _get_ip_and_mask(self, ip_range):
38 _ip_range = ip_range.split('-')
39 if len(_ip_range) == 1:
40 return _ip_range[0], None
42 mask = utils.get_mask_from_ip_range(_ip_range[0], _ip_range[1])
43 return _ip_range[0], mask
45 def _get_fixed_and_mask(self, port_range):
46 _port_range = str(port_range).split('-')
47 if len(_port_range) == 1:
48 return int(_port_range[0]), 0
50 return int(_port_range[0]), int(_port_range[1])
52 def _get_ixia_traffic_profile(self, profile_data, mac=None):
53 mac = {} if mac is None else mac
55 for traffickey, values in profile_data.items():
56 if not traffickey.startswith((self.UPLINK, self.DOWNLINK)):
59 # values should be single-item dict, so just grab the first item
61 key, value = next(iter(values.items()))
63 result[traffickey] = {}
66 port_id = value.get('id', 1)
67 port_index = port_id - 1
69 result[traffickey] = {
73 'rate_unit': self.rate_unit,
79 outer_l2 = value.get('outer_l2')
81 result[traffickey]['outer_l2'].update({
82 'framesize': outer_l2.get('framesize'),
83 'framesPerSecond': True,
84 'QinQ': outer_l2.get('QinQ'),
85 'srcmac': mac.get('src_mac_{}'.format(port_index)),
86 'dstmac': mac.get('dst_mac_{}'.format(port_index)),
89 if value.get('outer_l3v4'):
90 outer_l3 = value['outer_l3v4']
91 src_key, dst_key = 'srcip4', 'dstip4'
93 outer_l3 = value.get('outer_l3v6')
94 src_key, dst_key = 'srcip6', 'dstip6'
96 srcip = srcmask = dstip = dstmask = None
97 if outer_l3.get(src_key):
98 srcip, srcmask = self._get_ip_and_mask(outer_l3[src_key])
99 if outer_l3.get(dst_key):
100 dstip, dstmask = self._get_ip_and_mask(outer_l3[dst_key])
102 result[traffickey]['outer_l3'].update({
103 'count': outer_l3.get('count', 1),
104 'dscp': outer_l3.get('dscp'),
105 'ttl': outer_l3.get('ttl'),
106 'srcseed': outer_l3.get('srcseed', 1),
107 'dstseed': outer_l3.get('dstseed', 1),
113 'proto': outer_l3.get('proto'),
114 'priority': outer_l3.get('priority')
117 outer_l4 = value.get('outer_l4')
119 src_port = src_port_mask = dst_port = dst_port_mask = None
120 if outer_l4.get('srcport'):
121 src_port, src_port_mask = (
122 self._get_fixed_and_mask(outer_l4['srcport']))
124 if outer_l4.get('dstport'):
125 dst_port, dst_port_mask = (
126 self._get_fixed_and_mask(outer_l4['dstport']))
128 result[traffickey]['outer_l4'].update({
131 'srcportmask': src_port_mask,
132 'dstportmask': dst_port_mask,
133 'count': outer_l4.get('count', 1),
134 'seed': outer_l4.get('seed', 1),
139 def _ixia_traffic_generate(self, traffic, ixia_obj):
140 ixia_obj.update_frame(traffic, self.config.duration)
141 ixia_obj.update_ip_packet(traffic)
142 ixia_obj.update_l4(traffic)
143 ixia_obj.start_traffic()
145 def update_traffic_profile(self, traffic_generator):
146 def port_generator():
147 for vld_id, intfs in sorted(traffic_generator.networks.items()):
148 if not vld_id.startswith((self.UPLINK, self.DOWNLINK)):
150 profile_data = self.params.get(vld_id)
153 self.profile_data = profile_data
154 self.full_profile.update({vld_id: self.profile_data})
156 yield traffic_generator.vnfd_helper.port_num(intf)
158 self.ports = [port for port in port_generator()]
160 def execute_traffic(self, traffic_generator, ixia_obj=None, mac=None):
161 mac = {} if mac is None else mac
162 first_run = self.first_run
164 self.first_run = False
165 self.full_profile = {}
167 self.update_traffic_profile(traffic_generator)
168 self.max_rate = self.rate
171 self.rate = round(float(self.max_rate + self.min_rate) / 2.0,
174 traffic = self._get_ixia_traffic_profile(self.full_profile, mac)
175 self._ixia_traffic_generate(traffic, ixia_obj)
178 def get_drop_percentage(self, samples, tol_min, tolerance,
182 num_ifaces = len(samples)
183 duration = self.config.duration
184 in_packets_sum = sum(
185 [samples[iface]['in_packets'] for iface in samples])
186 out_packets_sum = sum(
187 [samples[iface]['out_packets'] for iface in samples])
188 rx_throughput = round(float(in_packets_sum) / duration, 3)
189 tx_throughput = round(float(out_packets_sum) / duration, 3)
190 packet_drop = abs(out_packets_sum - in_packets_sum)
193 drop_percent = round(
194 (packet_drop / float(out_packets_sum)) * 100,
195 self.DROP_PERCENT_ROUND)
196 except ZeroDivisionError:
197 LOG.info('No traffic is flowing')
200 completed = True if drop_percent <= tolerance else False
202 self.rate_unit == tp_base.TrafficProfileConfig.RATE_FPS):
203 self.rate = float(out_packets_sum) / duration / num_ifaces
205 if drop_percent > tolerance:
206 self.max_rate = self.rate
207 elif drop_percent < tol_min:
208 self.min_rate = self.rate
212 latency_ns_avg = float(
213 sum([samples[iface]['Store-Forward_Avg_latency_ns']
214 for iface in samples])) / num_ifaces
215 latency_ns_min = float(
216 sum([samples[iface]['Store-Forward_Min_latency_ns']
217 for iface in samples])) / num_ifaces
218 latency_ns_max = float(
219 sum([samples[iface]['Store-Forward_Max_latency_ns']
220 for iface in samples])) / num_ifaces
222 samples['TxThroughput'] = tx_throughput
223 samples['RxThroughput'] = rx_throughput
224 samples['DropPercentage'] = drop_percent
225 samples['latency_ns_avg'] = latency_ns_avg
226 samples['latency_ns_min'] = latency_ns_min
227 samples['latency_ns_max'] = latency_ns_max
229 return completed, samples