0

Let say that we have host A, and host B. We would like to use netem to simulate following scenario: B sends packets to A with some delay.
How to do it with netem in two scenarios:
(1) Running netem on host A
(2) Running netem on host 'B.

Any ideas ?

1

There are several good sources for how to introduce delay on incoming and outgoing packets. This NetEm wiki page as a lot of information. See section "1.1 Emulating wide area network delays" for delaying outgoing packets and "2.3 How can I use netem on incoming traffic?" for incoming packets. I tried these on my setup and had no trouble making it work.

Base latency:

# netperf -H $my_ip -t TCP_RR -P 0 -- -r 64 -o RT_LATENCY
21.800

100ms delay only on client side (B):

# tc qdisc add dev $my_interface root netem delay 100ms

Result:

# netperf -H $my_ip -t TCP_RR -P 0 -- -r 64 -o RT_LATENCY
102184.355

100ms delay only on client side (A):

First, create an Intermediate Functional Block pseudo-device IFB (ethernet bridge would also work):

# modprobe ifb
# ip link set dev ifb0 up

Next, redirect all incoming traffic to go through the IFB device first:

# tc qdisc add dev $my_interface ingress
# tc filter add dev $my_interface parent ffff: protocol ip u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb0

Now just add delay to the IFB device's outgoing traffic, which is now the incoming traffic to my_interface:

# tc qdisc add dev ifb0 root netem delay 100ms

Result:

# netperf -H $my_ip -t TCP_RR -P 0 -- -r 64 -o RT_LATENCY
154442.238

Applying both results in:

# netperf -H $my_ip -t TCP_RR -P 0 -- -r 64 -o RT_LATENCY
333803.282

As you can see, the latency is more than the added 100ms (or 200ms in last example) + base latency. NetEm causes a delay in a specific place in the pipe, so the longer than expected latency might be a side effect if the delay.

  • Some extra latency can be produced by the additional initial ARP request done which gets also the same delay. With a ping, the first ping answer would take twice the time it takes for the second answer. – A.B Jan 26 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.