A Discrete-Event Network Simulator
API
neighbor-cache-helper.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 ZHIHENG DONG
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Zhiheng Dong <dzh2077@gmail.com>
18  */
19 
20 #include "neighbor-cache-helper.h"
21 
22 #include "ns3/assert.h"
23 #include "ns3/channel-list.h"
24 #include "ns3/ipv4.h"
25 #include "ns3/ipv6.h"
26 #include "ns3/log.h"
27 #include "ns3/net-device.h"
28 #include "ns3/node.h"
29 #include "ns3/ptr.h"
30 #include "ns3/simulator.h"
31 
32 namespace ns3
33 {
34 
35 NS_LOG_COMPONENT_DEFINE("NeighborCacheHelper");
36 
38 {
39  NS_LOG_FUNCTION(this);
40 }
41 
43 {
44  NS_LOG_FUNCTION(this);
45 }
46 
47 void
49 {
50  NS_LOG_FUNCTION(this);
51  m_globalNeighborCache = true;
52  for (uint32_t i = 0; i < ChannelList::GetNChannels(); ++i)
53  {
56  }
57 }
58 
59 void
61 {
62  NS_LOG_FUNCTION(this << channel);
63  for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
64  {
65  Ptr<NetDevice> netDevice = channel->GetDevice(i);
66  Ptr<Node> node = netDevice->GetNode();
67 
68  int32_t ipv4InterfaceIndex = -1;
69  if (node->GetObject<Ipv4>())
70  {
71  ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
72  }
73  int32_t ipv6InterfaceIndex = -1;
74  if (node->GetObject<Ipv6>())
75  {
76  ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
77  }
78 
79  for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
80  {
81  Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
82  Ptr<Node> neighborNode = neighborDevice->GetNode();
83 
84  int32_t ipv4NeighborInterfaceIndex = -1;
85  if (neighborNode->GetObject<Ipv4>())
86  {
87  ipv4NeighborInterfaceIndex =
88  neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
89  }
90  int32_t ipv6NeighborInterfaceIndex = -1;
91  if (neighborNode->GetObject<Ipv6>())
92  {
93  ipv6NeighborInterfaceIndex =
94  neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
95  }
96 
97  if (neighborDevice != netDevice)
98  {
99  if (ipv4InterfaceIndex != -1)
100  {
101  Ptr<Ipv4Interface> ipv4Interface =
102  node->GetObject<Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
103  if (ipv4NeighborInterfaceIndex != -1)
104  {
105  Ptr<Ipv4Interface> ipv4NeighborInterface =
106  neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(
107  ipv4NeighborInterfaceIndex);
108  PopulateNeighborEntriesIpv4(ipv4Interface, ipv4NeighborInterface);
109  }
110  }
111  if (ipv6InterfaceIndex != -1)
112  {
113  Ptr<Ipv6Interface> ipv6Interface =
114  node->GetObject<Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
115  if (ipv6NeighborInterfaceIndex != -1)
116  {
117  Ptr<Ipv6Interface> ipv6NeighborInterface =
118  neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(
119  ipv6NeighborInterfaceIndex);
120  PopulateNeighborEntriesIpv6(ipv6Interface, ipv6NeighborInterface);
121  }
122  }
123  }
124  }
125  }
126 }
127 
128 void
130 {
131  NS_LOG_FUNCTION(this);
132  for (uint32_t i = 0; i < c.GetN(); ++i)
133  {
134  Ptr<NetDevice> netDevice = c.Get(i);
135  Ptr<Channel> channel = netDevice->GetChannel();
136  Ptr<Node> node = netDevice->GetNode();
137 
138  int32_t ipv4InterfaceIndex = -1;
139  if (node->GetObject<Ipv4>())
140  {
141  ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
142  }
143  int32_t ipv6InterfaceIndex = -1;
144  if (node->GetObject<Ipv6>())
145  {
146  ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
147  }
148 
149  for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
150  {
151  Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
152  Ptr<Node> neighborNode = neighborDevice->GetNode();
153 
154  int32_t ipv4NeighborInterfaceIndex = -1;
155  if (neighborNode->GetObject<Ipv4>())
156  {
157  ipv4NeighborInterfaceIndex =
158  neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
159  }
160  int32_t ipv6NeighborInterfaceIndex = -1;
161  if (neighborNode->GetObject<Ipv6>())
162  {
163  ipv6NeighborInterfaceIndex =
164  neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
165  }
166 
167  if (neighborDevice != netDevice)
168  {
169  if (ipv4InterfaceIndex != -1)
170  {
171  Ptr<Ipv4Interface> ipv4Interface =
172  node->GetObject<Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
173  if (ipv4NeighborInterfaceIndex != -1)
174  {
175  Ptr<Ipv4Interface> ipv4NeighborInterface =
176  neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(
177  ipv4NeighborInterfaceIndex);
178  PopulateNeighborEntriesIpv4(ipv4Interface, ipv4NeighborInterface);
179  }
180  }
181  if (ipv6InterfaceIndex != -1)
182  {
183  Ptr<Ipv6Interface> ipv6Interface =
184  node->GetObject<Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
185  if (ipv6NeighborInterfaceIndex != -1)
186  {
187  Ptr<Ipv6Interface> ipv6NeighborInterface =
188  neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(
189  ipv6NeighborInterfaceIndex);
190  PopulateNeighborEntriesIpv6(ipv6Interface, ipv6NeighborInterface);
191  }
192  }
193  }
194  }
195  }
196 }
197 
198 void
200 {
201  NS_LOG_FUNCTION(this);
202  for (uint32_t i = 0; i < c.GetN(); ++i)
203  {
204  std::pair<Ptr<Ipv4>, uint32_t> returnValue = c.Get(i);
205  Ptr<Ipv4> ipv4 = returnValue.first;
206  uint32_t index = returnValue.second;
207  Ptr<Ipv4Interface> ipv4Interface = DynamicCast<Ipv4L3Protocol>(ipv4)->GetInterface(index);
208  if (ipv4Interface)
209  {
210  Ptr<NetDevice> netDevice = ipv4Interface->GetDevice();
211  Ptr<Channel> channel = netDevice->GetChannel();
212  for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
213  {
214  Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
215  if (neighborDevice != netDevice)
216  {
217  Ptr<Node> neighborNode = neighborDevice->GetNode();
218  int32_t ipv4NeighborInterfaceIndex =
219  neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
220  if (ipv4NeighborInterfaceIndex != -1)
221  {
222  Ptr<Ipv4Interface> ipv4NeighborInterface =
223  neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(
224  ipv4NeighborInterfaceIndex);
225  PopulateNeighborEntriesIpv4(ipv4Interface, ipv4NeighborInterface);
226  }
227  }
228  }
229  }
230  }
231 }
232 
233 void
235 {
236  NS_LOG_FUNCTION(this);
237  for (uint32_t i = 0; i < c.GetN(); ++i)
238  {
239  std::pair<Ptr<Ipv6>, uint32_t> returnValue = c.Get(i);
240  Ptr<Ipv6> ipv6 = returnValue.first;
241  uint32_t index = returnValue.second;
242  Ptr<Ipv6Interface> ipv6Interface = DynamicCast<Ipv6L3Protocol>(ipv6)->GetInterface(index);
243  if (ipv6Interface)
244  {
245  Ptr<NetDevice> netDevice = ipv6Interface->GetDevice();
246  Ptr<Channel> channel = netDevice->GetChannel();
247  for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
248  {
249  Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
250  if (neighborDevice != netDevice)
251  {
252  Ptr<Node> neighborNode = neighborDevice->GetNode();
253  int32_t ipv6NeighborInterfaceIndex =
254  neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
255  if (ipv6NeighborInterfaceIndex != -1)
256  {
257  Ptr<Ipv6Interface> ipv6NeighborInterface =
258  neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(
259  ipv6NeighborInterfaceIndex);
260  PopulateNeighborEntriesIpv6(ipv6Interface, ipv6NeighborInterface);
261  }
262  }
263  }
264  }
265  }
266 }
267 
268 void
270  Ptr<Ipv4Interface> neighborDeviceInterface) const
271 {
272  uint32_t netDeviceAddresses = ipv4Interface->GetNAddresses();
273  uint32_t neighborDeviceAddresses = neighborDeviceInterface->GetNAddresses();
275  {
276  ipv4Interface->RemoveAddressCallback(
279  {
280  ipv4Interface->AddAddressCallback(
282  }
283  }
284  for (uint32_t n = 0; n < netDeviceAddresses; ++n)
285  {
286  Ipv4InterfaceAddress netDeviceIfAddr = ipv4Interface->GetAddress(n);
287  for (uint32_t m = 0; m < neighborDeviceAddresses; ++m)
288  {
289  Ipv4InterfaceAddress neighborDeviceIfAddr = neighborDeviceInterface->GetAddress(m);
290  if (netDeviceIfAddr.IsInSameSubnet(neighborDeviceIfAddr.GetLocal()))
291  {
292  Ptr<NetDevice> neighborDevice = neighborDeviceInterface->GetDevice();
293  // Add Arp entry of neighbor interface to current interface's Arp cache
294  AddEntry(ipv4Interface,
295  neighborDeviceIfAddr.GetAddress(),
296  neighborDevice->GetAddress());
297  }
298  }
299  }
300 }
301 
302 void
304  Ptr<Ipv6Interface> neighborDeviceInterface) const
305 {
306  uint32_t netDeviceAddresses = ipv6Interface->GetNAddresses();
307  uint32_t neighborDeviceAddresses = neighborDeviceInterface->GetNAddresses();
309  {
310  ipv6Interface->RemoveAddressCallback(
313  {
314  ipv6Interface->AddAddressCallback(
316  }
317  }
318  for (uint32_t n = 0; n < netDeviceAddresses; ++n)
319  {
320  Ipv6InterfaceAddress netDeviceIfAddr = ipv6Interface->GetAddress(n);
321  // Ignore if it is a linklocal address, which will be added along with the global address
322  if (netDeviceIfAddr.GetScope() == Ipv6InterfaceAddress::LINKLOCAL ||
323  netDeviceIfAddr.GetScope() == Ipv6InterfaceAddress::HOST)
324  {
325  NS_LOG_LOGIC("Skip the LINKLOCAL or LOCALHOST interface " << netDeviceIfAddr);
326  continue;
327  }
328  for (uint32_t m = 0; m < neighborDeviceAddresses; ++m)
329  {
330  // Ignore if it is a linklocal address, which will be added along with the global
331  // address
332  Ipv6InterfaceAddress neighborDeviceIfAddr = neighborDeviceInterface->GetAddress(m);
333  if (neighborDeviceIfAddr.GetScope() == Ipv6InterfaceAddress::LINKLOCAL ||
334  neighborDeviceIfAddr.GetScope() == Ipv6InterfaceAddress::HOST)
335  {
336  NS_LOG_LOGIC("Skip the LINKLOCAL or LOCALHOST interface " << neighborDeviceIfAddr);
337  continue;
338  }
339  if (netDeviceIfAddr.IsInSameSubnet(neighborDeviceIfAddr.GetAddress()))
340  {
341  Ptr<NetDevice> neighborDevice = neighborDeviceInterface->GetDevice();
342  // Add neighbor's Ndisc entries of global address and linklocal address to current
343  // interface's Ndisc cache
344  AddEntry(ipv6Interface,
345  neighborDeviceIfAddr.GetAddress(),
346  neighborDevice->GetAddress());
347  Ipv6InterfaceAddress neighborlinkLocalAddr =
348  neighborDeviceInterface->GetLinkLocalAddress();
349  AddEntry(ipv6Interface,
350  neighborlinkLocalAddr.GetAddress(),
351  neighborDevice->GetAddress());
352  }
353  }
354  }
355 }
356 
357 void
359  Ipv4Address ipv4Address,
360  Address macAddress) const
361 {
362  NS_LOG_FUNCTION(this << netDeviceInterface << ipv4Address << macAddress);
363  Ptr<ArpCache> arpCache = netDeviceInterface->GetArpCache();
364  if (!arpCache)
365  {
366  NS_LOG_LOGIC(
367  "ArpCache doesn't exist, might be a point-to-point NetDevice without ArpCache");
368  return;
369  }
370  ArpCache::Entry* entry = arpCache->Lookup(ipv4Address);
371  if (!entry)
372  {
373  NS_LOG_FUNCTION("ADD an ARP entry");
374  entry = arpCache->Add(ipv4Address);
375  }
376  entry->SetMacAddress(macAddress);
377  entry->MarkAutoGenerated();
378 }
379 
380 void
382  Ipv6Address ipv6Address,
383  Address macAddress) const
384 {
385  NS_LOG_FUNCTION(this << netDeviceInterface << ipv6Address << macAddress);
386  Ptr<NdiscCache> ndiscCache = netDeviceInterface->GetNdiscCache();
387  if (!ndiscCache)
388  {
389  NS_LOG_LOGIC(
390  "NdiscCache doesn't exist, might be a point-to-point NetDevice without NdiscCache");
391  return;
392  }
393  NdiscCache::Entry* entry = ndiscCache->Lookup(ipv6Address);
394  if (!entry)
395  {
396  NS_LOG_FUNCTION("ADD a NDISC entry");
397  entry = ndiscCache->Add(ipv6Address);
398  }
399  entry->SetMacAddress(macAddress);
400  entry->MarkAutoGenerated();
401 }
402 
403 void
405 {
406  NS_LOG_FUNCTION(this);
407  for (uint32_t i = 0; i < NodeList::GetNNodes(); ++i)
408  {
409  Ptr<Node> node = NodeList::GetNode(i);
410  for (uint32_t j = 0; j < node->GetNDevices(); ++j)
411  {
412  Ptr<NetDevice> netDevice = node->GetDevice(j);
413  int32_t ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
414  int32_t ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
415  if (ipv4InterfaceIndex != -1)
416  {
417  Ptr<Ipv4Interface> ipv4Interface =
418  node->GetObject<Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
419  Ptr<ArpCache> arpCache = ipv4Interface->GetArpCache();
420  if (arpCache)
421  {
422  NS_LOG_FUNCTION("Remove an ARP entry");
423  arpCache->RemoveAutoGeneratedEntries();
424  }
425  }
426  if (ipv6InterfaceIndex != -1)
427  {
428  Ptr<Ipv6Interface> ipv6Interface =
429  node->GetObject<Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
430  Ptr<NdiscCache> ndiscCache = ipv6Interface->GetNdiscCache();
431  if (ndiscCache)
432  {
433  NS_LOG_FUNCTION("Remove a NDISC entry");
434  ndiscCache->RemoveAutoGeneratedEntries();
435  }
436  }
437  }
438  }
439 }
440 
441 void
443  const Ipv4InterfaceAddress ifAddr) const
444 {
445  NS_LOG_FUNCTION(this);
446  Ptr<NetDevice> netDevice = interface->GetDevice();
447  Ptr<Channel> channel = netDevice->GetChannel();
448  for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
449  {
450  Ptr<NetDevice> neighborDevice = channel->GetDevice(i);
451  Ptr<Node> neighborNode = neighborDevice->GetNode();
452  int32_t neighborInterfaceIndex =
453  neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
454  if (neighborInterfaceIndex != -1)
455  {
456  Ptr<Ipv4Interface> neighborInterface =
457  neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(neighborInterfaceIndex);
458  Ptr<ArpCache> arpCache = neighborInterface->GetArpCache();
459  if (!arpCache)
460  {
461  NS_LOG_LOGIC("ArpCache doesn't exist");
462  return;
463  }
464  ArpCache::Entry* entry = arpCache->Lookup(ifAddr.GetLocal());
465  if (entry)
466  {
467  arpCache->Remove(entry);
468  }
469  }
470  }
471 }
472 
473 void
475  const Ipv4InterfaceAddress ifAddr) const
476 {
477  NS_LOG_FUNCTION(this);
478  Ptr<NetDevice> netDevice = interface->GetDevice();
479  Ptr<Channel> channel = netDevice->GetChannel();
480  for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
481  {
482  Ptr<NetDevice> neighborDevice = channel->GetDevice(i);
483  if (neighborDevice != netDevice)
484  {
485  Ptr<Node> neighborNode = neighborDevice->GetNode();
486  int32_t neighborInterfaceIndex =
487  neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
488  if (neighborInterfaceIndex != -1)
489  {
490  Ptr<Ipv4Interface> neighborInterface =
491  neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(neighborInterfaceIndex);
492  uint32_t neighborDeviceAddresses = neighborInterface->GetNAddresses();
493  for (uint32_t m = 0; m < neighborDeviceAddresses; ++m)
494  {
495  Ipv4InterfaceAddress neighborDeviceIfAddr = neighborInterface->GetAddress(m);
496  if (ifAddr.IsInSameSubnet(neighborDeviceIfAddr.GetLocal()))
497  {
498  // Add Arp entity of current interface to its neighbor's Arp cache
499  AddEntry(neighborInterface, ifAddr.GetAddress(), netDevice->GetAddress());
500  }
501  }
502  }
503  }
504  }
505 }
506 
507 void
509  const Ipv6InterfaceAddress ifAddr) const
510 {
511  NS_LOG_FUNCTION(this);
512  Ptr<NetDevice> netDevice = interface->GetDevice();
513  Ptr<Channel> channel = netDevice->GetChannel();
514  for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
515  {
516  Ptr<NetDevice> neighborDevice = channel->GetDevice(i);
517  Ptr<Node> neighborNode = neighborDevice->GetNode();
518  int32_t neighborInterfaceIndex =
519  neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
520  if (neighborInterfaceIndex != -1)
521  {
522  Ptr<Ipv6Interface> neighborInterface =
523  neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(neighborInterfaceIndex);
524  Ptr<NdiscCache> ndiscCache = neighborInterface->GetNdiscCache();
525  if (!ndiscCache)
526  {
527  NS_LOG_LOGIC("ndiscCache doesn't exist");
528  return;
529  }
530  NdiscCache::Entry* entry = ndiscCache->Lookup(ifAddr.GetAddress());
531  if (entry)
532  {
533  ndiscCache->Remove(entry);
534  }
535  }
536  }
537 }
538 
539 void
541  const Ipv6InterfaceAddress ifAddr) const
542 {
543  NS_LOG_FUNCTION(this);
544  Ptr<NetDevice> netDevice = interface->GetDevice();
545  Ptr<Channel> channel = netDevice->GetChannel();
546  for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
547  {
548  Ptr<NetDevice> neighborDevice = channel->GetDevice(i);
549  if (neighborDevice != netDevice)
550  {
551  Ptr<Node> neighborNode = neighborDevice->GetNode();
552  int32_t neighborInterfaceIndex =
553  neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
554  if (neighborInterfaceIndex != -1)
555  {
556  Ptr<Ipv6Interface> neighborInterface =
557  neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(neighborInterfaceIndex);
558  uint32_t neighborDeviceAddresses = neighborInterface->GetNAddresses();
559  for (uint32_t m = 0; m < neighborDeviceAddresses; ++m)
560  {
561  Ipv6InterfaceAddress neighborDeviceIfAddr = neighborInterface->GetAddress(m);
562  if (ifAddr.IsInSameSubnet(neighborDeviceIfAddr.GetAddress()))
563  {
564  // Add Arp entity of current interface to its neighbor's Arp cache
565  AddEntry(neighborInterface, ifAddr.GetAddress(), netDevice->GetAddress());
566  }
567  }
568  }
569  }
570  }
571 }
572 
573 void
575 {
576  NS_LOG_FUNCTION(this);
577  m_dynamicNeighborCache = enable;
578 }
579 
580 } // namespace ns3
a polymophic address class
Definition: address.h:101
A record that that holds information about an ArpCache entry.
Definition: arp-cache.h:184
void MarkAutoGenerated()
Changes the state of this entry to auto-generated.
Definition: arp-cache.cc:457
void SetMacAddress(Address macAddress)
Definition: arp-cache.cc:506
void Remove(ArpCache::Entry *entry)
Remove an entry.
Definition: arp-cache.cc:364
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
Definition: arp-cache.cc:352
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
Definition: arp-cache.cc:340
void RemoveAutoGeneratedEntries()
Clear the ArpCache of all Auto-Generated entries.
Definition: arp-cache.cc:306
static Ptr< Channel > GetChannel(uint32_t n)
static uint32_t GetNChannels()
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:80
a class to store IPv4 address information on an interface
bool IsInSameSubnet(const Ipv4Address b) const
Checks if the address is in the same subnet.
Ipv4Address GetAddress() const
Get the local address.
Ipv4Address GetLocal() const
Get the local address.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index.
uint32_t GetNAddresses() const
void RemoveAddressCallback(Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > removeAddressCallback)
This callback is set when an address is removed from an interface with auto-generated Arp cache and i...
Ipv4InterfaceAddress GetAddress(uint32_t index) const
Ptr< ArpCache > GetArpCache() const
Ptr< NetDevice > GetDevice() const
void AddAddressCallback(Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > addAddressCallback)
This callback is set when an address is added from an interface with auto-generated Arp cache and it ...
Implement the IPv4 layer.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
IPv6 address associated with an interface.
Ipv6Address GetAddress() const
Get the IPv6 address.
Ipv6InterfaceAddress::Scope_e GetScope() const
Get address scope.
bool IsInSameSubnet(Ipv6Address b) const
Checks if the address is in the same subnet.
@ LINKLOCAL
Link-local address (fe80::/64)
Keep track of a set of IPv6 interfaces.
std::pair< Ptr< Ipv6 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv6> and interface stored at the location specified by the index.
Ipv6InterfaceAddress GetLinkLocalAddress() const
Get link-local address from IPv6 interface.
void RemoveAddressCallback(Callback< void, Ptr< Ipv6Interface >, Ipv6InterfaceAddress > removeAddressCallback)
This callback is set when an address is removed from an interface with auto-generated Ndisc cache and...
uint32_t GetNAddresses() const
Get number of addresses on this IPv6 interface.
Ipv6InterfaceAddress GetAddress(uint32_t index) const
Get an address from IPv6 interface.
Ptr< NdiscCache > GetNdiscCache() const
void AddAddressCallback(Callback< void, Ptr< Ipv6Interface >, Ipv6InterfaceAddress > addAddressCallback)
This callback is set when an address is added from an interface with auto-generated Ndisc cache and i...
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
IPv6 layer implementation.
A record that holds information about a NdiscCache entry.
Definition: ndisc-cache.h:167
void MarkAutoGenerated()
Changes the state of this entry to auto-generated.
Definition: ndisc-cache.cc:616
void SetMacAddress(Address mac)
Set the MAC address of this entry.
Definition: ndisc-cache.cc:680
virtual NdiscCache::Entry * Add(Ipv6Address to)
Add an entry.
Definition: ndisc-cache.cc:134
void Remove(NdiscCache::Entry *entry)
Delete an entry.
Definition: ndisc-cache.cc:146
virtual NdiscCache::Entry * Lookup(Ipv6Address dst)
Lookup in the cache.
Definition: ndisc-cache.cc:100
void RemoveAutoGeneratedEntries()
Clear the NDISC cache of all Auto-Generated entries.
Definition: ndisc-cache.cc:717
bool m_globalNeighborCache
flag will set true if neighbor caches were generated for all devices
void UpdateCacheByIpv6AddressAdded(const Ptr< Ipv6Interface > interface, const Ipv6InterfaceAddress ifAddr) const
Update neighbor cache when an address is added to a Ipv6Interface with auto generated neighbor cache.
void AddEntry(Ptr< Ipv4Interface > netDeviceInterface, Ipv4Address ipv4Address, Address macAddress) const
Add an auto_generated entry to the ARP cache of an interface.
void PopulateNeighborCache()
Populate neighbor ARP and NDISC caches for all devices.
bool m_dynamicNeighborCache
flag will set true if dynamic neighbor cache is enabled.
NeighborCacheHelper()
Construct a helper class to make life easier while creating neighbor cache.
void PopulateNeighborEntriesIpv4(Ptr< Ipv4Interface > ipv4Interface, Ptr< Ipv4Interface > neighborDeviceInterface) const
Populate neighbor ARP entries for given IPv4 interface.
void SetDynamicNeighborCache(bool enable)
Enable/disable dynamic neighbor cache, auto-generated neighbor cache will update by IP addresses chan...
void PopulateNeighborEntriesIpv6(Ptr< Ipv6Interface > ipv6Interface, Ptr< Ipv6Interface > neighborDeviceInterface) const
Populate neighbor NDISC entries for given IPv6 interface.
void UpdateCacheByIpv6AddressRemoved(const Ptr< Ipv6Interface > interface, const Ipv6InterfaceAddress ifAddr) const
Update neighbor caches when an address is removed from a Ipv6Interface with auto generated neighbor c...
void FlushAutoGenerated() const
Remove entries generated from NeighborCacheHelper from ARP cache and NDISC cache.
void UpdateCacheByIpv4AddressAdded(const Ptr< Ipv4Interface > interface, const Ipv4InterfaceAddress ifAddr) const
Update neighbor caches when an address is added to a Ipv4Interface with auto generated neighbor cache...
void UpdateCacheByIpv4AddressRemoved(const Ptr< Ipv4Interface > interface, const Ipv4InterfaceAddress ifAddr) const
Update neighbor caches when an address is removed from a Ipv4Interface with auto generated neighbor c...
holds a vector of ns3::NetDevice pointers
uint32_t GetN() const
Get the number of Ptr<NetDevice> stored in this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
uint32_t GetNDevices() const
Definition: node.cc:162
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:152
static uint32_t GetNNodes()
Definition: node-list.cc:258
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:251
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:704
channel
Definition: third.py:88