blob: 5256166b9010ec1cd550cca065a1b3ad1dc88328 [file] [log] [blame]
Thomas Vachuska0a4c2702015-07-06 08:43:41 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Starts or interacts with mininet in a remote screen session.
4# -----------------------------------------------------------------------------
5
6[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
7. $ONOS_ROOT/tools/build/envDefaults
8
Thomas Vachuskaa02fc812015-07-21 18:37:58 -07009export MAX_WAIT=60
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070010
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070011cmd="$1" && shift
12log="screenlog.0"
13remote="$ONOS_USER@$OCN"
14mininet="ssh -t -t $remote screen -L -S mininet"
15
16case $cmd in
17send)
18 $mininet -X "stuff \"$@\\n\"" 2>/dev/null
19 ;;
20
21sendAndExpect)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070022 cmd=""
23 for a in $*; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
24 $mininet -X "stuff \"$cmd\\n\"" 2>/dev/null
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070025 onos-mininet expect "$@"
26 ;;
27
28wait)
29 ssh $remote "
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070030 let count=0
31 sleep 1 && while test ! -f $log; do if test \$count -ge $MAX_WAIT; then exit 1; fi; sleep 1; let count=count+1; done
32 while ! (tail -n1 $log | egrep -q '^mininet>'); do if [ \$count -ge $MAX_WAIT ]; then exit 1; fi; sleep 1; done
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070033 sleep ${1-:1}
34 "
35 ;;
36
37expect)
38 aux=/tmp/mininet.$$.log
39 ssh $remote "
Thomas Vachuskae76f6532015-07-08 09:40:53 -070040 sleep 1
41 if [ ! -f $log ]; then exit 1; fi;
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070042 let count=0
43 while ! (tail -n1 $log | egrep -q '^mininet>'); do if test \$count -ge $MAX_WAIT; then exit 1; fi; sleep 1; let count=count+1; done
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070044 tac $log | awk '{ print \$0; } /^mininet>/ { if (on) { exit 0; } on=1; }' | tac > $aux
45 cat $aux
46 set -x
47 egrep \"$@\" $aux
48 "
49 ;;
50
Thomas Vachuskaf1c42082015-07-10 16:41:31 -070051attach)
52 $mininet -x
53 ;;
54
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070055start)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070056 ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc"
57 (
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070058 $mininet "$@"
59 scp $remote:$log /tmp/mininet.log
60 ssh $remote rm -f $log
Thomas Vachuskae76f6532015-07-08 09:40:53 -070061 ) &
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070062 ;;
63
64stop)
65 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
66 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
67 $mininet -X "stuff \"exit\\n\"" 2>/dev/null
68 ;;
Thomas Vachuska4d5310c2016-07-14 12:48:39 -070069cleanup)
70 ssh -t -t $remote sudo mn -c
Thomas Vachuskaa8e125a2016-08-19 10:46:31 -070071 ssh -t -t $remote "screen -list | grep mininet | cut -d. -f1 | tr -d '\t' | xargs kill -9; screen -wipe; exit 0"
Thomas Vachuska4d5310c2016-07-14 12:48:39 -070072 ;;
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070073esac