blob: 9eff222ce44c74e494432aaf9b7c9639375bee77 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Muktadir R Chowdhury800833b2016-07-29 13:43:59 -05003 * Copyright (c) 2014-2016, 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
akmhoque298385a2014-02-13 14:13:09 -060022#ifndef NLSR_HPP
23#define NLSR_HPP
24
akmhoquefdbddb12014-05-02 18:35:19 -050025#include <boost/cstdint.hpp>
26#include <stdexcept>
27
akmhoquec8a10f72014-04-25 18:42:55 -050028#include <ndn-cxx/face.hpp>
29#include <ndn-cxx/security/key-chain.hpp>
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070030#include <ndn-cxx/security/certificate-cache-ttl.hpp>
akmhoquec8a10f72014-04-25 18:42:55 -050031#include <ndn-cxx/util/scheduler.hpp>
Junxiao Shi3e5120c2016-09-10 16:58:34 +000032#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
33#include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
akmhoque298385a2014-02-13 14:13:09 -060034
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050035#include "adjacency-list.hpp"
Vince Lehman0a7da612014-10-29 14:39:29 -050036#include "common.hpp"
akmhoque53353462014-04-22 08:43:45 -050037#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050038#include "hello-protocol.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050039#include "lsdb.hpp"
40#include "name-prefix-list.hpp"
41#include "sequencing-manager.hpp"
Vince Lehman7b616582014-10-17 16:25:39 -050042#include "test-access-control.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070043#include "validator.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050044#include "communication/sync-logic-handler.hpp"
45#include "publisher/lsdb-dataset-interest-handler.hpp"
46#include "route/fib.hpp"
47#include "route/name-prefix-table.hpp"
48#include "route/routing-table.hpp"
49#include "security/certificate-store.hpp"
50#include "update/prefix-update-processor.hpp"
51#include "utility/name-helper.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070052
akmhoque2bb198e2014-02-28 11:46:27 -060053
akmhoque53353462014-04-22 08:43:45 -050054namespace nlsr {
55
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070056static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
57
akmhoque53353462014-04-22 08:43:45 -050058class Nlsr
59{
akmhoquefdbddb12014-05-02 18:35:19 -050060 class Error : public std::runtime_error
61 {
62 public:
63 explicit
64 Error(const std::string& what)
65 : std::runtime_error(what)
66 {
67 }
68 };
69
akmhoque53353462014-04-22 08:43:45 -050070public:
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050071 Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::Face& face);
akmhoque298385a2014-02-13 14:13:09 -060072
akmhoque53353462014-04-22 08:43:45 -050073 void
74 registrationFailed(const ndn::Name& name);
75
76 void
akmhoque157b0a42014-05-13 00:26:37 -050077 onRegistrationSuccess(const ndn::Name& name);
78
79 void
alvy297f4162015-03-03 17:15:33 -060080 onLocalhostRegistrationSuccess(const ndn::Name& name);
81
82 void
akmhoque31d1d4b2014-05-05 22:08:14 -050083 setInfoInterestFilter();
84
85 void
86 setLsaInterestFilter();
akmhoque53353462014-04-22 08:43:45 -050087
88 void
89 startEventLoop();
90
akmhoque53353462014-04-22 08:43:45 -050091 std::string
akmhoquefdbddb12014-05-02 18:35:19 -050092 getConfFileName() const
Yingdi Yu40cd1c32014-04-17 15:02:17 -070093 {
akmhoque53353462014-04-22 08:43:45 -050094 return m_configFileName;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070095 }
96
akmhoque53353462014-04-22 08:43:45 -050097 void
akmhoquefdbddb12014-05-02 18:35:19 -050098 setConfFileName(const std::string& fileName)
akmhoque5a44dd42014-03-12 18:11:32 -050099 {
akmhoque53353462014-04-22 08:43:45 -0500100 m_configFileName = fileName;
101 }
akmhoque5a44dd42014-03-12 18:11:32 -0500102
akmhoque53353462014-04-22 08:43:45 -0500103 bool
104 getIsSetDaemonProcess()
105 {
106 return m_isDaemonProcess;
107 }
akmhoque5a44dd42014-03-12 18:11:32 -0500108
akmhoque53353462014-04-22 08:43:45 -0500109 void
110 setIsDaemonProcess(bool value)
111 {
112 m_isDaemonProcess = value;
113 }
akmhoque5a44dd42014-03-12 18:11:32 -0500114
akmhoque53353462014-04-22 08:43:45 -0500115 ConfParameter&
116 getConfParameter()
117 {
118 return m_confParam;
119 }
akmhoque5a44dd42014-03-12 18:11:32 -0500120
akmhoquec8a10f72014-04-25 18:42:55 -0500121 AdjacencyList&
122 getAdjacencyList()
akmhoque53353462014-04-22 08:43:45 -0500123 {
akmhoquec8a10f72014-04-25 18:42:55 -0500124 return m_adjacencyList;
akmhoque53353462014-04-22 08:43:45 -0500125 }
akmhoque298385a2014-02-13 14:13:09 -0600126
akmhoquec8a10f72014-04-25 18:42:55 -0500127 NamePrefixList&
128 getNamePrefixList()
akmhoque53353462014-04-22 08:43:45 -0500129 {
akmhoquec8a10f72014-04-25 18:42:55 -0500130 return m_namePrefixList;
akmhoque53353462014-04-22 08:43:45 -0500131 }
akmhoque298385a2014-02-13 14:13:09 -0600132
akmhoquefdbddb12014-05-02 18:35:19 -0500133 ndn::Face&
akmhoque53353462014-04-22 08:43:45 -0500134 getNlsrFace()
135 {
136 return m_nlsrFace;
137 }
akmhoque298385a2014-02-13 14:13:09 -0600138
akmhoque53353462014-04-22 08:43:45 -0500139 SequencingManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500140 getSequencingManager()
akmhoque53353462014-04-22 08:43:45 -0500141 {
akmhoquec8a10f72014-04-25 18:42:55 -0500142 return m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500143 }
akmhoque298385a2014-02-13 14:13:09 -0600144
akmhoque53353462014-04-22 08:43:45 -0500145 Lsdb&
146 getLsdb()
147 {
148 return m_nlsrLsdb;
149 }
akmhoque298385a2014-02-13 14:13:09 -0600150
akmhoque53353462014-04-22 08:43:45 -0500151 RoutingTable&
152 getRoutingTable()
153 {
154 return m_routingTable;
155 }
akmhoque298385a2014-02-13 14:13:09 -0600156
akmhoquec8a10f72014-04-25 18:42:55 -0500157 NamePrefixTable&
158 getNamePrefixTable()
akmhoque53353462014-04-22 08:43:45 -0500159 {
akmhoquec8a10f72014-04-25 18:42:55 -0500160 return m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500161 }
akmhoque298385a2014-02-13 14:13:09 -0600162
akmhoque53353462014-04-22 08:43:45 -0500163 Fib&
164 getFib()
165 {
166 return m_fib;
167 }
akmhoque298385a2014-02-13 14:13:09 -0600168
akmhoque53353462014-04-22 08:43:45 -0500169 long int
170 getAdjBuildCount()
171 {
172 return m_adjBuildCount;
173 }
akmhoque298385a2014-02-13 14:13:09 -0600174
akmhoque53353462014-04-22 08:43:45 -0500175 void
176 incrementAdjBuildCount()
177 {
178 m_adjBuildCount++;
179 }
akmhoque298385a2014-02-13 14:13:09 -0600180
akmhoque53353462014-04-22 08:43:45 -0500181 void
akmhoquefdbddb12014-05-02 18:35:19 -0500182 setAdjBuildCount(int64_t abc)
akmhoque53353462014-04-22 08:43:45 -0500183 {
184 m_adjBuildCount = abc;
185 }
akmhoque298385a2014-02-13 14:13:09 -0600186
akmhoque157b0a42014-05-13 00:26:37 -0500187 bool
akmhoque53353462014-04-22 08:43:45 -0500188 getIsBuildAdjLsaSheduled()
189 {
190 return m_isBuildAdjLsaSheduled;
191 }
akmhoque298385a2014-02-13 14:13:09 -0600192
akmhoque53353462014-04-22 08:43:45 -0500193 void
194 setIsBuildAdjLsaSheduled(bool iabls)
195 {
196 m_isBuildAdjLsaSheduled = iabls;
197 }
akmhoque298385a2014-02-13 14:13:09 -0600198
akmhoque53353462014-04-22 08:43:45 -0500199 bool
200 getIsRoutingTableCalculating()
201 {
202 return m_isRoutingTableCalculating;
203 }
akmhoque85d88332014-02-17 21:11:21 -0600204
akmhoque53353462014-04-22 08:43:45 -0500205 void
206 setIsRoutingTableCalculating(bool irtc)
207 {
208 m_isRoutingTableCalculating = irtc;
209 }
akmhoque298385a2014-02-13 14:13:09 -0600210
akmhoque53353462014-04-22 08:43:45 -0500211 bool
212 getIsRouteCalculationScheduled()
213 {
214 return m_isRouteCalculationScheduled;
215 }
akmhoque298385a2014-02-13 14:13:09 -0600216
akmhoque53353462014-04-22 08:43:45 -0500217 void
218 setIsRouteCalculationScheduled(bool ircs)
219 {
220 m_isRouteCalculationScheduled = ircs;
221 }
akmhoque298385a2014-02-13 14:13:09 -0600222
akmhoque53353462014-04-22 08:43:45 -0500223 SyncLogicHandler&
akmhoquec8a10f72014-04-25 18:42:55 -0500224 getSyncLogicHandler()
akmhoque53353462014-04-22 08:43:45 -0500225 {
akmhoquec8a10f72014-04-25 18:42:55 -0500226 return m_syncLogicHandler;
akmhoque53353462014-04-22 08:43:45 -0500227 }
akmhoque2bb198e2014-02-28 11:46:27 -0600228
Muktadir R Chowdhury3ac07282016-06-17 16:30:29 -0500229 LsdbDatasetInterestHandler&
230 getLsdbDatasetHandler()
231 {
232 return m_lsdbDatasetHandler;
233 }
234
akmhoque53353462014-04-22 08:43:45 -0500235 void
236 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600237
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700238 void
akmhoque443ad812014-07-29 10:26:56 -0500239 initializeKey();
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700240
241 void
242 loadValidator(boost::property_tree::ptree section,
243 const std::string& filename)
244 {
245 m_validator.load(section, filename);
246 }
247
248 Validator&
249 getValidator()
250 {
251 return m_validator;
252 }
253
254 void
255 loadCertToPublish(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
256 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500257 m_certStore.insert(certificate);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700258 }
259
260 ndn::shared_ptr<const ndn::IdentityCertificate>
261 getCertificate(const ndn::Name& certificateNameWithoutVersion)
262 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500263 shared_ptr<const ndn::IdentityCertificate> cert =
264 m_certStore.find(certificateNameWithoutVersion);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700265
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500266 if (cert != nullptr) {
267 return cert;
268 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700269
270 return m_certificateCache->getCertificate(certificateNameWithoutVersion);
271 }
272
273 ndn::KeyChain&
274 getKeyChain()
275 {
276 return m_keyChain;
277 }
278
279 const ndn::Name&
280 getDefaultCertName()
281 {
282 return m_defaultCertName;
283 }
284
alvy297f4162015-03-03 17:15:33 -0600285 update::PrefixUpdateProcessor&
286 getPrefixUpdateProcessor()
287 {
288 return m_prefixUpdateProcessor;
289 }
290
akmhoquee1765152014-06-30 11:32:01 -0500291 void
292 createFace(const std::string& faceUri,
akmhoquee1765152014-06-30 11:32:01 -0500293 const CommandSucceedCallback& onSuccess,
294 const CommandFailCallback& onFailure);
295
296 void
297 destroyFaces();
298
akmhoque157b0a42014-05-13 00:26:37 -0500299 void
akmhoquec04e7272014-07-02 11:00:14 -0500300 setStrategies();
akmhoque157b0a42014-05-13 00:26:37 -0500301
akmhoque0494c252014-07-23 23:46:44 -0500302 void
303 daemonize();
304
Vince Lehman7b616582014-10-17 16:25:39 -0500305 uint32_t
306 getFirstHelloInterval() const
307 {
308 return m_firstHelloInterval;
309 }
310
alvy297f4162015-03-03 17:15:33 -0600311PUBLIC_WITH_TESTS_ELSE_PRIVATE:
312 void
313 addCertificateToCache(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
314 {
315 if (certificate != nullptr) {
316 m_certificateCache->insertCertificate(certificate);
317 }
318 }
319
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500320 security::CertificateStore&
321 getCertificateStore()
322 {
323 return m_certStore;
324 }
325
akmhoque393d4ff2014-07-16 14:27:03 -0500326private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700327 void
328 registerKeyPrefix();
329
330 void
alvy297f4162015-03-03 17:15:33 -0600331 registerLocalhostPrefix();
332
333 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700334 onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
335
336 void
337 onKeyPrefixRegSuccess(const ndn::Name& name);
338
akmhoquee1765152014-06-30 11:32:01 -0500339 void
akmhoquee1765152014-06-30 11:32:01 -0500340 onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
341
342 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000343 onDestroyFaceFailure(const ndn::nfd::ControlResponse& response);
akmhoquee1765152014-06-30 11:32:01 -0500344
345 void
akmhoquec04e7272014-07-02 11:00:14 -0500346 onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
akmhoquee1765152014-06-30 11:32:01 -0500347
Vince Lehman7b616582014-10-17 16:25:39 -0500348 void
349 setFirstHelloInterval(uint32_t interval)
350 {
351 m_firstHelloInterval = interval;
352 }
353
alvy297f4162015-03-03 17:15:33 -0600354public:
355 static const ndn::Name LOCALHOST_PREFIX;
356
akmhoque157b0a42014-05-13 00:26:37 -0500357private:
Vince Lehman904c2412014-09-23 19:36:11 -0500358 ndn::Face& m_nlsrFace;
Vince Lehman7c603292014-09-11 17:48:16 -0500359 ndn::Scheduler& m_scheduler;
akmhoque53353462014-04-22 08:43:45 -0500360 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500361 AdjacencyList m_adjacencyList;
362 NamePrefixList m_namePrefixList;
akmhoquec8a10f72014-04-25 18:42:55 -0500363 SequencingManager m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500364 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500365 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500366 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500367 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500368 bool m_isBuildAdjLsaSheduled;
369 bool m_isRouteCalculationScheduled;
370 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500371 RoutingTable m_routingTable;
akmhoque53353462014-04-22 08:43:45 -0500372 Fib m_fib;
akmhoque31d1d4b2014-05-05 22:08:14 -0500373 NamePrefixTable m_namePrefixTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500374 SyncLogicHandler m_syncLogicHandler;
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500375 LsdbDatasetInterestHandler m_lsdbDatasetHandler;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700376
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500377PUBLIC_WITH_TESTS_ELSE_PRIVATE:
378 HelloProtocol m_helloProtocol;
379
Vince Lehman7b616582014-10-17 16:25:39 -0500380private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700381 ndn::shared_ptr<ndn::CertificateCacheTtl> m_certificateCache;
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500382 security::CertificateStore m_certStore;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700383 Validator m_validator;
384 ndn::KeyChain m_keyChain;
Joao Pereira97473d42015-07-03 16:57:27 -0400385 ndn::security::SigningInfo m_signingInfo;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700386 ndn::Name m_defaultCertName;
alvy297f4162015-03-03 17:15:33 -0600387 update::PrefixUpdateProcessor m_prefixUpdateProcessor;
akmhoquee1765152014-06-30 11:32:01 -0500388
akmhoque060d3022014-08-12 13:35:06 -0500389 ndn::nfd::FaceMonitor m_faceMonitor;
Vince Lehman7b616582014-10-17 16:25:39 -0500390
391 uint32_t m_firstHelloInterval;
akmhoque53353462014-04-22 08:43:45 -0500392};
akmhoque298385a2014-02-13 14:13:09 -0600393
Nick Gordonfad8e252016-08-11 14:21:38 -0500394} // namespace nlsr
akmhoqueb1710aa2014-02-19 17:13:36 -0600395
akmhoque53353462014-04-22 08:43:45 -0500396#endif //NLSR_HPP