Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 1 | # Trema Sliceable Switch |
| 2 | # ---------------------- |
| 3 | |
| 4 | # Trema is a Full-Stack OpenFlow Framework in Ruby and C |
| 5 | # https://github.com/trema/trema |
| 6 | # |
| 7 | # Trema Sliceable Switch is an OpenFlow controller which provides |
| 8 | # virtual layer-2 network slices. |
| 9 | # https://github.com/trema/apps/wiki |
| 10 | |
| 11 | # Trema Sliceable Switch (OpenFlow Controller) |
| 12 | TREMA_APPS_REPO=${TREMA_APPS_REPO:-https://github.com/trema/apps.git} |
| 13 | TREMA_APPS_BRANCH=${TREMA_APPS_BRANCH:-master} |
| 14 | |
| 15 | # Save trace setting |
| 16 | MY_XTRACE=$(set +o | grep xtrace) |
| 17 | set +o xtrace |
| 18 | |
| 19 | TREMA_DIR=${TREMA_DIR:-$DEST/trema} |
| 20 | TREMA_SS_DIR="$TREMA_DIR/apps/sliceable_switch" |
| 21 | |
| 22 | TREMA_DATA_DIR=${TREMA_DATA_DIR:-$DATA_DIR/trema} |
| 23 | TREMA_SS_ETC_DIR=$TREMA_DATA_DIR/sliceable_switch/etc |
| 24 | TREMA_SS_DB_DIR=$TREMA_DATA_DIR/sliceable_switch/db |
| 25 | TREMA_SS_SCRIPT_DIR=$TREMA_DATA_DIR/sliceable_switch/script |
| 26 | TREMA_TMP_DIR=$TREMA_DATA_DIR/trema |
| 27 | |
| 28 | TREMA_LOG_LEVEL=${TREMA_LOG_LEVEL:-info} |
| 29 | |
| 30 | TREMA_SS_CONFIG=$TREMA_SS_ETC_DIR/sliceable.conf |
Akihiro MOTOKI | 7a4ae3d | 2013-10-10 00:40:38 +0900 | [diff] [blame] | 31 | TREMA_SS_APACHE_CONFIG=/etc/apache2/sites-available/sliceable_switch.conf |
Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 32 | |
| 33 | # configure_trema - Set config files, create data dirs, etc |
| 34 | function configure_trema() { |
| 35 | # prepare dir |
| 36 | for d in $TREMA_SS_ETC_DIR $TREMA_SS_DB_DIR $TREMA_SS_SCRIPT_DIR; do |
| 37 | sudo mkdir -p $d |
| 38 | sudo chown -R `whoami` $d |
| 39 | done |
| 40 | sudo mkdir -p $TREMA_TMP_DIR |
| 41 | } |
| 42 | |
| 43 | # init_trema - Initialize databases, etc. |
| 44 | function init_trema() { |
| 45 | local _pwd=$(pwd) |
| 46 | |
| 47 | # Initialize databases for Sliceable Switch |
| 48 | cd $TREMA_SS_DIR |
| 49 | rm -f filter.db slice.db |
| 50 | ./create_tables.sh |
| 51 | mv filter.db slice.db $TREMA_SS_DB_DIR |
| 52 | # Make sure that apache cgi has write access to the databases |
| 53 | sudo chown -R www-data.www-data $TREMA_SS_DB_DIR |
| 54 | cd $_pwd |
| 55 | |
| 56 | # Setup HTTP Server for sliceable_switch |
| 57 | cp $TREMA_SS_DIR/{Slice.pm,Filter.pm,config.cgi} $TREMA_SS_SCRIPT_DIR |
| 58 | sed -i -e "s|/home/sliceable_switch/db|$TREMA_SS_DB_DIR|" \ |
| 59 | $TREMA_SS_SCRIPT_DIR/config.cgi |
| 60 | |
| 61 | sudo cp $TREMA_SS_DIR/apache/sliceable_switch $TREMA_SS_APACHE_CONFIG |
| 62 | sudo sed -i -e "s|/home/sliceable_switch/script|$TREMA_SS_SCRIPT_DIR|" \ |
| 63 | $TREMA_SS_APACHE_CONFIG |
| 64 | sudo a2enmod rewrite actions |
Yuiko Takada | 74ba66d | 2013-12-20 08:25:10 +0000 | [diff] [blame] | 65 | sudo a2ensite sliceable_switch.conf |
Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 66 | |
| 67 | cp $TREMA_SS_DIR/sliceable_switch_null.conf $TREMA_SS_CONFIG |
| 68 | sed -i -e "s|^\$apps_dir.*$|\$apps_dir = \"$TREMA_DIR/apps\"|" \ |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 69 | -e "s|^\$db_dir.*$|\$db_dir = \"$TREMA_SS_DB_DIR\"|" \ |
| 70 | $TREMA_SS_CONFIG |
Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | function gem_install() { |
| 74 | [[ "$OFFLINE" = "True" ]] && return |
| 75 | [ -n "$RUBYGEMS_CMD" ] || get_gem_command |
| 76 | |
| 77 | local pkg=$1 |
| 78 | $RUBYGEMS_CMD list | grep "^${pkg} " && return |
| 79 | sudo $RUBYGEMS_CMD install $pkg |
| 80 | } |
| 81 | |
| 82 | function get_gem_command() { |
| 83 | # Trema requires ruby 1.8, so gem1.8 is checked first |
| 84 | RUBYGEMS_CMD=$(which gem1.8 || which gem) |
| 85 | if [ -z "$RUBYGEMS_CMD" ]; then |
| 86 | echo "Warning: ruby gems command not found." |
| 87 | fi |
| 88 | } |
| 89 | |
| 90 | function install_trema() { |
| 91 | # Trema |
| 92 | gem_install trema |
| 93 | # Sliceable Switch |
| 94 | git_clone $TREMA_APPS_REPO $TREMA_DIR/apps $TREMA_APPS_BRANCH |
| 95 | make -C $TREMA_DIR/apps/topology |
| 96 | make -C $TREMA_DIR/apps/flow_manager |
| 97 | make -C $TREMA_DIR/apps/sliceable_switch |
| 98 | } |
| 99 | |
| 100 | function start_trema() { |
| 101 | # APACHE_NAME is defined in init_horizon (in lib/horizon) |
| 102 | restart_service $APACHE_NAME |
| 103 | |
| 104 | sudo LOGGING_LEVEL=$TREMA_LOG_LEVEL TREMA_TMP=$TREMA_TMP_DIR \ |
| 105 | trema run -d -c $TREMA_SS_CONFIG |
| 106 | } |
| 107 | |
| 108 | function stop_trema() { |
| 109 | sudo TREMA_TMP=$TREMA_TMP_DIR trema killall |
| 110 | } |
| 111 | |
armando-migliaccio | ef1e080 | 2014-01-02 16:33:53 -0800 | [diff] [blame] | 112 | function check_trema() { |
| 113 | : |
| 114 | } |
| 115 | |
Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 116 | # Restore xtrace |
| 117 | $MY_XTRACE |