blob: 4c60e42ed33f3a3c00f51edb36b684f53a336c29 [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"
Terje Mikal Mjeldefbaf0552018-03-09 09:14:03 +010014screenversion=$(ssh $remote screen -v | sed -n -e 's/^Screen version \([0-9]*\.[0-9]*\).*$/\1/p')
15# note: Screen version check for >4.04 may be inaccurate - The only sure thing is that v4.01
16# requires logname to NOT be given while in v4.05 it is optional (as long as -L is the
17# last parameter on the command line).
18[[ $screenversion > "4.04" ]] && screenlog=$log
19mininet="ssh -t -t $remote screen -L $screenlog -S mininet"
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070020
21case $cmd in
22send)
23 $mininet -X "stuff \"$@\\n\"" 2>/dev/null
24 ;;
25
26sendAndExpect)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070027 cmd=""
28 for a in $*; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
29 $mininet -X "stuff \"$cmd\\n\"" 2>/dev/null
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070030 onos-mininet expect "$@"
31 ;;
32
33wait)
34 ssh $remote "
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070035 let count=0
36 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 Milkey5d35f9c2018-04-02 08:54:51 -070037 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 -070038 sleep ${1-:1}
39 "
40 ;;
41
42expect)
43 aux=/tmp/mininet.$$.log
44 ssh $remote "
Thomas Vachuskae76f6532015-07-08 09:40:53 -070045 sleep 1
46 if [ ! -f $log ]; then exit 1; fi;
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070047 let count=0
Ray Milkey5d35f9c2018-04-02 08:54:51 -070048 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
49 tac $log | awk '{ print \$0; } /^[ ]*[0]*mininet>/ { if (on) { exit 0; } on=1; }' | tac > $aux
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070050 cat $aux
51 set -x
52 egrep \"$@\" $aux
53 "
54 ;;
55
Thomas Vachuskaf1c42082015-07-10 16:41:31 -070056attach)
57 $mininet -x
58 ;;
59
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070060start)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070061 ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc"
62 (
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070063 $mininet "$@"
64 scp $remote:$log /tmp/mininet.log
65 ssh $remote rm -f $log
Thomas Vachuskae76f6532015-07-08 09:40:53 -070066 ) &
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070067 ;;
68
69stop)
70 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
71 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
72 $mininet -X "stuff \"exit\\n\"" 2>/dev/null
Thomas Vachuskae1125352016-11-09 14:06:51 -080073 ssh -t -t $remote sudo mn -c
74
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070075 ;;
Thomas Vachuska4d5310c2016-07-14 12:48:39 -070076cleanup)
77 ssh -t -t $remote sudo mn -c
Thomas Vachuskaa8e125a2016-08-19 10:46:31 -070078 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 -070079 ;;
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070080esac