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