A Discrete-Event Network Simulator
API
dsr-routing.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 Yufei Cheng
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
19 *
20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21 * ResiliNets Research Group https://resilinets.org/
22 * Information and Telecommunication Technology Center (ITTC)
23 * and Department of Electrical Engineering and Computer Science
24 * The University of Kansas Lawrence, KS USA.
25 *
26 * Work supported in part by NSF FIND (Future Internet Design) Program
27 * under grant CNS-0626918 (Postmodern Internet Architecture),
28 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29 * US Department of Defense (DoD), and ITTC at The University of Kansas.
30 */
31
32#define NS_LOG_APPEND_CONTEXT \
33 if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId () << "] "; }
34
35#include <list>
36#include <ctime>
37#include <map>
38#include <limits>
39#include <algorithm>
40#include <iostream>
41
42#include "ns3/config.h"
43#include "ns3/enum.h"
44#include "ns3/string.h"
45#include "ns3/ptr.h"
46#include "ns3/log.h"
47#include "ns3/assert.h"
48#include "ns3/uinteger.h"
49#include "ns3/net-device.h"
50#include "ns3/packet.h"
51#include "ns3/boolean.h"
52#include "ns3/node-list.h"
53#include "ns3/double.h"
54#include "ns3/pointer.h"
55#include "ns3/timer.h"
56#include "ns3/object-vector.h"
57#include "ns3/ipv4-address.h"
58#include "ns3/ipv4-header.h"
59#include "ns3/ipv4-l3-protocol.h"
60#include "ns3/ipv4-route.h"
61#include "ns3/trace-source-accessor.h"
62#include "ns3/icmpv4-l4-protocol.h"
63#include "ns3/adhoc-wifi-mac.h"
64#include "ns3/wifi-net-device.h"
65#include "ns3/inet-socket-address.h"
66#include "ns3/udp-l4-protocol.h"
67#include "ns3/udp-socket-factory.h"
68#include "ns3/tcp-socket-factory.h"
69#include "ns3/llc-snap-header.h"
70#include "ns3/arp-header.h"
71#include "ns3/ipv6-interface.h"
72
73#include "dsr-rreq-table.h"
74#include "dsr-rcache.h"
75#include "dsr-routing.h"
76#include "dsr-fs-header.h"
77#include "dsr-options.h"
78
79namespace ns3 {
80
81NS_LOG_COMPONENT_DEFINE ("DsrRouting");
82
83namespace dsr {
84
86
87/* see http://www.iana.org/assignments/protocol-numbers */
88const uint8_t DsrRouting::PROT_NUMBER = 48;
89/*
90 * The extension header is the fixed size dsr header, it is response for recognizing DSR option types
91 * and demux to right options to process the packet.
92 *
93 * The header format with neighboring layers is as follows:
94 *
95 +-+-+-+-+-+-+-+-+-+-+-
96 | Application Header |
97 +-+-+-+-+-+-+-+-+-+-+-+
98 | Transport Header |
99 +-+-+-+-+-+-+-+-+-+-+-+
100 | Fixed DSR Header |
101 +---------------------+
102 | DSR Options |
103 +-+-+-+-+-+-+-+-+-+-+-+
104 | IP Header |
105 +-+-+-+-+-+-+-+-+-+-+-+
106 */
107
109{
110 static TypeId tid = TypeId ("ns3::dsr::DsrRouting")
112 .SetGroupName ("Dsr")
113 .AddConstructor<DsrRouting> ()
114 .AddAttribute ("RouteCache",
115 "The route cache for saving routes from "
116 "route discovery process.",
117 PointerValue (0),
120 MakePointerChecker<DsrRouteCache> ())
121 .AddAttribute ("RreqTable",
122 "The request table to manage route requests.",
123 PointerValue (0),
126 MakePointerChecker<DsrRreqTable> ())
127 .AddAttribute ("PassiveBuffer",
128 "The passive buffer to manage "
129 "promisucously received passive ack.",
130 PointerValue (0),
133 MakePointerChecker<DsrPassiveBuffer> ())
134 .AddAttribute ("MaxSendBuffLen",
135 "Maximum number of packets that can be stored "
136 "in send buffer.",
137 UintegerValue (64),
139 MakeUintegerChecker<uint32_t> ())
140 .AddAttribute ("MaxSendBuffTime",
141 "Maximum time packets can be queued in the send buffer .",
142 TimeValue (Seconds (30)),
145 .AddAttribute ("MaxMaintLen",
146 "Maximum number of packets that can be stored "
147 "in maintenance buffer.",
148 UintegerValue (50),
150 MakeUintegerChecker<uint32_t> ())
151 .AddAttribute ("MaxMaintTime",
152 "Maximum time packets can be queued in maintenance buffer.",
153 TimeValue (Seconds (30)),
156 .AddAttribute ("MaxCacheLen",
157 "Maximum number of route entries that can be stored "
158 "in route cache.",
159 UintegerValue (64),
161 MakeUintegerChecker<uint32_t> ())
162 .AddAttribute ("RouteCacheTimeout",
163 "Maximum time the route cache can be queued in "
164 "route cache.",
165 TimeValue (Seconds (300)),
168 .AddAttribute ("MaxEntriesEachDst",
169 "Maximum number of route entries for a "
170 "single destination to respond.",
171 UintegerValue (20),
173 MakeUintegerChecker<uint32_t> ())
174 .AddAttribute ("SendBuffInterval",
175 "How often to check send buffer for packet with route.",
176 TimeValue (Seconds (500)),
179 .AddAttribute ("NodeTraversalTime",
180 "The time it takes to traverse two neighboring nodes.",
181 TimeValue (MilliSeconds (40)),
184 .AddAttribute ("RreqRetries",
185 "Maximum number of retransmissions for "
186 "request discovery of a route.",
187 UintegerValue (16),
189 MakeUintegerChecker<uint32_t> ())
190 .AddAttribute ("MaintenanceRetries",
191 "Maximum number of retransmissions for "
192 "data packets from maintenance buffer.",
193 UintegerValue (2),
195 MakeUintegerChecker<uint32_t> ())
196 .AddAttribute ("RequestTableSize",
197 "Maximum number of request entries in the request table, "
198 "set this as the number of nodes in the simulation.",
199 UintegerValue (64),
201 MakeUintegerChecker<uint32_t> ())
202 .AddAttribute ("RequestIdSize",
203 "Maximum number of request source Ids in "
204 "the request table.",
205 UintegerValue (16),
207 MakeUintegerChecker<uint32_t> ())
208 .AddAttribute ("UniqueRequestIdSize",
209 "Maximum number of request Ids in "
210 "the request table for a single destination.",
211 UintegerValue (256),
213 MakeUintegerChecker<uint32_t> ())
214 .AddAttribute ("NonPropRequestTimeout",
215 "The timeout value for non-propagation request.",
216 TimeValue (MilliSeconds (30)),
219 .AddAttribute ("DiscoveryHopLimit",
220 "The max discovery hop limit for route requests.",
221 UintegerValue (255),
223 MakeUintegerChecker<uint32_t> ())
224 .AddAttribute ("MaxSalvageCount",
225 "The max salvage count for a single data packet.",
226 UintegerValue (15),
228 MakeUintegerChecker<uint8_t> ())
229 .AddAttribute ("BlacklistTimeout",
230 "The time for a neighbor to stay in blacklist.",
231 TimeValue (Seconds (3)),
234 .AddAttribute ("GratReplyHoldoff",
235 "The time for gratuitous reply entry to expire.",
236 TimeValue (Seconds (1)),
239 .AddAttribute ("BroadcastJitter",
240 "The jitter time to avoid collision for broadcast packets.",
241 UintegerValue (10),
243 MakeUintegerChecker<uint32_t> ())
244 .AddAttribute ("LinkAckTimeout",
245 "The time a packet in maintenance buffer wait for "
246 "link acknowledgment.",
247 TimeValue (MilliSeconds (100)),
250 .AddAttribute ("TryLinkAcks",
251 "The number of link acknowledgment to use.",
252 UintegerValue (1),
254 MakeUintegerChecker<uint32_t> ())
255 .AddAttribute ("PassiveAckTimeout",
256 "The time a packet in maintenance buffer wait for "
257 "passive acknowledgment.",
258 TimeValue (MilliSeconds (100)),
261 .AddAttribute ("TryPassiveAcks",
262 "The number of passive acknowledgment to use.",
263 UintegerValue (1),
265 MakeUintegerChecker<uint32_t> ())
266 .AddAttribute ("RequestPeriod",
267 "The base time interval between route requests.",
268 TimeValue (MilliSeconds (500)),
271 .AddAttribute ("MaxRequestPeriod",
272 "The max time interval between route requests.",
273 TimeValue (Seconds (10)),
276 .AddAttribute ("GraReplyTableSize",
277 "The gratuitous reply table size.",
278 UintegerValue (64),
280 MakeUintegerChecker<uint32_t> ())
281 .AddAttribute ("CacheType",
282 "Use Link Cache or use Path Cache",
283 StringValue ("LinkCache"),
286 .AddAttribute ("StabilityDecrFactor",
287 "The stability decrease factor for link cache",
288 UintegerValue (2),
290 MakeUintegerChecker<uint32_t> ())
291 .AddAttribute ("StabilityIncrFactor",
292 "The stability increase factor for link cache",
293 UintegerValue (4),
295 MakeUintegerChecker<uint32_t> ())
296 .AddAttribute ("InitStability",
297 "The initial stability factor for link cache",
298 TimeValue (Seconds (25)),
301 .AddAttribute ("MinLifeTime",
302 "The minimal life time for link cache",
303 TimeValue (Seconds (1)),
306 .AddAttribute ("UseExtends",
307 "The extension time for link cache",
308 TimeValue (Seconds (120)),
311 .AddAttribute ("EnableSubRoute",
312 "Enables saving of sub route when receiving "
313 "route error messages, only available when "
314 "using path route cache",
315 BooleanValue (true),
318 .AddAttribute ("RetransIncr",
319 "The increase time for retransmission timer "
320 "when facing network congestion",
321 TimeValue (MilliSeconds (20)),
324 .AddAttribute ("MaxNetworkQueueSize",
325 "The max number of packet to save in the network queue.",
326 UintegerValue (400),
328 MakeUintegerChecker<uint32_t> ())
329 .AddAttribute ("MaxNetworkQueueDelay",
330 "The max time for a packet to stay in the network queue.",
331 TimeValue (Seconds (30.0)),
334 .AddAttribute ("NumPriorityQueues",
335 "The max number of packet to save in the network queue.",
336 UintegerValue (2),
338 MakeUintegerChecker<uint32_t> ())
339 .AddAttribute ("LinkAcknowledgment",
340 "Enable Link layer acknowledgment mechanism",
341 BooleanValue (true),
344 .AddTraceSource ("Tx",
345 "Send DSR packet.",
347 "ns3::dsr::DsrOptionSRHeader::TracedCallback")
348 .AddTraceSource ("Drop",
349 "Drop DSR packet",
351 "ns3::Packet::TracedCallback")
352 ;
353 return tid;
354}
355
357{
359
360 m_uniformRandomVariable = CreateObject<UniformRandomVariable> ();
361
362 /*
363 * The following Ptr statements created objects for all the options header for DSR, and each of them have
364 * distinct option number assigned, when DSR Routing received a packet from higher layer, it will find
365 * the following options based on the option number, and pass the packet to the appropriate option to
366 * process it. After the option processing, it will pass the packet back to DSR Routing to send down layer.
367 */
368 Ptr<dsr::DsrOptionPad1> pad1Option = CreateObject<dsr::DsrOptionPad1> ();
369 Ptr<dsr::DsrOptionPadn> padnOption = CreateObject<dsr::DsrOptionPadn> ();
370 Ptr<dsr::DsrOptionRreq> rreqOption = CreateObject<dsr::DsrOptionRreq> ();
371 Ptr<dsr::DsrOptionRrep> rrepOption = CreateObject<dsr::DsrOptionRrep> ();
372 Ptr<dsr::DsrOptionSR> srOption = CreateObject<dsr::DsrOptionSR> ();
373 Ptr<dsr::DsrOptionRerr> rerrOption = CreateObject<dsr::DsrOptionRerr> ();
374 Ptr<dsr::DsrOptionAckReq> ackReq = CreateObject<dsr::DsrOptionAckReq> ();
375 Ptr<dsr::DsrOptionAck> ack = CreateObject<dsr::DsrOptionAck> ();
376
377 Insert (pad1Option);
378 Insert (padnOption);
379 Insert (rreqOption);
380 Insert (rrepOption);
381 Insert (srOption);
382 Insert (rerrOption);
383 Insert (ackReq);
384 Insert (ack);
385
386 // Check the send buffer for sending packets
389}
390
392{
394}
395
396void
398{
399 NS_LOG_FUNCTION (this << "NotifyNewAggregate");
400 if (!m_node)
401 {
402 Ptr<Node> node = this->GetObject<Node> ();
403 if (node)
404 {
405 m_ipv4 = this->GetObject<Ipv4L3Protocol> ();
406 if (m_ipv4)
407 {
408 this->SetNode (node);
409 m_ipv4->Insert (this);
411 }
412
413 m_ip = node->GetObject<Ipv4> ();
414 if (m_ip)
415 {
416 NS_LOG_DEBUG ("Ipv4 started");
417 }
418 }
419 }
422}
423
425{
426 NS_LOG_FUNCTION (this << "Start DSR Routing protocol");
427
428 NS_LOG_INFO ("The number of network queues " << m_numPriorityQueues);
429 for (uint32_t i = 0; i < m_numPriorityQueues; i++)
430 {
431 // Set the network queue max size and the delay
432 NS_LOG_INFO ("The network queue size " << m_maxNetworkSize << " and the queue delay " << m_maxNetworkDelay.As (Time::S));
433 Ptr<dsr::DsrNetworkQueue> queue_i = CreateObject<dsr::DsrNetworkQueue> (m_maxNetworkSize,m_maxNetworkDelay);
434 std::pair<std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator, bool> result_i = m_priorityQueue.insert (std::make_pair (i, queue_i));
435 NS_ASSERT_MSG (result_i.second, "Error in creating queues");
436 }
437 Ptr<dsr::DsrRreqTable> rreqTable = CreateObject<dsr::DsrRreqTable> ();
438 // Set the initial hop limit
439 rreqTable->SetInitHopLimit (m_discoveryHopLimit);
440 // Configure the request table parameters
441 rreqTable->SetRreqTableSize (m_requestTableSize);
442 rreqTable->SetRreqIdSize (m_requestTableIds);
443 rreqTable->SetUniqueRreqIdSize (m_maxRreqId);
444 SetRequestTable (rreqTable);
445 // Set the passive buffer parameters using just the send buffer parameters
446 Ptr<dsr::DsrPassiveBuffer> passiveBuffer = CreateObject<dsr::DsrPassiveBuffer> ();
447 passiveBuffer->SetMaxQueueLen (m_maxSendBuffLen);
448 passiveBuffer->SetPassiveBufferTimeout (m_sendBufferTimeout);
449 SetPassiveBuffer (passiveBuffer);
450
451 // Set the send buffer parameters
454 // Set the error buffer parameters using just the send buffer parameters
457 // Set the maintenance buffer parameters
460 // Set the gratuitous reply table size
462
463 if (m_mainAddress == Ipv4Address ())
464 {
465 Ipv4Address loopback ("127.0.0.1");
466 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
467 {
468 // Use primary address, if multiple
469 Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
470 m_broadcast = m_ipv4->GetAddress (i, 0).GetBroadcast ();
471 if (addr != loopback)
472 {
473 /*
474 * Set dsr route cache
475 */
476 Ptr<dsr::DsrRouteCache> routeCache = CreateObject<dsr::DsrRouteCache> ();
477 // Configure the path cache parameters
478 routeCache->SetCacheType (m_cacheType);
479 routeCache->SetSubRoute (m_subRoute);
480 routeCache->SetMaxCacheLen (m_maxCacheLen);
481 routeCache->SetCacheTimeout (m_maxCacheTime);
482 routeCache->SetMaxEntriesEachDst (m_maxEntriesEachDst);
483 // Parameters for link cache
484 routeCache->SetStabilityDecrFactor (m_stabilityDecrFactor);
485 routeCache->SetStabilityIncrFactor (m_stabilityIncrFactor);
486 routeCache->SetInitStability (m_initStability);
487 routeCache->SetMinLifeTime (m_minLifeTime);
488 routeCache->SetUseExtends (m_useExtends);
489 routeCache->ScheduleTimer ();
490 // The call back to handle link error and send error message to appropriate nodes
492 // routeCache->SetCallback (MakeCallback (&DsrRouting::SendRerrWhenBreaksLinkToNextHop, this));
493 SetRouteCache (routeCache);
494 // Set the main address as the current ip address
495 m_mainAddress = addr;
496
497 m_ipv4->GetNetDevice (1)->SetPromiscReceiveCallback (MakeCallback (&DsrRouting::PromiscReceive, this));
498
499 // Allow neighbor manager use this interface for layer 2 feedback if possible
500 Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (addr));
501 Ptr<WifiNetDevice> wifi = dev->GetObject<WifiNetDevice> ();
502 if (!wifi)
503 {
504 break;
505 }
506 Ptr<WifiMac> mac = wifi->GetMac ();
507 if (!mac)
508 {
509 break;
510 }
511
512 routeCache->AddArpCache (m_ipv4->GetInterface (i)->GetArpCache ());
513 NS_LOG_LOGIC ("Starting DSR on node " << m_mainAddress);
514 break;
515 }
516 }
518 }
519}
520
523{
524 // Use "NodeList/*/DeviceList/*/ as reference
525 // where element [1] is the Node Id
526 // element [2] is the NetDevice Id
527 std::vector <std::string> elements = GetElementsFromContext (context);
528 Ptr<Node> n = NodeList::GetNode (atoi (elements[1].c_str ()));
529 NS_ASSERT (n);
530 return n->GetDevice (atoi (elements[3].c_str ()));
531}
532
533std::vector<std::string>
535{
536 std::vector <std::string> elements;
537 size_t pos1 = 0, pos2;
538 while (pos1 != context.npos)
539 {
540 pos1 = context.find ("/",pos1);
541 pos2 = context.find ("/",pos1 + 1);
542 elements.push_back (context.substr (pos1 + 1,pos2 - (pos1 + 1)));
543 pos1 = pos2;
544 }
545 return elements;
546}
547
548void
550{
552 m_node = 0;
553 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
554 {
555 // Disable layer 2 link state monitoring (if possible)
556 Ptr<NetDevice> dev = m_ipv4->GetNetDevice (i);
557 Ptr<WifiNetDevice> wifi = dev->GetObject<WifiNetDevice> ();
558 if (wifi)
559 {
560 Ptr<WifiMac> mac = wifi->GetMac ();
561 if (mac)
562 {
563 Ptr<AdhocWifiMac> adhoc = mac->GetObject<AdhocWifiMac> ();
564 if (adhoc)
565 {
566 adhoc->TraceDisconnectWithoutContext ("TxErrHeader",
567 m_routeCache->GetTxErrorCallback ());
568 m_routeCache->DelArpCache (m_ipv4->GetInterface (i)->GetArpCache ());
569 }
570 }
571 }
572 }
574}
575
576void
578{
579 m_node = node;
580}
581
584{
586 return m_node;
587}
588
590{
591 // / Set the route cache to use
592 m_routeCache = r;
593}
594
597{
598 // / Get the route cache to use
599 return m_routeCache;
600}
601
603{
604 // / Set the request table to use
605 m_rreqTable = q;
606}
607
610{
611 // / Get the request table to use
612 return m_rreqTable;
613}
614
616{
617 // / Set the request table to use
618 m_passiveBuffer = p;
619}
620
623{
624 // / Get the request table to use
625 return m_passiveBuffer;
626}
627
630{
631 NS_LOG_FUNCTION (this << ipv4Address);
632 int32_t nNodes = NodeList::GetNNodes ();
633 for (int32_t i = 0; i < nNodes; ++i)
634 {
635 Ptr<Node> node = NodeList::GetNode (i);
636 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
637 int32_t ifIndex = ipv4->GetInterfaceForAddress (ipv4Address);
638 if (ifIndex != -1)
639 {
640 return node;
641 }
642 }
643 return 0;
644}
645
647{
648 return m_routeCache->IsLinkCache ();
649}
650
652{
653 m_routeCache->UseExtends (rt);
654}
655
657{
658 return m_routeCache->LookupRoute (id, rt);
659}
660
662{
663 Ipv4Address nextHop = SearchNextHop (source, nodelist);
664 m_errorBuffer.DropPacketForErrLink (source, nextHop);
665 return m_routeCache->AddRoute_Link (nodelist, source);
666}
667
669{
670 std::vector<Ipv4Address> nodelist = rt.GetVector ();
671 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodelist);
673 return m_routeCache->AddRoute (rt);
674}
675
677{
678 m_routeCache->DeleteAllRoutesIncludeLink (errorSrc, unreachNode, node);
679}
680
682{
683 return m_routeCache->UpdateRouteEntry (dst);
684}
685
687{
688 return m_rreqTable->FindSourceEntry (src, dst, id);
689}
690
693{
694 NS_LOG_FUNCTION (this << address);
695 int32_t nNodes = NodeList::GetNNodes ();
696 for (int32_t i = 0; i < nNodes; ++i)
697 {
698 Ptr<Node> node = NodeList::GetNode (i);
699 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
700 Ptr<NetDevice> netDevice = ipv4->GetNetDevice (1);
701
702 if (netDevice->GetAddress () == address)
703 {
704 return ipv4->GetAddress (1, 0).GetLocal ();
705 }
706 }
707 return 0;
708}
709
710void DsrRouting::PrintVector (std::vector<Ipv4Address>& vec)
711{
712 NS_LOG_FUNCTION (this);
713 /*
714 * Check elements in a route vector
715 */
716 if (!vec.size ())
717 {
718 NS_LOG_DEBUG ("The vector is empty");
719 }
720 else
721 {
722 NS_LOG_DEBUG ("Print all the elements in a vector");
723 for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
724 {
725 NS_LOG_DEBUG ("The ip address " << *i);
726 }
727 }
728}
729
730Ipv4Address DsrRouting::SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
731{
732 NS_LOG_FUNCTION (this << ipv4Address);
733 Ipv4Address nextHop;
734 NS_LOG_DEBUG ("the vector size " << vec.size ());
735 if (vec.size () == 2)
736 {
737 NS_LOG_DEBUG ("The two nodes are neighbors");
738 nextHop = vec[1];
739 return nextHop;
740 }
741 else
742 {
743 if (ipv4Address == vec.back ())
744 {
745 NS_LOG_DEBUG ("We have reached to the final destination " << ipv4Address << " " << vec.back ());
746 return ipv4Address;
747 }
748 for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
749 {
750 if (ipv4Address == (*i))
751 {
752 nextHop = *(++i);
753 return nextHop;
754 }
755 }
756 }
757 NS_LOG_DEBUG ("Next hop address not found");
758 Ipv4Address none = "0.0.0.0";
759 return none;
760}
761
764{
765 NS_LOG_FUNCTION (this << nextHop << srcAddress);
766 m_ipv4Route = Create<Ipv4Route> ();
767 m_ipv4Route->SetDestination (nextHop);
768 m_ipv4Route->SetGateway (nextHop);
769 m_ipv4Route->SetSource (srcAddress);
770 return m_ipv4Route;
771}
772
773int
775{
776 // / This is the protocol number for DSR which is 48
777 return PROT_NUMBER;
778}
779
780uint16_t
782{
783 int32_t nNodes = NodeList::GetNNodes ();
784 for (int32_t i = 0; i < nNodes; ++i)
785 {
786 Ptr<Node> node = NodeList::GetNode (i);
787 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
788 if (ipv4->GetAddress (1, 0).GetLocal () == address)
789 {
790 return uint16_t (i);
791 }
792 }
793 return 256;
794}
795
798{
799 if (id >= 256)
800 {
801 NS_LOG_DEBUG ("Exceed the node range");
802 return "0.0.0.0";
803 }
804 else
805 {
807 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
808 return ipv4->GetAddress (1, 0).GetLocal ();
809 }
810}
811
814{
815 if (messageType == DSR_CONTROL_PACKET)
816 {
817 return 0;
818 }
819 else
820 {
821 return 1;
822 }
823}
824
826{
828 {
830 }
833}
834
836{
838 << " Checking send buffer at " << m_mainAddress << " with size " << m_sendBuffer.GetSize ());
839
840 for (std::vector<DsrSendBuffEntry>::iterator i = m_sendBuffer.GetBuffer ().begin (); i != m_sendBuffer.GetBuffer ().end (); )
841 {
842 NS_LOG_DEBUG ("Here we try to find the data packet in the send buffer");
843 Ipv4Address destination = i->GetDestination ();
844 DsrRouteCacheEntry toDst;
845 bool findRoute = m_routeCache->LookupRoute (destination, toDst);
846 if (findRoute)
847 {
848 NS_LOG_INFO ("We have found a route for the packet");
849 Ptr<const Packet> packet = i->GetPacket ();
850 Ptr<Packet> cleanP = packet->Copy ();
851 uint8_t protocol = i->GetProtocol ();
852
853 i = m_sendBuffer.GetBuffer ().erase (i);
854
855 DsrRoutingHeader dsrRoutingHeader;
856 Ptr<Packet> copyP = packet->Copy ();
857 Ptr<Packet> dsrPacket = packet->Copy ();
858 dsrPacket->RemoveHeader (dsrRoutingHeader);
859 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
860 copyP->RemoveAtStart (offset); // Here the processed size is 8 bytes, which is the fixed sized extension header
861 // The packet to get ipv4 header
862 Ptr<Packet> ipv4P = copyP->Copy ();
863 /*
864 * Peek data to get the option type as well as length and segmentsLeft field
865 */
866 uint32_t size = copyP->GetSize ();
867 uint8_t *data = new uint8_t[size];
868 copyP->CopyData (data, size);
869
870 uint8_t optionType = 0;
871 optionType = *(data);
872
873 if (optionType == 3)
874 {
875 Ptr<dsr::DsrOptions> dsrOption;
876 DsrOptionHeader dsrOptionHeader;
877 uint8_t errorType = *(data + 2);
878
879 if (errorType == 1) // This is the Route Error Option
880 {
882 copyP->RemoveHeader (rerr);
883 NS_ASSERT (copyP->GetSize () == 0);
884
886 newUnreach.SetErrorType (1);
887 newUnreach.SetErrorSrc (rerr.GetErrorSrc ());
888 newUnreach.SetUnreachNode (rerr.GetUnreachNode ());
889 newUnreach.SetErrorDst (rerr.GetErrorDst ());
890 newUnreach.SetSalvage (rerr.GetSalvage ()); // Set the value about whether to salvage a packet or not
891
892 DsrOptionSRHeader sourceRoute;
893 std::vector<Ipv4Address> errorRoute = toDst.GetVector ();
894 sourceRoute.SetNodesAddress (errorRoute);
896 if (m_routeCache->IsLinkCache ())
897 {
898 m_routeCache->UseExtends (errorRoute);
899 }
900 sourceRoute.SetSegmentsLeft ((errorRoute.size () - 2));
901 uint8_t salvage = 0;
902 sourceRoute.SetSalvage (salvage);
903 Ipv4Address nextHop = SearchNextHop (m_mainAddress, errorRoute); // Get the next hop address
904
905 if (nextHop == "0.0.0.0")
906 {
907 PacketNewRoute (dsrPacket, m_mainAddress, destination, protocol);
908 return;
909 }
910
911 SetRoute (nextHop, m_mainAddress);
912 uint8_t length = (sourceRoute.GetLength () + newUnreach.GetLength ());
913 dsrRoutingHeader.SetNextHeader (protocol);
914 dsrRoutingHeader.SetMessageType (1);
915 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress));
916 dsrRoutingHeader.SetDestId (255);
917 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 4);
918 dsrRoutingHeader.AddDsrOption (newUnreach);
919 dsrRoutingHeader.AddDsrOption (sourceRoute);
920
921 Ptr<Packet> newPacket = Create<Packet> ();
922 newPacket->AddHeader (dsrRoutingHeader); // Add the routing header with rerr and sourceRoute attached to it
923 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
924 m_ipv4Route->SetOutputDevice (dev);
925
927 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
928 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
929 NS_LOG_LOGIC ("Will be inserting into priority queue number: " << priority);
930
931 //m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
932
934 DsrNetworkQueueEntry newEntry (newPacket, m_mainAddress, nextHop, Simulator::Now (), m_ipv4Route);
935
936 if (dsrNetworkQueue->Enqueue (newEntry))
937 {
938 Scheduler (priority);
939 }
940 else
941 {
942 NS_LOG_INFO ("Packet dropped as dsr network queue is full");
943 }
944 }
945 }
946 else
947 {
948 dsrRoutingHeader.SetNextHeader (protocol);
949 dsrRoutingHeader.SetMessageType (2);
950 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress));
951 dsrRoutingHeader.SetDestId (GetIDfromIP (destination));
952
953 DsrOptionSRHeader sourceRoute;
954 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the route from the route entry we found
955 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); // Get the next hop address for the route
956 if (nextHop == "0.0.0.0")
957 {
958 PacketNewRoute (dsrPacket, m_mainAddress, destination, protocol);
959 return;
960 }
961 uint8_t salvage = 0;
962 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the source route header of the packet
963 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segmentsLeft field will indicate the hops to go
964 sourceRoute.SetSalvage (salvage);
966 if (m_routeCache->IsLinkCache ())
967 {
968 m_routeCache->UseExtends (nodeList);
969 }
970 uint8_t length = sourceRoute.GetLength ();
971 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
972 dsrRoutingHeader.AddDsrOption (sourceRoute);
973 cleanP->AddHeader (dsrRoutingHeader);
974 Ptr<const Packet> mtP = cleanP->Copy ();
975 // Put the data packet in the maintenance queue for data packet retransmission
976 DsrMaintainBuffEntry newEntry (/*packet=*/ mtP,
977 /*ourAddress=*/ m_mainAddress,
978 /*nextHop=*/ nextHop,
979 /*src=*/ m_mainAddress,
980 /*dst=*/ destination,
981 /*ackId=*/ 0,
982 /*segsLeft=*/ nodeList.size () - 2,
983 /*expire=*/ m_maxMaintainTime);
984 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the packet the the maintenance buffer
985 if (result)
986 {
987 NetworkKey networkKey;
988 networkKey.m_ackId = newEntry.GetAckId ();
989 networkKey.m_ourAdd = newEntry.GetOurAdd ();
990 networkKey.m_nextHop = newEntry.GetNextHop ();
991 networkKey.m_source = newEntry.GetSrc ();
992 networkKey.m_destination = newEntry.GetDst ();
993
994 PassiveKey passiveKey;
995 passiveKey.m_ackId = 0;
996 passiveKey.m_source = newEntry.GetSrc ();
997 passiveKey.m_destination = newEntry.GetDst ();
998 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
999
1000 LinkKey linkKey;
1001 linkKey.m_source = newEntry.GetSrc ();
1002 linkKey.m_destination = newEntry.GetDst ();
1003 linkKey.m_ourAdd = newEntry.GetOurAdd ();
1004 linkKey.m_nextHop = newEntry.GetNextHop ();
1005
1006 m_addressForwardCnt[networkKey] = 0;
1007 m_passiveCnt[passiveKey] = 0;
1008 m_linkCnt[linkKey] = 0;
1009
1010 if (m_linkAck)
1011 {
1012 ScheduleLinkPacketRetry (newEntry, protocol);
1013 }
1014 else
1015 {
1016 NS_LOG_LOGIC ("Not using link acknowledgment");
1017 if (nextHop != destination)
1018 {
1019 SchedulePassivePacketRetry (newEntry, protocol);
1020 }
1021 else
1022 {
1023 // This is the first network retry
1024 ScheduleNetworkPacketRetry (newEntry, true, protocol);
1025 }
1026 }
1027 }
1028 // we need to suspend the normal timer that checks the send buffer
1029 // until we are done sending packets
1031 {
1033 }
1035 return;
1036 }
1037 }
1038 else
1039 {
1040 ++i;
1041 }
1042 }
1043 //after going through the entire send buffer and send all packets found route,
1044 //we need to resume the timer if it has been suspended
1046 {
1047 NS_LOG_DEBUG ("Resume the send buffer timer");
1049 }
1050}
1051
1052bool DsrRouting::PromiscReceive (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, const Address &from,
1053 const Address &to, NetDevice::PacketType packetType)
1054{
1055
1056 if (protocol != Ipv4L3Protocol::PROT_NUMBER)
1057 {
1058 return false;
1059 }
1060 // Remove the ipv4 header here
1061 Ptr<Packet> pktMinusIpHdr = packet->Copy ();
1062 Ipv4Header ipv4Header;
1063 pktMinusIpHdr->RemoveHeader (ipv4Header);
1064
1065 if (ipv4Header.GetProtocol () != DsrRouting::PROT_NUMBER)
1066 {
1067 return false;
1068 }
1069 // Remove the dsr routing header here
1070 Ptr<Packet> pktMinusDsrHdr = pktMinusIpHdr->Copy ();
1071 DsrRoutingHeader dsrRouting;
1072 pktMinusDsrHdr->RemoveHeader (dsrRouting);
1073
1074 /*
1075 * Message type 2 means the data packet, we will further process the data
1076 * packet for delivery notification, safely ignore control packet
1077 * Another check here is our own address, if this is the data destinated for us,
1078 * process it further, otherwise, just ignore it
1079 */
1080 Ipv4Address ourAddress = m_ipv4->GetAddress (1, 0).GetLocal ();
1081 // check if the message type is 2 and if the ipv4 address matches
1082 if (dsrRouting.GetMessageType () == 2 && ourAddress == m_mainAddress)
1083 {
1084 NS_LOG_DEBUG ("data packet receives " << packet->GetUid ());
1085 Ipv4Address sourceIp = GetIPfromID (dsrRouting.GetSourceId ());
1086 Ipv4Address destinationIp = GetIPfromID ( dsrRouting.GetDestId ());
1088 Ipv4Address previousHop = GetIPfromMAC (Mac48Address::ConvertFrom (from));
1089
1090 Ptr<Packet> p = Create<Packet> ();
1091 // Here the segments left value need to plus one to check the earlier hop maintain buffer entry
1092 DsrMaintainBuffEntry newEntry;
1093 newEntry.SetPacket (p);
1094 newEntry.SetSrc (sourceIp);
1095 newEntry.SetDst (destinationIp);
1097 newEntry.SetOurAdd (previousHop);
1098 newEntry.SetNextHop (ourAddress);
1100 Ptr<Node> node = GetNodeWithAddress (previousHop);
1101 NS_LOG_DEBUG ("The previous node " << previousHop);
1102
1104 dsr->CancelLinkPacketTimer (newEntry);
1105 }
1106
1107 // Receive only IP packets and packets destined for other hosts
1108 if (packetType == NetDevice::PACKET_OTHERHOST)
1109 {
1110 //just to minimize debug output
1111 NS_LOG_INFO (this << from << to << packetType << *pktMinusIpHdr);
1112
1113 uint8_t offset = dsrRouting.GetDsrOptionsOffset (); // Get the offset for option header, 4 bytes in this case
1114 uint8_t nextHeader = dsrRouting.GetNextHeader ();
1115 uint32_t sourceId = dsrRouting.GetSourceId ();
1116 Ipv4Address source = GetIPfromID (sourceId);
1117
1118 // This packet is used to peek option type
1119 pktMinusIpHdr->RemoveAtStart (offset);
1120 /*
1121 * Peek data to get the option type as well as length and segmentsLeft field
1122 */
1123 uint32_t size = pktMinusIpHdr->GetSize ();
1124 uint8_t *data = new uint8_t[size];
1125 pktMinusIpHdr->CopyData (data, size);
1126 uint8_t optionType = 0;
1127 optionType = *(data);
1128
1129 Ptr<dsr::DsrOptions> dsrOption;
1130
1131 if (optionType == 96) // This is the source route option
1132 {
1133 Ipv4Address promiscSource = GetIPfromMAC (Mac48Address::ConvertFrom (from));
1134 dsrOption = GetOption (optionType); // Get the relative DSR option and demux to the process function
1136 " DSR node " << m_mainAddress <<
1137 " overhearing packet PID: " << pktMinusIpHdr->GetUid () <<
1138 " from " << promiscSource <<
1139 " to " << GetIPfromMAC (Mac48Address::ConvertFrom (to)) <<
1140 " with source IP " << ipv4Header.GetSource () <<
1141 " and destination IP " << ipv4Header.GetDestination () <<
1142 " and packet : " << *pktMinusDsrHdr);
1143
1144 bool isPromisc = true; // Set the boolean value isPromisc as true
1145 dsrOption->Process (pktMinusIpHdr, pktMinusDsrHdr, m_mainAddress, source, ipv4Header, nextHeader, isPromisc, promiscSource);
1146 return true;
1147
1148 }
1149 }
1150 return false;
1151}
1152
1153void
1155 Ipv4Address source,
1156 Ipv4Address destination,
1157 uint8_t protocol)
1158{
1159 NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)protocol);
1160 // Look up routes for the specific destination
1161 DsrRouteCacheEntry toDst;
1162 bool findRoute = m_routeCache->LookupRoute (destination, toDst);
1163 // Queue the packet if there is no route pre-existing
1164 if (!findRoute)
1165 {
1167 << " " << m_mainAddress << " there is no route for this packet, queue the packet");
1168
1169 Ptr<Packet> p = packet->Copy ();
1170 DsrSendBuffEntry newEntry (p, destination, m_sendBufferTimeout, protocol); // Create a new entry for send buffer
1171 bool result = m_sendBuffer.Enqueue (newEntry); // Enqueue the packet in send buffer
1172 if (result)
1173 {
1175 << " Add packet PID: " << packet->GetUid () << " to queue. Packet: " << *packet);
1176
1177 NS_LOG_LOGIC ("Send RREQ to" << destination);
1178 if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ()) && (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ()))
1179 {
1180 /*
1181 * Call the send request function, it will update the request table entry and ttl there
1182 */
1183 SendInitialRequest (source, destination, protocol);
1184 }
1185 }
1186 }
1187 else
1188 {
1189 Ptr<Packet> cleanP = packet->Copy ();
1190 DsrRoutingHeader dsrRoutingHeader;
1191 dsrRoutingHeader.SetNextHeader (protocol);
1192 dsrRoutingHeader.SetMessageType (2);
1193 dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
1194 dsrRoutingHeader.SetDestId (GetIDfromIP (destination));
1195
1196 DsrOptionSRHeader sourceRoute;
1197 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the route from the route entry we found
1198 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); // Get the next hop address for the route
1199 if (nextHop == "0.0.0.0")
1200 {
1201 PacketNewRoute (cleanP, source, destination, protocol);
1202 return;
1203 }
1204 uint8_t salvage = 0;
1205 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the source route header of the packet
1207 if (m_routeCache->IsLinkCache ())
1208 {
1209 m_routeCache->UseExtends (nodeList);
1210 }
1211 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segmentsLeft field will indicate the hops to go
1212 sourceRoute.SetSalvage (salvage);
1213
1214 uint8_t length = sourceRoute.GetLength ();
1215 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
1216 dsrRoutingHeader.AddDsrOption (sourceRoute);
1217 cleanP->AddHeader (dsrRoutingHeader);
1218 Ptr<const Packet> mtP = cleanP->Copy ();
1219 SetRoute (nextHop, m_mainAddress);
1220 // Put the data packet in the maintenance queue for data packet retransmission
1221 DsrMaintainBuffEntry newEntry (/*packet=*/ mtP,
1222 /*ourAddress=*/ m_mainAddress,
1223 /*nextHop=*/ nextHop,
1224 /*src=*/ source,
1225 /*dst=*/ destination,
1226 /*ackId=*/ 0,
1227 /*segsLeft=*/ nodeList.size () - 2,
1228 /*expire=*/ m_maxMaintainTime);
1229 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the packet the the maintenance buffer
1230
1231 if (result)
1232 {
1233 NetworkKey networkKey;
1234 networkKey.m_ackId = newEntry.GetAckId ();
1235 networkKey.m_ourAdd = newEntry.GetOurAdd ();
1236 networkKey.m_nextHop = newEntry.GetNextHop ();
1237 networkKey.m_source = newEntry.GetSrc ();
1238 networkKey.m_destination = newEntry.GetDst ();
1239
1240 PassiveKey passiveKey;
1241 passiveKey.m_ackId = 0;
1242 passiveKey.m_source = newEntry.GetSrc ();
1243 passiveKey.m_destination = newEntry.GetDst ();
1244 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
1245
1246 LinkKey linkKey;
1247 linkKey.m_source = newEntry.GetSrc ();
1248 linkKey.m_destination = newEntry.GetDst ();
1249 linkKey.m_ourAdd = newEntry.GetOurAdd ();
1250 linkKey.m_nextHop = newEntry.GetNextHop ();
1251
1252 m_addressForwardCnt[networkKey] = 0;
1253 m_passiveCnt[passiveKey] = 0;
1254 m_linkCnt[linkKey] = 0;
1255
1256 if (m_linkAck)
1257 {
1258 ScheduleLinkPacketRetry (newEntry, protocol);
1259 }
1260 else
1261 {
1262 NS_LOG_LOGIC ("Not using link acknowledgment");
1263 if (nextHop != destination)
1264 {
1265 SchedulePassivePacketRetry (newEntry, protocol);
1266 }
1267 else
1268 {
1269 // This is the first network retry
1270 ScheduleNetworkPacketRetry (newEntry, true, protocol);
1271 }
1272 }
1273 }
1274 }
1275}
1276
1277void
1278DsrRouting::SendUnreachError (Ipv4Address unreachNode, Ipv4Address destination, Ipv4Address originalDst, uint8_t salvage, uint8_t protocol)
1279{
1280 NS_LOG_FUNCTION (this << unreachNode << destination << originalDst << (uint32_t)salvage << (uint32_t)protocol);
1281 DsrRoutingHeader dsrRoutingHeader;
1282 dsrRoutingHeader.SetNextHeader (protocol);
1283 dsrRoutingHeader.SetMessageType (1);
1284 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress));
1285 dsrRoutingHeader.SetDestId (GetIDfromIP (destination));
1286
1287 DsrOptionRerrUnreachHeader rerrUnreachHeader;
1288 rerrUnreachHeader.SetErrorType (1);
1289 rerrUnreachHeader.SetErrorSrc (m_mainAddress);
1290 rerrUnreachHeader.SetUnreachNode (unreachNode);
1291 rerrUnreachHeader.SetErrorDst (destination);
1292 rerrUnreachHeader.SetOriginalDst (originalDst);
1293 rerrUnreachHeader.SetSalvage (salvage); // Set the value about whether to salvage a packet or not
1294 uint8_t rerrLength = rerrUnreachHeader.GetLength ();
1295
1296
1297 DsrRouteCacheEntry toDst;
1298 bool findRoute = m_routeCache->LookupRoute (destination, toDst);
1299 // Queue the packet if there is no route pre-existing
1300 Ptr<Packet> newPacket = Create<Packet> ();
1301 if (!findRoute)
1302 {
1303 if (destination == m_mainAddress)
1304 {
1305 NS_LOG_INFO ("We are the error source, send request to original dst " << originalDst);
1306 // Send error request message if we are the source node
1307 SendErrorRequest (rerrUnreachHeader, protocol);
1308 }
1309 else
1310 {
1312 << " " << m_mainAddress << " there is no route for this packet, queue the packet");
1313
1314 dsrRoutingHeader.SetPayloadLength (rerrLength + 2);
1315 dsrRoutingHeader.AddDsrOption (rerrUnreachHeader);
1316 newPacket->AddHeader (dsrRoutingHeader);
1317 Ptr<Packet> p = newPacket->Copy ();
1318 // Save the error packet in the error buffer
1319 DsrErrorBuffEntry newEntry (p, destination, m_mainAddress, unreachNode, m_sendBufferTimeout, protocol);
1320 bool result = m_errorBuffer.Enqueue (newEntry); // Enqueue the packet in send buffer
1321 if (result)
1322 {
1324 << " Add packet PID: " << p->GetUid () << " to queue. Packet: " << *p);
1325 NS_LOG_LOGIC ("Send RREQ to" << destination);
1326 if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ()) && (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ()))
1327 {
1328 NS_LOG_DEBUG ("When there is no existing route request for " << destination << ", initialize one");
1329 /*
1330 * Call the send request function, it will update the request table entry and ttl there
1331 */
1332 SendInitialRequest (m_mainAddress, destination, protocol);
1333 }
1334 }
1335 }
1336 }
1337 else
1338 {
1339 std::vector<Ipv4Address> nodeList = toDst.GetVector ();
1340 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList);
1341 if (nextHop == "0.0.0.0")
1342 {
1343 NS_LOG_DEBUG ("The route is not right");
1344 PacketNewRoute (newPacket, m_mainAddress, destination, protocol);
1345 return;
1346 }
1347 DsrOptionSRHeader sourceRoute;
1348 sourceRoute.SetNodesAddress (nodeList);
1350 if (m_routeCache->IsLinkCache ())
1351 {
1352 m_routeCache->UseExtends (nodeList);
1353 }
1354 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2));
1355 uint8_t srLength = sourceRoute.GetLength ();
1356 uint8_t length = (srLength + rerrLength);
1357
1358 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 4);
1359 dsrRoutingHeader.AddDsrOption (rerrUnreachHeader);
1360 dsrRoutingHeader.AddDsrOption (sourceRoute);
1361 newPacket->AddHeader (dsrRoutingHeader);
1362
1363 SetRoute (nextHop, m_mainAddress);
1364 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
1365 m_ipv4Route->SetOutputDevice (dev);
1366 NS_LOG_INFO ("Send the packet to the next hop address " << nextHop << " from " << m_mainAddress << " with the size " << newPacket->GetSize ());
1367
1369 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
1370 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
1371 NS_LOG_DEBUG ("Will be inserting into priority queue " << dsrNetworkQueue << " number: " << priority);
1372
1373 //m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
1374
1376 DsrNetworkQueueEntry newEntry (newPacket, m_mainAddress, nextHop, Simulator::Now (), m_ipv4Route);
1377
1378 if (dsrNetworkQueue->Enqueue (newEntry))
1379 {
1380 Scheduler (priority);
1381 }
1382 else
1383 {
1384 NS_LOG_INFO ("Packet dropped as dsr network queue is full");
1385 }
1386 }
1387}
1388
1389void
1391 DsrOptionSRHeader &sourceRoute,
1392 Ipv4Address nextHop,
1393 uint8_t protocol,
1394 Ptr<Ipv4Route> route)
1395{
1396 NS_LOG_FUNCTION (this << rerr << sourceRoute << nextHop << (uint32_t)protocol << route);
1397 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
1398 DsrRoutingHeader dsrRoutingHeader;
1399 dsrRoutingHeader.SetNextHeader (protocol);
1400 dsrRoutingHeader.SetMessageType (1);
1401 dsrRoutingHeader.SetSourceId (GetIDfromIP (rerr.GetErrorSrc ()));
1402 dsrRoutingHeader.SetDestId (GetIDfromIP (rerr.GetErrorDst ()));
1403
1404 uint8_t length = (sourceRoute.GetLength () + rerr.GetLength ());
1405 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 4);
1406 dsrRoutingHeader.AddDsrOption (rerr);
1407 dsrRoutingHeader.AddDsrOption (sourceRoute);
1408 Ptr<Packet> packet = Create<Packet> ();
1409 packet->AddHeader (dsrRoutingHeader);
1410 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
1411 route->SetOutputDevice (dev);
1412
1414 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
1415 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
1416 NS_LOG_DEBUG ("Will be inserting into priority queue " << dsrNetworkQueue << " number: " << priority);
1417
1418 //m_downTarget (packet, m_mainAddress, nextHop, GetProtocolNumber (), route);
1419
1421 DsrNetworkQueueEntry newEntry (packet, m_mainAddress, nextHop, Simulator::Now (), route);
1422
1423 if (dsrNetworkQueue->Enqueue (newEntry))
1424 {
1425 Scheduler (priority);
1426 }
1427 else
1428 {
1429 NS_LOG_INFO ("Packet dropped as dsr network queue is full");
1430 }
1431}
1432
1433void
1435 Ipv4Address source,
1436 Ipv4Address destination,
1437 uint8_t protocol,
1438 Ptr<Ipv4Route> route)
1439{
1440 NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)protocol << route);
1441 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
1442
1443 if (protocol == 1)
1444 {
1445 NS_LOG_INFO ("Drop packet. Not handling ICMP packet for now");
1446 }
1447 else
1448 {
1449 // Look up routes for the specific destination
1450 DsrRouteCacheEntry toDst;
1451 bool findRoute = m_routeCache->LookupRoute (destination, toDst);
1452 // Queue the packet if there is no route pre-existing
1453 if (!findRoute)
1454 {
1456 << " " << m_mainAddress << " there is no route for this packet, queue the packet");
1457
1458 Ptr<Packet> p = packet->Copy ();
1459 DsrSendBuffEntry newEntry (p, destination, m_sendBufferTimeout, protocol); // Create a new entry for send buffer
1460 bool result = m_sendBuffer.Enqueue (newEntry); // Enqueue the packet in send buffer
1461 if (result)
1462 {
1464 << " Add packet PID: " << packet->GetUid () << " to send buffer. Packet: " << *packet);
1465 // Only when there is no existing route request timer when new route request is scheduled
1466 if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ()) && (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ()))
1467 {
1468 /*
1469 * Call the send request function, it will update the request table entry and ttl value
1470 */
1471 NS_LOG_LOGIC ("Send initial RREQ to " << destination);
1472 SendInitialRequest (source, destination, protocol);
1473 }
1474 else
1475 {
1476 NS_LOG_LOGIC ("There is existing route request timer with request count " << m_rreqTable->GetRreqCnt (destination));
1477 }
1478 }
1479 }
1480 else
1481 {
1482 Ptr<Packet> cleanP = packet->Copy ();
1483 DsrRoutingHeader dsrRoutingHeader;
1484 dsrRoutingHeader.SetNextHeader (protocol);
1485 dsrRoutingHeader.SetMessageType (2);
1486 dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
1487 dsrRoutingHeader.SetDestId (GetIDfromIP (destination));
1488
1489 DsrOptionSRHeader sourceRoute;
1490 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the route from the route entry we found
1491 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); // Get the next hop address for the route
1492 if (nextHop == "0.0.0.0")
1493 {
1494 PacketNewRoute (cleanP, source, destination, protocol);
1495 return;
1496 }
1497 uint8_t salvage = 0;
1498 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the source route header of the packet
1500 if (m_routeCache->IsLinkCache ())
1501 {
1502 m_routeCache->UseExtends (nodeList);
1503 }
1504 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segmentsLeft field will indicate the hops to go
1505 sourceRoute.SetSalvage (salvage);
1506
1507 uint8_t length = sourceRoute.GetLength ();
1508
1509 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
1510 dsrRoutingHeader.AddDsrOption (sourceRoute);
1511 cleanP->AddHeader (dsrRoutingHeader);
1512
1513 Ptr<const Packet> mtP = cleanP->Copy ();
1514 NS_LOG_DEBUG ("maintain packet size " << cleanP->GetSize ());
1515 // Put the data packet in the maintenance queue for data packet retransmission
1516 DsrMaintainBuffEntry newEntry (/*packet=*/ mtP,
1517 /*ourAddress=*/ m_mainAddress,
1518 /*nextHop=*/ nextHop,
1519 /*src=*/ source,
1520 /*dst=*/ destination,
1521 /*ackId=*/ 0,
1522 /*segsLeft=*/ nodeList.size () - 2,
1523 /*expire=*/ m_maxMaintainTime);
1524 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the packet the the maintenance buffer
1525 if (result)
1526 {
1527 NetworkKey networkKey;
1528 networkKey.m_ackId = newEntry.GetAckId ();
1529 networkKey.m_ourAdd = newEntry.GetOurAdd ();
1530 networkKey.m_nextHop = newEntry.GetNextHop ();
1531 networkKey.m_source = newEntry.GetSrc ();
1532 networkKey.m_destination = newEntry.GetDst ();
1533
1534 PassiveKey passiveKey;
1535 passiveKey.m_ackId = 0;
1536 passiveKey.m_source = newEntry.GetSrc ();
1537 passiveKey.m_destination = newEntry.GetDst ();
1538 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
1539
1540 LinkKey linkKey;
1541 linkKey.m_source = newEntry.GetSrc ();
1542 linkKey.m_destination = newEntry.GetDst ();
1543 linkKey.m_ourAdd = newEntry.GetOurAdd ();
1544 linkKey.m_nextHop = newEntry.GetNextHop ();
1545
1546 m_addressForwardCnt[networkKey] = 0;
1547 m_passiveCnt[passiveKey] = 0;
1548 m_linkCnt[linkKey] = 0;
1549
1550 if (m_linkAck)
1551 {
1552 ScheduleLinkPacketRetry (newEntry, protocol);
1553 }
1554 else
1555 {
1556 NS_LOG_LOGIC ("Not using link acknowledgment");
1557 if (nextHop != destination)
1558 {
1559 SchedulePassivePacketRetry (newEntry, protocol);
1560 }
1561 else
1562 {
1563 // This is the first network retry
1564 ScheduleNetworkPacketRetry (newEntry, true, protocol);
1565 }
1566 }
1567 }
1568
1569 if (m_sendBuffer.GetSize () != 0 && m_sendBuffer.Find (destination))
1570 {
1571 // Try to send packet from *previously* queued entries from send buffer if any
1573 &DsrRouting::SendPacketFromBuffer, this, sourceRoute, nextHop, protocol);
1574 }
1575 }
1576 }
1577}
1578
1579uint16_t
1581{
1582 NS_LOG_FUNCTION (this << packet << nextHop);
1583 // This packet is used to peek option type
1584 Ptr<Packet> dsrP = packet->Copy ();
1585 Ptr<Packet> tmpP = packet->Copy ();
1586
1587 DsrRoutingHeader dsrRoutingHeader;
1588 dsrP->RemoveHeader (dsrRoutingHeader); // Remove the DSR header in whole
1589 uint8_t protocol = dsrRoutingHeader.GetNextHeader ();
1590 uint32_t sourceId = dsrRoutingHeader.GetSourceId ();
1591 uint32_t destinationId = dsrRoutingHeader.GetDestId ();
1592 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
1593 tmpP->RemoveAtStart (offset); // Here the processed size is 8 bytes, which is the fixed sized extension header
1594
1595 // Get the number of routers' address field
1596 uint8_t buf[2];
1597 tmpP->CopyData (buf, sizeof(buf));
1598 uint8_t numberAddress = (buf[1] - 2) / 4;
1599 DsrOptionSRHeader sourceRoute;
1600 sourceRoute.SetNumberAddress (numberAddress);
1601 tmpP->RemoveHeader (sourceRoute); // this is a clean packet without any dsr involved headers
1602
1603 DsrOptionAckReqHeader ackReq;
1604 m_ackId = m_routeCache->CheckUniqueAckId (nextHop);
1605 ackReq.SetAckId (m_ackId);
1606 uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ());
1607 DsrRoutingHeader newDsrRoutingHeader;
1608 newDsrRoutingHeader.SetNextHeader (protocol);
1609 newDsrRoutingHeader.SetMessageType (2);
1610 newDsrRoutingHeader.SetSourceId (sourceId);
1611 newDsrRoutingHeader.SetDestId (destinationId);
1612 newDsrRoutingHeader.SetPayloadLength (length + 4);
1613 newDsrRoutingHeader.AddDsrOption (sourceRoute);
1614 newDsrRoutingHeader.AddDsrOption (ackReq);
1615 dsrP->AddHeader (newDsrRoutingHeader);
1616 // give the dsrP value to packet and then return
1617 packet = dsrP;
1618 return m_ackId;
1619}
1620
1621void
1622DsrRouting::SendPacket (Ptr<Packet> packet, Ipv4Address source, Ipv4Address nextHop, uint8_t protocol)
1623{
1624 NS_LOG_FUNCTION (this << packet << source << nextHop << (uint32_t)protocol);
1625 // Send out the data packet
1626 m_ipv4Route = SetRoute (nextHop, m_mainAddress);
1627 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
1628 m_ipv4Route->SetOutputDevice (dev);
1629
1631 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
1632 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
1633 NS_LOG_INFO ("Will be inserting into priority queue number: " << priority);
1634
1635 //m_downTarget (packet, source, nextHop, GetProtocolNumber (), m_ipv4Route);
1636
1638 DsrNetworkQueueEntry newEntry (packet, source, nextHop, Simulator::Now (), m_ipv4Route);
1639
1640 if (dsrNetworkQueue->Enqueue (newEntry))
1641 {
1642 Scheduler (priority);
1643 }
1644 else
1645 {
1646 NS_LOG_INFO ("Packet dropped as dsr network queue is full");
1647 }
1648}
1649
1650void
1652{
1653 NS_LOG_FUNCTION (this);
1654 PriorityScheduler (priority, true);
1655}
1656
1657void
1658DsrRouting::PriorityScheduler (uint32_t priority, bool continueWithFirst)
1659{
1660 NS_LOG_FUNCTION (this << priority << continueWithFirst);
1661 uint32_t numPriorities;
1662 if (continueWithFirst)
1663 {
1664 numPriorities = 0;
1665 }
1666 else
1667 {
1668 numPriorities = priority;
1669 }
1670 // priorities ranging from 0 to m_numPriorityQueues, with 0 as the highest priority
1671 for (uint32_t i = priority; numPriorities < m_numPriorityQueues; numPriorities++)
1672 {
1673 std::map<uint32_t, Ptr<DsrNetworkQueue> >::iterator q = m_priorityQueue.find (i);
1674 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = q->second;
1675 uint32_t queueSize = dsrNetworkQueue->GetSize ();
1676 if (queueSize == 0)
1677 {
1678 if ((i == (m_numPriorityQueues - 1)) && continueWithFirst)
1679 {
1680 i = 0;
1681 }
1682 else
1683 {
1684 i++;
1685 }
1686 }
1687 else
1688 {
1689 uint32_t totalQueueSize = 0;
1690 for (std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator j = m_priorityQueue.begin (); j != m_priorityQueue.end (); j++)
1691 {
1692 NS_LOG_INFO ("The size of the network queue for " << j->first << " is " << j->second->GetSize ());
1693 totalQueueSize += j->second->GetSize ();
1694 NS_LOG_INFO ("The total network queue size is " << totalQueueSize);
1695 }
1696 if (totalQueueSize > 5)
1697 {
1698 // Here the queue size is larger than 5, we need to increase the retransmission timer for each packet in the network queue
1700 }
1701 DsrNetworkQueueEntry newEntry;
1702 dsrNetworkQueue->Dequeue (newEntry);
1703 if (SendRealDown (newEntry))
1704 {
1705 NS_LOG_LOGIC ("Packet sent by Dsr. Calling PriorityScheduler after some time");
1706 // packet was successfully sent down. call scheduler after some time
1708 &DsrRouting::PriorityScheduler,this, i, false);
1709 }
1710 else
1711 {
1712 // packet was dropped by Dsr. Call scheduler immediately so that we can
1713 // send another packet immediately.
1714 NS_LOG_LOGIC ("Packet dropped by Dsr. Calling PriorityScheduler immediately");
1716 }
1717
1718 if ((i == (m_numPriorityQueues - 1)) && continueWithFirst)
1719 {
1720 i = 0;
1721 }
1722 else
1723 {
1724 i++;
1725 }
1726 }
1727 }
1728}
1729
1730void
1732{
1733 NS_LOG_FUNCTION (this);
1734 // We may want to get the queue first and then we need to save a vector of the entries here and then find
1736 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
1737 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
1738
1739 std::vector<DsrNetworkQueueEntry> newNetworkQueue = dsrNetworkQueue->GetQueue ();
1740 for (std::vector<DsrNetworkQueueEntry>::iterator i = newNetworkQueue.begin (); i != newNetworkQueue.end (); i++)
1741 {
1742 Ipv4Address nextHop = i->GetNextHopAddress ();
1743 for (std::map<NetworkKey, Timer>::iterator j = m_addressForwardTimer.begin (); j != m_addressForwardTimer.end (); j++)
1744 {
1745 if (nextHop == j->first.m_nextHop)
1746 {
1747 NS_LOG_DEBUG ("The network delay left is " << j->second.GetDelayLeft ());
1748 j->second.SetDelay (j->second.GetDelayLeft () + m_retransIncr);
1749 }
1750 }
1751 }
1752}
1753
1754bool
1756{
1757 NS_LOG_FUNCTION (this);
1758 Ipv4Address source = newEntry.GetSourceAddress ();
1759 Ipv4Address nextHop = newEntry.GetNextHopAddress ();
1760 Ptr<Packet> packet = newEntry.GetPacket ()->Copy ();
1761 Ptr<Ipv4Route> route = newEntry.GetIpv4Route ();
1762 m_downTarget (packet, source, nextHop, GetProtocolNumber (), route);
1763 return true;
1764}
1765
1766void
1767DsrRouting::SendPacketFromBuffer (DsrOptionSRHeader const &sourceRoute, Ipv4Address nextHop, uint8_t protocol)
1768{
1769 NS_LOG_FUNCTION (this << nextHop << (uint32_t)protocol);
1770 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
1771
1772 // Reconstruct the route and Retransmit the data packet
1773 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
1774 Ipv4Address destination = nodeList.back ();
1775 Ipv4Address source = nodeList.front (); // Get the source address
1776 NS_LOG_INFO ("The nexthop address " << nextHop << " the source " << source << " the destination " << destination);
1777 /*
1778 * Here we try to find data packet from send buffer, if packet with this destination found, send it out
1779 */
1780 if (m_sendBuffer.Find (destination))
1781 {
1782 NS_LOG_DEBUG ("destination over here " << destination);
1783
1785 if (m_routeCache->IsLinkCache ())
1786 {
1787 m_routeCache->UseExtends (nodeList);
1788 }
1789 DsrSendBuffEntry entry;
1790 if (m_sendBuffer.Dequeue (destination, entry))
1791 {
1792 Ptr<Packet> packet = entry.GetPacket ()->Copy ();
1793 Ptr<Packet> p = packet->Copy (); // get a copy of the packet
1794 // Set the source route option
1795 DsrRoutingHeader dsrRoutingHeader;
1796 dsrRoutingHeader.SetNextHeader (protocol);
1797 dsrRoutingHeader.SetMessageType (2);
1798 dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
1799 dsrRoutingHeader.SetDestId (GetIDfromIP (destination));
1800
1801 uint8_t length = sourceRoute.GetLength ();
1802 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
1803 dsrRoutingHeader.AddDsrOption (sourceRoute);
1804
1805 p->AddHeader (dsrRoutingHeader);
1806
1807 Ptr<const Packet> mtP = p->Copy ();
1808 // Put the data packet in the maintenance queue for data packet retransmission
1809 DsrMaintainBuffEntry newEntry (/*packet=*/ mtP,
1810 /*ourAddress=*/ m_mainAddress,
1811 /*nextHop=*/ nextHop,
1812 /*src=*/ source,
1813 /*dst=*/ destination,
1814 /*ackId=*/ 0,
1815 /*segsLeft=*/ nodeList.size () - 2,
1816 /*expire=*/ m_maxMaintainTime);
1817 bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the packet the the maintenance buffer
1818
1819 if (result)
1820 {
1821 NetworkKey networkKey;
1822 networkKey.m_ackId = newEntry.GetAckId ();
1823 networkKey.m_ourAdd = newEntry.GetOurAdd ();
1824 networkKey.m_nextHop = newEntry.GetNextHop ();
1825 networkKey.m_source = newEntry.GetSrc ();
1826 networkKey.m_destination = newEntry.GetDst ();
1827
1828 PassiveKey passiveKey;
1829 passiveKey.m_ackId = 0;
1830 passiveKey.m_source = newEntry.GetSrc ();
1831 passiveKey.m_destination = newEntry.GetDst ();
1832 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
1833
1834 LinkKey linkKey;
1835 linkKey.m_source = newEntry.GetSrc ();
1836 linkKey.m_destination = newEntry.GetDst ();
1837 linkKey.m_ourAdd = newEntry.GetOurAdd ();
1838 linkKey.m_nextHop = newEntry.GetNextHop ();
1839
1840 m_addressForwardCnt[networkKey] = 0;
1841 m_passiveCnt[passiveKey] = 0;
1842 m_linkCnt[linkKey] = 0;
1843
1844 if (m_linkAck)
1845 {
1846 ScheduleLinkPacketRetry (newEntry, protocol);
1847 }
1848 else
1849 {
1850 NS_LOG_LOGIC ("Not using link acknowledgment");
1851 if (nextHop != destination)
1852 {
1853 SchedulePassivePacketRetry (newEntry, protocol);
1854 }
1855 else
1856 {
1857 // This is the first network retry
1858 ScheduleNetworkPacketRetry (newEntry, true, protocol);
1859 }
1860 }
1861 }
1862
1863 NS_LOG_DEBUG ("send buffer size here and the destination " << m_sendBuffer.GetSize () << " " << destination);
1864 if (m_sendBuffer.GetSize () != 0 && m_sendBuffer.Find (destination))
1865 {
1866 NS_LOG_LOGIC ("Schedule sending the next packet in send buffer");
1868 &DsrRouting::SendPacketFromBuffer, this, sourceRoute, nextHop, protocol);
1869 }
1870 }
1871 else
1872 {
1873 NS_LOG_LOGIC ("All queued packets are out-dated for the destination in send buffer");
1874 }
1875 }
1876 /*
1877 * Here we try to find data packet from send buffer, if packet with this destination found, send it out
1878 */
1879 else if (m_errorBuffer.Find (destination))
1880 {
1881 DsrErrorBuffEntry entry;
1882 if (m_errorBuffer.Dequeue (destination, entry))
1883 {
1884 Ptr<Packet> packet = entry.GetPacket ()->Copy ();
1885 NS_LOG_DEBUG ("The queued packet size " << packet->GetSize ());
1886
1887 DsrRoutingHeader dsrRoutingHeader;
1888 Ptr<Packet> copyP = packet->Copy ();
1889 Ptr<Packet> dsrPacket = packet->Copy ();
1890 dsrPacket->RemoveHeader (dsrRoutingHeader);
1891 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
1892 copyP->RemoveAtStart (offset); // Here the processed size is 8 bytes, which is the fixed sized extension header
1893 /*
1894 * Peek data to get the option type as well as length and segmentsLeft field
1895 */
1896 uint32_t size = copyP->GetSize ();
1897 uint8_t *data = new uint8_t[size];
1898 copyP->CopyData (data, size);
1899
1900 uint8_t optionType = 0;
1901 optionType = *(data);
1902 NS_LOG_DEBUG ("The option type value in send packet " << (uint32_t)optionType);
1903 if (optionType == 3)
1904 {
1905 NS_LOG_DEBUG ("The packet is error packet");
1906 Ptr<dsr::DsrOptions> dsrOption;
1907 DsrOptionHeader dsrOptionHeader;
1908
1909 uint8_t errorType = *(data + 2);
1910 NS_LOG_DEBUG ("The error type");
1911 if (errorType == 1)
1912 {
1913 NS_LOG_DEBUG ("The packet is route error unreach packet");
1915 copyP->RemoveHeader (rerr);
1916 NS_ASSERT (copyP->GetSize () == 0);
1917 uint8_t length = (sourceRoute.GetLength () + rerr.GetLength ());
1918
1919 DsrOptionRerrUnreachHeader newUnreach;
1920 newUnreach.SetErrorType (1);
1921 newUnreach.SetErrorSrc (rerr.GetErrorSrc ());
1922 newUnreach.SetUnreachNode (rerr.GetUnreachNode ());
1923 newUnreach.SetErrorDst (rerr.GetErrorDst ());
1924 newUnreach.SetOriginalDst (rerr.GetOriginalDst ());
1925 newUnreach.SetSalvage (rerr.GetSalvage ()); // Set the value about whether to salvage a packet or not
1926
1927 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
1928 DsrRoutingHeader newRoutingHeader;
1929 newRoutingHeader.SetNextHeader (protocol);
1930 newRoutingHeader.SetMessageType (1);
1931 newRoutingHeader.SetSourceId (GetIDfromIP (rerr.GetErrorSrc ()));
1932 newRoutingHeader.SetDestId (GetIDfromIP (rerr.GetErrorDst ()));
1933 newRoutingHeader.SetPayloadLength (uint16_t (length) + 4);
1934 newRoutingHeader.AddDsrOption (newUnreach);
1935 newRoutingHeader.AddDsrOption (sourceRoute);
1937 if (m_routeCache->IsLinkCache ())
1938 {
1939 m_routeCache->UseExtends (nodeList);
1940 }
1941 SetRoute (nextHop, m_mainAddress);
1942 Ptr<Packet> newPacket = Create<Packet> ();
1943 newPacket->AddHeader (newRoutingHeader); // Add the extension header with rerr and sourceRoute attached to it
1944 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
1945 m_ipv4Route->SetOutputDevice (dev);
1946
1948 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
1949 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
1950 NS_LOG_DEBUG ("Will be inserting into priority queue " << dsrNetworkQueue << " number: " << priority);
1951
1952 //m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
1953
1955 DsrNetworkQueueEntry newEntry (newPacket, m_mainAddress, nextHop, Simulator::Now (), m_ipv4Route);
1956
1957 if (dsrNetworkQueue->Enqueue (newEntry))
1958 {
1959 Scheduler (priority);
1960 }
1961 else
1962 {
1963 NS_LOG_INFO ("Packet dropped as dsr network queue is full");
1964 }
1965 }
1966 }
1967
1968 if (m_errorBuffer.GetSize () != 0 && m_errorBuffer.Find (destination))
1969 {
1970 NS_LOG_LOGIC ("Schedule sending the next packet in error buffer");
1972 &DsrRouting::SendPacketFromBuffer, this, sourceRoute, nextHop, protocol);
1973 }
1974 }
1975 }
1976 else
1977 {
1978 NS_LOG_DEBUG ("Packet not found in either the send or error buffer");
1979 }
1980}
1981
1982bool
1983DsrRouting::PassiveEntryCheck (Ptr<Packet> packet, Ipv4Address source, Ipv4Address destination, uint8_t segsLeft,
1984 uint16_t fragmentOffset, uint16_t identification, bool saveEntry)
1985{
1986 NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)segsLeft);
1987
1988 Ptr<Packet> p = packet->Copy ();
1989 // Here the segments left value need to plus one to check the earlier hop maintain buffer entry
1990 DsrPassiveBuffEntry newEntry;
1991 newEntry.SetPacket (p);
1992 newEntry.SetSource (source);
1993 newEntry.SetDestination (destination);
1994 newEntry.SetIdentification (identification);
1995 newEntry.SetFragmentOffset (fragmentOffset);
1996 newEntry.SetSegsLeft (segsLeft); // We try to make sure the segments left is larger for 1
1997
1998
1999 NS_LOG_DEBUG ("The passive buffer size " << m_passiveBuffer->GetSize ());
2000
2001 if (m_passiveBuffer->AllEqual (newEntry) && (!saveEntry))
2002 {
2003 // The PromiscEqual function will remove the maintain buffer entry if equal value found
2004 // It only compares the source and destination address, ackId, and the segments left value
2005 NS_LOG_DEBUG ("We get the all equal for passive buffer here");
2006
2007 DsrMaintainBuffEntry mbEntry;
2008 mbEntry.SetPacket (p);
2009 mbEntry.SetSrc (source);
2010 mbEntry.SetDst (destination);
2011 mbEntry.SetAckId (0);
2012 mbEntry.SetSegsLeft (segsLeft + 1);
2013
2014 CancelPassivePacketTimer (mbEntry);
2015 return true;
2016 }
2017 if (saveEntry)
2018 {
2020 m_passiveBuffer->Enqueue (newEntry);
2021 }
2022 return false;
2023}
2024
2025bool
2027 uint8_t segsLeft)
2028{
2029 NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)segsLeft);
2030
2031 NS_LOG_DEBUG ("Cancel the passive timer");
2032
2033 Ptr<Packet> p = packet->Copy ();
2034 // Here the segments left value need to plus one to check the earlier hop maintain buffer entry
2035 DsrMaintainBuffEntry newEntry;
2036 newEntry.SetPacket (p);
2037 newEntry.SetSrc (source);
2038 newEntry.SetDst (destination);
2039 newEntry.SetAckId (0);
2040 newEntry.SetSegsLeft (segsLeft + 1);
2041
2042 if (m_maintainBuffer.PromiscEqual (newEntry))
2043 {
2044 // The PromiscEqual function will remove the maintain buffer entry if equal value found
2045 // It only compares the source and destination address, ackId, and the segments left value
2046 CancelPassivePacketTimer (newEntry);
2047 return true;
2048 }
2049 return false;
2050}
2051
2052void
2053DsrRouting::CallCancelPacketTimer (uint16_t ackId, Ipv4Header const& ipv4Header, Ipv4Address realSrc, Ipv4Address realDst)
2054{
2055 NS_LOG_FUNCTION (this << (uint32_t)ackId << ipv4Header << realSrc << realDst);
2056 Ipv4Address sender = ipv4Header.GetDestination ();
2057 Ipv4Address receiver = ipv4Header.GetSource ();
2058 /*
2059 * Create a packet to fill maintenance buffer, not used to compare with maintenance entry
2060 * The reason is ack header doesn't have the original packet copy
2061 */
2062 Ptr<Packet> mainP = Create<Packet> ();
2063 DsrMaintainBuffEntry newEntry (/*packet=*/ mainP,
2064 /*ourAddress=*/ sender,
2065 /*nextHop=*/ receiver,
2066 /*src=*/ realSrc,
2067 /*dst=*/ realDst,
2068 /*ackId=*/ ackId,
2069 /*segsLeft=*/ 0,
2070 /*expire=*/ Simulator::Now ());
2071 CancelNetworkPacketTimer (newEntry); // Only need to cancel network packet timer
2072}
2073
2074void
2076{
2077 NS_LOG_FUNCTION (this);
2081}
2082
2083void
2085{
2086 NS_LOG_FUNCTION (this);
2087 LinkKey linkKey;
2088 linkKey.m_ourAdd = mb.GetOurAdd ();
2089 linkKey.m_nextHop = mb.GetNextHop ();
2090 linkKey.m_source = mb.GetSrc ();
2091 linkKey.m_destination = mb.GetDst ();
2092 /*
2093 * Here we have found the entry for send retries, so we get the value and increase it by one
2094 */
2096 m_linkCnt[linkKey] = 0;
2097 m_linkCnt.erase (linkKey);
2098
2099 // TODO if find the linkkey, we need to remove it
2100
2101 // Find the network acknowledgment timer
2102 std::map<LinkKey, Timer>::const_iterator i =
2103 m_linkAckTimer.find (linkKey);
2104 if (i == m_linkAckTimer.end ())
2105 {
2106 NS_LOG_INFO ("did not find the link timer");
2107 }
2108 else
2109 {
2110 NS_LOG_INFO ("did find the link timer");
2111 /*
2112 * Schedule the packet retry
2113 * Push back the nextHop, source, destination address
2114 */
2115 m_linkAckTimer[linkKey].Cancel ();
2116 if (m_linkAckTimer[linkKey].IsRunning ())
2117 {
2118 NS_LOG_INFO ("Timer not canceled");
2119 }
2120 m_linkAckTimer.erase (linkKey);
2121 }
2122
2123 // Erase the maintenance entry
2124 // yet this does not check the segments left value here
2125 NS_LOG_DEBUG ("The link buffer size " << m_maintainBuffer.GetSize ());
2126 if (m_maintainBuffer.LinkEqual (mb))
2127 {
2128 NS_LOG_INFO ("Link acknowledgment received, remove same maintenance buffer entry");
2129 }
2130}
2131
2132void
2134{
2135 NS_LOG_FUNCTION (this);
2136 NetworkKey networkKey;
2137 networkKey.m_ackId = mb.GetAckId ();
2138 networkKey.m_ourAdd = mb.GetOurAdd ();
2139 networkKey.m_nextHop = mb.GetNextHop ();
2140 networkKey.m_source = mb.GetSrc ();
2141 networkKey.m_destination = mb.GetDst ();
2142 /*
2143 * Here we have found the entry for send retries, so we get the value and increase it by one
2144 */
2145 m_addressForwardCnt[networkKey] = 0;
2146 m_addressForwardCnt.erase (networkKey);
2147
2148 NS_LOG_INFO ("ackId " << mb.GetAckId () << " ourAdd " << mb.GetOurAdd () << " nextHop " << mb.GetNextHop ()
2149 << " source " << mb.GetSrc () << " destination " << mb.GetDst ()
2150 << " segsLeft " << (uint32_t)mb.GetSegsLeft ()
2151 );
2152 // Find the network acknowledgment timer
2153 std::map<NetworkKey, Timer>::const_iterator i =
2154 m_addressForwardTimer.find (networkKey);
2155 if (i == m_addressForwardTimer.end ())
2156 {
2157 NS_LOG_INFO ("did not find the packet timer");
2158 }
2159 else
2160 {
2161 NS_LOG_INFO ("did find the packet timer");
2162 /*
2163 * Schedule the packet retry
2164 * Push back the nextHop, source, destination address
2165 */
2166 m_addressForwardTimer[networkKey].Cancel ();
2167 if (m_addressForwardTimer[networkKey].IsRunning ())
2168 {
2169 NS_LOG_INFO ("Timer not canceled");
2170 }
2171 m_addressForwardTimer.erase (networkKey);
2172 }
2173 // Erase the maintenance entry
2174 // yet this does not check the segments left value here
2176 {
2177 NS_LOG_INFO ("Remove same maintenance buffer entry based on network acknowledgment");
2178 }
2179}
2180
2181void
2183{
2184 NS_LOG_FUNCTION (this);
2185 PassiveKey passiveKey;
2186 passiveKey.m_ackId = 0;
2187 passiveKey.m_source = mb.GetSrc ();
2188 passiveKey.m_destination = mb.GetDst ();
2189 passiveKey.m_segsLeft = mb.GetSegsLeft ();
2190
2191 m_passiveCnt[passiveKey] = 0;
2192 m_passiveCnt.erase (passiveKey);
2193
2194 // Find the passive acknowledgment timer
2195 std::map<PassiveKey, Timer>::const_iterator j =
2196 m_passiveAckTimer.find (passiveKey);
2197 if (j == m_passiveAckTimer.end ())
2198 {
2199 NS_LOG_INFO ("did not find the passive timer");
2200 }
2201 else
2202 {
2203 NS_LOG_INFO ("find the passive timer");
2204 /*
2205 * Cancel passive acknowledgment timer
2206 */
2207 m_passiveAckTimer[passiveKey].Cancel ();
2208 if (m_passiveAckTimer[passiveKey].IsRunning ())
2209 {
2210 NS_LOG_INFO ("Timer not canceled");
2211 }
2212 m_passiveAckTimer.erase (passiveKey);
2213 }
2214}
2215
2216void
2218{
2219 NS_LOG_FUNCTION (this << nextHop << (uint32_t)protocol);
2220
2222 std::vector<Ipv4Address> previousErrorDst;
2223 if (m_maintainBuffer.Dequeue (nextHop, entry))
2224 {
2225 Ipv4Address source = entry.GetSrc ();
2226 Ipv4Address destination = entry.GetDst ();
2227
2228 Ptr<Packet> dsrP = entry.GetPacket ()->Copy ();
2229 Ptr<Packet> p = dsrP->Copy ();
2230 Ptr<Packet> packet = dsrP->Copy ();
2231 DsrRoutingHeader dsrRoutingHeader;
2232 dsrP->RemoveHeader (dsrRoutingHeader); // Remove the dsr header in whole
2233 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
2234 p->RemoveAtStart (offset);
2235
2236 // Get the number of routers' address field
2237 uint8_t buf[2];
2238 p->CopyData (buf, sizeof(buf));
2239 uint8_t numberAddress = (buf[1] - 2) / 4;
2240 NS_LOG_DEBUG ("The number of addresses " << (uint32_t)numberAddress);
2241 DsrOptionSRHeader sourceRoute;
2242 sourceRoute.SetNumberAddress (numberAddress);
2243 p->RemoveHeader (sourceRoute);
2244 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
2245 uint8_t salvage = sourceRoute.GetSalvage ();
2246 Ipv4Address address1 = nodeList[1];
2247 PrintVector (nodeList);
2248
2249 /*
2250 * If the salvage is not 0, use the first address in the route as the error dst in error header
2251 * otherwise use the source of packet as the error destination
2252 */
2253 Ipv4Address errorDst;
2254 if (salvage)
2255 {
2256 errorDst = address1;
2257 }
2258 else
2259 {
2260 errorDst = source;
2261 }
2263 if (std::find (previousErrorDst.begin (), previousErrorDst.end (), destination) == previousErrorDst.end ())
2264 {
2265 NS_LOG_DEBUG ("have not seen this dst before " << errorDst << " in " << previousErrorDst.size ());
2266 SendUnreachError (nextHop, errorDst, destination, salvage, protocol);
2267 previousErrorDst.push_back (errorDst);
2268 }
2269
2270 /*
2271 * Cancel the packet timer and then salvage the data packet
2272 */
2273
2274 CancelPacketAllTimer (entry);
2275 SalvagePacket (packet, source, destination, protocol);
2276
2277 if (m_maintainBuffer.GetSize () && m_maintainBuffer.Find (nextHop))
2278 {
2279 NS_LOG_INFO ("Cancel the packet timer for next maintenance entry");
2281 &DsrRouting::CancelPacketTimerNextHop,this,nextHop,protocol);
2282 }
2283 }
2284 else
2285 {
2286 NS_LOG_INFO ("Maintenance buffer entry not found");
2287 }
2289}
2290
2291void
2293{
2294 NS_LOG_FUNCTION (this << packet << source << dst << (uint32_t)protocol);
2295 // Create two copies of packet
2296 Ptr<Packet> p = packet->Copy ();
2297 Ptr<Packet> newPacket = packet->Copy ();
2298 // Remove the routing header in a whole to get a clean packet
2299 DsrRoutingHeader dsrRoutingHeader;
2300 p->RemoveHeader (dsrRoutingHeader);
2301 // Remove offset of dsr routing header
2302 uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
2303 newPacket->RemoveAtStart (offset);
2304
2305 // Get the number of routers' address field
2306 uint8_t buf[2];
2307 newPacket->CopyData (buf, sizeof(buf));
2308 uint8_t numberAddress = (buf[1] - 2) / 4;
2309
2310 DsrOptionSRHeader sourceRoute;
2311 sourceRoute.SetNumberAddress (numberAddress);
2312 newPacket->RemoveHeader (sourceRoute);
2313 uint8_t salvage = sourceRoute.GetSalvage ();
2314 /*
2315 * Look in the route cache for other routes for this destination
2316 */
2317 DsrRouteCacheEntry toDst;
2318 bool findRoute = m_routeCache->LookupRoute (dst, toDst);
2319 if (findRoute && (salvage < m_maxSalvageCount))
2320 {
2321 NS_LOG_DEBUG ("We have found a route for the packet");
2322 DsrRoutingHeader newDsrRoutingHeader;
2323 newDsrRoutingHeader.SetNextHeader (protocol);
2324 newDsrRoutingHeader.SetMessageType (2);
2325 newDsrRoutingHeader.SetSourceId (GetIDfromIP (source));
2326 newDsrRoutingHeader.SetDestId (GetIDfromIP (dst));
2327
2328 std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the route from the route entry we found
2329 Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); // Get the next hop address for the route
2330 if (nextHop == "0.0.0.0")
2331 {
2332 PacketNewRoute (p, source, dst, protocol);
2333 return;
2334 }
2335 // Increase the salvage count by 1
2336 salvage++;
2337 DsrOptionSRHeader sourceRoute;
2338 sourceRoute.SetSalvage (salvage);
2339 sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the source route header of the packet
2340 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segmentsLeft field will indicate the hops to go
2342 if (m_routeCache->IsLinkCache ())
2343 {
2344 m_routeCache->UseExtends (nodeList);
2345 }
2346 uint8_t length = sourceRoute.GetLength ();
2347 NS_LOG_INFO ("length of source route header " << (uint32_t)(sourceRoute.GetLength ()));
2348 newDsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
2349 newDsrRoutingHeader.AddDsrOption (sourceRoute);
2350 p->AddHeader (newDsrRoutingHeader);
2351
2352 SetRoute (nextHop, m_mainAddress);
2353 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
2354 m_ipv4Route->SetOutputDevice (dev);
2355
2356 // Send out the data packet
2358 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
2359 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
2360 NS_LOG_DEBUG ("Will be inserting into priority queue " << dsrNetworkQueue << " number: " << priority);
2361
2362 //m_downTarget (p, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
2363
2366
2367 if (dsrNetworkQueue->Enqueue (newEntry))
2368 {
2369 Scheduler (priority);
2370 }
2371 else
2372 {
2373 NS_LOG_INFO ("Packet dropped as dsr network queue is full");
2374 }
2375
2376 /*
2377 * Mark the next hop address in blacklist
2378 */
2379// NS_LOG_DEBUG ("Save the next hop node in blacklist");
2380// m_rreqTable->MarkLinkAsUnidirectional (nextHop, m_blacklistTimeout);
2381 }
2382 else
2383 {
2384 NS_LOG_DEBUG ("Will not salvage this packet, silently drop");
2385 }
2386}
2387
2388void
2390 uint8_t protocol)
2391{
2392 NS_LOG_FUNCTION (this << (uint32_t) protocol);
2393
2394 Ptr<Packet> p = mb.GetPacket ()->Copy ();
2395 Ipv4Address source = mb.GetSrc ();
2396 Ipv4Address nextHop = mb.GetNextHop ();
2397
2398 // Send the data packet out before schedule the next packet transmission
2399 SendPacket (p, source, nextHop, protocol);
2400
2401 LinkKey linkKey;
2402 linkKey.m_source = mb.GetSrc ();
2403 linkKey.m_destination = mb.GetDst ();
2404 linkKey.m_ourAdd = mb.GetOurAdd ();
2405 linkKey.m_nextHop = mb.GetNextHop ();
2406
2407 if (m_linkAckTimer.find (linkKey) == m_linkAckTimer.end ())
2408 {
2410 m_linkAckTimer[linkKey] = timer;
2411 }
2412 m_linkAckTimer[linkKey].SetFunction (&DsrRouting::LinkScheduleTimerExpire, this);
2413 m_linkAckTimer[linkKey].Cancel ();
2414 m_linkAckTimer[linkKey].SetArguments (mb, protocol);
2415 m_linkAckTimer[linkKey].Schedule (m_linkAckTimeout);
2416}
2417
2418void
2420 uint8_t protocol)
2421{
2422 NS_LOG_FUNCTION (this << (uint32_t)protocol);
2423
2424 Ptr<Packet> p = mb.GetPacket ()->Copy ();
2425 Ipv4Address source = mb.GetSrc ();
2426 Ipv4Address nextHop = mb.GetNextHop ();
2427
2428 // Send the data packet out before schedule the next packet transmission
2429 SendPacket (p, source, nextHop, protocol);
2430
2431 PassiveKey passiveKey;
2432 passiveKey.m_ackId = 0;
2433 passiveKey.m_source = mb.GetSrc ();
2434 passiveKey.m_destination = mb.GetDst ();
2435 passiveKey.m_segsLeft = mb.GetSegsLeft ();
2436
2437 if (m_passiveAckTimer.find (passiveKey) == m_passiveAckTimer.end ())
2438 {
2440 m_passiveAckTimer[passiveKey] = timer;
2441 }
2442 NS_LOG_DEBUG ("The passive acknowledgment option for data packet");
2443 m_passiveAckTimer[passiveKey].SetFunction (&DsrRouting::PassiveScheduleTimerExpire, this);
2444 m_passiveAckTimer[passiveKey].Cancel ();
2445 m_passiveAckTimer[passiveKey].SetArguments (mb, protocol);
2446 m_passiveAckTimer[passiveKey].Schedule (m_passiveAckTimeout);
2447}
2448
2449void
2451 bool isFirst,
2452 uint8_t protocol)
2453{
2454 Ptr<Packet> p = Create<Packet> ();
2455 Ptr<Packet> dsrP = Create<Packet> ();
2456 // The new entry will be used for retransmission
2457 NetworkKey networkKey;
2458 Ipv4Address nextHop = mb.GetNextHop ();
2459 NS_LOG_DEBUG ("is the first retry or not " << isFirst);
2460 if (isFirst)
2461 {
2462 // This is the very first network packet retry
2463 p = mb.GetPacket ()->Copy ();
2464 // Here we add the ack request header to the data packet for network acknowledgement
2465 uint16_t ackId = AddAckReqHeader (p, nextHop);
2466
2467 Ipv4Address source = mb.GetSrc ();
2468 Ipv4Address nextHop = mb.GetNextHop ();
2469 // Send the data packet out before schedule the next packet transmission
2470 SendPacket (p, source, nextHop, protocol);
2471
2472 dsrP = p->Copy ();
2473 DsrMaintainBuffEntry newEntry = mb;
2474 // The function AllEqual will find the exact entry and delete it if found
2476 newEntry.SetPacket (dsrP);
2477 newEntry.SetAckId (ackId);
2479
2480 networkKey.m_ackId = newEntry.GetAckId ();
2481 networkKey.m_ourAdd = newEntry.GetOurAdd ();
2482 networkKey.m_nextHop = newEntry.GetNextHop ();
2483 networkKey.m_source = newEntry.GetSrc ();
2484 networkKey.m_destination = newEntry.GetDst ();
2485
2486 m_addressForwardCnt[networkKey] = 0;
2487 if (!m_maintainBuffer.Enqueue (newEntry))
2488 {
2489 NS_LOG_ERROR ("Failed to enqueue packet retry");
2490 }
2491
2492 if (m_addressForwardTimer.find (networkKey) == m_addressForwardTimer.end ())
2493 {
2495 m_addressForwardTimer[networkKey] = timer;
2496 }
2497
2498 // After m_tryPassiveAcks, schedule the packet retransmission using network acknowledgment option
2499 m_addressForwardTimer[networkKey].SetFunction (&DsrRouting::NetworkScheduleTimerExpire, this);
2500 m_addressForwardTimer[networkKey].Cancel ();
2501 m_addressForwardTimer[networkKey].SetArguments (newEntry, protocol);
2502 NS_LOG_DEBUG ("The packet retries time for " << newEntry.GetAckId () << " is " << m_sendRetries
2503 << " and the delay time is " << Time (2 * m_nodeTraversalTime).As (Time::S));
2504 // Back-off mechanism
2505 m_addressForwardTimer[networkKey].Schedule (Time (2 * m_nodeTraversalTime));
2506 }
2507 else
2508 {
2509 networkKey.m_ackId = mb.GetAckId ();
2510 networkKey.m_ourAdd = mb.GetOurAdd ();
2511 networkKey.m_nextHop = mb.GetNextHop ();
2512 networkKey.m_source = mb.GetSrc ();
2513 networkKey.m_destination = mb.GetDst ();
2514 /*
2515 * Here we have found the entry for send retries, so we get the value and increase it by one
2516 */
2517 m_sendRetries = m_addressForwardCnt[networkKey];
2518 NS_LOG_DEBUG ("The packet retry we have done " << m_sendRetries);
2519
2520 p = mb.GetPacket ()->Copy ();
2521 dsrP = mb.GetPacket ()->Copy ();
2522
2523 Ipv4Address source = mb.GetSrc ();
2524 Ipv4Address nextHop = mb.GetNextHop ();
2525 // Send the data packet out before schedule the next packet transmission
2526 SendPacket (p, source, nextHop, protocol);
2527
2528 NS_LOG_DEBUG ("The packet with dsr header " << dsrP->GetSize ());
2529 networkKey.m_ackId = mb.GetAckId ();
2530 networkKey.m_ourAdd = mb.GetOurAdd ();
2531 networkKey.m_nextHop = mb.GetNextHop ();
2532 networkKey.m_source = mb.GetSrc ();
2533 networkKey.m_destination = mb.GetDst ();
2534 /*
2535 * If a data packet has been attempted SendRetries times at the maximum TTL without
2536 * receiving any ACK, all data packets destined for the corresponding destination SHOULD be
2537 * dropped from the send buffer
2538 *
2539 * The maxMaintRexmt also needs to decrease one for the passive ack packet
2540 */
2541 /*
2542 * Check if the send retry time for a certain packet has already passed max maintenance retransmission
2543 * time or not
2544 */
2545
2546 // After m_tryPassiveAcks, schedule the packet retransmission using network acknowledgment option
2547 m_addressForwardTimer[networkKey].SetFunction (&DsrRouting::NetworkScheduleTimerExpire, this);
2548 m_addressForwardTimer[networkKey].Cancel ();
2549 m_addressForwardTimer[networkKey].SetArguments (mb, protocol);
2550 NS_LOG_DEBUG ("The packet retries time for " << mb.GetAckId () << " is " << m_sendRetries
2551 << " and the delay time is " << Time (2 * m_sendRetries * m_nodeTraversalTime).As (Time::S));
2552 // Back-off mechanism
2553 m_addressForwardTimer[networkKey].Schedule (Time (2 * m_sendRetries * m_nodeTraversalTime));
2554 }
2555}
2556
2557void
2559 uint8_t protocol)
2560{
2561 NS_LOG_FUNCTION (this << (uint32_t)protocol);
2562 Ipv4Address nextHop = mb.GetNextHop ();
2563 Ptr<const Packet> packet = mb.GetPacket ();
2564 SetRoute (nextHop, m_mainAddress);
2565 Ptr<Packet> p = packet->Copy ();
2566
2567 LinkKey lk;
2568 lk.m_source = mb.GetSrc ();
2569 lk.m_destination = mb.GetDst ();
2570 lk.m_ourAdd = mb.GetOurAdd ();
2571 lk.m_nextHop = mb.GetNextHop ();
2572
2573 // Cancel passive ack timer
2574 m_linkAckTimer[lk].Cancel ();
2575 if (m_linkAckTimer[lk].IsRunning ())
2576 {
2577 NS_LOG_DEBUG ("Timer not canceled");
2578 }
2579 m_linkAckTimer.erase (lk);
2580
2581 // Increase the send retry times
2584 {
2585 m_linkCnt[lk] = ++m_linkRetries;
2586 ScheduleLinkPacketRetry (mb, protocol);
2587 }
2588 else
2589 {
2590 NS_LOG_INFO ("We need to send error messages now");
2591
2592 // Delete all the routes including the links
2593 m_routeCache->DeleteAllRoutesIncludeLink (m_mainAddress, nextHop, m_mainAddress);
2594 /*
2595 * here we cancel the packet retransmission time for all the packets have next hop address as nextHop
2596 * Also salvage the packet for the all the packet destined for the nextHop address
2597 * this is also responsible for send unreachable error back to source
2598 */
2599 CancelPacketTimerNextHop (nextHop, protocol);
2600 }
2601}
2602
2603void
2605 uint8_t protocol)
2606{
2607 NS_LOG_FUNCTION (this << (uint32_t)protocol);
2608 Ipv4Address nextHop = mb.GetNextHop ();
2609 Ptr<const Packet> packet = mb.GetPacket ();
2610 SetRoute (nextHop, m_mainAddress);
2611 Ptr<Packet> p = packet->Copy ();
2612
2613 PassiveKey pk;
2614 pk.m_ackId = 0;
2615 pk.m_source = mb.GetSrc ();
2616 pk.m_destination = mb.GetDst ();
2617 pk.m_segsLeft = mb.GetSegsLeft ();
2618
2619 // Cancel passive ack timer
2620 m_passiveAckTimer[pk].Cancel ();
2621 if (m_passiveAckTimer[pk].IsRunning ())
2622 {
2623 NS_LOG_DEBUG ("Timer not canceled");
2624 }
2625 m_passiveAckTimer.erase (pk);
2626
2627 // Increase the send retry times
2630 {
2632 SchedulePassivePacketRetry (mb, protocol);
2633 }
2634 else
2635 {
2636 // This is the first network acknowledgement retry
2637 // Cancel the passive packet timer now and remove maintenance buffer entry for it
2639 ScheduleNetworkPacketRetry (mb, true, protocol);
2640 }
2641}
2642
2643int64_t
2645{
2646 NS_LOG_FUNCTION (this << stream);
2648 return 1;
2649}
2650
2651void
2653 uint8_t protocol)
2654{
2655 Ptr<Packet> p = mb.GetPacket ()->Copy ();
2656 Ipv4Address source = mb.GetSrc ();
2657 Ipv4Address nextHop = mb.GetNextHop ();
2658 Ipv4Address dst = mb.GetDst ();
2659
2660 NetworkKey networkKey;
2661 networkKey.m_ackId = mb.GetAckId ();
2662 networkKey.m_ourAdd = mb.GetOurAdd ();
2663 networkKey.m_nextHop = nextHop;
2664 networkKey.m_source = source;
2665 networkKey.m_destination = dst;
2666
2667 // Increase the send retry times
2668 m_sendRetries = m_addressForwardCnt[networkKey];
2669
2671 {
2672 // Delete all the routes including the links
2673 m_routeCache->DeleteAllRoutesIncludeLink (m_mainAddress, nextHop, m_mainAddress);
2674 /*
2675 * here we cancel the packet retransmission time for all the packets have next hop address as nextHop
2676 * Also salvage the packet for the all the packet destined for the nextHop address
2677 */
2678 CancelPacketTimerNextHop (nextHop, protocol);
2679 }
2680 else
2681 {
2682 m_addressForwardCnt[networkKey] = ++m_sendRetries;
2683 ScheduleNetworkPacketRetry (mb, false, protocol);
2684 }
2685}
2686
2687void
2689 DsrOptionSRHeader &sourceRoute,
2690 Ipv4Header const& ipv4Header,
2691 Ipv4Address source,
2692 Ipv4Address nextHop,
2693 Ipv4Address targetAddress,
2694 uint8_t protocol,
2695 Ptr<Ipv4Route> route)
2696{
2697 NS_LOG_FUNCTION (this << packet << sourceRoute << source << nextHop << targetAddress << (uint32_t)protocol << route);
2698 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
2699
2700 DsrRoutingHeader dsrRoutingHeader;
2701 dsrRoutingHeader.SetNextHeader (protocol);
2702 dsrRoutingHeader.SetMessageType (2);
2703 dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
2704 dsrRoutingHeader.SetDestId (GetIDfromIP (targetAddress));
2705
2706 // We get the salvage value in sourceRoute header and set it to route error header if triggered error
2707 Ptr<Packet> p = packet->Copy ();
2708 uint8_t length = sourceRoute.GetLength ();
2709 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
2710 dsrRoutingHeader.AddDsrOption (sourceRoute);
2711 p->AddHeader (dsrRoutingHeader);
2712
2713 Ptr<const Packet> mtP = p->Copy ();
2714
2715 DsrMaintainBuffEntry newEntry (/*packet=*/ mtP,
2716 /*ourAddress=*/ m_mainAddress,
2717 /*nextHop=*/ nextHop,
2718 /*src=*/ source,
2719 /*dst=*/ targetAddress,
2720 /*ackId=*/ m_ackId,
2721 /*segsLeft=*/ sourceRoute.GetSegmentsLeft (),
2722 /*expire=*/ m_maxMaintainTime);
2723 bool result = m_maintainBuffer.Enqueue (newEntry);
2724
2725 if (result)
2726 {
2727 NetworkKey networkKey;
2728 networkKey.m_ackId = newEntry.GetAckId ();
2729 networkKey.m_ourAdd = newEntry.GetOurAdd ();
2730 networkKey.m_nextHop = newEntry.GetNextHop ();
2731 networkKey.m_source = newEntry.GetSrc ();
2732 networkKey.m_destination = newEntry.GetDst ();
2733
2734 PassiveKey passiveKey;
2735 passiveKey.m_ackId = 0;
2736 passiveKey.m_source = newEntry.GetSrc ();
2737 passiveKey.m_destination = newEntry.GetDst ();
2738 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
2739
2740 LinkKey linkKey;
2741 linkKey.m_source = newEntry.GetSrc ();
2742 linkKey.m_destination = newEntry.GetDst ();
2743 linkKey.m_ourAdd = newEntry.GetOurAdd ();
2744 linkKey.m_nextHop = newEntry.GetNextHop ();
2745
2746 m_addressForwardCnt[networkKey] = 0;
2747 m_passiveCnt[passiveKey] = 0;
2748 m_linkCnt[linkKey] = 0;
2749
2750 if (m_linkAck)
2751 {
2752 ScheduleLinkPacketRetry (newEntry, protocol);
2753 }
2754 else
2755 {
2756 NS_LOG_LOGIC ("Not using link acknowledgment");
2757 if (nextHop != targetAddress)
2758 {
2759 SchedulePassivePacketRetry (newEntry, protocol);
2760 }
2761 else
2762 {
2763 // This is the first network retry
2764 ScheduleNetworkPacketRetry (newEntry, true, protocol);
2765 }
2766 }
2767 }
2768}
2769
2770void
2772 Ipv4Address destination,
2773 uint8_t protocol)
2774{
2775 NS_LOG_FUNCTION (this << source << destination << (uint32_t)protocol);
2776 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
2777 Ptr<Packet> packet = Create<Packet> ();
2778 // Create an empty Ipv4 route ptr
2779 Ptr<Ipv4Route> route;
2780 /*
2781 * Construct the route request option header
2782 */
2783 DsrRoutingHeader dsrRoutingHeader;
2784 dsrRoutingHeader.SetNextHeader (protocol);
2785 dsrRoutingHeader.SetMessageType (1);
2786 dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
2787 dsrRoutingHeader.SetDestId (255);
2788
2789 DsrOptionRreqHeader rreqHeader; // has an alignment of 4n+0
2790 rreqHeader.AddNodeAddress (m_mainAddress); // Add our own address in the header
2791 rreqHeader.SetTarget (destination);
2792 m_requestId = m_rreqTable->CheckUniqueRreqId (destination); // Check the Id cache for duplicate ones
2793 rreqHeader.SetId (m_requestId);
2794
2795 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader to the dsr extension header
2796 uint8_t length = rreqHeader.GetLength ();
2797 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
2798 packet->AddHeader (dsrRoutingHeader);
2799
2800 // Schedule the route requests retry with non-propagation set true
2801 bool nonProp = true;
2802 std::vector<Ipv4Address> address;
2803 address.push_back (source);
2804 address.push_back (destination);
2805 /*
2806 * Add the socket ip ttl tag to the packet to limit the scope of route requests
2807 */
2808 SocketIpTtlTag tag;
2809 tag.SetTtl (0);
2810 Ptr<Packet> nonPropPacket = packet->Copy ();
2811 nonPropPacket->AddPacketTag (tag);
2812 // Increase the request count
2813 m_rreqTable->FindAndUpdate (destination);
2814 SendRequest (nonPropPacket, source);
2815 // Schedule the next route request
2816 ScheduleRreqRetry (packet, address, nonProp, m_requestId, protocol);
2817}
2818
2819void
2821{
2822 NS_LOG_FUNCTION (this << (uint32_t)protocol);
2823 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
2824 uint8_t salvage = rerr.GetSalvage ();
2825 Ipv4Address dst = rerr.GetOriginalDst ();
2826 NS_LOG_DEBUG ("our own address here " << m_mainAddress << " error source " << rerr.GetErrorSrc () << " error destination " << rerr.GetErrorDst ()
2827 << " error next hop " << rerr.GetUnreachNode () << " original dst " << rerr.GetOriginalDst ()
2828 );
2829 DsrRouteCacheEntry toDst;
2830 if (m_routeCache->LookupRoute (dst, toDst))
2831 {
2832 /*
2833 * Found a route the dst, construct the source route option header
2834 */
2835 DsrOptionSRHeader sourceRoute;
2836 std::vector<Ipv4Address> ip = toDst.GetVector ();
2837 sourceRoute.SetNodesAddress (ip);
2839 if (m_routeCache->IsLinkCache ())
2840 {
2841 m_routeCache->UseExtends (ip);
2842 }
2843 sourceRoute.SetSegmentsLeft ((ip.size () - 2));
2844 sourceRoute.SetSalvage (salvage);
2845 Ipv4Address nextHop = SearchNextHop (m_mainAddress, ip); // Get the next hop address
2846 NS_LOG_DEBUG ("The nextHop address " << nextHop);
2847 Ptr<Packet> packet = Create<Packet> ();
2848 if (nextHop == "0.0.0.0")
2849 {
2850 NS_LOG_DEBUG ("Error next hop address");
2851 PacketNewRoute (packet, m_mainAddress, dst, protocol);
2852 return;
2853 }
2854 SetRoute (nextHop, m_mainAddress);
2855 CancelRreqTimer (dst, true);
2857 if (m_sendBuffer.GetSize () != 0 && m_sendBuffer.Find (dst))
2858 {
2859 SendPacketFromBuffer (sourceRoute, nextHop, protocol);
2860 }
2861 NS_LOG_LOGIC ("Route to " << dst << " found");
2862 return;
2863 }
2864 else
2865 {
2866 NS_LOG_INFO ("No route found, initiate route error request");
2867 Ptr<Packet> packet = Create<Packet> ();
2868 Ipv4Address originalDst = rerr.GetOriginalDst ();
2869 // Create an empty route ptr
2870 Ptr<Ipv4Route> route = 0;
2871 /*
2872 * Construct the route request option header
2873 */
2874 DsrRoutingHeader dsrRoutingHeader;
2875 dsrRoutingHeader.SetNextHeader (protocol);
2876 dsrRoutingHeader.SetMessageType (1);
2877 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress));
2878 dsrRoutingHeader.SetDestId (255);
2879
2880 Ptr<Packet> dstP = Create<Packet> ();
2881 DsrOptionRreqHeader rreqHeader; // has an alignment of 4n+0
2882 rreqHeader.AddNodeAddress (m_mainAddress); // Add our own address in the header
2883 rreqHeader.SetTarget (originalDst);
2884 m_requestId = m_rreqTable->CheckUniqueRreqId (originalDst); // Check the Id cache for duplicate ones
2885 rreqHeader.SetId (m_requestId);
2886
2887 dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader to the dsr extension header
2888 dsrRoutingHeader.AddDsrOption (rerr);
2889 uint8_t length = rreqHeader.GetLength () + rerr.GetLength ();
2890 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 4);
2891 dstP->AddHeader (dsrRoutingHeader);
2892 // Schedule the route requests retry, propagate the route request message as it contains error
2893 bool nonProp = false;
2894 std::vector<Ipv4Address> address;
2895 address.push_back (m_mainAddress);
2896 address.push_back (originalDst);
2897 /*
2898 * Add the socket ip ttl tag to the packet to limit the scope of route requests
2899 */
2900 SocketIpTtlTag tag;
2901 tag.SetTtl ((uint8_t)m_discoveryHopLimit);
2902 Ptr<Packet> propPacket = dstP->Copy ();
2903 propPacket->AddPacketTag (tag);
2904
2905 if ((m_addressReqTimer.find (originalDst) == m_addressReqTimer.end ()) && (m_nonPropReqTimer.find (originalDst) == m_nonPropReqTimer.end ()))
2906 {
2907 NS_LOG_INFO ("Only when there is no existing route request time when the initial route request is scheduled");
2908 SendRequest (propPacket, m_mainAddress);
2909 ScheduleRreqRetry (dstP, address, nonProp, m_requestId, protocol);
2910 }
2911 else
2912 {
2913 NS_LOG_INFO ("There is existing route request, find the existing route request entry");
2914 /*
2915 * Cancel the route request timer first before scheduling the route request
2916 * in this case, we do not want to remove the route request entry, so the isRemove value is false
2917 */
2918 CancelRreqTimer (originalDst, false);
2919 ScheduleRreqRetry (dstP, address, nonProp, m_requestId, protocol);
2920 }
2921 }
2922}
2923
2924void
2926{
2927 NS_LOG_FUNCTION (this << dst << isRemove);
2928 // Cancel the non propagation request timer if found
2929 if (m_nonPropReqTimer.find (dst) == m_nonPropReqTimer.end ())
2930 {
2931 NS_LOG_DEBUG ("Did not find the non-propagation timer");
2932 }
2933 else
2934 {
2935 NS_LOG_DEBUG ("did find the non-propagation timer");
2936 }
2937 m_nonPropReqTimer[dst].Cancel ();
2938
2939 if (m_nonPropReqTimer[dst].IsRunning ())
2940 {
2941 NS_LOG_DEBUG ("Timer not canceled");
2942 }
2943 m_nonPropReqTimer.erase (dst);
2944
2945 // Cancel the address request timer if found
2946 if (m_addressReqTimer.find (dst) == m_addressReqTimer.end ())
2947 {
2948 NS_LOG_DEBUG ("Did not find the propagation timer");
2949 }
2950 else
2951 {
2952 NS_LOG_DEBUG ("did find the propagation timer");
2953 }
2954 m_addressReqTimer[dst].Cancel ();
2955 if (m_addressReqTimer[dst].IsRunning ())
2956 {
2957 NS_LOG_DEBUG ("Timer not canceled");
2958 }
2959 m_addressReqTimer.erase (dst);
2960 /*
2961 * If the route request is scheduled to remove the route request entry
2962 * Remove the route request entry with the route retry times done for certain destination
2963 */
2964 if (isRemove)
2965 {
2966 // remove the route request entry from route request table
2967 m_rreqTable->RemoveRreqEntry (dst);
2968 }
2969}
2970
2971void
2972DsrRouting::ScheduleRreqRetry (Ptr<Packet> packet, std::vector<Ipv4Address> address, bool nonProp, uint32_t requestId, uint8_t protocol)
2973{
2974 NS_LOG_FUNCTION (this << packet << nonProp << requestId << (uint32_t)protocol);
2975 Ipv4Address source = address[0];
2976 Ipv4Address dst = address[1];
2977 if (nonProp)
2978 {
2979 // The nonProp route request is only sent out only and is already used
2980 if (m_nonPropReqTimer.find (dst) == m_nonPropReqTimer.end ())
2981 {
2983 m_nonPropReqTimer[dst] = timer;
2984 }
2985 std::vector<Ipv4Address> address;
2986 address.push_back (source);
2987 address.push_back (dst);
2989 m_nonPropReqTimer[dst].Cancel ();
2990 m_nonPropReqTimer[dst].SetArguments (packet, address, requestId, protocol);
2992 }
2993 else
2994 {
2995 // Cancel the non propagation request timer if found
2996 m_nonPropReqTimer[dst].Cancel ();
2997 if (m_nonPropReqTimer[dst].IsRunning ())
2998 {
2999 NS_LOG_DEBUG ("Timer not canceled");
3000 }
3001 m_nonPropReqTimer.erase (dst);
3002
3003 if (m_addressReqTimer.find (dst) == m_addressReqTimer.end ())
3004 {
3006 m_addressReqTimer[dst] = timer;
3007 }
3008 std::vector<Ipv4Address> address;
3009 address.push_back (source);
3010 address.push_back (dst);
3012 m_addressReqTimer[dst].Cancel ();
3013 m_addressReqTimer[dst].SetArguments (packet, address, requestId, protocol);
3014 Time rreqDelay;
3015 // back off mechanism for sending route requests
3016 if (m_rreqTable->GetRreqCnt (dst))
3017 {
3018 // When the route request count is larger than 0
3019 // This is the exponential back-off mechanism for route request
3020 rreqDelay = Time (std::pow (static_cast<double> (m_rreqTable->GetRreqCnt (dst)), 2.0) * m_requestPeriod);
3021 }
3022 else
3023 {
3024 // This is the first route request retry
3025 rreqDelay = m_requestPeriod;
3026 }
3027 NS_LOG_LOGIC ("Request count for " << dst << " " << m_rreqTable->GetRreqCnt (dst) << " with delay time " << rreqDelay.As (Time::S));
3028 if (rreqDelay > m_maxRequestPeriod)
3029 {
3030 // use the max request period
3031 NS_LOG_LOGIC ("The max request delay time " << m_maxRequestPeriod.As (Time::S));
3032 m_addressReqTimer[dst].Schedule (m_maxRequestPeriod);
3033 }
3034 else
3035 {
3036 NS_LOG_LOGIC ("The request delay time " << rreqDelay.As (Time::S));
3037 m_addressReqTimer[dst].Schedule (rreqDelay);
3038 }
3039 }
3040}
3041
3042void
3043DsrRouting::RouteRequestTimerExpire (Ptr<Packet> packet, std::vector<Ipv4Address> address, uint32_t requestId, uint8_t protocol)
3044{
3045 NS_LOG_FUNCTION (this << packet << requestId << (uint32_t)protocol);
3046 // Get a clean packet without dsr header
3047 Ptr<Packet> dsrP = packet->Copy ();
3048 DsrRoutingHeader dsrRoutingHeader;
3049 dsrP->RemoveHeader (dsrRoutingHeader); // Remove the dsr header in whole
3050
3051 Ipv4Address source = address[0];
3052 Ipv4Address dst = address[1];
3053 DsrRouteCacheEntry toDst;
3054 if (m_routeCache->LookupRoute (dst, toDst))
3055 {
3056 /*
3057 * Found a route the dst, construct the source route option header
3058 */
3059 DsrOptionSRHeader sourceRoute;
3060 std::vector<Ipv4Address> ip = toDst.GetVector ();
3061 sourceRoute.SetNodesAddress (ip);
3062 // When we found the route and use it, UseExtends for the link cache
3063 if (m_routeCache->IsLinkCache ())
3064 {
3065 m_routeCache->UseExtends (ip);
3066 }
3067 sourceRoute.SetSegmentsLeft ((ip.size () - 2));
3069 sourceRoute.SetSalvage (0);
3070 Ipv4Address nextHop = SearchNextHop (m_mainAddress, ip); // Get the next hop address
3071 NS_LOG_INFO ("The nextHop address is " << nextHop);
3072 if (nextHop == "0.0.0.0")
3073 {
3074 NS_LOG_DEBUG ("Error next hop address");
3075 PacketNewRoute (dsrP, source, dst, protocol);
3076 return;
3077 }
3078 SetRoute (nextHop, m_mainAddress);
3079 CancelRreqTimer (dst, true);
3081 if (m_sendBuffer.GetSize () != 0 && m_sendBuffer.Find (dst))
3082 {
3083 SendPacketFromBuffer (sourceRoute, nextHop, protocol);
3084 }
3085 NS_LOG_LOGIC ("Route to " << dst << " found");
3086 return;
3087 }
3088 /*
3089 * If a route discovery has been attempted m_rreqRetries times at the maximum TTL without
3090 * receiving any RREP, all data packets destined for the corresponding destination SHOULD be
3091 * dropped from the buffer and a Destination Unreachable message SHOULD be delivered to the application.
3092 */
3093 NS_LOG_LOGIC ("The new request count for " << dst << " is " << m_rreqTable->GetRreqCnt (dst) << " the max " << m_rreqRetries);
3094 if (m_rreqTable->GetRreqCnt (dst) >= m_rreqRetries)
3095 {
3096 NS_LOG_LOGIC ("Route discovery to " << dst << " has been attempted " << m_rreqRetries << " times");
3097 CancelRreqTimer (dst, true);
3098 NS_LOG_DEBUG ("Route not found. Drop packet with dst " << dst);
3100 }
3101 else
3102 {
3103 SocketIpTtlTag tag;
3104 tag.SetTtl ((uint8_t)m_discoveryHopLimit);
3105 Ptr<Packet> propPacket = packet->Copy ();
3106 propPacket->AddPacketTag (tag);
3107 // Increase the request count
3108 m_rreqTable->FindAndUpdate (dst);
3109 SendRequest (propPacket, source);
3110 NS_LOG_DEBUG ("Check the route request entry " << source << " " << dst);
3111 ScheduleRreqRetry (packet, address, false, requestId, protocol);
3112 }
3113}
3114
3115void
3117 Ipv4Address source)
3118{
3119 NS_LOG_FUNCTION (this << packet << source);
3120
3121 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
3122 /*
3123 * The destination address here is directed broadcast address
3124 */
3126 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
3127 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
3128 NS_LOG_LOGIC ("Inserting into priority queue number: " << priority);
3129
3130 //m_downTarget (packet, source, m_broadcast, GetProtocolNumber (), 0);
3131
3133 DsrNetworkQueueEntry newEntry (packet, source, m_broadcast, Simulator::Now (), 0);
3134 if (dsrNetworkQueue->Enqueue (newEntry))
3135 {
3136 Scheduler (priority);
3137 }
3138 else
3139 {
3140 NS_LOG_INFO ("Packet dropped as dsr network queue is full");
3141 }
3142}
3143
3144void
3146{
3147 NS_LOG_FUNCTION (this << packet);
3148 /*
3149 * This is a forwarding case when sending route requests, a random delay time [0, m_broadcastJitter]
3150 * used before forwarding as link-layer broadcast
3151 */
3153 packet, m_mainAddress);
3154}
3155
3156void
3157DsrRouting::SendGratuitousReply (Ipv4Address source, Ipv4Address srcAddress, std::vector<Ipv4Address> &nodeList, uint8_t protocol)
3158{
3159 NS_LOG_FUNCTION (this << source << srcAddress << (uint32_t)protocol);
3160 if (!(m_graReply.FindAndUpdate (source, srcAddress, m_gratReplyHoldoff))) // Find the gratuitous reply entry
3161 {
3162 NS_LOG_LOGIC ("Update gratuitous reply " << source);
3163 GraReplyEntry graReplyEntry (source, srcAddress, m_gratReplyHoldoff + Simulator::Now ());
3164 m_graReply.AddEntry (graReplyEntry);
3165 /*
3166 * Automatic route shortening
3167 */
3168 m_finalRoute.clear (); // Clear the final route vector
3172 std::vector<Ipv4Address>::iterator before = find (nodeList.begin (), nodeList.end (), srcAddress);
3173 for (std::vector<Ipv4Address>::iterator i = nodeList.begin (); i != before; ++i)
3174 {
3175 m_finalRoute.push_back (*i);
3176 }
3177 m_finalRoute.push_back (srcAddress);
3178 std::vector<Ipv4Address>::iterator after = find (nodeList.begin (), nodeList.end (), m_mainAddress);
3179 for (std::vector<Ipv4Address>::iterator j = after; j != nodeList.end (); ++j)
3180 {
3181 m_finalRoute.push_back (*j);
3182 }
3184 rrep.SetNodesAddress (m_finalRoute); // Set the node addresses in the route reply header
3185 // Get the real reply source and destination
3186 Ipv4Address replySrc = m_finalRoute.back ();
3187 Ipv4Address replyDst = m_finalRoute.front ();
3188 /*
3189 * Set the route and use it in send back route reply
3190 */
3191 m_ipv4Route = SetRoute (srcAddress, m_mainAddress);
3192 /*
3193 * This part adds DSR header to the packet and send reply
3194 */
3195 DsrRoutingHeader dsrRoutingHeader;
3196 dsrRoutingHeader.SetNextHeader (protocol);
3197 dsrRoutingHeader.SetMessageType (1);
3198 dsrRoutingHeader.SetSourceId (GetIDfromIP (replySrc));
3199 dsrRoutingHeader.SetDestId (GetIDfromIP (replyDst));
3200
3201 uint8_t length = rrep.GetLength (); // Get the length of the rrep header excluding the type header
3202 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
3203 dsrRoutingHeader.AddDsrOption (rrep);
3204 Ptr<Packet> newPacket = Create<Packet> ();
3205 newPacket->AddHeader (dsrRoutingHeader);
3206 /*
3207 * Send gratuitous reply
3208 */
3209 NS_LOG_INFO ("Send back gratuitous route reply");
3210 SendReply (newPacket, m_mainAddress, srcAddress, m_ipv4Route);
3211 }
3212 else
3213 {
3214 NS_LOG_INFO ("The same gratuitous route reply has already sent");
3215 }
3216}
3217
3218void
3220 Ipv4Address source,
3221 Ipv4Address nextHop,
3222 Ptr<Ipv4Route> route)
3223{
3224 NS_LOG_FUNCTION (this << packet << source << nextHop);
3225 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
3226
3227 Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (m_mainAddress));
3228 route->SetOutputDevice (dev);
3229 NS_LOG_INFO ("The output device " << dev << " packet is: " << *packet);
3230
3232 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
3233 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
3234 NS_LOG_INFO ("Inserting into priority queue number: " << priority);
3235
3236 //m_downTarget (packet, source, nextHop, GetProtocolNumber (), route);
3237
3239 DsrNetworkQueueEntry newEntry (packet, source, nextHop, Simulator::Now (), route);
3240 if (dsrNetworkQueue->Enqueue (newEntry))
3241 {
3242 Scheduler (priority);
3243 }
3244 else
3245 {
3246 NS_LOG_INFO ("Packet dropped as dsr network queue is full");
3247 }
3248}
3249
3250void
3252 Ipv4Address source,
3253 Ipv4Address nextHop,
3254 Ptr<Ipv4Route> route)
3255{
3256 NS_LOG_FUNCTION (this << packet << source << nextHop);
3258 packet, source, nextHop, route);
3259}
3260
3261void
3263 Ipv4Address source,
3264 Ipv4Address destination,
3265 Ptr<Ipv4Route> route,
3266 double hops)
3267{
3268 NS_LOG_FUNCTION (this << packet << source << destination);
3269 Simulator::Schedule (Time (2 * m_nodeTraversalTime * (hops - 1 + m_uniformRandomVariable->GetValue (0,1))), &DsrRouting::SendReply, this, packet, source, destination, route);
3270}
3271
3272void
3273DsrRouting::SendAck (uint16_t ackId,
3274 Ipv4Address destination,
3275 Ipv4Address realSrc,
3276 Ipv4Address realDst,
3277 uint8_t protocol,
3278 Ptr<Ipv4Route> route)
3279{
3280 NS_LOG_FUNCTION (this << ackId << destination << realSrc << realDst << (uint32_t)protocol << route);
3281 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
3282
3283 // This is a route reply option header
3284 DsrRoutingHeader dsrRoutingHeader;
3285 dsrRoutingHeader.SetNextHeader (protocol);
3286 dsrRoutingHeader.SetMessageType (1);
3287 dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress));
3288 dsrRoutingHeader.SetDestId (GetIDfromIP (destination));
3289
3291 /*
3292 * Set the ack Id and set the ack source address and destination address
3293 */
3294 ack.SetAckId (ackId);
3295 ack.SetRealSrc (realSrc);
3296 ack.SetRealDst (realDst);
3297
3298 uint8_t length = ack.GetLength ();
3299 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
3300 dsrRoutingHeader.AddDsrOption (ack);
3301
3302 Ptr<Packet> packet = Create<Packet> ();
3303 packet->AddHeader (dsrRoutingHeader);
3304 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
3305 route->SetOutputDevice (dev);
3306
3308 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i = m_priorityQueue.find (priority);
3309 Ptr<dsr::DsrNetworkQueue> dsrNetworkQueue = i->second;
3310
3311 NS_LOG_LOGIC ("Will be inserting into priority queue " << dsrNetworkQueue << " number: " << priority);
3312
3313 //m_downTarget (packet, m_mainAddress, destination, GetProtocolNumber (), route);
3314
3316 DsrNetworkQueueEntry newEntry (packet, m_mainAddress, destination, Simulator::Now (), route);
3317 if (dsrNetworkQueue->Enqueue (newEntry))
3318 {
3319 Scheduler (priority);
3320 }
3321 else
3322 {
3323 NS_LOG_INFO ("Packet dropped as dsr network queue is full");
3324 }
3325}
3326
3329 Ipv4Header const &ip,
3330 Ptr<Ipv4Interface> incomingInterface)
3331{
3332 NS_LOG_FUNCTION (this << p << ip << incomingInterface);
3333
3334 NS_LOG_INFO ("Our own IP address " << m_mainAddress << " The incoming interface address " << incomingInterface);
3335 m_node = GetNode (); // Get the node
3336 Ptr<Packet> packet = p->Copy (); // Save a copy of the received packet
3337 /*
3338 * When forwarding or local deliver packets, this one should be used always!!
3339 */
3340 DsrRoutingHeader dsrRoutingHeader;
3341 packet->RemoveHeader (dsrRoutingHeader); // Remove the DSR header in whole
3342 Ptr<Packet> copy = packet->Copy ();
3343
3344 uint8_t protocol = dsrRoutingHeader.GetNextHeader ();
3345 uint32_t sourceId = dsrRoutingHeader.GetSourceId ();
3346 Ipv4Address source = GetIPfromID (sourceId);
3347 NS_LOG_INFO ("The source address " << source << " with source id " << sourceId);
3348 /*
3349 * Get the IP source and destination address
3350 */
3351 Ipv4Address src = ip.GetSource ();
3352
3353 bool isPromisc = false;
3354 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); // Get the offset for option header, 8 bytes in this case
3355
3356 // This packet is used to peek option type
3357 p->RemoveAtStart (offset);
3358
3359 Ptr<dsr::DsrOptions> dsrOption;
3360 DsrOptionHeader dsrOptionHeader;
3361 /*
3362 * Peek data to get the option type as well as length and segmentsLeft field
3363 */
3364 uint32_t size = p->GetSize ();
3365 uint8_t *data = new uint8_t[size];
3366 p->CopyData (data, size);
3367
3368 uint8_t optionType = 0;
3369 uint8_t optionLength = 0;
3370 uint8_t segmentsLeft = 0;
3371
3372 optionType = *(data);
3373 NS_LOG_LOGIC ("The option type value " << (uint32_t)optionType << " with packet id " << p->GetUid ());
3374 dsrOption = GetOption (optionType); // Get the relative dsr option and demux to the process function
3375 Ipv4Address promiscSource;
3376 if (optionType == 1) // This is the request option
3377 {
3378 BlackList *blackList = m_rreqTable->FindUnidirectional (src);
3379 if (blackList)
3380 {
3381 NS_LOG_INFO ("Discard this packet due to unidirectional link");
3382 m_dropTrace (p);
3383 }
3384
3385 dsrOption = GetOption (optionType);
3386 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3387
3388 if (optionLength == 0)
3389 {
3390 NS_LOG_INFO ("Discard this packet");
3391 m_dropTrace (p);
3392 }
3393 }
3394 else if (optionType == 2)
3395 {
3396 dsrOption = GetOption (optionType);
3397 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3398
3399 if (optionLength == 0)
3400 {
3401 NS_LOG_INFO ("Discard this packet");
3402 m_dropTrace (p);
3403 }
3404 }
3405
3406 else if (optionType == 32) // This is the ACK option
3407 {
3408 NS_LOG_INFO ("This is the ack option");
3409 dsrOption = GetOption (optionType);
3410 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3411
3412 if (optionLength == 0)
3413 {
3414 NS_LOG_INFO ("Discard this packet");
3415 m_dropTrace (p);
3416 }
3417 }
3418
3419 else if (optionType == 3) // This is a route error header
3420 {
3421 // populate this route error
3422 NS_LOG_INFO ("The option type value " << (uint32_t)optionType);
3423
3424 dsrOption = GetOption (optionType);
3425 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3426
3427 if (optionLength == 0)
3428 {
3429 NS_LOG_INFO ("Discard this packet");
3430 m_dropTrace (p);
3431 }
3432 NS_LOG_INFO ("The option Length " << (uint32_t)optionLength);
3433 }
3434
3435 else if (optionType == 96) // This is the source route option
3436 {
3437 dsrOption = GetOption (optionType);
3438 optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3439 segmentsLeft = *(data + 3);
3440 if (optionLength == 0)
3441 {
3442 NS_LOG_INFO ("Discard this packet");
3443 m_dropTrace (p);
3444 }
3445 else
3446 {
3447 if (segmentsLeft == 0)
3448 {
3449 // / Get the next header
3450 uint8_t nextHeader = dsrRoutingHeader.GetNextHeader ();
3452 Ptr<IpL4Protocol> nextProto = l3proto->GetProtocol (nextHeader);
3453 if (nextProto)
3454 {
3455 // we need to make a copy in the unlikely event we hit the
3456 // RX_ENDPOINT_UNREACH code path
3457 // Here we can use the packet that has been get off whole DSR header
3458 enum IpL4Protocol::RxStatus status =
3459 nextProto->Receive (copy, ip, incomingInterface);
3460 NS_LOG_DEBUG ("The receive status " << status);
3461 switch (status)
3462 {
3464 // fall through
3466 // fall through
3468 break;
3470 if (ip.GetDestination ().IsBroadcast () == true
3471 || ip.GetDestination ().IsMulticast () == true)
3472 {
3473 break; // Do not reply to broadcast or multicast
3474 }
3475 // Another case to suppress ICMP is a subnet-directed broadcast
3476 }
3477 return status;
3478 }
3479 else
3480 {
3481 NS_FATAL_ERROR ("Should not have 0 next protocol value");
3482 }
3483 }
3484 else
3485 {
3486 NS_LOG_INFO ("This is not the final destination, the packet has already been forward to next hop");
3487 }
3488 }
3489 }
3490 else
3491 {
3492 NS_LOG_LOGIC ("Unknown Option. Drop!");
3493 /*
3494 * Initialize the salvage value to 0
3495 */
3496 uint8_t salvage = 0;
3497
3498 DsrOptionRerrUnsupportHeader rerrUnsupportHeader;
3499 rerrUnsupportHeader.SetErrorType (3); // The error type 3 means Option not supported
3500 rerrUnsupportHeader.SetErrorSrc (m_mainAddress); // The error source address is our own address
3501 rerrUnsupportHeader.SetUnsupported (optionType); // The unsupported option type number
3502 rerrUnsupportHeader.SetErrorDst (src); // Error destination address is the destination of the data packet
3503 rerrUnsupportHeader.SetSalvage (salvage); // Set the value about whether to salvage a packet or not
3504
3505 /*
3506 * The unknown option error is not supported currently in this implementation, and it's also not likely to
3507 * happen in simulations
3508 */
3509// SendError (rerrUnsupportHeader, 0, protocol); // Send the error packet
3510 }
3511 return IpL4Protocol::RX_OK;
3512}
3513
3516 Ipv6Header const &ip,
3517 Ptr<Ipv6Interface> incomingInterface)
3518{
3519 NS_LOG_FUNCTION (this << p << ip.GetSource () << ip.GetDestination () << incomingInterface);
3521}
3522
3523void
3525{
3526 m_downTarget = callback;
3527}
3528
3529void
3531{
3532 NS_FATAL_ERROR ("Unimplemented");
3533}
3534
3535
3538{
3539 return m_downTarget;
3540}
3541
3544{
3545 NS_FATAL_ERROR ("Unimplemented");
3546 return MakeNullCallback<void,Ptr<Packet>, Ipv6Address, Ipv6Address, uint8_t, Ptr<Ipv6Route> > ();
3547}
3548
3550{
3551 m_options.push_back (option);
3552}
3553
3555{
3556 for (DsrOptionList_t::iterator i = m_options.begin (); i != m_options.end (); ++i)
3557 {
3558 if ((*i)->GetOptionNumber () == optionNumber)
3559 {
3560 return *i;
3561 }
3562 }
3563 return 0;
3564}
3565} /* namespace dsr */
3566} /* namespace ns3 */
a polymophic address class
Definition: address.h:91
Wifi MAC high model for an ad-hoc Wifi MAC.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:532
L4 Protocol abstract base class.
RxStatus
Rx status codes.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
bool IsMulticast(void) const
bool IsBroadcast(void) const
Packet header for IPv4.
Definition: ipv4-header.h:34
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
uint8_t GetProtocol(void) const
Definition: ipv4-header.cc:272
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:77
Implement the IPv4 layer.
static const uint16_t PROT_NUMBER
Protocol number (0x0800)
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
Describes an IPv6 address.
Definition: ipv6-address.h:50
Packet header for IPv6.
Definition: ipv6-header.h:36
Ipv6Address GetSource(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:105
Ipv6Address GetDestination(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:125
an EUI-48 address
Definition: mac48-address.h:44
static Mac48Address ConvertFrom(const Address &address)
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
@ PACKET_OTHERHOST
Packet addressed to someone else.
Definition: net-device.h:304
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:241
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition: object.cc:325
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:362
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:390
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:956
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:555
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:586
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
Definition: socket.h:1117
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:603
Hold variables of type string.
Definition: string.h:41
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
@ S
second
Definition: nstime.h:115
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:418
AttributeValue implementation for Time.
Definition: nstime.h:1309
A simple virtual Timer class.
Definition: timer.h:74
void SetFunction(FN fn)
Definition: timer.h:278
void Suspend(void)
Pause the timer and save the amount of time left until it was set to expire.
Definition: timer.cc:177
bool IsRunning(void) const
Definition: timer.cc:127
@ CANCEL_ON_DESTROY
This policy cancels the event from the destructor of the Timer or from Suspend().
Definition: timer.h:93
void Resume(void)
Restart the timer to expire within the amount of time left saved during Suspend.
Definition: timer.cc:194
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
Definition: timer.cc:158
void Cancel(void)
Cancel the currently-running event if there is one.
Definition: timer.cc:109
bool IsSuspended(void) const
Definition: timer.cc:133
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
uint32_t GetInteger(uint32_t min, uint32_t max)
Get the next random value, as an unsigned integer in the specified range .
Hold together all Wifi-related objects.
DSR Error Buffer Entry.
Definition: dsr-errorbuff.h:46
Ptr< const Packet > GetPacket() const
Get packet from entry.
Definition: dsr-errorbuff.h:83
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool Enqueue(DsrErrorBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
bool Dequeue(Ipv4Address dst, DsrErrorBuffEntry &entry)
Return first found (the earliest) entry for given destination.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void DropPacketForErrLink(Ipv4Address source, Ipv4Address nextHop)
Remove all packets with the error link.
void SetErrorBufferTimeout(Time t)
Set error buffer timeout.
uint32_t GetSize()
Returns the number of entries in the queue.
void SetSourceId(uint16_t sourceId)
brief Set the source ID of the header.
void SetNextHeader(uint8_t protocol)
Set the "Next header" field.
void SetDestId(uint16_t destId)
brief Set the dest ID of the header.
uint8_t GetMessageType() const
brief Get the message type of the header.
uint8_t GetNextHeader() const
Get the next header.
uint16_t GetSourceId() const
brief Get the source ID of the header.
uint16_t GetDestId() const
brief Get the dest ID of the header.
void SetMessageType(uint8_t messageType)
brief Set the message type of the header.
void SetPayloadLength(uint16_t length)
brief Set the payload length of the header.
bool AddEntry(GraReplyEntry &graTableEntry)
Add a new gratuitous reply entry.
void SetGraTableSize(uint32_t g)
Set the gratuitous reply table size.
bool FindAndUpdate(Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff)
Update the route entry if found.
DSR Maintain Buffer Entry.
uint8_t GetSegsLeft() const
Get segments left.
void SetDst(Ipv4Address n)
Set destination address.
void SetExpireTime(Time exp)
Set expiration time.
void SetNextHop(Ipv4Address n)
Set next hop of entry.
Ipv4Address GetSrc() const
Get source address.
void SetSegsLeft(uint8_t segs)
Set segments left.
void SetPacket(Ptr< const Packet > p)
Set packet.
Ptr< const Packet > GetPacket() const
Get packet.
void SetOurAdd(Ipv4Address us)
Set local address of entry.
void SetSrc(Ipv4Address s)
Set source address.
uint16_t GetAckId() const
Get acknowledge ID.
Ipv4Address GetOurAdd() const
Get local address of entry.
void SetAckId(uint16_t ackId)
Set acknowledge ID.
Ipv4Address GetNextHop() const
Get next hop of entry.
Ipv4Address GetDst() const
Get destination address.
bool Dequeue(Ipv4Address dst, DsrMaintainBuffEntry &entry)
Return first found (the earliest) entry for given destination.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool AllEqual(DsrMaintainBuffEntry &entry)
Verify if all the elements in the maintenance buffer entry is the same.
bool LinkEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for link ack.
bool Find(Ipv4Address nextHop)
Finds whether a packet with next hop dst exists in the queue.
void SetMaintainBufferTimeout(Time t)
Set maintain buffer timeout.
uint32_t GetSize()
Number of entries.
bool PromiscEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for promiscuous ack.
bool NetworkEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for network ack.
bool Enqueue(DsrMaintainBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
DSR Network Queue Entry.
Ptr< Ipv4Route > GetIpv4Route() const
Get IP route function.
Ptr< const Packet > GetPacket() const
Get packet function.
Ipv4Address GetSourceAddress() const
Get source address function.
Ipv4Address GetNextHopAddress() const
Get next hop address function.
Acknowledgement (ACK) Message Format.
void SetAckId(uint16_t identification)
Set the Ack id number.
void SetRealSrc(Ipv4Address realSrcAddress)
Set Error source ip address.
void SetRealDst(Ipv4Address realDstAddress)
Set Error source ip address.
Acknowledgement Request (ACK_RREQ) Message Format.
void SetAckId(uint16_t identification)
Set the Ack request id number.
uint32_t GetDsrOptionsOffset()
Get the offset where the options begin, measured from the start of the extension header.
void AddDsrOption(DsrOptionHeader const &option)
Serialize the option, prepending pad1 or padn option as necessary.
Header for Dsr Options.
uint8_t GetLength() const
Get the option length.
void SetErrorType(uint8_t errorType)
Set the route error type.
Route Error (RERR) Unreachable node address option Message Format.
void SetOriginalDst(Ipv4Address originalDst)
Set the unreachable node ip address.
virtual void SetErrorSrc(Ipv4Address errorSrcAddress)
Set the route error source address.
Ipv4Address GetOriginalDst() const
Get the unreachable node ip address.
void SetUnreachNode(Ipv4Address unreachNode)
Set the unreachable node ip address.
virtual void SetErrorDst(Ipv4Address errorDstAddress)
Set the error destination ip address.
virtual Ipv4Address GetErrorSrc() const
Get the route error source address.
virtual uint8_t GetSalvage() const
Get the salvage value of the packet.
virtual void SetSalvage(uint8_t salvage)
Set the salvage value of the packet.
virtual Ipv4Address GetErrorDst() const
Get the error destination ip address.
Ipv4Address GetUnreachNode() const
Get the unreachable node ip address.
Route Error (RERR) Unsupported option Message Format.
virtual void SetSalvage(uint8_t salvage)
Set the salvage value of the packet.
void SetUnsupported(uint16_t optionType)
Set the unsupported option type value.
virtual void SetErrorSrc(Ipv4Address errorSrcAddress)
Set the route error source address.
virtual void SetErrorDst(Ipv4Address errorDstAddress)
Set the error destination ip address.
Route Reply (RREP) Message Format.
void SetNodesAddress(std::vector< Ipv4Address > ipv4Address)
Set the vector of ipv4 address.
Route Request (RREQ) Message Format.
void SetTarget(Ipv4Address target)
Set the target ipv4 address.
void AddNodeAddress(Ipv4Address ipv4)
Add one node address.
void SetId(uint16_t identification)
Set the request id number.
Source Route (SR) Message Format.
std::vector< Ipv4Address > GetNodesAddress() const
Get the vector of ipv4 address.
void SetNumberAddress(uint8_t n)
Set the number of ipv4 address.
void SetSalvage(uint8_t salvage)
Set the salvage value for a packet.
void SetSegmentsLeft(uint8_t segmentsLeft)
Set the number of segments left to send.
uint8_t GetSalvage() const
Get the salvage value for a packet.
void SetNodesAddress(std::vector< Ipv4Address > ipv4Address)
Set the vector of ipv4 address.
uint8_t GetSegmentsLeft() const
Get the number of segments left to send.
DSR Passive Buffer Entry.
void SetIdentification(uint16_t i)
Set identification function.
void SetDestination(Ipv4Address d)
Set destination address function.
void SetSegsLeft(uint8_t seg)
Set segments left.
void SetSource(Ipv4Address s)
Set surce address function.
void SetPacket(Ptr< const Packet > p)
Set packet function.
void SetFragmentOffset(uint16_t f)
Set fragment offset function.
DsrRouteCacheEntry class for entries in the route cache.
Definition: dsr-rcache.h:221
IP_VECTOR GetVector() const
Get the IP vector.
Definition: dsr-rcache.h:293
std::vector< Ipv4Address > IP_VECTOR
Define the vector to hold Ip address.
Definition: dsr-rcache.h:223
Header of Dsr Routing.
Dsr Routing base.
Definition: dsr-routing.h:96
Ptr< dsr::DsrRreqTable > GetRequestTable() const
Get the request table.
Definition: dsr-routing.cc:609
void ScheduleInterRequest(Ptr< Packet > packet)
Schedule the intermediate route request.
void CheckSendBuffer()
Check the send buffer of packets with route when send buffer timer expire.
Definition: dsr-routing.cc:835
Ptr< Ipv4 > m_ip
The ip ptr.
Definition: dsr-routing.h:754
void ScheduleRreqRetry(Ptr< Packet > packet, std::vector< Ipv4Address > address, bool nonProp, uint32_t requestId, uint8_t protocol)
Schedule the route request retry.
Time m_blacklistTimeout
The black list time out.
Definition: dsr-routing.h:820
std::string m_cacheType
The type of route cache.
Definition: dsr-routing.h:844
std::map< Ipv4Address, Timer > m_nonPropReqTimer
Map IP address + RREQ timer.
Definition: dsr-routing.h:866
void SetNode(Ptr< Node > node)
Set the node.
Definition: dsr-routing.cc:577
void SendBuffTimerExpire()
The send buffer timer expire.
Definition: dsr-routing.cc:825
void SetPassiveBuffer(Ptr< dsr::DsrPassiveBuffer > r)
Set the node.
Definition: dsr-routing.cc:615
std::vector< std::string > GetElementsFromContext(std::string context)
Get the elements from the tracing context.
Definition: dsr-routing.cc:534
void UseExtends(DsrRouteCacheEntry::IP_VECTOR rt)
Extends the lifetime of a route cache entry.
Definition: dsr-routing.cc:651
uint32_t m_maxRreqId
The max number of request ids for a single destination.
Definition: dsr-routing.h:818
void SetDownTarget6(IpL4Protocol::DownTargetCallback6 callback)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
void SendPacketFromBuffer(DsrOptionSRHeader const &sourceRoute, Ipv4Address nextHop, uint8_t protocol)
This function is responsible for sending out data packets when have route, if no route found,...
bool SendRealDown(DsrNetworkQueueEntry &newEntry)
This function is called to send packets down stack.
Time m_sendBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for.
Definition: dsr-routing.h:790
uint8_t segsLeft
The segment left value from SR header.
Definition: dsr-routing.h:760
void SendRequest(Ptr< Packet > packet, Ipv4Address source)
Forward the route request if the node is not the destination.
void CancelPacketTimerNextHop(Ipv4Address nextHop, uint8_t protocol)
Cancel the packet retransmission timer for a all maintenance entries with nextHop address.
bool m_linkAck
define if we use link acknowledgement or not
Definition: dsr-routing.h:888
void PrintVector(std::vector< Ipv4Address > &vec)
Print the route vector.
Definition: dsr-routing.cc:710
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
Definition: dsr-routing.h:902
virtual void DoDispose(void)
Drop trace callback.
Definition: dsr-routing.cc:549
void ForwardErrPacket(DsrOptionRerrUnreachHeader &rerr, DsrOptionSRHeader &sourceRoute, Ipv4Address nextHop, uint8_t protocol, Ptr< Ipv4Route > route)
This function is responsible for forwarding error packets along the route.
bool CancelPassiveTimer(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t segsLeft)
Cancel the passive timer.
void PassiveScheduleTimerExpire(DsrMaintainBuffEntry &mb, uint8_t protocol)
This function deals with packet retransmission timer expire using passive acknowledgment.
void SetDownTarget(IpL4Protocol::DownTargetCallback callback)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
bool AddRoute_Link(DsrRouteCacheEntry::IP_VECTOR nodelist, Ipv4Address source)
dd route link to cache See also DsrRouteCache::AddRoute_Link
Definition: dsr-routing.cc:661
uint16_t m_ackId
The ack id assigned to each acknowledge.
Definition: dsr-routing.h:812
DsrRouting()
Constructor.
Definition: dsr-routing.cc:356
void CancelLinkPacketTimer(DsrMaintainBuffEntry &mb)
Cancel the link packet retransmission timer for a specific maintenance entry.
IpL4Protocol::DownTargetCallback6 GetDownTarget6(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
Time m_nonpropRequestTimeout
The non-propagation request timeout.
Definition: dsr-routing.h:774
Time m_gratReplyHoldoff
The max gratuitous reply hold off time.
Definition: dsr-routing.h:838
uint16_t GetIDfromIP(Ipv4Address address)
Get the node id from ip address.
Definition: dsr-routing.cc:781
std::map< uint32_t, Ptr< dsr::DsrNetworkQueue > > m_priorityQueue
priority queues
Definition: dsr-routing.h:890
uint32_t m_maxEntriesEachDst
Max number of route entries to save for each destination.
Definition: dsr-routing.h:806
std::map< Ipv4Address, Timer > m_addressReqTimer
Map IP address + RREQ timer.
Definition: dsr-routing.h:864
virtual enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)
Time m_retransIncr
the increase time for retransmission timer when face network congestion
Definition: dsr-routing.h:860
std::map< NetworkKey, Timer > m_addressForwardTimer
Map network key + forward timer.
Definition: dsr-routing.h:868
uint32_t m_stabilityDecrFactor
The initial decrease factor for link cache.
Definition: dsr-routing.h:848
Time m_nodeTraversalTime
Time estimated for packet to travel between two nodes.
Definition: dsr-routing.h:786
uint32_t m_requestId
The id assigned to each route request.
Definition: dsr-routing.h:810
std::map< NetworkKey, uint32_t > m_addressForwardCnt
Map network key + forward counts.
Definition: dsr-routing.h:870
Ptr< NetDevice > GetNetDeviceFromContext(std::string context)
Get the netdevice from the context.
Definition: dsr-routing.cc:522
bool FindSourceEntry(Ipv4Address src, Ipv4Address dst, uint16_t id)
Find the source request entry in the route request queue, return false if not found.
Definition: dsr-routing.cc:686
Ipv4Address m_broadcast
The broadcast IP address.
Definition: dsr-routing.h:822
Ptr< dsr::DsrPassiveBuffer > GetPassiveBuffer() const
Get the passive buffer.
Definition: dsr-routing.cc:622
Ipv4Address GetIPfromMAC(Mac48Address address)
Get the Ip address from mac address.
Definition: dsr-routing.cc:692
Ptr< dsr::DsrRouteCache > GetRouteCache() const
Get the route cache.
Definition: dsr-routing.cc:596
Time m_maxNetworkDelay
Maximum network delay.
Definition: dsr-routing.h:766
Ptr< dsr::DsrOptions > GetOption(int optionNumber)
Get the option corresponding to optionNumber.
uint32_t m_maxSendBuffLen
The maximum number of packets that we allow a routing protocol to buffer.
Definition: dsr-routing.h:788
IpL4Protocol::DownTargetCallback GetDownTarget(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
TracedCallback< const DsrOptionSRHeader & > m_txPacketTrace
packet trace callback
Definition: dsr-routing.h:719
Time m_passiveAckTimeout
The timeout value for passive acknowledge.
Definition: dsr-routing.h:826
void SetRequestTable(Ptr< dsr::DsrRreqTable > r)
Set the node.
Definition: dsr-routing.cc:602
uint32_t m_maxMaintainLen
Max # of entries for maintenance buffer.
Definition: dsr-routing.h:796
static const uint8_t PROT_NUMBER
Define the dsr protocol number.
Definition: dsr-routing.h:106
uint32_t GetPriority(DsrMessageType messageType)
Set the priority of the packet in network queue.
Definition: dsr-routing.cc:813
void SendReply(Ptr< Packet > packet, Ipv4Address source, Ipv4Address nextHop, Ptr< Ipv4Route > route)
Send the route reply back to the request originator with the cumulated route.
void ScheduleNetworkPacketRetry(DsrMaintainBuffEntry &mb, bool isFirst, uint8_t protocol)
Schedule the packet retransmission based on network layer acknowledgment.
void CallCancelPacketTimer(uint16_t ackId, Ipv4Header const &ipv4Header, Ipv4Address realSrc, Ipv4Address realDst)
Call the cancel packet retransmission timer function.
Ipv4Address m_mainAddress
Our own Ip address.
Definition: dsr-routing.h:758
void SendInitialRequest(Ipv4Address source, Ipv4Address destination, uint8_t protocol)
Broadcast the route request packet in subnet.
Timer m_sendBuffTimer
The send buffer timer.
Definition: dsr-routing.h:834
Time m_maxCacheTime
Max time for caching the route cache entry.
Definition: dsr-routing.h:802
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition: dsr-routing.cc:397
void SendGratuitousReply(Ipv4Address replyTo, Ipv4Address replyFrom, std::vector< Ipv4Address > &nodeList, uint8_t protocol)
Send the gratuitous reply.
void DeleteAllRoutesIncludeLink(Ipv4Address errorSrc, Ipv4Address unreachNode, Ipv4Address node)
Delete all the routes which includes the link from next hop address that has just been notified as un...
Definition: dsr-routing.cc:676
DsrOptionList_t m_options
List of DSR Options supported.
Definition: dsr-routing.h:748
std::map< PassiveKey, uint32_t > m_passiveCnt
Map packet key + passive forward counts.
Definition: dsr-routing.h:872
DsrErrorBuffer m_errorBuffer
The error buffer to save the error messages.
Definition: dsr-routing.h:794
void SalvagePacket(Ptr< const Packet > packet, Ipv4Address source, Ipv4Address dst, uint8_t protocol)
Salvage the packet which has been transmitted for 3 times.
bool m_subRoute
Whether to save sub route or not.
Definition: dsr-routing.h:858
void SendPacket(Ptr< Packet > packet, Ipv4Address source, Ipv4Address nextHop, uint8_t protocol)
This function is called by when really sending out the packet.
bool IsLinkCache()
Checks if the link is cached in the route cache See also DsrRouteCache::IsLinkCache.
Definition: dsr-routing.cc:646
std::map< LinkKey, uint32_t > m_linkCnt
Map packet key + link forward counts.
Definition: dsr-routing.h:876
DsrSendBuffer m_sendBuffer
The send buffer.
Definition: dsr-routing.h:792
uint32_t m_passiveRetries
Definition: dsr-routing.h:778
uint32_t m_rreqRetries
Maximum number of retransmissions of RREQ with TTL = NetDiameter to discover a route.
Definition: dsr-routing.h:782
uint8_t m_maxSalvageCount
Maximum # times to salvage a packet.
Definition: dsr-routing.h:770
Ptr< Ipv4Route > SetRoute(Ipv4Address nextHop, Ipv4Address srcAddress)
Set the route to use for data packets, used by the option headers when sending data/control packets.
Definition: dsr-routing.cc:763
uint16_t AddAckReqHeader(Ptr< Packet > &packet, Ipv4Address nextHop)
This function is called to add ack request header for network acknowledgement.
uint32_t m_requestTableSize
The max size of the request table size.
Definition: dsr-routing.h:814
DsrGraReply m_graReply
The gratuitous route reply.
Definition: dsr-routing.h:892
void ScheduleLinkPacketRetry(DsrMaintainBuffEntry &mb, uint8_t protocol)
Schedule the packet retransmission based on link-layer acknowledgment.
bool PromiscReceive(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Promiscuous receive data packets destined to some other node.
Time m_sendBuffInterval
how often to check send buffer
Definition: dsr-routing.h:836
void ScheduleInitialReply(Ptr< Packet > packet, Ipv4Address source, Ipv4Address nextHop, Ptr< Ipv4Route > route)
this is a generating the initial route reply from the destination address, a random delay time [0,...
bool LookupRoute(Ipv4Address id, DsrRouteCacheEntry &rt)
Lookup route cache entry with destination address dst See also DsrRouteCache::LookupRoute.
Definition: dsr-routing.cc:656
Time m_initStability
The initial stability value for link cache.
Definition: dsr-routing.h:852
uint32_t m_stabilityIncrFactor
The initial increase factor for link cache.
Definition: dsr-routing.h:850
Time m_useExtends
The use extension of the life time for link cache.
Definition: dsr-routing.h:856
uint32_t m_numPriorityQueues
The number of priority queues used.
Definition: dsr-routing.h:886
Ipv4Address SearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Get the next hop of the route.
Definition: dsr-routing.cc:730
IpL4Protocol::DownTargetCallback m_downTarget
The callback for down layer.
Definition: dsr-routing.h:762
uint32_t m_graReplyTableSize
Set the gratuitous reply table size.
Definition: dsr-routing.h:842
bool PassiveEntryCheck(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t segsLeft, uint16_t fragmentOffset, uint16_t identification, bool saveEntry)
Find the same passive entry.
Ptr< Node > GetNodeWithAddress(Ipv4Address ipv4Address)
Get the node with give ip address.
Definition: dsr-routing.cc:629
Ptr< Ipv4L3Protocol > m_ipv4
Ipv4l3Protocol.
Definition: dsr-routing.h:750
void Scheduler(uint32_t priority)
This function is called to schedule sending packets from the network queue.
void RouteRequestTimerExpire(Ptr< Packet > packet, std::vector< Ipv4Address > address, uint32_t requestId, uint8_t protocol)
Handle route discovery timer.
void NetworkScheduleTimerExpire(DsrMaintainBuffEntry &mb, uint8_t protocol)
This function deals with packet retransmission timer expire using network acknowledgment.
uint32_t m_requestTableIds
The request table identifiers.
Definition: dsr-routing.h:816
TracedCallback< Ptr< const Packet > > m_dropTrace
The trace for drop, receive and send data packets.
Definition: dsr-routing.h:718
uint32_t m_tryPassiveAcks
Maximum number of packet transmission using passive acknowledgment.
Definition: dsr-routing.h:828
void LinkScheduleTimerExpire(DsrMaintainBuffEntry &mb, uint8_t protocol)
This function deals with packet retransmission timer expire using link acknowledgment.
bool UpdateRouteEntry(Ipv4Address dst)
Update route cache entry if it has been recently used and successfully delivered the data packet.
Definition: dsr-routing.cc:681
uint32_t m_maxNetworkSize
Maximum network queue size.
Definition: dsr-routing.h:764
Ptr< Ipv4Route > m_ipv4Route
Ipv4 Route.
Definition: dsr-routing.h:752
Ptr< Node > GetNode() const
Get the node.
Definition: dsr-routing.cc:583
Ipv4Address GetIPfromID(uint16_t id)
Get the ip address from id.
Definition: dsr-routing.cc:797
Time m_maxRequestPeriod
The max request period.
Definition: dsr-routing.h:840
void SchedulePassivePacketRetry(DsrMaintainBuffEntry &mb, uint8_t protocol)
Schedule the packet retransmission based on passive acknowledgment.
Ptr< dsr::DsrPassiveBuffer > m_passiveBuffer
A "drop-front" queue used by the routing layer to cache route request sent.
Definition: dsr-routing.h:884
Ptr< Node > m_node
The node ptr.
Definition: dsr-routing.h:756
Ptr< dsr::DsrRouteCache > m_routeCache
A "drop-front" queue used by the routing layer to cache routes found.
Definition: dsr-routing.h:880
std::map< PassiveKey, Timer > m_passiveAckTimer
The timer for passive acknowledgment.
Definition: dsr-routing.h:874
bool AddRoute(DsrRouteCacheEntry &rt)
Add route cache entry if it doesn't yet exist in route cache See also DsrRouteCache::AddRoute.
Definition: dsr-routing.cc:668
Time m_maxMaintainTime
Time out for maintenance buffer.
Definition: dsr-routing.h:798
DsrMaintainBuffer m_maintainBuffer
The declaration of maintain buffer.
Definition: dsr-routing.h:808
uint32_t m_maxMaintRexmt
Maximum number of retransmissions of data packets.
Definition: dsr-routing.h:784
void ForwardPacket(Ptr< const Packet > packet, DsrOptionSRHeader &sourceRoute, Ipv4Header const &ipv4Header, Ipv4Address source, Ipv4Address destination, Ipv4Address targetAddress, uint8_t protocol, Ptr< Ipv4Route > route)
Forward the packet using the route saved in the source route option header.
Time m_requestPeriod
The base time interval between route requests.
Definition: dsr-routing.h:772
Time m_linkAckTimeout
The timeout value for link acknowledge.
Definition: dsr-routing.h:830
void SendUnreachError(Ipv4Address unreachNode, Ipv4Address destination, Ipv4Address originalDst, uint8_t salvage, uint8_t protocol)
This function is responsible for sending error packets in case of break link to next hop.
uint32_t m_tryLinkAcks
Maximum number of packet transmission using link acknowledgment.
Definition: dsr-routing.h:832
uint32_t m_discoveryHopLimit
Maximum hops to go for route request.
Definition: dsr-routing.h:768
void CancelRreqTimer(Ipv4Address dst, bool isRemove)
Cancel the route request timer.
std::map< LinkKey, Timer > m_linkAckTimer
The timer for link acknowledgment.
Definition: dsr-routing.h:878
Time m_minLifeTime
The min life time.
Definition: dsr-routing.h:854
static TypeId GetTypeId()
Get the type identificator.
Definition: dsr-routing.cc:108
void SendErrorRequest(DsrOptionRerrUnreachHeader &rerr, uint8_t protocol)
Send the error request packet.
void PacketNewRoute(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol)
When route vector corrupted, originate a new packet, normally not happening.
Ptr< dsr::DsrRreqTable > m_rreqTable
A "drop-front" queue used by the routing layer to cache route request sent.
Definition: dsr-routing.h:882
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void IncreaseRetransTimer()
This function is called to increase the retransmission timer for data packet in the network queue.
int GetProtocolNumber(void) const
Get the dsr protocol number.
Definition: dsr-routing.cc:774
void CancelPassivePacketTimer(DsrMaintainBuffEntry &mb)
Cancel the passive packet retransmission timer for a specific maintenance entry.
void CancelNetworkPacketTimer(DsrMaintainBuffEntry &mb)
Cancel the network packet retransmission timer for a specific maintenance entry.
void PriorityScheduler(uint32_t priority, bool continueWithFirst)
This function is called to schedule sending packets from the network queue by priority.
void ScheduleCachedReply(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, Ptr< Ipv4Route > route, double hops)
Schedule the cached reply to a random start time to avoid possible route reply storm.
void SendAck(uint16_t ackId, Ipv4Address destination, Ipv4Address realSrc, Ipv4Address realDst, uint8_t protocol, Ptr< Ipv4Route > route)
Send network layer acknowledgment back to the earlier hop to notify the receipt of data packet.
void SetRouteCache(Ptr< dsr::DsrRouteCache > r)
Set the route cache.
Definition: dsr-routing.cc:589
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
This function is called by higher layer protocol when sending packets.
virtual ~DsrRouting()
Destructor.
Definition: dsr-routing.cc:391
void Insert(Ptr< dsr::DsrOptions > option)
Insert a new Dsr Option.
std::vector< Ipv4Address > m_finalRoute
The route cache.
Definition: dsr-routing.h:862
void CancelPacketAllTimer(DsrMaintainBuffEntry &mb)
Cancel all the packet timers.
uint32_t m_broadcastJitter
The max time to delay route request broadcast.
Definition: dsr-routing.h:824
uint32_t m_maxCacheLen
Max # of cache entries for route cache.
Definition: dsr-routing.h:800
DSR Send Buffer Entry.
Definition: dsr-rsendbuff.h:46
Ptr< const Packet > GetPacket() const
Get pointer to entry's packet.
Definition: dsr-rsendbuff.h:79
void SetMaxQueueLen(uint32_t len)
Set the maximum queue length.
uint32_t GetSize()
Number of entries.
bool Dequeue(Ipv4Address dst, DsrSendBuffEntry &entry)
Return first found (the earliest) entry for the given destination.
void SetSendBufferTimeout(Time t)
Set the entry lifetime in the queue.
std::vector< DsrSendBuffEntry > & GetBuffer()
Return a pointer to the internal queue.
bool Enqueue(DsrSendBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
bool Find(Ipv4Address dst)
Check if a packet with destination dst exists in the queue.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:85
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Definition: string.h:42
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1310
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:45
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:258
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:274
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:290
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:282
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1261
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1253
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
address
Definition: first.py:40
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:794
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:661
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:522
mac
Definition: third.py:87
wifi
Definition: third.py:90
uint8_t data[writeSize]
BlackList description.
The gratuitous table entries, it maintains the already sent gratuitous route reply entries.
NetworkKey structure.
Ipv4Address m_ourAdd
local address
Ipv4Address m_destination
destination address
uint16_t m_ackId
acknowledge ID
Ipv4Address m_source
source address
Ipv4Address m_nextHop
next hop
PassiveKey structure.
Ipv4Address m_destination
destination address
Ipv4Address m_source
source address
uint8_t m_segsLeft
segments left
uint16_t m_ackId
acknowledge ID