Bug 85 - NetDevice::m_ifIndex not the same as Ipv4's ifIndex
NetDevice::m_ifIndex not the same as Ipv4's ifIndex
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: network
pre-release
All All
: P2 minor
Assigned To: Tom Henderson
:
Depends on:
Blocks: 384
  Show dependency treegraph
 
Reported: 2007-10-08 00:46 EDT by Tom Henderson
Modified: 2009-04-21 00:11 EDT (History)
3 users (show)

See Also:


Attachments
change ifIndex to interfaceIndex, at IPv4 layer (35.44 KB, patch)
2008-06-11 01:07 EDT, Tom Henderson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Henderson 2007-10-08 00:46:57 EDT
This is a reminder that we ought to consider an alternative to using ifIndex both in the NetDevice and in the API for Ipv4.  These two indices are not the same; namely, the Ipv4 ifIndex (the underlying variable is Ipv4L3Protocol::m_nInterfaces) is often one greater than the NetDevice ifIndex due to the Ipv4 loopback interface not having a corresponding NetDevice.

At least we should consider changing one of these names because otherwise some subtle programming errors are likely.
Comment 1 Mathieu Lacage 2007-10-08 03:03:52 EDT
Agreed. Proposal for better names ?
Comment 2 Craig Dowell 2007-10-09 00:26:42 EDT
I've been calling them interface index (ifIndex) and net device index (ndIndex) in the tutorial and the difference is explained and emphasized. 
Comment 3 Tom Henderson 2007-10-10 10:35:20 EDT
If we want to maintain alignment with Linux naming conventions, we should keep the netdevice parameter to be named ifIndex and call the Ipv4Interface parameter something else or else refactor to not require a separate Ipv4Interface index.
Comment 4 Tom Henderson 2008-06-05 10:59:14 EDT
raising to P1 (we should resolve before the release)
Comment 5 Craig Dowell 2008-06-10 13:50:35 EDT
Marked as P2/LATER per prior agreement.  Will revisit after 3.1 release.
Comment 6 Tom Henderson 2008-06-11 01:07:28 EDT
Created attachment 161 [details]
change ifIndex to interfaceIndex, at IPv4 layer

attached documentation patch should mostly resolve it.  Release mgr, OK to commit?

(leaves NetDevice ifIndex as is, changes use of "ifIndex" at the Ipv4 layer to instead refer to "interfaceIndex", in most places, and clarified in a few doxygen headers about the distinction between NetDevice and Ipv4Interface indices)
Comment 7 Tom Henderson 2008-06-11 01:08:32 EDT
reopen for consideration for 3.1 release
Comment 8 Craig Dowell 2008-06-11 12:38:48 EDT
I'm okay with committing this, but the basic problem of two meanings still exists.

When I stare at the string "ifIndex" I read "interface index".  Now when I look at the string "interfaceIndex" I still read "interface index."

When I look at IP code, I see methods like GetIfIndexForDestination() with variables scattered around looking like "interfaceIndex."

When I look at device code, I see methods like SetIfIndex() and I see an m_ifIndex member variable.  I read "set interface index" and "interface index member variable."  When I look at Node::AddDevice() though, I find,

Node::AddDevice (Ptr<NetDevice> device)
{
  uint32_t index = m_devices.size ();
  ...
  device->SetIfIndex(index);
  ...
}

All of the methods still refer to IfIndex everywhere; and it's the method names I usually pay more attention to.
Comment 9 Craig Dowell 2008-06-11 14:26:01 EDT
By the same logic applied recently to another bug (218) we may want to consider changing the names of the methods in Ipv4 that refer to an IfIndex to something else before we ship.

If we change these methods to be called something like BlahIpv4IndexMumble instead of BlahIfIndexMumble but leave the ifIndex found in the net devices alone we may be able to put this to rest.

This would have a relatively large scope but it is a simple rename operation and as such would be relatively low risk.
Comment 10 Mathieu Lacage 2008-06-11 14:37:34 EDT
I think that a major difference with bug 218 is that this change is most likely not going to have any real impact on most scripts. Instead, it will have impact on ipv4 routing protocols, etc. which are, hopefully, more rare than user scripts.
Comment 11 Tom Henderson 2008-06-11 15:01:52 EDT
(In reply to comment #8)
> I'm okay with committing this, but the basic problem of two meanings still
> exists.
> 
> When I stare at the string "ifIndex" I read "interface index".  Now when I look
> at the string "interfaceIndex" I still read "interface index."

Yes, this is a bit unfortunate.  In Linux, there is an ifIndex (struct net_device), but there is no integer equivalent to interfaceIndex.  Instead, interfaces (in_addrs) are named by device name strings such as "eth0" and "eth0:1".  

> 
> When I look at IP code, I see methods like GetIfIndexForDestination() with
> variables scattered around looking like "interfaceIndex."

Yes, this is what I mean that the patch "mostly" fixes this-- I did not change any method names.  I think it would be cleaner to change those method names, but I can live without it I guess (with documentation around it).

> 
> When I look at device code, I see methods like SetIfIndex() and I see an
> m_ifIndex member variable.  I read "set interface index" and "interface index
> member variable."  When I look at Node::AddDevice() though, I find,
> 
> Node::AddDevice (Ptr<NetDevice> device)
> {
>   uint32_t index = m_devices.size ();
>   ...
>   device->SetIfIndex(index);
>   ...
> }
> 
> All of the methods still refer to IfIndex everywhere; and it's the method names
> I usually pay more attention to.

good point. 

another alternative would be to use names like intIndex and devIndex at the respective levels and avoid altogether "ifIndex", including fixing method names, but that is more intrusive still.

Comment 12 Gustavo J. A. M. Carneiro 2008-06-16 11:04:24 EDT
Real world scenario; just happened to me.  Student writes code to bring down all interfaces.  I have to spend considerable time debugging his code.  Guess what was the patch to fix it:

-  for(uint32_t i = 0; i < GetNode()->GetNDevices(); i++)
-   ipv4->SetDown(i);
+  for(uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
+    {
+      ipv4->SetDown (i);
Comment 13 Tom Henderson 2009-02-16 01:01:18 EST
sliding to ns-3.5
Comment 14 Tom Henderson 2009-04-21 00:11:18 EDT
fixed:  changeset d99061f1167c