retrive sender's ip address in IP l3 protocol

155 views
Skip to first unread message

funbird

unread,
Oct 28, 2011, 5:17:07 AM10/28/11
to ns-3-users
Hi all,

I am wondering how to retrive the sender's IP address in Ip-l3-
protocol. It seems that from IPv4 header only destination can be
retrived

Thanks in advance

Lalith Suresh

unread,
Oct 28, 2011, 8:46:53 AM10/28/11
to ns-3-...@googlegroups.com
On Fri, Oct 28, 2011 at 11:17 AM, funbird <wangke...@yahoo.com.cn> wrote:
Hi all,

    I am wondering how to retrive the sender's IP address in Ip-l3-
protocol. It seems that from IPv4 header only destination can be
retrived


Have you tried Ipv4Header::GetSource ()?
 
Thanks in advance

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Lalith Suresh

funbird

unread,
Oct 31, 2011, 3:55:40 AM10/31/11
to ns-3-users
Hi,

Thanks for the reply, GetSource will give me the origin sender of
the packet, what I want is the immediate sender. For example, for
multi-hop:

n1----------n2---------n3

for n3, GetSource will let me get n1 but actually I want to get n2.

On Oct 28, 8:46 pm, Lalith Suresh <suresh.lal...@gmail.com> wrote:

Lalith Suresh

unread,
Oct 31, 2011, 5:55:33 PM10/31/11
to ns-3-...@googlegroups.com
On Mon, Oct 31, 2011 at 8:55 AM, funbird <wangke...@yahoo.com.cn> wrote:
Hi,

   Thanks for the reply, GetSource will give me the origin sender of
the packet, what I want is the immediate sender. For example, for
multi-hop:

n1----------n2---------n3

for n3, GetSource will let me get n1 but actually I want to get n2.


The best you can get is the hardware address of n2's NetDevice which sent the packet to node n3. Look at the "from" argument of Ipv4L3Protocol::Receive().



--
Lalith Suresh

funbird

unread,
Nov 3, 2011, 1:03:18 AM11/3/11
to ns-3-users
Thanks a lot. So is there any way I can get the ip address from
hardware address, go through ARP?

On Nov 1, 5:55 am, Lalith Suresh <suresh.lal...@gmail.com> wrote:

Lalith Suresh

unread,
Nov 3, 2011, 9:13:34 AM11/3/11
to ns-3-...@googlegroups.com
On Thu, Nov 3, 2011 at 6:03 AM, funbird <wangke...@yahoo.com.cn> wrote:
Thanks a lot. So is there any way I can get the ip address from
hardware address, go through ARP?

Well, you would need something like reverse ARP (which ns-3 doesn't support, probably because it is an obsolete protocol).

Since this information isn't really stored in the packet, I'd say you need some higher level protocol to handle this for you, like how AODV treats (IP,Mac) address tuples as neighbours.



--
Lalith Suresh

funbird

unread,
Nov 8, 2011, 2:35:27 AM11/8/11
to ns-3-users
I see, thanks a lot, it really helps:)

On Nov 3, 9:13 pm, Lalith Suresh <suresh.lal...@gmail.com> wrote:

Mouna

unread,
Dec 24, 2014, 2:11:50 PM12/24/14
to ns-3-...@googlegroups.com
Hello,
How can i simulate reverse arp ??
i want your help.
Thanks in advance.

Tommaso Pecorella

unread,
Dec 24, 2014, 2:38:35 PM12/24/14
to ns-3-...@googlegroups.com
Hi,

if you mean RARP (http://en.wikipedia.org/wiki/Reverse_Address_Resolution_Protocol), then the answer is: by implementing it.
Currently the ns-3 IPv4 stack doesn't support DHCP, BOOTP or RARP. Addresses are assigned automatically though an helper (it may be seines a sort of offline DHCP) or manually. Unfortunately, no model for dynamic address assignment is present. Additions are always welcome, of course.

Cheers,

T.

Mouna Gassara

unread,
Dec 24, 2014, 5:54:41 PM12/24/14
to ns-3-users
Sir ,
I need to know the ip address of the intermidiate sender (previous hop), I have the mac address (the "from" argument of Ipv4L3Protocol::Receive()) . Is there a way to find this ip address other than RARP using ns3 ? if not, can you help me to implement reverse ARP because i am new in ns3.
Thanks a lot.

--
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/udfw-2B_wjI/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.

Mouna Gassara

unread,
Dec 28, 2014, 1:46:03 AM12/28/14
to ns-3-users
Hello
I need your help, when i execute this code:

uint16_t offset = 0;
 Ipv4Address address=m_node->GetObject<Ipv4>()->GetAddress (1,0).GetLocal();
 offset =  address.Get() & 8191;
 ipHeader.SetFragmentOffset(offset);

this error occured:
aborted. cond="(offsetBytes & 0x7)", msg="offsetBytes must be multiple of 8 bytes", file=../src/internet/model/ipv4-header.cc, line=242
I don't understand what is the problem???How can i correct it?? help me please.

Tommaso Pecorella

unread,
Dec 28, 2014, 6:23:25 AM12/28/14
to ns-3-...@googlegroups.com
Hi,

I don't understand what you're trying to do, but it's wrong.
You are setting the fragment offset field in the IPv4 header. That field is the fragment offset measured in 8bytes units. I.e., a fragment offset of 1 means an offset of 8 bytes.
For historical reasons, the "SetFragmentOffset" function wants the fragment offset in bytes units. This is an ns-3 internal thing. However, in the packets the fragment offset is really written in 8-bytes units, i.e., you say "8" and it writes 1.
In order to prevent idiotic bugs, there's a check preventing the user to set an offset of, let's say, 9. That's what the error message is stating: you're using SetFragmentOffset in a funny way. Why you're trying to set it to that value is another issue.

Have fun,

T.

Mouna

unread,
Dec 28, 2014, 8:13:15 AM12/28/14
to ns-3-...@googlegroups.com
Thank you for your reply.
I have to implement an ip traceback solution. The space available to put marking information is : type of service+ fragment ID+ unused flag+ fragment offset , specified by D. Dean, M. Franklin, and A. Stubblefield, "An Algebraic Approach to IP Traceback," ACM Transactions on Information and System Security (TISSEC), vol. 5, no. 2, 2002, pp. 119-137.
What i have to do?? I want to set fragment offset field, I should comment this msg in ipv4-header.cc?? that's right?? 


On Friday, October 28, 2011 11:17:07 AM UTC+2, funbird wrote:

Tommaso Pecorella

unread,
Dec 28, 2014, 4:45:15 PM12/28/14
to ns-3-...@googlegroups.com
Hi,

that paper is very, very old. Right now (no offence for the authors) wouldn't pass the first review stage. The main issue is that, from 2002 to now, there have been a lot of new RFCs and many IPv4 fields used by the paper are definitely not usable anymore. TOS is now used a lot, and the fragment field use has been coded strictly (i.e., routers are expected to drop badly coded packets).
I'd strongly suggest to adapt the technique proposed in the paper to the today status of things. As is, define an IP extension header and use that one.

As a side note, you CAN use the fragment field. Just remember: you want to write x in the field ? Pass X*8 to the function.

Hope this helps,

T.

Mouna Gassara

unread,
Dec 29, 2014, 7:54:57 AM12/29/14
to ns-3-users
thank you sir for your reply , it's very helpfull.
 I implemented my traceback solution, but when i want to display ipheader.GetTos() any thing appeared, Why??
 I need to evaluate the performance of this solution. How can i meseare  bandwidth, memory and processing overhead??
help me please.

--

Tommaso Pecorella

unread,
Dec 29, 2014, 9:02:38 AM12/29/14
to ns-3-...@googlegroups.com
Hi,

what do you mean with "when i want to display ipheader.GetTos() any thing appeared" ?
How did you check / see the TOS value ? Are you sure it is zero, or you just can't print it ?

About the second question... bandwidth: it depends on what you're transmitting. I don't know your protocol, so I can't say. However there are plenty of discussion in the group about how to measure the bandwidth.
The memory and processing overhead, as stated countless times in the group, can NOT be measured through ns-3. You can, of course, count the "operations" (i.e., how many times a function is called) and the dimension of the data structures you need to memorise (e.g., the size of a vector), but that's the only things you can measure. How to do it.. it depends on your scripts, but it should be easy enough to add a couple of counters.

Happy coding,

T.

Mouna Gassara

unread,
Dec 29, 2014, 11:07:28 AM12/29/14
to ns-3-users
I want to print ipheader.GetTos(), it's different to 0 because i changed it in my solution .

Tommaso Pecorella

unread,
Dec 29, 2014, 12:33:28 PM12/29/14
to ns-3-...@googlegroups.com
Hi,

that was pretty obvious. Mind to avoid wasting my and your time like this ?
1) The fact that you changed the TOS is logical, otherwise you wouldn't assume that it's not zero.
2) The fact that you want to print it is logical too. You already said it some messages ago.

The most important things are missing, tho:
1) the **** code, and
2) the output (the expected one and what you have instead).

Without the two above mentioned things, the best I can say is: there's an error somewhere. Obvious and not very informative, but if it's enough for you...

Thanks,

T.

Mouna Gassara

unread,
Dec 30, 2014, 1:52:22 AM12/30/14
to ns-3-users
thank you for your reply. I need in my implementation the option field of ipv4 header, that exists in ns3.21 ??If not how can i add it??
I want your help.

Tommaso Pecorella

unread,
Dec 30, 2014, 3:18:13 AM12/30/14
to ns-3-...@googlegroups.com
Hi,

if you mean the Option filed, i.e., the variable-length part after the canonical and mandatory 20 bytes... no, it's not implemented in ns-3. Moreover, implementing it is a major headache: in a lot of places it is assumed that the IP header is 20 bytes long, and adding the Options would mean to check the whole codebase and replace these parts.

I hope you meant another field...

Cheers,

T.

Mouna Gassara

unread,
Dec 30, 2014, 3:23:10 AM12/30/14
to ns-3-users
enter image description here
I mean the options field in ipv4 header.

Mouna Gassara

unread,
Dec 30, 2014, 3:36:58 AM12/30/14
to ns-3-users
thank you for your reply.
If options field don't exist so how can i change TOS value??, my code is:
                  
                  Ipv4Address address=m_node->GetObject<Ipv4>()->GetAddress (1,0).GetLocal();                  
                  ipHeader.SetTos(static_cast<uint8_t>  (address.Get() >> 0x1D) & 7);
        
     std::cout << "********** tos =" << ipHeader.GetTos() << std::endl;
and the result: "********** tos =
I think that tos still equal to zero. This is a critical problem for my ip traceback solution. Help me sir and thanks in advance.
     

Tommaso Pecorella

unread,
Dec 30, 2014, 3:51:51 AM12/30/14
to ns-3-...@googlegroups.com
Hi,

mind to use some logic ?
Otherwise, when the Vulcanians will land they'll exterminate the whole human race for being an insult to the logical process.

If TOS would be zero, then the output would have been "********** tos = 0".
On the contrary, nothing is printed, not even zero (the character).
Now, ipHeader.GetTos() returns an uint8_t, and this is mistakenly printed as a char. Remember that C++ << operator does some guessing about the data types...
Unfortunately, many "low value" ASCII chars are not printable, and they just are... not printed at all. Hence the blank space.

The correct way to print it is:
std::cout << "********** tos =" << int(ipHeader.GetTos()) << std::endl;

T.

Mouna Gassara

unread,
Dec 30, 2014, 8:27:03 AM12/30/14
to ns-3-users
Thank you Mr.Tommaso.
I tried your proposition, but i don't understand why int(ipHeader.GetTos()) still equal to zero inspite of  changing this value:

ipHeader.SetTos(static_cast<uint8_t>  (traceback.COUNTER_ROUTERS << 3  |((binary_word >> 29) & 7)));
in receive() method of ipv4-l3-protocol.cc
and i comment every changements in other methods:
//uint8_t tos = m_defaultTos;
//tos = ipTosTag.GetTos ();
/*.AddAttribute ("DefaultTos", "The TOS value set by default on all outgoing packets generated on this node.",
                   UintegerValue (0),
                   MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTos),
                   MakeUintegerChecker<uint8_t> ())*/
i modify tos by ipHeader.GetTos() in
     ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, ipHeader.GetTos(), mayFragment);
Can you help me please, i want to pass this tos value between routers for remaining the traceback procedure.

Tommaso Pecorella

unread,
Dec 30, 2014, 9:53:29 AM12/30/14
to ns-3-...@googlegroups.com
???
Routers will not change anything in the IP header. They'll just read it (the header) to do the routing, but they'll not touch it.
As a consequence, if you set it right in the source, the value should be kept 'til the destination.
Unless, of course, you did something with how IP headers are processed by the routing.

I'd start by checking that, once you set the intended value, this is registered in the header. Try printing the header. Moreover, check what's the header in the very first hop.

T.

Mouna Gassara

unread,
Dec 30, 2014, 11:23:08 AM12/30/14
to ns-3-users
my solution based on marking approach so it's evident to modify the IP Header in order to avoid source ip spoofing.

Tommaso Pecorella

unread,
Dec 30, 2014, 11:56:00 AM12/30/14
to ns-3-...@googlegroups.com
Touché.

T.

Mouna Gassara

unread,
Dec 30, 2014, 12:21:41 PM12/30/14
to ns-3-users
Please can you help me to change Tos value . I want to correct the dynamic ip tracaback procedure. I need that urgent to complete the implementation. Thank you in advance.

Tommaso Pecorella

unread,
Dec 30, 2014, 3:04:55 PM12/30/14
to ns-3-...@googlegroups.com
you said:

> I modify tos by ipHeader.GetTos() in
>       ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, ipHeader.GetTos(), mayFragment);

BuildHeader is a function only called in Ipv4L3Protocol::Send. In that point the header is... BUILT for the first time. As a consequence, it can not have any previously set TOS. You can comment the attribute part, but an unset variable will be always zero.
Hence, the packet is sent with a zero TOS.

Moreover, you said:
> ipHeader.SetTos(static_cast<uint8_t>  (traceback.COUNTER_ROUTERS << 3  |((binary_word >> 29) & 7)));
> in receive() method of ipv4-l3-protocol.cc

This will work or not, depending if it's done before or after removing the header from the packet. If it's done before, the packet's value will overwrite your.

I can't say more because the snippets are too few.
As I said before, print the header just after you set the TOS and just after removing the header in receive function. Check that the value you set is kept in both places.

T.

Mouna Gassara

unread,
Jan 3, 2015, 9:56:07 AM1/3/15
to ns-3-users
thank you a lot.
can you help me, how can i implement IARP process??

Tommaso Pecorella

unread,
Jan 3, 2015, 10:48:51 AM1/3/15
to ns-3-...@googlegroups.com
You mean this ?

Anyway, the answer doesn't change too much, and it has been said countless times.
You develop a protocol by implementing it. If it seems recursive and obvious, it's because it is obvious and it is recursive. You implement something by writing the code that implements the procedures (semantic, syntax, timing, etc.) that are described in the protocol standard documents.
It is easy ? No.

Cheers,

T.

Mouna Gassara

unread,
Jan 6, 2015, 1:05:51 PM1/6/15
to ns-3-users
Thank you sir.
I have a problem, help me please, I changed some fields in ipv4 header (Ipv4L3Protocol::receive()) but these values don't change in the next receive (next hop) with methods getTos() getIdentification  () and getOffset().
ip address=10.1.2.2
----------- counter router =0
---------- identification =201
---------- fragment_offset =0
----------- counter router =1// i incremented TOS, identification and offset  by 1, 
---------- identification =202// 
---------- fragment_offset =1
ip address=10.1.3.2
----------- counter router =0
---------- identification =198
---------- fragment_offset =0
------------------------------------------------------------------------------------------------------
how can i change result to be:
ip address=10.1.3.2
----------- counter router =1
---------- identification =202
---------- fragment_offset =1
I want to retreive these values in receive method of next hop. Thank you in advance. 

Tommaso Pecorella

unread,
Jan 6, 2015, 3:23:53 PM1/6/15
to ns-3-...@googlegroups.com
Hi,

I'll go meditate about this. When I'll have reached the Illumination and I'll be a real bodhisattva, perhaps I'll be able to give you a meaningful answer. Without the necessary enlightenment I'm not able to help you. As a matter of fact, without knowing what's going on in your code, I can't possibly say anything.
Anyway, I'll be back if and when I'll have the Illumination. See you in 20 or 30 years. Maybe more.

Cheers,

T.

PS: I already told you in a previous post how to proceed and what to do to check that your headers are built correctly.

Mouna Gassara

unread,
Jan 6, 2015, 3:59:06 PM1/6/15
to ns-3-users
Mr bodhisattva
you have to reach now the illumination, this is my code :
in Ipv4L3Protocol::receive (......):
packet->RemoveHeader (ipHeader);

    COUNTER_ROUTERS = ipHeader.GetTos() ;

      uint32_t identification= ipHeader.GetIdentification();
      uint32_t offset_fragment= ipHeader.GetFragmentOffset()/8;


                  std::cout << "ip address=" << address << std::endl;
        std::cout << "----------- counter router =" << COUNTER_ROUTERS << std::endl;
        std::cout << "---------- identification =" << identification << std::endl;
        std::cout << "---------- fragment_offset =" << offset_fragment << std::endl;
   ipHeader.SetTos(COUNTER_ROUTERS++);
   ipHeader.SetIdentification(identification++);
   ipHeader.SetFragmentOffset((offset_fragment++ )*8);

   packet->AddHeader(ipHeader);
   std::cout << "----------- counter router =" << ipHeader.GetTos() << std::endl;
              std::cout << "---------- identification =" << identification << std::endl;
              std::cout << "---------- fragment_offset =" << offset_fragment << std::endl;
 the call of method Ipv4L3Protocol::BuildHeader(......) in Ipv4L3Protocol::send() permits to update the header , so what i have to do for transmitting packet with modified ip header from node to other? it's possible to add header as argument in send() method or a whole packet??
I hope you reach the illumination ;)

Tommaso Pecorella

unread,
Jan 6, 2015, 4:21:09 PM1/6/15
to ns-3-...@googlegroups.com
I'll have a chance to reach a less unstable, angry and prone to swearing state of mind when I'll not feel compelled to reply to messages containing mistakes.

1) "address". What is it ? Sender or receiver ? In both cases it seems that you're dealing with two different packets, no wonder they have different headers.
2) Read the code. Learn and understand what BuildHeader does (and no, you don't need it).
3) Send: why the *** should you use that ?

PLEASE read the code, understand it and try to find the solution s by yourself before asking for help.

Thanks,

T,

Mouna Gassara

unread,
Jan 6, 2015, 5:02:04 PM1/6/15
to ns-3-users
Thank you sir. I'm sorry for mistakes. English isn't my mother tongue.
1) address is a receiver, i deal with one packet because i have just changed ip header fields in receive method
2) i read carefully the code and i think that BuildHeader method is the only method witch modifies header fields
3) i don't use send method . 
Sorry for making you angry and prone.
Reply all
Reply to author
Forward
0 new messages