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) |
Thomas Vachuska | e76f653 | 2015-07-08 09:40:53 -0700 | [diff] [blame] | 20 | 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 Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 23 | onos-mininet expect "$@" |
| 24 | ;; |
| 25 | |
| 26 | wait) |
| 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 | |
| 34 | expect) |
| 35 | aux=/tmp/mininet.$$.log |
| 36 | ssh $remote " |
Thomas Vachuska | e76f653 | 2015-07-08 09:40:53 -0700 | [diff] [blame] | 37 | sleep 1 |
| 38 | if [ ! -f $log ]; then exit 1; fi; |
| 39 | while ! (tail -n1 $log | egrep -q '^mininet>'); do sleep 1; done |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 40 | 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 Vachuska | f1c4208 | 2015-07-10 16:41:31 -0700 | [diff] [blame^] | 47 | attach) |
| 48 | $mininet -x |
| 49 | ;; |
| 50 | |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 51 | start) |
Thomas Vachuska | e76f653 | 2015-07-08 09:40:53 -0700 | [diff] [blame] | 52 | ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc" |
| 53 | ( |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 54 | $mininet "$@" |
| 55 | scp $remote:$log /tmp/mininet.log |
| 56 | ssh $remote rm -f $log |
Thomas Vachuska | e76f653 | 2015-07-08 09:40:53 -0700 | [diff] [blame] | 57 | ) & |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 58 | ;; |
| 59 | |
| 60 | stop) |
| 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 | ;; |
| 65 | esac |