Fixing bugs related to NACKs implementation
diff --git a/apps/ndn-consumer-window.cc b/apps/ndn-consumer-window.cc
index 4ae30dd..165326b 100644
--- a/apps/ndn-consumer-window.cc
+++ b/apps/ndn-consumer-window.cc
@@ -32,9 +32,9 @@
namespace ns3 {
namespace ndn {
-
+
NS_OBJECT_ENSURE_REGISTERED (ConsumerWindow);
-
+
TypeId
ConsumerWindow::GetTypeId (void)
{
@@ -126,14 +126,19 @@
void
ConsumerWindow::ScheduleNextPacket ()
{
- if (m_window == static_cast<uint32_t> (0) || m_inFlight >= m_window)
+ if (m_window == static_cast<uint32_t> (0))
{
if (!m_sendEvent.IsRunning ())
{
- m_sendEvent = Simulator::Schedule (Seconds (m_rtt->RetransmitTimeout ().ToDouble (Time::S) * 0.1),
+ m_sendEvent = Simulator::Schedule (Seconds (m_rtt->RetransmitTimeout ().ToDouble (Time::S)),
&Consumer::SendPacket, this);
+ m_rtt->IncreaseMultiplier ();
}
}
+ else if (m_inFlight >= m_window)
+ {
+ // simply do nothing
+ }
else
{
if (m_sendEvent.IsRunning ())
@@ -141,7 +146,7 @@
Simulator::Remove (m_sendEvent);
}
- NS_LOG_DEBUG ("Window: " << m_window << ", InFlight: " << m_inFlight);
+ // NS_LOG_DEBUG ("Window: " << m_window << ", InFlight: " << m_inFlight);
m_inFlight++;
m_sendEvent = Simulator::ScheduleNow (&Consumer::SendPacket, this);
}
@@ -169,22 +174,25 @@
ConsumerWindow::OnNack (const Ptr<const InterestHeader> &interest, Ptr<Packet> payload)
{
Consumer::OnNack (interest, payload);
-
+
if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
if (m_window > static_cast<uint32_t> (0))
{
// m_window = 0.5 * m_window;//m_window - 1;
- m_window = m_window - 1;
+ m_window = std::max<uint32_t> (0, m_window - 1);
}
-
+
// NS_LOG_DEBUG ("Window: " << m_window);
}
void
ConsumerWindow::OnTimeout (uint32_t sequenceNumber)
{
+ // NS_FATAL_ERROR ("No timeouts should happen: " << sequenceNumber);
if (m_inFlight > static_cast<uint32_t> (0)) m_inFlight--;
+ // m_window = std::max<uint32_t> (0, m_window - 1);
+ m_window = 0;
Consumer::OnTimeout (sequenceNumber);
}
diff --git a/apps/ndn-consumer.cc b/apps/ndn-consumer.cc
index 60ef55b..8c2619e 100644
--- a/apps/ndn-consumer.cc
+++ b/apps/ndn-consumer.cc
@@ -47,9 +47,9 @@
namespace ns3 {
namespace ndn {
-
+
NS_OBJECT_ENSURE_REGISTERED (Consumer);
-
+
TypeId
Consumer::GetTypeId (void)
{
@@ -85,7 +85,7 @@
return tid;
}
-
+
Consumer::Consumer ()
: m_rand (0, std::numeric_limits<uint32_t>::max ())
, m_seq (0)
@@ -108,7 +108,7 @@
// schedule even with new timeout
m_retxEvent = Simulator::Schedule (m_retxTimer,
- &Consumer::CheckRetxTimeout, this);
+ &Consumer::CheckRetxTimeout, this);
}
Time
@@ -123,6 +123,7 @@
Time now = Simulator::Now ();
Time rto = m_rtt->RetransmitTimeout ();
+ NS_LOG_DEBUG ("Current RTO: " << rto.ToDouble (Time::S) << "s");
while (!m_seqTimeouts.empty ())
{
@@ -139,11 +140,11 @@
}
m_retxEvent = Simulator::Schedule (m_retxTimer,
- &Consumer::CheckRetxTimeout, this);
+ &Consumer::CheckRetxTimeout, this);
}
// Application Methods
-void
+void
Consumer::StartApplication () // Called at time specified by Start
{
NS_LOG_FUNCTION_NOARGS ();
@@ -153,8 +154,8 @@
ScheduleNextPacket ();
}
-
-void
+
+void
Consumer::StopApplication () // Called at time specified by Stop
{
NS_LOG_FUNCTION_NOARGS ();
@@ -165,7 +166,7 @@
// cleanup base stuff
App::StopApplication ();
}
-
+
void
Consumer::SendPacket ()
{
@@ -191,10 +192,10 @@
return; // we are totally done
}
}
-
+
seq = m_seq++;
}
-
+
//
Ptr<NameComponents> nameWithSequence = Create<NameComponents> (m_interestName);
(*nameWithSequence) (seq);
@@ -203,7 +204,7 @@
InterestHeader interestHeader;
interestHeader.SetNonce (m_rand.GetValue ());
interestHeader.SetName (nameWithSequence);
-
+
// NS_LOG_INFO ("Requesting Interest: \n" << interestHeader);
NS_LOG_INFO ("> Interest for " << seq);
@@ -211,8 +212,8 @@
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");
-
+ 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 ()));
@@ -220,14 +221,14 @@
m_seqLastDelay.insert (SeqTimeout (seq, Simulator::Now ()));
m_seqRetxCounts[seq] ++;
-
+
m_transmittedInterests (&interestHeader, this, m_face);
m_rtt->SentSeq (SequenceNumber32 (seq), 1);
FwHopCountTag hopCountTag;
packet->AddPacketTag (hopCountTag);
-
+
m_protocolHandler (packet);
ScheduleNextPacket ();
@@ -245,11 +246,11 @@
if (!m_active) return;
App::OnContentObject (contentObject, payload); // tracing inside
-
+
NS_LOG_FUNCTION (this << contentObject << payload);
// NS_LOG_INFO ("Received content object: " << boost::cref(*contentObject));
-
+
uint32_t seq = boost::lexical_cast<uint32_t> (contentObject->GetName ().GetComponents ().back ());
NS_LOG_INFO ("< DATA for " << seq);
@@ -259,7 +260,7 @@
{
hopCount = hopCountTag.Get ();
}
-
+
SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find (seq);
if (entry != m_seqLastDelay.end ())
{
@@ -272,10 +273,10 @@
m_firstInterestDataDelay (this, seq, Simulator::Now () - entry->time, m_seqRetxCounts[seq], hopCount);
}
- m_seqRetxCounts.erase (seq);
+ m_seqRetxCounts.erase (seq);
m_seqFullDelay.erase (seq);
m_seqLastDelay.erase (seq);
-
+
m_seqTimeouts.erase (seq);
m_retxSeqs.erase (seq);
@@ -286,9 +287,9 @@
Consumer::OnNack (const Ptr<const InterestHeader> &interest, Ptr<Packet> origPacket)
{
if (!m_active) return;
-
+
App::OnNack (interest, origPacket); // tracing inside
-
+
// NS_LOG_DEBUG ("Nack type: " << interest->GetNack ());
// NS_LOG_FUNCTION (interest->GetName ());
@@ -296,13 +297,15 @@
// NS_LOG_INFO ("Received NACK: " << boost::cref(*interest));
uint32_t seq = boost::lexical_cast<uint32_t> (interest->GetName ().GetComponents ().back ());
NS_LOG_INFO ("< NACK for " << seq);
- // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << "NACK for " << seq << "\n";
+ // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << "NACK for " << seq << "\n";
// put in the queue of interests to be retransmitted
// NS_LOG_INFO ("Before: " << m_retxSeqs.size ());
m_retxSeqs.insert (seq);
// NS_LOG_INFO ("After: " << m_retxSeqs.size ());
+ m_seqTimeouts.erase (seq);
+
m_rtt->IncreaseMultiplier (); // Double the next RTO ??
ScheduleNextPacket ();
}
@@ -316,7 +319,7 @@
m_rtt->IncreaseMultiplier (); // Double the next RTO
m_rtt->SentSeq (SequenceNumber32 (sequenceNumber), 1); // make sure to disable RTT calculation for this sample
m_retxSeqs.insert (sequenceNumber);
- ScheduleNextPacket ();
+ ScheduleNextPacket ();
}
} // namespace ndn
diff --git a/apps/ndn-consumer.h b/apps/ndn-consumer.h
index 5d09672..970da4c 100644
--- a/apps/ndn-consumer.h
+++ b/apps/ndn-consumer.h
@@ -27,8 +27,8 @@
#include "ns3/ndn-name-components.h"
#include "ns3/nstime.h"
#include "ns3/data-rate.h"
-#include "../../internet/model/rtt-estimator.h"
//#include "ns3/internet-module.h"
+#include "ns3/rtt-estimator.h"
#include <set>
#include <map>
@@ -47,11 +47,11 @@
*/
class Consumer: public App
{
-public:
+public:
static TypeId GetTypeId ();
-
+
/**
- * \brief Default constructor
+ * \brief Default constructor
* Sets up randomizer function and packet sequence number
*/
Consumer ();
@@ -80,7 +80,7 @@
*/
void
SendPacket ();
-
+
protected:
// from App
virtual void
@@ -88,19 +88,19 @@
virtual void
StopApplication ();
-
+
/**
* \brief Constructs the Interest packet and sends it using a callback to the underlying NDN protocol
*/
virtual void
ScheduleNextPacket () = 0;
-
+
/**
* \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
*/
void
CheckRetxTimeout ();
-
+
/**
* \brief Modifies the frequency of checking the retransmission timeouts
* \param retxTimer Timeout defining how frequent retransmission timeouts should be checked
@@ -114,7 +114,7 @@
*/
Time
GetRetxTimer () const;
-
+
protected:
UniformVariable m_rand; ///< @brief nonce generator
@@ -125,37 +125,37 @@
EventId m_retxEvent; ///< @brief Event to check whether or not retransmission should be performed
Ptr<RttEstimator> m_rtt; ///< @brief RTT estimator
-
+
Time m_offTime; ///< \brief Time interval between packets
NameComponents m_interestName; ///< \brief NDN Name of the Interest (use NameComponents)
Time m_interestLifeTime; ///< \brief LifeTime for interest packet
-/// @cond include_hidden
+/// @cond include_hidden
/**
* \struct This struct contains sequence numbers of packets to be retransmitted
*/
struct RetxSeqsContainer :
public std::set<uint32_t> { };
-
+
RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
/**
* \struct This struct contains a pair of packet sequence number and its timeout
- */
+ */
struct SeqTimeout
{
SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
-
+
uint32_t seq;
Time time;
};
/// @endcond
-
+
/// @cond include_hidden
class i_seq { };
- class i_timestamp { };
+ class i_timestamp { };
/// @endcond
-
+
/// @cond include_hidden
/**
* \struct This struct contains a multi-index for the set of SeqTimeout structs
@@ -180,13 +180,13 @@
SeqTimeoutsContainer m_seqLastDelay;
SeqTimeoutsContainer m_seqFullDelay;
std::map<uint32_t, uint32_t> m_seqRetxCounts;
-
+
TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */,
Time /* delay */, int32_t /*hop count*/> m_lastRetransmittedInterestDataDelay;
TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */,
Time /* delay */, uint32_t /*retx count*/,
int32_t /*hop count*/> m_firstInterestDataDelay;
-
+
/// @endcond
};
diff --git a/model/fw/nacks.cc b/model/fw/nacks.cc
index 4e7894a..8c24157 100644
--- a/model/fw/nacks.cc
+++ b/model/fw/nacks.cc
@@ -56,14 +56,14 @@
static TypeId tid = TypeId ("ns3::ndn::fw::Nacks")
.SetGroupName ("Ndn")
.SetParent<ForwardingStrategy> ()
-
+
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
.AddTraceSource ("OutNacks", "OutNacks", MakeTraceSourceAccessor (&Nacks::m_outNacks))
.AddTraceSource ("InNacks", "InNacks", MakeTraceSourceAccessor (&Nacks::m_inNacks))
.AddTraceSource ("DropNacks", "DropNacks", MakeTraceSourceAccessor (&Nacks::m_dropNacks))
-
+
.AddAttribute ("EnableNACKs", "Enabling support of NACKs",
BooleanValue (false),
MakeBooleanAccessor (&Nacks::m_nacksEnabled),
@@ -80,7 +80,7 @@
if (header->GetNack () > 0)
OnNack (inFace, header, origPacket/*original packet*/);
else
- super::OnInterest (inFace, header, origPacket/*original packet*/);
+ super::OnInterest (inFace, header, origPacket/*original packet*/);
}
void
@@ -88,7 +88,7 @@
Ptr<const InterestHeader> header,
Ptr<const Packet> origPacket)
{
- // NS_LOG_FUNCTION (inFace << header << origPacket);
+ // NS_LOG_FUNCTION (inFace << header->GetName ());
m_inNacks (header, inFace);
Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header);
@@ -98,11 +98,6 @@
m_dropNacks (header, inFace);
return;
}
-
- // This was done in error. Never, never do anything, except normal leakage. This way we ensure that we will not have losses,
- // at least when there is only one client
- //
- // inFace->LeakBucketByOnePacket ();
DidReceiveValidNack (inFace, header->GetNack (), header, origPacket, pitEntry);
}
@@ -148,8 +143,10 @@
m_outNacks (nackHeader, incoming.m_face);
}
+
+ pitEntry->ClearOutgoing (); // to force erasure of the record
}
-
+
super::DidExhaustForwardingOptions (inFace, header, origPacket, pitEntry);
}
@@ -160,6 +157,8 @@
Ptr<const Packet> origPacket,
Ptr<pit::Entry> pitEntry)
{
+ NS_LOG_DEBUG ("nackCode: " << nackCode << " for [" << header->GetName () << "]");
+
// If NACK is NACK_GIVEUP_PIT, then neighbor gave up trying to and removed it's PIT entry.
// So, if we had an incoming entry to this neighbor, then we can remove it now
if (nackCode == InterestHeader::NACK_GIVEUP_PIT)
@@ -181,12 +180,12 @@
m_dropNacks (header, inFace);
return;
}
-
+
Ptr<Packet> nonNackInterest = Create<Packet> ();
Ptr<InterestHeader> nonNackHeader = Create<InterestHeader> (*header);
nonNackHeader->SetNack (InterestHeader::NORMAL_INTEREST);
nonNackInterest->AddHeader (*nonNackHeader);
-
+
bool propagated = DoPropagateInterest (inFace, nonNackHeader, nonNackInterest, pitEntry);
if (!propagated)
{
diff --git a/model/fw/ndn-forwarding-strategy.cc b/model/fw/ndn-forwarding-strategy.cc
index 0e773f9..33f2942 100644
--- a/model/fw/ndn-forwarding-strategy.cc
+++ b/model/fw/ndn-forwarding-strategy.cc
@@ -71,7 +71,7 @@
.AddTraceSource ("OutInterests", "OutInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_outInterests))
.AddTraceSource ("InInterests", "InInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_inInterests))
.AddTraceSource ("DropInterests", "DropInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropInterests))
-
+
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
@@ -161,7 +161,7 @@
isDuplicated = false;
}
- if (isDuplicated)
+ if (isDuplicated)
{
DidReceiveDuplicateInterest (inFace, header, origPacket, pitEntry);
return;
@@ -221,7 +221,7 @@
{
NS_LOG_FUNCTION (inFace << header->GetName () << payload << origPacket);
m_inData (header, payload, inFace);
-
+
// Lookup PIT entry
Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header);
if (pitEntry == 0)
@@ -236,7 +236,7 @@
{
Ptr<Packet> payloadCopy = payload->Copy ();
payloadCopy->RemovePacketTag (hopCountTag);
-
+
// Add or update entry in the content store
m_contentStore->Add (header, payloadCopy);
}
@@ -314,7 +314,7 @@
Ptr<pit::Entry> pitEntry)
{
NS_LOG_FUNCTION (this << boost::cref (*inFace));
- if (pitEntry->GetOutgoing ().size () == 0)
+ if (pitEntry->AreAllOutgoingInVain ())
{
m_dropInterests (header, inFace);
@@ -323,12 +323,12 @@
// Remove also outgoing
pitEntry->ClearOutgoing ();
-
+
// Set pruning timout on PIT entry (instead of deleting the record)
m_pit->MarkErased (pitEntry);
}
}
-
+
bool
@@ -340,7 +340,7 @@
pit::Entry::in_iterator existingInFace = pitEntry->GetIncoming ().find (inFace);
bool isRetransmitted = false;
-
+
if (existingInFace != pitEntry->GetIncoming ().end ())
{
// this is almost definitely a retransmission. But should we trust the user on that?
@@ -368,7 +368,7 @@
{
m_outData (header, payload, inFace == 0, incoming.m_face);
DidSendOutData (inFace, incoming.m_face, header, payload, origPacket, pitEntry);
-
+
NS_LOG_DEBUG ("Satisfy " << *incoming.m_face);
}
else
@@ -376,7 +376,7 @@
m_dropData (header, payload, incoming.m_face);
NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face);
}
-
+
// successfull forwarded data trace
}
@@ -385,7 +385,7 @@
// Remove all outgoing faces
pitEntry->ClearOutgoing ();
-
+
// Set pruning timout on PIT entry (instead of deleting the record)
m_pit->MarkErased (pitEntry);
}
@@ -405,7 +405,7 @@
{
// Drop data packet if PIT entry is not found
// (unsolicited data packets should not "poison" content store)
-
+
//drop dulicated or not requested data packet
m_dropData (header, payload, inFace);
}
@@ -416,12 +416,12 @@
Ptr<pit::Entry> pitEntry)
{
pit::Entry::out_iterator out = pitEntry->GetOutgoing ().find (inFace);
-
+
// If we have sent interest for this data via this face, then update stats.
if (out != pitEntry->GetOutgoing ().end ())
{
pitEntry->GetFibEntry ()->UpdateFaceRtt (inFace, Simulator::Now () - out->m_sendTime);
- }
+ }
}
bool
@@ -433,9 +433,9 @@
bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0;
if (isNew) return false; // never suppress new interests
-
+
bool isRetransmitted = m_detectRetransmissions && // a small guard
- DetectRetransmittedInterest (inFace, header, origPacket, pitEntry);
+ DetectRetransmittedInterest (inFace, header, origPacket, pitEntry);
if (pitEntry->GetOutgoing ().find (inFace) != pitEntry->GetOutgoing ().end ())
{
@@ -447,7 +447,7 @@
// Mark interface YELLOW, but keep a small hope that data will come eventually.
// ?? not sure if we need to do that ?? ...
-
+
// pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_YELLOW);
}
else
@@ -466,12 +466,12 @@
Ptr<pit::Entry> pitEntry)
{
bool isRetransmitted = m_detectRetransmissions && // a small guard
- DetectRetransmittedInterest (inFace, header, origPacket, pitEntry);
-
+ DetectRetransmittedInterest (inFace, header, origPacket, pitEntry);
+
pitEntry->AddIncoming (inFace/*, header->GetInterestLifetime ()*/);
/// @todo Make lifetime per incoming interface
pitEntry->UpdateLifetime (header->GetInterestLifetime ());
-
+
bool propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry);
if (!propagated && isRetransmitted) //give another chance if retransmitted
@@ -483,10 +483,17 @@
propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry);
}
+ // if (!propagated)
+ // {
+ // NS_LOG_DEBUG ("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+ // NS_LOG_DEBUG ("+++ Not propagated ["<< header->GetName () <<"], but number of outgoing faces: " << pitEntry->GetOutgoing ().size ());
+ // NS_LOG_DEBUG ("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+ // }
+
// ForwardingStrategy will try its best to forward packet to at least one interface.
// If no interests was propagated, then there is not other option for forwarding or
- // ForwardingStrategy failed to find it.
- if (!propagated && pitEntry->GetOutgoing ().size () == 0)
+ // ForwardingStrategy failed to find it.
+ if (!propagated && pitEntry->AreAllOutgoingInVain ())
{
DidExhaustForwardingOptions (inFace, header, origPacket, pitEntry);
}
@@ -499,12 +506,12 @@
Ptr<const Packet> origPacket,
Ptr<pit::Entry> pitEntry)
{
- if (outFace == inFace)
+ if (outFace == inFace)
{
- NS_LOG_DEBUG ("Same as incoming");
+ // NS_LOG_DEBUG ("Same as incoming");
return false; // same face as incoming, don't forward
}
-
+
pit::Entry::out_iterator outgoing =
pitEntry->GetOutgoing ().find (outFace);
@@ -514,7 +521,7 @@
return false; // suppress
else if (outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
{
- NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ());
+ // NS_LOG_DEBUG ("Already forwarded before during this retransmission cycle (" <<outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount () << ")");
return false; // already forwarded before during this retransmission cycle
}
}
@@ -534,7 +541,7 @@
{
return false;
}
-
+
pitEntry->AddOutgoing (outFace);
//transmission