Skip to content

Commit

Permalink
apps: Solving a serious bug named-data-ndnSIM#33 in ndn::ConsumerWindow
Browse files Browse the repository at this point in the history
In certain cases, the number of in-flight packets was maintained in a
wrong way, creating inconsistencies and incorrect decision on when to
send out a new Interests.  That is, the number of in-flight
packets could be non-zero, while there were no outstanding packets at all.

Thanks to Cheng Yi for the bug discovery
  • Loading branch information
cawka committed Apr 12, 2013
1 parent b5e77d8 commit 79b2fb3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
10 changes: 8 additions & 2 deletions apps/ndn-consumer-window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ ConsumerWindow::ScheduleNextPacket ()
Simulator::Remove (m_sendEvent);
}

// NS_LOG_DEBUG ("Window: " << m_window << ", InFlight: " << m_inFlight);
m_inFlight++;
m_sendEvent = Simulator::ScheduleNow (&Consumer::SendPacket, this);
}
}
Expand Down Expand Up @@ -208,5 +206,13 @@ ConsumerWindow::OnTimeout (uint32_t sequenceNumber)
Consumer::OnTimeout (sequenceNumber);
}

void
ConsumerWindow::WillSendOutInterest (uint32_t sequenceNumber)
{
m_inFlight ++;
Consumer::WillSendOutInterest (sequenceNumber);
}


} // namespace ndn
} // namespace ns3
3 changes: 3 additions & 0 deletions apps/ndn-consumer-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class ConsumerWindow: public Consumer
virtual void
OnTimeout (uint32_t sequenceNumber);

virtual void
WillSendOutInterest (uint32_t sequenceNumber);

protected:
/**
* \brief Constructs the Interest packet and sends it using a callback to the underlying NDN protocol
Expand Down
32 changes: 19 additions & 13 deletions apps/ndn-consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,12 @@ Consumer::SendPacket ()
packet->AddHeader (interestHeader);
NS_LOG_DEBUG ("Interest packet size: " << packet->GetSize ());

NS_LOG_DEBUG ("Trying to add " << seq << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items");

m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ()));
m_seqFullDelay.insert (SeqTimeout (seq, Simulator::Now ()));

m_seqLastDelay.erase (seq);
m_seqLastDelay.insert (SeqTimeout (seq, Simulator::Now ()));

m_seqRetxCounts[seq] ++;

m_transmittedInterests (&interestHeader, this, m_face);

m_rtt->SentSeq (SequenceNumber32 (seq), 1);
WillSendOutInterest (seq);

FwHopCountTag hopCountTag;
packet->AddPacketTag (hopCountTag);

m_transmittedInterests (&interestHeader, this, m_face);
m_protocolHandler (packet);

ScheduleNextPacket ();
Expand Down Expand Up @@ -324,5 +313,22 @@ Consumer::OnTimeout (uint32_t sequenceNumber)
ScheduleNextPacket ();
}

void
Consumer::WillSendOutInterest (uint32_t sequenceNumber)
{
NS_LOG_DEBUG ("Trying to add " << sequenceNumber << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items");

m_seqTimeouts.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
m_seqFullDelay.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));

m_seqLastDelay.erase (sequenceNumber);
m_seqLastDelay.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));

m_seqRetxCounts[sequenceNumber] ++;

m_rtt->SentSeq (SequenceNumber32 (sequenceNumber), 1);
}


} // namespace ndn
} // namespace ns3
10 changes: 10 additions & 0 deletions apps/ndn-consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ class Consumer: public App
void
SendPacket ();

/**
* @brief An event that is fired just before an Interest packet is actually send out (send is inevitable)
*
* The reason for "before" even is that in certain cases (when it is possible to satisfy from the local cache),
* the send call will immediately return data, and if "after" even was used, this after would be called after
* all processing of incoming data, potentially producing unexpected results.
*/
virtual void
WillSendOutInterest (uint32_t sequenceNumber);

protected:
// from App
virtual void
Expand Down

0 comments on commit 79b2fb3

Please sign in to comment.