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 "ns3/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
32namespace ns3
33{
34
35NS_LOG_COMPONENT_DEFINE("NeighborCacheHelper");
36
38{
39 NS_LOG_FUNCTION(this);
40}
41
43{
44 NS_LOG_FUNCTION(this);
45}
46
47void
49{
50 NS_LOG_FUNCTION(this);
52 for (uint32_t i = 0; i < ChannelList::GetNChannels(); ++i)
53 {
56 }
57}
58
59void
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 int32_t ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
68 int32_t ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
69 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
70 {
71 Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
72 Ptr<Node> neighborNode = neighborDevice->GetNode();
73 int32_t ipv4NeighborInterfaceIndex =
74 neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
75 int32_t ipv6NeighborInterfaceIndex =
76 neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
77 if (neighborDevice != netDevice)
78 {
79 if (ipv4InterfaceIndex != -1)
80 {
81 Ptr<Ipv4Interface> ipv4Interface =
82 node->GetObject<Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
83 if (ipv4NeighborInterfaceIndex != -1)
84 {
85 Ptr<Ipv4Interface> ipv4NeighborInterface =
86 neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(
87 ipv4NeighborInterfaceIndex);
88 PopulateNeighborEntriesIpv4(ipv4Interface, ipv4NeighborInterface);
89 }
90 }
91 if (ipv6InterfaceIndex != -1)
92 {
93 Ptr<Ipv6Interface> ipv6Interface =
94 node->GetObject<Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
95 if (ipv6NeighborInterfaceIndex != -1)
96 {
97 Ptr<Ipv6Interface> ipv6NeighborInterface =
98 neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(
99 ipv6NeighborInterfaceIndex);
100 PopulateNeighborEntriesIpv6(ipv6Interface, ipv6NeighborInterface);
101 }
102 }
103 }
104 }
105 }
106}
107
108void
110{
111 NS_LOG_FUNCTION(this);
112 for (uint32_t i = 0; i < c.GetN(); ++i)
113 {
114 Ptr<NetDevice> netDevice = c.Get(i);
115 Ptr<Channel> channel = netDevice->GetChannel();
116 Ptr<Node> node = netDevice->GetNode();
117 int32_t ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
118 int32_t ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
119 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
120 {
121 Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
122 Ptr<Node> neighborNode = neighborDevice->GetNode();
123 int32_t ipv4NeighborInterfaceIndex =
124 neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
125 int32_t ipv6NeighborInterfaceIndex =
126 neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
127 if (neighborDevice != netDevice)
128 {
129 if (ipv4InterfaceIndex != -1)
130 {
131 Ptr<Ipv4Interface> ipv4Interface =
132 node->GetObject<Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
133 if (ipv4NeighborInterfaceIndex != -1)
134 {
135 Ptr<Ipv4Interface> ipv4NeighborInterface =
136 neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(
137 ipv4NeighborInterfaceIndex);
138 PopulateNeighborEntriesIpv4(ipv4Interface, ipv4NeighborInterface);
139 }
140 }
141 if (ipv6InterfaceIndex != -1)
142 {
143 Ptr<Ipv6Interface> ipv6Interface =
144 node->GetObject<Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
145 if (ipv6NeighborInterfaceIndex != -1)
146 {
147 Ptr<Ipv6Interface> ipv6NeighborInterface =
148 neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(
149 ipv6NeighborInterfaceIndex);
150 PopulateNeighborEntriesIpv6(ipv6Interface, ipv6NeighborInterface);
151 }
152 }
153 }
154 }
155 }
156}
157
158void
160{
161 NS_LOG_FUNCTION(this);
162 for (uint32_t i = 0; i < c.GetN(); ++i)
163 {
164 std::pair<Ptr<Ipv4>, uint32_t> returnValue = c.Get(i);
165 Ptr<Ipv4> ipv4 = returnValue.first;
166 uint32_t index = returnValue.second;
167 Ptr<Ipv4Interface> ipv4Interface = DynamicCast<Ipv4L3Protocol>(ipv4)->GetInterface(index);
168 if (ipv4Interface)
169 {
170 Ptr<NetDevice> netDevice = ipv4Interface->GetDevice();
171 Ptr<Channel> channel = netDevice->GetChannel();
172 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
173 {
174 Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
175 if (neighborDevice != netDevice)
176 {
177 Ptr<Node> neighborNode = neighborDevice->GetNode();
178 int32_t ipv4NeighborInterfaceIndex =
179 neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
180 if (ipv4NeighborInterfaceIndex != -1)
181 {
182 Ptr<Ipv4Interface> ipv4NeighborInterface =
183 neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(
184 ipv4NeighborInterfaceIndex);
185 PopulateNeighborEntriesIpv4(ipv4Interface, ipv4NeighborInterface);
186 }
187 }
188 }
189 }
190 }
191}
192
193void
195{
196 NS_LOG_FUNCTION(this);
197 for (uint32_t i = 0; i < c.GetN(); ++i)
198 {
199 std::pair<Ptr<Ipv6>, uint32_t> returnValue = c.Get(i);
200 Ptr<Ipv6> ipv6 = returnValue.first;
201 uint32_t index = returnValue.second;
202 Ptr<Ipv6Interface> ipv6Interface = DynamicCast<Ipv6L3Protocol>(ipv6)->GetInterface(index);
203 if (ipv6Interface)
204 {
205 Ptr<NetDevice> netDevice = ipv6Interface->GetDevice();
206 Ptr<Channel> channel = netDevice->GetChannel();
207 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
208 {
209 Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
210 if (neighborDevice != netDevice)
211 {
212 Ptr<Node> neighborNode = neighborDevice->GetNode();
213 int32_t ipv6NeighborInterfaceIndex =
214 neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
215 if (ipv6NeighborInterfaceIndex != -1)
216 {
217 Ptr<Ipv6Interface> ipv6NeighborInterface =
218 neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(
219 ipv6NeighborInterfaceIndex);
220 PopulateNeighborEntriesIpv6(ipv6Interface, ipv6NeighborInterface);
221 }
222 }
223 }
224 }
225 }
226}
227
228void
230 Ptr<Ipv4Interface> neighborDeviceInterface) const
231{
232 uint32_t netDeviceAddresses = ipv4Interface->GetNAddresses();
233 uint32_t neighborDeviceAddresses = neighborDeviceInterface->GetNAddresses();
235 {
236 ipv4Interface->RemoveAddressCallback(
239 {
240 ipv4Interface->AddAddressCallback(
242 }
243 }
244 for (uint32_t n = 0; n < netDeviceAddresses; ++n)
245 {
246 Ipv4InterfaceAddress netDeviceIfAddr = ipv4Interface->GetAddress(n);
247 for (uint32_t m = 0; m < neighborDeviceAddresses; ++m)
248 {
249 Ipv4InterfaceAddress neighborDeviceIfAddr = neighborDeviceInterface->GetAddress(m);
250 if (netDeviceIfAddr.IsInSameSubnet(neighborDeviceIfAddr.GetLocal()))
251 {
252 Ptr<NetDevice> neighborDevice = neighborDeviceInterface->GetDevice();
253 // Add Arp entry of neighbor interface to current interface's Arp cache
254 AddEntry(ipv4Interface,
255 neighborDeviceIfAddr.GetAddress(),
256 neighborDevice->GetAddress());
257 }
258 }
259 }
260}
261
262void
264 Ptr<Ipv6Interface> neighborDeviceInterface) const
265{
266 uint32_t netDeviceAddresses = ipv6Interface->GetNAddresses();
267 uint32_t neighborDeviceAddresses = neighborDeviceInterface->GetNAddresses();
269 {
270 ipv6Interface->RemoveAddressCallback(
273 {
274 ipv6Interface->AddAddressCallback(
276 }
277 }
278 for (uint32_t n = 0; n < netDeviceAddresses; ++n)
279 {
280 Ipv6InterfaceAddress netDeviceIfAddr = ipv6Interface->GetAddress(n);
281 // Ignore if it is a linklocal address, which will be added along with the global address
282 if (netDeviceIfAddr.GetScope() == Ipv6InterfaceAddress::LINKLOCAL ||
283 netDeviceIfAddr.GetScope() == Ipv6InterfaceAddress::HOST)
284 {
285 NS_LOG_LOGIC("Skip the LINKLOCAL or LOCALHOST interface " << netDeviceIfAddr);
286 continue;
287 }
288 for (uint32_t m = 0; m < neighborDeviceAddresses; ++m)
289 {
290 // Ignore if it is a linklocal address, which will be added along with the global
291 // address
292 Ipv6InterfaceAddress neighborDeviceIfAddr = neighborDeviceInterface->GetAddress(m);
293 if (neighborDeviceIfAddr.GetScope() == Ipv6InterfaceAddress::LINKLOCAL ||
294 neighborDeviceIfAddr.GetScope() == Ipv6InterfaceAddress::HOST)
295 {
296 NS_LOG_LOGIC("Skip the LINKLOCAL or LOCALHOST interface " << neighborDeviceIfAddr);
297 continue;
298 }
299 if (netDeviceIfAddr.IsInSameSubnet(neighborDeviceIfAddr.GetAddress()))
300 {
301 Ptr<NetDevice> neighborDevice = neighborDeviceInterface->GetDevice();
302 // Add neighbor's Ndisc entries of global address and linklocal address to current
303 // interface's Ndisc cache
304 AddEntry(ipv6Interface,
305 neighborDeviceIfAddr.GetAddress(),
306 neighborDevice->GetAddress());
307 Ipv6InterfaceAddress neighborlinkLocalAddr =
308 neighborDeviceInterface->GetLinkLocalAddress();
309 AddEntry(ipv6Interface,
310 neighborlinkLocalAddr.GetAddress(),
311 neighborDevice->GetAddress());
312 }
313 }
314 }
315}
316
317void
319 Ipv4Address ipv4Address,
320 Address macAddress) const
321{
322 NS_LOG_FUNCTION(this << netDeviceInterface << ipv4Address << macAddress);
323 Ptr<ArpCache> arpCache = netDeviceInterface->GetArpCache();
324 if (!arpCache)
325 {
327 "ArpCache doesn't exist, might be a point-to-point NetDevice without ArpCache");
328 return;
329 }
330 ArpCache::Entry* entry = arpCache->Lookup(ipv4Address);
331 if (!entry)
332 {
333 NS_LOG_FUNCTION("ADD an ARP entry");
334 entry = arpCache->Add(ipv4Address);
335 }
336 entry->SetMacAddress(macAddress);
337 entry->MarkAutoGenerated();
338}
339
340void
342 Ipv6Address ipv6Address,
343 Address macAddress) const
344{
345 NS_LOG_FUNCTION(this << netDeviceInterface << ipv6Address << macAddress);
346 Ptr<NdiscCache> ndiscCache = netDeviceInterface->GetNdiscCache();
347 if (!ndiscCache)
348 {
350 "NdiscCache doesn't exist, might be a point-to-point NetDevice without NdiscCache");
351 return;
352 }
353 NdiscCache::Entry* entry = ndiscCache->Lookup(ipv6Address);
354 if (!entry)
355 {
356 NS_LOG_FUNCTION("ADD a NDISC entry");
357 entry = ndiscCache->Add(ipv6Address);
358 }
359 entry->SetMacAddress(macAddress);
360 entry->MarkAutoGenerated();
361}
362
363void
365{
366 NS_LOG_FUNCTION(this);
367 for (uint32_t i = 0; i < NodeList::GetNNodes(); ++i)
368 {
370 for (uint32_t j = 0; j < node->GetNDevices(); ++j)
371 {
372 Ptr<NetDevice> netDevice = node->GetDevice(j);
373 int32_t ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
374 int32_t ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
375 if (ipv4InterfaceIndex != -1)
376 {
377 Ptr<Ipv4Interface> ipv4Interface =
378 node->GetObject<Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
379 Ptr<ArpCache> arpCache = ipv4Interface->GetArpCache();
380 if (arpCache)
381 {
382 NS_LOG_FUNCTION("Remove an ARP entry");
383 arpCache->RemoveAutoGeneratedEntries();
384 }
385 }
386 if (ipv6InterfaceIndex != -1)
387 {
388 Ptr<Ipv6Interface> ipv6Interface =
389 node->GetObject<Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
390 Ptr<NdiscCache> ndiscCache = ipv6Interface->GetNdiscCache();
391 if (ndiscCache)
392 {
393 NS_LOG_FUNCTION("Remove a NDISC entry");
394 ndiscCache->RemoveAutoGeneratedEntries();
395 }
396 }
397 }
398 }
399}
400
401void
403 const Ipv4InterfaceAddress ifAddr) const
404{
405 NS_LOG_FUNCTION(this);
406 Ptr<NetDevice> netDevice = interface->GetDevice();
407 Ptr<Channel> channel = netDevice->GetChannel();
408 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
409 {
410 Ptr<NetDevice> neighborDevice = channel->GetDevice(i);
411 Ptr<Node> neighborNode = neighborDevice->GetNode();
412 int32_t neighborInterfaceIndex =
413 neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
414 if (neighborInterfaceIndex != -1)
415 {
416 Ptr<Ipv4Interface> neighborInterface =
417 neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(neighborInterfaceIndex);
418 Ptr<ArpCache> arpCache = neighborInterface->GetArpCache();
419 if (!arpCache)
420 {
421 NS_LOG_LOGIC("ArpCache doesn't exist");
422 return;
423 }
424 ArpCache::Entry* entry = arpCache->Lookup(ifAddr.GetLocal());
425 if (entry)
426 {
427 arpCache->Remove(entry);
428 }
429 }
430 }
431}
432
433void
435 const Ipv4InterfaceAddress ifAddr) const
436{
437 NS_LOG_FUNCTION(this);
438 Ptr<NetDevice> netDevice = interface->GetDevice();
439 Ptr<Channel> channel = netDevice->GetChannel();
440 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
441 {
442 Ptr<NetDevice> neighborDevice = channel->GetDevice(i);
443 if (neighborDevice != netDevice)
444 {
445 Ptr<Node> neighborNode = neighborDevice->GetNode();
446 int32_t neighborInterfaceIndex =
447 neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
448 if (neighborInterfaceIndex != -1)
449 {
450 Ptr<Ipv4Interface> neighborInterface =
451 neighborNode->GetObject<Ipv4L3Protocol>()->GetInterface(neighborInterfaceIndex);
452 uint32_t neighborDeviceAddresses = neighborInterface->GetNAddresses();
453 for (uint32_t m = 0; m < neighborDeviceAddresses; ++m)
454 {
455 Ipv4InterfaceAddress neighborDeviceIfAddr = neighborInterface->GetAddress(m);
456 if (ifAddr.IsInSameSubnet(neighborDeviceIfAddr.GetLocal()))
457 {
458 // Add Arp entity of current interface to its neighbor's Arp cache
459 AddEntry(neighborInterface, ifAddr.GetAddress(), netDevice->GetAddress());
460 }
461 }
462 }
463 }
464 }
465}
466
467void
469 const Ipv6InterfaceAddress ifAddr) const
470{
471 NS_LOG_FUNCTION(this);
472 Ptr<NetDevice> netDevice = interface->GetDevice();
473 Ptr<Channel> channel = netDevice->GetChannel();
474 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
475 {
476 Ptr<NetDevice> neighborDevice = channel->GetDevice(i);
477 Ptr<Node> neighborNode = neighborDevice->GetNode();
478 int32_t neighborInterfaceIndex =
479 neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
480 if (neighborInterfaceIndex != -1)
481 {
482 Ptr<Ipv6Interface> neighborInterface =
483 neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(neighborInterfaceIndex);
484 Ptr<NdiscCache> ndiscCache = neighborInterface->GetNdiscCache();
485 if (!ndiscCache)
486 {
487 NS_LOG_LOGIC("ndiscCache doesn't exist");
488 return;
489 }
490 NdiscCache::Entry* entry = ndiscCache->Lookup(ifAddr.GetAddress());
491 if (entry)
492 {
493 ndiscCache->Remove(entry);
494 }
495 }
496 }
497}
498
499void
501 const Ipv6InterfaceAddress ifAddr) const
502{
503 NS_LOG_FUNCTION(this);
504 Ptr<NetDevice> netDevice = interface->GetDevice();
505 Ptr<Channel> channel = netDevice->GetChannel();
506 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
507 {
508 Ptr<NetDevice> neighborDevice = channel->GetDevice(i);
509 if (neighborDevice != netDevice)
510 {
511 Ptr<Node> neighborNode = neighborDevice->GetNode();
512 int32_t neighborInterfaceIndex =
513 neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
514 if (neighborInterfaceIndex != -1)
515 {
516 Ptr<Ipv6Interface> neighborInterface =
517 neighborNode->GetObject<Ipv6L3Protocol>()->GetInterface(neighborInterfaceIndex);
518 uint32_t neighborDeviceAddresses = neighborInterface->GetNAddresses();
519 for (uint32_t m = 0; m < neighborDeviceAddresses; ++m)
520 {
521 Ipv6InterfaceAddress neighborDeviceIfAddr = neighborInterface->GetAddress(m);
522 if (ifAddr.IsInSameSubnet(neighborDeviceIfAddr.GetAddress()))
523 {
524 // Add Arp entity of current interface to its neighbor's Arp cache
525 AddEntry(neighborInterface, ifAddr.GetAddress(), netDevice->GetAddress());
526 }
527 }
528 }
529 }
530 }
531}
532
533void
535{
536 NS_LOG_FUNCTION(this);
537 m_dynamicNeighborCache = enable;
538}
539
540} // namespace ns3
a polymophic address class
Definition: address.h:92
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:458
void SetMacAddress(Address macAddress)
Definition: arp-cache.cc:507
void Remove(ArpCache::Entry *entry)
Remove an entry.
Definition: arp-cache.cc:365
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
Definition: arp-cache.cc:353
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
Definition: arp-cache.cc:341
void RemoveAutoGeneratedEntries()
Clear the ArpCache of all Auto-Generated entries.
Definition: arp-cache.cc:307
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:43
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:79
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:50
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/diable dynamic neighbor cache, auto-generated neighbor cache will update by IP addresses chang...
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:691
channel
Definition: third.py:81