face: face refactoring completion
* delete old Face
* rename LpFace as Face
* eliminate LpFaceWrapper and use new Face
refs #3172
Change-Id: I08c3a5dfb4cc1b9834b30cccd9ab634535d0608c
diff --git a/daemon/face/channel.cpp b/daemon/face/channel.cpp
index d161504..65e0a25 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 <http://www.gnu.org/licenses/>.
- **/
+ */
#include "channel.hpp"
@@ -36,4 +37,17 @@
m_uri = uri;
}
+void
+connectFaceClosedSignal(Face& face, const std::function<void()>& 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 cb5ed27..640395a 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 @@
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<void()>& f);
+
} // namespace nfd
#endif // NFD_DAEMON_FACE_CHANNEL_HPP
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index 3592530..dd9d034 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<face::LpFaceWrapper>
+shared_ptr<Face>
EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& interface,
const ethernet::Address& address)
{
@@ -48,14 +46,11 @@
auto linkService = make_unique<face::GenericLinkService>(opts);
auto transport = make_unique<face::EthernetTransport>(interface, address);
- auto lpFace = make_unique<face::LpFace>(std::move(linkService), std::move(transport));
- face = make_shared<face::LpFaceWrapper>(std::move(lpFace));
+ face = make_shared<Face>(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 @@
return {};
}
-shared_ptr<face::LpFaceWrapper>
+shared_ptr<Face>
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 c0a951d..add176e 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 @@
};
typedef std::map<std::pair<std::string, ethernet::Address>,
- shared_ptr<face::LpFaceWrapper>> MulticastFaceMap;
+ shared_ptr<Face>> MulticastFaceMap;
/**
* \brief Create an EthernetFace to communicate with the given multicast group
@@ -69,7 +65,7 @@
*
* \throws EthernetFactory::Error or EthernetTransport::Error
*/
- shared_ptr<face::LpFaceWrapper>
+ shared_ptr<Face>
createMulticastFace(const NetworkInterfaceInfo& interface,
const ethernet::Address& address);
@@ -96,7 +92,7 @@
* \returns shared pointer to the existing EthernetFace object
* or nullptr when such face does not exist
*/
- shared_ptr<face::LpFaceWrapper>
+ shared_ptr<Face>
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 611b151..7c4dee4 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 @@
{
}
-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 93aebf4..08facf8 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 @@
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<T>() 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 5367d39..69d32c1 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -25,73 +25,31 @@
#include "face.hpp"
-#include <ndn-cxx/management/nfd-face-event-notification.hpp>
-
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<LinkService> service, unique_ptr<Transport> transport)
+ : afterReceiveInterest(service->afterReceiveInterest)
+ , afterReceiveData(service->afterReceiveData)
+ , afterReceiveNack(service->afterReceiveNack)
+ , afterStateChange(transport->afterStateChange)
+ , m_id(INVALID_FACEID)
+ , m_service(std::move(service))
+ , m_transport(std::move(transport))
+ , 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<Face>& 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<Interest> i = make_shared<Interest>();
- i->wireDecode(element);
- this->onReceiveInterest(*i);
- }
- else if (element.type() == tlv::Data)
- {
- shared_ptr<Data> d = make_shared<Data>();
- 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 d964ef1..d783dd0 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 <http://www.gnu.org/licenses/>.
*/
-#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 <ndn-cxx/management/nfd-face-status.hpp>
-
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 @@
/// 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<Face>
+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<Face>, noncopyable
{
public:
- /**
- * \brief Face-related error
+ Face(unique_ptr<LinkService> service, unique_ptr<Transport> 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<Face, Interest> onReceiveInterest;
-
- /// fires when a Data is received
- signal::Signal<Face, Data> onReceiveData;
-
- /// fires when a Nack is received
- signal::Signal<Face, lp::Nack> onReceiveNack;
-
- /// fires when an Interest is sent out
- signal::Signal<Face, Interest> onSendInterest;
-
- /// fires when a Data is sent out
- signal::Signal<Face, Data> onSendData;
-
- /// fires when a Nack is sent out
- signal::Signal<Face, lp::Nack> onSendNack;
-
- /// fires when face disconnects or fails to perform properly
- signal::Signal<Face, std::string/*reason*/> onFail;
-
- /// 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<LinkService, Interest>& afterReceiveInterest;
+
+ /** \brief signals on Data received
+ */
+ signal::Signal<LinkService, Data>& afterReceiveData;
+
+ /** \brief signals on Nack received
+ */
+ signal::Signal<LinkService, lp::Nack>& afterReceiveNack;
+
+public: // static properties
+ /** \return face ID
+ */
FaceId
getId() const;
- /** \brief 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<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
+
+ /** \brief request the face to be closed
+ *
+ * This operation is effective only if face is in UP or DOWN state,
+ * otherwise it has no effect.
+ * The face changes state to CLOSING, and performs cleanup procedure.
+ * The state will be changed to CLOSED when cleanup is complete, which may
+ * happen synchronously or asynchronously.
+ *
+ * \warning the face must not be deallocated until its state changes to CLOSED
+ */
+ void
+ close();
+
+ const FaceCounters&
+ getCounters() const;
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<LinkService> m_service;
+ unique_ptr<Transport> 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 @@
}
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<Face>& flh);
template<typename T>
typename std::enable_if<std::is_base_of<Face, T>::value, std::ostream&>::type
-operator<<(std::ostream& os, const face::FaceLogHelper<T>& flh)
+operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
{
- const Face& face = flh.obj;
- os << "[id=" << face.getId() << ",local=" << face.getLocalUri() <<
- ",remote=" << face.getRemoteUri() << "] ";
- return os;
+ return os << FaceLogHelper<Face>(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 c89f87f..8bea03d 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 @@
GenericLinkService::Options serviceOpts;
serviceOpts.allowLocalFields = true;
- auto face = make_unique<LpFace>(make_unique<GenericLinkService>(serviceOpts),
- make_unique<InternalForwarderTransport>());
- auto faceW = make_shared<LpFaceWrapper>(std::move(face));
- // TODO#3172 eliminate wrapper
+ auto face = make_shared<Face>(make_unique<GenericLinkService>(serviceOpts),
+ make_unique<InternalForwarderTransport>());
- InternalForwarderTransport* forwarderTransport =
- static_cast<InternalForwarderTransport*>(faceW->getLpFace()->getTransport());
+ auto forwarderTransport = static_cast<InternalForwarderTransport*>(face->getTransport());
auto clientTransport = make_shared<InternalClientTransport>();
clientTransport->connectToForwarder(forwarderTransport);
auto clientFace = make_shared<ndn::Face>(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 93507e0..00dd6f0 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 @@
}
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 @@
std::ostream&
operator<<(std::ostream& os, const FaceLogHelper<LinkService>& 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 031735a..618e863 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 @@
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 @@
* \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 @@
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 920997a..0000000
--- 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 <http://www.gnu.org/licenses/>.
- */
-
-#include "lp-face-wrapper.hpp"
-
-namespace nfd {
-namespace face {
-
-LpFaceWrapper::LpFaceWrapper(unique_ptr<LpFace> face)
- : Face(face->getRemoteUri(), face->getLocalUri(),
- face->getScope() == ndn::nfd::FACE_SCOPE_LOCAL,
- face->getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS)
- , m_face(std::move(face))
-{
- this->Face::setPersistency(m_face->getPersistency());
- m_face->afterReceiveInterest.connect(bind(&LpFaceWrapper::dispatchInterest, this, _1));
- m_face->afterReceiveData.connect(bind(&LpFaceWrapper::dispatchData, this, _1));
- m_face->afterReceiveNack.connect(bind(&LpFaceWrapper::dispatchNack, this, _1));
- m_face->afterStateChange.connect(bind(&LpFaceWrapper::handleStateChange, this, _1, _2));
-}
-
-void
-LpFaceWrapper::setPersistency(ndn::nfd::FacePersistency persistency)
-{
- this->Face::setPersistency(persistency);
- m_face->setPersistency(persistency);
-}
-
-void
-LpFaceWrapper::setId(nfd::FaceId faceId)
-{
- this->Face::setId(faceId);
-
- FaceId lpId = static_cast<FaceId>(faceId);
- if (faceId == nfd::INVALID_FACEID) {
- lpId = INVALID_FACEID;
- }
- m_face->setId(lpId);
-}
-
-void
-LpFaceWrapper::dispatchInterest(const Interest& interest)
-{
- this->emitSignal(onReceiveInterest, interest);
-}
-
-void
-LpFaceWrapper::dispatchData(const Data& data)
-{
- this->emitSignal(onReceiveData, data);
-}
-
-void
-LpFaceWrapper::dispatchNack(const ndn::lp::Nack& nack)
-{
- this->emitSignal(onReceiveNack, nack);
-}
-
-void
-LpFaceWrapper::handleStateChange(FaceState oldState, FaceState newState)
-{
- if (newState != FaceState::CLOSED) {
- return;
- }
-
- switch (oldState) {
- case FaceState::CLOSING:
- this->fail("LpFace closed");
- break;
- case FaceState::FAILED:
- this->fail("LpFace failed");
- break;
- default:
- BOOST_ASSERT(false);
- break;
- }
-}
-
-} // namespace face
-} // namespace nfd
diff --git a/daemon/face/lp-face-wrapper.hpp b/daemon/face/lp-face-wrapper.hpp
deleted file mode 100644
index 4cfb0f3..0000000
--- 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_DAEMON_FACE_LP_FACE_WRAPPER_HPP
-#define NFD_DAEMON_FACE_LP_FACE_WRAPPER_HPP
-
-#include "common.hpp"
-#include "face.hpp"
-#include "lp-face.hpp"
-
-namespace nfd {
-namespace face {
-
-/** \brief an adaptor to provide old Face APIs from an LpFace
- * \sa LpFace
- */
-class LpFaceWrapper : public Face
-{
-public:
- explicit
- LpFaceWrapper(unique_ptr<LpFace> face);
-
- LpFace*
- getLpFace();
-
- virtual void
- sendInterest(const Interest& interest) DECL_OVERRIDE;
-
- virtual void
- sendData(const Data& data) DECL_OVERRIDE;
-
- virtual void
- sendNack(const lp::Nack& nack) DECL_OVERRIDE;
-
- virtual void
- close() DECL_OVERRIDE;
-
- virtual bool
- isUp() const DECL_OVERRIDE;
-
- virtual void
- setPersistency(ndn::nfd::FacePersistency persistency) DECL_OVERRIDE;
-
- virtual const FaceCounters&
- getCounters() const DECL_OVERRIDE;
-
-protected:
- virtual void
- setId(nfd::FaceId faceId) DECL_OVERRIDE;
-
-private:
- void
- dispatchInterest(const Interest& interest);
-
- void
- dispatchData(const Data& data);
-
- void
- dispatchNack(const lp::Nack& nack);
-
- void
- handleStateChange(FaceState oldState, FaceState newState);
-
-private:
- unique_ptr<LpFace> m_face;
-};
-
-inline LpFace*
-LpFaceWrapper::getLpFace()
-{
- return m_face.get();
-}
-
-inline void
-LpFaceWrapper::sendInterest(const Interest& interest)
-{
- this->emitSignal(onSendInterest, interest);
- m_face->sendInterest(interest);
-}
-
-inline void
-LpFaceWrapper::sendData(const Data& data)
-{
- this->emitSignal(onSendData, data);
- m_face->sendData(data);
-}
-
-inline void
-LpFaceWrapper::sendNack(const lp::Nack& nack)
-{
- this->emitSignal(onSendNack, nack);
- m_face->sendNack(nack);
-}
-
-inline void
-LpFaceWrapper::close()
-{
- m_face->close();
-}
-
-inline bool
-LpFaceWrapper::isUp() const
-{
- return m_face->getState() == FaceState::UP;
-}
-
-inline const FaceCounters&
-LpFaceWrapper::getCounters() const
-{
- return m_face->getCounters();
-}
-
-} // namespace face
-} // namespace nfd
-
-#endif // NFD_DAEMON_FACE_LP_FACE_WRAPPER_HPP
diff --git a/daemon/face/lp-face.cpp b/daemon/face/lp-face.cpp
deleted file mode 100644
index 55cc4d0..0000000
--- a/daemon/face/lp-face.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "lp-face.hpp"
-
-namespace nfd {
-namespace face {
-
-LpFace::LpFace(unique_ptr<LinkService> service, unique_ptr<Transport> transport)
- : afterReceiveInterest(service->afterReceiveInterest)
- , afterReceiveData(service->afterReceiveData)
- , afterReceiveNack(service->afterReceiveNack)
- , afterStateChange(transport->afterStateChange)
- , m_id(INVALID_FACEID)
- , m_service(std::move(service))
- , m_transport(std::move(transport))
- , m_counters(m_service->getCounters(), m_transport->getCounters())
-{
- m_service->setFaceAndTransport(*this, *m_transport);
- m_transport->setFaceAndLinkService(*this, *m_service);
-}
-
-} // namespace face
-} // namespace nfd
diff --git a/daemon/face/lp-face.hpp b/daemon/face/lp-face.hpp
deleted file mode 100644
index 130fe00..0000000
--- 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_DAEMON_LP_FACE_HPP
-#define NFD_DAEMON_LP_FACE_HPP
-
-#include "transport.hpp"
-#include "link-service.hpp"
-#include "face-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<LinkService> service, unique_ptr<Transport> transport);
-
- LinkService*
- getLinkService();
-
- Transport*
- getTransport();
-
-public: // upper interface connected to forwarding
- /** \brief sends Interest on Face
- */
- void
- sendInterest(const Interest& interest);
-
- /** \brief sends Data on Face
- */
- void
- sendData(const Data& data);
-
- /** \brief sends Nack on Face
- */
- void
- sendNack(const lp::Nack& nack);
-
- /** \brief signals on Interest received
- */
- signal::Signal<LinkService, Interest>& afterReceiveInterest;
-
- /** \brief signals on Data received
- */
- signal::Signal<LinkService, Data>& afterReceiveData;
-
- /** \brief signals on Nack received
- */
- signal::Signal<LinkService, lp::Nack>& afterReceiveNack;
-
-public: // static properties
- /** \return face ID
- */
- FaceId
- getId() const;
-
- /** \brief sets face ID
- * \note Normally, this should only be invoked by FaceTable.
- */
- void
- setId(FaceId id);
-
- /** \return a FaceUri representing local endpoint
- */
- FaceUri
- getLocalUri() const;
-
- /** \return a FaceUri representing remote endpoint
- */
- FaceUri
- getRemoteUri() const;
-
- /** \return whether face is local or non-local for scope control purpose
- */
- ndn::nfd::FaceScope
- getScope() const;
-
- /** \return face persistency setting
- */
- ndn::nfd::FacePersistency
- getPersistency() const;
-
- /** \brief changes face persistency setting
- */
- void
- setPersistency(ndn::nfd::FacePersistency persistency);
-
- /** \return whether face is point-to-point or multi-access
- */
- ndn::nfd::LinkType
- getLinkType() const;
-
-public: // dynamic properties
- /** \return face state
- */
- FaceState
- getState() const;
-
- /** \brief signals after face state changed
- */
- signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
-
- /** \brief request the face to be closed
- *
- * This operation is effective only if face is in UP or DOWN state,
- * otherwise it has no effect.
- * The face changes state to CLOSING, and performs cleanup procedure.
- * The state will be changed to CLOSED when cleanup is complete, which may
- * happen synchronously or asynchronously.
- *
- * \warning the face must not be deallocated until its state changes to CLOSED
- */
- void
- close();
-
- const FaceCounters&
- getCounters() const;
-
-private:
- FaceId m_id;
- unique_ptr<LinkService> m_service;
- unique_ptr<Transport> m_transport;
- FaceCounters m_counters;
-};
-
-inline LinkService*
-LpFace::getLinkService()
-{
- return m_service.get();
-}
-
-inline Transport*
-LpFace::getTransport()
-{
- return m_transport.get();
-}
-
-inline void
-LpFace::sendInterest(const Interest& interest)
-{
- m_service->sendInterest(interest);
-}
-
-inline void
-LpFace::sendData(const Data& data)
-{
- m_service->sendData(data);
-}
-
-inline void
-LpFace::sendNack(const lp::Nack& nack)
-{
- m_service->sendNack(nack);
-}
-
-inline FaceId
-LpFace::getId() const
-{
- return m_id;
-}
-
-inline void
-LpFace::setId(FaceId id)
-{
- m_id = id;
-}
-
-inline FaceUri
-LpFace::getLocalUri() const
-{
- return m_transport->getLocalUri();
-}
-
-inline FaceUri
-LpFace::getRemoteUri() const
-{
- return m_transport->getRemoteUri();
-}
-
-inline ndn::nfd::FaceScope
-LpFace::getScope() const
-{
- return m_transport->getScope();
-}
-
-inline ndn::nfd::FacePersistency
-LpFace::getPersistency() const
-{
- return m_transport->getPersistency();
-}
-
-inline void
-LpFace::setPersistency(ndn::nfd::FacePersistency persistency)
-{
- return m_transport->setPersistency(persistency);
-}
-
-inline ndn::nfd::LinkType
-LpFace::getLinkType() const
-{
- return m_transport->getLinkType();
-}
-
-inline FaceState
-LpFace::getState() const
-{
- return m_transport->getState();
-}
-
-inline void
-LpFace::close()
-{
- m_transport->close();
-}
-
-inline const FaceCounters&
-LpFace::getCounters() const
-{
- return m_counters;
-}
-
-template<typename T>
-typename std::enable_if<std::is_base_of<LpFace, T>::value, std::ostream&>::type
-operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
-{
- const LpFace& face = flh.obj;
- os << "[id=" << face.getId() << ",local=" << face.getLocalUri() <<
- ",remote=" << face.getRemoteUri() << "] ";
- return os;
-}
-
-} // namespace face
-
-// using face::FaceId; // TODO uncomment in #3172
-using face::LpFace;
-
-} // namespace nfd
-
-#endif // NFD_DAEMON_LP_FACE_HPP
diff --git a/daemon/face/null-face.cpp b/daemon/face/null-face.cpp
index 2c409a7..a793e3e 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 @@
shared_ptr<Face>
makeNullFace(const FaceUri& uri)
{
- auto face = make_unique<LpFace>(make_unique<GenericLinkService>(),
- make_unique<InternalForwarderTransport>(uri, uri, ndn::nfd::FACE_SCOPE_LOCAL));
- auto faceW = make_shared<LpFaceWrapper>(std::move(face));
- // TODO#3172 eliminate wrapper
-
- return faceW;
+ return make_shared<Face>(make_unique<GenericLinkService>(),
+ make_unique<InternalForwarderTransport>(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 1c1dd2e..0000000
--- 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 <http://www.gnu.org/licenses/>.
- */
-
-#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<typename R>
- 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<typename R>
- 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<typename R>
- 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 f9873c2..21943c8 100644
--- a/daemon/face/tcp-channel.cpp
+++ b/daemon/face/tcp-channel.cpp
@@ -99,7 +99,7 @@
const FaceCreatedCallback& onFaceCreated,
bool isOnDemand)
{
- shared_ptr<face::LpFaceWrapper> face;
+ shared_ptr<Face> face;
tcp::Endpoint remoteEndpoint = socket.remote_endpoint();
auto it = m_channelFaces.find(remoteEndpoint);
@@ -108,14 +108,14 @@
: ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
auto linkService = make_unique<face::GenericLinkService>();
auto transport = make_unique<face::TcpTransport>(std::move(socket), persistency);
- auto lpFace = make_unique<face::LpFace>(std::move(linkService), std::move(transport));
- face = make_shared<face::LpFaceWrapper>(std::move(lpFace));
+ face = make_shared<Face>(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 799fbf1..c819014 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 @@
const FaceCreationFailedCallback& onConnectFailed);
private:
- std::map<tcp::Endpoint, shared_ptr<face::LpFaceWrapper>> m_channelFaces;
+ std::map<tcp::Endpoint, shared_ptr<Face>> 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 e3e1e07..2d2c3dd 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 @@
}
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 @@
operator<<(std::ostream& os, const FaceLogHelper<Transport>& 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 626809c..56ff730 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_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 @@
* \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 @@
doSend(Packet&& packet) = 0;
private:
- LpFace* m_face;
+ Face* m_face;
LinkService* m_service;
FaceUri m_localUri;
FaceUri m_remoteUri;
@@ -318,7 +318,7 @@
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 bb6529f..e6d65df 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -120,7 +120,7 @@
NFD_LOG_DEBUG("[" << m_localEndpoint << "] New peer " << m_remoteEndpoint);
bool isCreated = false;
- shared_ptr<face::LpFaceWrapper> face;
+ shared_ptr<Face> face;
try {
std::tie(isCreated, face) = createFace(m_remoteEndpoint, ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
}
@@ -136,12 +136,12 @@
onFaceCreated(face);
// dispatch the datagram to the face for processing
- static_cast<face::UnicastUdpTransport*>(face->getLpFace()->getTransport())->receiveDatagram(m_inputBuffer, nBytesReceived, error);
+ static_cast<face::UnicastUdpTransport*>(face->getTransport())->receiveDatagram(m_inputBuffer, nBytesReceived, error);
this->waitForNewPeer(onFaceCreated, onReceiveFailed);
}
-std::pair<bool, shared_ptr<face::LpFaceWrapper>>
+std::pair<bool, shared_ptr<Face>>
UdpChannel::createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersistency persistency)
{
auto it = m_channelFaces.find(remoteEndpoint);
@@ -166,13 +166,13 @@
auto linkService = make_unique<face::GenericLinkService>();
auto transport = make_unique<face::UnicastUdpTransport>(std::move(socket), persistency, m_idleFaceTimeout);
- auto face = make_shared<face::LpFaceWrapper>(make_unique<face::LpFace>(
- std::move(linkService), std::move(transport)));
+ auto face = make_shared<Face>(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 a24d1ec..a2506d4 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 @@
const FaceCreatedCallback& onFaceCreated,
const FaceCreationFailedCallback& onReceiveFailed);
- std::pair<bool, shared_ptr<face::LpFaceWrapper>>
+ std::pair<bool, shared_ptr<Face>>
createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersistency persistency);
private:
- std::map<udp::Endpoint, shared_ptr<face::LpFaceWrapper>> m_channelFaces;
+ std::map<udp::Endpoint, shared_ptr<Face>> m_channelFaces;
udp::Endpoint m_localEndpoint;
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index 2a39e36..cc60a63 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 @@
return createChannel(endpoint, timeout);
}
-shared_ptr<face::LpFaceWrapper>
+shared_ptr<Face>
UdpFactory::createMulticastFace(const udp::Endpoint& localEndpoint,
const udp::Endpoint& multicastEndpoint,
const std::string& networkInterfaceName/* = ""*/)
@@ -210,18 +209,15 @@
auto transport = make_unique<face::MulticastUdpTransport>(localEndpoint, multicastEndpoint,
std::move(receiveSocket),
std::move(sendSocket));
- auto lpFace = make_unique<face::LpFace>(std::move(linkService), std::move(transport));
- face = make_shared<face::LpFaceWrapper>(std::move(lpFace));
+ face = make_shared<Face>(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<face::LpFaceWrapper>
+shared_ptr<Face>
UdpFactory::createMulticastFace(const std::string& localIp,
const std::string& multicastIp,
const std::string& multicastPort,
@@ -294,7 +290,7 @@
return nullptr;
}
-shared_ptr<face::LpFaceWrapper>
+shared_ptr<Face>
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 134c5ee..9c851bd 100644
--- a/daemon/face/udp-factory.hpp
+++ b/daemon/face/udp-factory.hpp
@@ -49,7 +49,7 @@
}
};
- typedef std::map<udp::Endpoint, shared_ptr<face::LpFaceWrapper>> MulticastFaceMap;
+ typedef std::map<udp::Endpoint, shared_ptr<Face>> MulticastFaceMap;
/**
* \brief Create UDP-based channel using udp::Endpoint
@@ -128,12 +128,12 @@
* \see http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/ip__udp/endpoint.html
* for details on ways to create udp::Endpoint
*/
- shared_ptr<face::LpFaceWrapper>
+ shared_ptr<Face>
createMulticastFace(const udp::Endpoint& localEndpoint,
const udp::Endpoint& multicastEndpoint,
const std::string& networkInterfaceName = "");
- shared_ptr<face::LpFaceWrapper>
+ shared_ptr<Face>
createMulticastFace(const std::string& localIp,
const std::string& multicastIp,
const std::string& multicastPort,
@@ -181,7 +181,7 @@
* \returns shared pointer to the existing multicast UdpFace object
* or nullptr when such face does not exist
*/
- shared_ptr<face::LpFaceWrapper>
+ shared_ptr<Face>
findMulticastFace(const udp::Endpoint& localEndpoint) const;
private:
diff --git a/daemon/face/unix-stream-channel.cpp b/daemon/face/unix-stream-channel.cpp
index c34ad7b..5b56c6a 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 @@
auto linkService = make_unique<face::GenericLinkService>();
auto transport = make_unique<face::UnixStreamTransport>(std::move(m_socket));
- auto lpFace = make_unique<face::LpFace>(std::move(linkService), std::move(transport));
- auto face = make_shared<face::LpFaceWrapper>(std::move(lpFace));
+ auto face = make_shared<Face>(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 520bb7d..75626ab 100644
--- a/daemon/face/websocket-channel.cpp
+++ b/daemon/face/websocket-channel.cpp
@@ -77,7 +77,7 @@
{
auto it = m_channelFaces.find(hdl);
if (it != m_channelFaces.end()) {
- static_cast<face::WebSocketTransport*>(it->second->getLpFace()->getTransport())->handlePongTimeout();
+ static_cast<face::WebSocketTransport*>(it->second->getTransport())->handlePongTimeout();
}
else {
NFD_LOG_WARN("Pong timeout on unknown transport");
@@ -89,7 +89,7 @@
{
auto it = m_channelFaces.find(hdl);
if (it != m_channelFaces.end()) {
- static_cast<face::WebSocketTransport*>(it->second->getLpFace()->getTransport())->handlePong();
+ static_cast<face::WebSocketTransport*>(it->second->getTransport())->handlePong();
}
else {
NFD_LOG_WARN("Pong received on unknown transport");
@@ -102,7 +102,7 @@
{
auto it = m_channelFaces.find(hdl);
if (it != m_channelFaces.end()) {
- static_cast<face::WebSocketTransport*>(it->second->getLpFace()->getTransport())->receiveMessage(msg->get_payload());
+ static_cast<face::WebSocketTransport*>(it->second->getTransport())->receiveMessage(msg->get_payload());
}
else {
NFD_LOG_WARN("Message received on unknown transport");
@@ -114,16 +114,10 @@
{
auto linkService = make_unique<face::GenericLinkService>();
auto transport = make_unique<face::WebSocketTransport>(hdl, ref(m_server), m_pingInterval);
- auto lpFace = make_unique<face::LpFace>(std::move(linkService), std::move(transport));
- auto face = make_shared<face::LpFaceWrapper>(std::move(lpFace));
+ auto face = make_shared<Face>(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 @@
{
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 47eda8c..1d56731 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 <http://www.gnu.org/licenses/>.
- **/
+ */
#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 @@
websocket::Endpoint m_localEndpoint;
websocket::Server m_server;
- std::map<websocketpp::connection_hdl, shared_ptr<face::LpFaceWrapper>,
+ std::map<websocketpp::connection_hdl, shared_ptr<Face>,
std::owner_less<websocketpp::connection_hdl>> m_channelFaces;
FaceCreatedCallback m_onFaceCreatedCallback;