extract modified header from Ipv4L3Protocol::send method

87 views
Skip to first unread message

Mouna

unread,
Jan 15, 2015, 8:51:21 AM1/15/15
to ns-3-...@googlegroups.com
Hi 
I modified packet header in Ipv4L3Protocol::receive and i want to extract previous modified information in Ipv4L3Protocol::send, 

packet->RemoveHeader(ipHeader) gives me an error when i put it in Ipv4L3Protocol::send:
--> failed assert ,cond((verIhl >>4)==4)

I think that is because the packet header don't exist in the beginning. 
How can i throw this assertion in send method (like this if ip header exist)??
Or it is possible to transmit ip header from receive method to send method??
I need your help. It's a big problem for me.
Thank you very much.

Tommaso Pecorella

unread,
Jan 15, 2015, 11:16:17 AM1/15/15
to ns-3-...@googlegroups.com
Hi,

today (well, better to say in the last few days) I'm a bit nervous. I'd be happy to be able to calm down and ease my pain, but I can't.
However, I'll be extremely grateful to anyone who can help.

What this does means for you? Maybe nothing, but you could start by describing your problem in a clear way. Maybe a way that doesn't make me wanting to search for your personal details and use the latest revenge idea on the 'net.

ANALYSIS.
"I modified packet header in Ipv4L3Protocol::receive and i want to extract previous modified information in Ipv4L3Protocol::send, "
Impossible. In Ipv4L3Protocol::Receive the packet is received. You can modify what you want, but the packet will not go through Ipv4L3Protocol::Send anymore. Perhaps Ipv4L3Protocol::IpForward.

"I think that is because the packet header don't exist in the beginning. "
Ohhhh.... so you're trying to use RemoveHeader knowing that there's no header to be removed ? And tell me, how can we help beside telling you that yes, it's a bad idea to remove an header if the header isn't there ?

"How can i throw this assertion in send method (like this if ip header exist)??"
I don't want to write an answer. And you don't want to read the answer.

Anyway, as for another post I replied today. Explain what you are trying to do. Explain it in a CLEAR way. I'm ready to bet that simply by trying to explaining it you will find why nothing is working. 

T.

Mouna Gassara

unread,
Jan 15, 2015, 12:39:31 PM1/15/15
to ns-3-users
Thank you for your answer. I am sorry, i try to more explain:
I want to implement an ip traceback solution. In  this solution, every router will modify dynamically some ip header fields extracted from received packet. In fact, every router will:
* receive packet from its previous 
* extract some fields from ip header
* apply a recurcive function to these values   :    new_field_value= function( old_field_value)
* send these values included in the packet to the next router.

 I implement this function in Ipv4L3Protocol::receive but the problem is that these fields don't change as i like. I think that the Ipv4L3Protocol::send method create always a new ip header in BuildHeader method. Whereas, i want to use the old ip header in the received packet and not the new one.
I tried with packet->RemoveHeader(ipHeader) to get old ip header fields but the problem appears only with the first sender which don't find the header of the empty packet. Therefore, i want to do that:

if (packet header is empty) then  old_field_value=0
else   new_field_value= function( old_field_value)

I hope this is clear. Sir, i need your help, without the first condition the traceback process will don't work.
Thanks in advance.

--
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/QTi9YWXu684/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,
Jan 15, 2015, 1:14:49 PM1/15/15
to ns-3-...@googlegroups.com
Hi,


The Ipv4L3Protocol::Send function is called only in 2 cases (check the ****#### code),
1) by L4 protocols in the SENDER node. The routers do NOT call Ipv4L3Protocol::Send.
2) By a router if the routing protocol is either DSR or DSDV (those are actually encapsulating a whole IP packet in their own packets).

If you don't use DSR or DSDV, the Ipv4L3Protocol::Send is NOT called in a router node.

Please study carefully how Ipv4L3Protocol::Send and Ipv4L3Protocol::SendRealOut work.

As for the statement "these fields don't change as i like", I must re-iterate the suggestion I already gave you (and mind, I only give suggestions two times): check that the received header is the one that you are expecting, and that you're looking at the same packet you transmitted. Not like the last time, when you was checking two different packets (they had different IP sources).
Use only 3 nodes in a line topology, have the sender... sending a packet and check that the node in the middle (the router) is receiving the right header, decoding it right and changing it. It is not hard. Especially because this is the 2nd (or 3rd?) time we tell you what to do.

T.

Mouna Gassara

unread,
Jan 16, 2015, 3:26:16 AM1/16/15
to ns-3-users
Thanks a lot.
I don't use DSR or DSDV, I use 802.11s stack in layer 2  and AODV in layer 3  (See attachement file). I think L4 protocol in the SENDER node changes fields values because when i add this line 
std::cout << "SENDERSENDER"<< std::endl; 
in  Ipv4L3Protocol::send method, I get this message in execution, so this method is executed. In addition, when i comment identification field value in BuildHeader ,this value becomes zero and don't changed in execution after  i add function in Ipv4L3Protocol::receive method:

packet->RemoveHeader(ipHeader);

  int COUNTER_ROUTERS = (ipHeader.GetTos() >> 3 )& 31;
  long long binary_word=0;


  uint32_t end_tos = ipHeader.GetTos() & 7;
  uint32_t identification= ipHeader.GetIdentification();
  uint32_t offset_fragment= ipHeader.GetFragmentOffset()/8;
     binary_word = end_tos << 29 | identification << 13 | offset_fragment;

         binary_word =Function(binary_word);

     COUNTER_ROUTERS++;
     ipHeader.SetTos((COUNTER_ROUTERS << 3) | ((binary_word >> 29) & 7));
     ipHeader.SetIdentification(uint16_t (binary_word >> 13) & 65535);
     packet->AddHeader(ipHeader);   

these values still zero. Please I need  your help sir.   
scenario.cc

Tommaso Pecorella

unread,
Jan 16, 2015, 3:38:53 AM1/16/15
to ns-3-...@googlegroups.com
Wait... you mean that you're changing the field values BEFORE calling BuildHeader ?!?!?!?!
No really, it can't be this. Please, don't tell me you did that, please. Please, don't.

T.

Mouna Gassara

unread,
Jan 16, 2015, 9:28:18 AM1/16/15
to ns-3-users
No not before BuildHeader but in BuildHeader, i want that BuildHeader method don't change fields values. 

Mouna Gassara

unread,
Jan 16, 2015, 9:49:11 AM1/16/15
to ns-3-users
When i print fields values in the receive method, nothing changes and these fields values still zero in router nodes, Why ???? 

Tommaso Pecorella

unread,
Jan 16, 2015, 11:09:18 AM1/16/15
to ns-3-...@googlegroups.com
If I get it right, you did modify the BuildHeader function. Mind posting the code of your BuildHeader function ?
Note, please double check your code before positing it... I can't guarantee anything.

T.

Mouna Gassara

unread,
Jan 16, 2015, 11:38:17 AM1/16/15
to ns-3-users
Ok. In BuildHeader, How can i write this condition: if (packet header is empty)??packet->RemoveHeader(ipHeader) gives me an error:
assert failed,cond(verIhl >>4)==4

Tommaso Pecorella

unread,
Jan 16, 2015, 3:58:27 PM1/16/15
to ns-3-...@googlegroups.com
If you're building the header, the header isn't there. it would be quite strange otherwise, isn't it ?
When I said to study and understand the code, I meant exactly that. The IP header is CREATED by BuildHeader and AFTER it is added to the packet. Any attempt to remove the header from within BuildHeader is bound to fail.

T.

Mouna Gassara

unread,
Jan 17, 2015, 3:20:24 AM1/17/15
to ns-3-users
Yes Yes, this is my problem. I know that the header isn't there firstly , i need to prevent BuildHeader method to create a new header and delete my old header modified by the previous router in receive method:
*the first sender (source) don't find any packet so any header therefore it will create a new packet. That makes packet->RemoveHeader(ipHeader)  failed.
*Otherwise, all nodes receive and send an existed packet (also existed header) so i can do packet->RemoveHeader(ipHeader) 
I tried to locate when the header change in my senario, I find that the header is changed in send method exactly in this part of code:

// 2) check: packet is destined to a subnet-directed broadcast address
  uint32_t ifaceIndex = 0;
  for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
       ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
    {
      Ptr<Ipv4Interface> outInterface = *ifaceIter;
      for (uint32_t j = 0; j < GetNAddresses (ifaceIndex); j++)
        {
          Ipv4InterfaceAddress ifAddr = GetAddress (ifaceIndex, j);
          NS_LOG_LOGIC ("Testing address " << ifAddr.GetLocal () << " with mask " << ifAddr.GetMask ());
          if (destination.IsSubnetDirectedBroadcast (ifAddr.GetMask ()) &&
              destination.CombineMask (ifAddr.GetMask ()) == ifAddr.GetLocal ().CombineMask (ifAddr.GetMask ())   )
            {
              NS_LOG_LOGIC ("Ipv4L3Protocol::Send case 2:  subnet directed bcast to " << ifAddr.GetLocal ())
----------->>>>> ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment);
              Ptr<Packet> packetCopy = packet->Copy ();
              m_sendOutgoingTrace (ipHeader, packetCopy, ifaceIndex);
            
                  if ( ??????????????????????????????? )  packet->RemoveHeader(ipHeader);
             packetCopy->AddHeader (ipHeader);

             
              m_txTrace (packetCopy, m_node->GetObject<Ipv4> (), ifaceIndex);
              outInterface->Send (packetCopy, destination);
              return;
            }
        }
    }
I want to add a condition for making packet->RemoveHeader(ipHeader) work and extract the old header.
Help me please Sir.

Tommaso Pecorella

unread,
Jan 18, 2015, 11:50:12 AM1/18/15
to ns-3-...@googlegroups.com
On Saturday, January 17, 2015 at 9:20:24 AM UTC+1, Mouna wrote:
Yes Yes, this is my problem. I know that the header isn't there firstly , i need to prevent BuildHeader method to create a new header and delete my old header modified by the previous router in receive method:

I'm not used to say something more than twice. I already said (also) this.
As a consequence, this is my last message to you, and I'm not joking.

Ipv4L3Protocol::Send and Ipv4L3Protocol::BuildHeader are NEVER called by a router, unless you are using DSDV or DSR.
You said you are using AODV, so the routers will NOT call Ipv4L3Protocol::Send or Ipv4L3Protocol::BuildHeader.

Good luck finding the error. I hereby declare that I am unable to assist you further. As a consequence, I'lll not waste your time trying to explain what's wrong.

T.

Reply all
Reply to author
Forward
0 new messages