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" 
   36 #include <boost/lexical_cast.hpp> 
   37 #include <boost/ref.hpp> 
   39 NS_LOG_COMPONENT_DEFINE(
"ndn.Consumer");
 
   50     TypeId(
"ns3::ndn::Consumer")
 
   53       .AddAttribute(
"StartSeq", 
"Initial sequence number", IntegerValue(0),
 
   56       .AddAttribute(
"Prefix", 
"Name of the Interest", StringValue(
"/"),
 
   58       .AddAttribute(
"LifeTime", 
"LifeTime for interest packet", StringValue(
"2s"),
 
   61       .AddAttribute(
"RetxTimer",
 
   62                     "Timeout defining how frequent retransmission timeouts should be checked",
 
   67       .AddTraceSource(
"LastRetransmittedInterestDataDelay",
 
   68                       "Delay between last retransmitted Interest and received Data",
 
   69                       MakeTraceSourceAccessor(&Consumer::m_lastRetransmittedInterestDataDelay))
 
   71       .AddTraceSource(
"FirstInterestDataDelay",
 
   72                       "Delay between first transmitted Interest and received Data",
 
   73                       MakeTraceSourceAccessor(&Consumer::m_firstInterestDataDelay));
 
   79   : m_rand(0, std::numeric_limits<uint32_t>::max())
 
   83   NS_LOG_FUNCTION_NOARGS();
 
   85   m_rtt = CreateObject<RttMeanDeviation>();
 
  110   Time now = Simulator::Now();
 
  112   Time rto = 
m_rtt->RetransmitTimeout();
 
  115   while (!m_seqTimeouts.empty()) {
 
  116     SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry =
 
  117       m_seqTimeouts.get<i_timestamp>().begin();
 
  118     if (entry->time + rto <= now) 
 
  120       uint32_t seqNo = entry->seq;
 
  121       m_seqTimeouts.get<i_timestamp>().erase(entry);
 
  135   NS_LOG_FUNCTION_NOARGS();
 
  146   NS_LOG_FUNCTION_NOARGS();
 
  161   NS_LOG_FUNCTION_NOARGS();
 
  163   uint32_t seq = std::numeric_limits<uint32_t>::max(); 
 
  165   while (m_retxSeqs.size()) {
 
  166     seq = *m_retxSeqs.begin();
 
  167     m_retxSeqs.erase(m_retxSeqs.begin());
 
  171   if (seq == std::numeric_limits<uint32_t>::max()) {
 
  172     if (
m_seqMax != std::numeric_limits<uint32_t>::max()) {
 
  182   shared_ptr<Name> nameWithSequence = make_shared<Name>(
m_interestName);
 
  183   nameWithSequence->appendSequenceNumber(seq);
 
  187   shared_ptr<Interest> interest = make_shared<Interest>();
 
  188   interest->setNonce(
m_rand.GetValue());
 
  189   interest->setName(*nameWithSequence);
 
  191   interest->setInterestLifetime(interestLifeTime);
 
  194   NS_LOG_INFO(
"> Interest for " << seq);
 
  199   m_face->onReceiveInterest(*interest);
 
  216   NS_LOG_FUNCTION(
this << data);
 
  221   uint32_t seq = data->getName().at(-1).toSequenceNumber();
 
  222   NS_LOG_INFO(
"< DATA for " << seq);
 
  226   if (ns3PacketTag != 
nullptr) {
 
  228     if (ns3PacketTag->getPacket()->PeekPacketTag(hopCountTag)) {
 
  229       hopCount = hopCountTag.
Get();
 
  230       NS_LOG_DEBUG(
"Hop count: " << hopCount);
 
  234   SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find(seq);
 
  235   if (entry != m_seqLastDelay.end()) {
 
  236     m_lastRetransmittedInterestDataDelay(
this, seq, Simulator::Now() - entry->time, hopCount);
 
  239   entry = m_seqFullDelay.find(seq);
 
  240   if (entry != m_seqFullDelay.end()) {
 
  241     m_firstInterestDataDelay(
this, seq, Simulator::Now() - entry->time, m_seqRetxCounts[seq], hopCount);
 
  244   m_seqRetxCounts.erase(seq);
 
  245   m_seqFullDelay.erase(seq);
 
  246   m_seqLastDelay.erase(seq);
 
  248   m_seqTimeouts.erase(seq);
 
  249   m_retxSeqs.erase(seq);
 
  251   m_rtt->AckSeq(SequenceNumber32(seq));
 
  257   NS_LOG_FUNCTION(sequenceNumber);
 
  261   m_rtt->IncreaseMultiplier(); 
 
  262   m_rtt->SentSeq(SequenceNumber32(sequenceNumber),
 
  264   m_retxSeqs.insert(sequenceNumber);
 
  271   NS_LOG_DEBUG(
"Trying to add " << sequenceNumber << 
" with " << Simulator::Now() << 
". already " 
  272                                 << m_seqTimeouts.size() << 
" items");
 
  274   m_seqTimeouts.insert(SeqTimeout(sequenceNumber, Simulator::Now()));
 
  275   m_seqFullDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now()));
 
  277   m_seqLastDelay.erase(sequenceNumber);
 
  278   m_seqLastDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now()));
 
  280   m_seqRetxCounts[sequenceNumber]++;
 
  282   m_rtt->SentSeq(SequenceNumber32(sequenceNumber), 1);
 
Time m_interestLifeTime
LifeTime for interest packet. 
 
virtual void OnTimeout(uint32_t sequenceNumber)
Timeout event. 
 
uint32_t m_seqMax
maximum number of sequence number 
 
Packet tag that is used to track hop count for Interest-Data pairs. 
 
virtual void StopApplication()
Called at time specified by Stop. 
 
void SetRetxTimer(Time retxTimer)
Modifies the frequency of checking the retransmission timeouts. 
 
ndn Consumer
Copyright (c) 2011-2015 Regents of the University of California. 
 
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
 
uint32_t m_seq
currently requested sequence number 
 
virtual void StartApplication()
Called at time specified by Start. 
 
Time m_retxTimer
Currently estimated retransmission timer. 
 
Ptr< RttEstimator > m_rtt
RTT estimator. 
 
Name m_interestName
NDN Name of the Interest (use Name) 
 
void CheckRetxTimeout()
Checks if the packet need to be retransmitted becuase of retransmission timer expiration. 
 
virtual void OnData(shared_ptr< const Data > contentObject)
Method that will be called every time new Data arrives. 
 
void SendPacket()
Actually send packet. 
 
virtual void ScheduleNextPacket()=0
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
 
UniformVariable m_rand
nonce generator 
 
uint32_t Get() const 
Get value of hop count. 
 
TracedCallback< shared_ptr< const Interest >, Ptr< App >, shared_ptr< Face > > m_transmittedInterests
App-level trace of transmitted Interests. 
 
shared_ptr< Face > m_face
and StopApplication) 
 
Base class that all NDN applications should be derived from. 
 
Consumer()
Default constructor Sets up randomizer function and packet sequence number. 
 
Ptr< const AttributeChecker > MakeNameChecker(void)
 
virtual void StopApplication()
Called at time specified by Stop. 
 
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) ...
 
Ptr< const AttributeAccessor > MakeNameAccessor(T1 a1)
 
EventId m_retxEvent
Event to check whether or not retransmission should be performed. 
 
bool m_active
Flag to indicate that application is active (set by StartApplication. 
 
static TypeId GetTypeId()
 
Time GetRetxTimer() const 
Returns the frequency of checking the retransmission timeouts. 
 
virtual void OnData(shared_ptr< const Data > data)
Method that will be called every time new Data arrives. 
 
virtual void StartApplication()
Called at time specified by Start.