aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/Map.py
diff options
context:
space:
mode:
authorMatej Klotton <mklotton@cisco.com>2016-08-11 18:33:34 +0200
committerJan Gelety <jgelety@cisco.com>2016-08-25 23:03:52 +0000
commitf591e5d8bd72f5f60d3c26222b14b512366fedc3 (patch)
tree741b9508d6b85a97f564eeb214ea83740fbc9803 /resources/libraries/python/Map.py
parent1942363fa62b6a079ae5552d20c90eb55f0033d9 (diff)
CSIT-353: Add basic map-t tests
Change-Id: I78075e445cdd61e0e3cf9353bddeaf6e6bc978fa Signed-off-by: Matej Klotton <mklotton@cisco.com>
Diffstat (limited to 'resources/libraries/python/Map.py')
-rw-r--r--resources/libraries/python/Map.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/resources/libraries/python/Map.py b/resources/libraries/python/Map.py
index b98d488e73..a1db3a8461 100644
--- a/resources/libraries/python/Map.py
+++ b/resources/libraries/python/Map.py
@@ -24,7 +24,7 @@ class Map(object):
@staticmethod
def map_add_domain(vpp_node, ip4_pfx, ip6_pfx, ip6_src, ea_bits_len,
- psid_offset, psid_len):
+ psid_offset, psid_len, map_t=False):
"""Add map domain on node.
:param vpp_node: VPP node to add map domain on.
@@ -34,6 +34,8 @@ class Map(object):
:param ea_bits_len: Embedded Address bits length.
:param psid_offset: Port Set Identifier (PSID) offset.
:param psid_len: Port Set Identifier (PSID) length.
+ :param map_t: Mapping using translation instead of encapsulation.
+ Default False.
:type vpp_node: dict
:type ip4_pfx: str
:type ip6_pfx: str
@@ -41,17 +43,21 @@ class Map(object):
:type ea_bits_len: int
:type psid_offset: int
:type psid_len: int
+ :type map_t: bool
:return: Index of created map domain.
:rtype: int
:raises RuntimeError: If unable to add map domain.
"""
+ translate = 'map-t' if map_t else ''
+
output = VatExecutor.cmd_from_template(vpp_node, "map_add_domain.vat",
ip4_pfx=ip4_pfx,
ip6_pfx=ip6_pfx,
ip6_src=ip6_src,
ea_bits_len=ea_bits_len,
psid_offset=psid_offset,
- psid_len=psid_len)
+ psid_len=psid_len,
+ map_t=translate)
if output[0]["retval"] == 0:
return output[0]["index"]
else:
@@ -261,3 +267,22 @@ class Map(object):
address |= interface_id # add Interface ID bits
return str(ipaddress.ip_address(address))
+
+ @staticmethod
+ def compute_ipv6_map_source_address(ipv6_pfx, ipv4_src):
+ """Compute IPv6 source address from IPv4 address for MAP-T algorithm.
+
+ :param ipv6_pfx: 96 bit long IPv6 prefix.
+ :param ipv4_src: IPv4 source address
+ :type ipv6_pfx: str
+ :type ipv4_src: str
+ :return: IPv6 address, combination of IPv6 prefix and IPv4 address.
+ :rtype: str
+ """
+ ipv6_net = ipaddress.ip_network(unicode(ipv6_pfx))
+ ipv4_host = ipaddress.ip_address(unicode(ipv4_src))
+
+ address = ipv6_net.network_address._ip
+ address |= ipv4_host._ip
+
+ return str(ipaddress.ip_address(address))