b4568bf4b460b8dea159e4f55bdca7105c112131
[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 print_function, absolute_import
16
17 import logging
18
19
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
23
24 LOG = logging.getLogger(__name__)
25
26
27 class ProxTrafficGen(SampleVNFTrafficGen):
28
29     PROX_MODE = "Traffic Gen"
30     LUA_PARAMETER_NAME = "gen"
31
32     @staticmethod
33     def _sort_vpci(vnfd):
34         """
35
36         :param vnfd: vnfd.yaml
37         :return: trex_cfg.yaml file
38         """
39
40         def key_func(interface):
41             return interface["virtual-interface"]["vpci"], interface["name"]
42
43         ext_intf = vnfd["vdu"][0]["external-interface"]
44         return sorted(ext_intf, key=key_func)
45
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
49
50         if resource_helper_type is None:
51             resource_helper_type = ProxResourceHelper
52
53         super(ProxTrafficGen, self).__init__(name, vnfd, setup_env_helper_type,
54                                              resource_helper_type)
55         self._result = {}
56         # for some reason
57         self.vpci_if_name_ascending = self._sort_vpci(vnfd)
58         self._traffic_process = None
59
60     def listen_traffic(self, traffic_profile):
61         pass
62
63     def terminate(self):
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()