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
21 from yardstick.common.utils import ErrorClass
22 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTrafficGen
23 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper
24 from yardstick.network_services.vnf_generic.vnf.sample_vnf import Rfc2544ResourceHelper
25 from yardstick.benchmark.scenarios.networking.vnf_generic import find_relative_file
27 LOG = logging.getLogger(__name__)
29 WAIT_AFTER_CFG_LOAD = 10
31 IXIA_LIB = os.path.dirname(os.path.realpath(__file__))
32 IXNET_LIB = os.path.join(IXIA_LIB, "../../libs/ixia_libs/IxNet")
33 sys.path.append(IXNET_LIB)
36 from IxNet import IxNextgen
38 IxNextgen = ErrorClass
41 class IxiaRfc2544Helper(Rfc2544ResourceHelper):
44 return self.latency and self.iteration.value > 10
47 class IxiaResourceHelper(ClientResourceHelper):
49 LATENCY_TIME_SLEEP = 120
51 def __init__(self, setup_helper, rfc_helper_type=None):
52 super(IxiaResourceHelper, self).__init__(setup_helper)
53 self.scenario_helper = setup_helper.scenario_helper
55 self.client = IxNextgen()
57 if rfc_helper_type is None:
58 rfc_helper_type = IxiaRfc2544Helper
60 self.rfc_helper = rfc_helper_type(self.scenario_helper)
61 self.priv_ports = None
64 def _connect(self, client=None):
65 self.client._connect(self.vnfd_helper)
67 def get_stats(self, *args, **kwargs):
68 return self.client.ix_get_statistics()
70 def stop_collect(self):
71 self._terminated.value = 0
72 if self.client and self.client.ixnet:
73 self.client.ix_stop_traffic()
75 def generate_samples(self, ports, key=None, default=None):
76 stats = self.get_stats()
77 last_result = stats[1]
81 for interface in self.vnfd_helper.interfaces:
83 name = interface["name"]
84 # this is not DPDK port num, but this is whatever number we gave
85 # when we selected ports and programmed the profile
86 port = self.vnfd_helper.port_num(name)
89 "rx_throughput_kps": float(last_result["Rx_Rate_Kbps"][port]),
90 "tx_throughput_kps": float(last_result["Tx_Rate_Kbps"][port]),
91 "rx_throughput_mbps": float(last_result["Rx_Rate_Mbps"][port]),
92 "tx_throughput_mbps": float(last_result["Tx_Rate_Mbps"][port]),
93 "in_packets": int(last_result["Valid_Frames_Rx"][port]),
94 "out_packets": int(last_result["Frames_Tx"][port]),
95 "RxThroughput": int(last_result["Valid_Frames_Rx"][port]) / 30,
96 "TxThroughput": int(last_result["Frames_Tx"][port]) / 30,
99 avg_latency = latency["Store-Forward_Avg_latency_ns"][port]
100 min_latency = latency["Store-Forward_Min_latency_ns"][port]
101 max_latency = latency["Store-Forward_Max_latency_ns"][port]
102 samples[name][key] = \
103 {"Store-Forward_Avg_latency_ns": avg_latency,
104 "Store-Forward_Min_latency_ns": min_latency,
105 "Store-Forward_Max_latency_ns": max_latency}
111 def run_traffic(self, traffic_profile):
112 if self._terminated.value:
115 min_tol = self.rfc_helper.tolerance_low
116 max_tol = self.rfc_helper.tolerance_high
117 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()
132 # TODO: shouldn't this index map to port number we used to generate the profile
133 for index, interface in enumerate(self.vnfd_helper.interfaces, 1):
134 virt_intf = interface["virtual-interface"]
136 "src_mac_{}".format(index): virt_intf.get("local_mac", default),
137 "dst_mac_{}".format(index): virt_intf.get("dst_mac", default),
142 ixia_file = find_relative_file("ixia_traffic.cfg",
143 self.scenario_helper.scenario_cfg["task_path"])
144 # Generate ixia traffic config...
145 while not self._terminated.value:
146 traffic_profile.execute_traffic(self, self.client, mac, ixia_file)
147 self.client_started.value = 1
148 time.sleep(WAIT_FOR_TRAFFIC)
149 self.client.ix_stop_traffic()
150 samples = self.generate_samples(traffic_profile.ports)
151 self._queue.put(samples)
152 status, samples = traffic_profile.get_drop_percentage(self, samples, min_tol,
153 max_tol, self.client, mac,
156 current = samples['CurrentDropPercentage']
157 if min_tol <= current <= max_tol or status == 'Completed' or \
158 self.rfc_helper.is_done():
161 self.client.ix_stop_traffic()
162 self._queue.put(samples)
164 if not self.rfc_helper.is_done():
165 self._terminated.value = 1
168 traffic_profile.execute_traffic(self, self.client, mac, ixia_file)
170 time.sleep(self.LATENCY_TIME_SLEEP)
171 self.client.ix_stop_traffic()
172 samples = self.generate_samples(traffic_profile.ports, 'latency', {})
173 self._queue.put(samples)
174 traffic_profile.start_ixia_latency(self, self.client, mac, ixia_file)
175 if self._terminated.value:
178 self.client.ix_stop_traffic()
179 self._terminated.value = 1
181 def collect_kpi(self):
182 self.rfc_helper.iteration.value += 1
183 return super(IxiaResourceHelper, self).collect_kpi()
186 class IxiaTrafficGen(SampleVNFTrafficGen):
190 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
191 if resource_helper_type is None:
192 resource_helper_type = IxiaResourceHelper
194 super(IxiaTrafficGen, self).__init__(name, vnfd, setup_env_helper_type,
195 resource_helper_type)
196 self._ixia_traffic_gen = None
197 self.ixia_file_name = ''
198 self.vnf_port_pairs = []
200 def _check_status(self):
203 def scale(self, flavor=""):
206 def listen_traffic(self, traffic_profile):
210 self.resource_helper.stop_collect()
211 super(IxiaTrafficGen, self).terminate()
213 def wait_for_instantiate(self):
214 # not needed for IxNet