3 # Copyright (c) 2015 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
21 # map add domain ip4-pfx <pfx> ip6-pfx ::/0 ip6-src <ip6-src> ea-bits-len 0 psid-offset 6 psid-len 6
22 # map add rule index <0> psid <psid> ip6-dst <ip6-dst>
24 parser = argparse.ArgumentParser(description="MAP VPP configuration generator")
25 parser.add_argument("-t", action="store", dest="mapmode")
26 args = parser.parse_args()
30 # 1:1 Shared IPv4 address, shared BR
33 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
34 ip6_dst = ipaddress.ip_network("bbbb::/32")
36 for i in range(ip4_pfx.num_addresses):
38 "map add domain ip4-pfx "
40 + "/32 ip6-pfx ::/0 ip6-shared-src cccc:bbbb::1",
41 "ea-bits-len 0 psid-offset 6 psid-len",
44 for psid in range(0x1 << psid_len):
51 ip6_dst[(i * (0x1 << psid_len)) + psid],
56 # 1:1 Shared IPv4 address
59 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
60 ip6_src = ipaddress.ip_network("cccc:bbbb::/64")
61 ip6_dst = ipaddress.ip_network("bbbb::/32")
63 for i in range(ip4_pfx.num_addresses):
65 "map add domain ip4-pfx " + str(ip4_pfx[i]) + "/32 ip6-pfx ::/0 ip6-src",
67 "ea-bits-len 0 psid-offset 6 psid-len",
70 for psid in range(0x1 << psid_len):
77 ip6_dst[(i * (0x1 << psid_len)) + psid],
82 # 1:1 Shared IPv4 address small
85 ip4_pfx = ipaddress.ip_network("20.0.0.0/24")
86 ip6_src = ipaddress.ip_network("cccc:bbbb::/64")
87 ip6_dst = ipaddress.ip_network("bbbb::/32")
89 for i in range(ip4_pfx.num_addresses):
91 "map add domain ip4-pfx " + str(ip4_pfx[i]) + "/32 ip6-pfx ::/0 ip6-src",
93 "ea-bits-len 0 psid-offset 6 psid-len",
96 for psid in range(0x1 << psid_len):
103 ip6_dst[(i * (0x1 << psid_len)) + psid],
108 # 1:1 Full IPv4 address
111 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
112 ip6_src = ipaddress.ip_network("cccc:bbbb::/64")
113 ip6_dst = ipaddress.ip_network("bbbb::/32")
115 for i in range(ip4_pfx.num_addresses):
117 "map add domain ip4-pfx "
123 "ea-bits-len 0 psid-offset 0 psid-len 0",
128 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
129 ip6_dst = ipaddress.ip_network("bbbb::/32")
131 for i in range(ip4_pfx.num_addresses):
133 "map add domain ip4-pfx "
137 + "/128 ip6-shared-src cccc:bbbb::1",
138 "ea-bits-len 0 psid-offset 0 psid-len 0",
143 # Algorithmic mapping Shared IPv4 address
147 "map add domain ip4-pfx 20.0.0.0/24 ip6-pfx bbbb::/32 ip6-src cccc:bbbb::1 ea-bits-len 16 psid-offset 6 psid-len 8"
150 "map add domain ip4-pfx 20.0.1.0/24 ip6-pfx bbbb:1::/32 ip6-src cccc:bbbb::2 ea-bits-len 8 psid-offset 0 psid-len 0"
158 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
159 for i in range(ip4_pfx.num_addresses):
160 print("ip route add " + str(ip4_pfx[i]) + "/32 via 172.16.0.2")
163 globals()[args.mapmode]()