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;
71 ipv4InterfaceIndex = node->
GetObject<
Ipv4>()->GetInterfaceForDevice(netDevice);
73 int32_t ipv6InterfaceIndex = -1;
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;
87 ipv4NeighborInterfaceIndex =
88 neighborNode->
GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
90 int32_t ipv6NeighborInterfaceIndex = -1;
93 ipv6NeighborInterfaceIndex =
94 neighborNode->
GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
97 if (neighborDevice != netDevice)
99 if (ipv4InterfaceIndex != -1)
103 if (ipv4NeighborInterfaceIndex != -1)
107 ipv4NeighborInterfaceIndex);
111 if (ipv6InterfaceIndex != -1)
115 if (ipv6NeighborInterfaceIndex != -1)
119 ipv6NeighborInterfaceIndex);
132 for (uint32_t i = 0; i < c.
GetN(); ++i)
138 int32_t ipv4InterfaceIndex = -1;
141 ipv4InterfaceIndex = node->
GetObject<
Ipv4>()->GetInterfaceForDevice(netDevice);
143 int32_t ipv6InterfaceIndex = -1;
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;
157 ipv4NeighborInterfaceIndex =
158 neighborNode->
GetObject<
Ipv4>()->GetInterfaceForDevice(neighborDevice);
160 int32_t ipv6NeighborInterfaceIndex = -1;
163 ipv6NeighborInterfaceIndex =
164 neighborNode->
GetObject<
Ipv6>()->GetInterfaceForDevice(neighborDevice);
167 if (neighborDevice != netDevice)
169 if (ipv4InterfaceIndex != -1)
173 if (ipv4NeighborInterfaceIndex != -1)
177 ipv4NeighborInterfaceIndex);
181 if (ipv6InterfaceIndex != -1)
185 if (ipv6NeighborInterfaceIndex != -1)
189 ipv6NeighborInterfaceIndex);
202 for (uint32_t i = 0; i < c.
GetN(); ++i)
204 std::pair<Ptr<Ipv4>, uint32_t> returnValue = c.
Get(i);
206 uint32_t index = returnValue.second;
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);
237 for (uint32_t i = 0; i < c.
GetN(); ++i)
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();
284 for (uint32_t n = 0; n < netDeviceAddresses; ++n)
287 for (uint32_t
m = 0;
m < neighborDeviceAddresses; ++
m)
296 neighborDevice->GetAddress());
306 uint32_t netDeviceAddresses = ipv6Interface->
GetNAddresses();
307 uint32_t neighborDeviceAddresses = neighborDeviceInterface->
GetNAddresses();
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);
346 neighborDevice->GetAddress());
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);
413 int32_t ipv4InterfaceIndex = node->
GetObject<
Ipv4>()->GetInterfaceForDevice(netDevice);
414 int32_t ipv6InterfaceIndex = node->
GetObject<
Ipv6>()->GetInterfaceForDevice(netDevice);
415 if (ipv4InterfaceIndex != -1)
426 if (ipv6InterfaceIndex != -1)
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)
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)
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)
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)
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)
void Remove(ArpCache::Entry *entry)
Remove an entry.
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
void RemoveAutoGeneratedEntries()
Clear the ArpCache of all Auto-Generated entries.
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.
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.
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.
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.
void MarkAutoGenerated()
Changes the state of this entry to auto-generated.
void SetMacAddress(Address mac)
Set the MAC address of this entry.
virtual NdiscCache::Entry * Add(Ipv6Address to)
Add an entry.
void Remove(NdiscCache::Entry *entry)
Delete an entry.
virtual NdiscCache::Entry * Lookup(Ipv6Address dst)
Lookup in the cache.
void RemoveAutoGeneratedEntries()
Clear the NDISC cache of all Auto-Generated entries.
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
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
static uint32_t GetNNodes()
static Ptr< Node > GetNode(uint32_t n)
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
#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...