A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sixlowpan-nd-binding-table.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 *
7 *
8 * Author: Boh Jie Qi <jieqiboh5836@gmail.com>
9 */
10#ifndef SIXLOW_ND_BINDING_TABLE_H
11#define SIXLOW_ND_BINDING_TABLE_H
12
13#include "ns3/ipv6-address.h"
14#include "ns3/ipv6-interface.h"
15#include "ns3/mac64-address.h"
16#include "ns3/ndisc-cache.h"
17#include "ns3/output-stream-wrapper.h"
18#include "ns3/ptr.h"
19#include "ns3/timer.h"
20
21namespace ns3
22{
23
24/**
25 * @ingroup sixlowpan
26 * @class SixLowPanNdBindingTable
27 * @brief A binding table for 6LoWPAN ND.
28 */
30{
31 public:
33
34 /**
35 * @brief Get the type ID
36 * @return type ID
37 */
38 static TypeId GetTypeId();
39
40 /**
41 * @brief Constructor.
42 */
44
45 /**
46 * @brief Destructor.
47 */
49
50 /**
51 * @brief Get the NetDevice associated with this cache.
52 * @return NetDevice
53 */
55
56 /**
57 * @brief Set the device and interface.
58 * @param device the device
59 * @param interface the IPv6 interface
60 * @param icmpv6 the ICMPv6 protocol
61 */
62 void SetDevice(Ptr<NetDevice> device,
63 Ptr<Ipv6Interface> interface,
65
66 /**
67 * @brief Get the IPv6 interface associated with this binding table.
68 * @return the Ipv6Interface pointer
69 */
71
72 /**
73 * @brief Lookup in the binding table.
74 * @param dst destination address
75 * @return the entry if found, 0 otherwise
76 */
78
79 /**
80 * @brief Add an entry.
81 * @param to address to add
82 * @return an new Entry
83 */
85
86 /**
87 * @brief Remove an entry from the binding table.
88 * @param entry pointer to the entry to remove
89 */
91
92 /**
93 * @brief Print the SixLowPanNdBindingTable entries
94 *
95 * @param stream the ostream the SixLowPanNdBindingTable entries is printed to
96 */
98
99 /**
100 * @class SixLowPanNdBindingTableEntry
101 * @brief A record that holds information about an SixLowPanNdBindingTable entry.
102 */
104 {
105 public:
106 /**
107 * @brief Constructor.
108 * @param bt The SixLowPanNdBindingTable this entry belongs to.
109 */
111
112 /**
113 * @brief Print the binding table entry to an output stream.
114 * @param os the output stream
115 */
116 void Print(std::ostream& os) const;
117
118 /**
119 * @brief Changes the state to this entry to REACHABLE.
120 * It starts the reachable timer.
121 * @param time the lifetime in units of 60 seconds (from ARO)
122 */
123 void MarkReachable(uint16_t time);
124
125 /**
126 * @brief Change the state to this entry to STALE.
127 * It starts the stale timer.
128 */
129 void MarkStale();
130
131 /**
132 * @brief Is the entry REACHABLE.
133 * @return true if the type of entry is REACHABLE, false otherwise
134 */
135 bool IsReachable() const;
136
137 /**
138 * @brief Is the entry STALE
139 * @return true if the type of entry is STALE, false otherwise
140 */
141 bool IsStale() const;
142
143 /**
144 * @brief Function called when timer timeout.
145 */
146 void FunctionTimeout();
147
148 /**
149 * @brief Get the ROVR field.
150 * @return the ROVR
151 */
152 std::vector<uint8_t> GetRovr() const;
153
154 /**
155 * @brief Set the ROVR field.
156 * @param rovr the ROVR value
157 */
158 void SetRovr(const std::vector<uint8_t>& rovr);
159
160 /**
161 * @brief Get the binding table this entry belongs to.
162 * @return pointer to the binding table
163 */
165
166 /**
167 * @brief Set the IPv6 address for this entry.
168 * @param ipv6Address the IPv6 address
169 */
170 void SetIpv6Address(Ipv6Address ipv6Address);
171
172 /**
173 * @brief Get the IPv6 address for this entry.
174 * @return the IPv6 address
175 */
177
178 private:
179 /**
180 * @brief The SixLowPanEntry type enumeration.
181 */
183 {
184 REACHABLE, /**< Active registration. */
185 STALE /**< Registration expired; entry pending removal. */
186 };
187
188 /**
189 * @brief The ROVR value.
190 */
191 std::vector<uint8_t> m_rovr;
192
193 /**
194 * @brief The state of the entry.
195 */
197
198 /**
199 * @brief Timer (used for REACHABLE entries).
200 */
202
203 /**
204 * @brief Timer (used for STALE entries).
205 */
207
208 /**
209 * @brief The binding table this entry belongs to.
210 */
212
213 /**
214 * @brief The IPv6 address for this entry.
215 */
217 };
218
219 protected:
220 /**
221 * @brief Dispose this object.
222 */
223 void DoDispose() override;
224
225 private:
226 /**
227 * @brief 6LoWPAN Neighbor Discovery Table container
228 */
229 typedef std::unordered_map<Ipv6Address,
233
234 SixLowPanTable m_sixLowPanNdBindingTable; ///< The actual binding table
235
236 Ptr<NetDevice> m_device; //!< The NetDevice associated with this binding table
237 Ptr<Ipv6Interface> m_interface; //!< The IPv6 interface associated with this binding table
238 Ptr<Icmpv6L4Protocol> m_icmpv6; //!< The ICMPv6 protocol associated with this binding table
239
240 Time m_staleDuration; //!< The duration (in hours) an entry remains in STALE state before being
241 //!< removed from the binding table.
242};
243
244/**
245 * @brief Stream insertion operator.
246 *
247 * @param os the reference to the output stream
248 * @param entry the SixLowPanNdBindingTable::SixLowPanNdBindingTableEntry
249 * @returns the reference to the output stream
250 */
251std::ostream& operator<<(std::ostream& os,
253
254} /* namespace ns3 */
255
256#endif /* SIXLOW_NDISC_CACHE_H */
Hash function class for IPv6 addresses.
Describes an IPv6 address.
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
A record that holds information about an SixLowPanNdBindingTable entry.
std::vector< uint8_t > m_rovr
The ROVR value.
void MarkStale()
Change the state to this entry to STALE.
void MarkReachable(uint16_t time)
Changes the state to this entry to REACHABLE.
Timer m_staleTimer
Timer (used for STALE entries).
void SetIpv6Address(Ipv6Address ipv6Address)
Set the IPv6 address for this entry.
Timer m_reachableTimer
Timer (used for REACHABLE entries).
SixLowPanNdBindingTableEntryType_e m_type
The state of the entry.
Ipv6Address m_ipv6Address
The IPv6 address for this entry.
Ipv6Address GetIpv6Address() const
Get the IPv6 address for this entry.
SixLowPanNdBindingTable * m_bindingTable
The binding table this entry belongs to.
bool IsStale() const
Is the entry STALE.
SixLowPanNdBindingTable * GetBindingTable() const
Get the binding table this entry belongs to.
std::vector< uint8_t > GetRovr() const
Get the ROVR field.
void FunctionTimeout()
Function called when timer timeout.
void Print(std::ostream &os) const
Print the binding table entry to an output stream.
bool IsReachable() const
Is the entry REACHABLE.
SixLowPanNdBindingTableEntry(SixLowPanNdBindingTable *bt)
Constructor.
SixLowPanNdBindingTableEntryType_e
The SixLowPanEntry type enumeration.
@ REACHABLE
Active registration.
@ STALE
Registration expired; entry pending removal.
void SetRovr(const std::vector< uint8_t > &rovr)
Set the ROVR field.
Ptr< NetDevice > m_device
The NetDevice associated with this binding table.
std::unordered_map< Ipv6Address, SixLowPanNdBindingTable::SixLowPanNdBindingTableEntry *, Ipv6AddressHash > SixLowPanTable
6LoWPAN Neighbor Discovery Table container
Ptr< Ipv6Interface > GetInterface() const
Get the IPv6 interface associated with this binding table.
Time m_staleDuration
The duration (in hours) an entry remains in STALE state before being removed from the binding table.
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv6Interface > interface, Ptr< Icmpv6L4Protocol > icmpv6)
Set the device and interface.
void Remove(SixLowPanNdBindingTable::SixLowPanNdBindingTableEntry *entry)
Remove an entry from the binding table.
SixLowPanNdBindingTable::SixLowPanNdBindingTableEntry * Add(Ipv6Address to)
Add an entry.
void PrintBindingTable(Ptr< OutputStreamWrapper > stream)
Print the SixLowPanNdBindingTable entries.
Ptr< Icmpv6L4Protocol > m_icmpv6
The ICMPv6 protocol associated with this binding table.
Ptr< NetDevice > GetDevice() const
Get the NetDevice associated with this cache.
Ptr< Ipv6Interface > m_interface
The IPv6 interface associated with this binding table.
SixLowPanNdBindingTable::SixLowPanNdBindingTableEntry * Lookup(Ipv6Address dst)
Lookup in the binding table.
void DoDispose() override
Dispose this object.
SixLowPanTable m_sixLowPanNdBindingTable
The actual binding table.
static TypeId GetTypeId()
Get the type ID.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
A simple virtual Timer class.
Definition timer.h:67
a unique identifier for an interface.
Definition type-id.h:50
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148