OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 Yufei Cheng | 3 * Copyright (c) 2011 Yufei Cheng |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "ns3/boolean.h" | 49 #include "ns3/boolean.h" |
50 #include "ns3/node-list.h" | 50 #include "ns3/node-list.h" |
51 #include "ns3/double.h" | 51 #include "ns3/double.h" |
52 #include "ns3/pointer.h" | 52 #include "ns3/pointer.h" |
53 #include "ns3/object-vector.h" | 53 #include "ns3/object-vector.h" |
54 #include "ns3/ipv4-address.h" | 54 #include "ns3/ipv4-address.h" |
55 #include "ns3/ipv4-header.h" | 55 #include "ns3/ipv4-header.h" |
56 #include "ns3/ipv4-l3-protocol.h" | 56 #include "ns3/ipv4-l3-protocol.h" |
57 #include "ns3/ipv4-route.h" | 57 #include "ns3/ipv4-route.h" |
58 #include "ns3/trace-source-accessor.h" | 58 #include "ns3/trace-source-accessor.h" |
59 #include "ns3/random-variable.h" | |
60 #include "ns3/icmpv4-l4-protocol.h" | 59 #include "ns3/icmpv4-l4-protocol.h" |
61 #include "ns3/adhoc-wifi-mac.h" | 60 #include "ns3/adhoc-wifi-mac.h" |
62 #include "ns3/wifi-net-device.h" | 61 #include "ns3/wifi-net-device.h" |
63 #include "ns3/inet-socket-address.h" | 62 #include "ns3/inet-socket-address.h" |
64 #include "ns3/udp-l4-protocol.h" | 63 #include "ns3/udp-l4-protocol.h" |
65 #include "ns3/udp-socket-factory.h" | 64 #include "ns3/udp-socket-factory.h" |
66 #include "ns3/tcp-socket-factory.h" | 65 #include "ns3/tcp-socket-factory.h" |
67 | 66 |
68 #include "dsr-rreq-table.h" | 67 #include "dsr-rreq-table.h" |
69 #include "dsr-rcache.h" | 68 #include "dsr-rcache.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 MakeTraceSourceAccessor (&DsrRouting::m_txPacketTrace)) | 261 MakeTraceSourceAccessor (&DsrRouting::m_txPacketTrace)) |
263 .AddTraceSource ("Drop", "Drop DSR packet", | 262 .AddTraceSource ("Drop", "Drop DSR packet", |
264 MakeTraceSourceAccessor (&DsrRouting::m_dropTrace)) | 263 MakeTraceSourceAccessor (&DsrRouting::m_dropTrace)) |
265 ; | 264 ; |
266 return tid; | 265 return tid; |
267 } | 266 } |
268 | 267 |
269 DsrRouting::DsrRouting () | 268 DsrRouting::DsrRouting () |
270 { | 269 { |
271 NS_LOG_FUNCTION_NOARGS (); | 270 NS_LOG_FUNCTION_NOARGS (); |
| 271 |
| 272 m_uniformRandomVariable = CreateObject<UniformRandomVariable> (); |
| 273 |
272 /* | 274 /* |
273 * The following Ptr statements created objects for all the options header for
DSR, and each of them have | 275 * The following Ptr statements created objects for all the options header for
DSR, and each of them have |
274 * distinct option number assigned, when DSR Routing received a packet from hi
gher layer, it will find | 276 * distinct option number assigned, when DSR Routing received a packet from hi
gher layer, it will find |
275 * the following options based on the option number, and pass the packet to th
e appropriate option to | 277 * the following options based on the option number, and pass the packet to th
e appropriate option to |
276 * process it. After the option processing, it will pass the packet back to DS
R Routing to send down layer. | 278 * process it. After the option processing, it will pass the packet back to DS
R Routing to send down layer. |
277 */ | 279 */ |
278 Ptr<dsr::DsrOptionPad1> pad1Option = CreateObject<dsr::DsrOptionPad1> (); | 280 Ptr<dsr::DsrOptionPad1> pad1Option = CreateObject<dsr::DsrOptionPad1> (); |
279 Ptr<dsr::DsrOptionPadn> padnOption = CreateObject<dsr::DsrOptionPadn> (); | 281 Ptr<dsr::DsrOptionPadn> padnOption = CreateObject<dsr::DsrOptionPadn> (); |
280 Ptr<dsr::DsrOptionRreq> rreqOption = CreateObject<dsr::DsrOptionRreq> (); | 282 Ptr<dsr::DsrOptionRreq> rreqOption = CreateObject<dsr::DsrOptionRreq> (); |
281 Ptr<dsr::DsrOptionRrep> rrepOption = CreateObject<dsr::DsrOptionRrep> (); | 283 Ptr<dsr::DsrOptionRrep> rrepOption = CreateObject<dsr::DsrOptionRrep> (); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 errorDst = source; | 781 errorDst = source; |
780 } | 782 } |
781 SendUnreachError (nextHop, errorDst, destination, salvage, protoco
l); | 783 SendUnreachError (nextHop, errorDst, destination, salvage, protoco
l); |
782 /* | 784 /* |
783 * here we cancel the packet retransmission time for all the packe
ts have next hop address | 785 * here we cancel the packet retransmission time for all the packe
ts have next hop address |
784 * as nextHop | 786 * as nextHop |
785 */ | 787 */ |
786 } | 788 } |
787 if (m_maintainBuffer.GetSize () != 0 && m_maintainBuffer.Find (nextHop
)) | 789 if (m_maintainBuffer.GetSize () != 0 && m_maintainBuffer.Find (nextHop
)) |
788 { | 790 { |
789 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (
0,100)), | 791 Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInt
eger (0,100)), |
790 &DsrRouting::SendRerrWhenBreaksLinkToNextHop,
this,nextHop,protocol); | 792 &DsrRouting::SendRerrWhenBreaksLinkToNextHop,
this,nextHop,protocol); |
791 } | 793 } |
792 } | 794 } |
793 } | 795 } |
794 } | 796 } |
795 | 797 |
796 void DsrRouting::SendBuffTimerExpire () | 798 void DsrRouting::SendBuffTimerExpire () |
797 { | 799 { |
798 if (m_sendBuffTimer.IsRunning ()) | 800 if (m_sendBuffTimer.IsRunning ()) |
799 { | 801 { |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 { | 1406 { |
1405 SchedulePassivePacketRetry (newEntry, false, protocol); | 1407 SchedulePassivePacketRetry (newEntry, false, protocol); |
1406 } | 1408 } |
1407 else | 1409 else |
1408 { | 1410 { |
1409 // This is the first network retry | 1411 // This is the first network retry |
1410 ScheduleNetworkPacketRetry (newEntry, true, protocol); | 1412 ScheduleNetworkPacketRetry (newEntry, true, protocol); |
1411 } | 1413 } |
1412 } | 1414 } |
1413 // Try to send packet from *previously* queued entries from send buffe
r if any | 1415 // Try to send packet from *previously* queued entries from send buffe
r if any |
1414 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,10
0)), | 1416 Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger
(0,100)), |
1415 &DsrRouting::SendPacketFromBuffer,this,sourceRout
e,nextHop,protocol); | 1417 &DsrRouting::SendPacketFromBuffer,this,sourceRout
e,nextHop,protocol); |
1416 } | 1418 } |
1417 } | 1419 } |
1418 } | 1420 } |
1419 | 1421 |
1420 uint16_t | 1422 uint16_t |
1421 DsrRouting::AddAckReqHeader (Ptr<Packet>& packet, Ipv4Address nextHop) | 1423 DsrRouting::AddAckReqHeader (Ptr<Packet>& packet, Ipv4Address nextHop) |
1422 { | 1424 { |
1423 NS_LOG_FUNCTION (this << packet << nextHop); | 1425 NS_LOG_FUNCTION (this << packet << nextHop); |
1424 // This packet is used to peek option type | 1426 // This packet is used to peek option type |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 { | 1539 { |
1538 // Here the queue size is larger than 5, we need to increase the r
etransmission timer for each packet in the network queue | 1540 // Here the queue size is larger than 5, we need to increase the r
etransmission timer for each packet in the network queue |
1539 IncreaseRetransTimer (); | 1541 IncreaseRetransTimer (); |
1540 } | 1542 } |
1541 DsrNetworkQueueEntry newEntry; | 1543 DsrNetworkQueueEntry newEntry; |
1542 dsrNetworkQueue->Dequeue (newEntry); | 1544 dsrNetworkQueue->Dequeue (newEntry); |
1543 if (SendRealDown (newEntry)) | 1545 if (SendRealDown (newEntry)) |
1544 { | 1546 { |
1545 NS_LOG_DEBUG ("Packet sent by Dsr. Calling PriorityScheduler after
some time"); | 1547 NS_LOG_DEBUG ("Packet sent by Dsr. Calling PriorityScheduler after
some time"); |
1546 //packet was successfully sent down. call scheduler after some tim
e | 1548 //packet was successfully sent down. call scheduler after some tim
e |
1547 Simulator::Schedule (MicroSeconds (UniformVariable ().GetInteger (
0, 1000)), | 1549 Simulator::Schedule (MicroSeconds (m_uniformRandomVariable->GetInt
eger (0, 1000)), |
1548 &DsrRouting::PriorityScheduler,this, i, false
); | 1550 &DsrRouting::PriorityScheduler,this, i, false
); |
1549 } | 1551 } |
1550 else | 1552 else |
1551 { | 1553 { |
1552 // packet was dropped by Dsr. Call scheduler immediately so that w
e can | 1554 // packet was dropped by Dsr. Call scheduler immediately so that w
e can |
1553 // send another packet immediately. | 1555 // send another packet immediately. |
1554 NS_LOG_DEBUG ("Packet dropped by Dsr. Calling PriorityScheduler im
mediately"); | 1556 NS_LOG_DEBUG ("Packet dropped by Dsr. Calling PriorityScheduler im
mediately"); |
1555 Simulator::Schedule (Seconds (0), &DsrRouting::PriorityScheduler,
this, i, false); | 1557 Simulator::Schedule (Seconds (0), &DsrRouting::PriorityScheduler,
this, i, false); |
1556 } | 1558 } |
1557 if ((i == (m_numPriorityQueues - 1)) && continueWithFirst) | 1559 if ((i == (m_numPriorityQueues - 1)) && continueWithFirst) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 else | 1678 else |
1677 { | 1679 { |
1678 // This is the first network retry | 1680 // This is the first network retry |
1679 ScheduleNetworkPacketRetry (newEntry, true, protocol); | 1681 ScheduleNetworkPacketRetry (newEntry, true, protocol); |
1680 } | 1682 } |
1681 } | 1683 } |
1682 | 1684 |
1683 if (m_sendBuffer.GetSize () != 0 && m_sendBuffer.Find (destination)) | 1685 if (m_sendBuffer.GetSize () != 0 && m_sendBuffer.Find (destination)) |
1684 { | 1686 { |
1685 NS_LOG_DEBUG ("Schedule sending the next packet in send buffer"); | 1687 NS_LOG_DEBUG ("Schedule sending the next packet in send buffer"); |
1686 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (
0,100)), | 1688 Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInt
eger (0,100)), |
1687 &DsrRouting::SendPacketFromBuffer,this,source
Route,nextHop,protocol); | 1689 &DsrRouting::SendPacketFromBuffer,this,source
Route,nextHop,protocol); |
1688 } | 1690 } |
1689 } | 1691 } |
1690 else | 1692 else |
1691 { | 1693 { |
1692 NS_LOG_DEBUG ("All queued packets are out-dated for the destination in
send buffer"); | 1694 NS_LOG_DEBUG ("All queued packets are out-dated for the destination in
send buffer"); |
1693 } | 1695 } |
1694 } | 1696 } |
1695 /* | 1697 /* |
1696 * Here we try to find data packet from send buffer, if packet with this desti
antion found, send it out | 1698 * Here we try to find data packet from send buffer, if packet with this desti
antion found, send it out |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1776 else | 1778 else |
1777 { | 1779 { |
1778 NS_LOG_INFO ("Packet dropped as dsr network queue is full"
); | 1780 NS_LOG_INFO ("Packet dropped as dsr network queue is full"
); |
1779 } | 1781 } |
1780 } | 1782 } |
1781 } | 1783 } |
1782 | 1784 |
1783 if (m_errorBuffer.GetSize () != 0 && m_errorBuffer.Find (destination)) | 1785 if (m_errorBuffer.GetSize () != 0 && m_errorBuffer.Find (destination)) |
1784 { | 1786 { |
1785 NS_LOG_DEBUG ("Schedule sending the next packet in send buffer"); | 1787 NS_LOG_DEBUG ("Schedule sending the next packet in send buffer"); |
1786 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (
0,100)), | 1788 Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInt
eger (0,100)), |
1787 &DsrRouting::SendPacketFromBuffer,this,source
Route,nextHop,protocol); | 1789 &DsrRouting::SendPacketFromBuffer,this,source
Route,nextHop,protocol); |
1788 } | 1790 } |
1789 } | 1791 } |
1790 } | 1792 } |
1791 else | 1793 else |
1792 { | 1794 { |
1793 NS_LOG_DEBUG ("Packet not found in either the send or error buffer"); | 1795 NS_LOG_DEBUG ("Packet not found in either the send or error buffer"); |
1794 } | 1796 } |
1795 } | 1797 } |
1796 | 1798 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1934 Ipv4Address destination = entry.GetDst (); | 1936 Ipv4Address destination = entry.GetDst (); |
1935 /* | 1937 /* |
1936 * Cancel the packet timer and then salvage the data packet | 1938 * Cancel the packet timer and then salvage the data packet |
1937 */ | 1939 */ |
1938 CancelNetworkPacketTimer (entry); | 1940 CancelNetworkPacketTimer (entry); |
1939 SalvagePacket (packet, source, destination, protocol); | 1941 SalvagePacket (packet, source, destination, protocol); |
1940 | 1942 |
1941 if (m_maintainBuffer.GetSize () && m_maintainBuffer.Find (nextHop)) | 1943 if (m_maintainBuffer.GetSize () && m_maintainBuffer.Find (nextHop)) |
1942 { | 1944 { |
1943 NS_LOG_INFO ("Cancel the packet timer for next maintenance entry"); | 1945 NS_LOG_INFO ("Cancel the packet timer for next maintenance entry"); |
1944 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,10
0)), | 1946 Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger
(0,100)), |
1945 &DsrRouting::CancelPacketTimerNextHop,this,nextHo
p,protocol); | 1947 &DsrRouting::CancelPacketTimerNextHop,this,nextHo
p,protocol); |
1946 } | 1948 } |
1947 } | 1949 } |
1948 else | 1950 else |
1949 { | 1951 { |
1950 NS_LOG_INFO ("Maintenance buffer entry not found"); | 1952 NS_LOG_INFO ("Maintenance buffer entry not found"); |
1951 } | 1953 } |
1952 } | 1954 } |
1953 | 1955 |
1954 void | 1956 void |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2212 } | 2214 } |
2213 else | 2215 else |
2214 { | 2216 { |
2215 // This is the end of the data retransmission retries | 2217 // This is the end of the data retransmission retries |
2216 CancelPassivePacketTimer (mb); | 2218 CancelPassivePacketTimer (mb); |
2217 // The function AllEqual will find the exact entry and delete it if found | 2219 // The function AllEqual will find the exact entry and delete it if found |
2218 m_maintainBuffer.AllEqual (mb); | 2220 m_maintainBuffer.AllEqual (mb); |
2219 } | 2221 } |
2220 } | 2222 } |
2221 | 2223 |
| 2224 int64_t |
| 2225 DsrRouting::AssignStreams (int64_t stream) |
| 2226 { |
| 2227 NS_LOG_FUNCTION (this << stream); |
| 2228 m_uniformRandomVariable->SetStream (stream); |
| 2229 return 1; |
| 2230 } |
| 2231 |
2222 void | 2232 void |
2223 DsrRouting::NetworkScheduleTimerExpire (MaintainBuffEntry & mb, | 2233 DsrRouting::NetworkScheduleTimerExpire (MaintainBuffEntry & mb, |
2224 uint8_t protocol) | 2234 uint8_t protocol) |
2225 { | 2235 { |
2226 Ptr<Packet> p = mb.GetPacket ()->Copy (); | 2236 Ptr<Packet> p = mb.GetPacket ()->Copy (); |
2227 Ipv4Address source = mb.GetSrc (); | 2237 Ipv4Address source = mb.GetSrc (); |
2228 Ipv4Address nextHop = mb.GetNextHop (); | 2238 Ipv4Address nextHop = mb.GetNextHop (); |
2229 Ipv4Address dst = mb.GetDst (); | 2239 Ipv4Address dst = mb.GetDst (); |
2230 | 2240 |
2231 NetworkKey networkKey; | 2241 NetworkKey networkKey; |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2722 } | 2732 } |
2723 | 2733 |
2724 void | 2734 void |
2725 DsrRouting::ScheduleInterRequest (Ptr<Packet> packet) | 2735 DsrRouting::ScheduleInterRequest (Ptr<Packet> packet) |
2726 { | 2736 { |
2727 NS_LOG_FUNCTION (this << packet); | 2737 NS_LOG_FUNCTION (this << packet); |
2728 /* | 2738 /* |
2729 * This is a forwarding case when sending route requests, a random delay time
[0, m_broadcastJitter] | 2739 * This is a forwarding case when sending route requests, a random delay time
[0, m_broadcastJitter] |
2730 * used before forwarding as link-layer broadcast | 2740 * used before forwarding as link-layer broadcast |
2731 */ | 2741 */ |
2732 Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0, m_broadca
stJitter)), &DsrRouting::SendRequest, this, | 2742 Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0, m_b
roadcastJitter)), &DsrRouting::SendRequest, this, |
2733 packet, m_mainAddress); | 2743 packet, m_mainAddress); |
2734 } | 2744 } |
2735 | 2745 |
2736 void | 2746 void |
2737 DsrRouting::SendGratuitousReply (Ipv4Address source, Ipv4Address srcAddress, std
::vector<Ipv4Address> &nodeList, uint8_t protocol) | 2747 DsrRouting::SendGratuitousReply (Ipv4Address source, Ipv4Address srcAddress, std
::vector<Ipv4Address> &nodeList, uint8_t protocol) |
2738 { | 2748 { |
2739 NS_LOG_FUNCTION (this << source << srcAddress << (uint32_t)protocol); | 2749 NS_LOG_FUNCTION (this << source << srcAddress << (uint32_t)protocol); |
2740 if (!(m_graReply.FindAndUpdate (source, srcAddress, m_gratReplyHoldoff)))
// Find the gratuitous reply entry | 2750 if (!(m_graReply.FindAndUpdate (source, srcAddress, m_gratReplyHoldoff)))
// Find the gratuitous reply entry |
2741 { | 2751 { |
2742 NS_LOG_LOGIC ("Update gratuitous reply " << source); | 2752 NS_LOG_LOGIC ("Update gratuitous reply " << source); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2836 } | 2846 } |
2837 | 2847 |
2838 void | 2848 void |
2839 DsrRouting::ScheduleCachedReply (Ptr<Packet> packet, | 2849 DsrRouting::ScheduleCachedReply (Ptr<Packet> packet, |
2840 Ipv4Address source, | 2850 Ipv4Address source, |
2841 Ipv4Address destination, | 2851 Ipv4Address destination, |
2842 Ptr<Ipv4Route> route, | 2852 Ptr<Ipv4Route> route, |
2843 double hops) | 2853 double hops) |
2844 { | 2854 { |
2845 NS_LOG_FUNCTION (this << packet << source << destination); | 2855 NS_LOG_FUNCTION (this << packet << source << destination); |
2846 Simulator::Schedule (Time (2 * m_nodeTraversalTime * (hops - 1 + UniformVariab
le ().GetValue (0,1))), &DsrRouting::SendReply, this, packet, source, destinatio
n, route); | 2856 Simulator::Schedule (Time (2 * m_nodeTraversalTime * (hops - 1 + m_uniformRand
omVariable->GetValue (0,1))), &DsrRouting::SendReply, this, packet, source, dest
ination, route); |
2847 } | 2857 } |
2848 | 2858 |
2849 void | 2859 void |
2850 DsrRouting::SendAck (uint16_t ackId, | 2860 DsrRouting::SendAck (uint16_t ackId, |
2851 Ipv4Address destination, | 2861 Ipv4Address destination, |
2852 Ipv4Address realSrc, | 2862 Ipv4Address realSrc, |
2853 Ipv4Address realDst, | 2863 Ipv4Address realDst, |
2854 uint8_t protocol, | 2864 uint8_t protocol, |
2855 Ptr<Ipv4Route> route) | 2865 Ptr<Ipv4Route> route) |
2856 { | 2866 { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3133 { | 3143 { |
3134 if ((*i)->GetOptionNumber () == optionNumber) | 3144 if ((*i)->GetOptionNumber () == optionNumber) |
3135 { | 3145 { |
3136 return *i; | 3146 return *i; |
3137 } | 3147 } |
3138 } | 3148 } |
3139 return 0; | 3149 return 0; |
3140 } | 3150 } |
3141 } /* namespace dsr */ | 3151 } /* namespace dsr */ |
3142 } /* namespace ns3 */ | 3152 } /* namespace ns3 */ |
OLD | NEW |