author | Tom Henderson <tomh@tomh.org> |
Sun, 13 May 2012 10:47:11 -0700 | |
changeset 8756 | 9a34e618f40b |
parent 8752 | 2da1fab73114 |
child 8775 | b05792ad16f7 |
permissions | -rw-r--r-- |
8751 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2011 Yufei Cheng |
|
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: Yufei Cheng <yfcheng@ittc.ku.edu> |
|
19 |
* Song Luan <lsuper@mail.ustc.edu.cn> (Implemented Link Cache using dijsktra algorithm to get the best route) |
|
20 |
* |
|
21 |
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director |
|
22 |
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets |
|
23 |
* Information and Telecommunication Technology Center (ITTC) |
|
24 |
* and Department of Electrical Engineering and Computer Science |
|
25 |
* The University of Kansas Lawrence, KS USA. |
|
26 |
* |
|
27 |
* Work supported in part by NSF FIND (Future Internet Design) Program |
|
28 |
* under grant CNS-0626918 (Postmodern Internet Architecture), |
|
29 |
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI), |
|
30 |
* US Department of Defense (DoD), and ITTC at The University of Kansas. |
|
31 |
*/ |
|
32 |
||
33 |
#ifndef DSR_RCACHE_H |
|
34 |
#define DSR_RCACHE_H |
|
35 |
||
36 |
#include <map> |
|
37 |
#include <stdint.h> |
|
38 |
#include <cassert> |
|
39 |
#include <sys/types.h> |
|
40 |
#include <iostream> |
|
41 |
#include <vector> |
|
42 |
||
43 |
#include "ns3/simulator.h" |
|
44 |
#include "ns3/timer.h" |
|
45 |
#include "ns3/simple-ref-count.h" |
|
46 |
#include "ns3/header.h" |
|
47 |
#include "ns3/enum.h" |
|
48 |
#include "ns3/ipv4-address.h" |
|
49 |
#include "ns3/nstime.h" |
|
50 |
#include "ns3/ipv4.h" |
|
51 |
#include "ns3/ipv4-route.h" |
|
52 |
#include "ns3/net-device.h" |
|
53 |
#include "ns3/ipv4-l3-protocol.h" |
|
54 |
#include "ns3/callback.h" |
|
55 |
#include "ns3/wifi-mac-header.h" |
|
56 |
#include "ns3/arp-cache.h" |
|
57 |
#include "dsr-option-header.h" |
|
58 |
||
59 |
namespace ns3 { |
|
60 |
class Time; |
|
61 |
namespace dsr { |
|
62 |
||
63 |
/* |
|
64 |
* The route cache structure |
|
65 |
\verbatim |
|
66 |
+-+-+-+-+-+-+-+-+-+-+-+- +-+-+-+-+-+-+-+-+-+-+- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+- |
|
67 |
| Destination Address |---------| Route Cache Entry | ---------- | IP_VECTOR | dst | exp time | |
|
68 |
+-+-+-+-+-+-+-+-+-+-+-+- Map +-+-+-+-+-+-+-+-+-+-+- Contains +-+-+-+-+-+-+-+-+-+-+-+-+-+-+- |
|
69 |
+-+-+-+-+-+-+-+-+-+-+- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+- |
|
70 |
| Route Cache Entry | ---------- | IP_VECTOR | dst | exp time | |
|
71 |
+-+-+-+-+-+-+-+-+-+-+- Contains +-+-+-+-+-+-+-+-+-+-+-+-+-+-+- |
|
72 |
. . |
|
73 |
. . |
|
74 |
. . |
|
75 |
. . |
|
76 |
+-+-+-+-+-+-+-+-+-+-+- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+- |
|
77 |
| Route Cache Entry | ---------- | IP_VECTOR | dst | exp time | |
|
78 |
+-+-+-+-+-+-+-+-+-+-+- Contains +-+-+-+-+-+-+-+-+-+-+-+-+-+-+- |
|
79 |
||
80 |
\endverbatim |
|
81 |
*/ |
|
82 |
/** |
|
83 |
* \ingroup dsr |
|
84 |
* \brief DSR Route Cache Entry |
|
85 |
*/ |
|
86 |
struct Link |
|
87 |
{ |
|
88 |
Ipv4Address m_low; |
|
89 |
Ipv4Address m_high; |
|
90 |
Link (Ipv4Address ip1, Ipv4Address ip2) |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
91 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
92 |
if (ip1 < ip2) |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
93 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
94 |
m_low = ip1; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
95 |
m_high = ip2; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
96 |
} |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
97 |
else |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
98 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
99 |
m_low = ip2; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
100 |
m_high = ip1; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
101 |
} |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
102 |
} |
8751 | 103 |
bool operator < (Link const& L) const |
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
104 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
105 |
if (m_low < L.m_low) |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
106 |
{ |
8751 | 107 |
return true; |
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
108 |
} |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
109 |
else if (m_low == L.m_low) |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
110 |
{ |
8751 | 111 |
return (m_high < L.m_high); |
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
112 |
} |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
113 |
else |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
114 |
{ |
8751 | 115 |
return false; |
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
116 |
} |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
117 |
} |
8751 | 118 |
void Print () const; |
119 |
}; |
|
120 |
||
121 |
class LinkStab |
|
122 |
{ |
|
123 |
public: |
|
124 |
/** |
|
125 |
* \brief Constructor |
|
126 |
*/ |
|
8752 | 127 |
LinkStab (Time linkStab = Simulator::Now ()); |
8751 | 128 |
/** |
129 |
* \brief Destructor |
|
130 |
*/ |
|
131 |
virtual ~LinkStab (); |
|
132 |
||
133 |
void SetLinkStability (Time linkStab) |
|
134 |
{ |
|
135 |
m_linkStability = linkStab + Simulator::Now (); |
|
136 |
} |
|
137 |
Time GetLinkStability () const |
|
138 |
{ |
|
139 |
return m_linkStability - Simulator::Now (); |
|
140 |
} |
|
141 |
||
142 |
void Print () const; |
|
8752 | 143 |
|
8751 | 144 |
private: |
145 |
/* |
|
146 |
* The link stability lifetime expected, when the time is due, the link expires the expiration happens |
|
147 |
* when purge the node and link cache before update them when receiving new information |
|
148 |
*/ |
|
149 |
Time m_linkStability; |
|
150 |
}; |
|
151 |
||
8752 | 152 |
class NodeStab |
153 |
{ |
|
154 |
public: |
|
155 |
/** |
|
156 |
* \brief Constructor |
|
157 |
*/ |
|
158 |
// NodeStab (); |
|
159 |
NodeStab (Time nodeStab = Simulator::Now ()); |
|
160 |
/** |
|
161 |
* \brief Destructor |
|
162 |
*/ |
|
163 |
virtual ~NodeStab (); |
|
164 |
||
165 |
void SetNodeStability (Time nodeStab) |
|
166 |
{ |
|
167 |
m_nodeStability = nodeStab + Simulator::Now (); |
|
168 |
} |
|
169 |
Time GetNodeStability () const |
|
170 |
{ |
|
171 |
return m_nodeStability - Simulator::Now (); |
|
172 |
} |
|
173 |
private: |
|
174 |
Time m_nodeStability; |
|
175 |
}; |
|
176 |
||
8751 | 177 |
class RouteCacheEntry |
178 |
{ |
|
179 |
public: |
|
180 |
typedef std::vector<Ipv4Address> IP_VECTOR; // Define the vector to hold Ip address |
|
181 |
typedef std::vector<Ipv4Address>::iterator Iterator; // Define the iterator |
|
182 |
// / c-tor |
|
183 |
/** |
|
184 |
* \brief Constructor |
|
185 |
*/ |
|
186 |
RouteCacheEntry (IP_VECTOR const & ip = IP_VECTOR (), Ipv4Address dst = Ipv4Address (), Time exp = Simulator::Now ()); |
|
187 |
/** |
|
188 |
* \brief Destructor |
|
189 |
*/ |
|
190 |
virtual ~RouteCacheEntry (); |
|
191 |
// / Mark entry as "down" (i.e. disable it) |
|
192 |
void Invalidate (Time badLinkLifetime); |
|
193 |
// /\name Fields |
|
194 |
// \{ |
|
195 |
void SetUnidirectional (bool u) |
|
196 |
{ |
|
197 |
m_blackListState = u; |
|
198 |
} |
|
199 |
bool IsUnidirectional () const |
|
200 |
{ |
|
201 |
return m_blackListState; |
|
202 |
} |
|
203 |
void SetBlacklistTimeout (Time t) |
|
204 |
{ |
|
205 |
m_blackListTimeout = t; |
|
206 |
} |
|
207 |
Time GetBlacklistTimeout () const |
|
208 |
{ |
|
209 |
return m_blackListTimeout; |
|
210 |
} |
|
211 |
Ipv4Address GetDestination () const |
|
212 |
{ |
|
213 |
return m_dst; |
|
214 |
} |
|
215 |
void SetDestination (Ipv4Address d) |
|
216 |
{ |
|
217 |
m_dst = d; |
|
218 |
} |
|
219 |
IP_VECTOR GetVector () const |
|
220 |
{ |
|
221 |
return m_path; |
|
222 |
} |
|
223 |
void SetVector (IP_VECTOR v) |
|
224 |
{ |
|
225 |
m_path = v; |
|
226 |
} |
|
227 |
void SetExpireTime (Time exp) |
|
228 |
{ |
|
229 |
m_expire = exp + Simulator::Now (); |
|
230 |
} |
|
231 |
Time GetExpireTime () const |
|
232 |
{ |
|
233 |
return m_expire - Simulator::Now (); |
|
234 |
} |
|
235 |
// \} |
|
236 |
/** |
|
237 |
* \brief Print necessary fields |
|
238 |
*/ |
|
239 |
void Print (std::ostream & os) const; |
|
240 |
/** |
|
241 |
* \brief Compare the route cache entry |
|
242 |
* \return true if equal |
|
243 |
*/ |
|
244 |
bool operator== (RouteCacheEntry const & o) const |
|
245 |
{ |
|
246 |
if (m_path.size () != o.m_path.size ()) |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
247 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
248 |
NS_ASSERT (false); |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
249 |
return false; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
250 |
} |
8751 | 251 |
IP_VECTOR::const_iterator j = o.m_path.begin (); |
252 |
for (IP_VECTOR::const_iterator i = m_path.begin (); i |
|
253 |
!= m_path.end (); i++, j++) |
|
254 |
{ |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
255 |
/* |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
256 |
* Verify if neither the entry are not 0 and they equal to each other |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
257 |
*/ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
258 |
if (((*i) == 0) || ((*j) == 0)) |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
259 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
260 |
return false; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
261 |
} |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
262 |
else if (!((*i) == (*j)) ) |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
263 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
264 |
return false; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
265 |
} |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
266 |
else |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
267 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
268 |
return true; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
269 |
} |
8752 | 270 |
} |
8751 | 271 |
return false; |
272 |
} |
|
273 |
// \} |
|
8752 | 274 |
|
275 |
private: |
|
8751 | 276 |
// / RREP_ACK timer |
277 |
Timer m_ackTimer; |
|
278 |
// / The destination Ip address |
|
279 |
Ipv4Address m_dst; |
|
280 |
// / brief The IP address constructed route |
|
281 |
IP_VECTOR m_path; |
|
282 |
// / Expire time for queue entry |
|
283 |
Time m_expire; |
|
284 |
// / Output interface address |
|
285 |
Ipv4InterfaceAddress m_iface; |
|
286 |
// / Number of route requests |
|
287 |
uint8_t m_reqCount; |
|
288 |
// / Indicate if this entry is in "blacklist" |
|
289 |
bool m_blackListState; |
|
290 |
// / Time for which the node is put into the blacklist |
|
291 |
Time m_blackListTimeout; |
|
292 |
// / The Ipv4 route |
|
293 |
Ptr<Ipv4Route> m_ipv4Route; |
|
294 |
// / The Ipv4 layer 3 |
|
295 |
Ptr<Ipv4> m_ipv4; |
|
296 |
}; |
|
297 |
/** |
|
298 |
* \ingroup dsr |
|
299 |
* \brief DSR route request queue |
|
300 |
* Since DSR is an on demand routing we queue requests while looking for route. |
|
301 |
*/ |
|
302 |
class RouteCache : public Object |
|
303 |
{ |
|
304 |
public: |
|
305 |
// / Default c-tor |
|
306 |
/** |
|
307 |
* \ingroup dsr |
|
308 |
* \brief The Route Cache used by DSR |
|
309 |
*/ |
|
310 |
static TypeId GetTypeId (); |
|
311 |
/** |
|
312 |
* \brief Constructor. |
|
313 |
*/ |
|
314 |
RouteCache (); |
|
315 |
/** |
|
316 |
* \brief Destructor. |
|
317 |
*/ |
|
318 |
virtual ~RouteCache (); |
|
319 |
// / Remove the aged route cache entries when the route cache is full |
|
320 |
void RemoveLastEntry (std::list<RouteCacheEntry> & rtVector); |
|
321 |
// / Define the vector of route entries. |
|
322 |
typedef std::list<RouteCacheEntry::IP_VECTOR> routeVector; |
|
323 |
// / Get the destination address of the route. |
|
324 |
Ipv4Address GetDestination (void) const; |
|
325 |
// / Remove all packets with destination IP address dst |
|
326 |
void DropPathWithDst (Ipv4Address dst); |
|
327 |
// / To know if the two entries are the same |
|
328 |
bool IsEqual (RouteCacheEntry ca); |
|
329 |
// /\name Fields |
|
330 |
// \{ |
|
331 |
bool GetSubRoute () const |
|
332 |
{ |
|
333 |
return m_subRoute; |
|
334 |
} |
|
335 |
void SetSubRoute (bool subRoute) |
|
336 |
{ |
|
337 |
m_subRoute = subRoute; |
|
338 |
} |
|
339 |
uint32_t GetMaxCacheLen () const |
|
340 |
{ |
|
341 |
return m_maxCacheLen; |
|
342 |
} |
|
343 |
void SetMaxCacheLen (uint32_t len) |
|
344 |
{ |
|
345 |
m_maxCacheLen = len; |
|
346 |
} |
|
347 |
Time GetCacheTimeout () const |
|
348 |
{ |
|
349 |
return RouteCacheTimeout; |
|
350 |
} |
|
351 |
void SetCacheTimeout (Time t) |
|
352 |
{ |
|
353 |
RouteCacheTimeout = t; |
|
354 |
} |
|
355 |
uint32_t GetMaxEntriesEachDst () const |
|
356 |
{ |
|
357 |
return m_maxEntriesEachDst; |
|
358 |
} |
|
359 |
void SetMaxEntriesEachDst (uint32_t entries) |
|
360 |
{ |
|
361 |
m_maxEntriesEachDst = entries; |
|
362 |
} |
|
363 |
Time GetBadLinkLifetime () const |
|
364 |
{ |
|
365 |
return m_badLinkLifetime; |
|
366 |
} |
|
367 |
void SetBadLinkLifetime (Time t) |
|
368 |
{ |
|
369 |
m_badLinkLifetime = t; |
|
370 |
} |
|
8752 | 371 |
uint64_t GetStabilityDecrFactor () const |
8751 | 372 |
{ |
373 |
return m_stabilityDecrFactor; |
|
374 |
} |
|
8752 | 375 |
void SetStabilityDecrFactor (uint64_t decrFactor) |
8751 | 376 |
{ |
377 |
m_stabilityDecrFactor = decrFactor; |
|
378 |
} |
|
8752 | 379 |
uint64_t GetStabilityIncrFactor () const |
8751 | 380 |
{ |
381 |
return m_stabilityIncrFactor; |
|
382 |
} |
|
8752 | 383 |
void SetStabilityIncrFactor (uint64_t incrFactor) |
8751 | 384 |
{ |
385 |
m_stabilityIncrFactor = incrFactor; |
|
386 |
} |
|
8752 | 387 |
Time GetInitStability () const |
8751 | 388 |
{ |
389 |
return m_initStability; |
|
390 |
} |
|
8752 | 391 |
void SetInitStability (Time initStability) |
8751 | 392 |
{ |
393 |
m_initStability = initStability; |
|
394 |
} |
|
8752 | 395 |
Time GetMinLifeTime () const |
8751 | 396 |
{ |
397 |
return m_minLifeTime; |
|
398 |
} |
|
8752 | 399 |
void SetMinLifeTime (Time minLifeTime) |
8751 | 400 |
{ |
401 |
m_minLifeTime = minLifeTime; |
|
402 |
} |
|
8752 | 403 |
Time GetUseExtends () const |
8751 | 404 |
{ |
405 |
return m_useExtends; |
|
406 |
} |
|
8752 | 407 |
void SetUseExtends (Time useExtends) |
8751 | 408 |
{ |
409 |
m_useExtends = useExtends; |
|
410 |
} |
|
411 |
// \} |
|
412 |
/** |
|
413 |
* Update route cache entry if it has been recently used and successfully delivered the data packet |
|
414 |
* \param dst destination address of the route |
|
415 |
* \param vec the route vector |
|
416 |
* \return true in success |
|
417 |
*/ |
|
418 |
bool UpdateRouteEntry (Ipv4Address dst); |
|
419 |
/** |
|
420 |
* Add route cache entry if it doesn't yet exist in route cache |
|
421 |
* \param rt route cache entry |
|
422 |
* \return true in success |
|
423 |
*/ |
|
424 |
bool AddRoute (RouteCacheEntry & rt); |
|
425 |
/** |
|
426 |
* Lookup route cache entry with destination address dst |
|
427 |
* \param dst destination address |
|
428 |
* \param rt entry with destination address dst, if exists |
|
429 |
* \return true on success |
|
430 |
*/ |
|
431 |
bool LookupRoute (Ipv4Address id, RouteCacheEntry & rt); |
|
432 |
/** |
|
433 |
* Print the route vector elements |
|
434 |
* \param vec the route vector |
|
435 |
*/ |
|
436 |
void PrintVector (std::vector<Ipv4Address>& vec); |
|
437 |
/** |
|
438 |
* Print all the route vector elements from the route list |
|
439 |
* \param route the route list |
|
440 |
*/ |
|
441 |
void PrintRouteVector (std::list<RouteCacheEntry> route); |
|
442 |
/** |
|
443 |
* Find the same route in the route cache |
|
444 |
* \param rt entry with destination address dst, if exists |
|
445 |
* \param rtVector the route vector |
|
446 |
*/ |
|
447 |
bool FindSameRoute (RouteCacheEntry & rt, std::list<RouteCacheEntry> & rtVector); |
|
448 |
/** |
|
449 |
* Delete the route with certain destination address |
|
450 |
* \param dst the destination address of the routes that should be deleted |
|
451 |
*/ |
|
452 |
bool DeleteRoute (Ipv4Address dst); |
|
453 |
/* |
|
454 |
* Delete all the routes which includes the link from next hop address that has just been notified |
|
455 |
* as unreachable |
|
456 |
*/ |
|
457 |
void DeleteAllRoutesIncludeLink (Ipv4Address errorSrc, Ipv4Address unreachNode, Ipv4Address node); |
|
458 |
// / Delete all entries from routing table |
|
459 |
void Clear () |
|
460 |
{ |
|
461 |
m_routeEntryVector.erase (m_routeEntryVector.begin (), m_routeEntryVector.end ()); |
|
462 |
} |
|
463 |
// / Delete all outdated entries and invalidate valid entry if Lifetime is expired |
|
464 |
void Purge (); |
|
465 |
// / Print route cache |
|
466 |
void Print (std::ostream &os); |
|
467 |
||
468 |
//------------------------------------------------------------------------------------------ |
|
469 |
/* |
|
470 |
* The following code deals with duplicate ack ids |
|
471 |
*/ |
|
472 |
// / Check for duplicate ids and save new entries if the id is not present in the table |
|
473 |
uint16_t CheckUniqueAckId (Ipv4Address nextHop); |
|
474 |
// / Get the ack table size |
|
475 |
uint16_t GetAckSize (); |
|
476 |
||
477 |
// -------------------------------------------------------------------------------------------- |
|
478 |
/* |
|
479 |
* The following code handles link-layer acks |
|
480 |
*/ |
|
481 |
// / Neighbor description |
|
482 |
struct Neighbor |
|
483 |
{ |
|
484 |
Ipv4Address m_neighborAddress; |
|
485 |
Mac48Address m_hardwareAddress; |
|
486 |
Time m_expireTime; |
|
487 |
bool close; |
|
488 |
||
489 |
Neighbor (Ipv4Address ip, Mac48Address mac, Time t) |
|
490 |
: m_neighborAddress (ip), |
|
491 |
m_hardwareAddress (mac), |
|
492 |
m_expireTime (t), |
|
493 |
close (false) |
|
494 |
{ |
|
495 |
} |
|
496 |
}; |
|
497 |
// / Return expire time for neighbor node with address addr, if exists, else return 0. |
|
498 |
Time GetExpireTime (Ipv4Address addr); |
|
499 |
// / Check that node with address addr is neighbor |
|
500 |
bool IsNeighbor (Ipv4Address addr); |
|
501 |
// / Update expire time for entry with address addr, if it exists, else add new entry |
|
502 |
void UpdateNeighbor (std::vector<Ipv4Address> nodeList, Time expire); |
|
503 |
// / Add to the neighbor list |
|
504 |
void AddNeighbor (std::vector<Ipv4Address> nodeList, Ipv4Address ownAddress, Time expire); |
|
505 |
// / Remove all expired mac entries |
|
506 |
void PurgeMac (); |
|
507 |
// / Schedule m_ntimer. |
|
508 |
void ScheduleTimer (); |
|
509 |
// / Remove all entries |
|
510 |
void ClearMac () |
|
511 |
{ |
|
512 |
m_nb.clear (); |
|
513 |
} |
|
514 |
// / Add ARP cache to be used to allow layer 2 notifications processing |
|
515 |
void AddArpCache (Ptr<ArpCache>); |
|
516 |
// / Don't use given ARP cache any more (interface is down) |
|
517 |
void DelArpCache (Ptr<ArpCache>); |
|
518 |
// / Get callback to ProcessTxError |
|
519 |
/* |
|
520 |
* This callback is trying to use the wifi mac tx error header to notify a link layer drop event, however, |
|
521 |
* it is not fully supported yet |
|
522 |
*/ |
|
523 |
Callback<void, WifiMacHeader const &> GetTxErrorCallback () const |
|
524 |
{ |
|
525 |
return m_txErrorCallback; |
|
526 |
} |
|
527 |
// /\name Handle link failure callback |
|
528 |
// \{ |
|
529 |
void SetCallback (Callback<void, Ipv4Address, uint8_t > cb) |
|
530 |
{ |
|
531 |
m_handleLinkFailure = cb; |
|
532 |
} |
|
533 |
Callback<void, Ipv4Address, uint8_t > GetCallback () const |
|
534 |
{ |
|
535 |
return m_handleLinkFailure; |
|
536 |
} |
|
537 |
// \} |
|
538 |
||
539 |
private: |
|
540 |
RouteCache & operator= (RouteCache const &); |
|
541 |
RouteCacheEntry::IP_VECTOR m_vector; // /< The route vector to save the ip addresses for intermediate nodes. |
|
542 |
uint32_t m_maxCacheLen; // /< The maximum number of packets that we allow a routing protocol to buffer. |
|
543 |
Time RouteCacheTimeout; // /< The maximum period of time that dsr is allowed to for an unused route. |
|
544 |
Time m_badLinkLifetime; // /< The time for which the neighboring node is put into the blacklist. |
|
545 |
/* |
|
546 |
* Define the parameters for link cache type |
|
547 |
*/ |
|
8752 | 548 |
uint64_t m_stabilityDecrFactor; |
549 |
uint64_t m_stabilityIncrFactor; |
|
550 |
Time m_initStability; |
|
551 |
Time m_minLifeTime; |
|
552 |
Time m_useExtends; |
|
8751 | 553 |
/* |
554 |
* Define the route cache data structure |
|
555 |
*/ |
|
556 |
typedef std::list<RouteCacheEntry> routeEntryVector; |
|
557 |
// / Map the ipv4Address to route entry vector |
|
558 |
std::map<Ipv4Address, routeEntryVector> m_sortedRoutes; |
|
559 |
// Define the route vector |
|
560 |
routeEntryVector m_routeEntryVector; |
|
561 |
// / number of entries for each destination |
|
562 |
uint32_t m_maxEntriesEachDst; |
|
563 |
// / The id cache to ensure all the ids are unique |
|
564 |
std::map<Ipv4Address, uint16_t> m_ackIdCache; |
|
565 |
// / Check if the route is using path cache or link cache |
|
566 |
bool m_isLinkCache; |
|
567 |
// / Check if save the sub route entries or not |
|
568 |
bool m_subRoute; |
|
8752 | 569 |
/** |
8751 | 570 |
* The link cache to update all the link status, bi-link is two link for link is a struct |
571 |
* when the weight is calculated we normalized them: 100*weight/max of Weight |
|
572 |
*/ |
|
573 |
#define MAXWEIGHT 0xFFFF; |
|
8752 | 574 |
/** |
8751 | 575 |
* Current network graph state for this node, double is weight, which is calculated by the node information |
576 |
* and link information, any time some changes of link cache and node cache |
|
577 |
* change the weight and then recompute the best choice for each node |
|
578 |
*/ |
|
579 |
std::map<Ipv4Address, std::map<Ipv4Address, uint32_t> > m_netGraph; |
|
580 |
// for link route cache |
|
581 |
std::map<Ipv4Address, RouteCacheEntry::IP_VECTOR> m_bestRoutesTable_link; |
|
582 |
std::map<Link, LinkStab> m_linkCache; |
|
583 |
std::map<Ipv4Address, NodeStab> m_nodeCache; |
|
8752 | 584 |
// used by LookupRoute when LinkCache |
8751 | 585 |
bool LookupRoute_Link (Ipv4Address id, RouteCacheEntry & rt); |
8752 | 586 |
|
587 |
bool IncStability (Ipv4Address node); |
|
588 |
||
589 |
bool DecStability (Ipv4Address node); |
|
590 |
||
8751 | 591 |
public: |
592 |
/** |
|
593 |
* \brief dijsktra algorithm to get the best route from m_netGraph and update the m_bestRoutesTable_link |
|
594 |
* \when current graph information has changed |
|
595 |
*/ |
|
596 |
void SetCacheType (std::string type); |
|
597 |
bool IsLinkCache (); |
|
598 |
bool AddRoute_Link (RouteCacheEntry::IP_VECTOR nodelist, Ipv4Address node); |
|
8752 | 599 |
/** |
600 |
* \brief USE MAXWEIGHT TO REPRESENT MAX; USE BROADCAST ADDRESS TO REPRESENT NULL PRECEEDING ADDRESS |
|
8751 | 601 |
*/ |
602 |
void RebuildBestRouteTable (Ipv4Address source); |
|
603 |
void PurgeLinkNode (); |
|
8752 | 604 |
/** |
8751 | 605 |
* When a link from the Route Cache is used in routing a packet originated or salvaged |
606 |
* by that node, the stability metric for each of the two endpoint nodes of that link is incremented by the |
|
607 |
* amount of time since that link was last used. When a link is used in a route chosen for a packet originated or |
|
608 |
* salvaged by this node, the link's lifetime is set to be at least UseExtends into the future |
|
609 |
*/ |
|
610 |
void UseExtends (RouteCacheEntry::IP_VECTOR rt); |
|
611 |
/** |
|
612 |
* \brief Update the Net Graph for the link and node cache has changed |
|
613 |
*/ |
|
614 |
void UpdateNetGraph (); |
|
615 |
//--------------------------------------------------------------------------------------- |
|
8752 | 616 |
/** |
8751 | 617 |
* The following code handles link-layer acks |
618 |
*/ |
|
619 |
// / link failure callback |
|
620 |
Callback<void, Ipv4Address, uint8_t > m_handleLinkFailure; |
|
621 |
// / TX error callback |
|
622 |
Callback<void, WifiMacHeader const &> m_txErrorCallback; |
|
623 |
// / Timer for neighbor's list. Schedule Purge(). |
|
624 |
Timer m_ntimer; |
|
625 |
// / vector of entries |
|
626 |
std::vector<Neighbor> m_nb; |
|
627 |
// / list of ARP cached to be used for layer 2 notifications processing |
|
628 |
std::vector<Ptr<ArpCache> > m_arp; |
|
629 |
// This timeout deals with the passive ack |
|
630 |
Time m_delay; |
|
631 |
// / Find MAC address by IP using list of ARP caches |
|
632 |
Mac48Address LookupMacAddress (Ipv4Address); |
|
633 |
// / Process layer 2 TX error notification |
|
634 |
void ProcessTxError (WifiMacHeader const &); |
|
635 |
}; |
|
636 |
} // namespace dsr |
|
637 |
} // namespace ns3 |
|
638 |
#endif /* DSR_RCACHE_H */ |