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):
46 class IxiaResourceHelper(ClientResourceHelper):
48 def __init__(self, setup_helper, rfc_helper_type=None):
49 super(IxiaResourceHelper, self).__init__(setup_helper)
50 self.scenario_helper = setup_helper.scenario_helper
52 self.client = IxNextgen()
54 if rfc_helper_type is None:
55 rfc_helper_type = IxiaRfc2544Helper
57 self.rfc_helper = rfc_helper_type(self.scenario_helper)
58 self.tg_port_pairs = []
59 self.priv_ports = None
62 def _connect(self, client=None):
63 self.client._connect(self.vnfd_helper)
65 def _build_ports(self):
66 # self.generate_port_pairs(self.topology)
67 self.priv_ports = [int(x[0][2:]) for x in self.tg_port_pairs]
68 self.pub_ports = [int(x[1][2:]) for x in self.tg_port_pairs]
69 self.my_ports = list(set(self.priv_ports).union(set(self.pub_ports)))
71 def get_stats(self, *args, **kwargs):
72 return self.client.ix_get_statistics()[1]
74 def stop_collect(self):
75 self._terminated.value = 0
76 if self.client and self.client.ixnet:
77 self.client.ix_stop_traffic()
79 def generate_samples(self, key=None, default=None):
80 last_result = self.get_stats()
83 for vpci_idx, interface in enumerate(self.vnfd_helper.interfaces):
84 name = "xe{0}".format(vpci_idx)
86 "rx_throughput_kps": float(last_result["Rx_Rate_Kbps"][vpci_idx]),
87 "tx_throughput_kps": float(last_result["Tx_Rate_Kbps"][vpci_idx]),
88 "rx_throughput_mbps": float(last_result["Rx_Rate_Mbps"][vpci_idx]),
89 "tx_throughput_mbps": float(last_result["Tx_Rate_Mbps"][vpci_idx]),
90 "in_packets": int(last_result["Valid_Frames_Rx"][vpci_idx]),
91 "out_packets": int(last_result["Frames_Tx"][vpci_idx]),
92 "RxThroughput": int(last_result["Valid_Frames_Rx"][vpci_idx]) / 30,
93 "TxThroughput": int(last_result["Frames_Tx"][vpci_idx]) / 30,
98 def run_traffic(self, traffic_profile):
99 min_tol = self.rfc_helper.tolerance_low
100 max_tol = self.rfc_helper.tolerance_high
105 # we don't know client_file_name until runtime as instantiate
107 find_relative_file(self.scenario_helper.scenario_cfg['ixia_profile'],
108 self.scenario_helper.scenario_cfg["task_path"])
109 self.client.ix_load_config(client_file_name)
110 time.sleep(WAIT_AFTER_CFG_LOAD)
112 self.client.ix_assign_ports()
115 for index, interface in enumerate(self.vnfd_helper.interfaces, 1):
116 virt_intf = interface["virtual-interface"]
118 "src_mac_{}".format(index): virt_intf["local_mac"],
119 "dst_mac_{}".format(index): virt_intf["dst_mac"],
124 ixia_file = find_relative_file("ixia_traffic.cfg",
125 self.scenario_helper.scenario_cfg["task_path"])
126 # Generate ixia traffic config...
127 while not self._terminated.value:
128 traffic_profile.execute(self, self.client, mac, ixia_file)
129 self.client_started.value = 1
130 time.sleep(WAIT_FOR_TRAFFIC)
131 self.client.ix_stop_traffic()
132 samples = self.generate_samples()
133 self._queue.put(samples)
134 status, samples = traffic_profile.get_drop_percentage(self, samples, min_tol,
135 max_tol, self.client, mac,
138 current = samples['CurrentDropPercentage']
139 if min_tol <= current <= max_tol or status == 'Completed':
140 self._terminated.value = 1
142 self.client.ix_stop_traffic()
143 self._queue.put(samples)
146 class IxiaTrafficGen(SampleVNFTrafficGen):
150 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
151 if resource_helper_type is None:
152 resource_helper_type = IxiaResourceHelper
154 super(IxiaTrafficGen, self).__init__(name, vnfd, setup_env_helper_type,
155 resource_helper_type)
156 self._ixia_traffic_gen = None
157 self.ixia_file_name = ''
158 self.tg_port_pairs = []
159 self.vnf_port_pairs = []
161 def _check_status(self):
164 def scale(self, flavor=""):
167 def listen_traffic(self, traffic_profile):
171 self.resource_helper.stop_collect()
172 super(IxiaTrafficGen, self).terminate()
174 def wait_for_instantiate(self):
175 # not needed for IxNet