mgmt refactoring: Refactor InternalFace
InternalFace is now exclusively for internal use by NFD's forwarding
pipelines. A separate InternalClientFace has been introduced, intended
to be used by the NFD internal applications, including FIB, Face, RIB
manager, and others.
Change-Id: I4a06b9d05b1613a456c6267582091924557d73be
Refs: #2107
diff --git a/daemon/face/internal-client-face.cpp b/daemon/face/internal-client-face.cpp
new file mode 100644
index 0000000..510b087
--- /dev/null
+++ b/daemon/face/internal-client-face.cpp
@@ -0,0 +1,99 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "internal-client-face.hpp"
+#include "internal-face.hpp"
+#include "core/global-io.hpp"
+
+#include <ndn-cxx/management/nfd-local-control-header.hpp>
+
+namespace nfd {
+
+void
+InternalClientFace::Transport::receive(const Block& block)
+{
+ if (m_receiveCallback) {
+ m_receiveCallback(block);
+ }
+}
+
+void
+InternalClientFace::Transport::close()
+{
+}
+
+void
+InternalClientFace::Transport::send(const Block& wire)
+{
+ onSendBlock(wire);
+}
+
+void
+InternalClientFace::Transport::send(const Block& header, const Block& payload)
+{
+ ndn::EncodingBuffer encoder(header.size() + payload.size(), header.size() + payload.size());
+ encoder.appendByteArray(header.wire(), header.size());
+ encoder.appendByteArray(payload.wire(), payload.size());
+
+ this->send(encoder.block());
+}
+
+void
+InternalClientFace::Transport::pause()
+{
+}
+
+void
+InternalClientFace::Transport::resume()
+{
+}
+
+InternalClientFace::InternalClientFace(const shared_ptr<InternalFace>& face,
+ const shared_ptr<InternalClientFace::Transport>& transport,
+ ndn::KeyChain& keyChain)
+ : ndn::Face(transport, getGlobalIoService(), keyChain)
+ , m_face(face)
+ , m_transport(transport)
+{
+ construct();
+}
+
+void
+InternalClientFace::construct()
+{
+ m_face->onSendInterest.connect(bind(&InternalClientFace::receive<Interest>, this, _1));
+ m_face->onSendData.connect(bind(&InternalClientFace::receive<Data>, this, _1));
+ m_transport->onSendBlock.connect(bind(&InternalFace::receive, m_face, _1));
+}
+
+shared_ptr<InternalClientFace>
+makeInternalClientFace(const shared_ptr<InternalFace>& face,
+ ndn::KeyChain& keyChain)
+{
+ auto transport = make_shared<InternalClientFace::Transport>();
+ return shared_ptr<InternalClientFace>(new InternalClientFace(face, transport, keyChain));
+}
+
+} // namespace nfd
diff --git a/daemon/face/internal-client-face.hpp b/daemon/face/internal-client-face.hpp
new file mode 100644
index 0000000..8eb3c46
--- /dev/null
+++ b/daemon/face/internal-client-face.hpp
@@ -0,0 +1,118 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_DAEMON_FACE_INTERNAL_CLIENT_FACE_HPP
+#define NFD_DAEMON_FACE_INTERNAL_CLIENT_FACE_HPP
+
+#include "common.hpp"
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/transport/transport.hpp>
+
+namespace nfd {
+
+class InternalFace;
+class InternalClientFace;
+
+shared_ptr<InternalClientFace>
+makeInternalClientFace(const shared_ptr<InternalFace>& face, ndn::KeyChain& keyChain);
+
+/** \brief a client face that is connected to NFD InternalFace
+ */
+class InternalClientFace : public ndn::Face
+{
+public:
+ template<typename Packet>
+ void
+ receive(const Packet& packet);
+
+private:
+ class Transport : public ndn::Transport
+ {
+ public:
+ signal::Signal<Transport, Block> onSendBlock;
+
+ void
+ receive(const Block& block);
+
+ virtual void
+ close() DECL_OVERRIDE;
+
+ virtual void
+ send(const Block& wire) DECL_OVERRIDE;
+
+ virtual void
+ send(const Block& header, const Block& payload) DECL_OVERRIDE;
+
+ virtual void
+ pause() DECL_OVERRIDE;
+
+ virtual void
+ resume() DECL_OVERRIDE;
+ };
+
+private:
+ InternalClientFace(const shared_ptr<InternalFace>& face,
+ const shared_ptr<InternalClientFace::Transport>& transport,
+ ndn::KeyChain& keyChain);
+
+ void
+ construct();
+
+ friend shared_ptr<InternalClientFace>
+ makeInternalClientFace(const shared_ptr<InternalFace>& face,
+ ndn::KeyChain& keyChain);
+
+private:
+ shared_ptr<InternalFace> m_face;
+ shared_ptr<InternalClientFace::Transport> m_transport;
+};
+
+template<typename Packet>
+void
+InternalClientFace::receive(const Packet& packet)
+{
+ if (!packet.getLocalControlHeader().empty(ndn::nfd::LocalControlHeader::ENCODE_ALL)) {
+
+ Block header = packet.getLocalControlHeader()
+ .wireEncode(packet, ndn::nfd::LocalControlHeader::ENCODE_ALL);
+ Block payload = packet.wireEncode();
+
+ ndn::EncodingBuffer encoder(header.size() + payload.size(),
+ header.size() + payload.size());
+ encoder.appendByteArray(header.wire(), header.size());
+ encoder.appendByteArray(payload.wire(), payload.size());
+
+ m_transport->receive(encoder.block());
+ }
+ else {
+ m_transport->receive(packet.wireEncode());
+ }
+}
+
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_INTERNAL_CLIENT_FACE_HPP
diff --git a/daemon/face/internal-face.cpp b/daemon/face/internal-face.cpp
new file mode 100644
index 0000000..c5ab2ca
--- /dev/null
+++ b/daemon/face/internal-face.cpp
@@ -0,0 +1,93 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "internal-face.hpp"
+
+namespace nfd {
+
+InternalFace::InternalFace()
+ : Face(FaceUri("internal://"), FaceUri("internal://"), true)
+{
+}
+
+void
+InternalFace::sendInterest(const Interest& interest)
+{
+ this->emitSignal(onSendInterest, interest);
+}
+
+void
+InternalFace::sendData(const Data& data)
+{
+ this->emitSignal(onSendData, data);
+}
+
+void
+InternalFace::close()
+{
+}
+
+void
+InternalFace::receive(const Block& blockFromClient)
+{
+ const Block& payLoad = ndn::nfd::LocalControlHeader::getPayload(blockFromClient);
+ if (payLoad.type() == ndn::tlv::Interest) {
+ receiveInterest(*extractPacketFromBlock<Interest>(blockFromClient, payLoad));
+ }
+ else if (payLoad.type() == ndn::tlv::Data) {
+ receiveData(*extractPacketFromBlock<Data>(blockFromClient, payLoad));
+ }
+}
+
+void
+InternalFace::receiveInterest(const Interest& interest)
+{
+ this->emitSignal(onReceiveInterest, interest);
+}
+
+void
+InternalFace::receiveData(const Data& data)
+{
+ this->emitSignal(onReceiveData, data);
+}
+
+template<typename Packet>
+shared_ptr<Packet>
+InternalFace::extractPacketFromBlock(const Block& blockFromClient, const Block& payLoad)
+{
+ auto packet = make_shared<Packet>(payLoad);
+ if (&payLoad != &blockFromClient) {
+ packet->getLocalControlHeader().wireDecode(blockFromClient);
+ }
+ return packet;
+}
+
+template shared_ptr<Interest>
+InternalFace::extractPacketFromBlock<Interest>(const Block& blockFromClient, const Block& payLoad);
+
+template shared_ptr<Data>
+InternalFace::extractPacketFromBlock<Data>(const Block& blockFromClient, const Block& payLoad);
+
+} // namespace nfd
diff --git a/daemon/face/internal-face.hpp b/daemon/face/internal-face.hpp
new file mode 100644
index 0000000..1014fca
--- /dev/null
+++ b/daemon/face/internal-face.hpp
@@ -0,0 +1,102 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_DAEMON_FACE_INTERNAL_FACE_HPP
+#define NFD_DAEMON_FACE_INTERNAL_FACE_HPP
+
+#include "face.hpp"
+
+namespace nfd {
+
+/**
+ * @brief represents a face for internal use in NFD.
+ */
+class InternalFace : public Face
+{
+public:
+
+ InternalFace();
+
+ virtual void
+ sendInterest(const Interest& interest) DECL_OVERRIDE;
+
+ virtual void
+ sendData(const Data& data) DECL_OVERRIDE;
+
+ virtual void
+ close() DECL_OVERRIDE;
+
+ /**
+ * @brief receive a block from a client face
+ *
+ * step1. extracte the packet payload from the received block.
+ * step2. check the type (either Interest or Data) through the payload.
+ * step3. call receiveInterest / receiveData respectively according to the type.
+ *
+ * @param blockFromClient the block from a client face
+ */
+ void
+ receive(const Block& blockFromClient);
+
+ /**
+ * @brief receive an Interest from a client face
+ *
+ * emit the onReceiveInterest signal.
+ *
+ * @param interest the received Interest packet
+ */
+ void
+ receiveInterest(const Interest& interest);
+
+ /**
+ * @brief receive a Data from a client face
+ *
+ * emit the onReceiveData signal.
+ *
+ * @param data the received Data packet
+ */
+ void
+ receiveData(const Data& data);
+
+ /**
+ * @brief compose the whole packet from the received block after payload is extracted
+ *
+ * construct a packet from the extracted payload, and then decode the localControlHeader if the
+ * received block holds more information than the payload.
+ *
+ * @tparam Packet the type of packet, Interest or Data
+ * @param blockFromClient the received block
+ * @param payLoad the extracted payload
+ *
+ * @return a complete packet
+ */
+ template<typename Packet>
+ static shared_ptr<Packet>
+ extractPacketFromBlock(const Block& blockFromClient, const Block& payLoad);
+};
+
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_INTERNAL_FACE_HPP
diff --git a/daemon/mgmt/internal-face.cpp b/daemon/mgmt/internal-face.cpp
deleted file mode 100644
index 7569fb9..0000000
--- a/daemon/mgmt/internal-face.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "internal-face.hpp"
-#include "core/logger.hpp"
-#include "core/global-io.hpp"
-
-namespace nfd {
-
-NFD_LOG_INIT("InternalFace");
-
-InternalFace::InternalFace()
- : Face(FaceUri("internal://"), FaceUri("internal://"), true)
-{
-}
-
-void
-InternalFace::sendInterest(const Interest& interest)
-{
- this->emitSignal(onSendInterest, interest);
-
- // Invoke .processInterest a bit later,
- // to avoid potential problems in forwarding pipelines.
- getGlobalIoService().post(bind(&InternalFace::processInterest,
- this, interest.shared_from_this()));
-}
-
-void
-InternalFace::processInterest(const shared_ptr<const Interest>& interest)
-{
- if (m_interestFilters.size() == 0)
- {
- NFD_LOG_DEBUG("no Interest filters to match against");
- return;
- }
-
- const Name& interestName(interest->getName());
- NFD_LOG_DEBUG("received Interest: " << interestName);
-
- std::map<Name, OnInterest>::const_iterator filter =
- m_interestFilters.lower_bound(interestName);
-
- // lower_bound gives us the first Name that is
- // an exact match OR ordered after interestName.
- //
- // If we reach the end of the map, then we need
- // only check if the before-end element is a match.
- //
- // If we match an element, then the current
- // position or the previous element are potential
- // matches.
- //
- // If we hit begin, the element is either an exact
- // match or there is no matching prefix in the map.
-
-
- if (filter == m_interestFilters.end() && filter != m_interestFilters.begin())
- {
- // We hit the end, check if the previous element
- // is a match
- --filter;
- if (filter->first.isPrefixOf(interestName))
- {
- NFD_LOG_DEBUG("found Interest filter for " << filter->first << " (before end match)");
- filter->second(interestName, *interest);
- }
- else
- {
- NFD_LOG_DEBUG("no Interest filter found for " << interestName << " (before end)");
- }
- }
- else if (filter->first == interestName)
- {
- NFD_LOG_DEBUG("found Interest filter for " << filter->first << " (exact match)");
- filter->second(interestName, *interest);
- }
- else if (filter != m_interestFilters.begin())
- {
- // the element we found is canonically
- // ordered after interestName.
- // Check the previous element.
- --filter;
- if (filter->first.isPrefixOf(interestName))
- {
- NFD_LOG_DEBUG("found Interest filter for " << filter->first << " (previous match)");
- filter->second(interestName, *interest);
- }
- else
- {
- NFD_LOG_DEBUG("no Interest filter found for " << interestName << " (previous)");
- }
- }
- else
- {
- NFD_LOG_DEBUG("no Interest filter found for " << interestName << " (begin)");
- }
- //Drop Interest
-}
-
-void
-InternalFace::sendData(const Data& data)
-{
- this->emitSignal(onSendData, data);
-}
-
-void
-InternalFace::close()
-{
- BOOST_THROW_EXCEPTION(Error("Internal face cannot be closed"));
-}
-
-void
-InternalFace::setInterestFilter(const Name& filter,
- OnInterest onInterest)
-{
- NFD_LOG_INFO("registering callback for " << filter);
- m_interestFilters[filter] = onInterest;
-}
-
-void
-InternalFace::put(const Data& data)
-{
- this->emitSignal(onReceiveData, data);
-}
-
-InternalFace::~InternalFace()
-{
-
-}
-
-} // namespace nfd
diff --git a/daemon/mgmt/internal-face.hpp b/daemon/mgmt/internal-face.hpp
deleted file mode 100644
index c35676f..0000000
--- a/daemon/mgmt/internal-face.hpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_DAEMON_MGMT_INTERNAL_FACE_HPP
-#define NFD_DAEMON_MGMT_INTERNAL_FACE_HPP
-
-#include "face/face.hpp"
-#include "app-face.hpp"
-
-#include "command-validator.hpp"
-
-namespace nfd {
-
-class InternalFace : public Face, public AppFace
-{
-public:
- /**
- * \brief InternalFace-related error
- */
- class Error : public Face::Error
- {
- public:
- explicit
- Error(const std::string& what)
- : Face::Error(what)
- {
- }
- };
-
- InternalFace();
-
- CommandValidator&
- getValidator();
-
- virtual
- ~InternalFace();
-
- // Overridden Face methods for forwarder
-
- virtual void
- sendInterest(const Interest& interest);
-
- virtual void
- sendData(const Data& data);
-
- virtual void
- close();
-
- // Methods implementing AppFace interface. Do not invoke from forwarder.
-
- virtual void
- setInterestFilter(const Name& filter,
- OnInterest onInterest);
-
- virtual void
- put(const Data& data);
-
-private:
- void
- processInterest(const shared_ptr<const Interest>& interest);
-
-private:
- std::map<Name, OnInterest> m_interestFilters;
- CommandValidator m_validator;
-};
-
-inline CommandValidator&
-InternalFace::getValidator()
-{
- return m_validator;
-}
-
-
-} // namespace nfd
-
-#endif // NFD_DAEMON_MGMT_INTERNAL_FACE_HPP
diff --git a/daemon/nfd.cpp b/daemon/nfd.cpp
index 1041643..66ab514 100644
--- a/daemon/nfd.cpp
+++ b/daemon/nfd.cpp
@@ -31,7 +31,8 @@
#include "core/config-file.hpp"
#include "fw/forwarder.hpp"
#include "face/null-face.hpp"
-#include "mgmt/internal-face.hpp"
+#include "face/internal-face.hpp"
+#include "face/internal-client-face.hpp"
// #include "mgmt/fib-manager.hpp"
// #include "mgmt/face-manager.hpp"
// #include "mgmt/strategy-choice-manager.hpp"
@@ -47,14 +48,14 @@
Nfd::Nfd(const std::string& configFile, ndn::KeyChain& keyChain)
: m_configFile(configFile)
- // , m_keyChain(keyChain)
+ , m_keyChain(keyChain)
, m_networkMonitor(getGlobalIoService())
{
}
Nfd::Nfd(const ConfigSection& config, ndn::KeyChain& keyChain)
: m_configSection(config)
- // , m_keyChain(keyChain)
+ , m_keyChain(keyChain)
, m_networkMonitor(getGlobalIoService())
{
}
@@ -128,6 +129,8 @@
Nfd::initializeManagement()
{
m_internalFace = make_shared<InternalFace>();
+ m_forwarder->getFaceTable().addReserved(m_internalFace, FACEID_INTERNAL_FACE);
+ m_internalClientFace = makeInternalClientFace(m_internalFace, m_keyChain);
// m_fibManager.reset(new FibManager(m_forwarder->getFib(),
// bind(&Forwarder::getFace, m_forwarder.get(), _1),
@@ -150,7 +153,7 @@
m_forwarder->getMeasurements());
tablesConfig.setConfigFile(config);
- m_internalFace->getValidator().setConfigFile(config);
+ // m_internalFace->getValidator().setConfigFile(config);
m_forwarder->getFaceTable().addReserved(m_internalFace, FACEID_INTERNAL_FACE);
@@ -193,7 +196,7 @@
tablesConfig.setConfigFile(config);
- m_internalFace->getValidator().setConfigFile(config);
+ // m_internalFace->getValidator().setConfigFile(config);
// m_faceManager->setConfigFile(config);
if (!m_configFile.empty()) {
diff --git a/daemon/nfd.hpp b/daemon/nfd.hpp
index acd3096..1240835 100644
--- a/daemon/nfd.hpp
+++ b/daemon/nfd.hpp
@@ -41,6 +41,7 @@
class FaceManager;
class StrategyChoiceManager;
class StatusServer;
+class InternalClientFace;
/**
* \brief Class representing NFD instance
@@ -97,14 +98,14 @@
unique_ptr<Forwarder> m_forwarder;
+ ndn::KeyChain& m_keyChain;
shared_ptr<InternalFace> m_internalFace;
+ shared_ptr<InternalClientFace> m_internalClientFace;
// unique_ptr<FibManager> m_fibManager;
// unique_ptr<FaceManager> m_faceManager;
// unique_ptr<StrategyChoiceManager> m_strategyChoiceManager;
// unique_ptr<StatusServer> m_statusServer;
- // ndn::KeyChain& m_keyChain;
-
ndn::util::NetworkMonitor m_networkMonitor;
scheduler::ScopedEventId m_reloadConfigEvent;
};
diff --git a/tests/daemon/face/internal-client-face.t.cpp b/tests/daemon/face/internal-client-face.t.cpp
new file mode 100644
index 0000000..0b2295c
--- /dev/null
+++ b/tests/daemon/face/internal-client-face.t.cpp
@@ -0,0 +1,134 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "face/internal-client-face.hpp"
+#include "face/internal-face.hpp"
+#include "tests/test-common.hpp"
+#include "tests/identity-management-fixture.hpp"
+
+namespace nfd {
+namespace tests {
+
+class InternalClientFaceFixture : public UnitTestTimeFixture
+ , public IdentityManagementFixture
+{
+public:
+ InternalClientFaceFixture()
+ : m_internalFace(make_shared<InternalFace>())
+ , m_face(makeInternalClientFace(m_internalFace, m_keyChain))
+ {
+ }
+
+protected:
+ shared_ptr<InternalFace> m_internalFace;
+ shared_ptr<InternalClientFace> m_face;
+};
+
+BOOST_FIXTURE_TEST_SUITE(FaceInternalClientFace, InternalClientFaceFixture)
+
+BOOST_AUTO_TEST_CASE(ExpressInterest)
+{
+ bool didReceiveDataBack = false;
+ bool didTimeoutCallbackFire = false;
+ Data receivedData;
+
+ auto expressInterest = [&] (shared_ptr<Interest> interest) {
+ didReceiveDataBack = false;
+ didTimeoutCallbackFire = false;
+ m_face->expressInterest(interest->setInterestLifetime(time::milliseconds(100)),
+ [&] (const Interest& interest, Data& data) {
+ didReceiveDataBack = true;
+ receivedData = data;
+ },
+ bind([&] { didTimeoutCallbackFire = true; }));
+ advanceClocks(time::milliseconds(1));
+ };
+
+ expressInterest(makeInterest("/test/timeout"));
+ advanceClocks(time::milliseconds(1), 200); // wait for time out
+ BOOST_CHECK(didTimeoutCallbackFire);
+
+ auto dataToSend = makeData("/test/data")->setContent(Block("\x81\x01\0x01", 3));
+ expressInterest(makeInterest("/test/data"));
+ m_internalFace->sendData(dataToSend); // send data to satisfy the expressed interest
+ advanceClocks(time::milliseconds(1));
+ BOOST_CHECK(didReceiveDataBack);
+ BOOST_CHECK(receivedData.wireEncode() == dataToSend.wireEncode());
+}
+
+BOOST_AUTO_TEST_CASE(InterestFilter)
+{
+ bool didOnInterestCallbackFire = false;
+ Block receivedBlock, expectedBlock;
+
+ auto testSendInterest = [&] (shared_ptr<Interest> interest) {
+ didOnInterestCallbackFire = false;
+ expectedBlock = interest->wireEncode();
+ m_internalFace->sendInterest(*interest);
+ };
+
+ testSendInterest(makeInterest("/test/filter")); // no filter is set now
+ BOOST_CHECK(!didOnInterestCallbackFire);
+
+ // set filter
+ auto filter = m_face->setInterestFilter("/test/filter",
+ bind([&](const Interest& interset) {
+ didOnInterestCallbackFire = true;
+ receivedBlock = interset.wireEncode();
+ }, _2));
+ advanceClocks(time::milliseconds(1));
+
+ testSendInterest(makeInterest("/test/filter"));
+ BOOST_CHECK(didOnInterestCallbackFire);
+ BOOST_CHECK(receivedBlock == expectedBlock);
+
+ // unset filter
+ didOnInterestCallbackFire = false;
+ m_face->unsetInterestFilter(filter);
+ advanceClocks(time::milliseconds(1));
+ testSendInterest(makeInterest("/test/filter"));
+ BOOST_CHECK(!didOnInterestCallbackFire);
+}
+
+BOOST_AUTO_TEST_CASE(PutData)
+{
+ bool didInternalFaceReceiveData = false;
+ Data receivedData;
+ m_internalFace->onReceiveData.connect([&] (const Data& data) {
+ didInternalFaceReceiveData = true;
+ receivedData = data;
+ });
+
+ auto dataToPut = makeData("/test/put/data");
+ m_face->put(*dataToPut);
+ advanceClocks(time::milliseconds(1));
+ BOOST_CHECK(didInternalFaceReceiveData);
+ BOOST_CHECK(receivedData.wireEncode() == dataToPut->wireEncode());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/face/internal-face.t.cpp b/tests/daemon/face/internal-face.t.cpp
new file mode 100644
index 0000000..44f5e7b
--- /dev/null
+++ b/tests/daemon/face/internal-face.t.cpp
@@ -0,0 +1,143 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "face/internal-face.hpp"
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace tests {
+
+class InternalFaceFixture : protected BaseFixture
+{
+public:
+ InternalFaceFixture()
+ {
+ m_face.onReceiveInterest.connect([this] (const Interest& interest) {
+ inInterests.push_back(interest);
+ });
+ m_face.onSendInterest.connect([this] (const Interest& interest) {
+ outInterests.push_back(interest);
+ });
+ m_face.onReceiveData.connect([this] (const Data& data) {
+ inData.push_back(data);
+ });
+ m_face.onSendData.connect([this] (const Data& data) {
+ outData.push_back(data);
+ });
+ }
+
+protected:
+ InternalFace m_face;
+ std::vector<Interest> inInterests;
+ std::vector<Interest> outInterests;
+ std::vector<Data> inData;
+ std::vector<Data> outData;
+};
+
+BOOST_FIXTURE_TEST_SUITE(FaceInternalFace, InternalFaceFixture)
+
+BOOST_AUTO_TEST_CASE(SendInterest)
+{
+ BOOST_CHECK(outInterests.empty());
+
+ auto interest = makeInterest("/test/send/interest");
+ Block expectedBlock = interest->wireEncode(); // assign a value to nonce
+ m_face.sendInterest(*interest);
+
+ BOOST_CHECK_EQUAL(outInterests.size(), 1);
+ BOOST_CHECK(outInterests[0].wireEncode() == expectedBlock);
+}
+
+BOOST_AUTO_TEST_CASE(SendData)
+{
+ BOOST_CHECK(outData.empty());
+
+ auto data = makeData("/test/send/data");
+ m_face.sendData(*data);
+
+ BOOST_CHECK_EQUAL(outData.size(), 1);
+ BOOST_CHECK(outData[0].wireEncode() == data->wireEncode());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveInterest)
+{
+ BOOST_CHECK(inInterests.empty());
+
+ auto interest = makeInterest("/test/receive/interest");
+ Block expectedBlock = interest->wireEncode(); // assign a value to nonce
+ m_face.receiveInterest(*interest);
+
+ BOOST_CHECK_EQUAL(inInterests.size(), 1);
+ BOOST_CHECK(inInterests[0].wireEncode() == expectedBlock);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveData)
+{
+ BOOST_CHECK(inData.empty());
+
+ auto data = makeData("/test/send/data");
+ m_face.receiveData(*data);
+
+ BOOST_CHECK_EQUAL(inData.size(), 1);
+ BOOST_CHECK(inData[0].wireEncode() == data->wireEncode());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveBlock)
+{
+ BOOST_CHECK(inInterests.empty());
+ BOOST_CHECK(inData.empty());
+
+ Block interestBlock = makeInterest("test/receive/interest")->wireEncode();
+ m_face.receive(interestBlock);
+ BOOST_CHECK_EQUAL(inInterests.size(), 1);
+ BOOST_CHECK(inInterests[0].wireEncode() == interestBlock);
+
+ Block dataBlock = makeData("test/receive/data")->wireEncode();
+ m_face.receive(dataBlock);
+ BOOST_CHECK_EQUAL(inData.size(), 1);
+ BOOST_CHECK(inData[0].wireEncode() == dataBlock);
+}
+
+BOOST_AUTO_TEST_CASE(ExtractPacketFromBlock)
+{
+ {
+ Block block = makeInterest("/test/interest")->wireEncode();
+ const Block& payload = ndn::nfd::LocalControlHeader::getPayload(block);
+ auto interest = m_face.extractPacketFromBlock<Interest>(block, payload);
+ BOOST_CHECK(interest->wireEncode() == block);
+ }
+
+ {
+ Block block = makeData("/test/data")->wireEncode();
+ const Block& payload = ndn::nfd::LocalControlHeader::getPayload(block);
+ auto data = m_face.extractPacketFromBlock<Data>(block, payload);
+ BOOST_CHECK(data->wireEncode() == block);
+ }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/mgmt/internal-face.t.cpp b/tests/daemon/mgmt/internal-face.t.cpp
deleted file mode 100644
index 29b602c..0000000
--- a/tests/daemon/mgmt/internal-face.t.cpp
+++ /dev/null
@@ -1,238 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "mgmt/internal-face.hpp"
-#include "tests/daemon/face/dummy-face.hpp"
-
-#include "tests/test-common.hpp"
-
-namespace nfd {
-namespace tests {
-
-class InternalFaceFixture : protected BaseFixture
-{
-public:
-
- InternalFaceFixture()
- : m_onInterestFired(false),
- m_noOnInterestFired(false)
- {
-
- }
-
- void
- validateOnInterestCallback(const Name& name, const Interest& interest)
- {
- m_onInterestFired = true;
- }
-
- void
- validateNoOnInterestCallback(const Name& name, const Interest& interest)
- {
- m_noOnInterestFired = true;
- }
-
- void
- addFace(shared_ptr<Face> face)
- {
- m_faces.push_back(face);
- }
-
- bool
- didOnInterestFire()
- {
- return m_onInterestFired;
- }
-
- bool
- didNoOnInterestFire()
- {
- return m_noOnInterestFired;
- }
-
- void
- resetOnInterestFired()
- {
- m_onInterestFired = false;
- }
-
- void
- resetNoOnInterestFired()
- {
- m_noOnInterestFired = false;
- }
-
-protected:
- ndn::KeyChain m_keyChain;
-
-private:
- std::vector<shared_ptr<Face> > m_faces;
- bool m_onInterestFired;
- bool m_noOnInterestFired;
-};
-
-BOOST_FIXTURE_TEST_SUITE(MgmtInternalFace, InternalFaceFixture)
-
-void
-validatePutData(bool& called, const Name& expectedName, const Data& data)
-{
- called = true;
- BOOST_CHECK_EQUAL(expectedName, data.getName());
-}
-
-BOOST_AUTO_TEST_CASE(PutData)
-{
- addFace(make_shared<DummyFace>());
-
- shared_ptr<InternalFace> face(new InternalFace);
-
- bool didPutData = false;
- Name dataName("/hello");
- face->onReceiveData.connect(bind(&validatePutData, ref(didPutData), dataName, _1));
-
- Data testData(dataName);
- m_keyChain.sign(testData);
- face->put(testData);
-
- BOOST_REQUIRE(didPutData);
-
- BOOST_CHECK_THROW(face->close(), InternalFace::Error);
-}
-
-BOOST_AUTO_TEST_CASE(SendInterestHitEnd)
-{
- addFace(make_shared<DummyFace>());
-
- shared_ptr<InternalFace> face(new InternalFace);
-
- face->setInterestFilter("/localhost/nfd/fib",
- bind(&InternalFaceFixture::validateOnInterestCallback,
- this, _1, _2));
-
- // generate command whose name is canonically
- // ordered after /localhost/nfd/fib so that
- // we hit the end of the std::map
-
- Name commandName("/localhost/nfd/fib/end");
- shared_ptr<Interest> command = makeInterest(commandName);
- face->sendInterest(*command);
- g_io.run_one();
-
- BOOST_REQUIRE(didOnInterestFire());
- BOOST_REQUIRE(didNoOnInterestFire() == false);
-}
-
-BOOST_AUTO_TEST_CASE(SendInterestHitBegin)
-{
- addFace(make_shared<DummyFace>());
-
- shared_ptr<InternalFace> face(new InternalFace);
-
- face->setInterestFilter("/localhost/nfd/fib",
- bind(&InternalFaceFixture::validateNoOnInterestCallback,
- this, _1, _2));
-
- // generate command whose name is canonically
- // ordered before /localhost/nfd/fib so that
- // we hit the beginning of the std::map
-
- Name commandName("/localhost/nfd");
- shared_ptr<Interest> command = makeInterest(commandName);
- face->sendInterest(*command);
- g_io.run_one();
-
- BOOST_REQUIRE(didNoOnInterestFire() == false);
-}
-
-BOOST_AUTO_TEST_CASE(SendInterestHitExact)
-{
- addFace(make_shared<DummyFace>());
-
- shared_ptr<InternalFace> face(new InternalFace);
-
- face->setInterestFilter("/localhost/nfd/eib",
- bind(&InternalFaceFixture::validateNoOnInterestCallback,
- this, _1, _2));
-
- face->setInterestFilter("/localhost/nfd/fib",
- bind(&InternalFaceFixture::validateOnInterestCallback,
- this, _1, _2));
-
- face->setInterestFilter("/localhost/nfd/gib",
- bind(&InternalFaceFixture::validateNoOnInterestCallback,
- this, _1, _2));
-
- // generate command whose name exactly matches
- // /localhost/nfd/fib
-
- Name commandName("/localhost/nfd/fib");
- shared_ptr<Interest> command = makeInterest(commandName);
- face->sendInterest(*command);
- g_io.run_one();
-
- BOOST_REQUIRE(didOnInterestFire());
- BOOST_REQUIRE(didNoOnInterestFire() == false);
-}
-
-BOOST_AUTO_TEST_CASE(SendInterestHitPrevious)
-{
- addFace(make_shared<DummyFace>());
-
- shared_ptr<InternalFace> face(new InternalFace);
-
- face->setInterestFilter("/localhost/nfd/fib",
- bind(&InternalFaceFixture::validateOnInterestCallback,
- this, _1, _2));
-
- face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/",
- bind(&InternalFaceFixture::validateNoOnInterestCallback,
- this, _1, _2));
-
- // generate command whose name exactly matches
- // an Interest filter
-
- Name commandName("/localhost/nfd/fib/previous");
- shared_ptr<Interest> command = makeInterest(commandName);
- face->sendInterest(*command);
- g_io.run_one();
-
- BOOST_REQUIRE(didOnInterestFire());
- BOOST_REQUIRE(didNoOnInterestFire() == false);
-}
-
-BOOST_AUTO_TEST_CASE(InterestGone)
-{
- shared_ptr<InternalFace> face = make_shared<InternalFace>();
- shared_ptr<Interest> interest = makeInterest("ndn:/localhost/nfd/gone");
- face->sendInterest(*interest);
-
- interest.reset();
- BOOST_CHECK_NO_THROW(g_io.poll());
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace nfd