Changing internals. PIT, FIB, CS, and ForwardingStrategy now are aggregated onto the node

Also, CcnxStackHelper provide an easy way to set up individual
parameters for them.
diff --git a/model/ccnx-fib.cc b/model/ccnx-fib.cc
index bfcb961..1c86b28 100644
--- a/model/ccnx-fib.cc
+++ b/model/ccnx-fib.cc
@@ -38,8 +38,11 @@
 #include <boost/lambda/bind.hpp>
 namespace ll = boost::lambda;
 
+NS_LOG_COMPONENT_DEFINE ("CcnxFib");
+
 namespace ns3 {
 
+NS_OBJECT_ENSURE_REGISTERED (CcnxFib);
 
 //////////////////////////////////////////////////////////////////////
 // Helpers
@@ -55,7 +58,6 @@
 }
 //////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////
-NS_LOG_COMPONENT_DEFINE ("CcnxFib");
     
 using namespace __ccnx_private;
 
diff --git a/model/ccnx-forwarding-strategy.cc b/model/ccnx-forwarding-strategy.cc
index a856577..93c3847 100644
--- a/model/ccnx-forwarding-strategy.cc
+++ b/model/ccnx-forwarding-strategy.cc
@@ -67,9 +67,18 @@
 }
 
 void
-CcnxForwardingStrategy::SetPit (Ptr<CcnxPit> pit)
+CcnxForwardingStrategy::NotifyNewAggregate ()
 {
-  m_pit = pit;
+  if (m_pit == 0)
+    {
+      m_pit = GetObject<CcnxPit> ();
+    }
+}
+
+void
+CcnxForwardingStrategy::DoDispose ()
+{
+  // nothing to do...
 }
 
 bool
@@ -79,6 +88,7 @@
                                                    const Ptr<const Packet> &packet)
 {
   NS_LOG_FUNCTION (this);
+  NS_ASSERT_MSG (m_pit != 0, "PIT should be aggregated with forwarding strategy");
 
   int propagatedCount = 0;
   
diff --git a/model/ccnx-forwarding-strategy.h b/model/ccnx-forwarding-strategy.h
index 07e6cf2..99ed02c 100644
--- a/model/ccnx-forwarding-strategy.h
+++ b/model/ccnx-forwarding-strategy.h
@@ -66,14 +66,6 @@
                      Ptr<CcnxInterestHeader> &header,
                      const Ptr<const Packet> &packet) = 0;
     
-  /**
-   * @brief Set link to PIT for the forwarding strategy
-   *
-   * @param pit pointer to PIT
-   */
-  void
-  SetPit (Ptr<CcnxPit> pit);
-  
 protected:
   /**
    * @brief Propagate interest via a green interface. Fail, if no green interfaces available
@@ -95,6 +87,11 @@
 
   /// @brief Transmitted interests trace
   TracedCallback<Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace> > m_transmittedInterestsTrace;
+
+protected:
+  // inherited from Object class                                                                                                                                                        
+  virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
+  virtual void DoDispose (); ///< @brief Do cleanup
   
 protected:  
   Ptr<CcnxPit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
diff --git a/model/ccnx-l3-protocol.cc b/model/ccnx-l3-protocol.cc
index 013a2ee..aa5be00 100644
--- a/model/ccnx-l3-protocol.cc
+++ b/model/ccnx-l3-protocol.cc
@@ -71,11 +71,6 @@
                    MakeObjectVectorAccessor (&CcnxL3Protocol::m_faces),
                    MakeObjectVectorChecker<CcnxFace> ())
 
-    .AddAttribute ("ForwardingStrategy", "Forwarding strategy used by CCNx stack",
-                   PointerValue (),
-                   MakePointerAccessor (&CcnxL3Protocol::SetForwardingStrategy, &CcnxL3Protocol::GetForwardingStrategy),
-                   MakePointerChecker<CcnxForwardingStrategy> ())
-    
     .AddAttribute ("EnableNACKs", "Enabling support of NACKs",
                    BooleanValue (false),
                    MakeBooleanAccessor (&CcnxL3Protocol::m_nacksEnabled),
@@ -84,10 +79,6 @@
                    BooleanValue (false),
                    MakeBooleanAccessor (&CcnxL3Protocol::m_cacheUnsolicitedData),
                    MakeBooleanChecker ())
-    .AddAttribute ("RandomDataDelaying", "Delaying data processing",
-                   BooleanValue (false),
-                   MakeBooleanAccessor (&CcnxL3Protocol::m_delayingDataProcessing),
-                   MakeBooleanChecker ())
   ;
   return tid;
 }
@@ -96,8 +87,6 @@
 : m_faceCounter (0)
 {
   NS_LOG_FUNCTION (this);
-  
-  m_pit = CreateObject<CcnxPit> ();
 }
 
 CcnxL3Protocol::~CcnxL3Protocol ()
@@ -105,16 +94,6 @@
   NS_LOG_FUNCTION (this);
 }
 
-void
-CcnxL3Protocol::SetNode (Ptr<Node> node)
-{
-  m_node = node;
-  m_fib = m_node->GetObject<CcnxFib> ();
-  NS_ASSERT_MSG (m_fib != 0, "FIB should be created and aggregated to a node before calling Ccnx::SetNode");
-
-  m_pit->SetFib (m_fib);
-}
-
 /*
  * This method is called by AddAgregate and completes the aggregation
  * by setting the node in the ccnx stack
@@ -122,19 +101,31 @@
 void
 CcnxL3Protocol::NotifyNewAggregate ()
 {
+  // not really efficient, but this will work only once
   if (m_node == 0)
     {
-      Ptr<Node> node = this->GetObject<Node>();
-      // verify that it's a valid node and that
-      // the node has not been set before
-      if (node != 0)
+      m_node = GetObject<Node> ();
+      if (m_node != 0)
         {
-          this->SetNode (node);
+          NS_ASSERT_MSG (m_pit != 0 && m_fib != 0 && m_contentStore != 0 && m_forwardingStrategy != 0,
+                         "PIT, FIB, and ContentStore should be aggregated before CcnxL3Protocol");
         }
     }
+  if (m_pit == 0)
+    {
+      m_pit = GetObject<CcnxPit> ();
+    }
+  if (m_fib == 0)
+    {
+      m_fib = GetObject<CcnxFib> ();
+    }
+  if (m_forwardingStrategy == 0)
+    {
+      m_forwardingStrategy = GetObject<CcnxForwardingStrategy> ();
+    }
   if (m_contentStore == 0)
     {
-      m_contentStore = this->GetObject<CcnxContentStore> ();
+      m_contentStore = GetObject<CcnxContentStore> ();
     }
 
   Object::NotifyNewAggregate ();
@@ -158,31 +149,9 @@
   m_contentStore = 0;
   m_fib = 0;
 
-  // m_forwardingStrategy = 0;
   Object::DoDispose ();
 }
 
-void
-CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy)
-{
-  NS_LOG_FUNCTION (this);
-  m_forwardingStrategy = forwardingStrategy;
-  m_forwardingStrategy->SetPit (m_pit);
-}
-
-Ptr<CcnxForwardingStrategy>
-CcnxL3Protocol::GetForwardingStrategy (void) const
-{
-  return m_forwardingStrategy;
-}
-
-Ptr<CcnxPit>
-CcnxL3Protocol::GetPit () const
-{
-  return m_pit;
-}
-
-
 uint32_t 
 CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face)
 {
@@ -388,8 +357,6 @@
       return;
     }
   
-  NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets");
-
   Ptr<Packet> nonNackInterest = Create<Packet> ();
   header->SetNack (CcnxInterestHeader::NORMAL_INTEREST);
   nonNackInterest->AddHeader (*header);
@@ -531,8 +498,6 @@
   // Propagate
   /////////////////////////////////////////////////////////////////////
   
-  NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets");
-  
   bool propagated = m_forwardingStrategy->
     PropagateInterest (pitEntry, incomingFace, header, packet);
 
@@ -563,12 +528,6 @@
                                Ptr<const Packet> payload,
                                const Ptr<const Packet> &packet)
 {
-  if (m_delayingDataProcessing)
-    {
-      NS_LOG_DEBUG ("Delayed processing " << header->GetName ());
-      // NS_LOG_DEBUG (*m_pit);
-    }
-  
   // 1. Lookup PIT entry
   try
     {
@@ -677,17 +636,7 @@
         }
       else
         {
-          if (!m_delayingDataProcessing)
-            {
-              OnDataDelayed (header, payload, packet);
-            }
-          else
-            {
-              NS_LOG_DEBUG ("Delaying Data forwarding " << header->GetName ());
-              UniformVariable delay (0.0001, 0.002);
-              Simulator::Schedule (Seconds (delay.GetValue ()),
-                                   &CcnxL3Protocol::OnDataDelayed, this, header, payload, packet);
-            }
+          OnDataDelayed (header, payload, packet);
         }
     }
   catch (CcnxPitEntryNotFound)
diff --git a/model/ccnx-l3-protocol.h b/model/ccnx-l3-protocol.h
index 157703c..1d5a3af 100644
--- a/model/ccnx-l3-protocol.h
+++ b/model/ccnx-l3-protocol.h
@@ -83,25 +83,8 @@
   CcnxL3Protocol();
   virtual ~CcnxL3Protocol ();
 
-  /**
-   * \brief Assigns node to the CCNx stack
-   *
-   * \param node Simulation node
-   */
-  void SetNode (Ptr<Node> node);
-
   ////////////////////////////////////////////////////////////////////
   // functions defined in base class Ccnx
-  
-  void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
-  Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
-
-  // virtual void SendInterest (const Ptr<CcnxFace> &face,
-  //                            const Ptr<const CcnxInterestHeader> &header,
-  //                            const Ptr<Packet> &packet);
-  // virtual void SendContentObject (const Ptr<CcnxFace> &face,
-  //                                 const Ptr<const CcnxContentObjectHeader> &header,
-  //                                 const Ptr<Packet> &packet);
 
   virtual uint32_t
   AddFace (const Ptr<CcnxFace> &face);
@@ -118,9 +101,6 @@
   virtual Ptr<CcnxFace>
   GetFaceByNetDevice (Ptr<NetDevice> netDevice) const;
   
-  virtual Ptr<CcnxPit>
-  GetPit () const;
-  
   // void ScheduleLeakage();
 private:
   void
@@ -206,20 +186,15 @@
   typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
   CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
 
+  // These objects are aggregated, but for optimization, get them here
   Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
   Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
-
-  // Ptr<CcnxRit> m_rit; ///< \brief RIT (recently interest table)
   Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table)
   Ptr<CcnxFib> m_fib; ///< \brief FIB  
   Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
 
   bool m_nacksEnabled;
   bool m_cacheUnsolicitedData;
-  bool m_delayingDataProcessing;
-  
-  // Time    m_bucketLeakInterval;
-  // EventId m_bucketLeakEvent;
 };
   
 } // Namespace ns3
diff --git a/model/ccnx-pit.cc b/model/ccnx-pit.cc
index 6e63550..4186af4 100644
--- a/model/ccnx-pit.cc
+++ b/model/ccnx-pit.cc
@@ -21,6 +21,7 @@
 #include "ccnx-pit.h"
 #include "ns3/log.h"
 #include "ns3/string.h"
+#include "ns3/uinteger.h"
 #include "ns3/simulator.h"
 #include "ccnx-interest-header.h"
 #include "ccnx-content-object-header.h"
@@ -63,6 +64,12 @@
                    StringValue("4s"),
                    MakeTimeAccessor (&CcnxPit::m_PitEntryDefaultLifetime),
                    MakeTimeChecker ())
+
+    .AddAttribute ("MaxSize",
+                   "Set maximum number of entries in PIT. If 0, limit is not enforced",
+                   StringValue ("0"),
+                   MakeUintegerAccessor (&CcnxPit::m_maxSize),
+                   MakeUintegerChecker<uint32_t> ())
     ;
 
   return tid;
@@ -74,12 +81,15 @@
 
 CcnxPit::~CcnxPit ()
 {
-  DoDispose ();
 }
 
 void 
 CcnxPit::NotifyNewAggregate ()
 {
+  if (m_fib == 0)
+    {
+      m_fib = GetObject<CcnxFib> ();
+    }
 }
 
 void 
@@ -134,12 +144,6 @@
                                         &CcnxPit::CleanExpired, this); 
 }
 
-void
-CcnxPit::SetFib (Ptr<CcnxFib> fib)
-{
-  m_fib = fib;
-}
-
 CcnxPitEntryContainer::type::iterator
 CcnxPit::Lookup (const CcnxContentObjectHeader &header) const
 {
@@ -177,6 +181,13 @@
 
   if (entry == end ())
     {
+      if (m_maxSize > 0 &&
+          size () >= m_maxSize)
+        {
+          // remove old record
+          get<i_timestamp> ().erase (get<i_timestamp> ().begin ());
+        }
+      
       CcnxFibEntryContainer::type::iterator fibEntry = m_fib->LongestPrefixMatch (header);
       NS_ASSERT_MSG (fibEntry != m_fib->m_fib.end (),
                      "There should be at least default route set" << " Prefix = "<<header.GetName() << "NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib);
diff --git a/model/ccnx-pit.h b/model/ccnx-pit.h
index 84b1685..826f49f 100644
--- a/model/ccnx-pit.h
+++ b/model/ccnx-pit.h
@@ -150,11 +150,6 @@
     return m_PitEntryPruningTimout;
   }
   
-  /**
-   * \brief Set FIB table
-   */
-  void SetFib (Ptr<CcnxFib> fib);
-
 protected:
   // inherited from Object class                                                                                                                                                        
   virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
@@ -190,6 +185,8 @@
   Time    m_PitEntryPruningTimout;
   Time    m_PitEntryDefaultLifetime;
 
+  uint32_t m_maxSize;
+
   Ptr<CcnxFib> m_fib; ///< \brief Link to FIB table
 };
 
diff --git a/model/ccnx.h b/model/ccnx.h
index 4dc3cea..41e950a 100644
--- a/model/ccnx.h
+++ b/model/ccnx.h
@@ -90,29 +90,7 @@
    */
   static TypeId GetTypeId ();
   virtual ~Ccnx ();
-
-  /**
-   * \brief Register a new forwarding strategy to be used by this Ccnx
-   * stack
-   *
-   * This call will replace any forwarding strategy that has been
-   * previously registered.
-   * 
-   * \param forwardingStrategy smart pointer to CcnxForwardingStrategy
-   * object
-   */
-  virtual void
-  SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) = 0;
-
-  /**
-   * \brief Get the forwarding strategy being used by this Ccnx stack
-   * 
-   * \returns smart pointer to CcnxForwardingStrategy object, or null
-   * pointer if none
-   */
-  virtual Ptr<CcnxForwardingStrategy>
-  GetForwardingStrategy (void) const = 0;
-
+  
   /**
    * \brief Add face to CCNx stack
    *
@@ -154,12 +132,6 @@
   GetFaceByNetDevice (Ptr<NetDevice> netDevice) const = 0;
 
   /**
-   * \brief Get PIT associated with Node 
-   */
-  virtual Ptr<CcnxPit>
-  GetPit() const = 0;
-
-  /**
    * \enum DropReason
    * \brief A reason why the packet has been dropped
    */