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 
32 #include <ndn-cxx/encoding/nfd-constants.hpp>
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
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 protected: // upper interface to be invoked by subclass
209  void
210  receive(Packet&& packet);
211 
212 public: // static properties
215  FaceUri
216  getLocalUri() const;
217 
220  FaceUri
221  getRemoteUri() const;
222 
226  getScope() const;
227 
231  getPersistency() const;
232 
241  bool
243 
246  void
248 
252  getLinkType() const;
253 
263  ssize_t
264  getMtu() const;
265 
270  ssize_t
271  getSendQueueCapacity() const;
272 
273 public: // dynamic properties
277  getState() const;
278 
282 
287  getExpirationTime() const;
288 
293  virtual ssize_t
295 
296 protected: // properties to be set by subclass
297  void
298  setLocalUri(const FaceUri& uri);
299 
300  void
301  setRemoteUri(const FaceUri& uri);
302 
303  void
305 
306  void
308 
309  void
310  setMtu(ssize_t mtu);
311 
312  void
313  setSendQueueCapacity(ssize_t sendQueueCapacity);
314 
322  void
323  setState(TransportState newState);
324 
325  void
326  setExpirationTime(const time::steady_clock::TimePoint& expirationTime);
327 
328 protected: // to be overridden by subclass
335  virtual bool
337 
344  virtual void
346 
355  virtual void
356  doClose() = 0;
357 
358 private: // to be overridden by subclass
363  virtual void
364  doSend(Packet&& packet) = 0;
365 
366 private:
367  Face* m_face;
368  LinkService* m_service;
369  FaceUri m_localUri;
370  FaceUri m_remoteUri;
371  ndn::nfd::FaceScope m_scope;
372  ndn::nfd::FacePersistency m_persistency;
373  ndn::nfd::LinkType m_linkType;
374  ssize_t m_mtu;
375  size_t m_sendQueueCapacity;
376  TransportState m_state;
377  time::steady_clock::TimePoint m_expirationTime;
378 };
379 
380 inline const Face*
382 {
383  return m_face;
384 }
385 
386 inline const LinkService*
388 {
389  return m_service;
390 }
391 
392 inline LinkService*
394 {
395  return m_service;
396 }
397 
398 inline const Transport::Counters&
400 {
401  return *this;
402 }
403 
404 inline FaceUri
406 {
407  return m_localUri;
408 }
409 
410 inline void
412 {
413  m_localUri = uri;
414 }
415 
416 inline FaceUri
418 {
419  return m_remoteUri;
420 }
421 
422 inline void
424 {
425  m_remoteUri = uri;
426 }
427 
428 inline ndn::nfd::FaceScope
430 {
431  return m_scope;
432 }
433 
434 inline void
436 {
437  m_scope = scope;
438 }
439 
442 {
443  return m_persistency;
444 }
445 
446 inline ndn::nfd::LinkType
448 {
449  return m_linkType;
450 }
451 
452 inline void
454 {
455  m_linkType = linkType;
456 }
457 
458 inline ssize_t
460 {
461  return m_mtu;
462 }
463 
464 inline void
465 Transport::setMtu(ssize_t mtu)
466 {
467  BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0);
468  m_mtu = mtu;
469 }
470 
471 inline ssize_t
473 {
474  return m_sendQueueCapacity;
475 }
476 
477 inline void
478 Transport::setSendQueueCapacity(ssize_t sendQueueCapacity)
479 {
480  m_sendQueueCapacity = sendQueueCapacity;
481 }
482 
483 inline TransportState
485 {
486  return m_state;
487 }
488 
491 {
492  return m_expirationTime;
493 }
494 
495 inline void
497 {
498  m_expirationTime = expirationTime;
499 }
500 
501 std::ostream&
502 operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh);
503 
504 template<typename T>
505 typename std::enable_if<std::is_base_of<Transport, T>::value &&
506  !std::is_same<Transport, T>::value, std::ostream&>::type
507 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
508 {
509  return os << FaceLogHelper<Transport>(flh.obj);
510 }
511 
512 } // namespace face
513 } // namespace nfd
514 
515 #endif // NFD_DAEMON_FACE_TRANSPORT_HPP
virtual void afterChangePersistency(ndn::nfd::FacePersistency oldPersistency)
invoked after the persistency has been changed
Definition: transport.cpp:176
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:158
time_point TimePoint
Definition: time.hpp:226
void setFaceAndLinkService(Face &face, LinkService &service)
set Face and LinkService for Transport
Definition: transport.cpp:75
void setExpirationTime(const time::steady_clock::TimePoint &expirationTime)
Definition: transport.hpp:496
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:490
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:423
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:152
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:429
void close()
request the transport to be closed
Definition: transport.cpp:85
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:453
represents a counter of number of packets
Definition: counter.hpp:77
const Face * getFace() const
Definition: transport.hpp:381
ByteCounter nOutBytes
total outgoing bytes
Definition: transport.hpp:91
provides a lightweight signal / event system
Definition: signal.hpp:50
void setMtu(ssize_t mtu)
Definition: transport.hpp:465
FaceUri getRemoteUri() const
Definition: transport.hpp:417
void send(Packet &&packet)
send a link-layer packet
Definition: transport.cpp:98
the transport is being closed due to a failure
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:435
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:136
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:405
TransportState getState() const
Definition: transport.hpp:484
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:281
the transport is closed, and can be safely deallocated
ssize_t getMtu() const
Definition: transport.hpp:459
ssize_t getSendQueueCapacity() const
Definition: transport.hpp:472
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:411
const LinkService * getLinkService() const
Definition: transport.hpp:387
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:447
virtual const Counters & getCounters() const
Definition: transport.hpp:399
ndn::nfd::FacePersistency getPersistency() const
Definition: transport.hpp:441
void setSendQueueCapacity(ssize_t sendQueueCapacity)
Definition: transport.hpp:478
void setState(TransportState newState)
set transport state
Definition: transport.cpp:181
the transport is up and can transmit packets
void receive(Packet &&packet)
receive a link-layer packet
Definition: transport.cpp:118
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
virtual ssize_t getSendQueueLength()
Definition: transport.cpp:130
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:59
the transport is temporarily down, and is being recovered