NSB: fix port topology
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / acl_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 from __future__ import absolute_import
16 from __future__ import print_function
17 import logging
18
19 from yardstick.benchmark.scenarios.networking.vnf_generic import find_relative_file
20 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF, DpdkVnfSetupEnvHelper
21 from yardstick.network_services.yang_model import YangModel
22
23 LOG = logging.getLogger(__name__)
24
25 # ACL should work the same on all systems, we can provide the binary
26 ACL_PIPELINE_COMMAND = \
27     'sudo {tool_path} -p {port_mask_hex} -f {cfg_file} -s {script}'
28
29 ACL_COLLECT_KPI = r"""\
30 ACL TOTAL:[^p]+pkts_processed"?:\s(\d+),[^p]+pkts_drop"?:\s(\d+),[^p]+pkts_received"?:\s(\d+),"""
31
32
33 class AclApproxSetupEnvSetupEnvHelper(DpdkVnfSetupEnvHelper):
34
35     APP_NAME = "vACL"
36     CFG_CONFIG = "/tmp/acl_config"
37     CFG_SCRIPT = "/tmp/acl_script"
38     PIPELINE_COMMAND = ACL_PIPELINE_COMMAND
39     HW_DEFAULT_CORE = 2
40     SW_DEFAULT_CORE = 5
41     DEFAULT_CONFIG_TPL_CFG = "acl.cfg"
42     VNF_TYPE = "ACL"
43
44
45 class AclApproxVnf(SampleVNF):
46
47     APP_NAME = "vACL"
48     APP_WORD = 'acl'
49     COLLECT_KPI = ACL_COLLECT_KPI
50
51     COLLECT_MAP = {
52         'packets_in': 3,
53         'packets_fwd': 1,
54         'packets_dropped': 2,
55     }
56
57     def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
58         if setup_env_helper_type is None:
59             setup_env_helper_type = AclApproxSetupEnvSetupEnvHelper
60
61         super(AclApproxVnf, self).__init__(name, vnfd, setup_env_helper_type, resource_helper_type)
62         self.acl_rules = None
63
64     def scale(self, flavor=""):
65         raise NotImplementedError
66
67     def _start_vnf(self):
68         yang_model_path = find_relative_file(self.scenario_helper.options['rules'],
69                                              self.scenario_helper.task_path)
70         yang_model = YangModel(yang_model_path)
71         self.acl_rules = yang_model.get_rules()
72         super(AclApproxVnf, self)._start_vnf()