getting ipv6addresses and prefixs for a node

37 views
Skip to first unread message

Hajar Hantouti

unread,
Jan 4, 2016, 6:02:29 AM1/4/16
to ns-3-users
Hello ,

I have an Ipv6 address and prefix that I want to know  whether they belong to a given node or not .
for this purpose i browse the nodedevices list (for a given node) , retrieve every address and prefix and compare them with the given ipv6address and prefix.


Actually it couldn't be resolved this way ..

Ptr <Node> node = NodeList::GetNode(node_id);
uint32_t a
= node->GetNDevices();
 
for(uint32_t k=0 ;k<a ;k++){
     
Ipv6Address dev_address=node->GetDevice(k)->GetAddress();
     
// but how to get the prefix ??
   
}


Tommaso Pecorella

unread,
Jan 4, 2016, 2:44:49 PM1/4/16
to ns-3-users
Hi,

the code you posted is wrong.
It's wrong now because it's wrong per-se, it's wrong because it's not right.

The above sentence was often said by one of my professors, just before making a student fail his exam.
The hidden meaning is that the sentence (or the code) could be "right", but not going the thing it was supposed to be doing. As a consequence, it's right, but it's also wrong.

What you get from your code its the MAC address, not the IP address... and the MAC address doesn't have a prefix.
The code you want is:
  Ptr <Node> node = NodeList::GetNode(node_id);

 
Ptr <Ipv6L3Protocol> ip = node->GetObject<Ipv6L3Protocol>();
  uint32_t nInterfaces
= ip->GetNInterfaces ();
 
for(uint32_t i=0; i<nInterfaces; i++)
   
{
      uint32_t nAddresses
= ip->GetNAddresses (i);
     
for(uint32_t j=0; j<nAddresses; j++)
       
{
         
Ipv6InterfaceAddress dev_address = ip->GetAddress (i,j);
          std
::cout << "Address " << dev_address.GetAddress () << " / " << dev_address.GetPrefix().GetPrefixLength() << std::endl;
       
}
   
}


Cheers,

T.

Hajar Hantouti

unread,
Jan 5, 2016, 5:39:18 AM1/5/16
to ns-3-users
Thank you Tomaso ,
it resolved the issue , I 'll remember your professor's lesson :).
May I ask another question concerning the function :
bool Ipv6InterfaceAddress::IsInSameSubnet (Ipv6Address b) const

is it recommanded to use it with different prefix lenghts? ,It could be mistaken when the prefix of b is long than the  prefix of a.

Tommaso Pecorella

unread,
Jan 5, 2016, 6:00:31 AM1/5/16
to ns-3-users
Yo,

that function is meant to be used by a node when it receives a packet from another node. The receiver doesn't know the sender's prefix (because it's something that it could have been set manually in the sender's stack. Thus, it uses its own prefix length.
Think about it: the receiver never knows the prefix length o other nodes, just its own. That's why it's so disruptive to set different prefix length in different nodes in the same network: the nodes will start go crazy.

As a consequence, you're right: this function must be used when the two addresses have the same prefix length. However, it's outside of the scope of the Ipv6InterfaceAddress class to make sure that this happens.

Cheers,

T.

Hajar Hantouti

unread,
Jan 5, 2016, 11:05:53 AM1/5/16
to ns-3-users
Hello ,
I understand , thank's for your explanation.
Cordially,
Hajar
Reply all
Reply to author
Forward
0 new messages