blob: 651867352476b5f3fb20067c14f780a1ac30a110 [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
Flavio Fernandes0413d2d2015-01-09 16:09:12 -050075# Enable debug logs for odl ovsdb
76ODL_NETVIRT_DEBUG_LOGS=${ODL_NETVIRT_DEBUG_LOGS:-False}
77
78# The logging config file in ODL
79ODL_LOGGING_CONFIG=${ODL_LOGGING_CONFIG:-${ODL_DIR}/${ODL_NAME}/etc/org.ops4j.pax.logging.cfg}
Kyle Mesteryd44517d2014-01-28 20:29:18 +000080
81# Entry Points
82# ------------
83
84# Test if OpenDaylight is enabled
85# is_opendaylight_enabled
86function is_opendaylight_enabled {
87 [[ ,${ENABLED_SERVICES} =~ ,"odl-" ]] && return 0
88 return 1
89}
90
91# cleanup_opendaylight() - Remove residual data files, anything left over from previous
92# runs that a clean run would need to clean up
93function cleanup_opendaylight {
94 :
95}
96
97# configure_opendaylight() - Set config files, create data dirs, etc
98function configure_opendaylight {
Kyle Mestery3d6d8992014-10-15 16:30:15 +000099 # Add odl-ovsdb-openstack if it's not already there
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000100 local ODLOVSDB=$(cat $ODL_DIR/$ODL_NAME/etc/org.apache.karaf.features.cfg | grep featuresBoot= | grep odl)
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000101 if [ "$ODLOVSDB" == "" ]; then
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000102 sed -i '/^featuresBoot=/ s/$/,odl-ovsdb-openstack/' $ODL_DIR/$ODL_NAME/etc/org.apache.karaf.features.cfg
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000103 fi
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000104
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000105 # Configure OpenFlow 1.3 if it's not there
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000106 local OFLOW13=$(cat $ODL_DIR/$ODL_NAME/etc/custom.properties | grep ^of.version)
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000107 if [ "$OFLOW13" == "" ]; then
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000108 echo "ovsdb.of.version=1.3" >> $ODL_DIR/$ODL_NAME/etc/custom.properties
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000109 fi
110
111 # Configure L3 if the user wants it
112 if [ "${ODL_L3}" == "True" ]; then
113 # Configure L3 FWD if it's not there
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000114 local L3FWD=$(cat $ODL_DIR/$ODL_NAME/etc/custom.properties | grep ^ovsdb.l3.fwd.enabled)
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000115 if [ "$L3FWD" == "" ]; then
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000116 echo "ovsdb.l3.fwd.enabled=yes" >> $ODL_DIR/$ODL_NAME/etc/custom.properties
Kyle Mestery3d6d8992014-10-15 16:30:15 +0000117 fi
118 fi
Flavio Fernandes0413d2d2015-01-09 16:09:12 -0500119
120 # Configure DEBUG logs for network virtualization in odl, if the user wants it
121 if [ "${ODL_NETVIRT_DEBUG_LOGS}" == "True" ]; then
122 local OVSDB_DEBUG_LOGS=$(cat $ODL_LOGGING_CONFIG | grep ^log4j.logger.org.opendaylight.ovsdb)
123 if [ "${OVSDB_DEBUG_LOGS}" == "" ]; then
124 echo 'log4j.logger.org.opendaylight.ovsdb = TRACE' >> $ODL_LOGGING_CONFIG
125 echo 'log4j.logger.org.opendaylight.ovsdb.lib = INFO' >> $ODL_LOGGING_CONFIG
126 echo 'log4j.logger.org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter = DEBUG' >> $ODL_LOGGING_CONFIG
127 echo 'log4j.logger.org.opendaylight.ovsdb.openstack.netvirt.impl.TenantNetworkManagerImpl = DEBUG' >> $ODL_LOGGING_CONFIG
128 echo 'log4j.logger.org.opendaylight.ovsdb.plugin.md.OvsdbInventoryManager = INFO' >> $ODL_LOGGING_CONFIG
129 fi
130 local ODL_NEUTRON_DEBUG_LOGS=$(cat $ODL_LOGGING_CONFIG | grep ^log4j.logger.org.opendaylight.controller.networkconfig.neutron)
131 if [ "${ODL_NEUTRON_DEBUG_LOGS}" == "" ]; then
132 echo 'log4j.logger.org.opendaylight.controller.networkconfig.neutron = TRACE' >> $ODL_LOGGING_CONFIG
133 fi
134 fi
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000135}
136
Simon Pasquiercfc9ebb2014-04-08 09:34:44 +0200137function configure_ml2_odl {
138 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl url=$ODL_ENDPOINT
139 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl username=$ODL_USERNAME
140 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl password=$ODL_PASSWORD
141}
142
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000143# init_opendaylight() - Initialize databases, etc.
144function init_opendaylight {
145 # clean up from previous (possibly aborted) runs
146 # create required data files
147 :
148}
149
150# install_opendaylight() - Collect source and prepare
151function install_opendaylight {
152 local _pwd=$(pwd)
153
154 if is_ubuntu; then
155 install_package maven openjdk-7-jre openjdk-7-jdk
156 else
157 yum_install maven java-1.7.0-openjdk
158 fi
159
160 # Download OpenDaylight
161 mkdir -p $ODL_DIR
162 cd $ODL_DIR
163 wget -N $ODL_URL/$ODL_PKG
164 unzip -u $ODL_PKG
165}
166
Kyle Mestery86af4a02014-06-24 11:07:54 +0000167# install_opendaylight-compute - Make sure OVS is installed
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000168function install_opendaylight-compute {
Kyle Mestery86af4a02014-06-24 11:07:54 +0000169 # packages are the same as for Neutron OVS agent
170 _neutron_ovs_base_install_agent_packages
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000171}
172
173# start_opendaylight() - Start running processes, including screen
174function start_opendaylight {
175 if is_ubuntu; then
176 JHOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
177 else
178 JHOME=/usr/lib/jvm/java-1.7.0-openjdk
179 fi
180
181 # The flags to ODL have the following meaning:
182 # -of13: runs ODL using OpenFlow 1.3 protocol support.
183 # -virt ovsdb: Runs ODL in "virtualization" mode with OVSDB support
Dean Troyer3324f192014-09-18 09:26:39 -0500184
Kyle Mestery6a709ab2014-11-06 08:36:09 +0000185 run_process odl-server "cd $ODL_DIR/$ODL_NAME && JAVA_HOME=$JHOME bin/karaf"
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000186
187 # Sleep a bit to let OpenDaylight finish starting up
188 sleep $ODL_BOOT_WAIT
189}
190
191# stop_opendaylight() - Stop running processes (non-screen)
192function stop_opendaylight {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100193 stop_process odl-server
Kyle Mesteryd44517d2014-01-28 20:29:18 +0000194}
195
196# stop_opendaylight-compute() - Remove OVS bridges
197function stop_opendaylight-compute {
198 # remove all OVS ports that look like Neutron created ports
199 for port in $(sudo ovs-vsctl list port | grep -o -e tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do
200 sudo ovs-vsctl del-port ${port}
201 done
202
203 # remove all OVS bridges created by Neutron
204 for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE}); do
205 sudo ovs-vsctl del-br ${bridge}
206 done
207}
208
209# Restore xtrace
210$XTRACE
211
212# Tell emacs to use shell-script-mode
213## Local variables:
214## mode: shell-script
215## End: