tools: add prefix registration after creating the resolved hub face

Change-Id: Iaf845e440ec627eaee48d16d16a13245c8e7ac59
refs: #1578
diff --git a/tools/ndn-autoconfig.cpp b/tools/ndn-autoconfig.cpp
index d49c181..84a73d3 100644
--- a/tools/ndn-autoconfig.cpp
+++ b/tools/ndn-autoconfig.cpp
@@ -194,6 +194,17 @@
   onHubConnectSuccess(const ndn::nfd::ControlParameters& resp)
   {
     std::cerr << "Successfully created face: " << resp << std::endl;
+
+    // Register a prefix in RIB
+    ndn::nfd::ControlParameters ribParameters;
+    ribParameters
+      .setName("/ndn")
+      .setFaceId(resp.getFaceId());
+
+    m_controller.start<ndn::nfd::RibRegisterCommand>(
+      ribParameters,
+      bind(&NdnAutoconfig::onPrefixRegistrationSuccess, this, _1),
+      bind(&NdnAutoconfig::onPrefixRegistrationError, this, _1, _2));
   }
 
   void
@@ -278,6 +289,20 @@
     return false;
   }
 
+  void
+  onPrefixRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult)
+  {
+    std::cerr << "Successful in name registration: " << commandSuccessResult << std::endl;
+  }
+
+  void
+  onPrefixRegistrationError(uint32_t code, const std::string& error)
+  {
+    std::ostringstream os;
+    os << "Failed in name registration, " << error << " (code: " << code << ")";
+    throw Error(os.str());
+  }
+
 private:
   ndn::Face m_face;
   ndn::nfd::Controller m_controller;