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 | |
Thomas Vachuska | a02fc81 | 2015-07-21 18:37:58 -0700 | [diff] [blame^] | 9 | export MAX_WAIT=60 |
Thomas Vachuska | 2527a0f | 2015-07-14 11:38:21 -0700 | [diff] [blame] | 10 | |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 11 | cmd="$1" && shift |
| 12 | log="screenlog.0" |
| 13 | remote="$ONOS_USER@$OCN" |
| 14 | mininet="ssh -t -t $remote screen -L -S mininet" |
| 15 | |
| 16 | case $cmd in |
| 17 | send) |
| 18 | $mininet -X "stuff \"$@\\n\"" 2>/dev/null |
| 19 | ;; |
| 20 | |
| 21 | sendAndExpect) |
Thomas Vachuska | e76f653 | 2015-07-08 09:40:53 -0700 | [diff] [blame] | 22 | cmd="" |
| 23 | for a in $*; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done |
| 24 | $mininet -X "stuff \"$cmd\\n\"" 2>/dev/null |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 25 | onos-mininet expect "$@" |
| 26 | ;; |
| 27 | |
| 28 | wait) |
| 29 | ssh $remote " |
Thomas Vachuska | 2527a0f | 2015-07-14 11:38:21 -0700 | [diff] [blame] | 30 | let count=0 |
| 31 | sleep 1 && while test ! -f $log; do if test \$count -ge $MAX_WAIT; then exit 1; fi; sleep 1; let count=count+1; done |
| 32 | while ! (tail -n1 $log | egrep -q '^mininet>'); do if [ \$count -ge $MAX_WAIT ]; then exit 1; fi; sleep 1; done |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 33 | sleep ${1-:1} |
| 34 | " |
| 35 | ;; |
| 36 | |
| 37 | expect) |
| 38 | aux=/tmp/mininet.$$.log |
| 39 | ssh $remote " |
Thomas Vachuska | e76f653 | 2015-07-08 09:40:53 -0700 | [diff] [blame] | 40 | sleep 1 |
| 41 | if [ ! -f $log ]; then exit 1; fi; |
Thomas Vachuska | 2527a0f | 2015-07-14 11:38:21 -0700 | [diff] [blame] | 42 | let count=0 |
| 43 | while ! (tail -n1 $log | egrep -q '^mininet>'); do if test \$count -ge $MAX_WAIT; then exit 1; fi; sleep 1; let count=count+1; done |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 44 | tac $log | awk '{ print \$0; } /^mininet>/ { if (on) { exit 0; } on=1; }' | tac > $aux |
| 45 | cat $aux |
| 46 | set -x |
| 47 | egrep \"$@\" $aux |
| 48 | " |
| 49 | ;; |
| 50 | |
Thomas Vachuska | f1c4208 | 2015-07-10 16:41:31 -0700 | [diff] [blame] | 51 | attach) |
| 52 | $mininet -x |
| 53 | ;; |
| 54 | |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 55 | start) |
Thomas Vachuska | e76f653 | 2015-07-08 09:40:53 -0700 | [diff] [blame] | 56 | ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc" |
| 57 | ( |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 58 | $mininet "$@" |
| 59 | scp $remote:$log /tmp/mininet.log |
| 60 | ssh $remote rm -f $log |
Thomas Vachuska | e76f653 | 2015-07-08 09:40:53 -0700 | [diff] [blame] | 61 | ) & |
Thomas Vachuska | 0a4c270 | 2015-07-06 08:43:41 -0700 | [diff] [blame] | 62 | ;; |
| 63 | |
| 64 | stop) |
| 65 | $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \ |
| 66 | $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \ |
| 67 | $mininet -X "stuff \"exit\\n\"" 2>/dev/null |
| 68 | ;; |
| 69 | esac |