Adding RIT, PIT, FIB, and CS to ccnx-l3-protocol.  Some small
rearrangements in the code
diff --git a/examples/ccnx-test.cc b/examples/ccnx-test.cc
index e6242ab..27b120c 100644
--- a/examples/ccnx-test.cc
+++ b/examples/ccnx-test.cc
@@ -47,27 +47,27 @@
   CcnxStackHelper ccnx;
   Ptr<CcnxFaceContainer> cf = ccnx.Install (c);
 
-  // test RIT
-  NS_LOG_INFO ("Creating RIT");
-  Ptr<CcnxRit> rit = CreateObject<CcnxRit> ();
+  // // test RIT
+  // NS_LOG_INFO ("Creating RIT");
+  // Ptr<CcnxRit> rit = CreateObject<CcnxRit> ();
 
-  CcnxInterestHeader header;
-  Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
-  (*testname) ("test") ("test2");
-  header.SetName (testname);
-  header.SetNonce (1);
+  // CcnxInterestHeader header;
+  // Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
+  // (*testname) ("test") ("test2");
+  // header.SetName (testname);
+  // header.SetNonce (1);
 
-  rit->SetRecentlySatisfied (header);
+  // rit->SetRecentlySatisfied (header);
 
-  NS_LOG_INFO (rit->WasRecentlySatisfied (header));
+  // NS_LOG_INFO (rit->WasRecentlySatisfied (header));
 
-  (*testname) ("test3"); // should have a side effect of changing name in the packet
-  rit->SetRecentlySatisfied (header);
+  // (*testname) ("test3"); // should have a side effect of changing name in the packet
+  // rit->SetRecentlySatisfied (header);
 
-  NS_LOG_INFO (rit->WasRecentlySatisfied (header));
+  // NS_LOG_INFO (rit->WasRecentlySatisfied (header));
 
-  header.SetNonce (2);
-  NS_LOG_INFO (rit->WasRecentlySatisfied (header));
+  // header.SetNonce (2);
+  // NS_LOG_INFO (rit->WasRecentlySatisfied (header));
 
   // rit->SetRecentlySatisfied (header);
   // ? set up forwarding
diff --git a/helper/ccnx-header-helper.cc b/helper/ccnx-header-helper.cc
index 288162c..85c88f1 100644
--- a/helper/ccnx-header-helper.cc
+++ b/helper/ccnx-header-helper.cc
@@ -34,7 +34,7 @@
 namespace ns3
 {
 
-Ptr<Header>
+CcnxHeaderHelper::Type
 CcnxHeaderHelper::CreateCorrectCcnxHeader (Ptr<const Packet> packet)
 {
   uint8_t type[2];
@@ -43,11 +43,11 @@
   
   if (type[0] == INTEREST_BYTE0 && type[1] == INTEREST_BYTE1)
     {
-      return Create<CcnxInterestHeader> ();
+      return CcnxHeaderHelper::INTEREST;
     }
   else if (type[0] == CONTENT_OBJECT_BYTE0 && type[1] == CONTENT_OBJECT_BYTE1)
     {
-      return Create<CcnxContentObjectHeader> ();
+      return CcnxHeaderHelper::CONTENT_OBJECT;
     }
 
   throw CcnxUnknownHeaderException();
diff --git a/helper/ccnx-header-helper.h b/helper/ccnx-header-helper.h
index 0cfbd12..996b874 100644
--- a/helper/ccnx-header-helper.h
+++ b/helper/ccnx-header-helper.h
@@ -50,6 +50,7 @@
 class CcnxHeaderHelper
 {
 public:
+  enum Type {INTEREST, CONTENT_OBJECT};
 
   /**
    * Static function to create an appropriate CCNx header
@@ -72,7 +73,7 @@
    * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
    */
   
-  static Ptr<Header>
+  static Type
   CreateCorrectCcnxHeader (Ptr<const Packet> packet);
 };
 
diff --git a/model/ccnx-fib.cc b/model/ccnx-fib.cc
index fa972a0..d5b1043 100644
--- a/model/ccnx-fib.cc
+++ b/model/ccnx-fib.cc
@@ -103,8 +103,7 @@
 }
 
 
-CcnxFib::CcnxFib (Ptr<Ccnx> node)
-  : m_node (node)
+CcnxFib::CcnxFib ()
 {
 }
 
@@ -127,7 +126,7 @@
 
 std::ostream& operator<< (std::ostream& os, const CcnxFib &fib)
 {
-  os << "Node " << fib.m_node->GetObject<Node> ()->GetId () << "\n";
+  // os << "Node " << fib.m_node->GetObject<Node> ()->GetId () << "\n";
   os << "  Dest prefix      Interfaces(Costs)                  \n";
   os << "+-------------+--------------------------------------+\n";
   
diff --git a/model/ccnx-fib.h b/model/ccnx-fib.h
index bc559c6..cb0c8f7 100644
--- a/model/ccnx-fib.h
+++ b/model/ccnx-fib.h
@@ -194,7 +194,7 @@
  * Currently, there is only one index
  * - by prefix hash, which is used to perform prefix match
  */
-struct CcnxFibEntryContainer
+struct CcnxFibEntryContainer 
 {
   typedef boost::multi_index::multi_index_container<
     CcnxFibEntry,
@@ -221,9 +221,9 @@
 public:
   /**
    * \brief Constructor
-   * \param node smart pointer to Ccnx stack associated with particular node
    */
-  CcnxFib (Ptr<Ccnx> node);
+  CcnxFib ();
+   // * \param node smart pointer to Ccnx stack associated with particular node
 
   // // Invalidate entries in FIB
   // // Will leave FIB records in hash, but assign metric=NETWORK_UNREACHABLE
@@ -279,9 +279,10 @@
   // void resetProbing();    //reset needsProbing field for every FibEntry
 private:
   friend std::ostream& operator<< (std::ostream& os, const CcnxFib &fib);
-
+  CcnxFib(const CcnxFib&) {} ; ///< \brief copy constructor is disabled
+  
 private:
-  Ptr<Ccnx> m_node;
+  // Ptr<Ccnx> m_node;
 
   CcnxFibEntryContainer::type m_fib;
 };
diff --git a/model/ccnx-l3-protocol.cc b/model/ccnx-l3-protocol.cc
index 8b7cccd..2909b38 100644
--- a/model/ccnx-l3-protocol.cc
+++ b/model/ccnx-l3-protocol.cc
@@ -37,7 +37,6 @@
 #include "ccnx-forwarding-strategy.h"
 #include "ccnx-interest-header.h"
 #include "ccnx-content-object-header.h"
-#include "ccnx-content-store.h"
 
 #include <boost/foreach.hpp>
 
@@ -111,20 +110,6 @@
   Object::NotifyNewAggregate ();
 }
 
-void
-CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy)
-{
-  NS_LOG_FUNCTION (this);
-  m_forwardingStrategy = forwardingStrategy;
-  m_forwardingStrategy->SetCcnx (this);
-}
-
-Ptr<CcnxForwardingStrategy>
-CcnxL3Protocol::GetForwardingStrategy (void) const
-{
-  return m_forwardingStrategy;
-}
-
 void 
 CcnxL3Protocol::DoDispose (void)
 {
@@ -140,6 +125,20 @@
   Object::DoDispose ();
 }
 
+void
+CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy)
+{
+  NS_LOG_FUNCTION (this);
+  m_forwardingStrategy = forwardingStrategy;
+  m_forwardingStrategy->SetCcnx (this);
+}
+
+Ptr<CcnxForwardingStrategy>
+CcnxL3Protocol::GetForwardingStrategy (void) const
+{
+  return m_forwardingStrategy;
+}
+
 uint32_t 
 CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face)
 {
@@ -148,12 +147,8 @@
   face->SetNode (m_node);
   face->SetId (m_faceCounter); // sets a unique ID of the face. This ID serves only informational purposes
 
+  // ask face to register in lower-layer stack
   face->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::Receive, this));
-  // if (face->GetDevice() != 0)
-  //   {
-  //     m_node->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::ReceiveFromLower, this), 
-  //                                      CcnxL3Protocol::ETHERNET_FRAME_TYPE, face->GetDevice(), true/*promiscuous mode*/);
-  //   }
 
   m_faces.push_back (face);
   m_faceCounter ++;
@@ -184,7 +179,7 @@
   if (face->IsUp ())
     {
       NS_LOG_LOGIC ("Dropping received packet -- interface is down");
-      // m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), incomingFace);
+      m_dropTrace (p, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> ()/*this*/, face);
       return;
     }
   NS_LOG_LOGIC ("Packet from face " << &face << " received on node " <<  m_node->GetId ());
@@ -192,8 +187,24 @@
   Ptr<Packet> packet = p->Copy (); // give upper layers a rw copy of the packet
   try
     {
-      Ptr<Header> header = CcnxHeaderHelper::CreateCorrectCcnxHeader (p);
-      ReceiveAndProcess (face, header, packet);  // header should serve as overloaded method selector... not sure whether it works with this "smart" pointers...
+      CcnxHeaderHelper::Type type = CcnxHeaderHelper::CreateCorrectCcnxHeader (p);
+      switch (type)
+        {
+        case CcnxHeaderHelper::INTEREST:
+          {
+            Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> ();
+            OnInterest (face, header, packet);  
+            break;
+          }
+        case CcnxHeaderHelper::CONTENT_OBJECT:
+          {
+            Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
+            OnData (face, header, packet);  
+            break;
+          }
+        }
+      
+      // exception will be thrown if packet is not recognized
     }
   catch (CcnxUnknownHeaderException)
     {
@@ -202,12 +213,17 @@
 }
 
 // Processing Interests
-void CcnxL3Protocol::ReceiveAndProcess (const Ptr<CcnxFace> &incomingFace,
-                                        const Ptr<CcnxInterestHeader> &header,
-                                        const Ptr<Packet> &packet)
+void CcnxL3Protocol::OnInterest (const Ptr<CcnxFace> &incomingFace,
+                                 Ptr<CcnxInterestHeader> &header,
+                                 Ptr<Packet> &packet)
 {
   NS_LOG_LOGIC ("Receiving interest from " << &incomingFace);
-  // m_rxTrace (packet, m_node->GetObject<Ccnx> (), incomingFace);
+  m_receivedInterestsTrace (packet, m_node->GetObject<Ccnx> ()/*this*/, incomingFace);
+  
+  // dangerous place. Trying to deserialize header
+  packet->RemoveHeader (*header);
+
+  NS_ASSERT_MSG (packet->GetSize () == 0, "Payload of Interests should be zero");
 
   /// \todo Processing of Interest packets
   
@@ -223,22 +239,22 @@
 }
 
 // Processing ContentObjects
-void CcnxL3Protocol::ReceiveAndProcess (const Ptr<CcnxFace> &incomingFace,
-                                        const Ptr<CcnxContentObjectHeader> &header,
-                                        const Ptr<Packet> &packet)
+void CcnxL3Protocol::OnData (const Ptr<CcnxFace> &incomingFace,
+                             Ptr<CcnxContentObjectHeader> &header,
+                             Ptr<Packet> &packet)
 {
+  static CcnxContentObjectTail contentObjectTrailer; //there is no data in this object
+  
   NS_LOG_LOGIC ("Receiving contentObject from " << &incomingFace);
+  m_receivedDataTrace (packet, m_node->GetObject<Ccnx> ()/*this*/, incomingFace);
 
+  // dangerous place. Trying to deserialize header
+  packet->RemoveHeader (*header);
+  packet->RemoveTrailer (contentObjectTrailer);
+  
   /// \todo Processing of ContentObject packets
 }
 
-// fake method
-void
-CcnxL3Protocol::ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p)
-{
-  NS_ASSERT_MSG (false, "This function should never be called");
-}
-
 
 void
 CcnxL3Protocol::Send (const Ptr<CcnxFace> &face, const Ptr<Packet> &packet)
@@ -250,7 +266,7 @@
   if (face->IsUp ())
     {
       NS_LOG_LOGIC ("Sending via face " << &face); //
-      m_txTrace (packet, m_node->GetObject<Ccnx> (), face);
+      // m_txTrace (packet, m_node->GetObject<Ccnx> (), face);
       face->Send (packet);
     }
   else
diff --git a/model/ccnx-l3-protocol.h b/model/ccnx-l3-protocol.h
index 8c92c93..fd03be9 100644
--- a/model/ccnx-l3-protocol.h
+++ b/model/ccnx-l3-protocol.h
@@ -28,6 +28,11 @@
 #include "ns3/net-device.h"
 #include "ns3/traced-callback.h"
 
+#include "ccnx-content-store.h"
+#include "ccnx-rit.h"
+#include "ccnx-pit.h"
+#include "ccnx-fib.h"
+
 #include "ccnx.h"
 
 namespace ns3 {
@@ -41,8 +46,7 @@
 class Header;
 class CcnxInterestHeader;
 class CcnxContentObjectHeader;
-//class CcnxContentStore;
-
+  
 /**
  * \ingroup ccnx
  * \brief Actual implementation of the Ccnx network layer
@@ -119,9 +123,9 @@
    * Processing Interest packets
    */
   virtual void
-  ReceiveAndProcess (const Ptr<CcnxFace> &face,
-                     const Ptr<CcnxInterestHeader> &header,
-                     const Ptr<Packet> &p);
+  OnInterest (const Ptr<CcnxFace> &face,
+              Ptr<CcnxInterestHeader> &header,
+              Ptr<Packet> &p);
 
   
   /**
@@ -130,9 +134,9 @@
    * Processing ContentObject packets
    */
   virtual void
-  ReceiveAndProcess (const Ptr<CcnxFace> &face,
-                     const Ptr<CcnxContentObjectHeader> &header,
-                     const Ptr<Packet> &p);
+  OnData (const Ptr<CcnxFace> &face,
+          Ptr<CcnxContentObjectHeader> &header,
+          Ptr<Packet> &p);
 
 protected:
   virtual void DoDispose (void);
@@ -147,11 +151,11 @@
   CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
   CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
 
-  /**
-   * \brief Fake function. should never be called. Just to trick C++ to compile
-   */
-  virtual void
-  ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
+  // /**
+  //  * \brief Fake function. should never be called. Just to trick C++ to compile
+  //  */
+  // virtual void
+  // ReceiveAndProcess (const Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
 
 private:
   uint32_t m_faceCounter; ///< \brief counter of faces. Increased every time a new face is added to the stack
@@ -161,20 +165,18 @@
   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<CcnxContentStore> m_contentStore;
+  CcnxRit m_rit; ///< \brief RIT (recently interest table)
+  CcnxPit m_pit; ///< \brief PIT (pending interest table)
+  CcnxFib m_fib; ///< \brief FIB
   
-  /**
-   * \brief Trace of transmitted packets, including all headers
-   * \internal
-   */
-  TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
+  CcnxContentStore m_contentStore; ///< \brief Content store (for caching purposes only)
+  
+  TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedInterestsTrace;
+  TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedInterestsTrace;
 
-  /**
-   * \brief Trace of received packets, including all headers
-   * \internal
-   */
-  TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
-
+  TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedDataTrace;
+  TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedDataTrace;
+  
   /**
    * \brief Trace of dropped packets, including reason and all headers
    * \internal