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
20 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxDpdkVnfSetupEnvHelper
21 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper
22 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTrafficGen
24 LOG = logging.getLogger(__name__)
27 class ProxTrafficGen(SampleVNFTrafficGen):
29 PROX_MODE = "Traffic Gen"
30 LUA_PARAMETER_NAME = "gen"
36 :param vnfd: vnfd.yaml
37 :return: trex_cfg.yaml file
40 def key_func(interface):
41 return interface["virtual-interface"]["vpci"], interface["name"]
43 ext_intf = vnfd["vdu"][0]["external-interface"]
44 return sorted(ext_intf, key=key_func)
46 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
47 if setup_env_helper_type is None:
48 setup_env_helper_type = ProxDpdkVnfSetupEnvHelper
50 if resource_helper_type is None:
51 resource_helper_type = ProxResourceHelper
53 super(ProxTrafficGen, self).__init__(name, vnfd, setup_env_helper_type,
57 self.vpci_if_name_ascending = self._sort_vpci(vnfd)
58 self._traffic_process = None
60 def listen_traffic(self, traffic_profile):
64 super(ProxTrafficGen, self).terminate()
65 self.resource_helper.terminate()
66 if self._traffic_process:
67 self._traffic_process.terminate()
68 self.ssh_helper.execute("pkill prox")
69 self.resource_helper.rebind_drivers()