blob: 373b62b25ef4a8dca7e6dfa64e15c5f9e1c066df [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande0421bc62020-05-08 20:42:19 -07002/*
Ashlesh Gawandef89878c2020-03-06 19:07:09 -08003 * Copyright (c) 2014-2020, 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/>.
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070020 */
Jiewen Tana0497d82015-02-02 21:59:18 -080021
laqinfan35731852017-08-08 06:17:39 -050022#include "dataset-interest-handler.hpp"
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050023#include "nlsr.hpp"
Nick Gordon114537f2017-08-09 14:51:37 -050024#include "logger.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080025
Junxiao Shi3e5120c2016-09-10 16:58:34 +000026#include <ndn-cxx/mgmt/nfd/control-response.hpp>
Jiewen Tana0497d82015-02-02 21:59:18 -080027#include <ndn-cxx/util/regex.hpp>
28
29namespace nlsr {
30
dmcoomescf8d0ed2017-02-21 11:39:01 -060031INIT_LOGGER(DatasetInterestHandler);
Ashlesh Gawande90173ad2017-08-09 15:19:50 -050032
laqinfand22da512017-05-25 17:29:53 -050033const ndn::PartialName ADJACENCIES_DATASET = ndn::PartialName("lsdb/adjacencies");
34const ndn::PartialName COORDINATES_DATASET = ndn::PartialName("lsdb/coordinates");
35const ndn::PartialName NAMES_DATASET = ndn::PartialName("lsdb/names");
laqinfan35731852017-08-08 06:17:39 -050036const ndn::PartialName RT_DATASET = ndn::PartialName("routing-table");
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050037
Ashlesh Gawande85998a12017-12-07 22:22:13 -060038DatasetInterestHandler::DatasetInterestHandler(ndn::mgmt::Dispatcher& dispatcher,
39 const Lsdb& lsdb,
40 const RoutingTable& rt)
41 : m_dispatcher(dispatcher)
42 , m_lsdb(lsdb)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070043 , m_routingTable(rt)
Jiewen Tana0497d82015-02-02 21:59:18 -080044{
laqinfan35731852017-08-08 06:17:39 -050045 setDispatcher(m_dispatcher);
Jiewen Tana0497d82015-02-02 21:59:18 -080046}
47
48void
laqinfan35731852017-08-08 06:17:39 -050049DatasetInterestHandler::setDispatcher(ndn::mgmt::Dispatcher& dispatcher)
Jiewen Tana0497d82015-02-02 21:59:18 -080050{
laqinfand22da512017-05-25 17:29:53 -050051 dispatcher.addStatusDataset(ADJACENCIES_DATASET,
52 ndn::mgmt::makeAcceptAllAuthorization(),
Ashlesh Gawande57a87172020-05-09 19:47:06 -070053 std::bind(&DatasetInterestHandler::publishLsaStatus<AdjLsa>, this, _1, _2, _3));
laqinfand22da512017-05-25 17:29:53 -050054 dispatcher.addStatusDataset(COORDINATES_DATASET,
55 ndn::mgmt::makeAcceptAllAuthorization(),
Ashlesh Gawande57a87172020-05-09 19:47:06 -070056 std::bind(&DatasetInterestHandler::publishLsaStatus<CoordinateLsa>, this, _1, _2, _3));
laqinfand22da512017-05-25 17:29:53 -050057 dispatcher.addStatusDataset(NAMES_DATASET,
58 ndn::mgmt::makeAcceptAllAuthorization(),
Ashlesh Gawande57a87172020-05-09 19:47:06 -070059 std::bind(&DatasetInterestHandler::publishLsaStatus<NameLsa>, this, _1, _2, _3));
laqinfan35731852017-08-08 06:17:39 -050060 dispatcher.addStatusDataset(RT_DATASET,
laqinfand22da512017-05-25 17:29:53 -050061 ndn::mgmt::makeAcceptAllAuthorization(),
laqinfan35731852017-08-08 06:17:39 -050062 std::bind(&DatasetInterestHandler::publishRtStatus, this, _1, _2, _3));
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050063}
64
Ashlesh Gawande57a87172020-05-09 19:47:06 -070065template <typename T>
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050066void
Ashlesh Gawande57a87172020-05-09 19:47:06 -070067DatasetInterestHandler::publishLsaStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
laqinfan35731852017-08-08 06:17:39 -050068 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050069{
Ashlesh Gawande57a87172020-05-09 19:47:06 -070070 auto lsaRange = m_lsdb.getLsdbIterator<T>();
71 for (auto lsaIt = lsaRange.first; lsaIt != lsaRange.second; ++lsaIt) {
72 context.append((*lsaIt)->wireEncode());
Jiewen Tana0497d82015-02-02 21:59:18 -080073 }
laqinfand22da512017-05-25 17:29:53 -050074 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -080075}
76
laqinfana073e2e2018-01-15 21:17:24 +000077void
78DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
79 ndn::mgmt::StatusDatasetContext& context)
80{
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070081 NLSR_LOG_DEBUG("Received interest: " << interest);
82 context.append(m_routingTable.wireEncode());
laqinfand22da512017-05-25 17:29:53 -050083 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -080084}
85
Jiewen Tana0497d82015-02-02 21:59:18 -080086} // namespace nlsr