blob: 808b84391db2d97a7de6c0fb1eaed91a64ef5225 [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
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050025#include "test-access-control.hpp"
26
akmhoque31d1d4b2014-05-05 22:08:14 -050027#include <ndn-cxx/face.hpp>
Junxiao Shi3e5120c2016-09-10 16:58:34 +000028#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
29#include <ndn-cxx/mgmt/nfd/control-response.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050030#include <ndn-cxx/util/scheduler.hpp>
31
32namespace nlsr {
33
34class Nlsr;
35
36class HelloProtocol
37{
akmhoque31d1d4b2014-05-05 22:08:14 -050038public:
Vince Lehman7c603292014-09-11 17:48:16 -050039 HelloProtocol(Nlsr& nlsr, ndn::Scheduler& scheduler)
akmhoque31d1d4b2014-05-05 22:08:14 -050040 : m_nlsr(nlsr)
Vince Lehman7c603292014-09-11 17:48:16 -050041 , m_scheduler(scheduler)
akmhoque31d1d4b2014-05-05 22:08:14 -050042 {
43 }
44
Nick G97e34942016-07-11 14:46:27 -050045 /*! \brief Schedules a hello Interest event.
46
47 \param seconds The number of seconds to wait before calling the event.
48 */
akmhoque31d1d4b2014-05-05 22:08:14 -050049 void
50 scheduleInterest(uint32_t seconds);
51
Nick G97e34942016-07-11 14:46:27 -050052 /*! \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 */
akmhoque31d1d4b2014-05-05 22:08:14 -050063 void
64 expressInterest(const ndn::Name& interestNamePrefix, uint32_t seconds);
65
Nick G97e34942016-07-11 14:46:27 -050066 /*! \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 */
akmhoque31d1d4b2014-05-05 22:08:14 -050077 void
78 sendScheduledInterest(uint32_t seconds);
79
Nick G97e34942016-07-11 14:46:27 -050080 /*! \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 */
akmhoque31d1d4b2014-05-05 22:08:14 -050093 void
94 processInterest(const ndn::Name& name, const ndn::Interest& interest);
95
96private:
97 void
98 processInterestTimedOut(const ndn::Interest& interest);
99
100 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700101 onContent(const ndn::Interest& interest, const ndn::Data& data);
102
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500103PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700104 void
dmcoomes9f936662017-03-02 10:33:09 -0600105 onContentValidated(const std::shared_ptr<const ndn::Data>& data);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700106
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500107private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700108 void
dmcoomes9f936662017-03-02 10:33:09 -0600109 onContentValidationFailed(const std::shared_ptr<const ndn::Data>& data,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700110 const std::string& msg);
akmhoque31d1d4b2014-05-05 22:08:14 -0500111
akmhoquec04e7272014-07-02 11:00:14 -0500112 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000113 onRegistrationFailure(const ndn::nfd::ControlResponse& response,
akmhoquedfe615f2014-07-27 14:12:21 -0500114 const ndn::Name& name);
akmhoquec04e7272014-07-02 11:00:14 -0500115
116 void
117 onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
akmhoque102aea42014-08-04 10:22:12 -0500118 const ndn::Name& neighbor, const ndn::time::milliseconds& timeout);
akmhoquec04e7272014-07-02 11:00:14 -0500119
akmhoque31d1d4b2014-05-05 22:08:14 -0500120private:
121 Nlsr& m_nlsr;
Vince Lehman7c603292014-09-11 17:48:16 -0500122 ndn::Scheduler& m_scheduler;
123
akmhoque157b0a42014-05-13 00:26:37 -0500124 static const std::string INFO_COMPONENT;
akmhoque93f1a072014-06-19 16:24:28 -0500125 static const std::string NLSR_COMPONENT;
akmhoque31d1d4b2014-05-05 22:08:14 -0500126};
127
Nick Gordonfad8e252016-08-11 14:21:38 -0500128} // namespace nlsr
akmhoque31d1d4b2014-05-05 22:08:14 -0500129
130#endif // NLSR_HELLO_PROTOCOL_HPP