blob: c1664bd5e2021f803fd4786bba3716bef5f0cb58 [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/*
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -04003 * Copyright (c) 2014-2022, 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
Ashlesh Gawande85998a12017-12-07 22:22:13 -060025#include "conf-parameter.hpp"
26#include "lsdb.hpp"
27#include "route/routing-table.hpp"
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040028#include "statistics.hpp"
29#include "test-access-control.hpp"
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050030
akmhoque31d1d4b2014-05-05 22:08:14 -050031#include <ndn-cxx/face.hpp>
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -040032#include <ndn-cxx/security/validation-error.hpp>
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040033#include <ndn-cxx/util/scheduler.hpp>
34#include <ndn-cxx/util/signal.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050035
36namespace nlsr {
37
akmhoque31d1d4b2014-05-05 22:08:14 -050038class HelloProtocol
39{
akmhoque31d1d4b2014-05-05 22:08:14 -050040public:
Saurab Dulal427e0122019-11-28 11:58:02 -060041 HelloProtocol(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam,
42 RoutingTable& routingTable, Lsdb& lsdb);
akmhoque31d1d4b2014-05-05 22:08:14 -050043
Nick Gordond0a7df32017-05-30 16:44:34 -050044 /*! \brief Sends a Hello Interest packet.
45 *
46 * \param interestNamePrefix The name of the router that has published the
47 * update we want. Here that should be: \<router name\>/NLSR/INFO
48 *
49 * \param seconds The lifetime of the Interest we construct, in seconds
50 *
51 * This function attempts to contact neighboring routers to
52 * determine their status (which currently is one of: ACTIVE,
53 * INACTIVE, or UNKNOWN)
Nick G97e34942016-07-11 14:46:27 -050054 */
akmhoque31d1d4b2014-05-05 22:08:14 -050055 void
56 expressInterest(const ndn::Name& interestNamePrefix, uint32_t seconds);
57
Nick Gordond0a7df32017-05-30 16:44:34 -050058 /*! \brief Sends Hello Interests to all neighbors
59 *
Nick Gordond0a7df32017-05-30 16:44:34 -050060 * This function is called as part of a schedule to regularly
61 * determine the adjacency status of neighbors. This function
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050062 * creates and sends a Hello Interest to the given adjacent.
63 *
64 * \param neighbor the name of the neighbor
Nick G97e34942016-07-11 14:46:27 -050065 */
akmhoque31d1d4b2014-05-05 22:08:14 -050066 void
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050067 sendHelloInterest(const ndn::Name& neighbor);
akmhoque31d1d4b2014-05-05 22:08:14 -050068
Nick Gordond0a7df32017-05-30 16:44:34 -050069 /*! \brief Processes a Hello Interest from a neighbor.
70 *
71 * \param name (ignored)
72 *
73 * \param interest The Interest object that we have received and need to
74 * process.
75 *
76 * Processes a Hello Interest that this router receives from one of
77 * its neighbors. If the neighbor that sent the Interest does not
78 * have a Face, NLSR will attempt to create one. Also, if the
79 * neighbor that sent the Interest was previously marked as
80 * INACTIVE, NLSR will attempt to contact it with its own Hello
81 * Interest.
Nick G97e34942016-07-11 14:46:27 -050082 */
akmhoque31d1d4b2014-05-05 22:08:14 -050083 void
84 processInterest(const ndn::Name& name, const ndn::Interest& interest);
85
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060086 ndn::util::signal::Signal<HelloProtocol, Statistics::PacketType> hpIncrementSignal;
87
akmhoque31d1d4b2014-05-05 22:08:14 -050088private:
Nick Gordond0a7df32017-05-30 16:44:34 -050089 /*! \brief Try to contact a neighbor via Hello protocol again
90 *
91 * This function will re-send Hello Interests a configured number
92 * of times. After that many failures, HelloProtocol will mark the neighbor as
93 * inactive and will not attempt to contact them until the next time
94 * HelloProtocol::sendScheduledInterest is called.
95 *
96 * \sa nlsr::ConfParameter::getInterestRetryNumber
97 */
akmhoque31d1d4b2014-05-05 22:08:14 -050098 void
99 processInterestTimedOut(const ndn::Interest& interest);
100
Nick Gordond0a7df32017-05-30 16:44:34 -0500101 /*! \brief Verify signatures and validate incoming Hello data.
102 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500103 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700104 onContent(const ndn::Interest& interest, const ndn::Data& data);
105
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500106PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick Gordond0a7df32017-05-30 16:44:34 -0500107
108 /*! \brief Change a neighbor's status
109 *
110 * Whenever incoming Hello data is verified and validated, change
111 * the status of this neighbor and then schedule an adjacency LSA
112 * build for us. This also resets the number of times we've failed
113 * to contact this neighbor so that we will retry later.
114 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700115 void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500116 onContentValidated(const ndn::Data& data);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700117
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500118private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500119 /*! \brief Log that incoming data couldn't be validated, but do nothing else.
120 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700121 void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500122 onContentValidationFailed(const ndn::Data& data,
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -0400123 const ndn::security::ValidationError& ve);
akmhoque31d1d4b2014-05-05 22:08:14 -0500124
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500125public:
Davide Pesavento1954a0c2022-09-30 15:56:04 -0400126 static inline const std::string INFO_COMPONENT{"INFO"};
127 static inline const std::string NLSR_COMPONENT{"nlsr"};
128
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;
akmhoque31d1d4b2014-05-05 22:08:14 -0500140};
141
Nick Gordonfad8e252016-08-11 14:21:38 -0500142} // namespace nlsr
akmhoque31d1d4b2014-05-05 22:08:14 -0500143
144#endif // NLSR_HELLO_PROTOCOL_HPP