Skip to content
Yancey Wang edited this page Oct 4, 2022 · 3 revisions

Simulated a 20mbps link with 300ms queue, no additional latency

DEV=ens5
IFB=ifb0
# turn driver optimizations off
sudo ethtool -K $DEV gro off
sudo ethtool -K $DEV tso off
sudo ethtool -K $DEV gso off

sudo modprobe ifb
sudo ifconfig ifb0 up

sudo ethtool -K $IFB gro off
sudo ethtool -K $IFB tso off
sudo ethtool -K $IFB gso off

sudo tc qdisc del dev $IFB root
sudo tc qdisc add dev $IFB root handle 10: tbf rate 20mbit buffer 4800 latency 300ms

sudo tc qdisc del dev $DEV root
# prio is used so that port 22 is unaffected
sudo tc qdisc add dev $DEV root handle 1: prio
# netem for simulate loss and delay
sudo tc qdisc add dev $DEV parent 1:2 handle 10: netem delay 0ms # you can simulate additional  latency by changing this
# use pfifo to replace inner queue of netem to prevent reordering
sudo tc qdisc add dev $DEV parent 10:1 pfifo limit 9999

# let ssh traffic get highest priority and not affected by netem
sudo tc filter add dev $DEV protocol ip parent 1: prio 1 u32 match ip sport 22 0xffff flowid 1:1
# let every other traffic going to ifb first
sudo tc filter add dev $DEV protocol ip parent 1: prio 2 u32 match ip dst 0.0.0.0/0 flowid 1:2 \
        action mirred egress redirect dev $IFB

A link with capacity varying between 10 15 20, with a gap of 20s

DEV=ens5
IFB=ifb0
# turn driver optimizations off
sudo ethtool -K $DEV gro off
sudo ethtool -K $DEV tso off
sudo ethtool -K $DEV gso off

sudo modprobe ifb
sudo ifconfig ifb0 up

sudo ethtool -K $IFB gro off
sudo ethtool -K $IFB tso off
sudo ethtool -K $IFB gso off

sudo tc qdisc del dev $IFB root
sudo tc qdisc add dev $IFB root handle 10: tbf rate 20mbit buffer 3000 latency 300ms

sudo tc qdisc del dev $DEV root
# prio is used so that port 22 is unaffected
sudo tc qdisc add dev $DEV root handle 1: prio
# netem for simulate loss and delay
sudo tc qdisc add dev $DEV parent 1:2 handle 10: netem delay 0ms #slot 80ms
# use pfifo to replace inner queue of netem to prevent reordering
sudo tc qdisc add dev $DEV parent 10:1 pfifo limit 9999

# let ssh traffic get highest priority and not affected by netem
sudo tc filter add dev $DEV protocol ip parent 1: prio 1 u32 match ip sport 22 0xffff flowid 1:1
# let every other traffic going to ifb first
sudo tc filter add dev $DEV protocol ip parent 1: prio 2 u32 match ip dst 0.0.0.0/0 flowid 1:2 \
        action mirred egress redirect dev $IFB

echo "======done======"
echo "---disc---"
sudo tc -s qdisc ls dev $DEV
echo "---class---"
sudo tc -s class ls dev $DEV
echo "---filter---"
sudo tc -s filter ls dev $DEV

GAP=20
while true
do
        echo "one round"
        for i in  {10,15,20,15}
        do
                echo $i
                #echo sudo tc qdisc replace dev $IFB root handle 10: tbf rate ${i}mbit buffer 3000 latency 300ms
                sudo tc qdisc replace dev $IFB root handle 10: tbf rate ${i}mbit buffer 3000 latency 300ms
                sleep $GAP
        done
done

A link with 20mps decrease to 10mpbs then increase back to 20mbps gradually

it decreases 500kbps for every 0.5 second.

DEV=ens5
IFB=ifb0
# turn driver optimizations off
sudo ethtool -K $DEV gro off
sudo ethtool -K $DEV tso off
sudo ethtool -K $DEV gso off

sudo modprobe ifb
sudo ifconfig ifb0 up

sudo ethtool -K $IFB gro off
sudo ethtool -K $IFB tso off
sudo ethtool -K $IFB gso off

sudo tc qdisc del dev $IFB root
sudo tc qdisc add dev $IFB root handle 10: tbf rate 20mbit buffer 3000 latency 300ms

sudo tc qdisc del dev $DEV root
# prio is used so that port 22 is unaffected
sudo tc qdisc add dev $DEV root handle 1: prio
# netem for simulate loss and delay
sudo tc qdisc add dev $DEV parent 1:2 handle 10: netem delay 0ms #slot 80ms
# use pfifo to replace inner queue of netem to prevent reordering
sudo tc qdisc add dev $DEV parent 10:1 pfifo limit 9999

# let ssh traffic get highest priority and not affected by netem
sudo tc filter add dev $DEV protocol ip parent 1: prio 1 u32 match ip sport 22 0xffff flowid 1:1
# let every other traffic going to ifb first
sudo tc filter add dev $DEV protocol ip parent 1: prio 2 u32 match ip dst 0.0.0.0/0 flowid 1:2 \
        action mirred egress redirect dev $IFB

echo "======done======"
echo "---disc---"
sudo tc -s qdisc ls dev $DEV
echo "---class---"
sudo tc -s class ls dev $DEV
echo "---filter---"
sudo tc -s filter ls dev $DEV

GAP=0.5
while true
do
        echo "one round"
        for ((i=20000;i>10000;i-=500))
        do
                echo $i
                #sudo tc qdisc replace dev $IFB root handle 10: tbf rate ${i}kbit buffer 3000 latency 300ms
                sudo tc qdisc replace dev $IFB root handle 10: tbf rate ${i}kbit buffer 3000 latency 300ms
                sleep $GAP
        done
        for ((i=10000;i<20000;i+=500))
        do
                echo $i
                sudo tc qdisc replace dev $IFB root handle 10: tbf rate ${i}kbit buffer 3000 latency 300ms
                sleep $GAP
        done

done