blob: c04270707642746f2d7fe3c4e7c2e26f6380c949 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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"
27
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060028#include <ndn-cxx/util/signal.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050029#include <ndn-cxx/face.hpp>
Junxiao Shi3e5120c2016-09-10 16:58:34 +000030#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
31#include <ndn-cxx/mgmt/nfd/control-response.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050032#include <ndn-cxx/util/scheduler.hpp>
33
34namespace nlsr {
35
36class Nlsr;
37
38class HelloProtocol
39{
akmhoque31d1d4b2014-05-05 22:08:14 -050040public:
Nick Gordone18296c2017-10-11 16:05:24 -050041 HelloProtocol(Nlsr& nlsr, ndn::Scheduler& scheduler);
akmhoque31d1d4b2014-05-05 22:08:14 -050042
Nick Gordond0a7df32017-05-30 16:44:34 -050043 /*! \brief Schedules a Hello Interest event.
44 *
45 * This function serves as the Hello Interest loop, and must be
46 * explicitly called to start the Hello cycle. This is done at
47 * NLSR's initialization.
48 *
49 * \sa Nlsr::initialize
50 * \param seconds The number of seconds to wait before calling the event.
Nick G97e34942016-07-11 14:46:27 -050051 */
akmhoque31d1d4b2014-05-05 22:08:14 -050052 void
53 scheduleInterest(uint32_t seconds);
54
Nick Gordond0a7df32017-05-30 16:44:34 -050055 /*! \brief Sends a Hello Interest packet.
56 *
57 * \param interestNamePrefix The name of the router that has published the
58 * update we want. Here that should be: \<router name\>/NLSR/INFO
59 *
60 * \param seconds The lifetime of the Interest we construct, in seconds
61 *
62 * This function attempts to contact neighboring routers to
63 * determine their status (which currently is one of: ACTIVE,
64 * INACTIVE, or UNKNOWN)
Nick G97e34942016-07-11 14:46:27 -050065 */
akmhoque31d1d4b2014-05-05 22:08:14 -050066 void
67 expressInterest(const ndn::Name& interestNamePrefix, uint32_t seconds);
68
Nick Gordond0a7df32017-05-30 16:44:34 -050069 /*! \brief Sends Hello Interests to all neighbors
70 *
71 * \param seconds (ignored)
72 *
73 * This function is called as part of a schedule to regularly
74 * determine the adjacency status of neighbors. This function
75 * creates and sends a Hello Interest to each neighbor in
76 * Nlsr::m_adjacencyList. If the neighbor has not been contacted
77 * before and curerntly has no Face in NFD, this method will call a
78 * different pipeline that creates the Face first, then registers
79 * prefixes.
Nick G97e34942016-07-11 14:46:27 -050080 */
akmhoque31d1d4b2014-05-05 22:08:14 -050081 void
82 sendScheduledInterest(uint32_t seconds);
83
Nick Gordond0a7df32017-05-30 16:44:34 -050084 /*! \brief Processes a Hello Interest from a neighbor.
85 *
86 * \param name (ignored)
87 *
88 * \param interest The Interest object that we have received and need to
89 * process.
90 *
91 * Processes a Hello Interest that this router receives from one of
92 * its neighbors. If the neighbor that sent the Interest does not
93 * have a Face, NLSR will attempt to create one. Also, if the
94 * neighbor that sent the Interest was previously marked as
95 * INACTIVE, NLSR will attempt to contact it with its own Hello
96 * Interest.
Nick G97e34942016-07-11 14:46:27 -050097 */
akmhoque31d1d4b2014-05-05 22:08:14 -050098 void
99 processInterest(const ndn::Name& name, const ndn::Interest& interest);
100
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600101 ndn::util::signal::Signal<HelloProtocol, Statistics::PacketType> hpIncrementSignal;
102
akmhoque31d1d4b2014-05-05 22:08:14 -0500103private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500104 /*! \brief Try to contact a neighbor via Hello protocol again
105 *
106 * This function will re-send Hello Interests a configured number
107 * of times. After that many failures, HelloProtocol will mark the neighbor as
108 * inactive and will not attempt to contact them until the next time
109 * HelloProtocol::sendScheduledInterest is called.
110 *
111 * \sa nlsr::ConfParameter::getInterestRetryNumber
112 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500113 void
114 processInterestTimedOut(const ndn::Interest& interest);
115
Nick Gordond0a7df32017-05-30 16:44:34 -0500116 /*! \brief Verify signatures and validate incoming Hello data.
117 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500118 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700119 onContent(const ndn::Interest& interest, const ndn::Data& data);
120
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500121PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick Gordond0a7df32017-05-30 16:44:34 -0500122
123 /*! \brief Change a neighbor's status
124 *
125 * Whenever incoming Hello data is verified and validated, change
126 * the status of this neighbor and then schedule an adjacency LSA
127 * build for us. This also resets the number of times we've failed
128 * to contact this neighbor so that we will retry later.
129 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700130 void
dmcoomes9f936662017-03-02 10:33:09 -0600131 onContentValidated(const std::shared_ptr<const ndn::Data>& data);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700132
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500133private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500134 /*! \brief Log that incoming data couldn't be validated, but do nothing else.
135 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700136 void
dmcoomes9f936662017-03-02 10:33:09 -0600137 onContentValidationFailed(const std::shared_ptr<const ndn::Data>& data,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700138 const std::string& msg);
akmhoque31d1d4b2014-05-05 22:08:14 -0500139
Nick Gordond0a7df32017-05-30 16:44:34 -0500140 /*! \brief Treat a failed Face registration as an INACTIVE neighbor.
141 *
142 * If NLSR fails to register a Face when contacting a neighbor, it
143 * will instantly toggle that neighbor to INACTIVE. This is
144 * necessary because NLSR will put off building its own adjacency
145 * LSA until the status of each neighbor is definitively
146 * known. Without this, NLSR might have to wait many scheduled Hello
147 * intervals to finish building an adjacency LSA.
148 */
akmhoquec04e7272014-07-02 11:00:14 -0500149 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000150 onRegistrationFailure(const ndn::nfd::ControlResponse& response,
akmhoquedfe615f2014-07-27 14:12:21 -0500151 const ndn::Name& name);
akmhoquec04e7272014-07-02 11:00:14 -0500152
Nick Gordond0a7df32017-05-30 16:44:34 -0500153 /*! \brief Set up a Face for NLSR use.
154 *
155 * When NLSR receives a Hello Interest from a neighbor that it has
156 * not seen before, it may need to create a Face for that
157 * neighbor. After doing so, it will be necessary to inform NFD
158 * about the standard prefixes that NLSR needs a node to have in
159 * order to conduct normal operations. This function accomplishes
160 * that, and then sends its own Hello Interest to confirm the
161 * contact.
162 */
akmhoquec04e7272014-07-02 11:00:14 -0500163 void
164 onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
akmhoque102aea42014-08-04 10:22:12 -0500165 const ndn::Name& neighbor, const ndn::time::milliseconds& timeout);
akmhoquec04e7272014-07-02 11:00:14 -0500166
Nick Gordond0a7df32017-05-30 16:44:34 -0500167 /*! \brief Create a Face for an adjacency
168 * \sa HelloProtocol::onRegistrationSuccess
169 */
170 void
171 registerPrefixes(const ndn::Name& adjName, const std::string& faceUri,
172 double linkCost, const ndn::time::milliseconds& timeout);
akmhoque31d1d4b2014-05-05 22:08:14 -0500173private:
174 Nlsr& m_nlsr;
Vince Lehman7c603292014-09-11 17:48:16 -0500175 ndn::Scheduler& m_scheduler;
176
akmhoque157b0a42014-05-13 00:26:37 -0500177 static const std::string INFO_COMPONENT;
akmhoque93f1a072014-06-19 16:24:28 -0500178 static const std::string NLSR_COMPONENT;
akmhoque31d1d4b2014-05-05 22:08:14 -0500179};
180
Nick Gordonfad8e252016-08-11 14:21:38 -0500181} // namespace nlsr
akmhoque31d1d4b2014-05-05 22:08:14 -0500182
183#endif // NLSR_HELLO_PROTOCOL_HPP