[Ns-developers] DelayBox - ns-3

Mathieu Lacage mathieu.lacage at sophia.inria.fr
Sun Apr 13 20:29:36 PDT 2008


On Sun, 2008-04-13 at 23:18 -0400, Matt Crinklaw wrote:
> What is the appropriate way to extract the ip src/dst address from a packet?
> 
> I see two options: enabling the metadata and somehow hooking into that
> (it looks possible, but there isn't much information about the
> metadata system and PacketMetadata/PacketMetadata::ItemIterator
> classes).

Nope, you won't be able to extract the information you want from the
metadata.

> 
> The other option that seems available is to serialize the packet and
> then try to deserialize the header.
> 
> Ipv4Header iph;
> iph.Deserialize(packet->Serialize().Begin());

Packet::Serialize/Deserialize are really not expected to be used in
normal simulations and they really don't do what you think they are
doing. i.e., they should be used only for distributed simulations by the
simulation engine. That might need to be documented though.

I suspect that the simplest way to solve your problem is this though:

// copy packet to avoid modifying the original packet
Ptr<Packet> copy = p->Copy ();
Ipv4Header iph;
copy->RemoveHeader (iph);
// copy will disappear when you are done with it.

regards,
Mathieu



More information about the Ns-developers mailing list