blob: c8e143e6d5576fa42d3d1db21e4a3ae95443614d [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>
26#include <ndn-cxx/security/validator-null.hpp>
Ashlesh Gawande415676b2016-12-22 00:26:23 -060027#include <ChronoSync/socket.hpp>
Vince Lehman904c2412014-09-23 19:36:11 -050028
akmhoque53353462014-04-22 08:43:45 -050029#include <iostream>
Vince Lehman904c2412014-09-23 19:36:11 -050030#include <unistd.h>
akmhoquefdbddb12014-05-02 18:35:19 -050031#include <boost/cstdint.hpp>
dmcoomes9f936662017-03-02 10:33:09 -060032#include <boost/throw_exception.hpp>
akmhoque53353462014-04-22 08:43:45 -050033
Vince Lehmanc11cc202015-01-20 11:41:33 -060034#include "test-access-control.hpp"
35
akmhoque53353462014-04-22 08:43:45 -050036class InterestManager;
akmhoque53353462014-04-22 08:43:45 -050037
38namespace nlsr {
39
Vince Lehman904c2412014-09-23 19:36:11 -050040class ConfParameter;
41class Lsdb;
42class SequencingManager;
43class SyncUpdate;
44
akmhoque53353462014-04-22 08:43:45 -050045class SyncLogicHandler
46{
47public:
Vince Lehman9d097802015-03-16 17:55:59 -050048 class Error : public std::runtime_error
49 {
50 public:
51 explicit
52 Error(const std::string& what)
53 : std::runtime_error(what)
54 {
55 }
56 };
akmhoque53353462014-04-22 08:43:45 -050057
Vince Lehman9d097802015-03-16 17:55:59 -050058 SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf, SequencingManager& seqManager);
akmhoque53353462014-04-22 08:43:45 -050059
Nick G97e34942016-07-11 14:46:27 -050060 /*! \brief Simple wrapper function to handle updates from Sync.
61
62 \param v The information that Sync has acquired.
Nick G97e34942016-07-11 14:46:27 -050063 */
akmhoque53353462014-04-22 08:43:45 -050064 void
Ashlesh Gawande415676b2016-12-22 00:26:23 -060065 onNsyncUpdate(const std::vector<chronosync::MissingDataInfo>& v);
akmhoque53353462014-04-22 08:43:45 -050066
67 void
Vince Lehman904c2412014-09-23 19:36:11 -050068 onNsyncRemoval(const std::string& prefix);
akmhoque53353462014-04-22 08:43:45 -050069
70 void
Vince Lehman0bcf9a32014-12-10 11:24:45 -060071 publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -050072
73 void
Vince Lehman9d097802015-03-16 17:55:59 -050074 createSyncSocket(const ndn::Name& syncPrefix);
akmhoque53353462014-04-22 08:43:45 -050075
Vince Lehman9d097802015-03-16 17:55:59 -050076private:
Vince Lehmanc11cc202015-01-20 11:41:33 -060077 void
78 buildUpdatePrefix();
79
akmhoque53353462014-04-22 08:43:45 -050080 void
Vince Lehman904c2412014-09-23 19:36:11 -050081 processUpdateFromSync(const SyncUpdate& updateName);
82
83 bool
84 isLsaNew(const ndn::Name& originRouter, const std::string& lsaType, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050085
86 void
Vince Lehman904c2412014-09-23 19:36:11 -050087 expressInterestForLsa(const SyncUpdate& updateName, std::string lsaType, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050088
akmhoque53353462014-04-22 08:43:45 -050089 void
akmhoque31d1d4b2014-05-05 22:08:14 -050090 publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050091
92private:
dmcoomes9f936662017-03-02 10:33:09 -060093 std::shared_ptr<ndn::ValidatorNull> m_validator;
Vince Lehman904c2412014-09-23 19:36:11 -050094 ndn::Face& m_syncFace;
Ashlesh Gawande415676b2016-12-22 00:26:23 -060095 std::shared_ptr<chronosync::Socket> m_syncSocket;
akmhoque53353462014-04-22 08:43:45 -050096 ndn::Name m_syncPrefix;
Vince Lehman904c2412014-09-23 19:36:11 -050097
Vince Lehmanc11cc202015-01-20 11:41:33 -060098private:
Vince Lehman904c2412014-09-23 19:36:11 -050099 Lsdb& m_lsdb;
100 ConfParameter& m_confParam;
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600101 const SequencingManager& m_sequencingManager;
102
Vince Lehmanc11cc202015-01-20 11:41:33 -0600103PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600104 ndn::Name m_updatePrefix;
Vince Lehman904c2412014-09-23 19:36:11 -0500105
Vince Lehmanc11cc202015-01-20 11:41:33 -0600106private:
Vince Lehman904c2412014-09-23 19:36:11 -0500107 static const std::string NLSR_COMPONENT;
108 static const std::string LSA_COMPONENT;
Vince Lehman904c2412014-09-23 19:36:11 -0500109
akmhoque53353462014-04-22 08:43:45 -0500110};
111
Nick Gordonfad8e252016-08-11 14:21:38 -0500112} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500113
dmcoomes9f936662017-03-02 10:33:09 -0600114#endif // NLSR_SYNC_LOGIC_HANDLER_HPP