Created
June 20, 2012 12:46
-
-
Save nicolargo/2959732 to your computer and use it in GitHub Desktop.
A WAN simulator script for Linux box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# simulwan-bridge.sh | |
# Nicolargo - 2012 | |
# | |
############################################################################## | |
# Nom des interfaces ou l'on doit faire les simulations | |
# eth0 cote LAN local | |
# eth1 cote LAN distant | |
IF=eth1 | |
# Liaison sortante (UPLOAD) a appliquer sur IF | |
# Debit sortant | |
BWU=4mbit | |
# Délai de transit sortant | |
DELAYU=10ms | |
# % de paquets perdus sortant | |
LOSSU=0.00% | |
# Liaison entrante (DOWNLOAD) a appliquer sur IF | |
# Debit entrant | |
BWD=2mbit | |
# Délai de transit entrant | |
DELAYD=10ms | |
# % de paquets perdus entrant | |
LOSSD=0.00% | |
############################################################################## | |
start() { | |
modprobe ifb | |
ip link set dev ifb0 up | |
tc qdisc add dev $IF ingress | |
tc filter add dev $IF parent ffff: \ | |
protocol ip u32 match u32 0 0 flowid 1:1 \ | |
action mirred egress redirect dev ifb0 | |
# Liaison entrante | |
tc qdisc add dev ifb0 root handle 1:0 \ | |
netem delay $DELAYD 10ms distribution normal \ | |
loss $LOSSD 25% | |
tc qdisc add dev ifb0 parent 1:1 handle 10: \ | |
tbf rate $BWD buffer 3200 limit 6000 | |
# Liaison sortante | |
tc qdisc add dev $IF root handle 2:0 \ | |
netem delay $DELAYU 10ms distribution normal \ | |
loss $LOSSU 25% | |
tc qdisc add dev $IF parent 2:1 handle 10: \ | |
tbf rate $BWU buffer 3200 limit 6000 | |
} | |
stop() { | |
tc qdisc del dev ifb0 root | |
tc qdisc del dev $IF root | |
# ip link set dev ifb0 down | |
} | |
restart() { | |
stop | |
sleep 1 | |
start | |
} | |
show() { | |
echo "Liaison entrante" | |
tc -s qdisc ls dev ifb0 | |
echo "Liaison sortante" | |
tc -s qdisc ls dev $IF | |
} | |
case "$1" in | |
start) | |
echo -n "Starting WAN simul: " | |
start | |
echo "done" | |
;; | |
stop) | |
echo -n "Stopping WAN simul: " | |
stop | |
echo "done" | |
;; | |
restart) | |
echo -n "Restarting WAN simul: " | |
restart | |
echo "done" | |
;; | |
show) | |
echo "WAN simul status for $IF:" | |
show | |
echo "" | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|show}" | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment