Chris Adams
Chris Adams

Reputation: 1018

tc: attaching many netems to an interface

I'm looking to simulate delays for a set of services that run on different ports on a host. I would like to simulate different delays to different services, potentially many on a given host hopefully without any limits.

The only way I've found to do this is with a prio qdisc. Here's an example:

IF=eth0
tc qdisc add dev $IF root handle 1: prio bands 16 priomap 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

# this loop is only a sample to make the example runnable; values will vary in practice
for handle in {2..16}; do
 # add a delay for the service on port 20000 + $handle
 tc qdisc add dev $IF handle $handle: parent 1:$handle netem delay 1000ms # example; this will vary in practice
 # add a filter to send the traffic to the correct netem
 tc filter add dev $IF pref $handle protocol ip u32 match ip sport $(( 20000 + $handle )) 0xffff flowid 1:$handle
done

If you run the command above, you'll notice that handles 11-16 don't get created and fail with an error.

NB. Here's an undo for the above.

IF=eth0
for handle in {2..16}; do
 tc filter del dev $IF pref $handle
 tc qdisc del dev $IF handle $handle: parent 1:$handle netem delay 1000ms
done
tc qdisc del dev $IF root

Is there a way to add more than 10 netems to an interface?

Upvotes: 1

Views: 1445

Answers (1)

Chris Adams
Chris Adams

Reputation: 1018

Solved it using htb and classes:

IF=eth0
tc qdisc add dev $IF root handle 1: htb
tc class add dev $IF parent 1: classid 1:1 htb rate 1000Mbps

for handle in {2..32}; do
 tc class add dev $IF parent 1:1 classid 1:$handle htb rate 1000Mbps
 tc qdisc add dev $IF handle $handle: parent 1:$handle netem delay 1000ms
 tc filter add dev $IF pref $handle protocol ip u32 match ip sport $(( 20000 + $handle )) 0xffff flowid 1:$handle
done

Upvotes: 2

Related Questions