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" |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 27 | |
Davide Pesavento | db9d37e | 2015-04-23 01:56:15 +0200 | [diff] [blame] | 28 | #include <boost/range/adaptor/reversed.hpp> |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 29 | #include <ndn-cxx/management/nfd-face-status.hpp> |
| 30 | |
| 31 | namespace nfd { |
| 32 | |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 33 | FaceQueryStatusPublisher::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 | |
| 44 | FaceQueryStatusPublisher::~FaceQueryStatusPublisher() |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | bool |
| 49 | FaceQueryStatusPublisher::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 | |
| 90 | size_t |
| 91 | FaceQueryStatusPublisher::generate(ndn::EncodingBuffer& outBuffer) |
| 92 | { |
| 93 | size_t totalLength = 0; |
| 94 | |
Junxiao Shi | afbd74d | 2014-11-29 21:18:17 -0700 | [diff] [blame] | 95 | for (const shared_ptr<Face>& face : m_faceTable | boost::adaptors::reversed) { |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 96 | 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 |