4 CMD_NAME=`basename $0 .sh`
5 CMD_PATH=`readlink -f $0`
6 CMD_DIR=`dirname $CMD_PATH`
9 DUMP_DIR=/tmp/test-mn/dump
12 MN_PRE_FILE=/tmp/test-mn/mn-pre
13 MN_POST_FILE=/tmp/test-mn/mn-post
14 PKG_LIST="tshark tcpreplay mz"
19 echo "Usage: $0 [OPTION] [TEST DIR or FILE]..."
21 echo "Run Ryu's test in mininet"
22 echo "ex.) $ $0 l2 l3/icmp/ICMP_ping.mn"
25 echo " -h, --help show this help message and exit"
29 # set default environment
45 # making mininet-test-pre-file
49 echo "sh echo '----------------------------------'"
50 echo "sh echo '(pre) mininet topology dump.'"
51 echo "sh echo '----------------------------------'"
54 echo "sh echo '----------------------------------'"
55 echo "sh echo '(pre) tshark start.'"
56 echo "sh echo '----------------------------------'"
57 echo "$DUMP_HOST tshark -i $DUMP_IF -a duration:$DUMP_SEC -w $DUMP_FILE &"
58 echo "sh sleep $DUMP_DELAY"
59 echo "sh echo '----------------------------------'"
63 # making mininet-test-post-file
67 echo "sh ovs-vsctl del-controller s1"
68 echo "sh ovs-vsctl set bridge s1 protocols='[OpenFlow10,OpenFlow12]'"
69 echo "sh ovs-vsctl set-controller s1 tcp:127.0.0.1"
70 echo "sh echo '----------------------------------'"
71 echo "sh echo '(post) packet sending...'"
72 echo "sh echo '----------------------------------'"
75 echo "sh echo '----------------------------------'"
76 echo "sh echo '(post) dump flows.'"
77 echo "sh echo '----------------------------------'"
78 echo "sh ovs-ofctl dump-flows s1"
79 echo "sh echo '----------------------------------'"
83 # ovs cache-hit incremental check
85 expr `sudo ovs-dpctl show|sed -n 's|lookups: hit:||gp'|awk '{print $1}'` - ${1:-0}
88 # starting ryu-manager
93 echo "Inf: RYU_APP=$RYU_APP"
94 echo "Inf: ryu-manager starting..."
95 ryu-manager --verbose $RYU_APP 2>$DUMP_DIR/$RYU_LOG &
98 [ -d /proc/$PID_RYU ] || err $ERRTAG "failed to start ryu-manager."
103 # starting mininet and test-script
105 echo "Info: mininet starting..."
106 sudo mn --mac --test none --pre $MN_PRE_FILE --post $MN_POST_FILE \
107 --controller remote 127.0.0.1
110 # cleaning after mininet
113 rm -f $MN_PRE_FILE $MN_POST_FILE
116 # check packet and chache-hit
118 PACKET=`tshark -r $DUMP_FILE -R "$PCAP_FILTER" 2>/dev/null`
119 if [ ! "$PACKET" ]; then
121 REASON="(unmatched packet. please check $DUMP_FILE)"
122 elif [ "$CACHE_HIT" ] && [ `ovs_cache_hit $CACHE_HIT` -eq 0 ]; then
124 REASON="(ovs cache hit miss.)"
129 echo "TEST ${TEST_NAME} : $RESULT $REASON"
132 # stoping ryu-manager
140 DUMP_FILE=$DUMP_DIR/$DUMP_FILE
142 sudo chmod o+w $DUMP_FILE
143 [ "$CACHE_HIT" ] && CACHE_HIT=`ovs_cache_hit 0`
146 run_ryu; [ $? -ne 0 ] && return 1
147 run_mn; [ $? -ne 0 ] && return 1
159 test=`basename $1 $TEST_SUFFIX`
160 file=`readlink -f $1`
161 TEST_DIR=`dirname $file`
163 ERRTAG="mnfile_check() :"
166 if [ ! -r $file ]; then
167 err $ERRTAG "cannot open the file: $file"
171 . $file || err $ERRTAG "failed to include $file"
174 [ "$RYU_APP" ] || err $ERRTAG: "RYU_APP is not defined"
175 [ "$PCAP_FILE" -o "$PCAP_MZ" ] || err $ERRTAG: "PCAP_FILE or PCAP_MZ is not defined"
176 [ "$PCAP_FILTER" ] || err $ERRTAG "PCAP_FILTER is not defined"
177 [ "$TEST_NAME" ] || TEST_NAME=$test
178 [ "$DUMP_FILE" ] || DUMP_FILE=$test.dump
179 [ "$RYU_LOG" ] || RYU_LOG=ryu-manager.$test.log
180 [ $ERRSTAT -ne 0 ] && return $ERRSTAT
182 # pcap check (pcap-file or mz-option)
183 if [ "$PCAP_FILE" ]; then
184 PCAP_FILE=$TEST_DIR/$PCAP_FILE
185 [ -r $PCAP_FILE ] || err $ERRTAG "PCAP_FILE[$PCAP_FILE] cannot read"
186 PCAP_COM="h1 tcpreplay -l 3 -i $POST_IF $PCAP_FILE"
187 elif [ "$PCAP_MZ" ]; then
188 PCAP_COM="h1 mz $POST_IF $PCAP_MZ"
190 [ $ERRSTAT -ne 0 ] && return $ERRSTAT
193 [ -r $TEST_DIR/$RYU_APP -o -r $TEST_DIR/${RYU_APP}.py ] && RYU_APP=$TEST_DIR/$RYU_APP
200 ERRTAG="argcheck() :"
206 if [ $# -ne 0 ]; then
209 ARGLIST=`find . -type f -name "*$TEST_SUFFIX"`
212 for arg in $ARGLIST; do
214 file=`find $arg -type f -name "*$TEST_SUFFIX"`
215 elif [ -f $arg ]; then
218 err $ERRTAG "$arg is not found"
222 TEST_LIST="$TEST_LIST $file"
228 for pkg in $PKG_LIST; do
229 [ ! `which $pkg` ] && no_pkg="$no_pkg $pkg"
231 for pkg in $no_pkg; do
232 echo "Error: Package [ $pkg ] is not found. Please install."
234 [ "$no_pkg" ] && exit 1
238 [ -d $DUMP_DIR ] || mkdir -p $DUMP_DIR
242 echo "\n---------- test target ----------"
243 for testfile in $TEST_LIST; do echo $testfile; done
246 for testfile in $TEST_LIST; do
247 echo "\n---------- test [$testfile] start ----------"
249 mnfile_check $testfile && test_mn
251 0) msg="finished : $RESULT" ;;
252 *) msg="skipped with error"; RESULT="skip" ;;
254 eval RESULT_${count}=\$RESULT
255 eval REASON_${count}=\$REASON
256 count=`expr $count + 1`
257 num=`eval echo \\${num_$RESULT:-0}`
258 eval num_${RESULT}=`expr $num + 1`
259 [ "$RESULT" != "OK" ] && RTN=1
261 echo "\n---------- test [$testfile] $msg ----------"
264 # output summary results
265 echo "\n---------- test results ----------"
267 for testfile in $TEST_LIST; do
268 eval echo \$testfile : \$RESULT_${count} \$REASON_${count}
269 count=`expr $count + 1`
271 echo "----------------------------------"
272 echo "Ran $count tests. Result: ${num_OK:+OK=}$num_OK ${num_NG:+NG=}$num_NG ${num_skip:+skip=}$num_skip"