blob: 5c03c062922dfde4052737ce6a62269cbcae7d0f [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)
20 $mininet -X "stuff \"$1\\n\"" 2>/dev/null
21 shift
22 onos-mininet expect "$@"
23 ;;
24
25wait)
26 ssh $remote "
27 sleep 1 && while test ! -f $log; do sleep 1; done
28 while ! (tail -n1 $log | egrep -q '^mininet>'); do sleep 1; done
29 sleep ${1-:1}
30 "
31 ;;
32
33expect)
34 aux=/tmp/mininet.$$.log
35 ssh $remote "
36 sleep 1 && while ! (tail -n1 $log | egrep -q '^mininet>'); do sleep 1; done
37 tac $log | awk '{ print \$0; } /^mininet>/ { if (on) { exit 0; } on=1; }' | tac > $aux
38 cat $aux
39 set -x
40 egrep \"$@\" $aux
41 "
42 ;;
43
44start)
45 ssh $remote rm -f $log
46 $mininet "$@"
47 scp $remote:$log /tmp/mininet.log
48 ssh $remote rm -f $log
49 ;;
50
51stop)
52 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
53 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
54 $mininet -X "stuff \"exit\\n\"" 2>/dev/null
55 ;;
56esac