blob: acd5c924db07ef2a94e49d68993df45f31536fc8 [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonfeae5572017-01-13 12:06:26 -06003 * Copyright (c) 2014-2017, 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
Nick G97e34942016-07-11 14:46:27 -050022/*! \file lsdb-dataset-interest-handler.cpp
23
24 This file details a class that is used by NLSRC and other command-line
25 tools to examine the state of NLSR. This system is not designed to
26 be used by routers to publish data to each other.
27 */
28
Jiewen Tana0497d82015-02-02 21:59:18 -080029#include "lsdb-dataset-interest-handler.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080030#include "logger.hpp"
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050031#include "nlsr.hpp"
Ashlesh Gawande90173ad2017-08-09 15:19:50 -050032#include "tlv/lsdb-status.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080033
34#include <ndn-cxx/face.hpp>
Junxiao Shi3e5120c2016-09-10 16:58:34 +000035#include <ndn-cxx/mgmt/nfd/control-response.hpp>
Jiewen Tana0497d82015-02-02 21:59:18 -080036#include <ndn-cxx/util/regex.hpp>
37
38namespace nlsr {
39
40INIT_LOGGER("LsdbDatasetInterestHandler");
Ashlesh Gawande90173ad2017-08-09 15:19:50 -050041
laqinfand22da512017-05-25 17:29:53 -050042const ndn::PartialName ADJACENCIES_DATASET = ndn::PartialName("lsdb/adjacencies");
43const ndn::PartialName COORDINATES_DATASET = ndn::PartialName("lsdb/coordinates");
44const ndn::PartialName NAMES_DATASET = ndn::PartialName("lsdb/names");
45const ndn::PartialName LISTS_DATASET = ndn::PartialName("lsdb/list");
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050046
Jiewen Tana0497d82015-02-02 21:59:18 -080047LsdbDatasetInterestHandler::LsdbDatasetInterestHandler(Lsdb& lsdb,
laqinfand22da512017-05-25 17:29:53 -050048 ndn::mgmt::Dispatcher& localHostDispatcher,
49 ndn::mgmt::Dispatcher& routerNameDispatcher,
Jiewen Tana0497d82015-02-02 21:59:18 -080050 ndn::Face& face,
Jiewen Tana0497d82015-02-02 21:59:18 -080051 ndn::KeyChain& keyChain)
laqinfand22da512017-05-25 17:29:53 -050052 : m_localhostDispatcher(localHostDispatcher)
53 , m_routerNameDispatcher(routerNameDispatcher)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050054 , m_adjacencyLsaPublisher(lsdb, face, keyChain)
55 , m_coordinateLsaPublisher(lsdb, face, keyChain)
56 , m_nameLsaPublisher(lsdb, face, keyChain)
laqinfand22da512017-05-25 17:29:53 -050057 , m_adjacencyLsas(lsdb.getAdjLsdb())
58 , m_coordinateLsas(lsdb.getCoordinateLsdb())
59 , m_nameLsas(lsdb.getNameLsdb())
Jiewen Tana0497d82015-02-02 21:59:18 -080060{
laqinfand22da512017-05-25 17:29:53 -050061 _LOG_DEBUG("Setting dispatcher for lsdb status dataset:");
62 setDispatcher(m_localhostDispatcher);
63 setDispatcher(m_routerNameDispatcher);
Jiewen Tana0497d82015-02-02 21:59:18 -080064}
65
66void
laqinfand22da512017-05-25 17:29:53 -050067LsdbDatasetInterestHandler::setDispatcher(ndn::mgmt::Dispatcher& dispatcher)
Jiewen Tana0497d82015-02-02 21:59:18 -080068{
laqinfand22da512017-05-25 17:29:53 -050069 dispatcher.addStatusDataset(ADJACENCIES_DATASET,
70 ndn::mgmt::makeAcceptAllAuthorization(),
71 std::bind(&LsdbDatasetInterestHandler::publishAdjStatus, this, _1, _2, _3));
72 dispatcher.addStatusDataset(COORDINATES_DATASET,
73 ndn::mgmt::makeAcceptAllAuthorization(),
74 std::bind(&LsdbDatasetInterestHandler::publishCoordinateStatus, this, _1, _2, _3));
75 dispatcher.addStatusDataset(NAMES_DATASET,
76 ndn::mgmt::makeAcceptAllAuthorization(),
77 std::bind(&LsdbDatasetInterestHandler::publishNameStatus, this, _1, _2, _3));
78 dispatcher.addStatusDataset(LISTS_DATASET,
79 ndn::mgmt::makeAcceptAllAuthorization(),
80 std::bind(&LsdbDatasetInterestHandler::publishAllStatus, this, _1, _2, _3));
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050081}
82
83void
laqinfand22da512017-05-25 17:29:53 -050084LsdbDatasetInterestHandler::publishAdjStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
85 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050086{
laqinfand22da512017-05-25 17:29:53 -050087 _LOG_DEBUG("Received interest: " << interest);
88 for (AdjLsa lsa : m_adjacencyLsas) {
89 tlv::AdjacencyLsa tlvLsa;
90 std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa);
91 tlvLsa.setLsaInfo(*tlvLsaInfo);
92
93 for (const Adjacent& adj : lsa.getAdl().getAdjList()) {
94 tlv::Adjacency tlvAdj;
95 tlvAdj.setName(adj.getName());
96 tlvAdj.setUri(adj.getFaceUri().toString());
97 tlvAdj.setCost(adj.getLinkCost());
98 tlvLsa.addAdjacency(tlvAdj);
99 }
100 const ndn::Block& wire = tlvLsa.wireEncode();
101 context.append(wire);
102 }
103 context.end();
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500104}
105
106void
laqinfand22da512017-05-25 17:29:53 -0500107LsdbDatasetInterestHandler::publishCoordinateStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
108 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500109{
laqinfand22da512017-05-25 17:29:53 -0500110 _LOG_DEBUG("Received interest: " << interest);
111 for (const CoordinateLsa lsa : m_coordinateLsas) {
112 tlv::CoordinateLsa tlvLsa;
113 std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa);
114 tlvLsa.setLsaInfo(*tlvLsaInfo);
Jiewen Tana0497d82015-02-02 21:59:18 -0800115
laqinfand22da512017-05-25 17:29:53 -0500116 tlvLsa.setHyperbolicRadius(lsa.getCorRadius());
117 tlvLsa.setHyperbolicAngle(lsa.getCorTheta());
118
119 const ndn::Block& wire = tlvLsa.wireEncode();
120 context.append(wire);
Jiewen Tana0497d82015-02-02 21:59:18 -0800121 }
laqinfand22da512017-05-25 17:29:53 -0500122 context.end();
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500123}
124
125void
laqinfand22da512017-05-25 17:29:53 -0500126LsdbDatasetInterestHandler::publishNameStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
127 ndn::mgmt::StatusDatasetContext& context)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500128{
laqinfand22da512017-05-25 17:29:53 -0500129 _LOG_DEBUG("Received interest: " << interest);
130 for (NameLsa lsa : m_nameLsas) {
131 tlv::NameLsa tlvLsa;
Jiewen Tana0497d82015-02-02 21:59:18 -0800132
laqinfand22da512017-05-25 17:29:53 -0500133 std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa);
134 tlvLsa.setLsaInfo(*tlvLsaInfo);
135
136 for (const ndn::Name& name : lsa.getNpl().getNameList()) {
137 tlvLsa.addName(name);
138 }
139
140 const ndn::Block& wire = tlvLsa.wireEncode();
141 context.append(wire);
Jiewen Tana0497d82015-02-02 21:59:18 -0800142 }
laqinfand22da512017-05-25 17:29:53 -0500143 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -0800144}
145
146void
laqinfand22da512017-05-25 17:29:53 -0500147LsdbDatasetInterestHandler::publishAllStatus(const ndn::Name& topPrefix, const ndn::Interest& interest,
148 ndn::mgmt::StatusDatasetContext& context)
Jiewen Tana0497d82015-02-02 21:59:18 -0800149{
laqinfand22da512017-05-25 17:29:53 -0500150 _LOG_DEBUG("Received interest: " << interest);
151 tlv::LsdbStatus lsdbStatus;
152 for (const tlv::AdjacencyLsa& tlvLsa : m_adjacencyLsaPublisher.getTlvLsas()) {
153 lsdbStatus.addAdjacencyLsa(tlvLsa);
154 }
Jiewen Tana0497d82015-02-02 21:59:18 -0800155
laqinfand22da512017-05-25 17:29:53 -0500156 for (const tlv::CoordinateLsa& tlvLsa : m_coordinateLsaPublisher.getTlvLsas()) {
157 lsdbStatus.addCoordinateLsa(tlvLsa);
158 }
Jiewen Tana0497d82015-02-02 21:59:18 -0800159
laqinfand22da512017-05-25 17:29:53 -0500160 for (const tlv::NameLsa& tlvLsa : m_nameLsaPublisher.getTlvLsas()) {
161 lsdbStatus.addNameLsa(tlvLsa);
162 }
163 const ndn::Block& wire = lsdbStatus.wireEncode();
164 context.append(wire);
165 context.end();
Jiewen Tana0497d82015-02-02 21:59:18 -0800166}
167
168} // namespace nlsr