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 | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 25 | #include "test-access-control.hpp" |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 26 | #include "signals.hpp" |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame^] | 27 | #include "lsa.hpp" |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 28 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 29 | #include <ndn-cxx/face.hpp> |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/util/signal.hpp> |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 31 | #include <ChronoSync/socket.hpp> |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 32 | #include <boost/throw_exception.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | class InterestManager; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | |
| 36 | namespace nlsr { |
| 37 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 38 | class ConfParameter; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 39 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 40 | /*! \brief NLSR-to-ChronoSync interaction point |
| 41 | * |
| 42 | * This class serves as the abstraction for the syncing portion of |
| 43 | * NLSR and its components. NLSR has no particular reliance on |
| 44 | * ChronoSync, except that the NLSR source would need to be modified |
| 45 | * for use with other sync protocols. |
| 46 | * |
| 47 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 48 | class SyncLogicHandler |
| 49 | { |
| 50 | public: |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 51 | using IsLsaNew = |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame^] | 52 | 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] | 53 | |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 54 | class Error : public std::runtime_error |
| 55 | { |
| 56 | public: |
| 57 | explicit |
| 58 | Error(const std::string& what) |
| 59 | : std::runtime_error(what) |
| 60 | { |
| 61 | } |
| 62 | }; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 63 | |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 64 | SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew, ConfParameter& conf); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 65 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 66 | /*! \brief Hook function to call whenever sync detects new data. |
| 67 | * |
| 68 | * This function packages the sync information into discrete updates |
| 69 | * and passes those off to another function, processUpdateFromSync. |
| 70 | * \sa processUpdateFromSync |
| 71 | * |
| 72 | * \param v A container with the new information sync has received |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 73 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 74 | void |
Ashlesh Gawande | 7600c90 | 2017-06-21 13:28:35 -0500 | [diff] [blame] | 75 | onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& v); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 77 | /*! \brief Instruct ChronoSync to publish an update. |
| 78 | * |
| 79 | * This function instructs sync to push an update into the network, |
| 80 | * based on whatever the state of the sequencing manager is when |
| 81 | * this is called. Since each ChronoSync instance maintains its own |
| 82 | * PIT, doing this satisfies those interests so that other routers |
| 83 | * know a sync update is available. |
| 84 | * \sa publishSyncUpdate |
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 |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame^] | 87 | publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 88 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 89 | /*! \brief Create and configure a socket to enable ChronoSync for this NLSR. |
| 90 | * |
| 91 | * In a typical situation this only needs to be called once, when NLSR starts. |
| 92 | * \param syncPrefix The sync prefix you want this ChronoSync to use |
| 93 | * \sa Nlsr::initialize |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 94 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 95 | void |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 96 | createSyncSocket(const ndn::Name& syncPrefix); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 97 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 98 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 99 | /*! \brief Simple function to glue Name components together |
| 100 | */ |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 101 | void |
| 102 | buildUpdatePrefix(); |
| 103 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 104 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 105 | /*! \brief Determine which kind of LSA was updated and fetch it. |
| 106 | * |
| 107 | * Checks that the received update is not from us, which can happen, |
| 108 | * and then inspects the update to determine which kind of LSA the |
| 109 | * update is for. Finally, it expresses interest for the correct LSA |
| 110 | * type. |
| 111 | * \throws SyncUpdate::Error If the sync update doesn't look like a sync LSA update. |
| 112 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 113 | void |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 114 | processUpdateFromSync(const ndn::Name& originRouter, |
| 115 | const ndn::Name& updateName, const uint64_t& seqNo); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 116 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 117 | /*! \brief Instruct ChronoSync, via the sync socket, to publish an update. |
| 118 | * |
| 119 | * Each ChronoSync instance maintains its own PIT for sync |
| 120 | * updates. This function creates a data that satisfies that update, |
| 121 | * so that the interested routers will know new data is available. |
| 122 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 123 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 124 | publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 125 | |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 126 | public: |
| 127 | std::unique_ptr<OnNewLsa> onNewLsa; |
| 128 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 129 | private: |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 130 | ndn::Face& m_syncFace; |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 131 | std::shared_ptr<chronosync::Socket> m_syncSocket; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 132 | ndn::Name m_syncPrefix; |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 133 | IsLsaNew m_isLsaNew; |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 134 | const ConfParameter& m_confParam; |
Vince Lehman | 0bcf9a3 | 2014-12-10 11:24:45 -0600 | [diff] [blame] | 135 | |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 136 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 137 | ndn::Name m_nameLsaUserPrefix; |
| 138 | ndn::Name m_adjLsaUserPrefix; |
| 139 | ndn::Name m_coorLsaUserPrefix; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 140 | |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 141 | private: |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 142 | static const std::string NLSR_COMPONENT; |
| 143 | static const std::string LSA_COMPONENT; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 144 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 145 | }; |
| 146 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 147 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 148 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 149 | #endif // NLSR_SYNC_LOGIC_HANDLER_HPP |