NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
face.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "face.hpp"
27 
28 #include <ndn-cxx/management/nfd-face-event-notification.hpp>
29 
30 namespace nfd {
31 
32 Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal, bool isMultiAccess)
33  : m_id(INVALID_FACEID)
34  , m_remoteUri(remoteUri)
35  , m_localUri(localUri)
36  , m_isLocal(isLocal)
37  , m_persistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
38  , m_isMultiAccess(isMultiAccess)
39  , m_isFailed(false)
40  , m_metric(0)
41 {
42  onReceiveInterest.connect([this] (const ndn::Interest&) { ++m_counters.getNInInterests(); });
43  onReceiveData .connect([this] (const ndn::Data&) { ++m_counters.getNInDatas(); });
44  onSendInterest .connect([this] (const ndn::Interest&) { ++m_counters.getNOutInterests(); });
45  onSendData .connect([this] (const ndn::Data&) { ++m_counters.getNOutDatas(); });
46 }
47 
49 {
50 }
51 
52 bool
53 Face::isUp() const
54 {
55  return true;
56 }
57 
58 bool
60 {
61  try {
63 
64  if (element.type() == tlv::Interest)
65  {
66  shared_ptr<Interest> i = make_shared<Interest>();
67  i->wireDecode(element);
68  this->onReceiveInterest(*i);
69  }
70  else if (element.type() == tlv::Data)
71  {
72  shared_ptr<Data> d = make_shared<Data>();
73  d->wireDecode(element);
74  this->onReceiveData(*d);
75  }
76  else
77  return false;
78 
79  return true;
80  }
81  catch (const tlv::Error&) {
82  return false;
83  }
84 }
85 
86 void
87 Face::fail(const std::string& reason)
88 {
89  if (m_isFailed) {
90  return;
91  }
92 
93  m_isFailed = true;
94  this->onFail(reason);
95 }
96 
97 template<typename FaceTraits>
98 void
99 Face::copyStatusTo(FaceTraits& traits) const
100 {
101  traits.setFaceId(getId())
102  .setRemoteUri(getRemoteUri().toString())
103  .setLocalUri(getLocalUri().toString())
104  .setFaceScope(isLocal() ? ndn::nfd::FACE_SCOPE_LOCAL
106  .setFacePersistency(getPersistency())
109 }
110 
111 template void
112 Face::copyStatusTo<ndn::nfd::FaceStatus>(ndn::nfd::FaceStatus&) const;
113 
114 template void
115 Face::copyStatusTo<ndn::nfd::FaceEventNotification>(ndn::nfd::FaceEventNotification&) const;
116 
119 {
120  ndn::nfd::FaceStatus status;
121 
122  copyStatusTo(status);
123  this->getCounters().copyTo(status);
124 
125  return status;
126 }
127 
128 } // namespace nfd
Copyright (c) 2011-2015 Regents of the University of California.
const FaceCounters & getCounters() const
Definition: face.hpp:269
virtual ndn::nfd::FaceStatus getFaceStatus() const
Definition: face.cpp:118
void copyStatusTo(FaceTraits &traits) const
Definition: face.cpp:99
virtual bool isUp() const
Get whether underlying communication is up.
Definition: face.cpp:53
ndn::nfd::FacePersistency getPersistency() const
Get the persistency setting.
Definition: face.hpp:251
signal::Signal< Face, Interest > onSendInterest
fires when an Interest is sent out
Definition: face.hpp:86
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
bool decodeAndDispatchInput(const Block &element)
Definition: face.cpp:59
represents a Face status change notification
signal::Signal< Face, Data > onReceiveData
fires when a Data is received
Definition: face.hpp:83
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:45
const PacketCounter & getNOutDatas() const
outgoing Data
const FaceUri & getRemoteUri() const
Definition: face.hpp:281
virtual ~Face()
Definition: face.cpp:48
const PacketCounter & getNOutInterests() const
outgoing Interest
signal::Signal< Face, Data > onSendData
fires when a Data is sent out
Definition: face.hpp:89
std::string toString(const system_clock::TimePoint &timePoint, const std::string &format, const std::locale &locale)
Convert time point to string with specified format.
Definition: time.cpp:162
void fail(const std::string &reason)
fail the face and raise onFail event if it&#39;s UP; otherwise do nothing
Definition: face.cpp:87
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
void copyTo(R &recipient) const
copy current obseverations to a struct
signal::Signal< Face, std::string > onFail
fires when face disconnects or fails to perform properly
Definition: face.hpp:92
represents Face status
const PacketCounter & getNInDatas() const
incoming Data
uint32_t type() const
Definition: block.hpp:346
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition: face.hpp:43
const PacketCounter & getNInInterests() const
incoming Interest
Face(const FaceUri &remoteUri, const FaceUri &localUri, bool isLocal=false, bool isMultiAccess=false)
Definition: face.cpp:32
bool isMultiAccess() const
Get whether packets sent by this face may reach multiple peers.
Definition: face.hpp:263
signal::Signal< Face, Interest > onReceiveInterest
fires when an Interest is received
Definition: face.hpp:80
FaceId getId() const
Definition: face.hpp:221
const FaceUri & getLocalUri() const
Definition: face.hpp:287
represents a Data packet
Definition: data.hpp:39
bool isLocal() const
Get whether face is connected to a local app.
Definition: face.hpp:245
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50