| 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 | # | 
|  | 6 | # - ``functions`` file | 
|  | 7 | # # ``DEST`` must be defined | 
|  | 8 | # # ``STACK_USER`` must be defined | 
|  | 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 | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 47 | # <define global variables here that belong to this project> | 
|  | 48 | ODL_DIR=$DEST/opendaylight | 
|  | 49 |  | 
|  | 50 | # The OpenDaylight Package, currently using 'Hydrogen' release | 
|  | 51 | ODL_PKG=${ODL_PKG:-distributions-virtualization-0.1.1-osgipackage.zip} | 
|  | 52 |  | 
|  | 53 | # The OpenDaylight URL | 
|  | 54 | ODL_URL=${ODL_URL:-https://nexus.opendaylight.org/content/repositories/opendaylight.release/org/opendaylight/integration/distributions-virtualization/0.1.1} | 
|  | 55 |  | 
|  | 56 | # Default arguments for OpenDaylight. This is typically used to set | 
|  | 57 | # Java memory options. | 
|  | 58 | #   ODL_ARGS=Xmx1024m -XX:MaxPermSize=512m | 
|  | 59 | ODL_ARGS=${ODL_ARGS:-"-XX:MaxPermSize=384m"} | 
|  | 60 |  | 
|  | 61 | # How long to pause after ODL starts to let it complete booting | 
|  | 62 | ODL_BOOT_WAIT=${ODL_BOOT_WAIT:-60} | 
|  | 63 |  | 
| Sam Hague | 09b56b1 | 2014-05-05 10:30:09 -0400 | [diff] [blame] | 64 | # The physical provider network to device mapping | 
|  | 65 | ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS:-physnet1:eth1} | 
|  | 66 |  | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 67 | # Set up default directories | 
|  | 68 |  | 
|  | 69 |  | 
|  | 70 | # Entry Points | 
|  | 71 | # ------------ | 
|  | 72 |  | 
|  | 73 | # Test if OpenDaylight is enabled | 
|  | 74 | # is_opendaylight_enabled | 
|  | 75 | function is_opendaylight_enabled { | 
|  | 76 | [[ ,${ENABLED_SERVICES} =~ ,"odl-" ]] && return 0 | 
|  | 77 | return 1 | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | # cleanup_opendaylight() - Remove residual data files, anything left over from previous | 
|  | 81 | # runs that a clean run would need to clean up | 
|  | 82 | function cleanup_opendaylight { | 
|  | 83 | : | 
|  | 84 | } | 
|  | 85 |  | 
|  | 86 | # configure_opendaylight() - Set config files, create data dirs, etc | 
|  | 87 | function configure_opendaylight { | 
|  | 88 | # Remove simple forwarder | 
|  | 89 | rm -f $ODL_DIR/opendaylight/plugins/org.opendaylight.controller.samples.simpleforwarding* | 
|  | 90 |  | 
|  | 91 | # Configure OpenFlow 1.3 | 
|  | 92 | echo "ovsdb.of.version=1.3" >> $ODL_DIR/opendaylight/configuration/config.ini | 
|  | 93 | } | 
|  | 94 |  | 
| Simon Pasquier | cfc9ebb | 2014-04-08 09:34:44 +0200 | [diff] [blame] | 95 | function configure_ml2_odl { | 
|  | 96 | populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl url=$ODL_ENDPOINT | 
|  | 97 | populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl username=$ODL_USERNAME | 
|  | 98 | populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_odl password=$ODL_PASSWORD | 
|  | 99 | } | 
|  | 100 |  | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 101 | # init_opendaylight() - Initialize databases, etc. | 
|  | 102 | function init_opendaylight { | 
|  | 103 | # clean up from previous (possibly aborted) runs | 
|  | 104 | # create required data files | 
|  | 105 | : | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | # install_opendaylight() - Collect source and prepare | 
|  | 109 | function install_opendaylight { | 
|  | 110 | local _pwd=$(pwd) | 
|  | 111 |  | 
|  | 112 | if is_ubuntu; then | 
|  | 113 | install_package maven openjdk-7-jre openjdk-7-jdk | 
|  | 114 | else | 
|  | 115 | yum_install maven java-1.7.0-openjdk | 
|  | 116 | fi | 
|  | 117 |  | 
|  | 118 | # Download OpenDaylight | 
|  | 119 | mkdir -p $ODL_DIR | 
|  | 120 | cd $ODL_DIR | 
|  | 121 | wget -N $ODL_URL/$ODL_PKG | 
|  | 122 | unzip -u $ODL_PKG | 
|  | 123 | } | 
|  | 124 |  | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 125 | # install_opendaylight-compute - Make sure OVS is installed | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 126 | function install_opendaylight-compute { | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 127 | # packages are the same as for Neutron OVS agent | 
|  | 128 | _neutron_ovs_base_install_agent_packages | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 129 | } | 
|  | 130 |  | 
|  | 131 | # start_opendaylight() - Start running processes, including screen | 
|  | 132 | function start_opendaylight { | 
|  | 133 | if is_ubuntu; then | 
|  | 134 | JHOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64 | 
|  | 135 | else | 
|  | 136 | JHOME=/usr/lib/jvm/java-1.7.0-openjdk | 
|  | 137 | fi | 
|  | 138 |  | 
|  | 139 | # The flags to ODL have the following meaning: | 
|  | 140 | #   -of13: runs ODL using OpenFlow 1.3 protocol support. | 
|  | 141 | #   -virt ovsdb: Runs ODL in "virtualization" mode with OVSDB support | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 142 | # NOTE(chdent): Leaving this as screen_it instead of run_process until | 
|  | 143 | # the right thing for this service is determined. | 
| fujioka yuuichi | 41ca6dc | 2014-03-20 03:03:26 +0000 | [diff] [blame] | 144 | screen_it odl-server "cd $ODL_DIR/opendaylight && JAVA_HOME=$JHOME ./run.sh $ODL_ARGS -of13 -virt ovsdb" | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 145 |  | 
|  | 146 | # Sleep a bit to let OpenDaylight finish starting up | 
|  | 147 | sleep $ODL_BOOT_WAIT | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | # stop_opendaylight() - Stop running processes (non-screen) | 
|  | 151 | function stop_opendaylight { | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 152 | stop_process odl-server | 
| Kyle Mestery | d44517d | 2014-01-28 20:29:18 +0000 | [diff] [blame] | 153 | } | 
|  | 154 |  | 
|  | 155 | # stop_opendaylight-compute() - Remove OVS bridges | 
|  | 156 | function stop_opendaylight-compute { | 
|  | 157 | # remove all OVS ports that look like Neutron created ports | 
|  | 158 | for port in $(sudo ovs-vsctl list port | grep -o -e tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do | 
|  | 159 | sudo ovs-vsctl del-port ${port} | 
|  | 160 | done | 
|  | 161 |  | 
|  | 162 | # remove all OVS bridges created by Neutron | 
|  | 163 | for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE}); do | 
|  | 164 | sudo ovs-vsctl del-br ${bridge} | 
|  | 165 | done | 
|  | 166 | } | 
|  | 167 |  | 
|  | 168 | # Restore xtrace | 
|  | 169 | $XTRACE | 
|  | 170 |  | 
|  | 171 | # Tell emacs to use shell-script-mode | 
|  | 172 | ## Local variables: | 
|  | 173 | ## mode: shell-script | 
|  | 174 | ## End: |