rib: change FIB mocking mechanism

Previously, RIB test suites mock FIB updates by invoking RibManager
or Rib's private methods from a callback. In this commit, Rib class
exposes a `mockFibResponse` function variable, so that test cases
can directly specify FibUpdater's response without needing to invoke
private methods. This further allows replacing these private methods
with lambdas.

Also, logic for beginning RibUpdateBatch is abstracted out of control
command handlers, in preparation for PrefixAnnouncement-based RIB
update functions.

refs #4683

Change-Id: I0c95d8daa1458c704c7352a7809e6bed69134642
diff --git a/rib/rib.cpp b/rib/rib.cpp
index 6a221ea..542a582 100644
--- a/rib/rib.cpp
+++ b/rib/rib.cpp
@@ -396,18 +396,27 @@
   // Until task #1698, each RibUpdateBatch contains exactly one RIB update
   BOOST_ASSERT(batch.size() == 1);
 
-  const Rib::UpdateSuccessCallback& managerSuccessCallback = item.managerSuccessCallback;
-  const Rib::UpdateFailureCallback& managerFailureCallback = item.managerFailureCallback;
+  auto fibSuccessCb = bind(&Rib::onFibUpdateSuccess, this, batch, _1, item.managerSuccessCallback);
+  auto fibFailureCb = bind(&Rib::onFibUpdateFailure, this, item.managerFailureCallback, _1, _2);
 
-  m_fibUpdater->computeAndSendFibUpdates(batch,
-                                         bind(&Rib::onFibUpdateSuccess, this,
-                                              batch, _1, managerSuccessCallback),
-                                         bind(&Rib::onFibUpdateFailure, this,
-                                              managerFailureCallback, _1, _2));
-
-  if (m_onSendBatchFromQueue != nullptr) {
-    m_onSendBatchFromQueue(batch);
+#ifdef WITH_TESTS
+  if (mockFibResponse != nullptr) {
+    m_fibUpdater->computeAndSendFibUpdates(batch, bind([]{}), bind([]{}));
+    bool shouldFibSucceed = mockFibResponse(batch);
+    if (wantMockFibResponseOnce) {
+      mockFibResponse = nullptr;
+    }
+    if (shouldFibSucceed) {
+      fibSuccessCb(m_fibUpdater->m_inheritedRoutes);
+    }
+    else {
+      fibFailureCb(504, "mocked failure");
+    }
+    return;
   }
+#endif
+
+  m_fibUpdater->computeAndSendFibUpdates(batch, fibSuccessCb, fibFailureCb);
 }
 
 void