dataset-interest-handler.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2023, The University of Memphis,
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 
23 #include "nlsr.hpp"
24 #include "logger.hpp"
25 
26 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
27 #include <ndn-cxx/util/regex.hpp>
28 
29 namespace nlsr {
30 
31 INIT_LOGGER(DatasetInterestHandler);
32 
33 const ndn::PartialName ADJACENCIES_DATASET{"lsdb/adjacencies"};
34 const ndn::PartialName COORDINATES_DATASET{"lsdb/coordinates"};
35 const ndn::PartialName NAMES_DATASET{"lsdb/names"};
36 const ndn::PartialName RT_DATASET{"routing-table"};
37 
38 DatasetInterestHandler::DatasetInterestHandler(ndn::mgmt::Dispatcher& dispatcher,
39  const Lsdb& lsdb,
40  const RoutingTable& rt)
41  : m_lsdb(lsdb)
42  , m_routingTable(rt)
43 {
44  dispatcher.addStatusDataset(ADJACENCIES_DATASET,
45  ndn::mgmt::makeAcceptAllAuthorization(),
46  std::bind(&DatasetInterestHandler::publishLsaStatus<AdjLsa>, this, _1, _2, _3));
47  dispatcher.addStatusDataset(COORDINATES_DATASET,
48  ndn::mgmt::makeAcceptAllAuthorization(),
49  std::bind(&DatasetInterestHandler::publishLsaStatus<CoordinateLsa>, this, _1, _2, _3));
50  dispatcher.addStatusDataset(NAMES_DATASET,
51  ndn::mgmt::makeAcceptAllAuthorization(),
52  std::bind(&DatasetInterestHandler::publishLsaStatus<NameLsa>, this, _1, _2, _3));
53  dispatcher.addStatusDataset(RT_DATASET,
54  ndn::mgmt::makeAcceptAllAuthorization(),
55  std::bind(&DatasetInterestHandler::publishRtStatus, this, _1, _2, _3));
56 }
57 
58 template <typename T>
59 void
60 DatasetInterestHandler::publishLsaStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
61  ndn::mgmt::StatusDatasetContext& context)
62 {
63  NLSR_LOG_TRACE("Received interest: " << interest);
64  auto lsaRange = m_lsdb.getLsdbIterator<T>();
65  for (auto lsaIt = lsaRange.first; lsaIt != lsaRange.second; ++lsaIt) {
66  context.append((*lsaIt)->wireEncode());
67  }
68  context.end();
69 }
70 
71 void
72 DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
73  ndn::mgmt::StatusDatasetContext& context)
74 {
75  NLSR_LOG_TRACE("Received interest: " << interest);
76  context.append(m_routingTable.wireEncode());
77  context.end();
78 }
79 
80 } // namespace nlsr
DatasetInterestHandler(ndn::mgmt::Dispatcher &dispatcher, const Lsdb &lsdb, const RoutingTable &rt)
std::pair< LsaContainer::index< Lsdb::byType >::type::iterator, LsaContainer::index< Lsdb::byType >::type::iterator > getLsdbIterator() const
Definition: lsdb.hpp:173
const ndn::Block & wireEncode() const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
Definition: logger.hpp:35
#define NLSR_LOG_TRACE(x)
Definition: logger.hpp:37
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
const ndn::PartialName ADJACENCIES_DATASET
const ndn::PartialName RT_DATASET
const ndn::PartialName NAMES_DATASET
const ndn::PartialName COORDINATES_DATASET