diff options
Diffstat (limited to 'yardstick/network_services/vnf_generic/vnf/tg_ixload.py')
-rw-r--r-- | yardstick/network_services/vnf_generic/vnf/tg_ixload.py | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/yardstick/network_services/vnf_generic/vnf/tg_ixload.py b/yardstick/network_services/vnf_generic/vnf/tg_ixload.py index 61c045405..38b00a4b2 100644 --- a/yardstick/network_services/vnf_generic/vnf/tg_ixload.py +++ b/yardstick/network_services/vnf_generic/vnf/tg_ixload.py @@ -12,20 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import +import collections import csv import glob import logging import os import shutil +import subprocess + +from oslo_serialization import jsonutils + +from yardstick.common import utils +from yardstick.network_services.vnf_generic.vnf import sample_vnf -from collections import OrderedDict -from subprocess import call -from yardstick.common.utils import makedirs -from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTrafficGen -from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper -from yardstick.benchmark.scenarios.networking.vnf_generic import find_relative_file LOG = logging.getLogger(__name__) @@ -45,7 +45,8 @@ IXLOAD_CONFIG_TEMPLATE = '''\ }, "remote_server": "%s", "result_dir": "%s", - "ixload_cfg": "C:/Results/%s" + "ixload_cfg": "C:/Results/%s", + "links_param": %s }''' IXLOAD_CMD = "{ixloadpy} {http_ixload} {args}" @@ -61,11 +62,11 @@ class ResourceDataHelper(list): } -class IxLoadResourceHelper(ClientResourceHelper): +class IxLoadResourceHelper(sample_vnf.ClientResourceHelper): RESULTS_MOUNT = "/mnt/Results" - KPI_LIST = OrderedDict(( + KPI_LIST = collections.OrderedDict(( ('http_throughput', 'HTTP Total Throughput (Kbps)'), ('simulated_users', 'HTTP Simulated Users'), ('concurrent_connections', 'HTTP Concurrent Connections'), @@ -75,7 +76,8 @@ class IxLoadResourceHelper(ClientResourceHelper): def __init__(self, setup_helper): super(IxLoadResourceHelper, self).__init__(setup_helper) - self.result = OrderedDict((key, ResourceDataHelper()) for key in self.KPI_LIST) + self.result = collections.OrderedDict((key, ResourceDataHelper()) + for key in self.KPI_LIST) self.resource_file_name = '' self.data = None @@ -91,19 +93,20 @@ class IxLoadResourceHelper(ClientResourceHelper): self.result[key].append(value) def setup(self): - # TODO: fixupt scenario_helper to hanlde ixia + # NOTE: fixup scenario_helper to hanlde ixia self.resource_file_name = \ - find_relative_file(self.scenario_helper.scenario_cfg['ixia_profile'], - self.scenario_helper.scenario_cfg["task_path"]) - makedirs(self.RESULTS_MOUNT) + utils.find_relative_file( + self.scenario_helper.scenario_cfg['ixia_profile'], + self.scenario_helper.scenario_cfg["task_path"]) + utils.makedirs(self.RESULTS_MOUNT) cmd = MOUNT_CMD.format(self.vnfd_helper.mgmt_interface, self) LOG.debug(cmd) if not os.path.ismount(self.RESULTS_MOUNT): - call(cmd, shell=True) + subprocess.call(cmd, shell=True) shutil.rmtree(self.RESULTS_MOUNT, ignore_errors=True) - makedirs(self.RESULTS_MOUNT) + utils.makedirs(self.RESULTS_MOUNT) shutil.copy(self.resource_file_name, self.RESULTS_MOUNT) def make_aggregates(self): @@ -113,7 +116,7 @@ class IxLoadResourceHelper(ClientResourceHelper): def collect_kpi(self): if self.data: self._result.update(self.data) - LOG.info("Collect {0} KPIs {1}".format(self.RESOURCE_WORD, self._result)) + LOG.info("Collect %s KPIs %s", self.RESOURCE_WORD, self._result) return self._result def log(self): @@ -121,7 +124,7 @@ class IxLoadResourceHelper(ClientResourceHelper): LOG.debug(self.result[key]) -class IxLoadTrafficGen(SampleVNFTrafficGen): +class IxLoadTrafficGen(sample_vnf.SampleVNFTrafficGen): def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None): if resource_helper_type is None: @@ -131,6 +134,26 @@ class IxLoadTrafficGen(SampleVNFTrafficGen): resource_helper_type) self._result = {} + def update_gateways(self, links): + for name in links: + try: + gateway = next(intf["virtual-interface"]["dst_ip"] for intf in + self.setup_helper.vnfd_helper["vdu"][0][ + "external-interface"] if + intf["virtual-interface"]["vld_id"] == name) + + try: + links[name]["ip"]["gateway"] = gateway + except KeyError: + LOG.error("Invalid traffic profile: No IP section defined for %s", name) + raise + + except StopIteration: + LOG.debug("Cant find gateway for link %s", name) + links[name]["ip"]["gateway"] = "0.0.0.0" + + return links + def run_traffic(self, traffic_profile): ports = [] card = None @@ -142,11 +165,16 @@ class IxLoadTrafficGen(SampleVNFTrafficGen): for csv_file in glob.iglob(self.ssh_helper.join_bin_path('*.csv')): os.unlink(csv_file) + links_param = self.update_gateways( + traffic_profile.get_links_param()) + ixia_config = self.vnfd_helper.mgmt_interface["tg-config"] ixload_config = IXLOAD_CONFIG_TEMPLATE % ( ixia_config["ixchassis"], ports, card, self.vnfd_helper.mgmt_interface["ip"], self.ssh_helper.bin_path, - os.path.basename(self.resource_helper.resource_file_name)) + os.path.basename(self.resource_helper.resource_file_name), + jsonutils.dumps(links_param) + ) http_ixload_path = os.path.join(VNF_PATH, "../../traffic_profile") @@ -156,7 +184,7 @@ class IxLoadTrafficGen(SampleVNFTrafficGen): args="'%s'" % ixload_config) LOG.debug(cmd) - call(cmd, shell=True) + subprocess.call(cmd, shell=True) with open(self.ssh_helper.join_bin_path("ixLoad_HTTP_Client.csv")) as csv_file: lines = csv_file.readlines()[10:] @@ -170,9 +198,6 @@ class IxLoadTrafficGen(SampleVNFTrafficGen): self.resource_helper.log() self.resource_helper.data = self.resource_helper.make_aggregates() - def instantiate(self, scenario_cfg, context_cfg): - super(IxLoadTrafficGen, self).instantiate(scenario_cfg, context_cfg) - def terminate(self): - call(["pkill", "-9", "http_ixload.py"]) + subprocess.call(["pkill", "-9", "http_ixload.py"]) super(IxLoadTrafficGen, self).terminate() |