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.
19 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxDpdkVnfSetupEnvHelper
20 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper
21 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
23 LOG = logging.getLogger(__name__)
26 class ProxApproxVnf(SampleVNF):
30 PROX_MODE = "Workload"
31 VNF_PROMPT = "PROX started"
32 LUA_PARAMETER_NAME = "sut"
34 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
35 if setup_env_helper_type is None:
36 setup_env_helper_type = ProxDpdkVnfSetupEnvHelper
38 if resource_helper_type is None:
39 resource_helper_type = ProxResourceHelper
41 super(ProxApproxVnf, self).__init__(name, vnfd, setup_env_helper_type,
44 def _vnf_up_post(self):
45 self.resource_helper.up_post()
47 def vnf_execute(self, cmd, *args, **kwargs):
48 # try to execute with socket commands
49 # ignore socket errors, e.g. when using force_quit
50 ignore_errors = kwargs.pop("_ignore_errors", False)
52 return self.resource_helper.execute(cmd, *args, **kwargs)
54 if not ignore_errors or e.errno not in {errno.EPIPE, errno.ESHUTDOWN}:
57 def collect_kpi(self):
58 if self.resource_helper is None:
63 "collect_stats": {"core": {}},
67 intf_count = len(self.vnfd_helper.interfaces)
68 if intf_count not in {1, 2, 4}:
69 raise RuntimeError("Failed ..Invalid no of ports .. "
70 "1, 2 or 4 ports only supported at this time")
72 port_stats = self.vnf_execute('port_stats', range(intf_count))
74 rx_total = port_stats[6]
75 tx_total = port_stats[7]
77 LOG.error("port_stats parse fail %s", port_stats)
78 # return empty dict so we don't mess up existing KPIs
82 "packets_in": tx_total,
83 "packets_dropped": (tx_total - rx_total),
84 "packets_fwd": rx_total,
85 # we share ProxResourceHelper with TG, but we want to collect
86 # collectd KPIs here and not TG KPIs, so use a different method name
87 "collect_stats": self.resource_helper.collect_collectd_kpi(),
89 LOG.debug("%s collect KPIs %s", self.APP_NAME, result)
93 # this should be standardized for all VNFs or removed
94 self.setup_helper.tear_down()
97 # try to quit with socket commands
98 self.vnf_execute("stop_all")
99 self.vnf_execute("quit")
100 # hopefully quit succeeds and socket closes, so ignore force_quit socket errors
101 self.vnf_execute("force_quit", _ignore_errors=True)
102 if self._vnf_process:
103 self._vnf_process.terminate()
104 self.setup_helper.kill_vnf()
106 self.resource_helper.stop_collect()