_XTRACE_ODL_RELEASE_COMMON=$(set +o | grep xtrace)
set -o xtrace

_odl_release=$1
if [[ "$_odl_release" =~ -snapshot ]]; then
    # <release name>-snapshot-<N>.<N>.<N> -> <N>.<N>.<N>-SNAPSHOT
    _odl_version=${_odl_release/[[:alpha:]]*-snapshot-/}
    if [[ "$_odl_release" == "latest-snapshot" ]]; then
       # get latest revision of snapshot
       _odl_version=$(odl_snapshot_full_version $ODL_DIR $ODL_URL_PREFIX "latest" $OFFLINE)
       # update ODL_RELEASE to prevent odl_snapshot_full_version from being called
       # every time networking-odl/devstack/plugin.sh is called by devstack
       # latest-snapshot -> latest-snapshot-<N>.<N>.<N>
       ODL_RELEASE=${ODL_RELEASE}-${_odl_version}
    elif [[ "${_odl_version}" =~ ^[[:digit:]]\.[[:digit:]]$ ]]; then
       # get latest revision of given major.minor
       # <major>.<minor> -> <major>.<minor>.<revision>
       _odl_version=$(odl_snapshot_full_version $ODL_DIR $ODL_URL_PREFIX $_odl_version $OFFLINE)
       # update ODL_RELEASE to prevent odl_snapshot_full_version from being called
       # every time networking-odl/devstack/plugin.sh is called by devstack
       # <release name>-snapshot-<N>.<N> -> <release name>-snapshot-<N>.<N>.<N>
       _odl_revision=${_odl_version/[[:digit:]]\.[[:digit:]]\./}
       ODL_RELEASE=${ODL_RELEASE}.${_odl_revision}
    fi
    _odl_bundleversion_default=${_odl_version}-SNAPSHOT
    export ODL_BUNDLEVERSION=${ODL_BUNDLEVERSION:-${_odl_bundleversion_default}}
    export ODL_SNAPSHOT_VERSION=${ODL_SNAPSHOT_VERSION:-latest}
else
    # <release name>-<N>.<N>.<N>[-SR<N>] -> <N>.<N>.<N>-<Release name>[-SR<N>]
    _name=$(echo ${_odl_release} | awk -F- '{print toupper(substr($1, 1, 1))substr($1, 2)}')
    _version=$(echo ${_odl_release} | awk -F- '{print $2}')
    _sr=$(echo ${_odl_release} | awk -F- '{print $3}')
    _odl_bundleversion_default=${_version}-${_name}
    if [[ -n $_sr ]]; then
        _odl_bundleversion_default=${_odl_bundleversion_default}-${_sr}
    fi
    export ODL_BUNDLEVERSION=${ODL_BUNDLEVERSION:-${_odl_bundleversion_default}}
fi


# Java major version required to run OpenDaylight: 7, 8, ...
# by default, ODL uses jdk 8 as of Boron
export ODL_REQUIRED_JAVA_VERSION=${ODL_REQUIRED_JAVA_VERSION:-8}

# karaf distribution name of ODL to download
export ODL_NAME=${ODL_NAME:-distribution-karaf-${ODL_BUNDLEVERSION}}

# The network virtualization older feature name (ovsdb based)
export ODL_NETVIRT_KARAF_FEATURE_OVSDB=${ODL_NETVIRT_KARAF_FEATURE_OVSDB:-odl-ovsdb-openstack}

# The network virtualization newer feature name (vpnservice based)
export ODL_NETVIRT_KARAF_FEATURE_VPNSERVICE=${ODL_NETVIRT_KARAF_FEATURE_VPNSERVICE:-odl-netvirt-openstack}

ODL_NETVIRT_KARAF_FEATURE_DEFAULT=odl-neutron-service,odl-restconf-all,odl-aaa-authn,odl-dlux-core,odl-mdsal-apidocs
# new netvirt has been introduced into netvirt from Boron release
# odl-neutron-logger has been introduced from Boron release
case "$ODL_BUNDLEVERSION" in
    # in Helium case, ODL_NETVIRT_KARAF_FEATURE is defined
    # so ODL_NETVIRT_KARAF_FEATURE_DEFAULT doesn't matter
    # Nothing to do
    0.2.?-*)
        ;;
    0.3.?-*|0.4.?-*)
        ODL_NETVIRT_KARAF_FEATURE_DEFAULT+=,$ODL_NETVIRT_KARAF_FEATURE_OVSDB
        ;;
    *)
        # 0.5.?-*, 0.6.?-* or later
        ODL_NETVIRT_KARAF_FEATURE_DEFAULT+=,$ODL_NETVIRT_KARAF_FEATURE_VPNSERVICE
        ODL_NETVIRT_KARAF_FEATURE_DEFAULT+=,odl-neutron-logger
        ;;
esac

# The network virtualization feature used by opendaylight loaded by Karaf
export ODL_NETVIRT_KARAF_FEATURE=${ODL_NETVIRT_KARAF_FEATURE:-$ODL_NETVIRT_KARAF_FEATURE_DEFAULT}

# The url that this version of ODL netvirt can use to know ODL is fully up
export ODL_BOOT_WAIT_URL=${ODL_BOOT_WAIT_URL:-restconf/operational/network-topology:network-topology/topology/netvirt:1}

$_XTRACE_ODL_RELEASE_COMMON
