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-2020, 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 = ndn::PartialName("lsdb/adjacencies");
34 const ndn::PartialName COORDINATES_DATASET = ndn::PartialName("lsdb/coordinates");
35 const ndn::PartialName NAMES_DATASET = ndn::PartialName("lsdb/names");
36 const ndn::PartialName RT_DATASET = ndn::PartialName("routing-table");
37 
38 DatasetInterestHandler::DatasetInterestHandler(ndn::mgmt::Dispatcher& dispatcher,
39  const Lsdb& lsdb,
40  const RoutingTable& rt)
41  : m_dispatcher(dispatcher)
42  , m_lsdb(lsdb)
43  , m_routingTable(rt)
44 {
45  setDispatcher(m_dispatcher);
46 }
47 
48 void
49 DatasetInterestHandler::setDispatcher(ndn::mgmt::Dispatcher& dispatcher)
50 {
51  dispatcher.addStatusDataset(ADJACENCIES_DATASET,
52  ndn::mgmt::makeAcceptAllAuthorization(),
53  std::bind(&DatasetInterestHandler::publishLsaStatus<AdjLsa>, this, _1, _2, _3));
54  dispatcher.addStatusDataset(COORDINATES_DATASET,
55  ndn::mgmt::makeAcceptAllAuthorization(),
56  std::bind(&DatasetInterestHandler::publishLsaStatus<CoordinateLsa>, this, _1, _2, _3));
57  dispatcher.addStatusDataset(NAMES_DATASET,
58  ndn::mgmt::makeAcceptAllAuthorization(),
59  std::bind(&DatasetInterestHandler::publishLsaStatus<NameLsa>, this, _1, _2, _3));
60  dispatcher.addStatusDataset(RT_DATASET,
61  ndn::mgmt::makeAcceptAllAuthorization(),
62  std::bind(&DatasetInterestHandler::publishRtStatus, this, _1, _2, _3));
63 }
64 
65 template <typename T>
66 void
67 DatasetInterestHandler::publishLsaStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
68  ndn::mgmt::StatusDatasetContext& context)
69 {
70  auto lsaRange = m_lsdb.getLsdbIterator<T>();
71  for (auto lsaIt = lsaRange.first; lsaIt != lsaRange.second; ++lsaIt) {
72  context.append((*lsaIt)->wireEncode());
73  }
74  context.end();
75 }
76 
77 void
78 DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
79  ndn::mgmt::StatusDatasetContext& context)
80 {
81  NLSR_LOG_DEBUG("Received interest: " << interest);
82  context.append(m_routingTable.wireEncode());
83  context.end();
84 }
85 
86 } // namespace nlsr
const ndn::PartialName COORDINATES_DATASET
#define NLSR_LOG_DEBUG(x)
Definition: logger.hpp:38
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
std::pair< LsaContainer::index< Lsdb::byType >::type::iterator, LsaContainer::index< Lsdb::byType >::type::iterator > getLsdbIterator() const
Definition: lsdb.hpp:169
#define INIT_LOGGER(name)
Definition: logger.hpp:35
const ndn::Block & wireEncode() const
const ndn::PartialName ADJACENCIES_DATASET
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
const ndn::PartialName NAMES_DATASET
DatasetInterestHandler(ndn::mgmt::Dispatcher &dispatcher, const Lsdb &lsdb, const RoutingTable &rt)
const ndn::PartialName RT_DATASET