blob: 3ba4ee740d9f3d46470b3fc268a79611008c2fbe [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Ashlesh Gawande85998a12017-12-07 22:22:13 -06003 * Copyright (c) 2014-2019, 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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
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>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050036#include <ndn-cxx/security/v2/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:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060044 HelloProtocol(ndn::Face& face, ndn::KeyChain& keyChain,
45 ndn::security::SigningInfo& signingInfo,
46 ConfParameter& confParam, RoutingTable& routingTable, Lsdb& lsdb);
akmhoque31d1d4b2014-05-05 22:08:14 -050047
Nick Gordond0a7df32017-05-30 16:44:34 -050048 /*! \brief Sends a Hello Interest packet.
49 *
50 * \param interestNamePrefix The name of the router that has published the
51 * update we want. Here that should be: \<router name\>/NLSR/INFO
52 *
53 * \param seconds The lifetime of the Interest we construct, in seconds
54 *
55 * This function attempts to contact neighboring routers to
56 * determine their status (which currently is one of: ACTIVE,
57 * INACTIVE, or UNKNOWN)
Nick G97e34942016-07-11 14:46:27 -050058 */
akmhoque31d1d4b2014-05-05 22:08:14 -050059 void
60 expressInterest(const ndn::Name& interestNamePrefix, uint32_t seconds);
61
Nick Gordond0a7df32017-05-30 16:44:34 -050062 /*! \brief Sends Hello Interests to all neighbors
63 *
Nick Gordond0a7df32017-05-30 16:44:34 -050064 * This function is called as part of a schedule to regularly
65 * determine the adjacency status of neighbors. This function
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050066 * creates and sends a Hello Interest to the given adjacent.
67 *
68 * \param neighbor the name of the neighbor
Nick G97e34942016-07-11 14:46:27 -050069 */
akmhoque31d1d4b2014-05-05 22:08:14 -050070 void
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050071 sendHelloInterest(const ndn::Name& neighbor);
akmhoque31d1d4b2014-05-05 22:08:14 -050072
Nick Gordond0a7df32017-05-30 16:44:34 -050073 /*! \brief Processes a Hello Interest from a neighbor.
74 *
75 * \param name (ignored)
76 *
77 * \param interest The Interest object that we have received and need to
78 * process.
79 *
80 * Processes a Hello Interest that this router receives from one of
81 * its neighbors. If the neighbor that sent the Interest does not
82 * have a Face, NLSR will attempt to create one. Also, if the
83 * neighbor that sent the Interest was previously marked as
84 * INACTIVE, NLSR will attempt to contact it with its own Hello
85 * Interest.
Nick G97e34942016-07-11 14:46:27 -050086 */
akmhoque31d1d4b2014-05-05 22:08:14 -050087 void
88 processInterest(const ndn::Name& name, const ndn::Interest& interest);
89
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060090 ndn::util::signal::Signal<HelloProtocol, Statistics::PacketType> hpIncrementSignal;
91
akmhoque31d1d4b2014-05-05 22:08:14 -050092private:
Nick Gordond0a7df32017-05-30 16:44:34 -050093 /*! \brief Try to contact a neighbor via Hello protocol again
94 *
95 * This function will re-send Hello Interests a configured number
96 * of times. After that many failures, HelloProtocol will mark the neighbor as
97 * inactive and will not attempt to contact them until the next time
98 * HelloProtocol::sendScheduledInterest is called.
99 *
100 * \sa nlsr::ConfParameter::getInterestRetryNumber
101 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500102 void
103 processInterestTimedOut(const ndn::Interest& interest);
104
Nick Gordond0a7df32017-05-30 16:44:34 -0500105 /*! \brief Verify signatures and validate incoming Hello data.
106 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500107 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700108 onContent(const ndn::Interest& interest, const ndn::Data& data);
109
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500110PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick Gordond0a7df32017-05-30 16:44:34 -0500111
112 /*! \brief Change a neighbor's status
113 *
114 * Whenever incoming Hello data is verified and validated, change
115 * the status of this neighbor and then schedule an adjacency LSA
116 * build for us. This also resets the number of times we've failed
117 * to contact this neighbor so that we will retry later.
118 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700119 void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500120 onContentValidated(const ndn::Data& data);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700121
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500122private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500123 /*! \brief Log that incoming data couldn't be validated, but do nothing else.
124 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700125 void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500126 onContentValidationFailed(const ndn::Data& data,
127 const ndn::security::v2::ValidationError& ve);
akmhoque31d1d4b2014-05-05 22:08:14 -0500128
Nick Gordond0a7df32017-05-30 16:44:34 -0500129 /*! \brief Treat a failed Face registration as an INACTIVE neighbor.
130 *
131 * If NLSR fails to register a Face when contacting a neighbor, it
132 * will instantly toggle that neighbor to INACTIVE. This is
133 * necessary because NLSR will put off building its own adjacency
134 * LSA until the status of each neighbor is definitively
135 * known. Without this, NLSR might have to wait many scheduled Hello
136 * intervals to finish building an adjacency LSA.
137 */
akmhoquec04e7272014-07-02 11:00:14 -0500138 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000139 onRegistrationFailure(const ndn::nfd::ControlResponse& response,
akmhoquedfe615f2014-07-27 14:12:21 -0500140 const ndn::Name& name);
akmhoquec04e7272014-07-02 11:00:14 -0500141
Nick Gordond0a7df32017-05-30 16:44:34 -0500142 /*! \brief Set up a Face for NLSR use.
143 *
144 * When NLSR receives a Hello Interest from a neighbor that it has
145 * not seen before, it may need to create a Face for that
146 * neighbor. After doing so, it will be necessary to inform NFD
147 * about the standard prefixes that NLSR needs a node to have in
148 * order to conduct normal operations. This function accomplishes
149 * that, and then sends its own Hello Interest to confirm the
150 * contact.
151 */
akmhoquec04e7272014-07-02 11:00:14 -0500152 void
153 onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
akmhoque102aea42014-08-04 10:22:12 -0500154 const ndn::Name& neighbor, const ndn::time::milliseconds& timeout);
akmhoquec04e7272014-07-02 11:00:14 -0500155
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500156public:
157 ndn::util::Signal<HelloProtocol, const ndn::Name&> onHelloDataValidated;
158
akmhoque31d1d4b2014-05-05 22:08:14 -0500159private:
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600160 ndn::Face& m_face;
161 ndn::Scheduler m_scheduler;
162 ndn::security::v2::KeyChain& m_keyChain;
163 ndn::security::SigningInfo& m_signingInfo;
164 ConfParameter& m_confParam;
165 RoutingTable& m_routingTable;
166 Lsdb& m_lsdb;
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500167 AdjacencyList& m_adjacencyList;
Vince Lehman7c603292014-09-11 17:48:16 -0500168
akmhoque157b0a42014-05-13 00:26:37 -0500169 static const std::string INFO_COMPONENT;
akmhoque93f1a072014-06-19 16:24:28 -0500170 static const std::string NLSR_COMPONENT;
akmhoque31d1d4b2014-05-05 22:08:14 -0500171};
172
Nick Gordonfad8e252016-08-11 14:21:38 -0500173} // namespace nlsr
akmhoque31d1d4b2014-05-05 22:08:14 -0500174
175#endif // NLSR_HELLO_PROTOCOL_HPP