face: InternalForwarderTransport & InternalClientTransport
InternalForwarderTransport and InternalClientTransport are a pair of forwarder-side
and client-side transports that can be connected with each other, so that link-layer
packets sent by one transport can be received by the other.
They are used together with LpFace, GenericLinkService, and ndn::Face to replace
InternalFace and InternalClientFace used by NFD management.
They also replace TopologyForwarderTransport and TopologyClientTransport used by
TopologyTester of forwarding unit tests.
refs #3225
Change-Id: I5b6b579c43dfd0b1b9def5100be2ce516219cb74
diff --git a/daemon/face/internal-transport.hpp b/daemon/face/internal-transport.hpp
new file mode 100644
index 0000000..a282638
--- /dev/null
+++ b/daemon/face/internal-transport.hpp
@@ -0,0 +1,127 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_DAEMON_FACE_INTERNAL_TRANSPORT_HPP
+#define NFD_DAEMON_FACE_INTERNAL_TRANSPORT_HPP
+
+#include "transport.hpp"
+#include <ndn-cxx/transport/transport.hpp>
+
+namespace nfd {
+namespace face {
+
+/** \brief abstracts a transport that can be paired with another
+ */
+class InternalTransportBase
+{
+public:
+ /** \brief causes the transport to receive a link-layer packet
+ */
+ virtual void
+ receiveFromLink(const Block& packet) = 0;
+
+ signal::Signal<InternalTransportBase, Block> afterSend;
+
+protected:
+ DECLARE_SIGNAL_EMIT(afterSend)
+};
+
+/** \brief implements a forwarder-side transport that can be paired with another
+ */
+class InternalForwarderTransport : public face::Transport, public InternalTransportBase
+{
+public:
+ InternalForwarderTransport(const FaceUri& localUri = FaceUri("internal://"),
+ const FaceUri& remoteUri = FaceUri("internal://"),
+ ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_LOCAL,
+ ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+
+ virtual void
+ receiveFromLink(const Block& packet) DECL_OVERRIDE;
+
+protected:
+ virtual void
+ doClose() DECL_OVERRIDE;
+
+private:
+ virtual void
+ doSend(Packet&& packet) DECL_OVERRIDE;
+
+private:
+ NFD_LOG_INCLASS_DECLARE();
+};
+
+/** \brief implements a client-side transport that can be paired with another
+ */
+class InternalClientTransport : public ndn::Transport, public InternalTransportBase
+{
+public:
+ /** \brief connect to a forwarder-side transport
+ * \param forwarderTransport the forwarder-side transport to connect to; may be nullptr
+ *
+ * The connected forwarder-side transport will be disconnected automatically if this method
+ * is called again, or if that transport is closed.
+ * It's safe to use InternalClientTransport without a connected forwarder-side transport:
+ * all sent packets would be lost, and nothing would be received.
+ */
+ void
+ connectToForwarder(InternalForwarderTransport* forwarderTransport);
+
+ virtual void
+ receiveFromLink(const Block& packet) DECL_OVERRIDE;
+
+ virtual void
+ close() DECL_OVERRIDE
+ {
+ }
+
+ virtual void
+ pause() DECL_OVERRIDE
+ {
+ }
+
+ virtual void
+ resume() DECL_OVERRIDE
+ {
+ }
+
+ virtual void
+ send(const Block& wire) DECL_OVERRIDE;
+
+ virtual void
+ send(const Block& header, const Block& payload) DECL_OVERRIDE;
+
+private:
+ NFD_LOG_INCLASS_DECLARE();
+
+ signal::ScopedConnection m_fwToClientTransmitConn;
+ signal::ScopedConnection m_clientToFwTransmitConn;
+ signal::ScopedConnection m_fwTransportStateConn;
+};
+
+} // namespace face
+} // namespace nfd
+
+#endif // NFD_DAEMON_FACE_INTERNAL_TRANSPORT_HPP