Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2018, 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 | /*! \file dataset-interest-handler.hpp |
| 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 class doesn't only handle interest |
| 26 | from local host, but also handle interests from remote router. |
| 27 | This system is not designed to |
| 28 | be used by routers to publish data to each other. |
| 29 | */ |
| 30 | |
| 31 | #ifndef NLSR_PUBLISHER_DATASET_INTEREST_HANDLER_HPP |
| 32 | #define NLSR_PUBLISHER_DATASET_INTEREST_HANDLER_HPP |
| 33 | |
| 34 | #include "route/routing-table-entry.hpp" |
| 35 | #include "route/routing-table.hpp" |
| 36 | #include "route/nexthop-list.hpp" |
| 37 | #include "lsdb.hpp" |
| 38 | #include "logger.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 39 | |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 40 | #include "tlv/adjacency-lsa.hpp" |
| 41 | #include "tlv/coordinate-lsa.hpp" |
| 42 | #include "tlv/name-lsa.hpp" |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 43 | #include "tlv/routing-table-status.hpp" |
| 44 | #include "tlv/routing-table-entry.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 45 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 46 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 47 | #include <ndn-cxx/face.hpp> |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 48 | #include <boost/noncopyable.hpp> |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 49 | |
| 50 | namespace nlsr { |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 51 | namespace dataset { |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 52 | const ndn::Name::Component ADJACENCY_COMPONENT = ndn::Name::Component{"adjacencies"}; |
| 53 | const ndn::Name::Component NAME_COMPONENT = ndn::Name::Component{"names"}; |
| 54 | const ndn::Name::Component COORDINATE_COMPONENT = ndn::Name::Component{"coordinates"}; |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 55 | } // namespace dataset |
| 56 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 57 | /*! |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 58 | \brief Class to publish all dataset |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 59 | \sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 60 | \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_DataSet |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 61 | */ |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 62 | class DatasetInterestHandler : boost::noncopyable |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 63 | { |
| 64 | public: |
| 65 | class Error : std::runtime_error |
| 66 | { |
| 67 | public: |
| 68 | explicit |
| 69 | Error(const std::string& what) |
| 70 | : std::runtime_error(what) |
| 71 | { |
| 72 | } |
| 73 | }; |
| 74 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 75 | DatasetInterestHandler(const Lsdb& lsdb, |
| 76 | const RoutingTable& rt, |
| 77 | ndn::mgmt::Dispatcher& dispatcher, |
| 78 | const ndn::Face& face, |
| 79 | const ndn::KeyChain& keyChain); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 80 | |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 81 | ndn::Name& |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 82 | getRouterNameCommandPrefix() |
| 83 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 84 | return m_routerNamePrefix; |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void |
| 88 | setRouterNameCommandPrefix(const ndn::Name& routerName) { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 89 | m_routerNamePrefix = routerName; |
| 90 | m_routerNamePrefix.append(Lsdb::NAME_COMPONENT); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | private: |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 94 | /*! \brief set dispatcher for localhost or remote router |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 95 | */ |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 96 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 97 | setDispatcher(ndn::mgmt::Dispatcher& dispatcher); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 98 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 99 | /*! \brief provide routing-table dataset |
| 100 | */ |
| 101 | void |
| 102 | publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 103 | ndn::mgmt::StatusDatasetContext& context); |
| 104 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 105 | /*! \brief provide adjacent status dataset |
| 106 | */ |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 107 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 108 | publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 109 | ndn::mgmt::StatusDatasetContext& context); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 110 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 111 | /*! \brief provide coordinate status dataset |
| 112 | */ |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 113 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 114 | publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 115 | ndn::mgmt::StatusDatasetContext& context); |
| 116 | |
| 117 | /*! \brief provide name status dataset |
| 118 | */ |
| 119 | void |
| 120 | publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 121 | ndn::mgmt::StatusDatasetContext& context); |
| 122 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 123 | private: |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 124 | const Lsdb& m_lsdb; |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 125 | ndn::Name m_routerNamePrefix; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 126 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 127 | ndn::mgmt::Dispatcher& m_dispatcher; |
| 128 | |
| 129 | const std::list<RoutingTableEntry>& m_routingTableEntries; |
| 130 | const std::list<RoutingTableEntry>& m_dryRoutingTableEntries; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 131 | }; |
| 132 | |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 133 | template<typename T> std::list<T> |
| 134 | getTlvLsas(const Lsdb& lsdb); |
| 135 | |
| 136 | template<> std::list<tlv::AdjacencyLsa> |
| 137 | getTlvLsas<tlv::AdjacencyLsa>(const Lsdb& lsdb); |
| 138 | |
| 139 | template<> std::list<tlv::CoordinateLsa> |
| 140 | getTlvLsas<tlv::CoordinateLsa>(const Lsdb& lsdb); |
| 141 | |
| 142 | template<> std::list<tlv::NameLsa> |
| 143 | getTlvLsas<tlv::NameLsa>(const Lsdb& lsdb); |
| 144 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 145 | } // namespace nlsr |
| 146 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 147 | #endif // NLSR_PUBLISHER_DATASET_INTEREST_HANDLER_HPP |