rib: reimplement auto prefix propagation based on readvertise

Change-Id: I6c4d81b829cf78084d26121c81d977d0a86c9a0c
Refs: #3819
diff --git a/rib/service.cpp b/rib/service.cpp
index 48ff69c..a91a93e 100644
--- a/rib/service.cpp
+++ b/rib/service.cpp
@@ -25,9 +25,9 @@
 
 #include "service.hpp"
 
-#include "auto-prefix-propagator.hpp"
 #include "fib-updater.hpp"
 #include "readvertise/client-to-nlsr-readvertise-policy.hpp"
+#include "readvertise/host-to-gateway-readvertise-policy.hpp"
 #include "readvertise/nfd-rib-readvertise-destination.hpp"
 #include "readvertise/readvertise.hpp"
 
@@ -51,6 +51,8 @@
 static const std::string CFG_PREFIX_PROPAGATE = "auto_prefix_propagate";
 static const std::string CFG_READVERTISE_NLSR = "readvertise_nlsr";
 static const Name READVERTISE_NLSR_PREFIX = "/localhost/nlsr";
+static const uint64_t PROPAGATE_DEFAULT_COST = 15;
+static const time::milliseconds PROPAGATE_DEFAULT_TIMEOUT = 10_s;
 
 static ConfigSection
 loadConfigSectionFromFile(const std::string& filename)
@@ -194,13 +196,33 @@
       m_ribManager.enableLocalhop(value, filename);
     }
     else if (key == CFG_PREFIX_PROPAGATE) {
-      if (m_prefixPropagator == nullptr) {
-        m_prefixPropagator = make_unique<AutoPrefixPropagator>(m_nfdController, m_keyChain,
-                                                               m_scheduler, m_rib);
-      }
-      m_prefixPropagator->loadConfig(item.second);
-      m_prefixPropagator->enable();
       wantPrefixPropagate = true;
+
+      if (!m_readvertisePropagation) {
+        NFD_LOG_DEBUG("Enabling automatic prefix propagation");
+
+        auto parameters = ndn::nfd::ControlParameters()
+          .setCost(PROPAGATE_DEFAULT_COST)
+          .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT);
+        auto cost = item.second.get_optional<uint64_t>("cost");
+        if (cost) {
+          parameters.setCost(*cost);
+        }
+
+        auto options = ndn::nfd::CommandOptions()
+          .setPrefix(RibManager::LOCALHOP_TOP_PREFIX)
+          .setTimeout(PROPAGATE_DEFAULT_TIMEOUT);
+        auto timeout = item.second.get_optional<uint64_t>("timeout");
+        if (timeout) {
+          options.setTimeout(time::milliseconds(*timeout));
+        }
+
+        m_readvertisePropagation = make_unique<Readvertise>(
+          m_rib,
+          m_scheduler,
+          make_unique<HostToGatewayReadvertisePolicy>(m_keyChain, item.second),
+          make_unique<NfdRibReadvertiseDestination>(m_nfdController, m_rib, options, parameters));
+      }
     }
     else if (key == CFG_READVERTISE_NLSR) {
       wantReadvertiseNlsr = ConfigFile::parseYesNo(item, CFG_SECTION + "." + CFG_READVERTISE_NLSR);
@@ -210,17 +232,19 @@
     }
   }
 
-  if (!wantPrefixPropagate && m_prefixPropagator != nullptr) {
-    m_prefixPropagator->disable();
+  if (!wantPrefixPropagate && m_readvertisePropagation != nullptr) {
+    NFD_LOG_DEBUG("Disabling automatic prefix propagation");
+    m_readvertisePropagation.reset();
   }
 
   if (wantReadvertiseNlsr && m_readvertiseNlsr == nullptr) {
     NFD_LOG_DEBUG("Enabling readvertise-to-nlsr");
+    auto options = ndn::nfd::CommandOptions().setPrefix(READVERTISE_NLSR_PREFIX);
     m_readvertiseNlsr = make_unique<Readvertise>(
       m_rib,
       m_scheduler,
       make_unique<ClientToNlsrReadvertisePolicy>(),
-      make_unique<NfdRibReadvertiseDestination>(m_nfdController, READVERTISE_NLSR_PREFIX, m_rib));
+      make_unique<NfdRibReadvertiseDestination>(m_nfdController, m_rib, options));
   }
   else if (!wantReadvertiseNlsr && m_readvertiseNlsr != nullptr) {
     NFD_LOG_DEBUG("Disabling readvertise-to-nlsr");