blob: 374de953c61a03821c7ce0a4835e64fe498e0d5b [file] [log] [blame]
Kyle Mesteryd44517d2014-01-28 20:29:18 +00001# lib/opendaylight
2# Functions to control the configuration and operation of the opendaylight service
3
4# Dependencies:
5#
Dean Troyer3324f192014-09-18 09:26:39 -05006# ``functions`` file
7# ``DEST`` must be defined
8# ``STACK_USER`` must be defined
Kyle Mesteryd44517d2014-01-28 20:29:18 +00009
10# ``stack.sh`` calls the entry points in this order:
11#
12# - is_opendaylight_enabled
13# - is_opendaylight-compute_enabled
14# - install_opendaylight
15# - install_opendaylight-compute
16# - configure_opendaylight
17# - init_opendaylight
18# - start_opendaylight
19# - stop_opendaylight-compute
20# - stop_opendaylight
21# - cleanup_opendaylight
22
23# Save trace setting
24XTRACE=$(set +o | grep xtrace)
25set +o xtrace
26
27
28# For OVS_BRIDGE and PUBLIC_BRIDGE
29source $TOP_DIR/lib/neutron_plugins/ovs_base
30
31# Defaults
32# --------
33
34# The IP address of ODL. Set this in local.conf.
35# ODL_MGR_IP=
36ODL_MGR_IP=${ODL_MGR_IP:-$SERVICE_HOST}
37
Simon Pasquiercfc9ebb2014-04-08 09:34:44 +020038# The ODL endpoint URL
39ODL_ENDPOINT=${ODL_ENDPOINT:-http://${ODL_MGR_IP}:8080/controller/nb/v2/neutron}
40
41# The ODL username
42ODL_USERNAME=${ODL_USERNAME:-admin}
43
44# The ODL password
45ODL_PASSWORD=${ODL_PASSWORD:-admin}
46
Kyle Mesteryd44517d2014-01-28 20:29:18 +000047# <define global variables here that belong to this project>
48ODL_DIR=$DEST/opendaylight
49
50# The OpenDaylight Package, currently using 'Hydrogen' release
Kyle Mestery3d6d8992014-10-15 16:30:15 +000051ODL_PKG=${ODL_PKG:-distribution-karaf-0.2.0-Helium.zip}
Kyle Mesteryd44517d2014-01-28 20:29:18 +000052
53# The OpenDaylight URL
Kyle Mestery3d6d8992014-10-15 16:30:15 +000054ODL_URL=${ODL_URL:-https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.2.0-Helium}
Kyle Mesteryd44517d2014-01-28 20:29:18 +000055
56# Default arguments for OpenDaylight. This is typically used to set
57# Java memory options.
Dean Troyer3324f192014-09-18 09:26:39 -050058# ``ODL_ARGS=Xmx1024m -XX:MaxPermSize=512m``
Kyle Mesteryd44517d2014-01-28 20:29:18 +000059ODL_ARGS=${ODL_ARGS:-"-XX:MaxPermSize=384m"}
60
61# How long to pause after ODL starts to let it complete booting
Kyle Mestery3d6d8992014-10-15 16:30:15 +000062ODL_BOOT_WAIT=${ODL_BOOT_WAIT:-20}
Kyle Mesteryd44517d2014-01-28 20:29:18 +000063
Sam Hague09b56b12014-05-05 10:30:09 -040064# The physical provider network to device mapping
65ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS:-physnet1:eth1}
66
Kyle Mestery3d6d8992014-10-15 16:30:15 +000067# Enable OpenDaylight l3 forwarding
68ODL_L3=${ODL_L3:-False}
69
Kyle Mesteryd44517d2014-01-28 20:29:18 +000070
71# Entry Points
72# ------------
73
74# Test if OpenDaylight is enabled
75# is_opendaylight_enabled
76function is_opendaylight_enabled {
77 [[ ,${ENABLED_SERVICES} =~ ,"odl-" ]] && return 0
78 return 1
79}
80
81# cleanup_opendaylight() - Remove residual data files, anything left over from previous
82# runs that a clean run would need to clean up
83function cleanup_opendaylight {
84 :
85}
86
87# configure_opendaylight() - Set config files, create data dirs, etc
88function configure_opendaylight {
Kyle Mestery3d6d8992014-10-15 16:30:15 +000089 # Add odl-ovsdb-openstack if it's not already there
90 local ODLOVSDB=$(cat $ODL_DIR/distribution-karaf-0.2.0-Helium/etc/org.apache.karaf.features.cfg | grep featuresBoot= | grep odl)
91 if [ "$ODLOVSDB" == "" ]; then
92 sed -i '/^featuresBoot=/ s/$/,odl-ovsdb-openstack/' $ODL_DIR/distribution-karaf-0.2.0-Helium/etc/org.apache.karaf.features.cfg
93 fi
Kyle Mesteryd44517d2014-01-28 20:29:18 +000094
Kyle Mestery3d6d8992014-10-15 16:30:15 +000095 # Configure OpenFlow 1.3 if it's not there
96 local OFLOW13=$(cat $ODL_DIR/distribution-karaf-0.2.0-Helium/etc/custom.properties | grep ^of.version)
97 if [ "$OFLOW13" == "" ]; then
98 echo "ovsdb.of.version=1.3" >> $ODL_DIR/distribution-karaf-0.2.0-Helium/etc/custom.properties
99 fi
100
101 # Configure L3 if the user wants it
102 if [ "${ODL_L3}" == "True" ]; then
103 # Configure L3 FWD if it's not there
104 local L3FWD=$(cat $ODL_DIR/distribution-karaf-0.2.0-Helium/etc/custom.properties | grep ^ovsdb.l3.fwd.enabled)
105 if [ "$L3FWD" == "" ]; then
106 echo "ovsdb.l3.fwd.enabled=yes" >> $ODL_DIR/distribution-karaf-0.2.0-Helium/etc/custom.properties
107 fi
108 fi
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000109}
110
Simon Pasquiercfc9ebb2014-04-08 09:34:44 +0200111function configure_ml2_odl {
112 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl url=$ODL_ENDPOINT
113 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl username=$ODL_USERNAME
114 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl password=$ODL_PASSWORD
115}
116
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000117# init_opendaylight() - Initialize databases, etc.
118function init_opendaylight {
119 # clean up from previous (possibly aborted) runs
120 # create required data files
121 :
122}
123
124# install_opendaylight() - Collect source and prepare
125function install_opendaylight {
126 local _pwd=$(pwd)
127
128 if is_ubuntu; then
129 install_package maven openjdk-7-jre openjdk-7-jdk
130 else
131 yum_install maven java-1.7.0-openjdk
132 fi
133
134 # Download OpenDaylight
135 mkdir -p $ODL_DIR
136 cd $ODL_DIR
137 wget -N $ODL_URL/$ODL_PKG
138 unzip -u $ODL_PKG
139}
140
Kyle Mestery86af4a02014-06-24 11:07:54 +0000141# install_opendaylight-compute - Make sure OVS is installed
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000142function install_opendaylight-compute {
Kyle Mestery86af4a02014-06-24 11:07:54 +0000143 # packages are the same as for Neutron OVS agent
144 _neutron_ovs_base_install_agent_packages
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000145}
146
147# start_opendaylight() - Start running processes, including screen
148function start_opendaylight {
149 if is_ubuntu; then
150 JHOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
151 else
152 JHOME=/usr/lib/jvm/java-1.7.0-openjdk
153 fi
154
155 # The flags to ODL have the following meaning:
156 # -of13: runs ODL using OpenFlow 1.3 protocol support.
157 # -virt ovsdb: Runs ODL in "virtualization" mode with OVSDB support
Dean Troyer3324f192014-09-18 09:26:39 -0500158
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000159 run_process odl-server "cd $ODL_DIR/distribution-karaf-0.2.0-Helium && JAVA_HOME=$JHOME bin/karaf"
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000160
161 # Sleep a bit to let OpenDaylight finish starting up
162 sleep $ODL_BOOT_WAIT
163}
164
165# stop_opendaylight() - Stop running processes (non-screen)
166function stop_opendaylight {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100167 stop_process odl-server
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000168}
169
170# stop_opendaylight-compute() - Remove OVS bridges
171function stop_opendaylight-compute {
172 # remove all OVS ports that look like Neutron created ports
173 for port in $(sudo ovs-vsctl list port | grep -o -e tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do
174 sudo ovs-vsctl del-port ${port}
175 done
176
177 # remove all OVS bridges created by Neutron
178 for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE}); do
179 sudo ovs-vsctl del-br ${bridge}
180 done
181}
182
183# Restore xtrace
184$XTRACE
185
186# Tell emacs to use shell-script-mode
187## Local variables:
188## mode: shell-script
189## End: