4 # Copyright (C) 2009 Universita` di Pisa
7 # This script is the frontend to be used with
9 # It allows to configure dummynet pipes and queues.
12 # - send command to the vsys input pipe
14 # - get the reply from the output vsys pipe
15 # - show the output to the user
18 # ./netconfig -p 9898 <dummynet configuration parameters>
19 # mandatory fields are the port to be configured
20 # and dummynet configuration parameters
22 PIPE_IN=/vsys/ipfw-be.in
23 PIPE_OUT=/vsys/ipfw-be.out
24 LOGFILE=/tmp/netconfig.log
26 SED=/bin/sed # used to extract the profile name
27 DEBUG=0 # 0 disable debug messages
28 prog=$0 # this program
30 # Print the first argument and exit
36 # if $DEBUG is enabled, print a debug message
37 # $1 the message to print
40 [ "${DEBUG}" != "0" ] && echo "$1" >> ${LOGFILE}
43 # print the usage and exit
47 Usage: $prog -p port [-U] [-t timeout[STRING]] ipfw_configuration_parameters \n
49 -p specify the port to configure \n
50 -t specify the timeout. STRING can be "1minute" or "4hours" (default 1 hour) \n
52 ipfw configuration parameters (mandatory) \n
53 extra-delay <filename> bw <value> delay <value> proto... plr... \n
58 # parse input line and fill missing fields
61 # counters used to check if at least
62 # two ipfw configuration parameters are present
63 local OPT_ARGS=2 # optional (timeout)
64 local MAND_ARGS=2 # mandatory (port)
68 while getopts ":hp:t:" opt; do
76 # check for mandatory arguments
77 [ -z ${PORT} ] && abort "a port value is mandatory";
79 # the default value for the timeout is 1H
80 if [ -z ${TIMEOUT} ]; then
82 OPT_ARGS=$((${OPT_ARGS}-2))
85 # compute residue argument, we need at least 2
86 # mandatory arguments (for ipfw), exit on error
87 #debug "Passed args $# Mandatory ${MAND_ARGS} Optional ${OPT_ARGS} Extra $(($#-${MAND_ARGS}-${OPT_ARGS}))"
88 if [ $(($#-${MAND_ARGS}-${OPT_ARGS})) -lt 2 ]; then
95 # allow ipfw show and ipfw pipe show
96 if [ x$1 = x"ipfw" ]; then
98 echo "ipfw" >> ${PIPE_IN}
101 else if [ x$1 = x"pipe" ]; then
102 echo "pipe" >> ${PIPE_IN}
110 shift $((${OPTIND}-1));
114 debug "TIMEOUT ${TIMEOUT}"
115 debug "PIPE_CONFIGURATION $*"
117 # format CMD as expected by the backend script
118 CMD="${PORT} ${TIMEOUT} $*";
121 debug "Sending: ${CMD}"
122 echo ${CMD} >> ${PIPE_IN}