blob: ae72fb826cfaac3f88a046117fbc0dac25a84e88 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordon563611e2018-01-23 13:44:36 -06003 * Copyright (c) 2014-2018, 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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
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"
Nick Gordond0a7df32017-05-30 16:44:34 -050026#include "test-access-control.hpp"
Nick Gordon9eac4d92017-08-29 17:31:29 -050027#include "signals.hpp"
Nick Gordon727d4832017-10-13 18:04:25 -050028#include "lsa.hpp"
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050029#include "sync-protocol-adapter.hpp"
Nick Gordond0a7df32017-05-30 16:44:34 -050030
Vince Lehman904c2412014-09-23 19:36:11 -050031#include <ndn-cxx/face.hpp>
Nick Gordon9eac4d92017-08-29 17:31:29 -050032#include <ndn-cxx/util/signal.hpp>
dmcoomes9f936662017-03-02 10:33:09 -060033#include <boost/throw_exception.hpp>
akmhoque53353462014-04-22 08:43:45 -050034
akmhoque53353462014-04-22 08:43:45 -050035class InterestManager;
akmhoque53353462014-04-22 08:43:45 -050036
37namespace nlsr {
38
Vince Lehman904c2412014-09-23 19:36:11 -050039class ConfParameter;
Vince Lehman904c2412014-09-23 19:36:11 -050040
Nick Gordond0a7df32017-05-30 16:44:34 -050041/*! \brief NLSR-to-ChronoSync interaction point
42 *
43 * This class serves as the abstraction for the syncing portion of
44 * NLSR and its components. NLSR has no particular reliance on
45 * ChronoSync, except that the NLSR source would need to be modified
46 * for use with other sync protocols.
47 *
48 */
akmhoque53353462014-04-22 08:43:45 -050049class SyncLogicHandler
50{
51public:
Nick Gordon9eac4d92017-08-29 17:31:29 -050052 using IsLsaNew =
Nick Gordon727d4832017-10-13 18:04:25 -050053 std::function<bool(const ndn::Name&, const Lsa::Type& lsaType, const uint64_t&)>;
Nick Gordon9eac4d92017-08-29 17:31:29 -050054
Vince Lehman9d097802015-03-16 17:55:59 -050055 class Error : public std::runtime_error
56 {
57 public:
58 explicit
59 Error(const std::string& what)
60 : std::runtime_error(what)
61 {
62 }
63 };
akmhoque53353462014-04-22 08:43:45 -050064
Nick Gordon563611e2018-01-23 13:44:36 -060065 SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew, const ConfParameter& conf);
akmhoque53353462014-04-22 08:43:45 -050066
Nick Gordond0a7df32017-05-30 16:44:34 -050067 /*! \brief Instruct ChronoSync to publish an update.
68 *
69 * This function instructs sync to push an update into the network,
70 * based on whatever the state of the sequencing manager is when
71 * this is called. Since each ChronoSync instance maintains its own
72 * PIT, doing this satisfies those interests so that other routers
73 * know a sync update is available.
74 * \sa publishSyncUpdate
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050075 */
akmhoque53353462014-04-22 08:43:45 -050076 void
Nick Gordon727d4832017-10-13 18:04:25 -050077 publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo);
akmhoque53353462014-04-22 08:43:45 -050078
Ashlesh Gawande48101072018-05-30 17:53:06 -050079 /*! \brief Create and configure a Logic object to enable ChronoSync for this NLSR.
Nick Gordond0a7df32017-05-30 16:44:34 -050080 *
81 * In a typical situation this only needs to be called once, when NLSR starts.
82 * \param syncPrefix The sync prefix you want this ChronoSync to use
Ashlesh Gawandef7da9c52018-02-06 17:36:46 -060083 * \param syncInterestLifetime ChronoSync sends a periodic sync interest every \p syncInterestLifetime / 2 ms
Nick Gordond0a7df32017-05-30 16:44:34 -050084 * \sa Nlsr::initialize
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050085 */
akmhoque53353462014-04-22 08:43:45 -050086 void
Ashlesh Gawande48101072018-05-30 17:53:06 -050087 createSyncLogic(const ndn::Name& syncPrefix,
88 const ndn::time::milliseconds& syncInterestLifetime =
89 ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT));
akmhoque53353462014-04-22 08:43:45 -050090
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050091 void
92 processUpdate(const ndn::Name& updateName, uint64_t highSeq);
93
Nick Gordon8f23b5d2017-08-31 17:53:07 -050094PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick Gordond0a7df32017-05-30 16:44:34 -050095 /*! \brief Simple function to glue Name components together
96 */
Vince Lehmanc11cc202015-01-20 11:41:33 -060097 void
98 buildUpdatePrefix();
99
Nick Gordond0a7df32017-05-30 16:44:34 -0500100 /*! \brief Determine which kind of LSA was updated and fetch it.
101 *
102 * Checks that the received update is not from us, which can happen,
103 * and then inspects the update to determine which kind of LSA the
104 * update is for. Finally, it expresses interest for the correct LSA
105 * type.
106 * \throws SyncUpdate::Error If the sync update doesn't look like a sync LSA update.
107 */
akmhoque53353462014-04-22 08:43:45 -0500108 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500109 processUpdateFromSync(const ndn::Name& originRouter,
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500110 const ndn::Name& updateName, uint64_t seqNo);
Vince Lehman904c2412014-09-23 19:36:11 -0500111
Nick Gordon9eac4d92017-08-29 17:31:29 -0500112public:
113 std::unique_ptr<OnNewLsa> onNewLsa;
114
akmhoque53353462014-04-22 08:43:45 -0500115private:
Vince Lehman904c2412014-09-23 19:36:11 -0500116 ndn::Face& m_syncFace;
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500117PUBLIC_WITH_TESTS_ELSE_PRIVATE:
118 std::shared_ptr<SyncProtocolAdapter> m_syncLogic;
119private:
Nick Gordon9eac4d92017-08-29 17:31:29 -0500120 IsLsaNew m_isLsaNew;
Nick Gordond0a7df32017-05-30 16:44:34 -0500121 const ConfParameter& m_confParam;
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600122
Vince Lehmanc11cc202015-01-20 11:41:33 -0600123PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500124 ndn::Name m_nameLsaUserPrefix;
125 ndn::Name m_adjLsaUserPrefix;
126 ndn::Name m_coorLsaUserPrefix;
Vince Lehman904c2412014-09-23 19:36:11 -0500127
Vince Lehmanc11cc202015-01-20 11:41:33 -0600128private:
Vince Lehman904c2412014-09-23 19:36:11 -0500129 static const std::string NLSR_COMPONENT;
130 static const std::string LSA_COMPONENT;
akmhoque53353462014-04-22 08:43:45 -0500131};
132
Nick Gordonfad8e252016-08-11 14:21:38 -0500133} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500134
dmcoomes9f936662017-03-02 10:33:09 -0600135#endif // NLSR_SYNC_LOGIC_HANDLER_HPP