23 #include "ns3/simulator.h"
24 #include "ns3/packet.h"
25 #include "ns3/callback.h"
26 #include "ns3/string.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/double.h"
30 NS_LOG_COMPONENT_DEFINE(
"ndn.ConsumerWindow");
41 TypeId(
"ns3::ndn::ConsumerWindow")
44 .AddConstructor<ConsumerWindow>()
46 .AddAttribute(
"Window",
"Initial size of the window", StringValue(
"1"),
47 MakeUintegerAccessor(&ConsumerWindow::GetWindow, &ConsumerWindow::SetWindow),
48 MakeUintegerChecker<uint32_t>())
50 .AddAttribute(
"PayloadSize",
51 "Average size of content object size (to calculate interest generation rate)",
52 UintegerValue(1040), MakeUintegerAccessor(&ConsumerWindow::GetPayloadSize,
53 &ConsumerWindow::SetPayloadSize),
54 MakeUintegerChecker<uint32_t>())
56 .AddAttribute(
"Size",
"Amount of data in megabytes to request, relying on PayloadSize "
57 "parameter (alternative to MaxSeq attribute)",
59 MakeDoubleAccessor(&ConsumerWindow::GetMaxSize, &ConsumerWindow::SetMaxSize),
60 MakeDoubleChecker<double>())
62 .AddAttribute(
"MaxSeq",
"Maximum sequence number to request (alternative to Size attribute, "
63 "would activate only if Size is -1). "
64 "The parameter is activated only if Size negative (not set)",
65 IntegerValue(std::numeric_limits<uint32_t>::max()),
66 MakeUintegerAccessor(&ConsumerWindow::GetSeqMax, &ConsumerWindow::SetSeqMax),
67 MakeUintegerChecker<uint32_t>())
69 .AddAttribute(
"InitialWindowOnTimeout",
"Set window to initial value when timeout occurs",
71 MakeBooleanAccessor(&ConsumerWindow::m_setInitialWindowOnTimeout),
74 .AddTraceSource(
"WindowTrace",
75 "Window that controls how many outstanding interests are allowed",
76 MakeTraceSourceAccessor(&ConsumerWindow::m_window))
77 .AddTraceSource(
"InFlight",
"Current number of outstanding interests",
78 MakeTraceSourceAccessor(&ConsumerWindow::m_inFlight));
90 ConsumerWindow::SetWindow(uint32_t window)
92 m_initialWindow = window;
93 m_window = m_initialWindow;
97 ConsumerWindow::GetWindow()
const
99 return m_initialWindow;
103 ConsumerWindow::GetPayloadSize()
const
105 return m_payloadSize;
109 ConsumerWindow::SetPayloadSize(uint32_t payload)
111 m_payloadSize = payload;
115 ConsumerWindow::GetMaxSize()
const
124 ConsumerWindow::SetMaxSize(
double size)
132 m_seqMax = floor(1.0 + m_maxSize * 1024.0 * 1024.0 / m_payloadSize);
133 NS_LOG_DEBUG(
"MaxSeqNo: " <<
m_seqMax);
138 ConsumerWindow::GetSeqMax()
const
144 ConsumerWindow::SetSeqMax(uint32_t seqMax)
155 if (m_window == static_cast<uint32_t>(0)) {
159 "Next event in " << (std::min<double>(0.5,
m_rtt->RetransmitTimeout().ToDouble(Time::S)))
162 Simulator::Schedule(Seconds(
163 std::min<double>(0.5,
m_rtt->RetransmitTimeout().ToDouble(Time::S))),
166 else if (m_inFlight >= m_window) {
187 m_window = m_window + 1;
189 if (m_inFlight > static_cast<uint32_t>(0))
191 NS_LOG_DEBUG(
"Window: " << m_window <<
", InFlight: " << m_inFlight);
199 if (m_inFlight > static_cast<uint32_t>(0))
202 if (m_setInitialWindowOnTimeout) {
204 m_window = m_initialWindow;
207 NS_LOG_DEBUG(
"Window: " << m_window <<
", InFlight: " << m_inFlight);
virtual void OnTimeout(uint32_t sequenceNumber)
Timeout event.
uint32_t m_seqMax
maximum number of sequence number
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
Ptr< RttEstimator > m_rtt
RTT estimator.
static TypeId GetTypeId()
virtual void OnTimeout(uint32_t sequenceNumber)
Timeout event.
virtual void ScheduleNextPacket()
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
NDN application for sending out Interest packets.
virtual void OnData(shared_ptr< const Data > contentObject)
Method that will be called every time new Data arrives.
void SendPacket()
Actually send packet.
ConsumerWindow()
Default constructor.
ndn ConsumerWindow
Copyright (c) 2011-2015 Regents of the University of California.
virtual void OnData(shared_ptr< const Data > contentObject)
Method that will be called every time new Data arrives.
EventId m_sendEvent
EventId of pending "send packet" event.
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 WillSendOutInterest(uint32_t sequenceNumber)
An event that is fired just before an Interest packet is actually send out (send is inevitable) ...