A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
neighbor-cache-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 ZHIHENG DONG
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Zhiheng Dong <dzh2077@gmail.com>
7 */
8
9#ifndef NEIGHBOR_CACHE_HELPER_H
10#define NEIGHBOR_CACHE_HELPER_H
11
14
15#include "ns3/arp-cache.h"
16#include "ns3/arp-header.h"
17#include "ns3/arp-l3-protocol.h"
18#include "ns3/channel.h"
19#include "ns3/icmpv6-l4-protocol.h"
20#include "ns3/ipv4-address.h"
21#include "ns3/ipv4-interface.h"
22#include "ns3/ipv4-l3-protocol.h"
23#include "ns3/ipv6-interface.h"
24#include "ns3/ipv6-l3-protocol.h"
25#include "ns3/net-device-container.h"
26#include "ns3/node-list.h"
27
28namespace ns3
29{
30
31/**
32 * \ingroup internet
33 *
34 * @brief A helper class to populate neighbor cache.
35 *
36 * This class is used to populate neighbor cache. Permanent entries will be added
37 * on the scope of a channel, a NetDeviceContainer, an InterfaceContainer or globally.
38 */
40{
41 public:
42 /**
43 * @brief Construct a helper class to make life easier while creating neighbor cache
44 */
47
48 /**
49 * \brief Populate neighbor ARP and NDISC caches for all devices.
50 * This method walks the global ChannelList.
51 */
53
54 /**
55 * \brief Populate neighbor ARP and NDISC caches for all devices in the given
56 * Channel.
57 * \param channel the Channel to process
58 */
59 void PopulateNeighborCache(Ptr<Channel> channel) const;
60
61 /**
62 * \brief Populate neighbor ARP and NDISC caches for all devices in the given
63 * NetDeviceContainer.
64 * \param c the NetDevice container to process
65 */
66 void PopulateNeighborCache(const NetDeviceContainer& c) const;
67
68 /**
69 * \brief Populate neighbor ARP caches for all IPv4 interfaces in the given
70 * Ipv4InterfaceContainer.
71 * \param c the Ipv4InterfaceContainer to process
72 */
74
75 /**
76 * \brief Populate neighbor NDISC caches for all IPv6 interfaces in the given
77 * Ipv6InterfaceContainer.
78 * \param c the Ipv6InterfaceContainer to process
79 */
81
82 /**
83 * \brief Remove entries generated from NeighborCacheHelper from ARP cache and NDISC cache
84 */
85 void FlushAutoGenerated() const;
86
87 /**
88 * \brief Enable/disable dynamic neighbor cache, auto-generated neighbor cache will update
89 * by IP addresses changed when dynamic neighbor cache enabled. User should ensure that
90 * the NeighborCacheHelper object persists for the duration of the simulation when dynamic
91 * neighbor cache is enabled.
92 * \param enable enable state
93 */
94 void SetDynamicNeighborCache(bool enable);
95
96 private:
97 /**
98 * \brief Populate neighbor ARP entries for given IPv4 interface.
99 * \param ipv4Interface the Ipv4Interface to process
100 * \param neighborDeviceInterface the potential neighbor Ipv4Interface
101 */
103 Ptr<Ipv4Interface> neighborDeviceInterface) const;
104
105 /**
106 * \brief Populate neighbor NDISC entries for given IPv6 interface.
107 * \param ipv6Interface the Ipv6Interface to process
108 * \param neighborDeviceInterface the potential neighbor Ipv6Interface
109 */
111 Ptr<Ipv6Interface> neighborDeviceInterface) const;
112
113 /**
114 * \brief Add an auto_generated entry to the ARP cache of an interface.
115 * \param netDeviceInterface the Ipv4Interface that ARP cache belongs to
116 * \param ipv4Address the IPv4 address will be added to the cache.
117 * \param macAddress the MAC address will be added to the cache.
118 */
119 void AddEntry(Ptr<Ipv4Interface> netDeviceInterface,
120 Ipv4Address ipv4Address,
121 Address macAddress) const;
122
123 /**
124 * \brief Add an auto_generated entry to the NDISC cache of an interface.
125 * \param netDeviceInterface the Ipv6Interface that NDISC cache belongs to
126 * \param ipv6Address the IPv6 address will be added to the cache.
127 * \param macAddress the MAC address will be added to the cache.
128 */
129 void AddEntry(Ptr<Ipv6Interface> netDeviceInterface,
130 Ipv6Address ipv6Address,
131 Address macAddress) const;
132
133 /**
134 * \brief Update neighbor caches when an address is removed from a Ipv4Interface with auto
135 * generated neighbor cache.
136 * \param interface the Ipv4Interface that address removed from.
137 * \param ifAddr the removed IPv4 interface address.
138 */
140 const Ipv4InterfaceAddress ifAddr) const;
141
142 /**
143 * \brief Update neighbor caches when an address is added to a Ipv4Interface with auto generated
144 * neighbor cache.
145 * \param interface the Ipv4Interface that address added to.
146 * \param ifAddr the added IPv4 interface address.
147 */
149 const Ipv4InterfaceAddress ifAddr) const;
150
151 /**
152 * \brief Update neighbor caches when an address is removed from a Ipv6Interface with auto
153 * generated neighbor cache.
154 * \param interface the Ipv6Interface that address removed from.
155 * \param ifAddr the removed IPv6 interface address.
156 */
158 const Ipv6InterfaceAddress ifAddr) const;
159
160 /**
161 * \brief Update neighbor cache when an address is added to a Ipv6Interface with auto generated
162 * neighbor cache.
163 * \param interface the Ipv6Interface that address added to.
164 * \param ifAddr the added IPv6 interface address.
165 */
167 const Ipv6InterfaceAddress ifAddr) const;
168
170 false}; //!< flag will set true if neighbor caches were generated for all devices
171
173 false}; //!< flag will set true if dynamic neighbor cache is enabled.
174};
175
176} // namespace ns3
177
178#endif /* NEIGHBOR_CACHE_HELPER_H */
a polymophic address class
Definition address.h:90
Ipv4 addresses are stored in host order in this class.
a class to store IPv4 address information on an interface
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Describes an IPv6 address.
IPv6 address associated with an interface.
Keep track of a set of IPv6 interfaces.
A helper class to populate neighbor cache.
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
Smart pointer class similar to boost::intrusive_ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.