Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame^] | 2 | /* |
Ashlesh Gawande | f89878c | 2020-03-06 19:07:09 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, 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/>. |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame^] | 20 | */ |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 21 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 22 | #include "dataset-interest-handler.hpp" |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 23 | #include "nlsr.hpp" |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 24 | #include "logger.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 25 | |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 26 | #include <ndn-cxx/mgmt/nfd/control-response.hpp> |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 27 | #include <ndn-cxx/util/regex.hpp> |
| 28 | |
| 29 | namespace nlsr { |
| 30 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 31 | INIT_LOGGER(DatasetInterestHandler); |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 32 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 33 | const ndn::PartialName ADJACENCIES_DATASET = ndn::PartialName("lsdb/adjacencies"); |
| 34 | const ndn::PartialName COORDINATES_DATASET = ndn::PartialName("lsdb/coordinates"); |
| 35 | const ndn::PartialName NAMES_DATASET = ndn::PartialName("lsdb/names"); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 36 | const ndn::PartialName RT_DATASET = ndn::PartialName("routing-table"); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 37 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 38 | DatasetInterestHandler::DatasetInterestHandler(ndn::mgmt::Dispatcher& dispatcher, |
| 39 | const Lsdb& lsdb, |
| 40 | const RoutingTable& rt) |
| 41 | : m_dispatcher(dispatcher) |
| 42 | , m_lsdb(lsdb) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame^] | 43 | , m_routingTable(rt) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 44 | { |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 45 | setDispatcher(m_dispatcher); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 49 | DatasetInterestHandler::setDispatcher(ndn::mgmt::Dispatcher& dispatcher) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 50 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 51 | dispatcher.addStatusDataset(ADJACENCIES_DATASET, |
| 52 | ndn::mgmt::makeAcceptAllAuthorization(), |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 53 | std::bind(&DatasetInterestHandler::publishAdjStatus, this, _1, _2, _3)); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 54 | dispatcher.addStatusDataset(COORDINATES_DATASET, |
| 55 | ndn::mgmt::makeAcceptAllAuthorization(), |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 56 | std::bind(&DatasetInterestHandler::publishCoordinateStatus, this, _1, _2, _3)); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 57 | dispatcher.addStatusDataset(NAMES_DATASET, |
| 58 | ndn::mgmt::makeAcceptAllAuthorization(), |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 59 | std::bind(&DatasetInterestHandler::publishNameStatus, this, _1, _2, _3)); |
| 60 | dispatcher.addStatusDataset(RT_DATASET, |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 61 | ndn::mgmt::makeAcceptAllAuthorization(), |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 62 | std::bind(&DatasetInterestHandler::publishRtStatus, this, _1, _2, _3)); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 66 | DatasetInterestHandler::publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 67 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 68 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 69 | for (const auto& adjLsa : m_lsdb.getAdjLsdb()) { |
| 70 | context.append(adjLsa.wireEncode()); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 71 | } |
| 72 | context.end(); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 76 | DatasetInterestHandler::publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 77 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 78 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 79 | for (const auto& coordinateLsa : m_lsdb.getCoordinateLsdb()) { |
| 80 | context.append(coordinateLsa.wireEncode()); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 81 | } |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 82 | context.end(); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 86 | DatasetInterestHandler::publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 87 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 88 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 89 | for (const auto& nameLsa : m_lsdb.getNameLsdb()) { |
| 90 | context.append(nameLsa.wireEncode()); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 91 | } |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 92 | context.end(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 93 | } |
| 94 | |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 95 | void |
| 96 | DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 97 | ndn::mgmt::StatusDatasetContext& context) |
| 98 | { |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame^] | 99 | NLSR_LOG_DEBUG("Received interest: " << interest); |
| 100 | context.append(m_routingTable.wireEncode()); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 101 | context.end(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 104 | } // namespace nlsr |