blob: 7df3671da5ea39d870255af71d5b83f530e6f207 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehmanc2e51f62015-01-20 15:03:11 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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>
27#include <nsync/sync-socket.h>
28
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>
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;
41class SequencingManager;
42class SyncUpdate;
43
akmhoque53353462014-04-22 08:43:45 -050044class SyncLogicHandler
45{
46public:
Vince Lehman9d097802015-03-16 17:55:59 -050047 class Error : public std::runtime_error
48 {
49 public:
50 explicit
51 Error(const std::string& what)
52 : std::runtime_error(what)
53 {
54 }
55 };
akmhoque53353462014-04-22 08:43:45 -050056
Vince Lehman9d097802015-03-16 17:55:59 -050057 SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf, SequencingManager& seqManager);
akmhoque53353462014-04-22 08:43:45 -050058
59 void
Vince Lehman904c2412014-09-23 19:36:11 -050060 onNsyncUpdate(const std::vector<Sync::MissingDataInfo>& v, Sync::SyncSocket* socket);
akmhoque53353462014-04-22 08:43:45 -050061
62 void
Vince Lehman904c2412014-09-23 19:36:11 -050063 onNsyncRemoval(const std::string& prefix);
akmhoque53353462014-04-22 08:43:45 -050064
65 void
Vince Lehman0bcf9a32014-12-10 11:24:45 -060066 publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -050067
68 void
Vince Lehman9d097802015-03-16 17:55:59 -050069 createSyncSocket(const ndn::Name& syncPrefix);
akmhoque53353462014-04-22 08:43:45 -050070
Vince Lehman9d097802015-03-16 17:55:59 -050071private:
Vince Lehmanc11cc202015-01-20 11:41:33 -060072 void
73 buildUpdatePrefix();
74
akmhoque53353462014-04-22 08:43:45 -050075 void
Vince Lehman904c2412014-09-23 19:36:11 -050076 processUpdateFromSync(const SyncUpdate& updateName);
77
78 bool
79 isLsaNew(const ndn::Name& originRouter, const std::string& lsaType, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050080
81 void
Vince Lehman904c2412014-09-23 19:36:11 -050082 expressInterestForLsa(const SyncUpdate& updateName, std::string lsaType, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050083
akmhoque53353462014-04-22 08:43:45 -050084 void
akmhoque31d1d4b2014-05-05 22:08:14 -050085 publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050086
87private:
88 ndn::shared_ptr<ndn::ValidatorNull> m_validator;
Vince Lehman904c2412014-09-23 19:36:11 -050089 ndn::Face& m_syncFace;
akmhoque53353462014-04-22 08:43:45 -050090 ndn::shared_ptr<Sync::SyncSocket> m_syncSocket;
91 ndn::Name m_syncPrefix;
Vince Lehman904c2412014-09-23 19:36:11 -050092
Vince Lehmanc11cc202015-01-20 11:41:33 -060093private:
Vince Lehman904c2412014-09-23 19:36:11 -050094 Lsdb& m_lsdb;
95 ConfParameter& m_confParam;
Vince Lehman0bcf9a32014-12-10 11:24:45 -060096 const SequencingManager& m_sequencingManager;
97
Vince Lehmanc11cc202015-01-20 11:41:33 -060098PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Vince Lehman0bcf9a32014-12-10 11:24:45 -060099 ndn::Name m_updatePrefix;
Vince Lehman904c2412014-09-23 19:36:11 -0500100
Vince Lehmanc11cc202015-01-20 11:41:33 -0600101private:
Vince Lehman904c2412014-09-23 19:36:11 -0500102 static const std::string NLSR_COMPONENT;
103 static const std::string LSA_COMPONENT;
Vince Lehman904c2412014-09-23 19:36:11 -0500104
akmhoque53353462014-04-22 08:43:45 -0500105};
106
107} //namespace nlsr
108
akmhoquefdbddb12014-05-02 18:35:19 -0500109#endif //NLSR_SYNC_LOGIC_HANDLER_HPP