| Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | # | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 3 | # lib/opendaylight | 
|  | 4 | # Functions to control the configuration and operation of the opendaylight service | 
|  | 5 |  | 
|  | 6 | # Dependencies: | 
|  | 7 | # | 
| Dean Troyer | 3324f19 | 2014-09-18 09:26:39 -0500 | [diff] [blame] | 8 | # ``functions`` file | 
|  | 9 | # ``DEST`` must be defined | 
|  | 10 | # ``STACK_USER`` must be defined | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 11 |  | 
|  | 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 | 
|  | 26 | XTRACE=$(set +o | grep xtrace) | 
|  | 27 | set +o xtrace | 
|  | 28 |  | 
|  | 29 |  | 
|  | 30 | # For OVS_BRIDGE and PUBLIC_BRIDGE | 
|  | 31 | source $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= | 
|  | 38 | ODL_MGR_IP=${ODL_MGR_IP:-$SERVICE_HOST} | 
|  | 39 |  | 
| Simon Pasquier | cfc9ebb | 2014-04-08 09:34:44 +0200 | [diff] [blame] | 40 | # The ODL endpoint URL | 
|  | 41 | ODL_ENDPOINT=${ODL_ENDPOINT:-http://${ODL_MGR_IP}:8080/controller/nb/v2/neutron} | 
|  | 42 |  | 
|  | 43 | # The ODL username | 
|  | 44 | ODL_USERNAME=${ODL_USERNAME:-admin} | 
|  | 45 |  | 
|  | 46 | # The ODL password | 
|  | 47 | ODL_PASSWORD=${ODL_PASSWORD:-admin} | 
|  | 48 |  | 
| Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 49 | # Short name of ODL package | 
| Kyle Mestery | 5c66ff6 | 2014-12-16 16:50:46 +0000 | [diff] [blame] | 50 | ODL_NAME=${ODL_NAME:-distribution-karaf-0.2.1-Helium-SR1.1} | 
| Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 51 |  | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 52 | # <define global variables here that belong to this project> | 
|  | 53 | ODL_DIR=$DEST/opendaylight | 
|  | 54 |  | 
|  | 55 | # The OpenDaylight Package, currently using 'Hydrogen' release | 
| Kyle Mestery | 5c66ff6 | 2014-12-16 16:50:46 +0000 | [diff] [blame] | 56 | ODL_PKG=${ODL_PKG:-distribution-karaf-0.2.1-Helium-SR1.1.zip} | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 57 |  | 
|  | 58 | # The OpenDaylight URL | 
| Kyle Mestery | 5c66ff6 | 2014-12-16 16:50:46 +0000 | [diff] [blame] | 59 | ODL_URL=${ODL_URL:-https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/integration/distribution-karaf/0.2.1-Helium-SR1.1/} | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 60 |  | 
|  | 61 | # Default arguments for OpenDaylight. This is typically used to set | 
|  | 62 | # Java memory options. | 
| Dean Troyer | 3324f19 | 2014-09-18 09:26:39 -0500 | [diff] [blame] | 63 | # ``ODL_ARGS=Xmx1024m -XX:MaxPermSize=512m`` | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 64 | ODL_ARGS=${ODL_ARGS:-"-XX:MaxPermSize=384m"} | 
|  | 65 |  | 
|  | 66 | # How long to pause after ODL starts to let it complete booting | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 67 | ODL_BOOT_WAIT=${ODL_BOOT_WAIT:-20} | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 68 |  | 
| Sam Hague | 09b56b1 | 2014-05-05 10:30:09 -0400 | [diff] [blame] | 69 | # The physical provider network to device mapping | 
|  | 70 | ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS:-physnet1:eth1} | 
|  | 71 |  | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 72 | # Enable OpenDaylight l3 forwarding | 
|  | 73 | ODL_L3=${ODL_L3:-False} | 
|  | 74 |  | 
| Flavio Fernandes | 0413d2d | 2015-01-09 16:09:12 -0500 | [diff] [blame] | 75 | # Enable debug logs for odl ovsdb | 
|  | 76 | ODL_NETVIRT_DEBUG_LOGS=${ODL_NETVIRT_DEBUG_LOGS:-False} | 
|  | 77 |  | 
|  | 78 | # The logging config file in ODL | 
|  | 79 | ODL_LOGGING_CONFIG=${ODL_LOGGING_CONFIG:-${ODL_DIR}/${ODL_NAME}/etc/org.ops4j.pax.logging.cfg} | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 80 |  | 
|  | 81 | # Entry Points | 
|  | 82 | # ------------ | 
|  | 83 |  | 
|  | 84 | # Test if OpenDaylight is enabled | 
|  | 85 | # is_opendaylight_enabled | 
|  | 86 | function 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 | 
|  | 93 | function cleanup_opendaylight { | 
|  | 94 | : | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | # configure_opendaylight() - Set config files, create data dirs, etc | 
|  | 98 | function configure_opendaylight { | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 99 | # Add odl-ovsdb-openstack if it's not already there | 
| Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 100 | local ODLOVSDB=$(cat $ODL_DIR/$ODL_NAME/etc/org.apache.karaf.features.cfg | grep featuresBoot= | grep odl) | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 101 | if [ "$ODLOVSDB" == "" ]; then | 
| Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 102 | sed -i '/^featuresBoot=/ s/$/,odl-ovsdb-openstack/' $ODL_DIR/$ODL_NAME/etc/org.apache.karaf.features.cfg | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 103 | fi | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 104 |  | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 105 | # Configure OpenFlow 1.3 if it's not there | 
| Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 106 | local OFLOW13=$(cat $ODL_DIR/$ODL_NAME/etc/custom.properties | grep ^of.version) | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 107 | if [ "$OFLOW13" == "" ]; then | 
| Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 108 | echo "ovsdb.of.version=1.3" >> $ODL_DIR/$ODL_NAME/etc/custom.properties | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 109 | 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 Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 114 | local L3FWD=$(cat $ODL_DIR/$ODL_NAME/etc/custom.properties | grep ^ovsdb.l3.fwd.enabled) | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 115 | if [ "$L3FWD" == "" ]; then | 
| Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 116 | echo "ovsdb.l3.fwd.enabled=yes" >> $ODL_DIR/$ODL_NAME/etc/custom.properties | 
| Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 117 | fi | 
|  | 118 | fi | 
| Flavio Fernandes | 0413d2d | 2015-01-09 16:09:12 -0500 | [diff] [blame] | 119 |  | 
|  | 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 Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 135 | } | 
|  | 136 |  | 
| Simon Pasquier | cfc9ebb | 2014-04-08 09:34:44 +0200 | [diff] [blame] | 137 | function 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 Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 143 | # init_opendaylight() - Initialize databases, etc. | 
|  | 144 | function 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 | 
|  | 151 | function 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 Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 167 | # install_opendaylight-compute - Make sure OVS is installed | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 168 | function install_opendaylight-compute { | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 169 | # packages are the same as for Neutron OVS agent | 
|  | 170 | _neutron_ovs_base_install_agent_packages | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 171 | } | 
|  | 172 |  | 
|  | 173 | # start_opendaylight() - Start running processes, including screen | 
|  | 174 | function 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 Troyer | 3324f19 | 2014-09-18 09:26:39 -0500 | [diff] [blame] | 184 |  | 
| Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 185 | run_process odl-server "cd $ODL_DIR/$ODL_NAME && JAVA_HOME=$JHOME bin/karaf" | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 186 |  | 
|  | 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) | 
|  | 192 | function stop_opendaylight { | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 193 | stop_process odl-server | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 194 | } | 
|  | 195 |  | 
|  | 196 | # stop_opendaylight-compute() - Remove OVS bridges | 
|  | 197 | function 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: |