model: A basic implementation of ndn::ApiFace that can be used as an NDN handler in any "normal" NS-3 application

Refs #1005 (http://redmine.named-data.net/)
diff --git a/apps/ndn-producer.cc b/apps/ndn-producer.cc
index 526e522..3442546 100644
--- a/apps/ndn-producer.cc
+++ b/apps/ndn-producer.cc
@@ -56,6 +56,10 @@
                    StringValue ("/"),
                    MakeNameAccessor (&Producer::m_prefix),
                    MakeNameChecker ())
+    .AddAttribute ("Postfix", "Postfix that is added to the output data (e.g., for adding producer-uniqueness)",
+                   StringValue ("/"),
+                   MakeNameAccessor (&Producer::m_postfix),
+                   MakeNameChecker ())
     .AddAttribute ("PayloadSize", "Virtual payload size for Content packets",
                    UintegerValue (1024),
                    MakeUintegerAccessor(&Producer::m_virtualPayloadSize),
@@ -65,7 +69,6 @@
                    MakeTimeAccessor (&Producer::m_freshness),
                    MakeTimeChecker ())
     ;
-        
   return tid;
 }
     
@@ -117,7 +120,9 @@
   if (!m_active) return;
     
   Ptr<ContentObject> data = Create<ContentObject> (Create<Packet> (m_virtualPayloadSize));
-  data->SetName (Create<Name> (interest->GetName ()));
+  Ptr<Name> dataName = Create<Name> (interest->GetName ());
+  dataName->Append (m_postfix);
+  data->SetName (dataName);
   data->SetFreshness (m_freshness);
 
   NS_LOG_INFO ("node("<< GetNode()->GetId() <<") respodning with ContentObject:\n" << data->GetName ());
diff --git a/apps/ndn-producer.h b/apps/ndn-producer.h
index 1563d12..42f65aa 100644
--- a/apps/ndn-producer.h
+++ b/apps/ndn-producer.h
@@ -60,6 +60,7 @@
 
 private:
   Name m_prefix;
+  Name m_postfix;
   uint32_t m_virtualPayloadSize;
   Time m_freshness;
 };
diff --git a/examples/custom-apps/ndn-api-app.cc b/examples/custom-apps/ndn-api-app.cc
index 90ebece..886a0b8 100644
--- a/examples/custom-apps/ndn-api-app.cc
+++ b/examples/custom-apps/ndn-api-app.cc
@@ -34,35 +34,57 @@
   static TypeId tid = TypeId ("ns3::ndn::ApiApp")
     .SetParent<Application> ()
     .AddConstructor<ApiApp> ()
+    
+    .AddAttribute ("Prefix","Name of the Interest",
+                   StringValue ("/"),
+                   MakeNameAccessor (&ApiApp::m_name),
+                   MakeNameChecker ())
+    .AddAttribute ("LifeTime", "LifeTime for interest packet",
+                   StringValue ("2s"),
+                   MakeTimeAccessor (&ApiApp::m_interestLifetime),
+                   MakeTimeChecker ())
     ;
 
   return tid;
 }
 
 ApiApp::ApiApp ()
+  : m_face (0)
 {
-  // m_handler = CreateObject<Handler> ();
 }
 
 void
 ApiApp::RequestData ()
 {
-  // m_handler->sendInterest ("/test/prefix", boost::bind (&ApiApp::OnData
+  NS_LOG_FUNCTION (this);
+  
+  Ptr<Interest> interest = Create<Interest> ();
+  interest->SetName (m_name);
+  interest->SetInterestLifetime (m_interestLifetime);
+  
+  m_face->ExpressInterest (interest,
+                           MakeCallback (&ApiApp::GotData, this),
+                           MakeNullCallback< void, Ptr<const Interest> > ());
 }
 
 void
+ApiApp::GotData (Ptr<const Interest> origInterest, Ptr<const ContentObject> data)
+{
+  NS_LOG_FUNCTION (this << origInterest->GetName () << data->GetName ());
+  // do nothing else
+}
+    
+void
 ApiApp::StartApplication ()
 {
-  // m_handler->SetNode (GetNode ());
-  // m_handler->StartApplication ();
+  m_face = Create<ApiFace> (GetNode ());
   
-  // Simulator::Schedule (Seconds (1), &::ns3::ndn::ApiApp::RequestData, this);
+  Simulator::Schedule (Seconds (1), &::ns3::ndn::ApiApp::RequestData, this);
 }
 
 void
 ApiApp::StopApplication ()
 {
-  // m_handler->StopApplication ();
 }
 
 } // namespace ndn
diff --git a/examples/custom-apps/ndn-api-app.h b/examples/custom-apps/ndn-api-app.h
index 4e9e487..7709b80 100644
--- a/examples/custom-apps/ndn-api-app.h
+++ b/examples/custom-apps/ndn-api-app.h
@@ -25,7 +25,7 @@
 #include "ns3/network-module.h"
 #include "ns3/ndnSIM-module.h"
 
-// #include "ns3/ndnSIM/ndn.cxx/ndn-handler.h"
+#include "ns3/ndnSIM/ndn.cxx/ndn-api-face.h"
 
 namespace ns3 {
 namespace ndn {
@@ -41,6 +41,9 @@
 private:
   void
   RequestData ();
+
+  void
+  GotData (Ptr<const Interest> origInterest, Ptr<const ContentObject> data);
   
 protected:
   // inherited from Application base class.
@@ -49,9 +52,12 @@
 
   virtual void
   StopApplication ();
-
+  
 private:
-  // Ptr<Handler> m_handler;
+  Ptr<ApiFace> m_face;
+
+  Name m_name;
+  Time m_interestLifetime;
 };
 
 } // namespace ndn
diff --git a/examples/ndn-simple-api.cc b/examples/ndn-simple-api.cc
index ba79af7..587ca55 100644
--- a/examples/ndn-simple-api.cc
+++ b/examples/ndn-simple-api.cc
@@ -75,15 +75,14 @@
 
   // Consumer
   ndn::AppHelper consumerHelper ("ns3::ndn::ApiApp");
-  // // Consumer will request /prefix/0, /prefix/1, ...
-  // consumerHelper.SetPrefix ("/prefix");
-  // consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
+  consumerHelper.SetPrefix ("/prefix");
   consumerHelper.Install (nodes.Get (0)); // first node
 
   // Producer
   ndn::AppHelper producerHelper ("ns3::ndn::Producer");
   // Producer will reply to all requests starting with /prefix
-  producerHelper.SetPrefix ("/prefix");
+  producerHelper.SetPrefix ("/");
+  producerHelper.SetAttribute ("Postfix", StringValue ("/unique/postfix"));
   producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
   producerHelper.Install (nodes.Get (2)); // last node
 
diff --git a/helper/ndn-app-helper.cc b/helper/ndn-app-helper.cc
index 58f62d3..d835da4 100644
--- a/helper/ndn-app-helper.cc
+++ b/helper/ndn-app-helper.cc
@@ -94,7 +94,7 @@
     }
 #endif
   
-  Ptr<App> app = m_factory.Create<App> ();        
+  Ptr<Application> app = m_factory.Create<Application> ();        
   node->AddApplication (app);
         
   return app;
diff --git a/model/ndn-name.h b/model/ndn-name.h
index 0694f0b..d69a75e 100644
--- a/model/ndn-name.h
+++ b/model/ndn-name.h
@@ -96,6 +96,13 @@
   Add (const T &value);
 
   /**
+   * \brief Append components from another name
+   * @param otherName Name to add at the end
+   */
+  inline Name&
+  Append (const Name &otherName);
+  
+  /**
    * \brief Generic constructor operator
    * The object of type T will be appended to the list of components
    */
@@ -266,6 +273,14 @@
   return *this;
 }
 
+inline Name&
+Name::Append (const Name &otherName)
+{
+  std::copy (otherName.begin (), otherName.end (), std::back_inserter (m_prefix));
+  return *this;
+}
+
+
 /**
  * \brief Equality operator for Name
  */
diff --git a/ndn.cxx/detail/filter-entry.h b/ndn.cxx/detail/filter-entry.h
new file mode 100644
index 0000000..97b9a14
--- /dev/null
+++ b/ndn.cxx/detail/filter-entry.h
@@ -0,0 +1,63 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ *
+ * GNU v3.0 license, See the LICENSE file for more information
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef NDN_NDNCXX_DETAIL_FILTER_ENTRY_H
+#define NDN_NDNCXX_DETAIL_FILTER_ENTRY_H
+
+#include <ns3/ndnSIM/utils/trie/trie-with-policy.h>
+#include <ns3/ndnSIM/utils/trie/counting-policy.h>
+
+namespace ns3 {
+namespace ndn {
+
+template<class Callback, class Payload>
+struct FilterEntry : public ns3::SimpleRefCount< FilterEntry<Callback, Payload> >
+{
+public:
+  FilterEntry (Ptr<const Payload> payload)
+    : m_payload (payload)
+  { }
+  
+  void
+  AddCallback (Callback callback)
+  { 
+    m_callback = callback;
+  }
+
+  void
+  ClearCallback ()
+  {
+    m_callback = Callback ();
+  }
+
+  Ptr<const Payload>
+  GetPayload () const
+  {
+    return m_payload;
+  }
+  
+public:
+  Callback m_callback;
+  Ptr<const Payload> m_payload;
+};
+
+
+template<class Callback, class Payload>
+struct FilterEntryContainer :
+    public ns3::ndn::ndnSIM::trie_with_policy<ns3::ndn::Name,
+                                              ns3::ndn::ndnSIM::smart_pointer_payload_traits< FilterEntry<Callback, Payload> >,
+                                              ns3::ndn::ndnSIM::counting_policy_traits>
+{
+};
+
+} // ndn
+} // ns3
+
+#endif // NDN_NDNCXX_DETAIL_FILTER_ENTRY_H
diff --git a/ndn.cxx/ndn-api-face.cc b/ndn.cxx/ndn-api-face.cc
index 6b80251..4c7cc10 100644
--- a/ndn.cxx/ndn-api-face.cc
+++ b/ndn.cxx/ndn-api-face.cc
@@ -16,198 +16,202 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- *         Zhenkai Zhu <zhenkai@cs.ucla.edu>
- *         Chaoyi Bian <bcy@pku.edu.cn>
  */
 
 #include "ndn-api-face.h"
+#include "detail/filter-entry.h"
 
-#include <boost/throw_exception.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/lambda/lambda.hpp>
-#include <boost/lambda/bind.hpp>
-namespace ll = boost::lambda;
+#include <ns3/random-variable.h>
 
-#include <ns3/packet.h>
-
+#include <ns3/ndn-l3-protocol.h>
 #include <ns3/ndn-interest.h>
 #include <ns3/ndn-content-object.h>
 #include <ns3/ndn-face.h>
 #include <ns3/ndn-fib.h>
-#include <ns3/log.h>
 
-typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
-typedef boost::error_info<struct tag_errmsg, int> errmsg_info_int;
+#include <ns3/packet.h>
+#include <ns3/log.h>
 
 using namespace std;
 using namespace boost;
 using namespace ns3;
 
-#define INIT_LOGGER NS_LOG_COMPONENT_DEFINE
-#define _LOG_DEBUG NS_LOG_DEBUG
-#define _LOG_TRACE NS_LOG_TRACE
-#define _LOG_INFO NS_LOG_INFO
-
-
-INIT_LOGGER ("ndn.ApiFace");
+NS_LOG_COMPONENT_DEFINE ("ndn.ApiFace");
 
 namespace ns3 {
 namespace ndn {
 
-// ApiFace::ApiFace()
-//   : m_rand (0, std::numeric_limits<uint32_t>::max ())
-// {
-// }
-
-// ApiFace::~ApiFace()
-// {
-// }
-
-// int
-// ApiFace::publishRawData (const std::string &name, const char *buf, size_t len, int freshness)
-// {
-//   // NS_LOG_INFO ("Requesting Interest: \n" << interestHeader);
-//   _LOG_INFO (">> publishRawData " << name);
-
-//   static ndn::ContentObjectTail trailer;
+class ApiFacePriv
+{
+public:
+  ApiFacePriv ()
+    : m_rand (0, std::numeric_limits<uint32_t>::max ())
+  {
+  }
   
-//   ndn::ContentObject data;
-//   data.SetName (name);
-//   data.SetFreshness (Seconds (freshness));
+  ns3::UniformVariable m_rand; // nonce generator
 
-//   Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t*> (buf), len);
-//   // packet->AddPacketTag (CreateObject<TypeTag> (TypeTag::DATA));
-//   packet->AddHeader (data);
-//   packet->AddTrailer (trailer);
-
-//   m_protocolHandler (packet);
-
-//   m_transmittedContentObjects (&data, packet, this, m_face);
-
-//   return 0;
-// }
+  FilterEntryContainer<ApiFace::DataCallback, Interest> m_pendingInterests;
+  FilterEntryContainer<ApiFace::InterestCallback, Name> m_expectedInterests;
+};
 
 
-// void
-// RawDataCallback2StringDataCallback (ApiFace::StringDataCallback callback, std::string str, const char *buf, size_t len)
-// {
-//   callback (str, string (buf, len));
-// }
+ApiFace::ApiFace (Ptr<Node> node)
+  : Face (node)
+  , m_this (new ApiFacePriv ())
+{
+  NS_ASSERT_MSG (GetNode ()->GetObject<L3Protocol> () != 0,
+                 "NDN stack should be installed on the node " << GetNode ());
 
-// int
-// ApiFace::sendInterestForString (const std::string &strInterest, const StringDataCallback &strDataCallback/*, int retry*/)
-// {
-//   return sendInterest (strInterest, boost::bind (RawDataCallback2StringDataCallback, strDataCallback, _1, _2, _3));
-// }
+  GetNode ()->GetObject<L3Protocol> ()->AddFace (this);
+  this->SetUp (true);
+  this->SetFlags (APPLICATION);
+}
 
-// int ApiFace::sendInterest (const string &strInterest, const RawDataCallback &rawDataCallback)
-// {
-//   // NS_LOG_INFO ("Requesting Interest: \n" << interestHeader);
-//   _LOG_INFO (">> I " << strInterest);
-//   Ptr<ndn::Name> name = Create<ndn::Name> (strInterest);
+ApiFace::~ApiFace ()
+{
+  delete m_this;
+}
 
-//   ndn::Interest interestHeader;
-//   interestHeader.SetNonce            (m_rand.GetValue ());
-//   interestHeader.SetName             (*name);
-//   interestHeader.SetInterestLifetime (Seconds (9.9)); // really long-lived interests
+void
+ApiFace::ExpressInterest (Ptr<Interest> interest,
+                          DataCallback onData,
+                          TimeoutCallback onTimeout/* = MakeNullCallback< void, Ptr<Interest> > ()*/)
+{
+  NS_LOG_INFO (">> I " << interest->GetName ());
 
-//   Ptr<Packet> packet = Create<Packet> ();
-//   // packet->AddPacketTag (CreateObject<TypeTag> (TypeTag::INTEREST));
-//   packet->AddHeader (interestHeader);
-
-//   // NS_LOG_DEBUG (interestHeader);
+  if (interest->GetNonce () == 0)
+    {
+      interest->SetNonce (m_this->m_rand.GetValue ());
+    }
   
-//   // Record the callback
-//   FilterEntryContainer<RawDataCallback>::iterator entry = m_dataCallbacks.find_exact (*name);
-//   if (entry == m_dataCallbacks.end ())
-//     {
-//       pair<FilterEntryContainer<RawDataCallback>::iterator, bool> status =
-//         m_dataCallbacks.insert (*name, Create< FilterEntry<RawDataCallback> > (name));
+  // Record the callback
+  FilterEntryContainer<DataCallback, Interest>::iterator entry =
+    m_this->m_pendingInterests.find_exact (interest->GetName ());
+  if (entry == m_this->m_pendingInterests.end ())
+    {
+      pair<FilterEntryContainer<DataCallback, Interest>::iterator, bool> status =
+        m_this->m_pendingInterests.insert (interest->GetName (), Create< FilterEntry<DataCallback, Interest> > (interest));
 
-//       entry = status.first;
-//     }
-//   entry->payload ()->AddCallback (rawDataCallback);
+      entry = status.first;
+    }
+  entry->payload ()->AddCallback (onData);
 
-//   m_protocolHanler (packet);
-//   m_transmittedInterests (&interestHeader, this, m_face);
+  ReceiveInterest (interest);
+}
+
+void
+ApiFace::SetInterestFilter (Ptr<const Name> prefix, InterestCallback onInterest)
+{
+  NS_LOG_DEBUG ("== setInterestFilter " << *prefix << " (" << GetNode ()->GetId () << ")");
+
+  FilterEntryContainer<InterestCallback, Name>::iterator entry = m_this->m_expectedInterests.find_exact (*prefix);
+  if (entry == m_this->m_expectedInterests.end ())
+    {
+      pair<FilterEntryContainer<InterestCallback, Name>::iterator, bool> status =
+        m_this->m_expectedInterests.insert (*prefix, Create < FilterEntry<InterestCallback, Name> > (prefix));
+
+      entry = status.first;
+    }
+
+  entry->payload ()->AddCallback (onInterest);
+
+  // creating actual face
+  Ptr<ndn::Fib> fib = GetNode ()->GetObject<ndn::Fib> ();
+  Ptr<ndn::fib::Entry> fibEntry = fib->Add (prefix, this, 0);
+  fibEntry->UpdateStatus (this, ndn::fib::FaceMetric::NDN_FIB_GREEN);
+}
+
+void
+ApiFace::ClearInterestFilter (Ptr<const Name> prefix)
+{
+  FilterEntryContainer<InterestCallback, Name>::iterator entry = m_this->m_expectedInterests.find_exact (*prefix);
+  if (entry == m_this->m_expectedInterests.end ())
+    return;
+
+  entry->payload ()->ClearCallback ();
+  m_this->m_expectedInterests.erase (entry);
+}
+
+void
+ApiFace::Put (Ptr<ContentObject> data)
+{
+  NS_LOG_INFO (">> D " << data->GetName ());
   
-//   return 0;
-// }
+  ReceiveData (data);
+}
 
-// int ApiFace::setInterestFilter (const string &prefix, const InterestCallback &interestCallback)
-// {
-//   NS_LOG_DEBUG ("== setInterestFilter " << prefix << " (" << GetNode ()->GetId () << ")");
-//   Ptr<ndn::Name> name = Create<ndn::Name> (prefix);
 
-//   FilterEntryContainer<InterestCallback>::iterator entry = m_interestCallbacks.find_exact (*name);
-//   if (entry == m_interestCallbacks.end ())
-//     {
-//       pair<FilterEntryContainer<InterestCallback>::iterator, bool> status =
-//         m_interestCallbacks.insert (*name, Create < FilterEntry<InterestCallback> > (name));
 
-//       entry = status.first;
-//     }
 
-//   entry->payload ()->AddCallback (interestCallback);
+///////////////////////////////////////////////
+// private stuff
 
-//   // creating actual face
-//   Ptr<ndn::Fib> fib = GetNode ()->GetObject<ndn::Fib> ();
-//   Ptr<ndn::fib::Entry> fibEntry = fib->Add (name, m_face, 0);
-//   fibEntry->UpdateStatus (m_face, ndn::fib::FaceMetric::NDN_FIB_GREEN);
 
-//   return 0;
-// }
+bool
+ApiFace::SendInterest (Ptr<const Interest> interest)
+{
+  NS_LOG_FUNCTION (this << interest);
 
-// void
-// ApiFace::clearInterestFilter (const std::string &prefix)
-// {
-//   Ptr<ndn::Name> name = Create<ndn::Name> (prefix);
-
-//   FilterEntryContainer<InterestCallback>::iterator entry = m_interestCallbacks.find_exact (*name);
-//   if (entry == m_interestCallbacks.end ())
-//     return;
-
-//   entry->payload ()->ClearCallback ();
-// }
-
-// void
-// ApiFace::OnInterest (const Ptr<const ndn::Interest> &interest, Ptr<Packet> packet)
-// {
-//   ndn::App::OnInterest (interest, packet);
-
-//   // the app cannot set several filters for the same prefix
-//   FilterEntryContainer<InterestCallback>::iterator entry = m_interestCallbacks.longest_prefix_match (interest->GetName ());
-//   if (entry == m_interestCallbacks.end ())
-//     {
-//       _LOG_DEBUG ("No Interest callback set");
-//       return;
-//     }
+  NS_LOG_DEBUG ("<< I " << interest->GetName ());
   
-//   entry->payload ()->m_callback (lexical_cast<string> (interest->GetName ()));  
-// }
+  if (!IsUp ())
+    {
+      return false;
+    }
 
-// void
-// ApiFace::OnContentObject (const Ptr<const ndn::ContentObject> &contentObject,
-//                               Ptr<Packet> payload)
-// {
-//   ndn::App::OnContentObject (contentObject, payload);
-//   NS_LOG_DEBUG ("<< D " << contentObject->GetName ());
+  // the app cannot set several filters for the same prefix
+  FilterEntryContainer<InterestCallback, Name>::iterator entry =
+    m_this->m_expectedInterests.longest_prefix_match (interest->GetName ());
+  if (entry == m_this->m_expectedInterests.end ())
+    {
+      return false;
+    }
+  
+  entry->payload ()->m_callback (entry->payload ()->GetPayload (), interest);
+  return true;
+}
 
-//   FilterEntryContainer<RawDataCallback>::iterator entry = m_dataCallbacks.longest_prefix_match (contentObject->GetName ());
-//   if (entry == m_dataCallbacks.end ())
-//     {
-//       _LOG_DEBUG ("No Data callback set");
-//       return;
-//     }
+bool
+ApiFace::SendData (Ptr<const ContentObject> data)
+{
+  // data has been send out from NDN stack towards the application
+  NS_LOG_DEBUG ("<< D " << data->GetName ());
 
-//   while (entry != m_dataCallbacks.end ())
-//     {
-//       entry->payload ()->m_callback (lexical_cast<string> (contentObject->GetName ()), payload);
-//       m_dataCallbacks.erase (entry);
 
-//       entry = m_dataCallbacks.longest_prefix_match (contentObject->GetName ());
-//     }
-// }
+  NS_LOG_FUNCTION (this << data);
+
+  if (!IsUp ())
+    {
+      return false;
+    }
+
+  FilterEntryContainer<DataCallback, Interest>::iterator entry =
+    m_this->m_pendingInterests.longest_prefix_match (data->GetName ());
+  if (entry == m_this->m_pendingInterests.end ())
+    {
+      return false;
+    }
+
+  while (entry != m_this->m_pendingInterests.end ())
+    {
+      entry->payload ()->m_callback (entry->payload ()->GetPayload (), data);
+      m_this->m_pendingInterests.erase (entry);
+
+      entry = m_this->m_pendingInterests.longest_prefix_match (data->GetName ());
+    }
+  m_this->m_pendingInterests.erase (entry);
+  
+  return true;
+}
+
+std::ostream&
+ApiFace::Print (std::ostream &os) const
+{
+  os << "dev=ApiFace(" << GetId () << ")";
+  return os;
+}
+
 
 }
 }
diff --git a/ndn.cxx/ndn-api-face.h b/ndn.cxx/ndn-api-face.h
index 133f29c..8c589bb 100644
--- a/ndn.cxx/ndn-api-face.h
+++ b/ndn.cxx/ndn-api-face.h
@@ -23,144 +23,90 @@
 #ifndef NDN_API_FACE_H
 #define NDN_API_FACE_H
 
-#include <boost/exception/all.hpp>
-#include <boost/function.hpp>
-#include <string>
-
 #include <ns3/ptr.h>
 #include <ns3/node.h>
-#include <ns3/random-variable.h>
-#include <ns3/ndn-app.h>
+#include <ns3/callback.h>
+#include <ns3/ndn-face.h>
 #include <ns3/ndn-name.h>
 
-#include <ns3/ndnSIM/utils/trie/trie-with-policy.h>
-#include <ns3/ndnSIM/utils/trie/counting-policy.h>
-
 namespace ns3 {
 namespace ndn {
 
-template<class Callback>
-struct FilterEntry : public ns3::SimpleRefCount< FilterEntry<Callback> >
-{
-public:
-  FilterEntry (ns3::Ptr<const ns3::ndn::Name> prefix)
-    : m_prefix (prefix)
-  { }
-  
-  const ns3::ndn::Name &
-  GetPrefix () const
-  { return *m_prefix; }
+class ApiFacePriv;
 
-  void
-  AddCallback (Callback callback)
-  { 
-    m_callback = callback;
-  }
-
-  void
-  ClearCallback ()
-  {
-    m_callback = 0;
-  }
-  
-public:
-  ns3::Ptr<const ns3::ndn::Name> m_prefix; ///< \brief Prefix of the PIT entry
-  Callback m_callback;
-};
-
-
-template<class Callback>
-struct FilterEntryContainer :
-    public ns3::ndn::ndnSIM::trie_with_policy<ns3::ndn::Name,
-                                              ns3::ndn::ndnSIM::smart_pointer_payload_traits< FilterEntry<Callback> >,
-                                              ns3::ndn::ndnSIM::counting_policy_traits>
-{
-};
-
-
-struct OperationException : virtual boost::exception, virtual std::exception { };
 /**
  * \ingroup sync
  * @brief A handler for NDN; clients of this code do not need to deal
  * with NDN API directly
  */
 class ApiFace
-  // : private ns3::ndn::Face
+  : public ns3::ndn::Face
 {
 public:
-  // typedef boost::function<void (const ndn::Name &, Ptr<Packet>)> DataCallback;
-  // typedef boost::function<void (const ndn::Name &)> InterestCallback;
-  
-  // /**
-  //  * @brief initialize the handler; a lot of things needs to be done. 1) init
-  //  * keystore 2) init keylocator 3) start a thread to hold a loop of ccn_run
-  //  *
-  //  */
-  // ApiFace (Ptr<Node> node);
-  // ~ApiFace ();
-
-  // /**
-  //  * @brief send Interest; need to grab lock m_mutex first
-  //  *
-  //  * @param name the Interest name
-  //  * @param dataCallback the callback function to deal with the returned data
-  //  * @return the return code of ccn_express_interest
-  //  */
-  // // int
-  // // sendInterestForString (const std::string &strInterest, const StringDataCallback &strDataCallback/*, int retry = 0*/);
-
-  // int
-  // sendInterest (const ndn::Name &name, const DataCallback &rawDataCallback/*, int retry = 0*/);
-  
-  // /**
-  //  * @brief set Interest filter (specify what interest you want to receive)
-  //  *
-  //  * @param prefix the prefix of Interest
-  //  * @param interestCallback the callback function to deal with the returned data
-  //  * @return the return code of ccn_set_interest_filter
-  //  */
-  // int
-  // setInterestFilter (const ndn::Name &prefix, const InterestCallback &interestCallback);
-
-  // /**
-  //  * @brief clear Interest filter
-  //  * @param prefix the prefix of Interest
-  //  */
-  // void
-  // clearInterestFilter (const std::string &prefix);
+  typedef Callback<void, Ptr<const Name>,     Ptr<const Interest> > InterestCallback;
+  typedef Callback<void, Ptr<const Interest>, Ptr<const ContentObject> > DataCallback;
+  typedef Callback<void, Ptr<const Interest> > TimeoutCallback;
 
   /**
-   * @brief publish data and put it to local ccn content store; need to grab
-   * lock m_mutex first
+   * @brief initialize the handler; a lot of things needs to be done. 1) init
+   * keystore 2) init keylocator 3) start a thread to hold a loop of ccn_run
    *
-   * @param name the name for the data object
-   * @param dataBuffer the data to be published
-   * @param freshness the freshness time for the data object
-   * @return code generated by NDN library calls, >0 if success
    */
-  // int
-  // publishStringData (const std::string &name, const std::string &dataBuffer, int freshness)
-  // {
-  //   return publishRawData (name, dataBuffer.c_str(), dataBuffer.length(), freshness);
-  // }
+  ApiFace (Ptr<Node> node);
+  ~ApiFace ();
 
-  // int
-  // publishRawData (const std::string &name, const char *buf, size_t len, int freshness);
+  /**
+   * @brief Express Interest
+   *
+   * @param name the Interest name
+   * @param onData the callback function to deal with the returned data
+   * @param onTimeout the callback function to deal with timeouts
+   */
+  void
+  ExpressInterest (Ptr<Interest> interest,
+                   DataCallback onData,
+                   TimeoutCallback onTimeout); // = MakeNullCallback< void, Ptr<Interest> > ()
+
+  /**
+   * @brief set Interest filter (specify what interest you want to receive)
+   *
+   * @param prefix the prefix of Interest
+   * @param onInterest the callback function to deal with the returned data
+   */
+  void
+  SetInterestFilter (Ptr<const Name> prefix, InterestCallback onInterest);
+
+  /**
+   * @brief clear Interest filter
+   * @param prefix the prefix of Interest
+   */
+  void
+  ClearInterestFilter (Ptr<const Name> prefix);
+
+  /**
+   * @brief Publish data
+   * @param data Data packet to publish
+   */
+  void
+  Put (Ptr<ContentObject> data);
+
+public:
+  virtual bool
+  SendInterest (Ptr<const Interest> interest);
+
+  virtual bool
+  SendData (Ptr<const ContentObject> data);
+
+  virtual std::ostream&
+  Print (std::ostream &os) const;
 
 private:
-  // // from ndn::App
-  // virtual void
-  // OnInterest (const ns3::Ptr<const ns3::ndn::Interest> &interest, ns3::Ptr<ns3::Packet> packet);
- 
-  // virtual void
-  // OnContentObject (const ns3::Ptr<const ns3::ndn::ContentObject> &contentObject,
-  //                  ns3::Ptr<ns3::Packet> payload);
+  ApiFace () : Face (0) {}
+  ApiFace (const ApiFace &) : Face (0) {}
+  ApiFace& operator= (const ApiFace &) { return *this; }
 
 private:
-  ns3::UniformVariable m_rand; // nonce generator
-
-  FilterEntryContainer<RawDataCallback> m_dataCallbacks;
-  FilterEntryContainer<InterestCallback> m_interestCallbacks;
+  ApiFacePriv *m_this;
 };
 
 }
diff --git a/wscript b/wscript
index 03ba951..9407508 100644
--- a/wscript
+++ b/wscript
@@ -108,14 +108,14 @@
                                        'apps/*.cc',
                                        'utils/**/*.cc',
                                        'helper/**/*.cc',
-                                       # 'ndn.cxx/**/*.cc',
+                                       'ndn.cxx/**/*.cc',
                                        ])
     module.full_headers = [p.path_from(bld.path) for p in bld.path.ant_glob([
                            'utils/**/*.h',
                            'model/**/*.h',
                            'apps/**/*.h',
                            'helper/**/*.h',
-                           # 'ndn.cxx/**/*.h',
+                           'ndn.cxx/**/*.h',
                            ])]
 
     headers.source = [
@@ -149,11 +149,10 @@
         "model/fw/ndn-forwarding-strategy.h",
         "model/fw/ndn-fw-tag.h",
 
-        # "utils/batches.h",
         "utils/ndn-limits.h",
         "utils/ndn-rtt-estimator.h",
-        # "utils/weights-path-stretch-tag.h",
 
+        "ndn.cxx/ndn-api-face.h",
         ]
 
     if 'topology' in bld.env['NDN_plugins']: