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
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ProactiveRoute m_root
Path to proactive tree root MP.
Definition: hwmp-rtable.h:166
std::vector< Precursor > precursors
precursors
Definition: hwmp-rtable.h:160
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
static const uint32_t MAX_METRIC
Maximum (the best?) path metric.
Definition: hwmp-rtable.h:41
Route lookup result, return type of LookupXXX methods.
Definition: hwmp-rtable.h:44
uint32_t seqnum
sequence number
Definition: hwmp-rtable.h:159
structure of unreachable destination - address and sequence number
Definition: hwmp-protocol.h:76
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
#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:202
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
Definition: hwmp-rtable.cc:166
void DoDispose()
Destructor implementation.
Definition: hwmp-rtable.cc:54
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
Definition: hwmp-rtable.cc:150
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:77
uint32_t seqnum
sequence number
Definition: hwmp-rtable.h:49
Routing table for HWMP – 802.11s routing protocol.
Definition: hwmp-rtable.h:35
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
PrecursorList GetPrecursors(Mac48Address destination)
Definition: hwmp-rtable.cc:223
Route found in reactive mode.
Definition: hwmp-rtable.h:135
static Mac48Address GetBroadcast(void)
void AddPrecursor(Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime)
Definition: hwmp-rtable.cc:90
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
Definition: hwmp-rtable.cc:190
bool operator==(const LookupResult &o) const
Compare route lookup results, used by tests.
Definition: hwmp-rtable.cc:243
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AddReactivePath(Mac48Address destination, Mac48Address retransmitter, uint32_t interface, uint32_t metric, Time lifetime, uint32_t seqnum)
Definition: hwmp-rtable.cc:59
static const uint32_t INTERFACE_ANY
Means all interfaces.
Definition: hwmp-rtable.h:39
std::map< Mac48Address, ReactiveRoute > m_routes
List of routes.
Definition: hwmp-rtable.h:164
an EUI-48 address
Definition: mac48-address.h:43
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
static TypeId GetTypeId()
Get the type ID.
Definition: hwmp-rtable.cc:38
Mac48Address destination
destination address
Definition: hwmp-protocol.h:78
Mac48Address retransmitter
retransmitter
Definition: hwmp-rtable.h:46
Mac48Address address
address
Definition: hwmp-rtable.h:137
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
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
void DeleteReactivePath(Mac48Address destination)
Definition: hwmp-rtable.cc:140
void AddProactivePath(uint32_t metric, Mac48Address root, Mac48Address retransmitter, uint32_t interface, Time lifetime, uint32_t seqnum)
Definition: hwmp-rtable.cc:78
A base class which provides memory management and object aggregation.
Definition: object.h:87
Mac48Address retransmitter
retransmitter
Definition: hwmp-rtable.h:155
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
Route found in reactive mode.
Definition: hwmp-rtable.h:142
LookupResult LookupProactive()
Find proactive path to tree root. Note that calling this method has side effect of deleting expired p...
Definition: hwmp-rtable.cc:179