blob: 3782663706676f38e94d0a7eb1376ba36d8a1719 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande0421bc62020-05-08 20:42:19 -07002/*
Junxiao Shif4674672024-01-06 02:27:36 +00003 * Copyright (c) 2014-2024, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * 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
Vince Lehmanc2e51f62015-01-20 15:03:11 -060019 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070020 */
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
akmhoquefdbddb12014-05-02 18:35:19 -050022#ifndef NLSR_SYNC_LOGIC_HANDLER_HPP
23#define NLSR_SYNC_LOGIC_HANDLER_HPP
akmhoque53353462014-04-22 08:43:45 -050024
Ashlesh Gawandef7da9c52018-02-06 17:36:46 -060025#include "conf-parameter.hpp"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080026#include "lsa/lsa.hpp"
Davide Pesavento1954a0c2022-09-30 15:56:04 -040027#include "signals.hpp"
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050028#include "sync-protocol-adapter.hpp"
Davide Pesavento1954a0c2022-09-30 15:56:04 -040029#include "test-access-control.hpp"
akmhoque53353462014-04-22 08:43:45 -050030
Junxiao Shif4674672024-01-06 02:27:36 +000031#include <boost/lexical_cast.hpp>
32
akmhoque53353462014-04-22 08:43:45 -050033namespace nlsr {
34
Junxiao Shif4674672024-01-06 02:27:36 +000035struct SyncLogicOptions
36{
37 SyncProtocol syncProtocol;
38 ndn::Name syncPrefix;
39 ndn::Name userPrefix;
40 ndn::time::milliseconds syncInterestLifetime;
41 ndn::Name routerPrefix;
42 HyperbolicState hyperbolicState;
43};
44
45inline ndn::Name
46makeLsaUserPrefix(const ndn::Name& userPrefix, Lsa::Type lsaType)
47{
48 return ndn::Name(userPrefix).append(boost::lexical_cast<std::string>(lsaType));
49}
50
51/*! \brief NLSR-to-sync interaction point
Nick Gordond0a7df32017-05-30 16:44:34 -050052 *
53 * This class serves as the abstraction for the syncing portion of
Junxiao Shif4674672024-01-06 02:27:36 +000054 * NLSR and its components.
Nick Gordond0a7df32017-05-30 16:44:34 -050055 */
akmhoque53353462014-04-22 08:43:45 -050056class SyncLogicHandler
57{
58public:
Vince Lehman9d097802015-03-16 17:55:59 -050059 class Error : public std::runtime_error
60 {
61 public:
Davide Pesaventod90338d2021-01-07 17:50:05 -050062 using std::runtime_error::runtime_error;
Vince Lehman9d097802015-03-16 17:55:59 -050063 };
akmhoque53353462014-04-22 08:43:45 -050064
Junxiao Shif4674672024-01-06 02:27:36 +000065 using IsLsaNew = std::function<
66 bool (const ndn::Name& routerName, Lsa::Type lsaType, uint64_t seqNo, uint64_t inFace)
67 >;
Davide Pesaventod90338d2021-01-07 17:50:05 -050068
Davide Pesavento1954a0c2022-09-30 15:56:04 -040069 SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain,
Junxiao Shif4674672024-01-06 02:27:36 +000070 IsLsaNew isLsaNew, const SyncLogicOptions& opts);
akmhoque53353462014-04-22 08:43:45 -050071
Nick Gordond0a7df32017-05-30 16:44:34 -050072 /*! \brief Instruct ChronoSync to publish an update.
73 *
74 * This function instructs sync to push an update into the network,
75 * based on whatever the state of the sequencing manager is when
76 * this is called. Since each ChronoSync instance maintains its own
77 * PIT, doing this satisfies those interests so that other routers
78 * know a sync update is available.
79 * \sa publishSyncUpdate
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050080 */
akmhoque53353462014-04-22 08:43:45 -050081 void
Junxiao Shif4674672024-01-06 02:27:36 +000082 publishRoutingUpdate(Lsa::Type type, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050083
Ashlesh Gawande85998a12017-12-07 22:22:13 -060084PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060085 /*! \brief Callback from Sync protocol
86 *
87 * In a typical situation this only needs to be called once, when NLSR starts.
88 * \param updateName The prefix for which sync reports an update
89 * \param highSeq The latest sequence number of the update
90 */
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050091 void
Alexander Afanasyev135288c2022-04-23 23:06:56 -040092 processUpdate(const ndn::Name& updateName, uint64_t highSeq, uint64_t incomingFaceId);
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050093
Nick Gordond0a7df32017-05-30 16:44:34 -050094 /*! \brief Determine which kind of LSA was updated and fetch it.
95 *
96 * Checks that the received update is not from us, which can happen,
97 * and then inspects the update to determine which kind of LSA the
98 * update is for. Finally, it expresses interest for the correct LSA
99 * type.
100 * \throws SyncUpdate::Error If the sync update doesn't look like a sync LSA update.
101 */
akmhoque53353462014-04-22 08:43:45 -0500102 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500103 processUpdateFromSync(const ndn::Name& originRouter,
Alexander Afanasyev135288c2022-04-23 23:06:56 -0400104 const ndn::Name& updateName, uint64_t seqNo, uint64_t incomingFaceId);
Vince Lehman904c2412014-09-23 19:36:11 -0500105
Nick Gordon9eac4d92017-08-29 17:31:29 -0500106public:
Davide Pesavento1954a0c2022-09-30 15:56:04 -0400107 OnNewLsa onNewLsa;
Nick Gordon9eac4d92017-08-29 17:31:29 -0500108
akmhoque53353462014-04-22 08:43:45 -0500109private:
Nick Gordon9eac4d92017-08-29 17:31:29 -0500110 IsLsaNew m_isLsaNew;
Junxiao Shif4674672024-01-06 02:27:36 +0000111 ndn::Name m_routerPrefix;
112 HyperbolicState m_hyperbolicState;
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600113
Vince Lehmanc11cc202015-01-20 11:41:33 -0600114PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500115 ndn::Name m_nameLsaUserPrefix;
116 ndn::Name m_adjLsaUserPrefix;
117 ndn::Name m_coorLsaUserPrefix;
Vince Lehman904c2412014-09-23 19:36:11 -0500118
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500119 SyncProtocolAdapter m_syncLogic;
akmhoque53353462014-04-22 08:43:45 -0500120};
121
Nick Gordonfad8e252016-08-11 14:21:38 -0500122} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500123
dmcoomes9f936662017-03-02 10:33:09 -0600124#endif // NLSR_SYNC_LOGIC_HANDLER_HPP