limits: Introducing modularity for Interest limits

Now ndn::Limits object can be aggregated on a face/FIB entry. A
forwarding strategy module is responsible in creating an appropriate
implementation of the Interest limits module.
diff --git a/model/fib/ndn-fib-entry.h b/model/fib/ndn-fib-entry.h
index c8072f4..272d801 100644
--- a/model/fib/ndn-fib-entry.h
+++ b/model/fib/ndn-fib-entry.h
@@ -165,7 +165,7 @@
  * \brief Structure for FIB table entry, holding indexed list of
  *        available faces and their respective metrics
  */
-class Entry : public SimpleRefCount<Entry>
+class Entry : public Object
 {
 public:
   class NoFaces {}; ///< @brief Exception class for the case when FIB entry is not found
@@ -178,7 +178,6 @@
   : m_prefix (prefix)
   , m_needsProbing (false)
   {
-    m_limits = CreateObject<Limits> ();
   }
   
   /**
@@ -231,15 +230,6 @@
     m_faces.erase (face);
   }
 
-  /**
-   * @brief Get reference to limits object
-   */
-  Limits &
-  GetLimits ()
-  {
-    return *m_limits;
-  }
-    
 private:
   friend std::ostream& operator<< (std::ostream& os, const Entry &entry);
 
@@ -248,8 +238,6 @@
   FaceMetricContainer::type m_faces; ///< \brief Indexed list of faces
 
   bool m_needsProbing;      ///< \brief flag indicating that probing should be performed
-
-  Ptr<Limits> m_limits;
 };
 
 std::ostream& operator<< (std::ostream& os, const Entry &entry);
diff --git a/model/fw/ndn-forwarding-strategy.cc b/model/fw/ndn-forwarding-strategy.cc
index 9fc4d29..b04d48e 100644
--- a/model/fw/ndn-forwarding-strategy.cc
+++ b/model/fw/ndn-forwarding-strategy.cc
@@ -528,6 +528,11 @@
   // do nothing for now. may be need to do some logging
 }
 
+void
+ForwardingStrategy::AddFace (Ptr<Face> face)
+{
+  // do nothing here
+}
 
 void
 ForwardingStrategy::RemoveFace (Ptr<Face> face)
diff --git a/model/fw/ndn-forwarding-strategy.h b/model/fw/ndn-forwarding-strategy.h
index 3f0a147..fbf2295 100644
--- a/model/fw/ndn-forwarding-strategy.h
+++ b/model/fw/ndn-forwarding-strategy.h
@@ -90,6 +90,13 @@
   WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
 
   /**
+   * @brief Event fired every time face is added to NDN stack
+   * @param face face to be removed
+   */
+  virtual void
+  AddFace (Ptr<Face> face);
+  
+  /**
    * @brief Event fired every time face is removed from NDN stack
    * @param face face to be removed
    *
diff --git a/model/fw/simple-limits.cc b/model/fw/simple-window-limits.cc
similarity index 68%
rename from model/fw/simple-limits.cc
rename to model/fw/simple-window-limits.cc
index 803d608..8939fa9 100644
--- a/model/fw/simple-limits.cc
+++ b/model/fw/simple-window-limits.cc
@@ -18,7 +18,7 @@
  * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
  */
 
-#include "simple-limits.h"
+#include "simple-window-limits.h"
 
 #include "ns3/ndn-l3-protocol.h"
 #include "ns3/ndn-interest-header.h"
@@ -32,20 +32,23 @@
 namespace ndn {
 namespace fw {
 
-typedef SimpleLimits<BestRoute> SimpleLimitsBestRoute;
+template class SimpleWindowLimits<BestRoute>;
+typedef SimpleWindowLimits<BestRoute> SimpleLimitsBestRoute;
 NS_OBJECT_ENSURE_REGISTERED (SimpleLimitsBestRoute);
 
-typedef SimpleLimits<Flooding> SimpleLimitsFlooding;
+template class SimpleWindowLimits<Flooding>;
+typedef SimpleWindowLimits<Flooding> SimpleLimitsFlooding;
 NS_OBJECT_ENSURE_REGISTERED (SimpleLimitsFlooding);
 
-typedef SimpleLimits<SmartFlooding> SimpleLimitsSmartFlooding;
+template class SimpleWindowLimits<SmartFlooding>;
+typedef SimpleWindowLimits<SmartFlooding> SimpleLimitsSmartFlooding;
 NS_OBJECT_ENSURE_REGISTERED (SimpleLimitsSmartFlooding);
 
 #ifdef DOXYGEN
 
-class SimpleLimitsBestRoute : public SimpleLimits<BestRoute> { };
-class SimpleLimitsFlooding : public SimpleLimits<Flooding> { };
-class SimpleLimitsSmartFlooding : public SimpleLimits<SmartFlooding> { };
+class SimpleWindowLimitsBestRoute : public SimpleWindowLimits<BestRoute> { };
+class SimpleWindowLimitsFlooding : public SimpleWindowLimits<Flooding> { };
+class SimpleWindowLimitsSmartFlooding : public SimpleWindowLimits<SmartFlooding> { };
 
 #endif
 
diff --git a/model/fw/simple-limits.h b/model/fw/simple-window-limits.h
similarity index 71%
rename from model/fw/simple-limits.h
rename to model/fw/simple-window-limits.h
index 22a94ed..69fcd19 100644
--- a/model/fw/simple-limits.h
+++ b/model/fw/simple-window-limits.h
@@ -19,8 +19,8 @@
  */
 
 
-#ifndef NDNSIM_SIMPLE_LIMITS_H
-#define NDNSIM_SIMPLE_LIMITS_H
+#ifndef NDNSIM_SIMPLE_WINDOW_LIMITS_H
+#define NDNSIM_SIMPLE_WINDOW_LIMITS_H
 
 #include "ns3/event-id.h"
 #include "ns3/ndn-pit.h"
@@ -29,6 +29,9 @@
 
 #include "ns3/ndn-forwarding-strategy.h"
 
+#include "../../utils/ndn-limits-window.h"
+
+
 namespace ns3 {
 namespace ndn {
 namespace fw {
@@ -38,7 +41,7 @@
  * \brief Strategy implementing per-FIB entry limits
  */
 template<class Parent>
-class SimpleLimits :
+class SimpleWindowLimits :
     public Parent
 {
 private:
@@ -51,13 +54,21 @@
   /**
    * @brief Default constructor
    */
-  SimpleLimits ()
-  {
-  }
+  SimpleWindowLimits ()
+  { }
   
   virtual void
   WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
 
+  virtual void
+  AddFace (Ptr<Face> face)
+  {
+    Ptr<Limits> limits = CreateObject<LimitsWindow> ();
+    face->AggregateObject (limits);
+
+    super::AddFace (face);
+  }
+  
 protected:
   virtual bool
   TrySendOutInterest (Ptr<Face> inFace,
@@ -74,23 +85,23 @@
 
 template<class Parent>
 TypeId
-SimpleLimits<Parent>::GetTypeId (void)
+SimpleWindowLimits<Parent>::GetTypeId (void)
 {
-  static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::SimpleLimits").c_str ())
+  static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::SimpleWindowLimits").c_str ())
     .SetGroupName ("Ndn")
     .template SetParent <super> ()
-    .template AddConstructor <SimpleLimits> ()
+    .template AddConstructor <SimpleWindowLimits> ()
     ;
   return tid;
 }
 
 template<class Parent>
 bool
-SimpleLimits<Parent>::TrySendOutInterest (Ptr<Face> inFace,
-                                          Ptr<Face> outFace,
-                                          Ptr<const InterestHeader> header,
-                                          Ptr<const Packet> origPacket,
-                                          Ptr<pit::Entry> pitEntry)
+SimpleWindowLimits<Parent>::TrySendOutInterest (Ptr<Face> inFace,
+                                                Ptr<Face> outFace,
+                                                Ptr<const InterestHeader> header,
+                                                Ptr<const Packet> origPacket,
+                                                Ptr<pit::Entry> pitEntry)
 {
   // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
   // totally override all (if any) parent processing
@@ -104,7 +115,7 @@
       return false;
     }
 
-  if (outFace->GetLimits ().IsBelowLimit ())
+  if (outFace->template GetObject<LimitsWindow> ()->IsBelowLimit ())
     {
       pitEntry->AddOutgoing (outFace);
 
@@ -125,7 +136,7 @@
 
 template<class Parent>
 void
-SimpleLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
+SimpleWindowLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
 {
   // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
 
@@ -133,7 +144,7 @@
        face != pitEntry->GetOutgoing ().end ();
        face ++)
     {
-      face->m_face->GetLimits ().RemoveOutstanding ();
+      face->m_face->GetObject<LimitsWindow> ()->RemoveOutstanding ();
     }
 
   super::WillEraseTimedOutPendingInterest (pitEntry);
@@ -142,8 +153,8 @@
 
 template<class Parent>
 void
-SimpleLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace,
-                                                  Ptr<pit::Entry> pitEntry)
+SimpleWindowLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace,
+                                                        Ptr<pit::Entry> pitEntry)
 {
   // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
 
@@ -151,7 +162,7 @@
        face != pitEntry->GetOutgoing ().end ();
        face ++)
     {
-      face->m_face->GetLimits ().RemoveOutstanding ();
+      face->m_face->GetObject<LimitsWindow> ()->RemoveOutstanding ();
     }
   
   super::WillSatisfyPendingInterest (inFace, pitEntry);
@@ -161,4 +172,4 @@
 } // namespace ndn
 } // namespace ns3
 
-#endif // NDNSIM_SIMPLE_LIMITS_H
+#endif // NDNSIM_SIMPLE_WINDOW_LIMITS_H
diff --git a/model/ndn-face.cc b/model/ndn-face.cc
index d709cfc..f91fc19 100644
--- a/model/ndn-face.cc
+++ b/model/ndn-face.cc
@@ -55,12 +55,6 @@
                    MakeUintegerAccessor (&Face::m_id),
                    MakeUintegerChecker<uint32_t> ())
 
-    .AddAttribute ("Limits", "Limits object",
-                   TypeId::ATTR_GET, // allow only getting it.
-                   PointerValue (0), // this is not really used, but needed for the compiler... so sad
-                   MakePointerAccessor (&Face::m_limits),
-                   MakePointerChecker<Limits> ())
-
     // .AddAttribute ("MetricTagging", "Enable metric tagging (path-stretch calculation)",
     //                BooleanValue (false),
     //                MakeBooleanAccessor (&Face::m_enableMetricTagging),
@@ -87,7 +81,6 @@
   , m_ifup (false)
   , m_id ((uint32_t)-1)
   , m_metric (0)
-  , m_limits (CreateObject<Limits> ())
   // , m_enableMetricTagging (false)
 {
   NS_LOG_FUNCTION (this);
diff --git a/model/ndn-face.h b/model/ndn-face.h
index 7741c1e..78c65a7 100644
--- a/model/ndn-face.h
+++ b/model/ndn-face.h
@@ -90,12 +90,6 @@
   RegisterProtocolHandler (ProtocolHandler handler);
 
   /**
-   * @brief Get reference to Limits object
-   */
-  inline Limits&
-  GetLimits ();    
-  
-  /**
    * \brief Send packet on a face
    *
    * This method will be called by lower layers to send data to device or application
@@ -221,7 +215,6 @@
   uint32_t m_id; ///< \brief id of the interface in Ndn stack (per-node uniqueness)
   uint32_t m_metric; ///< \brief metric of the face
 
-  Ptr<Limits> m_limits;
   // bool m_enableMetricTagging;
 
   TracedCallback<Ptr<const Packet> > m_txTrace;
@@ -255,13 +248,6 @@
   return !(*this == face);
 }
 
-inline Limits&
-Face::GetLimits ()
-{
-  return *m_limits;
-}
-
-
 } // namespace ndn
 } // namespace ns3
 
diff --git a/model/ndn-l3-protocol.cc b/model/ndn-l3-protocol.cc
index 372df77..850f84f 100644
--- a/model/ndn-l3-protocol.cc
+++ b/model/ndn-l3-protocol.cc
@@ -164,6 +164,8 @@
 
   m_faces.push_back (face);
   m_faceCounter++;
+
+  m_forwardingStrategy->AddFace (face); // notify that face is added    
   return face->GetId ();
 }
 
@@ -196,6 +198,9 @@
   FaceList::iterator face_it = find (m_faces.begin(), m_faces.end(), face);
   NS_ASSERT_MSG (face_it != m_faces.end (), "Attempt to remove face that doesn't exist");
   m_faces.erase (face_it);
+
+  GetObject<Fib> ()->RemoveFromAll (face);
+  m_forwardingStrategy->RemoveFace (face); // notify that face is removed  
 }
 
 Ptr<Face>