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
23 from yardstick.common.utils import ErrorClass
24 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTrafficGen
25 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper
26 from yardstick.network_services.vnf_generic.vnf.sample_vnf import Rfc2544ResourceHelper
27 from yardstick.benchmark.scenarios.networking.vnf_generic import find_relative_file
29 LOG = logging.getLogger(__name__)
31 WAIT_AFTER_CFG_LOAD = 10
33 IXIA_LIB = os.path.dirname(os.path.realpath(__file__))
34 IXNET_LIB = os.path.join(IXIA_LIB, "../../libs/ixia_libs/IxNet")
35 sys.path.append(IXNET_LIB)
38 from IxNet import IxNextgen
40 IxNextgen = ErrorClass
43 class IxiaRfc2544Helper(Rfc2544ResourceHelper):
46 return self.latency and self.iteration.value > 10
49 class IxiaResourceHelper(ClientResourceHelper):
51 LATENCY_TIME_SLEEP = 120
53 def __init__(self, setup_helper, rfc_helper_type=None):
54 super(IxiaResourceHelper, self).__init__(setup_helper)
55 self.scenario_helper = setup_helper.scenario_helper
57 self.client = IxNextgen()
59 if rfc_helper_type is None:
60 rfc_helper_type = IxiaRfc2544Helper
62 self.rfc_helper = rfc_helper_type(self.scenario_helper)
63 self.uplink_ports = None
64 self.downlink_ports = None
67 def _connect(self, client=None):
68 self.client._connect(self.vnfd_helper)
70 def get_stats(self, *args, **kwargs):
71 return self.client.ix_get_statistics()
73 def stop_collect(self):
74 self._terminated.value = 1
76 self.client.ix_stop_traffic()
78 def generate_samples(self, ports, key=None, default=None):
79 stats = self.get_stats()
80 last_result = stats[1]
84 # this is not DPDK port num, but this is whatever number we gave
85 # when we selected ports and programmed the profile
86 for port_num in ports:
88 # reverse lookup port name from port_num so the stats dict is descriptive
89 intf = self.vnfd_helper.find_interface_by_port(port_num)
90 port_name = intf["name"]
91 samples[port_name] = {
92 "rx_throughput_kps": float(last_result["Rx_Rate_Kbps"][port_num]),
93 "tx_throughput_kps": float(last_result["Tx_Rate_Kbps"][port_num]),
94 "rx_throughput_mbps": float(last_result["Rx_Rate_Mbps"][port_num]),
95 "tx_throughput_mbps": float(last_result["Tx_Rate_Mbps"][port_num]),
96 "in_packets": int(last_result["Valid_Frames_Rx"][port_num]),
97 "out_packets": int(last_result["Frames_Tx"][port_num]),
98 "RxThroughput": int(last_result["Valid_Frames_Rx"][port_num]) / 30,
99 "TxThroughput": int(last_result["Frames_Tx"][port_num]) / 30,
102 avg_latency = latency["Store-Forward_Avg_latency_ns"][port_num]
103 min_latency = latency["Store-Forward_Min_latency_ns"][port_num]
104 max_latency = latency["Store-Forward_Max_latency_ns"][port_num]
105 samples[port_name][key] = \
106 {"Store-Forward_Avg_latency_ns": avg_latency,
107 "Store-Forward_Min_latency_ns": min_latency,
108 "Store-Forward_Max_latency_ns": max_latency}
114 def run_traffic(self, traffic_profile):
115 if self._terminated.value:
118 min_tol = self.rfc_helper.tolerance_low
119 max_tol = self.rfc_helper.tolerance_high
120 default = "00:00:00:00:00:00"
124 # we don't know client_file_name until runtime as instantiate
126 find_relative_file(self.scenario_helper.scenario_cfg['ixia_profile'],
127 self.scenario_helper.scenario_cfg["task_path"])
128 self.client.ix_load_config(client_file_name)
129 time.sleep(WAIT_AFTER_CFG_LOAD)
131 self.client.ix_assign_ports()
133 ixia_file = find_relative_file("ixia_traffic.cfg",
134 self.scenario_helper.scenario_cfg["task_path"])
137 with open(ixia_file) as stream:
139 static_traffic = json.load(stream)
143 for vld_id, traffic in static_traffic.items():
144 intfs = self.vnfd_helper.port_pairs.networks.get(vld_id, [])
145 interface = next(iter(intfs), None)
147 virt_intf = self.vnfd_helper.find_interface(name=interface)["virtual-interface"]
148 # we only know static traffic id by reading the json
149 # this is used by _get_ixia_traffic_profile
150 mac["src_mac_{}".format(traffic["id"])] = virt_intf.get("local_mac", default)
151 mac["dst_mac_{}".format(traffic["id"])] = virt_intf.get("dst_mac", default)
154 # Generate ixia traffic config...
156 while not self._terminated.value:
157 traffic_profile.execute_traffic(self, self.client, mac, ixia_file)
158 self.client_started.value = 1
159 time.sleep(WAIT_FOR_TRAFFIC)
160 self.client.ix_stop_traffic()
161 samples = self.generate_samples(traffic_profile.ports)
162 self._queue.put(samples)
163 status, samples = traffic_profile.get_drop_percentage(self, samples, min_tol,
164 max_tol, self.client, mac,
167 current = samples['CurrentDropPercentage']
168 if min_tol <= current <= max_tol or status == 'Completed':
169 self._terminated.value = 1
171 self.client.ix_stop_traffic()
172 self._queue.put(samples)
174 LOG.exception("Run Traffic terminated")
176 if not self.rfc_helper.is_done():
177 self._terminated.value = 1
180 traffic_profile.execute_traffic(self, self.client, mac, ixia_file)
182 time.sleep(self.LATENCY_TIME_SLEEP)
183 self.client.ix_stop_traffic()
184 samples = self.generate_samples(traffic_profile.ports, 'latency', {})
185 self._queue.put(samples)
186 traffic_profile.start_ixia_latency(self, self.client, mac, ixia_file)
187 if self._terminated.value:
190 self.client.ix_stop_traffic()
191 self._terminated.value = 1
193 def collect_kpi(self):
194 self.rfc_helper.iteration.value += 1
195 return super(IxiaResourceHelper, self).collect_kpi()
198 class IxiaTrafficGen(SampleVNFTrafficGen):
202 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
203 if resource_helper_type is None:
204 resource_helper_type = IxiaResourceHelper
206 super(IxiaTrafficGen, self).__init__(name, vnfd, setup_env_helper_type,
207 resource_helper_type)
208 self._ixia_traffic_gen = None
209 self.ixia_file_name = ''
210 self.vnf_port_pairs = []
212 def _check_status(self):
215 def scale(self, flavor=""):
218 def listen_traffic(self, traffic_profile):
222 self.resource_helper.stop_collect()
223 super(IxiaTrafficGen, self).terminate()
225 def wait_for_instantiate(self):
226 # not needed for IxNet