akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Muktadir R Chowdhury | 800833b | 2016-07-29 13:43:59 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [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 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 25 | #include "test-access-control.hpp" |
| 26 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 27 | #include <ndn-cxx/face.hpp> |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame^] | 28 | #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
| 29 | #include <ndn-cxx/mgmt/nfd/control-response.hpp> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/util/scheduler.hpp> |
| 31 | |
| 32 | namespace nlsr { |
| 33 | |
| 34 | class Nlsr; |
| 35 | |
| 36 | class HelloProtocol |
| 37 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 38 | public: |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 39 | HelloProtocol(Nlsr& nlsr, ndn::Scheduler& scheduler) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 40 | : m_nlsr(nlsr) |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 41 | , m_scheduler(scheduler) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 45 | /*! \brief Schedules a hello Interest event. |
| 46 | |
| 47 | \param seconds The number of seconds to wait before calling the event. |
| 48 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 49 | void |
| 50 | scheduleInterest(uint32_t seconds); |
| 51 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 52 | /*! \brief Sends a hello Interest packet. |
| 53 | |
| 54 | \param interestNamePrefix The name of the router that has published the |
| 55 | update we want. Here that should be: \<router name\>/NLSR/INFO |
| 56 | |
| 57 | \param seconds The lifetime of the Interest we construct, in seconds |
| 58 | |
| 59 | This function attempts to contact neighboring routers to |
| 60 | determine their status (which currently is one of: ACTIVE, |
| 61 | INACTIVE, or UNKNOWN) |
| 62 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 63 | void |
| 64 | expressInterest(const ndn::Name& interestNamePrefix, uint32_t seconds); |
| 65 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 66 | /*! \brief Sends a hello Interest packet that was previously scheduled. |
| 67 | |
| 68 | \param seconds (ignored) |
| 69 | |
| 70 | This function is called as part of a schedule to regularly |
| 71 | determine the adjacency status of neighbors. This function checks |
| 72 | if the specified neighbor has a Face, and if not creates one. If |
| 73 | the neighbor had a Face, it calls \c expressInterest, else it will |
| 74 | attempt to create a Face, which will itself attempt to contact the |
| 75 | neighbor. Then the function schedules for this function to be invoked again. |
| 76 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 77 | void |
| 78 | sendScheduledInterest(uint32_t seconds); |
| 79 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 80 | /*! \brief Processes a hello Interest from a neighbor. |
| 81 | |
| 82 | \param name (ignored) |
| 83 | |
| 84 | \param interest The Interest object that we have received and need to |
| 85 | process. |
| 86 | |
| 87 | Processes a hello Interest that this router receives from one of |
| 88 | its neighbors. If the neighbor that sent the Interest does not |
| 89 | have a Face, NLSR will attempt to register one. Also, if the |
| 90 | neighbor that sent the Interest was previously marked as INACTIVE, |
| 91 | NLSR will attempt to contact it with its own hello Interest. |
| 92 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 93 | void |
| 94 | processInterest(const ndn::Name& name, const ndn::Interest& interest); |
| 95 | |
| 96 | private: |
| 97 | void |
| 98 | processInterestTimedOut(const ndn::Interest& interest); |
| 99 | |
| 100 | void |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 101 | onContent(const ndn::Interest& interest, const ndn::Data& data); |
| 102 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 103 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 104 | void |
| 105 | onContentValidated(const ndn::shared_ptr<const ndn::Data>& data); |
| 106 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 107 | private: |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 108 | void |
| 109 | onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, |
| 110 | const std::string& msg); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 111 | |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 112 | void |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 113 | onRegistrationFailure(const ndn::nfd::ControlResponse& response, |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 114 | const ndn::Name& name); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 115 | |
| 116 | void |
| 117 | onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 118 | const ndn::Name& neighbor, const ndn::time::milliseconds& timeout); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 119 | |
| 120 | void |
akmhoque | 8e0252b | 2014-07-07 16:04:44 -0500 | [diff] [blame] | 121 | registerPrefixes(const ndn::Name& adjName, const std::string& faceUri, |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 122 | double linkCost, const ndn::time::milliseconds& timeout); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 123 | private: |
| 124 | Nlsr& m_nlsr; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 125 | ndn::Scheduler& m_scheduler; |
| 126 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 127 | static const std::string INFO_COMPONENT; |
akmhoque | 93f1a07 | 2014-06-19 16:24:28 -0500 | [diff] [blame] | 128 | static const std::string NLSR_COMPONENT; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 129 | }; |
| 130 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 131 | } // namespace nlsr |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 132 | |
| 133 | #endif // NLSR_HELLO_PROTOCOL_HPP |