LEFT | RIGHT |
(no file at all) | |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 Yufei Cheng | 3 * Copyright (c) 2011 Yufei Cheng |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 */ | 92 */ |
93 RouteCacheEntry (IP_VECTOR const & ip = IP_VECTOR (), Ipv4Address dst = Ipv4A
ddress (), Time exp = Simulator::Now ()); | 93 RouteCacheEntry (IP_VECTOR const & ip = IP_VECTOR (), Ipv4Address dst = Ipv4A
ddress (), Time exp = Simulator::Now ()); |
94 /** | 94 /** |
95 * \brief Destructor. | 95 * \brief Destructor. |
96 */ | 96 */ |
97 virtual ~RouteCacheEntry (); | 97 virtual ~RouteCacheEntry (); |
98 // / Mark entry as "down" (i.e. disable it) | 98 // / Mark entry as "down" (i.e. disable it) |
99 void Invalidate (Time badLinkLifetime); | 99 void Invalidate (Time badLinkLifetime); |
100 // /\name Fields | 100 // /\name Fields |
101 // \{ | 101 // \{ |
102 void SetRreqCnt (uint8_t n) | |
103 { | |
104 m_reqCount = n; | |
105 } | |
106 uint8_t GetRreqCnt () const | |
107 { | |
108 return m_reqCount; | |
109 } | |
110 void IncrementRreqCnt () | |
111 { | |
112 m_reqCount++; | |
113 } | |
114 void SetUnidirectional (bool u) | 102 void SetUnidirectional (bool u) |
115 { | 103 { |
116 m_blackListState = u; | 104 m_blackListState = u; |
117 } | 105 } |
118 bool IsUnidirectional () const | 106 bool IsUnidirectional () const |
119 { | 107 { |
120 return m_blackListState; | 108 return m_blackListState; |
121 } | 109 } |
122 void SetBlacklistTimeout (Time t) | 110 void SetBlacklistTimeout (Time t) |
123 { | 111 { |
(...skipping 26 matching lines...) Expand all Loading... |
150 Time GetExpireTime () const | 138 Time GetExpireTime () const |
151 { | 139 { |
152 return m_expire - Simulator::Now (); | 140 return m_expire - Simulator::Now (); |
153 } | 141 } |
154 // \} | 142 // \} |
155 /** | 143 /** |
156 * \brief Print necessary fields | 144 * \brief Print necessary fields |
157 */ | 145 */ |
158 void Print (std::ostream & os) const; | 146 void Print (std::ostream & os) const; |
159 /** | 147 /** |
160 * \brief Compare destination address | 148 * \brief Compare the route cache entry |
161 * \return true if equal | 149 * \return true if equal |
162 */ | 150 */ |
163 bool operator== (RouteCacheEntry const & o) const | 151 bool operator== (RouteCacheEntry const & o) const |
164 { | 152 { |
165 if (m_path.size () != o.m_path.size ()) | 153 if (m_path.size () != o.m_path.size ()) |
166 { | 154 { |
167 NS_ASSERT (false); | 155 NS_ASSERT (false); |
168 return false; | 156 return false; |
169 } | 157 } |
170 IP_VECTOR::const_iterator j = o.m_path.begin (); | 158 IP_VECTOR::const_iterator j = o.m_path.begin (); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 */ | 215 */ |
228 static TypeId GetTypeId (); | 216 static TypeId GetTypeId (); |
229 /** | 217 /** |
230 * \brief Constructor. | 218 * \brief Constructor. |
231 */ | 219 */ |
232 RouteCache (); | 220 RouteCache (); |
233 /** | 221 /** |
234 * \brief Destructor. | 222 * \brief Destructor. |
235 */ | 223 */ |
236 virtual ~RouteCache (); | 224 virtual ~RouteCache (); |
237 | 225 // / Remove the aged route cache entries when the route cache is full |
| 226 void RemoveLastEntry (std::list<RouteCacheEntry> & rtVector); |
238 // / Define the vector of route entries. | 227 // / Define the vector of route entries. |
239 typedef std::vector<RouteCacheEntry::IP_VECTOR> routeVector; | 228 typedef std::list<RouteCacheEntry::IP_VECTOR> routeVector; |
240 // / Get the destination address of the route. | 229 // / Get the destination address of the route. |
241 Ipv4Address GetDestination (void) const; | 230 Ipv4Address GetDestination (void) const; |
242 // / Remove all packets with destination IP address dst | 231 // / Remove all packets with destination IP address dst |
243 void DropPathWithDst (Ipv4Address dst); | 232 void DropPathWithDst (Ipv4Address dst); |
244 // To know if the two entries are the same | 233 // / To know if the two entries are the same |
245 bool IsEqual (RouteCacheEntry ca); | 234 bool IsEqual (RouteCacheEntry ca); |
246 // /\name Fields | 235 // /\name Fields |
247 // \{ | 236 // \{ |
248 uint32_t GetMaxCacheLen () const | 237 uint32_t GetMaxCacheLen () const |
249 { | 238 { |
250 return m_maxCacheLen; | 239 return m_maxCacheLen; |
251 } | 240 } |
252 void SetMaxCacheLen (uint32_t len) | 241 void SetMaxCacheLen (uint32_t len) |
253 { | 242 { |
254 m_maxCacheLen = len; | 243 m_maxCacheLen = len; |
255 } | 244 } |
256 Time GetCacheTimeout () const | 245 Time GetCacheTimeout () const |
257 { | 246 { |
258 return RouteCacheTimeout; | 247 return RouteCacheTimeout; |
259 } | 248 } |
260 void SetCacheTimeout (Time t) | 249 void SetCacheTimeout (Time t) |
261 { | 250 { |
262 RouteCacheTimeout = t; | 251 RouteCacheTimeout = t; |
263 } | 252 } |
| 253 uint32_t GetMaxEntriesEachDst () const |
| 254 { |
| 255 return m_maxEntriesEachDst; |
| 256 } |
| 257 void SetMaxEntriesEachDst (uint32_t entries) |
| 258 { |
| 259 m_maxEntriesEachDst = entries; |
| 260 } |
264 // \} | 261 // \} |
265 | 262 |
266 // Route Cache | 263 // Route Cache |
267 Time GetBadLinkLifetime () const | 264 Time GetBadLinkLifetime () const |
268 { | 265 { |
269 return m_badLinkLifetime; | 266 return m_badLinkLifetime; |
270 } | 267 } |
271 void SetBadLinkLifetime (Time t) | 268 void SetBadLinkLifetime (Time t) |
272 { | 269 { |
273 m_badLinkLifetime = t; | 270 m_badLinkLifetime = t; |
274 } | 271 } |
275 // \} | 272 // \} |
276 /** | 273 /** |
| 274 * Update route cache entry if it has been recently used and successfully deli
vered the data packet |
| 275 * \param dst destination address of the route |
| 276 * \param vec the route vector |
| 277 * \return true in success |
| 278 */ |
| 279 bool UpdateRouteEntry (Ipv4Address dst, std::vector<Ipv4Address>& vec); |
| 280 /** |
277 * Add route cache entry if it doesn't yet exist in route cache | 281 * Add route cache entry if it doesn't yet exist in route cache |
278 * \param r route cache entry | 282 * \param rt route cache entry |
279 * \return true in success | 283 * \return true in success |
280 */ | 284 */ |
281 bool AddRoute (RouteCacheEntry & rt); | 285 bool AddRoute (RouteCacheEntry & rt); |
282 /** | |
283 * Delete routing table entry with destination address dst, if it exists. | |
284 * \param dst destination address | |
285 * \return true on success | |
286 */ | |
287 bool DeleteRoute (Ipv4Address dst); | |
288 /** | 286 /** |
289 * Lookup route cache entry with destination address dst | 287 * Lookup route cache entry with destination address dst |
290 * \param dst destination address | 288 * \param dst destination address |
291 * \param rt entry with destination address dst, if exists | 289 * \param rt entry with destination address dst, if exists |
292 * \return true on success | 290 * \return true on success |
293 */ | 291 */ |
294 bool LookupRoute (Ipv4Address id, RouteCacheEntry & rt); | 292 bool LookupRoute (Ipv4Address id, RouteCacheEntry & rt); |
295 /* | 293 /** |
296 * Delete the first route entry from the route cache | 294 * Print the route vector elements |
297 */ | 295 * \param vec the route vector |
298 bool DeleteRouteEntry (Ipv4Address id); | 296 */ |
299 // / Update the route | 297 void PrintVector (std::vector<Ipv4Address>& vec); |
300 bool UpdateRoute (Ipv4Address id); | 298 /** |
301 // / Find the same route in the route cache | 299 * Print all the route vector elements from the route list |
302 bool FindSameRoute (RouteCacheEntry & rt, std::vector<RouteCacheEntry> & rtVec
tor); | 300 * \param route the route list |
303 // / Remove the duplicate IP address from the route entry | 301 */ |
304 void RemoveDuplicates (std::vector<Ipv4Address>& vec); | 302 void PrintRouteVector (std::list<RouteCacheEntry> route); |
| 303 /** |
| 304 * Find the same route in the route cache |
| 305 * \param rt entry with destination address dst, if exists |
| 306 * \param rtVector the route vector |
| 307 */ |
| 308 bool FindSameRoute (RouteCacheEntry & rt, std::list<RouteCacheEntry> & rtVecto
r); |
| 309 /** |
| 310 * Delete the route with certain destination address |
| 311 * \param dst the destination address of the routes that should be deleted |
| 312 */ |
| 313 bool DeleteRoute (Ipv4Address dst); |
305 /* | 314 /* |
306 * Delete all the routes which includes the link from next hop address that ha
s just been notified | 315 * Delete all the routes which includes the link from next hop address that ha
s just been notified |
307 * as unreachable | 316 * as unreachable |
308 */ | 317 */ |
309 void DeleteAllRoutesIncludeLink (Ipv4Address errorSrc, Ipv4Address unreachNode
); | 318 void DeleteAllRoutesIncludeLink (Ipv4Address errorSrc, Ipv4Address unreachNode
); |
310 // / Delete all entries from routing table | 319 // / Delete all entries from routing table |
311 void Clear () | 320 void Clear () |
312 { | 321 { |
313 m_routeEntryVector.erase (m_routeEntryVector.begin (), m_routeEntryVector.en
d ()); | 322 m_routeEntryVector.erase (m_routeEntryVector.begin (), m_routeEntryVector.en
d ()); |
314 } | 323 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 { | 395 { |
387 return m_handleLinkFailure; | 396 return m_handleLinkFailure; |
388 } | 397 } |
389 // \} | 398 // \} |
390 | 399 |
391 private: | 400 private: |
392 RouteCache & operator= (RouteCache const &); | 401 RouteCache & operator= (RouteCache const &); |
393 RouteCacheEntry::IP_VECTOR m_vector; // /< The route vector to save the ip add
resses for intermediate nodes. | 402 RouteCacheEntry::IP_VECTOR m_vector; // /< The route vector to save the ip add
resses for intermediate nodes. |
394 uint32_t m_maxCacheLen; // /< The maximum number of packets that
we allow a routing protocol to buffer. | 403 uint32_t m_maxCacheLen; // /< The maximum number of packets that
we allow a routing protocol to buffer. |
395 Time RouteCacheTimeout; // /< The maximum period of time that dsr
is allowed to for an unused route. | 404 Time RouteCacheTimeout; // /< The maximum period of time that dsr
is allowed to for an unused route. |
396 Time ActiveRouteTimeout; // /< The active route timeout for a newl
y found route. | |
397 Time m_badLinkLifetime; // /< The time for which the neighboring
node is put into the blacklist. | 405 Time m_badLinkLifetime; // /< The time for which the neighboring
node is put into the blacklist. |
398 Time m_routeRequestTimout; // /< The time when I can send another re
quest | |
399 RouteCacheEntry m_route; // /< The route cache entry. | |
400 /* | 406 /* |
401 * Define the route cache data structure | 407 * Define the route cache data structure |
402 */ | 408 */ |
403 typedef std::vector<RouteCacheEntry> routeEntryVector; | 409 typedef std::list<RouteCacheEntry> routeEntryVector; |
404 // / Map the ipv4Address to route entry vector | 410 // / Map the ipv4Address to route entry vector |
405 std::map<Ipv4Address, routeEntryVector> m_sortedRoutes; | 411 std::map<Ipv4Address, routeEntryVector> m_sortedRoutes; |
406 // Define the route vector | 412 // Define the route vector |
407 routeEntryVector m_routeEntryVector; | 413 routeEntryVector m_routeEntryVector; |
408 // / number of routes stored for a certain dst | 414 // / number of entries for each destination |
409 uint8_t m_totalRouteNo; | 415 uint32_t m_maxEntriesEachDst; |
410 // / The id cache to ensure all the ids are unique | 416 // / The id cache to ensure all the ids are unique |
411 std::map<Ipv4Address, uint16_t> m_ackIdCache; | 417 std::map<Ipv4Address, uint16_t> m_ackIdCache; |
412 | 418 |
413 //----------------------------------------------------------------------------
----------- | 419 //----------------------------------------------------------------------------
----------- |
414 /* | 420 /* |
415 * The following code handles link-layer acks | 421 * The following code handles link-layer acks |
416 */ | 422 */ |
417 // / link failure callback | 423 // / link failure callback |
418 Callback<void, Ipv4Address, uint8_t > m_handleLinkFailure; | 424 Callback<void, Ipv4Address, uint8_t > m_handleLinkFailure; |
419 // / TX error callback | 425 // / TX error callback |
420 Callback<void, WifiMacHeader const &> m_txErrorCallback; | 426 Callback<void, WifiMacHeader const &> m_txErrorCallback; |
421 // / Timer for neighbor's list. Schedule Purge(). | 427 // / Timer for neighbor's list. Schedule Purge(). |
422 Timer m_ntimer; | 428 Timer m_ntimer; |
423 // / vector of entries | 429 // / vector of entries |
424 std::vector<Neighbor> m_nb; | 430 std::vector<Neighbor> m_nb; |
425 // / list of ARP cached to be used for layer 2 notifications processing | 431 // / list of ARP cached to be used for layer 2 notifications processing |
426 std::vector<Ptr<ArpCache> > m_arp; | 432 std::vector<Ptr<ArpCache> > m_arp; |
427 // This timeout deals with the passive ack | 433 // This timeout deals with the passive ack |
428 Time m_delay; | 434 Time m_delay; |
429 // / Find MAC address by IP using list of ARP caches | 435 // / Find MAC address by IP using list of ARP caches |
430 Mac48Address LookupMacAddress (Ipv4Address); | 436 Mac48Address LookupMacAddress (Ipv4Address); |
431 // / Process layer 2 TX error notification | 437 // / Process layer 2 TX error notification |
432 void ProcessTxError (WifiMacHeader const &); | 438 void ProcessTxError (WifiMacHeader const &); |
433 }; | 439 }; |
434 } // namespace dsr | 440 } // namespace dsr |
435 } // namespace ns3 | 441 } // namespace ns3 |
436 #endif /* DSR_RCACHE_H */ | 442 #endif /* DSR_RCACHE_H */ |
LEFT | RIGHT |