blob: 6e5169d38ae414ddc96f521f5001c81b5c086d28 [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
laqinfan35731852017-08-08 06:17:39 -05003 * Copyright (c) 2014-2018, The University of Memphis,
Jiewen Tana0497d82015-02-02 21:59:18 -08004 * 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
laqinfan35731852017-08-08 06:17:39 -050022 /*! \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 Tana0497d82015-02-02 21:59:18 -080039
Ashlesh Gawande90173ad2017-08-09 15:19:50 -050040#include "tlv/adjacency-lsa.hpp"
41#include "tlv/coordinate-lsa.hpp"
42#include "tlv/name-lsa.hpp"
laqinfan35731852017-08-08 06:17:39 -050043#include "tlv/routing-table-status.hpp"
44#include "tlv/routing-table-entry.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080045
laqinfand22da512017-05-25 17:29:53 -050046#include <ndn-cxx/mgmt/dispatcher.hpp>
Jiewen Tana0497d82015-02-02 21:59:18 -080047#include <ndn-cxx/face.hpp>
laqinfand22da512017-05-25 17:29:53 -050048#include <boost/noncopyable.hpp>
Jiewen Tana0497d82015-02-02 21:59:18 -080049
50namespace nlsr {
Nick Gordon114537f2017-08-09 14:51:37 -050051namespace dataset {
laqinfan35731852017-08-08 06:17:39 -050052const ndn::Name::Component ADJACENCY_COMPONENT = ndn::Name::Component{"adjacencies"};
53const ndn::Name::Component NAME_COMPONENT = ndn::Name::Component{"names"};
54const ndn::Name::Component COORDINATE_COMPONENT = ndn::Name::Component{"coordinates"};
Nick Gordon114537f2017-08-09 14:51:37 -050055} // namespace dataset
56
Nick G97e34942016-07-11 14:46:27 -050057/*!
laqinfan35731852017-08-08 06:17:39 -050058 \brief Class to publish all dataset
laqinfand22da512017-05-25 17:29:53 -050059 \sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
laqinfan35731852017-08-08 06:17:39 -050060 \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_DataSet
Jiewen Tana0497d82015-02-02 21:59:18 -080061 */
laqinfan35731852017-08-08 06:17:39 -050062class DatasetInterestHandler : boost::noncopyable
Jiewen Tana0497d82015-02-02 21:59:18 -080063{
64public:
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
laqinfan35731852017-08-08 06:17:39 -050075 DatasetInterestHandler(const Lsdb& lsdb,
76 const RoutingTable& rt,
77 ndn::mgmt::Dispatcher& dispatcher,
78 const ndn::Face& face,
79 const ndn::KeyChain& keyChain);
Jiewen Tana0497d82015-02-02 21:59:18 -080080
Muktadir R Chowdhury3ac07282016-06-17 16:30:29 -050081 ndn::Name&
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050082 getRouterNameCommandPrefix()
83 {
laqinfand22da512017-05-25 17:29:53 -050084 return m_routerNamePrefix;
Muktadir R Chowdhury3ac07282016-06-17 16:30:29 -050085 }
86
87 void
88 setRouterNameCommandPrefix(const ndn::Name& routerName) {
laqinfand22da512017-05-25 17:29:53 -050089 m_routerNamePrefix = routerName;
90 m_routerNamePrefix.append(Lsdb::NAME_COMPONENT);
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050091 }
92
93private:
laqinfan35731852017-08-08 06:17:39 -050094 /*! \brief set dispatcher for localhost or remote router
laqinfand22da512017-05-25 17:29:53 -050095 */
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050096 void
laqinfand22da512017-05-25 17:29:53 -050097 setDispatcher(ndn::mgmt::Dispatcher& dispatcher);
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050098
laqinfana073e2e2018-01-15 21:17:24 +000099 /*! \brief generate a TLV-format of routing table entry
100 */
101 std::vector<tlv::RoutingTable>
102 getTlvRTEntries();
103
laqinfan35731852017-08-08 06:17:39 -0500104 /*! \brief provide routing-table dataset
105 */
106 void
107 publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
108 ndn::mgmt::StatusDatasetContext& context);
109
laqinfand22da512017-05-25 17:29:53 -0500110 /*! \brief provide adjacent status dataset
111 */
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500112 void
laqinfand22da512017-05-25 17:29:53 -0500113 publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
114 ndn::mgmt::StatusDatasetContext& context);
Jiewen Tana0497d82015-02-02 21:59:18 -0800115
laqinfand22da512017-05-25 17:29:53 -0500116 /*! \brief provide coordinate status dataset
117 */
Jiewen Tana0497d82015-02-02 21:59:18 -0800118 void
laqinfand22da512017-05-25 17:29:53 -0500119 publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
120 ndn::mgmt::StatusDatasetContext& context);
121
122 /*! \brief provide name status dataset
123 */
124 void
125 publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
126 ndn::mgmt::StatusDatasetContext& context);
127
Jiewen Tana0497d82015-02-02 21:59:18 -0800128private:
Nick Gordon114537f2017-08-09 14:51:37 -0500129 const Lsdb& m_lsdb;
laqinfand22da512017-05-25 17:29:53 -0500130 ndn::Name m_routerNamePrefix;
Jiewen Tana0497d82015-02-02 21:59:18 -0800131
laqinfan35731852017-08-08 06:17:39 -0500132 ndn::mgmt::Dispatcher& m_dispatcher;
133
134 const std::list<RoutingTableEntry>& m_routingTableEntries;
135 const std::list<RoutingTableEntry>& m_dryRoutingTableEntries;
Jiewen Tana0497d82015-02-02 21:59:18 -0800136};
137
Nick Gordon114537f2017-08-09 14:51:37 -0500138template<typename T> std::list<T>
139getTlvLsas(const Lsdb& lsdb);
140
141template<> std::list<tlv::AdjacencyLsa>
142getTlvLsas<tlv::AdjacencyLsa>(const Lsdb& lsdb);
143
144template<> std::list<tlv::CoordinateLsa>
145getTlvLsas<tlv::CoordinateLsa>(const Lsdb& lsdb);
146
147template<> std::list<tlv::NameLsa>
148getTlvLsas<tlv::NameLsa>(const Lsdb& lsdb);
149
Jiewen Tana0497d82015-02-02 21:59:18 -0800150} // namespace nlsr
151
laqinfan35731852017-08-08 06:17:39 -0500152#endif // NLSR_PUBLISHER_DATASET_INTEREST_HANDLER_HPP