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 for port_name in ports:
86 # this is not DPDK port num, but this is whatever number we gave
87 # when we selected ports and programmed the profile
88 port_num = self.vnfd_helper.port_num(port_name)
89 samples[port_name] = {
90 "rx_throughput_kps": float(last_result["Rx_Rate_Kbps"][port_num]),
91 "tx_throughput_kps": float(last_result["Tx_Rate_Kbps"][port_num]),
92 "rx_throughput_mbps": float(last_result["Rx_Rate_Mbps"][port_num]),
93 "tx_throughput_mbps": float(last_result["Tx_Rate_Mbps"][port_num]),
94 "in_packets": int(last_result["Valid_Frames_Rx"][port_num]),
95 "out_packets": int(last_result["Frames_Tx"][port_num]),
96 "RxThroughput": int(last_result["Valid_Frames_Rx"][port_num]) / 30,
97 "TxThroughput": int(last_result["Frames_Tx"][port_num]) / 30,
100 avg_latency = latency["Store-Forward_Avg_latency_ns"][port_num]
101 min_latency = latency["Store-Forward_Min_latency_ns"][port_num]
102 max_latency = latency["Store-Forward_Max_latency_ns"][port_num]
103 samples[port_name][key] = \
104 {"Store-Forward_Avg_latency_ns": avg_latency,
105 "Store-Forward_Min_latency_ns": min_latency,
106 "Store-Forward_Max_latency_ns": max_latency}
112 def run_traffic(self, traffic_profile):
113 if self._terminated.value:
116 min_tol = self.rfc_helper.tolerance_low
117 max_tol = self.rfc_helper.tolerance_high
118 default = "00:00:00:00:00:00"
122 # we don't know client_file_name until runtime as instantiate
124 find_relative_file(self.scenario_helper.scenario_cfg['ixia_profile'],
125 self.scenario_helper.scenario_cfg["task_path"])
126 self.client.ix_load_config(client_file_name)
127 time.sleep(WAIT_AFTER_CFG_LOAD)
129 self.client.ix_assign_ports()
131 ixia_file = find_relative_file("ixia_traffic.cfg",
132 self.scenario_helper.scenario_cfg["task_path"])
135 with open(ixia_file) as stream:
137 static_traffic = json.load(stream)
141 for vld_id, traffic in static_traffic.items():
142 intfs = self.vnfd_helper.port_pairs.networks.get(vld_id, [])
143 interface = next(intfs, None)
145 virt_intf = interface["virtual-interface"]
146 # we only know static traffic id by reading the json
147 # this is used by _get_ixia_traffic_profile
148 mac["src_mac_{}".format(traffic["id"])] = virt_intf.get("local_mac", default)
149 mac["dst_mac_{}".format(traffic["id"])] = virt_intf.get("dst_mac", default)
152 # Generate ixia traffic config...
154 while not self._terminated.value:
155 traffic_profile.execute_traffic(self, self.client, mac, ixia_file)
156 self.client_started.value = 1
157 time.sleep(WAIT_FOR_TRAFFIC)
158 self.client.ix_stop_traffic()
159 samples = self.generate_samples(traffic_profile.ports)
160 self._queue.put(samples)
161 status, samples = traffic_profile.get_drop_percentage(self, samples, min_tol,
162 max_tol, self.client, mac,
165 current = samples['CurrentDropPercentage']
166 if min_tol <= current <= max_tol or status == 'Completed':
167 self._terminated.value = 1
169 self.client.ix_stop_traffic()
170 self._queue.put(samples)
172 LOG.info("Run Traffic terminated")
174 if not self.rfc_helper.is_done():
175 self._terminated.value = 1
178 traffic_profile.execute_traffic(self, self.client, mac, ixia_file)
180 time.sleep(self.LATENCY_TIME_SLEEP)
181 self.client.ix_stop_traffic()
182 samples = self.generate_samples(traffic_profile.ports, 'latency', {})
183 self._queue.put(samples)
184 traffic_profile.start_ixia_latency(self, self.client, mac, ixia_file)
185 if self._terminated.value:
188 self.client.ix_stop_traffic()
189 self._terminated.value = 1
191 def collect_kpi(self):
192 self.rfc_helper.iteration.value += 1
193 return super(IxiaResourceHelper, self).collect_kpi()
196 class IxiaTrafficGen(SampleVNFTrafficGen):
200 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
201 if resource_helper_type is None:
202 resource_helper_type = IxiaResourceHelper
204 super(IxiaTrafficGen, self).__init__(name, vnfd, setup_env_helper_type,
205 resource_helper_type)
206 self._ixia_traffic_gen = None
207 self.ixia_file_name = ''
208 self.vnf_port_pairs = []
210 def _check_status(self):
213 def scale(self, flavor=""):
216 def listen_traffic(self, traffic_profile):
220 self.resource_helper.stop_collect()
221 super(IxiaTrafficGen, self).terminate()
223 def wait_for_instantiate(self):
224 # not needed for IxNet