mgmt: loosened coupling between FibManager and InternalFace
Implemented InternalFace.setInterestFilter to loosen
coupling
refs: #1138
Change-Id: Ie58daed35bc3613398c8d3fc1de8b796e29907b8
diff --git a/daemon/mgmt/fib-manager.cpp b/daemon/mgmt/fib-manager.cpp
index 214bf0b..569a3be 100644
--- a/daemon/mgmt/fib-manager.cpp
+++ b/daemon/mgmt/fib-manager.cpp
@@ -69,8 +69,9 @@
};
FibManager::FibManager(Fib& fib,
- function<shared_ptr<Face>(FaceId)> getFace)
- : ManagerBase(shared_ptr<AppFace>(new InternalFace(*this))),
+ function<shared_ptr<Face>(FaceId)> getFace,
+ shared_ptr<AppFace> face)
+ : ManagerBase(face),
m_managedFib(fib),
m_getFace(getFace),
m_verbDispatch(FIB_MANAGER_REQUEST_VERBS,
@@ -131,7 +132,7 @@
const size_t optionCompIndex =
FIB_MANAGER_REQUEST_PREFIX.size() + 1;
- const ndn::Buffer &optionBuffer =
+ const ndn::Buffer& optionBuffer =
request.getName()[optionCompIndex].getValue();
shared_ptr<const ndn::Buffer> tmpOptionBuffer(new ndn::Buffer(optionBuffer));
Block rawOptions(tmpOptionBuffer);
diff --git a/daemon/mgmt/fib-manager.hpp b/daemon/mgmt/fib-manager.hpp
index 214b426..59a242b 100644
--- a/daemon/mgmt/fib-manager.hpp
+++ b/daemon/mgmt/fib-manager.hpp
@@ -23,7 +23,9 @@
{
public:
- FibManager(Fib& fib, function<shared_ptr<Face>(FaceId)> getFace);
+ FibManager(Fib& fib,
+ function<shared_ptr<Face>(FaceId)> getFace,
+ shared_ptr<AppFace> face);
void
onFibRequest(const Interest& request);
diff --git a/daemon/mgmt/internal-face.cpp b/daemon/mgmt/internal-face.cpp
index b207dd2..0c3fe3b 100644
--- a/daemon/mgmt/internal-face.cpp
+++ b/daemon/mgmt/internal-face.cpp
@@ -5,12 +5,12 @@
*/
#include "internal-face.hpp"
-#include "fib-manager.hpp"
namespace nfd {
-InternalFace::InternalFace(FibManager& manager)
- : m_fibManager(manager)
+NFD_LOG_INIT("InternalFace");
+
+InternalFace::InternalFace()
{
}
@@ -18,11 +18,25 @@
void
InternalFace::sendInterest(const Interest& interest)
{
- const Name& interestName = interest.getName();
+ const Name& interestName(interest.getName());
+ NFD_LOG_DEBUG("received Interest: " << interestName);
- if (m_fibManager.getRequestPrefix().isPrefixOf(interestName))
+ size_t nComps = interestName.size();
+ for (size_t i = 0; i < nComps; i++)
{
- m_fibManager.onFibRequest(interest);
+ Name prefix(interestName.getPrefix(nComps - i));
+ std::map<Name, OnInterest>::const_iterator filter =
+ m_interestFilters.find(prefix);
+
+ if (filter != m_interestFilters.end())
+ {
+ NFD_LOG_DEBUG("found Interest filter for " << prefix);
+ filter->second(interestName, interest);
+ }
+ else
+ {
+ NFD_LOG_DEBUG("no Interest filter found for " << prefix);
+ }
}
//Drop Interest
}
@@ -37,7 +51,8 @@
InternalFace::setInterestFilter(const Name& filter,
OnInterest onInterest)
{
-
+ NFD_LOG_INFO("registering callback for " << filter);
+ m_interestFilters[filter] = onInterest;
}
void
diff --git a/daemon/mgmt/internal-face.hpp b/daemon/mgmt/internal-face.hpp
index 4b16cc1..217d631 100644
--- a/daemon/mgmt/internal-face.hpp
+++ b/daemon/mgmt/internal-face.hpp
@@ -18,8 +18,7 @@
{
public:
- explicit
- InternalFace(FibManager& manager);
+ InternalFace();
// Overridden Face methods for forwarder
@@ -47,8 +46,6 @@
// onConfig(ConfigFile::Node section, bool isDryRun);
std::map<Name, OnInterest> m_interestFilters;
- FibManager& m_fibManager; // for mock only
-
};
} // namespace nfd
diff --git a/daemon/mgmt/manager-base.cpp b/daemon/mgmt/manager-base.cpp
index 1802018..5e561ff 100644
--- a/daemon/mgmt/manager-base.cpp
+++ b/daemon/mgmt/manager-base.cpp
@@ -11,6 +11,8 @@
namespace nfd {
+NFD_LOG_INIT("ManagerBase");
+
ManagerBase::ManagerBase(shared_ptr<AppFace> face)
: m_face(face)
{
@@ -27,10 +29,47 @@
uint32_t code,
const std::string& text)
{
- Data response(name);
+ // Path 1 - runtime exception on receive's wireDecode.
+ // Set Data response's content payload to the
+ // encoded Block.
+ {
+ ndn::ControlResponse control(code, text);
+ const Block& encodedControl = control.wireEncode();
- response.setContent(ndn::ControlResponse(code, text).wireEncode());
- m_face->put(response);
+ NFD_LOG_DEBUG("sending control response (Path 1)"
+ << " Name: " << name
+ << " code: " << code
+ << " text: " << text);
+
+ NFD_LOG_DEBUG("sending raw control block size = " << encodedControl.size());
+
+ Data response(name);
+ response.setContent(encodedControl);
+
+ m_face->put(response);
+ }
+
+ // Path 2 - works, but not conformant to protocol.
+ // Encode ControlResponse and append Block as
+ // the last component of the name.
+ // {
+ // ndn::ControlResponse control(code, text);
+ // const Block& encodedControl = control.wireEncode();
+
+ // NFD_LOG_DEBUG("sending control response (Path 2)"
+ // << " Name: " << name
+ // << " code: " << code
+ // << " text: " << text);
+
+ // NFD_LOG_DEBUG("sending raw control block size = " << encodedControl.size());
+
+ // Name responseName(name);
+ // responseName.append(encodedControl);
+
+ // Data response(responseName);
+ // m_face->put(response);
+ // }
+
}
diff --git a/daemon/mgmt/manager-base.hpp b/daemon/mgmt/manager-base.hpp
index 97f4c05..7308b3e 100644
--- a/daemon/mgmt/manager-base.hpp
+++ b/daemon/mgmt/manager-base.hpp
@@ -23,7 +23,7 @@
protected:
- virtual void
+ void
sendResponse(const Name& name,
uint32_t code,
const std::string& text);