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/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