A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
hwmp-rtable.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008,2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kirill Andreev <andreev@iitp.ru>
7 */
8
9#include "hwmp-rtable.h"
10
11#include "ns3/assert.h"
12#include "ns3/log.h"
13#include "ns3/object.h"
14#include "ns3/simulator.h"
15#include "ns3/test.h"
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("HwmpRtable");
21
22namespace dot11s
23{
24
26
27TypeId
29{
30 static TypeId tid = TypeId("ns3::dot11s::HwmpRtable")
32 .SetGroupName("Mesh")
33 .AddConstructor<HwmpRtable>();
34 return tid;
35}
36
41
45
46void
48{
49 m_routes.clear();
50}
51
52void
54 Mac48Address retransmitter,
55 uint32_t interface,
56 uint32_t metric,
57 Time lifetime,
58 uint32_t seqnum)
59{
60 NS_LOG_FUNCTION(this << destination << retransmitter << interface << metric
61 << lifetime.GetSeconds() << seqnum);
62 auto i = m_routes.find(destination);
63 if (i == m_routes.end())
64 {
65 ReactiveRoute newroute;
66 m_routes[destination] = newroute;
67 }
68 i = m_routes.find(destination);
69 NS_ASSERT(i != m_routes.end());
70 i->second.retransmitter = retransmitter;
71 i->second.interface = interface;
72 i->second.metric = metric;
73 i->second.whenExpire = Simulator::Now() + lifetime;
74 i->second.seqnum = seqnum;
75}
76
77void
79 Mac48Address root,
80 Mac48Address retransmitter,
81 uint32_t interface,
82 Time lifetime,
83 uint32_t seqnum)
84{
85 NS_LOG_FUNCTION(this << metric << root << retransmitter << interface << lifetime << seqnum);
86 m_root.root = root;
87 m_root.retransmitter = retransmitter;
88 m_root.metric = metric;
89 m_root.whenExpire = Simulator::Now() + lifetime;
90 m_root.seqnum = seqnum;
91 m_root.interface = interface;
92}
93
94void
96 uint32_t precursorInterface,
97 Mac48Address precursorAddress,
98 Time lifetime)
99{
100 NS_LOG_FUNCTION(this << destination << precursorInterface << precursorAddress << lifetime);
101 Precursor precursor;
102 precursor.interface = precursorInterface;
103 precursor.address = precursorAddress;
104 precursor.whenExpire = Simulator::Now() + lifetime;
105 auto i = m_routes.find(destination);
106 if (i != m_routes.end())
107 {
108 bool should_add = true;
109 for (unsigned int j = 0; j < i->second.precursors.size(); j++)
110 {
111 // NB: Only one active route may exist, so do not check
112 // interface ID, just address
113 if (i->second.precursors[j].address == precursorAddress)
114 {
115 should_add = false;
116 i->second.precursors[j].whenExpire = precursor.whenExpire;
117 break;
118 }
119 }
120 if (should_add)
121 {
122 i->second.precursors.push_back(precursor);
123 }
124 }
125}
126
127void
138
139void
141{
142 NS_LOG_FUNCTION(this << root);
143 if (m_root.root == root)
144 {
146 }
147}
148
149void
151{
152 NS_LOG_FUNCTION(this << destination);
153 auto i = m_routes.find(destination);
154 if (i != m_routes.end())
155 {
156 m_routes.erase(i);
157 }
158}
159
162{
163 NS_LOG_FUNCTION(this << destination);
164 auto i = m_routes.find(destination);
165 if (i == m_routes.end())
166 {
167 return LookupResult();
168 }
169 if ((i->second.whenExpire < Simulator::Now()) && (!i->second.whenExpire.IsZero()))
170 {
171 NS_LOG_DEBUG("Reactive route has expired, sorry.");
172 return LookupResult();
173 }
174 return LookupReactiveExpired(destination);
175}
176
179{
180 NS_LOG_FUNCTION(this << destination);
181 auto i = m_routes.find(destination);
182 if (i == m_routes.end())
183 {
184 return LookupResult();
185 }
186 NS_LOG_DEBUG("Returning reactive route to " << destination);
187 return LookupResult(i->second.retransmitter,
188 i->second.interface,
189 i->second.metric,
190 i->second.seqnum,
191 i->second.whenExpire - Simulator::Now());
192}
193
196{
197 NS_LOG_FUNCTION(this);
199 {
200 NS_LOG_DEBUG("Proactive route has expired and will be deleted, sorry.");
202 }
203 return LookupProactiveExpired();
204}
205
208{
209 NS_LOG_FUNCTION(this);
210 NS_LOG_DEBUG("Returning proactive route to root");
216}
217
218std::vector<HwmpProtocol::FailedDestination>
220{
221 NS_LOG_FUNCTION(this << peerAddress);
223 std::vector<HwmpProtocol::FailedDestination> retval;
224 for (auto i = m_routes.begin(); i != m_routes.end(); i++)
225 {
226 if (i->second.retransmitter == peerAddress)
227 {
228 dst.destination = i->first;
229 i->second.seqnum++;
230 dst.seqnum = i->second.seqnum;
231 retval.push_back(dst);
232 }
233 }
234 // Lookup a path to root
235 if (m_root.retransmitter == peerAddress)
236 {
237 dst.destination = m_root.root;
238 dst.seqnum = m_root.seqnum;
239 retval.push_back(dst);
240 }
241 return retval;
242}
243
246{
247 NS_LOG_FUNCTION(this << destination);
248 // We suppose that no duplicates here can be
249 PrecursorList retval;
250 auto route = m_routes.find(destination);
251 if (route != m_routes.end())
252 {
253 for (auto i = route->second.precursors.begin(); i != route->second.precursors.end(); i++)
254 {
255 if (i->whenExpire > Simulator::Now())
256 {
257 retval.emplace_back(i->interface, i->address);
258 }
259 }
260 }
261 return retval;
262}
263
264bool
270
272 : retransmitter(r),
273 ifIndex(i),
274 metric(m),
275 seqnum(s),
276 lifetime(l)
277{
278}
279
280bool
282{
283 return !(retransmitter == Mac48Address::GetBroadcast() && ifIndex == INTERFACE_ANY &&
284 metric == MAX_METRIC && seqnum == 0);
285}
286} // namespace dot11s
287} // namespace ns3
an EUI-48 address
static Mac48Address GetBroadcast()
A base class which provides memory management and object aggregation.
Definition object.h:78
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Routing table for HWMP – 802.11s routing protocol.
Definition hwmp-rtable.h:29
void DeleteReactivePath(Mac48Address destination)
Delete the reactive paths toward a destination.
void DoDispose() override
Destructor implementation.
static const uint32_t INTERFACE_ANY
Means all interfaces.
Definition hwmp-rtable.h:32
static const uint32_t MAX_METRIC
Maximum (the best?) path metric.
Definition hwmp-rtable.h:34
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
static TypeId GetTypeId()
Get the type ID.
std::map< Mac48Address, ReactiveRoute > m_routes
List of routes.
PrecursorList GetPrecursors(Mac48Address destination)
Get the precursors list.
void DeleteProactivePath()
Delete all the proactive paths.
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition hwmp-rtable.h:71
std::vector< HwmpProtocol::FailedDestination > GetUnreachableDestinations(Mac48Address peerAddress)
When peer link with a given MAC-address fails - it returns list of unreachable destination addresses.
ProactiveRoute m_root
Path to proactive tree root MP.
LookupResult LookupProactive()
Find proactive path to tree root.
void AddPrecursor(Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime)
Add a precursor.
void AddProactivePath(uint32_t metric, Mac48Address root, Mac48Address retransmitter, uint32_t interface, Time lifetime, uint32_t seqnum)
Add a proactive path.
void AddReactivePath(Mac48Address destination, Mac48Address retransmitter, uint32_t interface, uint32_t metric, Time lifetime, uint32_t seqnum)
Add a reactive path.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
structure of unreachable destination - address and sequence number
Mac48Address destination
destination address
Route lookup result, return type of LookupXXX methods.
Definition hwmp-rtable.h:38
bool operator==(const LookupResult &o) const
Compare route lookup results, used by tests.
uint32_t seqnum
sequence number
Definition hwmp-rtable.h:42
LookupResult(Mac48Address r=Mac48Address::GetBroadcast(), uint32_t i=INTERFACE_ANY, uint32_t m=MAX_METRIC, uint32_t s=0, Time l=Seconds(0))
Lookup result function.
Mac48Address retransmitter
retransmitter
Definition hwmp-rtable.h:39
Route found in reactive mode.
std::vector< Precursor > precursors
precursors
Mac48Address retransmitter
retransmitter
Route found in reactive mode.