blob: 46b1ab8f32e93459aa1903a811f18bfa70bd413b [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 Gawande5d93aa52020-06-13 18:57:45 -07003 * Copyright (c) 2014-2021, 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)
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070041 : m_lsdb(lsdb)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070042 , m_routingTable(rt)
Jiewen Tana0497d82015-02-02 21:59:18 -080043{
laqinfand22da512017-05-25 17:29:53 -050044 dispatcher.addStatusDataset(ADJACENCIES_DATASET,
45 ndn::mgmt::makeAcceptAllAuthorization(),
Ashlesh Gawande57a87172020-05-09 19:47:06 -070046 std::bind(&DatasetInterestHandler::publishLsaStatus<AdjLsa>, this, _1, _2, _3));
laqinfand22da512017-05-25 17:29:53 -050047 dispatcher.addStatusDataset(COORDINATES_DATASET,
48 ndn::mgmt::makeAcceptAllAuthorization(),
Ashlesh Gawande57a87172020-05-09 19:47:06 -070049 std::bind(&DatasetInterestHandler::publishLsaStatus<CoordinateLsa>, this, _1, _2, _3));
laqinfand22da512017-05-25 17:29:53 -050050 dispatcher.addStatusDataset(NAMES_DATASET,
51 ndn::mgmt::makeAcceptAllAuthorization(),
Ashlesh Gawande57a87172020-05-09 19:47:06 -070052 std::bind(&DatasetInterestHandler::publishLsaStatus<NameLsa>, this, _1, _2, _3));
laqinfan35731852017-08-08 06:17:39 -050053 dispatcher.addStatusDataset(RT_DATASET,
laqinfand22da512017-05-25 17:29:53 -050054 ndn::mgmt::makeAcceptAllAuthorization(),
laqinfan35731852017-08-08 06:17:39 -050055 std::bind(&DatasetInterestHandler::publishRtStatus, this, _1, _2, _3));
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050056}
57
Ashlesh Gawande57a87172020-05-09 19:47:06 -070058template <typename T>
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050059void
Ashlesh Gawande57a87172020-05-09 19:47:06 -070060DatasetInterestHandler::publishLsaStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
laqinfan35731852017-08-08 06:17:39 -050061 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050062{
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070063 NLSR_LOG_TRACE("Received interest: " << interest);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070064 auto lsaRange = m_lsdb.getLsdbIterator<T>();
65 for (auto lsaIt = lsaRange.first; lsaIt != lsaRange.second; ++lsaIt) {
66 context.append((*lsaIt)->wireEncode());
Jiewen Tana0497d82015-02-02 21:59:18 -080067 }
laqinfand22da512017-05-25 17:29:53 -050068 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -080069}
70
laqinfana073e2e2018-01-15 21:17:24 +000071void
72DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
73 ndn::mgmt::StatusDatasetContext& context)
74{
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070075 NLSR_LOG_TRACE("Received interest: " << interest);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070076 context.append(m_routingTable.wireEncode());
laqinfand22da512017-05-25 17:29:53 -050077 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -080078}
79
Jiewen Tana0497d82015-02-02 21:59:18 -080080} // namespace nlsr