1 # Copyright (c) 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 print_function, absolute_import
19 from yardstick.network_services.utils import get_nsb_option
20 from yardstick.network_services.vnf_generic.vnf.prox_vnf import ProxApproxVnf
21 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTrafficGen
23 LOG = logging.getLogger(__name__)
26 class ProxTrafficGen(SampleVNFTrafficGen):
29 PROX_MODE = "Traffic Gen"
30 LUA_PARAMETER_NAME = "gen"
37 :param vnfd: vnfd.yaml
38 :return: trex_cfg.yaml file
41 def key_func(interface):
42 return interface["virtual-interface"]["vpci"], interface["name"]
44 ext_intf = vnfd["vdu"][0]["external-interface"]
45 return sorted(ext_intf, key=key_func)
47 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
48 # don't call superclass, use custom wrapper of ProxApproxVnf
49 self._vnf_wrapper = ProxApproxVnf(name, vnfd, setup_env_helper_type, resource_helper_type)
50 self.bin_path = get_nsb_option('bin_path', '')
51 self.name = self._vnf_wrapper.name
52 self.ssh_helper = self._vnf_wrapper.ssh_helper
53 self.setup_helper = self._vnf_wrapper.setup_helper
54 self.resource_helper = self._vnf_wrapper.resource_helper
55 self.scenario_helper = self._vnf_wrapper.scenario_helper
57 self.runs_traffic = True
58 self.traffic_finished = False
59 self.tg_port_pairs = None
60 self._tg_process = None
61 self._traffic_process = None
63 # used for generating stats
64 self.vpci_if_name_ascending = self._sort_vpci(vnfd)
65 self.resource_helper.vpci_if_name_ascending = self._sort_vpci(vnfd)
67 def listen_traffic(self, traffic_profile):
71 self._vnf_wrapper.terminate()
72 super(ProxTrafficGen, self).terminate()
74 def instantiate(self, scenario_cfg, context_cfg):
75 self._vnf_wrapper.instantiate(scenario_cfg, context_cfg)
76 self._tg_process = self._vnf_wrapper._vnf_process
78 def wait_for_instantiate(self):
79 self._vnf_wrapper.wait_for_instantiate()