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)):
60 # values should be single-item dict, so just grab the first item
62 key, value = next(iter(values.items()))
64 result[traffickey] = {}
67 port_id = value.get('id', 1)
68 port_index = port_id - 1
70 if value.get('outer_l3v4'):
71 ip = value['outer_l3v4']
72 src_key, dst_key = 'srcip4', 'dstip4'
74 ip = value['outer_l3v6']
75 src_key, dst_key = 'srcip6', 'dstip6'
77 srcip, srcmask = self._get_ip_and_mask(ip[src_key])
78 dstip, dstmask = self._get_ip_and_mask(ip[dst_key])
80 outer_l4 = value.get('outer_l4')
81 src_port, src_port_mask = self._get_fixed_and_mask(outer_l4['srcport'])
82 dst_port, dst_port_mask = self._get_fixed_and_mask(outer_l4['dstport'])
83 result[traffickey] = {
87 'rate_unit': self.rate_unit,
89 'framesize': value['outer_l2']['framesize'],
90 'framesPerSecond': True,
91 'srcmac': mac['src_mac_{}'.format(port_index)],
92 'dstmac': mac['dst_mac_{}'.format(port_index)],
104 'proto': ip['proto'],
109 'srcportmask': src_port_mask,
110 'dstportmask': dst_port_mask,
111 'count': outer_l4['count'],
112 'seed': outer_l4['seed'],
121 def _ixia_traffic_generate(self, traffic, ixia_obj):
122 ixia_obj.update_frame(traffic, self.config.duration)
123 ixia_obj.update_ip_packet(traffic)
124 ixia_obj.update_l4(traffic)
125 ixia_obj.start_traffic()
127 def update_traffic_profile(self, traffic_generator):
128 def port_generator():
129 for vld_id, intfs in sorted(traffic_generator.networks.items()):
130 if not vld_id.startswith((self.UPLINK, self.DOWNLINK)):
132 profile_data = self.params.get(vld_id)
135 self.profile_data = profile_data
136 self.full_profile.update({vld_id: self.profile_data})
138 yield traffic_generator.vnfd_helper.port_num(intf)
140 self.ports = [port for port in port_generator()]
142 def execute_traffic(self, traffic_generator, ixia_obj=None, mac=None):
143 mac = {} if mac is None else mac
144 first_run = self.first_run
146 self.first_run = False
147 self.full_profile = {}
149 self.update_traffic_profile(traffic_generator)
150 self.max_rate = self.rate
153 self.rate = round(float(self.max_rate + self.min_rate) / 2.0,
156 traffic = self._get_ixia_traffic_profile(self.full_profile, mac)
157 self._ixia_traffic_generate(traffic, ixia_obj)
160 def get_drop_percentage(self, samples, tol_min, tolerance,
164 num_ifaces = len(samples)
165 duration = self.config.duration
166 in_packets_sum = sum(
167 [samples[iface]['in_packets'] for iface in samples])
168 out_packets_sum = sum(
169 [samples[iface]['out_packets'] for iface in samples])
171 [samples[iface]['RxThroughput'] for iface in samples])
172 rx_throughput = round(float(rx_throughput), 2)
174 [samples[iface]['TxThroughput'] for iface in samples])
175 tx_throughput = round(float(tx_throughput), 2)
176 packet_drop = abs(out_packets_sum - in_packets_sum)
179 drop_percent = round(
180 (packet_drop / float(out_packets_sum)) * 100,
181 self.DROP_PERCENT_ROUND)
182 except ZeroDivisionError:
183 LOG.info('No traffic is flowing')
185 samples['TxThroughput'] = tx_throughput
186 samples['RxThroughput'] = rx_throughput
187 samples['DropPercentage'] = drop_percent
190 completed = True if drop_percent <= tolerance else False
192 self.rate_unit == tp_base.TrafficProfileConfig.RATE_FPS):
193 self.rate = float(out_packets_sum) / duration / num_ifaces
195 if drop_percent > tolerance:
196 self.max_rate = self.rate
197 elif drop_percent < tol_min:
198 self.min_rate = self.rate
202 return completed, samples