blob: a574622508cf7a562e304224851d509cb1b40436 [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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/>.
20 **/
21
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)
laqinfan35731852017-08-08 06:17:39 -050043 , m_routingTableEntries(rt.getRoutingTableEntry())
44 , m_dryRoutingTableEntries(rt.getDryRoutingTableEntry())
Jiewen Tana0497d82015-02-02 21:59:18 -080045{
laqinfan35731852017-08-08 06:17:39 -050046 setDispatcher(m_dispatcher);
Jiewen Tana0497d82015-02-02 21:59:18 -080047}
48
49void
laqinfan35731852017-08-08 06:17:39 -050050DatasetInterestHandler::setDispatcher(ndn::mgmt::Dispatcher& dispatcher)
Jiewen Tana0497d82015-02-02 21:59:18 -080051{
laqinfand22da512017-05-25 17:29:53 -050052 dispatcher.addStatusDataset(ADJACENCIES_DATASET,
53 ndn::mgmt::makeAcceptAllAuthorization(),
laqinfan35731852017-08-08 06:17:39 -050054 std::bind(&DatasetInterestHandler::publishAdjStatus, this, _1, _2, _3));
laqinfand22da512017-05-25 17:29:53 -050055 dispatcher.addStatusDataset(COORDINATES_DATASET,
56 ndn::mgmt::makeAcceptAllAuthorization(),
laqinfan35731852017-08-08 06:17:39 -050057 std::bind(&DatasetInterestHandler::publishCoordinateStatus, this, _1, _2, _3));
laqinfand22da512017-05-25 17:29:53 -050058 dispatcher.addStatusDataset(NAMES_DATASET,
59 ndn::mgmt::makeAcceptAllAuthorization(),
laqinfan35731852017-08-08 06:17:39 -050060 std::bind(&DatasetInterestHandler::publishNameStatus, this, _1, _2, _3));
61 dispatcher.addStatusDataset(RT_DATASET,
laqinfand22da512017-05-25 17:29:53 -050062 ndn::mgmt::makeAcceptAllAuthorization(),
laqinfan35731852017-08-08 06:17:39 -050063 std::bind(&DatasetInterestHandler::publishRtStatus, this, _1, _2, _3));
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050064}
65
66void
laqinfan35731852017-08-08 06:17:39 -050067DatasetInterestHandler::publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
68 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050069{
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080070 for (const auto& adjLsa : m_lsdb.getAdjLsdb()) {
71 context.append(adjLsa.wireEncode());
laqinfand22da512017-05-25 17:29:53 -050072 }
73 context.end();
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050074}
75
76void
laqinfan35731852017-08-08 06:17:39 -050077DatasetInterestHandler::publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
78 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050079{
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080080 for (const auto& coordinateLsa : m_lsdb.getCoordinateLsdb()) {
81 context.append(coordinateLsa.wireEncode());
Jiewen Tana0497d82015-02-02 21:59:18 -080082 }
laqinfand22da512017-05-25 17:29:53 -050083 context.end();
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050084}
85
86void
laqinfan35731852017-08-08 06:17:39 -050087DatasetInterestHandler::publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
88 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050089{
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080090 for (const auto& nameLsa : m_lsdb.getNameLsdb()) {
91 context.append(nameLsa.wireEncode());
Jiewen Tana0497d82015-02-02 21:59:18 -080092 }
laqinfand22da512017-05-25 17:29:53 -050093 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -080094}
95
laqinfan35731852017-08-08 06:17:39 -050096
laqinfana073e2e2018-01-15 21:17:24 +000097std::vector<tlv::RoutingTable>
98DatasetInterestHandler::getTlvRTEntries()
99{
100 std::vector<tlv::RoutingTable> rtable;
laqinfan35731852017-08-08 06:17:39 -0500101 for (const auto& rte : m_routingTableEntries) {
laqinfana073e2e2018-01-15 21:17:24 +0000102 tlv::RoutingTable tlvRoutingTable;
laqinfan35731852017-08-08 06:17:39 -0500103 std::shared_ptr<tlv::Destination> tlvDes = tlv::makeDes(rte);
104 tlvRoutingTable.setDestination(*tlvDes);
laqinfan35731852017-08-08 06:17:39 -0500105 for (const auto& nh : rte.getNexthopList().getNextHops()) {
106 tlv::NextHop tlvNexthop;
107 tlvNexthop.setUri(nh.getConnectingFaceUri());
108 tlvNexthop.setCost(nh.getRouteCost());
109 tlvRoutingTable.addNexthops(tlvNexthop);
110 }
laqinfana073e2e2018-01-15 21:17:24 +0000111 rtable.push_back(tlvRoutingTable);
laqinfan35731852017-08-08 06:17:39 -0500112 }
113 if (!m_dryRoutingTableEntries.empty()) {
laqinfana073e2e2018-01-15 21:17:24 +0000114 for (const auto& dryRte : m_dryRoutingTableEntries) {
115 tlv::RoutingTable tlvRoutingTable;
116 std::shared_ptr<tlv::Destination> tlvDes = tlv::makeDes(dryRte);
117 tlvRoutingTable.setDestination(*tlvDes);
118 for (const auto& nh : dryRte.getNexthopList().getNextHops()) {
119 tlv::NextHop tlvNexthop;
120 tlvNexthop.setUri(nh.getConnectingFaceUri());
121 tlvNexthop.setCost(nh.getRouteCost());
122 tlvRoutingTable.addNexthops(tlvNexthop);
laqinfan35731852017-08-08 06:17:39 -0500123 }
laqinfana073e2e2018-01-15 21:17:24 +0000124 rtable.push_back(tlvRoutingTable);
125 }
laqinfand22da512017-05-25 17:29:53 -0500126 }
laqinfana073e2e2018-01-15 21:17:24 +0000127 return rtable;
128}
Jiewen Tana0497d82015-02-02 21:59:18 -0800129
laqinfana073e2e2018-01-15 21:17:24 +0000130void
131DatasetInterestHandler::publishRtStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
132 ndn::mgmt::StatusDatasetContext& context)
133{
134 NLSR_LOG_DEBUG("Received interest: " << interest);
135 tlv::RoutingTableStatus rtStatus;
136 for (const tlv::RoutingTable& rt : getTlvRTEntries()) {
137 rtStatus.addRoutingTable(rt);
138 }
139 const ndn::Block& wire = rtStatus.wireEncode();
140 context.append(wire);
laqinfand22da512017-05-25 17:29:53 -0500141 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -0800142}
143
Jiewen Tana0497d82015-02-02 21:59:18 -0800144} // namespace nlsr