How to get NetDevice associated with an Ipv4Address?

104 views
Skip to first unread message

Eduardo López

unread,
Jun 24, 2015, 8:31:57 PM6/24/15
to ns-3-...@googlegroups.com
Hi everybody:

I'm working with some RoutingProtocols and I'm a little confused.

I got the Ipv4Address that are neighbors from a Node.

I would like to know what NetDevices are associated to these Ip's, but I don't find a method in the Ipv4Address class that help to do that.

Is it possible to find this NetDevice?

Regards

Tom Henderson

unread,
Jun 24, 2015, 9:11:22 PM6/24/15
to ns-3-...@googlegroups.com
You have to find the possible neighboring nodes; in the worst case, you
can iterate all the nodes in the global NodeList.

Once you get a candidate node to check, you can (for each node):

Ipv4Address ipAddr = ...
Ptr<Node> node = ...
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
uint32_t index = ipv4->GetInterfaceForAddress (ipAddr);


This will return -1 if the address is not associated to any interface,
or the (non-negative) interface index if the address is associated to an
interface.

When you do find the node, you can pass the index to this method to get
the NetDevice:
Ptr<NetDevice> netDevice = ipv4->GetNetDevice (index);


- Tom

Tommaso Pecorella

unread,
Jun 24, 2015, 10:46:49 PM6/24/15
to ns-3-...@googlegroups.com
I totally agree with Tom's solution, but the question is: why do you want to know the NetDevice pointer ?
I usually don't like the answer (hint: don't tell me), because usually it's something like "I need to know some parameter of the receiver".

From the Routing Protocol point of view, remember that any routing decision should be based on local measures or stuff that is passed through the routing protocol messages. Any "direct" way to poke the other end NetDevice is cheating.
Once this is known and accepted, one can go ahead and do whatever is needed/wanted.
A notable example are position-based routing protocol, where one assumes that the two endpoints knows their respective position. In my opinion this is still black magic, but sometimes one can do a simplifying assumption before going full complex.

Anyway, this is just to suggest to double check if you really need the other NetDevice pointer.

Have fun,

T.

PS: the method above is damn slow. It's best to have a global "almighty" helper caching the lookups. It's still totally imaginary, but at least it will not slow down too much your simulations.

Eduardo López

unread,
Jun 26, 2015, 4:05:25 PM6/26/15
to ns-3-...@googlegroups.com
I'm sorry for response until now!

Thanks Tom! Your solution works.

I reflected about your comment Tommaso Pecorella.

I would like to put names to each NetDevices of the nodes neighbors, using the ns-3 class Names. First , I thought putting a name to each Ipv4Address, but I found that ns-3 just permit putting names to ns3::Objects.

I want to do this nomenclature starting in a certain node and to continue with the nodes neighbors until visit all the conexions. 

At begining, I know just the Ipv4Address that are stored in a table (this table is created by the RoutingProtocol). I know the method is slow (checking each node).

Do you have a suggestion to do this nomenclature faster?

Thank you very much!

Regards.

Tommaso Pecorella

unread,
Jun 26, 2015, 6:51:39 PM6/26/15
to ns-3-...@googlegroups.com
Hi,

I didn't understand exactly what you want to do, but then again I'm not really interested in knowing it.
I'd just like to stress that an Object can have a name, but only ONE name. As a consequence, if two nodes will give a conflicting name to the same neighbor, the 2nd one will "win". This can cause a race condition, think about it.

Have fun,

T.
Reply all
Reply to author
Forward
0 new messages