Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 1 | /* -*- 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" |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 28 | #include <boost/range/adaptor/reversed.hpp> |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 29 | |
| 30 | #include <ndn-cxx/management/nfd-face-status.hpp> |
| 31 | |
| 32 | namespace nfd { |
| 33 | |
| 34 | NFD_LOG_INIT("FaceQueryStatusPublisher"); |
| 35 | |
| 36 | |
| 37 | FaceQueryStatusPublisher::FaceQueryStatusPublisher(const FaceTable& faceTable, |
| 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 | |
| 48 | FaceQueryStatusPublisher::~FaceQueryStatusPublisher() |
| 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 | |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 99 | for (const shared_ptr<Face>& face : m_faceTable | boost::adaptors::reversed) { |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 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 |