LEFT | RIGHT |
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 MakeTimeAccessor (&DsrRouting::m_maxMaintainTime), | 132 MakeTimeAccessor (&DsrRouting::m_maxMaintainTime), |
133 MakeTimeChecker ()) | 133 MakeTimeChecker ()) |
134 .AddAttribute ("MaxCacheLen","Maximum number of route entries that can be st
ored in route cache.", | 134 .AddAttribute ("MaxCacheLen","Maximum number of route entries that can be st
ored in route cache.", |
135 UintegerValue (64), | 135 UintegerValue (64), |
136 MakeUintegerAccessor (&DsrRouting::m_maxCacheLen), | 136 MakeUintegerAccessor (&DsrRouting::m_maxCacheLen), |
137 MakeUintegerChecker<uint32_t> ()) | 137 MakeUintegerChecker<uint32_t> ()) |
138 .AddAttribute ("RouteCacheTimeout","Maximum time the route cache can be queu
ed in route cache.", | 138 .AddAttribute ("RouteCacheTimeout","Maximum time the route cache can be queu
ed in route cache.", |
139 TimeValue (Seconds (300)), | 139 TimeValue (Seconds (300)), |
140 MakeTimeAccessor (&DsrRouting::m_maxCacheTime), | 140 MakeTimeAccessor (&DsrRouting::m_maxCacheTime), |
141 MakeTimeChecker ()) | 141 MakeTimeChecker ()) |
| 142 .AddAttribute ("MaxEntriesEachDst","Maximum number of route entries for a si
ngle destination to respond.", |
| 143 UintegerValue (100), |
| 144 MakeUintegerAccessor (&DsrRouting::m_maxEntriesEachDst), |
| 145 MakeUintegerChecker<uint32_t> ()) |
142 .AddAttribute ("SendBuffInterval","How often to check send buffer for packet
with route.", | 146 .AddAttribute ("SendBuffInterval","How often to check send buffer for packet
with route.", |
143 TimeValue (Seconds (1)), | 147 TimeValue (Seconds (10)), |
144 MakeTimeAccessor (&DsrRouting::m_sendBuffInterval), | 148 MakeTimeAccessor (&DsrRouting::m_sendBuffInterval), |
145 MakeTimeChecker ()) | 149 MakeTimeChecker ()) |
146 .AddAttribute ("NodeTraversalTime","The time it takes to traversal the two n
eighboring nodes.", | 150 .AddAttribute ("NodeTraversalTime","The time it takes to traversal the two n
eighboring nodes.", |
147 TimeValue (MilliSeconds (40)), | 151 TimeValue (MilliSeconds (40)), |
148 MakeTimeAccessor (&DsrRouting::m_nodeTraversalTime), | 152 MakeTimeAccessor (&DsrRouting::m_nodeTraversalTime), |
149 MakeTimeChecker ()) | 153 MakeTimeChecker ()) |
150 .AddAttribute ("RreqRetries","Maximum number of retransmissions for request
discovery of a route.", | 154 .AddAttribute ("RreqRetries","Maximum number of retransmissions for request
discovery of a route.", |
151 UintegerValue (16), | 155 UintegerValue (16), |
152 MakeUintegerAccessor (&DsrRouting::m_rreqRetries), | 156 MakeUintegerAccessor (&DsrRouting::m_rreqRetries), |
153 MakeUintegerChecker<uint32_t> ()) | 157 MakeUintegerChecker<uint32_t> ()) |
154 .AddAttribute ("MaintenanceRetries","Maximum number of retransmissions for d
ata packets from maintenance buffer.", | 158 .AddAttribute ("MaintenanceRetries","Maximum number of retransmissions for d
ata packets from maintenance buffer.", |
155 UintegerValue (2), | 159 UintegerValue (2), |
156 MakeUintegerAccessor (&DsrRouting::m_maxMaintRexmt), | 160 MakeUintegerAccessor (&DsrRouting::m_maxMaintRexmt), |
157 MakeUintegerChecker<uint32_t> ()) | 161 MakeUintegerChecker<uint32_t> ()) |
158 .AddAttribute ("RequestTableSize","Maximum number of request entries in the
request table.", | 162 .AddAttribute ("RequestTableSize","Maximum number of request entries in the
request table.", |
159 UintegerValue (64), | 163 UintegerValue (64), |
160 MakeUintegerAccessor (&DsrRouting::m_requestTableSize), | 164 MakeUintegerAccessor (&DsrRouting::m_requestTableSize), |
161 MakeUintegerChecker<uint32_t> ()) | 165 MakeUintegerChecker<uint32_t> ()) |
162 .AddAttribute ("RequestIdSize","Maximum number of request source Ids in the
request table.", | 166 .AddAttribute ("RequestIdSize","Maximum number of request source Ids in the
request table.", |
163 UintegerValue (16), | 167 UintegerValue (16), |
164 MakeUintegerAccessor (&DsrRouting::m_requestTableIds), | 168 MakeUintegerAccessor (&DsrRouting::m_requestTableIds), |
| 169 MakeUintegerChecker<uint16_t> ()) |
| 170 .AddAttribute ("UniqueRequestIdSize","Maximum number of request Ids in the r
equest table for a single destination.", |
| 171 UintegerValue (256), |
| 172 MakeUintegerAccessor (&DsrRouting::m_maxRreqId), |
165 MakeUintegerChecker<uint16_t> ()) | 173 MakeUintegerChecker<uint16_t> ()) |
166 .AddAttribute ("NonPropRequestTimeout","The timeout value for non-propagatio
n request.", | 174 .AddAttribute ("NonPropRequestTimeout","The timeout value for non-propagatio
n request.", |
167 TimeValue (MilliSeconds (30)), | 175 TimeValue (MilliSeconds (30)), |
168 MakeTimeAccessor (&DsrRouting::m_nonpropRequestTimeout), | 176 MakeTimeAccessor (&DsrRouting::m_nonpropRequestTimeout), |
169 MakeTimeChecker ()) | 177 MakeTimeChecker ()) |
170 .AddAttribute ("DiscoveryHopLimit","The max discovery hop limit for route re
quests.", | 178 .AddAttribute ("DiscoveryHopLimit","The max discovery hop limit for route re
quests.", |
171 UintegerValue (255), | 179 UintegerValue (255), |
172 MakeUintegerAccessor (&DsrRouting::m_discoveryHopLimit), | 180 MakeUintegerAccessor (&DsrRouting::m_discoveryHopLimit), |
173 MakeUintegerChecker<uint8_t> ()) | 181 MakeUintegerChecker<uint8_t> ()) |
174 .AddAttribute ("MaxSalvageCount","The max salvage count for a single data pa
cket.", | 182 .AddAttribute ("MaxSalvageCount","The max salvage count for a single data pa
cket.", |
175 UintegerValue (15), | 183 UintegerValue (15), |
176 MakeUintegerAccessor (&DsrRouting::m_maxSalvageCount), | 184 MakeUintegerAccessor (&DsrRouting::m_maxSalvageCount), |
177 MakeUintegerChecker<uint8_t> ()) | 185 MakeUintegerChecker<uint8_t> ()) |
178 .AddAttribute ("BlacklistTimeout","The time for a neighbor to stay in blackl
ist.", | 186 .AddAttribute ("BlacklistTimeout","The time for a neighbor to stay in blackl
ist.", |
179 TimeValue (Seconds (3)), | 187 TimeValue (Seconds (3)), |
180 MakeTimeAccessor (&DsrRouting::m_blacklistTimeout), | 188 MakeTimeAccessor (&DsrRouting::m_blacklistTimeout), |
181 MakeTimeChecker ()) | 189 MakeTimeChecker ()) |
182 .AddAttribute ("GratReplyHoldoff","The time for gratuitous reply entry to ex
pire.", | 190 .AddAttribute ("GratReplyHoldoff","The time for gratuitous reply entry to ex
pire.", |
183 TimeValue (Seconds (1)), | 191 TimeValue (Seconds (1)), |
184 MakeTimeAccessor (&DsrRouting::m_gratReplyHoldoff), | 192 MakeTimeAccessor (&DsrRouting::m_gratReplyHoldoff), |
185 MakeTimeChecker ()) | 193 MakeTimeChecker ()) |
186 .AddAttribute ("BroadcastJitter","The jitter time to avoid collision for bro
adcast packets.", | 194 .AddAttribute ("BroadcastJitter","The jitter time to avoid collision for bro
adcast packets.", |
187 UintegerValue (10), | 195 UintegerValue (10), |
188 MakeUintegerAccessor (&DsrRouting::m_broadcastJitter), | 196 MakeUintegerAccessor (&DsrRouting::m_broadcastJitter), |
189 MakeUintegerChecker<uint16_t> ()) | 197 MakeUintegerChecker<uint16_t> ()) |
190 .AddAttribute ("PassiveAckTimeout","The time a packet in maintenance buffer
wait for passive acknowledgment.", | 198 .AddAttribute ("PassiveAckTimeout","The time a packet in maintenance buffer
wait for passive acknowledgment.", |
191 TimeValue (MilliSeconds (100)), | 199 TimeValue (MilliSeconds (100)), |
192 MakeTimeAccessor (&DsrRouting::m_passiveAckTimeout), | 200 MakeTimeAccessor (&DsrRouting::m_passiveAckTimeout), |
193 MakeTimeChecker ()) | 201 MakeTimeChecker ()) |
| 202 .AddAttribute ("TryPassiveAcks","The number of passive acknowledgment to use
.", |
| 203 UintegerValue (1), |
| 204 MakeUintegerAccessor (&DsrRouting::m_tryPassiveAcks), |
| 205 MakeUintegerChecker<uint32_t> ()) |
194 .AddAttribute ("RequestPeriod","The base time interval between route request
s.", | 206 .AddAttribute ("RequestPeriod","The base time interval between route request
s.", |
195 TimeValue (MilliSeconds (500)), | 207 TimeValue (MilliSeconds (500)), |
196 MakeTimeAccessor (&DsrRouting::m_requestPeriod), | 208 MakeTimeAccessor (&DsrRouting::m_requestPeriod), |
197 MakeTimeChecker ()) | 209 MakeTimeChecker ()) |
198 .AddAttribute ("MaxRequestPeriod","The max time interval between route reque
sts.", | 210 .AddAttribute ("MaxRequestPeriod","The max time interval between route reque
sts.", |
199 TimeValue (Seconds (10)), | 211 TimeValue (Seconds (10)), |
200 MakeTimeAccessor (&DsrRouting::m_maxRequestPeriod), | 212 MakeTimeAccessor (&DsrRouting::m_maxRequestPeriod), |
201 MakeTimeChecker ()) | 213 MakeTimeChecker ()) |
202 .AddAttribute ("GraReplyTableSize","The gratuitous reply table size.", | 214 .AddAttribute ("GraReplyTableSize","The gratuitous reply table size.", |
203 UintegerValue (64), | 215 UintegerValue (64), |
(...skipping 18 matching lines...) Expand all Loading... |
222 m_nonpropRequestTimeout (MilliSeconds (30)), | 234 m_nonpropRequestTimeout (MilliSeconds (30)), |
223 m_rreqRetries (16), | 235 m_rreqRetries (16), |
224 m_maxMaintRexmt (2), | 236 m_maxMaintRexmt (2), |
225 m_nodeTraversalTime (MilliSeconds (40)), | 237 m_nodeTraversalTime (MilliSeconds (40)), |
226 m_maxSendBuffLen (64), | 238 m_maxSendBuffLen (64), |
227 m_sendBufferTimeout (Seconds (30)), | 239 m_sendBufferTimeout (Seconds (30)), |
228 m_maxMaintainLen (50), | 240 m_maxMaintainLen (50), |
229 m_maxMaintainTime (Seconds (30)), | 241 m_maxMaintainTime (Seconds (30)), |
230 m_maxCacheLen (64), | 242 m_maxCacheLen (64), |
231 m_maxCacheTime (Seconds (300)), | 243 m_maxCacheTime (Seconds (300)), |
| 244 m_maxEntriesEachDst (100), |
232 m_requestTableSize (64), | 245 m_requestTableSize (64), |
233 m_requestTableIds (16), | 246 m_requestTableIds (16), |
| 247 m_maxRreqId (256), |
234 m_blacklistTimeout (Seconds (3)), | 248 m_blacklistTimeout (Seconds (3)), |
235 m_broadcastJitter (10), | 249 m_broadcastJitter (10), |
236 m_passiveAckTimeout (MilliSeconds (100)), | 250 m_passiveAckTimeout (MilliSeconds (100)), |
| 251 m_tryPassiveAcks (1), |
237 m_sendBuffTimer (Timer::CANCEL_ON_DESTROY), | 252 m_sendBuffTimer (Timer::CANCEL_ON_DESTROY), |
238 m_sendBuffInterval (Seconds (1)), | 253 m_sendBuffInterval (Seconds (10)), |
239 m_gratReplyHoldoff (Seconds (1)), | 254 m_gratReplyHoldoff (Seconds (1)), |
240 m_maxRequestPeriod (Seconds (10)), | 255 m_maxRequestPeriod (Seconds (10)), |
241 m_graReplyTableSize (64), | 256 m_graReplyTableSize (64), |
242 m_dataEndTime (Seconds (200)) | 257 m_dataEndTime (Seconds (200)) |
243 { | 258 { |
244 NS_LOG_FUNCTION_NOARGS (); | 259 NS_LOG_FUNCTION_NOARGS (); |
245 /* | 260 /* |
246 * The following Ptr statements created objects for all the options header for
DSR, and each of them have | 261 * The following Ptr statements created objects for all the options header for
DSR, and each of them have |
247 * distinct option number assigned, when DSR Routing received a packet from hi
gher layer, it will find | 262 * distinct option number assigned, when DSR Routing received a packet from hi
gher layer, it will find |
248 * the following options based on the option number, and pass the packet to th
e appropriate option to | 263 * the following options based on the option number, and pass the packet to th
e appropriate option to |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 void DsrRouting::Start () | 322 void DsrRouting::Start () |
308 { | 323 { |
309 NS_LOG_FUNCTION (this << "Start DSR Routing protocol"); | 324 NS_LOG_FUNCTION (this << "Start DSR Routing protocol"); |
310 if (m_mainAddress == Ipv4Address ()) | 325 if (m_mainAddress == Ipv4Address ()) |
311 { | 326 { |
312 Ipv4Address loopback ("127.0.0.1"); | 327 Ipv4Address loopback ("127.0.0.1"); |
313 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) | 328 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) |
314 { | 329 { |
315 // Use primary address, if multiple | 330 // Use primary address, if multiple |
316 Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal (); | 331 Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal (); |
317 Broadcast = m_ipv4->GetAddress (i, 0).GetBroadcast (); | 332 m_broadcast = m_ipv4->GetAddress (i, 0).GetBroadcast(); |
318 NS_LOG_DEBUG ("The addr " << addr); | 333 NS_LOG_DEBUG ("The addr " << addr); |
319 if (addr != loopback) | 334 if (addr != loopback) |
320 { | 335 { |
321 m_mainAddress = addr; | 336 m_mainAddress = addr; |
322 NS_LOG_DEBUG ("The node Address " << m_mainAddress); | 337 NS_LOG_DEBUG ("The node Address " << m_mainAddress); |
323 | 338 |
324 m_ipv4->GetNetDevice (1)->SetPromiscReceiveCallback (MakeCallback
(&DsrRouting::PromiscReceive, this)); | 339 m_ipv4->GetNetDevice (1)->SetPromiscReceiveCallback (MakeCallback
(&DsrRouting::PromiscReceive, this)); |
325 | 340 |
326 // Allow neighbor manager use this interface for layer 2 feedback
if possible | 341 // Allow neighbor manager use this interface for layer 2 feedback
if possible |
327 Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceFor
Address (addr)); | 342 Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceFor
Address (addr)); |
(...skipping 11 matching lines...) Expand all Loading... |
339 // trace back to link mac drop event to process tx error call back | 354 // trace back to link mac drop event to process tx error call back |
340 mac->TraceConnectWithoutContext ("TxErrHeader", m_routeCache->GetT
xErrorCallback ()); | 355 mac->TraceConnectWithoutContext ("TxErrHeader", m_routeCache->GetT
xErrorCallback ()); |
341 m_routeCache->AddArpCache (m_ipv4->GetInterface (i)->GetArpCache (
)); | 356 m_routeCache->AddArpCache (m_ipv4->GetInterface (i)->GetArpCache (
)); |
342 break; | 357 break; |
343 } | 358 } |
344 } | 359 } |
345 } | 360 } |
346 | 361 |
347 // Set the initial hop limit | 362 // Set the initial hop limit |
348 m_rreqTable->SetInitHopLimit (m_discoveryHopLimit); | 363 m_rreqTable->SetInitHopLimit (m_discoveryHopLimit); |
| 364 // Configure the request table parameters |
| 365 m_rreqTable->SetRreqTableSize (m_requestTableSize); |
| 366 m_rreqTable->SetRreqIdSize (m_requestTableIds); |
| 367 m_rreqTable->SetUniqueRreqIdSize (m_maxRreqId); |
349 // Set the send buffer parameters | 368 // Set the send buffer parameters |
350 m_sendBuffer.SetMaxQueueLen (m_maxSendBuffLen); | 369 m_sendBuffer.SetMaxQueueLen (m_maxSendBuffLen); |
351 m_sendBuffer.SetSendBufferTimeout (m_sendBufferTimeout); | 370 m_sendBuffer.SetSendBufferTimeout (m_sendBufferTimeout); |
352 // Set the maintenance buffer parameters | 371 // Set the maintenance buffer parameters |
353 m_maintainBuffer.SetMaxQueueLen (m_maxMaintainLen); | 372 m_maintainBuffer.SetMaxQueueLen (m_maxMaintainLen); |
354 m_maintainBuffer.SetMaintainBufferTimeout (m_maxMaintainTime); | 373 m_maintainBuffer.SetMaintainBufferTimeout (m_maxMaintainTime); |
355 // Configure the request table parameters | |
356 m_rreqTable->SetRreqTableSize (m_requestTableSize); | |
357 m_rreqTable->SetRreqIdSize (m_requestTableIds); | |
358 // Set the gratuitous reply table size | 374 // Set the gratuitous reply table size |
359 m_graReply.SetGraTableSize (m_graReplyTableSize); | 375 m_graReply.SetGraTableSize (m_graReplyTableSize); |
360 // Configure the route cache parameters | 376 // Configure the route cache parameters |
361 m_routeCache->SetMaxCacheLen (m_maxCacheLen); | 377 m_routeCache->SetMaxCacheLen (m_maxCacheLen); |
362 m_routeCache->SetCacheTimeout (m_maxCacheTime); | 378 m_routeCache->SetCacheTimeout (m_maxCacheTime); |
| 379 m_routeCache->SetMaxEntriesEachDst (m_maxEntriesEachDst); |
363 m_routeCache->ScheduleTimer (); | 380 m_routeCache->ScheduleTimer (); |
364 // The call back to handle link error and send error message to appropriate no
des | 381 // The call back to handle link error and send error message to appropriate no
des |
365 m_routeCache->SetCallback (MakeCallback (&DsrRouting::SendRerrWhenBreaksLinkTo
NextHop, this)); | 382 m_routeCache->SetCallback (MakeCallback (&DsrRouting::SendRerrWhenBreaksLinkTo
NextHop, this)); |
366 NS_LOG_DEBUG ("Starting DSR on node " << m_mainAddress); | 383 NS_LOG_DEBUG ("Starting DSR on node " << m_mainAddress); |
367 } | 384 } |
368 | 385 |
369 void | 386 void |
370 DsrRouting::SetNode (Ptr<Node> node) | 387 DsrRouting::SetNode (Ptr<Node> node) |
371 { | 388 { |
372 m_node = node; | 389 m_node = node; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 477 } |
461 for (std::vector<Ipv4Address>::iterator i = vec.begin (); i != vec.end ();
++i) | 478 for (std::vector<Ipv4Address>::iterator i = vec.begin (); i != vec.end ();
++i) |
462 { | 479 { |
463 if (ipv4Address == (*i)) | 480 if (ipv4Address == (*i)) |
464 { | 481 { |
465 nextHop = *(++i); | 482 nextHop = *(++i); |
466 return nextHop; | 483 return nextHop; |
467 } | 484 } |
468 } | 485 } |
469 } | 486 } |
470 NS_LOG_DEBUG ("next hop address not found"); | 487 NS_LOG_DEBUG ("Next hop address not found"); |
471 Ipv4Address none = "0.0.0.0"; | 488 Ipv4Address none = "0.0.0.0"; |
472 return none; | 489 return none; |
473 } | |
474 | |
475 bool | |
476 DsrRouting::FindSamePackets (Ptr<Packet> packet, Ipv4Header const & ipv4Header,
Ipv4Address ourAdd, Ipv4Address nextHop, Ipv4Address source, Ipv4Address destina
tion, | |
477 uint16_t ackId, uint8_t segsLeft, uint16_t routeSiz
e) | |
478 { | |
479 NS_LOG_FUNCTION (this << packet << ipv4Header << ourAdd << nextHop << source <
< destination << ackId << (uint32_t)segsLeft << routeSize); | |
480 Ptr<const Packet> p = packet->Copy (); | |
481 MaintainBuffEntry newEntry (/*Packet=*/ p, /*Ipv4Header=*/ ipv4Header, /*Ipv4A
ddress=*/ ourAdd, /*nextHop=*/ nextHop, | |
482 /*source=*/ source, /*destination=*/ d
estination, /*ackId=*/ ackId, | |
483 /*SegsLeft=*/ segsLeft, /*Salvage=*/
0, /*RouteSize=*/ routeSize, | |
484 /*expire time=*/ m_maxMaintainTime); | |
485 | |
486 NS_LOG_DEBUG ("Before canceling the packet timer " << *p); | |
487 CancelPacketTimer (newEntry); | |
488 return true; | |
489 } | 490 } |
490 | 491 |
491 Ptr<Ipv4Route> | 492 Ptr<Ipv4Route> |
492 DsrRouting::SetRoute (Ipv4Address nextHop, Ipv4Address srcAddress) | 493 DsrRouting::SetRoute (Ipv4Address nextHop, Ipv4Address srcAddress) |
493 { | 494 { |
494 NS_LOG_FUNCTION (this << nextHop << srcAddress); | 495 NS_LOG_FUNCTION (this << nextHop << srcAddress); |
495 m_ipv4Route = Create<Ipv4Route> (); | 496 m_ipv4Route = Create<Ipv4Route> (); |
496 m_ipv4Route->SetDestination (nextHop); | 497 m_ipv4Route->SetDestination (nextHop); |
497 m_ipv4Route->SetGateway (nextHop); | 498 m_ipv4Route->SetGateway (nextHop); |
498 m_ipv4Route->SetSource (srcAddress); | 499 m_ipv4Route->SetSource (srcAddress); |
499 return m_ipv4Route; | 500 return m_ipv4Route; |
500 } | 501 } |
501 | 502 |
| 503 void |
| 504 DsrRouting::CutRoute (Ipv4Address ourAdd, std::vector<Ipv4Address>& nodeList) |
| 505 { |
| 506 NS_LOG_FUNCTION (this << ourAdd); |
| 507 std::vector<Ipv4Address> newRoute = nodeList; |
| 508 nodeList.clear (); |
| 509 |
| 510 std::vector<Ipv4Address>::iterator it = find (newRoute.begin (), newRoute.end
(), ourAdd); |
| 511 |
| 512 for (std::vector<Ipv4Address>::iterator i = it; i != newRoute.end (); ++i) |
| 513 { |
| 514 nodeList.push_back (*i); |
| 515 } |
| 516 } |
| 517 |
502 int | 518 int |
503 DsrRouting::GetProtocolNumber (void) const | 519 DsrRouting::GetProtocolNumber (void) const |
504 { | 520 { |
505 // / This is the protocol number for DSR which is 48 | 521 // / This is the protocol number for DSR which is 48 |
506 return PROT_NUMBER; | 522 return PROT_NUMBER; |
507 } | 523 } |
508 | 524 |
509 void | 525 void |
510 DsrRouting::DoDispose (void) | 526 DsrRouting::DoDispose (void) |
511 { | 527 { |
(...skipping 11 matching lines...) Expand all Loading... |
523 Ptr<Node> node = NodeList::GetNode (i); | 539 Ptr<Node> node = NodeList::GetNode (i); |
524 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); | 540 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
525 if (ipv4->GetAddress (1, 0).GetLocal () == address) | 541 if (ipv4->GetAddress (1, 0).GetLocal () == address) |
526 { | 542 { |
527 return i; | 543 return i; |
528 } | 544 } |
529 } | 545 } |
530 return 255; | 546 return 255; |
531 } | 547 } |
532 | 548 |
| 549 Ipv4Address |
| 550 DsrRouting::GetIPfromID (uint32_t id) |
| 551 { |
| 552 if (id >= 255) |
| 553 { |
| 554 NS_LOG_DEBUG ("Exceed the node range"); |
| 555 return "0.0.0.0"; |
| 556 } |
| 557 else |
| 558 { |
| 559 Ptr<Node> node = NodeList::GetNode (id); |
| 560 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 561 return ipv4->GetAddress (1, 0).GetLocal (); |
| 562 } |
| 563 } |
| 564 |
533 void DsrRouting::SendRerrWhenBreaksLinkToNextHop (Ipv4Address nextHop, uint8_t p
rotocol) | 565 void DsrRouting::SendRerrWhenBreaksLinkToNextHop (Ipv4Address nextHop, uint8_t p
rotocol) |
534 { | 566 { |
535 NS_LOG_FUNCTION (this << nextHop << (uint32_t)protocol); | 567 NS_LOG_FUNCTION (this << nextHop << (uint32_t)protocol); |
536 MaintainBuffEntry entry; | 568 MaintainBuffEntry entry; |
537 // Find the packet in send buffer | 569 // Find the packet in send buffer |
538 if (m_maintainBuffer.FindPacketsWithNextHop (nextHop)) | 570 if (m_maintainBuffer.Find (nextHop)) |
539 { | 571 { |
540 NS_LOG_DEBUG ("Trying to dequeue"); | 572 NS_LOG_DEBUG ("Trying to dequeue"); |
541 m_maintainBuffer.Dequeue (nextHop, entry); | 573 |
542 NS_LOG_DEBUG ("creating new packet"); | 574 if (m_maintainBuffer.Dequeue (nextHop, entry)) |
543 /* | 575 { |
544 * Copy the packet and save a copy to the send buffer. | 576 NS_LOG_DEBUG ("creating new packet"); |
545 * For some reason, when queue the original packet to the buffer, | 577 /* |
546 * when dequeue the packet, it turns to be empty. | 578 * Copy the packet and save a copy to the send buffer. |
547 */ | 579 * For some reason, when queue the original packet to the buffer, |
548 Ptr<Packet> newPacket = entry.GetPacket ()->Copy (); | 580 * when dequeue the packet, it turns to be empty. |
549 Ipv4Address source = entry.GetSrc (); | 581 */ |
550 Ipv4Address destination = entry.GetDst (); | 582 Ptr<Packet> dequeP = ConstCast<Packet> (entry.GetPacket ()); |
551 | 583 Ptr<Packet> newPacket = dequeP->Copy (); |
552 DsrRoutingHeader dsrRoutingHeader; | 584 Ptr<Packet> p = dequeP->Copy (); |
553 Ptr<Packet> p = newPacket->Copy (); | 585 |
554 p->RemoveHeader (dsrRoutingHeader); | 586 Ipv4Address source = entry.GetSrc (); |
555 uint8_t dsrHeader = dsrRoutingHeader.GetNextHeader (); | 587 Ipv4Address destination = entry.GetDst (); |
556 uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); | 588 |
557 newPacket->RemoveAtStart (offset); | 589 DsrRoutingHeader dsrRoutingHeader; |
558 | 590 p->RemoveHeader (dsrRoutingHeader); |
559 // Get the number of routers' address field | 591 uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); |
560 uint8_t buf[2]; | 592 newPacket->RemoveAtStart (offset); |
561 newPacket->CopyData (buf, sizeof(buf)); | 593 |
562 uint8_t numberAddress = (buf[1] - 2) / 4; | 594 // Get the number of routers' address field |
563 | 595 uint8_t buf[2]; |
564 DsrOptionSRHeader sourceRoute; | 596 newPacket->CopyData (buf, sizeof(buf)); |
565 sourceRoute.SetNumberAddress (numberAddress); | 597 uint8_t numberAddress = (buf[1] - 2) / 4; |
566 newPacket->RemoveHeader (sourceRoute); | 598 |
567 uint8_t salvage = sourceRoute.GetSalvage (); | 599 DsrOptionSRHeader sourceRoute; |
568 | 600 sourceRoute.SetNumberAddress (numberAddress); |
569 DsrOptionAckReqHeader ackReq; | 601 newPacket->RemoveHeader (sourceRoute); |
570 newPacket->RemoveHeader (ackReq); | 602 uint8_t salvage = sourceRoute.GetSalvage (); |
571 /* | 603 |
572 * Get the node list address | 604 DsrOptionAckReqHeader ackReq; |
573 */ | 605 newPacket->RemoveHeader (ackReq); |
574 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress (); | 606 /* |
575 Ipv4Address address1 = nodeList.at (1); | 607 * Get the node list address |
576 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); | 608 */ |
577 NS_LOG_DEBUG ("The next hop address" << nextHop); | 609 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress (); |
578 if (nextHop == "0.0.0.0") | 610 Ipv4Address address1 = nodeList.front (); |
579 { | 611 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); |
580 return; | 612 NS_LOG_DEBUG ("The next hop address" << nextHop); |
581 } | 613 if (nextHop == "0.0.0.0") |
582 RouteCacheEntry salvageRoute; | |
583 bool findRoute = m_routeCache->LookupRoute (destination, salvageRoute); | |
584 // Check the salvage value in header, if salvage is needed, we should find
alternative route | |
585 if (findRoute && (salvage < m_maxSalvageCount)) | |
586 { | |
587 // Need to salvage the packet instead of discard it | |
588 Ipv4Address source = nodeList.front (); | |
589 std::vector<Ipv4Address> nodeList = salvageRoute.GetVector (); | |
590 DsrOptionSRHeader newSR; | |
591 newSR.SetNodesAddress (nodeList); | |
592 newSR.SetSegmentsLeft ((nodeList.size () - 2)); | |
593 newSR.SetSalvage (salvage + 1); | |
594 | |
595 if (m_maintainBuffer.FindPacketsWithNextHop (nextHop)) | |
596 { | 614 { |
597 // Send the data packet using the route we just find | 615 return; |
598 SendPacket (sourceRoute, nextHop, dsrHeader, m_ipv4Route); | |
599 } | 616 } |
600 } | 617 RouteCacheEntry salvageRoute; |
601 else | 618 bool findRoute = m_routeCache->LookupRoute (destination, salvageRoute)
; |
602 { | 619 // Check the salvage value in header, if salvage is needed, we should
find alternative route |
603 /* | 620 if (findRoute && (salvage < m_maxSalvageCount)) |
604 * This code block create a packet and attach a route error option to
it | |
605 */ | |
606 m_routeCache->DeleteAllRoutesIncludeLink (source, nextHop); | |
607 if (source == m_mainAddress) | |
608 { | 621 { |
609 DsrOptionRerrUnreachHeader rerr; | 622 // Need to salvage the packet instead of discard it |
610 rerr.SetErrorType (1); | 623 Ipv4Address source = nodeList.front (); |
611 rerr.SetErrorSrc (source); | 624 std::vector<Ipv4Address> nodeList = salvageRoute.GetVector (); |
612 rerr.SetUnreachNode (nextHop); | 625 DsrOptionSRHeader newSR; |
613 rerr.SetErrorDst (nextHop); | 626 newSR.SetNodesAddress (nodeList); |
614 rerr.SetSalvage (salvage); // Set the value about whether to s
alvage a packet or not | 627 newSR.SetSegmentsLeft ((nodeList.size () - 2)); |
615 SendErrorRequest (rerr, protocol); | 628 newSR.SetSalvage (salvage + 1); |
| 629 PacketKey packetKey; |
| 630 packetKey.m_ackId = entry.GetAckId (); |
| 631 packetKey.m_ourAdd = entry.GetOurAdd (); |
| 632 packetKey.m_nextHop = entry.GetNextHop (); |
| 633 packetKey.m_source = entry.GetSrc (); |
| 634 packetKey.m_destination = entry.GetDst (); |
| 635 packetKey.m_segsLeft = entry.GetSegsLeft (); |
| 636 SchedulePacketRetry (entry, packetKey, protocol); |
616 } | 637 } |
617 else | 638 else |
618 { | 639 { |
| 640 /* |
| 641 * This code block create a packet and attach a route error option
to it |
| 642 */ |
| 643 m_routeCache->DeleteAllRoutesIncludeLink (source, nextHop); |
| 644 |
| 645 /* |
| 646 * If the salvage is not 0, use the first address in the route as
the error dst in error header |
| 647 * otherwise use the source of packet as the error destination |
| 648 */ |
619 if (salvage) | 649 if (salvage) |
620 { | 650 { |
621 if (address1 == m_mainAddress) | 651 if (address1 == m_mainAddress) |
622 { | 652 { |
623 DsrOptionRerrUnreachHeader rerr; | 653 DsrOptionRerrUnreachHeader rerr; |
624 rerr.SetErrorType (1); | 654 rerr.SetErrorType (1); |
625 rerr.SetErrorSrc (source); | 655 rerr.SetErrorSrc (address1); |
626 rerr.SetUnreachNode (nextHop); | 656 rerr.SetUnreachNode (nextHop); |
627 rerr.SetErrorDst (nextHop); | 657 rerr.SetErrorDst (address1); |
628 rerr.SetSalvage (salvage); // Set the value about wh
ether to salvage a packet or not | 658 rerr.SetSalvage (salvage); // Set the value about wh
ether to salvage a packet or not |
629 SendErrorRequest (rerr, protocol); | 659 SendErrorRequest (rerr, protocol); |
630 } | 660 } |
631 else | 661 else |
632 { | 662 { |
633 SendUnreachError (nextHop, address1, salvage, protocol); | 663 SendUnreachError (nextHop, address1, salvage, protocol); |
634 } | 664 } |
635 } | 665 } |
636 else | 666 else |
637 { | 667 { |
638 SendUnreachError (nextHop, source, salvage, protocol); | 668 if (source == m_mainAddress) |
| 669 { |
| 670 DsrOptionRerrUnreachHeader rerr; |
| 671 rerr.SetErrorType (1); |
| 672 rerr.SetErrorSrc (source); |
| 673 rerr.SetUnreachNode (nextHop); |
| 674 rerr.SetErrorDst (source); |
| 675 rerr.SetSalvage (salvage); // Set the value about whet
her to salvage a packet or not |
| 676 SendErrorRequest (rerr, protocol); |
| 677 } |
| 678 else |
| 679 { |
| 680 SendUnreachError (nextHop, source, salvage, protocol); |
| 681 } |
639 } | 682 } |
| 683 } |
| 684 if (m_maintainBuffer.GetSize () != 0 && m_maintainBuffer.Find (nextHop
)) |
| 685 { |
| 686 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (
0,100)), |
| 687 &DsrRouting::SendRerrWhenBreaksLinkToNextHop,
this,nextHop,protocol); |
640 } | 688 } |
641 } | 689 } |
642 } | 690 } |
643 } | 691 } |
644 | 692 |
645 void DsrRouting::SendBuffTimerExpire () | 693 void DsrRouting::SendBuffTimerExpire () |
646 { | 694 { |
647 if (m_sendBuffTimer.IsRunning ()) | 695 if (m_sendBuffTimer.IsRunning ()) |
648 { | 696 { |
649 m_sendBuffTimer.Cancel (); | 697 m_sendBuffTimer.Cancel (); |
(...skipping 19 matching lines...) Expand all Loading... |
669 Ptr<const Packet> packet = i->GetPacket (); | 717 Ptr<const Packet> packet = i->GetPacket (); |
670 Ptr<Packet> cleanP = packet->Copy (); | 718 Ptr<Packet> cleanP = packet->Copy (); |
671 uint8_t protocol = i->GetProtocol (); | 719 uint8_t protocol = i->GetProtocol (); |
672 | 720 |
673 m_sendBuffer.GetBuffer ().erase (i); | 721 m_sendBuffer.GetBuffer ().erase (i); |
674 | 722 |
675 DsrRoutingHeader dsrRoutingHeader; | 723 DsrRoutingHeader dsrRoutingHeader; |
676 Ptr<Packet> copyP = packet->Copy (); | 724 Ptr<Packet> copyP = packet->Copy (); |
677 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); | 725 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); |
678 copyP->RemoveAtStart (offset); // Here the processed size is 8 bytes,
which is the fixed sized extension header | 726 copyP->RemoveAtStart (offset); // Here the processed size is 8 bytes,
which is the fixed sized extension header |
| 727 // The packet to get ipv4 header |
| 728 Ptr<Packet> ipv4P = copyP->Copy (); |
679 /* | 729 /* |
680 * Peek data to get the option type as well as length and segmentsLeft
field | 730 * Peek data to get the option type as well as length and segmentsLeft
field |
681 */ | 731 */ |
682 uint32_t size = copyP->GetSize (); | 732 uint32_t size = copyP->GetSize (); |
683 uint8_t *data = new uint8_t[size]; | 733 uint8_t *data = new uint8_t[size]; |
684 copyP->CopyData (data, size); | 734 copyP->CopyData (data, size); |
685 | 735 |
686 uint8_t optionType = 0; | 736 uint8_t optionType = 0; |
687 optionType = *(data); | 737 optionType = *(data); |
688 | 738 |
(...skipping 26 matching lines...) Expand all Loading... |
715 | 765 |
716 if (nextHop == "0.0.0.0") | 766 if (nextHop == "0.0.0.0") |
717 { | 767 { |
718 return; | 768 return; |
719 } | 769 } |
720 | 770 |
721 SetRoute (nextHop, m_mainAddress); | 771 SetRoute (nextHop, m_mainAddress); |
722 uint8_t length = (sourceRoute.GetLength () + newUnreach.GetLen
gth ()); | 772 uint8_t length = (sourceRoute.GetLength () + newUnreach.GetLen
gth ()); |
723 dsrRoutingHeader.SetNextHeader (protocol); | 773 dsrRoutingHeader.SetNextHeader (protocol); |
724 dsrRoutingHeader.SetMessageType (1); | 774 dsrRoutingHeader.SetMessageType (1); |
725 dsrRoutingHeader.SetSourceId (255); | 775 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress)); |
726 dsrRoutingHeader.SetDestId (255); | 776 dsrRoutingHeader.SetDestId (255); |
727 dsrRoutingHeader.SetPayloadLength (length + 4); | 777 dsrRoutingHeader.SetPayloadLength (length + 4); |
728 dsrRoutingHeader.AddDsrOption (newUnreach); | 778 dsrRoutingHeader.AddDsrOption (newUnreach); |
729 dsrRoutingHeader.AddDsrOption (sourceRoute); | 779 dsrRoutingHeader.AddDsrOption (sourceRoute); |
730 | 780 |
731 Ptr<Packet> newPacket = Create<Packet> (); | 781 Ptr<Packet> newPacket = Create<Packet> (); |
732 newPacket->AddHeader (dsrRoutingHeader); // Add the routing he
ader with rerr and sourceRoute attached to it | 782 newPacket->AddHeader (dsrRoutingHeader); // Add the routing he
ader with rerr and sourceRoute attached to it |
733 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceFor
Address (m_mainAddress)); | 783 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceFor
Address (m_mainAddress)); |
734 m_ipv4Route->SetOutputDevice (dev); | 784 m_ipv4Route->SetOutputDevice (dev); |
735 m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNu
mber (), m_ipv4Route); | 785 m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNu
mber (), m_ipv4Route); |
(...skipping 14 matching lines...) Expand all Loading... |
750 PacketNewRoute (cleanP, m_mainAddress, destination, protocol); | 800 PacketNewRoute (cleanP, m_mainAddress, destination, protocol); |
751 return; | 801 return; |
752 } | 802 } |
753 uint8_t salvage = 0; | 803 uint8_t salvage = 0; |
754 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in
the source route header of the packet | 804 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in
the source route header of the packet |
755 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segme
ntsLeft field will indicate the hops to go | 805 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segme
ntsLeft field will indicate the hops to go |
756 sourceRoute.SetSalvage (salvage); | 806 sourceRoute.SetSalvage (salvage); |
757 | 807 |
758 DsrOptionAckReqHeader ackReq; | 808 DsrOptionAckReqHeader ackReq; |
759 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); | 809 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); |
760 ackReq.SetId (m_ackId); | 810 ackReq.SetAckId (m_ackId); |
761 | 811 |
762 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); | 812 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); |
763 NS_LOG_DEBUG ("the length of source route header " << (uint32_t)(s
ourceRoute.GetLength ())); | 813 NS_LOG_DEBUG ("the length of source route header " << (uint32_t)(s
ourceRoute.GetLength ())); |
764 NS_LOG_DEBUG ("the length of ack request header " << (uint32_t)(ac
kReq.GetLength ())); | 814 NS_LOG_DEBUG ("the length of ack request header " << (uint32_t)(ac
kReq.GetLength ())); |
765 | 815 |
766 dsrRoutingHeader.SetPayloadLength (length + 4); | 816 dsrRoutingHeader.SetPayloadLength (length + 4); |
767 dsrRoutingHeader.AddDsrOption (sourceRoute); | 817 dsrRoutingHeader.AddDsrOption (sourceRoute); |
768 dsrRoutingHeader.AddDsrOption (ackReq); | 818 dsrRoutingHeader.AddDsrOption (ackReq); |
769 cleanP->AddHeader (dsrRoutingHeader); | 819 cleanP->AddHeader (dsrRoutingHeader); |
770 Ptr<const Packet> mtP = cleanP->Copy (); | 820 Ptr<const Packet> mtP = cleanP->Copy (); |
771 SetRoute (nextHop, m_mainAddress); | |
772 | |
773 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddr
ess (m_mainAddress)); | |
774 m_ipv4Route->SetOutputDevice (dev); | |
775 Ipv4Header const ipv4Header; | |
776 uint16_t routeSize = sourceRoute.GetNodeListSize (); // Get the ro
ute length of in the source route header | |
777 // Put the data packet in the maintenance queue for data packet re
transmission | 821 // Put the data packet in the maintenance queue for data packet re
transmission |
778 MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Header=*/ ipv4H
eader, /*Ipv4Address=*/ m_mainAddress, /*nextHop=*/ nextHop, | 822 MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Address=*/ m_ma
inAddress, /*nextHop=*/ nextHop, |
779 /*source=*/ m_mainAddress,
/*destination=*/ destination, /*ackId=*/ m_ackId, /*SegsLeft=*/ nodeList.size (
) - 2, | 823 /*source=*/ m_mainAddress, /*destinati
on=*/ destination, /*ackId=*/ m_ackId, |
780 /*Salvage=*/ 0, /*RouteSiz
e=*/ routeSize, /*expire time=*/ m_maxMaintainTime); | 824 /*SegsLeft=*/nodeList.size () - 2, /*e
xpire time=*/ m_maxMaintainTime); |
781 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the
packet the the maintenance buffer | 825 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the
packet the the maintenance buffer |
782 if (result) | 826 if (result) |
783 { | 827 { |
784 Ptr<Packet> newPacket = cleanP->Copy (); | 828 Ptr<Packet> newPacket = cleanP->Copy (); |
785 m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNu
mber (), m_ipv4Route); | |
786 PacketKey packetKey; | 829 PacketKey packetKey; |
787 packetKey.m_ackId = newEntry.GetAckId (); | 830 packetKey.m_ackId = newEntry.GetAckId (); |
788 packetKey.m_ourAdd = newEntry.GetOurAdd (); | 831 packetKey.m_ourAdd = newEntry.GetOurAdd (); |
789 packetKey.m_nextHop = newEntry.GetNextHop (); | 832 packetKey.m_nextHop = newEntry.GetNextHop (); |
790 packetKey.m_source = newEntry.GetSrc (); | 833 packetKey.m_source = newEntry.GetSrc (); |
791 packetKey.m_destination = newEntry.GetDst (); | 834 packetKey.m_destination = newEntry.GetDst (); |
792 packetKey.m_segsLeft = newEntry.GetSegsLeft (); | 835 packetKey.m_segsLeft = newEntry.GetSegsLeft (); |
793 packetKey.m_id = newEntry.GetId (); | 836 SchedulePacketRetry (newEntry, packetKey, protocol); |
794 packetKey.m_fragmentOffset = newEntry.GetFragmentOffset (); | |
795 SchedulePacketRetry (newEntry, packetKey, protocol, m_ipv4Rout
e); | |
796 } | 837 } |
797 //we need to suspend the normal timer that checks the send buffer | 838 //we need to suspend the normal timer that checks the send buffer |
798 //until we are done sending packets | 839 //until we are done sending packets |
799 if (!m_sendBuffTimer.IsSuspended ()) | 840 if (!m_sendBuffTimer.IsSuspended ()) |
800 { | 841 { |
801 m_sendBuffTimer.Suspend (); | 842 m_sendBuffTimer.Suspend (); |
802 } | 843 } |
803 Simulator::Schedule (m_sendBuffInterval, &DsrRouting::CheckSendBuf
fer, this); | 844 Simulator::Schedule (m_sendBuffInterval, &DsrRouting::CheckSendBuf
fer, this); |
804 return; | 845 return; |
805 } | 846 } |
(...skipping 27 matching lines...) Expand all Loading... |
833 if (ipv4Header.GetProtocol () == DsrRouting::PROT_NUMBER) | 874 if (ipv4Header.GetProtocol () == DsrRouting::PROT_NUMBER) |
834 { | 875 { |
835 //just to minimize debug output | 876 //just to minimize debug output |
836 NS_LOG_INFO (this << from << to << packetType << *p); | 877 NS_LOG_INFO (this << from << to << packetType << *p); |
837 DsrRoutingHeader dsrRoutingHeader; | 878 DsrRoutingHeader dsrRoutingHeader; |
838 //pull of DSR header to check option type | 879 //pull of DSR header to check option type |
839 Ptr<Packet> dsrPacket = p->Copy (); | 880 Ptr<Packet> dsrPacket = p->Copy (); |
840 dsrPacket->RemoveHeader (dsrRoutingHeader); | 881 dsrPacket->RemoveHeader (dsrRoutingHeader); |
841 uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); // Ge
t the offset for option header, 4 bytes in this case | 882 uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); // Ge
t the offset for option header, 4 bytes in this case |
842 uint8_t nextHeader = dsrRoutingHeader.GetNextHeader (); | 883 uint8_t nextHeader = dsrRoutingHeader.GetNextHeader (); |
| 884 uint32_t sourceId = dsrRoutingHeader.GetSourceId (); |
| 885 Ipv4Address source = GetIPfromID (sourceId); |
843 | 886 |
844 // This packet is used to peek option type | 887 // This packet is used to peek option type |
845 p->RemoveAtStart (offset); | 888 p->RemoveAtStart (offset); |
846 /* | 889 /* |
847 * Peek data to get the option type as well as length and segmentsLeft
field | 890 * Peek data to get the option type as well as length and segmentsLeft
field |
848 */ | 891 */ |
849 uint32_t size = p->GetSize (); | 892 uint32_t size = p->GetSize (); |
850 uint8_t *data = new uint8_t[size]; | 893 uint8_t *data = new uint8_t[size]; |
851 p->CopyData (data, size); | 894 p->CopyData (data, size); |
852 uint8_t optionType = 0; | 895 uint8_t optionType = 0; |
853 uint8_t optionLength = 0; | 896 uint8_t optionLength = 0; |
854 | 897 |
855 optionType = *(data); | 898 optionType = *(data); |
856 Ptr<DsrOptions> dsrOption; | 899 Ptr<DsrOptions> dsrOption; |
857 | 900 |
858 if (optionType == 96) // This is the source route option | 901 if (optionType == 96) // This is the source route option |
859 { | 902 { |
860 dsrOption = GetOption (optionType); // Get the relative dsr
option and demux to the process function | 903 dsrOption = GetOption (optionType); // Get the relative DSR
option and demux to the process function |
861 Ipv4Address fromAddr = GetIPfromMAC (Mac48Address::ConvertFrom (fr
om)); | 904 Ipv4Address fromAddr = GetIPfromMAC (Mac48Address::ConvertFrom (fr
om)); |
862 Ipv4Address toAddr = GetIPfromMAC (Mac48Address::ConvertFrom (to))
; | 905 Ipv4Address toAddr = GetIPfromMAC (Mac48Address::ConvertFrom (to))
; |
863 | 906 |
864 NS_LOG_DEBUG (Simulator::Now ().GetSeconds () | 907 NS_LOG_DEBUG (Simulator::Now ().GetSeconds () |
865 << " DSR node " << m_mainAddress << | 908 << " DSR node " << m_mainAddress << |
866 " overhearing packet PID: " << p->GetUid () << " fro
m " << fromAddr << " to " << toAddr << | 909 " overhearing packet PID: " << p->GetUid () << " fro
m " << fromAddr << " to " << toAddr << |
867 " with source IP " << ipv4Header.GetSource () << | 910 " with source IP " << ipv4Header.GetSource () << |
868 " and destination IP " << ipv4Header.GetDestination
() << | 911 " and destination IP " << ipv4Header.GetDestination
() << |
869 " and packet : " << *dsrPacket); | 912 " and packet : " << *dsrPacket); |
870 bool isPromisc = true; // Set the boolean valu
e isPromisc as true | 913 bool isPromisc = true; // Set the boolean valu
e isPromisc as true |
871 optionLength = dsrOption->Process (p, dsrPacket, m_mainAddress, ip
v4Header, nextHeader, isPromisc); | 914 optionLength = dsrOption->Process (p, dsrPacket, m_mainAddress, so
urce, ipv4Header, nextHeader, isPromisc); |
872 return true; | 915 return true; |
873 } | 916 } |
874 } | 917 } |
875 } | 918 } |
876 return false; | 919 return false; |
877 } | 920 } |
878 | 921 |
879 void | 922 void |
880 DsrRouting::PacketNewRoute (Ptr<Packet> packet, | 923 DsrRouting::PacketNewRoute (Ptr<Packet> packet, |
881 Ipv4Address source, | 924 Ipv4Address source, |
(...skipping 12 matching lines...) Expand all Loading... |
894 | 937 |
895 Ptr<Packet> p = packet->Copy (); | 938 Ptr<Packet> p = packet->Copy (); |
896 SendBuffEntry newEntry (p, destination, m_sendBufferTimeout, protocol);
// Create a new entry for send buffer | 939 SendBuffEntry newEntry (p, destination, m_sendBufferTimeout, protocol);
// Create a new entry for send buffer |
897 bool result = m_sendBuffer.Enqueue (newEntry); // Enqueue the packet i
n send buffer | 940 bool result = m_sendBuffer.Enqueue (newEntry); // Enqueue the packet i
n send buffer |
898 if (result) | 941 if (result) |
899 { | 942 { |
900 NS_LOG_INFO (Simulator::Now ().GetSeconds () | 943 NS_LOG_INFO (Simulator::Now ().GetSeconds () |
901 << "s Add packet PID: " << packet->GetUid () << " to queu
e. Packet: " << *packet); | 944 << "s Add packet PID: " << packet->GetUid () << " to queu
e. Packet: " << *packet); |
902 | 945 |
903 NS_LOG_LOGIC ("Send RREQ to" << destination); | 946 NS_LOG_LOGIC ("Send RREQ to" << destination); |
904 /* | 947 if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ())
&& (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ())) |
905 * Call the send request function, it will update the request table en
try and ttl there | 948 { |
906 */ | 949 /* |
907 SendInitialRequest (source, destination, protocol); | 950 * Call the send request function, it will update the request tabl
e entry and ttl there |
| 951 */ |
| 952 SendInitialRequest (source, destination, protocol); |
| 953 } |
908 } | 954 } |
909 } | 955 } |
910 else | 956 else |
911 { | 957 { |
912 Ptr<Packet> cleanP = packet->Copy (); | 958 Ptr<Packet> cleanP = packet->Copy (); |
913 DsrRoutingHeader dsrRoutingHeader; | 959 DsrRoutingHeader dsrRoutingHeader; |
914 dsrRoutingHeader.SetNextHeader (protocol); | 960 dsrRoutingHeader.SetNextHeader (protocol); |
915 dsrRoutingHeader.SetMessageType (2); | 961 dsrRoutingHeader.SetMessageType (2); |
916 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); | 962 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
917 dsrRoutingHeader.SetDestId (GetIDfromIP (destination)); | 963 dsrRoutingHeader.SetDestId (GetIDfromIP (destination)); |
918 | 964 |
919 DsrOptionSRHeader sourceRoute; | 965 DsrOptionSRHeader sourceRoute; |
920 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the rou
te from the route entry we found | 966 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the rou
te from the route entry we found |
921 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); // Get
the next hop address for the route | 967 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); // Get
the next hop address for the route |
922 if (nextHop == "0.0.0.0") | 968 if (nextHop == "0.0.0.0") |
923 { | 969 { |
924 PacketNewRoute (cleanP, source, destination, protocol); | 970 PacketNewRoute (cleanP, source, destination, protocol); |
925 return; | 971 return; |
926 } | 972 } |
927 uint8_t salvage = 0; | 973 uint8_t salvage = 0; |
928 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the
source route header of the packet | 974 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the
source route header of the packet |
929 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segmentsL
eft field will indicate the hops to go | 975 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segmentsL
eft field will indicate the hops to go |
930 sourceRoute.SetSalvage (salvage); | 976 sourceRoute.SetSalvage (salvage); |
931 | 977 |
932 DsrOptionAckReqHeader ackReq; | 978 DsrOptionAckReqHeader ackReq; |
933 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); | 979 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); |
934 ackReq.SetId (m_ackId); | 980 ackReq.SetAckId (m_ackId); |
935 | 981 |
936 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); | 982 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); |
937 | |
938 dsrRoutingHeader.SetPayloadLength (length + 4); | 983 dsrRoutingHeader.SetPayloadLength (length + 4); |
939 dsrRoutingHeader.AddDsrOption (sourceRoute); | 984 dsrRoutingHeader.AddDsrOption (sourceRoute); |
940 dsrRoutingHeader.AddDsrOption (ackReq); | 985 dsrRoutingHeader.AddDsrOption (ackReq); |
941 cleanP->AddHeader (dsrRoutingHeader); | 986 cleanP->AddHeader (dsrRoutingHeader); |
942 Ptr<const Packet> mtP = cleanP->Copy (); | 987 Ptr<const Packet> mtP = cleanP->Copy (); |
943 SetRoute (nextHop, m_mainAddress); | 988 SetRoute (nextHop, m_mainAddress); |
944 Ipv4Header const ipv4Header; | |
945 // Put the data packet in the maintenance queue for data packet retransmis
sion | 989 // Put the data packet in the maintenance queue for data packet retransmis
sion |
946 MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Header=*/ ipv4Header, /
*Ipv4Address=*/ m_mainAddress, /*nextHop=*/ nextHop, | 990 MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Address=*/ m_mainAddres
s, /*nextHop=*/ nextHop, |
947 /*source=*/ source, /*destination=
*/ destination, /*ackId=*/ m_ackId, /*SegsLeft=*/ sourceRoute.GetSegmentsLeft ()
, | 991 /*source=*/ source, /*destination=
*/ destination, /*ackId=*/ m_ackId, |
948 /*Salvage=*/ 0, /*RouteSize=*/ nod
eList.size (), /*expire time=*/ m_maxMaintainTime); | 992 /*SegsLeft=*/nodeList.size () - 2,
/*expire time=*/ m_maxMaintainTime); |
949 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the pack
et the the maintenance buffer | 993 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the pack
et the the maintenance buffer |
950 | 994 |
951 if (result) | 995 if (result) |
952 { | 996 { |
953 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress
(m_mainAddress)); | |
954 m_ipv4Route->SetOutputDevice (dev); | |
955 m_downTarget (cleanP, m_mainAddress, nextHop, GetProtocolNumber (), m_
ipv4Route); | |
956 PacketKey packetKey; | 997 PacketKey packetKey; |
957 packetKey.m_ackId = newEntry.GetAckId (); | 998 packetKey.m_ackId = newEntry.GetAckId (); |
958 packetKey.m_ourAdd = newEntry.GetOurAdd (); | 999 packetKey.m_ourAdd = newEntry.GetOurAdd (); |
959 packetKey.m_nextHop = newEntry.GetNextHop (); | 1000 packetKey.m_nextHop = newEntry.GetNextHop (); |
960 packetKey.m_source = newEntry.GetSrc (); | 1001 packetKey.m_source = newEntry.GetSrc (); |
961 packetKey.m_destination = newEntry.GetDst (); | 1002 packetKey.m_destination = newEntry.GetDst (); |
962 packetKey.m_segsLeft = newEntry.GetSegsLeft (); | 1003 packetKey.m_segsLeft = newEntry.GetSegsLeft (); |
963 packetKey.m_id = newEntry.GetId (); | 1004 SchedulePacketRetry (newEntry, packetKey, protocol); |
964 packetKey.m_fragmentOffset = newEntry.GetFragmentOffset (); | |
965 SchedulePacketRetry (newEntry, packetKey, protocol, m_ipv4Route); | |
966 } | 1005 } |
967 } | 1006 } |
968 } | 1007 } |
969 | 1008 |
970 void | 1009 void |
971 DsrRouting::SendUnreachError (Ipv4Address errorHop, Ipv4Address destination, uin
t8_t salvage, uint8_t protocol) | 1010 DsrRouting::SendUnreachError (Ipv4Address errorHop, Ipv4Address destination, uin
t8_t salvage, uint8_t protocol) |
972 { | 1011 { |
973 NS_LOG_FUNCTION (this << errorHop << destination << (uint32_t)salvage << (uint
32_t)protocol); | 1012 NS_LOG_FUNCTION (this << errorHop << destination << (uint32_t)salvage << (uint
32_t)protocol); |
974 DsrRoutingHeader dsrRoutingHeader; | 1013 DsrRoutingHeader dsrRoutingHeader; |
975 dsrRoutingHeader.SetNextHeader (protocol); | 1014 dsrRoutingHeader.SetNextHeader (protocol); |
976 dsrRoutingHeader.SetMessageType (1); | 1015 dsrRoutingHeader.SetMessageType (1); |
977 dsrRoutingHeader.SetSourceId (255); | 1016 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress)); |
978 dsrRoutingHeader.SetDestId (255); | 1017 dsrRoutingHeader.SetDestId (GetIDfromIP (destination)); |
979 | 1018 |
980 DsrOptionRerrUnreachHeader rerrUnreachHeader; | 1019 DsrOptionRerrUnreachHeader rerrUnreachHeader; |
981 rerrUnreachHeader.SetErrorType (1); | 1020 rerrUnreachHeader.SetErrorType (1); |
982 rerrUnreachHeader.SetErrorSrc (m_mainAddress); | 1021 rerrUnreachHeader.SetErrorSrc (m_mainAddress); |
983 rerrUnreachHeader.SetUnreachNode (errorHop); | 1022 rerrUnreachHeader.SetUnreachNode (errorHop); |
984 rerrUnreachHeader.SetErrorDst (destination); | 1023 rerrUnreachHeader.SetErrorDst (destination); |
985 rerrUnreachHeader.SetSalvage (salvage); // Set the value about whether to
salvage a packet or not | 1024 rerrUnreachHeader.SetSalvage (salvage); // Set the value about whether to
salvage a packet or not |
986 uint8_t rerrLength = rerrUnreachHeader.GetLength (); | 1025 uint8_t rerrLength = rerrUnreachHeader.GetLength (); |
987 | 1026 |
988 RouteCacheEntry toDst; | 1027 RouteCacheEntry toDst; |
(...skipping 10 matching lines...) Expand all Loading... |
999 newPacket->AddHeader (dsrRoutingHeader); | 1038 newPacket->AddHeader (dsrRoutingHeader); |
1000 Ptr<Packet> p = newPacket->Copy (); | 1039 Ptr<Packet> p = newPacket->Copy (); |
1001 SendBuffEntry newEntry (p, destination, m_sendBufferTimeout); | 1040 SendBuffEntry newEntry (p, destination, m_sendBufferTimeout); |
1002 newEntry.SetErrHeader (true); // Note it as an error packet | 1041 newEntry.SetErrHeader (true); // Note it as an error packet |
1003 bool result = m_sendBuffer.Enqueue (newEntry); // Enqueue the packet i
n send buffer | 1042 bool result = m_sendBuffer.Enqueue (newEntry); // Enqueue the packet i
n send buffer |
1004 if (result) | 1043 if (result) |
1005 { | 1044 { |
1006 NS_LOG_INFO (Simulator::Now ().GetSeconds () | 1045 NS_LOG_INFO (Simulator::Now ().GetSeconds () |
1007 << "s Add packet PID: " << p->GetUid () << " to queue. Pa
cket: " << *p); | 1046 << "s Add packet PID: " << p->GetUid () << " to queue. Pa
cket: " << *p); |
1008 NS_LOG_LOGIC ("Send RREQ to" << destination); | 1047 NS_LOG_LOGIC ("Send RREQ to" << destination); |
1009 SendInitialRequest (m_mainAddress, destination, protocol); | 1048 if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ())
&& (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ())) |
| 1049 { |
| 1050 NS_LOG_DEBUG ("When there is no existing route request for " << de
stination << ", initialize one"); |
| 1051 /* |
| 1052 * Call the send request function, it will update the request tabl
e entry and ttl there |
| 1053 */ |
| 1054 SendInitialRequest (m_mainAddress, destination, protocol); |
| 1055 } |
1010 } | 1056 } |
1011 } | 1057 } |
1012 else | 1058 else |
1013 { | 1059 { |
1014 std::vector<Ipv4Address> nodeList = toDst.GetVector (); | 1060 std::vector<Ipv4Address> nodeList = toDst.GetVector (); |
1015 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); | 1061 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); |
1016 if (nextHop == "0.0.0.0") | 1062 if (nextHop == "0.0.0.0") |
1017 { | 1063 { |
1018 return; | 1064 return; |
1019 } | 1065 } |
(...skipping 13 matching lines...) Expand all Loading... |
1033 SetRoute (nextHop, m_mainAddress); | 1079 SetRoute (nextHop, m_mainAddress); |
1034 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_m
ainAddress)); | 1080 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_m
ainAddress)); |
1035 m_ipv4Route->SetOutputDevice (dev); | 1081 m_ipv4Route->SetOutputDevice (dev); |
1036 m_downTarget (newPacket, m_mainAddress, nextHop, protocol, m_ipv4Route); | 1082 m_downTarget (newPacket, m_mainAddress, nextHop, protocol, m_ipv4Route); |
1037 } | 1083 } |
1038 } | 1084 } |
1039 | 1085 |
1040 void | 1086 void |
1041 DsrRouting::ForwardErrPacket (DsrOptionRerrUnreachHeader &rerr, | 1087 DsrRouting::ForwardErrPacket (DsrOptionRerrUnreachHeader &rerr, |
1042 DsrOptionSRHeader &sourceRoute, | 1088 DsrOptionSRHeader &sourceRoute, |
1043 Ipv4Address destination, | 1089 Ipv4Address nextHop, |
1044 uint8_t protocol, | 1090 uint8_t protocol, |
1045 Ptr<Ipv4Route> route) | 1091 Ptr<Ipv4Route> route) |
1046 { | 1092 { |
1047 NS_LOG_FUNCTION (this << rerr << sourceRoute << destination << (uint32_t)proto
col << route); | 1093 NS_LOG_FUNCTION (this << rerr << sourceRoute << nextHop << (uint32_t)protocol
<< route); |
1048 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 1094 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
1049 DsrRoutingHeader dsrRoutingHeader; | 1095 DsrRoutingHeader dsrRoutingHeader; |
1050 dsrRoutingHeader.SetNextHeader (protocol); | 1096 dsrRoutingHeader.SetNextHeader (protocol); |
1051 dsrRoutingHeader.SetMessageType (1); | 1097 dsrRoutingHeader.SetMessageType (1); |
1052 dsrRoutingHeader.SetSourceId (255); | 1098 dsrRoutingHeader.SetSourceId (GetIDfromIP (rerr.GetErrorSrc ())); |
1053 dsrRoutingHeader.SetDestId (255); | 1099 dsrRoutingHeader.SetDestId (GetIDfromIP (rerr.GetErrorDst ())); |
1054 | 1100 |
1055 uint8_t length = (sourceRoute.GetLength () + rerr.GetLength ()); | 1101 uint8_t length = (sourceRoute.GetLength () + rerr.GetLength ()); |
1056 dsrRoutingHeader.SetPayloadLength (length + 4); | 1102 dsrRoutingHeader.SetPayloadLength (length + 4); |
1057 dsrRoutingHeader.AddDsrOption (rerr); | 1103 dsrRoutingHeader.AddDsrOption (rerr); |
1058 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1104 dsrRoutingHeader.AddDsrOption (sourceRoute); |
1059 Ptr<Packet> packet = Create<Packet> (); | 1105 Ptr<Packet> packet = Create<Packet> (); |
1060 packet->AddHeader (dsrRoutingHeader); | 1106 packet->AddHeader (dsrRoutingHeader); |
1061 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainA
ddress)); | 1107 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainA
ddress)); |
1062 route->SetOutputDevice (dev); | 1108 route->SetOutputDevice (dev); |
1063 m_downTarget (packet, m_mainAddress, destination, GetProtocolNumber (), route)
; | 1109 m_downTarget (packet, m_mainAddress, nextHop, GetProtocolNumber (), route); |
1064 } | 1110 } |
1065 | 1111 |
1066 void | 1112 void |
1067 DsrRouting::Send (Ptr<Packet> packet, | 1113 DsrRouting::Send (Ptr<Packet> packet, |
1068 Ipv4Address source, | 1114 Ipv4Address source, |
1069 Ipv4Address destination, | 1115 Ipv4Address destination, |
1070 uint8_t protocol, | 1116 uint8_t protocol, |
1071 Ptr<Ipv4Route> route) | 1117 Ptr<Ipv4Route> route) |
1072 { | 1118 { |
1073 NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)protocol
<< route); | 1119 NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)protocol
<< route); |
(...skipping 17 matching lines...) Expand all Loading... |
1091 Ptr<Packet> p = packet->Copy (); | 1137 Ptr<Packet> p = packet->Copy (); |
1092 // This is the empty packet to send control packets | 1138 // This is the empty packet to send control packets |
1093 Ptr<Packet> newPacket = Create<Packet> (); | 1139 Ptr<Packet> newPacket = Create<Packet> (); |
1094 m_newPacketSize = packet->GetSize (); | 1140 m_newPacketSize = packet->GetSize (); |
1095 SendBuffEntry newEntry (p, destination, m_sendBufferTimeout, protocol)
; // Create a new entry for send buffer | 1141 SendBuffEntry newEntry (p, destination, m_sendBufferTimeout, protocol)
; // Create a new entry for send buffer |
1096 bool result = m_sendBuffer.Enqueue (newEntry); // Enqueue the pack
et in send buffer | 1142 bool result = m_sendBuffer.Enqueue (newEntry); // Enqueue the pack
et in send buffer |
1097 if (result) | 1143 if (result) |
1098 { | 1144 { |
1099 NS_LOG_INFO (Simulator::Now ().GetSeconds () | 1145 NS_LOG_INFO (Simulator::Now ().GetSeconds () |
1100 << "s Add packet PID: " << packet->GetUid () << " to
queue. Packet: " << *packet); | 1146 << "s Add packet PID: " << packet->GetUid () << " to
queue. Packet: " << *packet); |
1101 NS_LOG_LOGIC ("Send RREQ to" << destination); | 1147 NS_LOG_LOGIC ("Send RREQ to " << destination); |
1102 /* | 1148 // Only when there is no existing route request timer when new rou
te request is scheduled |
1103 * Call the send request function, it will update the request tabl
e entry and ttl there | 1149 if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end
()) && (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ())) |
1104 */ | 1150 { |
1105 SendInitialRequest (source, destination, protocol); | 1151 NS_LOG_DEBUG ("When there is no existing route request for " <
< destination << ", initialize one"); |
| 1152 /* |
| 1153 * Call the send request function, it will update the request
table entry and ttl there |
| 1154 */ |
| 1155 SendInitialRequest (source, destination, protocol); |
| 1156 } |
1106 } | 1157 } |
1107 } | 1158 } |
1108 else | 1159 else |
1109 { | 1160 { |
1110 Ptr<Packet> cleanP = packet->Copy (); | 1161 Ptr<Packet> cleanP = packet->Copy (); |
1111 DsrRoutingHeader dsrRoutingHeader; | 1162 DsrRoutingHeader dsrRoutingHeader; |
1112 dsrRoutingHeader.SetNextHeader (protocol); | 1163 dsrRoutingHeader.SetNextHeader (protocol); |
1113 dsrRoutingHeader.SetMessageType (2); | 1164 dsrRoutingHeader.SetMessageType (2); |
1114 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); | 1165 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
1115 dsrRoutingHeader.SetDestId (GetIDfromIP (destination)); | 1166 dsrRoutingHeader.SetDestId (GetIDfromIP (destination)); |
1116 | 1167 |
1117 DsrOptionSRHeader sourceRoute; | 1168 DsrOptionSRHeader sourceRoute; |
1118 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get t
he route from the route entry we found | 1169 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get t
he route from the route entry we found |
1119 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList);
// Get the next hop address for the route | 1170 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList);
// Get the next hop address for the route |
1120 if (nextHop == "0.0.0.0") | 1171 if (nextHop == "0.0.0.0") |
1121 { | 1172 { |
1122 PacketNewRoute (cleanP, source, destination, protocol); | 1173 PacketNewRoute (cleanP, source, destination, protocol); |
1123 return; | 1174 return; |
1124 } | 1175 } |
1125 uint8_t salvage = 0; | 1176 uint8_t salvage = 0; |
1126 sourceRoute.SetNodesAddress (nodeList); // Save the whole route
in the source route header of the packet | 1177 sourceRoute.SetNodesAddress (nodeList); // Save the whole route
in the source route header of the packet |
1127 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The seg
mentsLeft field will indicate the hops to go | 1178 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The seg
mentsLeft field will indicate the hops to go |
1128 sourceRoute.SetSalvage (salvage); | 1179 sourceRoute.SetSalvage (salvage); |
1129 | 1180 |
1130 DsrOptionAckReqHeader ackReq; | 1181 DsrOptionAckReqHeader ackReq; |
1131 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); | 1182 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); |
1132 ackReq.SetId (m_ackId); | 1183 ackReq.SetAckId (m_ackId); |
1133 | 1184 |
1134 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); | 1185 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); |
1135 | 1186 |
1136 dsrRoutingHeader.SetPayloadLength (length + 4); | 1187 dsrRoutingHeader.SetPayloadLength (length + 4); |
1137 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1188 dsrRoutingHeader.AddDsrOption (sourceRoute); |
1138 dsrRoutingHeader.AddDsrOption (ackReq); | 1189 dsrRoutingHeader.AddDsrOption (ackReq); |
1139 cleanP->AddHeader (dsrRoutingHeader); | 1190 cleanP->AddHeader (dsrRoutingHeader); |
| 1191 |
1140 Ptr<const Packet> mtP = cleanP->Copy (); | 1192 Ptr<const Packet> mtP = cleanP->Copy (); |
1141 Ipv4Header const ipv4Header; | |
1142 // Put the data packet in the maintenance queue for data packet retran
smission | 1193 // Put the data packet in the maintenance queue for data packet retran
smission |
1143 MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Header=*/ ipv4Heade
r, /*ourAddress=*/ m_mainAddress, /*nextHop=*/ nextHop, | 1194 MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_mainAdd
ress, /*nextHop=*/ nextHop, |
1144 /*source=*/ source, /*destinat
ion=*/ destination, /*ackId=*/ m_ackId, /*SegsLeft=*/ nodeList.size () - 2, | 1195 /*source=*/ source, /*destination=*/ desti
nation, /*ackId=*/ m_ackId, |
1145 /*Salvage=*/ 0, /*RouteSize=*/
nodeList.size (), /*expire time=*/ m_maxMaintainTime); | 1196 /*SegsLeft=*/nodeList.size () - 2, /*expir
e time=*/ m_maxMaintainTime); |
1146 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue th
e packet the the maintenance buffer | 1197 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue th
e packet the the maintenance buffer |
1147 if (result) | 1198 if (result) |
1148 { | 1199 { |
1149 SetRoute (nextHop, m_mainAddress); | |
1150 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddr
ess (m_mainAddress)); | |
1151 m_ipv4Route->SetOutputDevice (dev); | |
1152 Ptr<Packet> newPacket = cleanP->Copy (); | 1200 Ptr<Packet> newPacket = cleanP->Copy (); |
1153 m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNumber
(), m_ipv4Route); | 1201 /* |
| 1202 * Schedule the packet retransmission |
| 1203 */ |
1154 PacketKey packetKey; | 1204 PacketKey packetKey; |
1155 packetKey.m_ackId = newEntry.GetAckId (); | 1205 packetKey.m_ackId = newEntry.GetAckId (); |
1156 packetKey.m_ourAdd = newEntry.GetOurAdd (); | 1206 packetKey.m_ourAdd = newEntry.GetOurAdd (); |
1157 packetKey.m_nextHop = newEntry.GetNextHop (); | 1207 packetKey.m_nextHop = newEntry.GetNextHop (); |
1158 packetKey.m_source = newEntry.GetSrc (); | 1208 packetKey.m_source = newEntry.GetSrc (); |
1159 packetKey.m_destination = newEntry.GetDst (); | 1209 packetKey.m_destination = newEntry.GetDst (); |
1160 packetKey.m_segsLeft = newEntry.GetSegsLeft (); | 1210 packetKey.m_segsLeft = newEntry.GetSegsLeft (); |
1161 packetKey.m_id = newEntry.GetId (); | 1211 PacketKey networkKey = packetKey; |
1162 packetKey.m_fragmentOffset = newEntry.GetFragmentOffset (); | 1212 networkKey.m_segsLeft = 0; |
1163 SchedulePacketRetry (newEntry, packetKey, protocol, m_ipv4Route); | 1213 m_addressForwardCnt[networkKey] = 0; |
| 1214 SchedulePacketRetry (newEntry, packetKey, protocol); |
1164 } | 1215 } |
| 1216 // Try to send packet from *previously* queued entries from send buffe
r if any |
| 1217 SendPacket (sourceRoute, nextHop, protocol); |
1165 } | 1218 } |
1166 } | 1219 } |
1167 } | 1220 } |
1168 | 1221 |
1169 void | 1222 void |
1170 DsrRouting::SendPacket (DsrOptionSRHeader const &sourceRoute, | 1223 DsrRouting::SendPacket (DsrOptionSRHeader const &sourceRoute, |
1171 Ipv4Address nextHop, | 1224 Ipv4Address nextHop, |
1172 uint8_t protocol, | 1225 uint8_t protocol) |
1173 Ptr<Ipv4Route> route) | 1226 { |
1174 { | 1227 NS_LOG_FUNCTION (this << (uint32_t)protocol); |
1175 NS_LOG_FUNCTION (this << (uint32_t)protocol << route); | |
1176 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 1228 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
1177 | 1229 |
1178 // Reconstruct the route and Retransmit the data packet | 1230 // Reconstruct the route and Retransmit the data packet |
1179 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress (); | 1231 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress (); |
1180 Ipv4Address destination = nodeList.back (); | 1232 Ipv4Address destination = nodeList.back (); |
1181 Ipv4Address source = nodeList.front (); // Get the source address | 1233 Ipv4Address source = nodeList.front (); // Get the source address |
1182 | 1234 |
1183 NS_LOG_INFO ("The nexthop address " << nextHop << " the source " << source <<
"the destination " << destination); | 1235 NS_LOG_INFO ("The nexthop address " << nextHop << " the source " << source <<
" the destination " << destination); |
1184 | 1236 |
1185 if (m_sendBuffer.Find (destination)) | 1237 if (m_sendBuffer.Find (destination)) |
1186 { | 1238 { |
1187 SendBuffEntry entry; | 1239 SendBuffEntry entry; |
1188 if (m_sendBuffer.Dequeue (destination, entry)) | 1240 if (m_sendBuffer.Dequeue (destination, entry)) |
1189 { | 1241 { |
1190 Ptr<Packet> packet = entry.GetPacket ()->Copy (); | 1242 Ptr<Packet> packet = entry.GetPacket ()->Copy (); |
1191 NS_LOG_DEBUG ("The queued packet size " << packet->GetSize ()); | 1243 NS_LOG_DEBUG ("The queued packet size " << packet->GetSize ()); |
1192 | 1244 |
1193 DsrRoutingHeader dsrRoutingHeader; | 1245 DsrRoutingHeader dsrRoutingHeader; |
(...skipping 26 matching lines...) Expand all Loading... |
1220 newUnreach.SetErrorType (1); | 1272 newUnreach.SetErrorType (1); |
1221 newUnreach.SetErrorSrc (rerr.GetErrorSrc ()); | 1273 newUnreach.SetErrorSrc (rerr.GetErrorSrc ()); |
1222 newUnreach.SetUnreachNode (rerr.GetUnreachNode ()); | 1274 newUnreach.SetUnreachNode (rerr.GetUnreachNode ()); |
1223 newUnreach.SetErrorDst (rerr.GetErrorDst ()); | 1275 newUnreach.SetErrorDst (rerr.GetErrorDst ()); |
1224 newUnreach.SetSalvage (rerr.GetSalvage ()); // Set the v
alue about whether to salvage a packet or not | 1276 newUnreach.SetSalvage (rerr.GetSalvage ()); // Set the v
alue about whether to salvage a packet or not |
1225 | 1277 |
1226 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddres
s (); | 1278 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddres
s (); |
1227 DsrRoutingHeader newRoutingHeader; | 1279 DsrRoutingHeader newRoutingHeader; |
1228 newRoutingHeader.SetNextHeader (protocol); | 1280 newRoutingHeader.SetNextHeader (protocol); |
1229 newRoutingHeader.SetMessageType (1); | 1281 newRoutingHeader.SetMessageType (1); |
1230 newRoutingHeader.SetSourceId (255); | 1282 newRoutingHeader.SetSourceId (GetIDfromIP (rerr.GetErrorSrc ()
)); |
1231 newRoutingHeader.SetDestId (255); | 1283 newRoutingHeader.SetDestId (GetIDfromIP (rerr.GetErrorDst ()))
; |
1232 newRoutingHeader.SetPayloadLength (length + 4); | 1284 newRoutingHeader.SetPayloadLength (length + 4); |
1233 newRoutingHeader.AddDsrOption (newUnreach); | 1285 newRoutingHeader.AddDsrOption (newUnreach); |
1234 newRoutingHeader.AddDsrOption (sourceRoute); | 1286 newRoutingHeader.AddDsrOption (sourceRoute); |
1235 | 1287 |
1236 SetRoute (nextHop, m_mainAddress); | 1288 SetRoute (nextHop, m_mainAddress); |
1237 Ptr<Packet> newPacket = Create<Packet> (); | 1289 Ptr<Packet> newPacket = Create<Packet> (); |
1238 newPacket->AddHeader (newRoutingHeader); // Add the exte
nsion header with rerr and sourceRoute attached to it | 1290 newPacket->AddHeader (newRoutingHeader); // Add the exte
nsion header with rerr and sourceRoute attached to it |
1239 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceFor
Address (m_mainAddress)); | 1291 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceFor
Address (m_mainAddress)); |
1240 m_ipv4Route->SetOutputDevice (dev); | 1292 m_ipv4Route->SetOutputDevice (dev); |
1241 m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNu
mber (), m_ipv4Route); | 1293 m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNu
mber (), m_ipv4Route); |
1242 } | 1294 } |
1243 } | 1295 } |
1244 | |
1245 else | 1296 else |
1246 { | 1297 { |
1247 Ptr<Packet> p = packet->Copy (); // get a copy of the packet | 1298 Ptr<Packet> p = packet->Copy (); // get a copy of the packet |
1248 uint8_t segsLeft = sourceRoute.GetSegmentsLeft (); | |
1249 // Set the source route option | 1299 // Set the source route option |
1250 dsrRoutingHeader.SetNextHeader (protocol); | 1300 dsrRoutingHeader.SetNextHeader (protocol); |
1251 dsrRoutingHeader.SetMessageType (2); | 1301 dsrRoutingHeader.SetMessageType (2); |
1252 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); | 1302 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
1253 dsrRoutingHeader.SetDestId (GetIDfromIP (destination)); | 1303 dsrRoutingHeader.SetDestId (GetIDfromIP (destination)); |
1254 | 1304 |
1255 DsrOptionAckReqHeader ackReq; | 1305 DsrOptionAckReqHeader ackReq; |
1256 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); | 1306 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); |
1257 ackReq.SetId (m_ackId); | 1307 ackReq.SetAckId (m_ackId); |
1258 | 1308 |
1259 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); | 1309 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); |
1260 NS_LOG_DEBUG ("the length of source route header " << (uint32_t)(s
ourceRoute.GetLength ())); | |
1261 NS_LOG_DEBUG ("the length of ack request header " << (uint32_t)(ac
kReq.GetLength ())); | |
1262 | |
1263 dsrRoutingHeader.SetPayloadLength (length + 4); | 1310 dsrRoutingHeader.SetPayloadLength (length + 4); |
1264 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1311 dsrRoutingHeader.AddDsrOption (sourceRoute); |
1265 dsrRoutingHeader.AddDsrOption (ackReq); | 1312 dsrRoutingHeader.AddDsrOption (ackReq); |
1266 uint16_t routeSize = sourceRoute.GetNodeListSize (); // Get
the route length of in the source route header | 1313 |
1267 | 1314 // PrintVector (nodeList); |
1268 PrintVector (nodeList); | |
1269 p->AddHeader (dsrRoutingHeader); | 1315 p->AddHeader (dsrRoutingHeader); |
1270 Ptr<const Packet> mtP = p->Copy (); | 1316 Ptr<const Packet> mtP = p->Copy (); |
1271 Ipv4Header const ipv4Header; | |
1272 // Put the data packet in the maintenance queue for data packet re
transmission | 1317 // Put the data packet in the maintenance queue for data packet re
transmission |
1273 MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Header=*/ ipv4H
eader, /*ourAddress=*/ m_mainAddress, /*nextHop=*/ nextHop, | 1318 MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_mai
nAddress, /*nextHop=*/ nextHop, |
1274 /*source=*/ source, /*dest
ination=*/ destination, /*ackId=*/ m_ackId, /*SegsLeft=*/ segsLeft, | 1319 /*source=*/ source, /*dest
ination=*/ destination, /*ackId=*/ m_ackId, |
1275 /*Salvage=*/ 0, /*RouteSiz
e=*/ routeSize, /*expire time=*/ m_maxMaintainTime); | 1320 /*SegsLeft=*/nodeList.size
() - 2, /*expire time=*/ m_maxMaintainTime); |
1276 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueu
e the packet the the maintenance buffer | 1321 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueu
e the packet the the maintenance buffer |
1277 | 1322 |
1278 if (result) | 1323 if (result) |
1279 { | 1324 { |
1280 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceFor
Address (m_mainAddress)); | 1325 // Send out data packet |
1281 route->SetOutputDevice (dev); | 1326 NS_LOG_DEBUG ("Send out packet with ack id " << m_ackId); |
1282 m_downTarget (p, m_mainAddress, nextHop, GetProtocolNumber (),
route); | 1327 // Schedule the packet retry timer |
1283 PacketKey packetKey; | 1328 PacketKey packetKey; |
1284 packetKey.m_ackId = newEntry.GetAckId (); | 1329 packetKey.m_ackId = newEntry.GetAckId (); |
1285 packetKey.m_ourAdd = newEntry.GetOurAdd (); | 1330 packetKey.m_ourAdd = newEntry.GetOurAdd (); |
1286 packetKey.m_nextHop = newEntry.GetNextHop (); | 1331 packetKey.m_nextHop = newEntry.GetNextHop (); |
1287 packetKey.m_source = newEntry.GetSrc (); | 1332 packetKey.m_source = newEntry.GetSrc (); |
1288 packetKey.m_destination = newEntry.GetDst (); | 1333 packetKey.m_destination = newEntry.GetDst (); |
1289 packetKey.m_segsLeft = newEntry.GetSegsLeft (); | 1334 packetKey.m_segsLeft = newEntry.GetSegsLeft (); |
1290 packetKey.m_id = newEntry.GetId (); | 1335 PacketKey networkKey = packetKey; |
1291 packetKey.m_fragmentOffset = newEntry.GetFragmentOffset (); | 1336 networkKey.m_segsLeft = 0; |
1292 SchedulePacketRetry (newEntry, packetKey, protocol, route); | 1337 m_addressForwardCnt[networkKey] = 0; |
| 1338 SchedulePacketRetry (newEntry, packetKey, protocol); |
1293 } | 1339 } |
1294 } | 1340 } |
1295 | 1341 |
1296 if (m_sendBuffer.GetSize () != 0 && m_sendBuffer.Find (destination)) | 1342 if (m_sendBuffer.GetSize () != 0 && m_sendBuffer.Find (destination)) |
1297 { | 1343 { |
1298 NS_LOG_DEBUG ("Schedule sending the next packet in send buffer"); | 1344 NS_LOG_DEBUG ("Schedule sending the next packet in send buffer"); |
1299 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (
0,100)), | 1345 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (
0,100)), |
1300 &DsrRouting::SendPacket,this,sourceRoute,next
Hop,protocol,route); | 1346 &DsrRouting::SendPacket,this,sourceRoute,next
Hop,protocol); |
1301 } | 1347 } |
1302 } | 1348 } |
1303 else | 1349 else |
1304 { | 1350 { |
1305 NS_LOG_DEBUG ("All queued packets are outdated for the destination"); | 1351 NS_LOG_DEBUG ("All queued packets are out-dated for the destination"); |
1306 } | 1352 } |
1307 } | 1353 } |
1308 else | 1354 else |
1309 { | 1355 { |
1310 NS_LOG_DEBUG ("Packet not found in send buffer"); | 1356 NS_LOG_DEBUG ("Packet not found in send buffer"); |
1311 } | 1357 } |
| 1358 } |
| 1359 |
| 1360 bool |
| 1361 DsrRouting::FindSamePackets (Ptr<Packet> packet, Ipv4Header const& ipv4Header, I
pv4Address source, Ipv4Address destination, |
| 1362 uint8_t segsLeft) |
| 1363 { |
| 1364 NS_LOG_FUNCTION (this << packet << ipv4Header << source << destination << (uin
t32_t)segsLeft); |
| 1365 /* |
| 1366 * Get the source and destination address from ipv4 header |
| 1367 */ |
| 1368 Ipv4Address ourAdd = ipv4Header.GetSource (); |
| 1369 Ipv4Address nextHop = ipv4Header.GetDestination (); |
| 1370 |
| 1371 Ptr<Packet> p = packet->Copy (); |
| 1372 MaintainBuffEntry newEntry (/*Packet=*/ p, /*Ipv4Address=*/ ourAdd, /*nextHop=
*/ nextHop, |
| 1373 /*source=*/ source, /*destination=*/ d
estination, /*ackId=*/ 0, |
| 1374 /*SegsLeft=*/segsLeft, /*expire time=*
/ m_maxMaintainTime); |
| 1375 // Temporarily disable passive acknowledgment |
| 1376 // CancelPassivePacketTimer (newEntry); |
| 1377 return true; |
1312 } | 1378 } |
1313 | 1379 |
1314 void | 1380 void |
1315 DsrRouting::CallCancelPacketTimer (uint16_t ackId, Ipv4Header const& ipv4Header,
Ipv4Address realSrc, Ipv4Address realDst) | 1381 DsrRouting::CallCancelPacketTimer (uint16_t ackId, Ipv4Header const& ipv4Header,
Ipv4Address realSrc, Ipv4Address realDst) |
1316 { | 1382 { |
1317 NS_LOG_FUNCTION (this << (uint32_t)ackId << ipv4Header << realSrc << realDst); | 1383 NS_LOG_FUNCTION (this << (uint32_t)ackId << ipv4Header << realSrc << realDst); |
1318 Ipv4Address sender = ipv4Header.GetDestination (); | 1384 Ipv4Address sender = ipv4Header.GetDestination (); |
1319 Ipv4Address receiver = ipv4Header.GetSource (); | 1385 Ipv4Address receiver = ipv4Header.GetSource (); |
1320 | 1386 /* |
1321 // Put the data packet in the maintenance queue for data packet retransmission | 1387 * Create a packet to fill maintenance buffer, not used to compare |
| 1388 * The reason is ack header doesn't have the original packet copy |
| 1389 */ |
1322 Ptr<Packet> mainP = Create<Packet> (); | 1390 Ptr<Packet> mainP = Create<Packet> (); |
1323 MaintainBuffEntry newEntry (/*Packet=*/ mainP, /*Ipv4Header=*/ ipv4Header, /*o
urAddress=*/ sender, /*nextHop=*/ receiver, | 1391 MaintainBuffEntry newEntry (/*Packet=*/ mainP, /*ourAddress=*/ sender, /*nextH
op=*/ receiver, |
1324 /*source=*/ realSrc, /*destination=*/
realDst, /*ackId=*/ ackId, /*SegsLeft=*/ 0, | 1392 /*source=*/ realSrc, /*destination=*/
realDst, /*ackId=*/ ackId, |
1325 /*Salvage=*/ 0, /*RouteSize=*/ 0, /*ex
pire time=*/ Simulator::Now ()); | 1393 /*SegsLeft=*/0, /*expire time=*/ Simul
ator::Now ()); |
1326 CancelPacketTimer (newEntry); | 1394 CancelNetworkPacketTimer (newEntry); |
1327 } | 1395 } |
1328 | 1396 |
1329 void | 1397 void |
1330 DsrRouting::CancelPacketTimer (MaintainBuffEntry & mb) | 1398 DsrRouting::CancelNetworkPacketTimer (MaintainBuffEntry & mb) |
1331 { | 1399 { |
1332 NS_LOG_FUNCTION (this); | 1400 NS_LOG_FUNCTION (this); |
1333 PacketKey packetKey; | 1401 PacketKey packetKey; |
1334 packetKey.m_ackId = mb.GetAckId (); | 1402 packetKey.m_ackId = mb.GetAckId (); |
1335 packetKey.m_ourAdd = mb.GetOurAdd (); | 1403 packetKey.m_ourAdd = mb.GetOurAdd (); |
1336 packetKey.m_nextHop = mb.GetNextHop (); | 1404 packetKey.m_nextHop = mb.GetNextHop (); |
1337 packetKey.m_source = mb.GetSrc (); | 1405 packetKey.m_source = mb.GetSrc (); |
1338 packetKey.m_destination = mb.GetDst (); | 1406 packetKey.m_destination = mb.GetDst (); |
1339 packetKey.m_segsLeft = mb.GetSegsLeft (); | 1407 packetKey.m_segsLeft = 0; |
1340 packetKey.m_id = 0; | |
1341 packetKey.m_fragmentOffset = 0; | |
1342 NS_LOG_INFO ("ackId " << mb.GetAckId () << " ourAdd " << mb.GetOurAdd () << "
nextHop " << mb.GetNextHop () | |
1343 << " source " << mb.GetSrc () << " destination " | |
1344 << mb.GetDst () << " segsLeft " << (uint32_t)mb.GetSegsL
eft ()); | |
1345 /* | 1408 /* |
1346 * Schedule the packet retry | 1409 * Here we have found the entry for send retries, so we get the value and incr
ease it by one |
1347 * Push back the nextHop, source, dst address | |
1348 */ | 1410 */ |
1349 m_addressForwardTimer[packetKey].Cancel (); | |
1350 m_addressForwardTimer[packetKey].Remove (); | |
1351 m_addressForwardTimer.erase (packetKey); | |
1352 /* | |
1353 * cancel passive acknowledgment timer | |
1354 */ | |
1355 PacketKey passiveKey = packetKey; | |
1356 passiveKey.m_ackId = 0; | |
1357 passiveKey.m_id = mb.GetId (); | |
1358 passiveKey.m_fragmentOffset = mb.GetFragmentOffset (); | |
1359 m_passiveAckTimer[passiveKey].Cancel (); | |
1360 m_passiveAckTimer[passiveKey].Remove (); | |
1361 if (m_passiveAckTimer[passiveKey].IsRunning ()) | |
1362 { | |
1363 NS_LOG_DEBUG ("Timer not canceled"); | |
1364 } | |
1365 m_passiveAckTimer.erase (passiveKey); | |
1366 // 0 the forward count entry | |
1367 m_addressForwardCnt[packetKey] = 0; | 1411 m_addressForwardCnt[packetKey] = 0; |
1368 m_addressForwardCnt.erase (packetKey); | 1412 m_addressForwardCnt.erase (packetKey); |
| 1413 |
| 1414 NS_LOG_INFO ("ackId " << mb.GetAckId () << " ourAdd " << mb.GetOurAdd () << "
nextHop " << mb.GetNextHop () |
| 1415 << " source " << mb.GetSrc () << " destination " << mb.G
etDst () |
| 1416 << " segsLeft " << (uint32_t)mb.GetSegsLeft () |
| 1417 ); |
| 1418 // Find the network acknowledgment timer |
| 1419 std::map<PacketKey, Timer>::const_iterator i = |
| 1420 m_addressForwardTimer.find (packetKey); |
| 1421 if (i == m_addressForwardTimer.end ()) |
| 1422 { |
| 1423 NS_LOG_DEBUG ("did not find the packet timer"); |
| 1424 } |
| 1425 else |
| 1426 { |
| 1427 NS_LOG_DEBUG ("did find the packet timer"); |
| 1428 /* |
| 1429 * Schedule the packet retry |
| 1430 * Push back the nextHop, source, destination address |
| 1431 */ |
| 1432 m_addressForwardTimer[packetKey].Cancel (); |
| 1433 m_addressForwardTimer[packetKey].Remove (); |
| 1434 if (m_addressForwardTimer[packetKey].IsRunning ()) |
| 1435 { |
| 1436 NS_LOG_DEBUG ("Timer not canceled"); |
| 1437 } |
| 1438 m_addressForwardTimer.erase (packetKey); |
| 1439 } |
| 1440 // Erase the maintenance entry |
| 1441 if (m_maintainBuffer.AllEqual (mb)) |
| 1442 { |
| 1443 NS_LOG_DEBUG ("Remove same maintenance buffer entry based on network ack
nowledgment"); |
| 1444 } |
| 1445 } |
| 1446 |
| 1447 void |
| 1448 DsrRouting::CancelPassivePacketTimer (MaintainBuffEntry & mb) |
| 1449 { |
| 1450 NS_LOG_FUNCTION (this); |
| 1451 PacketKey passiveKey; |
| 1452 passiveKey.m_ackId = 0; |
| 1453 passiveKey.m_ourAdd = mb.GetOurAdd (); |
| 1454 passiveKey.m_nextHop = mb.GetNextHop (); |
| 1455 passiveKey.m_source = mb.GetSrc (); |
| 1456 passiveKey.m_destination = mb.GetDst (); |
| 1457 passiveKey.m_segsLeft = mb.GetSegsLeft (); |
| 1458 |
| 1459 m_addressForwardCnt[passiveKey] = 0; |
| 1460 m_addressForwardCnt.erase (passiveKey); |
| 1461 |
| 1462 // Find the passive acknowledgment timer |
| 1463 std::map<PacketKey, Timer>::const_iterator j = |
| 1464 m_passiveAckTimer.find (passiveKey); |
| 1465 if (j == m_passiveAckTimer.end ()) |
| 1466 { |
| 1467 NS_LOG_DEBUG ("did not find the passive timer"); |
| 1468 } |
| 1469 else |
| 1470 { |
| 1471 NS_LOG_DEBUG ("find the passive timer"); |
| 1472 /* |
| 1473 * Cancel passive acknowledgment timer |
| 1474 */ |
| 1475 m_passiveAckTimer[passiveKey].Cancel (); |
| 1476 m_passiveAckTimer[passiveKey].Remove (); |
| 1477 if (m_passiveAckTimer[passiveKey].IsRunning ()) |
| 1478 { |
| 1479 NS_LOG_DEBUG ("Timer not canceled"); |
| 1480 } |
| 1481 m_passiveAckTimer.erase (passiveKey); |
| 1482 } |
1369 // Erase the maintenance entry | 1483 // Erase the maintenance entry |
1370 if (m_maintainBuffer.AllEqual (mb)) | 1484 if (m_maintainBuffer.PromiscEqual (mb)) |
1371 { | 1485 { |
1372 NS_LOG_DEBUG ("Remove same maintenance buffer entry"); | 1486 NS_LOG_DEBUG ("Remove same maintenance buffer entry based on passive ackno
wledgment"); |
1373 m_maintainBuffer.EraseEntry (mb); | |
1374 } | 1487 } |
1375 } | 1488 } |
1376 | 1489 |
1377 void | 1490 void |
1378 DsrRouting::CancelPacketTimerNextHop (Ipv4Address nextHop, uint8_t protocol) | 1491 DsrRouting::CancelPacketTimerNextHop (Ipv4Address nextHop, uint8_t protocol) |
1379 { | 1492 { |
1380 NS_LOG_FUNCTION (this << nextHop << (uint32_t)protocol); | 1493 NS_LOG_FUNCTION (this << nextHop << (uint32_t)protocol); |
1381 MaintainBuffEntry entry; | 1494 MaintainBuffEntry entry; |
1382 if (m_maintainBuffer.Dequeue (nextHop, entry)) | 1495 if (m_maintainBuffer.Dequeue (nextHop, entry)) |
1383 { | 1496 { |
1384 Ptr<const Packet> packet = entry.GetPacket ()->Copy (); | 1497 Ptr<const Packet> packet = entry.GetPacket ()->Copy (); |
1385 Ipv4Address source = entry.GetSrc (); | 1498 Ipv4Address source = entry.GetSrc (); |
1386 Ipv4Address destination = entry.GetDst (); | 1499 Ipv4Address destination = entry.GetDst (); |
1387 uint8_t salvage = entry.GetSalvage (); | |
1388 /* | 1500 /* |
1389 * Cancel the packet timer and then salvage the data packet | 1501 * Cancel the packet timer and then salvage the data packet |
1390 */ | 1502 */ |
1391 CancelPacketTimer (entry); | 1503 CancelNetworkPacketTimer (entry); |
1392 SalvagePacket (packet, source, destination, salvage, protocol); | 1504 SalvagePacket (packet, source, destination, protocol); |
1393 | 1505 |
1394 if (m_maintainBuffer.GetSize () && m_maintainBuffer.Find (nextHop)) | 1506 if (m_maintainBuffer.GetSize () && m_maintainBuffer.Find (nextHop)) |
1395 { | 1507 { |
1396 NS_LOG_DEBUG ("Cancel the packet timer for next maintenance entry"); | 1508 NS_LOG_DEBUG ("Cancel the packet timer for next maintenance entry"); |
1397 CancelPacketTimerNextHop (nextHop, protocol); | 1509 |
| 1510 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,10
0)), |
| 1511 &DsrRouting::CancelPacketTimerNextHop,this,nextHo
p,protocol); |
1398 } | 1512 } |
1399 } | 1513 } |
1400 else | 1514 else |
1401 { | 1515 { |
1402 NS_LOG_DEBUG ("Maintenance buffer entry not found"); | 1516 NS_LOG_DEBUG ("Maintenance buffer entry not found"); |
1403 } | 1517 } |
1404 } | 1518 } |
1405 | 1519 |
1406 void | 1520 void |
1407 DsrRouting::SalvagePacket (Ptr<const Packet> packet, Ipv4Address source, Ipv4Add
ress dst, uint8_t salvage, uint8_t protocol) | 1521 DsrRouting::SalvagePacket (Ptr<const Packet> packet, Ipv4Address source, Ipv4Add
ress dst, uint8_t protocol) |
1408 { | 1522 { |
1409 NS_LOG_FUNCTION (this << packet << source << dst << (uint32_t)salvage << (uint
32_t)protocol); | 1523 NS_LOG_FUNCTION (this << packet << source << dst << (uint32_t)protocol); |
1410 /* | 1524 /* |
1411 * Look in the route cache for other routes for this destination | 1525 * Look in the route cache for other routes for this destination |
1412 */ | 1526 */ |
1413 RouteCacheEntry toDst; | 1527 RouteCacheEntry toDst; |
1414 Ptr<Packet> salP = packet->Copy (); | 1528 // Create two copies of packet |
| 1529 Ptr<Packet> p = packet->Copy (); |
| 1530 Ptr<Packet> newPacket = packet->Copy (); |
| 1531 // Remove the routing header in a whole to get a clean packet |
| 1532 DsrRoutingHeader dsrRoutingHeader; |
| 1533 p->RemoveHeader (dsrRoutingHeader); |
| 1534 // Remove offset of dsr routing header |
| 1535 uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); |
| 1536 newPacket->RemoveAtStart (offset); |
| 1537 |
| 1538 // Get the number of routers' address field |
| 1539 uint8_t buf[2]; |
| 1540 newPacket->CopyData (buf, sizeof(buf)); |
| 1541 uint8_t numberAddress = (buf[1] - 2) / 4; |
| 1542 |
| 1543 DsrOptionSRHeader sourceRoute; |
| 1544 sourceRoute.SetNumberAddress (numberAddress); |
| 1545 newPacket->RemoveHeader (sourceRoute); |
| 1546 uint8_t salvage = sourceRoute.GetSalvage (); |
| 1547 |
| 1548 NS_LOG_DEBUG ("The salvage value get from remove headers " << (uint32_t)salvag
e); |
| 1549 |
1415 bool findRoute = m_routeCache->LookupRoute (dst, toDst); | 1550 bool findRoute = m_routeCache->LookupRoute (dst, toDst); |
1416 if (findRoute && (salvage < m_maxSalvageCount)) | 1551 if (findRoute && (salvage < m_maxSalvageCount)) |
1417 { | 1552 { |
1418 NS_LOG_DEBUG ("We have found a route for the packet"); | 1553 NS_LOG_DEBUG ("We have found a route for the packet"); |
1419 DsrRoutingHeader dsrRoutingHeader; | 1554 DsrRoutingHeader newDsrRoutingHeader; |
1420 dsrRoutingHeader.SetNextHeader (protocol); | 1555 newDsrRoutingHeader.SetNextHeader (protocol); |
1421 dsrRoutingHeader.SetMessageType (2); | 1556 newDsrRoutingHeader.SetMessageType (2); |
1422 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); | 1557 newDsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
1423 dsrRoutingHeader.SetDestId (GetIDfromIP (dst)); | 1558 newDsrRoutingHeader.SetDestId (GetIDfromIP (dst)); |
1424 | 1559 |
1425 DsrOptionSRHeader sourceRoute; | |
1426 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the rou
te from the route entry we found | 1560 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the rou
te from the route entry we found |
1427 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); // Get
the next hop address for the route | 1561 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); // Get
the next hop address for the route |
1428 if (nextHop == "0.0.0.0") | 1562 if (nextHop == "0.0.0.0") |
1429 { | 1563 { |
1430 PacketNewRoute (salP, source, dst, protocol); | 1564 PacketNewRoute (p, source, dst, protocol); |
1431 return; | 1565 return; |
1432 } | 1566 } |
1433 // Increase the salvage count by 1 | 1567 // Increase the salvage count by 1 |
1434 salvage++; | 1568 salvage++; |
| 1569 DsrOptionSRHeader sourceRoute; |
1435 sourceRoute.SetSalvage (salvage); | 1570 sourceRoute.SetSalvage (salvage); |
1436 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the
source route header of the packet | 1571 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the
source route header of the packet |
1437 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segmentsL
eft field will indicate the hops to go | 1572 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segmentsL
eft field will indicate the hops to go |
1438 | |
1439 DsrOptionAckReqHeader ackReq; | 1573 DsrOptionAckReqHeader ackReq; |
1440 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); | 1574 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); |
1441 ackReq.SetId (m_ackId); | 1575 ackReq.SetAckId (m_ackId); |
1442 | 1576 |
1443 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); | 1577 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); |
1444 NS_LOG_INFO ("length of source route header " << (uint32_t)(sourceRoute.Ge
tLength ()) | 1578 NS_LOG_INFO ("length of source route header " << (uint32_t)(sourceRoute.Ge
tLength ()) |
1445 << " length of ack request h
eader " << (uint32_t)(ackReq.GetLength ())); | 1579 << " length of ack request h
eader " << (uint32_t)(ackReq.GetLength ())); |
1446 | 1580 newDsrRoutingHeader.SetPayloadLength (length + 4); |
1447 dsrRoutingHeader.SetPayloadLength (length + 4); | 1581 newDsrRoutingHeader.AddDsrOption (sourceRoute); |
1448 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1582 newDsrRoutingHeader.AddDsrOption (ackReq); |
1449 dsrRoutingHeader.AddDsrOption (ackReq); | 1583 p->AddHeader (newDsrRoutingHeader); |
1450 salP->AddHeader (dsrRoutingHeader); | |
1451 | 1584 |
1452 SetRoute (nextHop, m_mainAddress); | 1585 SetRoute (nextHop, m_mainAddress); |
1453 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_m
ainAddress)); | 1586 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_m
ainAddress)); |
1454 m_ipv4Route->SetOutputDevice (dev); | 1587 m_ipv4Route->SetOutputDevice (dev); |
1455 m_downTarget (salP, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Ro
ute); | 1588 // Send out the data packet |
| 1589 m_downTarget (p, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route
); |
1456 /* | 1590 /* |
1457 * Mark the next hop address in blacklist | 1591 * Mark the next hop address in blacklist |
1458 */ | 1592 */ |
1459 NS_LOG_DEBUG ("Save the next hop node in blacklist"); | 1593 NS_LOG_DEBUG ("Save the next hop node in blacklist"); |
1460 m_rreqTable->MarkLinkAsUnidirectional (nextHop, m_blacklistTimeout); | 1594 m_rreqTable->MarkLinkAsUnidirectional (nextHop, m_blacklistTimeout); |
1461 } | 1595 } |
| 1596 else |
| 1597 { |
| 1598 NS_LOG_DEBUG ("Will not salvage this packet, silently drop"); |
| 1599 } |
1462 } | 1600 } |
1463 | 1601 |
1464 void | 1602 void |
1465 DsrRouting::SchedulePacketRetry (MaintainBuffEntry & mb, | 1603 DsrRouting::SchedulePacketRetry (MaintainBuffEntry & mb, |
1466 PacketKey const & packetKey, | 1604 PacketKey const & packetKey, |
1467 uint8_t protocol, | 1605 uint8_t protocol) |
1468 Ptr<Ipv4Route> route) | 1606 { |
1469 { | 1607 NS_LOG_FUNCTION (this << (uint32_t)protocol); |
1470 NS_LOG_FUNCTION (this << (uint32_t)protocol << route); | |
1471 Ipv4Address nextHop = mb.GetNextHop (); | 1608 Ipv4Address nextHop = mb.GetNextHop (); |
1472 Ipv4Address source = mb.GetSrc (); | 1609 Ipv4Address source = mb.GetSrc (); |
1473 Ipv4Address dst = mb.GetDst (); | 1610 Ipv4Address dst = mb.GetDst (); |
1474 bool isPassive = mb.GetPassive (); | 1611 bool isPassive = mb.GetPassive (); |
| 1612 // Temporarily disable passive acknowledgment option |
| 1613 isPassive = false; |
| 1614 NS_LOG_DEBUG ("Sending passive packet retry or network one " << isPassive); |
| 1615 |
| 1616 // Make two copies of the packet key |
| 1617 PacketKey networkKey = packetKey; |
| 1618 PacketKey passiveKey = packetKey; |
| 1619 |
1475 if (isPassive && nextHop != dst) | 1620 if (isPassive && nextHop != dst) |
1476 { | 1621 { |
1477 PacketKey passiveKey = packetKey; | 1622 // There is no ack id for passive key, so 0 it |
1478 passiveKey.m_ackId = 0; | 1623 passiveKey.m_ackId = 0; |
| 1624 if (m_addressForwardTimer.find (passiveKey) == m_addressForwardTimer.end (
)) |
| 1625 { |
| 1626 Timer timer (Timer::CANCEL_ON_DESTROY); |
| 1627 m_addressForwardTimer[passiveKey] = timer; |
| 1628 } |
| 1629 m_sendRetries++; |
| 1630 // decrease the passive acknowledgment count |
| 1631 m_tryPassiveAcks = (m_tryPassiveAcks - 1); |
| 1632 if (!m_tryPassiveAcks) |
| 1633 { |
| 1634 NS_LOG_DEBUG ("Passive acknowledgment is over"); |
| 1635 isPassive = false; |
| 1636 } |
1479 NS_LOG_DEBUG ("The passive acknowledgment option for data packet"); | 1637 NS_LOG_DEBUG ("The passive acknowledgment option for data packet"); |
1480 m_passiveAckTimer[passiveKey].SetFunction (&DsrRouting::PacketScheduleTime
rExpire, this); | 1638 m_addressForwardTimer[passiveKey].SetFunction (&DsrRouting::PacketSchedule
TimerExpire, this); |
1481 m_passiveAckTimer[passiveKey].Remove (); | 1639 m_addressForwardTimer[passiveKey].Remove (); |
1482 m_passiveAckTimer[passiveKey].SetArguments (mb, passiveKey, protocol, isPa
ssive); | 1640 m_addressForwardTimer[passiveKey].SetArguments (mb, passiveKey, protocol,
isPassive); |
1483 m_passiveAckTimer[passiveKey].Schedule (m_passiveAckTimeout); | 1641 // forward count |
1484 isPassive = false; | 1642 m_addressForwardCnt[passiveKey] = m_sendRetries; |
| 1643 NS_LOG_DEBUG ("The packet retries time is " << m_sendRetries); |
| 1644 m_addressForwardTimer[passiveKey].Schedule (m_passiveAckTimeout); |
1485 return; | 1645 return; |
1486 } | 1646 } |
1487 else | 1647 else |
1488 { | 1648 { |
| 1649 // There is no segments left value for network key, so 0 it |
| 1650 networkKey.m_segsLeft = 0; |
| 1651 |
| 1652 if (m_addressForwardTimer.find (networkKey) == m_addressForwardTimer.end (
)) |
| 1653 { |
| 1654 Timer timer (Timer::CANCEL_ON_DESTROY); |
| 1655 m_addressForwardTimer[networkKey] = timer; |
| 1656 } |
1489 /* | 1657 /* |
1490 * Here we have found the entry for send retries, so we get the value and
increase it by one | 1658 * Here we have found the entry for send retries, so we get the value and
increase it by one |
1491 */ | 1659 */ |
1492 m_sendRetries = m_addressForwardCnt[packetKey]; | 1660 m_sendRetries = m_addressForwardCnt[networkKey]; |
| 1661 NS_LOG_DEBUG ("The packet retry we have done " << m_sendRetries); |
1493 /* | 1662 /* |
1494 * If a data packet has been attempted SendRetries times at the maximum T
TL without | 1663 * If a data packet has been attempted SendRetries times at the maximum T
TL without |
1495 * receiving any ACK, all data packets destined for the corresponding des
tination SHOULD be | 1664 * receiving any ACK, all data packets destined for the corresponding des
tination SHOULD be |
1496 * dropped from the send buffer | 1665 * dropped from the send buffer |
| 1666 * |
| 1667 * The maxMaintRexmt also needs to decrease one for the passive ack packe
t |
1497 */ | 1668 */ |
1498 if (m_sendRetries >= m_maxMaintRexmt) | 1669 Ptr<Packet> p = mb.GetPacket ()->Copy (); |
1499 { | 1670 Ptr<Packet> dsrP = p->Copy (); |
1500 NS_LOG_LOGIC ("Packet transmissions to " << nextHop << " has been atte
mpted SendRetries times, need to send error message"); | 1671 Ptr<Packet> salP = p->Copy (); |
1501 // Here is the route error header attached | 1672 Ptr<Packet> retransP = p->Copy (); |
1502 uint8_t salvage = mb.GetSalvage (); | 1673 // The packet retries time has exceed the max maintenance retransmission t
imes |
1503 Ptr<Packet> p = mb.GetPacket ()->Copy (); | 1674 if (m_sendRetries > m_maxMaintRexmt) |
1504 Ptr<Packet> dsrP = p->Copy (); | 1675 { |
1505 | 1676 NS_LOG_LOGIC ("Packet transmissions to " << nextHop << " has been atte
mpted SendRetries times for " << networkKey.m_ackId); |
1506 DsrRoutingHeader dsrRoutingHeader; | 1677 DsrRoutingHeader dsrRoutingHeader; |
1507 dsrP->RemoveHeader (dsrRoutingHeader); // Remove the dsr head
er in whole | 1678 dsrP->RemoveHeader (dsrRoutingHeader); // Remove the dsr head
er in whole |
1508 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); | 1679 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); |
1509 p->RemoveAtStart (offset); | 1680 p->RemoveAtStart (offset); |
1510 | 1681 |
1511 // Get the number of routers' address field | 1682 // Get the number of routers' address field |
1512 uint8_t buf[2]; | 1683 uint8_t buf[2]; |
1513 p->CopyData (buf, sizeof(buf)); | 1684 p->CopyData (buf, sizeof(buf)); |
1514 uint8_t numberAddress = (buf[1] - 2) / 4; | 1685 uint8_t numberAddress = (buf[1] - 2) / 4; |
1515 NS_LOG_DEBUG ("The number of addresses " << (uint32_t)numberAddress); | 1686 NS_LOG_DEBUG ("The number of addresses " << (uint32_t)numberAddress); |
1516 DsrOptionSRHeader sourceRoute; | 1687 DsrOptionSRHeader sourceRoute; |
1517 sourceRoute.SetNumberAddress (numberAddress); | 1688 sourceRoute.SetNumberAddress (numberAddress); |
1518 p->RemoveHeader (sourceRoute); | 1689 p->RemoveHeader (sourceRoute); |
1519 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress (); | 1690 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress (); |
1520 PrintVector (nodeList); | 1691 uint8_t salvage = sourceRoute.GetSalvage (); |
1521 Ipv4Address address1 = nodeList.at (1); | 1692 Ipv4Address address1 = nodeList.front (); |
1522 NS_LOG_DEBUG ("address1 " << address1); | 1693 NS_LOG_DEBUG ("address1 " << address1); |
1523 | 1694 |
| 1695 CutRoute (m_mainAddress, nodeList); |
| 1696 NS_LOG_DEBUG ("The route vector after cut and the route source " << no
deList.front ()); |
| 1697 // PrintVector (nodeList); |
1524 // Delete the route cache entry | 1698 // Delete the route cache entry |
1525 RouteCacheEntry toDst; | 1699 RouteCacheEntry toDst; |
1526 m_routeCache->DeleteRouteEntry (dst); | |
1527 // Cancel the packet timer for maintenance buffer entry | 1700 // Cancel the packet timer for maintenance buffer entry |
1528 CancelPacketTimer (mb); | 1701 CancelNetworkPacketTimer (mb); |
1529 /* | 1702 /* |
1530 * Mark the next hop address in blacklist | 1703 * Mark the next hop address in blacklist |
1531 */ | 1704 */ |
1532 NS_LOG_DEBUG ("Save the next hop node in blacklist"); | 1705 NS_LOG_DEBUG ("Save the next hop node in blacklist"); |
1533 m_rreqTable->MarkLinkAsUnidirectional (nextHop, m_blacklistTimeout); | 1706 m_rreqTable->MarkLinkAsUnidirectional (nextHop, m_blacklistTimeout); |
1534 | 1707 // Delete all the routes including the links |
1535 m_routeCache->DeleteAllRoutesIncludeLink (m_mainAddress, nextHop); | 1708 m_routeCache->DeleteAllRoutesIncludeLink (m_mainAddress, nextHop); |
1536 if (source == m_mainAddress) | 1709 // After deleting the broken link from all routes, need to salvage the
packet right after dropping it |
| 1710 SalvagePacket (salP, source, dst, protocol); |
| 1711 /* |
| 1712 * If the salvage is not 0, use the first address in the route as the
error dst in error header |
| 1713 * otherwise use the source of packet as the error destination |
| 1714 */ |
| 1715 if (salvage) |
1537 { | 1716 { |
1538 // We are the error source | 1717 if (address1 == m_mainAddress) |
1539 DsrOptionRerrUnreachHeader rerr; | 1718 { |
1540 rerr.SetErrorType (1); | 1719 DsrOptionRerrUnreachHeader rerr; |
1541 rerr.SetErrorSrc (source); | 1720 rerr.SetErrorType (1); |
1542 rerr.SetUnreachNode (nextHop); | 1721 rerr.SetErrorSrc (address1); |
1543 rerr.SetErrorDst (nextHop); | 1722 rerr.SetUnreachNode (nextHop); |
1544 rerr.SetSalvage (mb.GetSalvage ()); // Set the value about whet
her to salvage a packet or not | 1723 rerr.SetErrorDst (address1); |
1545 SendErrorRequest (rerr, protocol); | 1724 rerr.SetSalvage (salvage); // Set the value about whethe
r to salvage a packet or not |
| 1725 SendErrorRequest (rerr, protocol); |
| 1726 } |
| 1727 else |
| 1728 { |
| 1729 SendUnreachError (nextHop, address1, salvage, protocol); |
| 1730 } |
1546 } | 1731 } |
1547 else | 1732 else |
1548 { | 1733 { |
1549 if (salvage) | 1734 if (source == m_mainAddress) |
1550 { | 1735 { |
1551 if (address1 == m_mainAddress) | 1736 DsrOptionRerrUnreachHeader rerr; |
1552 { | 1737 rerr.SetErrorType (1); |
1553 DsrOptionRerrUnreachHeader rerr; | 1738 rerr.SetErrorSrc (source); |
1554 rerr.SetErrorType (1); | 1739 rerr.SetUnreachNode (nextHop); |
1555 rerr.SetErrorSrc (source); | 1740 rerr.SetErrorDst (source); |
1556 rerr.SetUnreachNode (nextHop); | 1741 rerr.SetSalvage (salvage); // Set the value about whether
to salvage a packet or not |
1557 rerr.SetErrorDst (nextHop); | 1742 SendErrorRequest (rerr, protocol); |
1558 rerr.SetSalvage (mb.GetSalvage ()); // Set the value ab
out whether to salvage a packet or not | |
1559 SendErrorRequest (rerr, protocol); | |
1560 } | |
1561 else | |
1562 { | |
1563 SendUnreachError (nextHop, address1, salvage, protocol); | |
1564 } | |
1565 } | 1743 } |
1566 else | 1744 else |
1567 { | 1745 { |
1568 SendUnreachError (nextHop, source, salvage, protocol); | 1746 SendUnreachError (nextHop, source, salvage, protocol); |
1569 } | 1747 } |
1570 } | 1748 } |
1571 CancelPacketTimerNextHop (nextHop, protocol); | 1749 CancelPacketTimerNextHop (nextHop, protocol); |
1572 } | 1750 } |
1573 else | 1751 else |
1574 { | 1752 { |
1575 m_sendRetries++; | 1753 m_sendRetries++; |
1576 PacketKey networkKey = packetKey; | 1754 // Send out the retransmission packet |
1577 networkKey.m_id = 0; | 1755 m_ipv4Route = SetRoute (nextHop, m_mainAddress); |
1578 networkKey.m_fragmentOffset = 0; | 1756 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress
(m_mainAddress)); |
| 1757 m_ipv4Route->SetOutputDevice (dev); |
| 1758 m_downTarget (retransP, source, nextHop, GetProtocolNumber (), m_ipv4R
oute); |
| 1759 // After m_tryPassiveAcks, schedule the packet retransmission using ne
twork acknowledgment option |
1579 m_addressForwardTimer[networkKey].SetFunction (&DsrRouting::PacketSche
duleTimerExpire, this); | 1760 m_addressForwardTimer[networkKey].SetFunction (&DsrRouting::PacketSche
duleTimerExpire, this); |
1580 m_addressForwardTimer[networkKey].Remove (); | 1761 m_addressForwardTimer[networkKey].Remove (); |
1581 m_addressForwardTimer[networkKey].SetArguments (mb, networkKey, protoc
ol, isPassive); | 1762 m_addressForwardTimer[networkKey].SetArguments (mb, networkKey, protoc
ol, false); |
1582 // forward count | 1763 // forward count |
1583 m_addressForwardCnt[networkKey] = m_sendRetries; | 1764 m_addressForwardCnt[networkKey] = m_sendRetries; |
| 1765 NS_LOG_DEBUG ("The packet retries time for " << mb.GetAckId() << " is
" << m_sendRetries); |
1584 // Back-off mechanism | 1766 // Back-off mechanism |
1585 m_addressForwardTimer[networkKey].Schedule (Time (2 * m_sendRetries *
m_nodeTraversalTime)); | 1767 m_addressForwardTimer[networkKey].Schedule (Time (2 * m_sendRetries *
m_nodeTraversalTime)); |
1586 } | 1768 } |
1587 } | 1769 } |
| 1770 return; |
1588 } | 1771 } |
1589 | 1772 |
1590 void | 1773 void |
1591 DsrRouting::AddAckReqHeader (Ptr<Packet> packet, DsrOptionSRHeader const &source
Route, Ipv4Address nextHop) | 1774 DsrRouting::AddAckReqHeader (Ptr<Packet> packet, DsrOptionSRHeader const &source
Route, Ipv4Address nextHop) |
1592 { | 1775 { |
1593 NS_LOG_FUNCTION (this << packet << nextHop); | 1776 NS_LOG_FUNCTION (this << packet << nextHop); |
1594 // This packet is used to peek option type | 1777 // This packet is used to peek option type |
1595 Ptr<Packet> cleanP = packet->Copy (); | 1778 Ptr<Packet> cleanP = packet->Copy (); |
1596 | 1779 |
1597 DsrOptionAckReqHeader ackReq; | 1780 DsrOptionAckReqHeader ackReq; |
1598 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); | 1781 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); |
1599 ackReq.SetId (m_ackId); | 1782 ackReq.SetAckId (m_ackId); |
1600 | 1783 |
1601 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); | 1784 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); |
1602 DsrRoutingHeader dsrRoutingHeader; | 1785 DsrRoutingHeader dsrRoutingHeader; |
1603 dsrRoutingHeader.SetPayloadLength (length + 4); | 1786 dsrRoutingHeader.SetPayloadLength (length + 4); |
1604 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1787 dsrRoutingHeader.AddDsrOption (sourceRoute); |
1605 dsrRoutingHeader.AddDsrOption (ackReq); | 1788 dsrRoutingHeader.AddDsrOption (ackReq); |
1606 cleanP->AddHeader (dsrRoutingHeader); | 1789 cleanP->AddHeader (dsrRoutingHeader); |
1607 } | 1790 } |
1608 | 1791 |
1609 void | 1792 void |
1610 DsrRouting::PacketScheduleTimerExpire (MaintainBuffEntry & mb, | 1793 DsrRouting::PacketScheduleTimerExpire (MaintainBuffEntry & mb, |
1611 PacketKey const & pk, | 1794 PacketKey const & pk, |
1612 uint8_t protocol, | 1795 uint8_t protocol, |
1613 bool isPassive) | 1796 bool isPassive) |
1614 { | 1797 { |
1615 NS_LOG_LOGIC (this << (uint32_t)protocol << isPassive); | 1798 NS_LOG_FUNCTION (this << (uint32_t)protocol << isPassive); |
1616 Ipv4Address nextHop = mb.GetNextHop (); | 1799 Ipv4Address nextHop = mb.GetNextHop (); |
1617 Ipv4Address source = mb.GetSrc (); | 1800 Ipv4Address source = mb.GetSrc (); |
1618 Ipv4Address dst = mb.GetDst (); | 1801 Ipv4Address dst = mb.GetDst (); |
1619 Ptr<const Packet> packet = mb.GetPacket (); | 1802 Ptr<const Packet> packet = mb.GetPacket (); |
1620 SetRoute (nextHop, source); | 1803 SetRoute (nextHop, m_mainAddress); |
1621 Ptr<Packet> p = packet->Copy (); | 1804 Ptr<Packet> p = packet->Copy (); |
1622 if (isPassive) | 1805 if (isPassive) |
1623 { | 1806 { |
1624 // Cancel passive ack timer | 1807 // Cancel passive ack timer |
1625 m_passiveAckTimer[pk].Cancel (); | 1808 m_passiveAckTimer[pk].Cancel (); |
1626 m_passiveAckTimer[pk].Remove (); | 1809 m_passiveAckTimer[pk].Remove (); |
1627 if (m_passiveAckTimer[pk].IsRunning ()) | 1810 if (m_passiveAckTimer[pk].IsRunning ()) |
1628 { | 1811 { |
1629 NS_LOG_DEBUG ("Timer not canceled"); | 1812 NS_LOG_DEBUG ("Timer not canceled"); |
1630 } | 1813 } |
1631 m_passiveAckTimer.erase (pk); | 1814 m_passiveAckTimer.erase (pk); |
1632 isPassive = false; | 1815 isPassive = false; |
1633 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_m
ainAddress)); | 1816 mb.SetPassive (false); |
1634 m_ipv4Route->SetOutputDevice (dev); | 1817 SchedulePacketRetry (mb, pk, protocol); |
1635 m_downTarget (p, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route
); | |
1636 ScheduleNetworkAck (mb, pk, protocol, m_ipv4Route, isPassive); | |
1637 } | 1818 } |
1638 else | 1819 else |
1639 { | 1820 { |
1640 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_m
ainAddress)); | 1821 mb.SetPassive (false); |
1641 m_ipv4Route->SetOutputDevice (dev); | 1822 SchedulePacketRetry (mb, pk, protocol); |
1642 m_downTarget (p, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route
); | 1823 } |
1643 } | 1824 return; |
1644 } | |
1645 | |
1646 void | |
1647 DsrRouting::ScheduleNetworkAck (MaintainBuffEntry & mb, | |
1648 PacketKey const & pk, | |
1649 uint8_t protocol, | |
1650 Ptr<Ipv4Route> route, | |
1651 bool isPassive) | |
1652 { | |
1653 NS_LOG_FUNCTION (this << (uint32_t) protocol << isPassive); | |
1654 NS_LOG_DEBUG ("Schedule network acknowledgment option for data packet"); | |
1655 m_passiveAckTimer[pk].SetFunction (&DsrRouting::SchedulePacketRetry, this); | |
1656 m_passiveAckTimer[pk].Remove (); | |
1657 isPassive = false; | |
1658 mb.SetPassive (isPassive); | |
1659 m_passiveAckTimer[pk].SetArguments (mb, pk, protocol, route); | |
1660 m_passiveAckTimer[pk].Schedule (m_passiveAckTimeout); | |
1661 } | 1825 } |
1662 | 1826 |
1663 void | 1827 void |
1664 DsrRouting::ForwardPacket (Ptr<const Packet> packet, | 1828 DsrRouting::ForwardPacket (Ptr<const Packet> packet, |
1665 DsrOptionSRHeader &sourceRoute, | 1829 DsrOptionSRHeader &sourceRoute, |
1666 Ipv4Header const& ipv4Header, | 1830 Ipv4Header const& ipv4Header, |
1667 Ipv4Address source, | 1831 Ipv4Address source, |
1668 Ipv4Address nextHop, | 1832 Ipv4Address nextHop, |
1669 Ipv4Address targetAddress, | 1833 Ipv4Address targetAddress, |
1670 uint8_t routeSize, | |
1671 uint8_t protocol, | 1834 uint8_t protocol, |
1672 Ptr<Ipv4Route> route) | 1835 Ptr<Ipv4Route> route) |
1673 { | 1836 { |
1674 NS_LOG_FUNCTION (this << packet << sourceRoute << source << nextHop << (uint32
_t)protocol << route); | 1837 NS_LOG_FUNCTION (this << packet << sourceRoute << source << nextHop << targetA
ddress << (uint32_t)protocol << route); |
1675 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 1838 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
1676 | 1839 |
1677 DsrRoutingHeader dsrRoutingHeader; | 1840 DsrRoutingHeader dsrRoutingHeader; |
1678 dsrRoutingHeader.SetNextHeader (protocol); | 1841 dsrRoutingHeader.SetNextHeader (protocol); |
1679 dsrRoutingHeader.SetMessageType (2); | 1842 dsrRoutingHeader.SetMessageType (2); |
1680 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); | 1843 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
1681 dsrRoutingHeader.SetDestId (GetIDfromIP (targetAddress)); | 1844 dsrRoutingHeader.SetDestId (GetIDfromIP (targetAddress)); |
1682 | 1845 |
1683 // We get the salvage value in sourceRoute header and set it to route error he
ader if triggered error | 1846 // We get the salvage value in sourceRoute header and set it to route error he
ader if triggered error |
1684 Ptr<Packet> p = packet->Copy (); | 1847 Ptr<Packet> p = packet->Copy (); |
1685 DsrOptionAckReqHeader ackReq; | 1848 DsrOptionAckReqHeader ackReq; |
1686 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); | 1849 m_ackId = m_routeCache->CheckUniqueAckId (nextHop); |
1687 ackReq.SetId (m_ackId); | 1850 ackReq.SetAckId (m_ackId); |
1688 | 1851 |
1689 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); | 1852 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ()); |
1690 dsrRoutingHeader.SetPayloadLength (length + 4); | 1853 dsrRoutingHeader.SetPayloadLength (length + 4); |
1691 dsrRoutingHeader.AddDsrOption (sourceRoute); | 1854 dsrRoutingHeader.AddDsrOption (sourceRoute); |
1692 dsrRoutingHeader.AddDsrOption (ackReq); | 1855 dsrRoutingHeader.AddDsrOption (ackReq); |
1693 p->AddHeader (dsrRoutingHeader); | 1856 p->AddHeader (dsrRoutingHeader); |
1694 Ptr<const Packet> mtP = p->Copy (); | 1857 Ptr<const Packet> mtP = p->Copy (); |
1695 | 1858 |
1696 MaintainBuffEntry newEntry (mtP, ipv4Header, m_mainAddress, nextHop, source, t
argetAddress, m_ackId, sourceRoute.GetSegmentsLeft (), sourceRoute.GetSalvage ()
, routeSize); | 1859 MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_mainAddress, /*
nextHop=*/ nextHop, |
| 1860 /*source=*/ source, /*destination=*/ t
argetAddress, |
| 1861 /*ackId=*/ m_ackId, /*SegsLeft=*/sourc
eRoute.GetSegmentsLeft(), /*expire time=*/ m_maxMaintainTime); |
1697 bool result = m_maintainBuffer.Enqueue (newEntry); | 1862 bool result = m_maintainBuffer.Enqueue (newEntry); |
1698 | 1863 |
1699 if (result) | 1864 if (result) |
1700 { | 1865 { |
1701 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_m
ainAddress)); | |
1702 route->SetOutputDevice (dev); | |
1703 Ptr<Packet> newPacket = p->Copy (); | 1866 Ptr<Packet> newPacket = p->Copy (); |
1704 m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNumber (), rou
te); | |
1705 PacketKey packetKey; | 1867 PacketKey packetKey; |
1706 packetKey.m_ackId = newEntry.GetAckId (); | 1868 packetKey.m_ackId = newEntry.GetAckId (); |
1707 packetKey.m_ourAdd = newEntry.GetOurAdd (); | 1869 packetKey.m_ourAdd = newEntry.GetOurAdd (); |
1708 packetKey.m_nextHop = newEntry.GetNextHop (); | 1870 packetKey.m_nextHop = newEntry.GetNextHop (); |
1709 packetKey.m_source = newEntry.GetSrc (); | 1871 packetKey.m_source = newEntry.GetSrc (); |
1710 packetKey.m_destination = newEntry.GetDst (); | 1872 packetKey.m_destination = newEntry.GetDst (); |
1711 packetKey.m_segsLeft = newEntry.GetSegsLeft (); | 1873 packetKey.m_segsLeft = newEntry.GetSegsLeft (); |
1712 packetKey.m_id = newEntry.GetId (); | 1874 PacketKey networkKey = packetKey; |
1713 packetKey.m_fragmentOffset = newEntry.GetFragmentOffset (); | 1875 networkKey.m_segsLeft = 0; |
1714 SchedulePacketRetry (newEntry, packetKey, protocol, route); | 1876 m_addressForwardCnt[networkKey] = 0; |
| 1877 SchedulePacketRetry (newEntry, packetKey, protocol); |
1715 } | 1878 } |
1716 } | 1879 } |
1717 | 1880 |
1718 void | 1881 void |
1719 DsrRouting::SendInitialRequest (Ipv4Address source, | 1882 DsrRouting::SendInitialRequest (Ipv4Address source, |
1720 Ipv4Address destination, | 1883 Ipv4Address destination, |
1721 uint8_t protocol) | 1884 uint8_t protocol) |
1722 { | 1885 { |
1723 NS_LOG_FUNCTION (this << source << destination << (uint32_t)protocol); | 1886 NS_LOG_FUNCTION (this << source << destination << (uint32_t)protocol); |
1724 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 1887 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
1725 Ptr<Packet> packet = Create<Packet> (); | 1888 Ptr<Packet> packet = Create<Packet> (); |
1726 // Create an empty route ptr | 1889 // Create an empty Ipv4 route ptr |
1727 Ptr<Ipv4Route> route; | 1890 Ptr<Ipv4Route> route; |
1728 /* | 1891 /* |
1729 * Construct the route request option header | 1892 * Construct the route request option header |
1730 */ | 1893 */ |
1731 DsrRoutingHeader dsrRoutingHeader; | 1894 DsrRoutingHeader dsrRoutingHeader; |
1732 dsrRoutingHeader.SetNextHeader (protocol); | 1895 dsrRoutingHeader.SetNextHeader (protocol); |
1733 dsrRoutingHeader.SetMessageType (1); | 1896 dsrRoutingHeader.SetMessageType (1); |
1734 dsrRoutingHeader.SetSourceId (255); | 1897 dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
1735 dsrRoutingHeader.SetDestId (255); | 1898 dsrRoutingHeader.SetDestId (255); |
1736 | 1899 |
1737 DsrOptionRreqHeader rreqHeader; // has an align
ment of 4n+0 | 1900 DsrOptionRreqHeader rreqHeader; // has an align
ment of 4n+0 |
1738 rreqHeader.AddNodeAddress (m_mainAddress); // Add our own
address in the header | 1901 rreqHeader.AddNodeAddress (m_mainAddress); // Add our own
address in the header |
1739 rreqHeader.SetTarget (destination); | 1902 rreqHeader.SetTarget (destination); |
1740 m_requestId = m_rreqTable->CheckUniqueRreqId (destination); // Check the
Id cache for duplicate ones | 1903 m_requestId = m_rreqTable->CheckUniqueRreqId (destination); // Check the
Id cache for duplicate ones |
1741 rreqHeader.SetId (m_requestId); | 1904 rreqHeader.SetId (m_requestId); |
1742 | 1905 // Increment the route request count, if entry not found, the function will cr
eate a new one |
1743 // This function will increase the request count if found the entry, will crea
te the entry if not found | 1906 m_rreqTable->FindAndUpdate (destination); |
1744 m_rreqTable->IncrementRreqCnt (destination); | |
1745 | 1907 |
1746 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader to t
he dsr extension header | 1908 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader to t
he dsr extension header |
1747 uint8_t length = rreqHeader.GetLength (); | 1909 uint8_t length = rreqHeader.GetLength (); |
1748 dsrRoutingHeader.SetPayloadLength (length + 2); | 1910 dsrRoutingHeader.SetPayloadLength (length + 2); |
1749 packet->AddHeader (dsrRoutingHeader); | 1911 packet->AddHeader (dsrRoutingHeader); |
1750 | 1912 |
1751 // Schedule the route requests retry | 1913 // This function will increase the request count if found the entry, will crea
te the entry if not found |
| 1914 m_rreqTable->FindAndUpdate (destination); |
| 1915 // Schedule the route requests retry with non-propagation set true |
1752 bool nonProp = true; | 1916 bool nonProp = true; |
1753 ScheduleRreqRetry (packet, source, destination, nonProp, protocol); | 1917 ScheduleRreqRetry (packet, source, destination, nonProp, protocol); |
1754 } | 1918 } |
1755 | 1919 |
1756 void | 1920 void |
1757 DsrRouting::SendErrorRequest (DsrOptionRerrUnreachHeader &rerr, uint8_t protocol
) | 1921 DsrRouting::SendErrorRequest (DsrOptionRerrUnreachHeader &rerr, uint8_t protocol
) |
1758 { | 1922 { |
1759 NS_LOG_FUNCTION (this << (uint32_t)protocol); | 1923 NS_LOG_FUNCTION (this << (uint32_t)protocol); |
1760 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 1924 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
1761 Ptr<Packet> packet = Create<Packet> (); | 1925 Ptr<Packet> packet = Create<Packet> (); |
1762 Ipv4Address destination = rerr.GetErrorSrc (); | 1926 Ipv4Address destination = rerr.GetErrorSrc (); |
1763 Ipv4Address unreachAddress = rerr.GetUnreachNode (); | 1927 Ipv4Address unreachAddress = rerr.GetUnreachNode (); |
1764 // Create an empty route ptr | 1928 // Create an empty route ptr |
1765 Ptr<Ipv4Route> route = 0; | 1929 Ptr<Ipv4Route> route = 0; |
1766 /* | 1930 /* |
1767 * Construct the route request option header | 1931 * Construct the route request option header |
1768 */ | 1932 */ |
1769 DsrRoutingHeader dsrRoutingHeader; | 1933 DsrRoutingHeader dsrRoutingHeader; |
1770 dsrRoutingHeader.SetNextHeader (protocol); | 1934 dsrRoutingHeader.SetNextHeader (protocol); |
1771 dsrRoutingHeader.SetMessageType (1); | 1935 dsrRoutingHeader.SetMessageType (1); |
1772 dsrRoutingHeader.SetSourceId (255); | 1936 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress)); |
1773 dsrRoutingHeader.SetDestId (255); | 1937 dsrRoutingHeader.SetDestId (255); |
1774 | 1938 |
1775 if (m_mainAddress != destination) | 1939 if (m_mainAddress != destination) |
1776 { | 1940 { |
1777 /* | 1941 /* |
1778 * Send error request to the error source | 1942 * Send error request to the error source |
1779 */ | 1943 */ |
| 1944 NS_LOG_DEBUG ("Send error packet to the error source"); |
1780 Ptr<Packet> dstP = Create<Packet> (); | 1945 Ptr<Packet> dstP = Create<Packet> (); |
1781 DsrOptionRreqHeader rreqHeader; // has an a
lignment of 4n+0 | 1946 DsrOptionRreqHeader rreqHeader; // has an a
lignment of 4n+0 |
1782 rreqHeader.AddNodeAddress (m_mainAddress); // Add our
own address in the header | 1947 rreqHeader.AddNodeAddress (m_mainAddress); // Add our
own address in the header |
1783 rreqHeader.SetTarget (destination); | 1948 rreqHeader.SetTarget (destination); |
1784 m_requestId = m_rreqTable->CheckUniqueRreqId (destination); // Check
the Id cache for duplicate ones | 1949 m_requestId = m_rreqTable->CheckUniqueRreqId (destination); // Check
the Id cache for duplicate ones |
1785 rreqHeader.SetId (m_requestId); | 1950 rreqHeader.SetId (m_requestId); |
1786 // This function will increase the request count if found the entry, will
create the entry if not found | 1951 // This function will increase the request count if found the entry, will
create the entry if not found |
1787 m_rreqTable->IncrementRreqCnt (destination); | 1952 m_rreqTable->FindAndUpdate (destination); |
1788 | 1953 |
1789 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader
to the dsr extension header | 1954 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader
to the dsr extension header |
1790 dsrRoutingHeader.AddDsrOption (rerr); | 1955 dsrRoutingHeader.AddDsrOption (rerr); |
1791 uint8_t length = rreqHeader.GetLength () + rerr.GetLength (); | 1956 uint8_t length = rreqHeader.GetLength () + rerr.GetLength (); |
1792 dsrRoutingHeader.SetPayloadLength (length + 4); | 1957 dsrRoutingHeader.SetPayloadLength (length + 4); |
1793 dstP->AddHeader (dsrRoutingHeader); | 1958 dstP->AddHeader (dsrRoutingHeader); |
1794 // Schedule the route requests retry, propagate the route request message
as it contains error | 1959 // Schedule the route requests retry, propagate the route request message
as it contains error |
1795 bool nonProp = false; | 1960 bool nonProp = false; |
1796 ScheduleRreqRetry (dstP, m_mainAddress, destination, nonProp, protocol); | 1961 if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ()) &&
(m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ())) |
1797 } | 1962 { |
1798 /* | 1963 NS_LOG_DEBUG ("Only when there is no existing route request time when
this one is triggered"); |
1799 * Send error request to the unreachable node | 1964 ScheduleRreqRetry (dstP, m_mainAddress, destination, nonProp, protocol
); |
1800 */ | 1965 } |
1801 DsrOptionRreqHeader rreqHeader; // has an align
ment of 4n+0 | 1966 } |
1802 rreqHeader.AddNodeAddress (m_mainAddress); // Add our own
address in the header | 1967 else |
1803 rreqHeader.SetTarget (unreachAddress); | 1968 { |
1804 m_requestId = m_rreqTable->CheckUniqueRreqId (unreachAddress); // Check
the Id cache for duplicate ones | 1969 /* |
1805 rreqHeader.SetId (m_requestId); | 1970 * Send error request to the unreachable node |
1806 // This function will increase the request count if found the entry, will crea
te the entry if not found | 1971 */ |
1807 m_rreqTable->IncrementRreqCnt (unreachAddress); | 1972 DsrOptionRreqHeader rreqHeader; // has an a
lignment of 4n+0 |
1808 | 1973 rreqHeader.AddNodeAddress (m_mainAddress); // Add our
own address in the header |
1809 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader to t
he dsr extension header | 1974 rreqHeader.SetTarget (unreachAddress); |
1810 dsrRoutingHeader.AddDsrOption (rerr); | 1975 m_requestId = m_rreqTable->CheckUniqueRreqId (unreachAddress); // Ch
eck the Id cache for duplicate ones |
1811 uint8_t length = rreqHeader.GetLength () + rerr.GetLength (); | 1976 rreqHeader.SetId (m_requestId); |
1812 dsrRoutingHeader.SetPayloadLength (length + 4); | 1977 // This function will increase the request count if found the entry, will
create the entry if not found |
1813 packet->AddHeader (dsrRoutingHeader); | 1978 m_rreqTable->FindAndUpdate (unreachAddress); |
1814 // Schedule the route requests retry, propagate the route request message as i
t contains error | 1979 |
1815 bool nonProp = false; | 1980 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader
to the dsr extension header |
1816 ScheduleRreqRetry (packet, m_mainAddress, unreachAddress, nonProp, protocol); | 1981 dsrRoutingHeader.AddDsrOption (rerr); |
1817 } | 1982 uint8_t length = rreqHeader.GetLength () + rerr.GetLength (); |
1818 | 1983 dsrRoutingHeader.SetPayloadLength (length + 4); |
| 1984 packet->AddHeader (dsrRoutingHeader); |
| 1985 // Schedule the route requests retry, propagate the route request message
as it contains error |
| 1986 bool nonProp = false; |
| 1987 if ((m_addressReqTimer.find (unreachAddress) == m_addressReqTimer.end ())
&& (m_nonPropReqTimer.find (unreachAddress) == m_nonPropReqTimer.end ())) |
| 1988 { |
| 1989 NS_LOG_DEBUG ("Only when there is no existing route request time when
this one is triggered"); |
| 1990 ScheduleRreqRetry (packet, m_mainAddress, unreachAddress, nonProp, pro
tocol); |
| 1991 } |
| 1992 } |
| 1993 } |
1819 | 1994 |
1820 void | 1995 void |
1821 DsrRouting::CancelRreqTimer (Ipv4Address dst) | 1996 DsrRouting::CancelRreqTimer (Ipv4Address dst) |
1822 { | 1997 { |
1823 NS_LOG_FUNCTION (this << dst); | 1998 NS_LOG_FUNCTION (this << dst); |
1824 // Cancel the non propagation request timer if found | 1999 // Cancel the non propagation request timer if found |
| 2000 if (m_nonPropReqTimer.find (dst) == m_nonPropReqTimer.end ()) |
| 2001 { |
| 2002 NS_LOG_DEBUG ("Did not find the non-propagation timer"); |
| 2003 } |
| 2004 else |
| 2005 { |
| 2006 NS_LOG_DEBUG ("did find the non-propagation timer"); |
| 2007 } |
1825 m_nonPropReqTimer[dst].Cancel (); | 2008 m_nonPropReqTimer[dst].Cancel (); |
1826 m_nonPropReqTimer[dst].Remove (); | 2009 m_nonPropReqTimer[dst].Remove (); |
| 2010 |
1827 if (m_nonPropReqTimer[dst].IsRunning ()) | 2011 if (m_nonPropReqTimer[dst].IsRunning ()) |
1828 { | 2012 { |
1829 NS_LOG_DEBUG ("Timer not canceled"); | 2013 NS_LOG_DEBUG ("Timer not canceled"); |
1830 } | 2014 } |
1831 m_nonPropReqTimer.erase (dst); | 2015 m_nonPropReqTimer.erase (dst); |
1832 | 2016 |
1833 // Cancel the address request timer if found | 2017 // Cancel the address request timer if found |
| 2018 if (m_addressReqTimer.find (dst) == m_addressReqTimer.end ()) |
| 2019 { |
| 2020 NS_LOG_DEBUG ("Did not find the propagation timer"); |
| 2021 } |
| 2022 else |
| 2023 { |
| 2024 NS_LOG_DEBUG ("did find the propagation timer"); |
| 2025 } |
1834 m_addressReqTimer[dst].Cancel (); | 2026 m_addressReqTimer[dst].Cancel (); |
1835 m_addressReqTimer[dst].Remove (); | 2027 m_addressReqTimer[dst].Remove (); |
1836 if (m_addressReqTimer[dst].IsRunning ()) | 2028 if (m_addressReqTimer[dst].IsRunning ()) |
1837 { | 2029 { |
1838 NS_LOG_DEBUG ("Timer not canceled"); | 2030 NS_LOG_DEBUG ("Timer not canceled"); |
1839 } | 2031 } |
1840 m_addressReqTimer.erase (dst); | 2032 m_addressReqTimer.erase (dst); |
1841 | 2033 |
1842 // remove the route request entry from rreq table | 2034 // remove the route request entry from route request table |
1843 m_rreqTable->RemoveRreqEntry (dst); | 2035 m_rreqTable->RemoveRreqEntry (dst); |
1844 } | 2036 } |
1845 | 2037 |
1846 void | 2038 void |
1847 DsrRouting::ScheduleRreqRetry (Ptr<Packet> packet, Ipv4Address source, Ipv4Addre
ss dst, bool nonProp, uint8_t protocol) | 2039 DsrRouting::ScheduleRreqRetry (Ptr<Packet> packet, Ipv4Address source, Ipv4Addre
ss dst, bool nonProp, uint8_t protocol) |
1848 { | 2040 { |
1849 NS_LOG_FUNCTION (this << packet << source << dst << nonProp << (uint32_t)proto
col); | 2041 NS_LOG_FUNCTION (this << packet << source << dst << nonProp << (uint32_t)proto
col); |
1850 if (nonProp) | 2042 if (nonProp) |
1851 { | 2043 { |
1852 nonProp = false; | 2044 nonProp = false; |
1853 if (m_nonPropReqTimer.find (dst) == m_nonPropReqTimer.end ()) | 2045 if (m_nonPropReqTimer.find (dst) == m_nonPropReqTimer.end ()) |
1854 { | 2046 { |
1855 Timer timer (Timer::CANCEL_ON_DESTROY); | 2047 Timer timer (Timer::CANCEL_ON_DESTROY); |
1856 m_nonPropReqTimer[dst] = timer; | 2048 m_nonPropReqTimer[dst] = timer; |
1857 } | 2049 } |
1858 /* | 2050 /* |
1859 * Add the socket ip ttl tag to the packet to limit the scope of route req
uests | 2051 * Add the socket ip ttl tag to the packet to limit the scope of route req
uests |
1860 */ | 2052 */ |
1861 SocketIpTtlTag tag; | 2053 SocketIpTtlTag tag; |
1862 tag.SetTtl (0); | 2054 tag.SetTtl (0); |
1863 Ptr<Packet> nonProP = packet->Copy (); | 2055 Ptr<Packet> nonPropPacket = packet->Copy (); |
1864 nonProP->AddPacketTag (tag); | 2056 nonPropPacket->AddPacketTag (tag); |
1865 // Set the request table entry | 2057 SendRequest (nonPropPacket, source); |
1866 RreqTableEntry entry; | 2058 NS_LOG_DEBUG ("Check the route request entry3 " << source << " " << dst); |
1867 entry.m_dst = dst; | |
1868 entry.m_ttl = 0; | |
1869 entry.m_reqNo = 0; | |
1870 m_rreqTable->Update (entry); | |
1871 SendRequest (nonProP, source); | |
1872 m_nonPropReqTimer[dst].SetFunction (&DsrRouting::ScheduleRreqRetry, this); | 2059 m_nonPropReqTimer[dst].SetFunction (&DsrRouting::ScheduleRreqRetry, this); |
1873 m_nonPropReqTimer[dst].Remove (); | 2060 m_nonPropReqTimer[dst].Remove (); |
1874 m_nonPropReqTimer[dst].SetArguments (packet, source, dst, nonProp, protoco
l); | 2061 m_nonPropReqTimer[dst].SetArguments (packet, source, dst, nonProp, protoco
l); |
1875 m_nonPropReqTimer[dst].Schedule (m_nonpropRequestTimeout); | 2062 m_nonPropReqTimer[dst].Schedule (m_nonpropRequestTimeout); |
1876 } | 2063 } |
1877 else | 2064 else |
1878 { | 2065 { |
1879 // Cancel the non propagation request timer if found | 2066 // Cancel the non propagation request timer if found |
1880 m_nonPropReqTimer[dst].Cancel (); | 2067 m_nonPropReqTimer[dst].Cancel (); |
1881 m_nonPropReqTimer[dst].Remove (); | 2068 m_nonPropReqTimer[dst].Remove (); |
1882 if (m_nonPropReqTimer[dst].IsRunning ()) | 2069 if (m_nonPropReqTimer[dst].IsRunning ()) |
1883 { | 2070 { |
1884 NS_LOG_DEBUG ("Timer not canceled"); | 2071 NS_LOG_DEBUG ("Timer not canceled"); |
1885 } | 2072 } |
1886 m_nonPropReqTimer.erase (dst); | 2073 m_nonPropReqTimer.erase (dst); |
1887 /* | 2074 /* |
1888 * Add the socket ip ttl tag to the packet to limit the scope of route req
uests | 2075 * Add the socket ip ttl tag to the packet to limit the scope of route req
uests |
1889 */ | 2076 */ |
1890 SocketIpTtlTag tag; | 2077 SocketIpTtlTag tag; |
1891 tag.SetTtl (m_discoveryHopLimit); | 2078 tag.SetTtl (m_discoveryHopLimit); |
1892 packet->AddPacketTag (tag); | 2079 packet->AddPacketTag (tag); |
1893 // Set the request table entry | |
1894 RreqTableEntry entry; | |
1895 entry.m_dst = dst; | |
1896 entry.m_ttl = m_discoveryHopLimit; | |
1897 entry.m_reqNo = 0; | |
1898 m_rreqTable->Update (entry); | |
1899 if (m_addressReqTimer.find (dst) == m_addressReqTimer.end ()) | 2080 if (m_addressReqTimer.find (dst) == m_addressReqTimer.end ()) |
1900 { | 2081 { |
1901 Timer timer (Timer::CANCEL_ON_DESTROY); | 2082 Timer timer (Timer::CANCEL_ON_DESTROY); |
1902 m_addressReqTimer[dst] = timer; | 2083 m_addressReqTimer[dst] = timer; |
1903 } | 2084 } |
1904 m_rreqTable->IncrementRreqCnt (dst); | |
1905 m_addressReqTimer[dst].SetFunction (&DsrRouting::RouteRequestTimerExpire,
this); | 2085 m_addressReqTimer[dst].SetFunction (&DsrRouting::RouteRequestTimerExpire,
this); |
1906 m_addressReqTimer[dst].Remove (); | 2086 m_addressReqTimer[dst].Remove (); |
1907 m_addressReqTimer[dst].SetArguments (packet, source, dst, protocol); | 2087 m_addressReqTimer[dst].SetArguments (packet, source, dst, protocol); |
1908 Time rreqDelay = Time (2 * m_rreqTable->GetRreqCnt (dst) * m_requestPeriod
); | 2088 // Increase the request count |
| 2089 m_rreqTable->FindAndUpdate (dst); |
| 2090 // back off mechanism for sending route requests |
| 2091 Time rreqDelay = Time (pow (m_rreqTable->GetRreqCnt (dst), 2) * m_requestP
eriod); |
| 2092 NS_LOG_DEBUG ("The request count for the destination " << dst << " " << m_
rreqTable->GetRreqCnt (dst) << " with time value " << rreqDelay); |
1909 if (rreqDelay > m_maxRequestPeriod) | 2093 if (rreqDelay > m_maxRequestPeriod) |
1910 { | 2094 { |
| 2095 // use the max request period |
| 2096 NS_LOG_DEBUG ("The max request delay time " << m_maxRequestPeriod.GetS
econds()); |
1911 m_addressReqTimer[dst].Schedule (m_maxRequestPeriod); | 2097 m_addressReqTimer[dst].Schedule (m_maxRequestPeriod); |
1912 } | 2098 } |
1913 else | 2099 else |
1914 { | 2100 { |
| 2101 NS_LOG_DEBUG ("The request delay time " << rreqDelay.GetSeconds()); |
1915 m_addressReqTimer[dst].Schedule (rreqDelay); | 2102 m_addressReqTimer[dst].Schedule (rreqDelay); |
1916 } | 2103 } |
1917 } | 2104 } |
1918 } | 2105 } |
1919 | 2106 |
1920 void | 2107 void |
1921 DsrRouting::RouteRequestTimerExpire (Ptr<Packet> packet, Ipv4Address source, Ipv
4Address dst, uint8_t protocol) | 2108 DsrRouting::RouteRequestTimerExpire (Ptr<Packet> packet, Ipv4Address source, Ipv
4Address dst, uint8_t protocol) |
1922 { | 2109 { |
1923 NS_LOG_LOGIC (this << packet << source << dst << (uint32_t)protocol); | 2110 NS_LOG_FUNCTION (this << packet << source << dst << (uint32_t)protocol); |
1924 RouteCacheEntry toDst; | 2111 RouteCacheEntry toDst; |
1925 if (m_routeCache->LookupRoute (dst, toDst)) | 2112 if (m_routeCache->LookupRoute (dst, toDst)) |
1926 { | 2113 { |
1927 /* | 2114 /* |
1928 * Found a route the dst, construct the source route option header | 2115 * Found a route the dst, construct the source route option header |
1929 */ | 2116 */ |
1930 DsrOptionSRHeader sourceRoute; | 2117 DsrOptionSRHeader sourceRoute; |
1931 std::vector<Ipv4Address> ip = toDst.GetVector (); | 2118 std::vector<Ipv4Address> ip = toDst.GetVector (); |
| 2119 // PrintVector (ip); |
1932 sourceRoute.SetNodesAddress (ip); | 2120 sourceRoute.SetNodesAddress (ip); |
1933 sourceRoute.SetSegmentsLeft ((ip.size () - 2)); | 2121 sourceRoute.SetSegmentsLeft ((ip.size () - 2)); |
1934 uint8_t salvage = 0; | 2122 uint8_t salvage = 0; |
1935 sourceRoute.SetSalvage (salvage); | 2123 sourceRoute.SetSalvage (salvage); |
1936 Ipv4Address nextHop = SearchNextHop (m_mainAddress, ip); // Get the
next hop address | 2124 Ipv4Address nextHop = SearchNextHop (m_mainAddress, ip); // Get the
next hop address |
1937 NS_LOG_DEBUG ("The nextHop address " << nextHop); | 2125 NS_LOG_DEBUG ("The nextHop address " << nextHop); |
1938 if (nextHop == "0.0.0.0") | 2126 if (nextHop == "0.0.0.0") |
1939 { | 2127 { |
1940 return; | 2128 return; |
1941 } | 2129 } |
1942 SetRoute (nextHop, m_mainAddress); | 2130 SetRoute (nextHop, m_mainAddress); |
1943 CancelRreqTimer (dst); | 2131 CancelRreqTimer (dst); |
1944 SendPacket (sourceRoute, nextHop, protocol, m_ipv4Route); | 2132 SendPacket (sourceRoute, nextHop, protocol); |
1945 NS_LOG_LOGIC ("Route to " << dst << " found"); | 2133 NS_LOG_LOGIC ("Route to " << dst << " found"); |
1946 return; | 2134 return; |
1947 } | 2135 } |
1948 /* | 2136 /* |
1949 * If a route discovery has been attempted m_rreqRetries times at the maximum
TTL without | 2137 * If a route discovery has been attempted m_rreqRetries times at the maximum
TTL without |
1950 * receiving any RREP, all data packets destined for the corresponding destin
ation SHOULD be | 2138 * receiving any RREP, all data packets destined for the corresponding destin
ation SHOULD be |
1951 * dropped from the buffer and a Destination Unreachable message SHOULD be de
livered to the application. | 2139 * dropped from the buffer and a Destination Unreachable message SHOULD be de
livered to the application. |
1952 */ | 2140 */ |
| 2141 NS_LOG_DEBUG ("The new request count for " << dst << " is " << m_rreqTable->Ge
tRreqCnt (dst) << " the max " << m_rreqRetries); |
1953 if (m_rreqTable->GetRreqCnt (dst) >= m_rreqRetries) | 2142 if (m_rreqTable->GetRreqCnt (dst) >= m_rreqRetries) |
1954 { | 2143 { |
1955 NS_LOG_LOGIC ("route discovery to " << dst << " has been attempted " << m_
rreqRetries << " times"); | 2144 NS_LOG_LOGIC ("Route discovery to " << dst << " has been attempted " << m_
rreqRetries << " times"); |
1956 m_addressReqTimer.erase (dst); | 2145 CancelRreqTimer (dst); |
1957 m_routeCache->DeleteRoute (dst); | |
1958 NS_LOG_DEBUG ("Route not found. Drop packet with dst " << dst); | 2146 NS_LOG_DEBUG ("Route not found. Drop packet with dst " << dst); |
1959 m_sendBuffer.DropPacketWithDst (dst); | 2147 m_sendBuffer.DropPacketWithDst (dst); |
1960 } | 2148 } |
1961 else | 2149 else |
1962 { | 2150 { |
1963 NS_LOG_DEBUG ("Here we send the request retry"); | |
1964 SendRequest (packet, source); | 2151 SendRequest (packet, source); |
1965 } | 2152 NS_LOG_DEBUG ("Check the route request entry1 " << source << " " << dst); |
| 2153 ScheduleRreqRetry (packet, source, dst, false, protocol); |
| 2154 } |
| 2155 return; |
1966 } | 2156 } |
1967 | 2157 |
1968 void | 2158 void |
1969 DsrRouting::SendRequest (Ptr<Packet> packet, | 2159 DsrRouting::SendRequest (Ptr<Packet> packet, |
1970 Ipv4Address source) | 2160 Ipv4Address source) |
1971 { | 2161 { |
1972 NS_LOG_FUNCTION (this << packet << source ); | 2162 NS_LOG_FUNCTION (this << packet << source); |
1973 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 2163 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
1974 /* | 2164 /* |
1975 * The destination address here is directed broadcast address | 2165 * The destination address here is directed broadcast address |
1976 */ | 2166 */ |
1977 m_downTarget (packet, source, Broadcast, GetProtocolNumber (), 0); | 2167 m_downTarget (packet, source, m_broadcast, GetProtocolNumber (), 0); |
1978 } | 2168 } |
1979 | 2169 |
1980 void | 2170 void |
1981 DsrRouting::ScheduleInterRequest (Ptr<Packet> packet, | 2171 DsrRouting::ScheduleInterRequest (Ptr<Packet> packet) |
1982 Ipv4Address source) | 2172 { |
1983 { | 2173 NS_LOG_FUNCTION (this << packet); |
1984 NS_LOG_FUNCTION (this << packet << source); | |
1985 /* | 2174 /* |
1986 * this is a forwarding case when sending ip packet to next hop, a random dela
y time [0, m_broadcastJitter] | 2175 * this is a forwarding case when sending route requests, a random delay time
[0, m_broadcastJitter] |
1987 * used before forwarding as link-layer broadcast | 2176 * used before forwarding as link-layer broadcast |
1988 */ | 2177 */ |
1989 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0, m_broadca
stJitter)), &DsrRouting::SendRequest, this, | 2178 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0, m_broadca
stJitter)), &DsrRouting::SendRequest, this, |
1990 packet, source); | 2179 packet, m_mainAddress); |
1991 } | 2180 } |
1992 | 2181 |
1993 void | 2182 void |
1994 DsrRouting::SendGratuitousReply (Ipv4Address replyTo, Ipv4Address replyFrom, std
::vector<Ipv4Address> &nodeList, uint8_t protocol) | 2183 DsrRouting::SendGratuitousReply (Ipv4Address source, Ipv4Address srcAddress, std
::vector<Ipv4Address> &nodeList, uint8_t protocol) |
1995 { | 2184 { |
1996 NS_LOG_FUNCTION (this << replyTo << replyFrom); | 2185 NS_LOG_FUNCTION (this << source << srcAddress << (uint32_t)protocol); |
1997 if (!(m_graReply.FindAndUpdate (replyTo, replyFrom, m_gratReplyHoldoff)))
// Find the gratuitous reply entry | 2186 if (!(m_graReply.FindAndUpdate (source, srcAddress, m_gratReplyHoldoff)))
// Find the gratuitous reply entry |
1998 { | 2187 { |
1999 NS_LOG_LOGIC ("Update gratuitous reply " << replyTo); | 2188 NS_LOG_LOGIC ("Update gratuitous reply " << source); |
2000 GraReplyEntry graReplyEntry (replyTo, replyFrom, m_gratReplyHoldoff + Simu
lator::Now ()); | 2189 GraReplyEntry graReplyEntry (source, srcAddress, m_gratReplyHoldoff + Simu
lator::Now ()); |
2001 m_graReply.AddEntry (graReplyEntry); | 2190 m_graReply.AddEntry (graReplyEntry); |
2002 /* | 2191 /* |
2003 * Automatic route shortening | 2192 * Automatic route shortening |
2004 */ | 2193 */ |
2005 m_finalRoute.clear (); // Clear the final route vector | 2194 m_finalRoute.clear (); // Clear the final route vector |
2006 /** | 2195 /** |
2007 * push back the node addresses other than those between srcAddress and ou
r own ip address | 2196 * Push back the node addresses other than those between srcAddress and ou
r own ip address |
2008 */ | 2197 */ |
2009 PrintVector (nodeList); | 2198 // PrintVector (nodeList); |
2010 std::vector<Ipv4Address>::iterator before = find (nodeList.begin (), nodeL
ist.end (), replyFrom); | 2199 std::vector<Ipv4Address>::iterator before = find (nodeList.begin (), nodeL
ist.end (), srcAddress); |
2011 for (std::vector<Ipv4Address>::iterator i = nodeList.begin (); i != before
; ++i) | 2200 for (std::vector<Ipv4Address>::iterator i = nodeList.begin (); i != before
; ++i) |
2012 { | 2201 { |
2013 m_finalRoute.push_back (*i); | 2202 m_finalRoute.push_back (*i); |
2014 } | 2203 } |
| 2204 m_finalRoute.push_back (srcAddress); |
2015 std::vector<Ipv4Address>::iterator after = find (nodeList.begin (), nodeLi
st.end (), m_mainAddress); | 2205 std::vector<Ipv4Address>::iterator after = find (nodeList.begin (), nodeLi
st.end (), m_mainAddress); |
2016 for (std::vector<Ipv4Address>::iterator j = after; j != nodeList.end (); +
+j) | 2206 for (std::vector<Ipv4Address>::iterator j = after; j != nodeList.end (); +
+j) |
2017 { | 2207 { |
2018 m_finalRoute.push_back (*j); | 2208 m_finalRoute.push_back (*j); |
2019 } | 2209 } |
2020 PrintVector (m_finalRoute); | 2210 // PrintVector (m_finalRoute); |
2021 DsrOptionRrepHeader rrep; | 2211 DsrOptionRrepHeader rrep; |
2022 rrep.SetNodesAddress (m_finalRoute); // Set the node addresses i
n the route reply header | 2212 rrep.SetNodesAddress (m_finalRoute); // Set the node addresses i
n the route reply header |
2023 // The source address of the route reply packet is the end of the node lis
t | 2213 // Get the real reply source and destination |
2024 Ipv4Address source = nodeList.back (); | 2214 Ipv4Address replySrc = m_finalRoute.back (); |
| 2215 Ipv4Address replyDst = m_finalRoute.front (); |
2025 /* | 2216 /* |
2026 * Set the route and use it in send back route reply | 2217 * Set the route and use it in send back route reply |
2027 */ | 2218 */ |
2028 m_ipv4Route = SetRoute (replyTo, m_mainAddress); | 2219 m_ipv4Route = SetRoute (srcAddress, m_mainAddress); |
2029 /* | 2220 /* |
2030 * This part add dsr header to the packet and send reply | 2221 * This part adds DSR header to the packet and send reply |
2031 */ | 2222 */ |
2032 DsrRoutingHeader dsrRoutingHeader; | 2223 DsrRoutingHeader dsrRoutingHeader; |
2033 dsrRoutingHeader.SetNextHeader (protocol); | 2224 dsrRoutingHeader.SetNextHeader (protocol); |
2034 dsrRoutingHeader.SetMessageType (1); | 2225 dsrRoutingHeader.SetMessageType (1); |
2035 dsrRoutingHeader.SetSourceId (255); | 2226 dsrRoutingHeader.SetSourceId (GetIDfromIP (replySrc)); |
2036 dsrRoutingHeader.SetDestId (255); | 2227 dsrRoutingHeader.SetDestId (GetIDfromIP (replyDst)); |
2037 | 2228 |
2038 uint8_t length = rrep.GetLength (); // Get the length of the rrep h
eader excluding the type header | 2229 uint8_t length = rrep.GetLength (); // Get the length of the rrep h
eader excluding the type header |
2039 dsrRoutingHeader.SetPayloadLength (length + 2); | 2230 dsrRoutingHeader.SetPayloadLength (length + 2); |
2040 dsrRoutingHeader.AddDsrOption (rrep); | 2231 dsrRoutingHeader.AddDsrOption (rrep); |
2041 Ptr<Packet> newPacket = Create<Packet> (); | 2232 Ptr<Packet> newPacket = Create<Packet> (); |
2042 newPacket->AddHeader (dsrRoutingHeader); | 2233 newPacket->AddHeader (dsrRoutingHeader); |
2043 /* | 2234 /* |
2044 * send gratuitous reply | 2235 * send gratuitous reply |
2045 */ | 2236 */ |
2046 NS_LOG_INFO ("Send back gratuitous route reply"); | 2237 NS_LOG_INFO ("Send back gratuitous route reply"); |
2047 SendReply (newPacket, m_mainAddress, replyTo, m_ipv4Route); | 2238 SendReply (newPacket, m_mainAddress, srcAddress, m_ipv4Route); |
2048 } | 2239 } |
2049 else | 2240 else |
2050 { | 2241 { |
2051 NS_LOG_INFO ("The same gratuitous route reply has already sent"); | 2242 NS_LOG_INFO ("The same gratuitous route reply has already sent"); |
2052 } | 2243 } |
2053 } | 2244 } |
2054 | 2245 |
2055 void | 2246 void |
2056 DsrRouting::SendReply (Ptr<Packet> packet, | 2247 DsrRouting::SendReply (Ptr<Packet> packet, |
2057 Ipv4Address source, | 2248 Ipv4Address source, |
2058 Ipv4Address destination, | 2249 Ipv4Address nextHop, |
2059 Ptr<Ipv4Route> route) | 2250 Ptr<Ipv4Route> route) |
2060 { | 2251 { |
2061 NS_LOG_FUNCTION (this << packet << source << destination); | 2252 NS_LOG_FUNCTION (this << packet << source << nextHop); |
2062 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 2253 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
2063 Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (m_m
ainAddress)); | 2254 Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (m_m
ainAddress)); |
2064 route->SetOutputDevice (dev); | 2255 route->SetOutputDevice (dev); |
2065 NS_LOG_INFO ("The output device " << dev << "packet is: " << *packet); | 2256 NS_LOG_INFO ("The output device " << dev << " packet is: " << *packet); |
2066 /* | 2257 m_downTarget (packet, source, nextHop, GetProtocolNumber (), route); |
2067 * Cancel the request timer | |
2068 */ | |
2069 m_addressReqTimer[destination].Cancel (); | |
2070 m_addressReqTimer[destination].Remove (); | |
2071 if (m_addressReqTimer[destination].IsRunning ()) | |
2072 { | |
2073 NS_LOG_DEBUG ("Timer not canceled"); | |
2074 } | |
2075 m_addressReqTimer.erase (destination); | |
2076 m_downTarget (packet, source, destination, GetProtocolNumber (), route); | |
2077 } | 2258 } |
2078 | 2259 |
2079 void | 2260 void |
2080 DsrRouting::ScheduleInitialReply (Ptr<Packet> packet, | 2261 DsrRouting::ScheduleInitialReply (Ptr<Packet> packet, |
2081 Ipv4Address source, | 2262 Ipv4Address source, |
2082 Ipv4Address destination, | 2263 Ipv4Address nextHop, |
2083 Ptr<Ipv4Route> route) | 2264 Ptr<Ipv4Route> route) |
2084 { | 2265 { |
2085 NS_LOG_FUNCTION (this << packet << source << destination); | 2266 NS_LOG_FUNCTION (this << packet << source << nextHop); |
2086 Simulator::ScheduleNow (&DsrRouting::SendReply, this, | 2267 Simulator::ScheduleNow (&DsrRouting::SendReply, this, |
2087 packet, source, destination, route); | 2268 packet, source, nextHop, route); |
2088 } | 2269 } |
2089 | 2270 |
2090 void | 2271 void |
2091 DsrRouting::ScheduleCachedReply (Ptr<Packet> packet, | 2272 DsrRouting::ScheduleCachedReply (Ptr<Packet> packet, |
2092 Ipv4Address source, | 2273 Ipv4Address source, |
2093 Ipv4Address destination, | 2274 Ipv4Address destination, |
2094 Ptr<Ipv4Route> route, | 2275 Ptr<Ipv4Route> route, |
2095 uint16_t hops) | 2276 uint16_t hops) |
2096 { | 2277 { |
2097 NS_LOG_FUNCTION (this << packet << source << destination); | 2278 NS_LOG_FUNCTION (this << packet << source << destination); |
2098 Simulator::Schedule (Time (2 * m_nodeTraversalTime * (hops - 1 + UniformVariab
le ().GetValue (0,1))), &DsrRouting::SendReply, this, packet, source, destinatio
n, route); | 2279 Simulator::Schedule (Time (2 * m_nodeTraversalTime * (hops - 1 + UniformVariab
le ().GetValue (0,1))), &DsrRouting::SendReply, this, packet, source, destinatio
n, route); |
2099 } | 2280 } |
2100 | 2281 |
2101 void | 2282 void |
2102 DsrRouting::SendAck (Ptr<Packet> packet, | 2283 DsrRouting::SendAck (uint16_t ackId, |
2103 uint16_t ackId, | |
2104 Ipv4Address source, | |
2105 Ipv4Address destination, | 2284 Ipv4Address destination, |
2106 Ipv4Address realSrc, | 2285 Ipv4Address realSrc, |
2107 Ipv4Address realDst, | 2286 Ipv4Address realDst, |
2108 uint8_t protocol, | 2287 uint8_t protocol, |
2109 Ptr<Ipv4Route> route) | 2288 Ptr<Ipv4Route> route) |
2110 { | 2289 { |
2111 NS_LOG_FUNCTION (this << source << destination << realSrc << realDst << protoc
ol << route); | 2290 NS_LOG_FUNCTION (this << ackId << destination << realSrc << realDst << (uint32
_t)protocol << route); |
2112 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); | 2291 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downwar
d"); |
2113 | 2292 |
2114 // This is a route reply option header | 2293 // This is a route reply option header |
2115 DsrRoutingHeader dsrRoutingHeader; | 2294 DsrRoutingHeader dsrRoutingHeader; |
2116 dsrRoutingHeader.SetNextHeader (protocol); | 2295 dsrRoutingHeader.SetNextHeader (protocol); |
2117 dsrRoutingHeader.SetMessageType (1); | 2296 dsrRoutingHeader.SetMessageType (1); |
2118 dsrRoutingHeader.SetSourceId (255); | 2297 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress)); |
2119 dsrRoutingHeader.SetDestId (255); | 2298 dsrRoutingHeader.SetDestId (GetIDfromIP (destination)); |
2120 /* | 2299 |
2121 * Check the ACK ID | |
2122 */ | |
2123 DsrOptionAckHeader ack; | 2300 DsrOptionAckHeader ack; |
2124 /* | 2301 /* |
2125 * Set the ack Id and set the ack source address and destination address | 2302 * Set the ack Id and set the ack source address and destination address |
2126 */ | 2303 */ |
2127 ack.SetId (ackId); | 2304 ack.SetAckId (ackId); |
2128 ack.SetRealSrc (realSrc); | 2305 ack.SetRealSrc (realSrc); |
2129 ack.SetRealDst (realDst); | 2306 ack.SetRealDst (realDst); |
2130 | 2307 |
2131 uint8_t length = ack.GetLength (); | 2308 uint8_t length = ack.GetLength (); |
2132 dsrRoutingHeader.SetPayloadLength (length + 2); | 2309 dsrRoutingHeader.SetPayloadLength (length + 2); |
2133 dsrRoutingHeader.AddDsrOption (ack); | 2310 dsrRoutingHeader.AddDsrOption (ack); |
2134 | 2311 |
| 2312 Ptr<Packet> packet = Create<Packet> (); |
2135 packet->AddHeader (dsrRoutingHeader); | 2313 packet->AddHeader (dsrRoutingHeader); |
2136 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainA
ddress)); | 2314 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainA
ddress)); |
2137 route->SetOutputDevice (dev); | 2315 route->SetOutputDevice (dev); |
2138 m_downTarget (packet, source, destination, GetProtocolNumber (), route); | 2316 NS_LOG_DEBUG ("Send out the ACK"); |
| 2317 m_downTarget (packet, m_mainAddress, destination, GetProtocolNumber (), route)
; |
2139 } | 2318 } |
2140 | 2319 |
2141 enum Ipv4L4Protocol::RxStatus | 2320 enum Ipv4L4Protocol::RxStatus |
2142 DsrRouting::Receive (Ptr<Packet> p, | 2321 DsrRouting::Receive (Ptr<Packet> p, |
2143 Ipv4Header const &ip, | 2322 Ipv4Header const &ip, |
2144 Ptr<Ipv4Interface> incomingInterface) | 2323 Ptr<Ipv4Interface> incomingInterface) |
2145 { | 2324 { |
2146 NS_LOG_FUNCTION (this << p << ip << incomingInterface); | 2325 NS_LOG_FUNCTION (this << p << ip << incomingInterface); |
2147 | 2326 |
2148 NS_LOG_INFO ("Our own IP address " << m_mainAddress << " The incoming interfac
e address " << incomingInterface); | 2327 NS_LOG_INFO ("Our own IP address " << m_mainAddress << " The incoming interfac
e address " << incomingInterface); |
2149 m_node = GetNode (); // Get the node | 2328 m_node = GetNode (); // Get the node |
2150 | |
2151 Ptr<Packet> packet = p->Copy (); // Save a copy of the received pac
ket | 2329 Ptr<Packet> packet = p->Copy (); // Save a copy of the received pac
ket |
2152 /* | 2330 /* |
2153 * When forwarding or local deliver packets, this one should be used always!! | 2331 * When forwarding or local deliver packets, this one should be used always!! |
2154 */ | 2332 */ |
2155 DsrRoutingHeader dsrRoutingHeader; | 2333 DsrRoutingHeader dsrRoutingHeader; |
2156 packet->RemoveHeader (dsrRoutingHeader); // Remove the dsr header in
whole | 2334 packet->RemoveHeader (dsrRoutingHeader); // Remove the DSR header in
whole |
| 2335 Ptr<Packet> copy = packet->Copy (); |
2157 uint8_t protocol = dsrRoutingHeader.GetNextHeader (); | 2336 uint8_t protocol = dsrRoutingHeader.GetNextHeader (); |
| 2337 uint32_t sourceId = dsrRoutingHeader.GetSourceId (); |
| 2338 Ipv4Address source = GetIPfromID (sourceId); |
| 2339 NS_LOG_DEBUG ("The source address " << source); |
2158 /* | 2340 /* |
2159 * Get the IP source and destination address | 2341 * Get the IP source and destination address |
2160 */ | 2342 */ |
2161 Ipv4Address src = ip.GetSource (); | 2343 Ipv4Address src = ip.GetSource (); |
2162 Ipv4Address dst = ip.GetDestination (); | 2344 Ipv4Address dst = ip.GetDestination (); |
2163 | 2345 |
2164 bool isPromisc = false; | 2346 bool isPromisc = false; |
2165 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); // Get the o
ffset for option header, 8 bytes in this case | 2347 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); // Get the o
ffset for option header, 8 bytes in this case |
2166 | 2348 |
2167 // This packet is used to peek option type | 2349 // This packet is used to peek option type |
(...skipping 19 matching lines...) Expand all Loading... |
2187 if (optionType == 1) // This is the request option | 2369 if (optionType == 1) // This is the request option |
2188 { | 2370 { |
2189 BlackList *blackList = m_rreqTable->FindUnidirectional (src); | 2371 BlackList *blackList = m_rreqTable->FindUnidirectional (src); |
2190 if (blackList) | 2372 if (blackList) |
2191 { | 2373 { |
2192 NS_LOG_DEBUG ("Discard this packet due to unidirectional link"); | 2374 NS_LOG_DEBUG ("Discard this packet due to unidirectional link"); |
2193 m_dropTrace (p); | 2375 m_dropTrace (p); |
2194 } | 2376 } |
2195 | 2377 |
2196 dsrOption = GetOption (optionType); | 2378 dsrOption = GetOption (optionType); |
2197 optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol,
isPromisc); | 2379 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, p
rotocol, isPromisc); |
2198 | 2380 |
2199 if (optionLength == 0) | 2381 if (optionLength == 0) |
2200 { | 2382 { |
2201 NS_LOG_DEBUG ("Discard this packet"); | 2383 NS_LOG_DEBUG ("Discard this packet"); |
2202 m_dropTrace (p); | 2384 m_dropTrace (p); |
2203 } | 2385 } |
2204 } | 2386 } |
2205 else if (optionType == 2) | 2387 else if (optionType == 2) |
2206 { | 2388 { |
2207 dsrOption = GetOption (optionType); | 2389 dsrOption = GetOption (optionType); |
2208 optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol,
isPromisc); | 2390 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, p
rotocol, isPromisc); |
2209 | 2391 |
2210 if (optionLength == 0) | 2392 if (optionLength == 0) |
2211 { | 2393 { |
2212 NS_LOG_DEBUG ("Discard this packet"); | 2394 NS_LOG_DEBUG ("Discard this packet"); |
2213 m_dropTrace (p); | 2395 m_dropTrace (p); |
2214 } | 2396 } |
2215 } | 2397 } |
2216 | 2398 |
2217 else if (optionType == 32) // This is the ACK option | 2399 else if (optionType == 32) // This is the ACK option |
2218 { | 2400 { |
2219 NS_LOG_DEBUG ("This is the ack option"); | 2401 NS_LOG_DEBUG ("This is the ack option"); |
2220 dsrOption = GetOption (optionType); | 2402 dsrOption = GetOption (optionType); |
2221 optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol,
isPromisc); | 2403 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, p
rotocol, isPromisc); |
2222 | 2404 |
2223 if (optionLength == 0) | 2405 if (optionLength == 0) |
2224 { | 2406 { |
2225 NS_LOG_DEBUG ("Discard this packet"); | 2407 NS_LOG_DEBUG ("Discard this packet"); |
2226 m_dropTrace (p); | 2408 m_dropTrace (p); |
2227 } | 2409 } |
2228 } | 2410 } |
2229 | 2411 |
2230 else if (optionType == 3) // This is a route error header | 2412 else if (optionType == 3) // This is a route error header |
2231 { | 2413 { |
2232 // populate this route error | 2414 // populate this route error |
2233 NS_LOG_DEBUG ("The option type value " << (uint32_t)optionType); | 2415 NS_LOG_DEBUG ("The option type value " << (uint32_t)optionType); |
2234 | 2416 |
2235 dsrOption = GetOption (optionType); | 2417 dsrOption = GetOption (optionType); |
2236 optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol,
isPromisc); | 2418 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, p
rotocol, isPromisc); |
2237 | 2419 |
2238 if (optionLength == 0) | 2420 if (optionLength == 0) |
2239 { | 2421 { |
2240 NS_LOG_DEBUG ("Discard this packet"); | 2422 NS_LOG_DEBUG ("Discard this packet"); |
2241 m_dropTrace (p); | 2423 m_dropTrace (p); |
2242 } | 2424 } |
2243 NS_LOG_DEBUG ("The option Length " << (uint32_t)optionLength); | 2425 NS_LOG_DEBUG ("The option Length " << (uint32_t)optionLength); |
2244 } | 2426 } |
2245 | 2427 |
2246 else if (optionType == 96) // This is the source route option | 2428 else if (optionType == 96) // This is the source route option |
2247 { | 2429 { |
2248 NS_LOG_DEBUG ("This is the source route option " << (uint32_t)optionType); | 2430 NS_LOG_DEBUG ("This is the source route option " << (uint32_t)optionType); |
2249 dsrOption = GetOption (optionType); | 2431 dsrOption = GetOption (optionType); |
2250 optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol,
isPromisc); | 2432 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, p
rotocol, isPromisc); |
2251 | 2433 |
2252 segmentsLeft = *(data + 3); | 2434 segmentsLeft = *(data + 3); |
2253 NS_LOG_DEBUG ("The segments left in source route header " << (uint32_t)seg
mentsLeft); | 2435 NS_LOG_DEBUG ("The segments left in source route header " << (uint32_t)seg
mentsLeft); |
2254 if (optionLength == 0) | 2436 if (optionLength == 0) |
2255 { | 2437 { |
2256 NS_LOG_DEBUG ("Discard this packet"); | 2438 NS_LOG_DEBUG ("Discard this packet"); |
2257 m_dropTrace (p); | 2439 m_dropTrace (p); |
2258 } | 2440 } |
2259 | 2441 |
2260 if (segmentsLeft == 0) | 2442 if (segmentsLeft == 0) |
2261 { | 2443 { |
2262 // / get the next header | 2444 // / get the next header |
2263 uint8_t nextHeader = dsrRoutingHeader.GetNextHeader (); | 2445 uint8_t nextHeader = dsrRoutingHeader.GetNextHeader (); |
2264 Ptr<Ipv4L3Protocol> l3proto = m_node->GetObject<Ipv4L3Protocol> (); | 2446 Ptr<Ipv4L3Protocol> l3proto = m_node->GetObject<Ipv4L3Protocol> (); |
2265 Ptr<Ipv4L4Protocol> nextProto = l3proto->GetProtocol (nextHeader); | 2447 Ptr<Ipv4L4Protocol> nextProto = l3proto->GetProtocol (nextHeader); |
2266 if (nextProto != 0) | 2448 if (nextProto != 0) |
2267 { | 2449 { |
2268 // we need to make a copy in the unlikely event we hit the | 2450 // we need to make a copy in the unlikely event we hit the |
2269 // RX_ENDPOINT_UNREACH code path | 2451 // RX_ENDPOINT_UNREACH code path |
2270 // Here we can use the packet that has been get off whole DSR head
er | 2452 // Here we can use the packet that has been get off whole DSR head
er |
2271 Ptr<Packet> copy = packet->Copy (); | 2453 NS_LOG_DEBUG ("The packet received " << *copy); |
2272 enum Ipv4L4Protocol::RxStatus status = | 2454 enum Ipv4L4Protocol::RxStatus status = |
2273 nextProto->Receive (copy, ip, incomingInterface); | 2455 nextProto->Receive (copy, ip, incomingInterface); |
2274 NS_LOG_DEBUG ("The receive status " << status); | 2456 NS_LOG_DEBUG ("The receive status " << status); |
2275 switch (status) | 2457 switch (status) |
2276 { | 2458 { |
2277 case Ipv4L4Protocol::RX_OK: | 2459 case Ipv4L4Protocol::RX_OK: |
2278 // fall through | 2460 // fall through |
2279 case Ipv4L4Protocol::RX_ENDPOINT_CLOSED: | 2461 case Ipv4L4Protocol::RX_ENDPOINT_CLOSED: |
2280 // fall through | 2462 // fall through |
2281 case Ipv4L4Protocol::RX_CSUM_FAILED: | 2463 case Ipv4L4Protocol::RX_CSUM_FAILED: |
2282 break; | 2464 break; |
2283 case Ipv4L4Protocol::RX_ENDPOINT_UNREACH: | 2465 case Ipv4L4Protocol::RX_ENDPOINT_UNREACH: |
2284 if (ip.GetDestination ().IsBroadcast () == true | 2466 if (ip.GetDestination ().IsBroadcast () == true |
2285 || ip.GetDestination ().IsMulticast () == true) | 2467 || ip.GetDestination ().IsMulticast () == true) |
2286 { | 2468 { |
2287 break; // Do not reply to broadcast or multicast | 2469 break; // Do not reply to broadcast or multicast |
2288 } | 2470 } |
2289 // Another case to suppress ICMP is a subnet-directed broadcas
t | 2471 // Another case to suppress ICMP is a subnet-directed broadcas
t |
2290 } | 2472 } |
2291 return status; | 2473 return status; |
2292 } | 2474 } |
2293 } | 2475 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2339 { | 2521 { |
2340 if ((*i)->GetOptionNumber () == optionNumber) | 2522 if ((*i)->GetOptionNumber () == optionNumber) |
2341 { | 2523 { |
2342 return *i; | 2524 return *i; |
2343 } | 2525 } |
2344 } | 2526 } |
2345 return 0; | 2527 return 0; |
2346 } | 2528 } |
2347 } /* namespace dsr */ | 2529 } /* namespace dsr */ |
2348 } /* namespace ns3 */ | 2530 } /* namespace ns3 */ |
LEFT | RIGHT |