Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 1 | # lib/opendaylight |
| 2 | # Functions to control the configuration and operation of the opendaylight service |
| 3 | |
| 4 | # Dependencies: |
| 5 | # |
Dean Troyer | 3324f19 | 2014-09-18 09:26:39 -0500 | [diff] [blame] | 6 | # ``functions`` file |
| 7 | # ``DEST`` must be defined |
| 8 | # ``STACK_USER`` must be defined |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 9 | |
| 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 |
| 24 | XTRACE=$(set +o | grep xtrace) |
| 25 | set +o xtrace |
| 26 | |
| 27 | |
| 28 | # For OVS_BRIDGE and PUBLIC_BRIDGE |
| 29 | source $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= |
| 36 | ODL_MGR_IP=${ODL_MGR_IP:-$SERVICE_HOST} |
| 37 | |
Simon Pasquier | cfc9ebb | 2014-04-08 09:34:44 +0200 | [diff] [blame] | 38 | # The ODL endpoint URL |
| 39 | ODL_ENDPOINT=${ODL_ENDPOINT:-http://${ODL_MGR_IP}:8080/controller/nb/v2/neutron} |
| 40 | |
| 41 | # The ODL username |
| 42 | ODL_USERNAME=${ODL_USERNAME:-admin} |
| 43 | |
| 44 | # The ODL password |
| 45 | ODL_PASSWORD=${ODL_PASSWORD:-admin} |
| 46 | |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 47 | # Short name of ODL package |
| 48 | ODL_NAME=${ODL_NAME:-distribution-karaf-0.2.0-Helium} |
| 49 | |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 50 | # <define global variables here that belong to this project> |
| 51 | ODL_DIR=$DEST/opendaylight |
| 52 | |
| 53 | # The OpenDaylight Package, currently using 'Hydrogen' release |
Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 54 | ODL_PKG=${ODL_PKG:-distribution-karaf-0.2.0-Helium.zip} |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 55 | |
| 56 | # The OpenDaylight URL |
Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 57 | ODL_URL=${ODL_URL:-https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.2.0-Helium} |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 58 | |
| 59 | # Default arguments for OpenDaylight. This is typically used to set |
| 60 | # Java memory options. |
Dean Troyer | 3324f19 | 2014-09-18 09:26:39 -0500 | [diff] [blame] | 61 | # ``ODL_ARGS=Xmx1024m -XX:MaxPermSize=512m`` |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 62 | ODL_ARGS=${ODL_ARGS:-"-XX:MaxPermSize=384m"} |
| 63 | |
| 64 | # How long to pause after ODL starts to let it complete booting |
Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 65 | ODL_BOOT_WAIT=${ODL_BOOT_WAIT:-20} |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 66 | |
Sam Hague | 09b56b1 | 2014-05-05 10:30:09 -0400 | [diff] [blame] | 67 | # The physical provider network to device mapping |
| 68 | ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS:-physnet1:eth1} |
| 69 | |
Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 70 | # Enable OpenDaylight l3 forwarding |
| 71 | ODL_L3=${ODL_L3:-False} |
| 72 | |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 73 | |
| 74 | # Entry Points |
| 75 | # ------------ |
| 76 | |
| 77 | # Test if OpenDaylight is enabled |
| 78 | # is_opendaylight_enabled |
| 79 | function is_opendaylight_enabled { |
| 80 | [[ ,${ENABLED_SERVICES} =~ ,"odl-" ]] && return 0 |
| 81 | return 1 |
| 82 | } |
| 83 | |
| 84 | # cleanup_opendaylight() - Remove residual data files, anything left over from previous |
| 85 | # runs that a clean run would need to clean up |
| 86 | function cleanup_opendaylight { |
| 87 | : |
| 88 | } |
| 89 | |
| 90 | # configure_opendaylight() - Set config files, create data dirs, etc |
| 91 | function configure_opendaylight { |
Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 92 | # Add odl-ovsdb-openstack if it's not already there |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 93 | 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] | 94 | if [ "$ODLOVSDB" == "" ]; then |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 95 | 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] | 96 | fi |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 97 | |
Kyle Mestery | 3d6d899 | 2014-10-15 16:30:15 +0000 | [diff] [blame] | 98 | # Configure OpenFlow 1.3 if it's not there |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 99 | 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] | 100 | if [ "$OFLOW13" == "" ]; then |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 101 | 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] | 102 | fi |
| 103 | |
| 104 | # Configure L3 if the user wants it |
| 105 | if [ "${ODL_L3}" == "True" ]; then |
| 106 | # Configure L3 FWD if it's not there |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 107 | 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] | 108 | if [ "$L3FWD" == "" ]; then |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 109 | 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] | 110 | fi |
| 111 | fi |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Simon Pasquier | cfc9ebb | 2014-04-08 09:34:44 +0200 | [diff] [blame] | 114 | function configure_ml2_odl { |
| 115 | populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl url=$ODL_ENDPOINT |
| 116 | populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl username=$ODL_USERNAME |
| 117 | populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl password=$ODL_PASSWORD |
| 118 | } |
| 119 | |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 120 | # init_opendaylight() - Initialize databases, etc. |
| 121 | function init_opendaylight { |
| 122 | # clean up from previous (possibly aborted) runs |
| 123 | # create required data files |
| 124 | : |
| 125 | } |
| 126 | |
| 127 | # install_opendaylight() - Collect source and prepare |
| 128 | function install_opendaylight { |
| 129 | local _pwd=$(pwd) |
| 130 | |
| 131 | if is_ubuntu; then |
| 132 | install_package maven openjdk-7-jre openjdk-7-jdk |
| 133 | else |
| 134 | yum_install maven java-1.7.0-openjdk |
| 135 | fi |
| 136 | |
| 137 | # Download OpenDaylight |
| 138 | mkdir -p $ODL_DIR |
| 139 | cd $ODL_DIR |
| 140 | wget -N $ODL_URL/$ODL_PKG |
| 141 | unzip -u $ODL_PKG |
| 142 | } |
| 143 | |
Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 144 | # install_opendaylight-compute - Make sure OVS is installed |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 145 | function install_opendaylight-compute { |
Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 146 | # packages are the same as for Neutron OVS agent |
| 147 | _neutron_ovs_base_install_agent_packages |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | # start_opendaylight() - Start running processes, including screen |
| 151 | function start_opendaylight { |
| 152 | if is_ubuntu; then |
| 153 | JHOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64 |
| 154 | else |
| 155 | JHOME=/usr/lib/jvm/java-1.7.0-openjdk |
| 156 | fi |
| 157 | |
| 158 | # The flags to ODL have the following meaning: |
| 159 | # -of13: runs ODL using OpenFlow 1.3 protocol support. |
| 160 | # -virt ovsdb: Runs ODL in "virtualization" mode with OVSDB support |
Dean Troyer | 3324f19 | 2014-09-18 09:26:39 -0500 | [diff] [blame] | 161 | |
Kyle Mestery | 6a709ab | 2014-11-06 08:36:09 +0000 | [diff] [blame] | 162 | 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] | 163 | |
| 164 | # Sleep a bit to let OpenDaylight finish starting up |
| 165 | sleep $ODL_BOOT_WAIT |
| 166 | } |
| 167 | |
| 168 | # stop_opendaylight() - Stop running processes (non-screen) |
| 169 | function stop_opendaylight { |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 170 | stop_process odl-server |
Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | # stop_opendaylight-compute() - Remove OVS bridges |
| 174 | function stop_opendaylight-compute { |
| 175 | # remove all OVS ports that look like Neutron created ports |
| 176 | for port in $(sudo ovs-vsctl list port | grep -o -e tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do |
| 177 | sudo ovs-vsctl del-port ${port} |
| 178 | done |
| 179 | |
| 180 | # remove all OVS bridges created by Neutron |
| 181 | for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE}); do |
| 182 | sudo ovs-vsctl del-br ${bridge} |
| 183 | done |
| 184 | } |
| 185 | |
| 186 | # Restore xtrace |
| 187 | $XTRACE |
| 188 | |
| 189 | # Tell emacs to use shell-script-mode |
| 190 | ## Local variables: |
| 191 | ## mode: shell-script |
| 192 | ## End: |