|
|
| 135 |
MaxQueueTime (Seconds (30)), |
135 |
MaxQueueTime (Seconds (30)), |
| 136 |
DestinationOnly (false), |
136 |
DestinationOnly (false), |
| 137 |
GratuitousReply (true), |
137 |
GratuitousReply (true), |
| 138 |
EnableHello (true), |
138 |
EnableHello (false), |
| 139 |
m_routingTable (DeletePeriod), |
139 |
m_routingTable (DeletePeriod), |
| 140 |
m_queue (MaxQueueLen, MaxQueueTime), |
140 |
m_queue (MaxQueueLen, MaxQueueTime), |
| 141 |
m_requestId (0), |
141 |
m_requestId (0), |
|
|
| 147 |
m_rerrCount (0), |
147 |
m_rerrCount (0), |
| 148 |
m_htimer (Timer::CANCEL_ON_DESTROY), |
148 |
m_htimer (Timer::CANCEL_ON_DESTROY), |
| 149 |
m_rreqRateLimitTimer (Timer::CANCEL_ON_DESTROY), |
149 |
m_rreqRateLimitTimer (Timer::CANCEL_ON_DESTROY), |
| 150 |
m_rerrRateLimitTimer (Timer::CANCEL_ON_DESTROY) |
150 |
m_rerrRateLimitTimer (Timer::CANCEL_ON_DESTROY), |
|
|
151 |
m_lastBcastTime (Seconds (0)) |
| 151 |
{ |
152 |
{ |
| 152 |
if (EnableHello) |
153 |
m_nb.SetCallback (MakeCallback (&RoutingProtocol::SendRerrWhenBreaksLinkToNextHop, this)); |
| 153 |
{ |
|
|
| 154 |
m_nb.SetCallback (MakeCallback (&RoutingProtocol::SendRerrWhenBreaksLinkToNextHop, this)); |
| 155 |
} |
| 156 |
} |
154 |
} |
| 157 |
|
155 |
|
| 158 |
TypeId |
156 |
TypeId |
|
|
| 334 |
NS_LOG_FUNCTION (this << header << (oif ? oif->GetIfIndex () : 0)); |
332 |
NS_LOG_FUNCTION (this << header << (oif ? oif->GetIfIndex () : 0)); |
| 335 |
if (!p) |
333 |
if (!p) |
| 336 |
{ |
334 |
{ |
|
|
335 |
NS_LOG_DEBUG("Packet is == 0"); |
| 337 |
return LoopbackRoute (header, oif); // later |
336 |
return LoopbackRoute (header, oif); // later |
| 338 |
} |
337 |
} |
| 339 |
if (m_socketAddresses.empty ()) |
338 |
if (m_socketAddresses.empty ()) |
|
|
| 368 |
// routed to loopback, received from loopback and passed to RouteInput (see below) |
367 |
// routed to loopback, received from loopback and passed to RouteInput (see below) |
| 369 |
uint32_t iif = (oif ? m_ipv4->GetInterfaceForDevice (oif) : -1); |
368 |
uint32_t iif = (oif ? m_ipv4->GetInterfaceForDevice (oif) : -1); |
| 370 |
DeferredRouteOutputTag tag (iif); |
369 |
DeferredRouteOutputTag tag (iif); |
|
|
370 |
NS_LOG_DEBUG ("Valid Route not found"); |
| 371 |
if (!p->PeekPacketTag (tag)) |
371 |
if (!p->PeekPacketTag (tag)) |
| 372 |
{ |
372 |
{ |
| 373 |
p->AddPacketTag (tag); |
373 |
p->AddPacketTag (tag); |
|
|
| 903 |
destination = iface.GetBroadcast (); |
903 |
destination = iface.GetBroadcast (); |
| 904 |
} |
904 |
} |
| 905 |
NS_LOG_DEBUG ("Send RREQ with id " << rreqHeader.GetId () << " to socket"); |
905 |
NS_LOG_DEBUG ("Send RREQ with id " << rreqHeader.GetId () << " to socket"); |
| 906 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
906 |
m_lastBcastTime = Simulator::Now (); |
|
|
907 |
Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination); |
| 907 |
} |
908 |
} |
| 908 |
ScheduleRreqRetry (dst); |
909 |
ScheduleRreqRetry (dst); |
| 909 |
if (EnableHello) |
|
|
| 910 |
{ |
| 911 |
if (!m_htimer.IsRunning ()) |
| 912 |
{ |
| 913 |
m_htimer.Cancel (); |
| 914 |
m_htimer.Schedule (HelloInterval - Time (0.01 * MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10)))); |
| 915 |
} |
| 916 |
} |
| 917 |
} |
910 |
} |
| 918 |
|
911 |
|
| 919 |
void |
912 |
void |
|
|
913 |
RoutingProtocol::SendTo (Ptr<Socket> socket, Ptr<Packet> packet, Ipv4Address destination) |
| 914 |
{ |
| 915 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
| 916 |
|
| 917 |
} |
| 918 |
void |
| 920 |
RoutingProtocol::ScheduleRreqRetry (Ipv4Address dst) |
919 |
RoutingProtocol::ScheduleRreqRetry (Ipv4Address dst) |
| 921 |
{ |
920 |
{ |
| 922 |
NS_LOG_FUNCTION (this << dst); |
921 |
NS_LOG_FUNCTION (this << dst); |
|
|
| 1101 |
toOrigin.SetLifeTime (std::max (Time (2 * NetTraversalTime - 2 * hop * NodeTraversalTime), |
1100 |
toOrigin.SetLifeTime (std::max (Time (2 * NetTraversalTime - 2 * hop * NodeTraversalTime), |
| 1102 |
toOrigin.GetLifeTime ())); |
1101 |
toOrigin.GetLifeTime ())); |
| 1103 |
m_routingTable.Update (toOrigin); |
1102 |
m_routingTable.Update (toOrigin); |
|
|
1103 |
//m_nb.Update (src, Time (AllowedHelloLoss * HelloInterval)); |
| 1104 |
} |
1104 |
} |
|
|
1105 |
|
| 1106 |
|
| 1107 |
RoutingTableEntry toNeighbor; |
| 1108 |
if (!m_routingTable.LookupRoute (src, toNeighbor)) |
| 1109 |
{ |
| 1110 |
NS_LOG_DEBUG ("Neighbor:" << src << " not found in routing table. Creating an entry"); |
| 1111 |
Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver)); |
| 1112 |
RoutingTableEntry newEntry (dev, src, false, rreqHeader.GetOriginSeqno (), |
| 1113 |
m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0), |
| 1114 |
1, src, ActiveRouteTimeout); |
| 1115 |
m_routingTable.AddRoute (newEntry); |
| 1116 |
} |
| 1117 |
else |
| 1118 |
{ |
| 1119 |
toNeighbor.SetLifeTime (ActiveRouteTimeout); |
| 1120 |
toNeighbor.SetValidSeqNo (false); |
| 1121 |
toNeighbor.SetSeqNo (rreqHeader.GetOriginSeqno ()); |
| 1122 |
toNeighbor.SetFlag (VALID); |
| 1123 |
toNeighbor.SetOutputDevice (m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver))); |
| 1124 |
toNeighbor.SetInterface (m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0)); |
| 1125 |
m_routingTable.Update (toNeighbor); |
| 1126 |
} |
| 1127 |
m_nb.Update (src, Time (AllowedHelloLoss * HelloInterval)); |
| 1128 |
|
| 1105 |
NS_LOG_LOGIC (receiver << " receive RREQ with hop count " << static_cast<uint32_t>(rreqHeader.GetHopCount ()) |
1129 |
NS_LOG_LOGIC (receiver << " receive RREQ with hop count " << static_cast<uint32_t>(rreqHeader.GetHopCount ()) |
| 1106 |
<< " ID " << rreqHeader.GetId () |
1130 |
<< " ID " << rreqHeader.GetId () |
| 1107 |
<< " to destination " << rreqHeader.GetDst ()); |
1131 |
<< " to destination " << rreqHeader.GetDst ()); |
|
|
| 1170 |
{ |
1194 |
{ |
| 1171 |
destination = iface.GetBroadcast (); |
1195 |
destination = iface.GetBroadcast (); |
| 1172 |
} |
1196 |
} |
| 1173 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
1197 |
m_lastBcastTime = Simulator::Now (); |
| 1174 |
} |
1198 |
Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination); |
| 1175 |
|
1199 |
|
| 1176 |
if (EnableHello) |
|
|
| 1177 |
{ |
| 1178 |
if (!m_htimer.IsRunning ()) |
| 1179 |
{ |
| 1180 |
m_htimer.Cancel (); |
| 1181 |
m_htimer.Schedule (HelloInterval - Time (0.1 * MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10)))); |
| 1182 |
} |
| 1183 |
} |
1200 |
} |
| 1184 |
} |
1201 |
} |
| 1185 |
|
1202 |
|
|
|
| 1539 |
RoutingProtocol::HelloTimerExpire () |
1556 |
RoutingProtocol::HelloTimerExpire () |
| 1540 |
{ |
1557 |
{ |
| 1541 |
NS_LOG_FUNCTION (this); |
1558 |
NS_LOG_FUNCTION (this); |
| 1542 |
SendHello (); |
1559 |
Time offset = Time (Seconds (0)); |
|
|
1560 |
if (m_lastBcastTime > Time (Seconds (0))) |
| 1561 |
{ |
| 1562 |
offset = Simulator::Now () - m_lastBcastTime; |
| 1563 |
NS_LOG_DEBUG ("Hello deferred due to last bcast at:" << m_lastBcastTime); |
| 1564 |
} |
| 1565 |
else |
| 1566 |
{ |
| 1567 |
SendHello (); |
| 1568 |
} |
| 1543 |
m_htimer.Cancel (); |
1569 |
m_htimer.Cancel (); |
| 1544 |
Time t = Time (0.01 * MilliSeconds (m_uniformRandomVariable->GetInteger (0, 100))); |
1570 |
Time diff = HelloInterval - offset; |
| 1545 |
m_htimer.Schedule (HelloInterval - t); |
1571 |
m_htimer.Schedule (std::max (Time (Seconds (0)), diff)); |
|
|
1572 |
m_lastBcastTime = Time (Seconds (0)); |
| 1546 |
} |
1573 |
} |
| 1547 |
|
1574 |
|
| 1548 |
void |
1575 |
void |
|
|
| 1598 |
{ |
1625 |
{ |
| 1599 |
destination = iface.GetBroadcast (); |
1626 |
destination = iface.GetBroadcast (); |
| 1600 |
} |
1627 |
} |
| 1601 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
1628 |
Time jitter = Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))); |
|
|
1629 |
Simulator::Schedule (jitter, &RoutingProtocol::SendTo, this , socket, packet, destination); |
| 1602 |
} |
1630 |
} |
| 1603 |
} |
1631 |
} |
| 1604 |
|
1632 |
|
|
|
| 1757 |
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toPrecursor.GetInterface ()); |
1785 |
Ptr<Socket> socket = FindSocketWithInterfaceAddress (toPrecursor.GetInterface ()); |
| 1758 |
NS_ASSERT (socket); |
1786 |
NS_ASSERT (socket); |
| 1759 |
NS_LOG_LOGIC ("one precursor => unicast RERR to " << toPrecursor.GetDestination () << " from " << toPrecursor.GetInterface ().GetLocal ()); |
1787 |
NS_LOG_LOGIC ("one precursor => unicast RERR to " << toPrecursor.GetDestination () << " from " << toPrecursor.GetInterface ().GetLocal ()); |
| 1760 |
socket->SendTo (packet, 0, InetSocketAddress (precursors.front (), AODV_PORT)); |
1788 |
Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, precursors.front ()); |
| 1761 |
m_rerrCount++; |
1789 |
m_rerrCount++; |
| 1762 |
} |
1790 |
} |
| 1763 |
return; |
1791 |
return; |
|
|
| 1790 |
{ |
1818 |
{ |
| 1791 |
destination = i->GetBroadcast (); |
1819 |
destination = i->GetBroadcast (); |
| 1792 |
} |
1820 |
} |
| 1793 |
socket->SendTo (packet, 0, InetSocketAddress (destination, AODV_PORT)); |
1821 |
Simulator::Schedule (Time (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))), &RoutingProtocol::SendTo, this, socket, packet, destination); |
| 1794 |
m_rerrCount++; |
|
|
| 1795 |
} |
1822 |
} |
| 1796 |
} |
1823 |
} |
| 1797 |
|
1824 |
|