1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
15 from robot.api import logger
17 from resources.libraries.python.VatExecutor import VatExecutor, VatTerminal
20 class Classify(object):
21 """Classify utilities."""
24 def vpp_create_classify_table(node, ip_version, direction):
25 """Create classify table.
27 :param node: VPP node to create classify table.
28 :param ip_version: Version of IP protocol.
29 :param direction: Direction of traffic - src/dst.
33 :return table_index: Classify table index.
34 :return skip_n: Number of skip vectors.
35 :return match_n: Number of match vectors.
36 :rtype table_index: int
40 output = VatExecutor.cmd_from_template(node, "classify_add_table.vat",
41 ip_version=ip_version,
44 if output[0]["retval"] == 0:
45 table_index = output[0]["new_table_index"]
46 skip_n = output[0]["skip_n_vectors"]
47 match_n = output[0]["match_n_vectors"]
48 logger.trace('Classify table with table_index {} created on node {}'
49 .format(table_index, node['host']))
51 raise RuntimeError('Unable to create classify table on node {}'
52 .format(node['host']))
54 return table_index, skip_n, match_n
57 def vpp_configure_classify_session(node, acl_method, table_index, skip_n,
58 match_n, ip_version, direction, address):
59 """Configuration of classify session.
61 :param node: VPP node to setup classify session.
62 :param acl_method: ACL method - deny/permit.
63 :param table_index: Classify table index.
64 :param skip_n: Number of skip vectors based on mask.
65 :param match_n: Number of match vectors based on mask.
66 :param ip_version: Version of IP protocol.
67 :param direction: Direction of traffic - src/dst.
68 :param address: IPv4 or IPv6 address.
71 :type table_index: int
78 with VatTerminal(node) as vat:
79 vat.vat_terminal_exec_cmd_from_template("classify_add_session.vat",
80 acl_method=acl_method,
81 table_index=table_index,
84 ip_version=ip_version,