vlib: prevent some signals from being executed on workers
[vpp.git] / src / plugins / map / gen-rules.py
1 #!/usr/bin/env python3
2
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:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16
17 import ipaddress
18 import argparse
19 import sys
20
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>
23
24 parser = argparse.ArgumentParser(description="MAP VPP configuration generator")
25 parser.add_argument("-t", action="store", dest="mapmode")
26 args = parser.parse_args()
27
28
29 #
30 # 1:1 Shared IPv4 address, shared BR
31 #
32 def shared11br():
33     ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
34     ip6_dst = ipaddress.ip_network("bbbb::/32")
35     psid_len = 6
36     for i in range(ip4_pfx.num_addresses):
37         print(
38             "map add domain ip4-pfx "
39             + str(ip4_pfx[i])
40             + "/32 ip6-pfx ::/0 ip6-shared-src cccc:bbbb::1",
41             "ea-bits-len 0 psid-offset 6 psid-len",
42             psid_len,
43         )
44         for psid in range(0x1 << psid_len):
45             print(
46                 "map add rule index",
47                 i,
48                 "psid",
49                 psid,
50                 "ip6-dst",
51                 ip6_dst[(i * (0x1 << psid_len)) + psid],
52             )
53
54
55 #
56 # 1:1 Shared IPv4 address
57 #
58 def shared11():
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")
62     psid_len = 6
63     for i in range(ip4_pfx.num_addresses):
64         print(
65             "map add domain ip4-pfx " + str(ip4_pfx[i]) + "/32 ip6-pfx ::/0 ip6-src",
66             ip6_src[i],
67             "ea-bits-len 0 psid-offset 6 psid-len",
68             psid_len,
69         )
70         for psid in range(0x1 << psid_len):
71             print(
72                 "map add rule index",
73                 i,
74                 "psid",
75                 psid,
76                 "ip6-dst",
77                 ip6_dst[(i * (0x1 << psid_len)) + psid],
78             )
79
80
81 #
82 # 1:1 Shared IPv4 address small
83 #
84 def smallshared11():
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")
88     psid_len = 6
89     for i in range(ip4_pfx.num_addresses):
90         print(
91             "map add domain ip4-pfx " + str(ip4_pfx[i]) + "/32 ip6-pfx ::/0 ip6-src",
92             ip6_src[i],
93             "ea-bits-len 0 psid-offset 6 psid-len",
94             psid_len,
95         )
96         for psid in range(0x1 << psid_len):
97             print(
98                 "map add rule index",
99                 i,
100                 "psid",
101                 psid,
102                 "ip6-dst",
103                 ip6_dst[(i * (0x1 << psid_len)) + psid],
104             )
105
106
107 #
108 # 1:1 Full IPv4 address
109 #
110 def full11():
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")
114     psid_len = 0
115     for i in range(ip4_pfx.num_addresses):
116         print(
117             "map add domain ip4-pfx "
118             + str(ip4_pfx[i])
119             + "/32 ip6-pfx "
120             + str(ip6_dst[i])
121             + "/128 ip6-src",
122             ip6_src[i],
123             "ea-bits-len 0 psid-offset 0 psid-len 0",
124         )
125
126
127 def full11br():
128     ip4_pfx = ipaddress.ip_network("20.0.0.0/16")
129     ip6_dst = ipaddress.ip_network("bbbb::/32")
130     psid_len = 0
131     for i in range(ip4_pfx.num_addresses):
132         print(
133             "map add domain ip4-pfx "
134             + str(ip4_pfx[i])
135             + "/32 ip6-pfx "
136             + str(ip6_dst[i])
137             + "/128 ip6-shared-src cccc:bbbb::1",
138             "ea-bits-len 0 psid-offset 0 psid-len 0",
139         )
140
141
142 #
143 # Algorithmic mapping Shared IPv4 address
144 #
145 def algo():
146     print(
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"
148     )
149     print(
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"
151     )
152
153
154 #
155 # IP4 forwarding
156 #
157 def ip4():
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")
161
162
163 globals()[args.mapmode]()