akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | 563611e | 2018-01-23 13:44:36 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [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 |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 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 | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 22 | #ifndef NLSR_SYNC_LOGIC_HANDLER_HPP |
| 23 | #define NLSR_SYNC_LOGIC_HANDLER_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 24 | |
Ashlesh Gawande | f7da9c5 | 2018-02-06 17:36:46 -0600 | [diff] [blame] | 25 | #include "conf-parameter.hpp" |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 26 | #include "test-access-control.hpp" |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 27 | #include "signals.hpp" |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 28 | #include "lsa.hpp" |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 29 | #include "sync-protocol-adapter.hpp" |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 30 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/face.hpp> |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 32 | #include <ndn-cxx/util/signal.hpp> |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 33 | #include <boost/throw_exception.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | class InterestManager; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 36 | |
| 37 | namespace nlsr { |
| 38 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 39 | class ConfParameter; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 40 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 41 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 49 | class SyncLogicHandler |
| 50 | { |
| 51 | public: |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 52 | using IsLsaNew = |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 53 | std::function<bool(const ndn::Name&, const Lsa::Type& lsaType, const uint64_t&)>; |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 54 | |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 55 | 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 | }; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 64 | |
Nick Gordon | 563611e | 2018-01-23 13:44:36 -0600 | [diff] [blame] | 65 | SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew, const ConfParameter& conf); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 66 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 67 | /*! \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 Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 75 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | void |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 77 | publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 78 | |
Ashlesh Gawande | 4810107 | 2018-05-30 17:53:06 -0500 | [diff] [blame] | 79 | /*! \brief Create and configure a Logic object to enable ChronoSync for this NLSR. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 80 | * |
| 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 Gawande | f7da9c5 | 2018-02-06 17:36:46 -0600 | [diff] [blame] | 83 | * \param syncInterestLifetime ChronoSync sends a periodic sync interest every \p syncInterestLifetime / 2 ms |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 84 | * \sa Nlsr::initialize |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 85 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 86 | void |
Ashlesh Gawande | 4810107 | 2018-05-30 17:53:06 -0500 | [diff] [blame] | 87 | createSyncLogic(const ndn::Name& syncPrefix, |
| 88 | const ndn::time::milliseconds& syncInterestLifetime = |
| 89 | ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 90 | |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 91 | void |
| 92 | processUpdate(const ndn::Name& updateName, uint64_t highSeq); |
| 93 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 94 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 95 | /*! \brief Simple function to glue Name components together |
| 96 | */ |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 97 | void |
| 98 | buildUpdatePrefix(); |
| 99 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 100 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 108 | void |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 109 | processUpdateFromSync(const ndn::Name& originRouter, |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 110 | const ndn::Name& updateName, uint64_t seqNo); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 111 | |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 112 | public: |
| 113 | std::unique_ptr<OnNewLsa> onNewLsa; |
| 114 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 115 | private: |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 116 | ndn::Face& m_syncFace; |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 117 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 118 | std::shared_ptr<SyncProtocolAdapter> m_syncLogic; |
| 119 | private: |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 120 | IsLsaNew m_isLsaNew; |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 121 | const ConfParameter& m_confParam; |
Vince Lehman | 0bcf9a3 | 2014-12-10 11:24:45 -0600 | [diff] [blame] | 122 | |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 123 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 124 | ndn::Name m_nameLsaUserPrefix; |
| 125 | ndn::Name m_adjLsaUserPrefix; |
| 126 | ndn::Name m_coorLsaUserPrefix; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 127 | |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 128 | private: |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 129 | static const std::string NLSR_COMPONENT; |
| 130 | static const std::string LSA_COMPONENT; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 131 | }; |
| 132 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 133 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 134 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 135 | #endif // NLSR_SYNC_LOGIC_HANDLER_HPP |