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
21#include <unordered_map>
22#include <vector>
23
24namespace ns3
25{
26
27/**
28 * @ingroup sixlowpan
29 * @class SixLowPanNdBindingTable
30 * @brief A binding table for 6LoWPAN ND.
31 */
33{
34 public:
36
37 /**
38 * @brief Get the type ID
39 * @return type ID
40 */
41 static TypeId GetTypeId();
42
43 /**
44 * @brief Constructor.
45 */
47
48 /**
49 * @brief Destructor.
50 */
52
53 /**
54 * @brief Get the NetDevice associated with this cache.
55 * @return NetDevice
56 */
58
59 /**
60 * @brief Set the device and interface.
61 * @param device the device
62 * @param interface the IPv6 interface
63 * @param icmpv6 the ICMPv6 protocol
64 */
65 void SetDevice(Ptr<NetDevice> device,
66 Ptr<Ipv6Interface> interface,
68
69 /**
70 * @brief Get the IPv6 interface associated with this binding table.
71 * @return the Ipv6Interface pointer
72 */
74
75 /**
76 * @brief Lookup in the binding table.
77 * @param dst destination address
78 * @return the entry if found, 0 otherwise
79 */
81
82 /**
83 * @brief Add an entry.
84 * @param to address to add
85 * @return an new Entry
86 */
88
89 /**
90 * @brief Remove an entry from the binding table.
91 * @param entry pointer to the entry to remove
92 */
94
95 /**
96 * @brief Print the SixLowPanNdBindingTable entries
97 *
98 * @param stream the ostream the SixLowPanNdBindingTable entries is printed to
99 */
101
102 /**
103 * @class SixLowPanNdBindingTableEntry
104 * @brief A record that holds information about an SixLowPanNdBindingTable entry.
105 */
107 {
108 public:
109 /**
110 * @brief Constructor.
111 * @param bt The SixLowPanNdBindingTable this entry belongs to.
112 */
114
115 /**
116 * @brief Print the binding table entry to an output stream.
117 * @param os the output stream
118 */
119 void Print(std::ostream& os) const;
120
121 /**
122 * @brief Changes the state to this entry to REACHABLE.
123 * It starts the reachable timer.
124 * @param time the lifetime in units of 60 seconds (from ARO)
125 */
126 void MarkReachable(uint16_t time);
127
128 /**
129 * @brief Change the state to this entry to STALE.
130 * It starts the stale timer.
131 */
132 void MarkStale();
133
134 /**
135 * @brief Is the entry REACHABLE.
136 * @return true if the type of entry is REACHABLE, false otherwise
137 */
138 bool IsReachable() const;
139
140 /**
141 * @brief Is the entry STALE
142 * @return true if the type of entry is STALE, false otherwise
143 */
144 bool IsStale() const;
145
146 /**
147 * @brief Function called when timer timeout.
148 */
149 void FunctionTimeout();
150
151 /**
152 * @brief Get the ROVR field.
153 * @return the ROVR
154 */
155 std::vector<uint8_t> GetRovr() const;
156
157 /**
158 * @brief Set the ROVR field.
159 * @param rovr the ROVR value
160 */
161 void SetRovr(const std::vector<uint8_t>& rovr);
162
163 /**
164 * @brief Get the binding table this entry belongs to.
165 * @return pointer to the binding table
166 */
168
169 /**
170 * @brief Set the IPv6 address for this entry.
171 * @param ipv6Address the IPv6 address
172 */
173 void SetIpv6Address(Ipv6Address ipv6Address);
174
175 /**
176 * @brief Get the IPv6 address for this entry.
177 * @return the IPv6 address
178 */
180
181 private:
182 /**
183 * @brief The SixLowPanEntry type enumeration.
184 */
186 {
187 REACHABLE, /**< Active registration. */
188 STALE /**< Registration expired; entry pending removal. */
189 };
190
191 /**
192 * @brief The ROVR value.
193 */
194 std::vector<uint8_t> m_rovr;
195
196 /**
197 * @brief The state of the entry.
198 */
200
201 /**
202 * @brief Timer (used for REACHABLE entries).
203 */
205
206 /**
207 * @brief Timer (used for STALE entries).
208 */
210
211 /**
212 * @brief The binding table this entry belongs to.
213 */
215
216 /**
217 * @brief The IPv6 address for this entry.
218 */
220 };
221
222 protected:
223 /**
224 * @brief Dispose this object.
225 */
226 void DoDispose() override;
227
228 private:
229 /**
230 * @brief 6LoWPAN Neighbor Discovery Table container
231 */
232 typedef std::unordered_map<Ipv6Address, SixLowPanNdBindingTable::SixLowPanNdBindingTableEntry*>
234
235 SixLowPanTable m_sixLowPanNdBindingTable; ///< The actual binding table
236
237 Ptr<NetDevice> m_device; //!< The NetDevice associated with this binding table
238 Ptr<Ipv6Interface> m_interface; //!< The IPv6 interface associated with this binding table
239 Ptr<Icmpv6L4Protocol> m_icmpv6; //!< The ICMPv6 protocol associated with this binding table
240
241 Time m_staleDuration; //!< The duration (in hours) an entry remains in STALE state before being
242 //!< removed from the binding table.
243};
244
245/**
246 * @brief Stream insertion operator.
247 *
248 * @param os the reference to the output stream
249 * @param entry the SixLowPanNdBindingTable::SixLowPanNdBindingTableEntry
250 * @returns the reference to the output stream
251 */
252std::ostream& operator<<(std::ostream& os,
254
255} /* namespace ns3 */
256
257#endif /* SIXLOW_NDISC_CACHE_H */
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.
std::unordered_map< Ipv6Address, SixLowPanNdBindingTable::SixLowPanNdBindingTableEntry * > SixLowPanTable
6LoWPAN Neighbor Discovery Table container
Ptr< NetDevice > m_device
The NetDevice associated with this binding table.
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