blob: 24c6e1a061e97b0b0599292f15a9e50104f8e079 [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(),
laqinfan35731852017-08-08 06:17:39 -050053 std::bind(&DatasetInterestHandler::publishAdjStatus, this, _1, _2, _3));
laqinfand22da512017-05-25 17:29:53 -050054 dispatcher.addStatusDataset(COORDINATES_DATASET,
55 ndn::mgmt::makeAcceptAllAuthorization(),
laqinfan35731852017-08-08 06:17:39 -050056 std::bind(&DatasetInterestHandler::publishCoordinateStatus, this, _1, _2, _3));
laqinfand22da512017-05-25 17:29:53 -050057 dispatcher.addStatusDataset(NAMES_DATASET,
58 ndn::mgmt::makeAcceptAllAuthorization(),
laqinfan35731852017-08-08 06:17:39 -050059 std::bind(&DatasetInterestHandler::publishNameStatus, this, _1, _2, _3));
60 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
65void
laqinfan35731852017-08-08 06:17:39 -050066DatasetInterestHandler::publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
67 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050068{
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080069 for (const auto& adjLsa : m_lsdb.getAdjLsdb()) {
70 context.append(adjLsa.wireEncode());
laqinfand22da512017-05-25 17:29:53 -050071 }
72 context.end();
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050073}
74
75void
laqinfan35731852017-08-08 06:17:39 -050076DatasetInterestHandler::publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
77 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050078{
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080079 for (const auto& coordinateLsa : m_lsdb.getCoordinateLsdb()) {
80 context.append(coordinateLsa.wireEncode());
Jiewen Tana0497d82015-02-02 21:59:18 -080081 }
laqinfand22da512017-05-25 17:29:53 -050082 context.end();
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050083}
84
85void
laqinfan35731852017-08-08 06:17:39 -050086DatasetInterestHandler::publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
87 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050088{
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080089 for (const auto& nameLsa : m_lsdb.getNameLsdb()) {
90 context.append(nameLsa.wireEncode());
Jiewen Tana0497d82015-02-02 21:59:18 -080091 }
laqinfand22da512017-05-25 17:29:53 -050092 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -080093}
94
laqinfana073e2e2018-01-15 21:17:24 +000095void
96DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
97 ndn::mgmt::StatusDatasetContext& context)
98{
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070099 NLSR_LOG_DEBUG("Received interest: " << interest);
100 context.append(m_routingTable.wireEncode());
laqinfand22da512017-05-25 17:29:53 -0500101 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -0800102}
103
Jiewen Tana0497d82015-02-02 21:59:18 -0800104} // namespace nlsr