blob: e60b9490e3fec1b6bc1fc11ec2f6f72f5d031a8e [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() &&
Yukai Tu731f0d72015-07-04 11:14:44 +080077 m_faceFilter.getFacePersistency() != face->getPersistency()) {
Chengyu Fan320d2332014-10-29 16:40:33 -060078 return false;
79 }
80
81 if (m_faceFilter.hasLinkType() &&
82 (m_faceFilter.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) != face->isMultiAccess()) {
83 return false;
84 }
85
86 return true;
87}
88
89size_t
90FaceQueryStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
91{
92 size_t totalLength = 0;
93
Junxiao Shiafbd74d2014-11-29 21:18:17 -070094 for (const shared_ptr<Face>& face : m_faceTable | boost::adaptors::reversed) {
Chengyu Fan320d2332014-10-29 16:40:33 -060095 if (doesMatchFilter(face)) {
96 ndn::nfd::FaceStatus status = face->getFaceStatus();
97 totalLength += status.wireEncode(outBuffer);
98 }
99 }
100 return totalLength;
101}
102
103} // namespace nfd