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-2020, 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
127  ~Transport();
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 
171  void
172  send(const Block& packet);
173 
174 public: // static properties
177  FaceUri
178  getLocalUri() const;
179 
182  FaceUri
183  getRemoteUri() const;
184 
188  getScope() const;
189 
193  getPersistency() const;
194 
203  bool
204  canChangePersistencyTo(ndn::nfd::FacePersistency newPersistency) const;
205 
208  void
209  setPersistency(ndn::nfd::FacePersistency newPersistency);
210 
214  getLinkType() const;
215 
225  ssize_t
226  getMtu() const;
227 
232  ssize_t
233  getSendQueueCapacity() const;
234 
235 public: // dynamic properties
239  getState() const;
240 
243  signal::Signal<Transport, TransportState/*old*/, TransportState/*new*/> afterStateChange;
244 
249  getExpirationTime() const;
250 
255  virtual ssize_t
257  {
258  return QUEUE_UNSUPPORTED;
259  }
260 
261 protected: // upper interface to be invoked by subclass
267  void
268  receive(const Block& packet, const EndpointId& endpoint = 0);
269 
270 protected: // properties to be set by subclass
271  void
272  setLocalUri(const FaceUri& uri);
273 
274  void
275  setRemoteUri(const FaceUri& uri);
276 
277  void
278  setScope(ndn::nfd::FaceScope scope);
279 
280  void
281  setLinkType(ndn::nfd::LinkType linkType);
282 
283  void
284  setMtu(ssize_t mtu);
285 
286  void
287  setSendQueueCapacity(ssize_t sendQueueCapacity);
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(const Block& 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  ssize_t m_sendQueueCapacity;
350  TransportState m_state;
351  time::steady_clock::TimePoint m_expirationTime;
352 };
353 
354 inline const Face*
356 {
357  return m_face;
358 }
359 
360 inline const LinkService*
362 {
363  return m_service;
364 }
365 
366 inline LinkService*
368 {
369  return m_service;
370 }
371 
372 inline const Transport::Counters&
374 {
375  return *this;
376 }
377 
378 inline FaceUri
380 {
381  return m_localUri;
382 }
383 
384 inline void
386 {
387  m_localUri = uri;
388 }
389 
390 inline FaceUri
392 {
393  return m_remoteUri;
394 }
395 
396 inline void
398 {
399  m_remoteUri = uri;
400 }
401 
402 inline ndn::nfd::FaceScope
404 {
405  return m_scope;
406 }
407 
408 inline void
410 {
411  m_scope = scope;
412 }
413 
416 {
417  return m_persistency;
418 }
419 
420 inline ndn::nfd::LinkType
422 {
423  return m_linkType;
424 }
425 
426 inline void
428 {
429  m_linkType = linkType;
430 }
431 
432 inline ssize_t
434 {
435  return m_mtu;
436 }
437 
438 inline ssize_t
440 {
441  return m_sendQueueCapacity;
442 }
443 
444 inline void
445 Transport::setSendQueueCapacity(ssize_t sendQueueCapacity)
446 {
447  m_sendQueueCapacity = sendQueueCapacity;
448 }
449 
450 inline TransportState
452 {
453  return m_state;
454 }
455 
458 {
459  return m_expirationTime;
460 }
461 
462 inline void
464 {
465  m_expirationTime = expirationTime;
466 }
467 
468 std::ostream&
469 operator<<(std::ostream& os, const FaceLogHelper<Transport>& flh);
470 
471 template<typename T>
473  !std::is_same<Transport, T>::value, std::ostream&>::type
474 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
475 {
476  return os << FaceLogHelper<Transport>(flh.obj);
477 }
478 
479 } // namespace face
480 } // namespace nfd
481 
482 #endif // NFD_DAEMON_FACE_TRANSPORT_HPP
const ssize_t QUEUE_UNSUPPORTED
indicates that the transport does not support reading the queue capacity/length
Definition: transport.hpp:99
void setExpirationTime(const time::steady_clock::TimePoint &expirationTime)
Definition: transport.hpp:463
the upper part of a Face
std::ostream & operator<<(std::ostream &os, const Face &face)
Definition: ndn-common.hpp:85
time::steady_clock::TimePoint getExpirationTime() const
Definition: transport.hpp:457
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
Definition: transport.hpp:91
TransportState
Indicates the state of a transport.
Definition: transport.hpp:37
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:397
const ssize_t MTU_INVALID
(for internal use) indicates MTU field is unset
Definition: transport.hpp:95
Counters provided by a transport.
Definition: transport.hpp:53
PacketCounter nOutPackets
count of outgoing packets
Definition: transport.hpp:69
const ssize_t QUEUE_ERROR
indicates that the transport was unable to retrieve the queue capacity/length
Definition: transport.hpp:103
ndn::nfd::FaceScope getScope() const
Definition: transport.hpp:403
Represents a TLV element of the NDN packet format.
Definition: block.hpp:44
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:427
represents a counter of number of packets
Definition: counter.hpp:66
const Face * getFace() const
Definition: transport.hpp:355
ByteCounter nOutBytes
total outgoing bytes
Definition: transport.hpp:86
provides a lightweight signal / event system
Definition: signal.hpp:52
uint64_t EndpointId
Identifies a remote endpoint on the link.
Definition: face-common.hpp:71
FaceUri getRemoteUri() const
Definition: transport.hpp:391
the transport is being closed due to a failure
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:409
ndn Face
Definition: face-impl.hpp:42
ByteCounter nInBytes
total incoming bytes
Definition: transport.hpp:78
represents a counter of number of bytes
Definition: counter.hpp:84
FaceUri getLocalUri() const
Definition: transport.hpp:379
TransportState getState() const
Definition: transport.hpp:451
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
signal::Signal< Transport, TransportState, TransportState > afterStateChange
signals when transport state changes
Definition: transport.hpp:243
the transport is closed, and can be safely deallocated
virtual ssize_t getSendQueueLength()
Definition: transport.hpp:256
ndn::nfd::LinkType getLinkType(const std::string &ifName)
Obtain information about WiFi link type.
ssize_t getMtu() const
Definition: transport.hpp:433
ssize_t getSendQueueCapacity() const
Definition: transport.hpp:439
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:385
void close(T *e, websocketpp::connection_hdl hdl)
const LinkService * getLinkService() const
Definition: transport.hpp:361
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:421
virtual const Counters & getCounters() const
Definition: transport.hpp:373
ndn::nfd::FacePersistency getPersistency() const
Definition: transport.hpp:415
void setSendQueueCapacity(ssize_t sendQueueCapacity)
Definition: transport.hpp:445
the transport is up and can transmit packets
PacketCounter nInPackets
count of incoming packets
Definition: transport.hpp:62
The lower half of a Face.
Definition: transport.hpp:108
the transport is temporarily down, and is being recovered
time_point TimePoint
Definition: time.hpp:233