NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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 
232  bool
233  canChangePersistencyTo(ndn::nfd::FacePersistency newPersistency) const;
234 
237  void
238  setPersistency(ndn::nfd::FacePersistency newPersistency);
239 
243  getLinkType() const;
244 
254  ssize_t
255  getMtu() const;
256 
257 public: // dynamic properties
261  getState() const;
262 
265  signal::Signal<Transport, TransportState/*old*/, TransportState/*new*/> afterStateChange;
266 
271  getExpirationTime() const;
272 
273 protected: // properties to be set by subclass
274  void
275  setLocalUri(const FaceUri& uri);
276 
277  void
278  setRemoteUri(const FaceUri& uri);
279 
280  void
281  setScope(ndn::nfd::FaceScope scope);
282 
283  void
284  setLinkType(ndn::nfd::LinkType linkType);
285 
286  void
287  setMtu(ssize_t mtu);
288 
296  void
297  setState(TransportState newState);
298 
299  void
300  setExpirationTime(const time::steady_clock::TimePoint& expirationTime);
301 
302 protected: // to be overridden by subclass
309  virtual bool
310  canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const;
311 
318  virtual void
319  afterChangePersistency(ndn::nfd::FacePersistency oldPersistency);
320 
329  virtual void
330  doClose() = 0;
331 
332 private: // to be overridden by subclass
337  virtual void
338  doSend(Packet&& packet) = 0;
339 
340 private:
341  Face* m_face;
342  LinkService* m_service;
343  FaceUri m_localUri;
344  FaceUri m_remoteUri;
345  ndn::nfd::FaceScope m_scope;
346  ndn::nfd::FacePersistency m_persistency;
347  ndn::nfd::LinkType m_linkType;
348  ssize_t m_mtu;
349  TransportState m_state;
350  time::steady_clock::TimePoint m_expirationTime;
351 };
352 
353 inline const Face*
355 {
356  return m_face;
357 }
358 
359 inline const LinkService*
361 {
362  return m_service;
363 }
364 
365 inline LinkService*
367 {
368  return m_service;
369 }
370 
371 inline const Transport::Counters&
373 {
374  return *this;
375 }
376 
377 inline FaceUri
379 {
380  return m_localUri;
381 }
382 
383 inline void
385 {
386  m_localUri = uri;
387 }
388 
389 inline FaceUri
391 {
392  return m_remoteUri;
393 }
394 
395 inline void
397 {
398  m_remoteUri = uri;
399 }
400 
401 inline ndn::nfd::FaceScope
403 {
404  return m_scope;
405 }
406 
407 inline void
409 {
410  m_scope = scope;
411 }
412 
415 {
416  return m_persistency;
417 }
418 
419 inline ndn::nfd::LinkType
421 {
422  return m_linkType;
423 }
424 
425 inline void
427 {
428  m_linkType = linkType;
429 }
430 
431 inline ssize_t
433 {
434  return m_mtu;
435 }
436 
437 inline void
438 Transport::setMtu(ssize_t mtu)
439 {
440  BOOST_ASSERT(mtu == MTU_UNLIMITED || mtu > 0);
441  m_mtu = mtu;
442 }
443 
444 inline TransportState
446 {
447  return m_state;
448 }
449 
452 {
453  return m_expirationTime;
454 }
455 
456 inline void
458 {
459  m_expirationTime = expirationTime;
460 }
461 
462 std::ostream&
463 operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh);
464 
465 template<typename T>
467  !std::is_same<Transport, T>::value, std::ostream&>::type
468 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
469 {
470  return os << FaceLogHelper<Transport>(flh.obj);
471 }
472 
473 } // namespace face
474 } // namespace nfd
475 
476 #endif // NFD_DAEMON_FACE_TRANSPORT_HPP
time_point TimePoint
Definition: time.hpp:120
void setExpirationTime(const time::steady_clock::TimePoint &expirationTime)
Definition: transport.hpp:457
the upper part of a Face
time::steady_clock::TimePoint getExpirationTime() const
Definition: transport.hpp:451
TransportCounters Counters
counters provided by Transport
Definition: transport.hpp:137
generalization of a network interface
Definition: face.hpp:67
std::ostream & operator<<(std::ostream &os, const Face &face)
Definition: ndn-common.hpp:89
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:396
const ssize_t MTU_INVALID
(for internal use) indicates MTU field is unset
Definition: transport.hpp:99
ndn::nfd::LinkType getLinkType() const
Definition: transport.hpp:420
virtual const Counters & getCounters() const
Definition: transport.hpp:372
stores a packet along with the remote endpoint
Definition: transport.hpp:113
FaceUri getLocalUri() const
Definition: transport.hpp:378
counters provided by Transport
Definition: transport.hpp:57
PacketCounter nOutPackets
count of outgoing packets
Definition: transport.hpp:73
const LinkService * getLinkService() const
Definition: transport.hpp:360
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:426
represents a counter of number of packets
Definition: counter.hpp:77
ByteCounter nOutBytes
total outgoing bytes
Definition: transport.hpp:90
provides a lightweight signal / event system
Definition: signal.hpp:50
const Face * getFace() const
Definition: transport.hpp:354
void setMtu(ssize_t mtu)
Definition: transport.hpp:438
the transport is being closed due to a failure
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:408
ndn Face
Definition: face-impl.hpp:41
ssize_t getMtu() const
Definition: transport.hpp:432
ByteCounter nInBytes
total incoming bytes
Definition: transport.hpp:82
represents a counter of number of bytes
Definition: counter.hpp:95
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:265
the transport is closed, and can be safely deallocated
FaceUri getRemoteUri() const
Definition: transport.hpp:390
ndn::nfd::LinkType getLinkType(const std::string &ifName)
Obtain information about WiFi link type.
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:384
void close(T *e, websocketpp::connection_hdl hdl)
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:43
TransportState getState() const
Definition: transport.hpp:445
the transport is up and can transmit packets
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
ndn::nfd::FaceScope getScope() const
Definition: transport.hpp:402
Block packet
the packet as a TLV block
Definition: transport.hpp:124
the transport is temporarily down, and is being recovered
ndn::nfd::FacePersistency getPersistency() const
Definition: transport.hpp:414