Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 1 | #!/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 | |
| 9 | cmd="$1" && shift |
| 10 | log="screenlog.0" |
| 11 | remote="$ONOS_USER@$OCN" |
| 12 | mininet="ssh -t -t $remote screen -L -S mininet" |
| 13 | |
| 14 | case $cmd in |
| 15 | send) |
| 16 | $mininet -X "stuff \"$@\\n\"" 2>/dev/null |
| 17 | ;; |
| 18 | |
| 19 | sendAndExpect) |
| 20 | $mininet -X "stuff \"$1\\n\"" 2>/dev/null |
| 21 | shift |
| 22 | onos-mininet expect "$@" |
| 23 | ;; |
| 24 | |
| 25 | wait) |
| 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 | |
| 33 | expect) |
| 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 | |
| 44 | start) |
| 45 | ssh $remote rm -f $log |
| 46 | $mininet "$@" |
| 47 | scp $remote:$log /tmp/mininet.log |
| 48 | ssh $remote rm -f $log |
| 49 | ;; |
| 50 | |
| 51 | stop) |
| 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 | ;; |
| 56 | esac |