management: Correcting self-registration using raw NFD FIB Management protocol

Although this will not be useful later when NRD is ready, for now we can
use NFD FIB management protocol directly to do basic tests.

Change-Id: Id79c30b0a0bbd3f296767b08d9974c8b99c7dc4c
diff --git a/src/management/nfd-controller.cpp b/src/management/nfd-controller.cpp
index c6fa7e7..735c927 100644
--- a/src/management/nfd-controller.cpp
+++ b/src/management/nfd-controller.cpp
@@ -26,15 +26,33 @@
                                const SuccessCallback& onSuccess,
                                const FailCallback&    onFail)
 {
-  startFibCommand("add-nexthop",
+  // two stage process:
+  // 1. insert FIB entry
+  // 2. add-nexthop <self> to the FIB entry
+
+  // Step 1.
+  startFibCommand("insert",
                   FibManagementOptions()
-                  .setName(prefixToRegister)
-                  .setFaceId(0) // self-registration
-                  .setCost(0),
+                    .setName(prefixToRegister),
+                  bind(&Controller::selfRegisterPrefixAddNextop, this, _1, onSuccess, onFail),
+                  onFail);
+}
+
+void
+Controller::selfRegisterPrefixAddNextop(const FibManagementOptions& entry,
+                                        const SuccessCallback& onSuccess,
+                                        const FailCallback&    onFail)
+{
+  // Step 2.
+  startFibCommand("add-nexthop",
+                  FibManagementOptions(entry) // prefixToRegister should be inside the entry
+                    .setFaceId(0) // self-registration
+                    .setCost(0),
                   bind(&Controller::recordSelfRegisteredFaceId, this, _1, onSuccess),
                   onFail);
 }
 
+
 void
 Controller::selfDeregisterPrefix(const Name& prefixToRegister,
                                  const SuccessCallback& onSuccess,
@@ -49,8 +67,8 @@
 
   startFibCommand("remove-nexthop",
                   FibManagementOptions()
-                  .setName(prefixToRegister)
-                  .setFaceId(m_faceId),
+                    .setName(prefixToRegister)
+                    .setFaceId(m_faceId),
                   bind(onSuccess), onFail);
 }