22#include "ns3/assert.h"
23#include "ns3/channel-list.h"
27#include "ns3/net-device.h"
30#include "ns3/simulator.h"
63 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
68 int32_t ipv4InterfaceIndex = -1;
69 if (node->GetObject<
Ipv4>())
71 ipv4InterfaceIndex = node->GetObject<
Ipv4>()->GetInterfaceForDevice(netDevice);
73 int32_t ipv6InterfaceIndex = -1;
74 if (node->GetObject<
Ipv6>())
76 ipv6InterfaceIndex = node->GetObject<
Ipv6>()->GetInterfaceForDevice(netDevice);
79 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
82 Ptr<Node> neighborNode = neighborDevice->GetNode();
84 int32_t ipv4NeighborInterfaceIndex = -1;
85 if (neighborNode->GetObject<
Ipv4>())
87 ipv4NeighborInterfaceIndex =
88 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
90 int32_t ipv6NeighborInterfaceIndex = -1;
91 if (neighborNode->GetObject<
Ipv6>())
93 ipv6NeighborInterfaceIndex =
94 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
97 if (neighborDevice != netDevice)
99 if (ipv4InterfaceIndex != -1)
102 node->GetObject<
Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
103 if (ipv4NeighborInterfaceIndex != -1)
107 ipv4NeighborInterfaceIndex);
111 if (ipv6InterfaceIndex != -1)
114 node->GetObject<
Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
115 if (ipv6NeighborInterfaceIndex != -1)
119 ipv6NeighborInterfaceIndex);
138 int32_t ipv4InterfaceIndex = -1;
139 if (node->GetObject<
Ipv4>())
141 ipv4InterfaceIndex = node->GetObject<
Ipv4>()->GetInterfaceForDevice(netDevice);
143 int32_t ipv6InterfaceIndex = -1;
144 if (node->GetObject<
Ipv6>())
146 ipv6InterfaceIndex = node->GetObject<
Ipv6>()->GetInterfaceForDevice(netDevice);
149 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
152 Ptr<Node> neighborNode = neighborDevice->GetNode();
154 int32_t ipv4NeighborInterfaceIndex = -1;
155 if (neighborNode->GetObject<
Ipv4>())
157 ipv4NeighborInterfaceIndex =
158 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
160 int32_t ipv6NeighborInterfaceIndex = -1;
161 if (neighborNode->GetObject<
Ipv6>())
163 ipv6NeighborInterfaceIndex =
164 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
167 if (neighborDevice != netDevice)
169 if (ipv4InterfaceIndex != -1)
172 node->GetObject<
Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
173 if (ipv4NeighborInterfaceIndex != -1)
177 ipv4NeighborInterfaceIndex);
181 if (ipv6InterfaceIndex != -1)
184 node->GetObject<
Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
185 if (ipv6NeighborInterfaceIndex != -1)
189 ipv6NeighborInterfaceIndex);
204 std::pair<Ptr<Ipv4>,
uint32_t> returnValue = c.
Get(i);
206 uint32_t index = returnValue.second;
207 Ptr<Ipv4Interface> ipv4Interface = DynamicCast<Ipv4L3Protocol>(ipv4)->GetInterface(index);
212 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
215 if (neighborDevice != netDevice)
217 Ptr<Node> neighborNode = neighborDevice->GetNode();
218 int32_t ipv4NeighborInterfaceIndex =
219 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
220 if (ipv4NeighborInterfaceIndex != -1)
224 ipv4NeighborInterfaceIndex);
239 std::pair<Ptr<Ipv6>,
uint32_t> returnValue = c.
Get(i);
241 uint32_t index = returnValue.second;
242 Ptr<Ipv6Interface> ipv6Interface = DynamicCast<Ipv6L3Protocol>(ipv6)->GetInterface(index);
247 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
250 if (neighborDevice != netDevice)
252 Ptr<Node> neighborNode = neighborDevice->GetNode();
253 int32_t ipv6NeighborInterfaceIndex =
254 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
255 if (ipv6NeighborInterfaceIndex != -1)
259 ipv6NeighborInterfaceIndex);
272 uint32_t netDeviceAddresses = ipv4Interface->GetNAddresses();
273 uint32_t neighborDeviceAddresses = neighborDeviceInterface->GetNAddresses();
276 ipv4Interface->RemoveAddressCallback(
280 ipv4Interface->AddAddressCallback(
284 for (
uint32_t n = 0; n < netDeviceAddresses; ++n)
287 for (
uint32_t m = 0; m < neighborDeviceAddresses; ++m)
292 Ptr<NetDevice> neighborDevice = neighborDeviceInterface->GetDevice();
296 neighborDevice->GetAddress());
306 uint32_t netDeviceAddresses = ipv6Interface->GetNAddresses();
307 uint32_t neighborDeviceAddresses = neighborDeviceInterface->GetNAddresses();
310 ipv6Interface->RemoveAddressCallback(
314 ipv6Interface->AddAddressCallback(
318 for (
uint32_t n = 0; n < netDeviceAddresses; ++n)
325 NS_LOG_LOGIC(
"Skip the LINKLOCAL or LOCALHOST interface " << netDeviceIfAddr);
328 for (
uint32_t m = 0; m < neighborDeviceAddresses; ++m)
336 NS_LOG_LOGIC(
"Skip the LINKLOCAL or LOCALHOST interface " << neighborDeviceIfAddr);
341 Ptr<NetDevice> neighborDevice = neighborDeviceInterface->GetDevice();
346 neighborDevice->GetAddress());
348 neighborDeviceInterface->GetLinkLocalAddress();
351 neighborDevice->GetAddress());
362 NS_LOG_FUNCTION(
this << netDeviceInterface << ipv4Address << macAddress);
367 "ArpCache doesn't exist, might be a point-to-point NetDevice without ArpCache");
374 entry = arpCache->Add(ipv4Address);
385 NS_LOG_FUNCTION(
this << netDeviceInterface << ipv6Address << macAddress);
390 "NdiscCache doesn't exist, might be a point-to-point NetDevice without NdiscCache");
397 entry = ndiscCache->Add(ipv6Address);
410 for (
uint32_t j = 0; j < node->GetNDevices(); ++j)
413 int32_t ipv4InterfaceIndex = node->GetObject<
Ipv4>()->GetInterfaceForDevice(netDevice);
414 int32_t ipv6InterfaceIndex = node->GetObject<
Ipv6>()->GetInterfaceForDevice(netDevice);
415 if (ipv4InterfaceIndex != -1)
418 node->GetObject<
Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
423 arpCache->RemoveAutoGeneratedEntries();
426 if (ipv6InterfaceIndex != -1)
429 node->GetObject<
Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
434 ndiscCache->RemoveAutoGeneratedEntries();
448 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
451 Ptr<Node> neighborNode = neighborDevice->GetNode();
452 int32_t neighborInterfaceIndex =
453 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
454 if (neighborInterfaceIndex != -1)
457 neighborNode->GetObject<
Ipv4L3Protocol>()->GetInterface(neighborInterfaceIndex);
467 arpCache->Remove(entry);
480 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
483 if (neighborDevice != netDevice)
485 Ptr<Node> neighborNode = neighborDevice->GetNode();
486 int32_t neighborInterfaceIndex =
487 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
488 if (neighborInterfaceIndex != -1)
491 neighborNode->GetObject<
Ipv4L3Protocol>()->GetInterface(neighborInterfaceIndex);
492 uint32_t neighborDeviceAddresses = neighborInterface->GetNAddresses();
493 for (
uint32_t m = 0; m < neighborDeviceAddresses; ++m)
514 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
517 Ptr<Node> neighborNode = neighborDevice->GetNode();
518 int32_t neighborInterfaceIndex =
519 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
520 if (neighborInterfaceIndex != -1)
523 neighborNode->GetObject<
Ipv6L3Protocol>()->GetInterface(neighborInterfaceIndex);
533 ndiscCache->Remove(entry);
546 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
549 if (neighborDevice != netDevice)
551 Ptr<Node> neighborNode = neighborDevice->GetNode();
552 int32_t neighborInterfaceIndex =
553 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
554 if (neighborInterfaceIndex != -1)
557 neighborNode->GetObject<
Ipv6L3Protocol>()->GetInterface(neighborInterfaceIndex);
558 uint32_t neighborDeviceAddresses = neighborInterface->GetNAddresses();
559 for (
uint32_t m = 0; m < neighborDeviceAddresses; ++m)
a polymophic address class
A record that that holds information about an ArpCache entry.
void MarkAutoGenerated()
Changes the state of this entry to auto-generated.
void SetMacAddress(Address macAddress)
static Ptr< Channel > GetChannel(uint32_t n)
static uint32_t GetNChannels()
Ipv4 addresses are stored in host order in this class.
Access to the IPv4 forwarding table, interfaces, and configuration.
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.
Implement the IPv4 layer.
Describes an IPv6 address.
Access to the IPv6 forwarding table, interfaces, and configuration.
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)
@ HOST
Localhost (::1/128)
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.
IPv6 layer implementation.
A record that holds information about a NdiscCache entry.
void MarkAutoGenerated()
Changes the state of this entry to auto-generated.
void SetMacAddress(Address mac)
Set the MAC address of this entry.
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.
static uint32_t GetNNodes()
static Ptr< Node > GetNode(uint32_t n)
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#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...