Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 20 | **/ |
| 21 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 22 | /*! \file lsdb-dataset-interest-handler.cpp |
| 23 | |
| 24 | This file details a class that is used by NLSRC and other command-line |
| 25 | tools to examine the state of NLSR. This system is not designed to |
| 26 | be used by routers to publish data to each other. |
| 27 | */ |
| 28 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 29 | #include "lsdb-dataset-interest-handler.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 30 | #include "logger.hpp" |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 31 | #include "nlsr.hpp" |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame^] | 32 | #include "tlv/lsdb-status.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 33 | |
| 34 | #include <ndn-cxx/face.hpp> |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 35 | #include <ndn-cxx/mgmt/nfd/control-response.hpp> |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 36 | #include <ndn-cxx/util/regex.hpp> |
| 37 | |
| 38 | namespace nlsr { |
| 39 | |
| 40 | INIT_LOGGER("LsdbDatasetInterestHandler"); |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame^] | 41 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 42 | const ndn::PartialName ADJACENCIES_DATASET = ndn::PartialName("lsdb/adjacencies"); |
| 43 | const ndn::PartialName COORDINATES_DATASET = ndn::PartialName("lsdb/coordinates"); |
| 44 | const ndn::PartialName NAMES_DATASET = ndn::PartialName("lsdb/names"); |
| 45 | const ndn::PartialName LISTS_DATASET = ndn::PartialName("lsdb/list"); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 46 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 47 | LsdbDatasetInterestHandler::LsdbDatasetInterestHandler(Lsdb& lsdb, |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 48 | ndn::mgmt::Dispatcher& localHostDispatcher, |
| 49 | ndn::mgmt::Dispatcher& routerNameDispatcher, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 50 | ndn::Face& face, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 51 | ndn::KeyChain& keyChain) |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 52 | : m_localhostDispatcher(localHostDispatcher) |
| 53 | , m_routerNameDispatcher(routerNameDispatcher) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 54 | , m_adjacencyLsaPublisher(lsdb, face, keyChain) |
| 55 | , m_coordinateLsaPublisher(lsdb, face, keyChain) |
| 56 | , m_nameLsaPublisher(lsdb, face, keyChain) |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 57 | , m_adjacencyLsas(lsdb.getAdjLsdb()) |
| 58 | , m_coordinateLsas(lsdb.getCoordinateLsdb()) |
| 59 | , m_nameLsas(lsdb.getNameLsdb()) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 60 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 61 | _LOG_DEBUG("Setting dispatcher for lsdb status dataset:"); |
| 62 | setDispatcher(m_localhostDispatcher); |
| 63 | setDispatcher(m_routerNameDispatcher); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 67 | LsdbDatasetInterestHandler::setDispatcher(ndn::mgmt::Dispatcher& dispatcher) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 68 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 69 | dispatcher.addStatusDataset(ADJACENCIES_DATASET, |
| 70 | ndn::mgmt::makeAcceptAllAuthorization(), |
| 71 | std::bind(&LsdbDatasetInterestHandler::publishAdjStatus, this, _1, _2, _3)); |
| 72 | dispatcher.addStatusDataset(COORDINATES_DATASET, |
| 73 | ndn::mgmt::makeAcceptAllAuthorization(), |
| 74 | std::bind(&LsdbDatasetInterestHandler::publishCoordinateStatus, this, _1, _2, _3)); |
| 75 | dispatcher.addStatusDataset(NAMES_DATASET, |
| 76 | ndn::mgmt::makeAcceptAllAuthorization(), |
| 77 | std::bind(&LsdbDatasetInterestHandler::publishNameStatus, this, _1, _2, _3)); |
| 78 | dispatcher.addStatusDataset(LISTS_DATASET, |
| 79 | ndn::mgmt::makeAcceptAllAuthorization(), |
| 80 | std::bind(&LsdbDatasetInterestHandler::publishAllStatus, this, _1, _2, _3)); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 84 | LsdbDatasetInterestHandler::publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 85 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 86 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 87 | _LOG_DEBUG("Received interest: " << interest); |
| 88 | for (AdjLsa lsa : m_adjacencyLsas) { |
| 89 | tlv::AdjacencyLsa tlvLsa; |
| 90 | std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa); |
| 91 | tlvLsa.setLsaInfo(*tlvLsaInfo); |
| 92 | |
| 93 | for (const Adjacent& adj : lsa.getAdl().getAdjList()) { |
| 94 | tlv::Adjacency tlvAdj; |
| 95 | tlvAdj.setName(adj.getName()); |
| 96 | tlvAdj.setUri(adj.getFaceUri().toString()); |
| 97 | tlvAdj.setCost(adj.getLinkCost()); |
| 98 | tlvLsa.addAdjacency(tlvAdj); |
| 99 | } |
| 100 | const ndn::Block& wire = tlvLsa.wireEncode(); |
| 101 | context.append(wire); |
| 102 | } |
| 103 | context.end(); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 107 | LsdbDatasetInterestHandler::publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 108 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 109 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 110 | _LOG_DEBUG("Received interest: " << interest); |
| 111 | for (const CoordinateLsa lsa : m_coordinateLsas) { |
| 112 | tlv::CoordinateLsa tlvLsa; |
| 113 | std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa); |
| 114 | tlvLsa.setLsaInfo(*tlvLsaInfo); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 115 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 116 | tlvLsa.setHyperbolicRadius(lsa.getCorRadius()); |
| 117 | tlvLsa.setHyperbolicAngle(lsa.getCorTheta()); |
| 118 | |
| 119 | const ndn::Block& wire = tlvLsa.wireEncode(); |
| 120 | context.append(wire); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 121 | } |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 122 | context.end(); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 126 | LsdbDatasetInterestHandler::publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 127 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 128 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 129 | _LOG_DEBUG("Received interest: " << interest); |
| 130 | for (NameLsa lsa : m_nameLsas) { |
| 131 | tlv::NameLsa tlvLsa; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 132 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 133 | std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa); |
| 134 | tlvLsa.setLsaInfo(*tlvLsaInfo); |
| 135 | |
| 136 | for (const ndn::Name& name : lsa.getNpl().getNameList()) { |
| 137 | tlvLsa.addName(name); |
| 138 | } |
| 139 | |
| 140 | const ndn::Block& wire = tlvLsa.wireEncode(); |
| 141 | context.append(wire); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 142 | } |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 143 | context.end(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 147 | LsdbDatasetInterestHandler::publishAllStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 148 | ndn::mgmt::StatusDatasetContext& context) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 149 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 150 | _LOG_DEBUG("Received interest: " << interest); |
| 151 | tlv::LsdbStatus lsdbStatus; |
| 152 | for (const tlv::AdjacencyLsa& tlvLsa : m_adjacencyLsaPublisher.getTlvLsas()) { |
| 153 | lsdbStatus.addAdjacencyLsa(tlvLsa); |
| 154 | } |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 155 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 156 | for (const tlv::CoordinateLsa& tlvLsa : m_coordinateLsaPublisher.getTlvLsas()) { |
| 157 | lsdbStatus.addCoordinateLsa(tlvLsa); |
| 158 | } |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 159 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 160 | for (const tlv::NameLsa& tlvLsa : m_nameLsaPublisher.getTlvLsas()) { |
| 161 | lsdbStatus.addNameLsa(tlvLsa); |
| 162 | } |
| 163 | const ndn::Block& wire = lsdbStatus.wireEncode(); |
| 164 | context.append(wire); |
| 165 | context.end(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | } // namespace nlsr |