src: Recreating face in case of face deletion by NFD
Change-Id: Idd1d0b7f521e574ace38d6f671a682622d98209d
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index 8b5d668..48af899 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -256,19 +256,62 @@
}
void
-Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
- uint64_t faceCost, uint64_t timeout)
+Fib::createFace(const std::string& faceUri,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure)
{
ndn::nfd::ControlParameters faceParameters;
faceParameters
- .setUri(faceUri);
-
+ .setUri(faceUri);
m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters,
- ndn::bind(&Fib::registerPrefixInNfd, this,_1,
- namePrefix, faceCost, timeout),
- ndn::bind(&Fib::onFailure, this, _1, _2,
- "Failed in name registration"));
-
+ onSuccess,
+ onFailure);
+}
+
+void
+Fib::destroyFace(const std::string& faceUri,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure)
+{
+ createFace(faceUri,
+ ndn::bind(&Fib::destroyFaceInNfd, this, _1, onSuccess, onFailure),
+ onFailure);
+}
+
+void
+Fib::destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure)
+{
+ ndn::nfd::ControlParameters faceParameters;
+ faceParameters
+ .setFaceId(faceDestroyResult.getFaceId());
+ m_controller.start<ndn::nfd::FaceDestroyCommand>(faceParameters,
+ onSuccess,
+ onFailure);
+}
+
+void
+Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
+ uint64_t faceCost, uint64_t timeout)
+{
+ createFace(faceUri,
+ ndn::bind(&Fib::registerPrefixInNfd, this,_1, namePrefix, faceCost, timeout),
+ ndn::bind(&Fib::onFailure, this, _1, _2,"Failed in name registration"));
+}
+
+void
+Fib::registerPrefix(const ndn::Name& namePrefix,
+ const std::string& faceUri,
+ uint64_t faceCost, uint64_t timeout,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure)
+
+{
+ createFace(faceUri,
+ ndn::bind(&Fib::registerPrefixInNfd, this,_1,
+ namePrefix, faceCost, timeout, onSuccess, onFailure),
+ onFailure);
}
void
@@ -291,6 +334,24 @@
}
void
+Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
+ const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure)
+{
+ ndn::nfd::ControlParameters controlParameters;
+ controlParameters
+ .setName(namePrefix)
+ .setFaceId(faceCreateResult.getFaceId())
+ .setCost(faceCost)
+ .setExpirationPeriod(ndn::time::milliseconds(timeout * 1000))
+ .setOrigin(128);
+ m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
+ onSuccess,
+ onFailure);
+}
+
+void
Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri)
{
uint32_t faceId = m_faceMap.getFaceId(faceUri);
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 9ffd44c..ecc5030 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -33,6 +33,9 @@
namespace nlsr {
+typedef ndn::function<void(const ndn::nfd::ControlParameters&)> CommandSucceedCallback;
+typedef ndn::function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback;
+
class Nlsr;
@@ -90,8 +93,11 @@
uint64_t faceCost, uint64_t timeout);
void
- registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
- const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout);
+ registerPrefix(const ndn::Name& namePrefix,
+ const std::string& faceUri,
+ uint64_t faceCost, uint64_t timeout,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure);
void
setStrategy(const ndn::Name& name, const std::string& strategy);
@@ -99,8 +105,33 @@
void
writeLog();
+ void
+ destroyFace(const std::string& faceUri,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure);
+
private:
void
+ createFace(const std::string& faceUri,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure);
+
+ void
+ registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
+ const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout);
+
+ void
+ registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
+ const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure);
+
+ void
+ destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure);
+
+ void
unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
void