blob: a42a4de216e6681b21f16fd2bb327ff428616100 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -04002/*
Ashlesh Gawandee63b7fa2021-04-06 21:43:17 -07003 * Copyright (c) 2014-2021, The University of Memphis,
Vince Lehmanc2acdcb2015-04-29 11:14:35 -05004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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/>.
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -040020 */
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050021
akmhoque31d1d4b2014-05-05 22:08:14 -050022#ifndef NLSR_HELLO_PROTOCOL_HPP
23#define NLSR_HELLO_PROTOCOL_HPP
24
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060025#include "statistics.hpp"
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050026#include "test-access-control.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060027#include "conf-parameter.hpp"
28#include "lsdb.hpp"
29#include "route/routing-table.hpp"
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050030
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060031#include <ndn-cxx/util/signal.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050032#include <ndn-cxx/face.hpp>
Junxiao Shi3e5120c2016-09-10 16:58:34 +000033#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
34#include <ndn-cxx/mgmt/nfd/control-response.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050035#include <ndn-cxx/util/scheduler.hpp>
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -040036#include <ndn-cxx/security/validation-error.hpp>
Ashlesh Gawande85998a12017-12-07 22:22:13 -060037#include <ndn-cxx/security/validator-config.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050038
39namespace nlsr {
40
akmhoque31d1d4b2014-05-05 22:08:14 -050041class HelloProtocol
42{
akmhoque31d1d4b2014-05-05 22:08:14 -050043public:
Saurab Dulal427e0122019-11-28 11:58:02 -060044 HelloProtocol(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam,
45 RoutingTable& routingTable, Lsdb& lsdb);
akmhoque31d1d4b2014-05-05 22:08:14 -050046
Nick Gordond0a7df32017-05-30 16:44:34 -050047 /*! \brief Sends a Hello Interest packet.
48 *
49 * \param interestNamePrefix The name of the router that has published the
50 * update we want. Here that should be: \<router name\>/NLSR/INFO
51 *
52 * \param seconds The lifetime of the Interest we construct, in seconds
53 *
54 * This function attempts to contact neighboring routers to
55 * determine their status (which currently is one of: ACTIVE,
56 * INACTIVE, or UNKNOWN)
Nick G97e34942016-07-11 14:46:27 -050057 */
akmhoque31d1d4b2014-05-05 22:08:14 -050058 void
59 expressInterest(const ndn::Name& interestNamePrefix, uint32_t seconds);
60
Nick Gordond0a7df32017-05-30 16:44:34 -050061 /*! \brief Sends Hello Interests to all neighbors
62 *
Nick Gordond0a7df32017-05-30 16:44:34 -050063 * This function is called as part of a schedule to regularly
64 * determine the adjacency status of neighbors. This function
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050065 * creates and sends a Hello Interest to the given adjacent.
66 *
67 * \param neighbor the name of the neighbor
Nick G97e34942016-07-11 14:46:27 -050068 */
akmhoque31d1d4b2014-05-05 22:08:14 -050069 void
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050070 sendHelloInterest(const ndn::Name& neighbor);
akmhoque31d1d4b2014-05-05 22:08:14 -050071
Nick Gordond0a7df32017-05-30 16:44:34 -050072 /*! \brief Processes a Hello Interest from a neighbor.
73 *
74 * \param name (ignored)
75 *
76 * \param interest The Interest object that we have received and need to
77 * process.
78 *
79 * Processes a Hello Interest that this router receives from one of
80 * its neighbors. If the neighbor that sent the Interest does not
81 * have a Face, NLSR will attempt to create one. Also, if the
82 * neighbor that sent the Interest was previously marked as
83 * INACTIVE, NLSR will attempt to contact it with its own Hello
84 * Interest.
Nick G97e34942016-07-11 14:46:27 -050085 */
akmhoque31d1d4b2014-05-05 22:08:14 -050086 void
87 processInterest(const ndn::Name& name, const ndn::Interest& interest);
88
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060089 ndn::util::signal::Signal<HelloProtocol, Statistics::PacketType> hpIncrementSignal;
90
akmhoque31d1d4b2014-05-05 22:08:14 -050091private:
Nick Gordond0a7df32017-05-30 16:44:34 -050092 /*! \brief Try to contact a neighbor via Hello protocol again
93 *
94 * This function will re-send Hello Interests a configured number
95 * of times. After that many failures, HelloProtocol will mark the neighbor as
96 * inactive and will not attempt to contact them until the next time
97 * HelloProtocol::sendScheduledInterest is called.
98 *
99 * \sa nlsr::ConfParameter::getInterestRetryNumber
100 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500101 void
102 processInterestTimedOut(const ndn::Interest& interest);
103
Nick Gordond0a7df32017-05-30 16:44:34 -0500104 /*! \brief Verify signatures and validate incoming Hello data.
105 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500106 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700107 onContent(const ndn::Interest& interest, const ndn::Data& data);
108
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500109PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick Gordond0a7df32017-05-30 16:44:34 -0500110
111 /*! \brief Change a neighbor's status
112 *
113 * Whenever incoming Hello data is verified and validated, change
114 * the status of this neighbor and then schedule an adjacency LSA
115 * build for us. This also resets the number of times we've failed
116 * to contact this neighbor so that we will retry later.
117 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700118 void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500119 onContentValidated(const ndn::Data& data);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700120
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500121private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500122 /*! \brief Log that incoming data couldn't be validated, but do nothing else.
123 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700124 void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500125 onContentValidationFailed(const ndn::Data& data,
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -0400126 const ndn::security::ValidationError& ve);
akmhoque31d1d4b2014-05-05 22:08:14 -0500127
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500128public:
Ashlesh Gawandee63b7fa2021-04-06 21:43:17 -0700129 ndn::util::Signal<HelloProtocol, const ndn::Name&> onInitialHelloDataValidated;
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500130
akmhoque31d1d4b2014-05-05 22:08:14 -0500131private:
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600132 ndn::Face& m_face;
133 ndn::Scheduler m_scheduler;
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -0400134 ndn::security::KeyChain& m_keyChain;
Saurab Dulal427e0122019-11-28 11:58:02 -0600135 const ndn::security::SigningInfo& m_signingInfo;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600136 ConfParameter& m_confParam;
137 RoutingTable& m_routingTable;
138 Lsdb& m_lsdb;
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500139 AdjacencyList& m_adjacencyList;
Vince Lehman7c603292014-09-11 17:48:16 -0500140
Ashlesh Gawandee63b7fa2021-04-06 21:43:17 -0700141PUBLIC_WITH_TESTS_ELSE_PRIVATE:
akmhoque157b0a42014-05-13 00:26:37 -0500142 static const std::string INFO_COMPONENT;
akmhoque93f1a072014-06-19 16:24:28 -0500143 static const std::string NLSR_COMPONENT;
akmhoque31d1d4b2014-05-05 22:08:14 -0500144};
145
Nick Gordonfad8e252016-08-11 14:21:38 -0500146} // namespace nlsr
akmhoque31d1d4b2014-05-05 22:08:14 -0500147
148#endif // NLSR_HELLO_PROTOCOL_HPP