blob: 0af386007fadbf0dceb37dda0e494ec76aaadefb [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
Thomas Vachuskaa7b24042018-05-15 12:45:47 -070019[[ $screenversion > "4.05" ]] && screenlog="-Logfile $log"
Terje Mikal Mjeldefbaf0552018-03-09 09:14:03 +010020mininet="ssh -t -t $remote screen -L $screenlog -S mininet"
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070021
22case $cmd in
23send)
24 $mininet -X "stuff \"$@\\n\"" 2>/dev/null
25 ;;
26
27sendAndExpect)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070028 cmd=""
29 for a in $*; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
30 $mininet -X "stuff \"$cmd\\n\"" 2>/dev/null
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070031 onos-mininet expect "$@"
32 ;;
33
34wait)
35 ssh $remote "
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070036 let count=0
37 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 Milkey922db302018-04-02 08:54:51 -070038 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 -070039 sleep ${1-:1}
40 "
41 ;;
42
43expect)
44 aux=/tmp/mininet.$$.log
45 ssh $remote "
Thomas Vachuskae76f6532015-07-08 09:40:53 -070046 sleep 1
47 if [ ! -f $log ]; then exit 1; fi;
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070048 let count=0
Ray Milkey922db302018-04-02 08:54:51 -070049 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
50 tac $log | awk '{ print \$0; } /^[ ]*[0]*mininet>/ { if (on) { exit 0; } on=1; }' | tac > $aux
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070051 cat $aux
52 set -x
53 egrep \"$@\" $aux
54 "
55 ;;
56
Thomas Vachuskaf1c42082015-07-10 16:41:31 -070057attach)
58 $mininet -x
59 ;;
60
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070061start)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070062 ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc"
63 (
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070064 $mininet "$@"
65 scp $remote:$log /tmp/mininet.log
66 ssh $remote rm -f $log
Thomas Vachuskae76f6532015-07-08 09:40:53 -070067 ) &
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070068 ;;
69
70stop)
71 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
72 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
73 $mininet -X "stuff \"exit\\n\"" 2>/dev/null
Thomas Vachuskae1125352016-11-09 14:06:51 -080074 ssh -t -t $remote sudo mn -c
75
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070076 ;;
Thomas Vachuska4d5310c2016-07-14 12:48:39 -070077cleanup)
78 ssh -t -t $remote sudo mn -c
Thomas Vachuskaa8e125a2016-08-19 10:46:31 -070079 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 -070080 ;;
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070081esac