ndn.cxx: Initial work to introduce full NDN application API to ndnSIM

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
new file mode 100644
index 0000000..3df6a27
--- /dev/null
+++ b/examples/custom-apps/ndn-api-app.cc
@@ -0,0 +1,70 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndn-api-app.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.ApiApp");
+
+namespace ns3 {
+namespace ndn {
+
+// Necessary if you are planning to use ndn::AppHelper
+NS_OBJECT_ENSURE_REGISTERED (ApiApp);
+
+TypeId
+ApiApp::GetTypeId ()
+{
+  static TypeId tid = TypeId ("ns3::ndn::ApiApp")
+    .SetParent<Application> ()
+    .AddConstructor<ApiApp> ()
+    ;
+
+  return tid;
+}
+
+ApiApp::ApiApp ()
+{
+  m_handler = CreateObject<Handler> ();
+}
+
+void
+ApiApp::RequestData ()
+{
+  m_handler->sendInterest ("/test/prefix", boost::bind (&ApiApp::OnData
+}
+
+void
+ApiApp::StartApplication ()
+{
+  m_handler->SetNode (GetNode ());
+  m_handler->StartApplication ();
+  
+  Simulator::Schedule (Seconds (1), &::ns3::ndn::ApiApp::RequestData, this);
+}
+
+void
+ApiApp::StopApplication ()
+{
+  m_handler->StopApplication ();
+}
+
+} // namespace ndn
+} // namespace ns3
+
diff --git a/examples/custom-apps/ndn-api-app.h b/examples/custom-apps/ndn-api-app.h
new file mode 100644
index 0000000..26df590
--- /dev/null
+++ b/examples/custom-apps/ndn-api-app.h
@@ -0,0 +1,60 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef NDN_EXAMPLES_API_APP_H
+#define NDN_EXAMPLES_API_APP_H
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/ndnSIM-module.h"
+
+#include "ns3/ndnSIM/ndn.cxx/ndn-handler.h"
+
+namespace ns3 {
+namespace ndn {
+
+class ApiApp : public Application
+{
+public:
+  static TypeId
+  GetTypeId ();
+
+  ApiApp ();
+
+private:
+  void
+  RequestData ();
+  
+protected:
+  // inherited from Application base class.
+  virtual void
+  StartApplication ();
+
+  virtual void
+  StopApplication ();
+
+private:
+  Ptr<Handler> m_handler;
+};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDN_EXAMPLES_API_APP_H
diff --git a/examples/ndn-simple-api.cc b/examples/ndn-simple-api.cc
new file mode 100644
index 0000000..ba79af7
--- /dev/null
+++ b/examples/ndn-simple-api.cc
@@ -0,0 +1,96 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+// ndn-simple.cc
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/ndnSIM-module.h"
+
+using namespace ns3;
+
+/**
+ * This scenario simulates a very simple network topology:
+ *
+ *
+ *      +----------+     1Mbps      +--------+     1Mbps      +----------+
+ *      | consumer | <------------> | router | <------------> | producer |
+ *      +----------+         10ms   +--------+          10ms  +----------+
+ *
+ *
+ * Consumer requests data from producer with frequency 10 interests per second
+ * (interests contain constantly increasing sequence number).
+ *
+ * For every received interest, producer replies with a data packet, containing
+ * 1024 bytes of virtual payload.
+ *
+ * To run scenario and see what is happening, use the following command:
+ *
+ *     NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
+ */
+
+int 
+main (int argc, char *argv[])
+{
+  // setting default parameters for PointToPoint links and channels
+  Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
+  Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
+  Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
+
+  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
+  CommandLine cmd;
+  cmd.Parse (argc, argv);
+
+  // Creating nodes
+  NodeContainer nodes;
+  nodes.Create (3);
+
+  // Connecting nodes using two links
+  PointToPointHelper p2p;
+  p2p.Install (nodes.Get (0), nodes.Get (1));
+  p2p.Install (nodes.Get (1), nodes.Get (2));
+
+  // Install NDN stack on all nodes
+  ndn::StackHelper ndnHelper;
+  ndnHelper.SetDefaultRoutes (true);
+  ndnHelper.InstallAll ();
+
+  // Installing applications
+
+  // 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.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.SetAttribute ("PayloadSize", StringValue("1024"));
+  producerHelper.Install (nodes.Get (2)); // last node
+
+  Simulator::Stop (Seconds (20.0));
+
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  return 0;
+}
diff --git a/examples/wscript b/examples/wscript
index c9850ae..437ed26 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -85,3 +85,9 @@
 
     obj = bld.create_ns3_program('ndn-simple-with-pit-count-stats', all_modules)
     obj.source = 'ndn-simple-with-pit-count-stats.cc'
+
+    obj = bld.create_ns3_program('ndn-simple-api', all_modules)
+    obj.source = [
+        'ndn-simple-api.cc',
+        'custom-apps/ndn-api-app.cc'
+        ]