NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
face-query-status-publisher.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
27 #include "core/logger.hpp"
28 #include <boost/range/adaptor/reversed.hpp>
29 
30 #include <ndn-cxx/management/nfd-face-status.hpp>
31 
32 namespace nfd {
33 
34 NFD_LOG_INIT("FaceQueryStatusPublisher");
35 
36 
38  AppFace& face,
39  const Name& prefix,
40  const ndn::nfd::FaceQueryFilter& filter,
41  ndn::KeyChain& keyChain)
42  : SegmentPublisher(face, prefix, keyChain)
43  , m_faceTable(faceTable)
44  , m_faceFilter(filter)
45 {
46 }
47 
49 {
50 }
51 
52 bool
53 FaceQueryStatusPublisher::doesMatchFilter(const shared_ptr<Face>& face)
54 {
55  if (m_faceFilter.hasFaceId() &&
56  m_faceFilter.getFaceId() != static_cast<uint64_t>(face->getId())) {
57  return false;
58  }
59 
60  if (m_faceFilter.hasUriScheme() &&
61  (m_faceFilter.getUriScheme() != face->getRemoteUri().getScheme() ||
62  m_faceFilter.getUriScheme() != face->getLocalUri().getScheme())) {
63  return false;
64  }
65 
66  if (m_faceFilter.hasRemoteUri() &&
67  m_faceFilter.getRemoteUri() != face->getRemoteUri().toString()) {
68  return false;
69  }
70 
71  if (m_faceFilter.hasLocalUri() && m_faceFilter.getLocalUri() != face->getLocalUri().toString()) {
72  return false;
73  }
74 
75  if (m_faceFilter.hasFaceScope() &&
76  (m_faceFilter.getFaceScope() == ndn::nfd::FACE_SCOPE_LOCAL) != face->isLocal()) {
77  return false;
78  }
79 
80  if (m_faceFilter.hasFacePersistency() &&
81  (m_faceFilter.getFacePersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) !=
82  face->isOnDemand()) {
83  return false;
84  }
85 
86  if (m_faceFilter.hasLinkType() &&
87  (m_faceFilter.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) != face->isMultiAccess()) {
88  return false;
89  }
90 
91  return true;
92 }
93 
94 size_t
95 FaceQueryStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
96 {
97  size_t totalLength = 0;
98 
99  for (const shared_ptr<Face>& face : m_faceTable | boost::adaptors::reversed) {
100  if (doesMatchFilter(face)) {
101  ndn::nfd::FaceStatus status = face->getFaceStatus();
102  totalLength += status.wireEncode(outBuffer);
103  }
104  }
105  return totalLength;
106 }
107 
108 } // namespace nfd
provides a publisher of Status Dataset or other segmented octet stream
FaceQueryStatusPublisher(const FaceTable &faceTable, AppFace &face, const Name &prefix, const ndn::nfd::FaceQueryFilter &filter, ndn::KeyChain &keyChain)
container of all Faces
Definition: face-table.hpp:38
#define NFD_LOG_INIT(name)
Definition: logger.hpp:33
virtual size_t generate(ndn::EncodingBuffer &outBuffer)
In a derived class, write the octets into outBuffer.
bool doesMatchFilter(const shared_ptr< Face > &face)