11#include "ns3/assert.h"
12#include "ns3/channel-list.h"
16#include "ns3/net-device.h"
19#include "ns3/simulator.h"
52 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
57 int32_t ipv4InterfaceIndex = -1;
58 if (node->GetObject<
Ipv4>())
60 ipv4InterfaceIndex = node->GetObject<
Ipv4>()->GetInterfaceForDevice(netDevice);
62 int32_t ipv6InterfaceIndex = -1;
63 if (node->GetObject<
Ipv6>())
65 ipv6InterfaceIndex = node->GetObject<
Ipv6>()->GetInterfaceForDevice(netDevice);
68 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
71 Ptr<Node> neighborNode = neighborDevice->GetNode();
73 int32_t ipv4NeighborInterfaceIndex = -1;
74 if (neighborNode->GetObject<
Ipv4>())
76 ipv4NeighborInterfaceIndex =
77 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
79 int32_t ipv6NeighborInterfaceIndex = -1;
80 if (neighborNode->GetObject<
Ipv6>())
82 ipv6NeighborInterfaceIndex =
83 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
86 if (neighborDevice != netDevice)
88 if (ipv4InterfaceIndex != -1)
91 node->GetObject<
Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
92 if (ipv4NeighborInterfaceIndex != -1)
96 ipv4NeighborInterfaceIndex);
100 if (ipv6InterfaceIndex != -1)
103 node->GetObject<
Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
104 if (ipv6NeighborInterfaceIndex != -1)
108 ipv6NeighborInterfaceIndex);
127 int32_t ipv4InterfaceIndex = -1;
128 if (node->GetObject<
Ipv4>())
130 ipv4InterfaceIndex = node->GetObject<
Ipv4>()->GetInterfaceForDevice(netDevice);
132 int32_t ipv6InterfaceIndex = -1;
133 if (node->GetObject<
Ipv6>())
135 ipv6InterfaceIndex = node->GetObject<
Ipv6>()->GetInterfaceForDevice(netDevice);
138 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
141 Ptr<Node> neighborNode = neighborDevice->GetNode();
143 int32_t ipv4NeighborInterfaceIndex = -1;
144 if (neighborNode->GetObject<
Ipv4>())
146 ipv4NeighborInterfaceIndex =
147 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
149 int32_t ipv6NeighborInterfaceIndex = -1;
150 if (neighborNode->GetObject<
Ipv6>())
152 ipv6NeighborInterfaceIndex =
153 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
156 if (neighborDevice != netDevice)
158 if (ipv4InterfaceIndex != -1)
161 node->GetObject<
Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
162 if (ipv4NeighborInterfaceIndex != -1)
166 ipv4NeighborInterfaceIndex);
170 if (ipv6InterfaceIndex != -1)
173 node->GetObject<
Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
174 if (ipv6NeighborInterfaceIndex != -1)
178 ipv6NeighborInterfaceIndex);
193 std::pair<Ptr<Ipv4>,
uint32_t> returnValue = c.
Get(i);
195 uint32_t index = returnValue.second;
201 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
204 if (neighborDevice != netDevice)
206 Ptr<Node> neighborNode = neighborDevice->GetNode();
207 int32_t ipv4NeighborInterfaceIndex =
208 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
209 if (ipv4NeighborInterfaceIndex != -1)
213 ipv4NeighborInterfaceIndex);
228 std::pair<Ptr<Ipv6>,
uint32_t> returnValue = c.
Get(i);
230 uint32_t index = returnValue.second;
236 for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
239 if (neighborDevice != netDevice)
241 Ptr<Node> neighborNode = neighborDevice->GetNode();
242 int32_t ipv6NeighborInterfaceIndex =
243 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
244 if (ipv6NeighborInterfaceIndex != -1)
248 ipv6NeighborInterfaceIndex);
261 uint32_t netDeviceAddresses = ipv4Interface->GetNAddresses();
262 uint32_t neighborDeviceAddresses = neighborDeviceInterface->GetNAddresses();
265 ipv4Interface->RemoveAddressCallback(
269 ipv4Interface->AddAddressCallback(
273 for (
uint32_t n = 0; n < netDeviceAddresses; ++n)
276 for (
uint32_t m = 0; m < neighborDeviceAddresses; ++m)
281 Ptr<NetDevice> neighborDevice = neighborDeviceInterface->GetDevice();
285 neighborDevice->GetAddress());
295 uint32_t netDeviceAddresses = ipv6Interface->GetNAddresses();
296 uint32_t neighborDeviceAddresses = neighborDeviceInterface->GetNAddresses();
299 ipv6Interface->RemoveAddressCallback(
303 ipv6Interface->AddAddressCallback(
307 for (
uint32_t n = 0; n < netDeviceAddresses; ++n)
314 NS_LOG_LOGIC(
"Skip the LINKLOCAL or LOCALHOST interface " << netDeviceIfAddr);
317 for (
uint32_t m = 0; m < neighborDeviceAddresses; ++m)
325 NS_LOG_LOGIC(
"Skip the LINKLOCAL or LOCALHOST interface " << neighborDeviceIfAddr);
330 Ptr<NetDevice> neighborDevice = neighborDeviceInterface->GetDevice();
335 neighborDevice->GetAddress());
337 neighborDeviceInterface->GetLinkLocalAddress();
340 neighborDevice->GetAddress());
351 NS_LOG_FUNCTION(
this << netDeviceInterface << ipv4Address << macAddress);
356 "ArpCache doesn't exist, might be a point-to-point NetDevice without ArpCache");
363 entry = arpCache->Add(ipv4Address);
374 NS_LOG_FUNCTION(
this << netDeviceInterface << ipv6Address << macAddress);
379 "NdiscCache doesn't exist, might be a point-to-point NetDevice without NdiscCache");
386 entry = ndiscCache->Add(ipv6Address);
399 for (
uint32_t j = 0; j < node->GetNDevices(); ++j)
402 int32_t ipv4InterfaceIndex = node->GetObject<
Ipv4>()->GetInterfaceForDevice(netDevice);
403 int32_t ipv6InterfaceIndex = node->GetObject<
Ipv6>()->GetInterfaceForDevice(netDevice);
404 if (ipv4InterfaceIndex != -1)
407 node->GetObject<
Ipv4L3Protocol>()->GetInterface(ipv4InterfaceIndex);
412 arpCache->RemoveAutoGeneratedEntries();
415 if (ipv6InterfaceIndex != -1)
418 node->GetObject<
Ipv6L3Protocol>()->GetInterface(ipv6InterfaceIndex);
423 ndiscCache->RemoveAutoGeneratedEntries();
437 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
440 Ptr<Node> neighborNode = neighborDevice->GetNode();
441 int32_t neighborInterfaceIndex =
442 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
443 if (neighborInterfaceIndex != -1)
446 neighborNode->GetObject<
Ipv4L3Protocol>()->GetInterface(neighborInterfaceIndex);
456 arpCache->Remove(entry);
469 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
472 if (neighborDevice != netDevice)
474 Ptr<Node> neighborNode = neighborDevice->GetNode();
475 int32_t neighborInterfaceIndex =
476 neighborNode->GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
477 if (neighborInterfaceIndex != -1)
480 neighborNode->GetObject<
Ipv4L3Protocol>()->GetInterface(neighborInterfaceIndex);
481 uint32_t neighborDeviceAddresses = neighborInterface->GetNAddresses();
482 for (
uint32_t m = 0; m < neighborDeviceAddresses; ++m)
503 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
506 Ptr<Node> neighborNode = neighborDevice->GetNode();
507 int32_t neighborInterfaceIndex =
508 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
509 if (neighborInterfaceIndex != -1)
512 neighborNode->GetObject<
Ipv6L3Protocol>()->GetInterface(neighborInterfaceIndex);
522 ndiscCache->Remove(entry);
535 for (std::size_t i = 0; i < channel->GetNDevices(); ++i)
538 if (neighborDevice != netDevice)
540 Ptr<Node> neighborNode = neighborDevice->GetNode();
541 int32_t neighborInterfaceIndex =
542 neighborNode->GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
543 if (neighborInterfaceIndex != -1)
546 neighborNode->GetObject<
Ipv6L3Protocol>()->GetInterface(neighborInterfaceIndex);
547 uint32_t neighborDeviceAddresses = neighborInterface->GetNAddresses();
548 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...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.