blob: 2b125646dc24507765068c2c89bcabc577da0846 [file] [log] [blame]
Akihiro MOTOKIf85fa082013-01-13 05:01:08 +09001# 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)
12TREMA_APPS_REPO=${TREMA_APPS_REPO:-https://github.com/trema/apps.git}
13TREMA_APPS_BRANCH=${TREMA_APPS_BRANCH:-master}
14
15# Save trace setting
16MY_XTRACE=$(set +o | grep xtrace)
17set +o xtrace
18
19TREMA_DIR=${TREMA_DIR:-$DEST/trema}
20TREMA_SS_DIR="$TREMA_DIR/apps/sliceable_switch"
21
22TREMA_DATA_DIR=${TREMA_DATA_DIR:-$DATA_DIR/trema}
23TREMA_SS_ETC_DIR=$TREMA_DATA_DIR/sliceable_switch/etc
24TREMA_SS_DB_DIR=$TREMA_DATA_DIR/sliceable_switch/db
25TREMA_SS_SCRIPT_DIR=$TREMA_DATA_DIR/sliceable_switch/script
26TREMA_TMP_DIR=$TREMA_DATA_DIR/trema
27
28TREMA_LOG_LEVEL=${TREMA_LOG_LEVEL:-info}
29
30TREMA_SS_CONFIG=$TREMA_SS_ETC_DIR/sliceable.conf
Akihiro MOTOKI7a4ae3d2013-10-10 00:40:38 +090031TREMA_SS_APACHE_CONFIG=/etc/apache2/sites-available/sliceable_switch.conf
Akihiro MOTOKIf85fa082013-01-13 05:01:08 +090032
33# configure_trema - Set config files, create data dirs, etc
34function 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.
44function 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 Takada74ba66d2013-12-20 08:25:10 +000065 sudo a2ensite sliceable_switch.conf
Akihiro MOTOKIf85fa082013-01-13 05:01:08 +090066
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 Dague101b4242013-10-22 08:47:11 -040069 -e "s|^\$db_dir.*$|\$db_dir = \"$TREMA_SS_DB_DIR\"|" \
70 $TREMA_SS_CONFIG
Akihiro MOTOKIf85fa082013-01-13 05:01:08 +090071}
72
73function 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
82function 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
90function 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
100function 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
108function stop_trema() {
109 sudo TREMA_TMP=$TREMA_TMP_DIR trema killall
110}
111
armando-migliaccioef1e0802014-01-02 16:33:53 -0800112function check_trema() {
113 :
114}
115
Akihiro MOTOKIf85fa082013-01-13 05:01:08 +0900116# Restore xtrace
117$MY_XTRACE