akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 2 | /* |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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/>. |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 20 | */ |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 21 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 22 | #ifndef NLSR_HELLO_PROTOCOL_HPP |
| 23 | #define NLSR_HELLO_PROTOCOL_HPP |
| 24 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 25 | #include "statistics.hpp" |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 26 | #include "test-access-control.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 27 | #include "conf-parameter.hpp" |
| 28 | #include "lsdb.hpp" |
| 29 | #include "route/routing-table.hpp" |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 30 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 31 | #include <ndn-cxx/util/signal.hpp> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 32 | #include <ndn-cxx/face.hpp> |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 33 | #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
| 34 | #include <ndn-cxx/mgmt/nfd/control-response.hpp> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 35 | #include <ndn-cxx/util/scheduler.hpp> |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 36 | #include <ndn-cxx/security/validation-error.hpp> |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 37 | #include <ndn-cxx/security/validator-config.hpp> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 38 | |
| 39 | namespace nlsr { |
| 40 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 41 | class HelloProtocol |
| 42 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 43 | public: |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 44 | HelloProtocol(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam, |
| 45 | RoutingTable& routingTable, Lsdb& lsdb); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 46 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 47 | /*! \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 G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 57 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 58 | void |
| 59 | expressInterest(const ndn::Name& interestNamePrefix, uint32_t seconds); |
| 60 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 61 | /*! \brief Sends Hello Interests to all neighbors |
| 62 | * |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 63 | * This function is called as part of a schedule to regularly |
| 64 | * determine the adjacency status of neighbors. This function |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 65 | * creates and sends a Hello Interest to the given adjacent. |
| 66 | * |
| 67 | * \param neighbor the name of the neighbor |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 68 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 69 | void |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 70 | sendHelloInterest(const ndn::Name& neighbor); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 71 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 72 | /*! \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 G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 85 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 86 | void |
| 87 | processInterest(const ndn::Name& name, const ndn::Interest& interest); |
| 88 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 89 | ndn::util::signal::Signal<HelloProtocol, Statistics::PacketType> hpIncrementSignal; |
| 90 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 91 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 92 | /*! \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 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 101 | void |
| 102 | processInterestTimedOut(const ndn::Interest& interest); |
| 103 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 104 | /*! \brief Verify signatures and validate incoming Hello data. |
| 105 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 106 | void |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 107 | onContent(const ndn::Interest& interest, const ndn::Data& data); |
| 108 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 109 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 110 | |
| 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 Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 118 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 119 | onContentValidated(const ndn::Data& data); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 120 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 121 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 122 | /*! \brief Log that incoming data couldn't be validated, but do nothing else. |
| 123 | */ |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 124 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 125 | onContentValidationFailed(const ndn::Data& data, |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 126 | const ndn::security::ValidationError& ve); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 127 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 128 | /*! \brief Treat a failed Face registration as an INACTIVE neighbor. |
| 129 | * |
| 130 | * If NLSR fails to register a Face when contacting a neighbor, it |
| 131 | * will instantly toggle that neighbor to INACTIVE. This is |
| 132 | * necessary because NLSR will put off building its own adjacency |
| 133 | * LSA until the status of each neighbor is definitively |
| 134 | * known. Without this, NLSR might have to wait many scheduled Hello |
| 135 | * intervals to finish building an adjacency LSA. |
| 136 | */ |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 137 | void |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 138 | onRegistrationFailure(const ndn::nfd::ControlResponse& response, |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 139 | const ndn::Name& name); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 140 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 141 | /*! \brief Set up a Face for NLSR use. |
| 142 | * |
| 143 | * When NLSR receives a Hello Interest from a neighbor that it has |
| 144 | * not seen before, it may need to create a Face for that |
| 145 | * neighbor. After doing so, it will be necessary to inform NFD |
| 146 | * about the standard prefixes that NLSR needs a node to have in |
| 147 | * order to conduct normal operations. This function accomplishes |
| 148 | * that, and then sends its own Hello Interest to confirm the |
| 149 | * contact. |
| 150 | */ |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 151 | void |
| 152 | onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 153 | const ndn::Name& neighbor, const ndn::time::milliseconds& timeout); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 154 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 155 | public: |
| 156 | ndn::util::Signal<HelloProtocol, const ndn::Name&> onHelloDataValidated; |
| 157 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 158 | private: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 159 | ndn::Face& m_face; |
| 160 | ndn::Scheduler m_scheduler; |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 161 | ndn::security::KeyChain& m_keyChain; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 162 | const ndn::security::SigningInfo& m_signingInfo; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 163 | ConfParameter& m_confParam; |
| 164 | RoutingTable& m_routingTable; |
| 165 | Lsdb& m_lsdb; |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 166 | AdjacencyList& m_adjacencyList; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 167 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 168 | static const std::string INFO_COMPONENT; |
akmhoque | 93f1a07 | 2014-06-19 16:24:28 -0500 | [diff] [blame] | 169 | static const std::string NLSR_COMPONENT; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 170 | }; |
| 171 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 172 | } // namespace nlsr |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 173 | |
| 174 | #endif // NLSR_HELLO_PROTOCOL_HPP |