blob: 02fd4b67bb91bce0354eb62f29ed8c3951c4ea7c [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"
27#include "core/logger.hpp"
28
29#include <ndn-cxx/management/nfd-face-status.hpp>
30
31namespace nfd {
32
33NFD_LOG_INIT("FaceQueryStatusPublisher");
34
35
36FaceQueryStatusPublisher::FaceQueryStatusPublisher(const FaceTable& faceTable,
37 AppFace& face,
38 const Name& prefix,
39 const ndn::nfd::FaceQueryFilter& filter,
40 ndn::KeyChain& keyChain)
41 : SegmentPublisher(face, prefix, keyChain)
42 , m_faceTable(faceTable)
43 , m_faceFilter(filter)
44{
45}
46
47FaceQueryStatusPublisher::~FaceQueryStatusPublisher()
48{
49}
50
51bool
52FaceQueryStatusPublisher::doesMatchFilter(const shared_ptr<Face>& face)
53{
54 if (m_faceFilter.hasFaceId() &&
55 m_faceFilter.getFaceId() != static_cast<uint64_t>(face->getId())) {
56 return false;
57 }
58
59 if (m_faceFilter.hasUriScheme() &&
60 (m_faceFilter.getUriScheme() != face->getRemoteUri().getScheme() ||
61 m_faceFilter.getUriScheme() != face->getLocalUri().getScheme())) {
62 return false;
63 }
64
65 if (m_faceFilter.hasRemoteUri() &&
66 m_faceFilter.getRemoteUri() != face->getRemoteUri().toString()) {
67 return false;
68 }
69
70 if (m_faceFilter.hasLocalUri() && m_faceFilter.getLocalUri() != face->getLocalUri().toString()) {
71 return false;
72 }
73
74 if (m_faceFilter.hasFaceScope() &&
75 (m_faceFilter.getFaceScope() == ndn::nfd::FACE_SCOPE_LOCAL) != face->isLocal()) {
76 return false;
77 }
78
79 if (m_faceFilter.hasFacePersistency() &&
80 (m_faceFilter.getFacePersistency() == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) !=
81 face->isOnDemand()) {
82 return false;
83 }
84
85 if (m_faceFilter.hasLinkType() &&
86 (m_faceFilter.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) != face->isMultiAccess()) {
87 return false;
88 }
89
90 return true;
91}
92
93size_t
94FaceQueryStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
95{
96 size_t totalLength = 0;
97
98 for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin();
99 i != m_faceTable.rend(); ++i) {
100 const shared_ptr<Face>& face = *i;
101
102 if (doesMatchFilter(face)) {
103 ndn::nfd::FaceStatus status = face->getFaceStatus();
104 totalLength += status.wireEncode(outBuffer);
105 }
106 }
107 return totalLength;
108}
109
110} // namespace nfd