blob: 2f0f37e34de8b2c2e0b1bdce50a0cb0c773a0b05 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Kyle Mesteryd44517d2014-01-28 20:29:18 +00003# lib/opendaylight
4# Functions to control the configuration and operation of the opendaylight service
5
6# Dependencies:
7#
Dean Troyer3324f192014-09-18 09:26:39 -05008# ``functions`` file
9# ``DEST`` must be defined
10# ``STACK_USER`` must be defined
Kyle Mesteryd44517d2014-01-28 20:29:18 +000011
12# ``stack.sh`` calls the entry points in this order:
13#
14# - is_opendaylight_enabled
15# - is_opendaylight-compute_enabled
16# - install_opendaylight
17# - install_opendaylight-compute
18# - configure_opendaylight
19# - init_opendaylight
20# - start_opendaylight
21# - stop_opendaylight-compute
22# - stop_opendaylight
23# - cleanup_opendaylight
24
25# Save trace setting
26XTRACE=$(set +o | grep xtrace)
27set +o xtrace
28
29
30# For OVS_BRIDGE and PUBLIC_BRIDGE
31source $TOP_DIR/lib/neutron_plugins/ovs_base
32
33# Defaults
34# --------
35
36# The IP address of ODL. Set this in local.conf.
37# ODL_MGR_IP=
38ODL_MGR_IP=${ODL_MGR_IP:-$SERVICE_HOST}
39
Simon Pasquiercfc9ebb2014-04-08 09:34:44 +020040# The ODL endpoint URL
41ODL_ENDPOINT=${ODL_ENDPOINT:-http://${ODL_MGR_IP}:8080/controller/nb/v2/neutron}
42
43# The ODL username
44ODL_USERNAME=${ODL_USERNAME:-admin}
45
46# The ODL password
47ODL_PASSWORD=${ODL_PASSWORD:-admin}
48
Kyle Mestery6a709ab2014-11-06 08:36:09 +000049# Short name of ODL package
Kyle Mestery5c66ff62014-12-16 16:50:46 +000050ODL_NAME=${ODL_NAME:-distribution-karaf-0.2.1-Helium-SR1.1}
Kyle Mestery6a709ab2014-11-06 08:36:09 +000051
Kyle Mesteryd44517d2014-01-28 20:29:18 +000052# <define global variables here that belong to this project>
53ODL_DIR=$DEST/opendaylight
54
55# The OpenDaylight Package, currently using 'Hydrogen' release
Kyle Mestery5c66ff62014-12-16 16:50:46 +000056ODL_PKG=${ODL_PKG:-distribution-karaf-0.2.1-Helium-SR1.1.zip}
Kyle Mesteryd44517d2014-01-28 20:29:18 +000057
58# The OpenDaylight URL
Kyle Mestery5c66ff62014-12-16 16:50:46 +000059ODL_URL=${ODL_URL:-https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/integration/distribution-karaf/0.2.1-Helium-SR1.1/}
Kyle Mesteryd44517d2014-01-28 20:29:18 +000060
61# Default arguments for OpenDaylight. This is typically used to set
62# Java memory options.
Dean Troyer3324f192014-09-18 09:26:39 -050063# ``ODL_ARGS=Xmx1024m -XX:MaxPermSize=512m``
Kyle Mesteryd44517d2014-01-28 20:29:18 +000064ODL_ARGS=${ODL_ARGS:-"-XX:MaxPermSize=384m"}
65
66# How long to pause after ODL starts to let it complete booting
Kyle Mestery3d6d8992014-10-15 16:30:15 +000067ODL_BOOT_WAIT=${ODL_BOOT_WAIT:-20}
Kyle Mesteryd44517d2014-01-28 20:29:18 +000068
Sam Hague09b56b12014-05-05 10:30:09 -040069# The physical provider network to device mapping
70ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS:-physnet1:eth1}
71
Kyle Mestery3d6d8992014-10-15 16:30:15 +000072# Enable OpenDaylight l3 forwarding
73ODL_L3=${ODL_L3:-False}
74
Kyle Mesteryd44517d2014-01-28 20:29:18 +000075
76# Entry Points
77# ------------
78
79# Test if OpenDaylight is enabled
80# is_opendaylight_enabled
81function is_opendaylight_enabled {
82 [[ ,${ENABLED_SERVICES} =~ ,"odl-" ]] && return 0
83 return 1
84}
85
86# cleanup_opendaylight() - Remove residual data files, anything left over from previous
87# runs that a clean run would need to clean up
88function cleanup_opendaylight {
89 :
90}
91
92# configure_opendaylight() - Set config files, create data dirs, etc
93function configure_opendaylight {
Kyle Mestery3d6d8992014-10-15 16:30:15 +000094 # Add odl-ovsdb-openstack if it's not already there
Kyle Mestery6a709ab2014-11-06 08:36:09 +000095 local ODLOVSDB=$(cat $ODL_DIR/$ODL_NAME/etc/org.apache.karaf.features.cfg | grep featuresBoot= | grep odl)
Kyle Mestery3d6d8992014-10-15 16:30:15 +000096 if [ "$ODLOVSDB" == "" ]; then
Kyle Mestery6a709ab2014-11-06 08:36:09 +000097 sed -i '/^featuresBoot=/ s/$/,odl-ovsdb-openstack/' $ODL_DIR/$ODL_NAME/etc/org.apache.karaf.features.cfg
Kyle Mestery3d6d8992014-10-15 16:30:15 +000098 fi
Kyle Mesteryd44517d2014-01-28 20:29:18 +000099
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000100 # Configure OpenFlow 1.3 if it's not there
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000101 local OFLOW13=$(cat $ODL_DIR/$ODL_NAME/etc/custom.properties | grep ^of.version)
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000102 if [ "$OFLOW13" == "" ]; then
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000103 echo "ovsdb.of.version=1.3" >> $ODL_DIR/$ODL_NAME/etc/custom.properties
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000104 fi
105
106 # Configure L3 if the user wants it
107 if [ "${ODL_L3}" == "True" ]; then
108 # Configure L3 FWD if it's not there
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000109 local L3FWD=$(cat $ODL_DIR/$ODL_NAME/etc/custom.properties | grep ^ovsdb.l3.fwd.enabled)
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000110 if [ "$L3FWD" == "" ]; then
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000111 echo "ovsdb.l3.fwd.enabled=yes" >> $ODL_DIR/$ODL_NAME/etc/custom.properties
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000112 fi
113 fi
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000114}
115
Simon Pasquiercfc9ebb2014-04-08 09:34:44 +0200116function configure_ml2_odl {
117 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl url=$ODL_ENDPOINT
118 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl username=$ODL_USERNAME
119 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl password=$ODL_PASSWORD
120}
121
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000122# init_opendaylight() - Initialize databases, etc.
123function init_opendaylight {
124 # clean up from previous (possibly aborted) runs
125 # create required data files
126 :
127}
128
129# install_opendaylight() - Collect source and prepare
130function install_opendaylight {
131 local _pwd=$(pwd)
132
133 if is_ubuntu; then
134 install_package maven openjdk-7-jre openjdk-7-jdk
135 else
136 yum_install maven java-1.7.0-openjdk
137 fi
138
139 # Download OpenDaylight
140 mkdir -p $ODL_DIR
141 cd $ODL_DIR
142 wget -N $ODL_URL/$ODL_PKG
143 unzip -u $ODL_PKG
144}
145
Kyle Mestery86af4a02014-06-24 11:07:54 +0000146# install_opendaylight-compute - Make sure OVS is installed
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000147function install_opendaylight-compute {
Kyle Mestery86af4a02014-06-24 11:07:54 +0000148 # packages are the same as for Neutron OVS agent
149 _neutron_ovs_base_install_agent_packages
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000150}
151
152# start_opendaylight() - Start running processes, including screen
153function start_opendaylight {
154 if is_ubuntu; then
155 JHOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
156 else
157 JHOME=/usr/lib/jvm/java-1.7.0-openjdk
158 fi
159
160 # The flags to ODL have the following meaning:
161 # -of13: runs ODL using OpenFlow 1.3 protocol support.
162 # -virt ovsdb: Runs ODL in "virtualization" mode with OVSDB support
Dean Troyer3324f192014-09-18 09:26:39 -0500163
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000164 run_process odl-server "cd $ODL_DIR/$ODL_NAME && JAVA_HOME=$JHOME bin/karaf"
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000165
166 # Sleep a bit to let OpenDaylight finish starting up
167 sleep $ODL_BOOT_WAIT
168}
169
170# stop_opendaylight() - Stop running processes (non-screen)
171function stop_opendaylight {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100172 stop_process odl-server
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000173}
174
175# stop_opendaylight-compute() - Remove OVS bridges
176function stop_opendaylight-compute {
177 # remove all OVS ports that look like Neutron created ports
178 for port in $(sudo ovs-vsctl list port | grep -o -e tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do
179 sudo ovs-vsctl del-port ${port}
180 done
181
182 # remove all OVS bridges created by Neutron
183 for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE}); do
184 sudo ovs-vsctl del-br ${bridge}
185 done
186}
187
188# Restore xtrace
189$XTRACE
190
191# Tell emacs to use shell-script-mode
192## Local variables:
193## mode: shell-script
194## End: