blob: 5f11fd0786b0877503ff7376eb88a0cde15f02df [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
9cmd="$1" && shift
10log="screenlog.0"
11remote="$ONOS_USER@$OCN"
12mininet="ssh -t -t $remote screen -L -S mininet"
13
14case $cmd in
15send)
16 $mininet -X "stuff \"$@\\n\"" 2>/dev/null
17 ;;
18
19sendAndExpect)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070020 cmd=""
21 for a in $*; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
22 $mininet -X "stuff \"$cmd\\n\"" 2>/dev/null
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070023 onos-mininet expect "$@"
24 ;;
25
26wait)
27 ssh $remote "
28 sleep 1 && while test ! -f $log; do sleep 1; done
29 while ! (tail -n1 $log | egrep -q '^mininet>'); do sleep 1; done
30 sleep ${1-:1}
31 "
32 ;;
33
34expect)
35 aux=/tmp/mininet.$$.log
36 ssh $remote "
Thomas Vachuskae76f6532015-07-08 09:40:53 -070037 sleep 1
38 if [ ! -f $log ]; then exit 1; fi;
39 while ! (tail -n1 $log | egrep -q '^mininet>'); do sleep 1; done
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070040 tac $log | awk '{ print \$0; } /^mininet>/ { if (on) { exit 0; } on=1; }' | tac > $aux
41 cat $aux
42 set -x
43 egrep \"$@\" $aux
44 "
45 ;;
46
Thomas Vachuskaf1c42082015-07-10 16:41:31 -070047attach)
48 $mininet -x
49 ;;
50
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070051start)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070052 ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc"
53 (
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070054 $mininet "$@"
55 scp $remote:$log /tmp/mininet.log
56 ssh $remote rm -f $log
Thomas Vachuskae76f6532015-07-08 09:40:53 -070057 ) &
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070058 ;;
59
60stop)
61 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
62 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
63 $mininet -X "stuff \"exit\\n\"" 2>/dev/null
64 ;;
65esac