blob: 72a54874bbd77cecc0475bd656b95e09a3613012 [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
Vince Lehman904c2412014-09-23 19:36:11 -050025#include <ndn-cxx/face.hpp>
Ashlesh Gawande415676b2016-12-22 00:26:23 -060026#include <ChronoSync/socket.hpp>
Vince Lehman904c2412014-09-23 19:36:11 -050027
akmhoque53353462014-04-22 08:43:45 -050028#include <iostream>
Vince Lehman904c2412014-09-23 19:36:11 -050029#include <unistd.h>
akmhoquefdbddb12014-05-02 18:35:19 -050030#include <boost/cstdint.hpp>
dmcoomes9f936662017-03-02 10:33:09 -060031#include <boost/throw_exception.hpp>
akmhoque53353462014-04-22 08:43:45 -050032
Vince Lehmanc11cc202015-01-20 11:41:33 -060033#include "test-access-control.hpp"
34
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
akmhoque53353462014-04-22 08:43:45 -050042class SyncLogicHandler
43{
44public:
Vince Lehman9d097802015-03-16 17:55:59 -050045 class Error : public std::runtime_error
46 {
47 public:
48 explicit
49 Error(const std::string& what)
50 : std::runtime_error(what)
51 {
52 }
53 };
akmhoque53353462014-04-22 08:43:45 -050054
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050055 SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf);
akmhoque53353462014-04-22 08:43:45 -050056
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050057 /*! \brief Receive and parse update from Sync
58
59 Parses the router name the update came from and passes it to processUpdateFromSync
Nick G97e34942016-07-11 14:46:27 -050060
61 \param v The information that Sync has acquired.
Nick G97e34942016-07-11 14:46:27 -050062 */
akmhoque53353462014-04-22 08:43:45 -050063 void
Ashlesh Gawande7600c902017-06-21 13:28:35 -050064 onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& v);
akmhoque53353462014-04-22 08:43:45 -050065
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050066 /*! \brief Wrapper function to call publishSyncUpdate with correct LSA type
akmhoque53353462014-04-22 08:43:45 -050067
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050068 \param type The LSA type constant
69 \param seqNo The latest seqNo known to lsdb
70 */
akmhoque53353462014-04-22 08:43:45 -050071 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050072 publishRoutingUpdate(const ndn::Name& type, const uint64_t& seqNo);
akmhoque53353462014-04-22 08:43:45 -050073
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050074 /*! \brief Creates ChronoSync socket and register additional sync nodes (user prefixes)
75
76 \param syncPrefix /localhop/NLSR/sync
77 */
akmhoque53353462014-04-22 08:43:45 -050078 void
Vince Lehman9d097802015-03-16 17:55:59 -050079 createSyncSocket(const ndn::Name& syncPrefix);
akmhoque53353462014-04-22 08:43:45 -050080
Vince Lehman9d097802015-03-16 17:55:59 -050081private:
Vince Lehmanc11cc202015-01-20 11:41:33 -060082 void
83 buildUpdatePrefix();
84
akmhoque53353462014-04-22 08:43:45 -050085 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050086 processUpdateFromSync(const ndn::Name& originRouter,
87 const ndn::Name& updateName, const uint64_t& seqNo);
Vince Lehman904c2412014-09-23 19:36:11 -050088
89 bool
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050090 isLsaNew(const ndn::Name& originRouter, const std::string& lsaType,
91 const uint64_t& seqNo);
akmhoque53353462014-04-22 08:43:45 -050092
93 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050094 expressInterestForLsa(const ndn::Name& updateName, const uint64_t& seqNo);
akmhoque53353462014-04-22 08:43:45 -050095
akmhoque53353462014-04-22 08:43:45 -050096 void
akmhoque31d1d4b2014-05-05 22:08:14 -050097 publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050098
99private:
Vince Lehman904c2412014-09-23 19:36:11 -0500100 ndn::Face& m_syncFace;
Ashlesh Gawande415676b2016-12-22 00:26:23 -0600101 std::shared_ptr<chronosync::Socket> m_syncSocket;
akmhoque53353462014-04-22 08:43:45 -0500102 ndn::Name m_syncPrefix;
Vince Lehman904c2412014-09-23 19:36:11 -0500103
Vince Lehmanc11cc202015-01-20 11:41:33 -0600104private:
Vince Lehman904c2412014-09-23 19:36:11 -0500105 Lsdb& m_lsdb;
106 ConfParameter& m_confParam;
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600107
Vince Lehmanc11cc202015-01-20 11:41:33 -0600108PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500109 ndn::Name m_nameLsaUserPrefix;
110 ndn::Name m_adjLsaUserPrefix;
111 ndn::Name m_coorLsaUserPrefix;
Vince Lehman904c2412014-09-23 19:36:11 -0500112
Vince Lehmanc11cc202015-01-20 11:41:33 -0600113private:
Vince Lehman904c2412014-09-23 19:36:11 -0500114 static const std::string NLSR_COMPONENT;
115 static const std::string LSA_COMPONENT;
Vince Lehman904c2412014-09-23 19:36:11 -0500116
akmhoque53353462014-04-22 08:43:45 -0500117};
118
Nick Gordonfad8e252016-08-11 14:21:38 -0500119} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500120
dmcoomes9f936662017-03-02 10:33:09 -0600121#endif // NLSR_SYNC_LOGIC_HANDLER_HPP