21 #include "ndn-consumer.h"
24 #include "ns3/simulator.h"
25 #include "ns3/packet.h"
26 #include "ns3/callback.h"
27 #include "ns3/string.h"
28 #include "ns3/boolean.h"
29 #include "ns3/uinteger.h"
30 #include "ns3/integer.h"
31 #include "ns3/double.h"
33 #include "ns3/ndn-app-face.h"
34 #include "ns3/ndn-interest.h"
35 #include "ns3/ndn-data.h"
36 #include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.h"
37 #include "ns3/ndnSIM/utils/ndn-rtt-mean-deviation.h"
39 #include <boost/ref.hpp>
41 #include "ns3/names.h"
43 NS_LOG_COMPONENT_DEFINE (
"ndn.Consumer");
48 NS_OBJECT_ENSURE_REGISTERED (Consumer);
51 Consumer::GetTypeId (
void)
53 static TypeId tid = TypeId (
"ns3::ndn::Consumer")
56 .AddAttribute (
"StartSeq",
"Initial sequence number",
59 MakeIntegerChecker<int32_t>())
61 .AddAttribute (
"Prefix",
"Name of the Interest",
65 .AddAttribute (
"LifeTime",
"LifeTime for interest packet",
70 .AddAttribute (
"RetxTimer",
71 "Timeout defining how frequent retransmission timeouts should be checked",
76 .AddTraceSource (
"LastRetransmittedInterestDataDelay",
"Delay between last retransmitted Interest and received Data",
77 MakeTraceSourceAccessor (&Consumer::m_lastRetransmittedInterestDataDelay))
79 .AddTraceSource (
"FirstInterestDataDelay",
"Delay between first transmitted Interest and received Data",
80 MakeTraceSourceAccessor (&Consumer::m_firstInterestDataDelay))
87 : m_rand (0, std::numeric_limits<uint32_t>::max ())
91 NS_LOG_FUNCTION_NOARGS ();
93 m_rtt = CreateObject<RttMeanDeviation> ();
120 Time now = Simulator::Now ();
122 Time rto =
m_rtt->RetransmitTimeout ();
125 while (!m_seqTimeouts.empty ())
127 SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry =
128 m_seqTimeouts.get<i_timestamp> ().begin ();
129 if (entry->time + rto <= now)
131 uint32_t seqNo = entry->seq;
132 m_seqTimeouts.get<i_timestamp> ().erase (entry);
147 NS_LOG_FUNCTION_NOARGS ();
158 NS_LOG_FUNCTION_NOARGS ();
172 NS_LOG_FUNCTION_NOARGS ();
174 uint32_t seq=std::numeric_limits<uint32_t>::max ();
176 while (m_retxSeqs.size ())
178 seq = *m_retxSeqs.begin ();
179 m_retxSeqs.erase (m_retxSeqs.begin ());
183 if (seq == std::numeric_limits<uint32_t>::max ())
185 if (
m_seqMax != std::numeric_limits<uint32_t>::max ())
198 nameWithSequence->appendSeqNum (seq);
201 Ptr<Interest> interest = Create<Interest> ();
202 interest->SetNonce (
m_rand.GetValue ());
203 interest->SetName (nameWithSequence);
207 NS_LOG_INFO (
"> Interest for " << seq);
212 interest->GetPayload ()->AddPacketTag (hopCountTag);
215 m_face->ReceiveInterest (interest);
232 NS_LOG_FUNCTION (
this << data);
236 uint32_t seq = data->GetName ().get (-1).toSeqNum ();
237 NS_LOG_INFO (
"< DATA for " << seq);
241 if (data->GetPayload ()->PeekPacketTag (hopCountTag))
243 hopCount = hopCountTag.
Get ();
246 SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find (seq);
247 if (entry != m_seqLastDelay.end ())
249 m_lastRetransmittedInterestDataDelay (
this, seq, Simulator::Now () - entry->time, hopCount);
252 entry = m_seqFullDelay.find (seq);
253 if (entry != m_seqFullDelay.end ())
255 m_firstInterestDataDelay (
this, seq, Simulator::Now () - entry->time, m_seqRetxCounts[seq], hopCount);
258 m_seqRetxCounts.erase (seq);
259 m_seqFullDelay.erase (seq);
260 m_seqLastDelay.erase (seq);
262 m_seqTimeouts.erase (seq);
263 m_retxSeqs.erase (seq);
265 m_rtt->AckSeq (SequenceNumber32 (seq));
280 uint32_t seq = interest->GetName ().get (-1).toSeqNum ();
281 NS_LOG_INFO (
"< NACK for " << seq);
286 m_retxSeqs.insert (seq);
289 m_seqTimeouts.erase (seq);
291 m_rtt->IncreaseMultiplier ();
298 NS_LOG_FUNCTION (sequenceNumber);
301 m_rtt->IncreaseMultiplier ();
302 m_rtt->SentSeq (SequenceNumber32 (sequenceNumber), 1);
303 m_retxSeqs.insert (sequenceNumber);
310 NS_LOG_DEBUG (
"Trying to add " << sequenceNumber <<
" with " << Simulator::Now () <<
". already " << m_seqTimeouts.size () <<
" items");
312 m_seqTimeouts.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
313 m_seqFullDelay.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
315 m_seqLastDelay.erase (sequenceNumber);
316 m_seqLastDelay.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
318 m_seqRetxCounts[sequenceNumber] ++;
320 m_rtt->SentSeq (SequenceNumber32 (sequenceNumber), 1);
bool m_active
Flag to indicate that application is active (set by StartApplication and StopApplication) ...
virtual void OnTimeout(uint32_t sequenceNumber)
Timeout event.
Consumer()
Default constructor Sets up randomizer function and packet sequence number.
Name m_interestName
NDN Name of the Interest (use Name)
virtual void StartApplication()
Called at time specified by Start.
virtual void ScheduleNextPacket()=0
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
TracedCallback< Ptr< const Interest >, Ptr< App >, Ptr< Face > > m_transmittedInterests
App-level trace of transmitted Interests.
UniformVariable m_rand
nonce generator
Time m_retxTimer
Currently estimated retransmission timer.
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.
EventId m_retxEvent
Event to check whether or not retransmission should be performed.
Ptr< RttEstimator > m_rtt
RTT estimator.
virtual void OnNack(Ptr< const Interest > interest)
Method that will be called every time new NACK arrives.
Time GetRetxTimer() const
Returns the frequency of checking the retransmission timeouts.
void CheckRetxTimeout()
Checks if the packet need to be retransmitted becuase of retransmission timer expiration.
uint32_t m_seqMax
maximum number of sequence number
virtual void OnData(Ptr< const Data > contentObject)
Method that will be called every time new Data arrives.
void SendPacket()
Actually send packet.
virtual void StopApplication()
Called at time specified by Stop.
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 StartApplication()
Called at time specified by Start.
uint32_t Get() const
Get value of hop count.
Packet tag that is used to track hop count for Interest-Data pairs.
uint32_t m_seq
currently requested sequence number
App()
Default constructor.
Ptr< Face > m_face
automatically created application face through which application communicates
virtual void StopApplication()
Called at time specified by Stop.
Time m_interestLifeTime
LifeTime for interest packet.
void SetRetxTimer(Time retxTimer)
Modifies the frequency of checking the retransmission timeouts.
virtual void OnNack(Ptr< const Interest > interest)
Method that will be called every time new NACK arrives.