Issue: Get Hop limit from a received packet

57 views
Skip to first unread message

Shashidhar B.L

unread,
Jun 11, 2015, 4:31:48 AM6/11/15
to ns-3-...@googlegroups.com
Hi,
I want to obtain the Ipaddress and HopLimit count attached in IpHeader. I was able to do the 1st part successfully, but unable to get the hoplimit count. 

void ReceivePacket (Ptr<Socket> socket)
{
Address from;
Ptr<Packet> packet = socket->RecvFrom (from);
packet->RemoveAllPacketTags ();
packet->RemoveAllByteTags ();
uint8_t buf[packet->GetSize()]; // Create storage for pkt data
packet->CopyData (buf, packet->GetSize()); // Dump pkt data in buf
Inet6SocketAddress ipAddress = Inet6SocketAddress::ConvertFrom (from);
Ipv6Address add = ipAddress.GetIpv6();
NS_LOG_INFO("add="<<add);
Ipv6Header ipv6Header;
packet->RemoveHeader(ipv6Header);
NS_LOG_INFO("hoplimit="<<ipv6Header.GetHopLimit());
  while (socket->Recv ())
    {
      NS_LOG_UNCOND ("Received one packet!");
    }
}

get the following assert failure for hoplimit part

assert failed. cond="(m_version) == 6", file=../src/internet/model/ipv6-header.cc, line=172
terminate called without an active exception

I don't understand why the version is not matching, when the whole process uses only Ipv6 addressing. Or am i accessing the Ipv6Header in a wrong fashion. 
Please let me know. 
Any help would be greatly appreciated.

Regards
Shashidhar B.L

Tommaso Pecorella

unread,
Jun 11, 2015, 4:54:05 AM6/11/15
to ns-3-...@googlegroups.com
You're removing the header, but the header isn't there anymore. Probably it has been removed previously.
Suggestion: don't remove the tags, USE them.

Check this code (it's in UdpSocketImpl::ForwardUp6)
  if (IsIpv6RecvHopLimit ())
   
{
     
SocketIpv6HopLimitTag ipHopLimitTag;
      ipHopLimitTag
.SetHopLimit (header.GetHopLimit ());
      packet
->AddPacketTag (ipHopLimitTag);
   
}

I am confident that you can find the solution now.

Cheers,

T.

Shashidhar B.L

unread,
Jun 11, 2015, 6:30:47 AM6/11/15
to ns-3-...@googlegroups.com
Hi,
Your suggestion was correct and I could extract the hoplimit. Unfortunately the value is zero, for reasons am trying to figure out. 
But, I wanted to ask your suggestion for obtaining the number of hops a packet has taken to reach a particular destination. 

To describe it in detail, let us say I have sent a packet from a source node and received it at destination. Now I want to know by how many hops has it reached the destination. 

Based on your suggestion, what I did was the following: 

void ReceivePacket (Ptr<Socket> socket)
{
Ptr<Packet> packet = socket->Recv();
Ipv6PacketInfoTag hoplimitTag;
packet->RemovePacketTag (hoplimitTag);
NS_LOG_INFO("packet="<<(uint32_t)hoplimitTag.GetHoplimit());
  while (socket->Recv ())
    {
      NS_LOG_UNCOND ("Received one packet!");
    }
}

The value I get here is Zero unfortunately. My idea was to get the HopLimit at that node, subtract with the Initial hoplimit set while transmitting the packet, and there we go, we have the number of hops taken to reach the destination. 

Could you please tell me if this approach is correct?
If yes, then any idea why I might be getting a value zero there? (its 0 for every packet I received). 
Do you have any suggestions for other methods to get this hop count?

Thank you
Regards
Shashidhar B.L


--
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/cjY71MWux0U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Tommaso Pecorella

unread,
Jun 11, 2015, 6:44:41 AM6/11/15
to ns-3-...@googlegroups.com
Hi,

I'm in a rush, so quick answer.
Did you remember to enable them ?
socket->SetIpv6RecvHopLimit (true);

Otherwise...

Cheers,

T.

Shashidhar B.L

unread,
Jun 11, 2015, 7:09:07 AM6/11/15
to ns-3-...@googlegroups.com
Hi,
yes i have set it. 

Tommaso Pecorella

unread,
Jun 11, 2015, 9:14:43 AM6/11/15
to ns-3-...@googlegroups.com
Hi,

make sure to use the latest ns-3. In case it fails lease send a sample script, I'll take a look.

Cheers,

T.
Reply all
Reply to author
Forward
0 new messages