Gabriel Somlo
2007-Mar-30 02:49 UTC
Please Help: applying multiple different delays with netem
I''m trying to use tc and netem to delay packets from several different machines as they exit via eth0. Assume two source IPs, 10.0.0.122 and 10.0.0.133. I''d like to delay packets from the first one by 200ms, and packets from the second one by 300 ms. Any other traffic should be sent out normally. Here''s what I tried: # make three classes, 1:1, 1:2, and 1:3: tc qdisc add dev eth0 root handle 1: prio # attach netem with 200ms delay to priority 2 hook: tc qdisc add dev eth0 parent 1:2 handle 20: netem delay 200ms # attach netem with 300ms delay to priority 3 hook: tc qdisc add dev eth0 parent 1:3 handle 30: netem delay 300ms # classify packets from .122 as priority 2: tc filter add dev eth0 protocol ip parent 1:0 prio 2 u32 \ match ip src 10.0.0.122/32 flowid 10:2 # classify packets from .133 as priority 3: tc filter add dev eth0 protocol ip parent 1:0 prio 3 u32 \ match ip src 10.0.0.133/32 flowid 10:3 This works, except unclassified traffic (e.g., from another machine 10.0.0.111) will ALWAYS be delayed by 200 ms (same as traffic matched to priority 2). How do I make unmatched traffic go through normally ? Do I need to attach a qdisc to priority 1, or is there an assumed default qdisc already there ? Is there something magic about priority 2, and do I need to understand and modify the priomap to fix this? Would this way of doing things generalize for more classes with different delays applied to them ? This is the first time I''ve dealt with this, and I''m somewhat shocked and awed :) Any help is much appreciated ! Thanks, Gabriel
Andy Furniss
2007-Mar-30 22:57 UTC
Re: Please Help: applying multiple different delays with netem
Gabriel Somlo wrote:> I''m trying to use tc and netem to delay packets from several different > machines as they exit via eth0. Assume two source IPs, 10.0.0.122 and > 10.0.0.133. I''d like to delay packets from the first one by 200ms, and > packets from the second one by 300 ms. Any other traffic should be sent > out normally. Here''s what I tried: > > # make three classes, 1:1, 1:2, and 1:3: > tc qdisc add dev eth0 root handle 1: prio > > # attach netem with 200ms delay to priority 2 hook: > tc qdisc add dev eth0 parent 1:2 handle 20: netem delay 200ms > > # attach netem with 300ms delay to priority 3 hook: > tc qdisc add dev eth0 parent 1:3 handle 30: netem delay 300ms > > # classify packets from .122 as priority 2: > tc filter add dev eth0 protocol ip parent 1:0 prio 2 u32 \ > match ip src 10.0.0.122/32 flowid 10:2 > > # classify packets from .133 as priority 3: > tc filter add dev eth0 protocol ip parent 1:0 prio 3 u32 \ > match ip src 10.0.0.133/32 flowid 10:3I never did get why that example used 10:x rather that 1:x but it works either way.> > This works, except unclassified traffic (e.g., from another machine > 10.0.0.111) will ALWAYS be delayed by 200 ms (same as traffic > matched to priority 2).tc filter add dev eth0 protocol ip parent 1:0 prio 4 u32 \ match u32 0 0 flowid 1:1 (or 10:1) should do it - I just tested and it works for me - saw a very few on 1:2 which I suppose were arp (could be wrong) - but it may be better to use protocol all instaed of ip for the filter as we want arp highest prio. I noticed netem over delays the first packet - but then this PC is getting a bit out of date and netem has been changed recently.> > How do I make unmatched traffic go through normally ? Do I need to > attach a qdisc to priority 1, or is there an assumed default qdisc > already there ?Yes pfifo by default you can attach one explicitly to get better counters/estimators (if you set them up) when you tc -s qdisc ls .... Is there something magic about priority 2, and do I> need to understand and modify the priomap to fix this?Looks like most goes to 2 by tos - but the catch all seems to override it. And.