face: Transport::getMtu
refs #3253
Change-Id: Ia4c5cfe210a99b798ce7d05f74ebdd7cfab214f4
diff --git a/daemon/face/transport.hpp b/daemon/face/transport.hpp
index 144e0dc..b7f1c30 100644
--- a/daemon/face/transport.hpp
+++ b/daemon/face/transport.hpp
@@ -51,6 +51,10 @@
std::ostream&
operator<<(std::ostream& os, TransportState state);
+/** \brief indicates the transport has no limit on payload size
+ */
+const ssize_t MTU_UNLIMITED = -1;
+
/** \brief the lower part of an LpFace
* \sa LpFace
*/
@@ -125,12 +129,15 @@
close();
/** \brief send a link-layer packet
+ * \note This operation has no effect if \p getState() is neither UP nor DOWN
+ * \warning undefined behavior if packet size exceeds MTU limit
*/
void
send(Packet&& packet);
protected: // upper interface to be invoked by subclass
/** \brief receive a link-layer packet
+ * \warning undefined behavior if packet size exceeds MTU limit
*/
void
receive(Packet&& packet);
@@ -166,6 +173,18 @@
ndn::nfd::LinkType
getLinkType() const;
+ /** \return maximum payload size
+ * \retval MTU_UNLIMITED transport has no limit on payload size
+ *
+ * This size is the maximum packet size that can be sent or received through this transport.
+ *
+ * For a datagram-based transport, this is typically the Maximum Transmission Unit (MTU),
+ * after the overhead of headers introduced by the transport has been accounted for.
+ * For a stream-based transport, this is typically unlimited (MTU_UNLIMITED).
+ */
+ ssize_t
+ getMtu() const;
+
public: // dynamic properties
/** \return transport state
*/
@@ -189,6 +208,9 @@
void
setLinkType(ndn::nfd::LinkType linkType);
+ void
+ setMtu(ssize_t mtu);
+
/** \brief set transport state
*
* Only the following transitions are valid:
@@ -213,8 +235,11 @@
/** \brief performs Transport specific operations to close the transport
*
+ * This is invoked once by \p close() after changing state to CLOSING.
+ * It will not be invoked by Transport class if the transport is already CLOSING or CLOSED.
+ *
* When the cleanup procedure is complete, this method should change state to CLOSED.
- * This can happen synchronously or asynchronously.
+ * This transition can happen synchronously or asynchronously.
*/
virtual void
doClose() = 0;
@@ -222,6 +247,7 @@
private: // to be overridden by subclass
/** \brief performs Transport specific operations to send a packet
* \param packet the packet, which must be a well-formed TLV block
+ * \pre state is either UP or DOWN
*/
virtual void
doSend(Packet&& packet) = 0;
@@ -234,6 +260,7 @@
ndn::nfd::FaceScope m_scope;
ndn::nfd::FacePersistency m_persistency;
ndn::nfd::LinkType m_linkType;
+ ssize_t m_mtu;
TransportState m_state;
LinkLayerCounters* m_counters; // TODO#3177 change into LinkCounters
};
@@ -262,18 +289,36 @@
return m_localUri;
}
+inline void
+Transport::setLocalUri(const FaceUri& uri)
+{
+ m_localUri = uri;
+}
+
inline FaceUri
Transport::getRemoteUri() const
{
return m_remoteUri;
}
+inline void
+Transport::setRemoteUri(const FaceUri& uri)
+{
+ m_remoteUri = uri;
+}
+
inline ndn::nfd::FaceScope
Transport::getScope() const
{
return m_scope;
}
+inline void
+Transport::setScope(ndn::nfd::FaceScope scope)
+{
+ m_scope = scope;
+}
+
inline ndn::nfd::FacePersistency
Transport::getPersistency() const
{
@@ -293,36 +338,31 @@
return m_linkType;
}
-inline TransportState
-Transport::getState() const
-{
- return m_state;
-}
-
-inline void
-Transport::setLocalUri(const FaceUri& uri)
-{
- m_localUri = uri;
-}
-
-inline void
-Transport::setRemoteUri(const FaceUri& uri)
-{
- m_remoteUri = uri;
-}
-
-inline void
-Transport::setScope(ndn::nfd::FaceScope scope)
-{
- m_scope = scope;
-}
-
inline void
Transport::setLinkType(ndn::nfd::LinkType linkType)
{
m_linkType = linkType;
}
+inline ssize_t
+Transport::getMtu() const
+{
+ return m_mtu;
+}
+
+inline void
+Transport::setMtu(ssize_t mtu)
+{
+ BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0);
+ m_mtu = mtu;
+}
+
+inline TransportState
+Transport::getState() const
+{
+ return m_state;
+}
+
std::ostream&
operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh);