bradmontgomery.net

A packet grabber for the network simulator ns-2

[07.19.2006] [Keywords: ns-2 agent link node packets]

I've recently been using ns-2 to do some networking research and I ran into a problem where I needed an Agent to process every packet that passed through the node to which it was attached. I posed the following question to the ns-users mailing list, but got no response:

I would like to write an Agent that inspects all packets that 
pass through the node to which it is connected.  For example:

Given the topology,

N0 - N1 - N2 

An Agent attached to N1 would execute it's recv() function 
even if N2 was sending a packet to N0.  Is this possible?
If so, any pointers to examples or descriptions would be
greatly appreciated!
...

During my search for a solution, I was introduced to the RSVP code (described in [1]) that was originally written by Marc Greis, and later modified by Juha Villanen. This code contained an RSVPChecker object that almost did what I wanted, so I modified it to grab EVERY packet on the link and then send it to a specified agent.

Code

Note that in order for this to work, you must modify your Makefile, and recompile ns. If you put the packetGrabber directory in your ns directory (ns-2.29 for me), just edit your make file, and smewhere after OBJ_CC, you can add the following line:

packetGrabber/packetGrabber.o

Then at the top of your simulation, you can source the packetGrabber.tcl file to get the tcl procs, OR, you can copy the contents of packetGrabber.tcl to your ns-default.tcl file (located in ns-2.29/tcl/lib for me.)

packetGrabber.zip (4.9K)
packetGrabber.tar.gz (2.4K)

Resources:

[1] RSVP/ns: An Implementation of RSVP for the Network Simulator; Marc Greis, University of Bonn (google search)
[2] The Network Simulator - ns-2: http://www.isi.edu/nsnam/ns/

Was this helpful? Let me know!