#!/bin/bash # Set the data rate, delay and jitter on all links in a network # # Read the comments in this script or the help for details. # For more info see: http://sandilands.info/sgordon/virtnet # # $Revision$ # $Author$ # $Date$ # $URL$ # Script parameters netlinks="" topology="" clearlinks=0 virtnethostpath="`dirname $BASH_SOURCE`/../../" vmusername="root" idfile="`dirname $BASH_SOURCE`/../../data/defaults/root/.ssh/id_rsa" portbase=2200 function usage { cat << End-of-help Usage: vn-setnetworklinks --file FILE --topology NUM [--clear] Set the data rate, delay and jitter on all links in virtnet OPTIONS -f, --file FILE file specifying link characteristics -t, --topology NUM topology to set links for -c, --clear clear the link characteristics previously set -h, --help show this help EXAMPLES 1. Set links using file links-100.txt for topology 100: vn-setnetworklinks --file links-100.txt --topology 100 2. Clear the links for same topology: vn-setnetworklinks --file links-100.txt --topology 100 --clear FILE FORMAT The network links file is a comma separated text file containing one line for each network in the topology. Each line is of the format network,rate,delay,jitter where: network is the VBoxNetwork field in the interfaces file, e.g. 'neta' rate is the desired link data rate, with units of kbps or mbps delay is the desired link delay, with units of ms or s jitter is the desired link jitter, with units of ms or s Note that link characteristics are set for networks, meaning all links in a network are symmetrical. An example file for a topology with three networks may be: neta,500kbps,10ms,1ms netb,1000kbps,5ms,0ms netc,500kbps,8ms,0ms End-of-help } # Read input parameters while [ "$1" != "" ]; do case $1 in -c | --clear ) clearlinks=1; ;; -t | --topology ) shift; topology=$1; ;; -f | --file ) shift; netlinks=$1; ;; * ) usage exit 1 esac shift done # Topology must be specified if [ -z ${topology} ]; then echo "Error. You must specify a topology." echo "Run 'vn-setnetworklinks --help' for help" exit 1; fi # File must be specified if [ -z ${file} ]; then echo "Error. You must specify the a file giving link characteristics." echo "Run 'vn-setnetworklinks --help' for help" exit 1; fi # For each node in the topology ... for iffile in `ls ${virtnethostpath}data/topologies/interfaces-topology-${topology}-node-*`; do # Find the networks its attached to ... for network in `grep "VBoxNetwork:" ${iffile} | cut -d ":" -f 2 | tr -d '[:blank:]'`; do # Find the interface and desired link characteristics interface=`grep -A 1 "VBoxNetwork: ${network}" ${iffile} | tail -1 | cut -d " " -f 2 | tr -d '[:blank:]'` rate=`grep "${network}" ${netlinks} | cut -d "," -f 2 | sed 's/bps/bit/'` delay=`grep "${network}" ${netlinks} | cut -d "," -f 3` jitter=`grep "${network}" ${netlinks} | cut -d "," -f 4` node=`basename ${iffile} | cut -d "-" -f 5 | cut -d "." -f 1` port=$(( ${portbase} + ${node} )); # Set the link characteristics if [ "${clearlinks}" != "1" ]; then ssh -o "StrictHostKeyChecking no" -l ${vmusername} -i ${idfile} -p ${port} 127.0.0.1 "bash /home/network/virtnet/bin/vn-link --interface ${interface} --set --rate ${rate} --delay ${delay}" else ssh -o "StrictHostKeyChecking no" -l ${vmusername} -i ${idfile} -p ${port} 127.0.0.1 "bash /home/network/virtnet/bin/vn-link --interface ${interface} --clear" fi done done