NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
transport.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2019, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef NFD_DAEMON_FACE_TRANSPORT_HPP
27 #define NFD_DAEMON_FACE_TRANSPORT_HPP
28 
29 #include "face-common.hpp"
30 #include "common/counter.hpp"
31 
32 namespace nfd {
33 namespace face {
34 
37 enum class TransportState {
38  NONE,
39  UP,
40  DOWN,
41  CLOSING,
42  FAILED,
43  CLOSED
44 };
45 
46 std::ostream&
47 operator<<(std::ostream& os, TransportState state);
48 
54 {
55 public:
63 
70 
79 
87 };
88 
91 const ssize_t MTU_UNLIMITED = -1;
92 
95 const ssize_t MTU_INVALID = -2;
96 
99 const ssize_t QUEUE_UNSUPPORTED = -1;
100 
103 const ssize_t QUEUE_ERROR = -2;
104 
108 class Transport : protected virtual TransportCounters, noncopyable
109 {
110 public:
115 
124  Transport();
125 
126  virtual
128 
129 public:
133  void
134  setFaceAndLinkService(Face& face, LinkService& service);
135 
138  const Face*
139  getFace() const;
140 
143  const LinkService*
144  getLinkService() const;
145 
148  LinkService*
149  getLinkService();
150 
151  virtual const Counters&
152  getCounters() const;
153 
154 public: // upper interface
163  void
164  close();
165 
172  void
173  send(const Block& packet, const EndpointId& endpoint = 0);
174 
175 public: // static properties
178  FaceUri
179  getLocalUri() const;
180 
183  FaceUri
184  getRemoteUri() const;
185 
189  getScope() const;
190 
194  getPersistency() const;
195 
204  bool
206 
209  void
211 
215  getLinkType() const;
216 
226  ssize_t
227  getMtu() const;
228 
233  ssize_t
234  getSendQueueCapacity() const;
235 
236 public: // dynamic properties
240  getState() const;
241 
245 
250  getExpirationTime() const;
251 
256  virtual ssize_t
258  {
259  return QUEUE_UNSUPPORTED;
260  }
261 
262 protected: // upper interface to be invoked by subclass
268  void
269  receive(const Block& packet, const EndpointId& endpoint = 0);
270 
271 protected: // properties to be set by subclass
272  void
273  setLocalUri(const FaceUri& uri);
274 
275  void
276  setRemoteUri(const FaceUri& uri);
277 
278  void
280 
281  void
283 
284  void
285  setMtu(ssize_t mtu);
286 
287  void
288  setSendQueueCapacity(ssize_t sendQueueCapacity);
289 
297  void
298  setState(TransportState newState);
299 
300  void
301  setExpirationTime(const time::steady_clock::TimePoint& expirationTime);
302 
303 protected: // to be overridden by subclass
310  virtual bool
312 
319  virtual void
321 
330  virtual void
331  doClose() = 0;
332 
333 private: // to be overridden by subclass
339  virtual void
340  doSend(const Block& packet, const EndpointId& endpoint) = 0;
341 
342 public:
347  static constexpr ssize_t MIN_MTU = 64;
348 
349 private:
350  Face* m_face;
351  LinkService* m_service;
352  FaceUri m_localUri;
353  FaceUri m_remoteUri;
354  ndn::nfd::FaceScope m_scope;
355  ndn::nfd::FacePersistency m_persistency;
356  ndn::nfd::LinkType m_linkType;
357  ssize_t m_mtu;
358  ssize_t m_sendQueueCapacity;
359  TransportState m_state;
360  time::steady_clock::TimePoint m_expirationTime;
361 };
362 
363 inline const Face*
365 {
366  return m_face;
367 }
368 
369 inline const LinkService*
371 {
372  return m_service;
373 }
374 
375 inline LinkService*
377 {
378  return m_service;
379 }
380 
381 inline const Transport::Counters&
383 {
384  return *this;
385 }
386 
387 inline FaceUri
389 {
390  return m_localUri;
391 }
392 
393 inline void
395 {
396  m_localUri = uri;
397 }
398 
399 inline FaceUri
401 {
402  return m_remoteUri;
403 }
404 
405 inline void
407 {
408  m_remoteUri = uri;
409 }
410 
411 inline ndn::nfd::FaceScope
413 {
414  return m_scope;
415 }
416 
417 inline void
419 {
420  m_scope = scope;
421 }
422 
425 {
426  return m_persistency;
427 }
428 
429 inline ndn::nfd::LinkType
431 {
432  return m_linkType;
433 }
434 
435 inline void
437 {
438  m_linkType = linkType;
439 }
440 
441 inline ssize_t
443 {
444  return m_mtu;
445 }
446 
447 inline void
448 Transport::setMtu(ssize_t mtu)
449 {
450  BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0);
451  m_mtu = mtu;
452 }
453 
454 inline ssize_t
456 {
457  return m_sendQueueCapacity;
458 }
459 
460 inline void
461 Transport::setSendQueueCapacity(ssize_t sendQueueCapacity)
462 {
463  m_sendQueueCapacity = sendQueueCapacity;
464 }
465 
466 inline TransportState
468 {
469  return m_state;
470 }
471 
474 {
475  return m_expirationTime;
476 }
477 
478 inline void
480 {
481  m_expirationTime = expirationTime;
482 }
483 
484 std::ostream&
485 operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh);
486 
487 template<typename T>
488 typename std::enable_if<std::is_base_of<Transport, T>::value &&
489  !std::is_same<Transport, T>::value, std::ostream&>::type
490 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
491 {
492  return os << FaceLogHelper<Transport>(flh.obj);
493 }
494 
495 } // namespace face
496 } // namespace nfd
497 
498 #endif // NFD_DAEMON_FACE_TRANSPORT_HPP
nfd::face::Transport::setSendQueueCapacity
void setSendQueueCapacity(ssize_t sendQueueCapacity)
Definition: transport.hpp:461
nfd::face::TransportState
TransportState
Indicates the state of a transport.
Definition: transport.hpp:37
nfd::face::MTU_INVALID
const ssize_t MTU_INVALID
(for internal use) indicates MTU field is unset
Definition: transport.hpp:95
nfd::face::TransportCounters
Counters provided by a transport.
Definition: transport.hpp:54
nfd::face::TransportState::CLOSED
@ CLOSED
the transport is closed, and can be safely deallocated
nfd::face::Transport::canChangePersistencyTo
bool canChangePersistencyTo(ndn::nfd::FacePersistency newPersistency) const
check whether the face persistency can be changed to newPersistency
Definition: transport.cpp:128
nfd::face::MTU_UNLIMITED
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
Definition: transport.hpp:91
nfd::face::Transport::setMtu
void setMtu(ssize_t mtu)
Definition: transport.hpp:448
nfd::face::Transport::setRemoteUri
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:406
nfd::face::Transport::getRemoteUri
FaceUri getRemoteUri() const
Definition: transport.hpp:400
nfd::face::Transport::~Transport
virtual ~Transport()
nfd::face::Transport::getSendQueueCapacity
ssize_t getSendQueueCapacity() const
Definition: transport.hpp:455
ndn::FaceUri
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:45
nfd::face::Transport::setScope
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:418
nfd::face::Transport::doClose
virtual void doClose()=0
performs Transport specific operations to close the transport
nfd::face::TransportState::NONE
@ NONE
nfd::face::Transport::setState
void setState(TransportState newState)
set transport state
Definition: transport.cpp:173
nfd::face::TransportState::DOWN
@ DOWN
the transport is temporarily down, and is being recovered
nfd::face::Transport::getLinkType
ndn::nfd::LinkType getLinkType() const
Definition: transport.hpp:430
ndn::nfd::LinkType
LinkType
Definition: nfd-constants.hpp:57
face-common.hpp
nfd::face::Transport::getPersistency
ndn::nfd::FacePersistency getPersistency() const
Definition: transport.hpp:424
nfd::face::Transport::setExpirationTime
void setExpirationTime(const time::steady_clock::TimePoint &expirationTime)
Definition: transport.hpp:479
ndn::nfd::FacePersistency
FacePersistency
Definition: nfd-constants.hpp:45
ndn::util::signal::Signal
provides a lightweight signal / event system
Definition: signal.hpp:52
nfd::face::TransportState::CLOSING
@ CLOSING
the transport is being closed gracefully, either by the peer or by a call to close()
nfd::face::Transport::Transport
Transport()
Default constructor.
Definition: transport.cpp:55
nfd::face::Transport::setFaceAndLinkService
void setFaceAndLinkService(Face &face, LinkService &service)
set Face and LinkService for Transport
Definition: transport.cpp:71
nfd::face::operator<<
std::ostream & operator<<(std::ostream &os, const Face &face)
Definition: ndn-common.hpp:87
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
nfd::face::LinkService
the upper part of a Face
Definition: link-service.hpp:76
nfd::face::TransportCounters::nOutPackets
PacketCounter nOutPackets
count of outgoing packets
Definition: transport.hpp:69
nfd::face::Transport::afterChangePersistency
virtual void afterChangePersistency(ndn::nfd::FacePersistency oldPersistency)
invoked after the persistency has been changed
Definition: transport.cpp:168
nfd::face::Face
generalization of a network interface
Definition: face.hpp:53
nfd::face::Transport::send
void send(const Block &packet, const EndpointId &endpoint=0)
Send a link-layer packet.
Definition: transport.cpp:94
nfd::face::TransportCounters::nOutBytes
ByteCounter nOutBytes
total outgoing bytes
Definition: transport.hpp:86
nfd::face::QUEUE_ERROR
const ssize_t QUEUE_ERROR
indicates that the transport was unable to retrieve the queue capacity/length
Definition: transport.hpp:103
nfd::face::QUEUE_UNSUPPORTED
const ssize_t QUEUE_UNSUPPORTED
indicates that the transport does not support reading the queue capacity/length
Definition: transport.hpp:99
counter.hpp
nfd::face::Transport::getScope
ndn::nfd::FaceScope getScope() const
Definition: transport.hpp:412
nfd::face::Transport::getFace
const Face * getFace() const
Definition: transport.hpp:364
nfd::face::Transport::canChangePersistencyToImpl
virtual bool canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const
invoked by canChangePersistencyTo to perform the check
Definition: transport.cpp:144
nfd::face::Transport::setLinkType
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:436
ndn::time::steady_clock::TimePoint
time_point TimePoint
Definition: time.hpp:225
nfd::face::TransportState::UP
@ UP
the transport is up and can transmit packets
nfd::face::Transport::getLocalUri
FaceUri getLocalUri() const
Definition: transport.hpp:388
nfd::PacketCounter
represents a counter of number of packets
Definition: counter.hpp:67
ndn::Block
Represents a TLV element of NDN packet format.
Definition: block.hpp:43
nfd::face::Transport::setPersistency
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
Definition: transport.cpp:150
nfd::face::Transport::getLinkService
const LinkService * getLinkService() const
Definition: transport.hpp:370
nfd::face::Transport::getCounters
virtual const Counters & getCounters() const
Definition: transport.hpp:382
nfd::face::TransportCounters::nInBytes
ByteCounter nInBytes
total incoming bytes
Definition: transport.hpp:78
nfd::face::TransportState::FAILED
@ FAILED
the transport is being closed due to a failure
nfd::face::Transport::getExpirationTime
time::steady_clock::TimePoint getExpirationTime() const
Definition: transport.hpp:473
nfd::face::TransportCounters::nInPackets
PacketCounter nInPackets
count of incoming packets
Definition: transport.hpp:62
nfd::face::Transport::getState
TransportState getState() const
Definition: transport.hpp:467
nfd::face::Transport::MIN_MTU
static constexpr ssize_t MIN_MTU
minimum MTU that may be set on a transport
Definition: transport.hpp:347
nfd::face::EndpointId
uint64_t EndpointId
Identifies a remote endpoint on the link.
Definition: face-common.hpp:65
nfd::face::Transport::receive
void receive(const Block &packet, const EndpointId &endpoint=0)
Pass a received link-layer packet to the upper layer for further processing.
Definition: transport.cpp:115
nfd::face::Transport::close
void close()
Request the transport to be closed.
Definition: transport.cpp:81
ndn::nfd::FaceScope
FaceScope
Definition: nfd-constants.hpp:34
nfd::face::FaceLogHelper
For internal use by FaceLogging macros.
Definition: face-common.hpp:93
nfd::face::Transport
The lower half of a Face.
Definition: transport.hpp:109
nfd::face::Transport::getSendQueueLength
virtual ssize_t getSendQueueLength()
Definition: transport.hpp:257
nfd::ByteCounter
represents a counter of number of bytes
Definition: counter.hpp:85
nfd::face::Transport::getMtu
ssize_t getMtu() const
Definition: transport.hpp:442
nfd::face::FaceLogHelper::obj
const T & obj
Definition: face-common.hpp:102
nfd::face::Transport::setLocalUri
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:394
nfd::face::Transport::afterStateChange
signal::Signal< Transport, TransportState, TransportState > afterStateChange
signals when transport state changes
Definition: transport.hpp:244