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-2018, 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 "core/counter.hpp"
30 #include "face-log.hpp"
31 
33 
34 namespace nfd {
35 namespace face {
36 
37 class Face;
38 class LinkService;
39 
42 enum class TransportState {
43  NONE,
44  UP,
45  DOWN,
46  CLOSING,
47  FAILED,
48  CLOSED
49 };
50 
51 std::ostream&
52 operator<<(std::ostream& os, TransportState state);
53 
59 {
60 public:
68 
75 
84 
92 };
93 
96 const ssize_t MTU_UNLIMITED = -1;
97 
100 const ssize_t MTU_INVALID = -2;
101 
104 const ssize_t QUEUE_UNSUPPORTED = -1;
105 
108 const ssize_t QUEUE_ERROR = -2;
109 
113 class Transport : protected virtual TransportCounters, noncopyable
114 {
115 public:
118  typedef uint64_t EndpointId;
119 
122  class Packet
123  {
124  public:
125  Packet() = default;
126 
127  explicit
128  Packet(Block&& packet);
129 
130  public:
134 
142  };
143 
147 
156  Transport();
157 
158  virtual
159  ~Transport();
160 
161 public:
165  void
166  setFaceAndLinkService(Face& face, LinkService& service);
167 
170  const Face*
171  getFace() const;
172 
175  const LinkService*
176  getLinkService() const;
177 
180  LinkService*
181  getLinkService();
182 
183  virtual const Counters&
184  getCounters() const;
185 
186 public: // upper interface
195  void
196  close();
197 
202  void
203  send(Packet&& packet);
204 
205 public: // static properties
208  FaceUri
209  getLocalUri() const;
210 
213  FaceUri
214  getRemoteUri() const;
215 
219  getScope() const;
220 
224  getPersistency() const;
225 
234  bool
236 
239  void
241 
245  getLinkType() const;
246 
256  ssize_t
257  getMtu() const;
258 
263  ssize_t
264  getSendQueueCapacity() const;
265 
266 public: // dynamic properties
270  getState() const;
271 
275 
280  getExpirationTime() const;
281 
286  virtual ssize_t
288  {
289  return QUEUE_UNSUPPORTED;
290  }
291 
292 protected: // upper interface to be invoked by subclass
296  void
297  receive(Packet&& packet);
298 
299 protected: // properties to be set by subclass
300  void
301  setLocalUri(const FaceUri& uri);
302 
303  void
304  setRemoteUri(const FaceUri& uri);
305 
306  void
308 
309  void
311 
312  void
313  setMtu(ssize_t mtu);
314 
315  void
316  setSendQueueCapacity(ssize_t sendQueueCapacity);
317 
325  void
326  setState(TransportState newState);
327 
328  void
329  setExpirationTime(const time::steady_clock::TimePoint& expirationTime);
330 
331 protected: // to be overridden by subclass
338  virtual bool
340 
347  virtual void
349 
358  virtual void
359  doClose() = 0;
360 
361 private: // to be overridden by subclass
366  virtual void
367  doSend(Packet&& packet) = 0;
368 
369 public:
374  static constexpr ssize_t MIN_MTU = 64;
375 
376 private:
377  Face* m_face;
378  LinkService* m_service;
379  FaceUri m_localUri;
380  FaceUri m_remoteUri;
381  ndn::nfd::FaceScope m_scope;
382  ndn::nfd::FacePersistency m_persistency;
383  ndn::nfd::LinkType m_linkType;
384  ssize_t m_mtu;
385  ssize_t m_sendQueueCapacity;
386  TransportState m_state;
387  time::steady_clock::TimePoint m_expirationTime;
388 };
389 
390 inline const Face*
392 {
393  return m_face;
394 }
395 
396 inline const LinkService*
398 {
399  return m_service;
400 }
401 
402 inline LinkService*
404 {
405  return m_service;
406 }
407 
408 inline const Transport::Counters&
410 {
411  return *this;
412 }
413 
414 inline FaceUri
416 {
417  return m_localUri;
418 }
419 
420 inline void
422 {
423  m_localUri = uri;
424 }
425 
426 inline FaceUri
428 {
429  return m_remoteUri;
430 }
431 
432 inline void
434 {
435  m_remoteUri = uri;
436 }
437 
438 inline ndn::nfd::FaceScope
440 {
441  return m_scope;
442 }
443 
444 inline void
446 {
447  m_scope = scope;
448 }
449 
452 {
453  return m_persistency;
454 }
455 
456 inline ndn::nfd::LinkType
458 {
459  return m_linkType;
460 }
461 
462 inline void
464 {
465  m_linkType = linkType;
466 }
467 
468 inline ssize_t
470 {
471  return m_mtu;
472 }
473 
474 inline void
475 Transport::setMtu(ssize_t mtu)
476 {
477  BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0);
478  m_mtu = mtu;
479 }
480 
481 inline ssize_t
483 {
484  return m_sendQueueCapacity;
485 }
486 
487 inline void
488 Transport::setSendQueueCapacity(ssize_t sendQueueCapacity)
489 {
490  m_sendQueueCapacity = sendQueueCapacity;
491 }
492 
493 inline TransportState
495 {
496  return m_state;
497 }
498 
501 {
502  return m_expirationTime;
503 }
504 
505 inline void
507 {
508  m_expirationTime = expirationTime;
509 }
510 
511 std::ostream&
512 operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh);
513 
514 template<typename T>
515 typename std::enable_if<std::is_base_of<Transport, T>::value &&
516  !std::is_same<Transport, T>::value, std::ostream&>::type
517 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
518 {
519  return os << FaceLogHelper<Transport>(flh.obj);
520 }
521 
522 } // namespace face
523 } // namespace nfd
524 
525 #endif // NFD_DAEMON_FACE_TRANSPORT_HPP
virtual void afterChangePersistency(ndn::nfd::FacePersistency oldPersistency)
invoked after the persistency has been changed
Definition: transport.cpp:172
const ssize_t QUEUE_UNSUPPORTED
indicates that the transport does not support reading the queue capacity/length
Definition: transport.hpp:104
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
Definition: transport.cpp:154
time_point TimePoint
Definition: time.hpp:225
void setFaceAndLinkService(Face &face, LinkService &service)
set Face and LinkService for Transport
Definition: transport.cpp:77
void setExpirationTime(const time::steady_clock::TimePoint &expirationTime)
Definition: transport.hpp:506
the upper part of a Face
TransportCounters Counters
counters provided by Transport
Definition: transport.hpp:146
generalization of a network interface
Definition: face.hpp:67
std::ostream & operator<<(std::ostream &os, const Face &face)
Definition: ndn-common.hpp:89
time::steady_clock::TimePoint getExpirationTime() const
Definition: transport.hpp:500
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
Definition: transport.hpp:96
TransportState
indicates the state of a transport
Definition: transport.hpp:42
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:433
const ssize_t MTU_INVALID
(for internal use) indicates MTU field is unset
Definition: transport.hpp:100
virtual bool canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const
invoked by canChangePersistencyTo to perform the check
Definition: transport.cpp:148
static constexpr ssize_t MIN_MTU
minimum MTU that may be set on a transport
Definition: transport.hpp:374
stores a packet along with the remote endpoint
Definition: transport.hpp:122
counters provided by Transport
Definition: transport.hpp:58
PacketCounter nOutPackets
count of outgoing packets
Definition: transport.hpp:74
const ssize_t QUEUE_ERROR
indicates that the transport was unable to retrieve the queue capacity/length
Definition: transport.hpp:108
ndn::nfd::FaceScope getScope() const
Definition: transport.hpp:439
void close()
request the transport to be closed
Definition: transport.cpp:87
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:463
represents a counter of number of packets
Definition: counter.hpp:77
const Face * getFace() const
Definition: transport.hpp:391
ByteCounter nOutBytes
total outgoing bytes
Definition: transport.hpp:91
provides a lightweight signal / event system
Definition: signal.hpp:51
void setMtu(ssize_t mtu)
Definition: transport.hpp:475
FaceUri getRemoteUri() const
Definition: transport.hpp:427
void send(Packet &&packet)
send a link-layer packet
Definition: transport.cpp:100
the transport is being closed due to a failure
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:445
ndn Face
Definition: face-impl.hpp:42
bool canChangePersistencyTo(ndn::nfd::FacePersistency newPersistency) const
check whether the face persistency can be changed to newPersistency
Definition: transport.cpp:132
ByteCounter nInBytes
total incoming bytes
Definition: transport.hpp:83
represents a counter of number of bytes
Definition: counter.hpp:95
FaceUri getLocalUri() const
Definition: transport.hpp:415
TransportState getState() const
Definition: transport.hpp:494
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
EndpointId remoteEndpoint
identifies the remote endpoint
Definition: transport.hpp:141
signal::Signal< Transport, TransportState, TransportState > afterStateChange
signals when transport state changes
Definition: transport.hpp:274
the transport is closed, and can be safely deallocated
virtual ssize_t getSendQueueLength()
Definition: transport.hpp:287
ssize_t getMtu() const
Definition: transport.hpp:469
ssize_t getSendQueueCapacity() const
Definition: transport.hpp:482
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:421
const LinkService * getLinkService() const
Definition: transport.hpp:397
the transport is being closed gracefully, either by the peer or by a call to close()
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
ndn::nfd::LinkType getLinkType() const
Definition: transport.hpp:457
virtual const Counters & getCounters() const
Definition: transport.hpp:409
ndn::nfd::FacePersistency getPersistency() const
Definition: transport.hpp:451
void setSendQueueCapacity(ssize_t sendQueueCapacity)
Definition: transport.hpp:488
void setState(TransportState newState)
set transport state
Definition: transport.cpp:177
the transport is up and can transmit packets
for internal use by FaceLogging macros
Definition: face-log.hpp:43
void receive(Packet &&packet)
receive a link-layer packet
Definition: transport.cpp:120
PacketCounter nInPackets
count of incoming packets
Definition: transport.hpp:67
virtual void doClose()=0
performs Transport specific operations to close the transport
uint64_t EndpointId
identifies an endpoint on the link
Definition: transport.hpp:118
the lower part of a Face
Definition: transport.hpp:113
Block packet
the packet as a TLV block
Definition: transport.hpp:133
Transport()
constructor
Definition: transport.cpp:61
the transport is temporarily down, and is being recovered