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 | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2021, 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) |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 41 | : m_lsdb(lsdb) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 42 | , m_routingTable(rt) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 43 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 44 | dispatcher.addStatusDataset(ADJACENCIES_DATASET, |
| 45 | ndn::mgmt::makeAcceptAllAuthorization(), |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 46 | std::bind(&DatasetInterestHandler::publishLsaStatus<AdjLsa>, this, _1, _2, _3)); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 47 | dispatcher.addStatusDataset(COORDINATES_DATASET, |
| 48 | ndn::mgmt::makeAcceptAllAuthorization(), |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 49 | std::bind(&DatasetInterestHandler::publishLsaStatus<CoordinateLsa>, this, _1, _2, _3)); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 50 | dispatcher.addStatusDataset(NAMES_DATASET, |
| 51 | ndn::mgmt::makeAcceptAllAuthorization(), |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 52 | std::bind(&DatasetInterestHandler::publishLsaStatus<NameLsa>, this, _1, _2, _3)); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 53 | dispatcher.addStatusDataset(RT_DATASET, |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 54 | ndn::mgmt::makeAcceptAllAuthorization(), |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 55 | std::bind(&DatasetInterestHandler::publishRtStatus, this, _1, _2, _3)); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 56 | } |
| 57 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 58 | template <typename T> |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 59 | void |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 60 | DatasetInterestHandler::publishLsaStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 61 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 62 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 63 | NLSR_LOG_TRACE("Received interest: " << interest); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 64 | auto lsaRange = m_lsdb.getLsdbIterator<T>(); |
| 65 | for (auto lsaIt = lsaRange.first; lsaIt != lsaRange.second; ++lsaIt) { |
| 66 | context.append((*lsaIt)->wireEncode()); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 67 | } |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 68 | context.end(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 69 | } |
| 70 | |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 71 | void |
| 72 | DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 73 | ndn::mgmt::StatusDatasetContext& context) |
| 74 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 75 | NLSR_LOG_TRACE("Received interest: " << interest); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 76 | context.append(m_routingTable.wireEncode()); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 77 | context.end(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 80 | } // namespace nlsr |