-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet_create.sh
executable file
·245 lines (226 loc) · 8.68 KB
/
net_create.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: $0 <operation> <use-case>
operation: s: for setup, d: for deletion
use-case: (IPv4: 1-19, IPv6: 20-30, DualStack: 40-50
1 (IPv4): Single IPv4 Network connected to a Neutron Router
10 (IPv4-External): Single IPv4 Network connected to a Neutron Router with external connectivity
11 (IPv4-EastWest): Two IPv4 Networks connected to a Neutron Router for validating east-west routing support
20 (IPv6): Single IPv6 Network connected to a Neutron Router
21 (IPv6-EastWest): Two IPv6 Networks connected to a Neutron Router for validating east-west routing support
40 (DualStack): Network with V4/V6 subnets connected to a Neutron Router
41 (DualStack-EastWest): Two IPv6 & IPv4 Networks connected to a Neutron Router for validating east-west routing support"
exit 1
fi
# CONSTANTS
EXT_NET_ONE="ext-net"
NET_ONE="n1"
NET_TWO="n2"
IPV4_EXT_SUBNET_ONE="ipv4_ext_s1"
IPV4_SUBNET_ONE="ipv4_s1"
IPV4_SUBNET_TWO="ipv4_s2"
IPV4_EXT_CIDR_ONE="192.168.124.0/24"
IPV4_CIDR_ONE="10.0.0.0/24"
IPV4_CIDR_TWO="20.0.0.0/24"
IPV6_SUBNET_ONE="ipv6_s1"
IPV6_SUBNET_TWO="ipv6_s2"
IPV6_CIDR_ONE="2001:db8:1111::/64"
IPV6_CIDR_TWO="2001:db8:2222::/64"
ROUTER_ONE="r1"
function create_network() {
echo "Creating a network with name $1"
neutron net-create $1
}
function create_ext_flat_network() {
echo "Creating an external flat network with name $1"
neutron net-create --router:external=True --provider:network_type flat --provider:physical_network public $1
}
function delete_network() {
echo "Deleting the network with name $1"
neutron net-delete $1
}
function create_v4_subnet() {
# $1 : SubnetName
# $2 : Network Name
# $3 : CIDR
echo "Creating an IPv4 Subnet with name $1, network $2, CIDR $3"
neutron subnet-create --name $1 --ip-version 4 $2 $3
}
function create_v4_ext_subnet() {
# $1 : SubnetName
# $2 : Network Name
# $3 : CIDR
echo "Creating an IPv4 Subnet with name $1, network $2, CIDR $3"
neutron subnet-create --name $1 --ip-version 4 --allocation-pool start=192.168.124.110,end=192.168.124.120 --gateway=192.168.124.1 --disable-dhcp $2 $3
}
function create_v6_subnet() {
# $1 : SubnetName
# $2 : Network Name
# $3 : CIDR
echo "Creating an IPv6 Subnet with name $1, network $2, CIDR $3"
neutron subnet-create --name $1 --ip-version 6 --ipv6-ra-mode slaac --ipv6-address-mode slaac $2 $3
}
function delete_subnet() {
echo "Deleting the Subnet with name $1"
neutron subnet-delete $1
}
function create_router() {
echo "Creating a Router with name $1"
neutron router-create $1
}
function delete_router() {
echo "Deleting Router with name $1"
neutron router-delete $1
}
function associate_router() {
# $1: RouterID
# $2: SubnetID
echo "Associating Router $1 with Subnet $2"
neutron router-interface-add $1 $2
}
function router_gateway_set() {
# $1: RouterID
# $2: NetworkID
echo "Associating Router $1 with External Network $2"
neutron router-gateway-set $1 $2
}
function router_gateway_clear() {
# $1: RouterID
# $2: NetworkID
echo "Disassociating Router $1 from External Network $2"
neutron router-gateway-clear $1 $2
}
function dissociate_router() {
# $1: RouterID
# $2: SubnetID
echo "Dissociating Router $1 from Subnet $2"
neutron router-interface-delete $1 $2
}
if [ $2 == 1 ]; then
# (IPv4): Single IPv4 Network connected to a Neutron Router
if [ $1 == 's' ]; then
create_network $NET_ONE
create_v4_subnet $IPV4_SUBNET_ONE $NET_ONE $IPV4_CIDR_ONE
create_router $ROUTER_ONE
associate_router $ROUTER_ONE $IPV4_SUBNET_ONE
elif [ $1 == 'd' ]; then
dissociate_router $ROUTER_ONE $IPV4_SUBNET_ONE
delete_router $ROUTER_ONE
delete_subnet $IPV4_SUBNET_ONE
delete_network $NET_ONE
fi
elif [ $2 == 10 ]; then
# (IPv4): Single IPv4 Network connected to a Neutron Router with external connectivity
if [ $1 == 's' ]; then
create_ext_flat_network $EXT_NET_ONE
create_v4_ext_subnet $IPV4_EXT_SUBNET_ONE $EXT_NET_ONE $IPV4_EXT_CIDR_ONE
create_network $NET_ONE
create_v4_subnet $IPV4_SUBNET_ONE $NET_ONE $IPV4_CIDR_ONE
create_router $ROUTER_ONE
associate_router $ROUTER_ONE $IPV4_SUBNET_ONE
router_gateway_set $ROUTER_ONE $EXT_NET_ONE
elif [ $1 == 'd' ]; then
router_gateway_clear $ROUTER_ONE $EXT_NET_ONE
dissociate_router $ROUTER_ONE $IPV4_SUBNET_ONE
delete_router $ROUTER_ONE
delete_subnet $IPV4_SUBNET_ONE
delete_subnet $IPV4_EXT_SUBNET_ONE
delete_network $NET_ONE
delete_network $EXT_NET_ONE
fi
elif [ $2 == 11 ]; then
# (IPv4-EastWest): IPv4 East-West Routing support
if [ $1 == 's' ]; then
create_network $NET_ONE
create_v4_subnet $IPV4_SUBNET_ONE $NET_ONE $IPV4_CIDR_ONE
create_network $NET_TWO
create_v4_subnet $IPV4_SUBNET_TWO $NET_TWO $IPV4_CIDR_TWO
create_router $ROUTER_ONE
associate_router $ROUTER_ONE $IPV4_SUBNET_ONE
associate_router $ROUTER_ONE $IPV4_SUBNET_TWO
elif [ $1 == 'd' ]; then
dissociate_router $ROUTER_ONE $IPV4_SUBNET_ONE
dissociate_router $ROUTER_ONE $IPV4_SUBNET_TWO
delete_router $ROUTER_ONE
delete_subnet $IPV4_SUBNET_ONE
delete_subnet $IPV4_SUBNET_TWO
delete_network $NET_ONE
delete_network $NET_TWO
fi
elif [ $2 == '20' ]; then
# (IPv6): Single IPv6 Network connected to a Neutron Router
if [ $1 == 's' ]; then
create_network $NET_ONE
create_v6_subnet $IPV6_SUBNET_ONE $NET_ONE $IPV6_CIDR_ONE
create_router $ROUTER_ONE
associate_router $ROUTER_ONE $IPV6_SUBNET_ONE
elif [ $1 == 'd' ]; then
dissociate_router $ROUTER_ONE $IPV6_SUBNET_ONE
delete_router $ROUTER_ONE
delete_subnet $IPV6_SUBNET_ONE
delete_network $NET_ONE
fi
elif [ $2 == '21' ]; then
# (IPv6-EastWest): Two IPv6 Networks connected to a Neutron Router for validating east-west routing support
if [ $1 == 's' ]; then
create_network $NET_ONE
create_v6_subnet $IPV6_SUBNET_ONE $NET_ONE $IPV6_CIDR_ONE
create_network $NET_TWO
create_v6_subnet $IPV6_SUBNET_TWO $NET_TWO $IPV6_CIDR_TWO
create_router $ROUTER_ONE
associate_router $ROUTER_ONE $IPV6_SUBNET_ONE
associate_router $ROUTER_ONE $IPV6_SUBNET_TWO
elif [ $1 == 'd' ]; then
dissociate_router $ROUTER_ONE $IPV6_SUBNET_ONE
dissociate_router $ROUTER_ONE $IPV6_SUBNET_TWO
delete_router $ROUTER_ONE
delete_subnet $IPV6_SUBNET_ONE
delete_subnet $IPV6_SUBNET_TWO
delete_network $NET_ONE
delete_network $NET_TWO
fi
elif [ $2 == '40' ]; then
# (DualStack): Network with V4/V6 subnets connected to a Neutron Router
if [ $1 == 's' ]; then
create_network $NET_ONE
create_v4_subnet $IPV4_SUBNET_ONE $NET_ONE $IPV4_CIDR_ONE
create_v6_subnet $IPV6_SUBNET_ONE $NET_ONE $IPV6_CIDR_ONE
create_router $ROUTER_ONE
associate_router $ROUTER_ONE $IPV4_SUBNET_ONE
associate_router $ROUTER_ONE $IPV6_SUBNET_ONE
elif [ $1 == 'd' ]; then
dissociate_router $ROUTER_ONE $IPV4_SUBNET_ONE
dissociate_router $ROUTER_ONE $IPV6_SUBNET_ONE
delete_router $ROUTER_ONE
delete_subnet $IPV4_SUBNET_ONE
delete_subnet $IPV6_SUBNET_ONE
delete_network $NET_ONE
fi
elif [ $2 == '41' ]; then
# (DualStack-EastWest): Two IPv6 & IPv4 Networks connected to a Neutron Router for validating east-west routing support
if [ $1 == 's' ]; then
create_network $NET_ONE
create_v4_subnet $IPV4_SUBNET_ONE $NET_ONE $IPV4_CIDR_ONE
create_v6_subnet $IPV6_SUBNET_ONE $NET_ONE $IPV6_CIDR_ONE
create_network $NET_TWO
create_v4_subnet $IPV4_SUBNET_TWO $NET_TWO $IPV4_CIDR_TWO
create_v6_subnet $IPV6_SUBNET_TWO $NET_TWO $IPV6_CIDR_TWO
create_router $ROUTER_ONE
associate_router $ROUTER_ONE $IPV4_SUBNET_ONE
associate_router $ROUTER_ONE $IPV4_SUBNET_TWO
associate_router $ROUTER_ONE $IPV6_SUBNET_ONE
associate_router $ROUTER_ONE $IPV6_SUBNET_TWO
elif [ $1 == 'd' ]; then
dissociate_router $ROUTER_ONE $IPV4_SUBNET_ONE
dissociate_router $ROUTER_ONE $IPV4_SUBNET_TWO
dissociate_router $ROUTER_ONE $IPV6_SUBNET_ONE
dissociate_router $ROUTER_ONE $IPV6_SUBNET_TWO
delete_router $ROUTER_ONE
delete_subnet $IPV4_SUBNET_ONE
delete_subnet $IPV4_SUBNET_TWO
delete_subnet $IPV6_SUBNET_ONE
delete_subnet $IPV6_SUBNET_TWO
delete_network $NET_ONE
delete_network $NET_TWO
fi
fi