model+tracers: Implementing ability to trace satisfied/timed out interests

Implementing satsified/timed out interest tracing in L3AggregateTracer and L3RateTracer (only numbers)
diff --git a/model/fw/ndn-forwarding-strategy.cc b/model/fw/ndn-forwarding-strategy.cc
index 5b51993..6bfee78 100644
--- a/model/fw/ndn-forwarding-strategy.cc
+++ b/model/fw/ndn-forwarding-strategy.cc
@@ -79,6 +79,12 @@
     .AddTraceSource ("InData",   "InData",   MakeTraceSourceAccessor (&ForwardingStrategy::m_inData))
     .AddTraceSource ("DropData", "DropData", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropData))
 
+    ////////////////////////////////////////////////////////////////////
+    ////////////////////////////////////////////////////////////////////
+
+    .AddTraceSource ("SatisfiedInterests",  "SatisfiedInterests",  MakeTraceSourceAccessor (&ForwardingStrategy::m_satisfiedInterests))
+    .AddTraceSource ("TimedOutInterests",   "TimedOutInterests",   MakeTraceSourceAccessor (&ForwardingStrategy::m_timedOutInterests))
+    
     .AddAttribute ("CacheUnsolicitedData", "Cache overheard data that have not been requested",
                    BooleanValue (false),
                    MakeBooleanAccessor (&ForwardingStrategy::m_cacheUnsolicitedData),
@@ -441,6 +447,8 @@
     {
       pitEntry->GetFibEntry ()->UpdateFaceRtt (inFace, Simulator::Now () - out->m_sendTime);
     }
+
+  m_satisfiedInterests (pitEntry);
 }
 
 bool
@@ -600,7 +608,7 @@
 void
 ForwardingStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
 {
-  // do nothing for now. may be need to do some logging
+  m_timedOutInterests (pitEntry);
 }
 
 void
diff --git a/model/fw/ndn-forwarding-strategy.h b/model/fw/ndn-forwarding-strategy.h
index b87b07d..a3fe5b5 100644
--- a/model/fw/ndn-forwarding-strategy.h
+++ b/model/fw/ndn-forwarding-strategy.h
@@ -501,6 +501,13 @@
 
   TracedCallback<Ptr<const ContentObject>, Ptr<const Packet>,
                   Ptr<const Face> > m_dropData;  ///< @brief trace of dropped Data
+
+  ////////////////////////////////////////////////////////////////////
+  ////////////////////////////////////////////////////////////////////
+  ////////////////////////////////////////////////////////////////////
+
+  TracedCallback< Ptr<const pit::Entry> > m_satisfiedInterests;
+  TracedCallback< Ptr<const pit::Entry> > m_timedOutInterests;
 };
 
 } // namespace ndn
diff --git a/utils/tracers/ndn-l3-aggregate-tracer.cc b/utils/tracers/ndn-l3-aggregate-tracer.cc
index 1cc79a5..52eb9f8 100644
--- a/utils/tracers/ndn-l3-aggregate-tracer.cc
+++ b/utils/tracers/ndn-l3-aggregate-tracer.cc
@@ -28,6 +28,8 @@
 #include "ns3/ndn-face.h"
 #include "ns3/ndn-interest.h"
 #include "ns3/ndn-content-object.h"
+#include "ns3/ndn-pit-entry.h"
+
 #include "ns3/simulator.h"
 #include "ns3/node-list.h"
 #include "ns3/log.h"
@@ -44,7 +46,7 @@
 {
   using namespace boost;
   using namespace std;
-  
+
   std::list<Ptr<L3AggregateTracer> > tracers;
   boost::shared_ptr<std::ofstream> outputStream (new std::ofstream ());
   outputStream->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
@@ -106,7 +108,7 @@
 {
   Print (*m_os);
   Reset ();
-  
+
   m_printEvent = Simulator::Schedule (m_period, &L3AggregateTracer::PeriodicPrinter, this);
 }
 
@@ -141,9 +143,18 @@
 
 #define PRINTER(printName, fieldName) \
   os << time.ToDouble (Time::S) << "\t"                                 \
-  << m_node << "\t"                                                     \
-  << stats->first->GetId () << "\t"                                     \
-  << *stats->first << "\t"                                              \
+  << m_node << "\t";                                                    \
+  if (stats->first)                                                     \
+    {                                                                   \
+      os                                                                \
+        << stats->first->GetId () << "\t"                               \
+        << *stats->first << "\t";                                       \
+    }                                                                   \
+  else                                                                  \
+    {                                                                   \
+      os << "-1\tall\t";                                                \
+    }                                                                   \
+  os                                                                    \
   << printName << "\t"                                                  \
   << STATS(0).fieldName << "\t"                                         \
   << STATS(1).fieldName / 1024.0 << "\n";
@@ -152,16 +163,19 @@
 void
 L3AggregateTracer::Print (std::ostream &os) const
 {
+  Time time = Simulator::Now ();
+
   for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats> >::iterator stats = m_stats.begin ();
        stats != m_stats.end ();
        stats++)
     {
-      Time time = Simulator::Now ();
+      if (!stats->first)
+        continue;
 
       PRINTER ("InInterests",   m_inInterests);
       PRINTER ("OutInterests",  m_outInterests);
       PRINTER ("DropInterests", m_dropInterests);
-      
+
       PRINTER ("InNacks",   m_inNacks);
       PRINTER ("OutNacks",  m_outNacks);
       PRINTER ("DropNacks", m_dropNacks);
@@ -170,6 +184,12 @@
       PRINTER ("OutData",  m_outData);
       PRINTER ("DropData", m_dropData);
     }
+
+  {
+    std::map<Ptr<const Face>, boost::tuple<Stats, Stats> >::iterator stats = m_stats.find (Ptr<const Face> (0));
+    PRINTER ("SatisfiedInterests", m_satisfiedInterests);
+    PRINTER ("TimedOutInterests", m_timedOutInterests);
+  }
 }
 
 void
@@ -247,5 +267,19 @@
   m_stats[face].get<1> ().m_dropData += header->GetSerializedSize () + payload->GetSize ();
 }
 
+void
+L3AggregateTracer::SatisfiedInterests (Ptr<const pit::Entry>)
+{
+  m_stats[0].get<0> ().m_satisfiedInterests ++;
+  // no "size" stats
+}
+
+void
+L3AggregateTracer::TimedOutInterests (Ptr<const pit::Entry>)
+{
+  m_stats[0].get<0> ().m_timedOutInterests ++;
+  // no "size" stats
+}
+
 } // namespace ndn
 } // namespace ns3
diff --git a/utils/tracers/ndn-l3-aggregate-tracer.h b/utils/tracers/ndn-l3-aggregate-tracer.h
index c3f437b..b7f6ed3 100644
--- a/utils/tracers/ndn-l3-aggregate-tracer.h
+++ b/utils/tracers/ndn-l3-aggregate-tracer.h
@@ -47,7 +47,7 @@
    * @param node  pointer to the node
    */
   L3AggregateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
-  
+
   /**
    * @brief Trace constructor that attaches to the node using node name
    * @param os        reference to the output stream
@@ -68,12 +68,12 @@
    *
    * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
    *          for the lifetime of simulation, otherwise SEGFAULTs are inevitable
-   * 
+   *
    */
   static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3AggregateTracer> > >
   InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
 
-protected: 
+protected:
   // from L3Tracer
   virtual void
   PrintHeader (std::ostream &os) const;
@@ -92,7 +92,7 @@
   virtual void
   DropInterests (std::string context,
                  Ptr<const Interest>, Ptr<const Face>);
-  
+
   virtual void
   OutNacks  (std::string context,
              Ptr<const Interest>, Ptr<const Face>);
@@ -104,7 +104,7 @@
   virtual void
   DropNacks (std::string context,
              Ptr<const Interest>, Ptr<const Face>);
-  
+
   virtual void
   OutData  (std::string context,
             Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>);
@@ -117,6 +117,13 @@
   DropData (std::string context,
             Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>);
 
+
+  virtual void
+  SatisfiedInterests (Ptr<const pit::Entry>);
+
+  virtual void
+  TimedOutInterests (Ptr<const pit::Entry>);
+
 protected:
   void
   SetAveragingPeriod (const Time &period);
@@ -126,13 +133,13 @@
 
   void
   PeriodicPrinter ();
-  
+
 protected:
   boost::shared_ptr<std::ostream> m_os;
 
   Time m_period;
   EventId m_printEvent;
-  
+
   mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats> > m_stats;
 };
 
diff --git a/utils/tracers/ndn-l3-rate-tracer.cc b/utils/tracers/ndn-l3-rate-tracer.cc
index f7b5252..88079b9 100644
--- a/utils/tracers/ndn-l3-rate-tracer.cc
+++ b/utils/tracers/ndn-l3-rate-tracer.cc
@@ -31,6 +31,7 @@
 #include "ns3/ndn-face.h"
 #include "ns3/ndn-interest.h"
 #include "ns3/ndn-content-object.h"
+#include "ns3/ndn-pit-entry.h"
 
 #include <fstream>
 #include <boost/lexical_cast.hpp>
@@ -108,7 +109,7 @@
 {
   Print (*m_os);
   Reset ();
-  
+
   m_printEvent = Simulator::Schedule (m_period, &L3RateTracer::PeriodicPrinter, this);
 }
 
@@ -150,9 +151,18 @@
   STATS(3).fieldName = /*new value*/alpha * RATE(1, fieldName) / 1024.0 + /*old value*/(1-alpha) * STATS(3).fieldName; \
                                                                         \
   os << time.ToDouble (Time::S) << "\t"                                 \
-  << m_node << "\t"                                                     \
-  << stats->first->GetId () << "\t"                                     \
-  << *stats->first << "\t"                                              \
+  << m_node << "\t";                                                    \
+  if (stats->first)                                                     \
+    {                                                                   \
+      os                                                                \
+        << stats->first->GetId () << "\t"                               \
+        << *stats->first << "\t";                                       \
+    }                                                                   \
+  else                                                                  \
+    {                                                                   \
+      os << "-1\tall\t";                                                \
+    }                                                                   \
+  os                                                                    \
   << printName << "\t"                                                  \
   << STATS(2).fieldName << "\t"                                         \
   << STATS(3).fieldName << "\t"                                         \
@@ -162,16 +172,19 @@
 void
 L3RateTracer::Print (std::ostream &os) const
 {
+  Time time = Simulator::Now ();
+
   for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.begin ();
        stats != m_stats.end ();
        stats++)
     {
-      Time time = Simulator::Now ();
+      if (!stats->first)
+        continue;
 
       PRINTER ("InInterests",   m_inInterests);
       PRINTER ("OutInterests",  m_outInterests);
       PRINTER ("DropInterests", m_dropInterests);
-      
+
       PRINTER ("InNacks",   m_inNacks);
       PRINTER ("OutNacks",  m_outNacks);
       PRINTER ("DropNacks", m_dropNacks);
@@ -180,6 +193,12 @@
       PRINTER ("OutData",  m_outData);
       PRINTER ("DropData", m_dropData);
     }
+
+  {
+    std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.find (Ptr<const Face> (0));
+    PRINTER ("SatisfiedInterests", m_satisfiedInterests);
+    PRINTER ("TimedOutInterests", m_timedOutInterests);
+  }
 }
 
 
@@ -258,5 +277,20 @@
   m_stats[face].get<1> ().m_dropData += header->GetSerializedSize () + payload->GetSize ();
 }
 
+void
+L3RateTracer::SatisfiedInterests (Ptr<const pit::Entry>)
+{
+  m_stats[0].get<0> ().m_satisfiedInterests ++;
+  // no "size" stats
+}
+
+void
+L3RateTracer::TimedOutInterests (Ptr<const pit::Entry>)
+{
+  m_stats[0].get<0> ().m_timedOutInterests ++;
+  // no "size" stats
+}
+
+
 } // namespace ndn
 } // namespace ns3
diff --git a/utils/tracers/ndn-l3-rate-tracer.h b/utils/tracers/ndn-l3-rate-tracer.h
index b1c52a0..4db4e70 100644
--- a/utils/tracers/ndn-l3-rate-tracer.h
+++ b/utils/tracers/ndn-l3-rate-tracer.h
@@ -69,7 +69,7 @@
    *
    * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
    *          for the lifetime of simulation, otherwise SEGFAULTs are inevitable
-   * 
+   *
    */
   static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
   InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
@@ -94,7 +94,7 @@
   virtual void
   DropInterests (std::string context,
                  Ptr<const Interest>, Ptr<const Face>);
-  
+
   virtual void
   OutNacks  (std::string context,
              Ptr<const Interest>, Ptr<const Face>);
@@ -106,7 +106,7 @@
   virtual void
   DropNacks (std::string context,
              Ptr<const Interest>, Ptr<const Face>);
-  
+
   virtual void
   OutData  (std::string context,
             Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>);
@@ -119,13 +119,19 @@
   DropData (std::string context,
             Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>);
 
+  virtual void
+  SatisfiedInterests (Ptr<const pit::Entry>);
+
+  virtual void
+  TimedOutInterests (Ptr<const pit::Entry>);
+
 private:
   void
   SetAveragingPeriod (const Time &period);
 
   void
   PeriodicPrinter ();
-  
+
   void
   Reset ();
 
diff --git a/utils/tracers/ndn-l3-tracer.cc b/utils/tracers/ndn-l3-tracer.cc
index 847de2a..455f684 100644
--- a/utils/tracers/ndn-l3-tracer.cc
+++ b/utils/tracers/ndn-l3-tracer.cc
@@ -30,12 +30,13 @@
 #include "ns3/ndn-face.h"
 #include "ns3/ndn-interest.h"
 #include "ns3/ndn-content-object.h"
+#include "ns3/ndn-pit-entry.h"
 
 using namespace std;
 
 namespace ns3 {
 namespace ndn {
-    
+
 L3Tracer::L3Tracer (Ptr<Node> node)
 : m_nodePtr (node)
 {
@@ -85,6 +86,12 @@
                    MakeCallback (&L3Tracer::InNacks, this));
   Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/DropNacks",
                    MakeCallback (&L3Tracer::DropNacks, this));
+
+  // satisfied/timed out PIs
+  Config::ConnectWithoutContext ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/SatisfiedInterests",
+                                 MakeCallback (&L3Tracer::SatisfiedInterests, this));
+  Config::ConnectWithoutContext ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/TimedOutInterests",
+                                 MakeCallback (&L3Tracer::TimedOutInterests, this));
 }
 
 } // namespace ndn
diff --git a/utils/tracers/ndn-l3-tracer.h b/utils/tracers/ndn-l3-tracer.h
index 45eec7d..af840f4 100644
--- a/utils/tracers/ndn-l3-tracer.h
+++ b/utils/tracers/ndn-l3-tracer.h
@@ -31,6 +31,10 @@
 
 namespace ndn {
 
+namespace pit {
+class Entry;
+}
+
 class Face;
 
 class Interest;
@@ -77,11 +81,11 @@
    */
   virtual void
   Print (std::ostream &os) const = 0;
-  
+
 protected:
   void
   Connect ();
-  
+
   virtual void
   OutInterests  (std::string context,
                  Ptr<const Interest>, Ptr<const Face>) = 0;
@@ -93,7 +97,7 @@
   virtual void
   DropInterests (std::string context,
                  Ptr<const Interest>, Ptr<const Face>) = 0;
-  
+
   virtual void
   OutNacks  (std::string context,
              Ptr<const Interest>, Ptr<const Face>) = 0;
@@ -106,7 +110,7 @@
   DropNacks (std::string context,
              Ptr<const Interest>, Ptr<const Face>) = 0;
 
-  
+
   virtual void
   OutData  (std::string context,
             Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>) = 0;
@@ -119,6 +123,12 @@
   DropData (std::string context,
             Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>) = 0;
 
+  virtual void
+  SatisfiedInterests (Ptr<const pit::Entry>) = 0;
+
+  virtual void
+  TimedOutInterests (Ptr<const pit::Entry>) = 0;
+
 protected:
   std::string m_node;
   Ptr<Node> m_nodePtr;
@@ -136,8 +146,10 @@
       m_inData        = 0;
       m_outData       = 0;
       m_dropData      = 0;
+      m_satisfiedInterests = 0;
+      m_timedOutInterests = 0;
     }
-    
+
     double m_inInterests;
     double m_outInterests;
     double m_dropInterests;
@@ -147,6 +159,8 @@
     double m_inData;
     double m_outData;
     double m_dropData;
+    double m_satisfiedInterests;
+    double m_timedOutInterests;
   };
 };