blob: 6de6113068fa7acd0d242e733b4fd5810739c109 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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
Nick Gordond0a7df32017-05-30 16:44:34 -050025#include "test-access-control.hpp"
26
Vince Lehman904c2412014-09-23 19:36:11 -050027#include <ndn-cxx/face.hpp>
Ashlesh Gawande415676b2016-12-22 00:26:23 -060028#include <ChronoSync/socket.hpp>
Vince Lehman904c2412014-09-23 19:36:11 -050029
akmhoque53353462014-04-22 08:43:45 -050030#include <iostream>
Vince Lehman904c2412014-09-23 19:36:11 -050031#include <unistd.h>
akmhoquefdbddb12014-05-02 18:35:19 -050032#include <boost/cstdint.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;
40class Lsdb;
Vince Lehman904c2412014-09-23 19:36:11 -050041
Nick Gordond0a7df32017-05-30 16:44:34 -050042/*! \brief NLSR-to-ChronoSync interaction point
43 *
44 * This class serves as the abstraction for the syncing portion of
45 * NLSR and its components. NLSR has no particular reliance on
46 * ChronoSync, except that the NLSR source would need to be modified
47 * for use with other sync protocols.
48 *
49 */
akmhoque53353462014-04-22 08:43:45 -050050class SyncLogicHandler
51{
52public:
Vince Lehman9d097802015-03-16 17:55:59 -050053 class Error : public std::runtime_error
54 {
55 public:
56 explicit
57 Error(const std::string& what)
58 : std::runtime_error(what)
59 {
60 }
61 };
akmhoque53353462014-04-22 08:43:45 -050062
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050063 SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf);
akmhoque53353462014-04-22 08:43:45 -050064
Nick Gordond0a7df32017-05-30 16:44:34 -050065 /*! \brief Hook function to call whenever sync detects new data.
66 *
67 * This function packages the sync information into discrete updates
68 * and passes those off to another function, processUpdateFromSync.
69 * \sa processUpdateFromSync
70 *
71 * \param v A container with the new information sync has received
Nick G97e34942016-07-11 14:46:27 -050072 */
akmhoque53353462014-04-22 08:43:45 -050073 void
Ashlesh Gawande7600c902017-06-21 13:28:35 -050074 onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& v);
akmhoque53353462014-04-22 08:43:45 -050075
Nick Gordond0a7df32017-05-30 16:44:34 -050076 /*! \brief Instruct ChronoSync to publish an update.
77 *
78 * This function instructs sync to push an update into the network,
79 * based on whatever the state of the sequencing manager is when
80 * this is called. Since each ChronoSync instance maintains its own
81 * PIT, doing this satisfies those interests so that other routers
82 * know a sync update is available.
83 * \sa publishSyncUpdate
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050084 */
akmhoque53353462014-04-22 08:43:45 -050085 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050086 publishRoutingUpdate(const ndn::Name& type, const uint64_t& seqNo);
akmhoque53353462014-04-22 08:43:45 -050087
Nick Gordond0a7df32017-05-30 16:44:34 -050088 /*! \brief Create and configure a socket to enable ChronoSync for this NLSR.
89 *
90 * In a typical situation this only needs to be called once, when NLSR starts.
91 * \param syncPrefix The sync prefix you want this ChronoSync to use
92 * \sa Nlsr::initialize
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050093 */
akmhoque53353462014-04-22 08:43:45 -050094 void
Vince Lehman9d097802015-03-16 17:55:59 -050095 createSyncSocket(const ndn::Name& syncPrefix);
akmhoque53353462014-04-22 08:43:45 -050096
Vince Lehman9d097802015-03-16 17:55:59 -050097private:
Nick Gordond0a7df32017-05-30 16:44:34 -050098 /*! \brief Simple function to glue Name components together
99 */
Vince Lehmanc11cc202015-01-20 11:41:33 -0600100 void
101 buildUpdatePrefix();
102
Nick Gordond0a7df32017-05-30 16:44:34 -0500103 /*! \brief Determine which kind of LSA was updated and fetch it.
104 *
105 * Checks that the received update is not from us, which can happen,
106 * and then inspects the update to determine which kind of LSA the
107 * update is for. Finally, it expresses interest for the correct LSA
108 * type.
109 * \throws SyncUpdate::Error If the sync update doesn't look like a sync LSA update.
110 */
akmhoque53353462014-04-22 08:43:45 -0500111 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500112 processUpdateFromSync(const ndn::Name& originRouter,
113 const ndn::Name& updateName, const uint64_t& seqNo);
Vince Lehman904c2412014-09-23 19:36:11 -0500114
Nick Gordond0a7df32017-05-30 16:44:34 -0500115 /*! \brief Consults the LSDB to determine if a sync update has a new LSA.
116 *
117 * Given some information about an LSA, consult the LSDB to
118 * determine if the sequence number represents a new LSA from the
119 * origin router.
120 */
Vince Lehman904c2412014-09-23 19:36:11 -0500121 bool
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500122 isLsaNew(const ndn::Name& originRouter, const std::string& lsaType,
123 const uint64_t& seqNo);
akmhoque53353462014-04-22 08:43:45 -0500124
Nick Gordond0a7df32017-05-30 16:44:34 -0500125 /*! \brief Fetch an LSA of a certain type, with a certain sequence number.
126 */
akmhoque53353462014-04-22 08:43:45 -0500127 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500128 expressInterestForLsa(const ndn::Name& updateName, const uint64_t& seqNo);
akmhoque53353462014-04-22 08:43:45 -0500129
Nick Gordond0a7df32017-05-30 16:44:34 -0500130 /*! \brief Instruct ChronoSync, via the sync socket, to publish an update.
131 *
132 * Each ChronoSync instance maintains its own PIT for sync
133 * updates. This function creates a data that satisfies that update,
134 * so that the interested routers will know new data is available.
135 */
akmhoque53353462014-04-22 08:43:45 -0500136 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500137 publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500138
139private:
Vince Lehman904c2412014-09-23 19:36:11 -0500140 ndn::Face& m_syncFace;
Ashlesh Gawande415676b2016-12-22 00:26:23 -0600141 std::shared_ptr<chronosync::Socket> m_syncSocket;
akmhoque53353462014-04-22 08:43:45 -0500142 ndn::Name m_syncPrefix;
Vince Lehman904c2412014-09-23 19:36:11 -0500143
Vince Lehmanc11cc202015-01-20 11:41:33 -0600144private:
Vince Lehman904c2412014-09-23 19:36:11 -0500145 Lsdb& m_lsdb;
Nick Gordond0a7df32017-05-30 16:44:34 -0500146 const ConfParameter& m_confParam;
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600147
Vince Lehmanc11cc202015-01-20 11:41:33 -0600148PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500149 ndn::Name m_nameLsaUserPrefix;
150 ndn::Name m_adjLsaUserPrefix;
151 ndn::Name m_coorLsaUserPrefix;
Vince Lehman904c2412014-09-23 19:36:11 -0500152
Vince Lehmanc11cc202015-01-20 11:41:33 -0600153private:
Vince Lehman904c2412014-09-23 19:36:11 -0500154 static const std::string NLSR_COMPONENT;
155 static const std::string LSA_COMPONENT;
Vince Lehman904c2412014-09-23 19:36:11 -0500156
akmhoque53353462014-04-22 08:43:45 -0500157};
158
Nick Gordonfad8e252016-08-11 14:21:38 -0500159} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500160
dmcoomes9f936662017-03-02 10:33:09 -0600161#endif // NLSR_SYNC_LOGIC_HANDLER_HPP