blob: eb9132d50877bf55cff235b3cc81b505d9d6dcb3 [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"
Nick Gordon4d2c6c02017-01-20 13:18:46 -060053#include "update/nfd-rib-command-processor.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050054#include "utility/name-helper.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070055
akmhoque2bb198e2014-02-28 11:46:27 -060056
akmhoque53353462014-04-22 08:43:45 -050057namespace nlsr {
58
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070059static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
60
akmhoque53353462014-04-22 08:43:45 -050061class Nlsr
62{
akmhoquefdbddb12014-05-02 18:35:19 -050063 class Error : public std::runtime_error
64 {
65 public:
66 explicit
67 Error(const std::string& what)
68 : std::runtime_error(what)
69 {
70 }
71 };
72
akmhoque53353462014-04-22 08:43:45 -050073public:
Laqin Fana4cf4022017-01-03 18:57:35 +000074 Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::Face& face, ndn::KeyChain& keyChain);
akmhoque298385a2014-02-13 14:13:09 -060075
akmhoque53353462014-04-22 08:43:45 -050076 void
77 registrationFailed(const ndn::Name& name);
78
79 void
akmhoque157b0a42014-05-13 00:26:37 -050080 onRegistrationSuccess(const ndn::Name& name);
81
82 void
alvy297f4162015-03-03 17:15:33 -060083 onLocalhostRegistrationSuccess(const ndn::Name& name);
84
85 void
akmhoque31d1d4b2014-05-05 22:08:14 -050086 setInfoInterestFilter();
87
88 void
89 setLsaInterestFilter();
akmhoque53353462014-04-22 08:43:45 -050090
91 void
92 startEventLoop();
93
akmhoque53353462014-04-22 08:43:45 -050094 std::string
akmhoquefdbddb12014-05-02 18:35:19 -050095 getConfFileName() const
Yingdi Yu40cd1c32014-04-17 15:02:17 -070096 {
akmhoque53353462014-04-22 08:43:45 -050097 return m_configFileName;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070098 }
99
akmhoque53353462014-04-22 08:43:45 -0500100 void
akmhoquefdbddb12014-05-02 18:35:19 -0500101 setConfFileName(const std::string& fileName)
akmhoque5a44dd42014-03-12 18:11:32 -0500102 {
akmhoque53353462014-04-22 08:43:45 -0500103 m_configFileName = fileName;
104 }
akmhoque5a44dd42014-03-12 18:11:32 -0500105
akmhoque53353462014-04-22 08:43:45 -0500106 bool
107 getIsSetDaemonProcess()
108 {
109 return m_isDaemonProcess;
110 }
akmhoque5a44dd42014-03-12 18:11:32 -0500111
akmhoque53353462014-04-22 08:43:45 -0500112 void
113 setIsDaemonProcess(bool value)
114 {
115 m_isDaemonProcess = value;
116 }
akmhoque5a44dd42014-03-12 18:11:32 -0500117
akmhoque53353462014-04-22 08:43:45 -0500118 ConfParameter&
119 getConfParameter()
120 {
121 return m_confParam;
122 }
akmhoque5a44dd42014-03-12 18:11:32 -0500123
akmhoquec8a10f72014-04-25 18:42:55 -0500124 AdjacencyList&
125 getAdjacencyList()
akmhoque53353462014-04-22 08:43:45 -0500126 {
akmhoquec8a10f72014-04-25 18:42:55 -0500127 return m_adjacencyList;
akmhoque53353462014-04-22 08:43:45 -0500128 }
akmhoque298385a2014-02-13 14:13:09 -0600129
akmhoquec8a10f72014-04-25 18:42:55 -0500130 NamePrefixList&
131 getNamePrefixList()
akmhoque53353462014-04-22 08:43:45 -0500132 {
akmhoquec8a10f72014-04-25 18:42:55 -0500133 return m_namePrefixList;
akmhoque53353462014-04-22 08:43:45 -0500134 }
akmhoque298385a2014-02-13 14:13:09 -0600135
akmhoquefdbddb12014-05-02 18:35:19 -0500136 ndn::Face&
akmhoque53353462014-04-22 08:43:45 -0500137 getNlsrFace()
138 {
139 return m_nlsrFace;
140 }
akmhoque298385a2014-02-13 14:13:09 -0600141
akmhoque53353462014-04-22 08:43:45 -0500142 SequencingManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500143 getSequencingManager()
akmhoque53353462014-04-22 08:43:45 -0500144 {
akmhoquec8a10f72014-04-25 18:42:55 -0500145 return m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500146 }
akmhoque298385a2014-02-13 14:13:09 -0600147
akmhoque53353462014-04-22 08:43:45 -0500148 Lsdb&
149 getLsdb()
150 {
151 return m_nlsrLsdb;
152 }
akmhoque298385a2014-02-13 14:13:09 -0600153
akmhoque53353462014-04-22 08:43:45 -0500154 RoutingTable&
155 getRoutingTable()
156 {
157 return m_routingTable;
158 }
akmhoque298385a2014-02-13 14:13:09 -0600159
akmhoquec8a10f72014-04-25 18:42:55 -0500160 NamePrefixTable&
161 getNamePrefixTable()
akmhoque53353462014-04-22 08:43:45 -0500162 {
akmhoquec8a10f72014-04-25 18:42:55 -0500163 return m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500164 }
akmhoque298385a2014-02-13 14:13:09 -0600165
akmhoque53353462014-04-22 08:43:45 -0500166 Fib&
167 getFib()
168 {
169 return m_fib;
170 }
akmhoque298385a2014-02-13 14:13:09 -0600171
akmhoque53353462014-04-22 08:43:45 -0500172 long int
173 getAdjBuildCount()
174 {
175 return m_adjBuildCount;
176 }
akmhoque298385a2014-02-13 14:13:09 -0600177
akmhoque53353462014-04-22 08:43:45 -0500178 void
179 incrementAdjBuildCount()
180 {
181 m_adjBuildCount++;
182 }
akmhoque298385a2014-02-13 14:13:09 -0600183
akmhoque53353462014-04-22 08:43:45 -0500184 void
akmhoquefdbddb12014-05-02 18:35:19 -0500185 setAdjBuildCount(int64_t abc)
akmhoque53353462014-04-22 08:43:45 -0500186 {
187 m_adjBuildCount = abc;
188 }
akmhoque298385a2014-02-13 14:13:09 -0600189
akmhoque157b0a42014-05-13 00:26:37 -0500190 bool
akmhoque53353462014-04-22 08:43:45 -0500191 getIsBuildAdjLsaSheduled()
192 {
193 return m_isBuildAdjLsaSheduled;
194 }
akmhoque298385a2014-02-13 14:13:09 -0600195
akmhoque53353462014-04-22 08:43:45 -0500196 void
197 setIsBuildAdjLsaSheduled(bool iabls)
198 {
199 m_isBuildAdjLsaSheduled = iabls;
200 }
akmhoque298385a2014-02-13 14:13:09 -0600201
akmhoque53353462014-04-22 08:43:45 -0500202 bool
203 getIsRoutingTableCalculating()
204 {
205 return m_isRoutingTableCalculating;
206 }
akmhoque85d88332014-02-17 21:11:21 -0600207
akmhoque53353462014-04-22 08:43:45 -0500208 void
209 setIsRoutingTableCalculating(bool irtc)
210 {
211 m_isRoutingTableCalculating = irtc;
212 }
akmhoque298385a2014-02-13 14:13:09 -0600213
akmhoque53353462014-04-22 08:43:45 -0500214 bool
215 getIsRouteCalculationScheduled()
216 {
217 return m_isRouteCalculationScheduled;
218 }
akmhoque298385a2014-02-13 14:13:09 -0600219
akmhoque53353462014-04-22 08:43:45 -0500220 void
221 setIsRouteCalculationScheduled(bool ircs)
222 {
223 m_isRouteCalculationScheduled = ircs;
224 }
akmhoque298385a2014-02-13 14:13:09 -0600225
akmhoque53353462014-04-22 08:43:45 -0500226 SyncLogicHandler&
akmhoquec8a10f72014-04-25 18:42:55 -0500227 getSyncLogicHandler()
akmhoque53353462014-04-22 08:43:45 -0500228 {
akmhoquec8a10f72014-04-25 18:42:55 -0500229 return m_syncLogicHandler;
akmhoque53353462014-04-22 08:43:45 -0500230 }
akmhoque2bb198e2014-02-28 11:46:27 -0600231
Muktadir R Chowdhury3ac07282016-06-17 16:30:29 -0500232 LsdbDatasetInterestHandler&
233 getLsdbDatasetHandler()
234 {
235 return m_lsdbDatasetHandler;
236 }
237
akmhoque53353462014-04-22 08:43:45 -0500238 void
239 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600240
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700241 void
akmhoque443ad812014-07-29 10:26:56 -0500242 initializeKey();
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700243
244 void
245 loadValidator(boost::property_tree::ptree section,
246 const std::string& filename)
247 {
248 m_validator.load(section, filename);
249 }
250
251 Validator&
252 getValidator()
253 {
254 return m_validator;
255 }
256
257 void
dmcoomes9f936662017-03-02 10:33:09 -0600258 loadCertToPublish(std::shared_ptr<ndn::IdentityCertificate> certificate)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700259 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500260 m_certStore.insert(certificate);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700261 }
262
dmcoomes9f936662017-03-02 10:33:09 -0600263 std::shared_ptr<const ndn::IdentityCertificate>
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700264 getCertificate(const ndn::Name& certificateNameWithoutVersion)
265 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500266 shared_ptr<const ndn::IdentityCertificate> cert =
267 m_certStore.find(certificateNameWithoutVersion);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700268
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500269 if (cert != nullptr) {
270 return cert;
271 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700272
273 return m_certificateCache->getCertificate(certificateNameWithoutVersion);
274 }
275
276 ndn::KeyChain&
277 getKeyChain()
278 {
279 return m_keyChain;
280 }
281
282 const ndn::Name&
283 getDefaultCertName()
284 {
285 return m_defaultCertName;
286 }
287
alvy297f4162015-03-03 17:15:33 -0600288 update::PrefixUpdateProcessor&
289 getPrefixUpdateProcessor()
290 {
291 return m_prefixUpdateProcessor;
292 }
293
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600294 update::NfdRibCommandProcessor&
295 getNfdRibCommandProcessor()
296 {
297 return m_nfdRibCommandProcessor;
298 }
299
Nick Gordond1f4f332017-01-20 13:40:57 -0600300 ndn::mgmt::Dispatcher&
301 getDispatcher()
302 {
303 return m_dispatcher;
304 }
305
akmhoquee1765152014-06-30 11:32:01 -0500306 void
307 createFace(const std::string& faceUri,
akmhoquee1765152014-06-30 11:32:01 -0500308 const CommandSucceedCallback& onSuccess,
309 const CommandFailCallback& onFailure);
310
311 void
312 destroyFaces();
313
akmhoque157b0a42014-05-13 00:26:37 -0500314 void
akmhoquec04e7272014-07-02 11:00:14 -0500315 setStrategies();
akmhoque157b0a42014-05-13 00:26:37 -0500316
akmhoque0494c252014-07-23 23:46:44 -0500317 void
318 daemonize();
319
Vince Lehman7b616582014-10-17 16:25:39 -0500320 uint32_t
321 getFirstHelloInterval() const
322 {
323 return m_firstHelloInterval;
324 }
325
alvy297f4162015-03-03 17:15:33 -0600326PUBLIC_WITH_TESTS_ELSE_PRIVATE:
327 void
dmcoomes9f936662017-03-02 10:33:09 -0600328 addCertificateToCache(std::shared_ptr<ndn::IdentityCertificate> certificate)
alvy297f4162015-03-03 17:15:33 -0600329 {
330 if (certificate != nullptr) {
331 m_certificateCache->insertCertificate(certificate);
332 }
333 }
334
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500335 security::CertificateStore&
336 getCertificateStore()
337 {
338 return m_certStore;
339 }
340
akmhoque393d4ff2014-07-16 14:27:03 -0500341private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700342 void
343 registerKeyPrefix();
344
345 void
alvy297f4162015-03-03 17:15:33 -0600346 registerLocalhostPrefix();
347
348 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700349 onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
350
351 void
352 onKeyPrefixRegSuccess(const ndn::Name& name);
353
akmhoquee1765152014-06-30 11:32:01 -0500354 void
akmhoquee1765152014-06-30 11:32:01 -0500355 onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
356
357 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000358 onDestroyFaceFailure(const ndn::nfd::ControlResponse& response);
akmhoquee1765152014-06-30 11:32:01 -0500359
360 void
akmhoquec04e7272014-07-02 11:00:14 -0500361 onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
akmhoquee1765152014-06-30 11:32:01 -0500362
Vince Lehman7b616582014-10-17 16:25:39 -0500363 void
364 setFirstHelloInterval(uint32_t interval)
365 {
366 m_firstHelloInterval = interval;
367 }
368
alvy297f4162015-03-03 17:15:33 -0600369public:
370 static const ndn::Name LOCALHOST_PREFIX;
371
akmhoque157b0a42014-05-13 00:26:37 -0500372private:
Vince Lehman904c2412014-09-23 19:36:11 -0500373 ndn::Face& m_nlsrFace;
Vince Lehman7c603292014-09-11 17:48:16 -0500374 ndn::Scheduler& m_scheduler;
Laqin Fana4cf4022017-01-03 18:57:35 +0000375 ndn::KeyChain& m_keyChain;
akmhoque53353462014-04-22 08:43:45 -0500376 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500377 AdjacencyList m_adjacencyList;
378 NamePrefixList m_namePrefixList;
akmhoquec8a10f72014-04-25 18:42:55 -0500379 SequencingManager m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500380 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500381 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500382 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500383 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500384 bool m_isBuildAdjLsaSheduled;
385 bool m_isRouteCalculationScheduled;
386 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500387 RoutingTable m_routingTable;
akmhoque53353462014-04-22 08:43:45 -0500388 Fib m_fib;
akmhoque31d1d4b2014-05-05 22:08:14 -0500389 NamePrefixTable m_namePrefixTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500390 SyncLogicHandler m_syncLogicHandler;
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500391 LsdbDatasetInterestHandler m_lsdbDatasetHandler;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700392
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500393PUBLIC_WITH_TESTS_ELSE_PRIVATE:
394 HelloProtocol m_helloProtocol;
395
Vince Lehman7b616582014-10-17 16:25:39 -0500396private:
dmcoomes9f936662017-03-02 10:33:09 -0600397 std::shared_ptr<ndn::CertificateCacheTtl> m_certificateCache;
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500398 security::CertificateStore m_certStore;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700399 Validator m_validator;
Joao Pereira97473d42015-07-03 16:57:27 -0400400 ndn::security::SigningInfo m_signingInfo;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700401 ndn::Name m_defaultCertName;
alvy297f4162015-03-03 17:15:33 -0600402 update::PrefixUpdateProcessor m_prefixUpdateProcessor;
Nick Gordond1f4f332017-01-20 13:40:57 -0600403 ndn::mgmt::Dispatcher m_dispatcher;
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600404 update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
akmhoquee1765152014-06-30 11:32:01 -0500405
akmhoque060d3022014-08-12 13:35:06 -0500406 ndn::nfd::FaceMonitor m_faceMonitor;
Vince Lehman7b616582014-10-17 16:25:39 -0500407
408 uint32_t m_firstHelloInterval;
akmhoque53353462014-04-22 08:43:45 -0500409};
akmhoque298385a2014-02-13 14:13:09 -0600410
Nick Gordonfad8e252016-08-11 14:21:38 -0500411} // namespace nlsr
akmhoqueb1710aa2014-02-19 17:13:36 -0600412
dmcoomes9f936662017-03-02 10:33:09 -0600413#endif // NLSR_NLSR_HPP