blob: e5898d2af42402afe33b39ab7fe4ec357639a4ca [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
Thomas Vachuska534f4762016-08-30 16:25:13 -07009export MAX_WAIT=${ONOS_MN_TIMEOUT:-90}
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070010
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070011cmd="$1" && shift
12log="screenlog.0"
13remote="$ONOS_USER@$OCN"
DongRyeol Cha5c0a9f02018-05-17 14:32:55 +090014remote_scp="$ONOS_USER@[$OCN]"
Terje Mikal Mjeldefbaf0552018-03-09 09:14:03 +010015screenversion=$(ssh $remote screen -v | sed -n -e 's/^Screen version \([0-9]*\.[0-9]*\).*$/\1/p')
16# note: Screen version check for >4.04 may be inaccurate - The only sure thing is that v4.01
17# requires logname to NOT be given while in v4.05 it is optional (as long as -L is the
18# last parameter on the command line).
19[[ $screenversion > "4.04" ]] && screenlog=$log
Thomas Vachuskaa7b24042018-05-15 12:45:47 -070020[[ $screenversion > "4.05" ]] && screenlog="-Logfile $log"
Terje Mikal Mjeldefbaf0552018-03-09 09:14:03 +010021mininet="ssh -t -t $remote screen -L $screenlog -S mininet"
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070022
23case $cmd in
24send)
25 $mininet -X "stuff \"$@\\n\"" 2>/dev/null
26 ;;
27
28sendAndExpect)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070029 cmd=""
30 for a in $*; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
31 $mininet -X "stuff \"$cmd\\n\"" 2>/dev/null
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070032 onos-mininet expect "$@"
33 ;;
34
35wait)
36 ssh $remote "
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070037 let count=0
38 sleep 1 && while test ! -f $log; do if test \$count -ge $MAX_WAIT; then exit 1; fi; sleep 1; let count=count+1; done
Ray Milkey922db302018-04-02 08:54:51 -070039 while ! (tail -n1 $log | egrep -q '^[ ]*[0]*mininet>'); do if [ \$count -ge $MAX_WAIT ]; then exit 1; fi; sleep 1; done
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070040 sleep ${1-:1}
41 "
42 ;;
43
44expect)
45 aux=/tmp/mininet.$$.log
46 ssh $remote "
Thomas Vachuskae76f6532015-07-08 09:40:53 -070047 sleep 1
48 if [ ! -f $log ]; then exit 1; fi;
Thomas Vachuska2527a0f2015-07-14 11:38:21 -070049 let count=0
Ray Milkey922db302018-04-02 08:54:51 -070050 while ! (tail -n1 $log | egrep -q '^[ ]*[0]*mininet>'); do if test \$count -ge $MAX_WAIT; then exit 1; fi; sleep 1; let count=count+1; done
51 tac $log | awk '{ print \$0; } /^[ ]*[0]*mininet>/ { if (on) { exit 0; } on=1; }' | tac > $aux
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070052 cat $aux
53 set -x
54 egrep \"$@\" $aux
55 "
56 ;;
57
Thomas Vachuskaf1c42082015-07-10 16:41:31 -070058attach)
59 $mininet -x
60 ;;
61
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070062start)
Thomas Vachuskae76f6532015-07-08 09:40:53 -070063 ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc"
64 (
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070065 $mininet "$@"
DongRyeol Cha5c0a9f02018-05-17 14:32:55 +090066 scp $remote_scp:$log /tmp/mininet.log
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070067 ssh $remote rm -f $log
Thomas Vachuskae76f6532015-07-08 09:40:53 -070068 ) &
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070069 ;;
70
71stop)
72 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
73 $mininet -X "stuff \"^C\\n\"" 2>/dev/null && \
74 $mininet -X "stuff \"exit\\n\"" 2>/dev/null
Thomas Vachuskae1125352016-11-09 14:06:51 -080075 ssh -t -t $remote sudo mn -c
76
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070077 ;;
Thomas Vachuska4d5310c2016-07-14 12:48:39 -070078cleanup)
79 ssh -t -t $remote sudo mn -c
Thomas Vachuskaa8e125a2016-08-19 10:46:31 -070080 ssh -t -t $remote "screen -list | grep mininet | cut -d. -f1 | tr -d '\t' | xargs kill -9; screen -wipe; exit 0"
Thomas Vachuska4d5310c2016-07-14 12:48:39 -070081 ;;
Thomas Vachuska0a4c2702015-07-06 08:43:41 -070082esac