tools/dtnd-run
changeset 29 00dfdf113d87
equal deleted inserted replaced
28:406d4f7eb00d 29:00dfdf113d87
       
     1 #!/bin/bash
       
     2 
       
     3 usage() {
       
     4 cat << EOF
       
     5 usage: $0 options
       
     6 
       
     7 This script runs the dtn daemon with optional disruptions.
       
     8 
       
     9 OPTIONS:
       
    10    -h      Show this message
       
    11    -i n    Restart the daemon every n seconds (used to force fragmentation)
       
    12    -l n    Drop all links every n seconds (used to force fragmentation)
       
    13    -r      Remove log file at start
       
    14    -t      tidy the daemon the first time
       
    15    -T      tidy the daemon every time
       
    16 EOF
       
    17 }
       
    18 
       
    19 if [[ $EUID -ne 0 ]]; then
       
    20    echo "This script must be run as root" 1>&2
       
    21    exit 1
       
    22 fi
       
    23 
       
    24 DTND="/home/aidan/build/DTN2-BPQ/daemon/dtnd"
       
    25 LOG="/var/log/dtn/dtnd.log"
       
    26 
       
    27 INT=0
       
    28 INT_LINK=0
       
    29 RM_LOG=0
       
    30 TIDY=0
       
    31 TIDY_ALL=0
       
    32 while getopts “hi:l:rtT” OPTION; do
       
    33     case $OPTION in
       
    34         h)
       
    35             usage
       
    36             exit 1
       
    37             ;;
       
    38         i)
       
    39             INT=1
       
    40             SEC=$OPTARG
       
    41             ;;
       
    42         l)
       
    43             INT_LINK=1
       
    44             SEC=$OPTARG
       
    45             ;;
       
    46         r)
       
    47             RM_LOG=1
       
    48             ;;
       
    49         t)
       
    50             TIDY=1
       
    51             ;;
       
    52         T)
       
    53             TIDY=1
       
    54             TIDY_ALL=1
       
    55             ;;
       
    56         ?)
       
    57             usage
       
    58             exit 1
       
    59     esac
       
    60 done
       
    61 
       
    62 
       
    63 echo "stop dtnd (if running)"
       
    64 dtnd-control stop
       
    65 
       
    66 if [[ $RM_LOG -eq 1 ]]; then
       
    67     echo "removing old log file"
       
    68     rm -f $LOG
       
    69 fi
       
    70 
       
    71 if [[ $TIDY -eq 1 ]]; then
       
    72     echo "starting dtnd (tidy)"
       
    73     $DTND -o $LOG -l debug -dt
       
    74 else
       
    75     echo "starting dtnd"
       
    76     $DTND -o $LOG -l debug -d
       
    77 fi
       
    78 
       
    79 while [[ $INT -eq 1 ]]; do
       
    80     echo "sleep for $SEC seconds..."
       
    81     sleep $SEC
       
    82     echo "stop dtnd"
       
    83     dtnd-control stop
       
    84 
       
    85     echo "sleep for 5 seconds..."
       
    86     sleep 5
       
    87     if [[ $TIDY_ALL -eq 1 ]]; then
       
    88         echo "starting dtnd (tidy)"
       
    89         $DTND -o $LOG -l debug -dt
       
    90     else
       
    91         echo "starting dtnd"
       
    92         $DTND -o $LOG -l debug -d
       
    93     fi
       
    94 done
       
    95 
       
    96 while [[ $INT_LINK -eq 1 ]]; do
       
    97     echo "sleep for $SEC seconds..."
       
    98     sleep $SEC
       
    99     
       
   100     dtnd-control link_dump  | \
       
   101     grep -v "^$"            | \
       
   102     awk '{print $1}'        | \
       
   103     while read link; do
       
   104         echo "closing link: $link..."
       
   105         dtnd-control -name $link link_close
       
   106     done
       
   107 done
       
   108 
       
   109 sleep 2
       
   110 echo "check if the daemon is running before exiting"
       
   111 dtnd-control check
       
   112 
       
   113 exit 0
       
   114