A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 namespace dot11s {
31 
32 NS_LOG_COMPONENT_DEFINE ("HwmpRtable");
33 
34 NS_OBJECT_ENSURE_REGISTERED (HwmpRtable);
35 
36 TypeId
38 {
39  static TypeId tid = TypeId ("ns3::dot11s::HwmpRtable")
40  .SetParent<Object> ()
41  .AddConstructor<HwmpRtable> ();
42  return tid;
43 }
45 {
47 }
49 {
50 }
51 void
53 {
54  m_routes.clear ();
55 }
56 void
57 HwmpRtable::AddReactivePath (Mac48Address destination, Mac48Address retransmitter, uint32_t interface,
58  uint32_t metric, Time lifetime, uint32_t seqnum)
59 {
60  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
61  if (i == m_routes.end ())
62  {
63  ReactiveRoute newroute;
64  m_routes[destination] = newroute;
65  }
66  i = m_routes.find (destination);
67  NS_ASSERT (i != m_routes.end ());
68  i->second.retransmitter = retransmitter;
69  i->second.interface = interface;
70  i->second.metric = metric;
71  i->second.whenExpire = Simulator::Now () + lifetime;
72  i->second.seqnum = seqnum;
73 }
74 void
75 HwmpRtable::AddProactivePath (uint32_t metric, Mac48Address root, Mac48Address retransmitter,
76  uint32_t interface, Time lifetime, uint32_t seqnum)
77 {
78  m_root.root = root;
79  m_root.retransmitter = retransmitter;
80  m_root.metric = metric;
81  m_root.whenExpire = Simulator::Now () + lifetime;
82  m_root.seqnum = seqnum;
83  m_root.interface = interface;
84 }
85 void
86 HwmpRtable::AddPrecursor (Mac48Address destination, uint32_t precursorInterface,
87  Mac48Address precursorAddress, Time lifetime)
88 {
89  Precursor precursor;
90  precursor.interface = precursorInterface;
91  precursor.address = precursorAddress;
92  precursor.whenExpire = Simulator::Now () + lifetime;
93  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
94  if (i != m_routes.end ())
95  {
96  bool should_add = true;
97  for (unsigned int j = 0; j < i->second.precursors.size (); j++)
98  {
99  //NB: Only one active route may exist, so do not check
100  //interface ID, just address
101  if (i->second.precursors[j].address == precursorAddress)
102  {
103  should_add = false;
104  i->second.precursors[j].whenExpire = precursor.whenExpire;
105  break;
106  }
107  }
108  if (should_add)
109  {
110  i->second.precursors.push_back (precursor);
111  }
112  }
113 }
114 void
116 {
117  m_root.precursors.clear ();
121  m_root.seqnum = 0;
123 }
124 void
126 {
127  if (m_root.root == root)
128  {
130  }
131 }
132 void
134 {
135  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
136  if (i != m_routes.end ())
137  {
138  m_routes.erase (i);
139  }
140 }
143 {
144  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
145  if (i == m_routes.end ())
146  {
147  return LookupResult ();
148  }
149  if ((i->second.whenExpire < Simulator::Now ()) && (i->second.whenExpire != Seconds (0)))
150  {
151  NS_LOG_DEBUG ("Reactive route has expired, sorry.");
152  return LookupResult ();
153  }
154  return LookupReactiveExpired (destination);
155 }
158 {
159  std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination);
160  if (i == m_routes.end ())
161  {
162  return LookupResult ();
163  }
164  return LookupResult (i->second.retransmitter, i->second.interface, i->second.metric, i->second.seqnum,
165  i->second.whenExpire - Simulator::Now ());
166 }
169 {
171  {
172  NS_LOG_DEBUG ("Proactive route has expired and will be deleted, sorry.");
174  }
175  return LookupProactiveExpired ();
176 }
179 {
182 }
183 std::vector<HwmpProtocol::FailedDestination>
185 {
187  std::vector<HwmpProtocol::FailedDestination> retval;
188  for (std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.begin (); i != m_routes.end (); i++)
189  {
190  if (i->second.retransmitter == peerAddress)
191  {
192  dst.destination = i->first;
193  i->second.seqnum++;
194  dst.seqnum = i->second.seqnum;
195  retval.push_back (dst);
196  }
197  }
198  //Lookup a path to root
199  if (m_root.retransmitter == peerAddress)
200  {
201  dst.destination = m_root.root;
202  dst.seqnum = m_root.seqnum;
203  retval.push_back (dst);
204  }
205  return retval;
206 }
209 {
210  //We suppose that no duplicates here can be
211  PrecursorList retval;
212  std::map<Mac48Address, ReactiveRoute>::iterator route = m_routes.find (destination);
213  if (route != m_routes.end ())
214  {
215  for (std::vector<Precursor>::const_iterator i = route->second.precursors.begin ();
216  i != route->second.precursors.end (); i++)
217  {
218  if (i->whenExpire > Simulator::Now ())
219  {
220  retval.push_back (std::make_pair (i->interface, i->address));
221  }
222  }
223  }
224  return retval;
225 }
226 bool
228 {
229  return (retransmitter == o.retransmitter && ifIndex == o.ifIndex && metric == o.metric && seqnum
230  == o.seqnum);
231 }
232 HwmpRtable::LookupResult::LookupResult (Mac48Address r, uint32_t i, uint32_t m, uint32_t s, Time l) :
233  retransmitter (r), ifIndex (i), metric (m), seqnum (s), lifetime (l)
234 {
235 }
236 bool
238 {
239  return !(retransmitter == Mac48Address::GetBroadcast () && ifIndex == INTERFACE_ANY && metric == MAX_METRIC
240  && seqnum == 0);
241 }
242 } // namespace dot11s
243 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
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 the class in the ns-3 factory.
Definition: object-base.h:38
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:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
Definition: hwmp-rtable.cc:157
bool IsValid() const
True for valid route.
Definition: hwmp-rtable.cc:237
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: hwmp-rtable.cc:52
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
Definition: hwmp-rtable.cc:142
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:62
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:184
PrecursorList GetPrecursors(Mac48Address destination)
Definition: hwmp-rtable.cc:208
Ptr< SampleEmitter > s
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:86
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
Definition: hwmp-rtable.cc:178
void AddReactivePath(Mac48Address destination, Mac48Address retransmitter, uint32_t interface, uint32_t metric, Time lifetime, uint32_t seqnum)
Definition: hwmp-rtable.cc:57
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:227
std::map< Mac48Address, ReactiveRoute > m_routes
List of routes.
Definition: hwmp-rtable.h:140
an EUI-48 address
Definition: mac48-address.h:41
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
static TypeId GetTypeId()
Definition: hwmp-rtable.cc:37
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
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:232
void DeleteReactivePath(Mac48Address destination)
Definition: hwmp-rtable.cc:133
void AddProactivePath(uint32_t metric, Mac48Address root, Mac48Address retransmitter, uint32_t interface, Time lifetime, uint32_t seqnum)
Definition: hwmp-rtable.cc:75
a base class which provides memory management and object aggregation
Definition: object.h:64
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
LookupResult LookupProactive()
Find proactive path to tree root. Note that calling this method has side effect of deleting expired p...
Definition: hwmp-rtable.cc:168