How to find a specific header in packet in NS-3

In: Network|NS-3|Simulation|Software

27 Aug 2010

You can scan through headers like this:

PacketMetadata::ItemIterator metadataIterator = copy->BeginItem();
PacketMetadata::Item item;
while (metadataIterator.HasNext())
{
item = metadataIterator.Next();
NS_LOG_FUNCTION("item name: " << item.tid.GetName());
if(item.tid.GetName() == "ns3::Ipv4Header")
{
NS_LOG_DEBUG("Header Found");
m_isIpv4HeaderFound = true;
break;
}
}

In above code I tried to find  Ipv4Header

And it is possible to access it like:


if (m_isIpv4HeaderFound)
{
NS_LOG_DEBUG("Header Found");
Callback constructor = item.tid.GetConstructor();

NS_ASSERT(!constructor.IsNull());
ObjectBase *instance = constructor();
NS_ASSERT(instance != 0);
Ipv4Header *ipv4Header = dynamic_cast (instance);
NS_ASSERT(ipv4Header != 0);
ipv4Header->Deserialize(item.current);
delete ipv4Header;
}

Share

1 Response to How to find a specific header in packet in NS-3

Avatar

Linus

November 25th, 2015 at 10:11 am

It says ‘constructor’ was not declared in this scope. What #includes is necessary for this code?

Comment Form

About this blog

In addition to a daily blog I will try to add our works in wireless network and data communication projects for our courses here

Photostream

    Autumn yellow leavesAutumn yellow leavesAutumn yellow leavesAutumn yellow leavesAutumn yellow leaves and stairsAutumn yellow leaves
  • Linus: It says 'constructor' was not declared in this scope. What #includes is necessary for this code? [...]
  • padmanabham: how can create end node ie (RFD) in topology. please help me...... thank you................. [...]
  • padmanabham: i am doing M.tech project on lowrate WPAN (Zigbee) using star,cluster tree and mesh topology i can [...]
  • Layla Wilson: At the least it's more educational than one of our reality TV stars, kim who? Joey what? [...]
  • san ramon website design: Right here is the perfect web site for anybody who wants to find out about this topic. You realize [...]