Merge "Add methods to get an existing stack"
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / vfw_vnf.py
1 # Copyright (c) 2016-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 import logging
16
17 from yardstick.common import utils
18 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF, DpdkVnfSetupEnvHelper
19 from yardstick.network_services.yang_model import YangModel
20
21 LOG = logging.getLogger(__name__)
22
23 # vFW should work the same on all systems, we can provide the binary
24 FW_PIPELINE_COMMAND = """sudo {tool_path} -p {port_mask_hex} -f {cfg_file} -s {script}"""
25
26 FW_COLLECT_KPI = (r"""VFW TOTAL:[^p]+pkts_received"?:\s(\d+),[^p]+pkts_fw_forwarded"?:\s(\d+),"""
27                   r"""[^p]+pkts_drop_fw"?:\s(\d+),\s""")
28
29
30 class FWApproxSetupEnvHelper(DpdkVnfSetupEnvHelper):
31
32     APP_NAME = "vFW"
33     CFG_CONFIG = "/tmp/vfw_config"
34     CFG_SCRIPT = "/tmp/vfw_script"
35     DEFAULT_CONFIG_TPL_CFG = "vfw.cfg"
36     PIPELINE_COMMAND = FW_PIPELINE_COMMAND
37     SW_DEFAULT_CORE = 5
38     HW_DEFAULT_CORE = 2
39     VNF_TYPE = "VFW"
40
41
42 class FWApproxVnf(SampleVNF):
43
44     APP_NAME = "vFW"
45     APP_WORD = 'vfw'
46     COLLECT_KPI = FW_COLLECT_KPI
47
48     COLLECT_MAP = {
49         'packets_in': 1,
50         'packets_fwd': 2,
51         'packets_dropped': 3,
52     }
53
54     def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
55         if setup_env_helper_type is None:
56             setup_env_helper_type = FWApproxSetupEnvHelper
57
58         super(FWApproxVnf, self).__init__(name, vnfd, setup_env_helper_type, resource_helper_type)
59         self.vfw_rules = None
60
61     def _start_vnf(self):
62         yang_model_path = utils.find_relative_file(
63             self.scenario_helper.options['rules'],
64             self.scenario_helper.task_path)
65         yang_model = YangModel(yang_model_path)
66         self.vfw_rules = yang_model.get_rules()
67         super(FWApproxVnf, self)._start_vnf()