blob: 59cf513bd30db8b4b143f5ce28514d013ae8e19e [file] [log] [blame]
Chengyu Fan320d2332014-10-29 16:40:33 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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#include "face-query-status-publisher.hpp"
Chengyu Fan320d2332014-10-29 16:40:33 -060027
Davide Pesaventodb9d37e2015-04-23 01:56:15 +020028#include <boost/range/adaptor/reversed.hpp>
Chengyu Fan320d2332014-10-29 16:40:33 -060029#include <ndn-cxx/management/nfd-face-status.hpp>
30
31namespace nfd {
32
Chengyu Fan320d2332014-10-29 16:40:33 -060033FaceQueryStatusPublisher::FaceQueryStatusPublisher(const FaceTable& faceTable,
34 AppFace& face,
35 const Name& prefix,
36 const ndn::nfd::FaceQueryFilter& filter,
37 ndn::KeyChain& keyChain)
38 : SegmentPublisher(face, prefix, keyChain)
39 , m_faceTable(faceTable)
40 , m_faceFilter(filter)
41{
42}
43
44FaceQueryStatusPublisher::~FaceQueryStatusPublisher()
45{
46}
47
48bool
49FaceQueryStatusPublisher::doesMatchFilter(const shared_ptr<Face>& face)
50{
51 if (m_faceFilter.hasFaceId() &&
52 m_faceFilter.getFaceId() != static_cast<uint64_t>(face->getId())) {
53 return false;
54 }
55
56 if (m_faceFilter.hasUriScheme() &&
57 (m_faceFilter.getUriScheme() != face->getRemoteUri().getScheme() ||
58 m_faceFilter.getUriScheme() != face->getLocalUri().getScheme())) {
59 return false;
60 }
61
62 if (m_faceFilter.hasRemoteUri() &&
63 m_faceFilter.getRemoteUri() != face->getRemoteUri().toString()) {
64 return false;
65 }
66
67 if (m_faceFilter.hasLocalUri() && m_faceFilter.getLocalUri() != face->getLocalUri().toString()) {
68 return false;
69 }
70
71 if (m_faceFilter.hasFaceScope() &&
72 (m_faceFilter.getFaceScope() == ndn::nfd::FACE_SCOPE_LOCAL) != face->isLocal()) {
73 return false;
74 }
75
76 if (m_faceFilter.hasFacePersistency() &&
77 (m_faceFilter.getFacePersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) !=
78 face->isOnDemand()) {
79 return false;
80 }
81
82 if (m_faceFilter.hasLinkType() &&
83 (m_faceFilter.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) != face->isMultiAccess()) {
84 return false;
85 }
86
87 return true;
88}
89
90size_t
91FaceQueryStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
92{
93 size_t totalLength = 0;
94
Junxiao Shiafbd74d2014-11-29 21:18:17 -070095 for (const shared_ptr<Face>& face : m_faceTable | boost::adaptors::reversed) {
Chengyu Fan320d2332014-10-29 16:40:33 -060096 if (doesMatchFilter(face)) {
97 ndn::nfd::FaceStatus status = face->getFaceStatus();
98 totalLength += status.wireEncode(outBuffer);
99 }
100 }
101 return totalLength;
102}
103
104} // namespace nfd