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()
29 # 1:1 Shared IPv4 address, shared BR
32 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
33 ip6_dst = ipaddress.ip_network("bbbb::/32")
35 for i in range(ip4_pfx.num_addresses):
37 "map add domain ip4-pfx "
39 + "/32 ip6-pfx ::/0 ip6-shared-src cccc:bbbb::1",
40 "ea-bits-len 0 psid-offset 6 psid-len",
43 for psid in range(0x1 << psid_len):
50 ip6_dst[(i * (0x1 << psid_len)) + psid],
55 # 1:1 Shared IPv4 address
58 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
59 ip6_src = ipaddress.ip_network("cccc:bbbb::/64")
60 ip6_dst = ipaddress.ip_network("bbbb::/32")
62 for i in range(ip4_pfx.num_addresses):
64 "map add domain ip4-pfx " + str(ip4_pfx[i]) + "/32 ip6-pfx ::/0 ip6-src",
66 "ea-bits-len 0 psid-offset 6 psid-len",
69 for psid in range(0x1 << psid_len):
76 ip6_dst[(i * (0x1 << psid_len)) + psid],
81 # 1:1 Shared IPv4 address small
84 ip4_pfx = ipaddress.ip_network("20.0.0.0/24")
85 ip6_src = ipaddress.ip_network("cccc:bbbb::/64")
86 ip6_dst = ipaddress.ip_network("bbbb::/32")
88 for i in range(ip4_pfx.num_addresses):
90 "map add domain ip4-pfx " + str(ip4_pfx[i]) + "/32 ip6-pfx ::/0 ip6-src",
92 "ea-bits-len 0 psid-offset 6 psid-len",
95 for psid in range(0x1 << psid_len):
102 ip6_dst[(i * (0x1 << psid_len)) + psid],
107 # 1:1 Full IPv4 address
110 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
111 ip6_src = ipaddress.ip_network("cccc:bbbb::/64")
112 ip6_dst = ipaddress.ip_network("bbbb::/32")
114 for i in range(ip4_pfx.num_addresses):
116 "map add domain ip4-pfx "
122 "ea-bits-len 0 psid-offset 0 psid-len 0",
127 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
128 ip6_dst = ipaddress.ip_network("bbbb::/32")
130 for i in range(ip4_pfx.num_addresses):
132 "map add domain ip4-pfx "
136 + "/128 ip6-shared-src cccc:bbbb::1",
137 "ea-bits-len 0 psid-offset 0 psid-len 0",
142 # Algorithmic mapping Shared IPv4 address
146 "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"
149 "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"
157 ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
158 for i in range(ip4_pfx.num_addresses):
159 print("ip route add " + str(ip4_pfx[i]) + "/32 via 172.16.0.2")
162 globals()[args.mapmode]()