blob: 6eee2132a5049f6db2d9a263db10df28657c8f67 [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/*
Alexander Afanasyev135288c2022-04-23 23:06:56 -04003 * Copyright (c) 2014-2022, 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
31namespace nlsr {
32
Nick Gordond0a7df32017-05-30 16:44:34 -050033/*! \brief NLSR-to-ChronoSync interaction point
34 *
35 * This class serves as the abstraction for the syncing portion of
36 * NLSR and its components. NLSR has no particular reliance on
37 * ChronoSync, except that the NLSR source would need to be modified
38 * for use with other sync protocols.
Nick Gordond0a7df32017-05-30 16:44:34 -050039 */
akmhoque53353462014-04-22 08:43:45 -050040class SyncLogicHandler
41{
42public:
Vince Lehman9d097802015-03-16 17:55:59 -050043 class Error : public std::runtime_error
44 {
45 public:
Davide Pesaventod90338d2021-01-07 17:50:05 -050046 using std::runtime_error::runtime_error;
Vince Lehman9d097802015-03-16 17:55:59 -050047 };
akmhoque53353462014-04-22 08:43:45 -050048
Davide Pesaventod90338d2021-01-07 17:50:05 -050049 using IsLsaNew =
Alexander Afanasyev135288c2022-04-23 23:06:56 -040050 std::function<bool(const ndn::Name&, const Lsa::Type& lsaType, const uint64_t&, uint64_t/*inFace*/)>;
Davide Pesaventod90338d2021-01-07 17:50:05 -050051
Davide Pesavento1954a0c2022-09-30 15:56:04 -040052 SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain,
53 IsLsaNew isLsaNew, const ConfParameter& conf);
akmhoque53353462014-04-22 08:43:45 -050054
Nick Gordond0a7df32017-05-30 16:44:34 -050055 /*! \brief Instruct ChronoSync to publish an update.
56 *
57 * This function instructs sync to push an update into the network,
58 * based on whatever the state of the sequencing manager is when
59 * this is called. Since each ChronoSync instance maintains its own
60 * PIT, doing this satisfies those interests so that other routers
61 * know a sync update is available.
62 * \sa publishSyncUpdate
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050063 */
akmhoque53353462014-04-22 08:43:45 -050064 void
Nick Gordon727d4832017-10-13 18:04:25 -050065 publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo);
akmhoque53353462014-04-22 08:43:45 -050066
Ashlesh Gawande85998a12017-12-07 22:22:13 -060067PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060068 /*! \brief Callback from Sync protocol
69 *
70 * In a typical situation this only needs to be called once, when NLSR starts.
71 * \param updateName The prefix for which sync reports an update
72 * \param highSeq The latest sequence number of the update
73 */
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050074 void
Alexander Afanasyev135288c2022-04-23 23:06:56 -040075 processUpdate(const ndn::Name& updateName, uint64_t highSeq, uint64_t incomingFaceId);
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050076
Nick Gordond0a7df32017-05-30 16:44:34 -050077 /*! \brief Determine which kind of LSA was updated and fetch it.
78 *
79 * Checks that the received update is not from us, which can happen,
80 * and then inspects the update to determine which kind of LSA the
81 * update is for. Finally, it expresses interest for the correct LSA
82 * type.
83 * \throws SyncUpdate::Error If the sync update doesn't look like a sync LSA update.
84 */
akmhoque53353462014-04-22 08:43:45 -050085 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050086 processUpdateFromSync(const ndn::Name& originRouter,
Alexander Afanasyev135288c2022-04-23 23:06:56 -040087 const ndn::Name& updateName, uint64_t seqNo, uint64_t incomingFaceId);
Vince Lehman904c2412014-09-23 19:36:11 -050088
Nick Gordon9eac4d92017-08-29 17:31:29 -050089public:
Davide Pesavento1954a0c2022-09-30 15:56:04 -040090 OnNewLsa onNewLsa;
Nick Gordon9eac4d92017-08-29 17:31:29 -050091
akmhoque53353462014-04-22 08:43:45 -050092private:
Nick Gordon9eac4d92017-08-29 17:31:29 -050093 IsLsaNew m_isLsaNew;
Nick Gordond0a7df32017-05-30 16:44:34 -050094 const ConfParameter& m_confParam;
Vince Lehman0bcf9a32014-12-10 11:24:45 -060095
Vince Lehmanc11cc202015-01-20 11:41:33 -060096PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050097 ndn::Name m_nameLsaUserPrefix;
98 ndn::Name m_adjLsaUserPrefix;
99 ndn::Name m_coorLsaUserPrefix;
Vince Lehman904c2412014-09-23 19:36:11 -0500100
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500101 SyncProtocolAdapter m_syncLogic;
akmhoque53353462014-04-22 08:43:45 -0500102};
103
Nick Gordonfad8e252016-08-11 14:21:38 -0500104} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500105
dmcoomes9f936662017-03-02 10:33:09 -0600106#endif // NLSR_SYNC_LOGIC_HANDLER_HPP