Many corrections to face/local-face/net-device-face/fib/pit.  Now
interest packets actually go down to ccnx stack.  Also, now it is
possible to manually configure FIB entries.

CcnxFib now is an object aggregated to the node
diff --git a/apps/ccnx-consumer.cc b/apps/ccnx-consumer.cc
index 0e6ec9e..71aac13 100644
--- a/apps/ccnx-consumer.cc
+++ b/apps/ccnx-consumer.cc
@@ -19,6 +19,11 @@
  */
 
 #include "ccnx-consumer.h"
+#include "ns3/ptr.h"
+#include "ns3/ccnx-local-face.h"
+#include "ns3/ccnx.h"
+#include "ns3/callback.h"
+#include "ns3/ccnx-content-object-header.h"
 
 NS_LOG_COMPONENT_DEFINE ("CcnxConsumer");
 
@@ -31,49 +36,45 @@
 CcnxConsumer::GetTypeId (void)
 {
     static TypeId tid = TypeId ("ns3::CcnxConsumer")
-    .SetParent<Application> ()
-    .AddConstructor<CcnxConsumer> ()
-    .AddAttribute ("OffTime", "Time interval between packets",
-                    TimeValue (Seconds (0.1)),
-                    MakeTimeAccessor (&CcnxConsumer::m_offTime),
-                    MakeTimeChecker ())
-    .AddAttribute ("Face","Local face to be used",
-                    PointerValue (CreateObject<CcnxLocalFace> ()),
-                    MakePointerAccessor (&CcnxConsumer::m_face),
-                    MakePointerChecker<CcnxLocalFace> ())
-    .AddAttribute ("InterestName","CcnxName of the Interest (use CcnxNameComponents)",
-                    CcnxNameComponentsValue (CcnxNameComponents ()),
-                    MakeCcnxNameComponentsAccessor (&CcnxConsumer::m_interestName),
-                    MakeCcnxNameComponentsChecker ())
-    .AddAttribute ("LifeTime", "LifeTime fo interest packet",
-                    TimeValue (Seconds (4.0)),
-                    MakeTimeAccessor (&CcnxConsumer::m_interestLifeTime),
-                    MakeTimeChecker ())
-    .AddAttribute ("MinSuffixComponents", "MinSuffixComponents",
-                    IntegerValue(-1),
-                    MakeIntegerAccessor(&CcnxConsumer::m_minSuffixComponents),
-                    MakeIntegerChecker<int32_t>())
-    .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents",
-                    IntegerValue(-1),
-                    MakeIntegerAccessor(&CcnxConsumer::m_maxSuffixComponents),
-                    MakeIntegerChecker<int32_t>())
-    .AddAttribute ("ChildSelector", "ChildSelector",
-                    BooleanValue(false),
-                    MakeBooleanAccessor(&CcnxConsumer::m_childSelector),
-                    MakeBooleanChecker())
-    .AddAttribute ("Exclude", "only simple name matching is supported (use CcnxNameComponents)",
-                   CcnxNameComponentsValue (CcnxNameComponents ()),
-                   MakeCcnxNameComponentsAccessor (&CcnxConsumer::m_exclude),
-                   MakeCcnxNameComponentsChecker ())
-    .AddAttribute ("Initial Nonce", "If 0 then nonce is not used",
-                    UintegerValue(1),
-                    MakeUintegerAccessor(&CcnxConsumer::m_initialNonce),
-                    MakeUintegerChecker<uint32_t>())
-    .AddTraceSource ("InterestTrace", "Interests that were sent",
-                     MakeTraceSourceAccessor (&CcnxConsumer::m_interestsTrace))
-    .AddTraceSource ("ContentObjectTrace", "ContentObjects that were received",
-                     MakeTraceSourceAccessor (&CcnxConsumer::m_contentObjectsTrace))
-    ;
+      .SetParent<Application> ()
+      .AddConstructor<CcnxConsumer> ()
+      .AddAttribute ("OffTime", "Time interval between packets",
+                     TimeValue (Seconds (0.1)),
+                     MakeTimeAccessor (&CcnxConsumer::m_offTime),
+                     MakeTimeChecker ())
+      .AddAttribute ("InterestName","CcnxName of the Interest (use CcnxNameComponents)",
+                     CcnxNameComponentsValue (),
+                     MakeCcnxNameComponentsAccessor (&CcnxConsumer::m_interestName),
+                     MakeCcnxNameComponentsChecker ())
+      .AddAttribute ("LifeTime", "LifeTime fo interest packet",
+                     TimeValue (Seconds (0)),
+                     MakeTimeAccessor (&CcnxConsumer::m_interestLifeTime),
+                     MakeTimeChecker ())
+      .AddAttribute ("MinSuffixComponents", "MinSuffixComponents",
+                     IntegerValue(-1),
+                     MakeIntegerAccessor(&CcnxConsumer::m_minSuffixComponents),
+                     MakeIntegerChecker<int32_t>())
+      .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents",
+                     IntegerValue(-1),
+                     MakeIntegerAccessor(&CcnxConsumer::m_maxSuffixComponents),
+                     MakeIntegerChecker<int32_t>())
+      .AddAttribute ("ChildSelector", "ChildSelector",
+                     BooleanValue(false),
+                     MakeBooleanAccessor(&CcnxConsumer::m_childSelector),
+                     MakeBooleanChecker())
+      .AddAttribute ("Exclude", "only simple name matching is supported (use CcnxNameComponents)",
+                     CcnxNameComponentsValue (),
+                     MakeCcnxNameComponentsAccessor (&CcnxConsumer::m_exclude),
+                     MakeCcnxNameComponentsChecker ())
+      .AddAttribute ("Initial Nonce", "If 0 then nonce is not used",
+                     UintegerValue(1),
+                     MakeUintegerAccessor(&CcnxConsumer::m_initialNonce),
+                     MakeUintegerChecker<uint32_t>())
+      .AddTraceSource ("InterestTrace", "Interests that were sent",
+                       MakeTraceSourceAccessor (&CcnxConsumer::m_interestsTrace))
+      .AddTraceSource ("ContentObjectTrace", "ContentObjects that were received",
+                       MakeTraceSourceAccessor (&CcnxConsumer::m_contentObjectsTrace))
+      ;
 
     return tid;
 }
@@ -101,7 +102,24 @@
 CcnxConsumer::StartApplication () // Called at time specified by Start
 {
     NS_LOG_FUNCTION_NOARGS ();
-    ScheduleNextTx();
+
+    NS_ASSERT_MSG (m_face == 0, "Face should not exist");
+    m_face = Create<CcnxLocalFace> ();
+
+    // step 1. Set up forwarding from face to application
+    m_face->SetNode (GetNode ());
+    m_face->SetContentObjectHandler (MakeCallback (&CcnxConsumer::OnContentObject, this));
+
+    // step 2. Set up forwarding to and from ccnx
+    NS_ASSERT_MSG (GetNode ()->GetObject<Ccnx> () !=0,
+                   "Ccnx stack should be installed on the node " << GetNode ());
+    GetNode ()->GetObject<Ccnx> ()->AddFace (m_face);
+
+    // step 3. Enable face
+    m_face->SetUp ();
+
+    // Send first packet immediately
+    m_sendEvent = Simulator::Schedule (Seconds(0.0), &CcnxConsumer::SendPacket, this);
 }
     
 void 
@@ -110,6 +128,17 @@
     NS_LOG_FUNCTION_NOARGS ();
         
     CancelEvents ();
+
+    // step 1. Disable face
+    m_face->SetDown ();
+
+    // step 2. Remove face from ccnx stack
+    GetNode ()->GetObject<Ccnx> ()->RemoveFace (m_face);
+
+    // step 3. Disable callbacks
+    m_face->SetContentObjectHandler (MakeNullCallback<void,
+                                                      const Ptr<const CcnxContentObjectHeader> &,
+                                                      const Ptr<const Packet> &> ());
 }
     
 void 
@@ -120,15 +149,6 @@
     Simulator::Cancel (m_sendEvent);
 }
     
-void 
-CcnxConsumer::ScheduleNextTx ()
-{
-    NS_LOG_FUNCTION_NOARGS ();
-        
-    Time nextTime = Seconds(m_offTime);
-    m_sendEvent = Simulator::Schedule (nextTime, &CcnxConsumer::SendPacket, this);
-}
-    
 void
 CcnxConsumer::SendPacket ()
 {
@@ -145,32 +165,28 @@
     interestHeader.SetMaxSuffixComponents(m_maxSuffixComponents);
     interestHeader.SetMinSuffixComponents(m_minSuffixComponents);
         
+    NS_LOG_INFO ("Interest: \n" << interestHeader);
+
     Ptr<Packet> packet = Create<Packet> ();
     packet->AddHeader (interestHeader);
         
-    m_face->Receive(packet);
-        
-    ScheduleNextTx();
+    m_face->ReceiveFromApplication (packet);
+
+    m_sendEvent = Simulator::Schedule (Seconds(m_offTime), &CcnxConsumer::SendPacket, this);
 }
     
+// void
+// CcnxConsumer::OnInterest (const Ptr<const CcnxInterestHeader> &interest)
+// {
+// }
+
 void
-CcnxConsumer::HandlePacket(const Ptr<CcnxFace> &face, const Ptr<const Packet> &packet)
+CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
+                               const Ptr<const Packet> &payload)
 {
-    uint8_t type[2];
-    uint32_t read = packet->CopyData (type,2);
-    if (read!=2)
-    {
-        NS_LOG_INFO ("Unknown CcnxPacket");
-        return;
-    }
-    
-    if (type[0] == INTEREST_BYTE0 && type[1] == INTEREST_BYTE1)
-    {
-        m_interestsTrace(face,packet);
-    }
-    else if (type[0] == CONTENT_OBJECT_BYTE0 && type[1] == CONTENT_OBJECT_BYTE1)
-    {
-        m_contentObjectsTrace(face,packet);
-    }
+  // do stuff
+  NS_LOG_FUNCTION ("Received contentObject " << contentObject );
 }
+
+
 }
diff --git a/apps/ccnx-consumer.h b/apps/ccnx-consumer.h
index ab12105..1b1971f 100644
--- a/apps/ccnx-consumer.h
+++ b/apps/ccnx-consumer.h
@@ -35,8 +35,6 @@
 #include "ns3/boolean.h"
 #include "ns3/integer.h"
 #include "ns3/uinteger.h"
-#include "ns3/random-variable.h"
-#include <limits> 
 #include "ns3/pointer.h"
 #include "ns3/traced-callback.h"
 #include "ns3/ccnx-header-helper.h"
@@ -50,62 +48,49 @@
 class CcnxConsumer: public Application
 {
 public: 
-    static TypeId GetTypeId (void);
+  static TypeId GetTypeId ();
         
-    CcnxConsumer ();
-        
-    virtual ~CcnxConsumer ();
-    
-    void HandlePacket (const Ptr<CcnxFace> &face, const Ptr<const Packet> &packet);
+  CcnxConsumer ();
+  virtual ~CcnxConsumer ();
+
+  void OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
+                        const Ptr<const Packet> &payload);
         
 protected:
-    virtual void DoDispose (void);
+  virtual void DoDispose (void);
+  
 private:
-    // inherited from Application base class.
-    virtual void StartApplication (void);    // Called at time specified by Start
-    virtual void StopApplication (void);     // Called at time specified by Stop
+  // inherited from Application base class.
+  virtual void StartApplication (void);    // Called at time specified by Start
+  virtual void StopApplication (void);     // Called at time specified by Stop
         
-    Time m_offTime;
-    CcnxNameComponents m_interestName;
-    Time m_interestLifeTime;
-    int32_t m_minSuffixComponents;
-    int32_t m_maxSuffixComponents;
-    bool m_childSelector;
-    CcnxNameComponents m_exclude;
-    uint32_t m_initialNonce;
-        
-    EventId         m_sendEvent;    // Eventid of pending "send packet" event
-    TypeId          m_tid;
-    Ptr<CcnxLocalFace> m_face;
-        
-    //helpers
-    void CancelEvents ();
-        
-    void Construct (Ptr<Node> n,
-                    std::string tid,
-                    const Time& offtime,
-                    Ptr<CcnxLocalFace> face,
-                    Ptr<CcnxNameComponents> nameComponents,
-                    const Time& lifetime,
-                    const int32_t& minSuffixComponents,
-                    const int32_t& maxSuffixComponents,
-                    const bool childSelector,
-                    Ptr<CcnxNameComponents> exclude,
-                    const uint32_t& initialNonce
-                    );
-        
-    // Event handlers
-    void StartSending ();
-    void StopSending ();
-    void SendPacket ();
-    //typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>& > ProtocolHandler;
+  //helpers
+  void CancelEvents ();
+
+  // Event handlers
+  // void StartSending ();
+  // void StopSending ();
+  void SendPacket ();
+  //typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>& > ProtocolHandler;
      
 private:
-    void ScheduleNextTx ();
-    //typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>& > ProtocolHandler;
-    
-    TracedCallback<const Ptr<CcnxFace>&,const Ptr<const Packet>& > m_interestsTrace;
-    TracedCallback<const Ptr<CcnxFace>&,const Ptr<const Packet>& > m_contentObjectsTrace;
+  TracedCallback<const Ptr<CcnxFace>&,const Ptr<const Packet>& > m_interestsTrace;
+  TracedCallback<const Ptr<CcnxFace>&,const Ptr<const Packet>& > m_contentObjectsTrace;
+
+  Time m_offTime;
+  CcnxNameComponents m_interestName;
+  Time m_interestLifeTime;
+  int32_t m_minSuffixComponents;
+  int32_t m_maxSuffixComponents;
+  bool m_childSelector;
+  CcnxNameComponents m_exclude;
+  uint32_t m_initialNonce;
+        
+  EventId         m_sendEvent;    // Eventid of pending "send packet" event
+  TypeId          m_tid;
+  Ptr<CcnxLocalFace> m_face;
 };
-}
+
+} // namespace ns3
+
 #endif
diff --git a/apps/ccnx-interest-sender.cc b/apps/ccnx-interest-sender.cc
index c3ecc59..bcf3d76 100644
--- a/apps/ccnx-interest-sender.cc
+++ b/apps/ccnx-interest-sender.cc
@@ -37,10 +37,11 @@
                    TimeValue (Seconds (0.1)),
                    MakeTimeAccessor (&CcnxInterestSender::m_offTime),
                    MakeTimeChecker ())
-    .AddAttribute ("Face","Local face to be used",
-                   PointerValue (CreateObject<CcnxLocalFace> ()),
-                   MakePointerAccessor (&CcnxInterestSender::m_face),
-                   MakePointerChecker<CcnxLocalFace> ())
+    // Alex: this is incorrect. SetNode call is not called if face is created using this accessor
+    // .AddAttribute ("Face","Local face to be used",
+    //                PointerValue (CreateObject<CcnxLocalFace> ()),
+    //                MakePointerAccessor (&CcnxInterestSender::m_face),
+    //                MakePointerChecker<CcnxLocalFace> ())
     .AddAttribute ("NameComponents","CcnxName of the Interest (use CcnxNameComponents)",
                    CcnxNameComponentsValue (CcnxNameComponents (/* root */)),
                    MakeCcnxNameComponentsAccessor (&CcnxInterestSender::m_interestName),
diff --git a/apps/ccnx-producer.cc b/apps/ccnx-producer.cc
index 43964b1..7e0757a 100644
--- a/apps/ccnx-producer.cc
+++ b/apps/ccnx-producer.cc
@@ -34,10 +34,11 @@
     static TypeId tid = TypeId ("ns3::CcnxProducer")
     .SetParent<Application> ()
     .AddConstructor<CcnxProducer> ()
-    .AddAttribute ("Face","Local face to be used",
-                    PointerValue (CreateObject<CcnxLocalFace> ()),
-                    MakePointerAccessor (&CcnxProducer::m_face),
-                    MakePointerChecker<CcnxLocalFace> ())
+    // Alex: this is incorrect. SetNode call is not called if face is created using this accessor
+    // .AddAttribute ("Face","Local face to be used",
+    //                 PointerValue (CreateObject<CcnxLocalFace> ()),
+    //                 MakePointerAccessor (&CcnxProducer::m_face),
+    //                 MakePointerChecker<CcnxLocalFace> ())
     .AddAttribute ("Ccnx","Ccnx is needed to access ContentStore",
                    PointerValue (NULL),
                    MakePointerAccessor (&CcnxProducer::m_ccnx),