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& route = m_routes[destination]; // find existing record or create new
63 route.retransmitter = retransmitter;
64 route.interface = interface;
65 route.metric = metric;
66 route.whenExpire = Simulator::Now() + lifetime;
67 route.seqnum = seqnum;
68}
69
70void
72 Mac48Address root,
73 Mac48Address retransmitter,
74 uint32_t interface,
75 Time lifetime,
76 uint32_t seqnum)
77{
78 NS_LOG_FUNCTION(this << metric << root << retransmitter << interface << lifetime << seqnum);
79 m_root.root = root;
80 m_root.retransmitter = retransmitter;
81 m_root.metric = metric;
82 m_root.whenExpire = Simulator::Now() + lifetime;
83 m_root.seqnum = seqnum;
84 m_root.interface = interface;
85}
86
87void
89 uint32_t precursorInterface,
90 Mac48Address precursorAddress,
91 Time lifetime)
92{
93 NS_LOG_FUNCTION(this << destination << precursorInterface << precursorAddress << lifetime);
94 Precursor precursor;
95 precursor.interface = precursorInterface;
96 precursor.address = precursorAddress;
97 precursor.whenExpire = Simulator::Now() + lifetime;
98 auto i = m_routes.find(destination);
99 if (i != m_routes.end())
100 {
101 bool should_add = true;
102 for (unsigned int j = 0; j < i->second.precursors.size(); j++)
103 {
104 // NB: Only one active route may exist, so do not check
105 // interface ID, just address
106 if (i->second.precursors[j].address == precursorAddress)
107 {
108 should_add = false;
109 i->second.precursors[j].whenExpire = precursor.whenExpire;
110 break;
111 }
112 }
113 if (should_add)
114 {
115 i->second.precursors.push_back(precursor);
116 }
117 }
118}
119
120void
131
132void
134{
135 NS_LOG_FUNCTION(this << root);
136 if (m_root.root == root)
137 {
139 }
140}
141
142void
144{
145 NS_LOG_FUNCTION(this << destination);
146 auto i = m_routes.find(destination);
147 if (i != m_routes.end())
148 {
149 m_routes.erase(i);
150 }
151}
152
155{
156 NS_LOG_FUNCTION(this << destination);
157 auto i = m_routes.find(destination);
158 if (i == m_routes.end())
159 {
160 return LookupResult();
161 }
162 if ((i->second.whenExpire < Simulator::Now()) && (!i->second.whenExpire.IsZero()))
163 {
164 NS_LOG_DEBUG("Reactive route has expired, sorry.");
165 return LookupResult();
166 }
167 return LookupReactiveExpired(destination);
168}
169
172{
173 NS_LOG_FUNCTION(this << destination);
174 auto i = m_routes.find(destination);
175 if (i == m_routes.end())
176 {
177 return LookupResult();
178 }
179 NS_LOG_DEBUG("Returning reactive route to " << destination);
180 return LookupResult(i->second.retransmitter,
181 i->second.interface,
182 i->second.metric,
183 i->second.seqnum,
184 i->second.whenExpire - Simulator::Now());
185}
186
189{
190 NS_LOG_FUNCTION(this);
192 {
193 NS_LOG_DEBUG("Proactive route has expired and will be deleted, sorry.");
195 }
196 return LookupProactiveExpired();
197}
198
201{
202 NS_LOG_FUNCTION(this);
203 NS_LOG_DEBUG("Returning proactive route to root");
209}
210
211std::vector<HwmpProtocol::FailedDestination>
213{
214 NS_LOG_FUNCTION(this << peerAddress);
216 std::vector<HwmpProtocol::FailedDestination> retval;
217 for (auto i = m_routes.begin(); i != m_routes.end(); i++)
218 {
219 if (i->second.retransmitter == peerAddress)
220 {
221 dst.destination = i->first;
222 i->second.seqnum++;
223 dst.seqnum = i->second.seqnum;
224 retval.push_back(dst);
225 }
226 }
227 // Lookup a path to root
228 if (m_root.retransmitter == peerAddress)
229 {
230 dst.destination = m_root.root;
231 dst.seqnum = m_root.seqnum;
232 retval.push_back(dst);
233 }
234 return retval;
235}
236
239{
240 NS_LOG_FUNCTION(this << destination);
241 // We suppose that no duplicates here can be
242 PrecursorList retval;
243 auto route = m_routes.find(destination);
244 if (route != m_routes.end())
245 {
246 for (auto i = route->second.precursors.begin(); i != route->second.precursors.end(); i++)
247 {
248 if (i->whenExpire > Simulator::Now())
249 {
250 retval.emplace_back(i->interface, i->address);
251 }
252 }
253 }
254 return retval;
255}
256
257bool
263
265 : retransmitter(r),
266 ifIndex(i),
267 metric(m),
268 seqnum(s),
269 lifetime(l)
270{
271}
272
273bool
275{
276 return !(retransmitter == Mac48Address::GetBroadcast() && ifIndex == INTERFACE_ANY &&
277 metric == MAX_METRIC && seqnum == 0);
278}
279} // namespace dot11s
280} // 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:49
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_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