Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 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/>. |
| 20 | **/ |
| 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) |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 43 | , m_routingTableEntries(rt.getRoutingTableEntry()) |
| 44 | , m_dryRoutingTableEntries(rt.getDryRoutingTableEntry()) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 45 | { |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 46 | setDispatcher(m_dispatcher); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 50 | DatasetInterestHandler::setDispatcher(ndn::mgmt::Dispatcher& dispatcher) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 51 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 52 | dispatcher.addStatusDataset(ADJACENCIES_DATASET, |
| 53 | ndn::mgmt::makeAcceptAllAuthorization(), |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 54 | std::bind(&DatasetInterestHandler::publishAdjStatus, this, _1, _2, _3)); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 55 | dispatcher.addStatusDataset(COORDINATES_DATASET, |
| 56 | ndn::mgmt::makeAcceptAllAuthorization(), |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 57 | std::bind(&DatasetInterestHandler::publishCoordinateStatus, this, _1, _2, _3)); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 58 | dispatcher.addStatusDataset(NAMES_DATASET, |
| 59 | ndn::mgmt::makeAcceptAllAuthorization(), |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 60 | std::bind(&DatasetInterestHandler::publishNameStatus, this, _1, _2, _3)); |
| 61 | dispatcher.addStatusDataset(RT_DATASET, |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 62 | ndn::mgmt::makeAcceptAllAuthorization(), |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 63 | std::bind(&DatasetInterestHandler::publishRtStatus, this, _1, _2, _3)); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 67 | DatasetInterestHandler::publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 68 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 69 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 70 | for (const auto& adjLsa : m_lsdb.getAdjLsdb()) { |
| 71 | context.append(adjLsa.wireEncode()); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 72 | } |
| 73 | context.end(); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 77 | DatasetInterestHandler::publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 78 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 79 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 80 | for (const auto& coordinateLsa : m_lsdb.getCoordinateLsdb()) { |
| 81 | context.append(coordinateLsa.wireEncode()); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 82 | } |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 83 | context.end(); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 87 | DatasetInterestHandler::publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 88 | ndn::mgmt::StatusDatasetContext& context) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 89 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 90 | for (const auto& nameLsa : m_lsdb.getNameLsdb()) { |
| 91 | context.append(nameLsa.wireEncode()); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 92 | } |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 93 | context.end(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 94 | } |
| 95 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 96 | |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 97 | std::vector<tlv::RoutingTable> |
| 98 | DatasetInterestHandler::getTlvRTEntries() |
| 99 | { |
| 100 | std::vector<tlv::RoutingTable> rtable; |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 101 | for (const auto& rte : m_routingTableEntries) { |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 102 | tlv::RoutingTable tlvRoutingTable; |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 103 | std::shared_ptr<tlv::Destination> tlvDes = tlv::makeDes(rte); |
| 104 | tlvRoutingTable.setDestination(*tlvDes); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 105 | for (const auto& nh : rte.getNexthopList().getNextHops()) { |
| 106 | tlv::NextHop tlvNexthop; |
| 107 | tlvNexthop.setUri(nh.getConnectingFaceUri()); |
| 108 | tlvNexthop.setCost(nh.getRouteCost()); |
| 109 | tlvRoutingTable.addNexthops(tlvNexthop); |
| 110 | } |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 111 | rtable.push_back(tlvRoutingTable); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 112 | } |
| 113 | if (!m_dryRoutingTableEntries.empty()) { |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 114 | for (const auto& dryRte : m_dryRoutingTableEntries) { |
| 115 | tlv::RoutingTable tlvRoutingTable; |
| 116 | std::shared_ptr<tlv::Destination> tlvDes = tlv::makeDes(dryRte); |
| 117 | tlvRoutingTable.setDestination(*tlvDes); |
| 118 | for (const auto& nh : dryRte.getNexthopList().getNextHops()) { |
| 119 | tlv::NextHop tlvNexthop; |
| 120 | tlvNexthop.setUri(nh.getConnectingFaceUri()); |
| 121 | tlvNexthop.setCost(nh.getRouteCost()); |
| 122 | tlvRoutingTable.addNexthops(tlvNexthop); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 123 | } |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 124 | rtable.push_back(tlvRoutingTable); |
| 125 | } |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 126 | } |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 127 | return rtable; |
| 128 | } |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 129 | |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 130 | void |
| 131 | DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 132 | ndn::mgmt::StatusDatasetContext& context) |
| 133 | { |
| 134 | NLSR_LOG_DEBUG("Received interest: " << interest); |
| 135 | tlv::RoutingTableStatus rtStatus; |
| 136 | for (const tlv::RoutingTable& rt : getTlvRTEntries()) { |
| 137 | rtStatus.addRoutingTable(rt); |
| 138 | } |
| 139 | const ndn::Block& wire = rtStatus.wireEncode(); |
| 140 | context.append(wire); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 141 | context.end(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 144 | } // namespace nlsr |