Tcp staticroute 20051109.sh

From
Revision as of 09:23, 25 January 2006 by Kurth (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
 #!/bin/sh
 ########################################################################
 # tcp_throughput.sh
 ########################################################################
 #
 # This file is executed on each test node. It is not intended for
 # direct execution. See run_test.sh instead.
 #
 # Note: 
 #   In order to execute all necessary commands on test nodes, add
 #   the following line to your sudoers (visudo):
 # brn       ALL = (root) NOPASSWD: /sbin/route, /sbin/ifconfig, /usr/sbin/iptables
 ########################################################################
 
 DEBUG=""
 BRNSRC=""
 BRNDST=""
 TSTSRC=""
 TSTDST=""
 NODES=""
 NODEDB=""
 
 CLICK_SCRIPT=brn_master.click
 CLICKPATH=/mnt/kurth
 SCRIPTNAME="${0}"
 TEST_ABORT=80
 CLICK_PROC=/tmp/click
 CHANNEL=14
 
 #-----------------------------------------------------------------------
 
 usage()
 {
   echo
   echo "Usage: ${SCRIPTNAME} <options> <additional nodes>"
   echo "  options are..."
   echo "     -a brn-src        IP of the input node into the BRN."
   echo "     -b brn-dst        IP of the ouput node out of the BRN."
   echo "     -c tst-src        IP of the test source generating the traffic."
   echo "     -d tst-dst        IP of the test destination processing the traffic."
   echo "     --nodedb file     The nodedb file to use."
   echo "     --clickpath  path Path to the click bin dir."
   echo "     --clickscript scr The click script to execute."
   echo "     --debug           Turn on debug (optional)"
   echo "     add. nodes        Nodes over which the traffic is relayed."
   echo ""
   echo "    note: all used nodes must be listed in the nodedb file."
   exit 1
 }
 
 #-----------------------------------------------------------------------
 
 error()
 {
   echo "ERROR: $1"
   usage
   exit 1
 }
 
 #-----------------------------------------------------------------------
 
 warning()
 {
   echo "WARN:  $1"
 }
 
 #-----------------------------------------------------------------------
 
 debug()
 {
   if test ! -z "$DEBUG"
   then
     echo "DEBUG: $1"
   fi
 }
 
 #-----------------------------------------------------------------------
 
 nodedb_getath()
 {
   RETV=`grep -e "$1" ${NODEDB} | awk '{print $5}' | egrep -e '([0-9A-Fa-f]{2}:){5}[0-9a-fA-F]'`
   debug "Node $1 has ath0 mac $RETV"
   
   if test -z ${RETV} 
   then
     error "Could not grep ath0 address of node $1 from node-db."
   fi
   
   echo ${RETV}
 }
 
 #-----------------------------------------------------------------------
 
 nodedb_getmac()
 {
   RETV=`grep -e "$1" ${NODEDB} | awk '{print $4}' | egrep -e '([0-9A-Fa-f]{2}:){5}[0-9a-fA-F]'`
   debug "Node $1 has mac $RETV"
   
   if test -z ${RETV} 
   then
     error "Could not grep ether address of node $1 from node-db."
   fi
   
   echo ${RETV}
 }
 
 #-----------------------------------------------------------------------
 
 run_node0()
 {
   # Please set the -r option for the syslogd, so that it will accept
   # remote logging messges (SYSLOGD_PARAMS="-r" in /etc/sysconfig/syslog
   # or corresponding entry in /etc/syslog-ng/syslog-ng.conf)
 
   sleep 12
   debug "iperf -c ${BRNSRC} -p 4711 -t 5 -f k &"
   iperf -c ${BRNSRC} -p 4711 -t 5 -f k &
 
   sleep 15
   debug "kill %1"
   kill %1
 
   debug "iperf -c ${BRNSRC} -p 4711 -t 30 -f k &"
   sh -c "iperf -c ${BRNSRC} -p 4711 -t 30 -f k; killall sleep" &
 
   sleep ${TEST_ABORT}
   debug "killall -q -SIGKILL iperf"
   killall -q -SIGKILL iperf
 }
 
 #-----------------------------------------------------------------------
 
 run_node1()
 {
   debug "Executing iperf -s -p 4711 -f k &"
   iperf -s -p 4711 -f k &
       
   sleep ${TEST_ABORT}
   debug "Executing killall -q -SIGKILL iperf"
   killall -q -SIGKILL iperf
 }
 
 #-----------------------------------------------------------------------
 
 shutdown_click()
 {
   IFCONFIG=ifconfig
   UMOUNT=umount
   RMMOD=rmmod
 
   debug "Executing killall -q logserver"
   killall -q -SIGKILL logserver
 
   debug "Executing killall -q -SIGKILL click"
   killall -q -SIGKILL click
 
   debug "${IFCONFIG} ath0 down 2>&1 > /dev/null"
   ${IFCONFIG} ath0 down 2>&1 > /dev/null
 
   debug "${UMOUNT}  ${CLICK_PROC} 2>&1 > /dev/null"
   ${UMOUNT}  ${CLICK_PROC} 2>&1 > /dev/null
 
   debug "${RMMOD} click.ko"
   ${RMMOD} click.ko
 
   debug "${RMMOD} proclikefs.ko"
   ${RMMOD} proclikefs.ko
 
   debug "${RMMOD} ath_pci.ko"
   ${RMMOD} ath_pci.ko
 
   debug "${RMMOD} ath_hal.ko"
   ${RMMOD} ath_hal.ko
 
 #debug "killall -q syslogd"
 #killall -q syslogd
 #killall -SIGKILL -q syslogd
 
 #debug "syslogd -C 16 < /dev/null > /dev/null 2>&1"
 #syslogd -C 16 < /dev/null > /dev/null 2>&1
 }
 
 #-----------------------------------------------------------------------
 
 setup_click()
 {
   IFCONFIG=ifconfig
   MOUNT=mount
   INSMOD=insmod
   IWCONFIG=/usr/sbin/iwconfig
 
 #debug "killall -q syslogd"
 #killall -q syslogd
 
 #debug "syslogd -R ${TSTSRC} -L -C 16"
 #syslogd -R ${TSTSRC} -L -C 16 
 
   #export CLICKPATH
   debug "${INSMOD} ./ath_hal.ko"
   ${INSMOD} ./ath_hal.ko
 
   debug "${INSMOD} ./ath_pci.ko"
   ${INSMOD} ./ath_pci.ko countrycode=392
 
   debug "${INSMOD} ./proclikefs.ko"
   ${INSMOD} ./proclikefs.ko
 
   debug "${INSMOD} ./click.ko"
   ${INSMOD} ./click.ko
 
   debug "mkdir -p ${CLICK_PROC}"
   mkdir -p ${CLICK_PROC} 
 
   debug "${MOUNT} -t click none ${CLICK_PROC}"
   ${MOUNT} -t click none ${CLICK_PROC}
 
   debug "${IFCONFIG} ath0 up"
   ${IFCONFIG} ath0 up
 
   debug "iwconfig ath0 channel ${CHANNEL}"
   ${IWCONFIG} ath0 channel ${CHANNEL}
 
   debug "Executing ./logserver 7777 &"
   ./logserver 7777 &
 }
 
 #-----------------------------------------------------------------------
 
 run_node2()
 {
   BRNDSTMAC=`nodedb_getmac ${BRNDST}`
   BRNSRCMAC=`nodedb_getmac ${BRNSRC}`
   TSTDSTMAC=`nodedb_getmac ${TSTDST}`
   TSTSRCMAC=`nodedb_getmac ${TSTSRC}`
 
 # Prepare first rewriter
   debug "echo \"${BRNDSTMAC}\" > ${CLICK_PROC}/rewriter1/ether_dst"
   echo "${BRNDSTMAC}" > ${CLICK_PROC}/rewriter1/ether_dst
   debug "echo \"${BRNSRCMAC}\" > ${CLICK_PROC}/rewriter1/ether_src"
   echo "${BRNSRCMAC}" > ${CLICK_PROC}/rewriter1/ether_src
   debug "echo \"${TSTDST}\"    > ${CLICK_PROC}/rewriter1/ip_dst"
   echo "${TSTDST}"    > ${CLICK_PROC}/rewriter1/ip_dst
   debug "echo \"${BRNDST}\"    > ${CLICK_PROC}/rewriter1/ip_src"
   echo "${BRNDST}"    > ${CLICK_PROC}/rewriter1/ip_src
   debug "echo \"true\"         > ${CLICK_PROC}/rewriter1/active"
   echo "true"         > ${CLICK_PROC}/rewriter1/active
   
 
   # Set up second rewriter  
   debug "echo \"${TSTSRCMAC}\" > ${CLICK_PROC}/rewriter2/ether_dst"
   echo "${TSTSRCMAC}" > ${CLICK_PROC}/rewriter2/ether_dst
   debug "echo \"${BRNSRCMAC}\" > ${CLICK_PROC}/rewriter2/ether_src"
   echo "${BRNSRCMAC}" > ${CLICK_PROC}/rewriter2/ether_src
   debug "echo \"${TSTSRC}\"    > ${CLICK_PROC}/rewriter2/ip_dst"
   echo "${TSTSRC}"    > ${CLICK_PROC}/rewriter2/ip_dst
   debug "echo \"${BRNSRC}\"    > ${CLICK_PROC}/rewriter2/ip_src"
   echo "${BRNSRC}"    > ${CLICK_PROC}/rewriter2/ip_src
   debug "echo \"true\"         > ${CLICK_PROC}/rewriter2/active"
   echo "true"         > ${CLICK_PROC}/rewriter2/active
 
   ROUTESTART="`nodedb_getmac ${BRNDST}` `nodedb_getath ${BRNDST}`"
   ROUTEEND="`nodedb_getath ${BRNSRC}` `nodedb_getmac ${BRNSRC}`"
   ROUTEINT=""
   for node in ${NODES}
   do 
     route_host=${node}
     index=`expr index "${node}" "@"`
     if test 0 != ${index}
     then
       route_host=`echo "${node}" | awk -F@ '{print $2}'`
     fi
     ROUTEINT="${ROUTEINT} `nodedb_getath ${route_host}`"
   done
   ROUTE="${ROUTESTART} ${ROUTEINT} ${ROUTEEND}"
   echo "Node2 route = $ROUTE"
   echo ${ROUTE} > ${CLICK_PROC}/dsr/querier/fixed_route
 
 #echo "00:0F:B5:3F:49:EE 00:0F:B5:3F:58:49 00:0F:B5:3F:21:81 00:0F:B5:3F:21:60 00:0F:B5:3F:20:D6 00:0F:B5:3F:21:3C 00:0F:B5:3F:1E:EA 00:0F:B5:3F:1B:BF 00:0F:B5:3F:3E:D8" > ${CLICK_PROC}/dsr/querier/fixed_route
 }
 
 #-----------------------------------------------------------------------
 
 run_node3()
 {
   BRNDSTMAC=`nodedb_getmac ${BRNDST}`
   BRNSRCMAC=`nodedb_getmac ${BRNSRC}`
   TSTDSTMAC=`nodedb_getmac ${TSTDST}`
   TSTSRCMAC=`nodedb_getmac ${TSTSRC}`
 
 # Prepare first rewriter
   debug "Executing echo \"${BRNSRCMAC}\" > ${CLICK_PROC}/rewriter1/ether_dst"
   echo "${BRNSRCMAC}" > ${CLICK_PROC}/rewriter1/ether_dst
   debug "Executing echo \"${BRNDSTMAC}\" > ${CLICK_PROC}/rewriter1/ether_src"
   echo "${BRNDSTMAC}" > ${CLICK_PROC}/rewriter1/ether_src
   debug "Executing echo \"${TSTSRC}\"    > ${CLICK_PROC}/rewriter1/ip_dst"
   echo "${TSTSRC}"    > ${CLICK_PROC}/rewriter1/ip_dst
   debug "Executing echo \"${BRNSRC}\"    > ${CLICK_PROC}/rewriter1/ip_src"
   echo "${BRNSRC}"    > ${CLICK_PROC}/rewriter1/ip_src
   debug "Executing echo \"true\"         > ${CLICK_PROC}/rewriter1/active"
   echo "true"         > ${CLICK_PROC}/rewriter1/active
   
 
   # Set up second rewriter  
   debug "Executing echo \"${TSTDSTMAC}\" > ${CLICK_PROC}/rewriter2/ether_dst"
   echo "${TSTDSTMAC}" > ${CLICK_PROC}/rewriter2/ether_dst
   debug "Executing echo \"${BRNDSTMAC}\" > ${CLICK_PROC}/rewriter2/ether_src"
   echo "${BRNDSTMAC}" > ${CLICK_PROC}/rewriter2/ether_src
   debug "Executing echo \"${TSTDST}\"    > ${CLICK_PROC}/rewriter2/ip_dst"
   echo "${TSTDST}"    > ${CLICK_PROC}/rewriter2/ip_dst
   debug "Executing echo \"${BRNDST}\"    > ${CLICK_PROC}/rewriter2/ip_src"
   echo "${BRNDST}"    > ${CLICK_PROC}/rewriter2/ip_src
   debug "Executing echo \"true\"         > ${CLICK_PROC}/rewriter2/active"
   echo "true"         > ${CLICK_PROC}/rewriter2/active
 
   ROUTESTART="`nodedb_getmac ${BRNSRC}` `nodedb_getath ${BRNSRC}`"
   ROUTEEND="`nodedb_getath ${BRNDST}` `nodedb_getmac ${BRNDST}`"
   ROUTEINT=""
   for node in ${NODES}
   do 
     route_host=${node}
     index=`expr index "${node}" "@"`
     if test 0 != ${index}
     then
       route_host=`echo "${node}" | awk -F@ '{print $2}'`
     fi
     ROUTEINT="${ROUTEINT} `nodedb_getath ${route_host}`"
   done
   ROUTE="${ROUTESTART} ${ROUTEINT} ${ROUTEEND}"
   echo "Node3 route = $ROUTE"
   echo ${ROUTE} > ${CLICK_PROC}/dsr/querier/fixed_route
 
 #echo "00:0F:B5:3F:3E:D8 00:0F:B5:3F:1B:BF 00:0F:B5:3F:1E:EA 00:0F:B5:3F:21:3C 00:0F:B5:3F:20:D6 00:0F:B5:3F:21:60 00:0F:B5:3F:21:81 00:0F:B5:3F:58:49 00:0F:B5:3F:49:EE" > ${CLICK_PROC}/dsr/querier/fixed_route
 }
 
 #-----------------------------------------------------------------------
 
 # Runs the given click script using the click kernel module
 # For the userland version, see former versions of this file.
 run_others()
 {
   if test ! -x ${CLICKPATH}/click-align
   then
     error "Could not find click-align (expected ${CLICKPATH}/click-align)."
   fi 
   if test ! -r ${CLICK_SCRIPT}
   then
     error "Could not find click script (expected ${CLICK_SCRIPT})."
   fi 
     
   # Clear all click
   shutdown_click
 
   # Insert modules
   setup_click
   
   # Execute the click script
   debug "${CLICKPATH}/click-align ${CLICK_SCRIPT} > ${CLICK_PROC}/config"
   ${CLICKPATH}/click-align ${CLICK_SCRIPT} > ${CLICK_PROC}/config
   
   sleep 8
   case "${NODE}" in
     "2")
       run_node2
       ;;
     "3")
       run_node3
       ;;
   esac
 
   sleep ${TEST_ABORT}
   cat ${CLICK_PROC}/errors
   cat ${CLICK_PROC}/messages
   echo "" > ${CLICK_PROC}/config
 
   # Clear all click
   shutdown_click
 }
 
 #-----------------------------------------------------------------------
 
 run_test()
 {
   case "${NODE}" in
     "0")
       run_node0
       ;;
     "1")
       run_node1
       ;;
     *)
       run_others
       ;;
   esac
 }
 
 #-----------------------------------------------------------------------
 # main()
 #-----------------------------------------------------------------------
 
 # Parse parameters
 while [ $# -gt 0 ]; do    # Until you run out of parameters . . .
   case "$1" in
     -a|--brn-src)
       BRNSRC="$2"
       shift
       ;;
     -b|--brn-dst)
       BRNDST="$2"
       shift
       ;;
     -c|--tst-src)
       TSTSRC="$2"
       shift
       ;;
     -d|--tst-dst)
       TSTDST="$2"
       shift
       ;;
     --clickpath)
       CLICKPATH=$2
       shift
       ;;
     --clickscript)
       CLICK_SCRIPT=$2
       shift
       ;;
     --nodedb)
       NODEDB=$2
       shift
       ;;
     --debug)
       DEBUG="--debug"
       ;;
     -h|--help)
       usage
       exit 1
       ;;
     *)
       NODES="$*"
       break
       ;;
   esac
   shift       # Check next set of parameters.
 done
 
 debug "Param BRNSRC=${BRNSRC}"
 debug "Param BRNDST=${BRNDST}"
 debug "Param TSTSRC=${TSTSRC}"
 debug "Param TSTDST=${TSTDST}"
 debug "Param NODEDB=${NODEDB}"
 debug "Param DEBUG=${DEBUG}"
 debug "Param NODES=${NODES}"
 debug "Param CLICKPATH=${CLICKPATH}"
 debug "Param HOST=${HOST}"
 debug "Param NODE=${NODE}"
 debug "Param CLICK_SCRIPT=${CLICK_SCRIPT}"
 debug "Param PWD=`pwd`"
 
 # Check parameters
 if test -z ${BRNSRC}
 then
   error "Parameter brn-src not specified."
 fi
 if test -z ${BRNDST}
 then
   error "Parameter brn-dst not specified."
 fi
 if test -z ${TSTDST}
 then
   error "Parameter tst-src not specified."
 fi
 if test -z ${TSTDST}
 then
   error "Parameter tst-dst not specified."
 fi
 if test ! -r ${NODEDB}
 then
   error "Node-DB not found (--nodedb=...)."
 fi
 
 # Run the test
 run_test
 
 exit 0