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