X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FMap.py;h=a1db3a846154550b55b551e7404feaa05be9a574;hp=b98d488e73e916c74d6dacd78d7360bb765ed0d1;hb=f591e5d8bd72f5f60d3c26222b14b512366fedc3;hpb=1942363fa62b6a079ae5552d20c90eb55f0033d9 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))