shaper tc class ifb
Правила:
set traffic-policy shaper DOWNLOAD default bandwidth 100%
set traffic-policy shaper DOWNLOAD bandwidth 1000mbit
set traffic-policy shaper DOWNLOAD class 1002 bandwidth 10mbit
set traffic-policy shaper DOWNLOAD class 1002 match ADDR ip destination address 192.168.1.2/32
set traffic-policy shaper DOWNLOAD class 1003 bandwidth 10mbit
set traffic-policy shaper DOWNLOAD class 1003 match ADDR ip destination address 192.168.1.3/32
set traffic-policy shaper UPLOAD default bandwidth 100%
set traffic-policy shaper UPLOAD bandwidth 1000mbit
set traffic-policy shaper UPLOAD class 2002 bandwidth 10mbit
set traffic-policy shaper UPLOAD class 2002 match ADDR ip source address 192.168.1.2/32
set traffic-policy shaper UPLOAD class 2003 bandwidth 10mbit
set traffic-policy shaper UPLOAD class 2003 match ADDR ip source address 192.168.1.3/32
set interfaces input ifb0 traffic-policy out UPLOAD
set interfaces ethernet eth0 redirect ifb0
set interfaces ethernet eth0 traffic-policy out DOWNLOAD |
set traffic-policy shaper DOWNLOAD default bandwidth 100%
set traffic-policy shaper DOWNLOAD bandwidth 1000mbit
set traffic-policy shaper DOWNLOAD class 1002 bandwidth 10mbit
set traffic-policy shaper DOWNLOAD class 1002 match ADDR ip destination address 192.168.1.2/32
set traffic-policy shaper DOWNLOAD class 1003 bandwidth 10mbit
set traffic-policy shaper DOWNLOAD class 1003 match ADDR ip destination address 192.168.1.3/32
set traffic-policy shaper UPLOAD default bandwidth 100%
set traffic-policy shaper UPLOAD bandwidth 1000mbit
set traffic-policy shaper UPLOAD class 2002 bandwidth 10mbit
set traffic-policy shaper UPLOAD class 2002 match ADDR ip source address 192.168.1.2/32
set traffic-policy shaper UPLOAD class 2003 bandwidth 10mbit
set traffic-policy shaper UPLOAD class 2003 match ADDR ip source address 192.168.1.3/32
set interfaces input ifb0 traffic-policy out UPLOAD
set interfaces ethernet eth0 redirect ifb0
set interfaces ethernet eth0 traffic-policy out DOWNLOAD
Скрипт на bash генериращ правила:
#!/bin/bash
#
# traffic-policy generator
# variables
download=10mbit
upload=10mbit
start=2
end=10
a=192
b=168
c=0
# Code
while [ $start -le $end ]
do
bytes=`echo $start | wc | awk '{print $3}'`
case $bytes in
2)
s1=`echo "00$start"`
;;
3)
s1=`echo "0$start"`
;;
4)
s1=$start
;;
esac
echo "set traffic-policy shaper DOWNLOAD class 1$s1 bandwidth $download"
echo "set traffic-policy shaper DOWNLOAD class 1$s1 match ADDR ip destination address $a.$b.$c.$start/32"
echo "set traffic-policy shaper UPLOAD class 2$s1 bandwidth $upload"
echo "set traffic-policy shaper UPLOAD class 2$s1 match ADDR ip source address $a.$b.$c.$start/32"
start=`expr $start + 1`;
done |
#!/bin/bash
#
# traffic-policy generator
# variables
download=10mbit
upload=10mbit
start=2
end=10
a=192
b=168
c=0
# Code
while [ $start -le $end ]
do
bytes=`echo $start | wc | awk '{print $3}'`
case $bytes in
2)
s1=`echo "00$start"`
;;
3)
s1=`echo "0$start"`
;;
4)
s1=$start
;;
esac
echo "set traffic-policy shaper DOWNLOAD class 1$s1 bandwidth $download"
echo "set traffic-policy shaper DOWNLOAD class 1$s1 match ADDR ip destination address $a.$b.$c.$start/32"
echo "set traffic-policy shaper UPLOAD class 2$s1 bandwidth $upload"
echo "set traffic-policy shaper UPLOAD class 2$s1 match ADDR ip source address $a.$b.$c.$start/32"
start=`expr $start + 1`;
done
firewall mark group address
### DOWNLOAD ###################################################
set firewall modify DOWNLOAD rule 1010 destination address 192.168.10.10-192.168.10.20
set firewall modify DOWNLOAD rule 1010 modify mark 1010
set interfaces ethernet eth0 firewall out modify DOWNLOAD
set traffic-policy shaper DOWNLOAD bandwidth 1000mbit
set traffic-policy shaper DOWNLOAD default bandwidth 100%
set traffic-policy shaper DOWNLOAD class 1010 bandwidth 10mbit
set traffic-policy shaper DOWNLOAD class 1010 match ADDR mark 1010
set interfaces ethernet eth0 traffic-policy out DOWNLOAD
### UPLOAD ##########################################################
set firewall modify UPLOAD rule 2010 source address 192.168.10.10-192.168.10.20
set firewall modify UPLOAD rule 2010 modify mark 2010
set interfaces ethernet eth2 vif 72 firewall out modify UPLOAD
set traffic-policy shaper UPLOAD bandwidth 1000mbit
set traffic-policy shaper UPLOAD default bandwidth 100%
set traffic-policy shaper UPLOAD class 2010 bandwidth 10mbit
set traffic-policy shaper UPLOAD class 2010 match ADDR mark 2010
set interfaces ethernet eth2 vif 72 traffic-policy out UPLOAD |
### DOWNLOAD ###################################################
set firewall modify DOWNLOAD rule 1010 destination address 192.168.10.10-192.168.10.20
set firewall modify DOWNLOAD rule 1010 modify mark 1010
set interfaces ethernet eth0 firewall out modify DOWNLOAD
set traffic-policy shaper DOWNLOAD bandwidth 1000mbit
set traffic-policy shaper DOWNLOAD default bandwidth 100%
set traffic-policy shaper DOWNLOAD class 1010 bandwidth 10mbit
set traffic-policy shaper DOWNLOAD class 1010 match ADDR mark 1010
set interfaces ethernet eth0 traffic-policy out DOWNLOAD
### UPLOAD ##########################################################
set firewall modify UPLOAD rule 2010 source address 192.168.10.10-192.168.10.20
set firewall modify UPLOAD rule 2010 modify mark 2010
set interfaces ethernet eth2 vif 72 firewall out modify UPLOAD
set traffic-policy shaper UPLOAD bandwidth 1000mbit
set traffic-policy shaper UPLOAD default bandwidth 100%
set traffic-policy shaper UPLOAD class 2010 bandwidth 10mbit
set traffic-policy shaper UPLOAD class 2010 match ADDR mark 2010
set interfaces ethernet eth2 vif 72 traffic-policy out UPLOAD
ubnt@R2# run show firewall modify statistics
--------------------------------------------------------------------------------
IPv4 Firewall "DOWNLOAD"
Active on (eth0,OUT)
rule packets bytes action description
---- ------- ----- ------ -----------
1010 270744 327393876 MODIFY
10000 301806 329885420 ACCEPT DEFAULT ACTION
--------------------------------------------------------------------------------
IPv4 Firewall "UPLOAD"
Active on (eth2.72,OUT)
rule packets bytes action description
---- ------- ----- ------ -----------
2010 219314 90710203 MODIFY
10000 4384969 429027687 ACCEPT DEFAULT ACTION |
ubnt@R2# run show firewall modify statistics
--------------------------------------------------------------------------------
IPv4 Firewall "DOWNLOAD"
Active on (eth0,OUT)
rule packets bytes action description
---- ------- ----- ------ -----------
1010 270744 327393876 MODIFY
10000 301806 329885420 ACCEPT DEFAULT ACTION
--------------------------------------------------------------------------------
IPv4 Firewall "UPLOAD"
Active on (eth2.72,OUT)
rule packets bytes action description
---- ------- ----- ------ -----------
2010 219314 90710203 MODIFY
10000 4384969 429027687 ACCEPT DEFAULT ACTION
ubnt@R2# run show queueing ethernet eth0
eth0 Queueing:
Class Policy Sent Rate Dropped Overlimit Backlog
root shaper 330419077 855 342508 0
1010 fair-queue 329603071 20368 855 0 0
default fair-queue 2022954 1112 0 0 0
[edit]
ubnt@R2# run show queueing ethernet eth2 vif 72
eth2.72 Queueing:
Class Policy Sent Rate Dropped Overlimit Backlog
root shaper 484559223 68 123152 0
2010 fair-queue 93593247 1440 68 0 0
default fair-queue 391019154 246864 0 0 0
[edit] |
ubnt@R2# run show queueing ethernet eth0
eth0 Queueing:
Class Policy Sent Rate Dropped Overlimit Backlog
root shaper 330419077 855 342508 0
1010 fair-queue 329603071 20368 855 0 0
default fair-queue 2022954 1112 0 0 0
[edit]
ubnt@R2# run show queueing ethernet eth2 vif 72
eth2.72 Queueing:
Class Policy Sent Rate Dropped Overlimit Backlog
root shaper 484559223 68 123152 0
2010 fair-queue 93593247 1440 68 0 0
default fair-queue 391019154 246864 0 0 0
[edit]