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
26 LOG = logging.getLogger(__name__)
28 WAIT_AFTER_CFG_LOAD = 10
30 IXIA_LIB = os.path.dirname(os.path.realpath(__file__))
31 IXNET_LIB = os.path.join(IXIA_LIB, "../../libs/ixia_libs/IxNet")
32 sys.path.append(IXNET_LIB)
35 from IxNet import IxNextgen
37 IxNextgen = ErrorClass
40 class IxiaRfc2544Helper(Rfc2544ResourceHelper):
45 class IxiaResourceHelper(ClientResourceHelper):
47 def __init__(self, setup_helper, rfc_helper_type=None):
48 super(IxiaResourceHelper, self).__init__(setup_helper)
49 self.scenario_helper = setup_helper.scenario_helper
51 self.client = IxNextgen()
53 if rfc_helper_type is None:
54 rfc_helper_type = IxiaRfc2544Helper
56 self.rfc_helper = rfc_helper_type(self.scenario_helper)
57 self.tg_port_pairs = []
58 self.priv_ports = None
61 def _connect(self, client=None):
62 self.client._connect(self.vnfd_helper)
64 def _build_ports(self):
65 # self.generate_port_pairs(self.topology)
66 self.priv_ports = [int(x[0][2:]) for x in self.tg_port_pairs]
67 self.pub_ports = [int(x[1][2:]) for x in self.tg_port_pairs]
68 self.my_ports = list(set(self.priv_ports).union(set(self.pub_ports)))
70 def get_stats(self, *args, **kwargs):
71 return self.client.ix_get_statistics()[1]
73 def stop_collect(self):
74 self._terminated.value = 0
75 if self.client and self.client.ixnet:
76 self.client.ix_stop_traffic()
78 def generate_samples(self, key=None, default=None):
79 last_result = self.get_stats()
82 for vpci_idx, interface in enumerate(self.vnfd_helper.interfaces):
83 name = "xe{0}".format(vpci_idx)
85 "rx_throughput_kps": float(last_result["Rx_Rate_Kbps"][vpci_idx]),
86 "tx_throughput_kps": float(last_result["Tx_Rate_Kbps"][vpci_idx]),
87 "rx_throughput_mbps": float(last_result["Rx_Rate_Mbps"][vpci_idx]),
88 "tx_throughput_mbps": float(last_result["Tx_Rate_Mbps"][vpci_idx]),
89 "in_packets": int(last_result["Valid_Frames_Rx"][vpci_idx]),
90 "out_packets": int(last_result["Frames_Tx"][vpci_idx]),
91 "RxThroughput": int(last_result["Valid_Frames_Rx"][vpci_idx]) / 30,
92 "TxThroughput": int(last_result["Frames_Tx"][vpci_idx]) / 30,
97 def run_traffic(self, traffic_profile):
98 min_tol = self.rfc_helper.tolerance_low
99 max_tol = self.rfc_helper.tolerance_high
104 # we don't know client_file_name until runtime as instantiate
105 client_file_name = self.scenario_helper.scenario_cfg['ixia_profile']
106 self.client.ix_load_config(client_file_name)
107 time.sleep(WAIT_AFTER_CFG_LOAD)
109 self.client.ix_assign_ports()
112 for index, interface in enumerate(self.vnfd_helper.interfaces, 1):
113 virt_intf = interface["virtual-interface"]
115 "src_mac_{}".format(index): virt_intf["local_mac"],
116 "dst_mac_{}".format(index): virt_intf["dst_mac"],
120 ixia_file = os.path.join(os.getcwd(), "ixia_traffic.cfg")
121 # Generate ixia traffic config...
122 while not self._terminated.value:
123 traffic_profile.execute(self, self.client, mac, ixia_file)
124 self.client_started.value = 1
125 time.sleep(WAIT_FOR_TRAFFIC)
126 self.client.ix_stop_traffic()
127 samples = self.generate_samples()
128 self._queue.put(samples)
129 status, samples = traffic_profile.get_drop_percentage(self, samples, min_tol,
130 max_tol, self.client, mac,
133 current = samples['CurrentDropPercentage']
134 if min_tol <= current <= max_tol or status == 'Completed':
135 self._terminated.value = 1
137 self.client.ix_stop_traffic()
138 self._queue.put(samples)
141 class IxiaTrafficGen(SampleVNFTrafficGen):
143 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
144 if resource_helper_type is None:
145 resource_helper_type = IxiaResourceHelper
147 super(IxiaTrafficGen, self).__init__(name, vnfd, setup_env_helper_type,
148 resource_helper_type)
149 self._ixia_traffic_gen = None
150 self.ixia_file_name = ''
151 self.tg_port_pairs = []
152 self.vnf_port_pairs = []
154 def _check_status(self):
157 def scale(self, flavor=""):
160 def listen_traffic(self, traffic_profile):
164 self.resource_helper.stop_collect()
165 super(IxiaTrafficGen, self).terminate()
167 def wait_for_instantiate(self):
168 # not needed for IxNet