A Discrete-Event Network Simulator
API
hwmp-rtable.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008,2009 IITP RAS
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Kirill Andreev <andreev@iitp.ru>
18  */
19 
20 #include "hwmp-rtable.h"
21 
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/object.h"
25 #include "ns3/simulator.h"
26 #include "ns3/test.h"
27 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("HwmpRtable");
32 
33 namespace dot11s
34 {
35 
36 NS_OBJECT_ENSURE_REGISTERED(HwmpRtable);
37 
38 TypeId
40 {
41  static TypeId tid = TypeId("ns3::dot11s::HwmpRtable")
42  .SetParent<Object>()
43  .SetGroupName("Mesh")
44  .AddConstructor<HwmpRtable>();
45  return tid;
46 }
47 
49 {
51 }
52 
54 {
55 }
56 
57 void
59 {
60  m_routes.clear();
61 }
62 
63 void
65  Mac48Address retransmitter,
66  uint32_t interface,
67  uint32_t metric,
68  Time lifetime,
69  uint32_t seqnum)
70 {
71  NS_LOG_FUNCTION(this << destination << retransmitter << interface << metric
72  << lifetime.GetSeconds() << seqnum);
73  auto i = m_routes.find(destination);
74  if (i == m_routes.end())
75  {
76  ReactiveRoute newroute;
77  m_routes[destination] = newroute;
78  }
79  i = m_routes.find(destination);
80  NS_ASSERT(i != m_routes.end());
81  i->second.retransmitter = retransmitter;
82  i->second.interface = interface;
83  i->second.metric = metric;
84  i->second.whenExpire = Simulator::Now() + lifetime;
85  i->second.seqnum = seqnum;
86 }
87 
88 void
90  Mac48Address root,
91  Mac48Address retransmitter,
92  uint32_t interface,
93  Time lifetime,
94  uint32_t seqnum)
95 {
96  NS_LOG_FUNCTION(this << metric << root << retransmitter << interface << lifetime << seqnum);
97  m_root.root = root;
98  m_root.retransmitter = retransmitter;
99  m_root.metric = metric;
100  m_root.whenExpire = Simulator::Now() + lifetime;
101  m_root.seqnum = seqnum;
102  m_root.interface = interface;
103 }
104 
105 void
107  uint32_t precursorInterface,
108  Mac48Address precursorAddress,
109  Time lifetime)
110 {
111  NS_LOG_FUNCTION(this << destination << precursorInterface << precursorAddress << lifetime);
112  Precursor precursor;
113  precursor.interface = precursorInterface;
114  precursor.address = precursorAddress;
115  precursor.whenExpire = Simulator::Now() + lifetime;
116  auto i = m_routes.find(destination);
117  if (i != m_routes.end())
118  {
119  bool should_add = true;
120  for (unsigned int j = 0; j < i->second.precursors.size(); j++)
121  {
122  // NB: Only one active route may exist, so do not check
123  // interface ID, just address
124  if (i->second.precursors[j].address == precursorAddress)
125  {
126  should_add = false;
127  i->second.precursors[j].whenExpire = precursor.whenExpire;
128  break;
129  }
130  }
131  if (should_add)
132  {
133  i->second.precursors.push_back(precursor);
134  }
135  }
136 }
137 
138 void
140 {
141  NS_LOG_FUNCTION(this);
142  m_root.precursors.clear();
146  m_root.seqnum = 0;
148 }
149 
150 void
152 {
153  NS_LOG_FUNCTION(this << root);
154  if (m_root.root == root)
155  {
157  }
158 }
159 
160 void
162 {
163  NS_LOG_FUNCTION(this << destination);
164  auto i = m_routes.find(destination);
165  if (i != m_routes.end())
166  {
167  m_routes.erase(i);
168  }
169 }
170 
173 {
174  NS_LOG_FUNCTION(this << destination);
175  auto i = m_routes.find(destination);
176  if (i == m_routes.end())
177  {
178  return LookupResult();
179  }
180  if ((i->second.whenExpire < Simulator::Now()) && (i->second.whenExpire != Seconds(0)))
181  {
182  NS_LOG_DEBUG("Reactive route has expired, sorry.");
183  return LookupResult();
184  }
185  return LookupReactiveExpired(destination);
186 }
187 
190 {
191  NS_LOG_FUNCTION(this << destination);
192  auto i = m_routes.find(destination);
193  if (i == m_routes.end())
194  {
195  return LookupResult();
196  }
197  NS_LOG_DEBUG("Returning reactive route to " << destination);
198  return LookupResult(i->second.retransmitter,
199  i->second.interface,
200  i->second.metric,
201  i->second.seqnum,
202  i->second.whenExpire - Simulator::Now());
203 }
204 
207 {
208  NS_LOG_FUNCTION(this);
210  {
211  NS_LOG_DEBUG("Proactive route has expired and will be deleted, sorry.");
213  }
214  return LookupProactiveExpired();
215 }
216 
219 {
220  NS_LOG_FUNCTION(this);
221  NS_LOG_DEBUG("Returning proactive route to root");
224  m_root.metric,
225  m_root.seqnum,
227 }
228 
229 std::vector<HwmpProtocol::FailedDestination>
231 {
232  NS_LOG_FUNCTION(this << peerAddress);
234  std::vector<HwmpProtocol::FailedDestination> retval;
235  for (auto i = m_routes.begin(); i != m_routes.end(); i++)
236  {
237  if (i->second.retransmitter == peerAddress)
238  {
239  dst.destination = i->first;
240  i->second.seqnum++;
241  dst.seqnum = i->second.seqnum;
242  retval.push_back(dst);
243  }
244  }
245  // Lookup a path to root
246  if (m_root.retransmitter == peerAddress)
247  {
248  dst.destination = m_root.root;
249  dst.seqnum = m_root.seqnum;
250  retval.push_back(dst);
251  }
252  return retval;
253 }
254 
257 {
258  NS_LOG_FUNCTION(this << destination);
259  // We suppose that no duplicates here can be
260  PrecursorList retval;
261  auto route = m_routes.find(destination);
262  if (route != m_routes.end())
263  {
264  for (auto i = route->second.precursors.begin(); i != route->second.precursors.end(); i++)
265  {
266  if (i->whenExpire > Simulator::Now())
267  {
268  retval.emplace_back(i->interface, i->address);
269  }
270  }
271  }
272  return retval;
273 }
274 
275 bool
277 {
278  return (retransmitter == o.retransmitter && ifIndex == o.ifIndex && metric == o.metric &&
279  seqnum == o.seqnum);
280 }
281 
282 HwmpRtable::LookupResult::LookupResult(Mac48Address r, uint32_t i, uint32_t m, uint32_t s, Time l)
283  : retransmitter(r),
284  ifIndex(i),
285  metric(m),
286  seqnum(s),
287  lifetime(l)
288 {
289 }
290 
291 bool
293 {
294  return !(retransmitter == Mac48Address::GetBroadcast() && ifIndex == INTERFACE_ANY &&
295  metric == MAX_METRIC && seqnum == 0);
296 }
297 } // namespace dot11s
298 } // namespace ns3
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetBroadcast()
A base class which provides memory management and object aggregation.
Definition: object.h:89
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Routing table for HWMP – 802.11s routing protocol.
Definition: hwmp-rtable.h:40
void DeleteReactivePath(Mac48Address destination)
Delete the reactive paths toward a destination.
Definition: hwmp-rtable.cc:161
void DoDispose() override
Destructor implementation.
Definition: hwmp-rtable.cc:58
static const uint32_t INTERFACE_ANY
Means all interfaces.
Definition: hwmp-rtable.h:43
static const uint32_t MAX_METRIC
Maximum (the best?) path metric.
Definition: hwmp-rtable.h:45
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
Definition: hwmp-rtable.cc:172
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
Definition: hwmp-rtable.cc:189
static TypeId GetTypeId()
Get the type ID.
Definition: hwmp-rtable.cc:39
std::map< Mac48Address, ReactiveRoute > m_routes
List of routes.
Definition: hwmp-rtable.h:231
PrecursorList GetPrecursors(Mac48Address destination)
Get the precursors list.
Definition: hwmp-rtable.cc:256
void DeleteProactivePath()
Delete all the proactive paths.
Definition: hwmp-rtable.cc:139
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
Definition: hwmp-rtable.cc:218
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:82
std::vector< HwmpProtocol::FailedDestination > GetUnreachableDestinations(Mac48Address peerAddress)
When peer link with a given MAC-address fails - it returns list of unreachable destination addresses.
Definition: hwmp-rtable.cc:230
ProactiveRoute m_root
Path to proactive tree root MP.
Definition: hwmp-rtable.h:233
LookupResult LookupProactive()
Find proactive path to tree root.
Definition: hwmp-rtable.cc:206
void AddPrecursor(Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime)
Add a precursor.
Definition: hwmp-rtable.cc:106
void AddProactivePath(uint32_t metric, Mac48Address root, Mac48Address retransmitter, uint32_t interface, Time lifetime, uint32_t seqnum)
Add a proactive path.
Definition: hwmp-rtable.cc:89
void AddReactivePath(Mac48Address destination, Mac48Address retransmitter, uint32_t interface, uint32_t metric, Time lifetime, uint32_t seqnum)
Add a reactive path.
Definition: hwmp-rtable.cc:64
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
structure of unreachable destination - address and sequence number
Definition: hwmp-protocol.h:89
Mac48Address destination
destination address
Definition: hwmp-protocol.h:90
Route lookup result, return type of LookupXXX methods.
Definition: hwmp-rtable.h:49
LookupResult(Mac48Address r=Mac48Address::GetBroadcast(), uint32_t i=INTERFACE_ANY, uint32_t m=MAX_METRIC, uint32_t s=0, Time l=Seconds(0.0))
Lookup result function.
Definition: hwmp-rtable.cc:282
bool operator==(const LookupResult &o) const
Compare route lookup results, used by tests.
Definition: hwmp-rtable.cc:276
uint32_t seqnum
sequence number
Definition: hwmp-rtable.h:53
Mac48Address retransmitter
retransmitter
Definition: hwmp-rtable.h:50
Route found in reactive mode.
Definition: hwmp-rtable.h:201
std::vector< Precursor > precursors
precursors
Definition: hwmp-rtable.h:227
Mac48Address retransmitter
retransmitter
Definition: hwmp-rtable.h:222
Route found in reactive mode.
Definition: hwmp-rtable.h:209