2018-01-27 14:52:45 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Contiki directory
|
|
|
|
CONTIKI=$1
|
|
|
|
|
|
|
|
# Simulation file
|
|
|
|
BASENAME=$2
|
|
|
|
|
|
|
|
# Destination IPv6
|
|
|
|
IPADDR=$3
|
|
|
|
|
2018-01-27 16:28:57 +00:00
|
|
|
# ICMP request-reply count
|
|
|
|
COUNT=5
|
|
|
|
|
2018-01-27 14:52:45 +00:00
|
|
|
# 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
|
|
|
|
|
|
|
|
# Connect to the simlation
|
|
|
|
echo "Starting native border-router"
|
2018-01-27 16:28:57 +00:00
|
|
|
nohup make -C $CONTIKI/examples/rpl-border-router/ connect-router-cooja TARGET=native >> $BASENAME.nbr.log 2>&1 &
|
2018-01-27 14:52:45 +00:00
|
|
|
MPID=$!
|
|
|
|
echo "Waiting for network formation"
|
2018-01-27 16:28:57 +00:00
|
|
|
sleep 60 # runs in real time so we need to wait a bit
|
2018-01-27 14:52:45 +00:00
|
|
|
|
|
|
|
# Do ping
|
|
|
|
echo "Pinging"
|
2018-01-27 16:28:57 +00:00
|
|
|
ping6 $IPADDR -c $COUNT | tee $BASENAME.scriptlog
|
2018-01-27 14:52:45 +00:00
|
|
|
# Fetch ping6 status code (not $? because this is piped)
|
|
|
|
STATUS=${PIPESTATUS[0]}
|
2018-01-27 16:28:57 +00:00
|
|
|
REPLIES=`grep -c 'icmp_seq=' $BASENAME.scriptlog`
|
2018-01-27 14:52:45 +00:00
|
|
|
|
|
|
|
echo "Closing simulation and nbr"
|
|
|
|
sleep 1
|
|
|
|
kill -9 $JPID
|
|
|
|
kill -9 $MPID
|
|
|
|
sleep 1
|
|
|
|
rm COOJA.testlog
|
|
|
|
rm COOJA.log
|
|
|
|
|
2018-01-27 16:28:57 +00:00
|
|
|
if [ $STATUS -eq 0 ] && [ $REPLIES -eq $COUNT ] ; then
|
2018-01-27 14:52:45 +00:00
|
|
|
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
|