#!/bin/bash # Contiki directory CONTIKI=$1 # Simulation file BASENAME=$2 # Destination IPv6 IPADDR=$3 # Start simulation echo "Starting Cooja simulation $BASENAME.csc" java -Xshare:on -jar $CONTIKI/tools/cooja/dist/cooja.jar -nogui=$BASENAME.csc -contiki=$CONTIKI > $BASENAME.coojalog & JPID=$! sleep 20 echo "Enabling IPv6" sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 # Connect to the simlation echo "Starting native border-router" make -C $CONTIKI/examples/rpl-border-router/ sudo $CONTIKI/examples/rpl-border-router/border-router.native -B 115200 -a localhost fd02::1/64 >> $BASENAME.nbr.log 2>&1 & MPID=$! echo "Waiting for network formation" sleep 50 # Do ping echo "Pinging" ping6 $IPADDR -s 10 -c 5 | tee $BASENAME.scriptlog # Fetch ping6 status code (not $? because this is piped) STATUS=${PIPESTATUS[0]} echo "Closing simulation and nbr" sleep 1 kill -9 $JPID kill -9 $MPID sleep 1 rm COOJA.testlog rm COOJA.log if [ $STATUS -eq 0 ] ; then printf "%-32s TEST OK\n" "$BASENAME" | tee $BASENAME.testlog; else echo "==== $BASENAME.coojalog ====" ; cat $BASENAME.coojalog; echo "==== $BASENAME.nbr.log ====" ; cat $BASENAME.nbr.log; echo "==== $BASENAME.scriptlog ====" ; cat $BASENAME.scriptlog; printf "%-32s TEST FAIL\n" "$BASENAME" | tee $BASENAME.testlog; fi # We do not want Make to stop -> Return 0 # The Makefile will check if a log contains FAIL at the end exit 0