diff --git a/daemon/face/channel.cpp b/daemon/face/channel.cpp index d161504d..65e0a25d 100644 --- a/daemon/face/channel.cpp +++ b/daemon/face/channel.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 . - **/ + */ #include "channel.hpp" @@ -36,4 +37,17 @@ Channel::setUri(const FaceUri& uri) m_uri = uri; } +void +connectFaceClosedSignal(Face& face, const std::function& f) +{ + using face::FaceState; + + face.afterStateChange.connect( + [f] (FaceState oldState, FaceState newState) { + if (newState == FaceState::CLOSED) { + f(); + } + }); +} + } // namespace nfd diff --git a/daemon/face/channel.hpp b/daemon/face/channel.hpp index cb5ed270..640395ab 100644 --- a/daemon/face/channel.hpp +++ b/daemon/face/channel.hpp @@ -26,12 +26,10 @@ #ifndef NFD_DAEMON_FACE_CHANNEL_HPP #define NFD_DAEMON_FACE_CHANNEL_HPP -#include "common.hpp" +#include "face.hpp" namespace nfd { -class Face; - /** * \brief Prototype for the callback that is invoked when the face * is created (as a response to incoming connection or after @@ -69,6 +67,16 @@ Channel::getUri() const return m_uri; } +/** \brief invokes a callback when the face is closed + * \param face the face + * \param f the callback to be invoked when the face enters CLOSED state + * + * This function connects a callback to the afterStateChange signal on the \p face, + * and invokes \p f when the state becomes CLOSED. + */ +void +connectFaceClosedSignal(Face& face, const std::function& f); + } // namespace nfd #endif // NFD_DAEMON_FACE_CHANNEL_HPP diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp index 35925307..dd9d034c 100644 --- a/daemon/face/ethernet-factory.cpp +++ b/daemon/face/ethernet-factory.cpp @@ -26,12 +26,10 @@ #include "ethernet-factory.hpp" #include "ethernet-transport.hpp" #include "generic-link-service.hpp" -#include "lp-face-wrapper.hpp" -#include "core/global-io.hpp" namespace nfd { -shared_ptr +shared_ptr EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& interface, const ethernet::Address& address) { @@ -48,14 +46,11 @@ EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& interface, auto linkService = make_unique(opts); auto transport = make_unique(interface, address); - auto lpFace = make_unique(std::move(linkService), std::move(transport)); - face = make_shared(std::move(lpFace)); + face = make_shared(std::move(linkService), std::move(transport)); auto key = std::make_pair(interface.name, address); - face->onFail.connectSingleShot([this, key] (const std::string& reason) { - m_multicastFaces.erase(key); - }); m_multicastFaces[key] = face; + connectFaceClosedSignal(*face, [this, key] { m_multicastFaces.erase(key); }); return face; } @@ -75,7 +70,7 @@ EthernetFactory::getChannels() const return {}; } -shared_ptr +shared_ptr EthernetFactory::findMulticastFace(const std::string& interfaceName, const ethernet::Address& address) const { diff --git a/daemon/face/ethernet-factory.hpp b/daemon/face/ethernet-factory.hpp index c0a951d7..add176ee 100644 --- a/daemon/face/ethernet-factory.hpp +++ b/daemon/face/ethernet-factory.hpp @@ -31,10 +31,6 @@ namespace nfd { -namespace face { -class LpFaceWrapper; -} // namespace face - class EthernetFactory : public ProtocolFactory { public: @@ -52,7 +48,7 @@ public: }; typedef std::map, - shared_ptr> MulticastFaceMap; + shared_ptr> MulticastFaceMap; /** * \brief Create an EthernetFace to communicate with the given multicast group @@ -69,7 +65,7 @@ public: * * \throws EthernetFactory::Error or EthernetTransport::Error */ - shared_ptr + shared_ptr createMulticastFace(const NetworkInterfaceInfo& interface, const ethernet::Address& address); @@ -96,7 +92,7 @@ private: * \returns shared pointer to the existing EthernetFace object * or nullptr when such face does not exist */ - shared_ptr + shared_ptr findMulticastFace(const std::string& interfaceName, const ethernet::Address& address) const; diff --git a/daemon/face/face-counters.cpp b/daemon/face/face-counters.cpp index 611b151e..7c4dee48 100644 --- a/daemon/face/face-counters.cpp +++ b/daemon/face/face-counters.cpp @@ -24,7 +24,6 @@ */ #include "face-counters.hpp" -#include "old-face-counters.hpp" namespace nfd { namespace face { @@ -46,24 +45,5 @@ FaceCounters::FaceCounters(const LinkService::Counters& linkServiceCounters, { } -static const LinkService::Counters g_dummyLinkServiceCounters{}; -static const Transport::Counters g_dummyTransportCounters{}; - -FaceCounters::FaceCounters(const OldFaceCounters& oldCounters) - : nInInterests(oldCounters.getNInInterests()) - , nOutInterests(oldCounters.getNOutInterests()) - , nInData(oldCounters.getNInDatas()) - , nOutData(oldCounters.getNOutDatas()) - , nInNacks(g_dummyLinkServiceCounters.nInNacks) - , nOutNacks(g_dummyLinkServiceCounters.nOutNacks) - , nInPackets(g_dummyTransportCounters.nInPackets) - , nOutPackets(g_dummyTransportCounters.nOutPackets) - , nInBytes(oldCounters.getNInBytes()) - , nOutBytes(oldCounters.getNOutBytes()) - , m_linkServiceCounters(g_dummyLinkServiceCounters) - , m_transportCounters(g_dummyTransportCounters) -{ -} - } // namespace face } // namespace nfd diff --git a/daemon/face/face-counters.hpp b/daemon/face/face-counters.hpp index 93aebf4e..08facf84 100644 --- a/daemon/face/face-counters.hpp +++ b/daemon/face/face-counters.hpp @@ -30,9 +30,6 @@ #include "transport.hpp" namespace nfd { - -class OldFaceCounters; - namespace face { /** \brief gives access to counters provided by Face @@ -48,14 +45,6 @@ public: FaceCounters(const LinkService::Counters& linkServiceCounters, const Transport::Counters& transportCounters); - /** \brief wraps old counters - * - * FaceCounters instance created from this constructor only provides Interest/Data counters - * and Nack counters. Other counters are always zero. get() should not be used. - */ - explicit - FaceCounters(const OldFaceCounters& oldCounters); - /** \return counters provided by LinkService * \tparam T LinkService counters type * \throw std::bad_cast counters type mismatch diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp index 5367d39b..69d32c1a 100644 --- a/daemon/face/face.cpp +++ b/daemon/face/face.cpp @@ -25,73 +25,31 @@ #include "face.hpp" -#include - namespace nfd { +namespace face { -Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal, bool isMultiAccess) - : m_id(INVALID_FACEID) - , m_countersWrapper(m_counters) - , m_remoteUri(remoteUri) - , m_localUri(localUri) - , m_isLocal(isLocal) - , m_persistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) - , m_isMultiAccess(isMultiAccess) - , m_isFailed(false) +Face::Face(unique_ptr service, unique_ptr 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)) + , m_counters(m_service->getCounters(), m_transport->getCounters()) { - onReceiveInterest.connect([this] (const ndn::Interest&) { ++m_counters.getNInInterests(); }); - onReceiveData .connect([this] (const ndn::Data&) { ++m_counters.getNInDatas(); }); - onSendInterest .connect([this] (const ndn::Interest&) { ++m_counters.getNOutInterests(); }); - onSendData .connect([this] (const ndn::Data&) { ++m_counters.getNOutDatas(); }); + m_service->setFaceAndTransport(*this, *m_transport); + m_transport->setFaceAndLinkService(*this, *m_service); } -Face::~Face() +std::ostream& +operator<<(std::ostream& os, const FaceLogHelper& flh) { + const Face& face = flh.obj; + os << "[id=" << face.getId() << ",local=" << face.getLocalUri() << + ",remote=" << face.getRemoteUri() << "] "; + return os; } -bool -Face::isUp() const -{ - return true; -} - -bool -Face::decodeAndDispatchInput(const Block& element) -{ - try { - /// \todo Ensure lazy field decoding process - - if (element.type() == tlv::Interest) - { - shared_ptr i = make_shared(); - i->wireDecode(element); - this->onReceiveInterest(*i); - } - else if (element.type() == tlv::Data) - { - shared_ptr d = make_shared(); - d->wireDecode(element); - this->onReceiveData(*d); - } - else - return false; - - return true; - } - catch (const tlv::Error&) { - return false; - } -} - -void -Face::fail(const std::string& reason) -{ - if (m_isFailed) { - return; - } - - m_isFailed = true; - this->onFail(reason); -} - +} // namespace face } // namespace nfd diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp index d964ef15..d783dd01 100644 --- a/daemon/face/face.hpp +++ b/daemon/face/face.hpp @@ -23,27 +23,23 @@ * NFD, e.g., in COPYING.md file. If not, see . */ -#ifndef NFD_DAEMON_FACE_FACE_HPP -#define NFD_DAEMON_FACE_FACE_HPP +#ifndef NFD_DAEMON_FACE_HPP +#define NFD_DAEMON_FACE_HPP -#include "common.hpp" -#include "core/logger.hpp" +#include "transport.hpp" +#include "link-service.hpp" #include "face-counters.hpp" -#include "old-face-counters.hpp" #include "face-log.hpp" -#include - namespace nfd { +namespace face { -/** \class FaceId - * \brief identifies a face +/** \brief identifies a face */ -typedef int FaceId; +typedef uint64_t FaceId; /// indicates an invalid FaceId -const FaceId INVALID_FACEID = -1; - +const FaceId INVALID_FACEID = 0; /// identifies the InternalFace used in management const FaceId FACEID_INTERNAL_FACE = 1; /// identifies a packet comes from the ContentStore @@ -53,169 +49,169 @@ const FaceId FACEID_NULL = 255; /// upper bound of reserved FaceIds const FaceId FACEID_RESERVED_MAX = 255; - -/** \brief represents a face +/** \brief indicates the state of a face */ -class Face : noncopyable, public enable_shared_from_this +typedef TransportState FaceState; + +/** \brief generalization of a network interface + * + * A face generalizes a network interface. + * It provides best-effort network-layer packet delivery services + * on a physical interface, an overlay tunnel, or a link to a local application. + * + * A face combines two parts: LinkService and Transport. + * Transport is the lower part, which provides best-effort TLV block deliveries. + * LinkService is the upper part, which translates between network-layer packets + * and TLV blocks, and may provide additional services such as fragmentation and reassembly. + */ +class Face +#ifndef WITH_TESTS +DECL_CLASS_FINAL +#endif + : public enable_shared_from_this, noncopyable { public: - /** - * \brief Face-related error + Face(unique_ptr service, unique_ptr transport); + + LinkService* + getLinkService(); + + Transport* + getTransport(); + +public: // upper interface connected to forwarding + /** \brief sends Interest on Face */ - class Error : public std::runtime_error - { - public: - explicit - Error(const std::string& what) - : std::runtime_error(what) - { - } - }; + void + sendInterest(const Interest& interest); - Face(const FaceUri& remoteUri, const FaceUri& localUri, - bool isLocal = false, bool isMultiAccess = false); - - virtual - ~Face(); - - /// fires when an Interest is received - signal::Signal onReceiveInterest; - - /// fires when a Data is received - signal::Signal onReceiveData; - - /// fires when a Nack is received - signal::Signal onReceiveNack; - - /// fires when an Interest is sent out - signal::Signal onSendInterest; - - /// fires when a Data is sent out - signal::Signal onSendData; - - /// fires when a Nack is sent out - signal::Signal onSendNack; - - /// fires when face disconnects or fails to perform properly - signal::Signal onFail; - - /// send an Interest - virtual void - sendInterest(const Interest& interest) = 0; - - /// send a Data - 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 - * onFail() method event to be invoked + /** \brief sends Data on Face */ - virtual void - close() = 0; + void + sendData(const Data& data); -public: // attributes + /** \brief sends Nack on Face + */ + void + sendNack(const lp::Nack& nack); + + /** \brief signals on Interest received + */ + signal::Signal& afterReceiveInterest; + + /** \brief signals on Data received + */ + signal::Signal& afterReceiveData; + + /** \brief signals on Nack received + */ + signal::Signal& afterReceiveNack; + +public: // static properties + /** \return face ID + */ FaceId getId() const; - /** \brief Get the description - */ - const std::string& - getDescription() const; - - /** \brief Set the face description - * - * This is typically invoked by management on set description command + /** \brief sets face ID + * \note Normally, this should only be invoked by FaceTable. */ void - setDescription(const std::string& description); + setId(FaceId id); - /** \brief Get whether face is connected to a local app + /** \return a FaceUri representing local endpoint */ - bool - isLocal() const; + FaceUri + getLocalUri() const; - /** \brief Get the persistency setting + /** \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; - // '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 - isMultiAccess() const; - - /** \brief Get whether underlying communication is up - * - * In this base class this property is always true. - */ - virtual bool - isUp() const; - - virtual const face::FaceCounters& - getCounters() const; - - /** \return a FaceUri that represents the remote endpoint - */ - const FaceUri& - getRemoteUri() const; - - /** \return a FaceUri that represents the local endpoint (NFD side) - */ - const FaceUri& - getLocalUri() const; - -protected: - bool - decodeAndDispatchInput(const Block& element); - - /** \brief fail the face and raise onFail event if it's UP; otherwise do nothing + /** \brief changes face persistency setting */ void - fail(const std::string& reason); + setPersistency(ndn::nfd::FacePersistency persistency); - OldFaceCounters& - getMutableCounters(); + /** \return whether face is point-to-point or multi-access + */ + ndn::nfd::LinkType + getLinkType() const; - DECLARE_SIGNAL_EMIT(onReceiveInterest) - DECLARE_SIGNAL_EMIT(onReceiveData) - DECLARE_SIGNAL_EMIT(onReceiveNack) - DECLARE_SIGNAL_EMIT(onSendInterest) - DECLARE_SIGNAL_EMIT(onSendData) - DECLARE_SIGNAL_EMIT(onSendNack) +public: // dynamic properties + /** \return face state + */ + FaceState + getState() const; - // this method should be used only by the FaceTable - // 'virtual' to allow override in LpFaceWrapper - virtual void - setId(FaceId faceId); + /** \brief signals after face state changed + */ + signal::Signal& 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; private: FaceId m_id; - std::string m_description; - OldFaceCounters m_counters; - face::FaceCounters m_countersWrapper; - const FaceUri m_remoteUri; - const FaceUri m_localUri; - const bool m_isLocal; - ndn::nfd::FacePersistency m_persistency; - const bool m_isMultiAccess; - bool m_isFailed; - - // allow setting FaceId - friend class FaceTable; + unique_ptr m_service; + unique_ptr m_transport; + FaceCounters m_counters; }; +inline LinkService* +Face::getLinkService() +{ + return m_service.get(); +} + +inline Transport* +Face::getTransport() +{ + return m_transport.get(); +} + +inline void +Face::sendInterest(const Interest& interest) +{ + m_service->sendInterest(interest); +} + +inline void +Face::sendData(const Data& data) +{ + m_service->sendData(data); +} + +inline void +Face::sendNack(const lp::Nack& nack) +{ + m_service->sendNack(nack); +} + inline FaceId Face::getId() const { @@ -223,81 +219,80 @@ Face::getId() const } inline void -Face::setId(FaceId faceId) +Face::setId(FaceId id) { - m_id = faceId; + m_id = id; } -inline const std::string& -Face::getDescription() const +inline FaceUri +Face::getLocalUri() const { - return m_description; + return m_transport->getLocalUri(); } -inline void -Face::setDescription(const std::string& description) +inline FaceUri +Face::getRemoteUri() const { - m_description = description; + return m_transport->getRemoteUri(); } -inline bool -Face::isLocal() const +inline ndn::nfd::FaceScope +Face::getScope() const { - return m_isLocal; + return m_transport->getScope(); } inline ndn::nfd::FacePersistency Face::getPersistency() const { - return m_persistency; + return m_transport->getPersistency(); } inline void Face::setPersistency(ndn::nfd::FacePersistency persistency) { - m_persistency = persistency; + return m_transport->setPersistency(persistency); } -inline bool -Face::isMultiAccess() const +inline ndn::nfd::LinkType +Face::getLinkType() const { - return m_isMultiAccess; + return m_transport->getLinkType(); } -inline const face::FaceCounters& +inline FaceState +Face::getState() const +{ + return m_transport->getState(); +} + +inline void +Face::close() +{ + m_transport->close(); +} + +inline const FaceCounters& Face::getCounters() const -{ - return m_countersWrapper; -} - -inline OldFaceCounters& -Face::getMutableCounters() { return m_counters; } -inline const FaceUri& -Face::getRemoteUri() const -{ - return m_remoteUri; -} - -inline const FaceUri& -Face::getLocalUri() const -{ - return m_localUri; -} +std::ostream& +operator<<(std::ostream& os, const FaceLogHelper& flh); template typename std::enable_if::value, std::ostream&>::type -operator<<(std::ostream& os, const face::FaceLogHelper& flh) +operator<<(std::ostream& os, const FaceLogHelper& flh) { - const Face& face = flh.obj; - os << "[id=" << face.getId() << ",local=" << face.getLocalUri() << - ",remote=" << face.getRemoteUri() << "] "; - return os; + return os << FaceLogHelper(flh.obj); } +} // namespace face + +using face::FaceId; +using face::Face; + } // namespace nfd -#endif // NFD_DAEMON_FACE_FACE_HPP +#endif // NFD_DAEMON_FACE_HPP diff --git a/daemon/face/internal-face.cpp b/daemon/face/internal-face.cpp index c89f87f5..8bea03db 100644 --- a/daemon/face/internal-face.cpp +++ b/daemon/face/internal-face.cpp @@ -26,7 +26,6 @@ #include "internal-face.hpp" #include "generic-link-service.hpp" #include "internal-transport.hpp" -#include "lp-face-wrapper.hpp" #include "core/global-io.hpp" namespace nfd { @@ -38,19 +37,16 @@ makeInternalFace(ndn::KeyChain& clientKeyChain) GenericLinkService::Options serviceOpts; serviceOpts.allowLocalFields = true; - auto face = make_unique(make_unique(serviceOpts), - make_unique()); - auto faceW = make_shared(std::move(face)); - // TODO#3172 eliminate wrapper + auto face = make_shared(make_unique(serviceOpts), + make_unique()); - InternalForwarderTransport* forwarderTransport = - static_cast(faceW->getLpFace()->getTransport()); + auto forwarderTransport = static_cast(face->getTransport()); auto clientTransport = make_shared(); clientTransport->connectToForwarder(forwarderTransport); auto clientFace = make_shared(clientTransport, getGlobalIoService(), clientKeyChain); - return std::make_tuple(faceW, clientFace); + return std::make_tuple(face, clientFace); } } // namespace face diff --git a/daemon/face/link-service.cpp b/daemon/face/link-service.cpp index 93507e08..00dd6f05 100644 --- a/daemon/face/link-service.cpp +++ b/daemon/face/link-service.cpp @@ -24,8 +24,7 @@ */ #include "link-service.hpp" -#include "lp-face.hpp" -#include "transport.hpp" +#include "face.hpp" namespace nfd { namespace face { @@ -43,7 +42,7 @@ LinkService::~LinkService() } void -LinkService::setFaceAndTransport(LpFace& face, Transport& transport) +LinkService::setFaceAndTransport(Face& face, Transport& transport) { BOOST_ASSERT(m_face == nullptr); BOOST_ASSERT(m_transport == nullptr); @@ -118,7 +117,7 @@ LinkService::receiveNack(const ndn::lp::Nack& nack) std::ostream& operator<<(std::ostream& os, const FaceLogHelper& flh) { - const LpFace* face = flh.obj.getFace(); + const Face* face = flh.obj.getFace(); if (face == nullptr) { os << "[id=0,local=unknown,remote=unknown] "; } diff --git a/daemon/face/link-service.hpp b/daemon/face/link-service.hpp index 031735a7..618e8637 100644 --- a/daemon/face/link-service.hpp +++ b/daemon/face/link-service.hpp @@ -33,7 +33,7 @@ namespace nfd { namespace face { -class LpFace; +class Face; /** \brief counters provided by LinkService * \note The type name 'LinkServiceCounters' is implementation detail. @@ -67,8 +67,8 @@ public: PacketCounter nOutNacks; }; -/** \brief the upper part of an LpFace - * \sa LpFace +/** \brief the upper part of a Face + * \sa Face */ class LinkService : protected virtual LinkServiceCounters, noncopyable { @@ -87,11 +87,11 @@ public: * \pre setFaceAndTransport has not been called */ void - setFaceAndTransport(LpFace& face, Transport& transport); + setFaceAndTransport(Face& face, Transport& transport); /** \return Face to which this LinkService is attached */ - const LpFace* + const Face* getFace() const; /** \return Transport to which this LinkService is attached @@ -187,11 +187,11 @@ private: // lower interface to be overridden in subclass doReceivePacket(Transport::Packet&& packet) = 0; private: - LpFace* m_face; + Face* m_face; Transport* m_transport; }; -inline const LpFace* +inline const Face* LinkService::getFace() const { return m_face; diff --git a/daemon/face/lp-face-wrapper.cpp b/daemon/face/lp-face-wrapper.cpp deleted file mode 100644 index 920997a6..00000000 --- a/daemon/face/lp-face-wrapper.cpp +++ /dev/null @@ -1,102 +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 . - */ - -#include "lp-face-wrapper.hpp" - -namespace nfd { -namespace face { - -LpFaceWrapper::LpFaceWrapper(unique_ptr 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); - 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 deleted file mode 100644 index 4cfb0f35..00000000 --- a/daemon/face/lp-face-wrapper.hpp +++ /dev/null @@ -1,138 +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 . - */ - -#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 - */ -class LpFaceWrapper : public Face -{ -public: - explicit - LpFaceWrapper(unique_ptr 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 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/lp-face.hpp b/daemon/face/lp-face.hpp deleted file mode 100644 index 130fe003..00000000 --- a/daemon/face/lp-face.hpp +++ /dev/null @@ -1,303 +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 . - */ - -#ifndef NFD_DAEMON_LP_FACE_HPP -#define NFD_DAEMON_LP_FACE_HPP - -#include "transport.hpp" -#include "link-service.hpp" -#include "face-counters.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 -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 service, unique_ptr 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& afterReceiveInterest; - - /** \brief signals on Data received - */ - signal::Signal& afterReceiveData; - - /** \brief signals on Nack received - */ - signal::Signal& 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& 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; - -private: - FaceId m_id; - unique_ptr m_service; - unique_ptr 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; -} - -template -typename std::enable_if::value, std::ostream&>::type -operator<<(std::ostream& os, const FaceLogHelper& 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/null-face.cpp b/daemon/face/null-face.cpp index 2c409a74..a793e3ec 100644 --- a/daemon/face/null-face.cpp +++ b/daemon/face/null-face.cpp @@ -24,7 +24,6 @@ */ #include "null-face.hpp" -#include "lp-face-wrapper.hpp" #include "generic-link-service.hpp" #include "internal-transport.hpp" @@ -37,12 +36,8 @@ namespace face { shared_ptr makeNullFace(const FaceUri& uri) { - auto face = make_unique(make_unique(), - make_unique(uri, uri, ndn::nfd::FACE_SCOPE_LOCAL)); - auto faceW = make_shared(std::move(face)); - // TODO#3172 eliminate wrapper - - return faceW; + return make_shared(make_unique(), + make_unique(uri, uri, ndn::nfd::FACE_SCOPE_LOCAL)); } } // namespace face diff --git a/daemon/face/old-face-counters.hpp b/daemon/face/old-face-counters.hpp deleted file mode 100644 index 1c1dd2e0..00000000 --- a/daemon/face/old-face-counters.hpp +++ /dev/null @@ -1,178 +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 . - */ - -#ifndef NFD_DAEMON_FACE_OLD_FACE_COUNTERS_HPP -#define NFD_DAEMON_FACE_OLD_FACE_COUNTERS_HPP - -#include "core/counter.hpp" - -namespace nfd { - -/** \brief contains network layer packet counters - */ -class NetworkLayerCounters : noncopyable -{ -public: - /// incoming Interest - const PacketCounter& - getNInInterests() const - { - return m_nInInterests; - } - - PacketCounter& - getNInInterests() - { - return m_nInInterests; - } - - /// incoming Data - const PacketCounter& - getNInDatas() const - { - return m_nInDatas; - } - - PacketCounter& - getNInDatas() - { - return m_nInDatas; - } - - /// outgoing Interest - const PacketCounter& - getNOutInterests() const - { - return m_nOutInterests; - } - - PacketCounter& - getNOutInterests() - { - return m_nOutInterests; - } - - /// outgoing Data - const PacketCounter& - getNOutDatas() const - { - return m_nOutDatas; - } - - PacketCounter& - getNOutDatas() - { - return m_nOutDatas; - } - -protected: - /** \brief copy current obseverations to a struct - * \param recipient an object with set methods for counters - */ - template - void - copyTo(R& recipient) const - { - recipient.setNInInterests(this->getNInInterests()); - recipient.setNInDatas(this->getNInDatas()); - recipient.setNOutInterests(this->getNOutInterests()); - recipient.setNOutDatas(this->getNOutDatas()); - } - -private: - PacketCounter m_nInInterests; - PacketCounter m_nInDatas; - PacketCounter m_nOutInterests; - PacketCounter m_nOutDatas; -}; - -/** \brief contains link layer byte counters - */ -class LinkLayerCounters : noncopyable -{ -public: - /// received bytes - const ByteCounter& - getNInBytes() const - { - return m_nInBytes; - } - - ByteCounter& - getNInBytes() - { - return m_nInBytes; - } - - /// sent bytes - const ByteCounter& - getNOutBytes() const - { - return m_nOutBytes; - } - - ByteCounter& - getNOutBytes() - { - return m_nOutBytes; - } - -protected: - /** \brief copy current obseverations to a struct - * \param recipient an object with set methods for counters - */ - template - void - copyTo(R& recipient) const - { - recipient.setNInBytes(this->getNInBytes()); - recipient.setNOutBytes(this->getNOutBytes()); - } - -private: - ByteCounter m_nInBytes; - ByteCounter m_nOutBytes; -}; - -/** \brief contains counters on face (2014 face architecture) - */ -class OldFaceCounters : public NetworkLayerCounters, public LinkLayerCounters -{ -public: - /** \brief copy current obseverations to a struct - * \param recipient an object with set methods for counters - */ - template - void - copyTo(R& recipient) const - { - this->NetworkLayerCounters::copyTo(recipient); - this->LinkLayerCounters::copyTo(recipient); - } -}; - -} // namespace nfd - -#endif // NFD_DAEMON_FACE_OLD_FACE_COUNTERS_HPP diff --git a/daemon/face/tcp-channel.cpp b/daemon/face/tcp-channel.cpp index f9873c26..21943c8f 100644 --- a/daemon/face/tcp-channel.cpp +++ b/daemon/face/tcp-channel.cpp @@ -99,7 +99,7 @@ TcpChannel::createFace(ip::tcp::socket&& socket, const FaceCreatedCallback& onFaceCreated, bool isOnDemand) { - shared_ptr face; + shared_ptr face; tcp::Endpoint remoteEndpoint = socket.remote_endpoint(); auto it = m_channelFaces.find(remoteEndpoint); @@ -108,14 +108,14 @@ TcpChannel::createFace(ip::tcp::socket&& socket, : ndn::nfd::FACE_PERSISTENCY_PERSISTENT; auto linkService = make_unique(); auto transport = make_unique(std::move(socket), persistency); - auto lpFace = make_unique(std::move(linkService), std::move(transport)); - face = make_shared(std::move(lpFace)); + face = make_shared(std::move(linkService), std::move(transport)); - 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; + connectFaceClosedSignal(*face, + [this, remoteEndpoint] { + NFD_LOG_TRACE("Erasing " << remoteEndpoint << " from channel face map"); + m_channelFaces.erase(remoteEndpoint); + }); } else { // we already have a face for this endpoint, just reuse it diff --git a/daemon/face/tcp-channel.hpp b/daemon/face/tcp-channel.hpp index 799fbf14..c8190144 100644 --- a/daemon/face/tcp-channel.hpp +++ b/daemon/face/tcp-channel.hpp @@ -27,7 +27,6 @@ #define NFD_DAEMON_FACE_TCP_CHANNEL_HPP #include "channel.hpp" -#include "lp-face-wrapper.hpp" #include "core/scheduler.hpp" namespace nfd { @@ -114,7 +113,7 @@ private: const FaceCreationFailedCallback& onConnectFailed); private: - std::map> m_channelFaces; + std::map> m_channelFaces; tcp::Endpoint m_localEndpoint; boost::asio::ip::tcp::acceptor m_acceptor; diff --git a/daemon/face/transport.cpp b/daemon/face/transport.cpp index e3e1e074..2d2c3dd4 100644 --- a/daemon/face/transport.cpp +++ b/daemon/face/transport.cpp @@ -24,8 +24,7 @@ */ #include "transport.hpp" -#include "lp-face.hpp" -#include "link-service.hpp" +#include "face.hpp" namespace nfd { namespace face { @@ -73,7 +72,7 @@ Transport::~Transport() } void -Transport::setFaceAndLinkService(LpFace& face, LinkService& service) +Transport::setFaceAndLinkService(Face& face, LinkService& service) { BOOST_ASSERT(m_face == nullptr); BOOST_ASSERT(m_service == nullptr); @@ -190,7 +189,7 @@ std::ostream& operator<<(std::ostream& os, const FaceLogHelper& flh) { const Transport& transport = flh.obj; - const LpFace* face = transport.getFace(); + const Face* face = transport.getFace(); FaceId faceId = face == nullptr ? INVALID_FACEID : face->getId(); os << "[id=" << faceId << ",local=" << transport.getLocalUri() diff --git a/daemon/face/transport.hpp b/daemon/face/transport.hpp index 626809c8..56ff7305 100644 --- a/daemon/face/transport.hpp +++ b/daemon/face/transport.hpp @@ -33,7 +33,7 @@ namespace nfd { namespace face { -class LpFace; +class Face; class LinkService; /** \brief indicates the state of a transport @@ -98,8 +98,8 @@ const ssize_t MTU_UNLIMITED = -1; */ const ssize_t MTU_INVALID = -2; -/** \brief the lower part of an LpFace - * \sa LpFace +/** \brief the lower part of a Face + * \sa Face */ class Transport : protected virtual TransportCounters, noncopyable { @@ -154,11 +154,11 @@ public: * \pre setFaceAndLinkService has not been called */ void - setFaceAndLinkService(LpFace& face, LinkService& service); + setFaceAndLinkService(Face& face, LinkService& service); /** \return Face to which this Transport is attached */ - const LpFace* + const Face* getFace() const; /** \return LinkService to which this Transport is attached @@ -307,7 +307,7 @@ private: // to be overridden by subclass doSend(Packet&& packet) = 0; private: - LpFace* m_face; + Face* m_face; LinkService* m_service; FaceUri m_localUri; FaceUri m_remoteUri; @@ -318,7 +318,7 @@ private: TransportState m_state; }; -inline const LpFace* +inline const Face* Transport::getFace() const { return m_face; diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp index bb6529fa..e6d65df3 100644 --- a/daemon/face/udp-channel.cpp +++ b/daemon/face/udp-channel.cpp @@ -120,7 +120,7 @@ UdpChannel::handleNewPeer(const boost::system::error_code& error, NFD_LOG_DEBUG("[" << m_localEndpoint << "] New peer " << m_remoteEndpoint); bool isCreated = false; - shared_ptr face; + shared_ptr face; try { std::tie(isCreated, face) = createFace(m_remoteEndpoint, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); } @@ -136,12 +136,12 @@ UdpChannel::handleNewPeer(const boost::system::error_code& error, onFaceCreated(face); // dispatch the datagram to the face for processing - static_cast(face->getLpFace()->getTransport())->receiveDatagram(m_inputBuffer, nBytesReceived, error); + static_cast(face->getTransport())->receiveDatagram(m_inputBuffer, nBytesReceived, error); this->waitForNewPeer(onFaceCreated, onReceiveFailed); } -std::pair> +std::pair> UdpChannel::createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersistency persistency) { auto it = m_channelFaces.find(remoteEndpoint); @@ -166,13 +166,13 @@ UdpChannel::createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersis auto linkService = make_unique(); auto transport = make_unique(std::move(socket), persistency, m_idleFaceTimeout); - auto face = make_shared(make_unique( - std::move(linkService), std::move(transport))); + auto face = make_shared(std::move(linkService), std::move(transport)); face->setPersistency(persistency); m_channelFaces[remoteEndpoint] = face; - face->onFail.connectSingleShot([this, remoteEndpoint] (const std::string&) { + connectFaceClosedSignal(*face, + [this, remoteEndpoint] { NFD_LOG_TRACE("Erasing " << remoteEndpoint << " from channel face map"); m_channelFaces.erase(remoteEndpoint); }); diff --git a/daemon/face/udp-channel.hpp b/daemon/face/udp-channel.hpp index a24d1ec1..a2506d4b 100644 --- a/daemon/face/udp-channel.hpp +++ b/daemon/face/udp-channel.hpp @@ -27,7 +27,6 @@ #define NFD_DAEMON_FACE_UDP_CHANNEL_HPP #include "channel.hpp" -#include "lp-face-wrapper.hpp" namespace nfd { @@ -105,11 +104,11 @@ private: const FaceCreatedCallback& onFaceCreated, const FaceCreationFailedCallback& onReceiveFailed); - std::pair> + std::pair> createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersistency persistency); private: - std::map> m_channelFaces; + std::map> m_channelFaces; udp::Endpoint m_localEndpoint; diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp index 2a39e36b..cc60a63c 100644 --- a/daemon/face/udp-factory.cpp +++ b/daemon/face/udp-factory.cpp @@ -25,7 +25,6 @@ #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" @@ -127,7 +126,7 @@ UdpFactory::createChannel(const std::string& localIp, const std::string& localPo return createChannel(endpoint, timeout); } -shared_ptr +shared_ptr UdpFactory::createMulticastFace(const udp::Endpoint& localEndpoint, const udp::Endpoint& multicastEndpoint, const std::string& networkInterfaceName/* = ""*/) @@ -210,18 +209,15 @@ UdpFactory::createMulticastFace(const udp::Endpoint& localEndpoint, auto transport = make_unique(localEndpoint, multicastEndpoint, std::move(receiveSocket), std::move(sendSocket)); - auto lpFace = make_unique(std::move(linkService), std::move(transport)); - face = make_shared(std::move(lpFace)); + face = make_shared(std::move(linkService), std::move(transport)); - face->onFail.connectSingleShot([this, localEndpoint] (const std::string& reason) { - m_multicastFaces.erase(localEndpoint); - }); m_multicastFaces[localEndpoint] = face; + connectFaceClosedSignal(*face, [this, localEndpoint] { m_multicastFaces.erase(localEndpoint); }); return face; } -shared_ptr +shared_ptr UdpFactory::createMulticastFace(const std::string& localIp, const std::string& multicastIp, const std::string& multicastPort, @@ -294,7 +290,7 @@ UdpFactory::findChannel(const udp::Endpoint& localEndpoint) const return nullptr; } -shared_ptr +shared_ptr UdpFactory::findMulticastFace(const udp::Endpoint& localEndpoint) const { auto i = m_multicastFaces.find(localEndpoint); diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp index 134c5eec..9c851bda 100644 --- a/daemon/face/udp-factory.hpp +++ b/daemon/face/udp-factory.hpp @@ -49,7 +49,7 @@ public: } }; - typedef std::map> MulticastFaceMap; + typedef std::map> MulticastFaceMap; /** * \brief Create UDP-based channel using udp::Endpoint @@ -128,12 +128,12 @@ public: * \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 + shared_ptr createMulticastFace(const udp::Endpoint& localEndpoint, const udp::Endpoint& multicastEndpoint, const std::string& networkInterfaceName = ""); - shared_ptr + shared_ptr createMulticastFace(const std::string& localIp, const std::string& multicastIp, const std::string& multicastPort, @@ -181,7 +181,7 @@ private: * \returns shared pointer to the existing multicast UdpFace object * or nullptr when such face does not exist */ - shared_ptr + shared_ptr findMulticastFace(const udp::Endpoint& localEndpoint) const; private: diff --git a/daemon/face/unix-stream-channel.cpp b/daemon/face/unix-stream-channel.cpp index c34ad7b0..5b56c6a3 100644 --- a/daemon/face/unix-stream-channel.cpp +++ b/daemon/face/unix-stream-channel.cpp @@ -25,7 +25,6 @@ #include "unix-stream-channel.hpp" #include "generic-link-service.hpp" -#include "lp-face-wrapper.hpp" #include "unix-stream-transport.hpp" #include "core/global-io.hpp" @@ -135,8 +134,7 @@ UnixStreamChannel::handleAccept(const boost::system::error_code& error, auto linkService = make_unique(); auto transport = make_unique(std::move(m_socket)); - auto lpFace = make_unique(std::move(linkService), std::move(transport)); - auto face = make_shared(std::move(lpFace)); + auto face = make_shared(std::move(linkService), std::move(transport)); onFaceCreated(face); // prepare accepting the next connection diff --git a/daemon/face/websocket-channel.cpp b/daemon/face/websocket-channel.cpp index 520bb7da..75626ab2 100644 --- a/daemon/face/websocket-channel.cpp +++ b/daemon/face/websocket-channel.cpp @@ -77,7 +77,7 @@ WebSocketChannel::handlePongTimeout(websocketpp::connection_hdl hdl) { auto it = m_channelFaces.find(hdl); if (it != m_channelFaces.end()) { - static_cast(it->second->getLpFace()->getTransport())->handlePongTimeout(); + static_cast(it->second->getTransport())->handlePongTimeout(); } else { NFD_LOG_WARN("Pong timeout on unknown transport"); @@ -89,7 +89,7 @@ WebSocketChannel::handlePong(websocketpp::connection_hdl hdl) { auto it = m_channelFaces.find(hdl); if (it != m_channelFaces.end()) { - static_cast(it->second->getLpFace()->getTransport())->handlePong(); + static_cast(it->second->getTransport())->handlePong(); } else { NFD_LOG_WARN("Pong received on unknown transport"); @@ -102,7 +102,7 @@ WebSocketChannel::handleMessage(websocketpp::connection_hdl hdl, { auto it = m_channelFaces.find(hdl); if (it != m_channelFaces.end()) { - static_cast(it->second->getLpFace()->getTransport())->receiveMessage(msg->get_payload()); + static_cast(it->second->getTransport())->receiveMessage(msg->get_payload()); } else { NFD_LOG_WARN("Message received on unknown transport"); @@ -114,16 +114,10 @@ WebSocketChannel::handleOpen(websocketpp::connection_hdl hdl) { auto linkService = make_unique(); auto transport = make_unique(hdl, ref(m_server), m_pingInterval); - auto lpFace = make_unique(std::move(linkService), std::move(transport)); - auto face = make_shared(std::move(lpFace)); + auto face = make_shared(std::move(linkService), std::move(transport)); - face->getLpFace()->afterStateChange.connect( - [this, hdl] (face::FaceState oldState, face::FaceState newState) { - if (newState == face::FaceState::CLOSED) { - m_channelFaces.erase(hdl); - } - }); m_channelFaces[hdl] = face; + connectFaceClosedSignal(*face, [this, hdl] { m_channelFaces.erase(hdl); }); m_onFaceCreatedCallback(face); } @@ -133,7 +127,7 @@ WebSocketChannel::handleClose(websocketpp::connection_hdl hdl) { auto it = m_channelFaces.find(hdl); if (it != m_channelFaces.end()) { - it->second->getLpFace()->close(); + it->second->close(); } else { NFD_LOG_WARN("Close on unknown transport"); diff --git a/daemon/face/websocket-channel.hpp b/daemon/face/websocket-channel.hpp index 47eda8c3..1d567314 100644 --- a/daemon/face/websocket-channel.hpp +++ b/daemon/face/websocket-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. @@ -21,13 +21,12 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #ifndef NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP #define NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP #include "channel.hpp" -#include "lp-face-wrapper.hpp" #include "websocketpp.hpp" namespace nfd { @@ -102,7 +101,7 @@ private: websocket::Endpoint m_localEndpoint; websocket::Server m_server; - std::map, + std::map, std::owner_less> m_channelFaces; FaceCreatedCallback m_onFaceCreatedCallback; diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp index 54898370..b1ed449b 100644 --- a/daemon/fw/access-strategy.cpp +++ b/daemon/fw/access-strategy.cpp @@ -115,7 +115,7 @@ bool AccessStrategy::sendToLastNexthop(const Face& inFace, shared_ptr pitEntry, MtInfo& mi, shared_ptr fibEntry) { - if (mi.lastNexthop == INVALID_FACEID) { + if (mi.lastNexthop == face::INVALID_FACEID) { NFD_LOG_DEBUG(pitEntry->getInterest() << " no-last-nexthop"); return false; } @@ -231,7 +231,7 @@ AccessStrategy::updateMeasurements(const Face& inFace, const Data& data, } AccessStrategy::MtInfo::MtInfo() - : lastNexthop(INVALID_FACEID) + : lastNexthop(face::INVALID_FACEID) , rtt(1, time::milliseconds(1), 0.1) { } diff --git a/daemon/fw/client-control-strategy.cpp b/daemon/fw/client-control-strategy.cpp index 7cc07fd9..1066efa3 100644 --- a/daemon/fw/client-control-strategy.cpp +++ b/daemon/fw/client-control-strategy.cpp @@ -58,7 +58,7 @@ ClientControlStrategy::afterReceiveInterest(const Face& inFace, FaceId outFaceId = static_cast(*tag); shared_ptr outFace = this->getFace(outFaceId); - if (!static_cast(outFace)) { + if (outFace == nullptr) { // If outFace doesn't exist, it's better to reject the Interest // than to use BestRouteStrategy. NFD_LOG_WARN("Interest " << interest.getName() << diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp index a8a8053e..b4bda234 100644 --- a/daemon/fw/face-table.cpp +++ b/daemon/fw/face-table.cpp @@ -27,6 +27,7 @@ #include "forwarder.hpp" #include "core/global-io.hpp" #include "core/logger.hpp" +#include "face/channel.hpp" namespace nfd { @@ -34,7 +35,7 @@ NFD_LOG_INIT("FaceTable"); FaceTable::FaceTable(Forwarder& forwarder) : m_forwarder(forwarder) - , m_lastFaceId(FACEID_RESERVED_MAX) + , m_lastFaceId(face::FACEID_RESERVED_MAX) { } @@ -59,22 +60,22 @@ FaceTable::size() const void FaceTable::add(shared_ptr face) { - if (face->getId() != INVALID_FACEID && m_faces.count(face->getId()) > 0) { + if (face->getId() != face::INVALID_FACEID && m_faces.count(face->getId()) > 0) { NFD_LOG_WARN("Trying to add existing face id=" << face->getId() << " to the face table"); return; } FaceId faceId = ++m_lastFaceId; - BOOST_ASSERT(faceId > FACEID_RESERVED_MAX); + BOOST_ASSERT(faceId > face::FACEID_RESERVED_MAX); this->addImpl(face, faceId); } void FaceTable::addReserved(shared_ptr face, FaceId faceId) { - BOOST_ASSERT(face->getId() == INVALID_FACEID); + BOOST_ASSERT(face->getId() == face::INVALID_FACEID); BOOST_ASSERT(m_faces.count(face->getId()) == 0); - BOOST_ASSERT(faceId <= FACEID_RESERVED_MAX); + BOOST_ASSERT(faceId <= face::FACEID_RESERVED_MAX); this->addImpl(face, faceId); } @@ -86,30 +87,26 @@ FaceTable::addImpl(shared_ptr face, FaceId faceId) NFD_LOG_INFO("Added face id=" << faceId << " remote=" << face->getRemoteUri() << " local=" << face->getLocalUri()); - face->onReceiveInterest.connect(bind(&Forwarder::startProcessInterest, - &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)); + face->afterReceiveInterest.connect(bind(&Forwarder::startProcessInterest, &m_forwarder, ref(*face), _1)); + face->afterReceiveData.connect(bind(&Forwarder::startProcessData, &m_forwarder, ref(*face), _1)); + face->afterReceiveNack.connect(bind(&Forwarder::startProcessNack, &m_forwarder, ref(*face), _1)); + connectFaceClosedSignal(*face, bind(&FaceTable::remove, this, face)); - this->onAdd(face); + this->afterAdd(face); } void -FaceTable::remove(shared_ptr face, const std::string& reason) +FaceTable::remove(shared_ptr face) { - this->onRemove(face); + this->beforeRemove(face); FaceId faceId = face->getId(); m_faces.erase(faceId); - face->setId(INVALID_FACEID); + face->setId(face::INVALID_FACEID); NFD_LOG_INFO("Removed face id=" << faceId << " remote=" << face->getRemoteUri() << - " local=" << face->getLocalUri() << - " (" << reason << ")"); + " local=" << face->getLocalUri()); m_forwarder.getFib().removeNextHopFromAllEntries(face); diff --git a/daemon/fw/face-table.hpp b/daemon/fw/face-table.hpp index 67c79324..a9186f6d 100644 --- a/daemon/fw/face-table.hpp +++ b/daemon/fw/face-table.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. @@ -75,22 +75,20 @@ public: // enumeration public: // signals /** \brief fires after a Face is added */ - signal::Signal> onAdd; + signal::Signal> afterAdd; /** \brief fires before a Face is removed * * FaceId is valid when this event is fired */ - signal::Signal> onRemove; + signal::Signal> beforeRemove; private: void addImpl(shared_ptr face, FaceId faceId); - // remove is private because it's a handler of face.onFail signal. - // face->close() closes the face and triggers .remove() void - remove(shared_ptr face, const std::string& reason); + remove(shared_ptr face); ForwardRange getForwardRange() const; diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp index e96b87b4..280c7133 100644 --- a/daemon/fw/forwarder.cpp +++ b/daemon/fw/forwarder.cpp @@ -108,7 +108,7 @@ Forwarder::onIncomingInterest(Face& inFace, const Interest& interest) ++m_counters.nInInterests; // /localhost scope control - bool isViolatingLocalhost = !inFace.isLocal() && + bool isViolatingLocalhost = inFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && LOCALHOST_NAME.isPrefixOf(interest.getName()); if (isViolatingLocalhost) { NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() << @@ -151,7 +151,7 @@ Forwarder::onInterestLoop(Face& inFace, const Interest& interest, shared_ptr pitEntry) { // if multi-access face, drop - if (inFace.isMultiAccess()) { + if (inFace.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) { NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() << " interest=" << interest.getName() << " drop"); @@ -244,7 +244,7 @@ Forwarder::onContentStoreHit(const Face& inFace, { NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName()); - data.setTag(make_shared(FACEID_CONTENT_STORE)); + data.setTag(make_shared(face::FACEID_CONTENT_STORE)); // XXX should we lookup PIT for other Interests that also match csMatch? // set PIT straggler timer @@ -284,7 +284,7 @@ void Forwarder::onOutgoingInterest(shared_ptr pitEntry, Face& outFace, bool wantNewNonce) { - if (outFace.getId() == INVALID_FACEID) { + if (outFace.getId() == face::INVALID_FACEID) { NFD_LOG_WARN("onOutgoingInterest face=invalid interest=" << pitEntry->getName()); return; } @@ -374,7 +374,7 @@ Forwarder::onIncomingData(Face& inFace, const Data& data) ++m_counters.nInData; // /localhost scope control - bool isViolatingLocalhost = !inFace.isLocal() && + bool isViolatingLocalhost = inFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && LOCALHOST_NAME.isPrefixOf(data.getName()); if (isViolatingLocalhost) { NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << @@ -439,7 +439,7 @@ void Forwarder::onDataUnsolicited(Face& inFace, const Data& data) { // accept to cache? - bool acceptToCache = inFace.isLocal(); + bool acceptToCache = inFace.getScope() == ndn::nfd::FACE_SCOPE_LOCAL; if (acceptToCache) { // CS insert m_cs.insert(data, true); @@ -453,14 +453,14 @@ Forwarder::onDataUnsolicited(Face& inFace, const Data& data) void Forwarder::onOutgoingData(const Data& data, Face& outFace) { - if (outFace.getId() == INVALID_FACEID) { + if (outFace.getId() == face::INVALID_FACEID) { NFD_LOG_WARN("onOutgoingData face=invalid data=" << data.getName()); return; } NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() << " data=" << data.getName()); // /localhost scope control - bool isViolatingLocalhost = !outFace.isLocal() && + bool isViolatingLocalhost = outFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && LOCALHOST_NAME.isPrefixOf(data.getName()); if (isViolatingLocalhost) { NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() << @@ -484,7 +484,7 @@ Forwarder::onIncomingNack(Face& inFace, const lp::Nack& nack) ++m_counters.nInNacks; // if multi-access face, drop - if (inFace.isMultiAccess()) { + if (inFace.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) { NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() << " nack=" << nack.getInterest().getName() << "~" << nack.getReason() << " face-is-multi-access"); @@ -537,7 +537,7 @@ void Forwarder::onOutgoingNack(shared_ptr pitEntry, const Face& outFace, const lp::NackHeader& nack) { - if (outFace.getId() == INVALID_FACEID) { + if (outFace.getId() == face::INVALID_FACEID) { NFD_LOG_WARN("onOutgoingNack face=invalid" << " nack=" << pitEntry->getInterest().getName() << "~" << nack.getReason() << " no-in-record"); @@ -556,7 +556,7 @@ Forwarder::onOutgoingNack(shared_ptr pitEntry, const Face& outFace, } // if multi-access face, drop - if (outFace.isMultiAccess()) { + if (outFace.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) { NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() << " nack=" << pitEntry->getInterest().getName() << "~" << nack.getReason() << " face-is-multi-access"); diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp index 7b0504e9..00fe82ff 100644 --- a/daemon/fw/strategy.cpp +++ b/daemon/fw/strategy.cpp @@ -33,8 +33,8 @@ namespace fw { NFD_LOG_INIT("Strategy"); Strategy::Strategy(Forwarder& forwarder, const Name& name) - : afterAddFace(forwarder.getFaceTable().onAdd) - , beforeRemoveFace(forwarder.getFaceTable().onRemove) + : afterAddFace(forwarder.getFaceTable().afterAdd) + , beforeRemoveFace(forwarder.getFaceTable().beforeRemove) , m_name(name) , m_forwarder(forwarder) , m_measurements(m_forwarder.getMeasurements(), diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp index d7732069..0cc40d51 100644 --- a/daemon/mgmt/face-manager.cpp +++ b/daemon/mgmt/face-manager.cpp @@ -27,7 +27,6 @@ #include "core/network-interface.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" @@ -77,9 +76,9 @@ FaceManager::FaceManager(FaceTable& faceTable, auto postNotification = registerNotificationStream("events"); m_faceAddConn = - m_faceTable.onAdd.connect(bind(&FaceManager::afterFaceAdded, this, _1, postNotification)); + m_faceTable.afterAdd.connect(bind(&FaceManager::afterFaceAdded, this, _1, postNotification)); m_faceRemoveConn = - m_faceTable.onRemove.connect(bind(&FaceManager::afterFaceRemoved, this, _1, postNotification)); + m_faceTable.beforeRemove.connect(bind(&FaceManager::afterFaceRemoved, this, _1, postNotification)); } void @@ -173,15 +172,14 @@ 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) { + Face* face = findFaceForLocalControl(interest, parameters, done); + if (!face) { return; } // 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(result.lpFace->getLinkService()); + auto service = dynamic_cast(face->getLinkService()); if (service == nullptr) { return done(ControlResponse(503, "LinkService type not supported")); } @@ -199,15 +197,14 @@ 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) { + Face* face = findFaceForLocalControl(interest, parameters, done); + if (!face) { return; } // 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(result.lpFace->getLinkService()); + auto service = dynamic_cast(face->getLinkService()); if (service == nullptr) { return done(ControlResponse(503, "LinkService type not supported")); } @@ -220,15 +217,11 @@ FaceManager::disableLocalControl(const Name& topPrefix, const Interest& interest .setBody(parameters.wireEncode())); } -FaceManager::ExtractLocalControlParametersResult -FaceManager::extractLocalControlParameters(const Interest& request, - const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done) +Face* +FaceManager::findFaceForLocalControl(const Interest& request, + const ControlParameters& parameters, + const ndn::mgmt::CommandContinuation& done) { - ExtractLocalControlParametersResult result; - result.isValid = false; - result.lpFace = nullptr; - shared_ptr incomingFaceIdTag = request.getTag(); // NDNLPv2 says "application MUST be prepared to receive a packet without IncomingFaceId field", // but it's fine to assert IncomingFaceId is available, because InternalFace lives inside NFD @@ -239,22 +232,16 @@ FaceManager::extractLocalControlParameters(const Interest& request, if (face == nullptr) { NFD_LOG_DEBUG("FaceId " << *incomingFaceIdTag << " not found"); done(ControlResponse(410, "Face not found")); - return result; + return nullptr; } - if (!face->isLocal()) { + if (face->getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) { NFD_LOG_DEBUG("Cannot enable local control on non-local FaceId " << face->getId()); done(ControlResponse(412, "Face is non-local")); - return result; + return nullptr; } - result.isValid = true; - auto lpFaceW = dynamic_pointer_cast(face); - // LocalFace is gone, so a face that is local must be an LpFace. - BOOST_ASSERT(lpFaceW != nullptr); - result.lpFace = lpFaceW->getLpFace(); - - return result; + return face.get(); } void @@ -345,7 +332,7 @@ FaceManager::doesMatchFilter(const ndn::nfd::FaceQueryFilter& filter, shared_ptr } if (filter.hasFaceScope() && - (filter.getFaceScope() == ndn::nfd::FACE_SCOPE_LOCAL) != face->isLocal()) { + filter.getFaceScope() != face->getScope()) { return false; } @@ -355,7 +342,7 @@ FaceManager::doesMatchFilter(const ndn::nfd::FaceQueryFilter& filter, shared_ptr } if (filter.hasLinkType() && - (filter.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) != face->isMultiAccess()) { + filter.getLinkType() != face->getLinkType()) { return false; } @@ -363,8 +350,8 @@ FaceManager::doesMatchFilter(const ndn::nfd::FaceQueryFilter& filter, shared_ptr } template -inline void -collectLpFaceProperties(const face::LpFace& face, FaceTraits& traits) +void +FaceManager::collectFaceProperties(const Face& face, FaceTraits& traits) { traits.setFaceId(face.getId()) .setRemoteUri(face.getRemoteUri().toString()) @@ -372,27 +359,6 @@ collectLpFaceProperties(const face::LpFace& face, FaceTraits& traits) .setFaceScope(face.getScope()) .setFacePersistency(face.getPersistency()) .setLinkType(face.getLinkType()); - // TODO#3172 replace this into FaceManager::collectFaceProperties -} - -template -void -FaceManager::collectFaceProperties(const Face& face, FaceTraits& traits) -{ - auto lpFace = dynamic_cast(&face); - if (lpFace != nullptr) { - collectLpFaceProperties(*lpFace, traits); - return; - } - - traits.setFaceId(face.getId()) - .setRemoteUri(face.getRemoteUri().toString()) - .setLocalUri(face.getLocalUri().toString()) - .setFaceScope(face.isLocal() ? ndn::nfd::FACE_SCOPE_LOCAL - : ndn::nfd::FACE_SCOPE_NON_LOCAL) - .setFacePersistency(face.getPersistency()) - .setLinkType(face.isMultiAccess() ? ndn::nfd::LINK_TYPE_MULTI_ACCESS - : ndn::nfd::LINK_TYPE_POINT_TO_POINT); } void @@ -717,7 +683,7 @@ FaceManager::processSectionUdp(const ConfigSection& configSection, bool isDryRun m_factories.insert(std::make_pair("udp6", factory)); } - std::set> multicastFacesToRemove; + std::set> multicastFacesToRemove; for (const auto& i : factory->getMulticastFaces()) { multicastFacesToRemove.insert(i.second); } @@ -799,7 +765,7 @@ FaceManager::processSectionEther(const ConfigSection& configSection, bool isDryR m_factories.insert(std::make_pair("ether", factory)); } - std::set> multicastFacesToRemove; + std::set> multicastFacesToRemove; for (const auto& i : factory->getMulticastFaces()) { multicastFacesToRemove.insert(i.second); } diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp index 8e90a73d..c2f43bbb 100644 --- a/daemon/mgmt/face-manager.hpp +++ b/daemon/mgmt/face-manager.hpp @@ -29,18 +29,14 @@ #include "manager-base.hpp" #include #include +#include "face/face.hpp" namespace nfd { -class Face; class FaceTable; 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 @@ -89,16 +85,10 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand afterCreateFaceFailure(const std::string& reason, const ndn::mgmt::CommandContinuation& done); - struct ExtractLocalControlParametersResult - { - bool isValid; - face::LpFace* lpFace; - }; - - ExtractLocalControlParametersResult - extractLocalControlParameters(const Interest& request, - const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done); + Face* + findFaceForLocalControl(const Interest& request, + const ControlParameters& parameters, + const ndn::mgmt::CommandContinuation& done); PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset void diff --git a/daemon/nfd.cpp b/daemon/nfd.cpp index bcc59262..5d9ce22a 100644 --- a/daemon/nfd.cpp +++ b/daemon/nfd.cpp @@ -91,8 +91,8 @@ Nfd::initialize() initializeManagement(); FaceTable& faceTable = m_forwarder->getFaceTable(); - faceTable.addReserved(face::makeNullFace(), FACEID_NULL); - faceTable.addReserved(face::makeNullFace(FaceUri("contentstore://")), FACEID_CONTENT_STORE); + faceTable.addReserved(face::makeNullFace(), face::FACEID_NULL); + faceTable.addReserved(face::makeNullFace(FaceUri("contentstore://")), face::FACEID_CONTENT_STORE); PrivilegeHelper::drop(); @@ -145,7 +145,7 @@ void Nfd::initializeManagement() { std::tie(m_internalFace, m_internalClientFace) = face::makeInternalFace(m_keyChain); - m_forwarder->getFaceTable().addReserved(m_internalFace, FACEID_INTERNAL_FACE); + m_forwarder->getFaceTable().addReserved(m_internalFace, face::FACEID_INTERNAL_FACE); m_dispatcher.reset(new ndn::mgmt::Dispatcher(*m_internalClientFace, m_keyChain)); m_validator.reset(new CommandValidator()); diff --git a/daemon/nfd.hpp b/daemon/nfd.hpp index 57b5e8a6..dd97cf4d 100644 --- a/daemon/nfd.hpp +++ b/daemon/nfd.hpp @@ -34,19 +34,14 @@ #include namespace ndn { - class Face; - namespace mgmt { - class Dispatcher; - -} -} +} // namespace mgmt +} // namespace ndn namespace nfd { -class Face; class Forwarder; class FibManager; class FaceManager; @@ -54,6 +49,10 @@ class StrategyChoiceManager; class ForwarderStatusManager; class CommandValidator; +namespace face { +class Face; +} // namespace face + /** * \brief Class representing NFD instance * This class can be used to initialize all components of NFD @@ -110,7 +109,7 @@ private: unique_ptr m_forwarder; ndn::KeyChain& m_keyChain; - shared_ptr m_internalFace; + shared_ptr m_internalFace; shared_ptr m_internalClientFace; unique_ptr m_validator; diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp index 85ea19c6..22df4a48 100644 --- a/daemon/table/pit-entry.cpp +++ b/daemon/table/pit-entry.cpp @@ -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. @@ -47,7 +47,7 @@ bool Entry::hasLocalInRecord() const { return std::any_of(m_inRecords.begin(), m_inRecords.end(), - [] (const InRecord& inRecord) { return inRecord.getFace()->isLocal(); }); + [] (const InRecord& inRecord) { return inRecord.getFace()->getScope() == ndn::nfd::FACE_SCOPE_LOCAL; }); } bool @@ -78,14 +78,14 @@ bool Entry::violatesScope(const Face& face) const { // /localhost scope - bool isViolatingLocalhost = !face.isLocal() && + bool isViolatingLocalhost = face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && LOCALHOST_NAME.isPrefixOf(this->getName()); if (isViolatingLocalhost) { return true; } // /localhop scope - bool isViolatingLocalhop = !face.isLocal() && + bool isViolatingLocalhop = face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && LOCALHOP_NAME.isPrefixOf(this->getName()) && !this->hasLocalInRecord(); if (isViolatingLocalhop) { diff --git a/tests/daemon/face/dummy-lp-face.cpp b/tests/daemon/face/dummy-face.cpp similarity index 77% rename from tests/daemon/face/dummy-lp-face.cpp rename to tests/daemon/face/dummy-face.cpp index 20fb20d7..c4f61542 100644 --- a/tests/daemon/face/dummy-lp-face.cpp +++ b/tests/daemon/face/dummy-face.cpp @@ -23,14 +23,14 @@ * NFD, e.g., in COPYING.md file. If not, see . */ -#include "dummy-lp-face.hpp" +#include "dummy-face.hpp" #include "dummy-transport.hpp" namespace nfd { namespace face { namespace tests { -class DummyLpFace::LinkService : public face::LinkService +class DummyFace::LinkService : public face::LinkService { public: void @@ -51,28 +51,28 @@ public: this->face::LinkService::receiveNack(nack); } - signal::Signal afterSend; + signal::Signal afterSend; private: virtual void doSendInterest(const Interest& interest) DECL_OVERRIDE { this->sentInterests.push_back(interest); - this->afterSend(); + this->afterSend(tlv::Interest); } virtual void doSendData(const Data& data) DECL_OVERRIDE { this->sentData.push_back(data); - this->afterSend(); + this->afterSend(tlv::Data); } virtual void doSendNack(const lp::Nack& nack) DECL_OVERRIDE { this->sentNacks.push_back(nack); - this->afterSend(); + this->afterSend(lp::tlv::Nack); } virtual void @@ -87,11 +87,11 @@ public: std::vector 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(), - make_unique(localUri, remoteUri, scope, persistency, linkType)) +DummyFace::DummyFace(const std::string& localUri, const std::string& remoteUri, + ndn::nfd::FaceScope scope, ndn::nfd::FacePersistency persistency, + ndn::nfd::LinkType linkType) + : Face(make_unique(), + make_unique(localUri, remoteUri, scope, persistency, linkType)) , afterSend(this->getLinkServiceInternal()->afterSend) , sentInterests(this->getLinkServiceInternal()->sentInterests) , sentData(this->getLinkServiceInternal()->sentData) @@ -100,37 +100,37 @@ DummyLpFace::DummyLpFace(const std::string& localUri, const std::string& remoteU } void -DummyLpFace::setState(FaceState state) +DummyFace::setState(FaceState state) { this->getTransportInternal()->setState(state); } void -DummyLpFace::receiveInterest(const Interest& interest) +DummyFace::receiveInterest(const Interest& interest) { this->getLinkServiceInternal()->receiveInterest(interest); } void -DummyLpFace::receiveData(const Data& data) +DummyFace::receiveData(const Data& data) { this->getLinkServiceInternal()->receiveData(data); } void -DummyLpFace::receiveNack(const lp::Nack& nack) +DummyFace::receiveNack(const lp::Nack& nack) { this->getLinkServiceInternal()->receiveNack(nack); } -DummyLpFace::LinkService* -DummyLpFace::getLinkServiceInternal() +DummyFace::LinkService* +DummyFace::getLinkServiceInternal() { return static_cast(this->getLinkService()); } DummyTransport* -DummyLpFace::getTransportInternal() +DummyFace::getTransportInternal() { return static_cast(this->getTransport()); } diff --git a/tests/daemon/face/dummy-face.hpp b/tests/daemon/face/dummy-face.hpp index 6ed7d467..34f2d09b 100644 --- a/tests/daemon/face/dummy-face.hpp +++ b/tests/daemon/face/dummy-face.hpp @@ -29,71 +29,78 @@ #include "face/face.hpp" namespace nfd { +namespace face { namespace tests { +class DummyTransport; + /** \brief a Face for unit testing + * + * The DummyFace has no underlying transport, but allows observing outgoing packets + * and injecting incoming packets at network layer. + * It's primarily used for forwarding test suites, but can be used in other tests as well. + * + * Outgoing network-layer packets sent through the DummyFace are recorded in sent* vectors, + * which can be observed in test cases. + * Incoming network-layer packets can be injected from test cases through receive* method. */ class DummyFace : public Face { public: - explicit - DummyFace(const std::string& remoteUri = "dummy://", const std::string& localUri = "dummy://", - bool isLocal = false) - : Face(FaceUri(remoteUri), FaceUri(localUri), isLocal) - { - } + class LinkService; + DummyFace(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 - sendInterest(const Interest& interest) DECL_OVERRIDE - { - this->emitSignal(onSendInterest, interest); - m_sentInterests.push_back(interest); - this->afterSend(); - } + setState(FaceState state); + /** \brief causes the face to receive an Interest + */ void - sendData(const Data& data) DECL_OVERRIDE - { - this->emitSignal(onSendData, data); - m_sentDatas.push_back(data); - this->afterSend(); - } + receiveInterest(const Interest& interest); + /** \brief causes the face to receive a Data + */ void - close() DECL_OVERRIDE - { - this->fail("close"); - } + receiveData(const Data& data); + /** \brief causes the face to receive a Nack + */ void - receiveInterest(const Interest& interest) - { - this->emitSignal(onReceiveInterest, interest); - } + receiveNack(const lp::Nack& nack); - void - receiveData(const Data& data) - { - this->emitSignal(onReceiveData, data); - } + /** \brief signals after any network-layer packet is sent + * + * The network-layer packet type is indicated as an argument, + * which is either of tlv::Interest, tlv::Data, or lp::tlv::Nack. + * The callback may retrieve the packet from sentInterests.back(), sentData.back(), or sentNacks.back(). + */ + signal::Signal& afterSend; - signal::Signal afterSend; +private: + LinkService* + getLinkServiceInternal(); + + DummyTransport* + getTransportInternal(); public: - std::vector m_sentInterests; - std::vector m_sentDatas; + std::vector& sentInterests; + std::vector& sentData; + std::vector& sentNacks; }; -class DummyLocalFace : public DummyFace -{ -public: - explicit - DummyLocalFace(const std::string& remoteUri = "dummy://", const std::string& localUri = "dummy://") - : DummyFace(remoteUri, localUri, true) - { - } -}; +} // namespace tests +} // namespace face +namespace tests { +using nfd::face::tests::DummyFace; } // namespace tests } // namespace nfd diff --git a/tests/daemon/face/dummy-lp-face.hpp b/tests/daemon/face/dummy-lp-face.hpp deleted file mode 100644 index 588cb59b..00000000 --- a/tests/daemon/face/dummy-lp-face.hpp +++ /dev/null @@ -1,99 +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 . - */ - -#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& afterSend; - -private: - LinkService* - getLinkServiceInternal(); - - DummyTransport* - getTransportInternal(); - -public: - std::vector& sentInterests; - std::vector& sentData; - std::vector& 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-stream-sender.hpp b/tests/daemon/face/dummy-stream-sender.hpp deleted file mode 100644 index 7cbb4e2a..00000000 --- a/tests/daemon/face/dummy-stream-sender.hpp +++ /dev/null @@ -1,116 +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 . - */ - -#ifndef NFD_TESTS_DAEMON_FACE_DUMMY_STREAM_SENDER_HPP -#define NFD_TESTS_DAEMON_FACE_DUMMY_STREAM_SENDER_HPP - -#include "core/scheduler.hpp" -#include "core/global-io.hpp" - -namespace nfd { -namespace tests { - - -template -class DummyStreamSender : public Dataset -{ -public: - typedef typename Protocol::endpoint Endpoint; - typedef typename Protocol::socket Socket; - - class Error : public std::runtime_error - { - public: - explicit - Error(const std::string& what) - : std::runtime_error(what) - { - } - }; - - DummyStreamSender() - : socket(getGlobalIoService()) - { - } - - void - start(const Endpoint& endpoint) - { - socket.async_connect(endpoint, - bind(&DummyStreamSender::onSuccessfullConnect, this, _1)); - } - - void - onSuccessfullConnect(const boost::system::error_code& error) - { - if (error) - { - BOOST_THROW_EXCEPTION(Error("Connection aborted")); - } - - // This value may need to be adjusted if some dataset exceeds 100k - socket.set_option(boost::asio::socket_base::send_buffer_size(100000)); - - for (typename Dataset::Container::iterator i = this->data.begin(); - i != this->data.end(); ++i) - { - socket.async_send(boost::asio::buffer(*i), - bind(&DummyStreamSender::onSendFinished, this, _1, false)); - } - - socket.async_send(boost::asio::buffer(static_cast(0), 0), - bind(&DummyStreamSender::onSendFinished, this, _1, true)); - } - - void - onSendFinished(const boost::system::error_code& error, bool isFinal) - { - if (error) { - BOOST_THROW_EXCEPTION(Error("Connection aborted")); - } - - if (isFinal) { - scheduler::schedule(ndn::time::seconds(1), - bind(&DummyStreamSender::stop, this)); - } - } - - void - stop() - { - // Terminate test - boost::system::error_code error; - socket.shutdown(Socket::shutdown_both, error); - socket.close(error); - } - -public: - Socket socket; -}; - -} // namespace tests -} // namespace nfd - -#endif // NFD_TESTS_DAEMON_FACE_DUMMY_STREAM_SENDER_HPP diff --git a/tests/daemon/face/dummy-transport.hpp b/tests/daemon/face/dummy-transport.hpp index ce2833b3..f957e1e3 100644 --- a/tests/daemon/face/dummy-transport.hpp +++ b/tests/daemon/face/dummy-transport.hpp @@ -91,6 +91,7 @@ private: doClose() DECL_OVERRIDE { isClosed = true; + this->setState(TransportState::CLOSED); } virtual void diff --git a/tests/daemon/face/ethernet-factory.t.cpp b/tests/daemon/face/ethernet-factory.t.cpp new file mode 100644 index 00000000..6148b3b8 --- /dev/null +++ b/tests/daemon/face/ethernet-factory.t.cpp @@ -0,0 +1,91 @@ +/* -*- 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 . + */ + +#include "face/ethernet-factory.hpp" + +#include "network-interface-fixture.hpp" + +namespace nfd { +namespace tests { + +using nfd::face::tests::NetworkInterfaceFixture; + +BOOST_AUTO_TEST_SUITE(Face) +BOOST_FIXTURE_TEST_SUITE(TestEthernetFactory, NetworkInterfaceFixture) + +BOOST_AUTO_TEST_CASE(GetChannels) +{ + EthernetFactory factory; + + auto channels = factory.getChannels(); + BOOST_CHECK_EQUAL(channels.empty(), true); +} + +BOOST_AUTO_TEST_CASE(MulticastFacesMap) +{ + SKIP_IF_NETWORK_INTERFACE_COUNT_LT(1); + + EthernetFactory factory; + auto face1 = factory.createMulticastFace(m_interfaces.front(), ethernet::getBroadcastAddress()); + auto face1bis = factory.createMulticastFace(m_interfaces.front(), ethernet::getBroadcastAddress()); + BOOST_CHECK_EQUAL(face1, face1bis); + + auto face2 = factory.createMulticastFace(m_interfaces.front(), ethernet::getDefaultMulticastAddress()); + BOOST_CHECK_NE(face1, face2); + + SKIP_IF_NETWORK_INTERFACE_COUNT_LT(2); + + auto face3 = factory.createMulticastFace(m_interfaces.back(), ethernet::getBroadcastAddress()); + BOOST_CHECK_NE(face1, face3); +} + +BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) +{ + EthernetFactory factory; + + BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"), + ndn::nfd::FACE_PERSISTENCY_PERMANENT, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); + + BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"), + ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); + + BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"), + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); +} + +BOOST_AUTO_TEST_SUITE_END() // TestEthernetFactory +BOOST_AUTO_TEST_SUITE_END() // Face + +} // namespace tests +} // namespace nfd diff --git a/tests/daemon/face/ethernet-transport.t.cpp b/tests/daemon/face/ethernet-transport.t.cpp index 1e021736..f7948a26 100644 --- a/tests/daemon/face/ethernet-transport.t.cpp +++ b/tests/daemon/face/ethernet-transport.t.cpp @@ -52,6 +52,10 @@ BOOST_AUTO_TEST_CASE(StaticProperties) BOOST_CHECK_EQUAL(transport.getLinkType(), ndn::nfd::LINK_TYPE_MULTI_ACCESS); } +// TODO add the equivalent of these test cases from ethernet.t.cpp as of commit:65caf200924b28748037750449e28bcb548dbc9c +// SendPacket +// ProcessIncomingPacket + BOOST_AUTO_TEST_SUITE_END() // TestEthernetTransport BOOST_AUTO_TEST_SUITE_END() // Face diff --git a/tests/daemon/face/ethernet.t.cpp b/tests/daemon/face/ethernet.t.cpp deleted file mode 100644 index 2b1d2de4..00000000 --- a/tests/daemon/face/ethernet.t.cpp +++ /dev/null @@ -1,231 +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 . - */ - -#include "face/ethernet-factory.hpp" -#include "face/ethernet-transport.hpp" - -#include "face/lp-face-wrapper.hpp" -#include "network-interface-fixture.hpp" - -#include - -namespace nfd { -namespace tests { - -using nfd::face::tests::NetworkInterfaceFixture; - -BOOST_AUTO_TEST_SUITE(Face) -BOOST_FIXTURE_TEST_SUITE(TestEthernet, NetworkInterfaceFixture) - -using nfd::Face; - -BOOST_AUTO_TEST_CASE(GetChannels) -{ - EthernetFactory factory; - - auto channels = factory.getChannels(); - BOOST_CHECK_EQUAL(channels.empty(), true); -} - -BOOST_AUTO_TEST_CASE(MulticastFacesMap) -{ - SKIP_IF_NETWORK_INTERFACE_COUNT_LT(1); - - EthernetFactory factory; - auto face1 = factory.createMulticastFace(m_interfaces.front(), ethernet::getBroadcastAddress()); - auto face1bis = factory.createMulticastFace(m_interfaces.front(), ethernet::getBroadcastAddress()); - BOOST_CHECK_EQUAL(face1, face1bis); - - auto face2 = factory.createMulticastFace(m_interfaces.front(), ethernet::getDefaultMulticastAddress()); - BOOST_CHECK_NE(face1, face2); - - SKIP_IF_NETWORK_INTERFACE_COUNT_LT(2); - - auto face3 = factory.createMulticastFace(m_interfaces.back(), ethernet::getBroadcastAddress()); - BOOST_CHECK_NE(face1, face3); -} - -BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) -{ - EthernetFactory factory; - - BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"), - ndn::nfd::FACE_PERSISTENCY_PERMANENT, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); - - BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"), - ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); - - BOOST_CHECK_THROW(factory.createFace(FaceUri("ether://[08:00:27:01:01:01]"), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); -} - -BOOST_AUTO_TEST_CASE(SendPacket) -{ - SKIP_IF_NETWORK_INTERFACE_COUNT_LT(1); - - EthernetFactory factory; - auto face = factory.createMulticastFace(m_interfaces.front(), ethernet::getDefaultMulticastAddress()); - - BOOST_REQUIRE(static_cast(face)); - BOOST_CHECK_EQUAL(face->isLocal(), false); - BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT); - BOOST_CHECK_EQUAL(face->isMultiAccess(), true); - BOOST_CHECK_EQUAL(face->getRemoteUri().toString(), - "ether://[" + ethernet::getDefaultMulticastAddress().toString() + "]"); - BOOST_CHECK_EQUAL(face->getLocalUri().toString(), - "dev://" + m_interfaces.front().name); - BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 0); - BOOST_CHECK_EQUAL(face->getCounters().nOutBytes, 0); - - face->onFail.connect([] (const std::string& reason) { BOOST_FAIL(reason); }); - - shared_ptr interest1 = makeInterest("ndn:/TpnzGvW9R"); - shared_ptr data1 = makeData("ndn:/KfczhUqVix"); - shared_ptr interest2 = makeInterest("ndn:/QWiIMfj5sL"); - shared_ptr data2 = makeData("ndn:/XNBV796f"); - - face->sendInterest(*interest1); - face->sendData (*data1 ); - face->sendInterest(*interest2); - face->sendData (*data2 ); - - BOOST_CHECK_EQUAL(face->getCounters().nOutBytes, - interest1->wireEncode().size() + - data1->wireEncode().size() + - interest2->wireEncode().size() + - data2->wireEncode().size()); -} - -BOOST_AUTO_TEST_CASE(ProcessIncomingPacket) -{ - SKIP_IF_NETWORK_INTERFACE_COUNT_LT(1); - - EthernetFactory factory; - auto face = factory.createMulticastFace(m_interfaces.front(), ethernet::getDefaultMulticastAddress()); - BOOST_REQUIRE(static_cast(face)); - - auto transport = dynamic_cast(face->getLpFace()->getTransport()); - BOOST_REQUIRE(transport != nullptr); - - std::vector recInterests; - std::vector recDatas; - - face->onFail.connect([] (const std::string& reason) { BOOST_FAIL(reason); }); - face->onReceiveInterest.connect( - [&recInterests] (const Interest& i) { recInterests.push_back(i); }); - face->onReceiveData.connect([&recDatas] (const Data& d) { recDatas.push_back(d); }); - - // check that packet data is not accessed if pcap didn't capture anything (caplen == 0) - static const pcap_pkthdr zeroHeader{}; - transport->processIncomingPacket(&zeroHeader, nullptr); - BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 0); - BOOST_CHECK_EQUAL(recInterests.size(), 0); - BOOST_CHECK_EQUAL(recDatas.size(), 0); - - // runt frame (too short) - pcap_pkthdr runtHeader{}; - runtHeader.caplen = ethernet::HDR_LEN + 6; - static const uint8_t packet2[ethernet::HDR_LEN + 6]{}; - transport->processIncomingPacket(&runtHeader, packet2); - BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 0); - BOOST_CHECK_EQUAL(recInterests.size(), 0); - BOOST_CHECK_EQUAL(recDatas.size(), 0); - - // valid frame, but TLV block has invalid length - pcap_pkthdr validHeader{}; - validHeader.caplen = ethernet::HDR_LEN + ethernet::MIN_DATA_LEN; - static const uint8_t packet3[ethernet::HDR_LEN + ethernet::MIN_DATA_LEN]{ - 0x01, 0x00, 0x5e, 0x00, 0x17, 0xaa, // destination address - 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, // source address - 0x86, 0x24, // NDN ethertype - tlv::Interest, // TLV type - 0xfd, 0xff, 0xff // TLV length (invalid because greater than buffer size) - }; - transport->processIncomingPacket(&validHeader, packet3); - BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 0); - BOOST_CHECK_EQUAL(recInterests.size(), 0); - BOOST_CHECK_EQUAL(recDatas.size(), 0); - - // valid frame, but TLV block has invalid type - static const uint8_t packet4[ethernet::HDR_LEN + ethernet::MIN_DATA_LEN]{ - 0x01, 0x00, 0x5e, 0x00, 0x17, 0xaa, // destination address - 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, // source address - 0x86, 0x24, // NDN ethertype - 0x00, // TLV type (invalid) - 0x00 // TLV length - }; - transport->processIncomingPacket(&validHeader, packet4); - BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 2); - BOOST_CHECK_EQUAL(recInterests.size(), 0); - BOOST_CHECK_EQUAL(recDatas.size(), 0); - - // valid frame and valid NDNLPv2 packet, but invalid network-layer packet - static const uint8_t packet5[ethernet::HDR_LEN + ethernet::MIN_DATA_LEN]{ - 0x01, 0x00, 0x5e, 0x00, 0x17, 0xaa, // destination address - 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, // source address - 0x86, 0x24, // NDN ethertype - lp::tlv::LpPacket, 0x04, // start of NDNLPv2 packet - lp::tlv::Fragment, 0x02, // single fragment - 0x00, // TLV type (invalid) - 0x00 // TLV length - }; - transport->processIncomingPacket(&validHeader, packet5); - BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 8); - BOOST_CHECK_EQUAL(recInterests.size(), 0); - BOOST_CHECK_EQUAL(recDatas.size(), 0); - - // valid frame, valid NDNLPv2 packet, and valid NDN (interest) packet - static const uint8_t packet6[ethernet::HDR_LEN + ethernet::MIN_DATA_LEN]{ - 0x01, 0x00, 0x5e, 0x00, 0x17, 0xaa, // destination address - 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, // source address - 0x86, 0x24, // NDN ethertype - lp::tlv::LpPacket, 0x1a, // start of NDNLPv2 packet - lp::tlv::Fragment, 0x18, // single fragment - tlv::Interest, 0x16, // start of NDN packet - 0x07, 0x0e, 0x08, 0x07, 0x65, 0x78, // payload - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x08, - 0x03, 0x66, 0x6f, 0x6f, 0x0a, 0x04, - 0x03, 0xef, 0xe9, 0x7c - }; - transport->processIncomingPacket(&validHeader, packet6); - BOOST_CHECK_EQUAL(face->getCounters().nInBytes, 36); - BOOST_CHECK_EQUAL(recInterests.size(), 1); - BOOST_CHECK_EQUAL(recDatas.size(), 0); -} - -BOOST_AUTO_TEST_SUITE_END() // TestEthernet -BOOST_AUTO_TEST_SUITE_END() // Face - -} // namespace tests -} // namespace nfd diff --git a/tests/daemon/face/face.t.cpp b/tests/daemon/face/face.t.cpp index 4a94a58c..7d0dba0f 100644 --- a/tests/daemon/face/face.t.cpp +++ b/tests/daemon/face/face.t.cpp @@ -24,60 +24,89 @@ */ #include "face/face.hpp" -#include "dummy-face.hpp" #include "tests/test-common.hpp" +#include "dummy-face.hpp" namespace nfd { +namespace face { namespace tests { -BOOST_FIXTURE_TEST_SUITE(FaceFace, BaseFixture) +using namespace nfd::tests; -BOOST_AUTO_TEST_CASE(Description) +BOOST_AUTO_TEST_SUITE(Face) +BOOST_FIXTURE_TEST_SUITE(TestFace, BaseFixture) + +// TODO add test cases for getLinkService, getTransport +// TODO add a test case for static properties +// TODO add a test case for getState + +BOOST_AUTO_TEST_CASE(LinkServiceSendReceive) { - DummyFace face; - face.setDescription("3pFsKrvWr"); - BOOST_CHECK_EQUAL(face.getDescription(), "3pFsKrvWr"); + auto face1 = make_shared(); + + 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; + face1->afterReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; })); + face1->afterReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; })); + face1->afterReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; })); + + for (size_t i = 0; i < nInInterests; ++i) { + shared_ptr interest = makeInterest("/JSQdqward4"); + face1->receiveInterest(*interest); + } + + for (size_t i = 0; i < nInData; ++i) { + shared_ptr 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 = makeInterest("/XyUAFYQDmd"); + face1->sendInterest(*interest); + } + + for (size_t i = 0; i < nOutData; ++i) { + shared_ptr data = makeData("/GigPEtPH6"); + face1->sendData(*data); + } + + for (size_t i = 0; i < nOutNacks; ++i) { + lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION); + face1->sendNack(nack); + } + + BOOST_CHECK_EQUAL(face1->getCounters().nInInterests, nInInterests); + BOOST_CHECK_EQUAL(face1->getCounters().nInData, nInData); + BOOST_CHECK_EQUAL(face1->getCounters().nInNacks, nInNacks); + BOOST_CHECK_EQUAL(face1->getCounters().nOutInterests, nOutInterests); + BOOST_CHECK_EQUAL(face1->getCounters().nOutData, nOutData); + BOOST_CHECK_EQUAL(face1->getCounters().nOutNacks, nOutNacks); + + 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); } -class FaceFailTestFace : public DummyFace -{ -public: - FaceFailTestFace() - : failCount(0) - { - this->onFail.connect(bind(&FaceFailTestFace::failHandler, this, _1)); - } - - void - failOnce() - { - this->fail("reason"); - } - -private: - void - failHandler(const std::string& reason) - { - BOOST_CHECK_EQUAL(reason, "reason"); - ++this->failCount; - } - -public: - int failCount; -}; - -BOOST_AUTO_TEST_CASE(FailTwice) -{ - FaceFailTestFace face; - BOOST_CHECK_EQUAL(face.failCount, 0); - face.failOnce(); - BOOST_CHECK_EQUAL(face.failCount, 1); - face.failOnce(); - BOOST_CHECK_EQUAL(face.failCount, 1); -} - -BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() // TestFace +BOOST_AUTO_TEST_SUITE_END() // Face } // namespace tests +} // namespace face } // namespace nfd diff --git a/tests/daemon/face/generic-link-service.t.cpp b/tests/daemon/face/generic-link-service.t.cpp index 70e078d8..888c222e 100644 --- a/tests/daemon/face/generic-link-service.t.cpp +++ b/tests/daemon/face/generic-link-service.t.cpp @@ -24,7 +24,7 @@ */ #include "face/generic-link-service.hpp" -#include "face/lp-face.hpp" +#include "face/face.hpp" #include "dummy-transport.hpp" #include "tests/test-common.hpp" @@ -37,6 +37,8 @@ using namespace nfd::tests; BOOST_AUTO_TEST_SUITE(Face) +using nfd::Face; + class GenericLinkServiceFixture : public BaseFixture { protected: @@ -52,8 +54,8 @@ protected: void initialize(const GenericLinkService::Options& options) { - face.reset(new LpFace(make_unique(options), - make_unique())); + face.reset(new Face(make_unique(options), + make_unique())); service = static_cast(face->getLinkService()); transport = static_cast(face->getTransport()); @@ -66,7 +68,7 @@ protected: } protected: - unique_ptr face; + unique_ptr face; GenericLinkService* service; DummyTransport* transport; std::vector receivedInterests; diff --git a/tests/daemon/face/internal-face.t.cpp b/tests/daemon/face/internal-face.t.cpp index cca385e9..43713176 100644 --- a/tests/daemon/face/internal-face.t.cpp +++ b/tests/daemon/face/internal-face.t.cpp @@ -24,9 +24,8 @@ */ #include "face/internal-face.hpp" -#include "face/lp-face-wrapper.hpp" -#include "transport-test-common.hpp" +#include "transport-test-common.hpp" #include "tests/identity-management-fixture.hpp" namespace nfd { @@ -43,9 +42,7 @@ class InternalFaceFixture : public UnitTestTimeFixture public: InternalFaceFixture() { - std::tie(forwarderFaceW, clientFace) = makeInternalFace(m_keyChain);; - forwarderFace = static_pointer_cast(forwarderFaceW)->getLpFace(); - // TODO#3172 eliminate wrapper + std::tie(forwarderFace, clientFace) = makeInternalFace(m_keyChain);; forwarderFace->afterReceiveInterest.connect( [this] (const Interest& interest) { receivedInterests.push_back(interest); } ); @@ -56,8 +53,7 @@ public: } protected: - shared_ptr forwarderFaceW; - LpFace* forwarderFace; + shared_ptr forwarderFace; shared_ptr clientFace; std::vector receivedInterests; @@ -199,7 +195,7 @@ BOOST_AUTO_TEST_CASE(CloseForwarderFace) forwarderFace->close(); this->advanceClocks(time::milliseconds(1), 10); BOOST_CHECK_EQUAL(forwarderFace->getState(), FaceState::CLOSED); - forwarderFaceW.reset(); + forwarderFace.reset(); shared_ptr interest = makeInterest("/zpHsVesu0B"); interest->setInterestLifetime(time::milliseconds(100)); diff --git a/tests/daemon/face/lp-face-wrapper.t.cpp b/tests/daemon/face/lp-face-wrapper.t.cpp deleted file mode 100644 index 8217d77b..00000000 --- a/tests/daemon/face/lp-face-wrapper.t.cpp +++ /dev/null @@ -1,162 +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 . - */ - -#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(make_unique()); - auto face1 = static_cast(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(face1w->getId())); -} - -BOOST_AUTO_TEST_CASE(SetPersistency) -{ - unique_ptr face1u = make_unique(); - face1u->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); - - auto face1w = make_shared(std::move(face1u)); - auto face1 = static_cast(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(Counters) -{ - auto face1w = make_shared(make_unique()); - auto face1 = static_cast(face1w->getLpFace()); - - BOOST_CHECK(&face1->getCounters() == &face1w->getCounters()); -} - -BOOST_AUTO_TEST_CASE(FailSignal) -{ - auto face1w = make_shared(make_unique()); - auto face1 = static_cast(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(make_unique()); - auto face1 = static_cast(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; })); - - for (size_t i = 0; i < nInInterests; ++i) { - shared_ptr interest = makeInterest("/JSQdqward4"); - face1->receiveInterest(*interest); - } - - for (size_t i = 0; i < nInData; ++i) { - shared_ptr 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 = makeInterest("/XyUAFYQDmd"); - face1w->sendInterest(*interest); - } - - for (size_t i = 0; i < nOutData; ++i) { - shared_ptr 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(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/lp-face.t.cpp b/tests/daemon/face/lp-face.t.cpp deleted file mode 100644 index 92a3755e..00000000 --- a/tests/daemon/face/lp-face.t.cpp +++ /dev/null @@ -1,108 +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 . - */ - -#include "face/lp-face.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(TestLpFace, BaseFixture) - -BOOST_AUTO_TEST_CASE(LinkServiceSendReceive) -{ - auto face1 = make_shared(); - - 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; - face1->afterReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; })); - face1->afterReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; })); - face1->afterReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; })); - - for (size_t i = 0; i < nInInterests; ++i) { - shared_ptr interest = makeInterest("/JSQdqward4"); - face1->receiveInterest(*interest); - } - - for (size_t i = 0; i < nInData; ++i) { - shared_ptr 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 = makeInterest("/XyUAFYQDmd"); - face1->sendInterest(*interest); - } - - for (size_t i = 0; i < nOutData; ++i) { - shared_ptr data = makeData("/GigPEtPH6"); - face1->sendData(*data); - } - - for (size_t i = 0; i < nOutNacks; ++i) { - lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION); - face1->sendNack(nack); - } - - BOOST_CHECK_EQUAL(face1->getCounters().nInInterests, nInInterests); - BOOST_CHECK_EQUAL(face1->getCounters().nInData, nInData); - BOOST_CHECK_EQUAL(face1->getCounters().nInNacks, nInNacks); - BOOST_CHECK_EQUAL(face1->getCounters().nOutInterests, nOutInterests); - BOOST_CHECK_EQUAL(face1->getCounters().nOutData, nOutData); - BOOST_CHECK_EQUAL(face1->getCounters().nOutNacks, nOutNacks); - - 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/null-face.t.cpp b/tests/daemon/face/null-face.t.cpp index 16d1a115..40752455 100644 --- a/tests/daemon/face/null-face.t.cpp +++ b/tests/daemon/face/null-face.t.cpp @@ -24,7 +24,7 @@ */ #include "face/null-face.hpp" -#include "face/lp-face-wrapper.hpp" + #include "transport-test-common.hpp" namespace nfd { @@ -40,8 +40,7 @@ using nfd::Face; BOOST_AUTO_TEST_CASE(StaticProperties) { - shared_ptr faceW = makeNullFace(FaceUri("testnull://hhppt12sy")); - LpFace* face = static_pointer_cast(faceW)->getLpFace(); + shared_ptr face = makeNullFace(FaceUri("testnull://hhppt12sy")); checkStaticPropertiesInitialized(*face->getTransport()); BOOST_CHECK_EQUAL(face->getLocalUri(), FaceUri("testnull://hhppt12sy")); diff --git a/tests/daemon/face/packet-datasets.hpp b/tests/daemon/face/packet-datasets.hpp deleted file mode 100644 index 95639c17..00000000 --- a/tests/daemon/face/packet-datasets.hpp +++ /dev/null @@ -1,64 +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 . - */ - -#ifndef NFD_TESTS_DAEMON_FACE_PACKET_DATASETS_HPP -#define NFD_TESTS_DAEMON_FACE_PACKET_DATASETS_HPP - -#include "tests/test-common.hpp" - -namespace nfd { -namespace tests { - -class CorruptedInterest -{ -public: - typedef std::vector Container; - - static std::string - getName() - { - return "CorruptedInterest"; - } - - CorruptedInterest() - { - static const uint8_t interest[] = { - 0x05, 0x1d, 0x07, 0x84, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64, - 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x01, - 0x01 - }; - - data.push_back(ndn::Buffer(interest, sizeof(interest))); - } -public: - Container data; -}; - -typedef boost::mpl::vector CorruptedPackets; - -} // namespace tests -} // namespace nfd - -#endif // NFD_TESTS_DAEMON_FACE_PACKET_DATASETS_HPP diff --git a/daemon/face/lp-face.cpp b/tests/daemon/face/tcp-channel.t.cpp similarity index 68% rename from daemon/face/lp-face.cpp rename to tests/daemon/face/tcp-channel.t.cpp index 55cc4d08..816761d7 100644 --- a/daemon/face/lp-face.cpp +++ b/tests/daemon/face/tcp-channel.t.cpp @@ -23,24 +23,22 @@ * NFD, e.g., in COPYING.md file. If not, see . */ -#include "lp-face.hpp" +#include "face/tcp-channel.hpp" + +#include "tests/test-common.hpp" namespace nfd { -namespace face { +namespace tests { -LpFace::LpFace(unique_ptr service, unique_ptr 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)) - , m_counters(m_service->getCounters(), m_transport->getCounters()) -{ - m_service->setFaceAndTransport(*this, *m_transport); - m_transport->setFaceAndLinkService(*this, *m_service); -} +BOOST_AUTO_TEST_SUITE(Face) +BOOST_FIXTURE_TEST_SUITE(TestTcpChannel, BaseFixture) -} // namespace face +// TODO add the equivalent of these test cases from tcp.t.cpp as of commit:65caf200924b28748037750449e28bcb548dbc9c +// MultipleAccepts +// FaceClosing + +BOOST_AUTO_TEST_SUITE_END() // TestTcpChannel +BOOST_AUTO_TEST_SUITE_END() // Face + +} // namespace tests } // namespace nfd diff --git a/tests/daemon/face/tcp-factory.t.cpp b/tests/daemon/face/tcp-factory.t.cpp new file mode 100644 index 00000000..ee796ab9 --- /dev/null +++ b/tests/daemon/face/tcp-factory.t.cpp @@ -0,0 +1,258 @@ +/* -*- 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 . + */ + +#include "face/tcp-factory.hpp" + +#include "core/network-interface.hpp" +#include "tests/test-common.hpp" +#include "tests/limited-io.hpp" + +namespace nfd { +namespace tests { + +BOOST_AUTO_TEST_SUITE(Face) +BOOST_FIXTURE_TEST_SUITE(TestTcpFactory, BaseFixture) + +using nfd::Face; + +BOOST_AUTO_TEST_CASE(ChannelMap) +{ + TcpFactory factory; + + shared_ptr channel1 = factory.createChannel("127.0.0.1", "20070"); + shared_ptr channel1a = factory.createChannel("127.0.0.1", "20070"); + BOOST_CHECK_EQUAL(channel1, channel1a); + BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070"); + + shared_ptr channel2 = factory.createChannel("127.0.0.1", "20071"); + BOOST_CHECK_NE(channel1, channel2); + + shared_ptr channel3 = factory.createChannel("::1", "20071"); + BOOST_CHECK_NE(channel2, channel3); + BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071"); +} + +BOOST_AUTO_TEST_CASE(GetChannels) +{ + TcpFactory factory; + BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); + + std::vector> expectedChannels; + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); + expectedChannels.push_back(factory.createChannel("::1", "20071")); + + for (const auto& ch : factory.getChannels()) { + auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), ch); + BOOST_REQUIRE(pos != expectedChannels.end()); + expectedChannels.erase(pos); + } + BOOST_CHECK_EQUAL(expectedChannels.size(), 0); +} + +class FaceCreateFixture : public BaseFixture +{ +public: + void + checkError(const std::string& errorActual, const std::string& errorExpected) + { + BOOST_CHECK_EQUAL(errorActual, errorExpected); + } + + void + failIfError(const std::string& errorActual) + { + BOOST_FAIL("No error expected, but got: [" << errorActual << "]"); + } +}; + +BOOST_FIXTURE_TEST_CASE(FaceCreate, FaceCreateFixture) +{ + TcpFactory factory; + + factory.createFace(FaceUri("tcp4://127.0.0.1:6363"), + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + bind([]{}), + bind(&FaceCreateFixture::checkError, this, _1, + "No channels available to connect to 127.0.0.1:6363")); + + factory.createChannel("127.0.0.1", "20071"); + + factory.createFace(FaceUri("tcp4://127.0.0.1:20070"), + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + bind([]{}), + bind(&FaceCreateFixture::failIfError, this, _1)); +} + +BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) +{ + TcpFactory factory; + + factory.createChannel("127.0.0.1", "20070"); + factory.createChannel("127.0.0.1", "20071"); + + BOOST_CHECK_THROW(factory.createFace(FaceUri("tcp4://127.0.0.1:20070"), + ndn::nfd::FACE_PERSISTENCY_PERMANENT, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); + + BOOST_CHECK_THROW(factory.createFace(FaceUri("tcp4://127.0.0.1:20071"), + ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); +} + +class FaceCreateTimeoutFixture : public BaseFixture +{ +public: + void + onFaceCreated(const shared_ptr& newFace) + { + BOOST_CHECK_MESSAGE(false, "Timeout expected"); + BOOST_CHECK(!static_cast(face1)); + face1 = newFace; + + limitedIo.afterOp(); + } + + void + onConnectFailed(const std::string& reason) + { + BOOST_CHECK_MESSAGE(true, reason); + + limitedIo.afterOp(); + } + +public: + LimitedIo limitedIo; + + shared_ptr face1; +}; + +BOOST_FIXTURE_TEST_CASE(FaceCreateTimeout, FaceCreateTimeoutFixture) +{ + TcpFactory factory; + shared_ptr channel = factory.createChannel("0.0.0.0", "20070"); + + factory.createFace(FaceUri("tcp4://192.0.2.1:20070"), + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + bind(&FaceCreateTimeoutFixture::onFaceCreated, this, _1), + bind(&FaceCreateTimeoutFixture::onConnectFailed, this, _1)); + + BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(10)) == LimitedIo::EXCEED_OPS, + "TcpChannel error: cannot connect or cannot accept connection"); + + BOOST_CHECK_EQUAL(static_cast(face1), false); +} + +class FakeNetworkInterfaceFixture : public BaseFixture +{ +public: + FakeNetworkInterfaceFixture() + { + using namespace boost::asio::ip; + + auto fakeInterfaces = make_shared>(); + + fakeInterfaces->push_back( + NetworkInterfaceInfo {0, "eth0", + ethernet::Address::fromString("3e:15:c2:8b:65:00"), + {address_v4::from_string("0.0.0.0")}, + {address_v6::from_string("::")}, + address_v4(), + IFF_UP}); + fakeInterfaces->push_back( + NetworkInterfaceInfo {1, "eth0", + ethernet::Address::fromString("3e:15:c2:8b:65:00"), + {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")}, + {}, + address_v4::from_string("192.168.2.255"), + 0}); + fakeInterfaces->push_back( + NetworkInterfaceInfo {2, "eth1", + ethernet::Address::fromString("3e:15:c2:8b:65:00"), + {address_v4::from_string("198.51.100.1")}, + {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")}, + address_v4::from_string("198.51.100.255"), + IFF_MULTICAST | IFF_BROADCAST | IFF_UP}); + + setDebugNetworkInterfaces(fakeInterfaces); + } + + ~FakeNetworkInterfaceFixture() + { + setDebugNetworkInterfaces(nullptr); + } +}; + +BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture) +{ + using namespace boost::asio::ip; + + TcpFactory factory; + factory.prohibitEndpoint(tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024)); + BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); + BOOST_CHECK((factory.m_prohibitedEndpoints == + std::set { + tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), + })); + + factory.m_prohibitedEndpoints.clear(); + factory.prohibitEndpoint(tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048)); + BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); + BOOST_CHECK((factory.m_prohibitedEndpoints == + std::set { + tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048) + })); + + factory.m_prohibitedEndpoints.clear(); + factory.prohibitEndpoint(tcp::Endpoint(address_v4(), 1024)); + BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 4); + BOOST_CHECK((factory.m_prohibitedEndpoints == + std::set { + tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), + tcp::Endpoint(address_v4::from_string("192.168.2.2"), 1024), + tcp::Endpoint(address_v4::from_string("198.51.100.1"), 1024), + tcp::Endpoint(address_v4::from_string("0.0.0.0"), 1024) + })); + + factory.m_prohibitedEndpoints.clear(); + factory.prohibitEndpoint(tcp::Endpoint(address_v6(), 2048)); + BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3); + BOOST_CHECK((factory.m_prohibitedEndpoints == + std::set { + tcp::Endpoint(address_v6::from_string("2001:db8::2"), 2048), + tcp::Endpoint(address_v6::from_string("2001:db8::3"), 2048), + tcp::Endpoint(address_v6::from_string("::"), 2048) + })); +} + +BOOST_AUTO_TEST_SUITE_END() // TestTcpFactory +BOOST_AUTO_TEST_SUITE_END() // Face + +} // namespace tests +} // namespace nfd diff --git a/tests/daemon/face/tcp-transport-fixture.hpp b/tests/daemon/face/tcp-transport-fixture.hpp index 38be67bf..e68eff9f 100644 --- a/tests/daemon/face/tcp-transport-fixture.hpp +++ b/tests/daemon/face/tcp-transport-fixture.hpp @@ -27,7 +27,7 @@ #define NFD_TESTS_DAEMON_FACE_TCP_TRANSPORT_FIXTURE_HPP #include "face/tcp-transport.hpp" -#include "face/lp-face.hpp" +#include "face/face.hpp" #include "dummy-receive-link-service.hpp" #include "tests/limited-io.hpp" @@ -73,9 +73,9 @@ protected: BOOST_REQUIRE_EQUAL(limitedIo.run(2, time::seconds(1)), LimitedIo::EXCEED_OPS); localEp = sock.local_endpoint(); - face = make_unique(make_unique(), - make_unique(std::move(sock), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT)); + face = make_unique(make_unique(), + make_unique(std::move(sock), + ndn::nfd::FACE_PERSISTENCY_PERSISTENT)); transport = static_cast(face->getTransport()); receivedPackets = &static_cast(face->getLinkService())->receivedPackets; @@ -103,7 +103,7 @@ protected: private: tcp::acceptor acceptor; - unique_ptr face; + unique_ptr face; }; } // namespace tests diff --git a/tests/daemon/face/tcp.t.cpp b/tests/daemon/face/tcp.t.cpp deleted file mode 100644 index 6d5fe195..00000000 --- a/tests/daemon/face/tcp.t.cpp +++ /dev/null @@ -1,758 +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 . - */ - -#include "face/tcp-channel.hpp" -#include "face/tcp-factory.hpp" - -#include "core/network-interface.hpp" -#include "tests/test-common.hpp" -#include "tests/limited-io.hpp" -#include "dummy-stream-sender.hpp" -#include "packet-datasets.hpp" - -namespace nfd { -namespace tests { - -BOOST_AUTO_TEST_SUITE(Face) -BOOST_FIXTURE_TEST_SUITE(TestTcp, BaseFixture) - -using nfd::Face; - -BOOST_AUTO_TEST_CASE(ChannelMap) -{ - TcpFactory factory; - - shared_ptr channel1 = factory.createChannel("127.0.0.1", "20070"); - shared_ptr channel1a = factory.createChannel("127.0.0.1", "20070"); - BOOST_CHECK_EQUAL(channel1, channel1a); - BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070"); - - shared_ptr channel2 = factory.createChannel("127.0.0.1", "20071"); - BOOST_CHECK_NE(channel1, channel2); - - shared_ptr channel3 = factory.createChannel("::1", "20071"); - BOOST_CHECK_NE(channel2, channel3); - BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071"); -} - -BOOST_AUTO_TEST_CASE(GetChannels) -{ - TcpFactory factory; - BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); - - std::vector> expectedChannels; - expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); - expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); - expectedChannels.push_back(factory.createChannel("::1", "20071")); - - for (const auto& ch : factory.getChannels()) { - auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), ch); - BOOST_REQUIRE(pos != expectedChannels.end()); - expectedChannels.erase(pos); - } - BOOST_CHECK_EQUAL(expectedChannels.size(), 0); -} - -class FaceCreateFixture : protected BaseFixture -{ -public: - void - checkError(const std::string& errorActual, const std::string& errorExpected) - { - BOOST_CHECK_EQUAL(errorActual, errorExpected); - } - - void - failIfError(const std::string& errorActual) - { - BOOST_FAIL("No error expected, but got: [" << errorActual << "]"); - } -}; - -BOOST_FIXTURE_TEST_CASE(FaceCreate, FaceCreateFixture) -{ - TcpFactory factory; - - factory.createFace(FaceUri("tcp4://127.0.0.1:6363"), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - bind([]{}), - bind(&FaceCreateFixture::checkError, this, _1, - "No channels available to connect to 127.0.0.1:6363")); - - factory.createChannel("127.0.0.1", "20071"); - - factory.createFace(FaceUri("tcp4://127.0.0.1:20070"), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - bind([]{}), - bind(&FaceCreateFixture::failIfError, this, _1)); -} - -BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) -{ - TcpFactory factory; - - factory.createChannel("127.0.0.1", "20070"); - factory.createChannel("127.0.0.1", "20071"); - - BOOST_CHECK_THROW(factory.createFace(FaceUri("tcp4://127.0.0.1:20070"), - ndn::nfd::FACE_PERSISTENCY_PERMANENT, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); - - BOOST_CHECK_THROW(factory.createFace(FaceUri("tcp4://127.0.0.1:20071"), - ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); -} - -class EndToEndFixture : protected BaseFixture -{ -public: - void - channel1_onFaceCreated(const shared_ptr& newFace) - { - BOOST_CHECK(!static_cast(face1)); - face1 = newFace; - face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1)); - face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1)); - face1->onFail.connect(bind(&EndToEndFixture::face1_onFail, this)); - - limitedIo.afterOp(); - } - - void - channel1_onConnectFailed(const std::string& reason) - { - BOOST_CHECK_MESSAGE(false, reason); - - limitedIo.afterOp(); - } - - void - face1_onReceiveInterest(const Interest& interest) - { - face1_receivedInterests.push_back(interest); - - limitedIo.afterOp(); - } - - void - face1_onReceiveData(const Data& data) - { - face1_receivedDatas.push_back(data); - - limitedIo.afterOp(); - } - - void - face1_onFail() - { - g_io.post([this] { - face1.reset(); - limitedIo.afterOp(); - }); - } - - void - channel2_onFaceCreated(const shared_ptr& newFace) - { - BOOST_CHECK(!static_cast(face2)); - face2 = newFace; - face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1)); - face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1)); - face2->onFail.connect(bind(&EndToEndFixture::face2_onFail, this)); - - limitedIo.afterOp(); - } - - void - channel2_onConnectFailed(const std::string& reason) - { - BOOST_CHECK_MESSAGE(false, reason); - - limitedIo.afterOp(); - } - - void - face2_onReceiveInterest(const Interest& interest) - { - face2_receivedInterests.push_back(interest); - - limitedIo.afterOp(); - } - - void - face2_onReceiveData(const Data& data) - { - face2_receivedDatas.push_back(data); - - limitedIo.afterOp(); - } - - void - face2_onFail() - { - g_io.post([this] { - face2.reset(); - limitedIo.afterOp(); - }); - } - - void - channel_onFaceCreated(const shared_ptr& newFace) - { - faces.push_back(newFace); - limitedIo.afterOp(); - } - - void - channel_onConnectFailed(const std::string& reason) - { - BOOST_CHECK_MESSAGE(false, reason); - - limitedIo.afterOp(); - } - - void - checkFaceList(size_t shouldBe) - { - BOOST_CHECK_EQUAL(faces.size(), shouldBe); - } - - void - connect(const shared_ptr& channel, - const std::string& remoteHost, - const std::string& remotePort) - { - channel->connect(tcp::Endpoint(boost::asio::ip::address::from_string(remoteHost), - boost::lexical_cast(remotePort)), - bind(&EndToEndFixture::channel_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); - } - -public: - LimitedIo limitedIo; - - shared_ptr face1; - std::vector face1_receivedInterests; - std::vector face1_receivedDatas; - shared_ptr face2; - std::vector face2_receivedInterests; - std::vector face2_receivedDatas; - - std::list> faces; -}; - -BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture) -{ - TcpFactory factory1; - - shared_ptr channel1 = factory1.createChannel("127.0.0.1", "20070"); - factory1.createChannel("127.0.0.1", "20071"); - - BOOST_CHECK_EQUAL(channel1->isListening(), false); - - channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); - - BOOST_CHECK_EQUAL(channel1->isListening(), true); - - TcpFactory factory2; - - shared_ptr channel2 = factory2.createChannel("127.0.0.2", "20070"); - factory2.createChannel("127.0.0.2", "20071"); - - factory2.createFace(FaceUri("tcp4://127.0.0.1:20070"), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); - - BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "TcpChannel error: cannot connect or cannot accept connection"); - - BOOST_REQUIRE(static_cast(face1)); - BOOST_REQUIRE(static_cast(face2)); - - BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); - BOOST_CHECK_EQUAL(face2->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); - BOOST_CHECK_EQUAL(face1->isMultiAccess(), false); - BOOST_CHECK_EQUAL(face2->isMultiAccess(), false); - - BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "tcp4://127.0.0.1:20070"); - BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "tcp4://127.0.0.1:20070"); - // face1 has an unknown remoteUri, since the source port is automatically chosen by OS - - BOOST_CHECK_EQUAL(face1->isLocal(), true); - BOOST_CHECK_EQUAL(face2->isLocal(), true); - - shared_ptr interest1 = makeInterest("ndn:/TpnzGvW9R"); - shared_ptr data1 = makeData("ndn:/KfczhUqVix"); - shared_ptr interest2 = makeInterest("ndn:/QWiIMfj5sL"); - shared_ptr data2 = makeData("ndn:/XNBV796f"); - - face1->sendInterest(*interest1); - face1->sendInterest(*interest1); - face1->sendInterest(*interest1); - face1->sendData (*data1 ); - size_t nBytesSent1 = interest1->wireEncode().size() * 3 + data1->wireEncode().size(); - face2->sendInterest(*interest2); - face2->sendData (*data2 ); - face2->sendData (*data2 ); - face2->sendData (*data2 ); - - BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "TcpChannel error: cannot send or receive Interest/Data packets"); - - BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); - BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3); - BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3); - BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); - - BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName()); - BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName()); - BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName()); - BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName()); - - // needed to ensure NOutBytes counters are accurate - limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1)); - - const face::FaceCounters& counters1 = face1->getCounters(); - BOOST_CHECK_EQUAL(counters1.nInInterests, 1); - BOOST_CHECK_EQUAL(counters1.nInData, 3); - BOOST_CHECK_EQUAL(counters1.nOutInterests, 3); - BOOST_CHECK_EQUAL(counters1.nOutData, 1); - BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent1); - - const face::FaceCounters& counters2 = face2->getCounters(); - BOOST_CHECK_EQUAL(counters2.nInInterests, 3); - BOOST_CHECK_EQUAL(counters2.nInData, 1); - BOOST_CHECK_EQUAL(counters2.nOutInterests, 1); - BOOST_CHECK_EQUAL(counters2.nOutData, 3); - BOOST_CHECK_EQUAL(counters2.nInBytes, nBytesSent1); -} - -BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture) -{ - TcpFactory factory1; - - shared_ptr channel1 = factory1.createChannel("::1", "20070"); - shared_ptr channel2 = factory1.createChannel("::1", "20071"); - - channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); - - TcpFactory factory2; - - factory2.createChannel("::2", "20070"); - - factory2.createFace(FaceUri("tcp6://[::1]:20070"), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); - - BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "TcpChannel error: cannot connect or cannot accept connection"); - - BOOST_REQUIRE(static_cast(face1)); - BOOST_REQUIRE(static_cast(face2)); - - BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "tcp6://[::1]:20070"); - BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "tcp6://[::1]:20070"); - // face1 has an unknown remoteUri, since the source port is automatically chosen by OS - - BOOST_CHECK_EQUAL(face1->isLocal(), true); - BOOST_CHECK_EQUAL(face2->isLocal(), true); - - shared_ptr interest1 = makeInterest("ndn:/TpnzGvW9R"); - shared_ptr data1 = makeData("ndn:/KfczhUqVix"); - shared_ptr interest2 = makeInterest("ndn:/QWiIMfj5sL"); - shared_ptr data2 = makeData("ndn:/XNBV796f"); - - face1->sendInterest(*interest1); - face1->sendData (*data1 ); - face2->sendInterest(*interest2); - face2->sendData (*data2 ); - - BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "TcpChannel error: cannot send or receive Interest/Data packets"); - - - BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); - BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); - BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); - BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); - - BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName()); - BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName()); - BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName()); - BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName()); -} - -BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) -{ - TcpFactory factory; - - shared_ptr channel1 = factory.createChannel("127.0.0.1", "20070"); - shared_ptr channel2 = factory.createChannel("127.0.0.1", "20071"); - - channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); - - using namespace boost::asio; - channel2->connect(tcp::Endpoint(ip::address::from_string("127.0.0.1"), 20070), - bind(&EndToEndFixture::channel_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel_onConnectFailed, this, _1), - time::seconds(4)); // very short timeout - - BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "TcpChannel error: cannot connect or cannot accept connection"); - - - BOOST_CHECK_EQUAL(faces.size(), 2); - - shared_ptr channel3 = factory.createChannel("127.0.0.1", "20072"); - channel3->connect(tcp::Endpoint(ip::address::from_string("127.0.0.1"), 20070), - bind(&EndToEndFixture::channel_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel_onConnectFailed, this, _1), - time::seconds(4)); // very short timeout - - - shared_ptr channel4 = factory.createChannel("127.0.0.1", "20073"); - - BOOST_CHECK_NE(channel3, channel4); - - scheduler::schedule(time::seconds(1), - bind(&EndToEndFixture::connect, this, channel4, "127.0.0.1", "20070")); - - scheduler::schedule(time::milliseconds(500), - bind(&EndToEndFixture::checkFaceList, this, 4)); - - BOOST_CHECK_MESSAGE(limitedIo.run(4,// 2 connects and 2 accepts - time::seconds(10)) == LimitedIo::EXCEED_OPS, - "TcpChannel error: cannot connect or cannot accept multiple connections"); - - BOOST_CHECK_EQUAL(faces.size(), 6); -} - -BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) -{ - TcpFactory factory; - - shared_ptr channel1 = factory.createChannel("127.0.0.1", "20070"); - shared_ptr channel2 = factory.createChannel("127.0.0.1", "20071"); - - channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); - - using namespace boost::asio; - channel2->connect(tcp::Endpoint(ip::address::from_string("127.0.0.1"), 20070), - bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel2_onConnectFailed, this, _1), - time::seconds(4)); // very short timeout - - BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "TcpChannel error: cannot connect or cannot accept connection"); - - BOOST_CHECK_EQUAL(channel1->size(), 1); - BOOST_CHECK_EQUAL(channel2->size(), 1); - - BOOST_REQUIRE(static_cast(face1)); - BOOST_CHECK(static_cast(face2)); - - // Face::close must be invoked during io run to be counted as an op - scheduler::schedule(time::milliseconds(100), bind(&Face::close, face1)); - - BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "FaceClosing error: cannot properly close faces"); - - // both faces should get closed - BOOST_CHECK(!static_cast(face1)); - BOOST_CHECK(!static_cast(face2)); - - BOOST_CHECK_EQUAL(channel1->size(), 0); - BOOST_CHECK_EQUAL(channel2->size(), 0); -} - -class SimpleEndToEndFixture : protected BaseFixture -{ -public: - void - onFaceCreated(const shared_ptr& 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)); - - limitedIo.afterOp(); - } - - void - onConnectFailed(const std::string& reason) - { - BOOST_CHECK_MESSAGE(false, reason); - - limitedIo.afterOp(); - } - - void - onReceiveInterest(const Interest& interest) - { - receivedInterests.push_back(interest); - - limitedIo.afterOp(); - } - - void - onReceiveData(const Data& data) - { - receivedDatas.push_back(data); - - limitedIo.afterOp(); - } - - void - onFail(const shared_ptr& face) - { - limitedIo.afterOp(); - } - -public: - LimitedIo limitedIo; - - std::vector receivedInterests; - std::vector receivedDatas; -}; - -BOOST_FIXTURE_TEST_CASE_TEMPLATE(FaceCorruptedInput, Dataset, - CorruptedPackets, SimpleEndToEndFixture) -{ - // test with non-local Face - boost::asio::ip::address_v4 someIpv4Address; - for (const auto& netif : listNetworkInterfaces()) { - if (!netif.isLoopback() && netif.isUp() && !netif.ipv4Addresses.empty()) { - someIpv4Address = netif.ipv4Addresses.front(); - break; - } - } - if (someIpv4Address.is_unspecified()) { - BOOST_TEST_MESSAGE("Test with non-local Face cannot be run " - "(no non-loopback interface with IPv4 address found)"); - return; - } - - TcpFactory factory; - tcp::Endpoint endpoint(someIpv4Address, 20070); - - shared_ptr channel = factory.createChannel(endpoint); - channel->listen(bind(&SimpleEndToEndFixture::onFaceCreated, this, _1), - bind(&SimpleEndToEndFixture::onConnectFailed, this, _1)); - BOOST_REQUIRE_EQUAL(channel->isListening(), true); - - DummyStreamSender sender; - sender.start(endpoint); - - BOOST_CHECK_MESSAGE(limitedIo.run(LimitedIo::UNLIMITED_OPS, - time::seconds(1)) == LimitedIo::EXCEED_TIME, - "Exception thrown for " + Dataset::getName()); -} - -class FaceCreateTimeoutFixture : protected BaseFixture -{ -public: - void - onFaceCreated(const shared_ptr& newFace) - { - BOOST_CHECK_MESSAGE(false, "Timeout expected"); - BOOST_CHECK(!static_cast(face1)); - face1 = newFace; - - limitedIo.afterOp(); - } - - void - onConnectFailed(const std::string& reason) - { - BOOST_CHECK_MESSAGE(true, reason); - - limitedIo.afterOp(); - } - -public: - LimitedIo limitedIo; - - shared_ptr face1; -}; - -BOOST_FIXTURE_TEST_CASE(FaceCreateTimeout, FaceCreateTimeoutFixture) -{ - TcpFactory factory; - shared_ptr channel = factory.createChannel("0.0.0.0", "20070"); - - factory.createFace(FaceUri("tcp4://192.0.2.1:20070"), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - bind(&FaceCreateTimeoutFixture::onFaceCreated, this, _1), - bind(&FaceCreateTimeoutFixture::onConnectFailed, this, _1)); - - BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "TcpChannel error: cannot connect or cannot accept connection"); - - BOOST_CHECK_EQUAL(static_cast(face1), false); -} - -BOOST_FIXTURE_TEST_CASE(Bug1856, EndToEndFixture) -{ - TcpFactory factory1; - - shared_ptr channel1 = factory1.createChannel("127.0.0.1", "20070"); - factory1.createChannel("127.0.0.1", "20071"); - - BOOST_CHECK_EQUAL(channel1->isListening(), false); - - channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); - - BOOST_CHECK_EQUAL(channel1->isListening(), true); - - TcpFactory factory2; - - shared_ptr channel2 = factory2.createChannel("127.0.0.2", "20070"); - factory2.createChannel("127.0.0.2", "20071"); - - factory2.createFace(FaceUri("tcp4://127.0.0.1:20070"), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); - - BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "TcpChannel error: cannot connect or cannot accept connection"); - - BOOST_REQUIRE(static_cast(face1)); - BOOST_REQUIRE(static_cast(face2)); - - std::ostringstream hugeName; - hugeName << "/huge-name/"; - for (size_t i = 0; i < ndn::MAX_NDN_PACKET_SIZE; i++) - hugeName << 'a'; - - shared_ptr interest = makeInterest("ndn:/KfczhUqVix"); - shared_ptr hugeInterest = makeInterest(hugeName.str()); - - face1->sendInterest(*hugeInterest); - face2->sendInterest(*interest); - face2->sendInterest(*interest); - - limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1)); - BOOST_TEST_MESSAGE("Unexpected assertion test passed"); -} - -class FakeNetworkInterfaceFixture : public BaseFixture -{ -public: - FakeNetworkInterfaceFixture() - { - using namespace boost::asio::ip; - - auto fakeInterfaces = make_shared>(); - - fakeInterfaces->push_back( - NetworkInterfaceInfo {0, "eth0", - ethernet::Address::fromString("3e:15:c2:8b:65:00"), - {address_v4::from_string("0.0.0.0")}, - {address_v6::from_string("::")}, - address_v4(), - IFF_UP}); - fakeInterfaces->push_back( - NetworkInterfaceInfo {1, "eth0", - ethernet::Address::fromString("3e:15:c2:8b:65:00"), - {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")}, - {}, - address_v4::from_string("192.168.2.255"), - 0}); - fakeInterfaces->push_back( - NetworkInterfaceInfo {2, "eth1", - ethernet::Address::fromString("3e:15:c2:8b:65:00"), - {address_v4::from_string("198.51.100.1")}, - {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")}, - address_v4::from_string("198.51.100.255"), - IFF_MULTICAST | IFF_BROADCAST | IFF_UP}); - - setDebugNetworkInterfaces(fakeInterfaces); - } - - ~FakeNetworkInterfaceFixture() - { - setDebugNetworkInterfaces(nullptr); - } -}; - -BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture) -{ - using namespace boost::asio::ip; - - TcpFactory factory; - factory.prohibitEndpoint(tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024)); - BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); - BOOST_CHECK((factory.m_prohibitedEndpoints == - std::set { - tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), - })); - - factory.m_prohibitedEndpoints.clear(); - factory.prohibitEndpoint(tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048)); - BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); - BOOST_CHECK((factory.m_prohibitedEndpoints == - std::set { - tcp::Endpoint(address_v6::from_string("2001:db8::1"), 2048) - })); - - factory.m_prohibitedEndpoints.clear(); - factory.prohibitEndpoint(tcp::Endpoint(address_v4(), 1024)); - BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 4); - BOOST_CHECK((factory.m_prohibitedEndpoints == - std::set { - tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), - tcp::Endpoint(address_v4::from_string("192.168.2.2"), 1024), - tcp::Endpoint(address_v4::from_string("198.51.100.1"), 1024), - tcp::Endpoint(address_v4::from_string("0.0.0.0"), 1024) - })); - - factory.m_prohibitedEndpoints.clear(); - factory.prohibitEndpoint(tcp::Endpoint(address_v6(), 2048)); - BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3); - BOOST_CHECK((factory.m_prohibitedEndpoints == - std::set { - tcp::Endpoint(address_v6::from_string("2001:db8::2"), 2048), - tcp::Endpoint(address_v6::from_string("2001:db8::3"), 2048), - tcp::Endpoint(address_v6::from_string("::"), 2048) - })); -} - -BOOST_AUTO_TEST_SUITE_END() // TestTcp -BOOST_AUTO_TEST_SUITE_END() // Face - -} // namespace tests -} // namespace nfd diff --git a/tests/daemon/face/transport.t.cpp b/tests/daemon/face/transport.t.cpp index 81898599..9a59491c 100644 --- a/tests/daemon/face/transport.t.cpp +++ b/tests/daemon/face/transport.t.cpp @@ -24,7 +24,7 @@ */ #include "face/transport.hpp" -#include "face/lp-face.hpp" +#include "face/face.hpp" #include "dummy-transport.hpp" #include "dummy-receive-link-service.hpp" #include "transport-test-common.hpp" @@ -45,6 +45,8 @@ namespace ip = boost::asio::ip; BOOST_AUTO_TEST_SUITE(Face) +using nfd::Face; + class DummyTransportFixture : public BaseFixture { public: @@ -60,14 +62,14 @@ public: void initialize(unique_ptr transport = make_unique()) { - this->face = make_unique(make_unique(), std::move(transport)); + this->face = make_unique(make_unique(), std::move(transport)); this->transport = static_cast(face->getTransport()); this->sentPackets = &this->transport->sentPackets; this->receivedPackets = &static_cast(face->getLinkService())->receivedPackets; } public: - unique_ptr face; + unique_ptr face; DummyTransport* transport; std::vector* sentPackets; std::vector* receivedPackets; diff --git a/tests/daemon/face/packet-datasets.cpp b/tests/daemon/face/udp-channel.t.cpp similarity index 53% rename from tests/daemon/face/packet-datasets.cpp rename to tests/daemon/face/udp-channel.t.cpp index 196fa869..447ec0d8 100644 --- a/tests/daemon/face/packet-datasets.cpp +++ b/tests/daemon/face/udp-channel.t.cpp @@ -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. @@ -23,32 +23,25 @@ * NFD, e.g., in COPYING.md file. If not, see . */ -#include "packet-datasets.hpp" -#include "tests/test-common.hpp" +#include "face/udp-channel.hpp" -#include +#include "tests/test-common.hpp" namespace nfd { namespace tests { -BOOST_FIXTURE_TEST_SUITE(Datasets, BaseFixture) +BOOST_AUTO_TEST_SUITE(Face) +BOOST_FIXTURE_TEST_SUITE(TestUdpChannel, BaseFixture) -BOOST_AUTO_TEST_CASE(Corrupted) -{ - { - typedef CorruptedInterest Dataset; - Dataset dataset; +using nfd::Face; - BOOST_FOREACH(Dataset::Container::value_type& data, dataset.data) - { - Block block(data.buf(), data.size()); +// TODO add the equivalent of these test cases from udp.t.cpp as of commit:65caf200924b28748037750449e28bcb548dbc9c +// MultipleAccepts +// ManualClose +// IdleClose - BOOST_CHECK_THROW((Interest(block)), tlv::Error); - } - } -} - -BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() // TestUdpChannel +BOOST_AUTO_TEST_SUITE_END() // Face } // namespace tests } // namespace nfd diff --git a/tests/daemon/face/udp.t.cpp b/tests/daemon/face/udp-factory.t.cpp similarity index 51% rename from tests/daemon/face/udp.t.cpp rename to tests/daemon/face/udp-factory.t.cpp index d38c908b..837262c4 100644 --- a/tests/daemon/face/udp.t.cpp +++ b/tests/daemon/face/udp-factory.t.cpp @@ -23,19 +23,17 @@ * NFD, e.g., in COPYING.md file. If not, see . */ -#include "face/udp-channel.hpp" #include "face/udp-factory.hpp" #include "core/network-interface.hpp" #include "tests/test-common.hpp" #include "tests/limited-io.hpp" -#include "face-history.hpp" namespace nfd { namespace tests { BOOST_AUTO_TEST_SUITE(Face) -BOOST_FIXTURE_TEST_SUITE(TestUdp, BaseFixture) +BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, BaseFixture) using nfd::Face; @@ -58,7 +56,7 @@ BOOST_AUTO_TEST_CASE(GetChannels) BOOST_CHECK_EQUAL(expectedChannels.size(), 0); } -class FactoryErrorCheck : protected BaseFixture +class FactoryErrorCheck : public BaseFixture { public: bool @@ -121,9 +119,6 @@ BOOST_FIXTURE_TEST_CASE(ChannelMapUdp, FactoryErrorCheck) auto multicastFace1 = factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072"); 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_PERMANENT); - BOOST_CHECK_EQUAL(multicastFace1->isMultiAccess(), true); //same endpoint of a multicast face BOOST_CHECK_EXCEPTION(factory.createChannel(interfaceIp, "20072"), @@ -249,370 +244,6 @@ BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) ProtocolFactory::Error); } -class EndToEndIpv4 -{ -public: - static const std::string - getScheme() - { - return "udp4"; - } - - static const std::string - getLocalIp() - { - return "127.0.0.1"; - } - - static const std::string - getPort1() - { - return "20071"; - } - - static const std::string - getPort2() - { - return "20072"; - } - - static const std::string - getPort3() - { - return "20073"; - } - - static const FaceUri - getFaceUri1() - { - return FaceUri("udp4://127.0.0.1:20071"); - } - - static const FaceUri - getFaceUri2() - { - return FaceUri("udp4://127.0.0.1:20072"); - } - - static const FaceUri - getFaceUri3() - { - return FaceUri("udp4://127.0.0.1:20073"); - } -}; - -class EndToEndIpv6 -{ -public: - static const std::string - getScheme() - { - return "udp6"; - } - - static const std::string - getLocalIp() - { - return "::1"; - } - - static const std::string - getPort1() - { - return "20071"; - } - - static const std::string - getPort2() - { - return "20072"; - } - - static const std::string - getPort3() - { - return "20073"; - } - - static const FaceUri - getFaceUri1() - { - return FaceUri("udp6://[::1]:20071"); - } - - static const FaceUri - getFaceUri2() - { - return FaceUri("udp6://[::1]:20072"); - } - - static const FaceUri - getFaceUri3() - { - return FaceUri("udp6://[::1]:20073"); - } -}; - -typedef boost::mpl::list EndToEndAddresses; - -// end to end communication -BOOST_AUTO_TEST_CASE_TEMPLATE(EndToEnd, A, EndToEndAddresses) -{ - LimitedIo limitedIo; - UdpFactory factory; - - shared_ptr channel1 = factory.createChannel(A::getLocalIp(), A::getPort1()); - - // face1 (on channel1) connects to face2 (on channel2, to be created) - shared_ptr face1; - unique_ptr history1; - factory.createFace(A::getFaceUri2(), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - [&] (shared_ptr newFace) { - face1 = newFace; - history1.reset(new FaceHistory(*face1, limitedIo)); - limitedIo.afterOp(); - }, - [] (const std::string& reason) { BOOST_ERROR(reason); }); - - limitedIo.run(1, time::seconds(1)); - BOOST_REQUIRE(face1 != nullptr); - BOOST_CHECK_EQUAL(face1->getRemoteUri(), A::getFaceUri2()); - BOOST_CHECK_EQUAL(face1->getLocalUri(), A::getFaceUri1()); - BOOST_CHECK_EQUAL(face1->isLocal(), false); // UdpFace is never local - BOOST_CHECK_EQUAL(face1->getCounters().nInBytes, 0); - BOOST_CHECK_EQUAL(face1->getCounters().nOutBytes, 0); - - // channel2 creation must be after face1 creation, - // otherwise channel2's endpoint would be prohibited - shared_ptr channel2 = factory.createChannel(A::getLocalIp(), A::getPort2()); - shared_ptr face2; - unique_ptr history2; - channel2->listen([&] (shared_ptr newFace) { - BOOST_CHECK(face2 == nullptr); - face2 = newFace; - history2.reset(new FaceHistory(*face2, limitedIo)); - limitedIo.afterOp(); - }, - [] (const std::string& reason) { BOOST_ERROR(reason); }); - - limitedIo.run(1, time::seconds(1)); - BOOST_CHECK(face2 == nullptr); // face2 shouldn't be created until face1 sends something - - shared_ptr interest1 = makeInterest("/I1"); - shared_ptr interest2 = makeInterest("/I2"); - shared_ptr data1 = makeData("/D1"); - shared_ptr data2 = makeData("/D2"); - - // face1 sends to channel2, creates face2 - face1->sendInterest(*interest1); - face1->sendData(*data1); - face1->sendData(*data1); - face1->sendData(*data1); - size_t nBytesSent1 = interest1->wireEncode().size() + 3 * data1->wireEncode().size(); - - limitedIo.run(5, time::seconds(1)); // 1 accept, 4 receives - - BOOST_REQUIRE(face2 != nullptr); - BOOST_CHECK_EQUAL(face2->getRemoteUri(), A::getFaceUri1()); - BOOST_CHECK_EQUAL(face2->getLocalUri(), A::getFaceUri2()); - BOOST_CHECK_EQUAL(face2->isLocal(), false); // UdpFace is never local - BOOST_CHECK_EQUAL(face2->getCounters().nInBytes, nBytesSent1); - BOOST_CHECK_EQUAL(face2->getCounters().nOutBytes, 0); - - BOOST_REQUIRE_EQUAL(history2->receivedInterests.size(), 1); - BOOST_CHECK_EQUAL(history2->receivedInterests.front().getName(), interest1->getName()); - BOOST_REQUIRE_EQUAL(history2->receivedData.size(), 3); - BOOST_CHECK_EQUAL(history2->receivedData.front().getName(), data1->getName()); - - // face2 sends to face1 - face2->sendInterest(*interest2); - face2->sendInterest(*interest2); - face2->sendInterest(*interest2); - face2->sendData(*data2); - size_t nBytesSent2 = 3 * interest2->wireEncode().size() + data2->wireEncode().size(); - - limitedIo.run(4, time::seconds(1)); // 4 receives - - BOOST_REQUIRE_EQUAL(history1->receivedInterests.size(), 3); - BOOST_CHECK_EQUAL(history1->receivedInterests.front().getName(), interest2->getName()); - BOOST_REQUIRE_EQUAL(history1->receivedData.size(), 1); - BOOST_CHECK_EQUAL(history1->receivedData.front().getName(), data2->getName()); - - // counters - const face::FaceCounters& counters1 = face1->getCounters(); - BOOST_CHECK_EQUAL(counters1.nInInterests, 3); - BOOST_CHECK_EQUAL(counters1.nInData, 1); - BOOST_CHECK_EQUAL(counters1.nOutInterests, 1); - BOOST_CHECK_EQUAL(counters1.nOutData, 3); - BOOST_CHECK_EQUAL(counters1.nInBytes, nBytesSent2); - BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent1); - - const face::FaceCounters& counters2 = face2->getCounters(); - BOOST_CHECK_EQUAL(counters2.nInInterests, 1); - BOOST_CHECK_EQUAL(counters2.nInData, 3); - BOOST_CHECK_EQUAL(counters2.nOutInterests, 3); - BOOST_CHECK_EQUAL(counters2.nOutData, 1); - BOOST_CHECK_EQUAL(counters2.nInBytes, nBytesSent1); - BOOST_CHECK_EQUAL(counters2.nOutBytes, nBytesSent2); -} - -// channel accepting multiple incoming connections -BOOST_AUTO_TEST_CASE_TEMPLATE(MultipleAccepts, A, EndToEndAddresses) -{ - LimitedIo limitedIo; - UdpFactory factory; - - // channel1 is listening - shared_ptr channel1 = factory.createChannel(A::getLocalIp(), A::getPort1()); - std::vector> faces1; - channel1->listen([&] (shared_ptr newFace) { - faces1.push_back(newFace); - limitedIo.afterOp(); - }, - [] (const std::string& reason) { BOOST_ERROR(reason); }); - - // face2 (on channel2) connects to channel1 - shared_ptr channel2 = factory.createChannel(A::getLocalIp(), A::getPort2()); - BOOST_CHECK_NE(channel1, channel2); - shared_ptr face2; - boost::asio::ip::address ipAddress2 = boost::asio::ip::address::from_string(A::getLocalIp()); - udp::Endpoint endpoint2(ipAddress2, boost::lexical_cast(A::getPort1())); - channel2->connect(endpoint2, - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - [&] (shared_ptr newFace) { - face2 = newFace; - limitedIo.afterOp(); - }, - [] (const std::string& reason) { BOOST_ERROR(reason); }); - - limitedIo.run(1, time::seconds(1)); // 1 create (on channel2) - BOOST_REQUIRE(face2 != nullptr); - BOOST_CHECK_EQUAL(faces1.size(), 0); // channel1 won't create face until face2 sends something - - // face3 (on channel3) connects to channel1 - shared_ptr channel3 = factory.createChannel(A::getLocalIp(), A::getPort3()); - BOOST_CHECK_NE(channel1, channel3); - shared_ptr face3; - boost::asio::ip::address ipAddress3 = boost::asio::ip::address::from_string(A::getLocalIp()); - udp::Endpoint endpoint3(ipAddress3, boost::lexical_cast(A::getPort1())); - channel3->connect(endpoint3, - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - [&] (shared_ptr newFace) { - face3 = newFace; - limitedIo.afterOp(); - }, - [] (const std::string& reason) { BOOST_ERROR(reason); }); - - limitedIo.run(1, time::seconds(1)); // 1 create (on channel3) - BOOST_REQUIRE(face3 != nullptr); - BOOST_CHECK_EQUAL(faces1.size(), 0); // channel1 won't create face until face3 sends something - - // face2 sends to channel1 - shared_ptr interest2 = makeInterest("/I2"); - face2->sendInterest(*interest2); - limitedIo.run(1, time::milliseconds(100)); // 1 accept (on channel1) - BOOST_REQUIRE_EQUAL(faces1.size(), 1); - BOOST_CHECK_EQUAL(channel1->size(), 1); - BOOST_CHECK_EQUAL(faces1.at(0)->getRemoteUri(), A::getFaceUri2()); - - // face3 sends to channel1 - shared_ptr data3 = makeData("/D3"); - face3->sendData(*data3); - limitedIo.run(1, time::milliseconds(100)); // 1 accept (on channel1) - BOOST_REQUIRE_EQUAL(faces1.size(), 2); - BOOST_CHECK_EQUAL(channel1->size(), 2); - BOOST_CHECK_EQUAL(faces1.at(1)->getRemoteUri(), A::getFaceUri3()); -} - -// manually close a face -BOOST_AUTO_TEST_CASE_TEMPLATE(ManualClose, A, EndToEndAddresses) -{ - LimitedIo limitedIo; - UdpFactory factory; - - shared_ptr channel1 = factory.createChannel(A::getLocalIp(), A::getPort1()); - shared_ptr face1; - unique_ptr history1; - factory.createFace(A::getFaceUri2(), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - [&] (shared_ptr newFace) { - face1 = newFace; - history1.reset(new FaceHistory(*face1, limitedIo)); - limitedIo.afterOp(); - }, - [] (const std::string& reason) { BOOST_ERROR(reason); }); - - limitedIo.run(1, time::milliseconds(100)); - BOOST_REQUIRE(face1 != nullptr); - BOOST_CHECK_EQUAL(channel1->size(), 1); - - face1->close(); - getGlobalIoService().poll(); - BOOST_CHECK_EQUAL(history1->failures.size(), 1); - BOOST_CHECK_EQUAL(channel1->size(), 0); -} - -// automatically close an idle incoming face -BOOST_AUTO_TEST_CASE_TEMPLATE(IdleClose, A, EndToEndAddresses) -{ - LimitedIo limitedIo; - UdpFactory factory; - - // channel1 is listening - shared_ptr channel1 = factory.createChannel(A::getLocalIp(), A::getPort1(), - time::seconds(2)); - shared_ptr face1; - unique_ptr history1; - channel1->listen([&] (shared_ptr newFace) { - BOOST_CHECK(face1 == nullptr); - face1 = newFace; - history1.reset(new FaceHistory(*face1, limitedIo)); - limitedIo.afterOp(); - }, - [] (const std::string& reason) { BOOST_ERROR(reason); }); - - // face2 (on channel2) connects to channel1 - shared_ptr channel2 = factory.createChannel(A::getLocalIp(), A::getPort2(), - time::seconds(2)); - shared_ptr face2; - unique_ptr history2; - boost::asio::ip::address ipAddress = boost::asio::ip::address::from_string(A::getLocalIp()); - udp::Endpoint endpoint(ipAddress, boost::lexical_cast(A::getPort1())); - channel2->connect(endpoint, - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - [&] (shared_ptr newFace) { - face2 = newFace; - history2.reset(new FaceHistory(*face2, limitedIo)); - limitedIo.afterOp(); - }, - [] (const std::string& reason) { BOOST_ERROR(reason); }); - - limitedIo.run(1, time::milliseconds(100)); // 1 create (on channel2) - BOOST_REQUIRE(face2 != nullptr); - BOOST_CHECK_EQUAL(face2->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); - BOOST_CHECK_EQUAL(face2->isMultiAccess(), false); - - // face2 sends to channel1, creates face1 - shared_ptr interest2 = makeInterest("/I2"); - face2->sendInterest(*interest2); - - limitedIo.run(2, time::seconds(1)); // 1 accept (on channel1), 1 receive (on face1) - BOOST_CHECK_EQUAL(channel1->size(), 1); - BOOST_REQUIRE(face1 != nullptr); - BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); - BOOST_CHECK_EQUAL(face1->isMultiAccess(), false); - - limitedIo.defer(time::seconds(1)); - BOOST_CHECK_EQUAL(history1->failures.size(), 0); // face1 is not idle - BOOST_CHECK_EQUAL(history2->failures.size(), 0); // face2 is outgoing face and never closed - - limitedIo.defer(time::seconds(4)); - BOOST_CHECK_EQUAL(history1->failures.size(), 1); // face1 is idle and automatically closed - BOOST_CHECK_EQUAL(channel1->size(), 0); - BOOST_CHECK_EQUAL(history2->failures.size(), 0); // face2 is outgoing face and never closed -} - class FakeNetworkInterfaceFixture : public BaseFixture { public: @@ -697,7 +328,7 @@ BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture) })); } -BOOST_AUTO_TEST_SUITE_END() // TestUdp +BOOST_AUTO_TEST_SUITE_END() // TestUdpFactory BOOST_AUTO_TEST_SUITE_END() // Face } // namespace tests diff --git a/tests/daemon/face/unicast-udp-transport-fixture.hpp b/tests/daemon/face/unicast-udp-transport-fixture.hpp index 6dd836ab..1ec37b0d 100644 --- a/tests/daemon/face/unicast-udp-transport-fixture.hpp +++ b/tests/daemon/face/unicast-udp-transport-fixture.hpp @@ -27,7 +27,7 @@ #define NFD_TESTS_DAEMON_FACE_UNICAST_UDP_TRANSPORT_FIXTURE_HPP #include "face/unicast-udp-transport.hpp" -#include "face/lp-face.hpp" +#include "face/face.hpp" #include "dummy-receive-link-service.hpp" #include "tests/limited-io.hpp" @@ -60,9 +60,9 @@ protected: remoteConnect(address); - face = make_unique(make_unique(), - make_unique(std::move(sock), persistency, - time::seconds(3))); + face = make_unique( + make_unique(), + make_unique(std::move(sock), persistency, time::seconds(3))); transport = static_cast(face->getTransport()); receivedPackets = &static_cast(face->getLinkService())->receivedPackets; @@ -99,7 +99,7 @@ protected: std::vector* receivedPackets; private: - unique_ptr face; + unique_ptr face; }; } // namespace tests diff --git a/tests/daemon/face/face-history.hpp b/tests/daemon/face/unix-stream-channel.t.cpp similarity index 50% rename from tests/daemon/face/face-history.hpp rename to tests/daemon/face/unix-stream-channel.t.cpp index 263a23ac..86caa8da 100644 --- a/tests/daemon/face/face-history.hpp +++ b/tests/daemon/face/unix-stream-channel.t.cpp @@ -23,71 +23,23 @@ * NFD, e.g., in COPYING.md file. If not, see . */ -#ifndef NFD_TESTS_DAEMON_FACE_FACE_HISTORY_HPP -#define NFD_TESTS_DAEMON_FACE_FACE_HISTORY_HPP +#include "face/unix-stream-channel.hpp" -#include "face/face.hpp" +#include "tests/test-common.hpp" namespace nfd { namespace tests { -/** \brief captures signals from Face - */ -class FaceHistory : noncopyable -{ -public: - explicit - FaceHistory(Face& face) - : m_limitedIo(nullptr) - { - this->construct(face); - } +BOOST_AUTO_TEST_SUITE(Face) +BOOST_FIXTURE_TEST_SUITE(TestUnixStreamChannel, BaseFixture) - FaceHistory(Face& face, LimitedIo& limitedIo) - : m_limitedIo(&limitedIo) - { - this->construct(face); - } +// TODO add the equivalent of these test cases from unix-stream.t.cpp as of commit:65caf200924b28748037750449e28bcb548dbc9c +// MultipleAccepts -private: - void - construct(Face& face) - { - m_receiveInterestConn = face.onReceiveInterest.connect([this] (const Interest& interest) { - this->receivedInterests.push_back(interest); - this->afterOp(); - }); - m_receiveDataConn = face.onReceiveData.connect([this] (const Data& data) { - this->receivedData.push_back(data); - this->afterOp(); - }); - m_failConn = face.onFail.connect([this] (const std::string& reason) { - this->failures.push_back(reason); - this->afterOp(); - }); - } +// TODO add a test case to check a failed face is removed from the channel - void - afterOp() - { - if (m_limitedIo != nullptr) { - m_limitedIo->afterOp(); - } - } - -public: - std::vector receivedInterests; - std::vector receivedData; - std::vector failures; - -private: - LimitedIo* m_limitedIo; - signal::ScopedConnection m_receiveInterestConn; - signal::ScopedConnection m_receiveDataConn; - signal::ScopedConnection m_failConn; -}; +BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamChannel +BOOST_AUTO_TEST_SUITE_END() // Face } // namespace tests } // namespace nfd - -#endif // NFD_TESTS_DAEMON_FACE_FACE_HISTORY_HPP diff --git a/tests/daemon/face/unix-stream-factory.t.cpp b/tests/daemon/face/unix-stream-factory.t.cpp new file mode 100644 index 00000000..2be2536c --- /dev/null +++ b/tests/daemon/face/unix-stream-factory.t.cpp @@ -0,0 +1,103 @@ +/* -*- 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 . + */ + +#include "face/unix-stream-factory.hpp" + +#include "tests/test-common.hpp" +#include "tests/limited-io.hpp" + +namespace nfd { +namespace tests { + +#define CHANNEL_PATH1 "unix-stream-test.1.sock" +#define CHANNEL_PATH2 "unix-stream-test.2.sock" + +BOOST_AUTO_TEST_SUITE(Face) +BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, BaseFixture) + +using nfd::Face; + +BOOST_AUTO_TEST_CASE(ChannelMap) +{ + UnixStreamFactory factory; + + shared_ptr channel1 = factory.createChannel(CHANNEL_PATH1); + shared_ptr channel1a = factory.createChannel(CHANNEL_PATH1); + BOOST_CHECK_EQUAL(channel1, channel1a); + std::string channel1uri = channel1->getUri().toString(); + BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator + BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1), + channel1uri.size() - std::string(CHANNEL_PATH1).size()); + + shared_ptr channel2 = factory.createChannel(CHANNEL_PATH2); + BOOST_CHECK_NE(channel1, channel2); +} + +BOOST_AUTO_TEST_CASE(GetChannels) +{ + UnixStreamFactory factory; + BOOST_CHECK(factory.getChannels().empty()); + + std::vector> expectedChannels; + expectedChannels.push_back(factory.createChannel(CHANNEL_PATH1)); + expectedChannels.push_back(factory.createChannel(CHANNEL_PATH2)); + + for (const auto& channel : factory.getChannels()) { + auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), channel); + BOOST_REQUIRE(pos != expectedChannels.end()); + expectedChannels.erase(pos); + } + + BOOST_CHECK_EQUAL(expectedChannels.size(), 0); +} + +BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) +{ + UnixStreamFactory factory; + + BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"), + ndn::nfd::FACE_PERSISTENCY_PERMANENT, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); + + BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"), + ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); + + BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"), + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); +} + +BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamFactory +BOOST_AUTO_TEST_SUITE_END() // Face + +} // namespace tests +} // namespace nfd diff --git a/tests/daemon/face/unix-stream-transport-fixture.hpp b/tests/daemon/face/unix-stream-transport-fixture.hpp index 38c9b5f6..0101f10c 100644 --- a/tests/daemon/face/unix-stream-transport-fixture.hpp +++ b/tests/daemon/face/unix-stream-transport-fixture.hpp @@ -27,7 +27,7 @@ #define NFD_TESTS_DAEMON_FACE_UNIX_STREAM_TRANSPORT_FIXTURE_HPP #include "face/unix-stream-transport.hpp" -#include "face/lp-face.hpp" +#include "face/face.hpp" #include "dummy-receive-link-service.hpp" #include "tests/limited-io.hpp" @@ -105,8 +105,8 @@ protected: BOOST_REQUIRE_EQUAL(limitedIo.run(2, time::seconds(1)), LimitedIo::EXCEED_OPS); localEp = sock.local_endpoint(); - face = make_unique(make_unique(), - make_unique(std::move(sock))); + face = make_unique(make_unique(), + make_unique(std::move(sock))); transport = static_cast(face->getTransport()); receivedPackets = &static_cast(face->getLinkService())->receivedPackets; @@ -134,7 +134,7 @@ protected: private: AcceptorWithCleanup acceptor; - unique_ptr face; + unique_ptr face; }; } // namespace tests diff --git a/tests/daemon/face/unix-stream.t.cpp b/tests/daemon/face/unix-stream.t.cpp deleted file mode 100644 index fc528c2b..00000000 --- a/tests/daemon/face/unix-stream.t.cpp +++ /dev/null @@ -1,347 +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 . - */ - -#include "face/unix-stream-channel.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" -#include "dummy-stream-sender.hpp" -#include "packet-datasets.hpp" - -namespace nfd { -namespace tests { - -#define CHANNEL_PATH1 "unix-stream-test.1.sock" -#define CHANNEL_PATH2 "unix-stream-test.2.sock" - -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) -{ - UnixStreamFactory factory; - - shared_ptr channel1 = factory.createChannel(CHANNEL_PATH1); - shared_ptr channel1a = factory.createChannel(CHANNEL_PATH1); - BOOST_CHECK_EQUAL(channel1, channel1a); - std::string channel1uri = channel1->getUri().toString(); - BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator - BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1), - channel1uri.size() - std::string(CHANNEL_PATH1).size()); - - shared_ptr channel2 = factory.createChannel(CHANNEL_PATH2); - BOOST_CHECK_NE(channel1, channel2); -} - -BOOST_AUTO_TEST_CASE(GetChannels) -{ - UnixStreamFactory factory; - BOOST_CHECK(factory.getChannels().empty()); - - std::vector> expectedChannels; - expectedChannels.push_back(factory.createChannel(CHANNEL_PATH1)); - expectedChannels.push_back(factory.createChannel(CHANNEL_PATH2)); - - for (const auto& channel : factory.getChannels()) { - auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), channel); - BOOST_REQUIRE(pos != expectedChannels.end()); - expectedChannels.erase(pos); - } - - BOOST_CHECK_EQUAL(expectedChannels.size(), 0); -} - -BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) -{ - UnixStreamFactory factory; - - BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"), - ndn::nfd::FACE_PERSISTENCY_PERMANENT, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); - - BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"), - ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); - - BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); -} - -class EndToEndFixture : protected BaseFixture -{ -public: - void - client_onConnect(const boost::system::error_code& error) - { - BOOST_CHECK_MESSAGE(!error, error.message()); - - limitedIo.afterOp(); - } - - void - channel1_onFaceCreated(const shared_ptr& newFace) - { - BOOST_CHECK(!static_cast(face1)); - face1 = static_pointer_cast(newFace); - face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1)); - face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1)); - - limitedIo.afterOp(); - } - - void - channel1_onConnectFailed(const std::string& reason) - { - BOOST_CHECK_MESSAGE(false, reason); - - limitedIo.afterOp(); - } - - void - face1_onReceiveInterest(const Interest& interest) - { - face1_receivedInterests.push_back(interest); - - limitedIo.afterOp(); - } - - void - face1_onReceiveData(const Data& data) - { - face1_receivedDatas.push_back(data); - - limitedIo.afterOp(); - } - - void - face2_onReceiveInterest(const Interest& interest) - { - face2_receivedInterests.push_back(interest); - - limitedIo.afterOp(); - } - - void - face2_onReceiveData(const Data& data) - { - face2_receivedDatas.push_back(data); - - limitedIo.afterOp(); - } - - void - channel_onFaceCreated(const shared_ptr& newFace) - { - faces.push_back(static_pointer_cast(newFace)); - - limitedIo.afterOp(); - } - - void - channel_onConnectFailed(const std::string& reason) - { - BOOST_CHECK_MESSAGE(false, reason); - - limitedIo.afterOp(); - } - - shared_ptr - makeFace(UnixStreamTransport::protocol::socket&& socket) - { - auto linkService = make_unique(); - auto transport = make_unique(std::move(socket)); - auto lpFace = make_unique(std::move(linkService), std::move(transport)); - return make_shared(std::move(lpFace)); - } - -protected: - LimitedIo limitedIo; - - shared_ptr face1; - std::vector face1_receivedInterests; - std::vector face1_receivedDatas; - shared_ptr face2; - std::vector face2_receivedInterests; - std::vector face2_receivedDatas; - - std::list> faces; -}; - - -BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture) -{ - UnixStreamFactory factory; - - shared_ptr 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(face1)); - BOOST_CHECK_EQUAL(face1->isLocal(), true); - BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); - BOOST_CHECK_EQUAL(face1->isMultiAccess(), false); - BOOST_CHECK_EQUAL(face1->getRemoteUri().getScheme(), "fd"); - BOOST_CHECK_NO_THROW(std::stoi(face1->getRemoteUri().getHost())); - std::string face1localUri = face1->getLocalUri().toString(); - BOOST_CHECK_EQUAL(face1localUri.find("unix:///"), 0); // third '/' is the path separator - BOOST_CHECK_EQUAL(face1localUri.rfind(CHANNEL_PATH1), - face1localUri.size() - std::string(CHANNEL_PATH1).size()); - - 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 interest1 = makeInterest("ndn:/TpnzGvW9R"); - shared_ptr data1 = makeData("ndn:/KfczhUqVix"); - shared_ptr interest2 = makeInterest("ndn:/QWiIMfj5sL"); - shared_ptr data2 = makeData("ndn:/XNBV796f"); - - face1->sendInterest(*interest1); - face1->sendInterest(*interest1); - face1->sendInterest(*interest1); - face1->sendData (*data1 ); - size_t nBytesSent1 = interest1->wireEncode().size() * 3 + data1->wireEncode().size(); - face2->sendInterest(*interest2); - face2->sendData (*data2 ); - face2->sendData (*data2 ); - face2->sendData (*data2 ); - size_t nBytesSent2 = interest2->wireEncode().size() + data2->wireEncode().size() * 3; - - BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Send/receive"); - - BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); - BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3); - BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3); - BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); - - BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName()); - BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName()); - BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName()); - BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName()); - - // needed to ensure NOutBytes counters are accurate - limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1)); - - const face::FaceCounters& counters1 = face1->getCounters(); - BOOST_CHECK_EQUAL(counters1.nInInterests, 1); - BOOST_CHECK_EQUAL(counters1.nInData, 3); - BOOST_CHECK_EQUAL(counters1.nOutInterests, 3); - BOOST_CHECK_EQUAL(counters1.nOutData, 1); - BOOST_CHECK_EQUAL(counters1.nInBytes, nBytesSent2); - BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent1); - - const face::FaceCounters& counters2 = face2->getCounters(); - BOOST_CHECK_EQUAL(counters2.nInInterests, 3); - BOOST_CHECK_EQUAL(counters2.nInData, 1); - BOOST_CHECK_EQUAL(counters2.nOutInterests, 1); - BOOST_CHECK_EQUAL(counters2.nOutData, 3); -} - -BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) -{ - UnixStreamFactory factory; - - shared_ptr channel = factory.createChannel(CHANNEL_PATH1); - channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); - - 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); - - 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"); - - BOOST_CHECK_EQUAL(faces.size(), 2); - - // now close one of the faces - faces.front()->close(); - - // we should still be able to send/receive with the other one - face1 = faces.back(); - face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1)); - face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1)); - - face2 = makeFace(std::move(client2)); - face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1)); - face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1)); - - shared_ptr interest1 = makeInterest("ndn:/TpnzGvW9R"); - shared_ptr data1 = makeData("ndn:/KfczhUqVix"); - shared_ptr interest2 = makeInterest("ndn:/QWiIMfj5sL"); - shared_ptr data2 = makeData("ndn:/XNBV796f"); - - face1->sendInterest(*interest1); - face1->sendData (*data1 ); - face2->sendInterest(*interest2); - face2->sendData (*data2 ); - - BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Send/receive"); - - BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); - BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); - BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); - BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); - - BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName()); - BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName()); - BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName()); - BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName()); -} - -BOOST_AUTO_TEST_SUITE_END() // TestUnixStream -BOOST_AUTO_TEST_SUITE_END() // Face - -} // namespace tests -} // namespace nfd diff --git a/tests/daemon/face/websocket-channel.t.cpp b/tests/daemon/face/websocket-channel.t.cpp new file mode 100644 index 00000000..9e102392 --- /dev/null +++ b/tests/daemon/face/websocket-channel.t.cpp @@ -0,0 +1,44 @@ +/* -*- 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 . + */ + +#include "face/websocket-channel.hpp" + +#include "tests/test-common.hpp" + +namespace nfd { +namespace tests { + +BOOST_AUTO_TEST_SUITE(Face) +BOOST_FIXTURE_TEST_SUITE(TestWebSocketChannel, BaseFixture) + +// TODO add a test case to accept multiple incoming connections on a channel + +// TODO add a test case to check a failed face is removed from the channel + +BOOST_AUTO_TEST_SUITE_END() // TestWebSocketChannel +BOOST_AUTO_TEST_SUITE_END() // Face + +} // namespace tests +} // namespace nfd diff --git a/tests/daemon/face/websocket-factory.t.cpp b/tests/daemon/face/websocket-factory.t.cpp new file mode 100644 index 00000000..9e469e83 --- /dev/null +++ b/tests/daemon/face/websocket-factory.t.cpp @@ -0,0 +1,85 @@ +/* -*- 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 . + */ + +#include "face/websocket-factory.hpp" + +#include "tests/test-common.hpp" +#include "tests/limited-io.hpp" + +namespace nfd { +namespace tests { + +BOOST_AUTO_TEST_SUITE(Face) +BOOST_FIXTURE_TEST_SUITE(TestWebSocketFactory, BaseFixture) + +using nfd::Face; + +BOOST_AUTO_TEST_CASE(GetChannels) +{ + WebSocketFactory factory; + BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); + + std::vector> expectedChannels; + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); + expectedChannels.push_back(factory.createChannel("::1", "20071")); + + for (const auto& i : factory.getChannels()) { + auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), i); + BOOST_REQUIRE(pos != expectedChannels.end()); + expectedChannels.erase(pos); + } + + BOOST_CHECK_EQUAL(expectedChannels.size(), 0); +} + +BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) +{ + WebSocketFactory factory; + + BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"), + ndn::nfd::FACE_PERSISTENCY_PERMANENT, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); + + BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"), + ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); + + BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"), + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + bind([]{}), + bind([]{})), + ProtocolFactory::Error); +} + +BOOST_AUTO_TEST_SUITE_END() // TestWebSocketFactory +BOOST_AUTO_TEST_SUITE_END() // Face + +} // namespace tests +} // namespace nfd diff --git a/tests/daemon/face/websocket-transport.t.cpp b/tests/daemon/face/websocket-transport.t.cpp index ca9bd728..edee799f 100644 --- a/tests/daemon/face/websocket-transport.t.cpp +++ b/tests/daemon/face/websocket-transport.t.cpp @@ -24,7 +24,7 @@ */ #include "face/websocket-transport.hpp" -#include "face/lp-face.hpp" +#include "face/face.hpp" #include "dummy-receive-link-service.hpp" #include "transport-test-common.hpp" @@ -39,6 +39,8 @@ namespace ip = boost::asio::ip; BOOST_AUTO_TEST_SUITE(Face) +using nfd::Face; + /** \brief a fixture that accepts a single WebSocket connection from a client */ class SingleWebSocketFixture : public BaseFixture @@ -97,7 +99,7 @@ public: void makeFace(const time::milliseconds& pingInterval = time::milliseconds(10000)) { - face = make_unique( + face = make_unique( make_unique(), make_unique(serverHdl, ref(server), pingInterval)); transport = static_cast(face->getTransport()); @@ -197,7 +199,7 @@ public: websocket::Server server; websocketpp::connection_hdl serverHdl; - unique_ptr face; + unique_ptr face; WebSocketTransport* transport; std::vector* serverReceivedPackets; diff --git a/tests/daemon/face/websocket.t.cpp b/tests/daemon/face/websocket.t.cpp deleted file mode 100644 index 38116358..00000000 --- a/tests/daemon/face/websocket.t.cpp +++ /dev/null @@ -1,306 +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 . - */ - -#include "face/websocket-channel.hpp" -#include "face/websocket-factory.hpp" -#include "face/websocketpp.hpp" - -#include "tests/test-common.hpp" -#include "tests/limited-io.hpp" - -namespace nfd { -namespace tests { - -BOOST_AUTO_TEST_SUITE(Face) -BOOST_FIXTURE_TEST_SUITE(TestWebSocket, BaseFixture) - -using nfd::Face; - -BOOST_AUTO_TEST_CASE(GetChannels) -{ - WebSocketFactory factory; - BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); - - std::vector> expectedChannels; - expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); - expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); - expectedChannels.push_back(factory.createChannel("::1", "20071")); - - for (const auto& i : factory.getChannels()) { - auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), i); - BOOST_REQUIRE(pos != expectedChannels.end()); - expectedChannels.erase(pos); - } - - BOOST_CHECK_EQUAL(expectedChannels.size(), 0); -} - -BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) -{ - WebSocketFactory factory; - - BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"), - ndn::nfd::FACE_PERSISTENCY_PERMANENT, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); - - BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"), - ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); - - BOOST_CHECK_THROW(factory.createFace(FaceUri("ws://127.0.0.1:20070"), - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - bind([]{}), - bind([]{})), - ProtocolFactory::Error); -} - -class EndToEndFixture : protected BaseFixture -{ -public: - void - channel1_onFaceCreated(const shared_ptr& newFace) - { - BOOST_CHECK(!static_cast(face1)); - face1 = newFace; - face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1)); - face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1)); - face1->onFail.connect(bind(&EndToEndFixture::face1_onFail, this)); - - limitedIo.afterOp(); - } - - void - face1_onReceiveInterest(const Interest& interest) - { - face1_receivedInterests.push_back(interest); - limitedIo.afterOp(); - } - - void - face1_onReceiveData(const Data& data) - { - face1_receivedDatas.push_back(data); - limitedIo.afterOp(); - } - - void - face1_onFail() - { - g_io.post([this] { - face1.reset(); - limitedIo.afterOp(); - }); - } - - void - client1_onOpen(websocketpp::connection_hdl hdl) - { - handle = hdl; - limitedIo.afterOp(); - } - - void - client1_onClose(websocketpp::connection_hdl hdl) - { - limitedIo.afterOp(); - } - - void - client1_onFail(websocketpp::connection_hdl hdl) - { - limitedIo.afterOp(); - } - - bool - client1_onPing(websocketpp::connection_hdl hdl, std::string msg) - { - limitedIo.afterOp(); - // Return false to suppress the pong response, - // which will cause timeout in the websocket channel - return false; - } - - void - client1_sendInterest(const Interest& interest) - { - const Block& payload = interest.wireEncode(); - client1.send(handle, payload.wire(), payload.size(), websocketpp::frame::opcode::binary); - } - - void - client1_sendData(const Data& data) - { - const Block& payload = data.wireEncode(); - client1.send(handle, payload.wire(), payload.size(), websocketpp::frame::opcode::binary); - } - - void - client1_onMessage(websocketpp::connection_hdl hdl, - websocketpp::config::asio_client::message_type::ptr msg) - { - bool isOk = false; - Block element; - const std::string& payload = msg->get_payload(); - std::tie(isOk, element) = Block::fromBuffer(reinterpret_cast(payload.c_str()), - payload.size()); - if (isOk) - { - try { - if (element.type() == tlv::Interest) - { - shared_ptr i = make_shared(); - i->wireDecode(element); - client1_onReceiveInterest(*i); - } - else if (element.type() == tlv::Data) - { - shared_ptr d = make_shared(); - d->wireDecode(element); - client1_onReceiveData(*d); - } - } - catch (tlv::Error&) { - // Do something? - } - } - limitedIo.afterOp(); - } - - void - client1_onReceiveInterest(const Interest& interest) - { - client1_receivedInterests.push_back(interest); - limitedIo.afterOp(); - } - - void - client1_onReceiveData(const Data& data) - { - client1_receivedDatas.push_back(data); - limitedIo.afterOp(); - } - -public: - LimitedIo limitedIo; - - shared_ptr face1; - std::vector face1_receivedInterests; - std::vector face1_receivedDatas; - websocket::Client client1; - websocketpp::connection_hdl handle; - std::vector client1_receivedInterests; - std::vector client1_receivedDatas; -}; - -BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture) -{ - WebSocketFactory factory1; - - shared_ptr channel1 = factory1.createChannel("127.0.0.1", "20070"); - channel1->setPingInterval(time::milliseconds(3000)); - channel1->setPongTimeout(time::milliseconds(1000)); - - BOOST_CHECK_EQUAL(channel1->isListening(), false); - - channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1)); - - BOOST_CHECK_EQUAL(channel1->isListening(), true); - - // Clear all logging info from websocketpp library - client1.clear_access_channels(websocketpp::log::alevel::all); - - client1.init_asio(&getGlobalIoService()); - client1.set_open_handler(bind(&EndToEndFixture::client1_onOpen, this, _1)); - client1.set_close_handler(bind(&EndToEndFixture::client1_onClose, this, _1)); - client1.set_fail_handler(bind(&EndToEndFixture::client1_onFail, this, _1)); - client1.set_message_handler(bind(&EndToEndFixture::client1_onMessage, this, _1, _2)); - client1.set_ping_handler(bind(&EndToEndFixture::client1_onPing, this, _1, _2)); - - websocketpp::lib::error_code ec; - auto con = client1.get_connection("ws://127.0.0.1:20070", ec); - client1.connect(con); - - BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "WebSocketChannel error: cannot connect or cannot accept connection"); - - BOOST_CHECK_EQUAL(channel1->size(), 1); - - BOOST_REQUIRE(static_cast(face1)); - BOOST_CHECK_EQUAL(face1->isLocal(), true); - BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); - BOOST_CHECK_EQUAL(face1->isMultiAccess(), false); - BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "ws://127.0.0.1:20070"); - - shared_ptr interest1 = makeInterest("ndn:/TpnzGvW9R"); - shared_ptr data1 = makeData("ndn:/KfczhUqVix"); - shared_ptr interest2 = makeInterest("ndn:/QWiIMfj5sL"); - shared_ptr data2 = makeData("ndn:/XNBV796f"); - - client1_sendInterest(*interest1); - client1_sendInterest(*interest1); - client1_sendInterest(*interest1); - face1->sendData (*data1); - face1->sendInterest (*interest2); - client1_sendData (*data2); - client1_sendData (*data2); - client1_sendData (*data2); - - size_t nBytesSent = data1->wireEncode().size() + interest2->wireEncode().size(); - size_t nBytesReceived = interest1->wireEncode().size() * 3 + data2->wireEncode().size() * 3; - - BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(10)) == LimitedIo::EXCEED_OPS, - "WebSocketChannel error: cannot send or receive Interest/Data packets"); - - BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 3); - BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3); - BOOST_REQUIRE_EQUAL(client1_receivedInterests.size(), 1); - BOOST_REQUIRE_EQUAL(client1_receivedDatas .size(), 1); - - BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest1->getName()); - BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName()); - BOOST_CHECK_EQUAL(client1_receivedInterests[0].getName(), interest2->getName()); - BOOST_CHECK_EQUAL(client1_receivedDatas [0].getName(), data1->getName()); - - const face::FaceCounters& counters1 = face1->getCounters(); - BOOST_CHECK_EQUAL(counters1.nInInterests, 3); - BOOST_CHECK_EQUAL(counters1.nInData, 3); - BOOST_CHECK_EQUAL(counters1.nOutInterests, 1); - BOOST_CHECK_EQUAL(counters1.nOutData, 1); - BOOST_CHECK_EQUAL(counters1.nInBytes, nBytesReceived); - BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent); - - limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(8)); - BOOST_CHECK_EQUAL(channel1->size(), 0); -} - -BOOST_AUTO_TEST_SUITE_END() // TestWebSocket -BOOST_AUTO_TEST_SUITE_END() // Face - -} // namespace tests -} // namespace nfd diff --git a/tests/daemon/fw/client-control-strategy.t.cpp b/tests/daemon/fw/client-control-strategy.t.cpp index 8f0870bd..e180ec9b 100644 --- a/tests/daemon/fw/client-control-strategy.t.cpp +++ b/tests/daemon/fw/client-control-strategy.t.cpp @@ -44,10 +44,10 @@ BOOST_AUTO_TEST_CASE(Forward3) typedef StrategyTester ClientControlStrategyTester; ClientControlStrategyTester strategy(forwarder); - shared_ptr face1 = make_shared(); - shared_ptr face2 = make_shared(); - shared_ptr face3 = make_shared(); - shared_ptr face4 = make_shared(); + auto face1 = make_shared(); + auto face2 = make_shared(); + auto face3 = make_shared(); + auto face4 = make_shared("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); forwarder.addFace(face1); forwarder.addFace(face2); forwarder.addFace(face3); diff --git a/tests/daemon/fw/face-table.t.cpp b/tests/daemon/fw/face-table.t.cpp index 66100346..59bb7c8d 100644 --- a/tests/daemon/fw/face-table.t.cpp +++ b/tests/daemon/fw/face-table.t.cpp @@ -32,52 +32,49 @@ namespace nfd { namespace tests { -BOOST_FIXTURE_TEST_SUITE(FwFaceTable, BaseFixture) +BOOST_AUTO_TEST_SUITE(Fw) +BOOST_FIXTURE_TEST_SUITE(TestFaceTable, BaseFixture) BOOST_AUTO_TEST_CASE(AddRemove) { Forwarder forwarder; FaceTable& faceTable = forwarder.getFaceTable(); - std::vector onAddHistory; - std::vector onRemoveHistory; - faceTable.onAdd.connect([&] (shared_ptr face) { - onAddHistory.push_back(face->getId()); - }); - faceTable.onRemove.connect([&] (shared_ptr face) { - onRemoveHistory.push_back(face->getId()); - }); + std::vector addHistory; + std::vector removeHistory; + faceTable.afterAdd.connect([&] (shared_ptr face) { addHistory.push_back(face->getId()); }); + faceTable.beforeRemove.connect([&] (shared_ptr face) { removeHistory.push_back(face->getId()); }); shared_ptr face1 = make_shared(); shared_ptr face2 = make_shared(); - BOOST_CHECK_EQUAL(face1->getId(), INVALID_FACEID); - BOOST_CHECK_EQUAL(face2->getId(), INVALID_FACEID); + BOOST_CHECK_EQUAL(face1->getId(), face::INVALID_FACEID); + BOOST_CHECK_EQUAL(face2->getId(), face::INVALID_FACEID); forwarder.addFace(face1); forwarder.addFace(face2); - BOOST_CHECK_NE(face1->getId(), INVALID_FACEID); - BOOST_CHECK_NE(face2->getId(), INVALID_FACEID); + BOOST_CHECK_NE(face1->getId(), face::INVALID_FACEID); + BOOST_CHECK_NE(face2->getId(), face::INVALID_FACEID); BOOST_CHECK_NE(face1->getId(), face2->getId()); - BOOST_CHECK_GT(face1->getId(), FACEID_RESERVED_MAX); - BOOST_CHECK_GT(face2->getId(), FACEID_RESERVED_MAX); + BOOST_CHECK_GT(face1->getId(), face::FACEID_RESERVED_MAX); + BOOST_CHECK_GT(face2->getId(), face::FACEID_RESERVED_MAX); FaceId oldId1 = face1->getId(); faceTable.add(face1); BOOST_CHECK_EQUAL(face1->getId(), oldId1); BOOST_CHECK_EQUAL(faceTable.size(), 2); - BOOST_REQUIRE_EQUAL(onAddHistory.size(), 2); - BOOST_CHECK_EQUAL(onAddHistory[0], face1->getId()); - BOOST_CHECK_EQUAL(onAddHistory[1], face2->getId()); + BOOST_REQUIRE_EQUAL(addHistory.size(), 2); + BOOST_CHECK_EQUAL(addHistory[0], face1->getId()); + BOOST_CHECK_EQUAL(addHistory[1], face2->getId()); face1->close(); - BOOST_CHECK_EQUAL(face1->getId(), INVALID_FACEID); + BOOST_CHECK_EQUAL(face1->getId(), face::INVALID_FACEID); - BOOST_REQUIRE_EQUAL(onRemoveHistory.size(), 1); - BOOST_CHECK_EQUAL(onRemoveHistory[0], onAddHistory[0]); + BOOST_REQUIRE_EQUAL(removeHistory.size(), 1); + BOOST_CHECK_EQUAL(removeHistory[0], addHistory[0]); } BOOST_AUTO_TEST_CASE(AddReserved) @@ -86,7 +83,7 @@ BOOST_AUTO_TEST_CASE(AddReserved) FaceTable& faceTable = forwarder.getFaceTable(); shared_ptr face1 = make_shared(); - BOOST_CHECK_EQUAL(face1->getId(), INVALID_FACEID); + BOOST_CHECK_EQUAL(face1->getId(), face::INVALID_FACEID); faceTable.addReserved(face1, 5); BOOST_CHECK_EQUAL(face1->getId(), 5); @@ -146,7 +143,8 @@ BOOST_AUTO_TEST_CASE(Enumerate) BOOST_CHECK(hasFace2); } -BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() // TestFaceTable +BOOST_AUTO_TEST_SUITE_END() // Fw } // namespace tests } // namespace nfd diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp index 67bce49b..cfa5f71b 100644 --- a/tests/daemon/fw/forwarder.t.cpp +++ b/tests/daemon/fw/forwarder.t.cpp @@ -25,8 +25,6 @@ #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" @@ -51,10 +49,10 @@ BOOST_AUTO_TEST_CASE(SimpleExchange) interestAB->setInterestLifetime(time::seconds(4)); shared_ptr dataABC = makeData(nameABC); - shared_ptr face1 = make_shared(); - shared_ptr face2 = make_shared(); - face1->afterSend.connect(afterOp); - face2->afterSend.connect(afterOp); + auto face1 = make_shared(); + auto face2 = make_shared(); + face1->afterSend.connect(bind(afterOp)); + face2->afterSend.connect(bind(afterOp)); forwarder.addFace(face1); forwarder.addFace(face2); @@ -66,10 +64,10 @@ BOOST_AUTO_TEST_CASE(SimpleExchange) BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 0); g_io.post([&] { face1->receiveInterest(*interestAB); }); BOOST_CHECK_EQUAL(limitedIo.run(1, time::seconds(1)), LimitedIo::EXCEED_OPS); - BOOST_REQUIRE_EQUAL(face2->m_sentInterests.size(), 1); - BOOST_CHECK_EQUAL(face2->m_sentInterests[0].getName(), nameAB); - BOOST_REQUIRE(face2->m_sentInterests[0].getTag() != nullptr); - BOOST_CHECK_EQUAL(*face2->m_sentInterests[0].getTag(), face1->getId()); + BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face2->sentInterests[0].getName(), nameAB); + BOOST_REQUIRE(face2->sentInterests[0].getTag() != nullptr); + BOOST_CHECK_EQUAL(*face2->sentInterests[0].getTag(), face1->getId()); BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 1); BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 1); @@ -77,10 +75,10 @@ BOOST_AUTO_TEST_CASE(SimpleExchange) BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 0); g_io.post([&] { face2->receiveData(*dataABC); }); BOOST_CHECK_EQUAL(limitedIo.run(1, time::seconds(1)), LimitedIo::EXCEED_OPS); - BOOST_REQUIRE_EQUAL(face1->m_sentDatas.size(), 1); - BOOST_CHECK_EQUAL(face1->m_sentDatas[0].getName(), nameABC); - BOOST_REQUIRE(face1->m_sentDatas[0].getTag() != nullptr); - BOOST_CHECK_EQUAL(*face1->m_sentDatas[0].getTag(), face2->getId()); + BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); + BOOST_CHECK_EQUAL(face1->sentData[0].getName(), nameABC); + BOOST_REQUIRE(face1->sentData[0].getTag() != nullptr); + BOOST_CHECK_EQUAL(*face1->sentData[0].getTag(), face2->getId()); BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 1); BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 1); } @@ -90,9 +88,9 @@ BOOST_AUTO_TEST_CASE(CsMatched) LimitedIo limitedIo; Forwarder forwarder; - shared_ptr face1 = make_shared(); - shared_ptr face2 = make_shared(); - shared_ptr face3 = make_shared(); + auto face1 = make_shared(); + auto face2 = make_shared(); + auto face3 = make_shared(); forwarder.addFace(face1); forwarder.addFace(face2); forwarder.addFace(face3); @@ -115,12 +113,12 @@ BOOST_AUTO_TEST_CASE(CsMatched) face1->receiveInterest(*interestA); limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5)); // Interest matching ContentStore should not be forwarded - BOOST_REQUIRE_EQUAL(face2->m_sentInterests.size(), 0); + BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 0); - BOOST_REQUIRE_EQUAL(face1->m_sentDatas.size(), 1); + BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); // IncomingFaceId field should be reset to represent CS - BOOST_REQUIRE(face1->m_sentDatas[0].getTag() != nullptr); - BOOST_CHECK_EQUAL(*face1->m_sentDatas[0].getTag(), FACEID_CONTENT_STORE); + BOOST_REQUIRE(face1->sentData[0].getTag() != nullptr); + BOOST_CHECK_EQUAL(*face1->sentData[0].getTag(), face::FACEID_CONTENT_STORE); limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(500)); // PIT entry should not be left behind @@ -155,8 +153,8 @@ public: BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming) { ScopeLocalhostIncomingTestForwarder forwarder; - shared_ptr face1 = make_shared(); - shared_ptr face2 = make_shared(); + auto face1 = make_shared("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); + auto face2 = make_shared(); forwarder.addFace(face1); forwarder.addFace(face2); @@ -212,9 +210,9 @@ BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming) BOOST_AUTO_TEST_CASE(ScopeLocalhostOutgoing) { Forwarder forwarder; - shared_ptr face1 = make_shared(); - shared_ptr face2 = make_shared(); - shared_ptr face3 = make_shared(); + auto face1 = make_shared("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); + auto face2 = make_shared(); + auto face3 = make_shared("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); forwarder.addFace(face1); forwarder.addFace(face2); forwarder.addFace(face3); @@ -224,62 +222,62 @@ BOOST_AUTO_TEST_CASE(ScopeLocalhostOutgoing) shared_ptr interestA1 = makeInterest("/localhost/A1"); shared_ptr pitA1 = pit.insert(*interestA1).first; pitA1->insertOrUpdateInRecord(face3, *interestA1); - face1->m_sentInterests.clear(); + face1->sentInterests.clear(); forwarder.onOutgoingInterest(pitA1, *face1); - BOOST_CHECK_EQUAL(face1->m_sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face1->sentInterests.size(), 1); // non-local face, /localhost: violate shared_ptr interestA2 = makeInterest("/localhost/A2"); shared_ptr pitA2 = pit.insert(*interestA2).first; pitA2->insertOrUpdateInRecord(face3, *interestA2); - face2->m_sentInterests.clear(); + face2->sentInterests.clear(); forwarder.onOutgoingInterest(pitA2, *face2); - BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 0); + BOOST_CHECK_EQUAL(face2->sentInterests.size(), 0); // local face, non-/localhost: OK shared_ptr interestA3 = makeInterest("/A3"); shared_ptr pitA3 = pit.insert(*interestA3).first; pitA3->insertOrUpdateInRecord(face3, *interestA3); - face1->m_sentInterests.clear(); + face1->sentInterests.clear(); forwarder.onOutgoingInterest(pitA3, *face1); - BOOST_CHECK_EQUAL(face1->m_sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face1->sentInterests.size(), 1); // non-local face, non-/localhost: OK shared_ptr interestA4 = makeInterest("/A4"); shared_ptr pitA4 = pit.insert(*interestA4).first; pitA4->insertOrUpdateInRecord(face3, *interestA4); - face2->m_sentInterests.clear(); + face2->sentInterests.clear(); forwarder.onOutgoingInterest(pitA4, *face2); - BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face2->sentInterests.size(), 1); // local face, /localhost: OK - face1->m_sentDatas.clear(); + face1->sentData.clear(); forwarder.onOutgoingData(Data("/localhost/B1"), *face1); - BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1); + BOOST_CHECK_EQUAL(face1->sentData.size(), 1); // non-local face, /localhost: OK - face2->m_sentDatas.clear(); + face2->sentData.clear(); forwarder.onOutgoingData(Data("/localhost/B2"), *face2); - BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 0); + BOOST_CHECK_EQUAL(face2->sentData.size(), 0); // local face, non-/localhost: OK - face1->m_sentDatas.clear(); + face1->sentData.clear(); forwarder.onOutgoingData(Data("/B3"), *face1); - BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1); + BOOST_CHECK_EQUAL(face1->sentData.size(), 1); // non-local face, non-/localhost: OK - face2->m_sentDatas.clear(); + face2->sentData.clear(); forwarder.onOutgoingData(Data("/B4"), *face2); - BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 1); + BOOST_CHECK_EQUAL(face2->sentData.size(), 1); } BOOST_AUTO_TEST_CASE(ScopeLocalhopOutgoing) { Forwarder forwarder; - shared_ptr face1 = make_shared(); - shared_ptr face2 = make_shared(); - shared_ptr face3 = make_shared(); - shared_ptr face4 = make_shared(); + auto face1 = make_shared("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); + auto face2 = make_shared(); + auto face3 = make_shared("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); + auto face4 = make_shared(); forwarder.addFace(face1); forwarder.addFace(face2); forwarder.addFace(face3); @@ -290,59 +288,59 @@ BOOST_AUTO_TEST_CASE(ScopeLocalhopOutgoing) shared_ptr interest1 = makeInterest("/localhop/1"); shared_ptr pit1 = pit.insert(*interest1).first; pit1->insertOrUpdateInRecord(face1, *interest1); - face3->m_sentInterests.clear(); + face3->sentInterests.clear(); forwarder.onOutgoingInterest(pit1, *face3); - BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face3->sentInterests.size(), 1); // from non-local face, to local face: OK shared_ptr interest2 = makeInterest("/localhop/2"); shared_ptr pit2 = pit.insert(*interest2).first; pit2->insertOrUpdateInRecord(face2, *interest2); - face3->m_sentInterests.clear(); + face3->sentInterests.clear(); forwarder.onOutgoingInterest(pit2, *face3); - BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face3->sentInterests.size(), 1); // from local face, to non-local face: OK shared_ptr interest3 = makeInterest("/localhop/3"); shared_ptr pit3 = pit.insert(*interest3).first; pit3->insertOrUpdateInRecord(face1, *interest3); - face4->m_sentInterests.clear(); + face4->sentInterests.clear(); forwarder.onOutgoingInterest(pit3, *face4); - BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face4->sentInterests.size(), 1); // from non-local face, to non-local face: violate shared_ptr interest4 = makeInterest("/localhop/4"); shared_ptr pit4 = pit.insert(*interest4).first; pit4->insertOrUpdateInRecord(face2, *interest4); - face4->m_sentInterests.clear(); + face4->sentInterests.clear(); forwarder.onOutgoingInterest(pit4, *face4); - BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 0); + BOOST_CHECK_EQUAL(face4->sentInterests.size(), 0); // from local face and non-local face, to local face: OK shared_ptr interest5 = makeInterest("/localhop/5"); shared_ptr pit5 = pit.insert(*interest5).first; pit5->insertOrUpdateInRecord(face1, *interest5); pit5->insertOrUpdateInRecord(face2, *interest5); - face3->m_sentInterests.clear(); + face3->sentInterests.clear(); forwarder.onOutgoingInterest(pit5, *face3); - BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face3->sentInterests.size(), 1); // from local face and non-local face, to non-local face: OK shared_ptr interest6 = makeInterest("/localhop/6"); shared_ptr pit6 = pit.insert(*interest6).first; pit6->insertOrUpdateInRecord(face1, *interest6); pit6->insertOrUpdateInRecord(face2, *interest6); - face4->m_sentInterests.clear(); + face4->sentInterests.clear(); forwarder.onOutgoingInterest(pit6, *face4); - BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face4->sentInterests.size(), 1); } BOOST_AUTO_TEST_CASE(IncomingInterestStrategyDispatch) { LimitedIo limitedIo; Forwarder forwarder; - shared_ptr face1 = make_shared(); - shared_ptr face2 = make_shared(); + auto face1 = make_shared(); + auto face2 = make_shared(); forwarder.addFace(face1); forwarder.addFace(face2); @@ -398,10 +396,10 @@ BOOST_AUTO_TEST_CASE(IncomingData) { LimitedIo limitedIo; Forwarder forwarder; - shared_ptr face1 = make_shared(); - shared_ptr face2 = make_shared(); - shared_ptr face3 = make_shared(); - shared_ptr face4 = make_shared(); + auto face1 = make_shared(); + auto face2 = make_shared(); + auto face3 = make_shared(); + auto face4 = make_shared(); forwarder.addFace(face1); forwarder.addFace(face2); forwarder.addFace(face3); @@ -424,10 +422,10 @@ BOOST_AUTO_TEST_CASE(IncomingData) forwarder.onIncomingData(*face3, *dataD); limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5)); - BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1); - BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 1); - BOOST_CHECK_EQUAL(face3->m_sentDatas.size(), 0); - BOOST_CHECK_EQUAL(face4->m_sentDatas.size(), 1); + BOOST_CHECK_EQUAL(face1->sentData.size(), 1); + BOOST_CHECK_EQUAL(face2->sentData.size(), 1); + BOOST_CHECK_EQUAL(face3->sentData.size(), 0); + BOOST_CHECK_EQUAL(face4->sentData.size(), 1); } BOOST_AUTO_TEST_CASE(IncomingNack) @@ -435,11 +433,10 @@ BOOST_AUTO_TEST_CASE(IncomingNack) Forwarder forwarder; auto face1 = make_shared(); auto face2 = make_shared(); - auto face3 = make_shared(make_unique( - "dummy://", "dummy://", - ndn::nfd::FACE_SCOPE_NON_LOCAL, - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - ndn::nfd::LINK_TYPE_MULTI_ACCESS)); + auto face3 = make_shared("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); @@ -524,20 +521,15 @@ BOOST_AUTO_TEST_CASE(IncomingNack) BOOST_AUTO_TEST_CASE(OutgoingNack) { Forwarder forwarder; - auto face1w = make_shared(make_unique()); - auto face1 = static_cast(face1w->getLpFace()); - auto face2w = make_shared(make_unique()); - auto face2 = static_cast(face2w->getLpFace()); - auto face3w = make_shared(make_unique( - "dummy://", "dummy://", - ndn::nfd::FACE_SCOPE_NON_LOCAL, - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - ndn::nfd::LINK_TYPE_MULTI_ACCESS)); - auto face3 = static_cast(face3w->getLpFace()); - forwarder.addFace(face1w); - forwarder.addFace(face2w); - forwarder.addFace(face3w); - // TODO#3172 eliminate wrapper + auto face1 = make_shared(); + auto face2 = make_shared(); + auto face3 = make_shared("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); Pit& pit = forwarder.getPit(); @@ -547,68 +539,63 @@ BOOST_AUTO_TEST_CASE(OutgoingNack) // don't send Nack if there's no in-record shared_ptr interest1 = makeInterest("/fM5IVEtC", 719); shared_ptr pit1 = pit.insert(*interest1).first; - pit1->insertOrUpdateInRecord(face1w, *interest1); + pit1->insertOrUpdateInRecord(face1, *interest1); face2->sentNacks.clear(); - forwarder.onOutgoingNack(pit1, *face2w, nackHeader); + forwarder.onOutgoingNack(pit1, *face2, nackHeader); BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0); // send Nack with correct Nonce shared_ptr interest2a = makeInterest("/Vi8tRm9MG3", 152); shared_ptr pit2 = pit.insert(*interest2a).first; - pit2->insertOrUpdateInRecord(face1w, *interest2a); + pit2->insertOrUpdateInRecord(face1, *interest2a); shared_ptr interest2b = makeInterest("/Vi8tRm9MG3", 808); - pit2->insertOrUpdateInRecord(face2w, *interest2b); + pit2->insertOrUpdateInRecord(face2, *interest2b); face1->sentNacks.clear(); - forwarder.onOutgoingNack(pit2, *face1w, nackHeader); + forwarder.onOutgoingNack(pit2, *face1, 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); + pit::InRecordCollection::const_iterator inRecord2a = pit2->getInRecord(*face1); BOOST_CHECK(inRecord2a == pit2->getInRecords().end()); // send Nack with correct Nonce face2->sentNacks.clear(); - forwarder.onOutgoingNack(pit2, *face2w, nackHeader); + forwarder.onOutgoingNack(pit2, *face2, 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); + pit::InRecordCollection::const_iterator inRecord2b = pit2->getInRecord(*face1); BOOST_CHECK(inRecord2b == pit2->getInRecords().end()); // don't send Nack to multi-access face shared_ptr interest2c = makeInterest("/Vi8tRm9MG3", 228); - pit2->insertOrUpdateInRecord(face3w, *interest2c); + pit2->insertOrUpdateInRecord(face3, *interest2c); face3->sentNacks.clear(); - forwarder.onOutgoingNack(pit1, *face3w, nackHeader); + forwarder.onOutgoingNack(pit1, *face3, nackHeader); BOOST_CHECK_EQUAL(face3->sentNacks.size(), 0); } BOOST_AUTO_TEST_CASE(InterestLoopNack) { Forwarder forwarder; - auto face1w = make_shared(make_unique()); - auto face1 = static_cast(face1w->getLpFace()); - auto face2w = make_shared(make_unique()); - auto face2 = static_cast(face2w->getLpFace()); - auto face3w = make_shared(make_unique( - "dummy://", "dummy://", - ndn::nfd::FACE_SCOPE_NON_LOCAL, - ndn::nfd::FACE_PERSISTENCY_PERSISTENT, - ndn::nfd::LINK_TYPE_MULTI_ACCESS)); - auto face3 = static_cast(face3w->getLpFace()); + auto face1 = make_shared(); + auto face2 = make_shared(); + auto face3 = make_shared("dummy://", "dummy://", + ndn::nfd::FACE_SCOPE_NON_LOCAL, + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + ndn::nfd::LINK_TYPE_MULTI_ACCESS); auto face4 = make_shared(); - forwarder.addFace(face1w); - forwarder.addFace(face2w); - forwarder.addFace(face3w); + forwarder.addFace(face1); + forwarder.addFace(face2); + forwarder.addFace(face3); forwarder.addFace(face4); - // TODO#3172 eliminate wrapper Fib& fib = forwarder.getFib(); shared_ptr fibEntry = fib.insert(Name("/zT4XwK0Hnx")).first; @@ -658,8 +645,11 @@ BOOST_FIXTURE_TEST_CASE(InterestLoopWithShortLifetime, UnitTestTimeFixture) // B forwarder.addFace(face2); // cause an Interest sent out of face2 to loop back into face1 after a delay - face2->onSendInterest.connect([&face1] (const Interest& interest) { - scheduler::schedule(time::milliseconds(170), [&] { face1->receiveInterest(interest); }); + face2->afterSend.connect([face1, face2] (uint32_t pktType) { + if (pktType == tlv::Interest) { + auto interest = make_shared(face2->sentInterests.back()); + scheduler::schedule(time::milliseconds(170), [face1, interest] { face1->receiveInterest(*interest); }); + } }); Fib& fib = forwarder.getFib(); @@ -676,7 +666,7 @@ BOOST_FIXTURE_TEST_CASE(InterestLoopWithShortLifetime, UnitTestTimeFixture) // B BOOST_ASSERT(time::milliseconds(25) * 40 < forwarder.getDeadNonceList().getLifetime()); this->advanceClocks(time::milliseconds(25), 40); - BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 1); + BOOST_CHECK_EQUAL(face2->sentInterests.size(), 1); // It's unnecessary to check that Interest with duplicate Nonce can be forwarded again // after it's gone from Dead Nonce List, because the entry lifetime of Dead Nonce List diff --git a/tests/daemon/fw/strategy.t.cpp b/tests/daemon/fw/strategy.t.cpp index 44fead20..90654d70 100644 --- a/tests/daemon/fw/strategy.t.cpp +++ b/tests/daemon/fw/strategy.t.cpp @@ -36,7 +36,8 @@ namespace tests { using namespace nfd::tests; -BOOST_FIXTURE_TEST_SUITE(FwStrategy, BaseFixture) +BOOST_AUTO_TEST_SUITE(Fw) +BOOST_FIXTURE_TEST_SUITE(TestStrategy, BaseFixture) class FaceTableAccessTestStrategy : public DummyStrategy { @@ -58,7 +59,7 @@ public: { auto enumerable = this->getFaceTable() | boost::adaptors::filtered([] (shared_ptr face) { - return face->isLocal(); + return face->getScope() == ndn::nfd::FACE_SCOPE_LOCAL; }); std::vector results; @@ -79,7 +80,7 @@ BOOST_AUTO_TEST_CASE(FaceTableAccess) FaceTableAccessTestStrategy strategy(forwarder); auto face1 = make_shared(); - auto face2 = make_shared(); + auto face2 = make_shared("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); forwarder.addFace(face1); forwarder.addFace(face2); FaceId id1 = face1->getId(); @@ -94,7 +95,8 @@ BOOST_AUTO_TEST_CASE(FaceTableAccess) BOOST_CHECK((strategy.removedFaces == std::vector{id2, id1})); } -BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() // TestStrategy +BOOST_AUTO_TEST_SUITE_END() // Fw } // namespace tests } // namespace fw diff --git a/tests/daemon/fw/topology-tester.cpp b/tests/daemon/fw/topology-tester.cpp index 8b94abc7..f1e54bba 100644 --- a/tests/daemon/fw/topology-tester.cpp +++ b/tests/daemon/fw/topology-tester.cpp @@ -34,7 +34,6 @@ namespace tests { using face::InternalTransportBase; using face::InternalForwarderTransport; using face::InternalClientTransport; -using face::LpFaceWrapper; using face::GenericLinkService; TopologyLink::TopologyLink(const time::nanoseconds& delay) @@ -46,9 +45,9 @@ TopologyLink::TopologyLink(const time::nanoseconds& delay) } void -TopologyLink::addFace(TopologyNode i, shared_ptr face) +TopologyLink::addFace(TopologyNode i, shared_ptr face) { - this->attachTransport(i, dynamic_cast(face->getLpFace()->getTransport())); + this->attachTransport(i, dynamic_cast(face->getTransport())); m_faces[i] = face; } @@ -87,9 +86,9 @@ TopologyLink::scheduleReceive(InternalTransportBase* recipient, const Block& pac }); } -TopologyAppLink::TopologyAppLink(shared_ptr forwarderFace) +TopologyAppLink::TopologyAppLink(shared_ptr forwarderFace) : m_face(forwarderFace) - , m_forwarderTransport(static_cast(forwarderFace->getLpFace()->getTransport())) + , m_forwarderTransport(static_cast(forwarderFace->getTransport())) , m_clientTransport(make_shared()) , m_client(make_shared(m_clientTransport, getGlobalIoService())) { @@ -136,11 +135,10 @@ TopologyTester::addLink(const std::string& label, const time::nanoseconds& delay auto service = make_unique(); auto transport = make_unique(localUri, remoteUri, ndn::nfd::FACE_SCOPE_NON_LOCAL, linkType); - auto face = make_unique(std::move(service), std::move(transport)); - auto faceW = make_shared(std::move(face)); + auto face = make_shared(std::move(service), std::move(transport)); - forwarder.addFace(faceW); - link->addFace(i, faceW); + forwarder.addFace(face); + link->addFace(i, face); } m_links.push_back(link); // keep a shared_ptr so callers don't have to @@ -157,12 +155,11 @@ TopologyTester::addAppFace(const std::string& label, TopologyNode i) auto service = make_unique(); auto transport = make_unique(localUri, remoteUri, ndn::nfd::FACE_SCOPE_LOCAL, ndn::nfd::LINK_TYPE_POINT_TO_POINT); - auto face = make_unique(std::move(service), std::move(transport)); - auto faceW = make_shared(std::move(face)); + auto face = make_shared(std::move(service), std::move(transport)); - forwarder.addFace(faceW); + forwarder.addFace(face); - auto al = make_shared(faceW); + auto al = make_shared(face); m_appLinks.push_back(al); // keep a shared_ptr so callers don't have to return al; } diff --git a/tests/daemon/fw/topology-tester.hpp b/tests/daemon/fw/topology-tester.hpp index 9a10ad77..88d73da3 100644 --- a/tests/daemon/fw/topology-tester.hpp +++ b/tests/daemon/fw/topology-tester.hpp @@ -32,7 +32,7 @@ #include #include "face/internal-transport.hpp" -#include "face/lp-face-wrapper.hpp" +#include "face/face.hpp" #include "fw/strategy.hpp" #include "tests/test-common.hpp" @@ -70,8 +70,12 @@ public: m_isUp = true; } + /** \brief attach a face to the link + * \param i forwarder index + * \param face a Face with InternalForwarderTransport + */ void - addFace(TopologyNode i, shared_ptr face); + addFace(TopologyNode i, shared_ptr face); /** \return a face of forwarder \p i which is attached to this link */ @@ -98,7 +102,7 @@ private: bool m_isUp; time::nanoseconds m_delay; std::unordered_map m_transports; - std::unordered_map> m_faces; + std::unordered_map> m_faces; }; /** \brief represents a link to a local application @@ -106,8 +110,11 @@ private: class TopologyAppLink : noncopyable { public: + /** \brief constructor + * \param forwarderFace a Face with InternalForwarderTransport + */ explicit - TopologyAppLink(shared_ptr forwarderFace); + TopologyAppLink(shared_ptr forwarderFace); /** \brief fail the link, cause packets to be dropped silently */ diff --git a/tests/daemon/mgmt/face-manager.t.cpp b/tests/daemon/mgmt/face-manager.t.cpp index 02bcd788..a8f30158 100644 --- a/tests/daemon/mgmt/face-manager.t.cpp +++ b/tests/daemon/mgmt/face-manager.t.cpp @@ -37,6 +37,9 @@ namespace nfd { namespace tests { +BOOST_AUTO_TEST_SUITE(Mgmt) + + class FaceManagerFixture : public ManagerCommonFixture { public: @@ -48,32 +51,74 @@ public: } public: - template + enum AddFaceFlags { + REMOVE_LAST_NOTIFICATION = 1 << 0, + SET_SCOPE_LOCAL = 1 << 1, + SET_URI_TEST = 1 << 2, + RANDOMIZE_COUNTERS = 1 << 3 + }; + + /** \brief adds a face to the FaceTable + * \param options bitwise OR'ed AddFaceFlags + */ shared_ptr - addFace(bool wantRemoveLastNotification = false) + addFace(int flags = 0) { - auto face = make_shared(); + std::string uri = "dummy://"; + ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL; + + if ((flags & SET_SCOPE_LOCAL) != 0) { + scope = ndn::nfd::FACE_SCOPE_LOCAL; + } + if ((flags & SET_URI_TEST) != 0) { + uri = "test://"; + } + + auto face = make_shared(uri, uri, scope); m_faceTable.add(face); + + if ((flags & RANDOMIZE_COUNTERS) != 0) { + const face::FaceCounters& counters = face->getCounters(); + randomizeCounter(counters.nInInterests); + randomizeCounter(counters.nOutInterests); + randomizeCounter(counters.nInData); + randomizeCounter(counters.nOutData); + randomizeCounter(counters.nInNacks); + randomizeCounter(counters.nOutNacks); + randomizeCounter(counters.nInPackets); + randomizeCounter(counters.nOutPackets); + randomizeCounter(counters.nInBytes); + randomizeCounter(counters.nOutBytes); + } + advanceClocks(time::milliseconds(1), 10); // wait for notification posted - if (wantRemoveLastNotification) { + if ((flags & REMOVE_LAST_NOTIFICATION) != 0) { m_responses.pop_back(); } + return face; } +private: + template + static typename std::enable_if::value>::type + randomizeCounter(const T& counter) + { + const_cast(counter).set(ndn::random::generateWord64()); + } + protected: FaceTable& m_faceTable; FaceManager m_manager; }; -BOOST_FIXTURE_TEST_SUITE(Mgmt, FaceManagerFixture) -BOOST_AUTO_TEST_SUITE(TestFaceManager) +BOOST_FIXTURE_TEST_SUITE(TestFaceManager, FaceManagerFixture) BOOST_AUTO_TEST_SUITE(DestroyFace) BOOST_AUTO_TEST_CASE(Existing) { - auto addedFace = addFace(true); // clear notification for creation + auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation auto parameters = ControlParameters().setFaceId(addedFace->getId()); auto command = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters); @@ -86,7 +131,7 @@ BOOST_AUTO_TEST_CASE(Existing) BOOST_CHECK_EQUAL(checkResponse(1, command->getName(), makeResponse(200, "OK", parameters)), CheckResponseResult::OK); - BOOST_CHECK_EQUAL(addedFace->getId(), -1); + BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID); } BOOST_AUTO_TEST_CASE(NonExisting) @@ -106,7 +151,7 @@ BOOST_AUTO_TEST_SUITE_END() // DestroyFace BOOST_AUTO_TEST_CASE(FaceEvents) { - auto addedFace = addFace(); // trigger FACE_EVENT_CREATED notification + auto addedFace = addFace(); // trigger FACE_EVENT_CREATED notification BOOST_CHECK_NE(addedFace->getId(), -1); int64_t faceId = addedFace->getId(); @@ -146,25 +191,9 @@ BOOST_AUTO_TEST_CASE(FaceEvents) BOOST_CHECK_EQUAL(notification.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); BOOST_CHECK_EQUAL(notification.getLinkType(), ndn::nfd::LinkType::LINK_TYPE_POINT_TO_POINT); } - BOOST_CHECK_EQUAL(addedFace->getId(), -1); + BOOST_CHECK_EQUAL(addedFace->getId(), face::INVALID_FACEID); } -class TestFace : public DummyFace -{ -public: - explicit - TestFace(const std::string& uri = "test://") - : DummyFace(uri, uri) - { - getMutableCounters().getNInInterests().set(ndn::random::generateWord64()); - getMutableCounters().getNInDatas().set(ndn::random::generateWord64()); - getMutableCounters().getNOutInterests().set(ndn::random::generateWord64()); - getMutableCounters().getNOutDatas().set(ndn::random::generateWord64()); - getMutableCounters().getNInBytes().set(ndn::random::generateWord64()); - getMutableCounters().getNOutBytes().set(ndn::random::generateWord64()); - } -}; - // @todo Refactor when ndn::nfd::FaceStatus implementes operator!= and operator<< class FaceStatus : public ndn::nfd::FaceStatus { @@ -179,16 +208,16 @@ bool operator!=(const FaceStatus& left, const FaceStatus& right) { return left.getRemoteUri() != right.getRemoteUri() || - left.getLocalUri() != right.getLocalUri() || - left.getFaceScope() != right.getFaceScope() || - left.getFacePersistency() != right.getFacePersistency() || - left.getLinkType() != right.getLinkType() || - left.getNInInterests() != right.getNInInterests() || - left.getNInDatas() != right.getNInDatas() || - left.getNOutInterests() != right.getNOutInterests() || - left.getNOutDatas() != right.getNOutDatas() || - left.getNInBytes() != right.getNInBytes() || - left.getNOutBytes() != right.getNOutBytes(); + left.getLocalUri() != right.getLocalUri() || + left.getFaceScope() != right.getFaceScope() || + left.getFacePersistency() != right.getFacePersistency() || + left.getLinkType() != right.getLinkType() || + left.getNInInterests() != right.getNInInterests() || + left.getNInDatas() != right.getNInDatas() || + left.getNOutInterests() != right.getNOutInterests() || + left.getNOutDatas() != right.getNOutDatas() || + left.getNInBytes() != right.getNInBytes() || + left.getNOutBytes() != right.getNOutBytes(); } std::ostream& @@ -210,8 +239,8 @@ operator<<(std::ostream &os, const FaceStatus& status) BOOST_AUTO_TEST_CASE(FaceDataset) { size_t nEntries = 303; - for (size_t i = 0 ; i < nEntries ; i ++) { - addFace(true); + for (size_t i = 0; i < nEntries; ++i) { + addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS); } receiveInterest(makeInterest("/localhost/nfd/faces/list")); @@ -237,9 +266,9 @@ BOOST_AUTO_TEST_CASE(FaceDataset) BOOST_AUTO_TEST_CASE(FaceQuery) { - auto face1 = addFace(true); // dummy:// - auto face2 = addFace(true); // dummy://, local - auto face3 = addFace(true); // test:// + auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy:// + auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local + auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test:// auto generateQueryName = [] (const ndn::nfd::FaceQueryFilter& filter) { return Name("/localhost/nfd/faces/query").append(filter.wireEncode()); diff --git a/tests/daemon/mgmt/fib-manager.t.cpp b/tests/daemon/mgmt/fib-manager.t.cpp index 945a07ea..87856ed3 100644 --- a/tests/daemon/mgmt/fib-manager.t.cpp +++ b/tests/daemon/mgmt/fib-manager.t.cpp @@ -80,7 +80,7 @@ public: // for check * @brief check whether the nexthop record is added / removed properly * * @param expectedNNextHops use -1 to skip this check - * @param faceId use FACEID_NULL to skip NextHopRecord checks + * @param faceId use face::FACEID_NULL to skip NextHopRecord checks * @param expectedCost use -1 to skip this check * * @retval OK FIB entry is found by exact match and has the expected number of nexthops; @@ -92,7 +92,7 @@ public: // for check */ CheckNextHopResult checkNextHop(const Name& prefix, ssize_t expectedNNextHops = -1, - FaceId faceId = FACEID_NULL, int32_t expectedCost = -1) + FaceId faceId = face::FACEID_NULL, int32_t expectedCost = -1) { auto entry = m_fib.findExactMatch(prefix); if (!static_cast(entry)) { @@ -104,7 +104,7 @@ public: // for check return CheckNextHopResult::WRONG_N_NEXTHOPS; } - if (faceId != FACEID_NULL) { + if (faceId != face::FACEID_NULL) { for (auto&& record : nextHops) { if (record.getFace()->getId() == faceId) { return expectedCost != -1 && record.getCost() != static_cast(expectedCost) ? @@ -158,7 +158,7 @@ BOOST_AUTO_TEST_SUITE(AddNextHop) BOOST_AUTO_TEST_CASE(UnknownFaceId) { auto command = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", - makeParameters("hello", FACEID_NULL, 101)); + makeParameters("hello", face::FACEID_NULL, 101)); receiveInterest(command); BOOST_REQUIRE_EQUAL(m_responses.size(), 1); @@ -167,14 +167,15 @@ BOOST_AUTO_TEST_CASE(UnknownFaceId) CheckResponseResult::OK); // double check that the next hop was not added - BOOST_CHECK_EQUAL(checkNextHop("/hello", -1, FACEID_NULL, 101), CheckNextHopResult::NO_FIB_ENTRY); + BOOST_CHECK_EQUAL(checkNextHop("/hello", -1, face::FACEID_NULL, 101), CheckNextHopResult::NO_FIB_ENTRY); } BOOST_AUTO_TEST_CASE(ImplicitFaceId) { auto face1 = addFace(); auto face2 = addFace(); - BOOST_REQUIRE(face1 != INVALID_FACEID && face2 != INVALID_FACEID); + BOOST_REQUIRE_NE(face1, face::INVALID_FACEID); + BOOST_REQUIRE_NE(face2, face::INVALID_FACEID); Name expectedName; ControlResponse expectedResponse; @@ -203,7 +204,7 @@ BOOST_AUTO_TEST_CASE(ImplicitFaceId) BOOST_AUTO_TEST_CASE(InitialAdd) { FaceId addedFaceId = addFace(); - BOOST_REQUIRE(addedFaceId != INVALID_FACEID); + BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID); auto parameters = makeParameters("hello", addedFaceId, 101); auto command = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", parameters); @@ -218,7 +219,7 @@ BOOST_AUTO_TEST_CASE(InitialAdd) BOOST_AUTO_TEST_CASE(ImplicitCost) { FaceId addedFaceId = addFace(); - BOOST_REQUIRE(addedFaceId != INVALID_FACEID); + BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID); auto originalParameters = ControlParameters().setName("/hello").setFaceId(addedFaceId); auto parameters = makeParameters("/hello", addedFaceId, 0); @@ -234,7 +235,7 @@ BOOST_AUTO_TEST_CASE(ImplicitCost) BOOST_AUTO_TEST_CASE(AddToExisting) { FaceId face = addFace(); - BOOST_CHECK(face != INVALID_FACEID); + BOOST_REQUIRE_NE(face, face::INVALID_FACEID); Name expectedName; ControlResponse expectedResponse; @@ -280,7 +281,9 @@ BOOST_AUTO_TEST_CASE(Basic) FaceId face1 = addFace(); FaceId face2 = addFace(); FaceId face3 = addFace(); - BOOST_REQUIRE(face1 != INVALID_FACEID && face2 != INVALID_FACEID && face3 != INVALID_FACEID); + BOOST_REQUIRE_NE(face1, face::INVALID_FACEID); + BOOST_REQUIRE_NE(face2, face::INVALID_FACEID); + BOOST_REQUIRE_NE(face3, face::INVALID_FACEID); shared_ptr entry = m_fib.insert("/hello").first; entry->addNextHop(m_faceTable.get(face1), 101); @@ -306,7 +309,7 @@ BOOST_AUTO_TEST_CASE(Basic) BOOST_AUTO_TEST_CASE(PrefixNotFound) { FaceId addedFaceId = addFace(); - BOOST_CHECK(addedFaceId != INVALID_FACEID); + BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID); auto parameters = makeParameters("hello", addedFaceId); auto command = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters); @@ -321,7 +324,8 @@ BOOST_AUTO_TEST_CASE(ImplicitFaceId) { auto face1 = addFace(); auto face2 = addFace(); - BOOST_REQUIRE(face1 != INVALID_FACEID && face2 != INVALID_FACEID); + BOOST_REQUIRE_NE(face1, face::INVALID_FACEID); + BOOST_REQUIRE_NE(face2, face::INVALID_FACEID); Name expectedName; ControlResponse expectedResponse; @@ -355,7 +359,8 @@ BOOST_AUTO_TEST_CASE(RecordNotExist) { auto face1 = addFace(); auto face2 = addFace(); - BOOST_REQUIRE(face1 != INVALID_FACEID && face2 != INVALID_FACEID); + BOOST_REQUIRE_NE(face1, face::INVALID_FACEID); + BOOST_REQUIRE_NE(face2, face::INVALID_FACEID); Name expectedName; ControlResponse expectedResponse;