Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(687)

Unified Diff: src/dsr/model/dsr-routing.cc

Issue 4823051: Dynamic Source Routing (DSR)
Patch Set: Added .rst file for feature discriptions, updated a little in route request process Created 12 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/dsr/model/dsr-routing.h ('k') | src/dsr/model/dsr-rreq-table.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/dsr/model/dsr-routing.cc
===================================================================
--- a/src/dsr/model/dsr-routing.cc
+++ b/src/dsr/model/dsr-routing.cc
@@ -139,8 +139,12 @@
TimeValue (Seconds (300)),
MakeTimeAccessor (&DsrRouting::m_maxCacheTime),
MakeTimeChecker ())
+ .AddAttribute ("MaxEntriesEachDst","Maximum number of route entries for a single destination to respond.",
+ UintegerValue (100),
+ MakeUintegerAccessor (&DsrRouting::m_maxEntriesEachDst),
+ MakeUintegerChecker<uint32_t> ())
.AddAttribute ("SendBuffInterval","How often to check send buffer for packet with route.",
- TimeValue (Seconds (1)),
+ TimeValue (Seconds (10)),
MakeTimeAccessor (&DsrRouting::m_sendBuffInterval),
MakeTimeChecker ())
.AddAttribute ("NodeTraversalTime","The time it takes to traversal the two neighboring nodes.",
@@ -163,6 +167,10 @@
UintegerValue (16),
MakeUintegerAccessor (&DsrRouting::m_requestTableIds),
MakeUintegerChecker<uint16_t> ())
+ .AddAttribute ("UniqueRequestIdSize","Maximum number of request Ids in the request table for a single destination.",
+ UintegerValue (256),
+ MakeUintegerAccessor (&DsrRouting::m_maxRreqId),
+ MakeUintegerChecker<uint16_t> ())
.AddAttribute ("NonPropRequestTimeout","The timeout value for non-propagation request.",
TimeValue (MilliSeconds (30)),
MakeTimeAccessor (&DsrRouting::m_nonpropRequestTimeout),
@@ -191,6 +199,10 @@
TimeValue (MilliSeconds (100)),
MakeTimeAccessor (&DsrRouting::m_passiveAckTimeout),
MakeTimeChecker ())
+ .AddAttribute ("TryPassiveAcks","The number of passive acknowledgment to use.",
+ UintegerValue (1),
+ MakeUintegerAccessor (&DsrRouting::m_tryPassiveAcks),
+ MakeUintegerChecker<uint32_t> ())
.AddAttribute ("RequestPeriod","The base time interval between route requests.",
TimeValue (MilliSeconds (500)),
MakeTimeAccessor (&DsrRouting::m_requestPeriod),
@@ -229,13 +241,16 @@
m_maxMaintainTime (Seconds (30)),
m_maxCacheLen (64),
m_maxCacheTime (Seconds (300)),
+ m_maxEntriesEachDst (100),
m_requestTableSize (64),
m_requestTableIds (16),
+ m_maxRreqId (256),
m_blacklistTimeout (Seconds (3)),
m_broadcastJitter (10),
m_passiveAckTimeout (MilliSeconds (100)),
+ m_tryPassiveAcks (1),
m_sendBuffTimer (Timer::CANCEL_ON_DESTROY),
- m_sendBuffInterval (Seconds (1)),
+ m_sendBuffInterval (Seconds (10)),
m_gratReplyHoldoff (Seconds (1)),
m_maxRequestPeriod (Seconds (10)),
m_graReplyTableSize (64),
@@ -314,7 +329,7 @@
{
// Use primary address, if multiple
Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
- Broadcast = m_ipv4->GetAddress (i, 0).GetBroadcast ();
+ m_broadcast = m_ipv4->GetAddress (i, 0).GetBroadcast();
NS_LOG_DEBUG ("The addr " << addr);
if (addr != loopback)
{
@@ -346,20 +361,22 @@
// Set the initial hop limit
m_rreqTable->SetInitHopLimit (m_discoveryHopLimit);
+ // Configure the request table parameters
+ m_rreqTable->SetRreqTableSize (m_requestTableSize);
+ m_rreqTable->SetRreqIdSize (m_requestTableIds);
+ m_rreqTable->SetUniqueRreqIdSize (m_maxRreqId);
// Set the send buffer parameters
m_sendBuffer.SetMaxQueueLen (m_maxSendBuffLen);
m_sendBuffer.SetSendBufferTimeout (m_sendBufferTimeout);
// Set the maintenance buffer parameters
m_maintainBuffer.SetMaxQueueLen (m_maxMaintainLen);
m_maintainBuffer.SetMaintainBufferTimeout (m_maxMaintainTime);
- // Configure the request table parameters
- m_rreqTable->SetRreqTableSize (m_requestTableSize);
- m_rreqTable->SetRreqIdSize (m_requestTableIds);
// Set the gratuitous reply table size
m_graReply.SetGraTableSize (m_graReplyTableSize);
// Configure the route cache parameters
m_routeCache->SetMaxCacheLen (m_maxCacheLen);
m_routeCache->SetCacheTimeout (m_maxCacheTime);
+ m_routeCache->SetMaxEntriesEachDst (m_maxEntriesEachDst);
m_routeCache->ScheduleTimer ();
// The call back to handle link error and send error message to appropriate nodes
m_routeCache->SetCallback (MakeCallback (&DsrRouting::SendRerrWhenBreaksLinkToNextHop, this));
@@ -467,27 +484,11 @@
}
}
}
- NS_LOG_DEBUG ("next hop address not found");
+ NS_LOG_DEBUG ("Next hop address not found");
Ipv4Address none = "0.0.0.0";
return none;
}
-bool
-DsrRouting::FindSamePackets (Ptr<Packet> packet, Ipv4Header const & ipv4Header, Ipv4Address ourAdd, Ipv4Address nextHop, Ipv4Address source, Ipv4Address destination,
- uint16_t ackId, uint8_t segsLeft, uint16_t routeSize)
-{
- NS_LOG_FUNCTION (this << packet << ipv4Header << ourAdd << nextHop << source << destination << ackId << (uint32_t)segsLeft << routeSize);
- Ptr<const Packet> p = packet->Copy ();
- MaintainBuffEntry newEntry (/*Packet=*/ p, /*Ipv4Header=*/ ipv4Header, /*Ipv4Address=*/ ourAdd, /*nextHop=*/ nextHop,
- /*source=*/ source, /*destination=*/ destination, /*ackId=*/ ackId,
- /*SegsLeft=*/ segsLeft, /*Salvage=*/ 0, /*RouteSize=*/ routeSize,
- /*expire time=*/ m_maxMaintainTime);
-
- NS_LOG_DEBUG ("Before canceling the packet timer " << *p);
- CancelPacketTimer (newEntry);
- return true;
-}
-
Ptr<Ipv4Route>
DsrRouting::SetRoute (Ipv4Address nextHop, Ipv4Address srcAddress)
{
@@ -499,6 +500,21 @@
return m_ipv4Route;
}
+void
+DsrRouting::CutRoute (Ipv4Address ourAdd, std::vector<Ipv4Address>& nodeList)
+{
+ NS_LOG_FUNCTION (this << ourAdd);
+ std::vector<Ipv4Address> newRoute = nodeList;
+ nodeList.clear ();
+
+ std::vector<Ipv4Address>::iterator it = find (newRoute.begin (), newRoute.end (), ourAdd);
+
+ for (std::vector<Ipv4Address>::iterator i = it; i != newRoute.end (); ++i)
+ {
+ nodeList.push_back (*i);
+ }
+}
+
int
DsrRouting::GetProtocolNumber (void) const
{
@@ -530,101 +546,115 @@
return 255;
}
+Ipv4Address
+DsrRouting::GetIPfromID (uint32_t id)
+{
+ if (id >= 255)
+ {
+ NS_LOG_DEBUG ("Exceed the node range");
+ return "0.0.0.0";
+ }
+ else
+ {
+ Ptr<Node> node = NodeList::GetNode (id);
+ Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
+ return ipv4->GetAddress (1, 0).GetLocal ();
+ }
+}
+
void DsrRouting::SendRerrWhenBreaksLinkToNextHop (Ipv4Address nextHop, uint8_t protocol)
{
NS_LOG_FUNCTION (this << nextHop << (uint32_t)protocol);
MaintainBuffEntry entry;
// Find the packet in send buffer
- if (m_maintainBuffer.FindPacketsWithNextHop (nextHop))
+ if (m_maintainBuffer.Find (nextHop))
{
NS_LOG_DEBUG ("Trying to dequeue");
- m_maintainBuffer.Dequeue (nextHop, entry);
- NS_LOG_DEBUG ("creating new packet");
- /*
- * Copy the packet and save a copy to the send buffer.
- * For some reason, when queue the original packet to the buffer,
- * when dequeue the packet, it turns to be empty.
- */
- Ptr<Packet> newPacket = entry.GetPacket ()->Copy ();
- Ipv4Address source = entry.GetSrc ();
- Ipv4Address destination = entry.GetDst ();
- DsrRoutingHeader dsrRoutingHeader;
- Ptr<Packet> p = newPacket->Copy ();
- p->RemoveHeader (dsrRoutingHeader);
- uint8_t dsrHeader = dsrRoutingHeader.GetNextHeader ();
- uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
- newPacket->RemoveAtStart (offset);
+ if (m_maintainBuffer.Dequeue (nextHop, entry))
+ {
+ NS_LOG_DEBUG ("creating new packet");
+ /*
+ * Copy the packet and save a copy to the send buffer.
+ * For some reason, when queue the original packet to the buffer,
+ * when dequeue the packet, it turns to be empty.
+ */
+ Ptr<Packet> dequeP = ConstCast<Packet> (entry.GetPacket ());
+ Ptr<Packet> newPacket = dequeP->Copy ();
+ Ptr<Packet> p = dequeP->Copy ();
- // Get the number of routers' address field
- uint8_t buf[2];
- newPacket->CopyData (buf, sizeof(buf));
- uint8_t numberAddress = (buf[1] - 2) / 4;
+ Ipv4Address source = entry.GetSrc ();
+ Ipv4Address destination = entry.GetDst ();
- DsrOptionSRHeader sourceRoute;
- sourceRoute.SetNumberAddress (numberAddress);
- newPacket->RemoveHeader (sourceRoute);
- uint8_t salvage = sourceRoute.GetSalvage ();
+ DsrRoutingHeader dsrRoutingHeader;
+ p->RemoveHeader (dsrRoutingHeader);
+ uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
+ newPacket->RemoveAtStart (offset);
- DsrOptionAckReqHeader ackReq;
- newPacket->RemoveHeader (ackReq);
- /*
- * Get the node list address
- */
- std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
- Ipv4Address address1 = nodeList.at (1);
- Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList);
- NS_LOG_DEBUG ("The next hop address" << nextHop);
- if (nextHop == "0.0.0.0")
- {
- return;
- }
- RouteCacheEntry salvageRoute;
- bool findRoute = m_routeCache->LookupRoute (destination, salvageRoute);
- // Check the salvage value in header, if salvage is needed, we should find alternative route
- if (findRoute && (salvage < m_maxSalvageCount))
- {
- // Need to salvage the packet instead of discard it
- Ipv4Address source = nodeList.front ();
- std::vector<Ipv4Address> nodeList = salvageRoute.GetVector ();
- DsrOptionSRHeader newSR;
- newSR.SetNodesAddress (nodeList);
- newSR.SetSegmentsLeft ((nodeList.size () - 2));
- newSR.SetSalvage (salvage + 1);
+ // Get the number of routers' address field
+ uint8_t buf[2];
+ newPacket->CopyData (buf, sizeof(buf));
+ uint8_t numberAddress = (buf[1] - 2) / 4;
- if (m_maintainBuffer.FindPacketsWithNextHop (nextHop))
+ DsrOptionSRHeader sourceRoute;
+ sourceRoute.SetNumberAddress (numberAddress);
+ newPacket->RemoveHeader (sourceRoute);
+ uint8_t salvage = sourceRoute.GetSalvage ();
+
+ DsrOptionAckReqHeader ackReq;
+ newPacket->RemoveHeader (ackReq);
+ /*
+ * Get the node list address
+ */
+ std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
+ Ipv4Address address1 = nodeList.front ();
+ Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList);
+ NS_LOG_DEBUG ("The next hop address" << nextHop);
+ if (nextHop == "0.0.0.0")
{
- // Send the data packet using the route we just find
- SendPacket (sourceRoute, nextHop, dsrHeader, m_ipv4Route);
+ return;
}
- }
- else
- {
- /*
- * This code block create a packet and attach a route error option to it
- */
- m_routeCache->DeleteAllRoutesIncludeLink (source, nextHop);
- if (source == m_mainAddress)
+ RouteCacheEntry salvageRoute;
+ bool findRoute = m_routeCache->LookupRoute (destination, salvageRoute);
+ // Check the salvage value in header, if salvage is needed, we should find alternative route
+ if (findRoute && (salvage < m_maxSalvageCount))
{
- DsrOptionRerrUnreachHeader rerr;
- rerr.SetErrorType (1);
- rerr.SetErrorSrc (source);
- rerr.SetUnreachNode (nextHop);
- rerr.SetErrorDst (nextHop);
- rerr.SetSalvage (salvage); // Set the value about whether to salvage a packet or not
- SendErrorRequest (rerr, protocol);
+ // Need to salvage the packet instead of discard it
+ Ipv4Address source = nodeList.front ();
+ std::vector<Ipv4Address> nodeList = salvageRoute.GetVector ();
+ DsrOptionSRHeader newSR;
+ newSR.SetNodesAddress (nodeList);
+ newSR.SetSegmentsLeft ((nodeList.size () - 2));
+ newSR.SetSalvage (salvage + 1);
+ PacketKey packetKey;
+ packetKey.m_ackId = entry.GetAckId ();
+ packetKey.m_ourAdd = entry.GetOurAdd ();
+ packetKey.m_nextHop = entry.GetNextHop ();
+ packetKey.m_source = entry.GetSrc ();
+ packetKey.m_destination = entry.GetDst ();
+ packetKey.m_segsLeft = entry.GetSegsLeft ();
+ SchedulePacketRetry (entry, packetKey, protocol);
}
else
{
+ /*
+ * This code block create a packet and attach a route error option to it
+ */
+ m_routeCache->DeleteAllRoutesIncludeLink (source, nextHop);
+
+ /*
+ * If the salvage is not 0, use the first address in the route as the error dst in error header
+ * otherwise use the source of packet as the error destination
+ */
if (salvage)
{
if (address1 == m_mainAddress)
{
DsrOptionRerrUnreachHeader rerr;
rerr.SetErrorType (1);
- rerr.SetErrorSrc (source);
+ rerr.SetErrorSrc (address1);
rerr.SetUnreachNode (nextHop);
- rerr.SetErrorDst (nextHop);
+ rerr.SetErrorDst (address1);
rerr.SetSalvage (salvage); // Set the value about whether to salvage a packet or not
SendErrorRequest (rerr, protocol);
}
@@ -635,9 +665,27 @@
}
else
{
- SendUnreachError (nextHop, source, salvage, protocol);
+ if (source == m_mainAddress)
+ {
+ DsrOptionRerrUnreachHeader rerr;
+ rerr.SetErrorType (1);
+ rerr.SetErrorSrc (source);
+ rerr.SetUnreachNode (nextHop);
+ rerr.SetErrorDst (source);
+ rerr.SetSalvage (salvage); // Set the value about whether to salvage a packet or not
+ SendErrorRequest (rerr, protocol);
+ }
+ else
+ {
+ SendUnreachError (nextHop, source, salvage, protocol);
+ }
}
}
+ if (m_maintainBuffer.GetSize () != 0 && m_maintainBuffer.Find (nextHop))
+ {
+ Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,100)),
+ &DsrRouting::SendRerrWhenBreaksLinkToNextHop,this,nextHop,protocol);
+ }
}
}
}
@@ -676,6 +724,8 @@
Ptr<Packet> copyP = packet->Copy ();
uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
copyP->RemoveAtStart (offset); // Here the processed size is 8 bytes, which is the fixed sized extension header
+ // The packet to get ipv4 header
+ Ptr<Packet> ipv4P = copyP->Copy ();
/*
* Peek data to get the option type as well as length and segmentsLeft field
*/
@@ -722,9 +772,9 @@
uint8_t length = (sourceRoute.GetLength () + newUnreach.GetLength ());
dsrRoutingHeader.SetNextHeader (protocol);
dsrRoutingHeader.SetMessageType (1);
- dsrRoutingHeader.SetSourceId (255);
+ dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress));
dsrRoutingHeader.SetDestId (255);
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dsrRoutingHeader.AddDsrOption (newUnreach);
dsrRoutingHeader.AddDsrOption (sourceRoute);
@@ -757,32 +807,25 @@
DsrOptionAckReqHeader ackReq;
m_ackId = m_routeCache->CheckUniqueAckId (nextHop);
- ackReq.SetId (m_ackId);
+ ackReq.SetAckId (m_ackId);
uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ());
NS_LOG_DEBUG ("the length of source route header " << (uint32_t)(sourceRoute.GetLength ()));
NS_LOG_DEBUG ("the length of ack request header " << (uint32_t)(ackReq.GetLength ()));
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dsrRoutingHeader.AddDsrOption (sourceRoute);
dsrRoutingHeader.AddDsrOption (ackReq);
cleanP->AddHeader (dsrRoutingHeader);
Ptr<const Packet> mtP = cleanP->Copy ();
- SetRoute (nextHop, m_mainAddress);
-
- Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
- m_ipv4Route->SetOutputDevice (dev);
- Ipv4Header const ipv4Header;
- uint16_t routeSize = sourceRoute.GetNodeListSize (); // Get the route length of in the source route header
// Put the data packet in the maintenance queue for data packet retransmission
- MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Header=*/ ipv4Header, /*Ipv4Address=*/ m_mainAddress, /*nextHop=*/ nextHop,
- /*source=*/ m_mainAddress, /*destination=*/ destination, /*ackId=*/ m_ackId, /*SegsLeft=*/ nodeList.size () - 2,
- /*Salvage=*/ 0, /*RouteSize=*/ routeSize, /*expire time=*/ m_maxMaintainTime);
+ MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Address=*/ m_mainAddress, /*nextHop=*/ nextHop,
+ /*source=*/ m_mainAddress, /*destination=*/ destination, /*ackId=*/ m_ackId,
+ /*SegsLeft=*/nodeList.size () - 2, /*expire time=*/ m_maxMaintainTime);
bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the packet the the maintenance buffer
if (result)
{
Ptr<Packet> newPacket = cleanP->Copy ();
- m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
PacketKey packetKey;
packetKey.m_ackId = newEntry.GetAckId ();
packetKey.m_ourAdd = newEntry.GetOurAdd ();
@@ -790,9 +833,7 @@
packetKey.m_source = newEntry.GetSrc ();
packetKey.m_destination = newEntry.GetDst ();
packetKey.m_segsLeft = newEntry.GetSegsLeft ();
- packetKey.m_id = newEntry.GetId ();
- packetKey.m_fragmentOffset = newEntry.GetFragmentOffset ();
- SchedulePacketRetry (newEntry, packetKey, protocol, m_ipv4Route);
+ SchedulePacketRetry (newEntry, packetKey, protocol);
}
//we need to suspend the normal timer that checks the send buffer
//until we are done sending packets
@@ -840,6 +881,8 @@
dsrPacket->RemoveHeader (dsrRoutingHeader);
uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset (); // Get the offset for option header, 4 bytes in this case
uint8_t nextHeader = dsrRoutingHeader.GetNextHeader ();
+ uint32_t sourceId = dsrRoutingHeader.GetSourceId ();
+ Ipv4Address source = GetIPfromID (sourceId);
// This packet is used to peek option type
p->RemoveAtStart (offset);
@@ -857,7 +900,7 @@
if (optionType == 96) // This is the source route option
{
- dsrOption = GetOption (optionType); // Get the relative dsr option and demux to the process function
+ dsrOption = GetOption (optionType); // Get the relative DSR option and demux to the process function
Ipv4Address fromAddr = GetIPfromMAC (Mac48Address::ConvertFrom (from));
Ipv4Address toAddr = GetIPfromMAC (Mac48Address::ConvertFrom (to));
@@ -868,7 +911,7 @@
" and destination IP " << ipv4Header.GetDestination () <<
" and packet : " << *dsrPacket);
bool isPromisc = true; // Set the boolean value isPromisc as true
- optionLength = dsrOption->Process (p, dsrPacket, m_mainAddress, ipv4Header, nextHeader, isPromisc);
+ optionLength = dsrOption->Process (p, dsrPacket, m_mainAddress, source, ipv4Header, nextHeader, isPromisc);
return true;
}
}
@@ -901,10 +944,13 @@
<< "s Add packet PID: " << packet->GetUid () << " to queue. Packet: " << *packet);
NS_LOG_LOGIC ("Send RREQ to" << destination);
- /*
- * Call the send request function, it will update the request table entry and ttl there
- */
- SendInitialRequest (source, destination, protocol);
+ if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ()) && (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ()))
+ {
+ /*
+ * Call the send request function, it will update the request table entry and ttl there
+ */
+ SendInitialRequest (source, destination, protocol);
+ }
}
}
else
@@ -931,28 +977,23 @@
DsrOptionAckReqHeader ackReq;
m_ackId = m_routeCache->CheckUniqueAckId (nextHop);
- ackReq.SetId (m_ackId);
+ ackReq.SetAckId (m_ackId);
uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ());
-
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dsrRoutingHeader.AddDsrOption (sourceRoute);
dsrRoutingHeader.AddDsrOption (ackReq);
cleanP->AddHeader (dsrRoutingHeader);
Ptr<const Packet> mtP = cleanP->Copy ();
SetRoute (nextHop, m_mainAddress);
- Ipv4Header const ipv4Header;
// Put the data packet in the maintenance queue for data packet retransmission
- MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Header=*/ ipv4Header, /*Ipv4Address=*/ m_mainAddress, /*nextHop=*/ nextHop,
- /*source=*/ source, /*destination=*/ destination, /*ackId=*/ m_ackId, /*SegsLeft=*/ sourceRoute.GetSegmentsLeft (),
- /*Salvage=*/ 0, /*RouteSize=*/ nodeList.size (), /*expire time=*/ m_maxMaintainTime);
+ MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Address=*/ m_mainAddress, /*nextHop=*/ nextHop,
+ /*source=*/ source, /*destination=*/ destination, /*ackId=*/ m_ackId,
+ /*SegsLeft=*/nodeList.size () - 2, /*expire time=*/ m_maxMaintainTime);
bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the packet the the maintenance buffer
if (result)
{
- Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
- m_ipv4Route->SetOutputDevice (dev);
- m_downTarget (cleanP, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
PacketKey packetKey;
packetKey.m_ackId = newEntry.GetAckId ();
packetKey.m_ourAdd = newEntry.GetOurAdd ();
@@ -960,9 +1001,7 @@
packetKey.m_source = newEntry.GetSrc ();
packetKey.m_destination = newEntry.GetDst ();
packetKey.m_segsLeft = newEntry.GetSegsLeft ();
- packetKey.m_id = newEntry.GetId ();
- packetKey.m_fragmentOffset = newEntry.GetFragmentOffset ();
- SchedulePacketRetry (newEntry, packetKey, protocol, m_ipv4Route);
+ SchedulePacketRetry (newEntry, packetKey, protocol);
}
}
}
@@ -974,8 +1013,8 @@
DsrRoutingHeader dsrRoutingHeader;
dsrRoutingHeader.SetNextHeader (protocol);
dsrRoutingHeader.SetMessageType (1);
- dsrRoutingHeader.SetSourceId (255);
- dsrRoutingHeader.SetDestId (255);
+ dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress));
+ dsrRoutingHeader.SetDestId (GetIDfromIP (destination));
DsrOptionRerrUnreachHeader rerrUnreachHeader;
rerrUnreachHeader.SetErrorType (1);
@@ -993,7 +1032,7 @@
NS_LOG_INFO (Simulator::Now ().GetSeconds ()
<< "s " << m_mainAddress << " there is no route for this packet, queue the packet");
- dsrRoutingHeader.SetLength (rerrLength + 2);
+ dsrRoutingHeader.SetPayloadLength (rerrLength + 2);
dsrRoutingHeader.AddDsrOption (rerrUnreachHeader);
Ptr<Packet> newPacket = Create<Packet> ();
newPacket->AddHeader (dsrRoutingHeader);
@@ -1006,7 +1045,14 @@
NS_LOG_INFO (Simulator::Now ().GetSeconds ()
<< "s Add packet PID: " << p->GetUid () << " to queue. Packet: " << *p);
NS_LOG_LOGIC ("Send RREQ to" << destination);
- SendInitialRequest (m_mainAddress, destination, protocol);
+ if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ()) && (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ()))
+ {
+ NS_LOG_DEBUG ("When there is no existing route request for " << destination << ", initialize one");
+ /*
+ * Call the send request function, it will update the request table entry and ttl there
+ */
+ SendInitialRequest (m_mainAddress, destination, protocol);
+ }
}
}
else
@@ -1024,7 +1070,7 @@
uint8_t length = (srLength + rerrLength);
dsrRoutingHeader.SetNextHeader (protocol);
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dsrRoutingHeader.AddDsrOption (rerrUnreachHeader);
dsrRoutingHeader.AddDsrOption (sourceRoute);
Ptr<Packet> newPacket = Create<Packet> ();
@@ -1040,27 +1086,27 @@
void
DsrRouting::ForwardErrPacket (DsrOptionRerrUnreachHeader &rerr,
DsrOptionSRHeader &sourceRoute,
- Ipv4Address destination,
+ Ipv4Address nextHop,
uint8_t protocol,
Ptr<Ipv4Route> route)
{
- NS_LOG_FUNCTION (this << rerr << sourceRoute << destination << (uint32_t)protocol << route);
+ NS_LOG_FUNCTION (this << rerr << sourceRoute << nextHop << (uint32_t)protocol << route);
NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
DsrRoutingHeader dsrRoutingHeader;
dsrRoutingHeader.SetNextHeader (protocol);
dsrRoutingHeader.SetMessageType (1);
- dsrRoutingHeader.SetSourceId (255);
- dsrRoutingHeader.SetDestId (255);
+ dsrRoutingHeader.SetSourceId (GetIDfromIP (rerr.GetErrorSrc ()));
+ dsrRoutingHeader.SetDestId (GetIDfromIP (rerr.GetErrorDst ()));
uint8_t length = (sourceRoute.GetLength () + rerr.GetLength ());
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dsrRoutingHeader.AddDsrOption (rerr);
dsrRoutingHeader.AddDsrOption (sourceRoute);
Ptr<Packet> packet = Create<Packet> ();
packet->AddHeader (dsrRoutingHeader);
Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
route->SetOutputDevice (dev);
- m_downTarget (packet, m_mainAddress, destination, GetProtocolNumber (), route);
+ m_downTarget (packet, m_mainAddress, nextHop, GetProtocolNumber (), route);
}
void
@@ -1098,11 +1144,16 @@
{
NS_LOG_INFO (Simulator::Now ().GetSeconds ()
<< "s Add packet PID: " << packet->GetUid () << " to queue. Packet: " << *packet);
- NS_LOG_LOGIC ("Send RREQ to" << destination);
- /*
- * Call the send request function, it will update the request table entry and ttl there
- */
- SendInitialRequest (source, destination, protocol);
+ NS_LOG_LOGIC ("Send RREQ to " << destination);
+ // Only when there is no existing route request timer when new route request is scheduled
+ if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ()) && (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ()))
+ {
+ NS_LOG_DEBUG ("When there is no existing route request for " << destination << ", initialize one");
+ /*
+ * Call the send request function, it will update the request table entry and ttl there
+ */
+ SendInitialRequest (source, destination, protocol);
+ }
}
}
else
@@ -1129,28 +1180,27 @@
DsrOptionAckReqHeader ackReq;
m_ackId = m_routeCache->CheckUniqueAckId (nextHop);
- ackReq.SetId (m_ackId);
+ ackReq.SetAckId (m_ackId);
uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ());
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dsrRoutingHeader.AddDsrOption (sourceRoute);
dsrRoutingHeader.AddDsrOption (ackReq);
cleanP->AddHeader (dsrRoutingHeader);
+
Ptr<const Packet> mtP = cleanP->Copy ();
- Ipv4Header const ipv4Header;
// Put the data packet in the maintenance queue for data packet retransmission
- MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Header=*/ ipv4Header, /*ourAddress=*/ m_mainAddress, /*nextHop=*/ nextHop,
- /*source=*/ source, /*destination=*/ destination, /*ackId=*/ m_ackId, /*SegsLeft=*/ nodeList.size () - 2,
- /*Salvage=*/ 0, /*RouteSize=*/ nodeList.size (), /*expire time=*/ m_maxMaintainTime);
+ MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_mainAddress, /*nextHop=*/ nextHop,
+ /*source=*/ source, /*destination=*/ destination, /*ackId=*/ m_ackId,
+ /*SegsLeft=*/nodeList.size () - 2, /*expire time=*/ m_maxMaintainTime);
bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the packet the the maintenance buffer
if (result)
{
- SetRoute (nextHop, m_mainAddress);
- Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
- m_ipv4Route->SetOutputDevice (dev);
Ptr<Packet> newPacket = cleanP->Copy ();
- m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
+ /*
+ * Schedule the packet retransmission
+ */
PacketKey packetKey;
packetKey.m_ackId = newEntry.GetAckId ();
packetKey.m_ourAdd = newEntry.GetOurAdd ();
@@ -1158,10 +1208,13 @@
packetKey.m_source = newEntry.GetSrc ();
packetKey.m_destination = newEntry.GetDst ();
packetKey.m_segsLeft = newEntry.GetSegsLeft ();
- packetKey.m_id = newEntry.GetId ();
- packetKey.m_fragmentOffset = newEntry.GetFragmentOffset ();
- SchedulePacketRetry (newEntry, packetKey, protocol, m_ipv4Route);
+ PacketKey networkKey = packetKey;
+ networkKey.m_segsLeft = 0;
+ m_addressForwardCnt[networkKey] = 0;
+ SchedulePacketRetry (newEntry, packetKey, protocol);
}
+ // Try to send packet from *previously* queued entries from send buffer if any
+ SendPacket (sourceRoute, nextHop, protocol);
}
}
}
@@ -1169,10 +1222,9 @@
void
DsrRouting::SendPacket (DsrOptionSRHeader const &sourceRoute,
Ipv4Address nextHop,
- uint8_t protocol,
- Ptr<Ipv4Route> route)
+ uint8_t protocol)
{
- NS_LOG_FUNCTION (this << (uint32_t)protocol << route);
+ NS_LOG_FUNCTION (this << (uint32_t)protocol);
NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
// Reconstruct the route and Retransmit the data packet
@@ -1180,7 +1232,7 @@
Ipv4Address destination = nodeList.back ();
Ipv4Address source = nodeList.front (); // Get the source address
- NS_LOG_INFO ("The nexthop address " << nextHop << " the source " << source << "the destination " << destination);
+ NS_LOG_INFO ("The nexthop address " << nextHop << " the source " << source << " the destination " << destination);
if (m_sendBuffer.Find (destination))
{
@@ -1227,9 +1279,9 @@
DsrRoutingHeader newRoutingHeader;
newRoutingHeader.SetNextHeader (protocol);
newRoutingHeader.SetMessageType (1);
- newRoutingHeader.SetSourceId (255);
- newRoutingHeader.SetDestId (255);
- newRoutingHeader.SetLength (length + 4);
+ newRoutingHeader.SetSourceId (GetIDfromIP (rerr.GetErrorSrc ()));
+ newRoutingHeader.SetDestId (GetIDfromIP (rerr.GetErrorDst ()));
+ newRoutingHeader.SetPayloadLength (length + 4);
newRoutingHeader.AddDsrOption (newUnreach);
newRoutingHeader.AddDsrOption (sourceRoute);
@@ -1241,11 +1293,9 @@
m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
}
}
-
else
{
Ptr<Packet> p = packet->Copy (); // get a copy of the packet
- uint8_t segsLeft = sourceRoute.GetSegmentsLeft ();
// Set the source route option
dsrRoutingHeader.SetNextHeader (protocol);
dsrRoutingHeader.SetMessageType (2);
@@ -1254,32 +1304,27 @@
DsrOptionAckReqHeader ackReq;
m_ackId = m_routeCache->CheckUniqueAckId (nextHop);
- ackReq.SetId (m_ackId);
+ ackReq.SetAckId (m_ackId);
uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ());
- NS_LOG_DEBUG ("the length of source route header " << (uint32_t)(sourceRoute.GetLength ()));
- NS_LOG_DEBUG ("the length of ack request header " << (uint32_t)(ackReq.GetLength ()));
-
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dsrRoutingHeader.AddDsrOption (sourceRoute);
dsrRoutingHeader.AddDsrOption (ackReq);
- uint16_t routeSize = sourceRoute.GetNodeListSize (); // Get the route length of in the source route header
- PrintVector (nodeList);
+ // PrintVector (nodeList);
p->AddHeader (dsrRoutingHeader);
Ptr<const Packet> mtP = p->Copy ();
- Ipv4Header const ipv4Header;
// Put the data packet in the maintenance queue for data packet retransmission
- MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*Ipv4Header=*/ ipv4Header, /*ourAddress=*/ m_mainAddress, /*nextHop=*/ nextHop,
- /*source=*/ source, /*destination=*/ destination, /*ackId=*/ m_ackId, /*SegsLeft=*/ segsLeft,
- /*Salvage=*/ 0, /*RouteSize=*/ routeSize, /*expire time=*/ m_maxMaintainTime);
+ MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_mainAddress, /*nextHop=*/ nextHop,
+ /*source=*/ source, /*destination=*/ destination, /*ackId=*/ m_ackId,
+ /*SegsLeft=*/nodeList.size () - 2, /*expire time=*/ m_maxMaintainTime);
bool result = m_maintainBuffer.Enqueue (newEntry); // Enqueue the packet the the maintenance buffer
if (result)
{
- Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
- route->SetOutputDevice (dev);
- m_downTarget (p, m_mainAddress, nextHop, GetProtocolNumber (), route);
+ // Send out data packet
+ NS_LOG_DEBUG ("Send out packet with ack id " << m_ackId);
+ // Schedule the packet retry timer
PacketKey packetKey;
packetKey.m_ackId = newEntry.GetAckId ();
packetKey.m_ourAdd = newEntry.GetOurAdd ();
@@ -1287,9 +1332,10 @@
packetKey.m_source = newEntry.GetSrc ();
packetKey.m_destination = newEntry.GetDst ();
packetKey.m_segsLeft = newEntry.GetSegsLeft ();
- packetKey.m_id = newEntry.GetId ();
- packetKey.m_fragmentOffset = newEntry.GetFragmentOffset ();
- SchedulePacketRetry (newEntry, packetKey, protocol, route);
+ PacketKey networkKey = packetKey;
+ networkKey.m_segsLeft = 0;
+ m_addressForwardCnt[networkKey] = 0;
+ SchedulePacketRetry (newEntry, packetKey, protocol);
}
}
@@ -1297,12 +1343,12 @@
{
NS_LOG_DEBUG ("Schedule sending the next packet in send buffer");
Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,100)),
- &DsrRouting::SendPacket,this,sourceRoute,nextHop,protocol,route);
+ &DsrRouting::SendPacket,this,sourceRoute,nextHop,protocol);
}
}
else
{
- NS_LOG_DEBUG ("All queued packets are outdated for the destination");
+ NS_LOG_DEBUG ("All queued packets are out-dated for the destination");
}
}
else
@@ -1311,23 +1357,45 @@
}
}
+bool
+DsrRouting::FindSamePackets (Ptr<Packet> packet, Ipv4Header const& ipv4Header, Ipv4Address source, Ipv4Address destination,
+ uint8_t segsLeft)
+{
+ NS_LOG_FUNCTION (this << packet << ipv4Header << source << destination << (uint32_t)segsLeft);
+ /*
+ * Get the source and destination address from ipv4 header
+ */
+ Ipv4Address ourAdd = ipv4Header.GetSource ();
+ Ipv4Address nextHop = ipv4Header.GetDestination ();
+
+ Ptr<Packet> p = packet->Copy ();
+ MaintainBuffEntry newEntry (/*Packet=*/ p, /*Ipv4Address=*/ ourAdd, /*nextHop=*/ nextHop,
+ /*source=*/ source, /*destination=*/ destination, /*ackId=*/ 0,
+ /*SegsLeft=*/segsLeft, /*expire time=*/ m_maxMaintainTime);
+ // Temporarily disable passive acknowledgment
+// CancelPassivePacketTimer (newEntry);
+ return true;
+}
+
void
DsrRouting::CallCancelPacketTimer (uint16_t ackId, Ipv4Header const& ipv4Header, Ipv4Address realSrc, Ipv4Address realDst)
{
NS_LOG_FUNCTION (this << (uint32_t)ackId << ipv4Header << realSrc << realDst);
Ipv4Address sender = ipv4Header.GetDestination ();
Ipv4Address receiver = ipv4Header.GetSource ();
-
- // Put the data packet in the maintenance queue for data packet retransmission
+ /*
+ * Create a packet to fill maintenance buffer, not used to compare
+ * The reason is ack header doesn't have the original packet copy
+ */
Ptr<Packet> mainP = Create<Packet> ();
- MaintainBuffEntry newEntry (/*Packet=*/ mainP, /*Ipv4Header=*/ ipv4Header, /*ourAddress=*/ sender, /*nextHop=*/ receiver,
- /*source=*/ realSrc, /*destination=*/ realDst, /*ackId=*/ ackId, /*SegsLeft=*/ 0,
- /*Salvage=*/ 0, /*RouteSize=*/ 0, /*expire time=*/ Simulator::Now ());
- CancelPacketTimer (newEntry);
+ MaintainBuffEntry newEntry (/*Packet=*/ mainP, /*ourAddress=*/ sender, /*nextHop=*/ receiver,
+ /*source=*/ realSrc, /*destination=*/ realDst, /*ackId=*/ ackId,
+ /*SegsLeft=*/0, /*expire time=*/ Simulator::Now ());
+ CancelNetworkPacketTimer (newEntry);
}
void
-DsrRouting::CancelPacketTimer (MaintainBuffEntry & mb)
+DsrRouting::CancelNetworkPacketTimer (MaintainBuffEntry & mb)
{
NS_LOG_FUNCTION (this);
PacketKey packetKey;
@@ -1336,41 +1404,86 @@
packetKey.m_nextHop = mb.GetNextHop ();
packetKey.m_source = mb.GetSrc ();
packetKey.m_destination = mb.GetDst ();
- packetKey.m_segsLeft = mb.GetSegsLeft ();
- packetKey.m_id = 0;
- packetKey.m_fragmentOffset = 0;
- NS_LOG_INFO ("ackId " << mb.GetAckId () << " ourAdd " << mb.GetOurAdd () << " nextHop " << mb.GetNextHop ()
- << " source " << mb.GetSrc () << " destination "
- << mb.GetDst () << " segsLeft " << (uint32_t)mb.GetSegsLeft ());
+ packetKey.m_segsLeft = 0;
/*
- * Schedule the packet retry
- * Push back the nextHop, source, dst address
+ * Here we have found the entry for send retries, so we get the value and increase it by one
*/
- m_addressForwardTimer[packetKey].Cancel ();
- m_addressForwardTimer[packetKey].Remove ();
- m_addressForwardTimer.erase (packetKey);
- /*
- * cancel passive acknowledgment timer
- */
- PacketKey passiveKey = packetKey;
- passiveKey.m_ackId = 0;
- passiveKey.m_id = mb.GetId ();
- passiveKey.m_fragmentOffset = mb.GetFragmentOffset ();
- m_passiveAckTimer[passiveKey].Cancel ();
- m_passiveAckTimer[passiveKey].Remove ();
- if (m_passiveAckTimer[passiveKey].IsRunning ())
- {
- NS_LOG_DEBUG ("Timer not canceled");
- }
- m_passiveAckTimer.erase (passiveKey);
- // 0 the forward count entry
m_addressForwardCnt[packetKey] = 0;
m_addressForwardCnt.erase (packetKey);
+
+ NS_LOG_INFO ("ackId " << mb.GetAckId () << " ourAdd " << mb.GetOurAdd () << " nextHop " << mb.GetNextHop ()
+ << " source " << mb.GetSrc () << " destination " << mb.GetDst ()
+ << " segsLeft " << (uint32_t)mb.GetSegsLeft ()
+ );
+ // Find the network acknowledgment timer
+ std::map<PacketKey, Timer>::const_iterator i =
+ m_addressForwardTimer.find (packetKey);
+ if (i == m_addressForwardTimer.end ())
+ {
+ NS_LOG_DEBUG ("did not find the packet timer");
+ }
+ else
+ {
+ NS_LOG_DEBUG ("did find the packet timer");
+ /*
+ * Schedule the packet retry
+ * Push back the nextHop, source, destination address
+ */
+ m_addressForwardTimer[packetKey].Cancel ();
+ m_addressForwardTimer[packetKey].Remove ();
+ if (m_addressForwardTimer[packetKey].IsRunning ())
+ {
+ NS_LOG_DEBUG ("Timer not canceled");
+ }
+ m_addressForwardTimer.erase (packetKey);
+ }
+ // Erase the maintenance entry
+ if (m_maintainBuffer.AllEqual (mb))
+ {
+ NS_LOG_DEBUG ("Remove same maintenance buffer entry based on network acknowledgment");
+ }
+}
+
+void
+DsrRouting::CancelPassivePacketTimer (MaintainBuffEntry & mb)
+{
+ NS_LOG_FUNCTION (this);
+ PacketKey passiveKey;
+ passiveKey.m_ackId = 0;
+ passiveKey.m_ourAdd = mb.GetOurAdd ();
+ passiveKey.m_nextHop = mb.GetNextHop ();
+ passiveKey.m_source = mb.GetSrc ();
+ passiveKey.m_destination = mb.GetDst ();
+ passiveKey.m_segsLeft = mb.GetSegsLeft ();
+
+ m_addressForwardCnt[passiveKey] = 0;
+ m_addressForwardCnt.erase (passiveKey);
+
+ // Find the passive acknowledgment timer
+ std::map<PacketKey, Timer>::const_iterator j =
+ m_passiveAckTimer.find (passiveKey);
+ if (j == m_passiveAckTimer.end ())
+ {
+ NS_LOG_DEBUG ("did not find the passive timer");
+ }
+ else
+ {
+ NS_LOG_DEBUG ("find the passive timer");
+ /*
+ * Cancel passive acknowledgment timer
+ */
+ m_passiveAckTimer[passiveKey].Cancel ();
+ m_passiveAckTimer[passiveKey].Remove ();
+ if (m_passiveAckTimer[passiveKey].IsRunning ())
+ {
+ NS_LOG_DEBUG ("Timer not canceled");
+ }
+ m_passiveAckTimer.erase (passiveKey);
+ }
// Erase the maintenance entry
- if (m_maintainBuffer.AllEqual (mb))
+ if (m_maintainBuffer.PromiscEqual (mb))
{
- NS_LOG_DEBUG ("Remove same maintenance buffer entry");
- m_maintainBuffer.EraseEntry (mb);
+ NS_LOG_DEBUG ("Remove same maintenance buffer entry based on passive acknowledgment");
}
}
@@ -1384,17 +1497,18 @@
Ptr<const Packet> packet = entry.GetPacket ()->Copy ();
Ipv4Address source = entry.GetSrc ();
Ipv4Address destination = entry.GetDst ();
- uint8_t salvage = entry.GetSalvage ();
/*
* Cancel the packet timer and then salvage the data packet
*/
- CancelPacketTimer (entry);
- SalvagePacket (packet, source, destination, salvage, protocol);
+ CancelNetworkPacketTimer (entry);
+ SalvagePacket (packet, source, destination, protocol);
if (m_maintainBuffer.GetSize () && m_maintainBuffer.Find (nextHop))
{
NS_LOG_DEBUG ("Cancel the packet timer for next maintenance entry");
- CancelPacketTimerNextHop (nextHop, protocol);
+
+ Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,100)),
+ &DsrRouting::CancelPacketTimerNextHop,this,nextHop,protocol);
}
}
else
@@ -1404,105 +1518,162 @@
}
void
-DsrRouting::SalvagePacket (Ptr<const Packet> packet, Ipv4Address source, Ipv4Address dst, uint8_t salvage, uint8_t protocol)
+DsrRouting::SalvagePacket (Ptr<const Packet> packet, Ipv4Address source, Ipv4Address dst, uint8_t protocol)
{
- NS_LOG_FUNCTION (this << packet << source << dst << (uint32_t)salvage << (uint32_t)protocol);
+ NS_LOG_FUNCTION (this << packet << source << dst << (uint32_t)protocol);
/*
* Look in the route cache for other routes for this destination
*/
RouteCacheEntry toDst;
- Ptr<Packet> salP = packet->Copy ();
+ // Create two copies of packet
+ Ptr<Packet> p = packet->Copy ();
+ Ptr<Packet> newPacket = packet->Copy ();
+ // Remove the routing header in a whole to get a clean packet
+ DsrRoutingHeader dsrRoutingHeader;
+ p->RemoveHeader (dsrRoutingHeader);
+ // Remove offset of dsr routing header
+ uint8_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
+ newPacket->RemoveAtStart (offset);
+
+ // Get the number of routers' address field
+ uint8_t buf[2];
+ newPacket->CopyData (buf, sizeof(buf));
+ uint8_t numberAddress = (buf[1] - 2) / 4;
+
+ DsrOptionSRHeader sourceRoute;
+ sourceRoute.SetNumberAddress (numberAddress);
+ newPacket->RemoveHeader (sourceRoute);
+ uint8_t salvage = sourceRoute.GetSalvage ();
+
+ NS_LOG_DEBUG ("The salvage value get from remove headers " << (uint32_t)salvage);
+
bool findRoute = m_routeCache->LookupRoute (dst, toDst);
if (findRoute && (salvage < m_maxSalvageCount))
{
NS_LOG_DEBUG ("We have found a route for the packet");
- DsrRoutingHeader dsrRoutingHeader;
- dsrRoutingHeader.SetNextHeader (protocol);
- dsrRoutingHeader.SetMessageType (2);
- dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
- dsrRoutingHeader.SetDestId (GetIDfromIP (dst));
+ DsrRoutingHeader newDsrRoutingHeader;
+ newDsrRoutingHeader.SetNextHeader (protocol);
+ newDsrRoutingHeader.SetMessageType (2);
+ newDsrRoutingHeader.SetSourceId (GetIDfromIP (source));
+ newDsrRoutingHeader.SetDestId (GetIDfromIP (dst));
- DsrOptionSRHeader sourceRoute;
std::vector<Ipv4Address> nodeList = toDst.GetVector (); // Get the route from the route entry we found
Ipv4Address nextHop = SearchNextHop (m_mainAddress, nodeList); // Get the next hop address for the route
if (nextHop == "0.0.0.0")
{
- PacketNewRoute (salP, source, dst, protocol);
+ PacketNewRoute (p, source, dst, protocol);
return;
}
// Increase the salvage count by 1
salvage++;
+ DsrOptionSRHeader sourceRoute;
sourceRoute.SetSalvage (salvage);
sourceRoute.SetNodesAddress (nodeList); // Save the whole route in the source route header of the packet
sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); // The segmentsLeft field will indicate the hops to go
-
DsrOptionAckReqHeader ackReq;
m_ackId = m_routeCache->CheckUniqueAckId (nextHop);
- ackReq.SetId (m_ackId);
+ ackReq.SetAckId (m_ackId);
uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ());
NS_LOG_INFO ("length of source route header " << (uint32_t)(sourceRoute.GetLength ())
<< " length of ack request header " << (uint32_t)(ackReq.GetLength ()));
-
- dsrRoutingHeader.SetLength (length + 4);
- dsrRoutingHeader.AddDsrOption (sourceRoute);
- dsrRoutingHeader.AddDsrOption (ackReq);
- salP->AddHeader (dsrRoutingHeader);
+ newDsrRoutingHeader.SetPayloadLength (length + 4);
+ newDsrRoutingHeader.AddDsrOption (sourceRoute);
+ newDsrRoutingHeader.AddDsrOption (ackReq);
+ p->AddHeader (newDsrRoutingHeader);
SetRoute (nextHop, m_mainAddress);
Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
m_ipv4Route->SetOutputDevice (dev);
- m_downTarget (salP, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
+ // Send out the data packet
+ m_downTarget (p, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
/*
* Mark the next hop address in blacklist
*/
NS_LOG_DEBUG ("Save the next hop node in blacklist");
m_rreqTable->MarkLinkAsUnidirectional (nextHop, m_blacklistTimeout);
}
+ else
+ {
+ NS_LOG_DEBUG ("Will not salvage this packet, silently drop");
+ }
}
void
DsrRouting::SchedulePacketRetry (MaintainBuffEntry & mb,
PacketKey const & packetKey,
- uint8_t protocol,
- Ptr<Ipv4Route> route)
+ uint8_t protocol)
{
- NS_LOG_FUNCTION (this << (uint32_t)protocol << route);
+ NS_LOG_FUNCTION (this << (uint32_t)protocol);
Ipv4Address nextHop = mb.GetNextHop ();
Ipv4Address source = mb.GetSrc ();
Ipv4Address dst = mb.GetDst ();
bool isPassive = mb.GetPassive ();
+ // Temporarily disable passive acknowledgment option
+ isPassive = false;
+ NS_LOG_DEBUG ("Sending passive packet retry or network one " << isPassive);
+
+ // Make two copies of the packet key
+ PacketKey networkKey = packetKey;
+ PacketKey passiveKey = packetKey;
+
if (isPassive && nextHop != dst)
{
- PacketKey passiveKey = packetKey;
+ // There is no ack id for passive key, so 0 it
passiveKey.m_ackId = 0;
+ if (m_addressForwardTimer.find (passiveKey) == m_addressForwardTimer.end ())
+ {
+ Timer timer (Timer::CANCEL_ON_DESTROY);
+ m_addressForwardTimer[passiveKey] = timer;
+ }
+ m_sendRetries++;
+ // decrease the passive acknowledgment count
+ m_tryPassiveAcks = (m_tryPassiveAcks - 1);
+ if (!m_tryPassiveAcks)
+ {
+ NS_LOG_DEBUG ("Passive acknowledgment is over");
+ isPassive = false;
+ }
NS_LOG_DEBUG ("The passive acknowledgment option for data packet");
- m_passiveAckTimer[passiveKey].SetFunction (&DsrRouting::PacketScheduleTimerExpire, this);
- m_passiveAckTimer[passiveKey].Remove ();
- m_passiveAckTimer[passiveKey].SetArguments (mb, passiveKey, protocol, isPassive);
- m_passiveAckTimer[passiveKey].Schedule (m_passiveAckTimeout);
- isPassive = false;
+ m_addressForwardTimer[passiveKey].SetFunction (&DsrRouting::PacketScheduleTimerExpire, this);
+ m_addressForwardTimer[passiveKey].Remove ();
+ m_addressForwardTimer[passiveKey].SetArguments (mb, passiveKey, protocol, isPassive);
+ // forward count
+ m_addressForwardCnt[passiveKey] = m_sendRetries;
+ NS_LOG_DEBUG ("The packet retries time is " << m_sendRetries);
+ m_addressForwardTimer[passiveKey].Schedule (m_passiveAckTimeout);
return;
}
else
{
+ // There is no segments left value for network key, so 0 it
+ networkKey.m_segsLeft = 0;
+
+ if (m_addressForwardTimer.find (networkKey) == m_addressForwardTimer.end ())
+ {
+ Timer timer (Timer::CANCEL_ON_DESTROY);
+ m_addressForwardTimer[networkKey] = timer;
+ }
/*
* Here we have found the entry for send retries, so we get the value and increase it by one
*/
- m_sendRetries = m_addressForwardCnt[packetKey];
+ m_sendRetries = m_addressForwardCnt[networkKey];
+ NS_LOG_DEBUG ("The packet retry we have done " << m_sendRetries);
/*
* If a data packet has been attempted SendRetries times at the maximum TTL without
* receiving any ACK, all data packets destined for the corresponding destination SHOULD be
* dropped from the send buffer
+ *
+ * The maxMaintRexmt also needs to decrease one for the passive ack packet
*/
- if (m_sendRetries >= m_maxMaintRexmt)
+ Ptr<Packet> p = mb.GetPacket ()->Copy ();
+ Ptr<Packet> dsrP = p->Copy ();
+ Ptr<Packet> salP = p->Copy ();
+ Ptr<Packet> retransP = p->Copy ();
+ // The packet retries time has exceed the max maintenance retransmission times
+ if (m_sendRetries > m_maxMaintRexmt)
{
- NS_LOG_LOGIC ("Packet transmissions to " << nextHop << " has been attempted SendRetries times, need to send error message");
- // Here is the route error header attached
- uint8_t salvage = mb.GetSalvage ();
- Ptr<Packet> p = mb.GetPacket ()->Copy ();
- Ptr<Packet> dsrP = p->Copy ();
-
+ NS_LOG_LOGIC ("Packet transmissions to " << nextHop << " has been attempted SendRetries times for " << networkKey.m_ackId);
DsrRoutingHeader dsrRoutingHeader;
dsrP->RemoveHeader (dsrRoutingHeader); // Remove the dsr header in whole
uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
@@ -1517,51 +1688,58 @@
sourceRoute.SetNumberAddress (numberAddress);
p->RemoveHeader (sourceRoute);
std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
- PrintVector (nodeList);
- Ipv4Address address1 = nodeList.at (1);
+ uint8_t salvage = sourceRoute.GetSalvage ();
+ Ipv4Address address1 = nodeList.front ();
NS_LOG_DEBUG ("address1 " << address1);
+ CutRoute (m_mainAddress, nodeList);
+ NS_LOG_DEBUG ("The route vector after cut and the route source " << nodeList.front ());
+// PrintVector (nodeList);
// Delete the route cache entry
RouteCacheEntry toDst;
- m_routeCache->DeleteRouteEntry (dst);
// Cancel the packet timer for maintenance buffer entry
- CancelPacketTimer (mb);
+ CancelNetworkPacketTimer (mb);
/*
* Mark the next hop address in blacklist
*/
NS_LOG_DEBUG ("Save the next hop node in blacklist");
m_rreqTable->MarkLinkAsUnidirectional (nextHop, m_blacklistTimeout);
-
+ // Delete all the routes including the links
m_routeCache->DeleteAllRoutesIncludeLink (m_mainAddress, nextHop);
- if (source == m_mainAddress)
+ // After deleting the broken link from all routes, need to salvage the packet right after dropping it
+ SalvagePacket (salP, source, dst, protocol);
+ /*
+ * If the salvage is not 0, use the first address in the route as the error dst in error header
+ * otherwise use the source of packet as the error destination
+ */
+ if (salvage)
{
- // We are the error source
- DsrOptionRerrUnreachHeader rerr;
- rerr.SetErrorType (1);
- rerr.SetErrorSrc (source);
- rerr.SetUnreachNode (nextHop);
- rerr.SetErrorDst (nextHop);
- rerr.SetSalvage (mb.GetSalvage ()); // Set the value about whether to salvage a packet or not
- SendErrorRequest (rerr, protocol);
+ if (address1 == m_mainAddress)
+ {
+ DsrOptionRerrUnreachHeader rerr;
+ rerr.SetErrorType (1);
+ rerr.SetErrorSrc (address1);
+ rerr.SetUnreachNode (nextHop);
+ rerr.SetErrorDst (address1);
+ rerr.SetSalvage (salvage); // Set the value about whether to salvage a packet or not
+ SendErrorRequest (rerr, protocol);
+ }
+ else
+ {
+ SendUnreachError (nextHop, address1, salvage, protocol);
+ }
}
else
{
- if (salvage)
+ if (source == m_mainAddress)
{
- if (address1 == m_mainAddress)
- {
- DsrOptionRerrUnreachHeader rerr;
- rerr.SetErrorType (1);
- rerr.SetErrorSrc (source);
- rerr.SetUnreachNode (nextHop);
- rerr.SetErrorDst (nextHop);
- rerr.SetSalvage (mb.GetSalvage ()); // Set the value about whether to salvage a packet or not
- SendErrorRequest (rerr, protocol);
- }
- else
- {
- SendUnreachError (nextHop, address1, salvage, protocol);
- }
+ DsrOptionRerrUnreachHeader rerr;
+ rerr.SetErrorType (1);
+ rerr.SetErrorSrc (source);
+ rerr.SetUnreachNode (nextHop);
+ rerr.SetErrorDst (source);
+ rerr.SetSalvage (salvage); // Set the value about whether to salvage a packet or not
+ SendErrorRequest (rerr, protocol);
}
else
{
@@ -1573,18 +1751,23 @@
else
{
m_sendRetries++;
- PacketKey networkKey = packetKey;
- networkKey.m_id = 0;
- networkKey.m_fragmentOffset = 0;
+ // Send out the retransmission packet
+ m_ipv4Route = SetRoute (nextHop, m_mainAddress);
+ Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
+ m_ipv4Route->SetOutputDevice (dev);
+ m_downTarget (retransP, source, nextHop, GetProtocolNumber (), m_ipv4Route);
+ // After m_tryPassiveAcks, schedule the packet retransmission using network acknowledgment option
m_addressForwardTimer[networkKey].SetFunction (&DsrRouting::PacketScheduleTimerExpire, this);
m_addressForwardTimer[networkKey].Remove ();
- m_addressForwardTimer[networkKey].SetArguments (mb, networkKey, protocol, isPassive);
+ m_addressForwardTimer[networkKey].SetArguments (mb, networkKey, protocol, false);
// forward count
m_addressForwardCnt[networkKey] = m_sendRetries;
+ NS_LOG_DEBUG ("The packet retries time for " << mb.GetAckId() << " is " << m_sendRetries);
// Back-off mechanism
m_addressForwardTimer[networkKey].Schedule (Time (2 * m_sendRetries * m_nodeTraversalTime));
}
}
+ return;
}
void
@@ -1596,11 +1779,11 @@
DsrOptionAckReqHeader ackReq;
m_ackId = m_routeCache->CheckUniqueAckId (nextHop);
- ackReq.SetId (m_ackId);
+ ackReq.SetAckId (m_ackId);
uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ());
DsrRoutingHeader dsrRoutingHeader;
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dsrRoutingHeader.AddDsrOption (sourceRoute);
dsrRoutingHeader.AddDsrOption (ackReq);
cleanP->AddHeader (dsrRoutingHeader);
@@ -1612,12 +1795,12 @@
uint8_t protocol,
bool isPassive)
{
- NS_LOG_LOGIC (this << (uint32_t)protocol << isPassive);
+ NS_LOG_FUNCTION (this << (uint32_t)protocol << isPassive);
Ipv4Address nextHop = mb.GetNextHop ();
Ipv4Address source = mb.GetSrc ();
Ipv4Address dst = mb.GetDst ();
Ptr<const Packet> packet = mb.GetPacket ();
- SetRoute (nextHop, source);
+ SetRoute (nextHop, m_mainAddress);
Ptr<Packet> p = packet->Copy ();
if (isPassive)
{
@@ -1630,34 +1813,15 @@
}
m_passiveAckTimer.erase (pk);
isPassive = false;
- Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
- m_ipv4Route->SetOutputDevice (dev);
- m_downTarget (p, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
- ScheduleNetworkAck (mb, pk, protocol, m_ipv4Route, isPassive);
+ mb.SetPassive (false);
+ SchedulePacketRetry (mb, pk, protocol);
}
else
{
- Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
- m_ipv4Route->SetOutputDevice (dev);
- m_downTarget (p, m_mainAddress, nextHop, GetProtocolNumber (), m_ipv4Route);
+ mb.SetPassive (false);
+ SchedulePacketRetry (mb, pk, protocol);
}
-}
-
-void
-DsrRouting::ScheduleNetworkAck (MaintainBuffEntry & mb,
- PacketKey const & pk,
- uint8_t protocol,
- Ptr<Ipv4Route> route,
- bool isPassive)
-{
- NS_LOG_FUNCTION (this << (uint32_t) protocol << isPassive);
- NS_LOG_DEBUG ("Schedule network acknowledgment option for data packet");
- m_passiveAckTimer[pk].SetFunction (&DsrRouting::SchedulePacketRetry, this);
- m_passiveAckTimer[pk].Remove ();
- isPassive = false;
- mb.SetPassive (isPassive);
- m_passiveAckTimer[pk].SetArguments (mb, pk, protocol, route);
- m_passiveAckTimer[pk].Schedule (m_passiveAckTimeout);
+ return;
}
void
@@ -1667,11 +1831,10 @@
Ipv4Address source,
Ipv4Address nextHop,
Ipv4Address targetAddress,
- uint8_t routeSize,
uint8_t protocol,
Ptr<Ipv4Route> route)
{
- NS_LOG_FUNCTION (this << packet << sourceRoute << source << nextHop << (uint32_t)protocol << route);
+ NS_LOG_FUNCTION (this << packet << sourceRoute << source << nextHop << targetAddress << (uint32_t)protocol << route);
NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
DsrRoutingHeader dsrRoutingHeader;
@@ -1684,24 +1847,23 @@
Ptr<Packet> p = packet->Copy ();
DsrOptionAckReqHeader ackReq;
m_ackId = m_routeCache->CheckUniqueAckId (nextHop);
- ackReq.SetId (m_ackId);
+ ackReq.SetAckId (m_ackId);
uint8_t length = (sourceRoute.GetLength () + ackReq.GetLength ());
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dsrRoutingHeader.AddDsrOption (sourceRoute);
dsrRoutingHeader.AddDsrOption (ackReq);
p->AddHeader (dsrRoutingHeader);
Ptr<const Packet> mtP = p->Copy ();
- MaintainBuffEntry newEntry (mtP, ipv4Header, m_mainAddress, nextHop, source, targetAddress, m_ackId, sourceRoute.GetSegmentsLeft (), sourceRoute.GetSalvage (), routeSize);
+ MaintainBuffEntry newEntry (/*Packet=*/ mtP, /*ourAddress=*/ m_mainAddress, /*nextHop=*/ nextHop,
+ /*source=*/ source, /*destination=*/ targetAddress,
+ /*ackId=*/ m_ackId, /*SegsLeft=*/sourceRoute.GetSegmentsLeft(), /*expire time=*/ m_maxMaintainTime);
bool result = m_maintainBuffer.Enqueue (newEntry);
if (result)
{
- Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
- route->SetOutputDevice (dev);
Ptr<Packet> newPacket = p->Copy ();
- m_downTarget (newPacket, m_mainAddress, nextHop, GetProtocolNumber (), route);
PacketKey packetKey;
packetKey.m_ackId = newEntry.GetAckId ();
packetKey.m_ourAdd = newEntry.GetOurAdd ();
@@ -1709,9 +1871,10 @@
packetKey.m_source = newEntry.GetSrc ();
packetKey.m_destination = newEntry.GetDst ();
packetKey.m_segsLeft = newEntry.GetSegsLeft ();
- packetKey.m_id = newEntry.GetId ();
- packetKey.m_fragmentOffset = newEntry.GetFragmentOffset ();
- SchedulePacketRetry (newEntry, packetKey, protocol, route);
+ PacketKey networkKey = packetKey;
+ networkKey.m_segsLeft = 0;
+ m_addressForwardCnt[networkKey] = 0;
+ SchedulePacketRetry (newEntry, packetKey, protocol);
}
}
@@ -1723,7 +1886,7 @@
NS_LOG_FUNCTION (this << source << destination << (uint32_t)protocol);
NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
Ptr<Packet> packet = Create<Packet> ();
- // Create an empty route ptr
+ // Create an empty Ipv4 route ptr
Ptr<Ipv4Route> route;
/*
* Construct the route request option header
@@ -1731,7 +1894,7 @@
DsrRoutingHeader dsrRoutingHeader;
dsrRoutingHeader.SetNextHeader (protocol);
dsrRoutingHeader.SetMessageType (1);
- dsrRoutingHeader.SetSourceId (255);
+ dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
dsrRoutingHeader.SetDestId (255);
DsrOptionRreqHeader rreqHeader; // has an alignment of 4n+0
@@ -1739,16 +1902,17 @@
rreqHeader.SetTarget (destination);
m_requestId = m_rreqTable->CheckUniqueRreqId (destination); // Check the Id cache for duplicate ones
rreqHeader.SetId (m_requestId);
-
- // This function will increase the request count if found the entry, will create the entry if not found
- m_rreqTable->IncrementRreqCnt (destination);
+ // Increment the route request count, if entry not found, the function will create a new one
+ m_rreqTable->FindAndUpdate (destination);
dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader to the dsr extension header
uint8_t length = rreqHeader.GetLength ();
- dsrRoutingHeader.SetLength (length + 2);
+ dsrRoutingHeader.SetPayloadLength (length + 2);
packet->AddHeader (dsrRoutingHeader);
- // Schedule the route requests retry
+ // This function will increase the request count if found the entry, will create the entry if not found
+ m_rreqTable->FindAndUpdate (destination);
+ // Schedule the route requests retry with non-propagation set true
bool nonProp = true;
ScheduleRreqRetry (packet, source, destination, nonProp, protocol);
}
@@ -1769,7 +1933,7 @@
DsrRoutingHeader dsrRoutingHeader;
dsrRoutingHeader.SetNextHeader (protocol);
dsrRoutingHeader.SetMessageType (1);
- dsrRoutingHeader.SetSourceId (255);
+ dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress));
dsrRoutingHeader.SetDestId (255);
if (m_mainAddress != destination)
@@ -1777,6 +1941,7 @@
/*
* Send error request to the error source
*/
+ NS_LOG_DEBUG ("Send error packet to the error source");
Ptr<Packet> dstP = Create<Packet> ();
DsrOptionRreqHeader rreqHeader; // has an alignment of 4n+0
rreqHeader.AddNodeAddress (m_mainAddress); // Add our own address in the header
@@ -1784,46 +1949,65 @@
m_requestId = m_rreqTable->CheckUniqueRreqId (destination); // Check the Id cache for duplicate ones
rreqHeader.SetId (m_requestId);
// This function will increase the request count if found the entry, will create the entry if not found
- m_rreqTable->IncrementRreqCnt (destination);
+ m_rreqTable->FindAndUpdate (destination);
dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader to the dsr extension header
dsrRoutingHeader.AddDsrOption (rerr);
uint8_t length = rreqHeader.GetLength () + rerr.GetLength ();
- dsrRoutingHeader.SetLength (length + 4);
+ dsrRoutingHeader.SetPayloadLength (length + 4);
dstP->AddHeader (dsrRoutingHeader);
// Schedule the route requests retry, propagate the route request message as it contains error
bool nonProp = false;
- ScheduleRreqRetry (dstP, m_mainAddress, destination, nonProp, protocol);
+ if ((m_addressReqTimer.find (destination) == m_addressReqTimer.end ()) && (m_nonPropReqTimer.find (destination) == m_nonPropReqTimer.end ()))
+ {
+ NS_LOG_DEBUG ("Only when there is no existing route request time when this one is triggered");
+ ScheduleRreqRetry (dstP, m_mainAddress, destination, nonProp, protocol);
+ }
}
- /*
- * Send error request to the unreachable node
- */
- DsrOptionRreqHeader rreqHeader; // has an alignment of 4n+0
- rreqHeader.AddNodeAddress (m_mainAddress); // Add our own address in the header
- rreqHeader.SetTarget (unreachAddress);
- m_requestId = m_rreqTable->CheckUniqueRreqId (unreachAddress); // Check the Id cache for duplicate ones
- rreqHeader.SetId (m_requestId);
- // This function will increase the request count if found the entry, will create the entry if not found
- m_rreqTable->IncrementRreqCnt (unreachAddress);
+ else
+ {
+ /*
+ * Send error request to the unreachable node
+ */
+ DsrOptionRreqHeader rreqHeader; // has an alignment of 4n+0
+ rreqHeader.AddNodeAddress (m_mainAddress); // Add our own address in the header
+ rreqHeader.SetTarget (unreachAddress);
+ m_requestId = m_rreqTable->CheckUniqueRreqId (unreachAddress); // Check the Id cache for duplicate ones
+ rreqHeader.SetId (m_requestId);
+ // This function will increase the request count if found the entry, will create the entry if not found
+ m_rreqTable->FindAndUpdate (unreachAddress);
- dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader to the dsr extension header
- dsrRoutingHeader.AddDsrOption (rerr);
- uint8_t length = rreqHeader.GetLength () + rerr.GetLength ();
- dsrRoutingHeader.SetLength (length + 4);
- packet->AddHeader (dsrRoutingHeader);
- // Schedule the route requests retry, propagate the route request message as it contains error
- bool nonProp = false;
- ScheduleRreqRetry (packet, m_mainAddress, unreachAddress, nonProp, protocol);
+ dsrRoutingHeader.AddDsrOption (rreqHeader); // Add the rreqHeader to the dsr extension header
+ dsrRoutingHeader.AddDsrOption (rerr);
+ uint8_t length = rreqHeader.GetLength () + rerr.GetLength ();
+ dsrRoutingHeader.SetPayloadLength (length + 4);
+ packet->AddHeader (dsrRoutingHeader);
+ // Schedule the route requests retry, propagate the route request message as it contains error
+ bool nonProp = false;
+ if ((m_addressReqTimer.find (unreachAddress) == m_addressReqTimer.end ()) && (m_nonPropReqTimer.find (unreachAddress) == m_nonPropReqTimer.end ()))
+ {
+ NS_LOG_DEBUG ("Only when there is no existing route request time when this one is triggered");
+ ScheduleRreqRetry (packet, m_mainAddress, unreachAddress, nonProp, protocol);
+ }
+ }
}
-
void
DsrRouting::CancelRreqTimer (Ipv4Address dst)
{
NS_LOG_FUNCTION (this << dst);
// Cancel the non propagation request timer if found
+ if (m_nonPropReqTimer.find (dst) == m_nonPropReqTimer.end ())
+ {
+ NS_LOG_DEBUG ("Did not find the non-propagation timer");
+ }
+ else
+ {
+ NS_LOG_DEBUG ("did find the non-propagation timer");
+ }
m_nonPropReqTimer[dst].Cancel ();
m_nonPropReqTimer[dst].Remove ();
+
if (m_nonPropReqTimer[dst].IsRunning ())
{
NS_LOG_DEBUG ("Timer not canceled");
@@ -1831,6 +2015,14 @@
m_nonPropReqTimer.erase (dst);
// Cancel the address request timer if found
+ if (m_addressReqTimer.find (dst) == m_addressReqTimer.end ())
+ {
+ NS_LOG_DEBUG ("Did not find the propagation timer");
+ }
+ else
+ {
+ NS_LOG_DEBUG ("did find the propagation timer");
+ }
m_addressReqTimer[dst].Cancel ();
m_addressReqTimer[dst].Remove ();
if (m_addressReqTimer[dst].IsRunning ())
@@ -1839,7 +2031,7 @@
}
m_addressReqTimer.erase (dst);
- // remove the route request entry from rreq table
+ // remove the route request entry from route request table
m_rreqTable->RemoveRreqEntry (dst);
}
@@ -1860,15 +2052,10 @@
*/
SocketIpTtlTag tag;
tag.SetTtl (0);
- Ptr<Packet> nonProP = packet->Copy ();
- nonProP->AddPacketTag (tag);
- // Set the request table entry
- RreqTableEntry entry;
- entry.m_dst = dst;
- entry.m_ttl = 0;
- entry.m_reqNo = 0;
- m_rreqTable->Update (entry);
- SendRequest (nonProP, source);
+ Ptr<Packet> nonPropPacket = packet->Copy ();
+ nonPropPacket->AddPacketTag (tag);
+ SendRequest (nonPropPacket, source);
+ NS_LOG_DEBUG ("Check the route request entry3 " << source << " " << dst);
m_nonPropReqTimer[dst].SetFunction (&DsrRouting::ScheduleRreqRetry, this);
m_nonPropReqTimer[dst].Remove ();
m_nonPropReqTimer[dst].SetArguments (packet, source, dst, nonProp, protocol);
@@ -1890,28 +2077,28 @@
SocketIpTtlTag tag;
tag.SetTtl (m_discoveryHopLimit);
packet->AddPacketTag (tag);
- // Set the request table entry
- RreqTableEntry entry;
- entry.m_dst = dst;
- entry.m_ttl = m_discoveryHopLimit;
- entry.m_reqNo = 0;
- m_rreqTable->Update (entry);
if (m_addressReqTimer.find (dst) == m_addressReqTimer.end ())
{
Timer timer (Timer::CANCEL_ON_DESTROY);
m_addressReqTimer[dst] = timer;
}
- m_rreqTable->IncrementRreqCnt (dst);
m_addressReqTimer[dst].SetFunction (&DsrRouting::RouteRequestTimerExpire, this);
m_addressReqTimer[dst].Remove ();
m_addressReqTimer[dst].SetArguments (packet, source, dst, protocol);
- Time rreqDelay = Time (2 * m_rreqTable->GetRreqCnt (dst) * m_requestPeriod);
+ // Increase the request count
+ m_rreqTable->FindAndUpdate (dst);
+ // back off mechanism for sending route requests
+ Time rreqDelay = Time (pow (m_rreqTable->GetRreqCnt (dst), 2) * m_requestPeriod);
+ NS_LOG_DEBUG ("The request count for the destination " << dst << " " << m_rreqTable->GetRreqCnt (dst) << " with time value " << rreqDelay);
if (rreqDelay > m_maxRequestPeriod)
{
+ // use the max request period
+ NS_LOG_DEBUG ("The max request delay time " << m_maxRequestPeriod.GetSeconds());
m_addressReqTimer[dst].Schedule (m_maxRequestPeriod);
}
else
{
+ NS_LOG_DEBUG ("The request delay time " << rreqDelay.GetSeconds());
m_addressReqTimer[dst].Schedule (rreqDelay);
}
}
@@ -1920,7 +2107,7 @@
void
DsrRouting::RouteRequestTimerExpire (Ptr<Packet> packet, Ipv4Address source, Ipv4Address dst, uint8_t protocol)
{
- NS_LOG_LOGIC (this << packet << source << dst << (uint32_t)protocol);
+ NS_LOG_FUNCTION (this << packet << source << dst << (uint32_t)protocol);
RouteCacheEntry toDst;
if (m_routeCache->LookupRoute (dst, toDst))
{
@@ -1929,6 +2116,7 @@
*/
DsrOptionSRHeader sourceRoute;
std::vector<Ipv4Address> ip = toDst.GetVector ();
+// PrintVector (ip);
sourceRoute.SetNodesAddress (ip);
sourceRoute.SetSegmentsLeft ((ip.size () - 2));
uint8_t salvage = 0;
@@ -1941,7 +2129,7 @@
}
SetRoute (nextHop, m_mainAddress);
CancelRreqTimer (dst);
- SendPacket (sourceRoute, nextHop, protocol, m_ipv4Route);
+ SendPacket (sourceRoute, nextHop, protocol);
NS_LOG_LOGIC ("Route to " << dst << " found");
return;
}
@@ -1950,93 +2138,96 @@
* receiving any RREP, all data packets destined for the corresponding destination SHOULD be
* dropped from the buffer and a Destination Unreachable message SHOULD be delivered to the application.
*/
+ NS_LOG_DEBUG ("The new request count for " << dst << " is " << m_rreqTable->GetRreqCnt (dst) << " the max " << m_rreqRetries);
if (m_rreqTable->GetRreqCnt (dst) >= m_rreqRetries)
{
- NS_LOG_LOGIC ("route discovery to " << dst << " has been attempted " << m_rreqRetries << " times");
- m_addressReqTimer.erase (dst);
- m_routeCache->DeleteRoute (dst);
+ NS_LOG_LOGIC ("Route discovery to " << dst << " has been attempted " << m_rreqRetries << " times");
+ CancelRreqTimer (dst);
NS_LOG_DEBUG ("Route not found. Drop packet with dst " << dst);
m_sendBuffer.DropPacketWithDst (dst);
}
else
{
- NS_LOG_DEBUG ("Here we send the request retry");
SendRequest (packet, source);
+ NS_LOG_DEBUG ("Check the route request entry1 " << source << " " << dst);
+ ScheduleRreqRetry (packet, source, dst, false, protocol);
}
+ return;
}
void
DsrRouting::SendRequest (Ptr<Packet> packet,
Ipv4Address source)
{
- NS_LOG_FUNCTION (this << packet << source );
+ NS_LOG_FUNCTION (this << packet << source);
NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
/*
* The destination address here is directed broadcast address
*/
- m_downTarget (packet, source, Broadcast, GetProtocolNumber (), 0);
+ m_downTarget (packet, source, m_broadcast, GetProtocolNumber (), 0);
}
void
-DsrRouting::ScheduleInterRequest (Ptr<Packet> packet,
- Ipv4Address source)
+DsrRouting::ScheduleInterRequest (Ptr<Packet> packet)
{
- NS_LOG_FUNCTION (this << packet << source);
+ NS_LOG_FUNCTION (this << packet);
/*
- * this is a forwarding case when sending ip packet to next hop, a random delay time [0, m_broadcastJitter]
+ * this is a forwarding case when sending route requests, a random delay time [0, m_broadcastJitter]
* used before forwarding as link-layer broadcast
*/
Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0, m_broadcastJitter)), &DsrRouting::SendRequest, this,
- packet, source);
+ packet, m_mainAddress);
}
void
-DsrRouting::SendGratuitousReply (Ipv4Address replyTo, Ipv4Address replyFrom, std::vector<Ipv4Address> &nodeList, uint8_t protocol)
+DsrRouting::SendGratuitousReply (Ipv4Address source, Ipv4Address srcAddress, std::vector<Ipv4Address> &nodeList, uint8_t protocol)
{
- NS_LOG_FUNCTION (this << replyTo << replyFrom);
- if (!(m_graReply.FindAndUpdate (replyTo, replyFrom, m_gratReplyHoldoff))) // Find the gratuitous reply entry
+ NS_LOG_FUNCTION (this << source << srcAddress << (uint32_t)protocol);
+ if (!(m_graReply.FindAndUpdate (source, srcAddress, m_gratReplyHoldoff))) // Find the gratuitous reply entry
{
- NS_LOG_LOGIC ("Update gratuitous reply " << replyTo);
- GraReplyEntry graReplyEntry (replyTo, replyFrom, m_gratReplyHoldoff + Simulator::Now ());
+ NS_LOG_LOGIC ("Update gratuitous reply " << source);
+ GraReplyEntry graReplyEntry (source, srcAddress, m_gratReplyHoldoff + Simulator::Now ());
m_graReply.AddEntry (graReplyEntry);
/*
* Automatic route shortening
*/
m_finalRoute.clear (); // Clear the final route vector
/**
- * push back the node addresses other than those between srcAddress and our own ip address
+ * Push back the node addresses other than those between srcAddress and our own ip address
*/
- PrintVector (nodeList);
- std::vector<Ipv4Address>::iterator before = find (nodeList.begin (), nodeList.end (), replyFrom);
+// PrintVector (nodeList);
+ std::vector<Ipv4Address>::iterator before = find (nodeList.begin (), nodeList.end (), srcAddress);
for (std::vector<Ipv4Address>::iterator i = nodeList.begin (); i != before; ++i)
{
m_finalRoute.push_back (*i);
}
+ m_finalRoute.push_back (srcAddress);
std::vector<Ipv4Address>::iterator after = find (nodeList.begin (), nodeList.end (), m_mainAddress);
for (std::vector<Ipv4Address>::iterator j = after; j != nodeList.end (); ++j)
{
m_finalRoute.push_back (*j);
}
- PrintVector (m_finalRoute);
+// PrintVector (m_finalRoute);
DsrOptionRrepHeader rrep;
rrep.SetNodesAddress (m_finalRoute); // Set the node addresses in the route reply header
- // The source address of the route reply packet is the end of the node list
- Ipv4Address source = nodeList.back ();
+ // Get the real reply source and destination
+ Ipv4Address replySrc = m_finalRoute.back ();
+ Ipv4Address replyDst = m_finalRoute.front ();
/*
* Set the route and use it in send back route reply
*/
- m_ipv4Route = SetRoute (replyTo, m_mainAddress);
+ m_ipv4Route = SetRoute (srcAddress, m_mainAddress);
/*
- * This part add dsr header to the packet and send reply
+ * This part adds DSR header to the packet and send reply
*/
DsrRoutingHeader dsrRoutingHeader;
dsrRoutingHeader.SetNextHeader (protocol);
dsrRoutingHeader.SetMessageType (1);
- dsrRoutingHeader.SetSourceId (255);
- dsrRoutingHeader.SetDestId (255);
+ dsrRoutingHeader.SetSourceId (GetIDfromIP (replySrc));
+ dsrRoutingHeader.SetDestId (GetIDfromIP (replyDst));
uint8_t length = rrep.GetLength (); // Get the length of the rrep header excluding the type header
- dsrRoutingHeader.SetLength (length + 2);
+ dsrRoutingHeader.SetPayloadLength (length + 2);
dsrRoutingHeader.AddDsrOption (rrep);
Ptr<Packet> newPacket = Create<Packet> ();
newPacket->AddHeader (dsrRoutingHeader);
@@ -2044,7 +2235,7 @@
* send gratuitous reply
*/
NS_LOG_INFO ("Send back gratuitous route reply");
- SendReply (newPacket, m_mainAddress, replyTo, m_ipv4Route);
+ SendReply (newPacket, m_mainAddress, srcAddress, m_ipv4Route);
}
else
{
@@ -2055,36 +2246,26 @@
void
DsrRouting::SendReply (Ptr<Packet> packet,
Ipv4Address source,
- Ipv4Address destination,
+ Ipv4Address nextHop,
Ptr<Ipv4Route> route)
{
- NS_LOG_FUNCTION (this << packet << source << destination);
+ NS_LOG_FUNCTION (this << packet << source << nextHop);
NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (m_mainAddress));
route->SetOutputDevice (dev);
- NS_LOG_INFO ("The output device " << dev << "packet is: " << *packet);
- /*
- * Cancel the request timer
- */
- m_addressReqTimer[destination].Cancel ();
- m_addressReqTimer[destination].Remove ();
- if (m_addressReqTimer[destination].IsRunning ())
- {
- NS_LOG_DEBUG ("Timer not canceled");
- }
- m_addressReqTimer.erase (destination);
- m_downTarget (packet, source, destination, GetProtocolNumber (), route);
+ NS_LOG_INFO ("The output device " << dev << " packet is: " << *packet);
+ m_downTarget (packet, source, nextHop, GetProtocolNumber (), route);
}
void
DsrRouting::ScheduleInitialReply (Ptr<Packet> packet,
Ipv4Address source,
- Ipv4Address destination,
+ Ipv4Address nextHop,
Ptr<Ipv4Route> route)
{
- NS_LOG_FUNCTION (this << packet << source << destination);
+ NS_LOG_FUNCTION (this << packet << source << nextHop);
Simulator::ScheduleNow (&DsrRouting::SendReply, this,
- packet, source, destination, route);
+ packet, source, nextHop, route);
}
void
@@ -2099,43 +2280,41 @@
}
void
-DsrRouting::SendAck (Ptr<Packet> packet,
- uint16_t ackId,
- Ipv4Address source,
+DsrRouting::SendAck (uint16_t ackId,
Ipv4Address destination,
Ipv4Address realSrc,
Ipv4Address realDst,
uint8_t protocol,
Ptr<Ipv4Route> route)
{
- NS_LOG_FUNCTION (this << source << destination << realSrc << realDst << protocol << route);
+ NS_LOG_FUNCTION (this << ackId << destination << realSrc << realDst << (uint32_t)protocol << route);
NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, DsrRouting cannot send downward");
// This is a route reply option header
DsrRoutingHeader dsrRoutingHeader;
dsrRoutingHeader.SetNextHeader (protocol);
dsrRoutingHeader.SetMessageType (1);
- dsrRoutingHeader.SetSourceId (255);
- dsrRoutingHeader.SetDestId (255);
- /*
- * Check the ACK ID
- */
+ dsrRoutingHeader.SetSourceId (GetIDfromIP (m_mainAddress));
+ dsrRoutingHeader.SetDestId (GetIDfromIP (destination));
+
DsrOptionAckHeader ack;
/*
* Set the ack Id and set the ack source address and destination address
*/
- ack.SetId (ackId);
+ ack.SetAckId (ackId);
ack.SetRealSrc (realSrc);
ack.SetRealDst (realDst);
uint8_t length = ack.GetLength ();
- dsrRoutingHeader.SetLength (length + 2);
+ dsrRoutingHeader.SetPayloadLength (length + 2);
dsrRoutingHeader.AddDsrOption (ack);
+ Ptr<Packet> packet = Create<Packet> ();
packet->AddHeader (dsrRoutingHeader);
Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainAddress));
route->SetOutputDevice (dev);
- m_downTarget (packet, source, destination, GetProtocolNumber (), route);
+ NS_LOG_DEBUG ("Send out the ACK");
+ m_downTarget (packet, m_mainAddress, destination, GetProtocolNumber (), route);
}
enum Ipv4L4Protocol::RxStatus
@@ -2147,14 +2326,17 @@
NS_LOG_INFO ("Our own IP address " << m_mainAddress << " The incoming interface address " << incomingInterface);
m_node = GetNode (); // Get the node
-
Ptr<Packet> packet = p->Copy (); // Save a copy of the received packet
/*
* When forwarding or local deliver packets, this one should be used always!!
*/
DsrRoutingHeader dsrRoutingHeader;
- packet->RemoveHeader (dsrRoutingHeader); // Remove the dsr header in whole
+ packet->RemoveHeader (dsrRoutingHeader); // Remove the DSR header in whole
+ Ptr<Packet> copy = packet->Copy ();
uint8_t protocol = dsrRoutingHeader.GetNextHeader ();
+ uint32_t sourceId = dsrRoutingHeader.GetSourceId ();
+ Ipv4Address source = GetIPfromID (sourceId);
+ NS_LOG_DEBUG ("The source address " << source);
/*
* Get the IP source and destination address
*/
@@ -2194,7 +2376,7 @@
}
dsrOption = GetOption (optionType);
- optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol, isPromisc);
+ optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
if (optionLength == 0)
{
@@ -2205,7 +2387,7 @@
else if (optionType == 2)
{
dsrOption = GetOption (optionType);
- optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol, isPromisc);
+ optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
if (optionLength == 0)
{
@@ -2218,7 +2400,7 @@
{
NS_LOG_DEBUG ("This is the ack option");
dsrOption = GetOption (optionType);
- optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol, isPromisc);
+ optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
if (optionLength == 0)
{
@@ -2233,7 +2415,7 @@
NS_LOG_DEBUG ("The option type value " << (uint32_t)optionType);
dsrOption = GetOption (optionType);
- optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol, isPromisc);
+ optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
if (optionLength == 0)
{
@@ -2247,7 +2429,7 @@
{
NS_LOG_DEBUG ("This is the source route option " << (uint32_t)optionType);
dsrOption = GetOption (optionType);
- optionLength = dsrOption->Process (p, packet, m_mainAddress, ip, protocol, isPromisc);
+ optionLength = dsrOption->Process (p, packet, m_mainAddress, source, ip, protocol, isPromisc);
segmentsLeft = *(data + 3);
NS_LOG_DEBUG ("The segments left in source route header " << (uint32_t)segmentsLeft);
@@ -2268,19 +2450,19 @@
// we need to make a copy in the unlikely event we hit the
// RX_ENDPOINT_UNREACH code path
// Here we can use the packet that has been get off whole DSR header
- Ptr<Packet> copy = packet->Copy ();
+ NS_LOG_DEBUG ("The packet received " << *copy);
enum Ipv4L4Protocol::RxStatus status =
nextProto->Receive (copy, ip, incomingInterface);
NS_LOG_DEBUG ("The receive status " << status);
switch (status)
{
- case Ipv4L4Protocol::RX_OK:
- // fall through
- case Ipv4L4Protocol::RX_ENDPOINT_CLOSED:
- // fall through
- case Ipv4L4Protocol::RX_CSUM_FAILED:
- break;
- case Ipv4L4Protocol::RX_ENDPOINT_UNREACH:
+ case Ipv4L4Protocol::RX_OK:
+ // fall through
+ case Ipv4L4Protocol::RX_ENDPOINT_CLOSED:
+ // fall through
+ case Ipv4L4Protocol::RX_CSUM_FAILED:
+ break;
+ case Ipv4L4Protocol::RX_ENDPOINT_UNREACH:
if (ip.GetDestination ().IsBroadcast () == true
|| ip.GetDestination ().IsMulticast () == true)
{
« no previous file with comments | « src/dsr/model/dsr-routing.h ('k') | src/dsr/model/dsr-rreq-table.h » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b