[tcng] sysVinit script

Linux Advanced Routing and Traffic Control

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi below is sysvinit script for handling tcng-script .... please excuse my bad bash skils, correct me where i'm doing stupid things :")

what is left... many things, if i have time i will implement them too :

- start [devices] - and then correct handling of service lock files i.e. per device lock file
- stats blah ... - all ideas are welcome !!
- test  or some such, i mean the ability to use temprary config file and restore back original if something
goes wrong.. ideas?  Or something like last-good-known config/s

And u normaly start this on sysv system like this :

service tcng [command] [subcommands|devices]

Don't forget to set correct paths to "tc, tcc and tcng-config"....

PS. probably the script can be easly tweaked to work also as pure TC -service !! 

#===============sample output==================================
[root@qos tcng]# ./tcng 
*** Usage: 
	    tcng {start|stop|status|restart} [devices]
	    tcng show [all|qdisc|class|filter] [devices]


[root@qos tcng]# ./tcng stop
Stopping some/all tcng services: 
No traffic control running on : eth0
Flushing : eth1
No traffic control running on : hdlc0
No traffic control running on : hdlc1
No traffic control running on : pvc0
No traffic control running on : pvc1
[root@qos tcng]# ./tcng start
Starting tcng services: 
Execute :  qdisc add dev eth1 handle 1:0 root dsmark indices 4 default_index 0:
Execute :  qdisc add dev eth1 handle 2:0 parent 1:0 htb:
Execute :  class add dev eth1 parent 2:0 classid 2:1 htb rate 56000bps:
Execute :  class add dev eth1 parent 2:1 classid 2:2 htb rate 125bps ceil 2400bps:
..................................
[root@qos tcng]# ./tcng status 
traffic control on eth0: [OFF]
traffic control on eth1 : [ON]
traffic control on hdlc0: [OFF]
traffic control on hdlc1: [OFF]
traffic control on pvc0: [OFF]
traffic control on pvc1: [OFF]
[root@qos tcng]# ./tcng status eth1
traffic control on eth1 : [ON]
[root@qos tcng]# ./tcng show class eth1

class htb 2:1 root rate 56000bps ceil 56000bps burst 2159b cburst 2159b 
class htb 2:2 parent 2:1 prio 0 rate 125bps ceil 2400bps burst 1600b cburst 1623b 
class htb 2:3 parent 2:1 leaf 3: prio 0 rate 125bps ceil 4200bps burst 1600b cburst 1641b 

[root@qos tcng]# ./tcng show           
qdisc sfq 3: limit 128p quantum 1514b 
qdisc htb 2: r2q 10 default 0 direct_packets_stat 0
qdisc dsmark 1: indices 0x0004 default_index 0x0000 
class htb 2:1 root rate 56000bps ceil 56000bps burst 2159b cburst 2159b 
.......................
[root@qos tcng]# 

#==================THE SCRIPT====================
#!/bin/sh
#
# tcng:       Starts the tcng Server
#
# Version:      @(#) /etc/rc.d/init.d/tcng 0.1
#
# chkconfig: 2345 90 10
# description: Starts and stops the tcng at boot time and shutdown.
#
# processname: tcng
#
# created : from Raptor
#

#path to the tc command
tc=/sbin/tc
#path to the tcc command
tcc=/arh/bin/com.pl
#where is the tcng config file
tcngConf=/etc/sysconfig/tcng

offMsg=OFF
onMsg=ON
debug=1

# Source function library.
. /etc/rc.d/init.d/functions

isUp () {
    res=`$tc qdisc show dev $1`
    if [ -z "$res" ]; then return 1; fi
    return 0
}

start () {
    gprintf "Starting tcng services: "; echo
    OLDIFS="$IFS"
    IFS="
"
    cmds=`$tcc $tcngConf | grep -v "^#" | sed -e "s/^tc//"`
    for cmd in $cmds; do
        [ $debug -eq 1 ] && gprintf "Execute : $cmd:" && echo; 
        eval "$tc $cmd"
    done
    touch /var/lock/subsys/tcng
    IFS="$OLDIFS"
}


stop () {
    gprintf "Stopping some/all tcng services: "
    echo
    #if explictly specified shut only these devices
    if [ "$1" ]; then devs=$*; fi
#	echo $devs
    for d in $devs; do
        if isUp $d ; then 
    	    gprintf "Flushing : $d"; echo
    	    $tc qdisc del dev $d root
	else gprintf "No traffic control running on : $d"; echo
        fi
#    	    rm -f /var/lock/subsys/tcng-$d	    
    done	
    rm -f /var/lock/subsys/tcng;#this is not the correct behavior 	
}


status () {
    if [ "$1" ]; then devs=$*; fi	
#    echo $devs
    for d in $devs; do
        if isUp $d ; 
    	    then gprintf "traffic control on $d : [$onMsg]"; echo;
	    else gprintf "traffic control on $d: [$offMsg]"; echo;
	fi
    done		
}

show () {
    if [ -z "$1" ]; then what=all; else what=$1; fi
    shift
    if [ "$1" ]; then devs=$*; fi	
    for d in $devs; do
	if isUp $d; then
    	    [ "$what" = "all" ] || [ "$what" = "qdisc" ] && gprintf "`$tc qdisc show dev $d`"; echo    
    	    [ "$what" = "all" ] || [ "$what" = "class" ] && gprintf "`$tc class show dev $d`"; echo    	
    	    [ "$what" = "all" ] || [ "$what" = "filter" ] && gprintf "`$tc filter show dev $d`"; echo    	
	fi
    done
}


devs=`ifconfig -a | grep '^\w' | grep -v lo | cut -f 1 -d ' '`
command=$1
shift;

case "$command" in
  start) start ;;
  stop)	stop $@ ;;
  status) status $@ ;;
  show) show $@ ;;	
  restart)
	gprintf "Restarting tcng. "; echo
	stop $@
	start $@
	;;
  *)
	gprintf "*** Usage: 
	    tcng {start|stop|status|restart} [devices]
	    tcng show [all|qdisc|class|filter] [devices]
	"; echo
	exit 1
esac

exit 0
_______________________________________________
LARTC mailing list / LARTC@mailman.ds9a.nl
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/

[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux