[ndnSIM] How to get a node's neighbour

Alex Afanasyev alexander.afanasyev at ucla.edu
Sun Mar 10 11:33:22 PDT 2013

Hi Pan,

In general, as in real system, you would need to implement some kind of a resource discovery protocol to discover all node's neighbors.  At the same time, in NS-3, since it is a simulation, it is technically possible to "discover" neighbors directly:

In NS-3 in general, you would enumerate all NetDevice's on a particular Node object (http://www.nsnam.org/doxygen/classns3_1_1_node.html):

for (uint32_t deviceId = 0; deviceId < node->GetNDevices (); deviceId ++)
    Ptr<NetDevice> device = node->GetDevice (deviceId);

    # get channel, to which device is connected (a "wire")
    Ptr<Channel> channel = device->GetChannel ();

    for (uint32_t channelDeviceId = 0; channelDeviceId < channel->GetNDevices (); channelDeviceId ++)
        Ptr<NetDevice> channelDevice = channel->GetDevice (channelDeviceId);
        if (channelDevice == device)

        # channelDevice is a "neighbor"


On Mar 10, 2013, at 5:53 AM, panhgshine at 163.com wrote:

> Hi All,
> I'm a beginner of NS3 and ndnSIM. Recently, I have read the cache replacement policy code.
> Now, I want to get a node's all neighbour. 
> Is there anyone can give me some advice or hint?
> Thank you in advance.
> Pan

More information about the ndnSIM mailing list