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.network_services.traffic_profile import base as tp_base
18 from yardstick.network_services.traffic_profile import trex_traffic_profile
21 LOG = logging.getLogger(__name__)
24 class IXIARFC2544Profile(trex_traffic_profile.TrexProfile):
28 DROP_PERCENT_ROUND = 6
31 def __init__(self, yaml_data):
32 super(IXIARFC2544Profile, self).__init__(yaml_data)
33 self.rate = self.config.frame_rate
34 self.rate_unit = self.config.rate_unit
36 def _get_ixia_traffic_profile(self, profile_data, mac=None):
37 mac = {} if mac is None else mac
39 for traffickey, values in profile_data.items():
40 if not traffickey.startswith((self.UPLINK, self.DOWNLINK)):
44 # values should be single-item dict, so just grab the first item
46 key, value = next(iter(values.items()))
48 result[traffickey] = {}
51 port_id = value.get('id', 1)
52 port_index = port_id - 1
54 ip = value['outer_l3v6']
56 ip = value['outer_l3v4']
57 src_key, dst_key = 'srcip4', 'dstip4'
59 src_key, dst_key = 'srcip6', 'dstip6'
61 result[traffickey] = {
65 'rate_unit': self.rate_unit,
67 'framesize': value['outer_l2']['framesize'],
68 'framesPerSecond': True,
69 'srcmac': mac['src_mac_{}'.format(port_index)],
70 'dstmac': mac['dst_mac_{}'.format(port_index)],
76 src_key: ip[src_key].split("-")[0],
77 dst_key: ip[dst_key].split("-")[0],
81 'outer_l4': value['outer_l4'],
88 def _ixia_traffic_generate(self, traffic, ixia_obj):
89 ixia_obj.update_frame(traffic)
90 ixia_obj.update_ip_packet(traffic)
91 ixia_obj.start_traffic()
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.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=None, mac=None):
109 mac = {} if mac is None else mac
110 first_run = self.first_run
112 self.first_run = False
113 self.full_profile = {}
115 self.update_traffic_profile(traffic_generator)
116 self.max_rate = self.rate
119 self.rate = round(float(self.max_rate + self.min_rate) / 2.0,
122 traffic = self._get_ixia_traffic_profile(self.full_profile, mac)
123 self._ixia_traffic_generate(traffic, ixia_obj)
126 def get_drop_percentage(self, samples, tol_min, tolerance, duration=30.0,
130 num_ifaces = len(samples)
131 in_packets_sum = sum(
132 [samples[iface]['in_packets'] for iface in samples])
133 out_packets_sum = sum(
134 [samples[iface]['out_packets'] for iface in samples])
136 [samples[iface]['RxThroughput'] for iface in samples])
137 rx_throughput = round(float(rx_throughput), 2)
139 [samples[iface]['TxThroughput'] for iface in samples])
140 tx_throughput = round(float(tx_throughput), 2)
141 packet_drop = abs(out_packets_sum - in_packets_sum)
144 drop_percent = round(
145 (packet_drop / float(out_packets_sum)) * 100,
146 self.DROP_PERCENT_ROUND)
147 except ZeroDivisionError:
148 LOG.info('No traffic is flowing')
150 samples['TxThroughput'] = tx_throughput
151 samples['RxThroughput'] = rx_throughput
152 samples['DropPercentage'] = drop_percent
155 completed = True if drop_percent <= tolerance else False
157 self.rate_unit == tp_base.TrafficProfileConfig.RATE_FPS):
158 self.rate = out_packets_sum / duration / num_ifaces
160 if drop_percent > tolerance:
161 self.max_rate = self.rate
162 elif drop_percent < tol_min:
163 self.min_rate = self.rate
167 return completed, samples