helper: Introduce helper to manage NetworkRegionTable

This is to add a mechanism to configure nfd NetworkRegionTable.

Refs: #3806
Change-Id: I13091f481a3d0e45ef46983ea12c84057682460c
diff --git a/examples/ndn-simple-for-nrt-helper.cpp b/examples/ndn-simple-for-nrt-helper.cpp
new file mode 100644
index 0000000..af67ac6
--- /dev/null
+++ b/examples/ndn-simple-for-nrt-helper.cpp
@@ -0,0 +1,131 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2016  Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM 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
+ * ndnSIM, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/ndnSIM-module.h"
+
+/**
+ * This scenario simulates a very simple network topology:
+ *
+ *
+ *
+ *                             ----------------------------- (Producer)
+ *                            /                                   |
+ *                           /                                    |
+ *    (Consumer) ------ (Non-Producer-Region Router) ----- (Produer-Region-Network Router)
+ *                                                                |
+ *                                                                |
+ *                                                               ( )
+ *
+ *
+ *
+ *
+ * Consumer sends interest with Link object attatched. Non-Producer-Region Router will
+ * forward the interest based on Forwarding Hint(dalegationName in Link object) toward
+ * delegationName direction because the router is not in
+ * ProducerRegion. Producer-Region-Network checks incomming interests and finds out the
+ * interest has reached ProducerRegion, thus the router will forward the incoming interest
+ * based on interestName.
+ *
+ * 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=nfd.Forwarder=logic ./waf --run=ndn-simple-for-nrt-helper
+ */
+
+namespace ns3 {
+
+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
+  Ptr<Node> consumer = CreateObject<Node>();
+  Ptr<Node> intRouter = CreateObject<Node>();
+  NodeContainer uclaRegion;
+  uclaRegion.Create(3);
+
+  // Connecting nodes using two links
+  PointToPointHelper p2p;
+  p2p.Install(consumer, intRouter);
+  p2p.Install(intRouter, uclaRegion.Get(0));
+  p2p.Install(intRouter, uclaRegion.Get(1));
+  p2p.Install(uclaRegion.Get(0), uclaRegion.Get(1));
+  p2p.Install(uclaRegion.Get(1), uclaRegion.Get(2));
+
+  // Install NDN stack on all nodes
+  ndn::StackHelper ndnHelper;
+  ndnHelper.SetDefaultRoutes(true);
+  ndnHelper.InstallAll();
+
+  // Install Routes Manually
+  ndn::FibHelper::AddRoute(intRouter, ndn::Name("/ucla"), uclaRegion.Get(1), 1);
+
+  // Configure NetworkRegionTable
+  ndn::NetworkRegionTableHelper::AddRegionName(uclaRegion, ndn::Name("/ucla"));
+
+  // Installing applications
+
+  // Consumer
+  ndn::AppHelper requesterHelper("RequesterApp");
+  requesterHelper.SetAttribute("Name", StringValue("/ndnSIM/someData"));
+  requesterHelper.SetAttribute("Delegation", StringValue("/ucla1"));
+  requesterHelper.Install(consumer).Start(Seconds(1));
+
+  requesterHelper.SetAttribute("Name", StringValue("/ndnSIM/anotherData"));
+  requesterHelper.Install(consumer).Start(Seconds(2));
+
+  requesterHelper.SetAttribute("Name", StringValue("/ndnSIM/yetAnotherData"));
+  requesterHelper.SetAttribute("Delegation", StringValue("/non-existing"));
+  requesterHelper.Install(consumer).Start(Seconds(3));
+
+  // Producer
+  ndn::AppHelper producerHelper("ns3::ndn::Producer");
+  producerHelper.SetPrefix("/ndnSIM");
+  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+  producerHelper.Install(uclaRegion.Get(0));
+
+  Simulator::Stop(Seconds(20.0));
+
+  Simulator::Run();
+  Simulator::Destroy();
+
+  return 0;
+}
+
+} // namespace ns3
+
+int
+main(int argc, char* argv[])
+{
+  return ns3::main(argc, argv);
+}
+
diff --git a/examples/ndn-simple-for-nrt-helper/requester-app.cpp b/examples/ndn-simple-for-nrt-helper/requester-app.cpp
new file mode 100644
index 0000000..6eee63c
--- /dev/null
+++ b/examples/ndn-simple-for-nrt-helper/requester-app.cpp
@@ -0,0 +1,111 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2016  Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM 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
+ * ndnSIM, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "ns3/core-module.h"
+#include "ns3/ndnSIM/helper/ndn-stack-helper.hpp"
+#include "ns3/ndnSIM/apps/ndn-app.hpp"
+#include "ns3/ndnSIM/ndn-cxx/link.hpp"
+#include "ns3/ndnSIM/ndn-cxx/interest.hpp"
+
+NS_LOG_COMPONENT_DEFINE("RequesterApp");
+
+namespace ns3 {
+namespace ndn {
+
+class RequesterApp : public App
+{
+public:
+  static TypeId
+  GetTypeId()
+  {
+    static TypeId tid = TypeId("RequesterApp")
+      .SetParent<App>()
+      .AddConstructor<RequesterApp>()
+      .AddAttribute("Name", "Name of data to request",
+                    StringValue("/data/name"),
+                    MakeNameAccessor(&RequesterApp::m_name), MakeNameChecker())
+      .AddAttribute("Delegation", "Delegation name to attach to Interest",
+                    StringValue("/"),
+                    MakeNameAccessor(&RequesterApp::getDelegation, &RequesterApp::setDelegation), MakeNameChecker())
+      ;
+
+    return tid;
+  }
+
+protected:
+  virtual void
+  StartApplication() override
+  {
+    App::StartApplication();
+
+    Simulator::Schedule(Seconds(1.0), &RequesterApp::sendInterest, this);
+  }
+
+  virtual void
+  StopApplication() override
+  {
+    // do cleanup
+    App::StopApplication();
+    m_face->close();
+  }
+
+private:
+  void
+  setDelegation(const Name& delegation)
+  {
+    m_delegation = delegation;
+
+    m_link = ::ndn::Link(Name(m_name).append("/LINK"));
+    m_link.addDelegation(1, m_delegation);
+    ndn::StackHelper::getKeyChain().sign(m_link, ::ndn::security::SigningInfo(::ndn::security::SigningInfo::SIGNER_TYPE_SHA256));
+
+    NS_LOG_DEBUG("Created Link Object "<< m_link);
+  }
+
+  Name
+  getDelegation() const
+  {
+    return m_delegation;
+  }
+
+  void
+  sendInterest()
+  {
+    auto interest = make_shared<Interest>(m_name);
+    interest->setInterestLifetime(time::seconds(1));
+    if (m_delegation.size() > 0) {
+      interest->setLink(m_link.wireEncode());
+    }
+
+    NS_LOG_DEBUG("Sending an Interest for "<< *interest);
+
+    m_transmittedInterests(interest, this, m_face);
+    m_appLink->onReceiveInterest(*interest);
+  }
+
+private:
+  Name m_name;
+  Name m_delegation;
+  ::ndn::Link m_link;
+};
+
+NS_OBJECT_ENSURE_REGISTERED(RequesterApp);
+
+} // namespace ndn
+} // namespace ns3