23 #include "ns3/simulator.h"
24 #include "ns3/packet.h"
25 #include "ns3/callback.h"
26 #include "ns3/string.h"
27 #include "ns3/boolean.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/integer.h"
30 #include "ns3/double.h"
37 #include <boost/lexical_cast.hpp>
38 #include <boost/ref.hpp>
40 NS_LOG_COMPONENT_DEFINE(
"ndn.Consumer");
51 TypeId(
"ns3::ndn::Consumer")
54 .AddAttribute(
"StartSeq",
"Initial sequence number", IntegerValue(0),
57 .AddAttribute(
"Prefix",
"Name of the Interest", StringValue(
"/"),
59 .AddAttribute(
"LifeTime",
"LifeTime for interest packet", StringValue(
"2s"),
62 .AddAttribute(
"RetxTimer",
63 "Timeout defining how frequent retransmission timeouts should be checked",
68 .AddTraceSource(
"LastRetransmittedInterestDataDelay",
69 "Delay between last retransmitted Interest and received Data",
70 MakeTraceSourceAccessor(&Consumer::m_lastRetransmittedInterestDataDelay),
71 "ns3::ndn::Consumer::LastRetransmittedInterestDataDelayCallback")
73 .AddTraceSource(
"FirstInterestDataDelay",
74 "Delay between first transmitted Interest and received Data",
75 MakeTraceSourceAccessor(&Consumer::m_firstInterestDataDelay),
76 "ns3::ndn::Consumer::FirstInterestDataDelayCallback");
82 : m_rand(CreateObject<UniformRandomVariable>())
86 NS_LOG_FUNCTION_NOARGS();
88 m_rtt = CreateObject<RttMeanDeviation>();
113 Time now = Simulator::Now();
115 Time rto =
m_rtt->RetransmitTimeout();
118 while (!m_seqTimeouts.empty()) {
119 SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry =
120 m_seqTimeouts.get<i_timestamp>().begin();
121 if (entry->time + rto <= now)
123 uint32_t seqNo = entry->seq;
124 m_seqTimeouts.get<i_timestamp>().erase(entry);
138 NS_LOG_FUNCTION_NOARGS();
149 NS_LOG_FUNCTION_NOARGS();
164 NS_LOG_FUNCTION_NOARGS();
166 uint32_t seq = std::numeric_limits<uint32_t>::max();
168 while (m_retxSeqs.size()) {
169 seq = *m_retxSeqs.begin();
170 m_retxSeqs.erase(m_retxSeqs.begin());
174 if (seq == std::numeric_limits<uint32_t>::max()) {
175 if (
m_seqMax != std::numeric_limits<uint32_t>::max()) {
185 shared_ptr<Name> nameWithSequence = make_shared<Name>(
m_interestName);
186 nameWithSequence->appendSequenceNumber(seq);
190 shared_ptr<Interest> interest = make_shared<Interest>();
191 interest->setNonce(
m_rand->GetValue(0, std::numeric_limits<uint32_t>::max()));
192 interest->setName(*nameWithSequence);
193 interest->setCanBePrefix(
false);
195 interest->setInterestLifetime(interestLifeTime);
198 NS_LOG_INFO(
"> Interest for " << seq);
220 NS_LOG_FUNCTION(
this << data);
225 uint32_t seq = data->getName().at(-1).toSequenceNumber();
226 NS_LOG_INFO(
"< DATA for " << seq);
230 if (hopCountTag !=
nullptr) {
231 hopCount = *hopCountTag;
233 NS_LOG_DEBUG(
"Hop count: " << hopCount);
235 SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find(seq);
236 if (entry != m_seqLastDelay.end()) {
237 m_lastRetransmittedInterestDataDelay(
this, seq, Simulator::Now() - entry->time, hopCount);
240 entry = m_seqFullDelay.find(seq);
241 if (entry != m_seqFullDelay.end()) {
242 m_firstInterestDataDelay(
this, seq, Simulator::Now() - entry->time, m_seqRetxCounts[seq], hopCount);
245 m_seqRetxCounts.erase(seq);
246 m_seqFullDelay.erase(seq);
247 m_seqLastDelay.erase(seq);
249 m_seqTimeouts.erase(seq);
250 m_retxSeqs.erase(seq);
252 m_rtt->AckSeq(SequenceNumber32(seq));
268 NS_LOG_FUNCTION(sequenceNumber);
272 m_rtt->IncreaseMultiplier();
273 m_rtt->SentSeq(SequenceNumber32(sequenceNumber),
275 m_retxSeqs.insert(sequenceNumber);
282 NS_LOG_DEBUG(
"Trying to add " << sequenceNumber <<
" with " << Simulator::Now() <<
". already "
283 << m_seqTimeouts.size() <<
" items");
285 m_seqTimeouts.insert(SeqTimeout(sequenceNumber, Simulator::Now()));
286 m_seqFullDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now()));
288 m_seqLastDelay.erase(sequenceNumber);
289 m_seqLastDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now()));
291 m_seqRetxCounts[sequenceNumber]++;
293 m_rtt->SentSeq(SequenceNumber32(sequenceNumber), 1);