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 | |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 75 | |
| 76 | # Entry Points |
| 77 | # ------------ |
| 78 | |
| 79 | # Test if OpenDaylight is enabled |
| 80 | # is_opendaylight_enabled |
| 81 | function 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 |
| 88 | function cleanup_opendaylight { |
| 89 | : |
| 90 | } |
| 91 | |
| 92 | # configure_opendaylight() - Set config files, create data dirs, etc |
| 93 | function configure_opendaylight { |
Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 94 | # Add odl-ovsdb-openstack if it's not already there |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 95 | 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] | 96 | if [ "$ODLOVSDB" == "" ]; then |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 97 | 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] | 98 | fi |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 99 | |
Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 100 | # Configure OpenFlow 1.3 if it's not there |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 101 | 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] | 102 | if [ "$OFLOW13" == "" ]; then |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 103 | 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] | 104 | 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 Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 109 | 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] | 110 | if [ "$L3FWD" == "" ]; then |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 111 | 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] | 112 | fi |
| 113 | fi |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Simon Pasquier | cfc9ebb | 2014-04-08 09:34:44 +0200 | [diff] [blame] | 116 | function 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 Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 122 | # init_opendaylight() - Initialize databases, etc. |
| 123 | function 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 |
| 130 | function 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 Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 146 | # install_opendaylight-compute - Make sure OVS is installed |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 147 | function install_opendaylight-compute { |
Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 148 | # packages are the same as for Neutron OVS agent |
| 149 | _neutron_ovs_base_install_agent_packages |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | # start_opendaylight() - Start running processes, including screen |
| 153 | function 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 Troyer | 3324f19 | 2014-09-18 09:26:39 -0500 | [diff] [blame] | 163 | |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 164 | 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] | 165 | |
| 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) |
| 171 | function stop_opendaylight { |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 172 | stop_process odl-server |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | # stop_opendaylight-compute() - Remove OVS bridges |
| 176 | function 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: |