NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
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 #include <ndn-cxx/encoding/nfd-constants.hpp>
32 
33 namespace nfd {
34 namespace face {
35 
36 class Face;
37 class LinkService;
38 
41 enum class TransportState {
42  NONE,
43  UP,
44  DOWN,
45  CLOSING,
46  FAILED,
47  CLOSED
48 };
49 
50 std::ostream&
51 operator<<(std::ostream& os, TransportState state);
52 
58 {
59 public:
67 
74 
83 
91 };
92 
95 const ssize_t MTU_UNLIMITED = -1;
96 
99 const ssize_t MTU_INVALID = -2;
100 
104 class Transport : protected virtual TransportCounters, noncopyable
105 {
106 public:
109  typedef uint64_t EndpointId;
110 
113  class Packet
114  {
115  public:
116  Packet() = default;
117 
118  explicit
119  Packet(Block&& packet);
120 
121  public:
125 
132  EndpointId remoteEndpoint;
133  };
134 
138 
147  Transport();
148 
149  virtual
150  ~Transport();
151 
152 public:
156  void
157  setFaceAndLinkService(Face& face, LinkService& service);
158 
161  const Face*
162  getFace() const;
163 
166  const LinkService*
167  getLinkService() const;
168 
171  LinkService*
172  getLinkService();
173 
174  virtual const Counters&
175  getCounters() const;
176 
177 public: // upper interface
186  void
187  close();
188 
193  void
194  send(Packet&& packet);
195 
196 protected: // upper interface to be invoked by subclass
200  void
201  receive(Packet&& packet);
202 
203 public: // static properties
206  FaceUri
207  getLocalUri() const;
208 
211  FaceUri
212  getRemoteUri() const;
213 
217  getScope() const;
218 
222  getPersistency() const;
223 
226  void
227  setPersistency(ndn::nfd::FacePersistency persistency);
228 
232  getLinkType() const;
233 
243  ssize_t
244  getMtu() const;
245 
246 public: // dynamic properties
250  getState() const;
251 
254  signal::Signal<Transport, TransportState/*old*/, TransportState/*new*/> afterStateChange;
255 
260  getExpirationTime() const;
261 
262 protected: // properties to be set by subclass
263  void
264  setLocalUri(const FaceUri& uri);
265 
266  void
267  setRemoteUri(const FaceUri& uri);
268 
269  void
270  setScope(ndn::nfd::FaceScope scope);
271 
272  void
273  setLinkType(ndn::nfd::LinkType linkType);
274 
275  void
276  setMtu(ssize_t mtu);
277 
285  void
286  setState(TransportState newState);
287 
288  void
289  setExpirationTime(const time::steady_clock::TimePoint& expirationTime);
290 
291 protected: // to be overridden by subclass
296  virtual void
297  beforeChangePersistency(ndn::nfd::FacePersistency newPersistency) = 0;
298 
307  virtual void
308  doClose() = 0;
309 
310 private: // to be overridden by subclass
315  virtual void
316  doSend(Packet&& packet) = 0;
317 
318 private:
319  Face* m_face;
320  LinkService* m_service;
321  FaceUri m_localUri;
322  FaceUri m_remoteUri;
323  ndn::nfd::FaceScope m_scope;
324  ndn::nfd::FacePersistency m_persistency;
325  ndn::nfd::LinkType m_linkType;
326  ssize_t m_mtu;
327  TransportState m_state;
328  time::steady_clock::TimePoint m_expirationTime;
329 };
330 
331 inline const Face*
333 {
334  return m_face;
335 }
336 
337 inline const LinkService*
339 {
340  return m_service;
341 }
342 
343 inline LinkService*
345 {
346  return m_service;
347 }
348 
349 inline const Transport::Counters&
351 {
352  return *this;
353 }
354 
355 inline FaceUri
357 {
358  return m_localUri;
359 }
360 
361 inline void
363 {
364  m_localUri = uri;
365 }
366 
367 inline FaceUri
369 {
370  return m_remoteUri;
371 }
372 
373 inline void
375 {
376  m_remoteUri = uri;
377 }
378 
379 inline ndn::nfd::FaceScope
381 {
382  return m_scope;
383 }
384 
385 inline void
387 {
388  m_scope = scope;
389 }
390 
393 {
394  return m_persistency;
395 }
396 
397 inline ndn::nfd::LinkType
399 {
400  return m_linkType;
401 }
402 
403 inline void
405 {
406  m_linkType = linkType;
407 }
408 
409 inline ssize_t
411 {
412  return m_mtu;
413 }
414 
415 inline void
416 Transport::setMtu(ssize_t mtu)
417 {
418  BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0);
419  m_mtu = mtu;
420 }
421 
422 inline TransportState
424 {
425  return m_state;
426 }
427 
430 {
431  return m_expirationTime;
432 }
433 
434 inline void
436 {
437  m_expirationTime = expirationTime;
438 }
439 
440 std::ostream&
441 operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh);
442 
443 template<typename T>
444 typename std::enable_if<std::is_base_of<Transport, T>::value &&
445  !std::is_same<Transport, T>::value, std::ostream&>::type
446 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
447 {
448  return os << FaceLogHelper<Transport>(flh.obj);
449 }
450 
451 } // namespace face
452 } // namespace nfd
453 
454 #endif // NFD_DAEMON_FACE_TRANSPORT_HPP
time_point TimePoint
Definition: time.hpp:108
void setExpirationTime(const time::steady_clock::TimePoint &expirationTime)
Definition: transport.hpp:435
the upper part of a Face
TransportCounters Counters
counters provided by Transport
Definition: transport.hpp:137
std::ostream & operator<<(std::ostream &os, const Face &face)
Definition: ndn-common.hpp:89
time::steady_clock::TimePoint getExpirationTime() const
Definition: transport.hpp:429
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
Definition: transport.hpp:95
TransportState
indicates the state of a transport
Definition: transport.hpp:41
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:374
const ssize_t MTU_INVALID
(for internal use) indicates MTU field is unset
Definition: transport.hpp:99
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
stores a packet along with the remote endpoint
Definition: transport.hpp:113
counters provided by Transport
Definition: transport.hpp:57
PacketCounter nOutPackets
count of outgoing packets
Definition: transport.hpp:73
ndn::nfd::FaceScope getScope() const
Definition: transport.hpp:380
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:404
represents a counter of number of packets
Definition: counter.hpp:77
const Face * getFace() const
Definition: transport.hpp:332
ByteCounter nOutBytes
total outgoing bytes
Definition: transport.hpp:90
provides a lightweight signal / event system
void setMtu(ssize_t mtu)
Definition: transport.hpp:416
FaceUri getRemoteUri() const
Definition: transport.hpp:368
the transport is being closed due to a failure
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:386
ByteCounter nInBytes
total incoming bytes
Definition: transport.hpp:82
represents a counter of number of bytes
Definition: counter.hpp:95
FaceUri getLocalUri() const
Definition: transport.hpp:356
TransportState getState() const
Definition: transport.hpp:423
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
EndpointId remoteEndpoint
identifies the remote endpoint
Definition: transport.hpp:132
signal::Signal< Transport, TransportState, TransportState > afterStateChange
signals when transport state changes
Definition: transport.hpp:254
the transport is closed, and can be safely deallocated
ssize_t getMtu() const
Definition: transport.hpp:410
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:362
const LinkService * getLinkService() const
Definition: transport.hpp:338
the transport is requested to be closed
ndn::nfd::LinkType getLinkType() const
Definition: transport.hpp:398
virtual const Counters & getCounters() const
Definition: transport.hpp:350
ndn::nfd::FacePersistency getPersistency() const
Definition: transport.hpp:392
the transport is up
PacketCounter nInPackets
count of incoming packets
Definition: transport.hpp:66
uint64_t EndpointId
identifies an endpoint on the link
Definition: transport.hpp:109
the lower part of a Face
Definition: transport.hpp:104
Block packet
the packet as a TLV block
Definition: transport.hpp:124
the transport is down temporarily, and is being recovered