blob: 5e5230620616222c5b223306fd6c4073c1236499 [file] [log] [blame]
Sean M. Collins2a242512016-05-03 09:03:09 -04001#!/bin/bash
2# Subnet IP version
3IP_VERSION=${IP_VERSION:-"4+6"}
4# Validate IP_VERSION
5if [[ $IP_VERSION != "4" ]] && [[ $IP_VERSION != "6" ]] && [[ $IP_VERSION != "4+6" ]]; then
6 die $LINENO "IP_VERSION must be either 4, 6, or 4+6"
7fi
8# Specify if the initial private and external networks should be created
9NEUTRON_CREATE_INITIAL_NETWORKS=${NEUTRON_CREATE_INITIAL_NETWORKS:-True}
10
11## Provider Network Information
12PROVIDER_SUBNET_NAME=${PROVIDER_SUBNET_NAME:-"provider_net"}
13IPV6_PROVIDER_SUBNET_NAME=${IPV6_PROVIDER_SUBNET_NAME:-"provider_net_v6"}
14IPV6_PROVIDER_FIXED_RANGE=${IPV6_PROVIDER_FIXED_RANGE:-}
15IPV6_PROVIDER_NETWORK_GATEWAY=${IPV6_PROVIDER_NETWORK_GATEWAY:-}
16
17PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
Ihar Hrachyshka7b5c7dc2016-07-15 20:17:13 +020018PUBLIC_BRIDGE_MTU=${PUBLIC_BRIDGE_MTU:-1500}
Sean M. Collins2a242512016-05-03 09:03:09 -040019
20# If Q_USE_PUBLIC_VETH=True, create and use a veth pair instead of
21# PUBLIC_BRIDGE. This is intended to be used with
22# Q_USE_PROVIDERNET_FOR_PUBLIC=True.
23Q_USE_PUBLIC_VETH=${Q_USE_PUBLIC_VETH:-False}
24Q_PUBLIC_VETH_EX=${Q_PUBLIC_VETH_EX:-veth-pub-ex}
25Q_PUBLIC_VETH_INT=${Q_PUBLIC_VETH_INT:-veth-pub-int}
26
vsaienkod8942212016-05-13 12:51:30 +030027# The next variable is configured by plugin
Sean M. Collins2a242512016-05-03 09:03:09 -040028# e.g. _configure_neutron_l3_agent or lib/neutron_plugins/*
29#
Sean M. Collins2a242512016-05-03 09:03:09 -040030# L3 routers exist per tenant
31Q_L3_ROUTER_PER_TENANT=${Q_L3_ROUTER_PER_TENANT:-True}
32
33
34# Use flat providernet for public network
35#
36# If Q_USE_PROVIDERNET_FOR_PUBLIC=True, use a flat provider network
37# for external interface of neutron l3-agent. In that case,
38# PUBLIC_PHYSICAL_NETWORK specifies provider:physical_network value
39# used for the network. In case of ofagent, you should add the
40# corresponding entry to your OFAGENT_PHYSICAL_INTERFACE_MAPPINGS.
41# For openvswitch agent, you should add the corresponding entry to
42# your OVS_BRIDGE_MAPPINGS.
43#
44# eg. (ofagent)
45# Q_USE_PROVIDERNET_FOR_PUBLIC=True
46# Q_USE_PUBLIC_VETH=True
47# PUBLIC_PHYSICAL_NETWORK=public
48# OFAGENT_PHYSICAL_INTERFACE_MAPPINGS=public:veth-pub-int
49#
50# eg. (openvswitch agent)
51# Q_USE_PROVIDERNET_FOR_PUBLIC=True
52# PUBLIC_PHYSICAL_NETWORK=public
53# OVS_BRIDGE_MAPPINGS=public:br-ex
Kevin Benton7da968a2016-07-22 06:02:22 +000054Q_USE_PROVIDERNET_FOR_PUBLIC=${Q_USE_PROVIDERNET_FOR_PUBLIC:-False}
Sean M. Collins2a242512016-05-03 09:03:09 -040055PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK:-public}
56
57# Generate 40-bit IPv6 Global ID to comply with RFC 4193
58IPV6_GLOBAL_ID=`uuidgen | sed s/-//g | cut -c 23- | sed -e "s/\(..\)\(....\)\(....\)/\1:\2:\3/"`
59
60# IPv6 gateway and subnet defaults, in case they are not customized in localrc
61IPV6_RA_MODE=${IPV6_RA_MODE:-slaac}
62IPV6_ADDRESS_MODE=${IPV6_ADDRESS_MODE:-slaac}
63IPV6_PUBLIC_SUBNET_NAME=${IPV6_PUBLIC_SUBNET_NAME:-ipv6-public-subnet}
64IPV6_PRIVATE_SUBNET_NAME=${IPV6_PRIVATE_SUBNET_NAME:-ipv6-private-subnet}
65FIXED_RANGE_V6=${FIXED_RANGE_V6:-fd$IPV6_GLOBAL_ID::/64}
66IPV6_PRIVATE_NETWORK_GATEWAY=${IPV6_PRIVATE_NETWORK_GATEWAY:-fd$IPV6_GLOBAL_ID::1}
67IPV6_PUBLIC_RANGE=${IPV6_PUBLIC_RANGE:-2001:db8::/64}
68IPV6_PUBLIC_NETWORK_GATEWAY=${IPV6_PUBLIC_NETWORK_GATEWAY:-2001:db8::2}
69IPV6_ROUTER_GW_IP=${IPV6_ROUTER_GW_IP:-2001:db8::1}
70
71# Gateway and subnet defaults, in case they are not customized in localrc
72NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
73PUBLIC_NETWORK_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
74PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
75PUBLIC_SUBNET_NAME=${PUBLIC_SUBNET_NAME:-"public-subnet"}
76
77# Subnetpool defaults
78SUBNETPOOL_NAME=${SUBNETPOOL_NAME:-"shared-default-subnetpool"}
79
80SUBNETPOOL_PREFIX_V4=${SUBNETPOOL_PREFIX_V4:-10.0.0.0/8}
81SUBNETPOOL_PREFIX_V6=${SUBNETPOOL_PREFIX_V6:-2001:db8:8000::/48}
82
83SUBNETPOOL_SIZE_V4=${SUBNETPOOL_SIZE_V4:-24}
84SUBNETPOOL_SIZE_V6=${SUBNETPOOL_SIZE_V6:-64}
85
86function _determine_config_l3 {
Angus Leesa1c70f22016-05-31 14:43:14 +100087 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
Sean M. Collins2a242512016-05-03 09:03:09 -040088 echo "$opts"
89}
90
91function _configure_neutron_l3_agent {
Sean M. Collins2a242512016-05-03 09:03:09 -040092
93 cp $NEUTRON_DIR/etc/l3_agent.ini.sample $Q_L3_CONF_FILE
94
Sean M. Collins2a242512016-05-03 09:03:09 -040095 iniset $Q_L3_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean M. Collinsa2ed0552016-05-11 15:35:10 -040096 iniset $Q_L3_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Sean M. Collins2a242512016-05-03 09:03:09 -040097 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Sean M. Collinsa2ed0552016-05-11 15:35:10 -040098 iniset $Q_L3_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Sean M. Collins2a242512016-05-03 09:03:09 -040099 fi
100
101 _neutron_setup_interface_driver $Q_L3_CONF_FILE
102
Stephen Finucane24e29f22016-06-15 14:31:51 +0100103 neutron_plugin_configure_l3_agent $Q_L3_CONF_FILE
Sean M. Collins2a242512016-05-03 09:03:09 -0400104
Sean Dague6a008fa2016-08-03 15:09:01 -0400105 # If we've given a PUBLIC_INTERFACE to take over, then we assume
106 # that we can own the whole thing, and privot it into the OVS
107 # bridge. If we are not, we're probably on a single interface
108 # machine, and we just setup NAT so that fixed guests can get out.
109 if [[ -n "$PUBLIC_INTERFACE" ]]; then
110 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
Sean M. Collins2a242512016-05-03 09:03:09 -0400111
Sean Dague6a008fa2016-08-03 15:09:01 -0400112 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
113 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
114 fi
115 else
116 local default_dev=""
117 default_dev=$(ip route | grep ^default | awk '{print $5}')
118 sudo iptables -t nat -A POSTROUTING -o $default_dev -s $FLOATING_RANGE -j MASQUERADE
Sean M. Collins2a242512016-05-03 09:03:09 -0400119 fi
120}
121
122# Explicitly set router id in l3 agent configuration
123function _neutron_set_router_id {
124 if [[ "$Q_L3_ROUTER_PER_TENANT" == "False" ]]; then
125 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
126 fi
127}
128
129# Get ext_gw_interface depending on value of Q_USE_PUBLIC_VETH
130function _neutron_get_ext_gw_interface {
131 if [[ "$Q_USE_PUBLIC_VETH" == "True" ]]; then
132 echo $Q_PUBLIC_VETH_EX
133 else
134 # Disable in-band as we are going to use local port
135 # to communicate with VMs
136 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
137 other_config:disable-in-band=true
138 echo $PUBLIC_BRIDGE
139 fi
140}
141
142function create_neutron_initial_network {
143 local project_id
144 project_id=$(openstack project list | grep " demo " | get_field 1)
145 die_if_not_set $LINENO project_id "Failure retrieving project_id for demo"
146
147 # Allow drivers that need to create an initial network to do so here
148 if type -p neutron_plugin_create_initial_network_profile > /dev/null; then
149 neutron_plugin_create_initial_network_profile $PHYSICAL_NETWORK
150 fi
151
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000152 if is_networking_extension_supported "auto-allocated-topology"; then
153 if [[ "$IP_VERSION" =~ 4.* ]]; then
154 SUBNETPOOL_V4_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnetpool-create $SUBNETPOOL_NAME --default-prefixlen $SUBNETPOOL_SIZE_V4 --pool-prefix $SUBNETPOOL_PREFIX_V4 --shared --is-default=True | grep ' id ' | get_field 2)
155 fi
156 if [[ "$IP_VERSION" =~ .*6 ]]; then
157 SUBNETPOOL_V6_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnetpool-create $SUBNETPOOL_NAME --default-prefixlen $SUBNETPOOL_SIZE_V6 --pool-prefix $SUBNETPOOL_PREFIX_V6 --shared --is-default=True | grep ' id ' | get_field 2)
158 fi
159 fi
160
Sean M. Collins2a242512016-05-03 09:03:09 -0400161 if is_provider_network; then
162 die_if_not_set $LINENO PHYSICAL_NETWORK "You must specify the PHYSICAL_NETWORK"
163 die_if_not_set $LINENO PROVIDER_NETWORK_TYPE "You must specify the PROVIDER_NETWORK_TYPE"
164 NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create $PHYSICAL_NETWORK --tenant_id $project_id --provider:network_type $PROVIDER_NETWORK_TYPE --provider:physical_network "$PHYSICAL_NETWORK" ${SEGMENTATION_ID:+--provider:segmentation_id $SEGMENTATION_ID} --shared | grep ' id ' | get_field 2)
165 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PHYSICAL_NETWORK $project_id"
166
167 if [[ "$IP_VERSION" =~ 4.* ]]; then
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000168 if [ -z $SUBNETPOOL_V4_ID ]; then
169 fixed_range_v4=$FIXED_RANGE
170 fi
171 SUBNET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create --tenant_id $project_id --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --name $PROVIDER_SUBNET_NAME --gateway $NETWORK_GATEWAY ${SUBNETPOOL_V4_ID:+--subnetpool $SUBNETPOOL_V4_ID} $NET_ID $fixed_range_v4 | grep ' id ' | get_field 2)
Sean M. Collins2a242512016-05-03 09:03:09 -0400172 die_if_not_set $LINENO SUBNET_ID "Failure creating SUBNET_ID for $PROVIDER_SUBNET_NAME $project_id"
173 fi
174
Sean M. Collinse34ec992016-06-07 12:36:50 -0400175 if [[ "$IP_VERSION" =~ .*6 ]]; then
176 die_if_not_set $LINENO IPV6_PROVIDER_FIXED_RANGE "IPV6_PROVIDER_FIXED_RANGE has not been set, but Q_USE_PROVIDERNET_FOR_PUBLIC is true and IP_VERSION includes 6"
177 die_if_not_set $LINENO IPV6_PROVIDER_NETWORK_GATEWAY "IPV6_PROVIDER_NETWORK_GATEWAY has not been set, but Q_USE_PROVIDERNET_FOR_PUBLIC is true and IP_VERSION includes 6"
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000178 if [ -z $SUBNETPOOL_V6_ID ]; then
179 fixed_range_v6=$IPV6_PROVIDER_FIXED_RANGE
180 fi
181 SUBNET_V6_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create --tenant_id $project_id --ip_version 6 --ipv6-address-mode $IPV6_ADDRESS_MODE --gateway $IPV6_PROVIDER_NETWORK_GATEWAY --name $IPV6_PROVIDER_SUBNET_NAME ${SUBNETPOOL_V6_ID:+--subnetpool $SUBNETPOOL_V6_ID} $NET_ID $fixed_range_v6 | grep 'id' | get_field 2)
Sean M. Collins2a242512016-05-03 09:03:09 -0400182 die_if_not_set $LINENO SUBNET_V6_ID "Failure creating SUBNET_V6_ID for $IPV6_PROVIDER_SUBNET_NAME $project_id"
183 fi
184
185 if [[ $Q_AGENT == "openvswitch" ]]; then
186 sudo ip link set $OVS_PHYSICAL_BRIDGE up
187 sudo ip link set br-int up
188 sudo ip link set $PUBLIC_INTERFACE up
189 fi
190 else
191 NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create --tenant-id $project_id "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
192 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PRIVATE_NETWORK_NAME $project_id"
193
194 if [[ "$IP_VERSION" =~ 4.* ]]; then
195 # Create IPv4 private subnet
196 SUBNET_ID=$(_neutron_create_private_subnet_v4 $project_id)
197 fi
198
199 if [[ "$IP_VERSION" =~ .*6 ]]; then
200 # Create IPv6 private subnet
201 IPV6_SUBNET_ID=$(_neutron_create_private_subnet_v6 $project_id)
202 fi
203 fi
204
Sean M. Collinsc35110e2016-05-18 10:38:51 -0400205 if is_networking_extension_supported "router" && is_networking_extension_supported "external-net"; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400206 # Create a router, and add the private subnet as one of its interfaces
207 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
208 # create a tenant-owned router.
209 ROUTER_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-create --tenant-id $project_id $Q_ROUTER_NAME | grep ' id ' | get_field 2)
210 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $project_id $Q_ROUTER_NAME"
211 else
212 # Plugin only supports creating a single router, which should be admin owned.
213 ROUTER_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
214 die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
215 fi
216
Sean M. Collins2a242512016-05-03 09:03:09 -0400217 EXTERNAL_NETWORK_FLAGS="--router:external"
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000218 if is_networking_extension_supported "auto-allocated-topology"; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400219 EXTERNAL_NETWORK_FLAGS="$EXTERNAL_NETWORK_FLAGS --is-default"
Sean M. Collins2a242512016-05-03 09:03:09 -0400220 fi
221 # Create an external network, and a subnet. Configure the external network as router gw
222 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
223 EXT_NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create "$PUBLIC_NETWORK_NAME" -- $EXTERNAL_NETWORK_FLAGS --provider:network_type=flat --provider:physical_network=${PUBLIC_PHYSICAL_NETWORK} | grep ' id ' | get_field 2)
224 else
225 EXT_NET_ID=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" net-create "$PUBLIC_NETWORK_NAME" -- $EXTERNAL_NETWORK_FLAGS | grep ' id ' | get_field 2)
226 fi
227 die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
228
229 if [[ "$IP_VERSION" =~ 4.* ]]; then
230 # Configure router for IPv4 public access
231 _neutron_configure_router_v4
232 fi
233
234 if [[ "$IP_VERSION" =~ .*6 ]]; then
235 # Configure router for IPv6 public access
236 _neutron_configure_router_v6
237 fi
238 fi
239}
240
241# Create private IPv4 subnet
242function _neutron_create_private_subnet_v4 {
243 local project_id=$1
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000244 if [ -z $SUBNETPOOL_V4_ID ]; then
245 fixed_range_v4=$FIXED_RANGE
246 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400247 local subnet_params="--tenant-id $project_id "
248 subnet_params+="--ip_version 4 "
249 subnet_params+="--gateway $NETWORK_GATEWAY "
250 subnet_params+="--name $PRIVATE_SUBNET_NAME "
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000251 subnet_params+="${SUBNETPOOL_V4_ID:+--subnetpool $SUBNETPOOL_V4_ID} "
252 subnet_params+="$NET_ID $fixed_range_v4"
Sean M. Collins2a242512016-05-03 09:03:09 -0400253 local subnet_id
254 subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2)
255 die_if_not_set $LINENO subnet_id "Failure creating private IPv4 subnet for $project_id"
256 echo $subnet_id
257}
258
259# Create private IPv6 subnet
260function _neutron_create_private_subnet_v6 {
261 local project_id=$1
262 die_if_not_set $LINENO IPV6_RA_MODE "IPV6 RA Mode not set"
263 die_if_not_set $LINENO IPV6_ADDRESS_MODE "IPV6 Address Mode not set"
264 local ipv6_modes="--ipv6-ra-mode $IPV6_RA_MODE --ipv6-address-mode $IPV6_ADDRESS_MODE"
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000265 if [ -z $SUBNETPOOL_V6_ID ]; then
266 fixed_range_v6=$FIXED_RANGE_V6
267 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400268 local subnet_params="--tenant-id $project_id "
269 subnet_params+="--ip_version 6 "
270 subnet_params+="--gateway $IPV6_PRIVATE_NETWORK_GATEWAY "
271 subnet_params+="--name $IPV6_PRIVATE_SUBNET_NAME "
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000272 subnet_params+="${SUBNETPOOL_V6_ID:+--subnetpool $SUBNETPOOL_V6_ID} "
273 subnet_params+="$NET_ID $fixed_range_v6 $ipv6_modes"
Sean M. Collins2a242512016-05-03 09:03:09 -0400274 local ipv6_subnet_id
275 ipv6_subnet_id=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep ' id ' | get_field 2)
276 die_if_not_set $LINENO ipv6_subnet_id "Failure creating private IPv6 subnet for $project_id"
277 echo $ipv6_subnet_id
278}
279
280# Create public IPv4 subnet
281function _neutron_create_public_subnet_v4 {
282 local subnet_params+="--ip_version 4 "
283 subnet_params+="${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} "
284 subnet_params+="--gateway $PUBLIC_NETWORK_GATEWAY "
285 subnet_params+="--name $PUBLIC_SUBNET_NAME "
286 subnet_params+="$EXT_NET_ID $FLOATING_RANGE "
287 subnet_params+="-- --enable_dhcp=False"
288 local id_and_ext_gw_ip
289 id_and_ext_gw_ip=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
290 die_if_not_set $LINENO id_and_ext_gw_ip "Failure creating public IPv4 subnet"
291 echo $id_and_ext_gw_ip
292}
293
294# Create public IPv6 subnet
295function _neutron_create_public_subnet_v6 {
296 local subnet_params="--ip_version 6 "
297 subnet_params+="--gateway $IPV6_PUBLIC_NETWORK_GATEWAY "
298 subnet_params+="--name $IPV6_PUBLIC_SUBNET_NAME "
299 subnet_params+="$EXT_NET_ID $IPV6_PUBLIC_RANGE "
300 subnet_params+="-- --enable_dhcp=False"
301 local ipv6_id_and_ext_gw_ip
302 ipv6_id_and_ext_gw_ip=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
303 die_if_not_set $LINENO ipv6_id_and_ext_gw_ip "Failure creating an IPv6 public subnet"
304 echo $ipv6_id_and_ext_gw_ip
305}
306
307# Configure neutron router for IPv4 public access
308function _neutron_configure_router_v4 {
309 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-interface-add $ROUTER_ID $SUBNET_ID
310 # Create a public subnet on the external network
311 local id_and_ext_gw_ip
312 id_and_ext_gw_ip=$(_neutron_create_public_subnet_v4 $EXT_NET_ID)
313 local ext_gw_ip
314 ext_gw_ip=$(echo $id_and_ext_gw_ip | get_field 2)
315 PUB_SUBNET_ID=$(echo $id_and_ext_gw_ip | get_field 5)
316 # Configure the external network as the default router gateway
317 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-gateway-set $ROUTER_ID $EXT_NET_ID
318
319 # This logic is specific to using the l3-agent for layer 3
Sean M. Collinsd00cbb72016-06-20 13:53:44 -0400320 if is_service_enabled q-l3 || is_service_enabled neutron-l3; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400321 # Configure and enable public bridge
322 local ext_gw_interface="none"
323 if is_neutron_ovs_base_plugin; then
324 ext_gw_interface=$(_neutron_get_ext_gw_interface)
325 elif [[ "$Q_AGENT" = "linuxbridge" ]]; then
326 # Search for the brq device the neutron router and network for $FIXED_RANGE
327 # will be using.
328 # e.x. brq3592e767-da for NET_ID 3592e767-da66-4bcb-9bec-cdb03cd96102
329 ext_gw_interface=brq${EXT_NET_ID:0:11}
330 fi
331 if [[ "$ext_gw_interface" != "none" ]]; then
332 local cidr_len=${FLOATING_RANGE#*/}
333 local testcmd="ip -o link | grep -q $ext_gw_interface"
334 test_with_retry "$testcmd" "$ext_gw_interface creation failed"
Kevin Benton7da968a2016-07-22 06:02:22 +0000335 if [[ $(ip addr show dev $ext_gw_interface | grep -c $ext_gw_ip) == 0 && ( $Q_USE_PROVIDERNET_FOR_PUBLIC == "False" || $Q_USE_PUBLIC_VETH == "True" ) ]]; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400336 sudo ip addr add $ext_gw_ip/$cidr_len dev $ext_gw_interface
337 sudo ip link set $ext_gw_interface up
338 fi
339 ROUTER_GW_IP=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F'ip_address' '{ print $2 }' | cut -f3 -d\" | tr '\n' ' ')
340 die_if_not_set $LINENO ROUTER_GW_IP "Failure retrieving ROUTER_GW_IP"
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000341 local replace_range=${SUBNETPOOL_PREFIX_V4}
342 if [[ -z "${SUBNETPOOL_V4_ID}" ]]; then
343 replace_range=${FIXED_RANGE}
344 fi
345 sudo ip route replace $replace_range via $ROUTER_GW_IP
Sean M. Collins2a242512016-05-03 09:03:09 -0400346 fi
347 _neutron_set_router_id
348 fi
349}
350
351# Configure neutron router for IPv6 public access
352function _neutron_configure_router_v6 {
353 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-interface-add $ROUTER_ID $IPV6_SUBNET_ID
354 # Create a public subnet on the external network
355 local ipv6_id_and_ext_gw_ip
356 ipv6_id_and_ext_gw_ip=$(_neutron_create_public_subnet_v6 $EXT_NET_ID)
357 local ipv6_ext_gw_ip
358 ipv6_ext_gw_ip=$(echo $ipv6_id_and_ext_gw_ip | get_field 2)
359 local ipv6_pub_subnet_id
360 ipv6_pub_subnet_id=$(echo $ipv6_id_and_ext_gw_ip | get_field 5)
361
362 # If the external network has not already been set as the default router
363 # gateway when configuring an IPv4 public subnet, do so now
364 if [[ "$IP_VERSION" == "6" ]]; then
365 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" router-gateway-set $ROUTER_ID $EXT_NET_ID
366 fi
367
368 # This logic is specific to using the l3-agent for layer 3
Sean M. Collinsd00cbb72016-06-20 13:53:44 -0400369 if is_service_enabled q-l3 || is_service_enabled neutron-l3; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400370 # Ensure IPv6 forwarding is enabled on the host
371 sudo sysctl -w net.ipv6.conf.all.forwarding=1
372 # Configure and enable public bridge
373 # Override global IPV6_ROUTER_GW_IP with the true value from neutron
374 IPV6_ROUTER_GW_IP=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" port-list -c fixed_ips | grep $ipv6_pub_subnet_id | awk -F'ip_address' '{ print $2 }' | cut -f3 -d\" | tr '\n' ' ')
375 die_if_not_set $LINENO IPV6_ROUTER_GW_IP "Failure retrieving IPV6_ROUTER_GW_IP"
376
377 if is_neutron_ovs_base_plugin; then
378 local ext_gw_interface
379 ext_gw_interface=$(_neutron_get_ext_gw_interface)
380 local ipv6_cidr_len=${IPV6_PUBLIC_RANGE#*/}
381
382 # Configure interface for public bridge
Yi Zhaoa464ea72016-05-12 10:32:58 +0800383 sudo ip -6 addr replace $ipv6_ext_gw_ip/$ipv6_cidr_len dev $ext_gw_interface
Matt Van Dijkd7a3f5c2016-08-16 15:46:58 +0000384 local replace_range=${SUBNETPOOL_PREFIX_V6}
385 if [[ -z "${SUBNETPOOL_V6_ID}" ]]; then
386 replace_range=${FIXED_RANGE_V6}
387 fi
388 sudo ip -6 route replace $replace_range via $IPV6_ROUTER_GW_IP dev $ext_gw_interface
Sean M. Collins2a242512016-05-03 09:03:09 -0400389 fi
390 _neutron_set_router_id
391 fi
392}
watanabe.isao4f4d95a2016-05-12 20:35:20 +0900393
394function is_provider_network {
vsaienkod8942212016-05-13 12:51:30 +0300395 if [ "$Q_USE_PROVIDER_NETWORKING" == "True" ]; then
watanabe.isao4f4d95a2016-05-12 20:35:20 +0900396 return 0
397 fi
398 return 1
399}
Sean M. Collinsc35110e2016-05-18 10:38:51 -0400400
401function is_networking_extension_supported {
402 local extension=$1
403 # TODO(sc68cal) cache this instead of calling every time
404 EXT_LIST=$(neutron --os-cloud devstack-admin --os-region "$REGION_NAME" ext-list -c alias -f value)
405 [[ $EXT_LIST =~ $extension ]] && return 0
406}