blob: 0ff0ff963930a04922053f0b46d1dd644ceaa7d7 [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 Vachuska534f4762016-08-30 16:25:13 -07009export MAX_WAIT=${ONOS_MN_TIMEOUT:-90}
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
Ray Milkey0b53f952018-04-02 08:54:51 -070032 while ! (tail -n1 $log | egrep -q '^[ ]*[0]*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
Ray Milkey0b53f952018-04-02 08:54:51 -070043 while ! (tail -n1 $log | egrep -q '^[ ]*[0]*mininet>'); do if test \$count -ge $MAX_WAIT; then exit 1; fi; sleep 1; let count=count+1; done
44 tac $log | awk '{ print \$0; } /^[ ]*[0]*mininet>/ { if (on) { exit 0; } on=1; }' | tac > $aux
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070045 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
Thomas Vachuskae1125352016-11-09 14:06:51 -080068 ssh -t -t $remote sudo mn -c
69
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070070 ;;
Thomas Vachuska4d5310c2016-07-14 12:48:39 -070071cleanup)
72 ssh -t -t $remote sudo mn -c
Thomas Vachuskaa8e125a2016-08-19 10:46:31 -070073 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 -070074 ;;
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070075esac