21 #include "ndn-consumer-window.h"
24 #include "ns3/simulator.h"
25 #include "ns3/packet.h"
26 #include "ns3/callback.h"
27 #include "ns3/string.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/double.h"
30 #include "ns3/ndn-data.h"
31 #include "ns3/ndn-interest.h"
33 NS_LOG_COMPONENT_DEFINE (
"ndn.ConsumerWindow");
38 NS_OBJECT_ENSURE_REGISTERED (ConsumerWindow);
41 ConsumerWindow::GetTypeId (
void)
43 static TypeId tid = TypeId (
"ns3::ndn::ConsumerWindow")
46 .AddConstructor<ConsumerWindow> ()
48 .AddAttribute (
"Window",
"Initial size of the window",
50 MakeUintegerAccessor (&ConsumerWindow::GetWindow, &ConsumerWindow::SetWindow),
51 MakeUintegerChecker<uint32_t> ())
53 .AddAttribute (
"PayloadSize",
"Average size of content object size (to calculate interest generation rate)",
55 MakeUintegerAccessor (&ConsumerWindow::GetPayloadSize, &ConsumerWindow::SetPayloadSize),
56 MakeUintegerChecker<uint32_t>())
58 .AddAttribute (
"Size",
59 "Amount of data in megabytes to request, relying on PayloadSize parameter (alternative to MaxSeq attribute)",
61 MakeDoubleAccessor (&ConsumerWindow::GetMaxSize, &ConsumerWindow::SetMaxSize),
62 MakeDoubleChecker<double> ())
64 .AddAttribute (
"MaxSeq",
65 "Maximum sequence number to request (alternative to Size attribute, would activate only if Size is -1). "
66 "The parameter is activated only if Size negative (not set)",
67 IntegerValue (std::numeric_limits<uint32_t>::max ()),
68 MakeUintegerAccessor (&ConsumerWindow::GetSeqMax, &ConsumerWindow::SetSeqMax),
69 MakeUintegerChecker<uint32_t> ())
71 .AddAttribute (
"InitialWindowOnTimeout",
"Set window to initial value when timeout occurs",
73 MakeBooleanAccessor (&ConsumerWindow::m_setInitialWindowOnTimeout),
74 MakeBooleanChecker ())
76 .AddTraceSource (
"WindowTrace",
77 "Window that controls how many outstanding interests are allowed",
78 MakeTraceSourceAccessor (&ConsumerWindow::m_window))
79 .AddTraceSource (
"InFlight",
80 "Current number of outstanding interests",
81 MakeTraceSourceAccessor (&ConsumerWindow::m_inFlight))
88 : m_payloadSize (1040)
94 ConsumerWindow::SetWindow (uint32_t window)
96 m_initialWindow = window;
97 m_window = m_initialWindow;
101 ConsumerWindow::GetWindow ()
const
103 return m_initialWindow;
107 ConsumerWindow::GetPayloadSize ()
const
109 return m_payloadSize;
113 ConsumerWindow::SetPayloadSize (uint32_t payload)
115 m_payloadSize = payload;
119 ConsumerWindow::GetMaxSize ()
const
128 ConsumerWindow::SetMaxSize (
double size)
137 m_seqMax = floor(1.0 + m_maxSize * 1024.0 * 1024.0 / m_payloadSize);
138 NS_LOG_DEBUG (
"MaxSeqNo: " <<
m_seqMax);
143 ConsumerWindow::GetSeqMax ()
const
149 ConsumerWindow::SetSeqMax (uint32_t seqMax)
161 if (m_window == static_cast<uint32_t> (0))
165 NS_LOG_DEBUG (
"Next event in " << (std::min<double> (0.5,
m_rtt->RetransmitTimeout ().ToDouble (Time::S))) <<
" sec");
166 m_sendEvent = Simulator::Schedule (Seconds (std::min<double> (0.5,
m_rtt->RetransmitTimeout ().ToDouble (Time::S))),
169 else if (m_inFlight >= m_window)
193 m_window = m_window + 1;
195 if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
196 NS_LOG_DEBUG (
"Window: " << m_window <<
", InFlight: " << m_inFlight);
206 if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
208 if (m_window > static_cast<uint32_t> (0))
211 m_window = std::max<uint32_t> (0, m_window - 1);
214 NS_LOG_DEBUG (
"Window: " << m_window <<
", InFlight: " << m_inFlight);
222 if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
224 if (m_setInitialWindowOnTimeout)
227 m_window = m_initialWindow;
230 NS_LOG_DEBUG (
"Window: " << m_window <<
", InFlight: " << m_inFlight);
virtual void OnData(Ptr< const Data > contentObject)
Method that will be called every time new Data arrives.
virtual void OnTimeout(uint32_t sequenceNumber)
Timeout event.
Consumer()
Default constructor Sets up randomizer function and packet sequence number.
virtual void OnNack(Ptr< const Interest > interest)
Method that will be called every time new NACK arrives.
virtual void WillSendOutInterest(uint32_t sequenceNumber)
An event that is fired just before an Interest packet is actually send out (send is inevitable) ...
virtual void ScheduleNextPacket()
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
EventId m_sendEvent
EventId of pending "send packet" event.
virtual void OnData(Ptr< const Data > contentObject)
Method that will be called every time new Data arrives.
virtual void OnTimeout(uint32_t sequenceNumber)
Timeout event.
Ptr< RttEstimator > m_rtt
RTT estimator.
uint32_t m_seqMax
maximum number of sequence number
void SendPacket()
Actually send packet.
virtual void WillSendOutInterest(uint32_t sequenceNumber)
An event that is fired just before an Interest packet is actually send out (send is inevitable) ...
virtual void OnNack(Ptr< const Interest > interest)
Method that will be called every time new NACK arrives.
ConsumerWindow()
Default constructor.