diff --git a/files/apts/trema b/files/apts/trema new file mode 100644 index 0000000000..e33ccd3004 --- /dev/null +++ b/files/apts/trema @@ -0,0 +1,15 @@ +# Trema +gcc +make +ruby1.8 +rubygems1.8 +ruby1.8-dev +libpcap-dev +libsqlite3-dev + +# Sliceable Switch +sqlite3 +libdbi-perl +libdbd-sqlite3-perl +apache2 +libjson-perl diff --git a/lib/quantum_plugins/nec b/lib/quantum_plugins/nec new file mode 100644 index 0000000000..f61f50bba5 --- /dev/null +++ b/lib/quantum_plugins/nec @@ -0,0 +1,122 @@ +# Quantum NEC OpenFlow plugin +# --------------------------- + +# Save trace setting +MY_XTRACE=$(set +o | grep xtrace) +set +o xtrace + +# Configuration parameters +OFC_HOST=${OFC_HOST:-127.0.0.1} +OFC_PORT=${OFC_PORT:-8888} + +OFC_API_HOST=${OFC_API_HOST:-$OFC_HOST} +OFC_API_PORT=${OFC_API_PORT:-$OFC_PORT} +OFC_OFP_HOST=${OFC_OFP_HOST:-$OFC_HOST} +OFC_OFP_PORT=${OFC_OFP_PORT:-6633} +OFC_DRIVER=${OFC_DRIVER:-trema} +OFC_RETRY_MAX=${OFC_RETRY_MAX:-0} +OFC_RETRY_INTERVAL=${OFC_RETRY_INTERVAL:-1} + +OVS_BRIDGE=${OVS_BRIDGE:-br-int} + +# Main logic +# --------------------------- + +source $TOP_DIR/lib/quantum_plugins/ovs_base + +function quantum_plugin_create_nova_conf() { + _quantum_ovs_base_configure_nova_vif_driver +} + +function quantum_plugin_install_agent_packages() { + # SKIP_OVS_INSTALL is useful when we want to use Open vSwitch whose + # version is different from the version provided by the distribution. + if [[ "$SKIP_OVS_INSTALL" = "True" ]]; then + echo "You need to install Open vSwitch manually." + return + fi + _quantum_ovs_base_install_agent_packages +} + +function quantum_plugin_configure_common() { + Q_PLUGIN_CONF_PATH=etc/quantum/plugins/nec + Q_PLUGIN_CONF_FILENAME=nec.ini + Q_DB_NAME="quantum_nec" + Q_PLUGIN_CLASS="quantum.plugins.nec.nec_plugin.NECPluginV2" +} + +function quantum_plugin_configure_debug_command() { + _quantum_ovs_base_configure_debug_command +} + +function quantum_plugin_configure_dhcp_agent() { + : +} + +function quantum_plugin_configure_l3_agent() { + _quantum_ovs_base_configure_l3_agent +} + +function quantum_plugin_configure_plugin_agent() { + if [[ "$SKIP_OVS_BRIDGE_SETUP" = "True" ]]; then + return + fi + # Set up integration bridge + _quantum_ovs_base_setup_bridge $OVS_BRIDGE + sudo ovs-vsctl --no-wait set-controller $OVS_BRIDGE tcp:$OFC_OFP_HOST:$OFC_OFP_PORT + # Generate datapath ID from HOST_IP + local dpid=$(printf "0x%07d%03d%03d%03d\n" ${HOST_IP//./ }) + sudo ovs-vsctl --no-wait set Bridge $OVS_BRIDGE other-config:datapath-id=$dpid + sudo ovs-vsctl --no-wait set-fail-mode $OVS_BRIDGE secure + if [ -n "$OVS_INTERFACE" ]; then + sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_BRIDGE $OVS_INTERFACE + fi + _quantum_setup_ovs_tunnels $OVS_BRIDGE + AGENT_BINARY="$QUANTUM_DIR/bin/quantum-nec-agent" + + _quantum_ovs_base_configure_firewall_driver +} + +function quantum_plugin_configure_service() { + iniset $QUANTUM_CONF DEFAULT api_extensions_path quantum/plugins/nec/extensions/ + iniset /$Q_PLUGIN_CONF_FILE OFC host $OFC_API_HOST + iniset /$Q_PLUGIN_CONF_FILE OFC port $OFC_API_PORT + iniset /$Q_PLUGIN_CONF_FILE OFC driver $OFC_DRIVER + iniset /$Q_PLUGIN_CONF_FILE OFC api_retry_max OFC_RETRY_MAX + iniset /$Q_PLUGIN_CONF_FILE OFC api_retry_interval OFC_RETRY_INTERVAL +} + +function quantum_plugin_setup_interface_driver() { + local conf_file=$1 + iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver + iniset $conf_file DEFAULT ovs_use_veth True +} + +# Utility functions +# --------------------------- + +# Setup OVS tunnel manually +function _quantum_setup_ovs_tunnels() { + local bridge=$1 + local id=0 + GRE_LOCAL_IP=${GRE_LOCAL_IP:-$HOST_IP} + if [ -n "$GRE_REMOTE_IPS" ]; then + for ip in ${GRE_REMOTE_IPS//:/ } + do + if [[ "$ip" == "$GRE_LOCAL_IP" ]]; then + continue + fi + sudo ovs-vsctl --no-wait add-port $bridge gre$id -- \ + set Interface gre$id type=gre options:remote_ip=$ip + id=`expr $id + 1` + done + fi +} + +function has_quantum_plugin_security_group() { + # 0 means True here + return 0 +} + +# Restore xtrace +$MY_XTRACE diff --git a/lib/quantum_thirdparty/trema b/lib/quantum_thirdparty/trema new file mode 100644 index 0000000000..09dc46bd83 --- /dev/null +++ b/lib/quantum_thirdparty/trema @@ -0,0 +1,113 @@ +# Trema Sliceable Switch +# ---------------------- + +# Trema is a Full-Stack OpenFlow Framework in Ruby and C +# https://github.com/trema/trema +# +# Trema Sliceable Switch is an OpenFlow controller which provides +# virtual layer-2 network slices. +# https://github.com/trema/apps/wiki + +# Trema Sliceable Switch (OpenFlow Controller) +TREMA_APPS_REPO=${TREMA_APPS_REPO:-https://github.com/trema/apps.git} +TREMA_APPS_BRANCH=${TREMA_APPS_BRANCH:-master} + +# Save trace setting +MY_XTRACE=$(set +o | grep xtrace) +set +o xtrace + +TREMA_DIR=${TREMA_DIR:-$DEST/trema} +TREMA_SS_DIR="$TREMA_DIR/apps/sliceable_switch" + +TREMA_DATA_DIR=${TREMA_DATA_DIR:-$DATA_DIR/trema} +TREMA_SS_ETC_DIR=$TREMA_DATA_DIR/sliceable_switch/etc +TREMA_SS_DB_DIR=$TREMA_DATA_DIR/sliceable_switch/db +TREMA_SS_SCRIPT_DIR=$TREMA_DATA_DIR/sliceable_switch/script +TREMA_TMP_DIR=$TREMA_DATA_DIR/trema + +TREMA_LOG_LEVEL=${TREMA_LOG_LEVEL:-info} + +TREMA_SS_CONFIG=$TREMA_SS_ETC_DIR/sliceable.conf +TREMA_SS_APACHE_CONFIG=/etc/apache2/sites-available/sliceable_switch + +# configure_trema - Set config files, create data dirs, etc +function configure_trema() { + # prepare dir + for d in $TREMA_SS_ETC_DIR $TREMA_SS_DB_DIR $TREMA_SS_SCRIPT_DIR; do + sudo mkdir -p $d + sudo chown -R `whoami` $d + done + sudo mkdir -p $TREMA_TMP_DIR +} + +# init_trema - Initialize databases, etc. +function init_trema() { + local _pwd=$(pwd) + + # Initialize databases for Sliceable Switch + cd $TREMA_SS_DIR + rm -f filter.db slice.db + ./create_tables.sh + mv filter.db slice.db $TREMA_SS_DB_DIR + # Make sure that apache cgi has write access to the databases + sudo chown -R www-data.www-data $TREMA_SS_DB_DIR + cd $_pwd + + # Setup HTTP Server for sliceable_switch + cp $TREMA_SS_DIR/{Slice.pm,Filter.pm,config.cgi} $TREMA_SS_SCRIPT_DIR + sed -i -e "s|/home/sliceable_switch/db|$TREMA_SS_DB_DIR|" \ + $TREMA_SS_SCRIPT_DIR/config.cgi + + sudo cp $TREMA_SS_DIR/apache/sliceable_switch $TREMA_SS_APACHE_CONFIG + sudo sed -i -e "s|/home/sliceable_switch/script|$TREMA_SS_SCRIPT_DIR|" \ + $TREMA_SS_APACHE_CONFIG + sudo a2enmod rewrite actions + sudo a2ensite sliceable_switch + + cp $TREMA_SS_DIR/sliceable_switch_null.conf $TREMA_SS_CONFIG + sed -i -e "s|^\$apps_dir.*$|\$apps_dir = \"$TREMA_DIR/apps\"|" \ + -e "s|^\$db_dir.*$|\$db_dir = \"$TREMA_SS_DB_DIR\"|" \ + $TREMA_SS_CONFIG +} + +function gem_install() { + [[ "$OFFLINE" = "True" ]] && return + [ -n "$RUBYGEMS_CMD" ] || get_gem_command + + local pkg=$1 + $RUBYGEMS_CMD list | grep "^${pkg} " && return + sudo $RUBYGEMS_CMD install $pkg +} + +function get_gem_command() { + # Trema requires ruby 1.8, so gem1.8 is checked first + RUBYGEMS_CMD=$(which gem1.8 || which gem) + if [ -z "$RUBYGEMS_CMD" ]; then + echo "Warning: ruby gems command not found." + fi +} + +function install_trema() { + # Trema + gem_install trema + # Sliceable Switch + git_clone $TREMA_APPS_REPO $TREMA_DIR/apps $TREMA_APPS_BRANCH + make -C $TREMA_DIR/apps/topology + make -C $TREMA_DIR/apps/flow_manager + make -C $TREMA_DIR/apps/sliceable_switch +} + +function start_trema() { + # APACHE_NAME is defined in init_horizon (in lib/horizon) + restart_service $APACHE_NAME + + sudo LOGGING_LEVEL=$TREMA_LOG_LEVEL TREMA_TMP=$TREMA_TMP_DIR \ + trema run -d -c $TREMA_SS_CONFIG +} + +function stop_trema() { + sudo TREMA_TMP=$TREMA_TMP_DIR trema killall +} + +# Restore xtrace +$MY_XTRACE