X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=slice%2Fnetconfig;h=e2afb0a43787f25335d4a30b82b60b8d962b7967;hb=6c2e192c3237bd46db6ad4230fed71d28f362331;hp=50fe7819c11a18819064e2b044b34f66f885ae00;hpb=1c3dc9f45532c25adc21f297422f0f5a7420b8ca;p=ipfw.git diff --git a/slice/netconfig b/slice/netconfig index 50fe781..e2afb0a 100755 --- a/slice/netconfig +++ b/slice/netconfig @@ -1,124 +1,14 @@ #!/bin/sh # -# Marta Carbone +# Marta Carbone, Luigi Rizzo # Copyright (C) 2009 Universita` di Pisa # $Id$ # -# This script is the frontend to be used with -# the vsys system. -# It allows to configure dummynet pipes and queues. -# In detail it: -# - get user input -# - send command to the vsys input pipe -# - wait a bit -# - get the reply from the output vsys pipe -# - show the output to the user -# -# A simple usage is: -# ./netconfig -p 9898 -# mandatory fields are the port to be configured -# and dummynet configuration parameters +# This script is the frontend to be used with the vsys system. +# It simply passes information to the backend and gets back the reply PIPE_IN=/vsys/ipfw-be.in PIPE_OUT=/vsys/ipfw-be.out -LOGFILE=/tmp/netconfig.log -SED=/bin/sed # used to extract the profile name -DEBUG=0 # 0 disable debug messages -prog=$0 # this program - -# Print the first argument and exit -abort() -{ - echo "$1"; exit 1 -} - -# if $DEBUG is enabled, print a debug message -# $1 the message to print -debug() -{ - [ "${DEBUG}" != "0" ] && echo "$1" >> ${LOGFILE} -} - -# print the usage and exit -help() -{ - cat << EOF -Usage: $prog [-n node_ip][-s slice] [-i key] -d dummynetbox_ip -p port [-U] [-t timeout[STRING]] ipfw_configuration_parameters \n - -h show help \n - -p specify the port to configure \n - -t specify the timeout. STRING can be "1minute" or "4hours" (default 1 hour) \n - - ipfw configuration parameters (mandatory) \n - extra-delay bw delay proto... plr... \n -EOF - exit 0 -} - -# parse input line and fill missing fields -parse_input() -{ - # counters used to check if at least - # two ipfw configuration parameters are present - local OPT_ARGS=2 # optional (timeout) - local MAND_ARGS=2 # mandatory (port) - - [ -z "$1" ] && help; - - while getopts ":hp:t:" opt; do - case $opt in - h | \?) help;; - p) PORT=$OPTARG;; - t) TIMEOUT=$OPTARG;; - esac - done - - # check for mandatory arguments - [ -z ${PORT} ] && abort "a port value is mandatory"; - - # the default value for the timeout is 1H - if [ -z ${TIMEOUT} ]; then - TIMEOUT="1hour" - OPT_ARGS=$((${OPT_ARGS}-2)) - fi - - # compute residue argument, we need at least 2 - # mandatory arguments (for ipfw), exit on error - #debug "Passed args $# Mandatory ${MAND_ARGS} Optional ${OPT_ARGS} Extra $(($#-${MAND_ARGS}-${OPT_ARGS}))" - if [ $(($#-${MAND_ARGS}-${OPT_ARGS})) -lt 2 ]; then - help - fi -} - -# main starts here - - # allow ipfw show and ipfw pipe show - if [ x$1 = x"ipfw" ]; then - echo "received" $1 - echo "ipfw" >> ${PIPE_IN} - cat ${PIPE_OUT} - exit 0; - else if [ x$1 = x"pipe" ]; then - echo "pipe" >> ${PIPE_IN} - cat ${PIPE_OUT} - exit 0; - fi - fi - - # parse the input - parse_input $* - shift $((${OPTIND}-1)); - - # print debug - debug "PORT ${PORT}" - debug "TIMEOUT ${TIMEOUT}" - debug "PIPE_CONFIGURATION $*" - - # format CMD as expected by the backend script - CMD="${PORT} ${TIMEOUT} $*"; - - # send the command - debug "Sending: ${CMD}" - echo ${CMD} >> ${PIPE_IN} - - cat ${PIPE_OUT} +sudo sh -c "echo $* >> ${PIPE_IN}" +sudo sh -c "cat ${PIPE_OUT}"