A Discrete-Event Network Simulator
API
hwmp-rtable.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008,2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Kirill Andreev <andreev@iitp.ru>
19  */
20 
21 #include "ns3/object.h"
22 #include "ns3/assert.h"
23 #include "ns3/simulator.h"
24 #include "ns3/test.h"
25 #include "ns3/log.h"
26 
27 #include "hwmp-rtable.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("HwmpRtable");
32 
33 namespace dot11s {
34 
35 NS_OBJECT_ENSURE_REGISTERED (HwmpRtable);
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::dot11s::HwmpRtable")
41  .SetParent<Object> ()
42  .SetGroupName ("Mesh")
43  .AddConstructor<HwmpRtable> ();
44  return tid;
45 }
47 {
49 }
51 {
52 }
53 void
55 {
56  m_routes.clear ();
57 }
58 void
59 HwmpRtable::AddReactivePath (Mac48Address destination, Mac48Address retransmitter, uint32_t interface,
60  uint32_t metric, Time lifetime, uint32_t seqnum)
61 {
62  NS_LOG_FUNCTION (this << destination << retransmitter << interface << metric << lifetime.GetSeconds () << seqnum);
63  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
64  if (i == m_routes.end ())
65  {
66  ReactiveRoute newroute;
67  m_routes[destination] = newroute;
68  }
69  i = m_routes.find (destination);
70  NS_ASSERT (i != m_routes.end ());
71  i->second.retransmitter = retransmitter;
72  i->second.interface = interface;
73  i->second.metric = metric;
74  i->second.whenExpire = Simulator::Now () + lifetime;
75  i->second.seqnum = seqnum;
76 }
77 void
78 HwmpRtable::AddProactivePath (uint32_t metric, Mac48Address root, Mac48Address retransmitter,
79  uint32_t interface, Time lifetime, uint32_t seqnum)
80 {
81  NS_LOG_FUNCTION (this << metric << root << retransmitter << interface << lifetime << seqnum);
82  m_root.root = root;
83  m_root.retransmitter = retransmitter;
84  m_root.metric = metric;
85  m_root.whenExpire = Simulator::Now () + lifetime;
86  m_root.seqnum = seqnum;
87  m_root.interface = interface;
88 }
89 void
90 HwmpRtable::AddPrecursor (Mac48Address destination, uint32_t precursorInterface,
91  Mac48Address precursorAddress, 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  std::map<Mac48Address, ReactiveRoute>::iterator 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 void
121 {
122  NS_LOG_FUNCTION (this);
123  m_root.precursors.clear ();
127  m_root.seqnum = 0;
129 }
130 void
132 {
133  NS_LOG_FUNCTION (this << root);
134  if (m_root.root == root)
135  {
137  }
138 }
139 void
141 {
142  NS_LOG_FUNCTION (this << destination);
143  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
144  if (i != m_routes.end ())
145  {
146  m_routes.erase (i);
147  }
148 }
151 {
152  NS_LOG_FUNCTION (this << destination);
153  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
154  if (i == m_routes.end ())
155  {
156  return LookupResult ();
157  }
158  if ((i->second.whenExpire < Simulator::Now ()) && (i->second.whenExpire != Seconds (0)))
159  {
160  NS_LOG_DEBUG ("Reactive route has expired, sorry.");
161  return LookupResult ();
162  }
163  return LookupReactiveExpired (destination);
164 }
167 {
168  NS_LOG_FUNCTION (this << destination);
169  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
170  if (i == m_routes.end ())
171  {
172  return LookupResult ();
173  }
174  NS_LOG_DEBUG ("Returning reactive route to " << destination);
175  return LookupResult (i->second.retransmitter, i->second.interface, i->second.metric, i->second.seqnum,
176  i->second.whenExpire - Simulator::Now ());
177 }
180 {
181  NS_LOG_FUNCTION (this);
183  {
184  NS_LOG_DEBUG ("Proactive route has expired and will be deleted, sorry.");
186  }
187  return LookupProactiveExpired ();
188 }
191 {
192  NS_LOG_FUNCTION (this);
193  NS_LOG_DEBUG ("Returning proactive route to root");
196 }
197 std::vector<HwmpProtocol::FailedDestination>
199 {
200  NS_LOG_FUNCTION (this << peerAddress);
202  std::vector<HwmpProtocol::FailedDestination> retval;
203  for (std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.begin (); i != m_routes.end (); i++)
204  {
205  if (i->second.retransmitter == peerAddress)
206  {
207  dst.destination = i->first;
208  i->second.seqnum++;
209  dst.seqnum = i->second.seqnum;
210  retval.push_back (dst);
211  }
212  }
213  //Lookup a path to root
214  if (m_root.retransmitter == peerAddress)
215  {
216  dst.destination = m_root.root;
217  dst.seqnum = m_root.seqnum;
218  retval.push_back (dst);
219  }
220  return retval;
221 }
224 {
225  NS_LOG_FUNCTION (this << destination);
226  //We suppose that no duplicates here can be
227  PrecursorList retval;
228  std::map<Mac48Address, ReactiveRoute>::iterator route = m_routes.find (destination);
229  if (route != m_routes.end ())
230  {
231  for (std::vector<Precursor>::const_iterator i = route->second.precursors.begin ();
232  i != route->second.precursors.end (); i++)
233  {
234  if (i->whenExpire > Simulator::Now ())
235  {
236  retval.push_back (std::make_pair (i->interface, i->address));
237  }
238  }
239  }
240  return retval;
241 }
242 bool
244 {
245  return (retransmitter == o.retransmitter && ifIndex == o.ifIndex && metric == o.metric && seqnum
246  == o.seqnum);
247 }
248 HwmpRtable::LookupResult::LookupResult (Mac48Address r, uint32_t i, uint32_t m, uint32_t s, Time l) :
249  retransmitter (r), ifIndex (i), metric (m), seqnum (s), lifetime (l)
250 {
251 }
252 bool
254 {
255  return !(retransmitter == Mac48Address::GetBroadcast () && ifIndex == INTERFACE_ANY && metric == MAX_METRIC
256  && seqnum == 0);
257 }
258 } // namespace dot11s
259 } // namespace ns3
an EUI-48 address
Definition: mac48-address.h:44
static Mac48Address GetBroadcast(void)
A base class which provides memory management and object aggregation.
Definition: object.h:88
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Routing table for HWMP – 802.11s routing protocol.
Definition: hwmp-rtable.h:36
void DeleteReactivePath(Mac48Address destination)
Delete the reactive paths toward a destination.
Definition: hwmp-rtable.cc:140
void DoDispose()
Destructor implementation.
Definition: hwmp-rtable.cc:54
static const uint32_t INTERFACE_ANY
Means all interfaces.
Definition: hwmp-rtable.h:39
static const uint32_t MAX_METRIC
Maximum (the best?) path metric.
Definition: hwmp-rtable.h:41
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
Definition: hwmp-rtable.cc:150
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
Definition: hwmp-rtable.cc:166
static TypeId GetTypeId()
Get the type ID.
Definition: hwmp-rtable.cc:38
std::map< Mac48Address, ReactiveRoute > m_routes
List of routes.
Definition: hwmp-rtable.h:222
PrecursorList GetPrecursors(Mac48Address destination)
Get the precursors list.
Definition: hwmp-rtable.cc:223
void DeleteProactivePath()
Delete all the proactive paths.
Definition: hwmp-rtable.cc:120
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
Definition: hwmp-rtable.cc:190
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:77
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:198
ProactiveRoute m_root
Path to proactive tree root MP.
Definition: hwmp-rtable.h:224
LookupResult LookupProactive()
Find proactive path to tree root.
Definition: hwmp-rtable.cc:179
void AddPrecursor(Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime)
Add a precursor.
Definition: hwmp-rtable.cc:90
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:78
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:59
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
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:79
Mac48Address destination
destination address
Definition: hwmp-protocol.h:80
Route lookup result, return type of LookupXXX methods.
Definition: hwmp-rtable.h:45
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:248
bool operator==(const LookupResult &o) const
Compare route lookup results, used by tests.
Definition: hwmp-rtable.cc:243
uint32_t seqnum
sequence number
Definition: hwmp-rtable.h:49
Mac48Address retransmitter
retransmitter
Definition: hwmp-rtable.h:46
Route found in reactive mode.
Definition: hwmp-rtable.h:194
std::vector< Precursor > precursors
precursors
Definition: hwmp-rtable.h:218
Mac48Address retransmitter
retransmitter
Definition: hwmp-rtable.h:213
Route found in reactive mode.
Definition: hwmp-rtable.h:201