blob: 5399ed8e87e677a2fda8b91373ac54f77ecc862b [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
19 * 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
dmcoomes9f936662017-03-02 10:33:09 -060022#ifndef NLSR_NLSR_HPP
23#define NLSR_NLSR_HPP
akmhoque298385a2014-02-13 14:13:09 -060024
akmhoquefdbddb12014-05-02 18:35:19 -050025#include <boost/cstdint.hpp>
26#include <stdexcept>
dmcoomes9f936662017-03-02 10:33:09 -060027#include <boost/throw_exception.hpp>
akmhoquefdbddb12014-05-02 18:35:19 -050028
akmhoquec8a10f72014-04-25 18:42:55 -050029#include <ndn-cxx/face.hpp>
30#include <ndn-cxx/security/key-chain.hpp>
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070031#include <ndn-cxx/security/certificate-cache-ttl.hpp>
akmhoquec8a10f72014-04-25 18:42:55 -050032#include <ndn-cxx/util/scheduler.hpp>
Junxiao Shi3e5120c2016-09-10 16:58:34 +000033#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
34#include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
Nick Gordond1f4f332017-01-20 13:40:57 -060035#include <ndn-cxx/mgmt/dispatcher.hpp>
akmhoque298385a2014-02-13 14:13:09 -060036
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050037#include "adjacency-list.hpp"
Vince Lehman0a7da612014-10-29 14:39:29 -050038#include "common.hpp"
akmhoque53353462014-04-22 08:43:45 -050039#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050040#include "hello-protocol.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050041#include "lsdb.hpp"
42#include "name-prefix-list.hpp"
43#include "sequencing-manager.hpp"
Vince Lehman7b616582014-10-17 16:25:39 -050044#include "test-access-control.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070045#include "validator.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050046#include "communication/sync-logic-handler.hpp"
47#include "publisher/lsdb-dataset-interest-handler.hpp"
48#include "route/fib.hpp"
49#include "route/name-prefix-table.hpp"
50#include "route/routing-table.hpp"
51#include "security/certificate-store.hpp"
52#include "update/prefix-update-processor.hpp"
53#include "utility/name-helper.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070054
akmhoque2bb198e2014-02-28 11:46:27 -060055
akmhoque53353462014-04-22 08:43:45 -050056namespace nlsr {
57
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070058static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
59
akmhoque53353462014-04-22 08:43:45 -050060class Nlsr
61{
akmhoquefdbddb12014-05-02 18:35:19 -050062 class Error : public std::runtime_error
63 {
64 public:
65 explicit
66 Error(const std::string& what)
67 : std::runtime_error(what)
68 {
69 }
70 };
71
akmhoque53353462014-04-22 08:43:45 -050072public:
Laqin Fana4cf4022017-01-03 18:57:35 +000073 Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::Face& face, ndn::KeyChain& keyChain);
akmhoque298385a2014-02-13 14:13:09 -060074
akmhoque53353462014-04-22 08:43:45 -050075 void
76 registrationFailed(const ndn::Name& name);
77
78 void
akmhoque157b0a42014-05-13 00:26:37 -050079 onRegistrationSuccess(const ndn::Name& name);
80
81 void
alvy297f4162015-03-03 17:15:33 -060082 onLocalhostRegistrationSuccess(const ndn::Name& name);
83
84 void
akmhoque31d1d4b2014-05-05 22:08:14 -050085 setInfoInterestFilter();
86
87 void
88 setLsaInterestFilter();
akmhoque53353462014-04-22 08:43:45 -050089
90 void
91 startEventLoop();
92
akmhoque53353462014-04-22 08:43:45 -050093 std::string
akmhoquefdbddb12014-05-02 18:35:19 -050094 getConfFileName() const
Yingdi Yu40cd1c32014-04-17 15:02:17 -070095 {
akmhoque53353462014-04-22 08:43:45 -050096 return m_configFileName;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070097 }
98
akmhoque53353462014-04-22 08:43:45 -050099 void
akmhoquefdbddb12014-05-02 18:35:19 -0500100 setConfFileName(const std::string& fileName)
akmhoque5a44dd42014-03-12 18:11:32 -0500101 {
akmhoque53353462014-04-22 08:43:45 -0500102 m_configFileName = fileName;
103 }
akmhoque5a44dd42014-03-12 18:11:32 -0500104
akmhoque53353462014-04-22 08:43:45 -0500105 bool
106 getIsSetDaemonProcess()
107 {
108 return m_isDaemonProcess;
109 }
akmhoque5a44dd42014-03-12 18:11:32 -0500110
akmhoque53353462014-04-22 08:43:45 -0500111 void
112 setIsDaemonProcess(bool value)
113 {
114 m_isDaemonProcess = value;
115 }
akmhoque5a44dd42014-03-12 18:11:32 -0500116
akmhoque53353462014-04-22 08:43:45 -0500117 ConfParameter&
118 getConfParameter()
119 {
120 return m_confParam;
121 }
akmhoque5a44dd42014-03-12 18:11:32 -0500122
akmhoquec8a10f72014-04-25 18:42:55 -0500123 AdjacencyList&
124 getAdjacencyList()
akmhoque53353462014-04-22 08:43:45 -0500125 {
akmhoquec8a10f72014-04-25 18:42:55 -0500126 return m_adjacencyList;
akmhoque53353462014-04-22 08:43:45 -0500127 }
akmhoque298385a2014-02-13 14:13:09 -0600128
akmhoquec8a10f72014-04-25 18:42:55 -0500129 NamePrefixList&
130 getNamePrefixList()
akmhoque53353462014-04-22 08:43:45 -0500131 {
akmhoquec8a10f72014-04-25 18:42:55 -0500132 return m_namePrefixList;
akmhoque53353462014-04-22 08:43:45 -0500133 }
akmhoque298385a2014-02-13 14:13:09 -0600134
akmhoquefdbddb12014-05-02 18:35:19 -0500135 ndn::Face&
akmhoque53353462014-04-22 08:43:45 -0500136 getNlsrFace()
137 {
138 return m_nlsrFace;
139 }
akmhoque298385a2014-02-13 14:13:09 -0600140
akmhoque53353462014-04-22 08:43:45 -0500141 SequencingManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500142 getSequencingManager()
akmhoque53353462014-04-22 08:43:45 -0500143 {
akmhoquec8a10f72014-04-25 18:42:55 -0500144 return m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500145 }
akmhoque298385a2014-02-13 14:13:09 -0600146
akmhoque53353462014-04-22 08:43:45 -0500147 Lsdb&
148 getLsdb()
149 {
150 return m_nlsrLsdb;
151 }
akmhoque298385a2014-02-13 14:13:09 -0600152
akmhoque53353462014-04-22 08:43:45 -0500153 RoutingTable&
154 getRoutingTable()
155 {
156 return m_routingTable;
157 }
akmhoque298385a2014-02-13 14:13:09 -0600158
akmhoquec8a10f72014-04-25 18:42:55 -0500159 NamePrefixTable&
160 getNamePrefixTable()
akmhoque53353462014-04-22 08:43:45 -0500161 {
akmhoquec8a10f72014-04-25 18:42:55 -0500162 return m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500163 }
akmhoque298385a2014-02-13 14:13:09 -0600164
akmhoque53353462014-04-22 08:43:45 -0500165 Fib&
166 getFib()
167 {
168 return m_fib;
169 }
akmhoque298385a2014-02-13 14:13:09 -0600170
akmhoque53353462014-04-22 08:43:45 -0500171 long int
172 getAdjBuildCount()
173 {
174 return m_adjBuildCount;
175 }
akmhoque298385a2014-02-13 14:13:09 -0600176
akmhoque53353462014-04-22 08:43:45 -0500177 void
178 incrementAdjBuildCount()
179 {
180 m_adjBuildCount++;
181 }
akmhoque298385a2014-02-13 14:13:09 -0600182
akmhoque53353462014-04-22 08:43:45 -0500183 void
akmhoquefdbddb12014-05-02 18:35:19 -0500184 setAdjBuildCount(int64_t abc)
akmhoque53353462014-04-22 08:43:45 -0500185 {
186 m_adjBuildCount = abc;
187 }
akmhoque298385a2014-02-13 14:13:09 -0600188
akmhoque157b0a42014-05-13 00:26:37 -0500189 bool
akmhoque53353462014-04-22 08:43:45 -0500190 getIsBuildAdjLsaSheduled()
191 {
192 return m_isBuildAdjLsaSheduled;
193 }
akmhoque298385a2014-02-13 14:13:09 -0600194
akmhoque53353462014-04-22 08:43:45 -0500195 void
196 setIsBuildAdjLsaSheduled(bool iabls)
197 {
198 m_isBuildAdjLsaSheduled = iabls;
199 }
akmhoque298385a2014-02-13 14:13:09 -0600200
akmhoque53353462014-04-22 08:43:45 -0500201 bool
202 getIsRoutingTableCalculating()
203 {
204 return m_isRoutingTableCalculating;
205 }
akmhoque85d88332014-02-17 21:11:21 -0600206
akmhoque53353462014-04-22 08:43:45 -0500207 void
208 setIsRoutingTableCalculating(bool irtc)
209 {
210 m_isRoutingTableCalculating = irtc;
211 }
akmhoque298385a2014-02-13 14:13:09 -0600212
akmhoque53353462014-04-22 08:43:45 -0500213 bool
214 getIsRouteCalculationScheduled()
215 {
216 return m_isRouteCalculationScheduled;
217 }
akmhoque298385a2014-02-13 14:13:09 -0600218
akmhoque53353462014-04-22 08:43:45 -0500219 void
220 setIsRouteCalculationScheduled(bool ircs)
221 {
222 m_isRouteCalculationScheduled = ircs;
223 }
akmhoque298385a2014-02-13 14:13:09 -0600224
akmhoque53353462014-04-22 08:43:45 -0500225 SyncLogicHandler&
akmhoquec8a10f72014-04-25 18:42:55 -0500226 getSyncLogicHandler()
akmhoque53353462014-04-22 08:43:45 -0500227 {
akmhoquec8a10f72014-04-25 18:42:55 -0500228 return m_syncLogicHandler;
akmhoque53353462014-04-22 08:43:45 -0500229 }
akmhoque2bb198e2014-02-28 11:46:27 -0600230
Muktadir R Chowdhury3ac07282016-06-17 16:30:29 -0500231 LsdbDatasetInterestHandler&
232 getLsdbDatasetHandler()
233 {
234 return m_lsdbDatasetHandler;
235 }
236
akmhoque53353462014-04-22 08:43:45 -0500237 void
238 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600239
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700240 void
akmhoque443ad812014-07-29 10:26:56 -0500241 initializeKey();
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700242
243 void
244 loadValidator(boost::property_tree::ptree section,
245 const std::string& filename)
246 {
247 m_validator.load(section, filename);
248 }
249
250 Validator&
251 getValidator()
252 {
253 return m_validator;
254 }
255
256 void
dmcoomes9f936662017-03-02 10:33:09 -0600257 loadCertToPublish(std::shared_ptr<ndn::IdentityCertificate> certificate)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700258 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500259 m_certStore.insert(certificate);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700260 }
261
dmcoomes9f936662017-03-02 10:33:09 -0600262 std::shared_ptr<const ndn::IdentityCertificate>
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700263 getCertificate(const ndn::Name& certificateNameWithoutVersion)
264 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500265 shared_ptr<const ndn::IdentityCertificate> cert =
266 m_certStore.find(certificateNameWithoutVersion);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700267
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500268 if (cert != nullptr) {
269 return cert;
270 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700271
272 return m_certificateCache->getCertificate(certificateNameWithoutVersion);
273 }
274
275 ndn::KeyChain&
276 getKeyChain()
277 {
278 return m_keyChain;
279 }
280
281 const ndn::Name&
282 getDefaultCertName()
283 {
284 return m_defaultCertName;
285 }
286
alvy297f4162015-03-03 17:15:33 -0600287 update::PrefixUpdateProcessor&
288 getPrefixUpdateProcessor()
289 {
290 return m_prefixUpdateProcessor;
291 }
292
Nick Gordond1f4f332017-01-20 13:40:57 -0600293 ndn::mgmt::Dispatcher&
294 getDispatcher()
295 {
296 return m_dispatcher;
297 }
298
akmhoquee1765152014-06-30 11:32:01 -0500299 void
300 createFace(const std::string& faceUri,
akmhoquee1765152014-06-30 11:32:01 -0500301 const CommandSucceedCallback& onSuccess,
302 const CommandFailCallback& onFailure);
303
304 void
305 destroyFaces();
306
akmhoque157b0a42014-05-13 00:26:37 -0500307 void
akmhoquec04e7272014-07-02 11:00:14 -0500308 setStrategies();
akmhoque157b0a42014-05-13 00:26:37 -0500309
akmhoque0494c252014-07-23 23:46:44 -0500310 void
311 daemonize();
312
Vince Lehman7b616582014-10-17 16:25:39 -0500313 uint32_t
314 getFirstHelloInterval() const
315 {
316 return m_firstHelloInterval;
317 }
318
alvy297f4162015-03-03 17:15:33 -0600319PUBLIC_WITH_TESTS_ELSE_PRIVATE:
320 void
dmcoomes9f936662017-03-02 10:33:09 -0600321 addCertificateToCache(std::shared_ptr<ndn::IdentityCertificate> certificate)
alvy297f4162015-03-03 17:15:33 -0600322 {
323 if (certificate != nullptr) {
324 m_certificateCache->insertCertificate(certificate);
325 }
326 }
327
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500328 security::CertificateStore&
329 getCertificateStore()
330 {
331 return m_certStore;
332 }
333
akmhoque393d4ff2014-07-16 14:27:03 -0500334private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700335 void
336 registerKeyPrefix();
337
338 void
alvy297f4162015-03-03 17:15:33 -0600339 registerLocalhostPrefix();
340
341 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700342 onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
343
344 void
345 onKeyPrefixRegSuccess(const ndn::Name& name);
346
akmhoquee1765152014-06-30 11:32:01 -0500347 void
akmhoquee1765152014-06-30 11:32:01 -0500348 onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
349
350 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000351 onDestroyFaceFailure(const ndn::nfd::ControlResponse& response);
akmhoquee1765152014-06-30 11:32:01 -0500352
353 void
akmhoquec04e7272014-07-02 11:00:14 -0500354 onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
akmhoquee1765152014-06-30 11:32:01 -0500355
Vince Lehman7b616582014-10-17 16:25:39 -0500356 void
357 setFirstHelloInterval(uint32_t interval)
358 {
359 m_firstHelloInterval = interval;
360 }
361
alvy297f4162015-03-03 17:15:33 -0600362public:
363 static const ndn::Name LOCALHOST_PREFIX;
364
akmhoque157b0a42014-05-13 00:26:37 -0500365private:
Vince Lehman904c2412014-09-23 19:36:11 -0500366 ndn::Face& m_nlsrFace;
Vince Lehman7c603292014-09-11 17:48:16 -0500367 ndn::Scheduler& m_scheduler;
Laqin Fana4cf4022017-01-03 18:57:35 +0000368 ndn::KeyChain& m_keyChain;
akmhoque53353462014-04-22 08:43:45 -0500369 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500370 AdjacencyList m_adjacencyList;
371 NamePrefixList m_namePrefixList;
akmhoquec8a10f72014-04-25 18:42:55 -0500372 SequencingManager m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500373 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500374 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500375 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500376 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500377 bool m_isBuildAdjLsaSheduled;
378 bool m_isRouteCalculationScheduled;
379 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500380 RoutingTable m_routingTable;
akmhoque53353462014-04-22 08:43:45 -0500381 Fib m_fib;
akmhoque31d1d4b2014-05-05 22:08:14 -0500382 NamePrefixTable m_namePrefixTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500383 SyncLogicHandler m_syncLogicHandler;
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500384 LsdbDatasetInterestHandler m_lsdbDatasetHandler;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700385
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500386PUBLIC_WITH_TESTS_ELSE_PRIVATE:
387 HelloProtocol m_helloProtocol;
388
Vince Lehman7b616582014-10-17 16:25:39 -0500389private:
dmcoomes9f936662017-03-02 10:33:09 -0600390 std::shared_ptr<ndn::CertificateCacheTtl> m_certificateCache;
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500391 security::CertificateStore m_certStore;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700392 Validator m_validator;
Joao Pereira97473d42015-07-03 16:57:27 -0400393 ndn::security::SigningInfo m_signingInfo;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700394 ndn::Name m_defaultCertName;
alvy297f4162015-03-03 17:15:33 -0600395 update::PrefixUpdateProcessor m_prefixUpdateProcessor;
Nick Gordond1f4f332017-01-20 13:40:57 -0600396 ndn::mgmt::Dispatcher m_dispatcher;
akmhoquee1765152014-06-30 11:32:01 -0500397
akmhoque060d3022014-08-12 13:35:06 -0500398 ndn::nfd::FaceMonitor m_faceMonitor;
Vince Lehman7b616582014-10-17 16:25:39 -0500399
400 uint32_t m_firstHelloInterval;
akmhoque53353462014-04-22 08:43:45 -0500401};
akmhoque298385a2014-02-13 14:13:09 -0600402
Nick Gordonfad8e252016-08-11 14:21:38 -0500403} // namespace nlsr
akmhoqueb1710aa2014-02-19 17:13:36 -0600404
dmcoomes9f936662017-03-02 10:33:09 -0600405#endif // NLSR_NLSR_HPP