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.
14 """Map utilities library."""
17 from resources.libraries.python.VatExecutor import VatExecutor
21 """Utilities for manipulating MAP feature in VPP."""
24 def map_add_domain(vpp_node, ip4_pfx, ip6_pfx, ip6_src, ea_bits_len,
25 psid_offset, psid_len):
26 """Add map domain on node.
28 :param vpp_node: VPP node to add map domain on.
29 :param ip4_pfx: Rule IPv4 prefix.
30 :param ip6_pfx: Rule IPv6 prefix.
31 :param ip6_src: MAP domain IPv6 BR address / Tunnel source.
32 :param ea_bits_len: Embedded Address bits length.
33 :param psid_offset: Port Set Identifier (PSID) offset.
34 :param psid_len: Port Set Identifier (PSID) length.
39 :type ea_bits_len: int
40 :type psid_offset: int
42 :return: Index of created map domain.
44 :raises RuntimeError: If unable to add map domain.
46 output = VatExecutor.cmd_from_template(vpp_node, "map_add_domain.vat",
50 ea_bits_len=ea_bits_len,
51 psid_offset=psid_offset,
53 if output[0]["retval"] == 0:
54 return output[0]["index"]
56 raise RuntimeError('Unable to add map domain on node {}'
57 .format(vpp_node['host']))
60 def map_add_rule(vpp_node, index, psid, dst, delete=False):
61 """Add or delete map rule on node.
63 :param vpp_node: VPP node to add map rule on.
64 :param index: Map domain index to add rule to.
65 :param psid: Port Set Identifier.
66 :param dst: MAP CE IPv6 address.
67 :param delete: If set to True, delete rule. Default False.
73 :raises RuntimeError: If unable to add map rule.
75 output = VatExecutor.cmd_from_template(vpp_node, "map_add_del_rule.vat",
79 delete='del' if delete else '')
81 if output[0]["retval"] != 0:
82 raise RuntimeError('Unable to add map rule on node {}'
83 .format(vpp_node['host']))