Correcting bug with NACK processing
diff --git a/examples/ccnx-grid.cc b/examples/ccnx-grid.cc
index d0c2882..9891a91 100644
--- a/examples/ccnx-grid.cc
+++ b/examples/ccnx-grid.cc
@@ -89,7 +89,7 @@
   // Install CCNx stack
   NS_LOG_INFO ("Installing CCNx stack");
   CcnxStackHelper ccnxHelper;
-  // ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy");
+  //ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy");
   ccnxHelper.SetForwardingStrategy ("ns3::CcnxFloodingStrategy");
   ccnxHelper.EnableLimits (true, Seconds(0.1));
   ccnxHelper.InstallAll ();
diff --git a/model/ccnx-face.cc b/model/ccnx-face.cc
index 3c092e9..92bdfee 100644
--- a/model/ccnx-face.cc
+++ b/model/ccnx-face.cc
@@ -82,10 +82,10 @@
   
   if (m_bucketMax > 0)
     {
-      //NS_LOG_ERROR ("Limits enabled: " << m_bucketMax << ", current: " << m_bucket);
+      //NS_LOG_DEBUG ("Limits enabled: " << m_bucketMax << ", current: " << m_bucket);
       if (m_bucket+1.0 > m_bucketMax)
         {
-          //NS_LOG_ERROR ("Returning false");
+          //NS_LOG_DEBUG ("Returning false");
           return false;
         }
       
@@ -101,7 +101,7 @@
   const double leak = m_bucketLeak * interval.ToDouble (Time::S);
   m_bucket = std::max (0.0, m_bucket - leak);
 
-  NS_LOG_ERROR ("max: " << m_bucketMax << ", Current bucket: " << m_bucket << ", leak size: " << leak << ", interval: " << interval << ", " << m_bucketLeak);
+  // NS_LOG_DEBUG ("max: " << m_bucketMax << ", Current bucket: " << m_bucket << ", leak size: " << leak << ", interval: " << interval << ", " << m_bucketLeak);
 }
 
 void
diff --git a/model/ccnx-flooding-strategy.cc b/model/ccnx-flooding-strategy.cc
index ee7df67..94c6512 100644
--- a/model/ccnx-flooding-strategy.cc
+++ b/model/ccnx-flooding-strategy.cc
@@ -21,6 +21,7 @@
 #include "ccnx-flooding-strategy.h"
 #include "ns3/assert.h"
 #include "ns3/log.h"
+#include "ns3/simulator.h"
 #include "ccnx-interest-header.h"
 
 #include <boost/ref.hpp>
@@ -75,12 +76,19 @@
 
       bool faceAvailable = metricFace.m_face->IsBelowLimit ();
       if (!faceAvailable) // huh...
-        continue;
+        {
+          // NS_LOG_ERROR (boost::cref (*metricFace.m_face) << " limit !!!");
+          continue;
+        }
 
       m_pit->modify (m_pit->iterator_to (pitEntry),
                      ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
 
-      // NS_LOG_DEBUG ("new outgoing entry for " << boost::cref (*metricFace.m_face));
+      // if (Simulator::GetContext ()==2)
+      //   {
+      //     NS_LOG_ERROR ("new outgoing entry for " << boost::cref (*metricFace.m_face));
+      //     NS_LOG_ERROR ("size: " << pitEntry.m_outgoing.size ());
+      //   }
 
       metricFace.m_face->Send (packet->Copy ());
       
diff --git a/model/ccnx-l3-protocol.cc b/model/ccnx-l3-protocol.cc
index 37264d5..596b36a 100644
--- a/model/ccnx-l3-protocol.cc
+++ b/model/ccnx-l3-protocol.cc
@@ -296,11 +296,11 @@
   tuple<const CcnxPitEntry&,bool,bool> ret = m_pit->Lookup (*header);
   CcnxPitEntry const& pitEntry = ret.get<0> ();
   bool isNew = ret.get<1> ();
-  //bool isDuplicated = ret.get<2> ();
+  bool isDuplicated = ret.get<2> ();
 
   // NS_ASSERT_MSG (isDuplicated,
   //                "NACK should be a duplicated interest");
-  if (isNew /*|| !isDuplicated*/) // potential flow
+  if (isNew || !isDuplicated) // potential flow
     {
       // somebody is doing something bad
       NS_ASSERT (false); // temporary assert
@@ -310,15 +310,18 @@
   // CcnxPitEntryIncomingFaceContainer::type::iterator inFace = pitEntry.m_incoming.find (incomingFace);
   CcnxPitEntryOutgoingFaceContainer::type::iterator outFace = pitEntry.m_outgoing.find (incomingFace);
 
-  if (outFace != pitEntry.m_outgoing.end ())
+  if (outFace == pitEntry.m_outgoing.end ())
     {
-      // NS_ASSERT_MSG (outFace != pitEntry.m_outgoing.end (),
-      //                "Outgoing entry should exist");
+      NS_ASSERT_MSG (false,
+                     "Node " << GetObject<Node> ()->GetId () << ", outgoing entry should exist for face " << boost::cref(*incomingFace) << "\n" <<
+                     "size: " << pitEntry.m_outgoing.size ());
       
       return;
     }
 
-  outFace->m_face->LeakBucketByOnePacket ();
+  NS_ASSERT_MSG (incomingFace == outFace->m_face, "Something is wrong");
+  incomingFace->LeakBucketByOnePacket ();
+
   m_pit->modify (m_pit->iterator_to (pitEntry),
                  ll::bind (&CcnxPitEntry::SetWaitingInVain, ll::_1, outFace));
   
@@ -337,11 +340,10 @@
                 ll::bind (&CcnxFibEntry::UpdateStatus,
                           ll::_1, incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW));
 
-  if (!pitEntry.AreAllOutgoingInVain ())
+  if (!pitEntry.AreAllOutgoingInVain ()) // not all ougtoing are in vain
     {
       // suppress
       // Don't do anything, we are still expecting data from some other face
-
       return;
     }
   
@@ -357,7 +359,7 @@
   // 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.AreAllOutgoingInVain ())
+  if (!propagated)
     GiveUpInterest (pitEntry, header);
 }
 
@@ -473,7 +475,7 @@
   // 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.AreAllOutgoingInVain ())
+  if (!propagated)
     GiveUpInterest (pitEntry, header);
 }