Blocking N consecutive packets with netgraph

Hartmut Brandt hartmut.brandt at dlr.de
Thu May 25 05:59:44 PDT 2006


benjamin at cactus.org wrote:

>I need to test a multicast streaming media application by selectively
>dropping packets in the network connecting the source to the viewer.
>
>The capability I need is to drop N consecutive packets, where N ranges
>from 1 to 50 and is chosen via the command line.
>
>I had hoped to do this with dummynet and ipfw, but apparently I can
>only drop packets with a specified probablity.  The network topology
>for this method was to bridge two ethernet nics, then use dummynet pipes
>to vary the bandwith and packet loss rate.
>
>I also tested a method using ipfw to temporarily enable packet block
>rules using a short sleep interval, but there was only very coarse
>control of the number of packets blocked.
>
>Is it feasible to do this with netgraph?  Please outline how this may
>be accomplihsed.
>  
>

Yes. Netgraph is really great for this kind of stuff. Four years ago I 
wrote a node that simulated a space ATM link. The entire
thing controlled remotely via SNMP. Variable delay, various kinds of 
loss and so on. I got around 50MBit/sec throughput on
a 2 CPU 1GHz machine, but the limiting factor was not the CPUs but the 
ATM cards. This year I did the same but for ethernet
frames (to simulate a DVB-S2/RCS system). With two gigabit ethernet  
adaptors I get more than 100MBit/sec through the machine
with a load in the order of 30%. It can probably do more, just didn't 
try it.

Because you can load/unload the nodes without rebooting it is just great 
for development - just be a little careful not to crash the kernel.

Your case should be easy: create a node with two hooks, connect them to 
the 'lower' hooks of the two ethernet nodes. Then in the receive
function you just count the packets and drop as much as you need. What 
you don't drop you just send out the other hook. Control is via
netgraph control messages. You just can enter them via ngctl.

harti



More information about the freebsd-net mailing list