Repository navigation
Expand file tree
/
Copy pathtc-con
More file actions
executable file
·145 lines (109 loc) · 2.67 KB
/
Copy pathtc-con
File metadata and controls
executable file
·145 lines (109 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh
#
# Script to reduce bandwidth rate and create network delay and packet loss on linux interfaces
# Can be placed on one interface (one server) or both interfaces (both servers).
#
# Simply run ./tc-con start to start it
# and ./tc-con stop to stop it.
# Run ./tc-con status to see if it's running.
#
# tc uses the following units when passed as a parameter.
# kbps: Kilobytes per second
# mbps: Megabytes per second
# kbit: Kilobits per second
# mbit: Megabits per second
# bps: Bytes per second
# Amounts of data can be specified in:
# kb or k: Kilobytes
# mb or m: Megabytes
# mbit: Megabits
# kbit: Kilobits
#
# Originally from iplocation.net/traffic-control
# Further information at http://www.linuxfoundation.org/collaborate/workgroups/networking/netem
# Updated by Jon Drews (jondrews.com)
# Name of the traffic control command.
TC=/sbin/tc
# The network interface we're planning on limiting bandwidth.
#IF=eth0
IF=enp9s0
# Rate (both ways)
RATE=21kbit
#RATE=14kbit
#RATE=7kbit
# Delay amount
#DELAY=10ms
#DELAY=100ms
DELAY=400ms
# Amount of delay variance (+/-)
#DELAY_VARIANCE=2ms
#DELAY_VARIANCE=20ms
DELAY_VARIANCE=80ms
# Packet loss amount
PACKET_LOSS=0%
#PACKET_LOSS=15%
#PACKET_LOSS=25%
# Packet loss variance
#PACKET_LOSS_VARIANCE=5%
#PACKET_LOSS_VARIANCE=0%
# Enable packet loss
PACKET_LOSS_ENABLED=TRUE
#PACKET_LOSS_ENABLED=FALSE
start() {
# Apply rate limits
$TC qdisc add dev $IF root handle 1: tbf rate $RATE buffer 1600 limit 3000
if [[ $PACKET_LOSS_ENABLED != TRUE ]]
then
# Apply delay with variance, and packet loss
$TC qdisc add dev $IF parent 1:1 handle 10: netem delay $DELAY $DELAY_VARIANCE distribution normal
else
# Apply delay with variance, and packet loss with variance
$TC qdisc add dev $IF parent 1:1 handle 10: netem delay $DELAY $DELAY_VARIANCE distribution normal loss $PACKET_LOSS #$PACKET_LOSS_VARIANCE
fi
}
stop() {
# Stop the bandwidth shaping.
$TC qdisc del dev $IF root
}
restart() {
# Self-explanatory.
stop
sleep 1
start
}
show() {
# Display status of traffic control status.
$TC -s qdisc ls dev $IF
}
case "$1" in
start)
echo -n "Starting bandwidth shaping: "
start
echo "done"
;;
stop)
echo -n "Stopping bandwidth shaping: "
stop
echo "done"
;;
restart)
echo -n "Restarting bandwidth shaping: "
restart
echo "done"
;;
show)
echo "Bandwidth shaping status for $IF:"
show
echo ""
;;
status)
echo "Bandwidth shaping status for $IF:"
show
echo ""
;;
*)
pwd=$(pwd)
echo "Usage: tc.bash {start|stop|restart|show|status}"
;;
esac
exit 0