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  std::map<Mac48Address, ReactiveRoute>::iterator 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 void
77 HwmpRtable::AddProactivePath (uint32_t metric, Mac48Address root, Mac48Address retransmitter,
78  uint32_t interface, Time lifetime, uint32_t seqnum)
79 {
80  m_root.root = root;
81  m_root.retransmitter = retransmitter;
82  m_root.metric = metric;
83  m_root.whenExpire = Simulator::Now () + lifetime;
84  m_root.seqnum = seqnum;
85  m_root.interface = interface;
86 }
87 void
88 HwmpRtable::AddPrecursor (Mac48Address destination, uint32_t precursorInterface,
89  Mac48Address precursorAddress, Time lifetime)
90 {
91  Precursor precursor;
92  precursor.interface = precursorInterface;
93  precursor.address = precursorAddress;
94  precursor.whenExpire = Simulator::Now () + lifetime;
95  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
96  if (i != m_routes.end ())
97  {
98  bool should_add = true;
99  for (unsigned int j = 0; j < i->second.precursors.size (); j++)
100  {
101  //NB: Only one active route may exist, so do not check
102  //interface ID, just address
103  if (i->second.precursors[j].address == precursorAddress)
104  {
105  should_add = false;
106  i->second.precursors[j].whenExpire = precursor.whenExpire;
107  break;
108  }
109  }
110  if (should_add)
111  {
112  i->second.precursors.push_back (precursor);
113  }
114  }
115 }
116 void
118 {
119  m_root.precursors.clear ();
123  m_root.seqnum = 0;
125 }
126 void
128 {
129  if (m_root.root == root)
130  {
132  }
133 }
134 void
136 {
137  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
138  if (i != m_routes.end ())
139  {
140  m_routes.erase (i);
141  }
142 }
145 {
146  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
147  if (i == m_routes.end ())
148  {
149  return LookupResult ();
150  }
151  if ((i->second.whenExpire < Simulator::Now ()) && (i->second.whenExpire != Seconds (0)))
152  {
153  NS_LOG_DEBUG ("Reactive route has expired, sorry.");
154  return LookupResult ();
155  }
156  return LookupReactiveExpired (destination);
157 }
160 {
161  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
162  if (i == m_routes.end ())
163  {
164  return LookupResult ();
165  }
166  return LookupResult (i->second.retransmitter, i->second.interface, i->second.metric, i->second.seqnum,
167  i->second.whenExpire - Simulator::Now ());
168 }
171 {
173  {
174  NS_LOG_DEBUG ("Proactive route has expired and will be deleted, sorry.");
176  }
177  return LookupProactiveExpired ();
178 }
181 {
184 }
185 std::vector<HwmpProtocol::FailedDestination>
187 {
189  std::vector<HwmpProtocol::FailedDestination> retval;
190  for (std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.begin (); i != m_routes.end (); i++)
191  {
192  if (i->second.retransmitter == peerAddress)
193  {
194  dst.destination = i->first;
195  i->second.seqnum++;
196  dst.seqnum = i->second.seqnum;
197  retval.push_back (dst);
198  }
199  }
200  //Lookup a path to root
201  if (m_root.retransmitter == peerAddress)
202  {
203  dst.destination = m_root.root;
204  dst.seqnum = m_root.seqnum;
205  retval.push_back (dst);
206  }
207  return retval;
208 }
211 {
212  //We suppose that no duplicates here can be
213  PrecursorList retval;
214  std::map<Mac48Address, ReactiveRoute>::iterator route = m_routes.find (destination);
215  if (route != m_routes.end ())
216  {
217  for (std::vector<Precursor>::const_iterator i = route->second.precursors.begin ();
218  i != route->second.precursors.end (); i++)
219  {
220  if (i->whenExpire > Simulator::Now ())
221  {
222  retval.push_back (std::make_pair (i->interface, i->address));
223  }
224  }
225  }
226  return retval;
227 }
228 bool
230 {
231  return (retransmitter == o.retransmitter && ifIndex == o.ifIndex && metric == o.metric && seqnum
232  == o.seqnum);
233 }
234 HwmpRtable::LookupResult::LookupResult (Mac48Address r, uint32_t i, uint32_t m, uint32_t s, Time l) :
235  retransmitter (r), ifIndex (i), metric (m), seqnum (s), lifetime (l)
236 {
237 }
238 bool
240 {
241  return !(retransmitter == Mac48Address::GetBroadcast () && ifIndex == INTERFACE_ANY && metric == MAX_METRIC
242  && seqnum == 0);
243 }
244 } // namespace dot11s
245 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
ProactiveRoute m_root
Path to proactive tree root MP.
Definition: hwmp-rtable.h:142
std::vector< Precursor > precursors
Definition: hwmp-rtable.h:136
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
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
structure of unreachable destination - address and sequence number
Definition: hwmp-protocol.h:57
#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:201
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
Definition: hwmp-rtable.cc:159
bool IsValid() const
True for valid route.
Definition: hwmp-rtable.cc:239
void DoDispose()
Destructor implementation.
Definition: hwmp-rtable.cc:54
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
Definition: hwmp-rtable.cc:144
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:62
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:186
PrecursorList GetPrecursors(Mac48Address destination)
Definition: hwmp-rtable.cc:210
Route found in reactive mode.
Definition: hwmp-rtable.h:112
static Mac48Address GetBroadcast(void)
void AddPrecursor(Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime)
Definition: hwmp-rtable.cc:88
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
Definition: hwmp-rtable.cc:180
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
bool operator==(const LookupResult &o) const
Compare route lookup results, used by tests.
Definition: hwmp-rtable.cc:229
std::map< Mac48Address, ReactiveRoute > m_routes
List of routes.
Definition: hwmp-rtable.h:140
an EUI-48 address
Definition: mac48-address.h:43
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
static TypeId GetTypeId()
Definition: hwmp-rtable.cc:38
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
LookupResult(Mac48Address r=Mac48Address::GetBroadcast(), uint32_t i=INTERFACE_ANY, uint32_t m=MAX_METRIC, uint32_t s=0, Time l=Seconds(0.0))
Definition: hwmp-rtable.cc:234
void DeleteReactivePath(Mac48Address destination)
Definition: hwmp-rtable.cc:135
void AddProactivePath(uint32_t metric, Mac48Address root, Mac48Address retransmitter, uint32_t interface, Time lifetime, uint32_t seqnum)
Definition: hwmp-rtable.cc:77
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
LookupResult LookupProactive()
Find proactive path to tree root. Note that calling this method has side effect of deleting expired p...
Definition: hwmp-rtable.cc:170