Merge branch 'feature-lp' into master
Change-Id: I2efd0bf044c07b8cdaf03ab62a9b6b71a76b8b09
diff --git a/.waf-tools/compiler-features.py b/.waf-tools/compiler-features.py
index 1fd529e..8fa6aa7 100644
--- a/.waf-tools/compiler-features.py
+++ b/.waf-tools/compiler-features.py
@@ -23,5 +23,41 @@
define_name='HAVE_CXX_OVERRIDE',
features='cxx', mandatory=False)
+FINAL = '''
+class Base
+{
+ virtual void
+ f(int a);
+};
+
+class Derived : public Base
+{
+ virtual void
+ f(int a) final;
+};
+'''
+
+@conf
+def check_final(self):
+ self.check_cxx(msg='Checking for final specifier on method',
+ fragment=FINAL,
+ define_name='HAVE_CXX_FINAL',
+ features='cxx', mandatory=False)
+
+CLASS_FINAL = '''
+class A final
+{
+};
+'''
+
+@conf
+def check_class_final(self):
+ self.check_cxx(msg='Checking for final specifier on class',
+ fragment=CLASS_FINAL,
+ define_name='HAVE_CXX_CLASS_FINAL',
+ features='cxx', mandatory=False)
+
def configure(conf):
conf.check_override()
+ conf.check_final()
+ conf.check_class_final()
diff --git a/common.hpp b/common.hpp
index 3e4f44f..c64dd37 100644
--- a/common.hpp
+++ b/common.hpp
@@ -41,7 +41,8 @@
#endif
/** \def DECL_OVERRIDE
- * \brief expands to 'override' if compiler supports this feature, otherwise expands to nothing
+ * \brief expands to 'override' if compiler supports 'override' specifier,
+ * otherwise expands to nothing
*/
#ifdef HAVE_CXX_OVERRIDE
#define DECL_OVERRIDE override
@@ -49,6 +50,26 @@
#define DECL_OVERRIDE
#endif
+/** \def DECL_FINAL
+ * \brief expands to 'final' if compiler supports 'final' specifier on method,
+ * otherwise expands to nothing
+ */
+#ifdef HAVE_CXX_FINAL
+#define DECL_FINAL final
+#else
+#define DECL_FINAL
+#endif
+
+/** \def DECL_CLASS_FINAL
+ * \brief expands to 'final' if compiler supports 'final' specifier on class,
+ * otherwise expands to nothing
+ */
+#ifdef HAVE_CXX_CLASS_FINAL
+#define DECL_CLASS_FINAL final
+#else
+#define DECL_CLASS_FINAL
+#endif
+
#include <cstddef>
#include <cstdint>
#include <functional>
@@ -67,6 +88,7 @@
#include <ndn-cxx/data.hpp>
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/encoding/block.hpp>
+#include <ndn-cxx/lp/nack.hpp>
#include <ndn-cxx/util/backports.hpp>
#include <ndn-cxx/util/face-uri.hpp>
#include <ndn-cxx/util/signal.hpp>
@@ -117,6 +139,7 @@
using namespace ndn::tlv;
} // namespace tlv
+namespace lp = ndn::lp;
namespace name = ndn::name;
namespace time = ndn::time;
namespace signal = ndn::util::signal;
diff --git a/daemon/face/datagram-face.hpp b/daemon/face/datagram-face.hpp
deleted file mode 100644
index a55fb8c..0000000
--- a/daemon/face/datagram-face.hpp
+++ /dev/null
@@ -1,300 +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/>.
- */
-
-#ifndef NFD_DAEMON_FACE_DATAGRAM_FACE_HPP
-#define NFD_DAEMON_FACE_DATAGRAM_FACE_HPP
-
-#include "face.hpp"
-#include "core/global-io.hpp"
-
-namespace nfd {
-
-struct Unicast {};
-struct Multicast {};
-
-template<class Protocol, class Addressing = Unicast>
-class DatagramFace : public Face
-{
-public:
- typedef Protocol protocol;
-
- /** \brief Construct datagram face
- *
- * \param socket Protocol-specific socket for the created face
- */
- DatagramFace(const FaceUri& remoteUri, const FaceUri& localUri,
- typename protocol::socket socket);
-
- // from Face
- void
- sendInterest(const Interest& interest) DECL_OVERRIDE;
-
- void
- sendData(const Data& data) DECL_OVERRIDE;
-
- void
- close() DECL_OVERRIDE;
-
- void
- receiveDatagram(const uint8_t* buffer,
- size_t nBytesReceived,
- const boost::system::error_code& error);
-
-protected:
- void
- processErrorCode(const boost::system::error_code& error);
-
- void
- handleSend(const boost::system::error_code& error,
- size_t nBytesSent,
- const Block& payload);
-
- void
- handleReceive(const boost::system::error_code& error,
- size_t nBytesReceived);
-
- void
- keepFaceAliveUntilAllHandlersExecuted(const shared_ptr<Face>& face);
-
- void
- closeSocket();
-
- bool
- hasBeenUsedRecently() const;
-
- /**
- * \brief Set m_hasBeenUsedRecently to false
- */
- void
- resetRecentUsage();
-
-protected:
- typename protocol::socket m_socket;
-
- NFD_LOG_INCLASS_DECLARE();
-
-private:
- uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
- bool m_hasBeenUsedRecently;
-};
-
-
-template<class T, class U>
-inline
-DatagramFace<T, U>::DatagramFace(const FaceUri& remoteUri, const FaceUri& localUri,
- typename DatagramFace::protocol::socket socket)
- : Face(remoteUri, localUri, false, std::is_same<U, Multicast>::value)
- , m_socket(std::move(socket))
-{
- NFD_LOG_FACE_INFO("Creating face");
-
- m_socket.async_receive(boost::asio::buffer(m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE),
- bind(&DatagramFace<T, U>::handleReceive, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::sendInterest(const Interest& interest)
-{
- NFD_LOG_FACE_TRACE(__func__);
-
- this->emitSignal(onSendInterest, interest);
-
- const Block& payload = interest.wireEncode();
- m_socket.async_send(boost::asio::buffer(payload.wire(), payload.size()),
- bind(&DatagramFace<T, U>::handleSend, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred,
- payload));
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::sendData(const Data& data)
-{
- NFD_LOG_FACE_TRACE(__func__);
-
- this->emitSignal(onSendData, data);
-
- const Block& payload = data.wireEncode();
- m_socket.async_send(boost::asio::buffer(payload.wire(), payload.size()),
- bind(&DatagramFace<T, U>::handleSend, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred,
- payload));
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::close()
-{
- if (!m_socket.is_open())
- return;
-
- NFD_LOG_FACE_INFO("Closing face");
-
- closeSocket();
- this->fail("Face closed");
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::processErrorCode(const boost::system::error_code& error)
-{
- if (error == boost::asio::error::operation_aborted) // when cancel() is called
- return;
-
- if (getPersistency() == ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERMANENT) {
- NFD_LOG_FACE_DEBUG("Permanent face ignores error: " << error.message());
- return;
- }
-
- if (!m_socket.is_open()) {
- this->fail("Tunnel closed");
- return;
- }
-
- if (error != boost::asio::error::eof)
- NFD_LOG_FACE_WARN("Send or receive operation failed: " << error.message());
-
- closeSocket();
-
- if (error == boost::asio::error::eof)
- this->fail("Tunnel closed");
- else
- this->fail(error.message());
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::handleSend(const boost::system::error_code& error,
- size_t nBytesSent,
- const Block& payload)
-// 'payload' is unused; it's needed to retain the underlying Buffer
-{
- if (error)
- return processErrorCode(error);
-
- NFD_LOG_FACE_TRACE("Successfully sent: " << nBytesSent << " bytes");
- this->getMutableCounters().getNOutBytes() += nBytesSent;
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::handleReceive(const boost::system::error_code& error,
- size_t nBytesReceived)
-{
- receiveDatagram(m_inputBuffer, nBytesReceived, error);
-
- if (m_socket.is_open())
- m_socket.async_receive(boost::asio::buffer(m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE),
- bind(&DatagramFace<T, U>::handleReceive, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::receiveDatagram(const uint8_t* buffer,
- size_t nBytesReceived,
- const boost::system::error_code& error)
-{
- if (error)
- return processErrorCode(error);
-
- NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes");
- this->getMutableCounters().getNInBytes() += nBytesReceived;
-
- bool isOk = false;
- Block element;
- std::tie(isOk, element) = Block::fromBuffer(buffer, nBytesReceived);
- if (!isOk)
- {
- NFD_LOG_FACE_WARN("Failed to parse incoming packet");
- // This message won't extend the face lifetime
- return;
- }
-
- if (element.size() != nBytesReceived)
- {
- NFD_LOG_FACE_WARN("Received datagram size and decoded element size don't match");
- // This message won't extend the face lifetime
- return;
- }
-
- if (!this->decodeAndDispatchInput(element))
- {
- NFD_LOG_FACE_WARN("Received unrecognized TLV block of type " << element.type());
- // This message won't extend the face lifetime
- return;
- }
-
- m_hasBeenUsedRecently = true;
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::keepFaceAliveUntilAllHandlersExecuted(const shared_ptr<Face>& face)
-{
- NFD_LOG_FACE_TRACE(__func__);
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::closeSocket()
-{
- NFD_LOG_FACE_TRACE(__func__);
-
- // use the non-throwing variants and ignore errors, if any
- boost::system::error_code error;
- m_socket.shutdown(protocol::socket::shutdown_both, error);
- m_socket.close(error);
- // after this, handlers will be called with an error code
-
- // ensure that the Face object is alive at least until all pending
- // handlers are dispatched
- getGlobalIoService().post(bind(&DatagramFace<T, U>::keepFaceAliveUntilAllHandlersExecuted,
- this, this->shared_from_this()));
-}
-
-template<class T, class U>
-inline bool
-DatagramFace<T, U>::hasBeenUsedRecently() const
-{
- return m_hasBeenUsedRecently;
-}
-
-template<class T, class U>
-inline void
-DatagramFace<T, U>::resetRecentUsage()
-{
- m_hasBeenUsedRecently = false;
-}
-
-} // namespace nfd
-
-#endif // NFD_DAEMON_FACE_DATAGRAM_FACE_HPP
diff --git a/daemon/face/datagram-transport.hpp b/daemon/face/datagram-transport.hpp
new file mode 100644
index 0000000..f9cf2fc
--- /dev/null
+++ b/daemon/face/datagram-transport.hpp
@@ -0,0 +1,239 @@
+/* -*- 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_DATAGRAM_TRANSPORT_HPP
+#define NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP
+
+#include "transport.hpp"
+#include "core/global-io.hpp"
+
+#include <array>
+
+namespace nfd {
+namespace face {
+
+struct Unicast {};
+struct Multicast {};
+
+/** \brief Implements Transport for datagram-based protocols.
+ *
+ * \tparam Protocol a datagram-based protocol in Boost.Asio
+ */
+template<class Protocol, class Addressing = Unicast>
+class DatagramTransport : public Transport
+{
+public:
+ typedef Protocol protocol;
+
+ /** \brief Construct datagram transport.
+ *
+ * \param socket Protocol-specific socket for the created transport
+ */
+ explicit
+ DatagramTransport(typename protocol::socket&& socket);
+
+ virtual void
+ doSend(Transport::Packet&& packet) DECL_OVERRIDE;
+
+ virtual void
+ doClose() DECL_OVERRIDE;
+
+ /** \brief Receive datagram, translate buffer into packet, deliver to parent class.
+ */
+ void
+ receiveDatagram(const uint8_t* buffer, size_t nBytesReceived,
+ const boost::system::error_code& error);
+
+protected:
+ void
+ handleReceive(const boost::system::error_code& error,
+ size_t nBytesReceived);
+
+ void
+ handleSend(const boost::system::error_code& error,
+ size_t nBytesSent, const Block& payload);
+
+ void
+ processErrorCode(const boost::system::error_code& error);
+
+ bool
+ hasBeenUsedRecently() const;
+
+ void
+ resetRecentUsage();
+
+protected:
+ typename protocol::socket m_socket;
+
+ NFD_LOG_INCLASS_DECLARE();
+
+private:
+ std::array<uint8_t, ndn::MAX_NDN_PACKET_SIZE> m_receiveBuffer;
+ bool m_hasBeenUsedRecently;
+};
+
+
+template<class T, class U>
+inline
+DatagramTransport<T, U>::DatagramTransport(typename DatagramTransport::protocol::socket&& socket)
+ : m_socket(std::move(socket))
+{
+ m_socket.async_receive(boost::asio::buffer(m_receiveBuffer),
+ bind(&DatagramTransport<T, U>::handleReceive, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
+}
+
+template<class T, class U>
+inline void
+DatagramTransport<T, U>::doSend(Transport::Packet&& packet)
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ m_socket.async_send(boost::asio::buffer(packet.packet),
+ bind(&DatagramTransport<T, U>::handleSend, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ packet.packet));
+}
+
+template<class T, class U>
+inline void
+DatagramTransport<T, U>::doClose()
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ if (m_socket.is_open()) {
+ // Cancel all outstanding operations and close the socket.
+ // Use the non-throwing variants and ignore errors, if any.
+ boost::system::error_code error;
+ m_socket.cancel(error);
+ m_socket.close(error);
+ }
+
+ // Ensure that the Transport stays alive at least until
+ // all pending handlers are dispatched
+ getGlobalIoService().post([this] {
+ this->setState(TransportState::CLOSED);
+ });
+}
+
+template<class T, class U>
+inline void
+DatagramTransport<T, U>::receiveDatagram(const uint8_t* buffer, size_t nBytesReceived,
+ const boost::system::error_code& error)
+{
+ if (error)
+ return processErrorCode(error);
+
+ NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes");
+
+ bool isOk = false;
+ Block element;
+ std::tie(isOk, element) = Block::fromBuffer(buffer, nBytesReceived);
+ if (!isOk) {
+ NFD_LOG_FACE_WARN("Failed to parse incoming packet");
+ // This packet won't extend the face lifetime
+ return;
+ }
+ if (element.size() != nBytesReceived) {
+ NFD_LOG_FACE_WARN("Received datagram size and decoded element size don't match");
+ // This packet won't extend the face lifetime
+ return;
+ }
+
+ m_hasBeenUsedRecently = true;
+ this->receive(Transport::Packet(std::move(element)));
+}
+
+template<class T, class U>
+inline void
+DatagramTransport<T, U>::handleReceive(const boost::system::error_code& error,
+ size_t nBytesReceived)
+{
+ receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
+
+ if (m_socket.is_open())
+ m_socket.async_receive(boost::asio::buffer(m_receiveBuffer),
+ bind(&DatagramTransport<T, U>::handleReceive, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
+}
+
+template<class T, class U>
+inline void
+DatagramTransport<T, U>::handleSend(const boost::system::error_code& error,
+ size_t nBytesSent, const Block& payload)
+// 'payload' is unused; it's needed to retain the underlying Buffer
+{
+ if (error)
+ return processErrorCode(error);
+
+ NFD_LOG_FACE_TRACE("Successfully sent: " << nBytesSent << " bytes");
+}
+
+template<class T, class U>
+inline void
+DatagramTransport<T, U>::processErrorCode(const boost::system::error_code& error)
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ if (getState() == TransportState::CLOSING ||
+ getState() == TransportState::FAILED ||
+ getState() == TransportState::CLOSED ||
+ error == boost::asio::error::operation_aborted)
+ // transport is shutting down, ignore any errors
+ return;
+
+ if (getPersistency() == ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERMANENT) {
+ NFD_LOG_FACE_DEBUG("Permanent face ignores error: " << error.message());
+ return;
+ }
+
+ if (error != boost::asio::error::eof)
+ NFD_LOG_FACE_WARN("Send or receive operation failed: " << error.message());
+
+ this->setState(TransportState::FAILED);
+ doClose();
+}
+
+template<class T, class U>
+inline bool
+DatagramTransport<T, U>::hasBeenUsedRecently() const
+{
+ return m_hasBeenUsedRecently;
+}
+
+template<class T, class U>
+inline void
+DatagramTransport<T, U>::resetRecentUsage()
+{
+ m_hasBeenUsedRecently = false;
+}
+
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP
diff --git a/daemon/face/face-log.hpp b/daemon/face/face-log.hpp
new file mode 100644
index 0000000..6e0b3fd
--- /dev/null
+++ b/daemon/face/face-log.hpp
@@ -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/>.
+ */
+
+#ifndef NFD_DAEMON_FACE_FACE_LOG_HPP
+#define NFD_DAEMON_FACE_FACE_LOG_HPP
+
+#include "core/logger.hpp"
+
+namespace nfd {
+namespace face {
+
+/** \brief for internal use by FaceLogging macros
+ *
+ * FaceLogHelper wraps a Face, LinkService, or Transport object.
+ *
+ * std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
+ * should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] "
+ * which appears as part of the log message.
+ */
+template<typename T>
+class FaceLogHelper
+{
+public:
+ explicit
+ FaceLogHelper(const T& obj1)
+ : obj(obj1)
+ {
+ }
+
+public:
+ const T& obj;
+};
+
+/** \defgroup FaceLogging Face logging macros
+ *
+ * These macros augment the log message with some face-specific information,
+ * such as the face ID, that are useful to distinguish which face produced the
+ * message. It is strongly recommended to use these macros instead of the
+ * generic ones for all logging inside Face, LinkService, Transport subclasses.
+ * @{
+ */
+
+#define NFD_LOG_FACE(level, msg) NFD_LOG_##level( \
+ ::nfd::face::FaceLogHelper< \
+ typename std::remove_cv< \
+ typename std::remove_reference<decltype(*this)>::type \
+ >::type \
+ >(*this) \
+ << msg)
+
+/** \brief Log a message at TRACE level */
+#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
+
+/** \brief Log a message at DEBUG level */
+#define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
+
+/** \brief Log a message at INFO level */
+#define NFD_LOG_FACE_INFO(msg) NFD_LOG_FACE(INFO, msg)
+
+/** \brief Log a message at WARN level */
+#define NFD_LOG_FACE_WARN(msg) NFD_LOG_FACE(WARN, msg)
+
+/** \brief Log a message at ERROR level */
+#define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
+
+/** @} */
+
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_FACE_LOG_HPP
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index a5923d2..9c2f2e6 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -29,6 +29,7 @@
#include "common.hpp"
#include "core/logger.hpp"
#include "face-counters.hpp"
+#include "face-log.hpp"
#include <ndn-cxx/management/nfd-face-status.hpp>
@@ -82,12 +83,18 @@
/// fires when a Data is received
signal::Signal<Face, Data> onReceiveData;
+ /// fires when a Nack is received
+ signal::Signal<Face, lp::Nack> onReceiveNack;
+
/// fires when an Interest is sent out
signal::Signal<Face, Interest> onSendInterest;
/// fires when a Data is sent out
signal::Signal<Face, Data> onSendData;
+ /// fires when a Nack is sent out
+ signal::Signal<Face, lp::Nack> onSendNack;
+
/// fires when face disconnects or fails to perform properly
signal::Signal<Face, std::string/*reason*/> onFail;
@@ -99,6 +106,12 @@
virtual void
sendData(const Data& data) = 0;
+ /// send a Nack
+ virtual void
+ sendNack(const ndn::lp::Nack& nack)
+ {
+ }
+
/** \brief Close the face
*
* This terminates all communication on the face and cause
@@ -133,6 +146,10 @@
ndn::nfd::FacePersistency
getPersistency() const;
+ // 'virtual' to allow override in LpFaceWrapper
+ virtual void
+ setPersistency(ndn::nfd::FacePersistency persistency);
+
/** \brief Get whether packets sent by this face may reach multiple peers
*/
bool
@@ -145,7 +162,8 @@
virtual bool
isUp() const;
- const FaceCounters&
+ // 'virtual' to allow override in LpFaceWrapper
+ virtual const FaceCounters&
getCounters() const;
/** \return a FaceUri that represents the remote endpoint
@@ -169,10 +187,6 @@
virtual ndn::nfd::FaceStatus
getFaceStatus() const;
-PUBLIC_WITH_TESTS_ELSE_PROTECTED:
- void
- setPersistency(ndn::nfd::FacePersistency persistency);
-
protected:
bool
decodeAndDispatchInput(const Block& element);
@@ -187,12 +201,14 @@
DECLARE_SIGNAL_EMIT(onReceiveInterest)
DECLARE_SIGNAL_EMIT(onReceiveData)
+ DECLARE_SIGNAL_EMIT(onReceiveNack)
DECLARE_SIGNAL_EMIT(onSendInterest)
DECLARE_SIGNAL_EMIT(onSendData)
+ DECLARE_SIGNAL_EMIT(onSendNack)
-private:
// this method should be used only by the FaceTable
- void
+ // 'virtual' to allow override in LpFaceWrapper
+ virtual void
setId(FaceId faceId);
private:
@@ -282,38 +298,15 @@
return m_localUri;
}
-
-/** \defgroup FaceLogging Face logging macros
- *
- * These macros augment the log message with some face-specific information,
- * such as the face ID, that are useful to distinguish which face produced the
- * message. It is strongly recommended to use these macros instead of the
- * generic ones for all logging inside Face subclasses.
- * @{
- */
-
-#define NFD_LOG_FACE(level, msg) \
- NFD_LOG_##level("[id=" << this->getId() << \
- ",local=" << this->getLocalUri() << \
- ",remote=" << this->getRemoteUri() << \
- "] " << msg)
-
-/** \brief Log a message at TRACE level */
-#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
-
-/** \brief Log a message at DEBUG level */
-#define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
-
-/** \brief Log a message at INFO level */
-#define NFD_LOG_FACE_INFO(msg) NFD_LOG_FACE(INFO, msg)
-
-/** \brief Log a message at WARN level */
-#define NFD_LOG_FACE_WARN(msg) NFD_LOG_FACE(WARN, msg)
-
-/** \brief Log a message at ERROR level */
-#define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
-
-/** @} */
+template<typename T>
+typename std::enable_if<std::is_base_of<Face, T>::value, std::ostream&>::type
+operator<<(std::ostream& os, const face::FaceLogHelper<T>& flh)
+{
+ const Face& face = flh.obj;
+ os << "[id=" << face.getId() << ",local=" << face.getLocalUri() <<
+ ",remote=" << face.getRemoteUri() << "] ";
+ return os;
+}
} // namespace nfd
diff --git a/daemon/face/generic-link-service.cpp b/daemon/face/generic-link-service.cpp
new file mode 100644
index 0000000..4fa4c1c
--- /dev/null
+++ b/daemon/face/generic-link-service.cpp
@@ -0,0 +1,257 @@
+/* -*- 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 "generic-link-service.hpp"
+
+namespace nfd {
+namespace face {
+
+NFD_LOG_INIT("GenericLinkService");
+
+GenericLinkService::Options::Options()
+ : allowLocalFields(false)
+{
+}
+
+GenericLinkService::GenericLinkService(const GenericLinkService::Options& options)
+ : m_options(options)
+{
+}
+
+void
+GenericLinkService::doSendInterest(const Interest& interest)
+{
+ lp::Packet lpPacket(interest.wireEncode());
+ if (m_options.allowLocalFields) {
+ encodeLocalFields(interest, lpPacket);
+ }
+ Transport::Packet packet;
+ packet.packet = lpPacket.wireEncode();
+ sendPacket(std::move(packet));
+}
+
+void
+GenericLinkService::doSendData(const Data& data)
+{
+ lp::Packet lpPacket(data.wireEncode());
+ if (m_options.allowLocalFields) {
+ encodeLocalFields(data, lpPacket);
+ }
+ Transport::Packet packet;
+ packet.packet = lpPacket.wireEncode();
+ sendPacket(std::move(packet));
+}
+
+void
+GenericLinkService::doSendNack(const lp::Nack& nack)
+{
+ lp::Packet lpPacket(nack.getInterest().wireEncode());
+ lpPacket.add<lp::NackField>(nack.getHeader());
+ if (m_options.allowLocalFields) {
+ encodeLocalFields(nack.getInterest(), lpPacket);
+ }
+ Transport::Packet packet;
+ packet.packet = lpPacket.wireEncode();
+ sendPacket(std::move(packet));
+}
+
+bool
+GenericLinkService::encodeLocalFields(const Interest& interest, lp::Packet& lpPacket)
+{
+ if (interest.getLocalControlHeader().hasIncomingFaceId()) {
+ lpPacket.add<lp::IncomingFaceIdField>(interest.getIncomingFaceId());
+ }
+
+ if (interest.getLocalControlHeader().hasCachingPolicy()) {
+ // Packet must be dropped
+ return false;
+ }
+
+ return true;
+}
+
+bool
+GenericLinkService::encodeLocalFields(const Data& data, lp::Packet& lpPacket)
+{
+ if (data.getLocalControlHeader().hasIncomingFaceId()) {
+ lpPacket.add<lp::IncomingFaceIdField>(data.getIncomingFaceId());
+ }
+
+ if (data.getLocalControlHeader().hasCachingPolicy()) {
+ switch (data.getCachingPolicy()) {
+ case ndn::nfd::LocalControlHeader::CachingPolicy::NO_CACHE: {
+ lp::CachePolicy cachePolicy;
+ cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE);
+ lpPacket.add<lp::CachePolicyField>(cachePolicy);
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ }
+
+ return true;
+}
+
+void
+GenericLinkService::doReceivePacket(Transport::Packet&& packet)
+{
+ lp::Packet pkt(packet.packet);
+
+ if (pkt.has<lp::FragIndexField>() || pkt.has<lp::FragCountField>()) {
+ NFD_LOG_FACE_WARN("received fragment, but reassembly not implemented: DROP");
+ return;
+ }
+
+ try {
+ ndn::Buffer::const_iterator fragBegin, fragEnd;
+ std::tie(fragBegin, fragEnd) = pkt.get<lp::FragmentField>();
+ Block netPkt(&*fragBegin, std::distance(fragBegin, fragEnd));
+
+ switch (netPkt.type()) {
+ case tlv::Interest:
+ if (pkt.has<lp::NackField>()) {
+ this->decodeNack(netPkt, pkt);
+ }
+ else {
+ this->decodeInterest(netPkt, pkt);
+ }
+ break;
+ case tlv::Data:
+ this->decodeData(netPkt, pkt);
+ break;
+ default:
+ NFD_LOG_FACE_WARN("unrecognized network-layer packet TLV-TYPE " << netPkt.type() << ": DROP");
+ return;
+ }
+ }
+ catch (const tlv::Error& e) {
+ NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
+ }
+}
+
+
+void
+GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstPkt)
+{
+ BOOST_ASSERT(netPkt.type() == tlv::Interest);
+ BOOST_ASSERT(!firstPkt.has<lp::NackField>());
+
+ // forwarding expects Interest to be created with make_shared
+ auto interest = make_shared<Interest>(netPkt);
+
+ if (firstPkt.has<lp::NextHopFaceIdField>()) {
+ if (m_options.allowLocalFields) {
+ interest->setNextHopFaceId(firstPkt.get<lp::NextHopFaceIdField>());
+ }
+ else {
+ NFD_LOG_FACE_WARN("received NextHopFaceId, but local fields disabled: DROP");
+ return;
+ }
+ }
+
+ if (firstPkt.has<lp::CachePolicyField>()) {
+ NFD_LOG_FACE_WARN("received CachePolicy with Interest: DROP");
+ return;
+ }
+
+ if (firstPkt.has<lp::IncomingFaceIdField>()) {
+ NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
+ }
+
+ this->receiveInterest(*interest);
+}
+
+void
+GenericLinkService::decodeData(const Block& netPkt, const lp::Packet& firstPkt)
+{
+ BOOST_ASSERT(netPkt.type() == tlv::Data);
+
+ // forwarding expects Data to be created with make_shared
+ auto data = make_shared<Data>(netPkt);
+
+ if (firstPkt.has<lp::NackField>()) {
+ NFD_LOG_FACE_WARN("received Nack with Data: DROP");
+ return;
+ }
+
+ if (firstPkt.has<lp::NextHopFaceIdField>()) {
+ NFD_LOG_FACE_WARN("received NextHopFaceId with Data: DROP");
+ return;
+ }
+
+ if (firstPkt.has<lp::CachePolicyField>()) {
+ if (m_options.allowLocalFields) {
+ lp::CachePolicyType policy = firstPkt.get<lp::CachePolicyField>().getPolicy();
+ switch (policy) {
+ case lp::CachePolicyType::NO_CACHE:
+ data->setCachingPolicy(ndn::nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
+ break;
+ default:
+ NFD_LOG_FACE_WARN("unrecognized CachePolicyType " << policy << ": DROP");
+ return;
+ }
+ }
+ else {
+ NFD_LOG_FACE_WARN("received CachePolicy, but local fields disabled: IGNORE");
+ }
+ }
+
+ if (firstPkt.has<lp::IncomingFaceIdField>()) {
+ NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
+ }
+
+ this->receiveData(*data);
+}
+
+void
+GenericLinkService::decodeNack(const Block& netPkt, const lp::Packet& firstPkt)
+{
+ BOOST_ASSERT(netPkt.type() == tlv::Interest);
+ BOOST_ASSERT(firstPkt.has<lp::NackField>());
+
+ lp::Nack nack((Interest(netPkt)));
+ nack.setHeader(firstPkt.get<lp::NackField>());
+
+ if (firstPkt.has<lp::NextHopFaceIdField>()) {
+ NFD_LOG_FACE_WARN("received NextHopFaceId with Nack: DROP");
+ return;
+ }
+
+ if (firstPkt.has<lp::CachePolicyField>()) {
+ NFD_LOG_FACE_WARN("received CachePolicy with Nack: DROP");
+ return;
+ }
+
+ if (firstPkt.has<lp::IncomingFaceIdField>()) {
+ NFD_LOG_FACE_WARN("received IncomingFaceId: IGNORE");
+ }
+
+ this->receiveNack(nack);
+}
+
+} // namespace face
+} // namespace nfd
diff --git a/daemon/face/generic-link-service.hpp b/daemon/face/generic-link-service.hpp
new file mode 100644
index 0000000..ae3328f
--- /dev/null
+++ b/daemon/face/generic-link-service.hpp
@@ -0,0 +1,162 @@
+/* -*- 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_GENERIC_LINK_SERVICE_HPP
+#define NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
+
+#include "common.hpp"
+#include "core/logger.hpp"
+
+#include "link-service.hpp"
+
+#include <ndn-cxx/lp/packet.hpp>
+
+namespace nfd {
+namespace face {
+
+/** \brief GenericLinkService is a LinkService that implements the NDNLPv2 protocol
+ * \sa http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
+ */
+class GenericLinkService : public LinkService
+{
+public:
+ /** \brief Options that control the behavior of GenericLinkService
+ */
+ class Options
+ {
+ public:
+ Options();
+
+ public:
+ // TODO #3171: fragmentation and reassembly options
+
+ /** \brief enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy
+ */
+ bool allowLocalFields;
+ };
+
+ explicit
+ GenericLinkService(const Options& options = Options());
+
+ /** \brief get Options used by GenericLinkService
+ */
+ const Options&
+ getOptions() const;
+
+ /** \brief sets Options used by GenericLinkService
+ */
+ void
+ setOptions(const Options& options);
+
+private: // send path entrypoint
+ /** \brief sends Interest
+ */
+ void
+ doSendInterest(const Interest& interest) DECL_OVERRIDE;
+
+ /** \brief sends Data
+ */
+ void
+ doSendData(const Data& data) DECL_OVERRIDE;
+
+ /** \brief sends Nack
+ * This class does not send out a Nack.
+ */
+ void
+ doSendNack(const ndn::lp::Nack& nack) DECL_OVERRIDE;
+
+private: // receive path entrypoint
+ /** \brief receives Packet
+ */
+ void
+ doReceivePacket(Transport::Packet&& packet) DECL_OVERRIDE;
+
+private: // encoding and decoding
+ /** \brief encode IncomingFaceId into LpPacket and verify local fields
+ */
+ static bool
+ encodeLocalFields(const Interest& interest, lp::Packet& lpPacket);
+
+ /** \brief encode CachingPolicy and IncomingFaceId into LpPacket and verify local fields
+ */
+ static bool
+ encodeLocalFields(const Data& data, lp::Packet& lpPacket);
+
+ /** \brief decode incoming Interest
+ * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest
+ * \param firstPkt LpPacket of first fragment; must not have Nack field
+ *
+ * If decoding is successful, receiveInterest signal is emitted;
+ * otherwise, a warning is logged.
+ *
+ * \throw tlv::Error parse error in an LpHeader field
+ */
+ void
+ decodeInterest(const Block& netPkt, const lp::Packet& firstPkt);
+
+ /** \brief decode incoming Interest
+ * \param netPkt reassembled network-layer packet; TLV-TYPE must be Data
+ * \param firstPkt LpPacket of first fragment
+ *
+ * If decoding is successful, receiveData signal is emitted;
+ * otherwise, a warning is logged.
+ *
+ * \throw tlv::Error parse error in an LpHeader field
+ */
+ void
+ decodeData(const Block& netPkt, const lp::Packet& firstPkt);
+
+ /** \brief decode incoming Interest
+ * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest
+ * \param firstPkt LpPacket of first fragment; must have Nack field
+ *
+ * If decoding is successful, receiveNack signal is emitted;
+ * otherwise, a warning is logged.
+ *
+ * \throw tlv::Error parse error in an LpHeader field
+ */
+ void
+ decodeNack(const Block& netPkt, const lp::Packet& firstPkt);
+
+private:
+ Options m_options;
+};
+
+inline const GenericLinkService::Options&
+GenericLinkService::getOptions() const
+{
+ return m_options;
+}
+
+inline void
+GenericLinkService::setOptions(const GenericLinkService::Options& options)
+{
+ m_options = options;
+}
+
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP
diff --git a/daemon/face/internal-client-face.hpp b/daemon/face/internal-client-face.hpp
index 8eb3c46..abc375b 100644
--- a/daemon/face/internal-client-face.hpp
+++ b/daemon/face/internal-client-face.hpp
@@ -31,6 +31,7 @@
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/transport/transport.hpp>
+#include <ndn-cxx/lp/packet.hpp>
namespace nfd {
@@ -95,22 +96,19 @@
void
InternalClientFace::receive(const Packet& packet)
{
- if (!packet.getLocalControlHeader().empty(ndn::nfd::LocalControlHeader::ENCODE_ALL)) {
+ lp::Packet lpPacket(packet.wireEncode());
- Block header = packet.getLocalControlHeader()
- .wireEncode(packet, ndn::nfd::LocalControlHeader::ENCODE_ALL);
- Block payload = packet.wireEncode();
+ ndn::nfd::LocalControlHeader localControlHeader = packet.getLocalControlHeader();
- 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());
+ if (localControlHeader.hasIncomingFaceId()) {
+ lpPacket.add<lp::IncomingFaceIdField>(localControlHeader.getIncomingFaceId());
}
- else {
- m_transport->receive(packet.wireEncode());
+
+ if (localControlHeader.hasNextHopFaceId()) {
+ lpPacket.add<lp::NextHopFaceIdField>(localControlHeader.getNextHopFaceId());
}
+
+ m_transport->receive(lpPacket.wireEncode());
}
} // namespace nfd
diff --git a/daemon/face/link-service.cpp b/daemon/face/link-service.cpp
new file mode 100644
index 0000000..3f19388
--- /dev/null
+++ b/daemon/face/link-service.cpp
@@ -0,0 +1,135 @@
+/* -*- 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 "link-service.hpp"
+#include "lp-face.hpp"
+#include "transport.hpp"
+
+namespace nfd {
+namespace face {
+
+NFD_LOG_INIT("LinkService");
+
+LinkService::LinkService()
+ : m_face(nullptr)
+ , m_transport(nullptr)
+ , m_counters(nullptr)
+{
+}
+
+LinkService::~LinkService()
+{
+}
+
+void
+LinkService::setFaceAndTransport(LpFace& face, Transport& transport)
+{
+ BOOST_ASSERT(m_face == nullptr);
+ BOOST_ASSERT(m_transport == nullptr);
+
+ m_face = &face;
+ m_transport = &transport;
+ m_counters = &m_face->getMutableCounters();
+}
+
+void
+LinkService::sendInterest(const Interest& interest)
+{
+ BOOST_ASSERT(m_transport != nullptr);
+ NFD_LOG_FACE_TRACE(__func__);
+
+ ++m_counters->getNOutInterests();
+
+ doSendInterest(interest);
+}
+
+void
+LinkService::sendData(const Data& data)
+{
+ BOOST_ASSERT(m_transport != nullptr);
+ NFD_LOG_FACE_TRACE(__func__);
+
+ ++m_counters->getNOutDatas();
+
+ doSendData(data);
+}
+
+void
+LinkService::sendNack(const ndn::lp::Nack& nack)
+{
+ BOOST_ASSERT(m_transport != nullptr);
+ NFD_LOG_FACE_TRACE(__func__);
+
+ // TODO#3177 increment counter
+
+ doSendNack(nack);
+}
+
+void
+LinkService::receiveInterest(const Interest& interest)
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ ++m_counters->getNInInterests();
+
+ afterReceiveInterest(interest);
+}
+
+void
+LinkService::receiveData(const Data& data)
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ ++m_counters->getNInDatas();
+
+ afterReceiveData(data);
+}
+
+void
+LinkService::receiveNack(const ndn::lp::Nack& nack)
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ // TODO#3177 increment counter
+
+ afterReceiveNack(nack);
+}
+
+std::ostream&
+operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh)
+{
+ const LpFace* face = flh.obj.getFace();
+ if (face == nullptr) {
+ os << "[id=0,local=unknown,remote=unknown] ";
+ }
+ else {
+ os << "[id=" << face->getId() << ",local=" << face->getLocalUri()
+ << ",remote=" << face->getRemoteUri() << "] ";
+ }
+ return os;
+}
+
+} // namespace face
+} // namespace nfd
diff --git a/daemon/face/link-service.hpp b/daemon/face/link-service.hpp
new file mode 100644
index 0000000..1b7bda8
--- /dev/null
+++ b/daemon/face/link-service.hpp
@@ -0,0 +1,198 @@
+/* -*- 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_LINK_SERVICE_HPP
+#define NFD_DAEMON_FACE_LINK_SERVICE_HPP
+
+#include "transport.hpp"
+#include "face-log.hpp"
+
+namespace nfd {
+namespace face {
+
+class LpFace;
+
+/** \brief the upper part of an LpFace
+ * \sa LpFace
+ */
+class LinkService : noncopyable
+{
+public:
+ LinkService();
+
+ virtual
+ ~LinkService();
+
+ /** \brief set Face and Transport for LinkService
+ * \pre setFaceAndTransport has not been called
+ */
+ void
+ setFaceAndTransport(LpFace& face, Transport& transport);
+
+ /** \return Face to which this LinkService is attached
+ */
+ const LpFace*
+ getFace() const;
+
+ /** \return Transport to which this LinkService is attached
+ */
+ const Transport*
+ getTransport() const;
+
+ /** \return Transport to which this LinkService is attached
+ */
+ Transport*
+ getTransport();
+
+public: // upper interface to be used by forwarding
+ /** \brief send Interest
+ * \pre setTransport has been called
+ */
+ void
+ sendInterest(const Interest& interest);
+
+ /** \brief send Data
+ * \pre setTransport has been called
+ */
+ void
+ sendData(const Data& data);
+
+ /** \brief send Nack
+ * \pre setTransport has been called
+ */
+ void
+ sendNack(const ndn::lp::Nack& nack);
+
+ /** \brief signals on Interest received
+ */
+ signal::Signal<LinkService, Interest> afterReceiveInterest;
+
+ /** \brief signals on Data received
+ */
+ signal::Signal<LinkService, Data> afterReceiveData;
+
+ /** \brief signals on Nack received
+ */
+ signal::Signal<LinkService, lp::Nack> afterReceiveNack;
+
+private: // upper interface to be overridden in subclass (send path entrypoint)
+ /** \brief performs LinkService specific operations to send an Interest
+ */
+ virtual void
+ doSendInterest(const Interest& interest) = 0;
+
+ /** \brief performs LinkService specific operations to send a Data
+ */
+ virtual void
+ doSendData(const Data& data) = 0;
+
+ /** \brief performs LinkService specific operations to send a Nack
+ */
+ virtual void
+ doSendNack(const lp::Nack& nack) = 0;
+
+protected: // upper interface to be invoked in subclass (receive path termination)
+ /** \brief delivers received Interest to forwarding
+ */
+ void
+ receiveInterest(const Interest& interest);
+
+ /** \brief delivers received Data to forwarding
+ */
+ void
+ receiveData(const Data& data);
+
+ /** \brief delivers received Nack to forwarding
+ */
+ void
+ receiveNack(const lp::Nack& nack);
+
+public: // lower interface to be invoked by Transport
+ /** \brief performs LinkService specific operations to receive a lower-layer packet
+ */
+ void
+ receivePacket(Transport::Packet&& packet);
+
+protected: // lower interface to be invoked in subclass (send path termination)
+ /** \brief sends a lower-layer packet via Transport
+ */
+ void
+ sendPacket(Transport::Packet&& packet);
+
+private: // lower interface to be overridden in subclass
+ virtual void
+ doReceivePacket(Transport::Packet&& packet) = 0;
+
+private:
+ LpFace* m_face;
+ Transport* m_transport;
+ NetworkLayerCounters* m_counters; // TODO#3177 change into NetCounters
+};
+
+inline const LpFace*
+LinkService::getFace() const
+{
+ return m_face;
+}
+
+inline const Transport*
+LinkService::getTransport() const
+{
+ return m_transport;
+}
+
+inline Transport*
+LinkService::getTransport()
+{
+ return m_transport;
+}
+
+inline void
+LinkService::receivePacket(Transport::Packet&& packet)
+{
+ doReceivePacket(std::move(packet));
+}
+
+inline void
+LinkService::sendPacket(Transport::Packet&& packet)
+{
+ m_transport->send(std::move(packet));
+}
+
+std::ostream&
+operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
+
+template<typename T>
+typename std::enable_if<std::is_base_of<LinkService, T>::value &&
+ !std::is_same<LinkService, T>::value, std::ostream&>::type
+operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
+{
+ return os << FaceLogHelper<LinkService>(flh.obj);
+}
+
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP
diff --git a/daemon/face/lp-face-wrapper.cpp b/daemon/face/lp-face-wrapper.cpp
new file mode 100644
index 0000000..920997a
--- /dev/null
+++ b/daemon/face/lp-face-wrapper.cpp
@@ -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/>.
+ */
+
+#include "lp-face-wrapper.hpp"
+
+namespace nfd {
+namespace face {
+
+LpFaceWrapper::LpFaceWrapper(unique_ptr<LpFace> face)
+ : Face(face->getRemoteUri(), face->getLocalUri(),
+ face->getScope() == ndn::nfd::FACE_SCOPE_LOCAL,
+ face->getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS)
+ , m_face(std::move(face))
+{
+ this->Face::setPersistency(m_face->getPersistency());
+ m_face->afterReceiveInterest.connect(bind(&LpFaceWrapper::dispatchInterest, this, _1));
+ m_face->afterReceiveData.connect(bind(&LpFaceWrapper::dispatchData, this, _1));
+ m_face->afterReceiveNack.connect(bind(&LpFaceWrapper::dispatchNack, this, _1));
+ m_face->afterStateChange.connect(bind(&LpFaceWrapper::handleStateChange, this, _1, _2));
+}
+
+void
+LpFaceWrapper::setPersistency(ndn::nfd::FacePersistency persistency)
+{
+ this->Face::setPersistency(persistency);
+ m_face->setPersistency(persistency);
+}
+
+void
+LpFaceWrapper::setId(nfd::FaceId faceId)
+{
+ this->Face::setId(faceId);
+
+ FaceId lpId = static_cast<FaceId>(faceId);
+ if (faceId == nfd::INVALID_FACEID) {
+ lpId = INVALID_FACEID;
+ }
+ m_face->setId(lpId);
+}
+
+void
+LpFaceWrapper::dispatchInterest(const Interest& interest)
+{
+ this->emitSignal(onReceiveInterest, interest);
+}
+
+void
+LpFaceWrapper::dispatchData(const Data& data)
+{
+ this->emitSignal(onReceiveData, data);
+}
+
+void
+LpFaceWrapper::dispatchNack(const ndn::lp::Nack& nack)
+{
+ this->emitSignal(onReceiveNack, nack);
+}
+
+void
+LpFaceWrapper::handleStateChange(FaceState oldState, FaceState newState)
+{
+ if (newState != FaceState::CLOSED) {
+ return;
+ }
+
+ switch (oldState) {
+ case FaceState::CLOSING:
+ this->fail("LpFace closed");
+ break;
+ case FaceState::FAILED:
+ this->fail("LpFace failed");
+ break;
+ default:
+ BOOST_ASSERT(false);
+ break;
+ }
+}
+
+} // namespace face
+} // namespace nfd
diff --git a/daemon/face/lp-face-wrapper.hpp b/daemon/face/lp-face-wrapper.hpp
new file mode 100644
index 0000000..084094f
--- /dev/null
+++ b/daemon/face/lp-face-wrapper.hpp
@@ -0,0 +1,140 @@
+/* -*- 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_LP_FACE_WRAPPER_HPP
+#define NFD_DAEMON_FACE_LP_FACE_WRAPPER_HPP
+
+#include "common.hpp"
+#include "face.hpp"
+#include "lp-face.hpp"
+
+namespace nfd {
+namespace face {
+
+/** \brief an adaptor to provide old Face APIs from an LpFace
+ * \sa LpFace
+ * \note When LpFace is adapted by LpFaceWrapper,
+ * FaceId and counters will come from old Face rather than LpFace.
+ */
+class LpFaceWrapper : public Face
+{
+public:
+ explicit
+ LpFaceWrapper(unique_ptr<LpFace> face);
+
+ LpFace*
+ getLpFace();
+
+ virtual void
+ sendInterest(const Interest& interest) DECL_OVERRIDE;
+
+ virtual void
+ sendData(const Data& data) DECL_OVERRIDE;
+
+ virtual void
+ sendNack(const lp::Nack& nack) DECL_OVERRIDE;
+
+ virtual void
+ close() DECL_OVERRIDE;
+
+ virtual bool
+ isUp() const DECL_OVERRIDE;
+
+ virtual void
+ setPersistency(ndn::nfd::FacePersistency persistency) DECL_OVERRIDE;
+
+ virtual const FaceCounters&
+ getCounters() const DECL_OVERRIDE;
+
+protected:
+ virtual void
+ setId(nfd::FaceId faceId) DECL_OVERRIDE;
+
+private:
+ void
+ dispatchInterest(const Interest& interest);
+
+ void
+ dispatchData(const Data& data);
+
+ void
+ dispatchNack(const lp::Nack& nack);
+
+ void
+ handleStateChange(FaceState oldState, FaceState newState);
+
+private:
+ unique_ptr<LpFace> m_face;
+};
+
+inline LpFace*
+LpFaceWrapper::getLpFace()
+{
+ return m_face.get();
+}
+
+inline void
+LpFaceWrapper::sendInterest(const Interest& interest)
+{
+ this->emitSignal(onSendInterest, interest);
+ m_face->sendInterest(interest);
+}
+
+inline void
+LpFaceWrapper::sendData(const Data& data)
+{
+ this->emitSignal(onSendData, data);
+ m_face->sendData(data);
+}
+
+inline void
+LpFaceWrapper::sendNack(const lp::Nack& nack)
+{
+ this->emitSignal(onSendNack, nack);
+ m_face->sendNack(nack);
+}
+
+inline void
+LpFaceWrapper::close()
+{
+ m_face->close();
+}
+
+inline bool
+LpFaceWrapper::isUp() const
+{
+ return m_face->getState() == FaceState::UP;
+}
+
+inline const FaceCounters&
+LpFaceWrapper::getCounters() const
+{
+ return m_face->getCounters();
+}
+
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_LP_FACE_WRAPPER_HPP
diff --git a/daemon/face/udp-face.hpp b/daemon/face/lp-face.cpp
similarity index 60%
copy from daemon/face/udp-face.hpp
copy to daemon/face/lp-face.cpp
index a7541a5..0b2e826 100644
--- a/daemon/face/udp-face.hpp
+++ b/daemon/face/lp-face.cpp
@@ -23,41 +23,23 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NFD_DAEMON_FACE_UDP_FACE_HPP
-#define NFD_DAEMON_FACE_UDP_FACE_HPP
-
-#include "datagram-face.hpp"
-#include "core/scheduler.hpp"
+#include "lp-face.hpp"
namespace nfd {
+namespace face {
-/**
- * \brief Implementation of Face abstraction that uses
- * unicast UDP as underlying transport mechanism
- */
-class UdpFace : public DatagramFace<boost::asio::ip::udp>
+LpFace::LpFace(unique_ptr<LinkService> service, unique_ptr<Transport> transport)
+ : afterReceiveInterest(service->afterReceiveInterest)
+ , afterReceiveData(service->afterReceiveData)
+ , afterReceiveNack(service->afterReceiveNack)
+ , afterStateChange(transport->afterStateChange)
+ , m_id(INVALID_FACEID)
+ , m_service(std::move(service))
+ , m_transport(std::move(transport))
{
-public:
- UdpFace(const FaceUri& remoteUri, const FaceUri& localUri,
- protocol::socket socket, ndn::nfd::FacePersistency persistency,
- const time::seconds& idleTimeout);
+ m_service->setFaceAndTransport(*this, *m_transport);
+ m_transport->setFaceAndLinkService(*this, *m_service);
+}
- ndn::nfd::FaceStatus
- getFaceStatus() const DECL_OVERRIDE;
-
-private:
- void
- closeIfIdle();
-
-private:
- const time::seconds m_idleTimeout;
- time::steady_clock::TimePoint m_lastIdleCheck;
- scheduler::ScopedEventId m_closeIfIdleEvent;
-
- // friend because it needs to invoke protected Face::setOnDemand
- friend class UdpChannel;
-};
-
+} // namespace face
} // namespace nfd
-
-#endif // NFD_DAEMON_FACE_UDP_FACE_HPP
diff --git a/daemon/face/lp-face.hpp b/daemon/face/lp-face.hpp
new file mode 100644
index 0000000..d825928
--- /dev/null
+++ b/daemon/face/lp-face.hpp
@@ -0,0 +1,311 @@
+/* -*- 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_LP_FACE_HPP
+#define NFD_DAEMON_LP_FACE_HPP
+
+#include "transport.hpp"
+#include "link-service.hpp"
+#include "face-log.hpp"
+
+namespace nfd {
+namespace face {
+
+/** \brief identifies a face
+ */
+typedef uint64_t FaceId;
+
+/// indicates an invalid FaceId
+const FaceId INVALID_FACEID = 0;
+/// identifies the InternalFace used in management
+const FaceId FACEID_INTERNAL_FACE = 1;
+/// identifies a packet comes from the ContentStore, in LocalControlHeader incomingFaceId
+const FaceId FACEID_CONTENT_STORE = 254;
+/// identifies the NullFace that drops every packet
+const FaceId FACEID_NULL = 255;
+/// upper bound of reserved FaceIds
+const FaceId FACEID_RESERVED_MAX = 255;
+
+/** \brief indicates the state of a face
+ */
+typedef TransportState FaceState;
+
+/** \brief generalization of a network interface
+ *
+ * A face generalizes a network interface.
+ * It provides network-layer packet delivery services on a physical interface,
+ * an overlay tunnel, or a link to a local application, with best-effort.
+ *
+ * A face combines two parts: LinkService and Transport.
+ * Transport is the lower part, which provides TLV block delivery services with best-effort.
+ * LinkService is the upper part, which translates between network-layer packets
+ * and TLV blocks, and may provide additional services such as fragmentation and reassembly.
+ *
+ * We are in the process of refactoring face system to use this LinkService+Transport
+ * architecture. During this process, the "face" is named LpFace, and we implement a
+ * LpFaceWrapper class as an adaptor to the old Face APIs. After the completion of refactoring,
+ * LpFace will be renamed to Face.
+ */
+class LpFace
+#ifndef WITH_TESTS
+DECL_CLASS_FINAL
+#endif
+ : noncopyable
+{
+public:
+ LpFace(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
+
+ LinkService*
+ getLinkService();
+
+ Transport*
+ getTransport();
+
+public: // upper interface connected to forwarding
+ /** \brief sends Interest on Face
+ */
+ void
+ sendInterest(const Interest& interest);
+
+ /** \brief sends Data on Face
+ */
+ void
+ sendData(const Data& data);
+
+ /** \brief sends Nack on Face
+ */
+ void
+ sendNack(const lp::Nack& nack);
+
+ /** \brief signals on Interest received
+ */
+ signal::Signal<LinkService, Interest>& afterReceiveInterest;
+
+ /** \brief signals on Data received
+ */
+ signal::Signal<LinkService, Data>& afterReceiveData;
+
+ /** \brief signals on Nack received
+ */
+ signal::Signal<LinkService, lp::Nack>& afterReceiveNack;
+
+public: // static properties
+ /** \return face ID
+ */
+ FaceId
+ getId() const;
+
+ /** \brief sets face ID
+ * \note Normally, this should only be invoked by FaceTable.
+ */
+ void
+ setId(FaceId id);
+
+ /** \return a FaceUri representing local endpoint
+ */
+ FaceUri
+ getLocalUri() const;
+
+ /** \return a FaceUri representing remote endpoint
+ */
+ FaceUri
+ getRemoteUri() const;
+
+ /** \return whether face is local or non-local for scope control purpose
+ */
+ ndn::nfd::FaceScope
+ getScope() const;
+
+ /** \return face persistency setting
+ */
+ ndn::nfd::FacePersistency
+ getPersistency() const;
+
+ /** \brief changes face persistency setting
+ */
+ void
+ setPersistency(ndn::nfd::FacePersistency persistency);
+
+ /** \return whether face is point-to-point or multi-access
+ */
+ ndn::nfd::LinkType
+ getLinkType() const;
+
+public: // dynamic properties
+ /** \return face state
+ */
+ FaceState
+ getState() const;
+
+ /** \brief signals after face state changed
+ */
+ signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
+
+ /** \brief request the face to be closed
+ *
+ * This operation is effective only if face is in UP or DOWN state,
+ * otherwise it has no effect.
+ * The face changes state to CLOSING, and performs cleanup procedure.
+ * The state will be changed to CLOSED when cleanup is complete, which may
+ * happen synchronously or asynchronously.
+ *
+ * \warning the face must not be deallocated until its state changes to CLOSED
+ */
+ void
+ close();
+
+ const FaceCounters&
+ getCounters() const;
+
+ FaceCounters&
+ getMutableCounters();
+
+private:
+ FaceId m_id;
+ unique_ptr<LinkService> m_service;
+ unique_ptr<Transport> m_transport;
+ FaceCounters m_counters;
+};
+
+inline LinkService*
+LpFace::getLinkService()
+{
+ return m_service.get();
+}
+
+inline Transport*
+LpFace::getTransport()
+{
+ return m_transport.get();
+}
+
+inline void
+LpFace::sendInterest(const Interest& interest)
+{
+ m_service->sendInterest(interest);
+}
+
+inline void
+LpFace::sendData(const Data& data)
+{
+ m_service->sendData(data);
+}
+
+inline void
+LpFace::sendNack(const lp::Nack& nack)
+{
+ m_service->sendNack(nack);
+}
+
+inline FaceId
+LpFace::getId() const
+{
+ return m_id;
+}
+
+inline void
+LpFace::setId(FaceId id)
+{
+ m_id = id;
+}
+
+inline FaceUri
+LpFace::getLocalUri() const
+{
+ return m_transport->getLocalUri();
+}
+
+inline FaceUri
+LpFace::getRemoteUri() const
+{
+ return m_transport->getRemoteUri();
+}
+
+inline ndn::nfd::FaceScope
+LpFace::getScope() const
+{
+ return m_transport->getScope();
+}
+
+inline ndn::nfd::FacePersistency
+LpFace::getPersistency() const
+{
+ return m_transport->getPersistency();
+}
+
+inline void
+LpFace::setPersistency(ndn::nfd::FacePersistency persistency)
+{
+ return m_transport->setPersistency(persistency);
+}
+
+inline ndn::nfd::LinkType
+LpFace::getLinkType() const
+{
+ return m_transport->getLinkType();
+}
+
+inline FaceState
+LpFace::getState() const
+{
+ return m_transport->getState();
+}
+
+inline void
+LpFace::close()
+{
+ m_transport->close();
+}
+
+inline const FaceCounters&
+LpFace::getCounters() const
+{
+ return m_counters;
+}
+
+inline FaceCounters&
+LpFace::getMutableCounters()
+{
+ return m_counters;
+}
+
+template<typename T>
+typename std::enable_if<std::is_base_of<LpFace, T>::value, std::ostream&>::type
+operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
+{
+ const LpFace& face = flh.obj;
+ os << "[id=" << face.getId() << ",local=" << face.getLocalUri() <<
+ ",remote=" << face.getRemoteUri() << "] ";
+ return os;
+}
+
+} // namespace face
+
+// using face::FaceId; // TODO uncomment in #3172
+using face::LpFace;
+
+} // namespace nfd
+
+#endif // NFD_DAEMON_LP_FACE_HPP
diff --git a/daemon/face/multicast-udp-face.cpp b/daemon/face/multicast-udp-face.cpp
deleted file mode 100644
index 8ac07af..0000000
--- a/daemon/face/multicast-udp-face.cpp
+++ /dev/null
@@ -1,77 +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 "multicast-udp-face.hpp"
-
-namespace nfd {
-
-NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(DatagramFace,
- MulticastUdpFace::protocol, Multicast,
- "MulticastUdpFace");
-
-MulticastUdpFace::MulticastUdpFace(const protocol::endpoint& multicastGroup,
- const FaceUri& localUri,
- protocol::socket recvSocket, protocol::socket sendSocket)
- : DatagramFace(FaceUri(multicastGroup), localUri, std::move(recvSocket))
- , m_multicastGroup(multicastGroup)
- , m_sendSocket(std::move(sendSocket))
-{
-}
-
-const MulticastUdpFace::protocol::endpoint&
-MulticastUdpFace::getMulticastGroup() const
-{
- return m_multicastGroup;
-}
-
-void
-MulticastUdpFace::sendInterest(const Interest& interest)
-{
- NFD_LOG_FACE_TRACE(__func__);
- this->emitSignal(onSendInterest, interest);
- sendBlock(interest.wireEncode());
-}
-
-void
-MulticastUdpFace::sendData(const Data& data)
-{
- NFD_LOG_FACE_TRACE(__func__);
- /// \todo After this face implements duplicate suppression, onSendData should
- /// be emitted only when data is actually sent out. See also #2555
- this->emitSignal(onSendData, data);
- sendBlock(data.wireEncode());
-}
-
-void
-MulticastUdpFace::sendBlock(const Block& block)
-{
- m_sendSocket.async_send_to(boost::asio::buffer(block.wire(), block.size()), m_multicastGroup,
- bind(&MulticastUdpFace::handleSend, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred,
- block));
-}
-
-} // namespace nfd
diff --git a/daemon/face/multicast-udp-face.hpp b/daemon/face/multicast-udp-face.hpp
deleted file mode 100644
index 7aab4a7..0000000
--- a/daemon/face/multicast-udp-face.hpp
+++ /dev/null
@@ -1,67 +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_FACE_MULTICAST_UDP_FACE_HPP
-#define NFD_DAEMON_FACE_MULTICAST_UDP_FACE_HPP
-
-#include "datagram-face.hpp"
-
-namespace nfd {
-
-/**
- * \brief Implementation of Face abstraction that uses
- * multicast UDP as underlying transport mechanism
- */
-class MulticastUdpFace : public DatagramFace<boost::asio::ip::udp, Multicast>
-{
-public:
- /**
- * \brief Creates a UDP-based face for multicast communication
- */
- MulticastUdpFace(const protocol::endpoint& multicastGroup, const FaceUri& localUri,
- protocol::socket recvSocket, protocol::socket sendSocket);
-
- const protocol::endpoint&
- getMulticastGroup() const;
-
- // from Face
- void
- sendInterest(const Interest& interest) DECL_OVERRIDE;
-
- void
- sendData(const Data& data) DECL_OVERRIDE;
-
-private:
- void
- sendBlock(const Block& block);
-
-private:
- protocol::endpoint m_multicastGroup;
- protocol::socket m_sendSocket;
-};
-
-} // namespace nfd
-
-#endif // NFD_DAEMON_FACE_MULTICAST_UDP_FACE_HPP
diff --git a/daemon/face/multicast-udp-transport.cpp b/daemon/face/multicast-udp-transport.cpp
new file mode 100644
index 0000000..7befa78
--- /dev/null
+++ b/daemon/face/multicast-udp-transport.cpp
@@ -0,0 +1,79 @@
+/* -*- 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 "multicast-udp-transport.hpp"
+
+namespace nfd {
+namespace face {
+
+NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(DatagramTransport, MulticastUdpTransport::protocol,
+ Multicast, "MulticastUdpTransport");
+
+MulticastUdpTransport::MulticastUdpTransport(const protocol::endpoint& localEndpoint,
+ const protocol::endpoint& multicastGroup,
+ protocol::socket&& recvSocket,
+ protocol::socket&& sendSocket)
+ : DatagramTransport(std::move(recvSocket))
+ , m_multicastGroup(multicastGroup)
+ , m_sendSocket(std::move(sendSocket))
+{
+ this->setLocalUri(FaceUri(localEndpoint));
+ this->setRemoteUri(FaceUri(multicastGroup));
+ this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+ this->setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS);
+
+ NFD_LOG_FACE_INFO("Creating transport");
+}
+
+void
+MulticastUdpTransport::doSend(Transport::Packet&& packet)
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ m_sendSocket.async_send_to(boost::asio::buffer(packet.packet), m_multicastGroup,
+ bind(&MulticastUdpTransport::handleSend, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ packet.packet));
+}
+
+void
+MulticastUdpTransport::doClose()
+{
+ if (m_sendSocket.is_open()) {
+ NFD_LOG_FACE_TRACE("Closing sending socket");
+
+ // Cancel all outstanding operations and close the socket.
+ // Use the non-throwing variants and ignore errors, if any.
+ boost::system::error_code error;
+ m_sendSocket.cancel(error);
+ m_sendSocket.close(error);
+ }
+
+ DatagramTransport::doClose();
+}
+
+} // namespace face
+} // namespace nfd
diff --git a/daemon/face/multicast-udp-transport.hpp b/daemon/face/multicast-udp-transport.hpp
new file mode 100644
index 0000000..7966b5b
--- /dev/null
+++ b/daemon/face/multicast-udp-transport.hpp
@@ -0,0 +1,64 @@
+/* -*- 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_MULTICAST_UDP_TRANSPORT_HPP
+#define NFD_DAEMON_FACE_MULTICAST_UDP_TRANSPORT_HPP
+
+#include "datagram-transport.hpp"
+
+namespace nfd {
+namespace face {
+
+/**
+ * \brief A Transport that communicates on a UDP multicast group
+ */
+class MulticastUdpTransport : public DatagramTransport<boost::asio::ip::udp, Multicast>
+{
+public:
+ /**
+ * \brief Creates a UDP-based transport for multicast communication
+ * \param recvSocket socket used to receive packets
+ * \param sendSocket socket used to send to the multicast address
+ */
+ MulticastUdpTransport(const protocol::endpoint& localEndpoint,
+ const protocol::endpoint& multicastGroup,
+ protocol::socket&& recvSocket, protocol::socket&& sendSocket);
+
+private:
+ virtual void
+ doSend(Transport::Packet&& packet) DECL_OVERRIDE;
+
+ virtual void
+ doClose() DECL_OVERRIDE;
+
+private:
+ protocol::endpoint m_multicastGroup;
+ protocol::socket m_sendSocket;
+};
+
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_MULTICAST_UDP_TRANSPORT_HPP
diff --git a/daemon/face/stream-transport.hpp b/daemon/face/stream-transport.hpp
new file mode 100644
index 0000000..e9ec78d
--- /dev/null
+++ b/daemon/face/stream-transport.hpp
@@ -0,0 +1,271 @@
+/* -*- 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_STREAM_TRANSPORT_HPP
+#define NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP
+
+#include "transport.hpp"
+#include "core/global-io.hpp"
+
+#include <queue>
+
+namespace nfd {
+namespace face {
+
+/** \brief Implements Transport for stream-based protocols.
+ *
+ * \tparam Protocol a stream-based protocol in Boost.Asio
+ */
+template<class Protocol>
+class StreamTransport : public Transport
+{
+public:
+ typedef Protocol protocol;
+
+ /** \brief Construct stream transport.
+ *
+ * \param socket Protocol-specific socket for the created transport
+ */
+ explicit
+ StreamTransport(typename protocol::socket&& socket);
+
+ virtual void
+ doSend(Transport::Packet&& packet) DECL_OVERRIDE;
+
+ virtual void
+ doClose() DECL_OVERRIDE;
+
+protected:
+ void
+ deferredClose();
+
+ void
+ sendFromQueue();
+
+ void
+ handleSend(const boost::system::error_code& error,
+ size_t nBytesSent);
+
+ void
+ handleReceive(const boost::system::error_code& error,
+ size_t nBytesReceived);
+
+ void
+ processErrorCode(const boost::system::error_code& error);
+
+protected:
+ typename protocol::socket m_socket;
+
+ NFD_LOG_INCLASS_DECLARE();
+
+private:
+ uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
+ size_t m_inputBufferSize;
+ std::queue<Block> m_sendQueue;
+};
+
+// All derived classes must use
+// NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(StreamTransport, <specialization-parameter>, "Name");
+
+
+template<class T>
+inline
+StreamTransport<T>::StreamTransport(typename StreamTransport::protocol::socket&& socket)
+ : m_socket(std::move(socket))
+ , m_inputBufferSize(0)
+{
+ m_socket.async_receive(boost::asio::buffer(m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE),
+ bind(&StreamTransport<T>::handleReceive, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
+}
+
+template<class T>
+inline void
+StreamTransport<T>::doSend(Transport::Packet&& packet)
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ bool wasQueueEmpty = m_sendQueue.empty();
+ m_sendQueue.push(packet.packet);
+
+ if (wasQueueEmpty)
+ sendFromQueue();
+}
+
+template<class T>
+inline void
+StreamTransport<T>::doClose()
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ if (m_socket.is_open()) {
+ // Cancel all outstanding operations and shutdown the socket
+ // so that no further sends or receives are possible.
+ // Use the non-throwing variants and ignore errors, if any.
+ boost::system::error_code error;
+ m_socket.cancel(error);
+ m_socket.shutdown(protocol::socket::shutdown_both, error);
+ }
+
+ // Ensure that the Transport stays alive at least until
+ // all pending handlers are dispatched
+ getGlobalIoService().post(bind(&StreamTransport<T>::deferredClose, this));
+
+ // Some bug or feature of Boost.Asio (see http://redmine.named-data.net/issues/1856):
+ //
+ // When doClose is called from a socket event handler (e.g., from handleReceive),
+ // m_socket.shutdown() does not trigger the cancellation of the handleSend callback.
+ // Instead, handleSend is invoked as nothing bad happened.
+ //
+ // In order to prevent the assertion in handleSend from failing, we clear the queue
+ // and close the socket in deferredClose, i.e., after all callbacks scheduled up to
+ // this point have been executed. If more send operations are scheduled after this
+ // point, they will fail because the socket has been shutdown, and their callbacks
+ // will be invoked with error code == asio::error::shut_down.
+}
+
+template<class T>
+inline void
+StreamTransport<T>::deferredClose()
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ // clear send queue
+ std::queue<Block> emptyQueue;
+ std::swap(emptyQueue, m_sendQueue);
+
+ // use the non-throwing variant and ignore errors, if any
+ boost::system::error_code error;
+ m_socket.close(error);
+
+ this->setState(TransportState::CLOSED);
+}
+
+template<class T>
+inline void
+StreamTransport<T>::sendFromQueue()
+{
+ boost::asio::async_write(m_socket, boost::asio::buffer(m_sendQueue.front()),
+ bind(&StreamTransport<T>::handleSend, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
+}
+
+template<class T>
+inline void
+StreamTransport<T>::handleSend(const boost::system::error_code& error,
+ size_t nBytesSent)
+{
+ if (error)
+ return processErrorCode(error);
+
+ NFD_LOG_FACE_TRACE("Successfully sent: " << nBytesSent << " bytes");
+
+ BOOST_ASSERT(!m_sendQueue.empty());
+ m_sendQueue.pop();
+
+ if (!m_sendQueue.empty())
+ sendFromQueue();
+}
+
+template<class T>
+inline void
+StreamTransport<T>::handleReceive(const boost::system::error_code& error,
+ size_t nBytesReceived)
+{
+ if (error)
+ return processErrorCode(error);
+
+ NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes");
+
+ m_inputBufferSize += nBytesReceived;
+
+ size_t offset = 0;
+
+ bool isOk = true;
+ Block element;
+ while (m_inputBufferSize - offset > 0) {
+ std::tie(isOk, element) = Block::fromBuffer(m_inputBuffer + offset, m_inputBufferSize - offset);
+ if (!isOk)
+ break;
+
+ offset += element.size();
+
+ BOOST_ASSERT(offset <= m_inputBufferSize);
+
+ Transport::Packet packet(std::move(element));
+ this->receive(std::move(packet));
+ }
+
+ if (!isOk && m_inputBufferSize == ndn::MAX_NDN_PACKET_SIZE && offset == 0) {
+ NFD_LOG_FACE_WARN("Failed to parse incoming packet or packet too large to process");
+ this->setState(TransportState::FAILED);
+ doClose();
+ return;
+ }
+
+ if (offset > 0) {
+ if (offset != m_inputBufferSize) {
+ std::copy(m_inputBuffer + offset, m_inputBuffer + m_inputBufferSize, m_inputBuffer);
+ m_inputBufferSize -= offset;
+ }
+ else {
+ m_inputBufferSize = 0;
+ }
+ }
+
+ m_socket.async_receive(boost::asio::buffer(m_inputBuffer + m_inputBufferSize,
+ ndn::MAX_NDN_PACKET_SIZE - m_inputBufferSize),
+ bind(&StreamTransport<T>::handleReceive, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
+}
+
+template<class T>
+inline void
+StreamTransport<T>::processErrorCode(const boost::system::error_code& error)
+{
+ NFD_LOG_FACE_TRACE(__func__);
+
+ if (getState() == TransportState::CLOSING ||
+ getState() == TransportState::FAILED ||
+ getState() == TransportState::CLOSED ||
+ error == boost::asio::error::operation_aborted || // when cancel() is called
+ error == boost::asio::error::shut_down) // after shutdown() is called
+ // transport is shutting down, ignore any errors
+ return;
+
+ if (error != boost::asio::error::eof)
+ NFD_LOG_FACE_WARN("Send or receive operation failed: " << error.message());
+
+ this->setState(TransportState::FAILED);
+ doClose();
+}
+
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP
diff --git a/daemon/face/transport.cpp b/daemon/face/transport.cpp
new file mode 100644
index 0000000..fa1159d
--- /dev/null
+++ b/daemon/face/transport.cpp
@@ -0,0 +1,169 @@
+/* -*- 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 "transport.hpp"
+#include "lp-face.hpp"
+#include "link-service.hpp"
+
+namespace nfd {
+namespace face {
+
+NFD_LOG_INIT("Transport");
+
+std::ostream&
+operator<<(std::ostream& os, TransportState state)
+{
+ switch (state) {
+ case TransportState::UP:
+ return os << "UP";
+ case TransportState::DOWN:
+ return os << "DOWN";
+ case TransportState::CLOSING:
+ return os << "CLOSING";
+ case TransportState::FAILED:
+ return os << "FAILED";
+ case TransportState::CLOSED:
+ return os << "CLOSED";
+ default:
+ return os << "NONE";
+ }
+}
+
+Transport::Packet::Packet(Block&& packet1)
+ : packet(std::move(packet1))
+{
+}
+
+Transport::Transport()
+ : m_face(nullptr)
+ , m_service(nullptr)
+ , m_scope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
+ , m_persistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
+ , m_linkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
+ , m_state(TransportState::UP)
+ , m_counters(nullptr)
+{
+}
+
+Transport::~Transport()
+{
+}
+
+void
+Transport::setFaceAndLinkService(LpFace& face, LinkService& service)
+{
+ BOOST_ASSERT(m_face == nullptr);
+ BOOST_ASSERT(m_service == nullptr);
+
+ m_face = &face;
+ m_service = &service;
+ m_counters = &m_face->getMutableCounters();
+}
+
+void
+Transport::close()
+{
+ if (m_state != TransportState::UP && m_state != TransportState::DOWN) {
+ return;
+ }
+
+ this->setState(TransportState::CLOSING);
+ this->doClose();
+ // warning: don't access any fields after this:
+ // the Transport may be deallocated if doClose changes state to CLOSED
+}
+
+void
+Transport::send(Transport::Packet&& packet)
+{
+ // TODO#3177 increment LpPacket counter
+ m_counters->getNOutBytes() += packet.packet.size();
+
+ this->doSend(std::move(packet));
+}
+
+void
+Transport::receive(Transport::Packet&& packet)
+{
+ // TODO#3177 increment LpPacket counter
+ m_counters->getNInBytes() += packet.packet.size();
+
+ m_service->receivePacket(std::move(packet));
+}
+
+void
+Transport::setState(TransportState newState)
+{
+ if (m_state == newState) {
+ return;
+ }
+
+ bool isValid = false;
+ switch (m_state) {
+ case TransportState::UP:
+ isValid = newState == TransportState::DOWN ||
+ newState == TransportState::CLOSING ||
+ newState == TransportState::FAILED;
+ break;
+ case TransportState::DOWN:
+ isValid = newState == TransportState::UP ||
+ newState == TransportState::CLOSING ||
+ newState == TransportState::FAILED;
+ break;
+ case TransportState::CLOSING:
+ case TransportState::FAILED:
+ isValid = newState == TransportState::CLOSED;
+ break;
+ default:
+ break;
+ }
+
+ if (!isValid) {
+ throw std::runtime_error("invalid state transition");
+ }
+
+ NFD_LOG_FACE_INFO("setState " << m_state << " -> " << newState);
+
+ TransportState oldState = m_state;
+ m_state = newState;
+ afterStateChange(oldState, newState);
+ // warning: don't access any fields after this:
+ // the Transport may be deallocated in the signal handler if newState is CLOSED
+}
+
+std::ostream&
+operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh)
+{
+ const Transport& transport = flh.obj;
+ const LpFace* face = transport.getFace();
+ FaceId faceId = face == nullptr ? INVALID_FACEID : face->getId();
+
+ os << "[id=" << faceId << ",local=" << transport.getLocalUri()
+ << ",remote=" << transport.getRemoteUri() << "] ";
+ return os;
+}
+
+} // namespace face
+} // namespace nfd
diff --git a/daemon/face/transport.hpp b/daemon/face/transport.hpp
new file mode 100644
index 0000000..144e0dc
--- /dev/null
+++ b/daemon/face/transport.hpp
@@ -0,0 +1,340 @@
+/* -*- 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_TRANSPORT_HPP
+#define NFD_DAEMON_FACE_TRANSPORT_HPP
+
+#include "common.hpp"
+
+#include "face-counters.hpp"
+#include "face-log.hpp"
+
+namespace nfd {
+namespace face {
+
+class LpFace;
+class LinkService;
+
+/** \brief indicates the state of a transport
+ */
+enum class TransportState {
+ NONE,
+ UP, ///< the transport is up
+ DOWN, ///< the transport is down temporarily, and is being recovered
+ CLOSING, ///< the transport is requested to be closed
+ FAILED, ///< the transport is being closed due to a failure
+ CLOSED ///< the transport is closed, and can be safely deallocated
+};
+
+std::ostream&
+operator<<(std::ostream& os, TransportState state);
+
+/** \brief the lower part of an LpFace
+ * \sa LpFace
+ */
+class Transport : noncopyable
+{
+public:
+ /** \brief identifies an endpoint on the link
+ */
+ typedef uint64_t EndpointId;
+
+ /** \brief stores a packet along with the remote endpoint
+ */
+ class Packet
+ {
+ public:
+ Packet() = default;
+
+ explicit
+ Packet(Block&& packet);
+
+ public:
+ /** \brief the packet as a TLV block
+ */
+ Block packet;
+
+ /** \brief identifies the remote endpoint
+ *
+ * This ID is only meaningful in the context of the same Transport.
+ * Incoming packets from the same remote endpoint have the same EndpointId,
+ * and incoming packets from different remote endpoints have different EndpointIds.
+ */
+ EndpointId remoteEndpoint;
+ };
+
+ Transport();
+
+ virtual
+ ~Transport();
+
+public:
+ /** \brief set Face and LinkService for Transport
+ * \pre setFaceAndLinkService has not been called
+ */
+ void
+ setFaceAndLinkService(LpFace& face, LinkService& service);
+
+ /** \return Face to which this Transport is attached
+ */
+ const LpFace*
+ getFace() const;
+
+ /** \return LinkService to which this Transport is attached
+ */
+ const LinkService*
+ getLinkService() const;
+
+ /** \return LinkService to which this Transport is attached
+ */
+ LinkService*
+ getLinkService();
+
+public: // upper interface
+ /** \brief request the transport to be closed
+ *
+ * This operation is effective only if transport is in UP or DOWN state,
+ * otherwise it has no effect.
+ * The transport changes state to CLOSING, and performs cleanup procedure.
+ * The state will be changed to CLOSED when cleanup is complete, which may
+ * happen synchronously or asynchronously.
+ */
+ void
+ close();
+
+ /** \brief send a link-layer packet
+ */
+ void
+ send(Packet&& packet);
+
+protected: // upper interface to be invoked by subclass
+ /** \brief receive a link-layer packet
+ */
+ void
+ receive(Packet&& packet);
+
+public: // static properties
+ /** \return a FaceUri representing local endpoint
+ */
+ FaceUri
+ getLocalUri() const;
+
+ /** \return a FaceUri representing remote endpoint
+ */
+ FaceUri
+ getRemoteUri() const;
+
+ /** \return whether face is local or non-local for scope control purpose
+ */
+ ndn::nfd::FaceScope
+ getScope() const;
+
+ /** \return face persistency setting
+ */
+ ndn::nfd::FacePersistency
+ getPersistency() const;
+
+ /** \brief changes face persistency setting
+ */
+ void
+ setPersistency(ndn::nfd::FacePersistency persistency);
+
+ /** \return whether face is point-to-point or multi-access
+ */
+ ndn::nfd::LinkType
+ getLinkType() const;
+
+public: // dynamic properties
+ /** \return transport state
+ */
+ TransportState
+ getState() const;
+
+ /** \brief signals when transport state changes
+ */
+ signal::Signal<Transport, TransportState/*old*/, TransportState/*new*/> afterStateChange;
+
+protected: // properties to be set by subclass
+ void
+ setLocalUri(const FaceUri& uri);
+
+ void
+ setRemoteUri(const FaceUri& uri);
+
+ void
+ setScope(ndn::nfd::FaceScope scope);
+
+ void
+ setLinkType(ndn::nfd::LinkType linkType);
+
+ /** \brief set transport state
+ *
+ * Only the following transitions are valid:
+ * UP->DOWN, DOWN->UP, UP/DOWN->CLOSING/FAILED, CLOSING/FAILED->CLOSED
+ *
+ * \throw std::runtime_error transition is invalid.
+ */
+ void
+ setState(TransportState newState);
+
+protected: // to be overridden by subclass
+ /** \brief invoked before persistency is changed
+ * \throw std::invalid_argument new persistency is not supported
+ * \throw std::runtime_error transition is disallowed
+ *
+ * Base class implementation does nothing.
+ */
+ virtual void
+ beforeChangePersistency(ndn::nfd::FacePersistency newPersistency)
+ {
+ }
+
+ /** \brief performs Transport specific operations to close the transport
+ *
+ * When the cleanup procedure is complete, this method should change state to CLOSED.
+ * This can happen synchronously or asynchronously.
+ */
+ virtual void
+ doClose() = 0;
+
+private: // to be overridden by subclass
+ /** \brief performs Transport specific operations to send a packet
+ * \param packet the packet, which must be a well-formed TLV block
+ */
+ virtual void
+ doSend(Packet&& packet) = 0;
+
+private:
+ LpFace* m_face;
+ LinkService* m_service;
+ FaceUri m_localUri;
+ FaceUri m_remoteUri;
+ ndn::nfd::FaceScope m_scope;
+ ndn::nfd::FacePersistency m_persistency;
+ ndn::nfd::LinkType m_linkType;
+ TransportState m_state;
+ LinkLayerCounters* m_counters; // TODO#3177 change into LinkCounters
+};
+
+inline const LpFace*
+Transport::getFace() const
+{
+ return m_face;
+}
+
+inline const LinkService*
+Transport::getLinkService() const
+{
+ return m_service;
+}
+
+inline LinkService*
+Transport::getLinkService()
+{
+ return m_service;
+}
+
+inline FaceUri
+Transport::getLocalUri() const
+{
+ return m_localUri;
+}
+
+inline FaceUri
+Transport::getRemoteUri() const
+{
+ return m_remoteUri;
+}
+
+inline ndn::nfd::FaceScope
+Transport::getScope() const
+{
+ return m_scope;
+}
+
+inline ndn::nfd::FacePersistency
+Transport::getPersistency() const
+{
+ return m_persistency;
+}
+
+inline void
+Transport::setPersistency(ndn::nfd::FacePersistency persistency)
+{
+ this->beforeChangePersistency(persistency);
+ m_persistency = persistency;
+}
+
+inline ndn::nfd::LinkType
+Transport::getLinkType() const
+{
+ return m_linkType;
+}
+
+inline TransportState
+Transport::getState() const
+{
+ return m_state;
+}
+
+inline void
+Transport::setLocalUri(const FaceUri& uri)
+{
+ m_localUri = uri;
+}
+
+inline void
+Transport::setRemoteUri(const FaceUri& uri)
+{
+ m_remoteUri = uri;
+}
+
+inline void
+Transport::setScope(ndn::nfd::FaceScope scope)
+{
+ m_scope = scope;
+}
+
+inline void
+Transport::setLinkType(ndn::nfd::LinkType linkType)
+{
+ m_linkType = linkType;
+}
+
+std::ostream&
+operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh);
+
+template<typename T>
+typename std::enable_if<std::is_base_of<Transport, T>::value &&
+ !std::is_same<Transport, T>::value, std::ostream&>::type
+operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
+{
+ return os << FaceLogHelper<Transport>(flh.obj);
+}
+
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_TRANSPORT_HPP
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index c9920c4..a1ff92c 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -24,7 +24,8 @@
*/
#include "udp-channel.hpp"
-#include "udp-face.hpp"
+#include "generic-link-service.hpp"
+#include "unicast-udp-transport.hpp"
#include "core/global-io.hpp"
namespace nfd {
@@ -71,7 +72,7 @@
const FaceCreatedCallback& onFaceCreated,
const ConnectFailedCallback& onConnectFailed)
{
- shared_ptr<UdpFace> face;
+ shared_ptr<face::LpFaceWrapper> face;
try {
face = createFace(remoteEndpoint, persistency).second;
}
@@ -93,7 +94,7 @@
return m_channelFaces.size();
}
-std::pair<bool, shared_ptr<UdpFace>>
+std::pair<bool, shared_ptr<face::LpFaceWrapper>>
UdpChannel::createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersistency persistency)
{
auto it = m_channelFaces.find(remoteEndpoint);
@@ -116,15 +117,18 @@
socket.bind(m_localEndpoint);
socket.connect(remoteEndpoint);
- auto face = make_shared<UdpFace>(FaceUri(remoteEndpoint), FaceUri(m_localEndpoint),
- std::move(socket), persistency, m_idleFaceTimeout);
+ auto linkService = make_unique<face::GenericLinkService>();
+ auto transport = make_unique<face::UnicastUdpTransport>(std::move(socket), persistency, m_idleFaceTimeout);
+ auto lpFace = make_unique<face::LpFace>(std::move(linkService), std::move(transport));
+ auto face = make_shared<face::LpFaceWrapper>(std::move(lpFace));
+ face->setPersistency(persistency);
face->onFail.connectSingleShot([this, remoteEndpoint] (const std::string&) {
NFD_LOG_TRACE("Erasing " << remoteEndpoint << " from channel face map");
m_channelFaces.erase(remoteEndpoint);
});
- m_channelFaces[remoteEndpoint] = face;
+ m_channelFaces[remoteEndpoint] = face;
return {true, face};
}
@@ -147,7 +151,7 @@
NFD_LOG_DEBUG("[" << m_localEndpoint << "] New peer " << m_remoteEndpoint);
bool created;
- shared_ptr<UdpFace> face;
+ shared_ptr<face::LpFaceWrapper> face;
try {
std::tie(created, face) = createFace(m_remoteEndpoint, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
}
@@ -163,7 +167,7 @@
onFaceCreated(face);
// dispatch the datagram to the face for processing
- face->receiveDatagram(m_inputBuffer, nBytesReceived, error);
+ static_cast<face::UnicastUdpTransport*>(face->getLpFace()->getTransport())->receiveDatagram(m_inputBuffer, nBytesReceived, error);
m_socket.async_receive_from(boost::asio::buffer(m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE),
m_remoteEndpoint,
diff --git a/daemon/face/udp-channel.hpp b/daemon/face/udp-channel.hpp
index 3f92ada..0825ad4 100644
--- a/daemon/face/udp-channel.hpp
+++ b/daemon/face/udp-channel.hpp
@@ -1,12 +1,12 @@
/* -*- 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
+ * 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.
@@ -27,6 +27,7 @@
#define NFD_DAEMON_FACE_UDP_CHANNEL_HPP
#include "channel.hpp"
+#include "lp-face-wrapper.hpp"
namespace nfd {
@@ -34,8 +35,6 @@
typedef boost::asio::ip::udp::endpoint Endpoint;
} // namespace udp
-class UdpFace;
-
/**
* \brief Class implementing UDP-based channel to create faces
*/
@@ -92,7 +91,7 @@
isListening() const;
private:
- std::pair<bool, shared_ptr<UdpFace>>
+ std::pair<bool, shared_ptr<face::LpFaceWrapper>>
createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersistency persistency);
/**
@@ -106,7 +105,7 @@
const ConnectFailedCallback& onReceiveFailed);
private:
- std::map<udp::Endpoint, shared_ptr<UdpFace>> m_channelFaces;
+ std::map<udp::Endpoint, shared_ptr<face::LpFaceWrapper>> m_channelFaces;
udp::Endpoint m_localEndpoint;
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index 8d24bbe..74636d8 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -24,6 +24,9 @@
*/
#include "udp-factory.hpp"
+#include "generic-link-service.hpp"
+#include "lp-face-wrapper.hpp"
+#include "multicast-udp-transport.hpp"
#include "core/global-io.hpp"
#include "core/network-interface.hpp"
@@ -117,11 +120,12 @@
if (static_cast<bool>(channel))
return channel;
- //checking if the endpoint is already in use for multicast face
- shared_ptr<MulticastUdpFace> multicast = findMulticastFace(endpoint);
- if (static_cast<bool>(multicast))
+ // check if the endpoint is already used by a multicast face
+ auto face = findMulticastFace(endpoint);
+ if (face) {
BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP unicast channel, local "
"endpoint is already allocated for a UDP multicast face"));
+ }
if (endpoint.address().is_multicast()) {
BOOST_THROW_EXCEPTION(Error("This method is only for unicast channel. The provided "
@@ -146,15 +150,15 @@
return createChannel(endpoint, timeout);
}
-shared_ptr<MulticastUdpFace>
+shared_ptr<face::LpFaceWrapper>
UdpFactory::createMulticastFace(const udp::Endpoint& localEndpoint,
const udp::Endpoint& multicastEndpoint,
const std::string& networkInterfaceName/* = ""*/)
{
// checking if the local and multicast endpoints are already in use for a multicast face
- shared_ptr<MulticastUdpFace> face = findMulticastFace(localEndpoint);
- if (static_cast<bool>(face)) {
- if (face->getMulticastGroup() == multicastEndpoint)
+ auto face = findMulticastFace(localEndpoint);
+ if (face) {
+ if (face->getRemoteUri() == FaceUri(multicastEndpoint))
return face;
else
BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP multicast face, local "
@@ -225,8 +229,12 @@
}
#endif
- face = make_shared<MulticastUdpFace>(multicastEndpoint, FaceUri(localEndpoint),
- std::move(receiveSocket), std::move(sendSocket));
+ auto linkService = make_unique<face::GenericLinkService>();
+ auto transport = make_unique<face::MulticastUdpTransport>(localEndpoint, multicastEndpoint,
+ std::move(receiveSocket),
+ std::move(sendSocket));
+ auto lpFace = make_unique<face::LpFace>(std::move(linkService), std::move(transport));
+ face = make_shared<face::LpFaceWrapper>(std::move(lpFace));
face->onFail.connectSingleShot([this, localEndpoint] (const std::string& reason) {
m_multicastFaces.erase(localEndpoint);
@@ -236,7 +244,7 @@
return face;
}
-shared_ptr<MulticastUdpFace>
+shared_ptr<face::LpFaceWrapper>
UdpFactory::createMulticastFace(const std::string& localIp,
const std::string& multicastIp,
const std::string& multicastPort,
@@ -302,14 +310,14 @@
return shared_ptr<UdpChannel>();
}
-shared_ptr<MulticastUdpFace>
+shared_ptr<face::LpFaceWrapper>
UdpFactory::findMulticastFace(const udp::Endpoint& localEndpoint)
{
MulticastFaceMap::iterator i = m_multicastFaces.find(localEndpoint);
if (i != m_multicastFaces.end())
return i->second;
else
- return shared_ptr<MulticastUdpFace>();
+ return nullptr;
}
std::list<shared_ptr<const Channel>>
diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp
index 1a3714c..0465ca5 100644
--- a/daemon/face/udp-factory.hpp
+++ b/daemon/face/udp-factory.hpp
@@ -28,7 +28,6 @@
#include "protocol-factory.hpp"
#include "udp-channel.hpp"
-#include "multicast-udp-face.hpp"
namespace nfd {
@@ -50,7 +49,7 @@
}
};
- typedef std::map<udp::Endpoint, shared_ptr<MulticastUdpFace>> MulticastFaceMap;
+ typedef std::map<udp::Endpoint, shared_ptr<face::LpFaceWrapper>> MulticastFaceMap;
explicit
UdpFactory(const std::string& defaultPort = "6363");
@@ -131,12 +130,12 @@
* \see http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/ip__udp/endpoint.html
* for details on ways to create udp::Endpoint
*/
- shared_ptr<MulticastUdpFace>
+ shared_ptr<face::LpFaceWrapper>
createMulticastFace(const udp::Endpoint& localEndpoint,
const udp::Endpoint& multicastEndpoint,
const std::string& networkInterfaceName = "");
- shared_ptr<MulticastUdpFace>
+ shared_ptr<face::LpFaceWrapper>
createMulticastFace(const std::string& localIp,
const std::string& multicastIp,
const std::string& multicastPort,
@@ -186,11 +185,9 @@
* \brief Look up multicast UdpFace using specified local endpoint
*
* \returns shared pointer to the existing multicast MulticastUdpFace object
- * or empty shared pointer when such face does not exist
- *
- * \throws never
+ * or nullptr when such face does not exist
*/
- shared_ptr<MulticastUdpFace>
+ shared_ptr<face::LpFaceWrapper>
findMulticastFace(const udp::Endpoint& localEndpoint);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
diff --git a/daemon/face/udp-face.cpp b/daemon/face/unicast-udp-transport.cpp
similarity index 63%
rename from daemon/face/udp-face.cpp
rename to daemon/face/unicast-udp-transport.cpp
index 6985784..eb8ab66 100644
--- a/daemon/face/udp-face.cpp
+++ b/daemon/face/unicast-udp-transport.cpp
@@ -23,8 +23,7 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "udp-face.hpp"
-// #include "core/global-io.hpp" // for #1718 manual test below
+#include "unicast-udp-transport.hpp"
#ifdef __linux__
#include <cerrno> // for errno
@@ -34,17 +33,24 @@
#endif
namespace nfd {
+namespace face {
-NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(DatagramFace, UdpFace::protocol, "UdpFace");
+NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(DatagramTransport, UnicastUdpTransport::protocol,
+ "UnicastUdpTransport");
-UdpFace::UdpFace(const FaceUri& remoteUri, const FaceUri& localUri,
- protocol::socket socket, ndn::nfd::FacePersistency persistency,
- const time::seconds& idleTimeout)
- : DatagramFace(remoteUri, localUri, std::move(socket))
+UnicastUdpTransport::UnicastUdpTransport(protocol::socket&& socket,
+ ndn::nfd::FacePersistency persistency,
+ const time::seconds& idleTimeout)
+ : DatagramTransport(std::move(socket))
, m_idleTimeout(idleTimeout)
, m_lastIdleCheck(time::steady_clock::now())
{
+ this->setLocalUri(FaceUri(m_socket.local_endpoint()));
+ this->setRemoteUri(FaceUri(m_socket.remote_endpoint()));
this->setPersistency(persistency);
+ this->setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+
+ NFD_LOG_FACE_INFO("Creating transport");
#ifdef __linux__
//
@@ -66,56 +72,31 @@
}
#endif
- if (this->getPersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND && m_idleTimeout > time::seconds::zero()) {
- m_closeIfIdleEvent = scheduler::schedule(m_idleTimeout, bind(&UdpFace::closeIfIdle, this));
+ if (getPersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND &&
+ m_idleTimeout > time::seconds::zero()) {
+ m_closeIfIdleEvent = scheduler::schedule(m_idleTimeout, bind(&UnicastUdpTransport::closeIfIdle, this));
}
}
-ndn::nfd::FaceStatus
-UdpFace::getFaceStatus() const
-{
- auto status = DatagramFace::getFaceStatus();
-
- if (this->getPersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
- time::milliseconds left = m_idleTimeout;
- left -= time::duration_cast<time::milliseconds>(time::steady_clock::now() - m_lastIdleCheck);
-
- if (left < time::milliseconds::zero())
- left = time::milliseconds::zero();
-
- if (hasBeenUsedRecently())
- left += m_idleTimeout;
-
- status.setExpirationPeriod(left);
- }
-
- return status;
-}
-
void
-UdpFace::closeIfIdle()
+UnicastUdpTransport::closeIfIdle()
{
- // Face can be switched from on-demand to non-on-demand mode
+ // transport can be switched from on-demand to non-on-demand mode
// (non-on-demand -> on-demand transition is not allowed)
- if (this->getPersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
+ if (getPersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
if (!hasBeenUsedRecently()) {
- NFD_LOG_FACE_INFO("Closing for inactivity");
- close();
-
- // #1718 manual test: uncomment, run NFD in valgrind, send in a UDP packet
- // expect read-after-free error and crash
- // getGlobalIoService().post([this] {
- // NFD_LOG_FACE_ERROR("Remaining references: " << this->shared_from_this().use_count());
- // });
+ NFD_LOG_FACE_INFO("Closing due to inactivity");
+ this->close();
}
else {
resetRecentUsage();
m_lastIdleCheck = time::steady_clock::now();
- m_closeIfIdleEvent = scheduler::schedule(m_idleTimeout, bind(&UdpFace::closeIfIdle, this));
+ m_closeIfIdleEvent = scheduler::schedule(m_idleTimeout, bind(&UnicastUdpTransport::closeIfIdle, this));
}
}
// else do nothing and do not reschedule the event
}
+} // namespace face
} // namespace nfd
diff --git a/daemon/face/udp-face.hpp b/daemon/face/unicast-udp-transport.hpp
similarity index 70%
rename from daemon/face/udp-face.hpp
rename to daemon/face/unicast-udp-transport.hpp
index a7541a5..2622e4b 100644
--- a/daemon/face/udp-face.hpp
+++ b/daemon/face/unicast-udp-transport.hpp
@@ -23,27 +23,24 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NFD_DAEMON_FACE_UDP_FACE_HPP
-#define NFD_DAEMON_FACE_UDP_FACE_HPP
+#ifndef NFD_DAEMON_FACE_UDP_TRANSPORT_HPP
+#define NFD_DAEMON_FACE_UDP_TRANSPORT_HPP
-#include "datagram-face.hpp"
+#include "datagram-transport.hpp"
#include "core/scheduler.hpp"
namespace nfd {
+namespace face {
/**
- * \brief Implementation of Face abstraction that uses
- * unicast UDP as underlying transport mechanism
+ * \brief A Transport that communicates on a unicast UDP socket
*/
-class UdpFace : public DatagramFace<boost::asio::ip::udp>
+class UnicastUdpTransport : public DatagramTransport<boost::asio::ip::udp>
{
public:
- UdpFace(const FaceUri& remoteUri, const FaceUri& localUri,
- protocol::socket socket, ndn::nfd::FacePersistency persistency,
- const time::seconds& idleTimeout);
-
- ndn::nfd::FaceStatus
- getFaceStatus() const DECL_OVERRIDE;
+ UnicastUdpTransport(protocol::socket&& socket,
+ ndn::nfd::FacePersistency persistency,
+ const time::seconds& idleTimeout);
private:
void
@@ -53,11 +50,9 @@
const time::seconds m_idleTimeout;
time::steady_clock::TimePoint m_lastIdleCheck;
scheduler::ScopedEventId m_closeIfIdleEvent;
-
- // friend because it needs to invoke protected Face::setOnDemand
- friend class UdpChannel;
};
+} // namespace face
} // namespace nfd
-#endif // NFD_DAEMON_FACE_UDP_FACE_HPP
+#endif // NFD_DAEMON_FACE_UDP_TRANSPORT_HPP
diff --git a/daemon/face/unix-stream-channel.cpp b/daemon/face/unix-stream-channel.cpp
index c883163..3de9850 100644
--- a/daemon/face/unix-stream-channel.cpp
+++ b/daemon/face/unix-stream-channel.cpp
@@ -24,7 +24,9 @@
*/
#include "unix-stream-channel.hpp"
-#include "unix-stream-face.hpp"
+#include "generic-link-service.hpp"
+#include "lp-face-wrapper.hpp"
+#include "unix-stream-transport.hpp"
#include "core/global-io.hpp"
#include <boost/filesystem.hpp>
@@ -131,9 +133,10 @@
NFD_LOG_DEBUG("[" << m_endpoint << "] Incoming connection");
- auto remoteUri = FaceUri::fromFd(m_socket.native_handle());
- auto localUri = FaceUri(m_socket.local_endpoint());
- auto face = make_shared<UnixStreamFace>(remoteUri, localUri, std::move(m_socket));
+ auto linkService = make_unique<face::GenericLinkService>();
+ auto transport = make_unique<face::UnixStreamTransport>(std::move(m_socket));
+ auto lpFace = make_unique<face::LpFace>(std::move(linkService), std::move(transport));
+ auto face = make_shared<face::LpFaceWrapper>(std::move(lpFace));
onFaceCreated(face);
// prepare accepting the next connection
diff --git a/daemon/face/unix-stream-face.cpp b/daemon/face/unix-stream-face.cpp
deleted file mode 100644
index 41ef68b..0000000
--- a/daemon/face/unix-stream-face.cpp
+++ /dev/null
@@ -1,46 +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
- *
- * 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 "unix-stream-face.hpp"
-
-namespace nfd {
-
-// The whole purpose of this file is to specialize the logger,
-// otherwise, everything could be put into the header file.
-
-NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(StreamFace,
- UnixStreamFace::protocol, LocalFace,
- "UnixStreamFace");
-
-UnixStreamFace::UnixStreamFace(const FaceUri& remoteUri, const FaceUri& localUri,
- protocol::socket socket)
- : StreamFace<protocol, LocalFace>(remoteUri, localUri, std::move(socket), true)
-{
- static_assert(
- std::is_same<std::remove_cv<protocol::socket::native_handle_type>::type, int>::value,
- "The native handle type for UnixStreamFace sockets must be 'int'"
- );
-}
-
-} // namespace nfd
diff --git a/daemon/face/unix-stream-face.hpp b/daemon/face/unix-stream-face.hpp
deleted file mode 100644
index c377819..0000000
--- a/daemon/face/unix-stream-face.hpp
+++ /dev/null
@@ -1,49 +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
- *
- * 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_UNIX_STREAM_FACE_HPP
-#define NFD_DAEMON_FACE_UNIX_STREAM_FACE_HPP
-
-#include "stream-face.hpp"
-
-#ifndef HAVE_UNIX_SOCKETS
-#error "Cannot include this file when UNIX sockets are not available"
-#endif
-
-namespace nfd {
-
-/**
- * \brief Implementation of Face abstraction that uses stream-oriented
- * Unix domain sockets as underlying transport mechanism
- */
-class UnixStreamFace : public StreamFace<boost::asio::local::stream_protocol, LocalFace>
-{
-public:
- UnixStreamFace(const FaceUri& remoteUri, const FaceUri& localUri,
- protocol::socket socket);
-};
-
-} // namespace nfd
-
-#endif // NFD_DAEMON_FACE_UNIX_STREAM_FACE_HPP
diff --git a/daemon/face/udp-face.hpp b/daemon/face/unix-stream-transport.cpp
similarity index 60%
copy from daemon/face/udp-face.hpp
copy to daemon/face/unix-stream-transport.cpp
index a7541a5..17351f0 100644
--- a/daemon/face/udp-face.hpp
+++ b/daemon/face/unix-stream-transport.cpp
@@ -23,41 +23,29 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NFD_DAEMON_FACE_UDP_FACE_HPP
-#define NFD_DAEMON_FACE_UDP_FACE_HPP
-
-#include "datagram-face.hpp"
-#include "core/scheduler.hpp"
+#include "unix-stream-transport.hpp"
namespace nfd {
+namespace face {
-/**
- * \brief Implementation of Face abstraction that uses
- * unicast UDP as underlying transport mechanism
- */
-class UdpFace : public DatagramFace<boost::asio::ip::udp>
+NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(StreamTransport, UnixStreamTransport::protocol,
+ "UnixStreamTransport");
+
+UnixStreamTransport::UnixStreamTransport(protocol::socket&& socket)
+ : StreamTransport(std::move(socket))
{
-public:
- UdpFace(const FaceUri& remoteUri, const FaceUri& localUri,
- protocol::socket socket, ndn::nfd::FacePersistency persistency,
- const time::seconds& idleTimeout);
+ static_assert(
+ std::is_same<std::remove_cv<protocol::socket::native_handle_type>::type, int>::value,
+ "The native handle type for UnixStreamFace sockets must be 'int'"
+ );
- ndn::nfd::FaceStatus
- getFaceStatus() const DECL_OVERRIDE;
+ this->setLocalUri(FaceUri(m_socket.local_endpoint()));
+ this->setRemoteUri(FaceUri::fromFd(m_socket.native_handle()));
+ this->setScope(ndn::nfd::FACE_SCOPE_LOCAL);
+ this->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
-private:
- void
- closeIfIdle();
+ NFD_LOG_FACE_INFO("Creating Transport");
+}
-private:
- const time::seconds m_idleTimeout;
- time::steady_clock::TimePoint m_lastIdleCheck;
- scheduler::ScopedEventId m_closeIfIdleEvent;
-
- // friend because it needs to invoke protected Face::setOnDemand
- friend class UdpChannel;
-};
-
+} // namespace face
} // namespace nfd
-
-#endif // NFD_DAEMON_FACE_UDP_FACE_HPP
diff --git a/daemon/face/udp-face.hpp b/daemon/face/unix-stream-transport.hpp
similarity index 61%
copy from daemon/face/udp-face.hpp
copy to daemon/face/unix-stream-transport.hpp
index a7541a5..27f4eaa 100644
--- a/daemon/face/udp-face.hpp
+++ b/daemon/face/unix-stream-transport.hpp
@@ -23,41 +23,29 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NFD_DAEMON_FACE_UDP_FACE_HPP
-#define NFD_DAEMON_FACE_UDP_FACE_HPP
+#ifndef NFD_DAEMON_FACE_UNIX_STREAM_TRANSPORT_HPP
+#define NFD_DAEMON_FACE_UNIX_STREAM_TRANSPORT_HPP
-#include "datagram-face.hpp"
-#include "core/scheduler.hpp"
+#include "stream-transport.hpp"
+
+#ifndef HAVE_UNIX_SOCKETS
+#error "Cannot include this file when UNIX sockets are not available"
+#endif
namespace nfd {
+namespace face {
/**
- * \brief Implementation of Face abstraction that uses
- * unicast UDP as underlying transport mechanism
+ * \brief A Transport that communicates on a stream-oriented Unix domain socket
*/
-class UdpFace : public DatagramFace<boost::asio::ip::udp>
+class UnixStreamTransport : public StreamTransport<boost::asio::local::stream_protocol>
{
public:
- UdpFace(const FaceUri& remoteUri, const FaceUri& localUri,
- protocol::socket socket, ndn::nfd::FacePersistency persistency,
- const time::seconds& idleTimeout);
-
- ndn::nfd::FaceStatus
- getFaceStatus() const DECL_OVERRIDE;
-
-private:
- void
- closeIfIdle();
-
-private:
- const time::seconds m_idleTimeout;
- time::steady_clock::TimePoint m_lastIdleCheck;
- scheduler::ScopedEventId m_closeIfIdleEvent;
-
- // friend because it needs to invoke protected Face::setOnDemand
- friend class UdpChannel;
+ explicit
+ UnixStreamTransport(protocol::socket&& socket);
};
+} // namespace face
} // namespace nfd
-#endif // NFD_DAEMON_FACE_UDP_FACE_HPP
+#endif // NFD_DAEMON_FACE_UNIX_STREAM_TRANSPORT_HPP
diff --git a/daemon/fw/best-route-strategy2.cpp b/daemon/fw/best-route-strategy2.cpp
index 2ec786c..e0e31dc 100644
--- a/daemon/fw/best-route-strategy2.cpp
+++ b/daemon/fw/best-route-strategy2.cpp
@@ -31,7 +31,7 @@
NFD_LOG_INIT("BestRouteStrategy2");
-const Name BestRouteStrategy2::STRATEGY_NAME("ndn:/localhost/nfd/strategy/best-route/%FD%03");
+const Name BestRouteStrategy2::STRATEGY_NAME("ndn:/localhost/nfd/strategy/best-route/%FD%04");
NFD_REGISTER_STRATEGY(BestRouteStrategy2);
BestRouteStrategy2::BestRouteStrategy2(Forwarder& forwarder, const Name& name)
@@ -104,8 +104,7 @@
const fib::NextHopList& nexthops = fibEntry->getNextHops();
fib::NextHopList::const_iterator it = nexthops.end();
- RetxSuppression::Result suppression =
- m_retxSuppression.decide(inFace, interest, *pitEntry);
+ RetxSuppression::Result suppression = m_retxSuppression.decide(inFace, interest, *pitEntry);
if (suppression == RetxSuppression::NEW) {
// forward to nexthop with lowest cost except downstream
it = std::find_if(nexthops.begin(), nexthops.end(),
@@ -114,6 +113,11 @@
if (it == nexthops.end()) {
NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " noNextHop");
+
+ lp::NackHeader nackHeader;
+ nackHeader.setReason(lp::NackReason::NO_ROUTE);
+ this->sendNack(pitEntry, inFace, nackHeader);
+
this->rejectPendingInterest(pitEntry);
return;
}
@@ -156,5 +160,72 @@
}
}
+/** \return less severe NackReason between x and y
+ *
+ * lp::NackReason::NONE is treated as most severe
+ */
+inline lp::NackReason
+compareLessSevere(lp::NackReason x, lp::NackReason y)
+{
+ if (x == lp::NackReason::NONE) {
+ return y;
+ }
+ if (y == lp::NackReason::NONE) {
+ return x;
+ }
+ return static_cast<lp::NackReason>(std::min(static_cast<int>(x), static_cast<int>(y)));
+}
+
+void
+BestRouteStrategy2::afterReceiveNack(const Face& inFace, const lp::Nack& nack,
+ shared_ptr<fib::Entry> fibEntry,
+ shared_ptr<pit::Entry> pitEntry)
+{
+ int nOutRecordsNotNacked = 0;
+ Face* lastFaceNotNacked = nullptr;
+ lp::NackReason leastSevereReason = lp::NackReason::NONE;
+ for (const pit::OutRecord& outR : pitEntry->getOutRecords()) {
+ const lp::NackHeader* inNack = outR.getIncomingNack();
+ if (inNack == nullptr) {
+ ++nOutRecordsNotNacked;
+ lastFaceNotNacked = outR.getFace().get();
+ continue;
+ }
+
+ leastSevereReason = compareLessSevere(leastSevereReason, inNack->getReason());
+ }
+
+ lp::NackHeader outNack;
+ outNack.setReason(leastSevereReason);
+
+ if (nOutRecordsNotNacked == 1) {
+ BOOST_ASSERT(lastFaceNotNacked != nullptr);
+ pit::InRecordCollection::const_iterator inR = pitEntry->getInRecord(*lastFaceNotNacked);
+ if (inR != pitEntry->getInRecords().end()) {
+ // one out-record not Nacked, which is also a downstream
+ NFD_LOG_DEBUG(nack.getInterest() << " nack-from=" << inFace.getId() <<
+ " nack=" << nack.getReason() <<
+ " nack-to(bidirectional)=" << lastFaceNotNacked->getId() <<
+ " out-nack=" << outNack.getReason());
+ this->sendNack(pitEntry, *lastFaceNotNacked, outNack);
+ return;
+ }
+ }
+
+ if (nOutRecordsNotNacked > 0) {
+ NFD_LOG_DEBUG(nack.getInterest() << " nack-from=" << inFace.getId() <<
+ " nack=" << nack.getReason() <<
+ " waiting=" << nOutRecordsNotNacked);
+ // continue waiting
+ return;
+ }
+
+
+ NFD_LOG_DEBUG(nack.getInterest() << " nack-from=" << inFace.getId() <<
+ " nack=" << nack.getReason() <<
+ " nack-to=all out-nack=" << outNack.getReason());
+ this->sendNacks(pitEntry, outNack);
+}
+
} // namespace fw
} // namespace nfd
diff --git a/daemon/fw/best-route-strategy2.hpp b/daemon/fw/best-route-strategy2.hpp
index bf3eba2..8c19dc0 100644
--- a/daemon/fw/best-route-strategy2.hpp
+++ b/daemon/fw/best-route-strategy2.hpp
@@ -32,13 +32,22 @@
namespace nfd {
namespace fw {
-/** \brief Best Route strategy version 3
+/** \brief Best Route strategy version 4
*
* This strategy forwards a new Interest to the lowest-cost nexthop (except downstream).
* After that, if consumer retransmits the Interest (and is not suppressed according to
* exponential backoff algorithm), the strategy forwards the Interest again to
* the lowest-cost nexthop (except downstream) that is not previously used.
- * If all nexthops have been used, the strategy starts over.
+ * If all nexthops have been used, the strategy starts over with the first nexthop.
+ *
+ * This strategy returns Nack to all downstreams with reason NoRoute
+ * if there is no usable nexthop, which may be caused by:
+ * (a) the FIB entry contains no nexthop;
+ * (b) the FIB nexthop happens to be the sole downstream;
+ * (c) the FIB nexthops violate scope.
+ *
+ * This strategy returns Nack to all downstreams if all upstreams have returned Nacks.
+ * The reason of the sent Nack equals the least severe reason among received Nacks.
*/
class BestRouteStrategy2 : public Strategy
{
@@ -46,11 +55,15 @@
BestRouteStrategy2(Forwarder& forwarder, const Name& name = STRATEGY_NAME);
virtual void
- afterReceiveInterest(const Face& inFace,
- const Interest& interest,
+ afterReceiveInterest(const Face& inFace, const Interest& interest,
shared_ptr<fib::Entry> fibEntry,
shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE;
+ virtual void
+ afterReceiveNack(const Face& inFace, const lp::Nack& nack,
+ shared_ptr<fib::Entry> fibEntry,
+ shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE;
+
public:
static const Name STRATEGY_NAME;
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index f256d20..a8a8053 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.cpp
@@ -25,6 +25,7 @@
#include "face-table.hpp"
#include "forwarder.hpp"
+#include "core/global-io.hpp"
#include "core/logger.hpp"
namespace nfd {
@@ -89,6 +90,8 @@
&m_forwarder, ref(*face), _1));
face->onReceiveData.connect(bind(&Forwarder::startProcessData,
&m_forwarder, ref(*face), _1));
+ face->onReceiveNack.connect(bind(&Forwarder::startProcessNack,
+ &m_forwarder, ref(*face), _1));
face->onFail.connectSingleShot(bind(&FaceTable::remove, this, face, _1));
this->onAdd(face);
@@ -109,6 +112,9 @@
" (" << reason << ")");
m_forwarder.getFib().removeNextHopFromAllEntries(face);
+
+ // defer Face deallocation, so that Transport isn't deallocated during afterStateChange signal
+ getGlobalIoService().post([face] {});
}
FaceTable::ForwardRange
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 27bfa38..20428c5 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -60,7 +60,7 @@
interest.getLink();
}
}
- catch (tlv::Error&) {
+ catch (const tlv::Error&) {
NFD_LOG_DEBUG("startProcessInterest face=" << face.getId() <<
" interest=" << interest.getName() << " malformed");
// It's safe to call interest.getName() because Name has been fully parsed
@@ -80,6 +80,25 @@
}
void
+Forwarder::startProcessNack(Face& face, const lp::Nack& nack)
+{
+ // check fields used by forwarding are well-formed
+ try {
+ if (nack.getInterest().hasLink()) {
+ nack.getInterest().getLink();
+ }
+ }
+ catch (const tlv::Error&) {
+ NFD_LOG_DEBUG("startProcessNack face=" << face.getId() <<
+ " nack=" << nack.getInterest().getName() <<
+ "~" << nack.getReason() << " malformed");
+ return;
+ }
+
+ this->onIncomingNack(face, nack);
+}
+
+void
Forwarder::onIncomingInterest(Face& inFace, const Interest& interest)
{
// receive Interest
@@ -131,10 +150,23 @@
Forwarder::onInterestLoop(Face& inFace, const Interest& interest,
shared_ptr<pit::Entry> pitEntry)
{
- NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() <<
- " interest=" << interest.getName());
+ // if multi-access face, drop
+ if (inFace.isMultiAccess()) {
+ NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() <<
+ " interest=" << interest.getName() <<
+ " drop");
+ return;
+ }
- // (drop)
+ NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() <<
+ " interest=" << interest.getName() <<
+ " send-Nack-duplicate");
+
+ // send Nack with reason=DUPLICATE
+ // note: Don't enter outgoing Nack pipeline because it needs an in-record.
+ lp::Nack nack(interest);
+ nack.setReason(lp::NackReason::DUPLICATE);
+ inFace.sendNack(nack);
}
void
@@ -362,7 +394,7 @@
// CS insert
m_cs.insert(data);
- std::set<shared_ptr<Face> > pendingDownstreams;
+ std::set<Face*> pendingDownstreams;
// foreach PitEntry
for (const shared_ptr<pit::Entry>& pitEntry : pitMatches) {
NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
@@ -372,10 +404,9 @@
// remember pending downstreams
const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
- for (pit::InRecordCollection::const_iterator it = inRecords.begin();
- it != inRecords.end(); ++it) {
- if (it->getExpiry() > time::steady_clock::now()) {
- pendingDownstreams.insert(it->getFace());
+ for (const pit::InRecord& inRecord : inRecords) {
+ if (inRecord.getExpiry() > time::steady_clock::now()) {
+ pendingDownstreams.insert(inRecord.getFace().get());
}
}
@@ -395,10 +426,8 @@
}
// foreach pending downstream
- for (std::set<shared_ptr<Face> >::iterator it = pendingDownstreams.begin();
- it != pendingDownstreams.end(); ++it) {
- shared_ptr<Face> pendingDownstream = *it;
- if (pendingDownstream.get() == &inFace) {
+ for (Face* pendingDownstream : pendingDownstreams) {
+ if (pendingDownstream == &inFace) {
continue;
}
// goto outgoing Data pipeline
@@ -447,6 +476,104 @@
++m_counters.getNOutDatas();
}
+void
+Forwarder::onIncomingNack(Face& inFace, const lp::Nack& nack)
+{
+ // if multi-access face, drop
+ if (inFace.isMultiAccess()) {
+ NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() <<
+ " nack=" << nack.getInterest().getName() <<
+ "~" << nack.getReason() << " face-is-multi-access");
+ return;
+ }
+
+ // PIT match
+ shared_ptr<pit::Entry> pitEntry = m_pit.find(nack.getInterest());
+ // if no PIT entry found, drop
+ if (pitEntry == nullptr) {
+ NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() <<
+ " nack=" << nack.getInterest().getName() <<
+ "~" << nack.getReason() << " no-PIT-entry");
+ return;
+ }
+
+ // has out-record?
+ pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(inFace);
+ // if no out-record found, drop
+ if (outRecord == pitEntry->getOutRecords().end()) {
+ NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() <<
+ " nack=" << nack.getInterest().getName() <<
+ "~" << nack.getReason() << " no-out-record");
+ return;
+ }
+
+ // if out-record has different Nonce, drop
+ if (nack.getInterest().getNonce() != outRecord->getLastNonce()) {
+ NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() <<
+ " nack=" << nack.getInterest().getName() <<
+ "~" << nack.getReason() << " wrong-Nonce " <<
+ nack.getInterest().getNonce() << "!=" << outRecord->getLastNonce());
+ return;
+ }
+
+ NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() <<
+ " nack=" << nack.getInterest().getName() <<
+ "~" << nack.getReason() << " OK");
+
+ // record Nack on out-record
+ outRecord->setIncomingNack(nack);
+
+ // trigger strategy: after receive NACK
+ shared_ptr<fib::Entry> fibEntry = m_fib.findLongestPrefixMatch(*pitEntry);
+ this->dispatchToStrategy(pitEntry, bind(&Strategy::afterReceiveNack, _1,
+ cref(inFace), cref(nack), fibEntry, pitEntry));
+}
+
+void
+Forwarder::onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
+ const lp::NackHeader& nack)
+{
+ if (outFace.getId() == INVALID_FACEID) {
+ NFD_LOG_WARN("onOutgoingNack face=invalid" <<
+ " nack=" << pitEntry->getInterest().getName() <<
+ "~" << nack.getReason() << " no-in-record");
+ return;
+ }
+
+ // has in-record?
+ pit::InRecordCollection::const_iterator inRecord = pitEntry->getInRecord(outFace);
+
+ // if no in-record found, drop
+ if (inRecord == pitEntry->getInRecords().end()) {
+ NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() <<
+ " nack=" << pitEntry->getInterest().getName() <<
+ "~" << nack.getReason() << " no-in-record");
+ return;
+ }
+
+ // if multi-access face, drop
+ if (outFace.isMultiAccess()) {
+ NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() <<
+ " nack=" << pitEntry->getInterest().getName() <<
+ "~" << nack.getReason() << " face-is-multi-access");
+ return;
+ }
+
+ NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() <<
+ " nack=" << pitEntry->getInterest().getName() <<
+ "~" << nack.getReason() << " OK");
+
+ // create Nack packet with the Interest from in-record
+ lp::Nack nackPkt(inRecord->getInterest());
+ nackPkt.setHeader(nack);
+
+ // erase in-record
+ pitEntry->deleteInRecord(outFace);
+
+ // send Nack on face
+ const_cast<Face&>(outFace).sendNack(nackPkt);
+}
+
static inline bool
compare_InRecord_expiry(const pit::InRecord& a, const pit::InRecord& b)
{
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index 155ec4a..ebfaa05 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -90,6 +90,12 @@
void
startProcessData(Face& face, const Data& data);
+ /** \brief start incoming Nack processing
+ * \param nack the incoming Nack, must be created with make_shared
+ */
+ void
+ startProcessNack(Face& face, const lp::Nack& nack);
+
NameTree&
getNameTree();
@@ -128,12 +134,12 @@
/** \brief Content Store miss pipeline
*/
- void
+ VIRTUAL_WITH_TESTS void
onContentStoreMiss(const Face& inFace, shared_ptr<pit::Entry> pitEntry, const Interest& interest);
/** \brief Content Store hit pipeline
*/
- void
+ VIRTUAL_WITH_TESTS void
onContentStoreHit(const Face& inFace, shared_ptr<pit::Entry> pitEntry,
const Interest& interest, const Data& data);
@@ -176,6 +182,16 @@
VIRTUAL_WITH_TESTS void
onOutgoingData(const Data& data, Face& outFace);
+ /** \brief incoming Nack pipeline
+ */
+ VIRTUAL_WITH_TESTS void
+ onIncomingNack(Face& inFace, const lp::Nack& nack);
+
+ /** \brief outgoing Nack pipeline
+ */
+ VIRTUAL_WITH_TESTS void
+ onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace, const lp::NackHeader& nack);
+
PROTECTED_WITH_TESTS_ELSE_PRIVATE:
VIRTUAL_WITH_TESTS void
setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 4f439db..7b0504e 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -60,23 +60,36 @@
NFD_LOG_DEBUG("beforeExpirePendingInterest pitEntry=" << pitEntry->getName());
}
-//void
-//Strategy::afterAddFibEntry(shared_ptr<fib::Entry> fibEntry)
-//{
-// NFD_LOG_DEBUG("afterAddFibEntry fibEntry=" << fibEntry->getPrefix());
-//}
-//
-//void
-//Strategy::afterUpdateFibEntry(shared_ptr<fib::Entry> fibEntry)
-//{
-// NFD_LOG_DEBUG("afterUpdateFibEntry fibEntry=" << fibEntry->getPrefix());
-//}
-//
-//void
-//Strategy::beforeRemoveFibEntry(shared_ptr<fib::Entry> fibEntry)
-//{
-// NFD_LOG_DEBUG("beforeRemoveFibEntry fibEntry=" << fibEntry->getPrefix());
-//}
+void
+Strategy::afterReceiveNack(const Face& inFace, const lp::Nack& nack,
+ shared_ptr<fib::Entry> fibEntry, shared_ptr<pit::Entry> pitEntry)
+{
+ NFD_LOG_DEBUG("afterReceiveNack inFace=" << inFace.getId() <<
+ " pitEntry=" << pitEntry->getName());
+}
+
+void
+Strategy::sendNacks(shared_ptr<pit::Entry> pitEntry, const lp::NackHeader& header,
+ std::initializer_list<const Face*> exceptFaces)
+{
+ // populate downstreams with all downstreams faces
+ std::unordered_set<const Face*> downstreams;
+ const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
+ std::transform(inRecords.begin(), inRecords.end(), std::inserter(downstreams, downstreams.end()),
+ [] (const pit::InRecord& inR) { return inR.getFace().get(); });
+
+ // delete excluded faces
+ // .erase in a loop is more efficient than std::set_difference between that requires sorted range
+ for (const Face* exceptFace : exceptFaces) {
+ downstreams.erase(exceptFace);
+ }
+
+ // send Nacks
+ for (const Face* downstream : downstreams) {
+ this->sendNack(pitEntry, *downstream, header);
+ }
+ // warning: don't loop on pitEntry->getInRecords(), because InRecord is erased when sending Nack
+}
} // namespace fw
} // namespace nfd
diff --git a/daemon/fw/strategy.hpp b/daemon/fw/strategy.hpp
index 8eca1db..ebbb361 100644
--- a/daemon/fw/strategy.hpp
+++ b/daemon/fw/strategy.hpp
@@ -70,7 +70,7 @@
* invoke this->rejectPendingInterest so that PIT entry will be deleted shortly
*
* \note The strategy is permitted to store a weak reference to fibEntry.
- * Do not store a shared reference, because PIT entry may be deleted at any moment.
+ * Do not store a shared reference, because FIB entry may be deleted at any moment.
* fibEntry is passed by value to allow obtaining a weak reference from it.
* \note The strategy is permitted to store a shared reference to pitEntry.
* pitEntry is passed by value to reflect this fact.
@@ -110,11 +110,33 @@
virtual void
beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry);
+ /** \brief trigger after Nack is received
+ *
+ * This trigger is invoked when an incoming Nack is received in response to
+ * an forwarded Interest.
+ * The Nack has been confirmed to be a response to the last Interest forwarded
+ * to that upstream, i.e. the PIT out-record exists and has a matching Nonce.
+ * The NackHeader has been recorded in the PIT out-record.
+ *
+ * In this base class this method does nothing.
+ *
+ * \note The strategy is permitted to store a weak reference to fibEntry.
+ * Do not store a shared reference, because PIT entry may be deleted at any moment.
+ * fibEntry is passed by value to allow obtaining a weak reference from it.
+ * \note The strategy is permitted to store a shared reference to pitEntry.
+ * pitEntry is passed by value to reflect this fact.
+ */
+ virtual void
+ afterReceiveNack(const Face& inFace, const lp::Nack& nack,
+ shared_ptr<fib::Entry> fibEntry, shared_ptr<pit::Entry> pitEntry);
+
protected: // actions
- /// send Interest to outFace
+ /** \brief send Interest to outFace
+ * \param wantNewNonce if true, a new Nonce will be generated,
+ * rather than reusing a Nonce from one of the PIT in-records
+ */
VIRTUAL_WITH_TESTS void
- sendInterest(shared_ptr<pit::Entry> pitEntry,
- shared_ptr<Face> outFace,
+ sendInterest(shared_ptr<pit::Entry> pitEntry, shared_ptr<Face> outFace,
bool wantNewNonce = false);
/** \brief decide that a pending Interest cannot be forwarded
@@ -125,6 +147,22 @@
VIRTUAL_WITH_TESTS void
rejectPendingInterest(shared_ptr<pit::Entry> pitEntry);
+ /** \brief send Nack to outFace
+ *
+ * The outFace must have a PIT in-record, otherwise this method has no effect.
+ */
+ VIRTUAL_WITH_TESTS void
+ sendNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
+ const lp::NackHeader& header);
+
+ /** \brief send Nack to every face that has an in-record,
+ * except those in \p exceptFaces
+ * \note This is not an action, but a helper that invokes the sendNack action.
+ */
+ void
+ sendNacks(shared_ptr<pit::Entry> pitEntry, const lp::NackHeader& header,
+ std::initializer_list<const Face*> exceptFaces = std::initializer_list<const Face*>());
+
protected: // accessors
MeasurementsAccessor&
getMeasurements();
@@ -171,6 +209,13 @@
m_forwarder.onInterestReject(pitEntry);
}
+inline void
+Strategy::sendNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
+ const lp::NackHeader& header)
+{
+ m_forwarder.onOutgoingNack(pitEntry, outFace, header);
+}
+
inline MeasurementsAccessor&
Strategy::getMeasurements()
{
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 2991ee6..29cac39 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -26,9 +26,11 @@
#include "face-manager.hpp"
#include "core/network-interface.hpp"
-#include "fw/face-table.hpp"
+#include "face/generic-link-service.hpp"
+#include "face/lp-face-wrapper.hpp"
#include "face/tcp-factory.hpp"
#include "face/udp-factory.hpp"
+#include "fw/face-table.hpp"
#include <ndn-cxx/management/nfd-face-status.hpp>
#include <ndn-cxx/management/nfd-channel-status.hpp>
@@ -132,43 +134,6 @@
}
void
-FaceManager::destroyFace(const Name& topPrefix, const Interest& interest,
- const ControlParameters& parameters,
- const ndn::mgmt::CommandContinuation& done)
-{
- shared_ptr<Face> target = m_faceTable.get(parameters.getFaceId());
- if (target) {
- target->close();
- }
-
- done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
-}
-
-void
-FaceManager::enableLocalControl(const Name& topPrefix, const Interest& interest,
- const ControlParameters& parameters,
- const ndn::mgmt::CommandContinuation& done)
-{
- auto result = extractLocalControlParameters(interest, parameters, done);
- if (result.isValid) {
- result.face->setLocalControlHeaderFeature(result.feature, true);
- return done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
- }
-}
-
-void
-FaceManager::disableLocalControl(const Name& topPrefix, const Interest& interest,
- const ControlParameters& parameters,
- const ndn::mgmt::CommandContinuation& done)
-{
- auto result = extractLocalControlParameters(interest, parameters, done);
- if (result.isValid) {
- result.face->setLocalControlHeaderFeature(result.feature, false);
- return done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
- }
-}
-
-void
FaceManager::afterCreateFaceSuccess(ControlParameters& parameters,
const shared_ptr<Face>& newFace,
const ndn::mgmt::CommandContinuation& done)
@@ -182,6 +147,19 @@
}
void
+FaceManager::destroyFace(const Name& topPrefix, const Interest& interest,
+ const ControlParameters& parameters,
+ const ndn::mgmt::CommandContinuation& done)
+{
+ shared_ptr<Face> target = m_faceTable.get(parameters.getFaceId());
+ if (target) {
+ target->close();
+ }
+
+ done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
+}
+
+void
FaceManager::afterCreateFaceFailure(const std::string& reason,
const ndn::mgmt::CommandContinuation& done)
{
@@ -190,6 +168,68 @@
done(ControlResponse(408, "Failed to create face: " + reason));
}
+void
+FaceManager::enableLocalControl(const Name& topPrefix, const Interest& interest,
+ const ControlParameters& parameters,
+ const ndn::mgmt::CommandContinuation& done)
+{
+ auto result = extractLocalControlParameters(interest, parameters, done);
+ if (!result.isValid) {
+ return;
+ }
+
+ if (result.face) {
+ result.face->setLocalControlHeaderFeature(result.feature, true);
+ return done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
+ }
+
+ // TODO#3226 redesign enable-local-control
+ // For now, enable-local-control will enable all local fields in GenericLinkService.
+ BOOST_ASSERT(result.lpFace != nullptr);
+ auto service = dynamic_cast<face::GenericLinkService*>(result.lpFace->getLinkService());
+ if (service == nullptr) {
+ return done(ControlResponse(503, "LinkService type not supported"));
+ }
+
+ face::GenericLinkService::Options options = service->getOptions();
+ options.allowLocalFields = true;
+ service->setOptions(options);
+
+ return done(ControlResponse(200, "OK: enable all local fields on GenericLinkService")
+ .setBody(parameters.wireEncode()));
+}
+
+void
+FaceManager::disableLocalControl(const Name& topPrefix, const Interest& interest,
+ const ControlParameters& parameters,
+ const ndn::mgmt::CommandContinuation& done)
+{
+ auto result = extractLocalControlParameters(interest, parameters, done);
+ if (!result.isValid) {
+ return;
+ }
+
+ if (result.face) {
+ result.face->setLocalControlHeaderFeature(result.feature, false);
+ return done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
+ }
+
+ // TODO#3226 redesign disable-local-control
+ // For now, disable-local-control will disable all local fields in GenericLinkService.
+ BOOST_ASSERT(result.lpFace != nullptr);
+ auto service = dynamic_cast<face::GenericLinkService*>(result.lpFace->getLinkService());
+ if (service == nullptr) {
+ return done(ControlResponse(503, "LinkService type not supported"));
+ }
+
+ face::GenericLinkService::Options options = service->getOptions();
+ options.allowLocalFields = false;
+ service->setOptions(options);
+
+ return done(ControlResponse(200, "OK: disable all local fields on GenericLinkService")
+ .setBody(parameters.wireEncode()));
+}
+
FaceManager::ExtractLocalControlParametersResult
FaceManager::extractLocalControlParameters(const Interest& request,
const ControlParameters& parameters,
@@ -197,6 +237,7 @@
{
ExtractLocalControlParametersResult result;
result.isValid = false;
+ result.lpFace = nullptr;
auto face = m_faceTable.get(request.getIncomingFaceId());
if (!static_cast<bool>(face)) {
@@ -214,6 +255,11 @@
result.isValid = true;
result.face = dynamic_pointer_cast<LocalFace>(face);
+ if (result.face == nullptr) {
+ auto lpFaceW = dynamic_pointer_cast<face::LpFaceWrapper>(face);
+ BOOST_ASSERT(lpFaceW != nullptr);
+ result.lpFace = lpFaceW->getLpFace();
+ }
result.feature = static_cast<LocalControlFeature>(parameters.getLocalControlFeature());
return result;
@@ -685,7 +731,7 @@
}
#endif
- std::list<shared_ptr<MulticastUdpFace> > multicastFacesToRemove;
+ std::list<shared_ptr<face::LpFaceWrapper>> multicastFacesToRemove;
for (auto i = factory->getMulticastFaces().begin();
i != factory->getMulticastFaces().end();
++i) {
@@ -693,33 +739,27 @@
}
for (const auto& nic : ipv4MulticastInterfaces) {
- shared_ptr<MulticastUdpFace> newFace;
- newFace = factory->createMulticastFace(nic.ipv4Addresses[0].to_string(),
- mcastGroup,
- mcastPort,
- isNicNameNecessary ? nic.name : "");
+ auto newFace = factory->createMulticastFace(nic.ipv4Addresses[0].to_string(),
+ mcastGroup, mcastPort,
+ isNicNameNecessary ? nic.name : "");
addCreatedFaceToForwarder(newFace);
multicastFacesToRemove.remove(newFace);
}
- for (auto i = multicastFacesToRemove.begin();
- i != multicastFacesToRemove.end();
- ++i) {
- (*i)->close();
+ for (const auto& face : multicastFacesToRemove) {
+ face->close();
}
}
else {
- std::list<shared_ptr<MulticastUdpFace>> multicastFacesToRemove;
+ std::list<shared_ptr<face::LpFaceWrapper>> multicastFacesToRemove;
for (auto i = factory->getMulticastFaces().begin();
i != factory->getMulticastFaces().end();
++i) {
multicastFacesToRemove.push_back(i->second);
}
- for (auto i = multicastFacesToRemove.begin();
- i != multicastFacesToRemove.end();
- ++i) {
- (*i)->close();
+ for (const auto& face : multicastFacesToRemove) {
+ face->close();
}
}
}
diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp
index f5283d6..e3c955f 100644
--- a/daemon/mgmt/face-manager.hpp
+++ b/daemon/mgmt/face-manager.hpp
@@ -36,6 +36,10 @@
class NetworkInterfaceInfo;
class ProtocolFactory;
+namespace face {
+class LpFace;
+} // namespace face
+
/**
* @brief implement the Face Management of NFD Management Protocol.
* @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
@@ -88,6 +92,7 @@
{
bool isValid;
shared_ptr<LocalFace> face;
+ face::LpFace* lpFace;
LocalControlFeature feature;
};
diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp
index da7c6ed..85ea19c 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.cpp
@@ -149,6 +149,16 @@
}
void
+Entry::deleteInRecord(const Face& face)
+{
+ auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
+ [&face] (const InRecord& inRecord) { return inRecord.getFace().get() == &face; });
+ if (it != m_inRecords.end()) {
+ m_inRecords.erase(it);
+ }
+}
+
+void
Entry::deleteInRecords()
{
m_inRecords.clear();
@@ -168,8 +178,8 @@
return it;
}
-OutRecordCollection::const_iterator
-Entry::getOutRecord(const Face& face) const
+OutRecordCollection::iterator
+Entry::getOutRecord(const Face& face)
{
return std::find_if(m_outRecords.begin(), m_outRecords.end(),
[&face] (const OutRecord& outRecord) { return outRecord.getFace().get() == &face; });
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index 6d59ce8..3f15598 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -132,6 +132,10 @@
InRecordCollection::const_iterator
getInRecord(const Face& face) const;
+ /// deletes one InRecord for face if exists
+ void
+ deleteInRecord(const Face& face);
+
/// deletes all InRecords
void
deleteInRecords();
@@ -151,8 +155,8 @@
/** \brief get the OutRecord for face
* \return an iterator to the OutRecord, or .end if it does not exist
*/
- OutRecordCollection::const_iterator
- getOutRecord(const Face& face) const;
+ OutRecordCollection::iterator
+ getOutRecord(const Face& face);
/// deletes one OutRecord for face if exists
void
diff --git a/daemon/table/pit-out-record.cpp b/daemon/table/pit-out-record.cpp
index 268b67b..1cf303d 100644
--- a/daemon/table/pit-out-record.cpp
+++ b/daemon/table/pit-out-record.cpp
@@ -1,11 +1,12 @@
/* -*- 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
+ * 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.
@@ -20,7 +21,7 @@
*
* 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 "pit-out-record.hpp"
@@ -32,5 +33,16 @@
{
}
+bool
+OutRecord::setIncomingNack(const lp::Nack& nack)
+{
+ if (nack.getInterest().getNonce() != this->getLastNonce()) {
+ return false;
+ }
+
+ m_incomingNack.reset(new lp::NackHeader(nack.getHeader()));
+ return true;
+}
+
} // namespace pit
} // namespace nfd
diff --git a/daemon/table/pit-out-record.hpp b/daemon/table/pit-out-record.hpp
index c75e005..4717779 100644
--- a/daemon/table/pit-out-record.hpp
+++ b/daemon/table/pit-out-record.hpp
@@ -1,11 +1,12 @@
/* -*- 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
+ * 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.
@@ -20,7 +21,7 @@
*
* 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_TABLE_PIT_OUT_RECORD_HPP
#define NFD_DAEMON_TABLE_PIT_OUT_RECORD_HPP
@@ -30,14 +31,49 @@
namespace nfd {
namespace pit {
-/** \class OutRecord
- * \brief contains information about an Interest toward an outgoing face
+/** \brief contains information about an Interest toward an outgoing face
*/
class OutRecord : public FaceRecord
{
public:
explicit
OutRecord(shared_ptr<Face> face);
+
+ /** \return last NACK returned by \p getFace()
+ *
+ * A nullptr return value means the Interest is still pending or has timed out.
+ * A non-null return value means the last outgoing Interest has been NACKed.
+ */
+ const lp::NackHeader*
+ getIncomingNack() const
+ {
+ return m_incomingNack.get();
+ }
+
+ /** \brief sets a NACK received from \p getFace()
+ * \return whether incoming NACK is accepted
+ *
+ * This is invoked in incoming NACK pipeline.
+ * An incoming NACK is accepted if its Nonce matches \p getLastNonce().
+ * If accepted, \p nack.getHeader() will be copied,
+ * and any pointer previously returned by \p .getIncomingNack() .
+ */
+ bool
+ setIncomingNack(const lp::Nack& nack);
+
+ /** \brief clears last NACK
+ *
+ * This is invoked in outgoing Interest pipeline.
+ * This invalidates any pointer previously returned by \p .getIncomingNack() .
+ */
+ void
+ clearIncomingNack()
+ {
+ m_incomingNack.reset();
+ }
+
+private:
+ unique_ptr<lp::NackHeader> m_incomingNack;
};
} // namespace pit
diff --git a/daemon/table/pit.cpp b/daemon/table/pit.cpp
index c21ccdf..959593f 100644
--- a/daemon/table/pit.cpp
+++ b/daemon/table/pit.cpp
@@ -62,7 +62,7 @@
}
std::pair<shared_ptr<pit::Entry>, bool>
-Pit::insert(const Interest& interest)
+Pit::findOrInsert(const Interest& interest, bool allowInsert)
{
// first lookup() the Interest Name in the NameTree, which will creates all
// the intermedia nodes, starting from the shortest prefix.
@@ -78,13 +78,17 @@
entry->getInterest().getSelectors() == interest.getSelectors();
});
if (it != pitEntries.end()) {
- return { *it, false };
+ return {*it, false};
+ }
+
+ if (!allowInsert) {
+ return {nullptr, true};
}
shared_ptr<pit::Entry> entry = make_shared<pit::Entry>(interest);
nameTreeEntry->insertPitEntry(entry);
m_nItems++;
- return { entry, true };
+ return {entry, true};
}
pit::DataMatchResult
diff --git a/daemon/table/pit.hpp b/daemon/table/pit.hpp
index e9616d5..adab085 100644
--- a/daemon/table/pit.hpp
+++ b/daemon/table/pit.hpp
@@ -58,10 +58,17 @@
size_t
size() const;
+ /** \brief finds a PIT entry for Interest
+ * \param interest the Interest
+ * \return an existing entry with same Name and Selectors; otherwise nullptr
+ */
+ shared_ptr<pit::Entry>
+ find(const Interest& interest) const;
+
/** \brief inserts a PIT entry for Interest
- *
- * If an entry for exact same name and selectors exists, that entry is returned.
- * \return the entry, and true for new entry, false for existing entry
+ * \param interest the Interest; must be created with make_shared
+ * \return a new or existing entry with same Name and Selectors,
+ * and true for new entry, false for existing entry
*/
std::pair<shared_ptr<pit::Entry>, bool>
insert(const Interest& interest);
@@ -135,6 +142,18 @@
};
private:
+ /** \brief finds or inserts a PIT entry for Interest
+ * \param interest the Interest; must be created with make_shared if allowInsert
+ * \param allowInsert whether inserting new entry is allowed.
+ * \return if allowInsert, a new or existing entry with same Name+Selectors,
+ * and true for new entry, false for existing entry;
+ * if not allowInsert, an existing entry with same Name+Selectors and false,
+ * or {nullptr, true} if there's no existing entry
+ */
+ std::pair<shared_ptr<pit::Entry>, bool>
+ findOrInsert(const Interest& interest, bool allowInsert);
+
+private:
NameTree& m_nameTree;
size_t m_nItems;
};
@@ -145,6 +164,18 @@
return m_nItems;
}
+inline shared_ptr<pit::Entry>
+Pit::find(const Interest& interest) const
+{
+ return const_cast<Pit*>(this)->findOrInsert(interest, false).first;
+}
+
+inline std::pair<shared_ptr<pit::Entry>, bool>
+Pit::insert(const Interest& interest)
+{
+ return this->findOrInsert(interest, true);
+}
+
inline Pit::const_iterator
Pit::end() const
{
diff --git a/tests/daemon/face/dummy-lp-face.cpp b/tests/daemon/face/dummy-lp-face.cpp
new file mode 100644
index 0000000..20fb20d
--- /dev/null
+++ b/tests/daemon/face/dummy-lp-face.cpp
@@ -0,0 +1,140 @@
+/* -*- 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 "dummy-lp-face.hpp"
+#include "dummy-transport.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+class DummyLpFace::LinkService : public face::LinkService
+{
+public:
+ void
+ receiveInterest(const Interest& interest)
+ {
+ this->face::LinkService::receiveInterest(interest);
+ }
+
+ void
+ receiveData(const Data& data)
+ {
+ this->face::LinkService::receiveData(data);
+ }
+
+ void
+ receiveNack(const lp::Nack& nack)
+ {
+ this->face::LinkService::receiveNack(nack);
+ }
+
+ signal::Signal<LinkService> afterSend;
+
+private:
+ virtual void
+ doSendInterest(const Interest& interest) DECL_OVERRIDE
+ {
+ this->sentInterests.push_back(interest);
+ this->afterSend();
+ }
+
+ virtual void
+ doSendData(const Data& data) DECL_OVERRIDE
+ {
+ this->sentData.push_back(data);
+ this->afterSend();
+ }
+
+ virtual void
+ doSendNack(const lp::Nack& nack) DECL_OVERRIDE
+ {
+ this->sentNacks.push_back(nack);
+ this->afterSend();
+ }
+
+ virtual void
+ doReceivePacket(Transport::Packet&& packet) DECL_OVERRIDE
+ {
+ BOOST_ASSERT(false);
+ }
+
+public:
+ std::vector<Interest> sentInterests;
+ std::vector<Data> sentData;
+ std::vector<lp::Nack> sentNacks;
+};
+
+DummyLpFace::DummyLpFace(const std::string& localUri, const std::string& remoteUri,
+ ndn::nfd::FaceScope scope, ndn::nfd::FacePersistency persistency,
+ ndn::nfd::LinkType linkType)
+ : LpFace(make_unique<LinkService>(),
+ make_unique<DummyTransport>(localUri, remoteUri, scope, persistency, linkType))
+ , afterSend(this->getLinkServiceInternal()->afterSend)
+ , sentInterests(this->getLinkServiceInternal()->sentInterests)
+ , sentData(this->getLinkServiceInternal()->sentData)
+ , sentNacks(this->getLinkServiceInternal()->sentNacks)
+{
+}
+
+void
+DummyLpFace::setState(FaceState state)
+{
+ this->getTransportInternal()->setState(state);
+}
+
+void
+DummyLpFace::receiveInterest(const Interest& interest)
+{
+ this->getLinkServiceInternal()->receiveInterest(interest);
+}
+
+void
+DummyLpFace::receiveData(const Data& data)
+{
+ this->getLinkServiceInternal()->receiveData(data);
+}
+
+void
+DummyLpFace::receiveNack(const lp::Nack& nack)
+{
+ this->getLinkServiceInternal()->receiveNack(nack);
+}
+
+DummyLpFace::LinkService*
+DummyLpFace::getLinkServiceInternal()
+{
+ return static_cast<LinkService*>(this->getLinkService());
+}
+
+DummyTransport*
+DummyLpFace::getTransportInternal()
+{
+ return static_cast<DummyTransport*>(this->getTransport());
+}
+
+} // namespace tests
+} // namespace face
+} // namespace nfd
diff --git a/tests/daemon/face/dummy-lp-face.hpp b/tests/daemon/face/dummy-lp-face.hpp
new file mode 100644
index 0000000..588cb59
--- /dev/null
+++ b/tests/daemon/face/dummy-lp-face.hpp
@@ -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/>.
+ */
+
+#ifndef NFD_TESTS_DAEMON_FACE_DUMMY_LP_FACE_HPP
+#define NFD_TESTS_DAEMON_FACE_DUMMY_LP_FACE_HPP
+
+#include "face/lp-face.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+class DummyTransport;
+
+/** \brief a LpFace for unit testing
+ *
+ * The DummyLpFace allows observing outgoing network-layer packets,
+ * and allows incoming network-layer packets to be injected from a test suite.
+ * It's primarily used for forwarding test suites, but can be used in other tests as well.
+ */
+class DummyLpFace : public LpFace
+{
+public:
+ class LinkService;
+
+ DummyLpFace(const std::string& localUri = "dummy://", const std::string& remoteUri = "dummy://",
+ ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+
+ /** \brief changes face state
+ * \pre current state is not CLOSED or FAILED
+ */
+ void
+ setState(FaceState state);
+
+ /** \brief causes the face to receive an Interest
+ */
+ void
+ receiveInterest(const Interest& interest);
+
+ /** \brief causes the face to receive a Data
+ */
+ void
+ receiveData(const Data& data);
+
+ /** \brief causes the face to receive a Nack
+ */
+ void
+ receiveNack(const lp::Nack& nack);
+
+ /** \brief signals after any network-layer packet is sent
+ */
+ signal::Signal<LinkService>& afterSend;
+
+private:
+ LinkService*
+ getLinkServiceInternal();
+
+ DummyTransport*
+ getTransportInternal();
+
+public:
+ std::vector<Interest>& sentInterests;
+ std::vector<Data>& sentData;
+ std::vector<lp::Nack>& sentNacks;
+};
+
+} // namespace tests
+} // namespace face
+
+namespace tests {
+using nfd::face::tests::DummyLpFace;
+} // namespace tests
+} // namespace nfd
+
+#endif // NFD_TESTS_DAEMON_FACE_DUMMY_LP_FACE_HPP
diff --git a/tests/daemon/face/dummy-transport.hpp b/tests/daemon/face/dummy-transport.hpp
new file mode 100644
index 0000000..df8fa54
--- /dev/null
+++ b/tests/daemon/face/dummy-transport.hpp
@@ -0,0 +1,96 @@
+/* -*- 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_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP
+#define NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP
+
+#include "common.hpp"
+
+#include "face/transport.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+/** \brief dummy Transport used in unit tests
+ */
+class DummyTransport : public Transport
+{
+public:
+ DummyTransport(const std::string& localUri = "dummy://",
+ const std::string& remoteUri = "dummy://",
+ ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT)
+ : isClosed(false)
+ {
+ this->setLocalUri(FaceUri(localUri));
+ this->setRemoteUri(FaceUri(remoteUri));
+ this->setScope(scope);
+ this->setPersistency(persistency);
+ this->setLinkType(linkType);
+ }
+
+ void
+ setState(FaceState state)
+ {
+ this->Transport::setState(state);
+ }
+
+ void
+ receivePacket(Packet&& packet)
+ {
+ this->receive(std::move(packet));
+ }
+
+ void
+ receivePacket(Block block)
+ {
+ this->receive(Packet(std::move(block)));
+ }
+
+private:
+ virtual void
+ doClose() DECL_OVERRIDE
+ {
+ isClosed = true;
+ }
+
+ virtual void
+ doSend(Packet&& packet) DECL_OVERRIDE
+ {
+ sentPackets.push_back(std::move(packet));
+ }
+
+public:
+ bool isClosed;
+ std::vector<Packet> sentPackets;
+};
+
+} // namespace tests
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP
diff --git a/tests/daemon/face/generic-link-service.t.cpp b/tests/daemon/face/generic-link-service.t.cpp
new file mode 100644
index 0000000..aa2c7a7
--- /dev/null
+++ b/tests/daemon/face/generic-link-service.t.cpp
@@ -0,0 +1,493 @@
+/* -*- 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/generic-link-service.hpp"
+#include "face/lp-face.hpp"
+#include "dummy-transport.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_AUTO_TEST_SUITE(Face)
+
+class GenericLinkServiceFixture : public BaseFixture
+{
+protected:
+ GenericLinkServiceFixture()
+ : service(nullptr)
+ , transport(nullptr)
+ {
+ this->initialize(GenericLinkService::Options());
+ // By default, GenericLinkService is created with default options.
+ // Test cases may invoke .initialize with alternate options.
+ }
+
+ void
+ initialize(const GenericLinkService::Options& options)
+ {
+ face.reset(new LpFace(make_unique<GenericLinkService>(options),
+ make_unique<DummyTransport>()));
+ service = static_cast<GenericLinkService*>(face->getLinkService());
+ transport = static_cast<DummyTransport*>(face->getTransport());
+
+ face->afterReceiveInterest.connect(
+ [this] (const Interest& interest) { receivedInterests.push_back(interest); });
+ face->afterReceiveData.connect(
+ [this] (const Data& data) { receivedData.push_back(data); });
+ face->afterReceiveNack.connect(
+ [this] (const lp::Nack& nack) { receivedNacks.push_back(nack); });
+ }
+
+protected:
+ unique_ptr<LpFace> face;
+ GenericLinkService* service;
+ DummyTransport* transport;
+ std::vector<Interest> receivedInterests;
+ std::vector<Data> receivedData;
+ std::vector<lp::Nack> receivedNacks;
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture)
+
+
+BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields
+
+BOOST_AUTO_TEST_CASE(SendInterest)
+{
+ // Initialize with Options that disables all services
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ shared_ptr<Interest> interest1 = makeInterest("/localhost/test");
+
+ face->sendInterest(*interest1);
+
+ BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
+ BOOST_CHECK(transport->sentPackets.back().packet == interest1->wireEncode());
+}
+
+BOOST_AUTO_TEST_CASE(SendData)
+{
+ // Initialize with Options that disables all services
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ shared_ptr<Data> data1 = makeData("/localhost/test");
+
+ face->sendData(*data1);
+
+ BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
+ BOOST_CHECK(transport->sentPackets.back().packet == data1->wireEncode());
+}
+
+BOOST_AUTO_TEST_CASE(SendNack)
+{
+ // Initialize with Options that disables all services
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
+
+ face->sendNack(nack1);
+
+ BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
+ lp::Packet nack1pkt;
+ BOOST_REQUIRE_NO_THROW(nack1pkt.wireDecode(transport->sentPackets.back().packet));
+ BOOST_CHECK_EQUAL(nack1pkt.has<lp::NackField>(), true);
+ BOOST_CHECK_EQUAL(nack1pkt.has<lp::FragmentField>(), true);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
+{
+ // Initialize with Options that disables all services
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR");
+
+ transport->receivePacket(interest1->wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
+ BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveInterest)
+{
+ // Initialize with Options that disables all services
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR");
+ lp::Packet lpPacket;
+ lpPacket.set<lp::FragmentField>(std::make_pair(
+ interest1->wireEncode().begin(), interest1->wireEncode().end()));
+ lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
+
+ transport->receivePacket(lpPacket.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
+ BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveBareData)
+{
+ // Initialize with Options that disables all services
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ shared_ptr<Data> data1 = makeData("/12345678");
+
+ transport->receivePacket(data1->wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
+ BOOST_CHECK_EQUAL(receivedData.back(), *data1);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveData)
+{
+ // Initialize with Options that disables all services
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ shared_ptr<Data> data1 = makeData("/12345689");
+ lp::Packet lpPacket;
+ lpPacket.set<lp::FragmentField>(std::make_pair(
+ data1->wireEncode().begin(), data1->wireEncode().end()));
+ lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
+
+ transport->receivePacket(lpPacket.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
+ BOOST_CHECK_EQUAL(receivedData.back(), *data1);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveNack)
+{
+ // Initialize with Options that disables all services
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
+ lp::Packet lpPacket;
+ lpPacket.set<lp::FragmentField>(std::make_pair(
+ nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end()));
+ lpPacket.set<lp::NackField>(nack1.getHeader());
+
+ transport->receivePacket(lpPacket.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
+
+
+BOOST_AUTO_TEST_SUITE(Fragmentation)
+
+BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex)
+{
+ // TODO#3171 Initialize with Options that disables reassembly
+
+ shared_ptr<Interest> interest = makeInterest("/IgFe6NvH");
+ lp::Packet packet(interest->wireEncode());
+ packet.set<lp::FragIndexField>(140);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_CHECK(receivedInterests.empty());
+}
+
+BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount)
+{
+ // TODO#3171 Initialize with Options that disables reassembly
+
+ shared_ptr<Interest> interest = makeInterest("/SeGmEjvIVX");
+ lp::Packet packet(interest->wireEncode());
+ packet.set<lp::FragCountField>(276);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_CHECK(receivedInterests.empty());
+}
+
+BOOST_AUTO_TEST_SUITE_END() // Fragmentation
+
+
+BOOST_AUTO_TEST_SUITE(LocalFields)
+
+BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ shared_ptr<Interest> interest = makeInterest("/12345678");
+ lp::Packet packet(interest->wireEncode());
+ packet.set<lp::NextHopFaceIdField>(1000);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
+ BOOST_REQUIRE(receivedInterests.back().getLocalControlHeader().hasNextHopFaceId());
+ BOOST_CHECK_EQUAL(receivedInterests.back().getNextHopFaceId(), 1000);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
+{
+ // Initialize with Options that disables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ shared_ptr<Interest> interest = makeInterest("/12345678");
+ lp::Packet packet(interest->wireEncode());
+ packet.set<lp::NextHopFaceIdField>(1000);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_CHECK(receivedInterests.empty());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ shared_ptr<Data> data = makeData("/12345678");
+ lp::Packet packet(data->wireEncode());
+ packet.set<lp::NextHopFaceIdField>(1000);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_CHECK(receivedData.empty());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
+ lp::Packet packet;
+ packet.set<lp::FragmentField>(std::make_pair(
+ nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
+ packet.set<lp::NackField>(nack.getHeader());
+ packet.set<lp::NextHopFaceIdField>(1000);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_CHECK(receivedNacks.empty());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveCacheControl)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ shared_ptr<Data> data = makeData("/12345678");
+ lp::Packet packet(data->wireEncode());
+ lp::CachePolicy policy;
+ policy.setPolicy(lp::CachePolicyType::NO_CACHE);
+ packet.set<lp::CachePolicyField>(policy);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
+ BOOST_REQUIRE(receivedData.back().getLocalControlHeader().hasCachingPolicy());
+ BOOST_CHECK_EQUAL(receivedData.back().getCachingPolicy(),
+ ndn::nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveCacheControlDisabled)
+{
+ // Initialize with Options that disables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ shared_ptr<Data> data = makeData("/12345678");
+ lp::Packet packet(data->wireEncode());
+ lp::CachePolicy policy;
+ policy.setPolicy(lp::CachePolicyType::NO_CACHE);
+ packet.set<lp::CachePolicyField>(policy);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
+ BOOST_CHECK(!receivedData.back().getLocalControlHeader().hasCachingPolicy());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropInterest)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ shared_ptr<Interest> interest = makeInterest("/12345678");
+ lp::Packet packet(interest->wireEncode());
+ lp::CachePolicy policy;
+ policy.setPolicy(lp::CachePolicyType::NO_CACHE);
+ packet.set<lp::CachePolicyField>(policy);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_CHECK(receivedInterests.empty());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropNack)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
+ lp::Packet packet(nack.getInterest().wireEncode());
+ packet.set<lp::NackField>(nack.getHeader());
+ lp::CachePolicy policy;
+ policy.setPolicy(lp::CachePolicyType::NO_CACHE);
+ packet.set<lp::CachePolicyField>(policy);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_CHECK(receivedNacks.empty());
+}
+
+BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ shared_ptr<Interest> interest = makeInterest("/12345678");
+ interest->setIncomingFaceId(1000);
+
+ face->sendInterest(*interest);
+
+ BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
+ lp::Packet sent(transport->sentPackets.back().packet);
+ BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>());
+ BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000);
+}
+
+BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
+{
+ // Initialize with Options that disables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = false;
+ initialize(options);
+
+ shared_ptr<Interest> interest = makeInterest("/12345678");
+ interest->setIncomingFaceId(1000);
+
+ face->sendInterest(*interest);
+
+ BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
+ lp::Packet sent(transport->sentPackets.back().packet);
+ BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ shared_ptr<Interest> interest = makeInterest("/12345678");
+ lp::Packet packet(interest->wireEncode());
+ packet.set<lp::IncomingFaceIdField>(1000);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
+ BOOST_CHECK(!receivedInterests.back().getLocalControlHeader().hasIncomingFaceId());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ shared_ptr<Data> data = makeData("/z1megUh9Bj");
+ lp::Packet packet(data->wireEncode());
+ packet.set<lp::IncomingFaceIdField>(1000);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
+ BOOST_CHECK(!receivedData.back().getLocalControlHeader().hasIncomingFaceId());
+}
+
+BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack)
+{
+ // Initialize with Options that enables local fields
+ GenericLinkService::Options options;
+ options.allowLocalFields = true;
+ initialize(options);
+
+ lp::Nack nack = makeNack("/TPAhdiHz", 278, lp::NackReason::CONGESTION);
+ lp::Packet packet(nack.getInterest().wireEncode());
+ packet.set<lp::NackField>(nack.getHeader());
+ packet.set<lp::IncomingFaceIdField>(1000);
+
+ transport->receivePacket(packet.wireEncode());
+
+ BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
+ BOOST_CHECK(!receivedNacks.back().getLocalControlHeader().hasIncomingFaceId());
+}
+
+BOOST_AUTO_TEST_SUITE_END() // LocalFields
+
+
+BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService
+BOOST_AUTO_TEST_SUITE_END() // Face
+
+} // namespace tests
+} // namespace face
+} // namespace nfd
diff --git a/tests/daemon/face/lp-face-wrapper.t.cpp b/tests/daemon/face/lp-face-wrapper.t.cpp
new file mode 100644
index 0000000..182d2fc
--- /dev/null
+++ b/tests/daemon/face/lp-face-wrapper.t.cpp
@@ -0,0 +1,173 @@
+/* -*- 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/lp-face-wrapper.hpp"
+#include "fw/forwarder.hpp"
+
+#include "tests/test-common.hpp"
+#include "dummy-lp-face.hpp"
+
+namespace nfd {
+namespace face {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestLpFaceWrapper, BaseFixture)
+
+BOOST_AUTO_TEST_CASE(SetId)
+{
+ Forwarder forwarder;
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+
+ BOOST_CHECK_EQUAL(face1->getId(), nfd::face::INVALID_FACEID);
+ BOOST_CHECK_EQUAL(face1w->getId(), nfd::INVALID_FACEID);
+
+ forwarder.addFace(face1w);
+
+ BOOST_CHECK_NE(face1->getId(), nfd::face::INVALID_FACEID);
+ BOOST_CHECK_NE(face1w->getId(), nfd::INVALID_FACEID);
+ BOOST_CHECK_EQUAL(face1->getId(), static_cast<face::FaceId>(face1w->getId()));
+}
+
+BOOST_AUTO_TEST_CASE(SetPersistency)
+{
+ unique_ptr<LpFace> face1u = make_unique<DummyLpFace>();
+ face1u->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+
+ auto face1w = make_shared<face::LpFaceWrapper>(std::move(face1u));
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+
+ BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+ BOOST_CHECK_EQUAL(face1w->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
+
+ face1w->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+
+ BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+ BOOST_CHECK_EQUAL(face1w->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+}
+
+BOOST_AUTO_TEST_CASE(FailSignal)
+{
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+
+ bool isFailed = false;
+ face1w->onFail.connect(bind([&isFailed] { isFailed = true; }));
+
+ face1->setState(FaceState::DOWN);
+ BOOST_CHECK(!isFailed);
+
+ face1->setState(FaceState::FAILED);
+ BOOST_CHECK(!isFailed);
+
+ face1->setState(FaceState::CLOSED);
+ BOOST_CHECK(isFailed);
+}
+
+BOOST_AUTO_TEST_CASE(SendReceive)
+{
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+
+ const size_t nInInterests = 192;
+ const size_t nInData = 91;
+ const size_t nInNacks = 29;
+ const size_t nOutInterests = 202;
+ const size_t nOutData = 128;
+ const size_t nOutNacks = 84;
+
+ size_t nReceivedInterests = 0;
+ size_t nReceivedData = 0;
+ size_t nReceivedNacks = 0;
+ face1w->onReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; }));
+ face1w->onReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; }));
+ face1w->onReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; }));
+
+ BOOST_CHECK_EQUAL(face1->getCounters().getNInInterests(), 0);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNInDatas(), 0);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNOutInterests(), 0);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNOutDatas(), 0);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNInInterests(), 0);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNInDatas(), 0);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNOutInterests(), 0);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNOutDatas(), 0);
+ // There's no counters for NACK for now.
+
+ for (size_t i = 0; i < nInInterests; ++i) {
+ shared_ptr<Interest> interest = makeInterest("/JSQdqward4");
+ face1->receiveInterest(*interest);
+ }
+
+ for (size_t i = 0; i < nInData; ++i) {
+ shared_ptr<Data> data = makeData("/hT8FDigWn1");
+ face1->receiveData(*data);
+ }
+
+ for (size_t i = 0; i < nInNacks; ++i) {
+ lp::Nack nack = makeNack("/StnEVTj4Ex", 561, lp::NackReason::CONGESTION);
+ face1->receiveNack(nack);
+ }
+
+ for (size_t i = 0; i < nOutInterests; ++i) {
+ shared_ptr<Interest> interest = makeInterest("/XyUAFYQDmd");
+ face1w->sendInterest(*interest);
+ }
+
+ for (size_t i = 0; i < nOutData; ++i) {
+ shared_ptr<Data> data = makeData("/GigPEtPH6");
+ face1w->sendData(*data);
+ }
+
+ for (size_t i = 0; i < nOutNacks; ++i) {
+ lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION);
+ face1w->sendNack(nack);
+ }
+
+ BOOST_CHECK_EQUAL(face1->getCounters().getNInInterests(), nInInterests);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNInDatas(), nInData);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNOutInterests(), nOutInterests);
+ BOOST_CHECK_EQUAL(face1->getCounters().getNOutDatas(), nOutData);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNInInterests(), nInInterests);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNInDatas(), nInData);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNOutInterests(), nOutInterests);
+ BOOST_CHECK_EQUAL(face1w->getCounters().getNOutDatas(), nOutData);
+
+ BOOST_CHECK_EQUAL(nReceivedInterests, nInInterests);
+ BOOST_CHECK_EQUAL(nReceivedData, nInData);
+ BOOST_CHECK_EQUAL(nReceivedNacks, nInNacks);
+ BOOST_CHECK_EQUAL(face1->sentInterests.size(), nOutInterests);
+ BOOST_CHECK_EQUAL(face1->sentData.size(), nOutData);
+ BOOST_CHECK_EQUAL(face1->sentNacks.size(), nOutNacks);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace face
+} // namespace nfd
diff --git a/tests/daemon/face/udp.t.cpp b/tests/daemon/face/udp.t.cpp
index c00f54f..6869176 100644
--- a/tests/daemon/face/udp.t.cpp
+++ b/tests/daemon/face/udp.t.cpp
@@ -24,7 +24,6 @@
*/
#include "face/udp-channel.hpp"
-#include "face/udp-face.hpp"
#include "face/udp-factory.hpp"
#include "core/network-interface.hpp"
@@ -35,7 +34,10 @@
namespace nfd {
namespace tests {
-BOOST_FIXTURE_TEST_SUITE(FaceUdp, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestUdp, BaseFixture)
+
+using nfd::Face;
BOOST_AUTO_TEST_CASE(GetChannels)
{
@@ -126,7 +128,7 @@
auto multicastFace1a = factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072");
BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
BOOST_CHECK_EQUAL(multicastFace1->isLocal(), false);
- BOOST_CHECK_EQUAL(multicastFace1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
+ BOOST_CHECK_EQUAL(multicastFace1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
BOOST_CHECK_EQUAL(multicastFace1->isMultiAccess(), true);
//same endpoint of a multicast face
@@ -701,7 +703,8 @@
}));
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestUdp
+BOOST_AUTO_TEST_SUITE_END() // Face
} // namespace tests
} // namespace nfd
diff --git a/tests/daemon/face/unix-stream.t.cpp b/tests/daemon/face/unix-stream.t.cpp
index c5f5221..0af9db2 100644
--- a/tests/daemon/face/unix-stream.t.cpp
+++ b/tests/daemon/face/unix-stream.t.cpp
@@ -24,8 +24,11 @@
*/
#include "face/unix-stream-channel.hpp"
-#include "face/unix-stream-face.hpp"
#include "face/unix-stream-factory.hpp"
+#include "face/unix-stream-transport.hpp"
+
+#include "face/generic-link-service.hpp"
+#include "face/lp-face-wrapper.hpp"
#include "tests/test-common.hpp"
#include "tests/limited-io.hpp"
@@ -38,7 +41,12 @@
#define CHANNEL_PATH1 "unix-stream-test.1.sock"
#define CHANNEL_PATH2 "unix-stream-test.2.sock"
-BOOST_FIXTURE_TEST_SUITE(FaceUnixStream, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestUnixStream, BaseFixture)
+
+using nfd::Face;
+using face::LpFaceWrapper;
+using face::UnixStreamTransport;
BOOST_AUTO_TEST_CASE(ChannelMap)
{
@@ -112,7 +120,7 @@
channel1_onFaceCreated(const shared_ptr<Face>& newFace)
{
BOOST_CHECK(!static_cast<bool>(face1));
- face1 = static_pointer_cast<UnixStreamFace>(newFace);
+ face1 = static_pointer_cast<LpFaceWrapper>(newFace);
face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1));
face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1));
@@ -162,7 +170,7 @@
void
channel_onFaceCreated(const shared_ptr<Face>& newFace)
{
- faces.push_back(static_pointer_cast<UnixStreamFace>(newFace));
+ faces.push_back(static_pointer_cast<LpFaceWrapper>(newFace));
limitedIo.afterOp();
}
@@ -175,25 +183,26 @@
limitedIo.afterOp();
}
- shared_ptr<UnixStreamFace>
- makeFace(UnixStreamFace::protocol::socket socket)
+ shared_ptr<LpFaceWrapper>
+ makeFace(UnixStreamTransport::protocol::socket&& socket)
{
- auto remoteUri = FaceUri::fromFd(socket.native_handle());
- auto localUri = FaceUri(socket.local_endpoint());
- return make_shared<UnixStreamFace>(remoteUri, localUri, std::move(socket));
+ auto linkService = make_unique<face::GenericLinkService>();
+ auto transport = make_unique<UnixStreamTransport>(std::move(socket));
+ auto lpFace = make_unique<LpFace>(std::move(linkService), std::move(transport));
+ return make_shared<LpFaceWrapper>(std::move(lpFace));
}
protected:
LimitedIo limitedIo;
- shared_ptr<UnixStreamFace> face1;
+ shared_ptr<LpFaceWrapper> face1;
std::vector<Interest> face1_receivedInterests;
std::vector<Data> face1_receivedDatas;
- shared_ptr<UnixStreamFace> face2;
+ shared_ptr<LpFaceWrapper> face2;
std::vector<Interest> face2_receivedInterests;
std::vector<Data> face2_receivedDatas;
- std::list<shared_ptr<UnixStreamFace>> faces;
+ std::list<shared_ptr<LpFaceWrapper>> faces;
};
@@ -205,8 +214,8 @@
channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
- UnixStreamFace::protocol::socket client(g_io);
- client.async_connect(UnixStreamFace::protocol::endpoint(CHANNEL_PATH1),
+ UnixStreamTransport::protocol::socket client(g_io);
+ client.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
bind(&EndToEndFixture::client_onConnect, this, _1));
BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect");
@@ -280,16 +289,16 @@
channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
- UnixStreamFace::protocol::socket client1(g_io);
- client1.async_connect(UnixStreamFace::protocol::endpoint(CHANNEL_PATH1),
+ UnixStreamTransport::protocol::socket client1(g_io);
+ client1.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
bind(&EndToEndFixture::client_onConnect, this, _1));
BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "First connect");
BOOST_CHECK_EQUAL(faces.size(), 1);
- UnixStreamFace::protocol::socket client2(g_io);
- client2.async_connect(UnixStreamFace::protocol::endpoint(CHANNEL_PATH1),
+ UnixStreamTransport::protocol::socket client2(g_io);
+ client2.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
bind(&EndToEndFixture::client_onConnect, this, _1));
BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Second connect");
@@ -331,188 +340,189 @@
BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName());
}
-BOOST_FIXTURE_TEST_CASE(UnixStreamFaceLocalControlHeader, EndToEndFixture)
-{
- UnixStreamFactory factory;
+//BOOST_FIXTURE_TEST_CASE(UnixStreamTransportLocalControlHeader, EndToEndFixture)
+//{
+// UnixStreamFactory factory;
+//
+// shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
+// channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
+// bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
+//
+// UnixStreamTransport::protocol::socket client(g_io);
+// client.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
+// bind(&EndToEndFixture::client_onConnect, this, _1));
+//
+// BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect");
+//
+// BOOST_REQUIRE(static_cast<bool>(face1));
+//
+// face2 = makeFace(std::move(client));
+// face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1));
+// face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1));
+//
+// shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
+// shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
- shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
- channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
+// face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
+// face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
+//
+// BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
+// BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
- UnixStreamFace::protocol::socket client(g_io);
- client.async_connect(UnixStreamFace::protocol::endpoint(CHANNEL_PATH1),
- bind(&EndToEndFixture::client_onConnect, this, _1));
+// face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
+// face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect");
-
- BOOST_REQUIRE(static_cast<bool>(face1));
-
- face2 = makeFace(std::move(client));
- face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1));
- face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1));
-
- shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
- shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
-
- face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
- face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
-
- BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
- BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
-
- face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
- face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
-
- BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
- BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
+// BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
+// BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
////////////////////////////////////////////////////////
- interest1->setIncomingFaceId(11);
- interest1->setNextHopFaceId(111);
- face1->sendInterest(*interest1);
+// interest1->setIncomingFaceId(11);
+// interest1->setNextHopFaceId(111);
+// face1->sendInterest(*interest1);
- data1->setIncomingFaceId(22);
- data1->getLocalControlHeader().setNextHopFaceId(222);
- face1->sendData(*data1);
+// data1->setIncomingFaceId(22);
+// data1->getLocalControlHeader().setNextHopFaceId(222);
+// face1->sendData(*data1);
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
- "Regular send/receive");
+// BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
+// "Regular send/receive");
- BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
- BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
+// BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
+// BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
- // sending allows only IncomingFaceId, receiving allows only NextHopFaceId
- BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false);
- BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), false);
+// sending allows only IncomingFaceId, receiving allows only NextHopFaceId
+// BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false);
+// BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), false);
- BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false);
- BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false);
+// BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false);
+// BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false);
- face1->close();
- face1.reset();
+// face1->close();
+// face1.reset();
////////////////////////////////////////////////////////
- client.async_connect(UnixStreamFace::protocol::endpoint(CHANNEL_PATH1),
- bind(&EndToEndFixture::client_onConnect, this, _1));
+// client.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
+// bind(&EndToEndFixture::client_onConnect, this, _1));
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect");
+// BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect");
- BOOST_REQUIRE(static_cast<bool>(face1));
- face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
- face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
+// BOOST_REQUIRE(static_cast<bool>(face1));
+// face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
+// face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
- Block iHeader = interest1->getLocalControlHeader()
- .wireEncode(*interest1, ndn::nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
- ndn::nfd::LocalControlHeader::ENCODE_NEXT_HOP);
- Block iPayload = interest1->wireEncode();
+// Block iHeader = interest1->getLocalControlHeader()
+// .wireEncode(*interest1, ndn::nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+// ndn::nfd::LocalControlHeader::ENCODE_NEXT_HOP);
+// Block iPayload = interest1->wireEncode();
- Block dHeader = data1->getLocalControlHeader()
- .wireEncode(*data1, ndn::nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
- ndn::nfd::LocalControlHeader::ENCODE_NEXT_HOP);
- Block dPayload = data1->wireEncode();
+// Block dHeader = data1->getLocalControlHeader()
+// .wireEncode(*data1, ndn::nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+// ndn::nfd::LocalControlHeader::ENCODE_NEXT_HOP);
+// Block dPayload = data1->wireEncode();
- client.async_send(std::vector<boost::asio::const_buffer>{iHeader, iPayload},
- [] (const boost::system::error_code& error, size_t nBytesSent) {
- BOOST_CHECK_MESSAGE(!error, error.message());
- });
- client.async_send(std::vector<boost::asio::const_buffer>{dHeader, dPayload},
- [] (const boost::system::error_code& error, size_t nBytesSent) {
- BOOST_CHECK_MESSAGE(!error, error.message());
- });
+// client.async_send(std::vector<boost::asio::const_buffer>{iHeader, iPayload},
+// [] (const boost::system::error_code& error, size_t nBytesSent) {
+// BOOST_CHECK_MESSAGE(!error, error.message());
+// });
+// client.async_send(std::vector<boost::asio::const_buffer>{dHeader, dPayload},
+// [] (const boost::system::error_code& error, size_t nBytesSent) {
+// BOOST_CHECK_MESSAGE(!error, error.message());
+// });
- BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
- "Send/receive with LocalControlHeader");
+// BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
+// "Send/receive with LocalControlHeader");
- BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
- BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
+// BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
+// BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
- BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false);
- BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), true);
- BOOST_CHECK_EQUAL(face1_receivedInterests[0].getNextHopFaceId(), 111);
+// BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false);
+// BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), true);
+// BOOST_CHECK_EQUAL(face1_receivedInterests[0].getNextHopFaceId(), 111);
- BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false);
- BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false);
-}
+// BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false);
+// BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false);
+//}
-class SimpleEndToEndFixture : protected BaseFixture
-{
-public:
- void
- onFaceCreated(const shared_ptr<Face>& face)
- {
- face->onReceiveInterest.connect(bind(&SimpleEndToEndFixture::onReceiveInterest, this, _1));
- face->onReceiveData.connect(bind(&SimpleEndToEndFixture::onReceiveData, this, _1));
- face->onFail.connect(bind(&SimpleEndToEndFixture::onFail, this, face));
+//class SimpleEndToEndFixture : protected BaseFixture
+//{
+//public:
+// void
+// onFaceCreated(const shared_ptr<Face>& face)
+// {
+// face->onReceiveInterest.connect(bind(&SimpleEndToEndFixture::onReceiveInterest, this, _1));
+// face->onReceiveData.connect(bind(&SimpleEndToEndFixture::onReceiveData, this, _1));
+// face->onFail.connect(bind(&SimpleEndToEndFixture::onFail, this, face));
- if (static_cast<bool>(dynamic_pointer_cast<LocalFace>(face))) {
- static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature(
- LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
+// if (static_cast<bool>(dynamic_pointer_cast<LocalFace>(face))) {
+// static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature(
+// LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
- static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature(
- LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
- }
+// static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature(
+// LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
+// }
- limitedIo.afterOp();
- }
+// limitedIo.afterOp();
+// }
- void
- onConnectFailed(const std::string& reason)
- {
- BOOST_CHECK_MESSAGE(false, reason);
+// void
+// onConnectFailed(const std::string& reason)
+// {
+// BOOST_CHECK_MESSAGE(false, reason);
- limitedIo.afterOp();
- }
+// limitedIo.afterOp();
+// }
- void
- onReceiveInterest(const Interest& interest)
- {
- receivedInterests.push_back(interest);
+// void
+// onReceiveInterest(const Interest& interest)
+// {
+// receivedInterests.push_back(interest);
- limitedIo.afterOp();
- }
+// limitedIo.afterOp();
+// }
- void
- onReceiveData(const Data& data)
- {
- receivedDatas.push_back(data);
+// void
+// onReceiveData(const Data& data)
+// {
+// receivedDatas.push_back(data);
- limitedIo.afterOp();
- }
+// limitedIo.afterOp();
+// }
- void
- onFail(const shared_ptr<Face>& face)
- {
- limitedIo.afterOp();
- }
+// void
+// onFail(const shared_ptr<Face>& face)
+// {
+// limitedIo.afterOp();
+// }
-public:
- LimitedIo limitedIo;
+//public:
+// LimitedIo limitedIo;
- std::vector<Interest> receivedInterests;
- std::vector<Data> receivedDatas;
-};
+// std::vector<Interest> receivedInterests;
+// std::vector<Data> receivedDatas;
+//};
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(CorruptedInput, Dataset,
- CorruptedPackets, SimpleEndToEndFixture)
-{
- UnixStreamFactory factory;
+//BOOST_FIXTURE_TEST_CASE_TEMPLATE(CorruptedInput, Dataset,
+// CorruptedPackets, SimpleEndToEndFixture)
+//{
+// UnixStreamFactory factory;
- shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1);
- channel->listen(bind(&SimpleEndToEndFixture::onFaceCreated, this, _1),
- bind(&SimpleEndToEndFixture::onConnectFailed, this, _1));
+// shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1);
+// channel->listen(bind(&SimpleEndToEndFixture::onFaceCreated, this, _1),
+// bind(&SimpleEndToEndFixture::onConnectFailed, this, _1));
- DummyStreamSender<UnixStreamFace::protocol, Dataset> sender;
- sender.start(UnixStreamFace::protocol::endpoint(CHANNEL_PATH1));
+// DummyStreamSender<UnixStreamTransport::protocol, Dataset> sender;
+// sender.start(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1));
- BOOST_CHECK_MESSAGE(limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1)) == LimitedIo::EXCEED_TIME,
- "Exception thrown for " + Dataset::getName());
-}
+// BOOST_CHECK_MESSAGE(limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1)) == LimitedIo::EXCEED_TIME,
+// "Exception thrown for " + Dataset::getName());
+//}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestUnixStream
+BOOST_AUTO_TEST_SUITE_END() // Face
} // namespace tests
} // namespace nfd
diff --git a/tests/daemon/fw/access-strategy.t.cpp b/tests/daemon/fw/access-strategy.t.cpp
index ddc0092..fa211a6 100644
--- a/tests/daemon/fw/access-strategy.t.cpp
+++ b/tests/daemon/fw/access-strategy.t.cpp
@@ -47,7 +47,8 @@
// code style rule 3.25. This is necessary because some lines ends with '\' which
// would cause "multi-line comment" compiler warning if '//' comments are used.
-BOOST_FIXTURE_TEST_SUITE(FwAccessStrategy, UnitTestTimeFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestAccessStrategy, UnitTestTimeFixture)
class TwoLaptopsFixture : public UnitTestTimeFixture
{
@@ -65,14 +66,14 @@
* +---------+ +---------+
*/
- router = topo.addForwarder();
- laptopA = topo.addForwarder();
- laptopB = topo.addForwarder();
+ router = topo.addForwarder("R");
+ laptopA = topo.addForwarder("A");
+ laptopB = topo.addForwarder("B");
topo.setStrategy<fw::AccessStrategy>(router);
- linkA = topo.addLink(time::milliseconds(10), {router, laptopA});
- linkB = topo.addLink(time::milliseconds(20), {router, laptopB});
+ linkA = topo.addLink("RA", time::milliseconds(10), {router, laptopA});
+ linkB = topo.addLink("RB", time::milliseconds(20), {router, laptopB});
}
protected:
@@ -115,19 +116,19 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
topo.registerPrefix(router, linkB->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producer = topo.addAppFace(laptopA, "ndn:/laptops/A");
- topo.addEchoProducer(*producer->getClientFace());
+ shared_ptr<TopologyAppLink> producer = topo.addAppFace("p", laptopA, "ndn:/laptops/A");
+ topo.addEchoProducer(producer->getClientFace());
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(router);
- topo.addIntervalConsumer(*consumer->getClientFace(), "ndn:/laptops/A",
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", router);
+ topo.addIntervalConsumer(consumer->getClientFace(), "ndn:/laptops/A",
time::milliseconds(100), 100);
this->advanceClocks(time::milliseconds(5), time::seconds(12));
// most Interests should be satisfied, and few Interests can go to wrong laptop
- BOOST_CHECK_GE(consumer->getForwarderFace()->m_sentDatas.size(), 97);
- BOOST_CHECK_GE(linkA->getFace(router)->m_sentInterests.size(), 97);
- BOOST_CHECK_LE(linkB->getFace(router)->m_sentInterests.size(), 5);
+ BOOST_CHECK_GE(consumer->getForwarderFace().getCounters().getNOutDatas(), 97);
+ BOOST_CHECK_GE(linkA->getFace(router).getCounters().getNOutInterests(), 97);
+ BOOST_CHECK_LE(linkB->getFace(router).getCounters().getNOutInterests(), 5);
}
BOOST_FIXTURE_TEST_CASE(FastSlowProducer, TwoLaptopsFixture)
@@ -160,21 +161,21 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
topo.registerPrefix(router, linkB->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producerA = topo.addAppFace(laptopA, "ndn:/laptops/BOTH");
- topo.addEchoProducer(*producerA->getClientFace());
- shared_ptr<TopologyAppLink> producerB = topo.addAppFace(laptopB, "ndn:/laptops/BOTH");
- topo.addEchoProducer(*producerB->getClientFace());
+ shared_ptr<TopologyAppLink> producerA = topo.addAppFace("pA", laptopA, "ndn:/laptops/BOTH");
+ topo.addEchoProducer(producerA->getClientFace());
+ shared_ptr<TopologyAppLink> producerB = topo.addAppFace("pB", laptopB, "ndn:/laptops/BOTH");
+ topo.addEchoProducer(producerB->getClientFace());
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(router);
- topo.addIntervalConsumer(*consumer->getClientFace(), "ndn:/laptops/BOTH",
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", router);
+ topo.addIntervalConsumer(consumer->getClientFace(), "ndn:/laptops/BOTH",
time::milliseconds(100), 100);
this->advanceClocks(time::milliseconds(5), time::seconds(12));
// most Interests should be satisfied, and few Interests can go to slower laptopB
- BOOST_CHECK_GE(consumer->getForwarderFace()->m_sentDatas.size(), 97);
- BOOST_CHECK_GE(linkA->getFace(router)->m_sentInterests.size(), 90);
- BOOST_CHECK_LE(linkB->getFace(router)->m_sentInterests.size(), 15);
+ BOOST_CHECK_GE(consumer->getForwarderFace().getCounters().getNOutDatas(), 97);
+ BOOST_CHECK_GE(linkA->getFace(router).getCounters().getNOutInterests(), 90);
+ BOOST_CHECK_LE(linkB->getFace(router).getCounters().getNOutInterests(), 15);
}
BOOST_FIXTURE_TEST_CASE(ProducerMobility, TwoLaptopsFixture)
@@ -207,13 +208,13 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
topo.registerPrefix(router, linkB->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producerA = topo.addAppFace(laptopA, "ndn:/laptops/M");
- topo.addEchoProducer(*producerA->getClientFace());
- shared_ptr<TopologyAppLink> producerB = topo.addAppFace(laptopB, "ndn:/laptops/M");
- topo.addEchoProducer(*producerB->getClientFace());
+ shared_ptr<TopologyAppLink> producerA = topo.addAppFace("pA", laptopA, "ndn:/laptops/M");
+ topo.addEchoProducer(producerA->getClientFace());
+ shared_ptr<TopologyAppLink> producerB = topo.addAppFace("pB", laptopB, "ndn:/laptops/M");
+ topo.addEchoProducer(producerB->getClientFace());
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(router);
- topo.addIntervalConsumer(*consumer->getClientFace(), "ndn:/laptops/M",
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", router);
+ topo.addIntervalConsumer(consumer->getClientFace(), "ndn:/laptops/M",
time::milliseconds(100), 100);
// producer is initially on laptopA
@@ -221,19 +222,19 @@
this->advanceClocks(time::milliseconds(5), time::seconds(6));
// few Interests can go to laptopB
- BOOST_CHECK_LE(linkB->getFace(router)->m_sentInterests.size(), 5);
+ BOOST_CHECK_LE(linkB->getFace(router).getCounters().getNOutInterests(), 5);
// producer moves to laptopB
producerA->fail();
producerB->recover();
- linkA->getFace(router)->m_sentInterests.clear();
+ const_cast<FaceCounters&>(linkA->getFace(router).getCounters()).getNOutInterests().set(0);
this->advanceClocks(time::milliseconds(5), time::seconds(6));
// few additional Interests can go to laptopA
- BOOST_CHECK_LE(linkA->getFace(router)->m_sentInterests.size(), 5);
+ BOOST_CHECK_LE(linkA->getFace(router).getCounters().getNOutInterests(), 5);
// most Interests should be satisfied
- BOOST_CHECK_GE(consumer->getForwarderFace()->m_sentDatas.size(), 97);
+ BOOST_CHECK_GE(consumer->getForwarderFace().getCounters().getNOutDatas(), 97);
}
BOOST_FIXTURE_TEST_CASE(Bidirectional, TwoLaptopsFixture)
@@ -263,23 +264,23 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
topo.registerPrefix(router, linkB->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producerA = topo.addAppFace(laptopA, "ndn:/laptops/A");
- topo.addEchoProducer(*producerA->getClientFace());
- shared_ptr<TopologyAppLink> producerB = topo.addAppFace(laptopB, "ndn:/laptops/B");
- topo.addEchoProducer(*producerB->getClientFace());
+ shared_ptr<TopologyAppLink> producerA = topo.addAppFace("pA", laptopA, "ndn:/laptops/A");
+ topo.addEchoProducer(producerA->getClientFace());
+ shared_ptr<TopologyAppLink> producerB = topo.addAppFace("pB", laptopB, "ndn:/laptops/B");
+ topo.addEchoProducer(producerB->getClientFace());
- shared_ptr<TopologyAppLink> consumerAB = topo.addAppFace(laptopA);
- topo.addIntervalConsumer(*consumerAB->getClientFace(), "ndn:/laptops/B",
+ shared_ptr<TopologyAppLink> consumerAB = topo.addAppFace("cAB", laptopA);
+ topo.addIntervalConsumer(consumerAB->getClientFace(), "ndn:/laptops/B",
time::milliseconds(100), 100);
- shared_ptr<TopologyAppLink> consumerBA = topo.addAppFace(laptopB);
- topo.addIntervalConsumer(*consumerBA->getClientFace(), "ndn:/laptops/A",
+ shared_ptr<TopologyAppLink> consumerBA = topo.addAppFace("cBA", laptopB);
+ topo.addIntervalConsumer(consumerBA->getClientFace(), "ndn:/laptops/A",
time::milliseconds(100), 100);
this->advanceClocks(time::milliseconds(5), time::seconds(12));
// most Interests should be satisfied
- BOOST_CHECK_GE(consumerAB->getForwarderFace()->m_sentDatas.size(), 97);
- BOOST_CHECK_GE(consumerBA->getForwarderFace()->m_sentDatas.size(), 97);
+ BOOST_CHECK_GE(consumerAB->getForwarderFace().getCounters().getNOutDatas(), 97);
+ BOOST_CHECK_GE(consumerBA->getForwarderFace().getCounters().getNOutDatas(), 97);
}
BOOST_FIXTURE_TEST_CASE(PacketLoss, TwoLaptopsFixture)
@@ -308,25 +309,25 @@
// laptopA has prefix in router FIB; laptopB is unused in this test case
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producerA = topo.addAppFace(laptopA, "ndn:/laptops/A");
- topo.addEchoProducer(*producerA->getClientFace());
+ shared_ptr<TopologyAppLink> producerA = topo.addAppFace("pA", laptopA, "ndn:/laptops/A");
+ topo.addEchoProducer(producerA->getClientFace());
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(router);
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", router);
// Interest 1 completes normally
shared_ptr<Interest> interest1 = makeInterest("ndn:/laptops/A/1");
bool hasData1 = false;
- consumer->getClientFace()->expressInterest(*interest1,
- bind([&hasData1] { hasData1 = true; }));
+ consumer->getClientFace().expressInterest(*interest1,
+ bind([&hasData1] { hasData1 = true; }));
this->advanceClocks(time::milliseconds(5), time::seconds(1));
BOOST_CHECK_EQUAL(hasData1, true);
// Interest 2 experiences a packet loss on initial transmission
shared_ptr<Interest> interest2a = makeInterest("ndn:/laptops/A/2");
bool hasData2a = false, hasTimeout2a = false;
- consumer->getClientFace()->expressInterest(*interest2a,
- bind([&hasData2a] { hasData2a = true; }),
- bind([&hasTimeout2a] { hasTimeout2a = true; }));
+ consumer->getClientFace().expressInterest(*interest2a,
+ bind([&hasData2a] { hasData2a = true; }),
+ bind([&hasTimeout2a] { hasTimeout2a = true; }));
producerA->fail();
this->advanceClocks(time::milliseconds(5), time::milliseconds(60));
BOOST_CHECK_EQUAL(hasData2a, false);
@@ -335,8 +336,8 @@
// Interest 2 retransmission is suppressed
shared_ptr<Interest> interest2b = makeInterest("ndn:/laptops/A/2");
bool hasData2b = false;
- consumer->getClientFace()->expressInterest(*interest2b,
- bind([&hasData2b] { hasData2b = true; }));
+ consumer->getClientFace().expressInterest(*interest2b,
+ bind([&hasData2b] { hasData2b = true; }));
producerA->recover();
this->advanceClocks(time::milliseconds(5), time::seconds(1));
BOOST_CHECK_EQUAL(hasData2b, false);
@@ -344,8 +345,8 @@
// Interest 2 retransmission gets through, and is answered
shared_ptr<Interest> interest2c = makeInterest("ndn:/laptops/A/2");
bool hasData2c = false;
- consumer->getClientFace()->expressInterest(*interest2c,
- bind([&hasData2c] { hasData2c = true; }));
+ consumer->getClientFace().expressInterest(*interest2c,
+ bind([&hasData2c] { hasData2c = true; }));
this->advanceClocks(time::milliseconds(5), time::seconds(1));
BOOST_CHECK_EQUAL(hasData2c, true);
}
@@ -357,17 +358,18 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/net");
// send Interests from laptopA to router
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(laptopA);
- topo.addIntervalConsumer(*consumer->getClientFace(), "ndn:/net",
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", laptopA);
+ topo.addIntervalConsumer(consumer->getClientFace(), "ndn:/net",
time::milliseconds(100), 10);
this->advanceClocks(time::milliseconds(5), time::seconds(2));
// Interest shouldn't loop back from router
- BOOST_CHECK_EQUAL(linkA->getFace(router)->m_sentInterests.size(), 0);
+ BOOST_CHECK_EQUAL(linkA->getFace(router).getCounters().getNOutInterests(), 0);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestAccessStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/best-route-strategy2.t.cpp b/tests/daemon/fw/best-route-strategy2.t.cpp
index 8a2c3db..4ee43e9 100644
--- a/tests/daemon/fw/best-route-strategy2.t.cpp
+++ b/tests/daemon/fw/best-route-strategy2.t.cpp
@@ -24,10 +24,11 @@
*/
#include "fw/best-route-strategy2.hpp"
-#include "strategy-tester.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/face/dummy-face.hpp"
+#include "strategy-tester.hpp"
+#include "topology-tester.hpp"
namespace nfd {
namespace fw {
@@ -35,33 +36,51 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(FwBestRouteStrategy2, UnitTestTimeFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+
+class BestRouteStrategy2Fixture : public UnitTestTimeFixture
+{
+protected:
+ BestRouteStrategy2Fixture()
+ : strategy(forwarder)
+ , fib(forwarder.getFib())
+ , pit(forwarder.getPit())
+ , face1(make_shared<DummyFace>())
+ , face2(make_shared<DummyFace>())
+ , face3(make_shared<DummyFace>())
+ , face4(make_shared<DummyFace>())
+ , face5(make_shared<DummyFace>())
+ {
+ forwarder.addFace(face1);
+ forwarder.addFace(face2);
+ forwarder.addFace(face3);
+ forwarder.addFace(face4);
+ forwarder.addFace(face5);
+ }
+
+public:
+ Forwarder forwarder;
+ StrategyTester<fw::BestRouteStrategy2> strategy;
+ Fib& fib;
+ Pit& pit;
+
+ shared_ptr<DummyFace> face1;
+ shared_ptr<DummyFace> face2;
+ shared_ptr<DummyFace> face3;
+ shared_ptr<DummyFace> face4;
+ shared_ptr<DummyFace> face5;
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy2, BestRouteStrategy2Fixture)
BOOST_AUTO_TEST_CASE(Forward)
{
- Forwarder forwarder;
- typedef StrategyTester<fw::BestRouteStrategy2> BestRouteStrategy2Tester;
- BestRouteStrategy2Tester strategy(forwarder);
-
- shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face4 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face5 = make_shared<DummyFace>();
- forwarder.addFace(face1);
- forwarder.addFace(face2);
- forwarder.addFace(face3);
- forwarder.addFace(face4);
- forwarder.addFace(face5);
-
- Fib& fib = forwarder.getFib();
shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
fibEntry->addNextHop(face1, 10);
fibEntry->addNextHop(face2, 20);
fibEntry->addNextHop(face3, 30);
shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA");
- Pit& pit = forwarder.getPit();
shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>(
@@ -71,20 +90,20 @@
// however face1 is downstream so it cannot be used
pitEntry->insertOrUpdateInRecord(face1, *interest);
strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.back().get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory.back().outFaceId, face2->getId());
// downstream retransmits frequently, but the strategy should not send Interests
// more often than DEFAULT_MIN_RETX_INTERVAL
scheduler::EventId retxFrom4Evt;
- size_t nSentLast = strategy.m_sendInterestHistory.size();
+ size_t nSentLast = strategy.sendInterestHistory.size();
time::steady_clock::TimePoint timeSentLast = time::steady_clock::now();
function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself
periodicalRetxFrom4 = [&] {
pitEntry->insertOrUpdateInRecord(face4, *interest);
strategy.afterReceiveInterest(*face4, *interest, fibEntry, pitEntry);
- size_t nSent = strategy.m_sendInterestHistory.size();
+ size_t nSent = strategy.sendInterestHistory.size();
if (nSent > nSentLast) {
BOOST_CHECK_EQUAL(nSent - nSentLast, 1);
time::steady_clock::TimePoint timeSent = time::steady_clock::now();
@@ -101,29 +120,346 @@
// nexthops for accepted retransmissions: follow FIB cost,
// later forward to an eligible upstream with earliest OutRecord
- BOOST_REQUIRE_GE(strategy.m_sendInterestHistory.size(), 6);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[1].get<1>(), face1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[2].get<1>(), face3);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[3].get<1>(), face2);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[4].get<1>(), face1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[5].get<1>(), face3);
+ BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 6);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face3->getId());
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[3].outFaceId, face2->getId());
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[4].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[5].outFaceId, face3->getId());
fibEntry->removeNextHop(face1);
- strategy.m_sendInterestHistory.clear();
+ strategy.sendInterestHistory.clear();
for (int i = 0; i < 3; ++i) {
this->advanceClocks(TICK, fw::RetxSuppressionExponential::DEFAULT_MAX_INTERVAL * 2);
pitEntry->insertOrUpdateInRecord(face5, *interest);
strategy.afterReceiveInterest(*face5, *interest, fibEntry, pitEntry);
}
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 3);
- BOOST_CHECK_NE(strategy.m_sendInterestHistory[0].get<1>(), face1);
- BOOST_CHECK_NE(strategy.m_sendInterestHistory[1].get<1>(), face1);
- BOOST_CHECK_NE(strategy.m_sendInterestHistory[2].get<1>(), face1);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 3);
+ BOOST_CHECK_NE(strategy.sendInterestHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_NE(strategy.sendInterestHistory[1].outFaceId, face1->getId());
+ BOOST_CHECK_NE(strategy.sendInterestHistory[2].outFaceId, face1->getId());
// face1 cannot be used because it's gone from FIB entry
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE(NoRouteNack) // send Nack-NoRoute if there's no usable FIB nexthop
+
+class EmptyNextHopList
+{
+public:
+ Name
+ getInterestName()
+ {
+ return "/P";
+ }
+
+ shared_ptr<fib::Entry>
+ makeFibEntry(BestRouteStrategy2Fixture* fixture)
+ {
+ return fixture->fib.insert(Name()).first;
+ }
+};
+
+class NextHopIsDownstream
+{
+public:
+ Name
+ getInterestName()
+ {
+ return "/P";
+ }
+
+ shared_ptr<fib::Entry>
+ makeFibEntry(BestRouteStrategy2Fixture* fixture)
+ {
+ shared_ptr<fib::Entry> fibEntry = fixture->fib.insert(Name()).first;
+ fibEntry->addNextHop(fixture->face1, 10);
+ return fibEntry;
+ }
+};
+
+class NextHopViolatesScope
+{
+public:
+ Name
+ getInterestName()
+ {
+ return "/localhop/P";
+ }
+
+ shared_ptr<fib::Entry>
+ makeFibEntry(BestRouteStrategy2Fixture* fixture)
+ {
+ shared_ptr<fib::Entry> fibEntry = fixture->fib.insert("/localhop").first;
+ fibEntry->addNextHop(fixture->face2, 10);
+ // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
+ return fibEntry;
+ }
+};
+
+typedef boost::mpl::vector<EmptyNextHopList, NextHopIsDownstream, NextHopViolatesScope> NoRouteScenarios;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(IncomingInterest, Scenario, NoRouteScenarios)
+{
+ Scenario scenario;
+
+ shared_ptr<Interest> interest = makeInterest(scenario.getInterestName());
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest);
+
+ shared_ptr<fib::Entry> fibEntry = scenario.makeFibEntry(this);
+
+ strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory[0].pitEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // NoRouteNack
+
+BOOST_AUTO_TEST_SUITE(IncomingNack)
+
+BOOST_AUTO_TEST_CASE(OneUpstream) // one upstream, send Nack when Nack arrives
+{
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
+ fibEntry->addNextHop(face3, 10);
+ fibEntry->addNextHop(face4, 20);
+ fibEntry->addNextHop(face5, 30);
+
+ shared_ptr<Interest> interest1 = makeInterest("/McQYjMbm", 992);
+ shared_ptr<Interest> interest2 = makeInterest("/McQYjMbm", 114);
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest1);
+ pitEntry->insertOrUpdateInRecord(face2, *interest2);
+ pitEntry->insertOrUpdateOutRecord(face3, *interest1);
+
+ lp::Nack nack3 = makeNack("/McQYjMbm", 992, lp::NackReason::CONGESTION);
+ pitEntry->getOutRecord(*face3)->setIncomingNack(nack3);
+ strategy.afterReceiveNack(*face3, nack3, fibEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 2);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::CONGESTION);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[1].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[1].header.getReason(), lp::NackReason::CONGESTION);
+ std::unordered_set<FaceId> nackFaceIds{strategy.sendNackHistory[0].outFaceId,
+ strategy.sendNackHistory[1].outFaceId};
+ std::unordered_set<FaceId> expectedNackFaceIds{face1->getId(), face2->getId()};
+ BOOST_CHECK_EQUAL_COLLECTIONS(nackFaceIds.begin(), nackFaceIds.end(),
+ expectedNackFaceIds.begin(), expectedNackFaceIds.end());
+}
+
+BOOST_AUTO_TEST_CASE(TwoUpstreams) // two upstreams, send Nack when both Nacks arrive
+{
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
+ fibEntry->addNextHop(face3, 10);
+ fibEntry->addNextHop(face4, 20);
+ fibEntry->addNextHop(face5, 30);
+
+ shared_ptr<Interest> interest1 = makeInterest("/aS9FAyUV19", 286);
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face3, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face4, *interest1);
+
+ lp::Nack nack3 = makeNack("/aS9FAyUV19", 286, lp::NackReason::CONGESTION);
+ pitEntry->getOutRecord(*face3)->setIncomingNack(nack3);
+ strategy.afterReceiveNack(*face3, nack3, fibEntry, pitEntry);
+
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0); // don't send Nack until all upstreams have Nacked
+
+ lp::Nack nack4 = makeNack("/aS9FAyUV19", 286, lp::NackReason::CONGESTION);
+ pitEntry->getOutRecord(*face4)->setIncomingNack(nack4);
+ strategy.afterReceiveNack(*face4, nack4, fibEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::CONGESTION);
+}
+
+BOOST_AUTO_TEST_CASE(Timeout) // two upstreams, one times out, don't send Nack
+{
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
+ fibEntry->addNextHop(face3, 10);
+ fibEntry->addNextHop(face4, 20);
+ fibEntry->addNextHop(face5, 30);
+
+ shared_ptr<Interest> interest1 = makeInterest("/sIYw0TXWDj", 115);
+ interest1->setInterestLifetime(time::milliseconds(400));
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face3, *interest1);
+
+ this->advanceClocks(time::milliseconds(300));
+ shared_ptr<Interest> interest2 = makeInterest("/sIYw0TXWDj", 223);
+ pitEntry->insertOrUpdateInRecord(face1, *interest2);
+ pitEntry->insertOrUpdateOutRecord(face4, *interest2);
+
+ this->advanceClocks(time::milliseconds(200)); // face3 has timed out
+
+ lp::Nack nack4 = makeNack("/sIYw0TXWDj", 223, lp::NackReason::CONGESTION);
+ pitEntry->getOutRecord(*face4)->setIncomingNack(nack4);
+ strategy.afterReceiveNack(*face4, nack4, fibEntry, pitEntry);
+
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0);
+}
+
+BOOST_FIXTURE_TEST_CASE(LiveDeadlock, UnitTestTimeFixture) // #3033 note-7
+{
+ /*
+ * /----------\
+ * | producer |
+ * \----------/
+ * |
+ * +---+
+ * | P |
+ * +---+
+ * |
+ * failed link
+ * |
+ * +---+
+ * | R |
+ * +---+
+ * ^ ^
+ * / \
+ * / \
+ * +---+ +---+
+ * | B | <---> | C |
+ * +---+ +---+
+ * ^ ^
+ * | |
+ * | |
+ * +---+ +---+
+ * | A | | D |
+ * +---+ +---+
+ * ^ ^
+ * | |
+ * /----------\ /----------\
+ * | consumer | | consumer |
+ * \----------/ \----------/
+ */
+
+ TopologyTester topo;
+ TopologyNode nodeP = topo.addForwarder("P"),
+ nodeR = topo.addForwarder("R"),
+ nodeA = topo.addForwarder("A"),
+ nodeB = topo.addForwarder("B"),
+ nodeC = topo.addForwarder("C"),
+ nodeD = topo.addForwarder("D");
+
+ for (TopologyNode node : {nodeP, nodeR, nodeA, nodeB, nodeC, nodeD}) {
+ topo.setStrategy<BestRouteStrategy2>(node);
+ }
+
+ const time::milliseconds LINK_DELAY(10);
+ shared_ptr<TopologyLink> linkPR = topo.addLink("PR", LINK_DELAY, {nodeP, nodeR}),
+ linkRB = topo.addLink("RB", LINK_DELAY, {nodeR, nodeB}),
+ linkRC = topo.addLink("RC", LINK_DELAY, {nodeR, nodeC}),
+ linkBC = topo.addLink("BC", LINK_DELAY, {nodeB, nodeC}),
+ linkBA = topo.addLink("BA", LINK_DELAY, {nodeB, nodeA}),
+ linkCD = topo.addLink("CD", LINK_DELAY, {nodeC, nodeD});
+
+ // TODO register the prefix on R->P but then set the face DOWN
+ // topo.registerPrefix(nodeR, linkPR->getFace(nodeR), "ndn:/P", 10);
+ topo.registerPrefix(nodeB, linkRB->getFace(nodeB), "ndn:/P", 20);
+ topo.registerPrefix(nodeB, linkBC->getFace(nodeB), "ndn:/P", 30);
+ topo.registerPrefix(nodeC, linkRC->getFace(nodeC), "ndn:/P", 20);
+ topo.registerPrefix(nodeC, linkBC->getFace(nodeC), "ndn:/P", 30);
+ topo.registerPrefix(nodeA, linkBA->getFace(nodeA), "ndn:/P", 30);
+ topo.registerPrefix(nodeD, linkCD->getFace(nodeD), "ndn:/P", 30);
+
+ ndn::Face& appA = topo.addAppFace("A", nodeA)->getClientFace();
+ ndn::Face& appD = topo.addAppFace("D", nodeD)->getClientFace();
+
+ int nNacksA = 0, nNacksD = 0;
+ appA.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksA]{ ++nNacksA; }), bind([]{}));
+ appD.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksD]{ ++nNacksD; }), bind([]{}));
+ this->advanceClocks(time::milliseconds(1), time::milliseconds(5));
+ appA.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksA]{ ++nNacksA; }), bind([]{}));
+ appD.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksD]{ ++nNacksD; }), bind([]{}));
+ this->advanceClocks(time::milliseconds(1), time::milliseconds(100));
+
+ // As long as at least one Nack arrives at each client, strategy behavior is correct.
+ // Whether both Interests are Nacked is a client face behavior, not strategy behavior.
+ BOOST_CHECK_GT(nNacksA, 0);
+ BOOST_CHECK_GT(nNacksD, 0);
+}
+
+template<lp::NackReason X, lp::NackReason Y, lp::NackReason R>
+struct NackReasonCombination
+{
+ lp::NackReason
+ getX() const
+ {
+ return X;
+ }
+
+ lp::NackReason
+ getY() const
+ {
+ return Y;
+ }
+
+ lp::NackReason
+ getExpectedResult() const
+ {
+ return R;
+ }
+};
+
+typedef boost::mpl::vector<
+ NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::DUPLICATE, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::NO_ROUTE, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE>,
+ NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::NO_ROUTE, lp::NackReason::DUPLICATE>,
+ NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE>,
+ NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::NO_ROUTE, lp::NackReason::NO_ROUTE>
+ > NackReasonCombinations;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(CombineReasons, Combination, NackReasonCombinations)
+{
+ Combination combination;
+
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
+ fibEntry->addNextHop(face3, 10);
+ fibEntry->addNextHop(face4, 20);
+ fibEntry->addNextHop(face5, 30);
+
+ shared_ptr<Interest> interest1 = makeInterest("/F6sEwB24I", 282);
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face3, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face4, *interest1);
+
+ lp::Nack nack3 = makeNack("/F6sEwB24I", 282, combination.getX());
+ pitEntry->getOutRecord(*face3)->setIncomingNack(nack3);
+ strategy.afterReceiveNack(*face3, nack3, fibEntry, pitEntry);
+
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0);
+
+ lp::Nack nack4 = makeNack("/F6sEwB24I", 282, combination.getY());
+ pitEntry->getOutRecord(*face4)->setIncomingNack(nack4);
+ strategy.afterReceiveNack(*face4, nack4, fibEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), combination.getExpectedResult());
+}
+
+BOOST_AUTO_TEST_SUITE_END() // IncomingNack
+
+BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy2
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/client-control-strategy.t.cpp b/tests/daemon/fw/client-control-strategy.t.cpp
index ee3a362..189d42f 100644
--- a/tests/daemon/fw/client-control-strategy.t.cpp
+++ b/tests/daemon/fw/client-control-strategy.t.cpp
@@ -35,7 +35,8 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(FwClientControlStrategy, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestClientControlStrategy, BaseFixture)
BOOST_AUTO_TEST_CASE(Forward3)
{
@@ -65,20 +66,20 @@
shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
pitEntry1->insertOrUpdateInRecord(face4, *interest1);
- strategy.m_sendInterestHistory.clear();
+ strategy.sendInterestHistory.clear();
strategy.afterReceiveInterest(*face4, *interest1, fibEntry, pitEntry1);
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face1);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId());
// Interest without NextHopFaceId
shared_ptr<Interest> interest2 = makeInterest("ndn:/y6JQADGVz");
shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first;
pitEntry2->insertOrUpdateInRecord(face4, *interest2);
- strategy.m_sendInterestHistory.clear();
+ strategy.sendInterestHistory.clear();
strategy.afterReceiveInterest(*face4, *interest2, fibEntry, pitEntry2);
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face2->getId());
// Interest with invalid NextHopFaceId
shared_ptr<Interest> interest3 = makeInterest("ndn:/0z8r6yDDe");
@@ -87,14 +88,15 @@
pitEntry3->insertOrUpdateInRecord(face4, *interest3);
face3->close(); // face3 is closed and its FaceId becomes invalid
- strategy.m_sendInterestHistory.clear();
- strategy.m_rejectPendingInterestHistory.clear();
+ strategy.sendInterestHistory.clear();
+ strategy.rejectPendingInterestHistory.clear();
strategy.afterReceiveInterest(*face4, *interest3, fibEntry, pitEntry3);
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 0);
- BOOST_REQUIRE_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 0);
+ BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestClientControlStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/dummy-strategy.hpp b/tests/daemon/fw/dummy-strategy.hpp
index d078051..33d2656 100644
--- a/tests/daemon/fw/dummy-strategy.hpp
+++ b/tests/daemon/fw/dummy-strategy.hpp
@@ -33,7 +33,7 @@
/** \brief strategy for unit testing
*
- * Triggers on DummyStrategy are recorded but does nothing
+ * Unless otherwise indicated, triggers are recorded but does nothing.
*/
class DummyStrategy : public fw::Strategy
{
@@ -47,9 +47,13 @@
{
}
+ /** \brief after receive Interest trigger
+ *
+ * If \p interestOutFace is not null, send Interest action is invoked with that face;
+ * otherwise, reject pending Interest action is invoked.
+ */
virtual void
- afterReceiveInterest(const Face& inFace,
- const Interest& interest,
+ afterReceiveInterest(const Face& inFace, const Interest& interest,
shared_ptr<fib::Entry> fibEntry,
shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE
{
@@ -59,7 +63,7 @@
interest, fibEntry, pitEntry));
}
- if (static_cast<bool>(interestOutFace)) {
+ if (interestOutFace) {
this->sendInterest(pitEntry, interestOutFace);
}
else {
@@ -80,16 +84,25 @@
++beforeExpirePendingInterest_count;
}
+ virtual void
+ afterReceiveNack(const Face& inFace, const lp::Nack& nack,
+ shared_ptr<fib::Entry> fibEntry,
+ shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE
+ {
+ ++afterReceiveNack_count;
+ }
+
public:
int afterReceiveInterest_count;
bool wantAfterReceiveInterestCalls;
std::vector<std::tuple<FaceId, Interest, shared_ptr<fib::Entry>,
shared_ptr<pit::Entry>>> afterReceiveInterestCalls;
+ shared_ptr<Face> interestOutFace;
+
int beforeSatisfyInterest_count;
int beforeExpirePendingInterest_count;
+ int afterReceiveNack_count;
- /// outFace to use in afterReceiveInterest, nullptr to reject
- shared_ptr<Face> interestOutFace;
};
} // namespace tests
diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp
index d9d50d6..6a3509f 100644
--- a/tests/daemon/fw/forwarder.t.cpp
+++ b/tests/daemon/fw/forwarder.t.cpp
@@ -25,6 +25,8 @@
#include "fw/forwarder.hpp"
#include "tests/daemon/face/dummy-face.hpp"
+#include "tests/daemon/face/dummy-lp-face.hpp"
+#include "face/lp-face-wrapper.hpp"
#include "dummy-strategy.hpp"
#include "tests/test-common.hpp"
@@ -425,6 +427,225 @@
BOOST_CHECK_EQUAL(face4->m_sentDatas.size(), 1);
}
+BOOST_AUTO_TEST_CASE(IncomingNack)
+{
+ Forwarder forwarder;
+ auto face1 = make_shared<DummyFace>();
+ auto face2 = make_shared<DummyFace>();
+ auto face3 = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>(
+ "dummy://", "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS));
+ forwarder.addFace(face1);
+ forwarder.addFace(face2);
+ forwarder.addFace(face3);
+
+ StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
+ shared_ptr<DummyStrategy> strategyP = make_shared<DummyStrategy>(
+ ref(forwarder), "ndn:/strategyP");
+ shared_ptr<DummyStrategy> strategyQ = make_shared<DummyStrategy>(
+ ref(forwarder), "ndn:/strategyQ");
+ strategyChoice.install(strategyP);
+ strategyChoice.install(strategyQ);
+ strategyChoice.insert("ndn:/" , strategyP->getName());
+ strategyChoice.insert("ndn:/B", strategyQ->getName());
+
+ Pit& pit = forwarder.getPit();
+
+ // dispatch to the correct strategy
+ shared_ptr<Interest> interest1 = makeInterest("/A/AYJqayrzF", 562);
+ shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first;
+ pit1->insertOrUpdateOutRecord(face1, *interest1);
+ shared_ptr<Interest> interest2 = makeInterest("/B/EVyP73ru", 221);
+ shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first;
+ pit2->insertOrUpdateOutRecord(face1, *interest2);
+
+ lp::Nack nack1 = makeNack("/A/AYJqayrzF", 562, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face1, nack1);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 1);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+
+ lp::Nack nack2 = makeNack("/B/EVyP73ru", 221, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face1, nack2);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 1);
+
+ // record Nack on PIT out-record
+ pit::OutRecordCollection::const_iterator outRecord1 = pit1->getOutRecord(*face1);
+ BOOST_REQUIRE(outRecord1 != pit1->getOutRecords().end());
+ BOOST_REQUIRE(outRecord1->getIncomingNack() != nullptr);
+ BOOST_CHECK_EQUAL(outRecord1->getIncomingNack()->getReason(), lp::NackReason::CONGESTION);
+
+ // drop if no PIT entry
+ lp::Nack nack3 = makeNack("/yEcw5HhdM", 243, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face1, nack3);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+
+ // drop if no out-record
+ shared_ptr<Interest> interest4 = makeInterest("/Etab4KpY", 157);
+ shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first;
+ pit4->insertOrUpdateOutRecord(face1, *interest4);
+
+ lp::Nack nack4a = makeNack("/Etab4KpY", 157, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face2, nack4a);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+
+ // drop if Nonce does not match out-record
+ lp::Nack nack4b = makeNack("/Etab4KpY", 294, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face1, nack4b);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+
+ // drop if inFace is multi-access
+ pit4->insertOrUpdateOutRecord(face3, *interest4);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face3, nack4a);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+}
+
+BOOST_AUTO_TEST_CASE(OutgoingNack)
+{
+ Forwarder forwarder;
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+ auto face2w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face2 = static_cast<DummyLpFace*>(face2w->getLpFace());
+ auto face3w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>(
+ "dummy://", "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS));
+ auto face3 = static_cast<DummyLpFace*>(face3w->getLpFace());
+ forwarder.addFace(face1w);
+ forwarder.addFace(face2w);
+ forwarder.addFace(face3w);
+ // TODO#3172 eliminate wrapper
+
+ Pit& pit = forwarder.getPit();
+
+ lp::NackHeader nackHeader;
+ nackHeader.setReason(lp::NackReason::CONGESTION);
+
+ // don't send Nack if there's no in-record
+ shared_ptr<Interest> interest1 = makeInterest("/fM5IVEtC", 719);
+ shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first;
+ pit1->insertOrUpdateInRecord(face1w, *interest1);
+
+ face2->sentNacks.clear();
+ forwarder.onOutgoingNack(pit1, *face2w, nackHeader);
+ BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0);
+
+ // send Nack with correct Nonce
+ shared_ptr<Interest> interest2a = makeInterest("/Vi8tRm9MG3", 152);
+ shared_ptr<pit::Entry> pit2 = pit.insert(*interest2a).first;
+ pit2->insertOrUpdateInRecord(face1w, *interest2a);
+ shared_ptr<Interest> interest2b = makeInterest("/Vi8tRm9MG3", 808);
+ pit2->insertOrUpdateInRecord(face2w, *interest2b);
+
+ face1->sentNacks.clear();
+ forwarder.onOutgoingNack(pit2, *face1w, nackHeader);
+ BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::CONGESTION);
+ BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest().getNonce(), 152);
+
+ // erase in-record
+ pit::InRecordCollection::const_iterator inRecord2a = pit2->getInRecord(*face1w);
+ BOOST_CHECK(inRecord2a == pit2->getInRecords().end());
+
+ // send Nack with correct Nonce
+ face2->sentNacks.clear();
+ forwarder.onOutgoingNack(pit2, *face2w, nackHeader);
+ BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1);
+ BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::CONGESTION);
+ BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest().getNonce(), 808);
+
+ // erase in-record
+ pit::InRecordCollection::const_iterator inRecord2b = pit2->getInRecord(*face1w);
+ BOOST_CHECK(inRecord2b == pit2->getInRecords().end());
+
+ // don't send Nack to multi-access face
+ shared_ptr<Interest> interest2c = makeInterest("/Vi8tRm9MG3", 228);
+ pit2->insertOrUpdateInRecord(face3w, *interest2c);
+
+ face3->sentNacks.clear();
+ forwarder.onOutgoingNack(pit1, *face3w, nackHeader);
+ BOOST_CHECK_EQUAL(face3->sentNacks.size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(InterestLoopNack)
+{
+ Forwarder forwarder;
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+ auto face2w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face2 = static_cast<DummyLpFace*>(face2w->getLpFace());
+ auto face3w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>(
+ "dummy://", "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS));
+ auto face3 = static_cast<DummyLpFace*>(face3w->getLpFace());
+ auto face4 = make_shared<DummyFace>();
+ forwarder.addFace(face1w);
+ forwarder.addFace(face2w);
+ forwarder.addFace(face3w);
+ forwarder.addFace(face4);
+ // TODO#3172 eliminate wrapper
+
+ Fib& fib = forwarder.getFib();
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name("/zT4XwK0Hnx")).first;
+ fibEntry->addNextHop(face4, 0);
+
+ // receive Interest on face1
+ face1->sentNacks.clear();
+ shared_ptr<Interest> interest1a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732);
+ face1->receiveInterest(*interest1a);
+ BOOST_CHECK(face1->sentNacks.empty());
+
+ // receive Interest with duplicate Nonce on face1
+ face1->sentNacks.clear();
+ shared_ptr<Interest> interest1b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732);
+ face1->receiveInterest(*interest1b);
+ BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest(), *interest1b);
+ BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::DUPLICATE);
+
+ // receive Interest with duplicate Nonce on face2
+ face2->sentNacks.clear();
+ shared_ptr<Interest> interest2a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732);
+ face2->receiveInterest(*interest2a);
+ BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1);
+ BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest(), *interest2a);
+ BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::DUPLICATE);
+
+ // receive Interest with new Nonce on face2
+ face2->sentNacks.clear();
+ shared_ptr<Interest> interest2b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 944);
+ face2->receiveInterest(*interest2b);
+ BOOST_CHECK(face2->sentNacks.empty());
+
+ // receive Interest with duplicate Nonce on face3, don't send Nack to multi-access face
+ face3->sentNacks.clear();
+ shared_ptr<Interest> interest3a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732);
+ face3->receiveInterest(*interest3a);
+ BOOST_CHECK(face3->sentNacks.empty());
+}
+
BOOST_FIXTURE_TEST_CASE(InterestLoopWithShortLifetime, UnitTestTimeFixture) // Bug 1953
{
Forwarder forwarder;
diff --git a/tests/daemon/fw/multicast-strategy.t.cpp b/tests/daemon/fw/multicast-strategy.t.cpp
index c67c408..3476cd3 100644
--- a/tests/daemon/fw/multicast-strategy.t.cpp
+++ b/tests/daemon/fw/multicast-strategy.t.cpp
@@ -35,7 +35,8 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(FwMulticastStrategy, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, BaseFixture)
BOOST_AUTO_TEST_CASE(Forward2)
{
@@ -62,21 +63,17 @@
pitEntry->insertOrUpdateInRecord(face3, *interest);
strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry);
- BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2);
- bool hasFace1 = false;
- bool hasFace2 = false;
- for (std::vector<MulticastStrategyTester::SendInterestArgs>::iterator it =
- strategy.m_sendInterestHistory.begin();
- it != strategy.m_sendInterestHistory.end(); ++it) {
- if (it->get<1>() == face1) {
- hasFace1 = true;
- }
- if (it->get<1>() == face2) {
- hasFace2 = true;
- }
- }
- BOOST_CHECK(hasFace1 && hasFace2);
+ BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2);
+ std::set<FaceId> sentInterestFaceIds;
+ std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(),
+ std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()),
+ [] (const MulticastStrategyTester::SendInterestArgs& args) {
+ return args.outFaceId;
+ });
+ std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()};
+ BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(),
+ expectedInterestFaceIds.begin(), expectedInterestFaceIds.end());
}
BOOST_AUTO_TEST_CASE(RejectScope)
@@ -100,8 +97,8 @@
pitEntry->insertOrUpdateInRecord(face1, *interest);
strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
- BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
+ BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
}
BOOST_AUTO_TEST_CASE(RejectLoopback)
@@ -123,11 +120,12 @@
pitEntry->insertOrUpdateInRecord(face1, *interest);
strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
- BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
+ BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/ncc-strategy.t.cpp b/tests/daemon/fw/ncc-strategy.t.cpp
index a10fc47..889b2e2 100644
--- a/tests/daemon/fw/ncc-strategy.t.cpp
+++ b/tests/daemon/fw/ncc-strategy.t.cpp
@@ -36,7 +36,8 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(FwNccStrategy, UnitTestTimeFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestNccStrategy, UnitTestTimeFixture)
// NccStrategy is fairly complex.
// The most important property is:
@@ -48,7 +49,7 @@
Forwarder forwarder;
typedef StrategyTester<fw::NccStrategy> NccStrategyTester;
shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
- strategy->onAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
+ strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -79,13 +80,13 @@
// forwards to face1 because routing says it's best
// (no io run here: afterReceiveInterest has already sent the Interest)
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face1);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId());
// forwards to face2 because face1 doesn't respond
limitedIo.run(1, time::milliseconds(500), time::milliseconds(10));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 2);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[1].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId());
// face2 responds
shared_ptr<Data> data1p = makeData("ndn:/0Jm1ajrW/%00");
@@ -104,8 +105,8 @@
// forwards to face2 because it responds previously
this->advanceClocks(time::milliseconds(1));
- BOOST_REQUIRE_GE(strategy->m_sendInterestHistory.size(), 3);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[2].get<1>(), face2);
+ BOOST_REQUIRE_GE(strategy->sendInterestHistory.size(), 3);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[2].outFaceId, face2->getId());
}
BOOST_AUTO_TEST_CASE(Bug1853)
@@ -140,8 +141,8 @@
strategy->afterReceiveInterest(*face3, *interest1, fibEntry, pitEntry1);
this->advanceClocks(time::milliseconds(1));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face1);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId());
// face1 responds
shared_ptr<Data> data1 = makeData("ndn:/nztwIvHX/%00");
@@ -168,7 +169,7 @@
Forwarder forwarder;
typedef StrategyTester<fw::NccStrategy> NccStrategyTester;
shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
- strategy->onAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
+ strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -195,11 +196,11 @@
pitEntry1->insertOrUpdateInRecord(face3, *interest1);
strategy->afterReceiveInterest(*face3, *interest1, fibEntry, pitEntry1);
- limitedIo.run(2 - strategy->m_sendInterestHistory.size(),
+ limitedIo.run(2 - strategy->sendInterestHistory.size(),
time::milliseconds(2000), time::milliseconds(10));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 2);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[1].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId());
// face1 responds
shared_ptr<Data> data1 = makeData("ndn:/seRMz5a6/%00");
@@ -217,11 +218,11 @@
pitEntry2->insertOrUpdateInRecord(face3, *interest2);
strategy->afterReceiveInterest(*face3, *interest2, fibEntry, pitEntry2);
- limitedIo.run(3 - strategy->m_sendInterestHistory.size(),
+ limitedIo.run(3 - strategy->sendInterestHistory.size(),
time::milliseconds(2000), time::milliseconds(10));
- BOOST_REQUIRE_GE(strategy->m_sendInterestHistory.size(), 3);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[2].get<1>(), face1);
+ BOOST_REQUIRE_GE(strategy->sendInterestHistory.size(), 3);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[2].outFaceId, face1->getId());
}
BOOST_AUTO_TEST_CASE(Bug1971)
@@ -230,7 +231,7 @@
Forwarder forwarder;
typedef StrategyTester<fw::NccStrategy> NccStrategyTester;
shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
- strategy->onAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
+ strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -254,10 +255,10 @@
pitEntry1->insertOrUpdateInRecord(face1, *interest1);
strategy->afterReceiveInterest(*face1, *interest1, fibEntry, pitEntry1);
- limitedIo.run(1 - strategy->m_sendInterestHistory.size(),
+ limitedIo.run(1 - strategy->sendInterestHistory.size(),
time::milliseconds(2000), time::milliseconds(10));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face2->getId());
// face2 responds
shared_ptr<Data> data1 = makeData("ndn:/M4mBXCsd");
@@ -270,10 +271,10 @@
// similar Interest: strategy should still forward it
pitEntry1->insertOrUpdateInRecord(face1, *interest1);
strategy->afterReceiveInterest(*face1, *interest1, fibEntry, pitEntry1);
- limitedIo.run(2 - strategy->m_sendInterestHistory.size(),
+ limitedIo.run(2 - strategy->sendInterestHistory.size(),
time::milliseconds(2000), time::milliseconds(10));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 2);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[1].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId());
}
BOOST_AUTO_TEST_CASE(Bug1998)
@@ -306,11 +307,12 @@
strategy->afterReceiveInterest(*face1, *interest1, fibEntry, pitEntry1);
// Interest shall go to face2, not loop back to face1
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face2->getId());
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestNccStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/retx-suppression.t.cpp b/tests/daemon/fw/retx-suppression.t.cpp
index 2d1b146..266f168 100644
--- a/tests/daemon/fw/retx-suppression.t.cpp
+++ b/tests/daemon/fw/retx-suppression.t.cpp
@@ -26,7 +26,6 @@
#include "fw/retx-suppression.hpp"
#include "fw/retx-suppression-fixed.hpp"
#include "fw/retx-suppression-exponential.hpp"
-#include "strategy-tester.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/face/dummy-face.hpp"
diff --git a/tests/daemon/fw/strategy-tester.hpp b/tests/daemon/fw/strategy-tester.hpp
index 9cf4855..26c29c1 100644
--- a/tests/daemon/fw/strategy-tester.hpp
+++ b/tests/daemon/fw/strategy-tester.hpp
@@ -33,8 +33,7 @@
namespace fw {
namespace tests {
-/** \class StrategyTester
- * \brief extends strategy S for unit testing
+/** \brief extends strategy S for unit testing
*
* Actions invoked by S are recorded but not passed to forwarder
*/
@@ -49,7 +48,7 @@
}
/// fires after each Action
- signal::Signal<StrategyTester<S>> onAction;
+ signal::Signal<StrategyTester<S>> afterAction;
protected:
virtual void
@@ -60,12 +59,32 @@
virtual void
rejectPendingInterest(shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE;
-public:
- typedef boost::tuple<shared_ptr<pit::Entry>, shared_ptr<Face>> SendInterestArgs;
- std::vector<SendInterestArgs> m_sendInterestHistory;
+ virtual void
+ sendNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
+ const lp::NackHeader& header) DECL_OVERRIDE;
- typedef boost::tuple<shared_ptr<pit::Entry>> RejectPendingInterestArgs;
- std::vector<RejectPendingInterestArgs> m_rejectPendingInterestHistory;
+public:
+ struct SendInterestArgs
+ {
+ shared_ptr<pit::Entry> pitEntry;
+ FaceId outFaceId;
+ bool wantNewNonce;
+ };
+ std::vector<SendInterestArgs> sendInterestHistory;
+
+ struct RejectPendingInterestArgs
+ {
+ shared_ptr<pit::Entry> pitEntry;
+ };
+ std::vector<RejectPendingInterestArgs> rejectPendingInterestHistory;
+
+ struct SendNackArgs
+ {
+ shared_ptr<pit::Entry> pitEntry;
+ FaceId outFaceId;
+ lp::NackHeader header;
+ };
+ std::vector<SendNackArgs> sendNackHistory;
};
@@ -75,17 +94,30 @@
shared_ptr<Face> outFace,
bool wantNewNonce)
{
- m_sendInterestHistory.push_back(SendInterestArgs(pitEntry, outFace));
+ SendInterestArgs args{pitEntry, outFace->getId()};
+ sendInterestHistory.push_back(args);
pitEntry->insertOrUpdateOutRecord(outFace, pitEntry->getInterest());
- onAction();
+ afterAction();
}
template<typename S>
inline void
StrategyTester<S>::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry)
{
- m_rejectPendingInterestHistory.push_back(RejectPendingInterestArgs(pitEntry));
- onAction();
+ RejectPendingInterestArgs args{pitEntry};
+ rejectPendingInterestHistory.push_back(args);
+ afterAction();
+}
+
+template<typename S>
+inline void
+StrategyTester<S>::sendNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
+ const lp::NackHeader& header)
+{
+ SendNackArgs args{pitEntry, outFace.getId(), header};
+ sendNackHistory.push_back(args);
+ pitEntry->deleteInRecord(outFace);
+ afterAction();
}
} // namespace tests
diff --git a/tests/daemon/fw/topology-tester.cpp b/tests/daemon/fw/topology-tester.cpp
new file mode 100644
index 0000000..10a0b31
--- /dev/null
+++ b/tests/daemon/fw/topology-tester.cpp
@@ -0,0 +1,260 @@
+/* -*- 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 "topology-tester.hpp"
+#include <ndn-cxx/encoding/encoding-buffer-fwd.hpp>
+#include "face/generic-link-service.hpp"
+
+namespace nfd {
+namespace fw {
+namespace tests {
+
+using face::LpFaceWrapper;
+
+TopologyForwarderTransport::TopologyForwarderTransport(
+ const FaceUri& localUri, const FaceUri& remoteUri,
+ ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType)
+{
+ this->setLocalUri(localUri);
+ this->setRemoteUri(remoteUri);
+ this->setScope(scope);
+ this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+ this->setLinkType(linkType);
+}
+
+void
+TopologyForwarderTransport::receiveFromTopology(const Block& packet)
+{
+ Packet p;
+ p.packet = packet;
+ this->receive(std::move(p));
+}
+
+void
+TopologyForwarderTransport::doSend(Packet&& packet)
+{
+ this->emitSignal(afterSend, packet.packet);
+}
+
+void
+TopologyClientTransport::receiveFromTopology(const Block& packet)
+{
+ if (m_receiveCallback) {
+ m_receiveCallback(packet);
+ }
+}
+
+void
+TopologyClientTransport::send(const Block& wire)
+{
+ this->emitSignal(afterSend, wire);
+}
+
+void
+TopologyClientTransport::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());
+}
+
+TopologyLinkBase::TopologyLinkBase()
+ : m_isUp(true)
+{
+}
+
+void
+TopologyLinkBase::attachTransport(TopologyNode i, TopologyTransportBase* transport)
+{
+ BOOST_ASSERT(transport != nullptr);
+ BOOST_ASSERT(m_transports.count(i) == 0);
+
+ m_transports[i] = transport;
+ transport->afterSend.connect([this, i] (const Block& packet) { this->transmit(i, packet); });
+}
+
+void
+TopologyLinkBase::transmit(TopologyNode i, const Block& packet)
+{
+ if (!m_isUp) {
+ return;
+ }
+
+ for (auto&& p : m_transports) {
+ if (p.first == i) {
+ continue;
+ }
+
+ TopologyTransportBase* recipient = p.second;
+ this->scheduleReceive(recipient, packet);
+ }
+}
+
+TopologyLink::TopologyLink(const time::nanoseconds& delay)
+ : m_delay(delay)
+{
+ BOOST_ASSERT(delay > time::nanoseconds::zero());
+ // zero delay does not work on OSX
+}
+
+void
+TopologyLink::addFace(TopologyNode i, shared_ptr<LpFaceWrapper> face)
+{
+ this->attachTransport(i, dynamic_cast<TopologyTransportBase*>(face->getLpFace()->getTransport()));
+ m_faces[i] = face;
+}
+
+void
+TopologyLink::scheduleReceive(TopologyTransportBase* recipient, const Block& packet)
+{
+ scheduler::schedule(m_delay, [packet, recipient] {
+ recipient->receiveFromTopology(packet);
+ });
+}
+
+TopologyAppLink::TopologyAppLink(shared_ptr<LpFaceWrapper> face)
+ : m_face(face)
+{
+ this->attachTransport(0, dynamic_cast<TopologyTransportBase*>(face->getLpFace()->getTransport()));
+
+ auto clientTransport = make_shared<TopologyClientTransport>();
+ m_client = make_shared<ndn::Face>(clientTransport, getGlobalIoService());
+ this->attachTransport(1, clientTransport.get());
+}
+
+void
+TopologyAppLink::scheduleReceive(TopologyTransportBase* recipient, const Block& packet)
+{
+ getGlobalIoService().post([packet, recipient] {
+ recipient->receiveFromTopology(packet);
+ });
+}
+
+TopologyNode
+TopologyTester::addForwarder(const std::string& label)
+{
+ size_t i = m_forwarders.size();
+ m_forwarders.push_back(std::move(make_unique<Forwarder>()));
+ m_forwarderLabels.push_back(label);
+ BOOST_ASSERT(m_forwarders.size() == m_forwarderLabels.size());
+ return i;
+}
+
+shared_ptr<TopologyLink>
+TopologyTester::addLink(const std::string& label, const time::nanoseconds& delay,
+ std::initializer_list<TopologyNode> forwarders,
+ bool forceMultiAccessFace)
+{
+ auto link = make_shared<TopologyLink>(delay);
+ FaceUri remoteUri("topology://link/" + label);
+ ndn::nfd::LinkType linkType = (forceMultiAccessFace || forwarders.size() > 2) ?
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS :
+ ndn::nfd::LINK_TYPE_POINT_TO_POINT;
+
+ for (TopologyNode i : forwarders) {
+ Forwarder& forwarder = this->getForwarder(i);
+ FaceUri localUri("topology://" + m_forwarderLabels.at(i) + "/" + label);
+
+ auto service = make_unique<face::GenericLinkService>();
+ auto transport = make_unique<TopologyForwarderTransport>(localUri, remoteUri,
+ ndn::nfd::FACE_SCOPE_NON_LOCAL, linkType);
+ auto face = make_unique<LpFace>(std::move(service), std::move(transport));
+ auto faceW = make_shared<LpFaceWrapper>(std::move(face));
+
+ forwarder.addFace(faceW);
+ link->addFace(i, faceW);
+ }
+
+ m_links.push_back(link); // keep a shared_ptr so callers don't have to
+ return link;
+}
+
+shared_ptr<TopologyAppLink>
+TopologyTester::addAppFace(const std::string& label, TopologyNode i)
+{
+ Forwarder& forwarder = this->getForwarder(i);
+ FaceUri localUri("topology://" + m_forwarderLabels.at(i) + "/local/" + label);
+ FaceUri remoteUri("topology://" + m_forwarderLabels.at(i) + "/app/" + label);
+
+ auto service = make_unique<face::GenericLinkService>();
+ auto transport = make_unique<TopologyForwarderTransport>(localUri, remoteUri,
+ ndn::nfd::FACE_SCOPE_LOCAL, ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+ auto face = make_unique<LpFace>(std::move(service), std::move(transport));
+ auto faceW = make_shared<LpFaceWrapper>(std::move(face));
+
+ forwarder.addFace(faceW);
+
+ auto al = make_shared<TopologyAppLink>(faceW);
+ m_appLinks.push_back(al); // keep a shared_ptr so callers don't have to
+ return al;
+}
+
+shared_ptr<TopologyAppLink>
+TopologyTester::addAppFace(const std::string& label, TopologyNode i, const Name& prefix, uint64_t cost)
+{
+ shared_ptr<TopologyAppLink> al = this->addAppFace(label, i);
+ this->registerPrefix(i, al->getForwarderFace(), prefix, cost);
+ return al;
+}
+
+void
+TopologyTester::registerPrefix(TopologyNode i, const Face& face, const Name& prefix, uint64_t cost)
+{
+ Forwarder& forwarder = this->getForwarder(i);
+ Fib& fib = forwarder.getFib();
+ shared_ptr<fib::Entry> fibEntry = fib.insert(prefix).first;
+ fibEntry->addNextHop(const_cast<Face&>(face).shared_from_this(), cost);
+}
+
+void
+TopologyTester::addEchoProducer(ndn::Face& face, const Name& prefix)
+{
+ face.setInterestFilter(prefix,
+ [&face] (const ndn::InterestFilter&, const Interest& interest) {
+ shared_ptr<Data> data = makeData(interest.getName());
+ face.put(*data);
+ });
+}
+
+void
+TopologyTester::addIntervalConsumer(ndn::Face& face, const Name& prefix,
+ const time::nanoseconds& interval, size_t n)
+{
+ Name name(prefix);
+ name.appendTimestamp();
+ shared_ptr<Interest> interest = makeInterest(name);
+ face.expressInterest(*interest, bind([]{}));
+
+ if (n > 1) {
+ scheduler::schedule(interval, bind(&TopologyTester::addIntervalConsumer, this,
+ ref(face), prefix, interval, n - 1));
+ }
+}
+
+} // namespace tests
+} // namespace fw
+} // namespace nfd
diff --git a/tests/daemon/fw/topology-tester.hpp b/tests/daemon/fw/topology-tester.hpp
index 406c6b1..dd6d77d 100644
--- a/tests/daemon/fw/topology-tester.hpp
+++ b/tests/daemon/fw/topology-tester.hpp
@@ -30,19 +30,86 @@
#ifndef NFD_TESTS_NFD_FW_TOPOLOGY_TESTER_HPP
#define NFD_TESTS_NFD_FW_TOPOLOGY_TESTER_HPP
-#include <unordered_map>
-#include <ndn-cxx/util/dummy-client-face.hpp>
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/transport/transport.hpp>
+#include "face/lp-face-wrapper.hpp"
#include "fw/strategy.hpp"
#include "tests/test-common.hpp"
-#include "../face/dummy-face.hpp"
namespace nfd {
namespace fw {
namespace tests {
-using ndn::util::DummyClientFace;
using namespace nfd::tests;
+/** \brief abstracts a Transport used in TopologyTester
+ */
+class TopologyTransportBase
+{
+public:
+ /** \brief causes the transport to receive a link-layer packet
+ */
+ virtual void
+ receiveFromTopology(const Block& packet) = 0;
+
+ signal::Signal<TopologyTransportBase, Block> afterSend;
+
+protected:
+ DECLARE_SIGNAL_EMIT(afterSend)
+};
+
+/** \brief implements a forwarder-side Transport used in TopologyTester
+ */
+class TopologyForwarderTransport : public face::Transport, public TopologyTransportBase
+{
+public:
+ TopologyForwarderTransport(const FaceUri& localUri, const FaceUri& remoteUri,
+ ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType);
+
+ virtual void
+ receiveFromTopology(const Block& packet) DECL_OVERRIDE;
+
+protected:
+ virtual void
+ doClose() DECL_OVERRIDE
+ {
+ }
+
+private:
+ virtual void
+ doSend(Packet&& packet) DECL_OVERRIDE;
+};
+
+/** \brief implements a client-side Transport used in TopologyTester
+ */
+class TopologyClientTransport : public ndn::Transport, public TopologyTransportBase
+{
+public:
+ virtual void
+ receiveFromTopology(const Block& packet) DECL_OVERRIDE;
+
+ virtual void
+ close() DECL_OVERRIDE
+ {
+ }
+
+ virtual void
+ pause() DECL_OVERRIDE
+ {
+ }
+
+ virtual void
+ resume() DECL_OVERRIDE
+ {
+ }
+
+ virtual void
+ send(const Block& wire) DECL_OVERRIDE;
+
+ virtual void
+ send(const Block& header, const Block& payload) DECL_OVERRIDE;
+};
+
/** \brief identifies a node (forwarder) in the topology
*/
typedef size_t TopologyNode;
@@ -52,10 +119,7 @@
class TopologyLinkBase : noncopyable
{
public:
- TopologyLinkBase()
- : m_isUp(true)
- {
- }
+ TopologyLinkBase();
/** \brief fail the link, cause packets to be dropped silently
*/
@@ -74,7 +138,21 @@
}
protected:
+ /** \brief attach a Transport onto this link
+ */
+ void
+ attachTransport(TopologyNode i, TopologyTransportBase* transport);
+
+private:
+ void
+ transmit(TopologyNode i, const Block& packet);
+
+ virtual void
+ scheduleReceive(TopologyTransportBase* recipient, const Block& packet) = 0;
+
+protected:
bool m_isUp;
+ std::unordered_map<TopologyNode, TopologyTransportBase*> m_transports;
};
/** \brief represents a network link in the topology which connects two or more nodes
@@ -82,90 +160,27 @@
class TopologyLink : public TopologyLinkBase
{
public:
+ explicit
+ TopologyLink(const time::nanoseconds& delay);
+
+ void
+ addFace(TopologyNode i, shared_ptr<face::LpFaceWrapper> face);
+
/** \return a face of forwarder \p i which is attached to this link
*/
- shared_ptr<DummyFace>
+ Face&
getFace(TopologyNode i)
{
- return m_faces.at(i)->face;
+ return *m_faces.at(i);
}
private:
- explicit
- TopologyLink(const time::nanoseconds& delay)
- : m_delay(delay)
- {
- BOOST_ASSERT(delay >= time::nanoseconds::zero());
- }
-
- struct LinkFace
- {
- shared_ptr<DummyFace> face;
- };
-
- void
- addFace(TopologyNode i, shared_ptr<DummyFace> face)
- {
- BOOST_ASSERT(m_faces.count(i) == 0);
-
- LinkFace* lf = new LinkFace();
- lf->face = face;
- face->onSendInterest.connect(bind(&TopologyLink::transmitInterest, this, i, _1));
- face->onSendData.connect(bind(&TopologyLink::transmitData, this, i, _1));
-
- m_faces[i].reset(lf);
- }
-
- friend class TopologyTester;
-
-private:
- void
- transmitInterest(TopologyNode i, const Interest& interest)
- {
- if (!m_isUp) {
- return;
- }
-
- // Interest object cannot be shared between faces because
- // Forwarder can set different IncomingFaceId.
- Block wire = interest.wireEncode();
- for (auto&& p : m_faces) {
- if (p.first == i) {
- continue;
- }
- shared_ptr<DummyFace> face = p.second->face;
- scheduler::schedule(m_delay, [wire, face] {
- auto interest = make_shared<Interest>(wire);
- face->receiveInterest(*interest);
- });
- }
- }
-
- void
- transmitData(TopologyNode i, const Data& data)
- {
- if (!m_isUp) {
- return;
- }
-
- // Data object cannot be shared between faces because
- // Forwarder can set different IncomingFaceId.
- Block wire = data.wireEncode();
- for (auto&& p : m_faces) {
- if (p.first == i) {
- continue;
- }
- shared_ptr<DummyFace> face = p.second->face;
- scheduler::schedule(m_delay, [wire, face] {
- auto data = make_shared<Data>(wire);
- face->receiveData(*data);
- });
- }
- }
+ virtual void
+ scheduleReceive(TopologyTransportBase* recipient, const Block& packet) DECL_OVERRIDE;
private:
time::nanoseconds m_delay;
- std::unordered_map<TopologyNode, unique_ptr<LinkFace>> m_faces;
+ std::unordered_map<TopologyNode, shared_ptr<face::LpFaceWrapper>> m_faces;
};
/** \brief represents a link to a local application
@@ -173,66 +188,32 @@
class TopologyAppLink : public TopologyLinkBase
{
public:
+ explicit
+ TopologyAppLink(shared_ptr<face::LpFaceWrapper> face);
+
/** \return face on forwarder side
*/
- shared_ptr<DummyLocalFace>
+ Face&
getForwarderFace()
{
- return m_face;
+ return *m_face;
}
/** \return face on application side
*/
- shared_ptr<DummyClientFace>
+ ndn::Face&
getClientFace()
{
- return m_client;
+ return *m_client;
}
private:
- explicit
- TopologyAppLink(shared_ptr<DummyLocalFace> face)
- : m_face(face)
- , m_client(ndn::util::makeDummyClientFace(getGlobalIoService(), {false, false}))
- {
- m_client->onSendInterest.connect([this] (const Interest& interest) {
- if (!m_isUp) {
- return;
- }
- auto interest2 = interest.shared_from_this();
- getGlobalIoService().post([=] { m_face->receiveInterest(*interest2); });
- });
-
- m_client->onSendData.connect([this] (const Data& data) {
- if (!m_isUp) {
- return;
- }
- auto data2 = data.shared_from_this();
- getGlobalIoService().post([=] { m_face->receiveData(*data2); });
- });
-
- m_face->onSendInterest.connect([this] (const Interest& interest) {
- if (!m_isUp) {
- return;
- }
- auto interest2 = interest.shared_from_this();
- getGlobalIoService().post([=] { m_client->receive(*interest2); });
- });
-
- m_face->onSendData.connect([this] (const Data& data) {
- if (!m_isUp) {
- return;
- }
- auto data2 = data.shared_from_this();
- getGlobalIoService().post([=] { m_client->receive(*data2); });
- });
- }
-
- friend class TopologyTester;
+ virtual void
+ scheduleReceive(TopologyTransportBase* recipient, const Block& packet) DECL_OVERRIDE;
private:
- shared_ptr<DummyLocalFace> m_face;
- shared_ptr<DummyClientFace> m_client;
+ shared_ptr<face::LpFaceWrapper> m_face;
+ shared_ptr<ndn::Face> m_client;
};
/** \brief builds a topology for forwarding tests
@@ -244,12 +225,7 @@
* \return index of new forwarder
*/
TopologyNode
- addForwarder()
- {
- size_t i = m_forwarders.size();
- m_forwarders.push_back(make_unique<Forwarder>());
- return i;
- }
+ addForwarder(const std::string& label);
/** \return forwarder instance \p i
*/
@@ -281,85 +257,42 @@
* this packet will be received by all other faces on this link after \p delay .
*/
shared_ptr<TopologyLink>
- addLink(const time::nanoseconds& delay, std::initializer_list<TopologyNode> forwarders)
- {
- auto link = shared_ptr<TopologyLink>(new TopologyLink(delay));
- for (TopologyNode i : forwarders) {
- Forwarder& forwarder = this->getForwarder(i);
- shared_ptr<DummyFace> face = make_shared<DummyFace>();
- forwarder.addFace(face);
- link->addFace(i, face);
- }
- return link;
- }
+ addLink(const std::string& label, const time::nanoseconds& delay,
+ std::initializer_list<TopologyNode> forwarders,
+ bool forceMultiAccessFace = false);
/** \brief makes a link to local application
*/
shared_ptr<TopologyAppLink>
- addAppFace(TopologyNode i)
- {
- Forwarder& forwarder = this->getForwarder(i);
- auto face = make_shared<DummyLocalFace>();
- forwarder.addFace(face);
-
- return shared_ptr<TopologyAppLink>(new TopologyAppLink(face));
- }
+ addAppFace(const std::string& label, TopologyNode i);
/** \brief makes a link to local application, and register a prefix
*/
shared_ptr<TopologyAppLink>
- addAppFace(TopologyNode i, const Name& prefix, uint64_t cost = 0)
- {
- shared_ptr<TopologyAppLink> al = this->addAppFace(i);
- this->registerPrefix(i, al->getForwarderFace(), prefix, cost);
- return al;
- }
+ addAppFace(const std::string& label, TopologyNode i, const Name& prefix, uint64_t cost = 0);
- /** \brief registers a prefix on a face
- * \tparam F either DummyFace or DummyLocalFace
+ /** \brief registers a prefix on a forwarder face
*/
- template<typename F>
void
- registerPrefix(TopologyNode i, shared_ptr<F> face, const Name& prefix, uint64_t cost = 0)
- {
- Forwarder& forwarder = this->getForwarder(i);
- Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(prefix).first;
- fibEntry->addNextHop(face, cost);
- }
+ registerPrefix(TopologyNode i, const Face& face, const Name& prefix, uint64_t cost = 0);
/** \brief creates a producer application that answers every Interest with Data of same Name
*/
void
- addEchoProducer(DummyClientFace& face, const Name& prefix = "/")
- {
- face.setInterestFilter(prefix,
- [&face] (const ndn::InterestFilter&, const Interest& interest) {
- shared_ptr<Data> data = makeData(interest.getName());
- face.put(*data);
- });
- }
+ addEchoProducer(ndn::Face& face, const Name& prefix = "/");
/** \brief creates a consumer application that sends \p n Interests under \p prefix
* at \p interval fixed rate.
*/
void
- addIntervalConsumer(DummyClientFace& face, const Name& prefix,
- const time::nanoseconds& interval, size_t n)
- {
- Name name(prefix);
- name.appendTimestamp();
- shared_ptr<Interest> interest = makeInterest(name);
- face.expressInterest(*interest, bind([]{}));
-
- if (n > 1) {
- scheduler::schedule(interval, bind(&TopologyTester::addIntervalConsumer, this,
- ref(face), prefix, interval, n - 1));
- }
- }
+ addIntervalConsumer(ndn::Face& face, const Name& prefix,
+ const time::nanoseconds& interval, size_t n);
private:
std::vector<unique_ptr<Forwarder>> m_forwarders;
+ std::vector<std::string> m_forwarderLabels;
+ std::vector<shared_ptr<TopologyLink>> m_links;
+ std::vector<shared_ptr<TopologyAppLink>> m_appLinks;
};
} // namespace tests
diff --git a/tests/daemon/mgmt/face-manager-process-config.t.cpp b/tests/daemon/mgmt/face-manager-process-config.t.cpp
index 9463ac4..5dedb91 100644
--- a/tests/daemon/mgmt/face-manager-process-config.t.cpp
+++ b/tests/daemon/mgmt/face-manager-process-config.t.cpp
@@ -279,8 +279,6 @@
BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
}
-
-
BOOST_AUTO_TEST_CASE(ProcessSectionUdpUnknownOption)
{
const std::string CONFIG =
@@ -295,7 +293,6 @@
BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
}
-
BOOST_AUTO_TEST_CASE(ProcessSectionUdpMulticastReinit)
{
const std::string CONFIG_WITH_MCAST =
@@ -317,7 +314,6 @@
"no UDP multicast faces are available");
return;
}
- BOOST_CHECK_GT(factory->getMulticastFaces().size(), 0);
const std::string CONFIG_WITHOUT_MCAST =
"face_system\n"
@@ -328,6 +324,7 @@
" }\n"
"}\n";
BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
+ BOOST_REQUIRE_NO_THROW(g_io.poll());
BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
}
diff --git a/tests/daemon/table/pit.t.cpp b/tests/daemon/table/pit.t.cpp
index 7bd89fc..dd02bec 100644
--- a/tests/daemon/table/pit.t.cpp
+++ b/tests/daemon/table/pit.t.cpp
@@ -34,9 +34,12 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(TablePit, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Table)
+BOOST_FIXTURE_TEST_SUITE(TestPit, BaseFixture)
-BOOST_AUTO_TEST_CASE(EntryInOutRecords)
+BOOST_AUTO_TEST_SUITE(PitEntry)
+
+BOOST_AUTO_TEST_CASE(InOutRecords)
{
shared_ptr<Face> face1 = make_shared<DummyFace>();
shared_ptr<Face> face2 = make_shared<DummyFace>();
@@ -151,7 +154,7 @@
BOOST_CHECK(entry.getOutRecord(*face2) == entry.getOutRecords().end());
}
-BOOST_AUTO_TEST_CASE(EntryNonce)
+BOOST_AUTO_TEST_CASE(Nonce)
{
shared_ptr<Face> face1 = make_shared<DummyFace>();
shared_ptr<Face> face2 = make_shared<DummyFace>();
@@ -210,7 +213,7 @@
BOOST_CHECK_EQUAL(entry5.findNonce(19004, *face2), pit::DUPLICATE_NONCE_NONE);
}
-BOOST_AUTO_TEST_CASE(EntryLifetime)
+BOOST_AUTO_TEST_CASE(Lifetime)
{
shared_ptr<Interest> interest = makeInterest("ndn:/7oIEurbgy6");
// library uses -1 to indicate unset lifetime
@@ -226,7 +229,7 @@
BOOST_CHECK_GT(outIt->getExpiry(), time::steady_clock::now());
}
-BOOST_AUTO_TEST_CASE(EntryCanForwardTo)
+BOOST_AUTO_TEST_CASE(CanForwardTo)
{
shared_ptr<Interest> interest = makeInterest("ndn:/WDsuBLIMG");
pit::Entry entry(*interest);
@@ -247,6 +250,37 @@
BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true);
}
+BOOST_AUTO_TEST_CASE(OutRecordNack)
+{
+ shared_ptr<Face> face1 = make_shared<DummyFace>();
+ pit::OutRecord outR(face1);
+ BOOST_CHECK(outR.getIncomingNack() == nullptr);
+
+ shared_ptr<Interest> interest1 = makeInterest("ndn:/uWiapGjYL");
+ interest1->setNonce(165);
+ outR.update(*interest1);
+ BOOST_CHECK(outR.getIncomingNack() == nullptr);
+
+ shared_ptr<Interest> interest2 = makeInterest("ndn:/uWiapGjYL");
+ interest2->setNonce(996);
+ lp::Nack nack2(*interest2);
+ nack2.setReason(lp::NackReason::CONGESTION);
+ BOOST_CHECK_EQUAL(outR.setIncomingNack(nack2), false);
+ BOOST_CHECK(outR.getIncomingNack() == nullptr);
+
+ lp::Nack nack1(*interest1);
+ nack1.setReason(lp::NackReason::DUPLICATE);
+ BOOST_CHECK_EQUAL(outR.setIncomingNack(nack1), true);
+ BOOST_REQUIRE(outR.getIncomingNack() != nullptr);
+ BOOST_CHECK_EQUAL(outR.getIncomingNack()->getReason(), lp::NackReason::DUPLICATE);
+
+ outR.clearIncomingNack();
+ BOOST_CHECK(outR.getIncomingNack() == nullptr);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // PitEntry
+
+
BOOST_AUTO_TEST_CASE(Insert)
{
Name name1("ndn:/5vzBNnMst");
@@ -368,18 +402,21 @@
insertResult = pit.insert(*interest);
BOOST_CHECK_EQUAL(insertResult.second, true);
BOOST_CHECK_EQUAL(pit.size(), 1);
+ BOOST_CHECK(pit.find(*interest) != nullptr);
insertResult = pit.insert(*interest);
BOOST_CHECK_EQUAL(insertResult.second, false);
BOOST_CHECK_EQUAL(pit.size(), 1);
+ BOOST_CHECK(pit.find(*interest) != nullptr);
pit.erase(insertResult.first);
BOOST_CHECK_EQUAL(pit.size(), 0);
+ BOOST_CHECK(pit.find(*interest) == nullptr);
insertResult = pit.insert(*interest);
BOOST_CHECK_EQUAL(insertResult.second, true);
BOOST_CHECK_EQUAL(pit.size(), 1);
-
+ BOOST_CHECK(pit.find(*interest) != nullptr);
}
BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
@@ -496,6 +533,7 @@
}
BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
} // namespace pit
diff --git a/tests/identity-management-fixture.hpp b/tests/identity-management-fixture.hpp
index 265c3bc..9774363 100644
--- a/tests/identity-management-fixture.hpp
+++ b/tests/identity-management-fixture.hpp
@@ -19,6 +19,9 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
+#ifndef NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
+#define NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
+
#include "tests/test-common.hpp"
#include <ndn-cxx/security/key-chain.hpp>
#include <vector>
@@ -35,7 +38,7 @@
* Identities added via addIdentity method are automatically deleted
* during test teardown.
*/
-class IdentityManagementFixture : public nfd::tests::BaseFixture
+class IdentityManagementFixture : public virtual BaseFixture
{
public:
IdentityManagementFixture();
@@ -54,3 +57,5 @@
} // namespace tests
} // namespace nfd
+
+#endif // NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
index 784ee2d..f5a309a 100644
--- a/tests/test-common.hpp
+++ b/tests/test-common.hpp
@@ -1,12 +1,12 @@
/* -*- 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
+ * 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.
@@ -62,7 +62,7 @@
/** \brief a base test fixture that overrides steady clock and system clock
*/
-class UnitTestTimeFixture : public BaseFixture
+class UnitTestTimeFixture : public virtual BaseFixture
{
protected:
UnitTestTimeFixture()
@@ -135,9 +135,13 @@
};
inline shared_ptr<Interest>
-makeInterest(const Name& name)
+makeInterest(const Name& name, uint32_t nonce = 0)
{
- return make_shared<Interest>(name);
+ auto interest = make_shared<Interest>(name);
+ if (nonce != 0) {
+ interest->setNonce(nonce);
+ }
+ return interest;
}
inline shared_ptr<Data>
@@ -166,6 +170,16 @@
return link;
}
+inline lp::Nack
+makeNack(const Name& name, uint32_t nonce, lp::NackReason reason)
+{
+ Interest interest(name);
+ interest.setNonce(nonce);
+ lp::Nack nack(std::move(interest));
+ nack.setReason(reason);
+ return nack;
+}
+
} // namespace tests
} // namespace nfd