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 | c6a8522 | 2017-01-03 16:54:34 -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 | |
| 22 | #ifndef NLSR_PUBLISHER_LSDB_DATASET_INTEREST_HANDLER_HPP |
| 23 | #define NLSR_PUBLISHER_LSDB_DATASET_INTEREST_HANDLER_HPP |
| 24 | |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 25 | #include "tlv/adjacency-lsa.hpp" |
| 26 | #include "tlv/coordinate-lsa.hpp" |
| 27 | #include "tlv/name-lsa.hpp" |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame^] | 28 | #include "lsdb.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 29 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 31 | #include <ndn-cxx/face.hpp> |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 32 | #include <boost/noncopyable.hpp> |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 33 | |
| 34 | namespace nlsr { |
| 35 | |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame^] | 36 | namespace dataset { |
| 37 | const ndn::Name::Component ADJACENCY_COMPONENT = ndn::Name::Component{"adjacencies"}; |
| 38 | const ndn::Name::Component NAME_COMPONENT = ndn::Name::Component{"names"}; |
| 39 | const ndn::Name::Component COORDINATE_COMPONENT = ndn::Name::Component{"coordinates"}; |
| 40 | } // namespace dataset |
| 41 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 42 | /*! |
| 43 | \brief Class to publish all lsa dataset |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 44 | \sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet |
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 | class LsdbDatasetInterestHandler : boost::noncopyable |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 47 | { |
| 48 | public: |
| 49 | class Error : std::runtime_error |
| 50 | { |
| 51 | public: |
| 52 | explicit |
| 53 | Error(const std::string& what) |
| 54 | : std::runtime_error(what) |
| 55 | { |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | LsdbDatasetInterestHandler(Lsdb& lsdb, |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 60 | ndn::mgmt::Dispatcher& localHostDispatcher, |
| 61 | ndn::mgmt::Dispatcher& routerNameDispatcher, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 62 | ndn::Face& face, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 63 | ndn::KeyChain& keyChain); |
| 64 | |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 65 | ndn::Name& |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 66 | getRouterNameCommandPrefix() |
| 67 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 68 | return m_routerNamePrefix; |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void |
| 72 | setRouterNameCommandPrefix(const ndn::Name& routerName) { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 73 | m_routerNamePrefix = routerName; |
| 74 | m_routerNamePrefix.append(Lsdb::NAME_COMPONENT); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 78 | /*! \brief Capture-point for Interests to verify Interests are |
| 79 | * valid, and then process them. |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 80 | */ |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 81 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 82 | setDispatcher(ndn::mgmt::Dispatcher& dispatcher); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 83 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 84 | /*! \brief provide adjacent status dataset |
| 85 | */ |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 86 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 87 | publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 88 | ndn::mgmt::StatusDatasetContext& context); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 89 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 90 | /*! \brief provide coordinate status dataset |
| 91 | */ |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 92 | void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 93 | publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 94 | ndn::mgmt::StatusDatasetContext& context); |
| 95 | |
| 96 | /*! \brief provide name status dataset |
| 97 | */ |
| 98 | void |
| 99 | publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 100 | ndn::mgmt::StatusDatasetContext& context); |
| 101 | |
| 102 | /*! \brief provide ladb status dataset |
| 103 | */ |
| 104 | void |
| 105 | publishAllStatus(const ndn::Name& topPrefix, const ndn::Interest& interest, |
| 106 | ndn::mgmt::StatusDatasetContext& context); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 107 | |
| 108 | private: |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame^] | 109 | const Lsdb& m_lsdb; |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 110 | ndn::Name m_routerNamePrefix; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 111 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 112 | ndn::mgmt::Dispatcher& m_localhostDispatcher; |
| 113 | ndn::mgmt::Dispatcher& m_routerNameDispatcher; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame^] | 116 | template<typename T> std::list<T> |
| 117 | getTlvLsas(const Lsdb& lsdb); |
| 118 | |
| 119 | template<> std::list<tlv::AdjacencyLsa> |
| 120 | getTlvLsas<tlv::AdjacencyLsa>(const Lsdb& lsdb); |
| 121 | |
| 122 | template<> std::list<tlv::CoordinateLsa> |
| 123 | getTlvLsas<tlv::CoordinateLsa>(const Lsdb& lsdb); |
| 124 | |
| 125 | template<> std::list<tlv::NameLsa> |
| 126 | getTlvLsas<tlv::NameLsa>(const Lsdb& lsdb); |
| 127 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 128 | } // namespace nlsr |
| 129 | |
| 130 | #endif // NLSR_PUBLISHER_LSDB_DATASET_INTEREST_HANDLER_HPP |