32 #define NS_LOG_APPEND_CONTEXT \
33 if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId () << "] "; }
42 #include "ns3/config.h"
44 #include "ns3/string.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/object-vector.h"
56 #include "ns3/ipv4-address.h"
57 #include "ns3/ipv4-header.h"
58 #include "ns3/ipv4-l3-protocol.h"
59 #include "ns3/ipv4-route.h"
60 #include "ns3/trace-source-accessor.h"
61 #include "ns3/icmpv4-l4-protocol.h"
62 #include "ns3/adhoc-wifi-mac.h"
63 #include "ns3/wifi-net-device.h"
64 #include "ns3/inet-socket-address.h"
65 #include "ns3/udp-l4-protocol.h"
66 #include "ns3/udp-socket-factory.h"
67 #include "ns3/tcp-socket-factory.h"
68 #include "ns3/llc-snap-header.h"
69 #include "ns3/arp-header.h"
71 #include "dsr-rreq-table.h"
72 #include "dsr-rcache.h"
73 #include "dsr-routing.h"
74 #include "dsr-fs-header.h"
75 #include "dsr-options.h"
82 NS_OBJECT_ENSURE_REGISTERED (DsrRouting);
109 .AddConstructor<DsrRouting> ()
110 .AddAttribute (
"RouteCache",
"The route cache for saving routes from route discovery process.",
114 MakePointerChecker<RouteCache> ())
115 .AddAttribute (
"RreqTable",
"The request table to manage route requests.",
119 MakePointerChecker<RreqTable> ())
120 .AddAttribute (
"PassiveBuffer",
"The passive buffer to manage promisucously received passive ack.",
124 MakePointerChecker<PassiveBuffer> ())
125 .AddAttribute (
"MaxSendBuffLen",
"Maximum number of packets that can be stored in send buffer.",
128 MakeUintegerChecker<uint32_t> ())
129 .AddAttribute (
"MaxSendBuffTime",
"Maximum time packets can be queued in the send buffer .",
133 .AddAttribute (
"MaxMaintLen",
"Maximum number of packets that can be stored in maintenance buffer.",
136 MakeUintegerChecker<uint32_t> ())
137 .AddAttribute (
"MaxMaintTime",
"Maximum time packets can be queued in maintenance buffer.",
141 .AddAttribute (
"MaxCacheLen",
"Maximum number of route entries that can be stored in route cache.",
144 MakeUintegerChecker<uint32_t> ())
145 .AddAttribute (
"RouteCacheTimeout",
"Maximum time the route cache can be queued in route cache.",
149 .AddAttribute (
"MaxEntriesEachDst",
"Maximum number of route entries for a single destination to respond.",
152 MakeUintegerChecker<uint32_t> ())
153 .AddAttribute (
"SendBuffInterval",
"How often to check send buffer for packet with route.",
157 .AddAttribute (
"NodeTraversalTime",
"The time it takes to traverse two neighboring nodes.",
161 .AddAttribute (
"RreqRetries",
"Maximum number of retransmissions for request discovery of a route.",
164 MakeUintegerChecker<uint32_t> ())
165 .AddAttribute (
"MaintenanceRetries",
"Maximum number of retransmissions for data packets from maintenance buffer.",
168 MakeUintegerChecker<uint32_t> ())
169 .AddAttribute (
"RequestTableSize",
"Maximum number of request entries in the request table, set this as the number of nodes in the simulation.",
172 MakeUintegerChecker<uint32_t> ())
173 .AddAttribute (
"RequestIdSize",
"Maximum number of request source Ids in the request table.",
176 MakeUintegerChecker<uint32_t> ())
177 .AddAttribute (
"UniqueRequestIdSize",
"Maximum number of request Ids in the request table for a single destination.",
180 MakeUintegerChecker<uint32_t> ())
181 .AddAttribute (
"NonPropRequestTimeout",
"The timeout value for non-propagation request.",
185 .AddAttribute (
"DiscoveryHopLimit",
"The max discovery hop limit for route requests.",
188 MakeUintegerChecker<uint32_t> ())
189 .AddAttribute (
"MaxSalvageCount",
"The max salvage count for a single data packet.",
192 MakeUintegerChecker<uint8_t> ())
193 .AddAttribute (
"BlacklistTimeout",
"The time for a neighbor to stay in blacklist.",
197 .AddAttribute (
"GratReplyHoldoff",
"The time for gratuitous reply entry to expire.",
201 .AddAttribute (
"BroadcastJitter",
"The jitter time to avoid collision for broadcast packets.",
204 MakeUintegerChecker<uint32_t> ())
205 .AddAttribute (
"LinkAckTimeout",
"The time a packet in maintenance buffer wait for link acknowledgment.",
209 .AddAttribute (
"TryLinkAcks",
"The number of link acknowledgment to use.",
212 MakeUintegerChecker<uint32_t> ())
213 .AddAttribute (
"PassiveAckTimeout",
"The time a packet in maintenance buffer wait for passive acknowledgment.",
217 .AddAttribute (
"TryPassiveAcks",
"The number of passive acknowledgment to use.",
220 MakeUintegerChecker<uint32_t> ())
221 .AddAttribute (
"RequestPeriod",
"The base time interval between route requests.",
225 .AddAttribute (
"MaxRequestPeriod",
"The max time interval between route requests.",
229 .AddAttribute (
"GraReplyTableSize",
"The gratuitous reply table size.",
232 MakeUintegerChecker<uint32_t> ())
233 .AddAttribute (
"CacheType",
"Use Link Cache or use Path Cache",
236 MakeStringChecker ())
237 .AddAttribute (
"StabilityDecrFactor",
"The stability decrease factor for link cache",
240 MakeUintegerChecker<uint32_t> ())
241 .AddAttribute (
"StabilityIncrFactor",
"The stability increase factor for link cache",
244 MakeUintegerChecker<uint32_t> ())
245 .AddAttribute (
"InitStability",
"The initial stability factor for link cache",
249 .AddAttribute (
"MinLifeTime",
"The minimal life time for link cache",
253 .AddAttribute (
"UseExtends",
"The extension time for link cache",
257 .AddAttribute (
"EnableSubRoute",
"Enables saving of sub route when receiving route error messages, only available when using path route cache",
260 MakeBooleanChecker ())
261 .AddAttribute (
"RetransIncr",
"The increase time for retransmission timer when facing network congestion",
265 .AddAttribute (
"MaxNetworkQueueSize",
"The max number of packet to save in the network queue.",
268 MakeUintegerChecker<uint32_t> ())
269 .AddAttribute (
"MaxNetworkQueueDelay",
"The max time for a packet to stay in the network queue.",
273 .AddAttribute (
"NumPriorityQueues",
"The max number of packet to save in the network queue.",
276 MakeUintegerChecker<uint32_t> ())
277 .AddAttribute (
"LinkAcknowledgment",
"Enable Link layer acknowledgment mechanism",
280 MakeBooleanChecker ())
281 .AddTraceSource (
"Tx",
"Send DSR packet.",
283 .AddTraceSource (
"Drop",
"Drop DSR packet",
335 Ptr<Node> node = this->GetObject<Node> ();
338 m_ipv4 = this->GetObject<Ipv4L3Protocol> ();
357 void DsrRouting::Start ()
367 std::pair<std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator,
bool> result_i =
m_priorityQueue.insert (std::make_pair (i, queue_i));
399 for (uint32_t i = 0; i <
m_ipv4->GetNInterfaces (); i++)
404 if (addr != loopback)
422 routeCache->ScheduleTimer ();
438 Ptr<WifiMac> mac = wifi->GetMac ();
444 routeCache->AddArpCache (
m_ipv4->GetInterface (i)->GetArpCache ());
457 Config::Connect (
"NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxEnd",
470 Mac48Address nodeAddr = netDevice->GetMac()->GetAddress();
471 std::ostringstream oss;
480 NS_LOG_WARN (
"WifiMacTrailer left, skip this packet");
501 NS_LOG_WARN (
"arp header present, skip this packet");
517 Ipv4Address ourAddress = ipv4->GetAddress (1, 0).GetLocal ();
530 newEntry.SetPacket (p);
531 newEntry.SetSrc (sourceIp);
532 newEntry.SetDst (destinationIp);
534 newEntry.SetOurAdd (previousHop);
535 newEntry.SetNextHop (ourAddress);
539 dsr->CancelLinkPacketTimer (newEntry);
552 return n->
GetDevice (atoi (elements[3].c_str ()));
555 std::vector<std::string>
558 std::vector <std::string> elements;
560 while (pos1 != context.npos)
562 pos1 = context.find (
"/",pos1);
563 pos2 = context.find (
"/",pos1+1);
564 elements.push_back (context.substr (pos1+1,pos2-(pos1+1)));
576 for (uint32_t i = 0; i <
m_ipv4->GetNInterfaces (); i++)
586 mac->TraceDisconnectWithoutContext (
"TxErrHeader",
652 for (int32_t i = 0; i < nNodes; ++i)
656 int32_t ifIndex = ipv4->GetInterfaceForAddress (ipv4Address);
675 bool DsrRouting::LookupRoute (
Ipv4Address id, RouteCacheEntry & rt)
687 bool DsrRouting::AddRoute (RouteCacheEntry & rt)
689 std::vector<Ipv4Address> nodelist = rt.GetVector ();
695 void DsrRouting::DeleteAllRoutesIncludeLink (Ipv4Address errorSrc, Ipv4Address unreachNode, Ipv4Address node)
697 m_routeCache->DeleteAllRoutesIncludeLink (errorSrc, unreachNode, node);
700 bool DsrRouting::UpdateRouteEntry (Ipv4Address dst)
705 bool DsrRouting::FindSourceEntry (Ipv4Address src, Ipv4Address dst, uint16_t
id)
707 return m_rreqTable->FindSourceEntry (src, dst,
id);
715 for (int32_t i = 0; i < nNodes; ++i)
721 if (netDevice->GetAddress () == address)
723 return ipv4->GetAddress (1, 0).GetLocal ();
742 for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
754 if (vec.size () == 2)
762 if (ipv4Address == vec.back ())
764 NS_LOG_DEBUG (
"We have reached to the final destination " << ipv4Address <<
" " << vec.back ());
767 for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
769 if (ipv4Address == (*i))
803 for (int32_t i = 0; i < nNodes; ++i)
807 if (ipv4->GetAddress (1, 0).GetLocal () == address)
827 return ipv4->GetAddress (1, 0).GetLocal ();
834 if (messageType == DSR_CONTROL_PACKET)
861 Ptr<Packet> dequeP = ConstCast<Packet> (entry.GetPacket ());
872 newPacket->RemoveAtStart (offset);
876 newPacket->CopyData (buf,
sizeof(buf));
877 uint8_t numberAddress = (buf[1] - 2) / 4;
881 newPacket->RemoveHeader (sourceRoute);
882 uint8_t salvage = sourceRoute.GetSalvage ();
885 newPacket->RemoveHeader (ackReq);
893 if (nextHop ==
"0.0.0.0")
899 bool findRoute =
m_routeCache->LookupRoute (destination, salvageRoute);
904 std::vector<Ipv4Address> nodeList = salvageRoute.GetVector ();
907 newSR.SetSegmentsLeft ((nodeList.size () - 2));
908 newSR.SetSalvage (salvage + 1);
915 networkKey.m_ackId = entry.GetAckId ();
916 networkKey.m_ourAdd = entry.GetOurAdd ();
917 networkKey.m_nextHop = entry.GetNextHop ();
918 networkKey.m_source = entry.GetSrc ();
919 networkKey.m_destination = entry.GetDst ();
922 passiveKey.m_ackId = 0;
923 passiveKey.m_source = entry.GetSrc ();
924 passiveKey.m_destination = entry.GetDst ();
925 passiveKey.m_segsLeft = entry.GetSegsLeft ();
928 linkKey.m_source = entry.GetSrc ();
929 linkKey.m_destination = entry.GetDst ();
930 linkKey.m_ourAdd = entry.GetOurAdd ();
931 linkKey.m_nextHop = entry.GetNextHop ();
944 if (nextHop != destination)
1004 for (std::vector<SendBuffEntry>::iterator i =
m_sendBuffer.GetBuffer ().begin (); i !=
m_sendBuffer.GetBuffer ().end (); )
1006 NS_LOG_DEBUG (
"Here we try to find the data packet in the send buffer");
1009 bool findRoute =
m_routeCache->LookupRoute (destination, toDst);
1012 NS_LOG_INFO (
"We have found a route for the packet");
1015 uint8_t protocol = i->GetProtocol ();
1030 uint32_t size = copyP->
GetSize ();
1031 uint8_t *data =
new uint8_t[size];
1034 uint8_t optionType = 0;
1035 optionType = *(data);
1037 if (optionType == 3)
1041 uint8_t errorType = *(data + 2);
1057 std::vector<Ipv4Address> errorRoute = toDst.GetVector ();
1064 sourceRoute.SetSegmentsLeft ((errorRoute.size () - 2));
1065 uint8_t salvage = 0;
1066 sourceRoute.SetSalvage (salvage);
1069 if (nextHop ==
"0.0.0.0")
1076 uint8_t length = (sourceRoute.
GetLength () + newUnreach.GetLength ());
1086 newPacket->
AddHeader (dsrRoutingHeader);
1090 uint32_t priority =
GetPriority (DSR_CONTROL_PACKET);
1091 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
1093 NS_LOG_LOGIC (
"Will be inserting into priority queue number: " << priority);
1118 std::vector<Ipv4Address> nodeList = toDst.GetVector ();
1120 if (nextHop ==
"0.0.0.0")
1125 uint8_t salvage = 0;
1127 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2));
1128 sourceRoute.SetSalvage (salvage);
1134 uint8_t length = sourceRoute.
GetLength ();
1147 networkKey.m_ackId = newEntry.GetAckId ();
1148 networkKey.m_ourAdd = newEntry.GetOurAdd ();
1149 networkKey.m_nextHop = newEntry.GetNextHop ();
1150 networkKey.m_source = newEntry.GetSrc ();
1151 networkKey.m_destination = newEntry.GetDst ();
1154 passiveKey.m_ackId = 0;
1155 passiveKey.m_source = newEntry.GetSrc ();
1156 passiveKey.m_destination = newEntry.GetDst ();
1157 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
1160 linkKey.m_source = newEntry.GetSrc ();
1161 linkKey.m_destination = newEntry.GetDst ();
1162 linkKey.m_ourAdd = newEntry.GetOurAdd ();
1163 linkKey.m_nextHop = newEntry.GetNextHop ();
1176 if (nextHop != destination)
1226 NS_LOG_INFO (
this << from << to << packetType << *p);
1233 uint32_t sourceId = dsrRoutingHeader.
GetSourceId ();
1241 uint32_t size = p->
GetSize ();
1242 uint8_t *data =
new uint8_t[size];
1244 uint8_t optionType = 0;
1245 optionType = *(data);
1249 if (optionType == 96)
1255 " overhearing packet PID: " << p->
GetUid () <<
1256 " from " << promiscSource <<
1258 " with source IP " << ipv4Header.
GetSource () <<
1260 " and packet : " << *dsrPacket);
1262 bool isPromisc =
true;
1263 dsrOption->Process (p, dsrPacket,
m_mainAddress, source, ipv4Header, nextHeader, isPromisc, promiscSource);
1277 NS_LOG_FUNCTION (
this << packet << source << destination << (uint32_t)protocol);
1280 bool findRoute =
m_routeCache->LookupRoute (destination, toDst);
1285 <<
"s " <<
m_mainAddress <<
" there is no route for this packet, queue the packet");
1293 <<
"s Add packet PID: " << packet->
GetUid () <<
" to queue. Packet: " << *packet);
1315 std::vector<Ipv4Address> nodeList = toDst.GetVector ();
1317 if (nextHop ==
"0.0.0.0")
1322 uint8_t salvage = 0;
1329 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2));
1330 sourceRoute.SetSalvage (salvage);
1332 uint8_t length = sourceRoute.
GetLength ();
1340 source, destination, 0,
1347 networkKey.m_ackId = newEntry.GetAckId ();
1348 networkKey.m_ourAdd = newEntry.GetOurAdd ();
1349 networkKey.m_nextHop = newEntry.GetNextHop ();
1350 networkKey.m_source = newEntry.GetSrc ();
1351 networkKey.m_destination = newEntry.GetDst ();
1354 passiveKey.m_ackId = 0;
1355 passiveKey.m_source = newEntry.GetSrc ();
1356 passiveKey.m_destination = newEntry.GetDst ();
1357 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
1360 linkKey.m_source = newEntry.GetSrc ();
1361 linkKey.m_destination = newEntry.GetDst ();
1362 linkKey.m_ourAdd = newEntry.GetOurAdd ();
1363 linkKey.m_nextHop = newEntry.GetNextHop ();
1376 if (nextHop != destination)
1393 NS_LOG_FUNCTION (
this << errorHop << destination << originalDst << (uint32_t)salvage << (uint32_t)protocol);
1407 uint8_t rerrLength = rerrUnreachHeader.
GetLength ();
1410 bool findRoute =
m_routeCache->LookupRoute (destination, toDst);
1416 <<
"s " <<
m_mainAddress <<
" there is no route for this packet, queue the packet");
1420 newPacket->
AddHeader (dsrRoutingHeader);
1428 <<
"s Add packet PID: " << p->
GetUid () <<
" to queue. Packet: " << *p);
1432 NS_LOG_DEBUG (
"When there is no existing route request for " << destination <<
", initialize one");
1442 std::vector<Ipv4Address> nodeList = toDst.GetVector ();
1444 if (nextHop ==
"0.0.0.0")
1457 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2));
1458 uint8_t srLength = sourceRoute.
GetLength ();
1459 uint8_t length = (srLength + rerrLength);
1464 newPacket->
AddHeader (dsrRoutingHeader);
1471 uint32_t priority =
GetPriority (DSR_CONTROL_PACKET);
1472 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
1474 NS_LOG_DEBUG (
"Will be inserting into priority queue " << dsrNetworkQueue <<
" number: " << priority);
1499 NS_LOG_FUNCTION (
this << rerr << sourceRoute << nextHop << (uint32_t)protocol << route);
1503 dsrRoutingHeader.SetMessageType (1);
1508 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 4);
1509 dsrRoutingHeader.AddDsrOption (rerr);
1510 dsrRoutingHeader.AddDsrOption (sourceRoute);
1516 uint32_t priority =
GetPriority (DSR_CONTROL_PACKET);
1517 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
1519 NS_LOG_DEBUG (
"Will be inserting into priority queue " << dsrNetworkQueue <<
" number: " << priority);
1543 NS_LOG_FUNCTION (
this << packet << source << destination << (uint32_t)protocol << route);
1548 NS_LOG_INFO (
"Drop packet. Not handling ICMP packet for now");
1554 bool findRoute =
m_routeCache->LookupRoute (destination, toDst);
1559 <<
"s " <<
m_mainAddress <<
" there is no route for this packet, queue the packet");
1567 <<
"s Add packet PID: " << packet->
GetUid () <<
" to send buffer. Packet: " << *packet);
1579 NS_LOG_LOGIC (
"There is existing route request timer with request count " <<
m_rreqTable->GetRreqCnt (destination));
1593 std::vector<Ipv4Address> nodeList = toDst.GetVector ();
1595 if (nextHop ==
"0.0.0.0")
1600 uint8_t salvage = 0;
1607 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2));
1608 sourceRoute.SetSalvage (salvage);
1610 uint8_t length = sourceRoute.
GetLength ();
1620 source, destination, 0,
1626 networkKey.m_ackId = newEntry.GetAckId ();
1627 networkKey.m_ourAdd = newEntry.GetOurAdd ();
1628 networkKey.m_nextHop = newEntry.GetNextHop ();
1629 networkKey.m_source = newEntry.GetSrc ();
1630 networkKey.m_destination = newEntry.GetDst ();
1633 passiveKey.m_ackId = 0;
1634 passiveKey.m_source = newEntry.GetSrc ();
1635 passiveKey.m_destination = newEntry.GetDst ();
1636 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
1639 linkKey.m_source = newEntry.GetSrc ();
1640 linkKey.m_destination = newEntry.GetDst ();
1641 linkKey.m_ourAdd = newEntry.GetOurAdd ();
1642 linkKey.m_nextHop = newEntry.GetNextHop ();
1655 if (nextHop != destination)
1688 uint32_t sourceId = dsrRoutingHeader.
GetSourceId ();
1689 uint32_t destinationId = dsrRoutingHeader.
GetDestId ();
1696 uint8_t numberAddress = (buf[1] - 2) / 4;
1709 newDsrRoutingHeader.
SetDestId (destinationId);
1722 NS_LOG_FUNCTION (
this << packet << source << nextHop << (uint32_t)protocol);
1728 uint32_t priority =
GetPriority (DSR_DATA_PACKET);
1729 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
1731 NS_LOG_INFO (
"Will be inserting into priority queue number: " << priority);
1759 uint32_t numPriorities;
1760 if (continueWithFirst)
1766 numPriorities = priority;
1771 std::map<uint32_t, Ptr<DsrNetworkQueue> >::iterator q =
m_priorityQueue.find (i);
1773 uint32_t queueSize = dsrNetworkQueue->GetSize ();
1776 if ((i == (m_numPriorityQueues - 1)) && continueWithFirst)
1787 uint32_t totalQueueSize = 0;
1790 NS_LOG_INFO (
"The size of the network queue for " << j->first <<
" is " << j->second->GetSize ());
1791 totalQueueSize += j->second->GetSize ();
1792 NS_LOG_INFO (
"The total network queue size is " << totalQueueSize);
1794 if (totalQueueSize > 5)
1800 dsrNetworkQueue->Dequeue (newEntry);
1803 NS_LOG_LOGIC (
"Packet sent by Dsr. Calling PriorityScheduler after some time");
1812 NS_LOG_LOGIC (
"Packet dropped by Dsr. Calling PriorityScheduler immediately");
1816 if ((i == (m_numPriorityQueues - 1)) && continueWithFirst)
1833 uint32_t priority =
GetPriority (DSR_DATA_PACKET);
1834 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
1837 std::vector<DsrNetworkQueueEntry> newNetworkQueue = dsrNetworkQueue->GetQueue ();
1838 for (std::vector<DsrNetworkQueueEntry>::iterator i = newNetworkQueue.begin (); i != newNetworkQueue.end (); i++)
1843 if (nextHop == j->first.m_nextHop)
1845 NS_LOG_DEBUG (
"The network delay left is " << j->second.GetDelayLeft ());
1846 j->second.SetDelay (j->second.GetDelayLeft () +
m_retransIncr);
1856 Ipv4Address source = newEntry.GetSourceAddress ();
1857 Ipv4Address nextHop = newEntry.GetNextHopAddress ();
1874 NS_LOG_INFO (
"The nexthop address " << nextHop <<
" the source " << source <<
" the destination " << destination);
1880 NS_LOG_DEBUG (
"destination over here " << destination);
1893 uint8_t length = sourceRoute.
GetLength ();
1902 source, destination, 0,
1909 networkKey.m_ackId = newEntry.GetAckId ();
1910 networkKey.m_ourAdd = newEntry.GetOurAdd ();
1911 networkKey.m_nextHop = newEntry.GetNextHop ();
1912 networkKey.m_source = newEntry.GetSrc ();
1913 networkKey.m_destination = newEntry.GetDst ();
1916 passiveKey.m_ackId = 0;
1917 passiveKey.m_source = newEntry.GetSrc ();
1918 passiveKey.m_destination = newEntry.GetDst ();
1919 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
1922 linkKey.m_source = newEntry.GetSrc ();
1923 linkKey.m_destination = newEntry.GetDst ();
1924 linkKey.m_ourAdd = newEntry.GetOurAdd ();
1925 linkKey.m_nextHop = newEntry.GetNextHop ();
1938 if (nextHop != destination)
1953 NS_LOG_LOGIC (
"Schedule sending the next packet in send buffer");
1960 NS_LOG_LOGIC (
"All queued packets are out-dated for the destination in send buffer");
1978 uint32_t offset = dsrRoutingHeader.GetDsrOptionsOffset ();
1983 uint32_t size = copyP->
GetSize ();
1984 uint8_t *data =
new uint8_t[size];
1987 uint8_t optionType = 0;
1988 optionType = *(data);
1989 NS_LOG_DEBUG (
"The option type value in send packet " << (uint32_t)optionType);
1990 if (optionType == 3)
1996 uint8_t errorType = *(data + 2);
2000 NS_LOG_DEBUG (
"The packet is route error unreach packet");
2030 newPacket->
AddHeader (newRoutingHeader);
2034 uint32_t priority =
GetPriority (DSR_CONTROL_PACKET);
2035 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
2037 NS_LOG_DEBUG (
"Will be inserting into priority queue " << dsrNetworkQueue <<
" number: " << priority);
2057 NS_LOG_LOGIC (
"Schedule sending the next packet in error buffer");
2065 NS_LOG_DEBUG (
"Packet not found in either the send or error buffer");
2071 uint16_t fragmentOffset, uint16_t identification,
bool saveEntry)
2073 NS_LOG_FUNCTION (
this << packet << source << destination << (uint32_t)segsLeft);
2078 newEntry.SetPacket (p);
2079 newEntry.SetSource (source);
2080 newEntry.SetDestination (destination);
2081 newEntry.SetIdentification (identification);
2082 newEntry.SetFragmentOffset (fragmentOffset);
2083 newEntry.SetSegsLeft (segsLeft);
2092 NS_LOG_DEBUG (
"We get the all equal for passive buffer here");
2095 mbEntry.SetPacket (p);
2096 mbEntry.SetSrc (source);
2097 mbEntry.SetDst (destination);
2098 mbEntry.SetAckId (0);
2099 mbEntry.SetSegsLeft (segsLeft + 1);
2116 NS_LOG_FUNCTION (
this << packet << source << destination << (uint32_t)segsLeft);
2123 newEntry.SetPacket (p);
2124 newEntry.SetSrc (source);
2125 newEntry.SetDst (destination);
2126 newEntry.SetAckId (0);
2127 newEntry.SetSegsLeft (segsLeft + 1);
2144 linkKey.m_ourAdd = mb.GetOurAdd ();
2145 linkKey.m_nextHop = mb.GetNextHop ();
2146 linkKey.m_source = mb.GetSrc ();
2147 linkKey.m_destination = mb.GetDst ();
2154 NS_LOG_INFO (
"ourAdd " << mb.GetOurAdd () <<
" nextHop " << mb.GetNextHop ()
2155 <<
" source " << mb.GetSrc () <<
" destination " << mb.GetDst ()
2158 std::map<LinkKey, Timer>::const_iterator i =
2184 NS_LOG_INFO (
"Link acknowledgment received, remove same maintenance buffer entry");
2191 NS_LOG_FUNCTION (
this << (uint32_t)ackId << ipv4Header << realSrc << realDst);
2200 realSrc, realDst, ackId,
2210 networkKey.m_ackId = mb.GetAckId ();
2211 networkKey.m_ourAdd = mb.GetOurAdd ();
2212 networkKey.m_nextHop = mb.GetNextHop ();
2213 networkKey.m_source = mb.GetSrc ();
2214 networkKey.m_destination = mb.GetDst ();
2221 NS_LOG_INFO (
"ackId " << mb.GetAckId () <<
" ourAdd " << mb.GetOurAdd () <<
" nextHop " << mb.GetNextHop ()
2222 <<
" source " << mb.GetSrc () <<
" destination " << mb.GetDst ()
2223 <<
" segsLeft " << (uint32_t)mb.GetSegsLeft ()
2226 std::map<NetworkKey, Timer>::const_iterator i =
2251 NS_LOG_INFO (
"Remove same maintenance buffer entry based on network acknowledgment");
2260 passiveKey.m_ackId = 0;
2261 passiveKey.m_source = mb.GetSrc ();
2262 passiveKey.m_destination = mb.GetDst ();
2263 passiveKey.m_segsLeft = mb.GetSegsLeft ();
2269 std::map<PassiveKey, Timer>::const_iterator j =
2309 NS_LOG_INFO (
"Cancel the packet timer for next maintenance entry");
2316 NS_LOG_INFO (
"Maintenance buffer entry not found");
2323 NS_LOG_FUNCTION (
this << packet << source << dst << (uint32_t)protocol);
2336 newPacket->
CopyData (buf,
sizeof(buf));
2337 uint8_t numberAddress = (buf[1] - 2) / 4;
2342 uint8_t salvage = sourceRoute.GetSalvage ();
2347 bool findRoute =
m_routeCache->LookupRoute (dst, toDst);
2357 std::vector<Ipv4Address> nodeList = toDst.GetVector ();
2359 if (nextHop ==
"0.0.0.0")
2367 sourceRoute.SetSalvage (salvage);
2369 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2));
2375 uint8_t length = sourceRoute.
GetLength ();
2386 uint32_t priority =
GetPriority (DSR_DATA_PACKET);
2387 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
2389 NS_LOG_DEBUG (
"Will be inserting into priority queue " << dsrNetworkQueue <<
" number: " << priority);
2413 NS_LOG_DEBUG (
"Will not salvage this packet, silently drop");
2431 linkKey.m_source = mb.GetSrc ();
2432 linkKey.m_destination = mb.GetDst ();
2433 linkKey.m_ourAdd = mb.GetOurAdd ();
2434 linkKey.m_nextHop = mb.GetNextHop ();
2461 passiveKey.m_ackId = 0;
2462 passiveKey.m_source = mb.GetSrc ();
2463 passiveKey.m_destination = mb.GetDst ();
2464 passiveKey.m_segsLeft = mb.GetSegsLeft ();
2471 NS_LOG_DEBUG (
"The passive acknowledgment option for data packet");
2488 NS_LOG_DEBUG (
"is the first retry or not " << isFirst);
2492 p = mb.GetPacket ()->
Copy ();
2505 newEntry.SetPacket (dsrP);
2506 newEntry.SetAckId (ackId);
2509 networkKey.m_ackId = newEntry.GetAckId ();
2510 networkKey.m_ourAdd = newEntry.GetOurAdd ();
2511 networkKey.m_nextHop = newEntry.GetNextHop ();
2512 networkKey.m_source = newEntry.GetSrc ();
2513 networkKey.m_destination = newEntry.GetDst ();
2535 networkKey.m_ackId = mb.GetAckId ();
2536 networkKey.m_ourAdd = mb.GetOurAdd ();
2537 networkKey.m_nextHop = mb.GetNextHop ();
2538 networkKey.m_source = mb.GetSrc ();
2539 networkKey.m_destination = mb.GetDst ();
2546 p = mb.GetPacket ()->
Copy ();
2547 dsrP = mb.GetPacket ()->
Copy ();
2554 NS_LOG_DEBUG (
"The packet with dsr header " << dsrP->GetSize ());
2555 networkKey.m_ackId = mb.GetAckId ();
2556 networkKey.m_ourAdd = mb.GetOurAdd ();
2557 networkKey.m_nextHop = mb.GetNextHop ();
2558 networkKey.m_source = mb.GetSrc ();
2559 networkKey.m_destination = mb.GetDst ();
2595 lk.m_source = mb.GetSrc ();
2596 lk.m_destination = mb.GetDst ();
2597 lk.m_ourAdd = mb.GetOurAdd ();
2598 lk.m_nextHop = mb.GetNextHop ();
2618 NS_LOG_DEBUG (
"We may need to send error messages now");
2629 uint8_t numberAddress = (buf[1] - 2) / 4;
2630 NS_LOG_DEBUG (
"The number of addresses " << (uint32_t)numberAddress);
2635 uint8_t salvage = sourceRoute.GetSalvage ();
2648 errorDst = address1;
2675 pk.m_source = mb.GetSrc ();
2676 pk.m_destination = mb.GetDst ();
2677 pk.m_segsLeft = mb.GetSegsLeft ();
2722 networkKey.m_ackId = mb.GetAckId ();
2723 networkKey.m_ourAdd = mb.GetOurAdd ();
2724 networkKey.m_nextHop = nextHop;
2725 networkKey.m_source = source;
2726 networkKey.m_destination = dst;
2735 NS_LOG_LOGIC (
"Packet transmissions to " << nextHop <<
" has been attempted SendRetries times for " << networkKey.m_ackId);
2744 uint8_t numberAddress = (buf[1] - 2) / 4;
2745 NS_LOG_DEBUG (
"The number of addresses " << (uint32_t)numberAddress);
2750 uint8_t salvage = sourceRoute.GetSalvage ();
2763 errorDst = address1;
2793 NS_LOG_FUNCTION (
this << packet << sourceRoute << source << nextHop << targetAddress << (uint32_t)protocol << route);
2798 dsrRoutingHeader.SetMessageType (2);
2799 dsrRoutingHeader.SetSourceId (
GetIDfromIP (source));
2800 dsrRoutingHeader.SetDestId (
GetIDfromIP (targetAddress));
2804 uint8_t length = sourceRoute.
GetLength ();
2805 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
2806 dsrRoutingHeader.AddDsrOption (sourceRoute);
2812 source, targetAddress,
m_ackId,
2819 networkKey.m_ackId = newEntry.GetAckId ();
2820 networkKey.m_ourAdd = newEntry.GetOurAdd ();
2821 networkKey.m_nextHop = newEntry.GetNextHop ();
2822 networkKey.m_source = newEntry.GetSrc ();
2823 networkKey.m_destination = newEntry.GetDst ();
2826 passiveKey.m_ackId = 0;
2827 passiveKey.m_source = newEntry.GetSrc ();
2828 passiveKey.m_destination = newEntry.GetDst ();
2829 passiveKey.m_segsLeft = newEntry.GetSegsLeft ();
2832 linkKey.m_source = newEntry.GetSrc ();
2833 linkKey.m_destination = newEntry.GetDst ();
2834 linkKey.m_ourAdd = newEntry.GetOurAdd ();
2835 linkKey.m_nextHop = newEntry.GetNextHop ();
2848 if (nextHop != targetAddress)
2866 NS_LOG_FUNCTION (
this << source << destination << (uint32_t)protocol);
2887 uint8_t length = rreqHeader.
GetLength ();
2889 packet->AddHeader (dsrRoutingHeader);
2892 bool nonProp =
true;
2893 std::vector<Ipv4Address> address;
2894 address.push_back (source);
2895 address.push_back (destination);
2927 std::vector<Ipv4Address> ip = toDst.GetVector ();
2934 sourceRoute.SetSegmentsLeft ((ip.size () - 2));
2935 sourceRoute.SetSalvage (salvage);
2939 if (nextHop ==
"0.0.0.0")
2957 NS_LOG_INFO (
"No route found, initiate route error request");
2974 rreqHeader.SetTarget (originalDst);
2980 uint8_t length = rreqHeader.GetLength () + rerr.
GetLength ();
2984 bool nonProp =
false;
2985 std::vector<Ipv4Address> address;
2987 address.push_back (originalDst);
2998 NS_LOG_INFO (
"Only when there is no existing route request time when the initial route request is scheduled");
3004 NS_LOG_INFO (
"There is existing route request, find the existing route request entry");
3022 NS_LOG_DEBUG (
"Did not find the non-propagation timer");
3067 NS_LOG_FUNCTION (
this << packet << nonProp << requestId << (uint32_t)protocol);
3078 std::vector<Ipv4Address> address;
3079 address.push_back (source);
3080 address.push_back (dst);
3102 std::vector<Ipv4Address> address;
3103 address.push_back (source);
3104 address.push_back (dst);
3154 std::vector<Ipv4Address> ip = toDst.GetVector ();
3161 sourceRoute.SetSegmentsLeft ((ip.size () - 2));
3163 sourceRoute.SetSalvage (0);
3165 NS_LOG_INFO (
"The nextHop address is " << nextHop);
3166 if (nextHop ==
"0.0.0.0")
3192 NS_LOG_DEBUG (
"Route not found. Drop packet with dst " << dst);
3204 NS_LOG_DEBUG (
"Check the route request entry " << source <<
" " << dst);
3220 uint32_t priority =
GetPriority (DSR_CONTROL_PACKET);
3221 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
3223 NS_LOG_LOGIC (
"Inserting into priority queue number: " << priority);
3267 std::vector<Ipv4Address>::iterator before = find (nodeList.begin (), nodeList.end (), srcAddress);
3268 for (std::vector<Ipv4Address>::iterator i = nodeList.begin (); i != before; ++i)
3273 std::vector<Ipv4Address>::iterator after = find (nodeList.begin (), nodeList.end (),
m_mainAddress);
3274 for (std::vector<Ipv4Address>::iterator j = after; j != nodeList.end (); ++j)
3300 newPacket->
AddHeader (dsrRoutingHeader);
3309 NS_LOG_INFO (
"The same gratuitous route reply has already sent");
3324 NS_LOG_INFO (
"The output device " << dev <<
" packet is: " << *packet);
3326 uint32_t priority =
GetPriority (DSR_CONTROL_PACKET);
3327 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
3329 NS_LOG_INFO (
"Inserting into priority queue number: " << priority);
3353 packet, source, nextHop, route);
3375 NS_LOG_FUNCTION (
this << ackId << destination << realSrc << realDst << (uint32_t)protocol << route);
3381 dsrRoutingHeader.SetMessageType (1);
3383 dsrRoutingHeader.SetDestId (
GetIDfromIP (destination));
3394 dsrRoutingHeader.SetPayloadLength (uint16_t (length) + 2);
3395 dsrRoutingHeader.AddDsrOption (ack);
3402 uint32_t priority =
GetPriority (DSR_CONTROL_PACKET);
3403 std::map<uint32_t, Ptr<dsr::DsrNetworkQueue> >::iterator i =
m_priorityQueue.find (priority);
3406 NS_LOG_LOGIC (
"Will be inserting into priority queue " << dsrNetworkQueue <<
" number: " << priority);
3422 enum IpL4Protocol::RxStatus
3440 uint32_t sourceId = dsrRoutingHeader.
GetSourceId ();
3442 NS_LOG_INFO (
"The source address " << source <<
" with source id " << sourceId);
3448 bool isPromisc =
false;
3459 uint32_t size = p->
GetSize ();
3460 uint8_t *data =
new uint8_t[size];
3463 uint8_t optionType = 0;
3464 uint8_t optionLength = 0;
3465 uint8_t segmentsLeft = 0;
3467 optionType = *(data);
3468 NS_LOG_LOGIC (
"The option type value " << (uint32_t)optionType <<
" with packet id " << p->
GetUid());
3471 if (optionType == 1)
3476 NS_LOG_INFO (
"Discard this packet due to unidirectional link");
3481 optionLength = dsrOption->Process (p, packet,
m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3483 if (optionLength == 0)
3489 else if (optionType == 2)
3492 optionLength = dsrOption->Process (p, packet,
m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3494 if (optionLength == 0)
3501 else if (optionType == 32)
3505 optionLength = dsrOption->Process (p, packet,
m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3507 if (optionLength == 0)
3514 else if (optionType == 3)
3517 NS_LOG_INFO (
"The option type value " << (uint32_t)optionType);
3520 optionLength = dsrOption->Process (p, packet,
m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3522 if (optionLength == 0)
3527 NS_LOG_INFO (
"The option Length " << (uint32_t)optionLength);
3530 else if (optionType == 96)
3533 optionLength = dsrOption->Process (p, packet,
m_mainAddress, source, ip, protocol, isPromisc, promiscSource);
3534 segmentsLeft = *(data + 3);
3535 if (optionLength == 0)
3542 if (segmentsLeft == 0)
3553 enum IpL4Protocol::RxStatus status =
3554 nextProto->Receive (copy, ip, incomingInterface);
3558 case IpL4Protocol::RX_OK:
3560 case IpL4Protocol::RX_ENDPOINT_CLOSED:
3562 case IpL4Protocol::RX_CSUM_FAILED:
3564 case IpL4Protocol::RX_ENDPOINT_UNREACH:
3581 NS_LOG_INFO (
"This is not the final destination, the packet has already been forward to next hop");
3591 uint8_t salvage = 0;
3606 return IpL4Protocol::RX_OK;
3609 enum IpL4Protocol::RxStatus
3615 return IpL4Protocol::RX_ENDPOINT_UNREACH;
3625 DsrRouting::SetDownTarget6 (DownTargetCallback6 callback)
3638 DsrRouting::GetDownTarget6 (
void)
const
3653 if ((*i)->GetOptionNumber () == optionNumber)
void SendRerrWhenBreaksLinkToNextHop(Ipv4Address nextHop, uint8_t protocol)
Send the route error message when the link breaks to the next hop.
uint32_t m_sendRetries
of retries have been sent for network acknowledgment
uint32_t m_stabilityDecrFactor
The initial decrease factor for link cache.
uint32_t RemoveHeader(Header &header)
void SetDownTarget(IpL4Protocol::DownTargetCallback callback)
std::string m_cacheType
The type of route cache.
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
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.
static uint32_t GetNNodes(void)
void CancelLinkPacketTimer(MaintainBuffEntry &mb)
Cancel the link packet retransmission timer for a specific maintenance entry.
virtual void DoDispose(void)
Drop trace callback.
uint32_t m_maxSendBuffLen
The maximum number of packets that we allow a routing protocol to buffer.
void ScheduleInterRequest(Ptr< Packet > packet)
Schedule the intermediate route request.
uint32_t m_stabilityIncrFactor
The initial increase factor for link cache.
void SendInitialRequest(Ipv4Address source, Ipv4Address destination, uint8_t protocol)
Broadcast the route request packet in subnet.
hold variables of type string
void SendBuffTimerExpire()
The send buffer timer expire.
static Ptr< Node > GetNode(uint32_t n)
void Scheduler(uint32_t priority)
This function is called to schedule sending packets from the network queue.
DSR Passive Buffer Entry.
void SalvagePacket(Ptr< const Packet > packet, Ipv4Address source, Ipv4Address dst, uint8_t protocol)
Salvage the packet which has been transmitted for 3 times.
Time m_sendBuffInterval
how often to check send buffer
Time m_passiveAckTimeout
The timeout value for passive acknowledge.
uint32_t m_discoveryHopLimit
Maximum hops to go for route request.
uint32_t GetPriority(DsrMessageType messageType)
Set the priority of the packet in network queue.
Ptr< Ipv4 > m_ip
The ip ptr.
void AddPacketTag(const Tag &tag) const
uint32_t m_linkRetries
of retries have been sent for link acknowledgment
uint64_t GetUid(void) const
bool Enqueue(ErrorBuffEntry &entry)
void NetworkScheduleTimerExpire(MaintainBuffEntry &mb, uint8_t protocol)
This function deals with packet retransmission timer expire using network acknowledgment.
Time m_maxRequestPeriod
The max request period.
void PrintVector(std::vector< Ipv4Address > &vec)
Print the route vector.
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t m_maxEntriesEachDst
Max number of route entries to save for each destination.
Ptr< dsr::RouteCache > m_routeCache
A "drop-front" queue used by the routing layer to cache routes found.
uint32_t GetSize(void) const
void IncreaseRetransTimer()
This function is called to increase the retransmission timer for data packet in the network queue...
bool IsMulticast(void) const
Ipv4Address m_mainAddress
Our own Ip address.
virtual void DoDispose(void)
Ipv4Address SearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Get the next hop of the route.
bool IsLinkCache()
used to direct to route cache
Time m_linkAckTimeout
The timeout value for link acknowledge.
#define NS_LOG_FUNCTION_NOARGS()
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
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.
void Connect(std::string path, const CallbackBase &cb)
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
uint32_t m_requestTableSize
The max size of the request table size.
void ScheduleCachedReply(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, Ptr< Ipv4Route > route, double hops)
uint32_t m_tryLinkAcks
Maximum number of packet transmission using link acknowledgment.
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.
Time m_maxCacheTime
Max time for caching the route cache entry.
#define NS_FATAL_ERROR(msg)
fatal error handling
Time m_gratReplyHoldoff
The max gratuitous reply hold off time.
a polymophic address class
uint32_t m_maxMaintainLen
Max # of entries for maintainance buffer.
void SendRequest(Ptr< Packet > packet, Ipv4Address source)
Forward the route request if the node is not the destination.
Ipv4Address GetIPfromID(uint16_t id)
Get the ip address from id.
bool IsRunning(void) const
std::vector< Ipv4Address > m_finalRoute
The route cache.
static TypeId GetTypeId()
Get the type identificator.
void SetSource(Ipv4Address src)
int64_t AssignStreams(int64_t stream)
uint32_t m_graReplyTableSize
Set the gratuitous reply table size.
void ConnectCallbacks()
Connect the callback for the tracing event.
Time m_maxNetworkDelay
Maximum network delay.
double GetSeconds(void) const
uint16_t m_ackId
The ack id assigned to each acknowledge.
uint32_t GetDsrOptionsOffset()
Get the offset where the options begin, measured from the start of the extension header.
Ptr< dsr::RreqTable > GetRequestTable() const
Get the request table.
void RemoveAtStart(uint32_t size)
void LinkScheduleTimerExpire(MaintainBuffEntry &mb, uint8_t protocol)
This function deals with packet retransmission timer expire using link acknowledgment.
hold objects of type ns3::Time
void SendUnreachError(Ipv4Address errorHop, 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...
void SetGateway(Ipv4Address gw)
Hold an unsigned integer type.
Time m_sendBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for.
int GetProtocolNumber(void) const
Get the dsr protocol number.
std::vector< Ipv4Address > IP_VECTOR
Define the vector to hold Ip address.
Ipv4Address m_broadcast
The broadcast IP address.
bool IsBroadcast(void) const
uint32_t m_numPriorityQueues
The number of priority queues used.
uint32_t m_broadcastJitter
The max time to delay route request broadcast.
void SetNode(Ptr< Node > node)
Set the node.
static const uint8_t PROT_NUMBER
Define the dsr protocol number.
uint32_t m_requestId
The id assigned to each route request.
Ptr< NetDevice > GetDevice(uint32_t index) const
Ptr< dsr::RouteCache > GetRouteCache() const
Get the route cache.
Hold together all Wifi-related objects.This class holds together ns3::WifiChannel, ns3::WifiPhy, ns3::WifiMac, and, ns3::WifiRemoteStationManager.
Ptr< Ipv4L3Protocol > m_ipv4
Ipv4l3Protocol.
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
uint32_t m_requestTableIds
The request table identifiers.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void CancelNetworkPacketTimer(MaintainBuffEntry &mb)
Cancel the network packet retransmission timer for a specific maintenance entry.
void SendReply(Ptr< Packet > packet, Ipv4Address source, Ipv4Address nextHop, Ptr< Ipv4Route > route)
Time m_minLifeTime
The min life time.
Time m_useExtends
The use extension of the life time for link cache.
GraReply m_graReply
The gratuitous route reply.
void ScheduleInitialReply(Ptr< Packet > packet, Ipv4Address source, Ipv4Address nextHop, Ptr< Ipv4Route > route)
#define NS_LOG_LOGIC(msg)
Time m_blacklistTimeout
The black list time out.
void SetPassiveBuffer(Ptr< dsr::PassiveBuffer > r)
Set the node.
std::map< NetworkKey, Timer > m_addressForwardTimer
Map network key + forward timer.
static Mac48Address ConvertFrom(const Address &address)
std::map< Ipv4Address, Timer > m_addressReqTimer
Map IP address + RREQ timer.
virtual void NotifyNewAggregate(void)
Access to the Ipv4 forwarding table, interfaces, and configuration.
Ptr< Packet > Copy(void) const
uint32_t PeekHeader(Header &header) const
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...
uint8_t m_maxSalvageCount
Maximum # times to salvage a packet.
Time m_initStability
The initial stability value for link cache.
Time m_requestPeriod
The base time interval between route requests.
Implement the Ipv4 layer.
Ptr< dsr::DsrOptions > GetOption(int optionNumber)
Get the option corresponding to optionNumber.
uint16_t GetIDfromIP(Ipv4Address address)
Get the node id from ip address.
hold objects of type Ptr<T>
Ptr< Node > m_node
The node ptr.
void CallCancelPacketTimer(uint16_t ackId, Ipv4Header const &ipv4Header, Ipv4Address realSrc, Ipv4Address realDst)
Call the cancel packet retransmission timer function.
void ScheduleNetworkPacketRetry(MaintainBuffEntry &mb, bool isFirst, uint8_t protocol)
Schedule the packet retransmission based on network layer acknowledgment.
uint32_t m_passiveRetries
of retries have been sent for passive acknowledgment
uint32_t m_maxNetworkSize
Maximum network queue size.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Ptr< Ipv4Route > SetRoute(Ipv4Address nextHop, Ipv4Address srcAddress)
Set the route to use for data packets.
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.
uint32_t m_tryPassiveAcks
Maximum number of packet transmission using passive acknowledgment.
Ptr< NetDevice > GetNetDeviceFromContext(std::string context)
Get the netdevice from the context.
ErrorBuffer m_errorBuffer
The error buffer to save the error messages.
uint32_t m_maxMaintRexmt
Maximum number of retransmissions of data packets.
uint16_t AddAckReqHeader(Ptr< Packet > &packet, Ipv4Address nextHop)
This function is called to add ack request header for network acknowledgement.
void PacketNewRoute(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol)
When route vector corrupted, originate a new packet, normally not happening.
Time m_retransIncr
the increase time for retransmission timer when face network congestion
void ScheduleLinkPacketRetry(MaintainBuffEntry &mb, uint8_t protocol)
Schedule the packet retransmission based on link-layer acknowledgment.
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.
Ptr< dsr::PassiveBuffer > m_passiveBuffer
A "drop-front" queue used by the routing layer to cache route request sent.
std::map< LinkKey, Timer > m_linkAckTimer
The timer for link acknowledgment.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
MaintainBuffer m_maintainBuffer
The declaration of maintain buffer.
L4 Protocol abstract base class.
void SetOutputDevice(Ptr< NetDevice > outputDevice)
void NotifyDataReceipt(std::string context, Ptr< const Packet > p)
Notify the data receipt.
DSR Maintain Buffer Entry.
void SendPacket(Ptr< Packet > packet, Ipv4Address source, Ipv4Address nextHop, uint8_t protocol)
This function is called by when really sending out the packet.
void ScheduleRreqRetry(Ptr< Packet > packet, std::vector< Ipv4Address > address, bool nonProp, uint32_t requestId, uint8_t protocol)
Schedule the route request retry.
IpL4Protocol::DownTargetCallback GetDownTarget(void) const
uint32_t m_maxRreqId
The max number of request ids for a single destination.
virtual enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)
Ptr< dsr::PassiveBuffer > GetPassiveBuffer() const
Get the passive buffer.
uint32_t m_maxCacheLen
Max # of cache entries for route cache.
#define NS_ASSERT_MSG(condition, message)
void CheckSendBuffer()
Check the send buffer of packets with route when send buffer timer expire.
std::map< uint32_t, Ptr< dsr::DsrNetworkQueue > > m_priorityQueue
priority queues
Describes an IPv6 address.
std::map< PassiveKey, uint32_t > m_passiveCnt
Map packet key + passive forward counts.
Ipv4 addresses are stored in host order in this class.
virtual void NotifyNewAggregate()
TracedCallback< Ptr< const Packet > > m_dropTrace
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Ptr< dsr::RreqTable > m_rreqTable
A "drop-front" queue used by the routing layer to cache route request sent.
std::map< PassiveKey, Timer > m_passiveAckTimer
The timer for passive acknowledgment.
void AddDsrOption(DsrOptionHeader const &option)
Serialize the option, prepending pad1 or padn option as necessary.
void CancelPacketTimerNextHop(Ipv4Address nextHop, uint8_t protocol)
Cancel the packet retransmission timer for a all maintenance entries with nextHop address...
Ptr< Ipv4Route > m_ipv4Route
Ipv4 Route.
void SendAck(uint16_t ackId, Ipv4Address destination, Ipv4Address realSrc, Ipv4Address realDst, uint8_t protocol, Ptr< Ipv4Route > route)
Time m_nodeTraversalTime
Time estimated for packet to travel between two nodes.
void SetRequestTable(Ptr< dsr::RreqTable > r)
Set the node.
#define NS_LOG_DEBUG(msg)
bool m_subRoute
Whether to save sub route or not.
bool CancelPassiveTimer(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t segsLeft)
Cancel the passive timer.
void Insert(Ptr< dsr::DsrOptions > option)
Insert a new Dsr Option.
Ipv4Address GetIPfromMAC(Mac48Address address)
Get the Ip address from mac address.
bool SendRealDown(DsrNetworkQueueEntry &newEntry)
This function is called to send packets down stack.
void RouteRequestTimerExpire(Ptr< Packet > packet, std::vector< Ipv4Address > address, uint32_t requestId, uint8_t protocol)
uint32_t m_rreqRetries
Maximum number of retransmissions of RREQ with TTL = NetDiameter to discover a route.
void PriorityScheduler(uint32_t priority, bool continueWithFirst)
This function is called to schedule sending packets from the network queue by priority.
Timer m_sendBuffTimer
The send buffer timer.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
Ptr< Node > GetNodeWithAddress(Ipv4Address ipv4Address)
Get the node with give ip address.
void SetRouteCache(Ptr< dsr::RouteCache > r)
Set the route cache.
DsrOptionList_t m_options
List of DSR Options supported.
void SendGratuitousReply(Ipv4Address replyTo, Ipv4Address replyFrom, std::vector< Ipv4Address > &nodeList, uint8_t protocol)
Send the gratuitous reply.
void SendErrorRequest(DsrOptionRerrUnreachHeader &rerr, uint8_t protocol)
Send the error request packet.
Ptr< Node > GetNode() const
Get the node.
SendBuffer m_sendBuffer
The send buffer.
std::map< LinkKey, uint32_t > m_linkCnt
Map packet key + link forward counts.
bool IsSuspended(void) const
std::map< NetworkKey, uint32_t > m_addressForwardCnt
Map network key + forward counts.
Ptr< T > GetObject(void) const
a unique identifier for an interface.
Time m_nonpropRequestTimeout
The non-propagation request timeout.
TypeId SetParent(TypeId tid)
std::map< Ipv4Address, Timer > m_nonPropReqTimer
Map IP address + RREQ timer.
bool m_linkAck
define if we use link acknowledgement or not
Time MicroSeconds(uint64_t us)
create ns3::Time instances in units of microseconds.
std::vector< std::string > GetElementsFromContext(std::string context)
Get the elements from the tracing context.
void PassiveScheduleTimerExpire(MaintainBuffEntry &mb, uint8_t protocol)
This function deals with packet retransmission timer expire using passive acknowledgment.
void AddHeader(const Header &header)
void CancelPassivePacketTimer(MaintainBuffEntry &mb)
Cancel the passive packet retransmission timer for a specific maintenance entry.
void SetDestination(Ipv4Address dest)
IpL4Protocol::DownTargetCallback m_downTarget
The callback for down layer.
Time m_maxMaintainTime
Time out for maintainance buffer.
void CancelRreqTimer(Ipv4Address dst, bool isRemove)
Cancel the route request timer.
virtual ~DsrRouting()
Destructor.
void SchedulePassivePacketRetry(MaintainBuffEntry &mb, uint8_t protocol)
Schedule the packet retransmission based on passive acknowledgment.