diff -r 406d4f7eb00d -r 00dfdf113d87 tools/dtnd-run --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/dtnd-run Wed Aug 10 13:38:52 2011 +0100 @@ -0,0 +1,114 @@ +#!/bin/bash + +usage() { +cat << EOF +usage: $0 options + +This script runs the dtn daemon with optional disruptions. + +OPTIONS: + -h Show this message + -i n Restart the daemon every n seconds (used to force fragmentation) + -l n Drop all links every n seconds (used to force fragmentation) + -r Remove log file at start + -t tidy the daemon the first time + -T tidy the daemon every time +EOF +} + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +DTND="/home/aidan/build/DTN2-BPQ/daemon/dtnd" +LOG="/var/log/dtn/dtnd.log" + +INT=0 +INT_LINK=0 +RM_LOG=0 +TIDY=0 +TIDY_ALL=0 +while getopts “hi:l:rtT” OPTION; do + case $OPTION in + h) + usage + exit 1 + ;; + i) + INT=1 + SEC=$OPTARG + ;; + l) + INT_LINK=1 + SEC=$OPTARG + ;; + r) + RM_LOG=1 + ;; + t) + TIDY=1 + ;; + T) + TIDY=1 + TIDY_ALL=1 + ;; + ?) + usage + exit 1 + esac +done + + +echo "stop dtnd (if running)" +dtnd-control stop + +if [[ $RM_LOG -eq 1 ]]; then + echo "removing old log file" + rm -f $LOG +fi + +if [[ $TIDY -eq 1 ]]; then + echo "starting dtnd (tidy)" + $DTND -o $LOG -l debug -dt +else + echo "starting dtnd" + $DTND -o $LOG -l debug -d +fi + +while [[ $INT -eq 1 ]]; do + echo "sleep for $SEC seconds..." + sleep $SEC + echo "stop dtnd" + dtnd-control stop + + echo "sleep for 5 seconds..." + sleep 5 + if [[ $TIDY_ALL -eq 1 ]]; then + echo "starting dtnd (tidy)" + $DTND -o $LOG -l debug -dt + else + echo "starting dtnd" + $DTND -o $LOG -l debug -d + fi +done + +while [[ $INT_LINK -eq 1 ]]; do + echo "sleep for $SEC seconds..." + sleep $SEC + + dtnd-control link_dump | \ + grep -v "^$" | \ + awk '{print $1}' | \ + while read link; do + echo "closing link: $link..." + dtnd-control -name $link link_close + done +done + +sleep 2 +echo "check if the daemon is running before exiting" +dtnd-control check + +exit 0 +