Merge "Deprecate authentication variable OS_TENANT_NAME"
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / tg_prox.py
1 # Copyright (c) 2017 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 from __future__ import absolute_import
16
17 import logging
18
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
22
23 LOG = logging.getLogger(__name__)
24
25
26 class ProxTrafficGen(SampleVNFTrafficGen):
27
28     APP_NAME = 'ProxTG'
29     PROX_MODE = "Traffic Gen"
30     LUA_PARAMETER_NAME = "gen"
31     WAIT_TIME = 1
32
33     @staticmethod
34     def _sort_vpci(vnfd):
35         """
36
37         :param vnfd: vnfd.yaml
38         :return: trex_cfg.yaml file
39         """
40
41         def key_func(interface):
42             return interface["virtual-interface"]["vpci"], interface["name"]
43
44         ext_intf = vnfd["vdu"][0]["external-interface"]
45         return sorted(ext_intf, key=key_func)
46
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
56
57         self.runs_traffic = True
58         self.traffic_finished = False
59         self._tg_process = None
60         self._traffic_process = None
61
62         # used for generating stats
63         self.vpci_if_name_ascending = self._sort_vpci(vnfd)
64         self.resource_helper.vpci_if_name_ascending = self._sort_vpci(vnfd)
65
66     def terminate(self):
67         self._vnf_wrapper.terminate()
68         super(ProxTrafficGen, self).terminate()
69
70     def instantiate(self, scenario_cfg, context_cfg):
71         self._vnf_wrapper.instantiate(scenario_cfg, context_cfg)
72         self._tg_process = self._vnf_wrapper._vnf_process
73
74     def wait_for_instantiate(self):
75         self._vnf_wrapper.wait_for_instantiate()