blob: 705cc765acbed52cdf749e650bc9f2d5140d270f [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
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>
Nick Gordond1f4f332017-01-20 13:40:57 -060034#include <ndn-cxx/mgmt/dispatcher.hpp>
akmhoque298385a2014-02-13 14:13:09 -060035
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050036#include "adjacency-list.hpp"
Vince Lehman0a7da612014-10-29 14:39:29 -050037#include "common.hpp"
akmhoque53353462014-04-22 08:43:45 -050038#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050039#include "hello-protocol.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050040#include "lsdb.hpp"
41#include "name-prefix-list.hpp"
42#include "sequencing-manager.hpp"
Vince Lehman7b616582014-10-17 16:25:39 -050043#include "test-access-control.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070044#include "validator.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050045#include "communication/sync-logic-handler.hpp"
46#include "publisher/lsdb-dataset-interest-handler.hpp"
47#include "route/fib.hpp"
48#include "route/name-prefix-table.hpp"
49#include "route/routing-table.hpp"
50#include "security/certificate-store.hpp"
51#include "update/prefix-update-processor.hpp"
52#include "utility/name-helper.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070053
akmhoque2bb198e2014-02-28 11:46:27 -060054
akmhoque53353462014-04-22 08:43:45 -050055namespace nlsr {
56
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070057static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
58
akmhoque53353462014-04-22 08:43:45 -050059class Nlsr
60{
akmhoquefdbddb12014-05-02 18:35:19 -050061 class Error : public std::runtime_error
62 {
63 public:
64 explicit
65 Error(const std::string& what)
66 : std::runtime_error(what)
67 {
68 }
69 };
70
akmhoque53353462014-04-22 08:43:45 -050071public:
Laqin Fana4cf4022017-01-03 18:57:35 +000072 Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::Face& face, ndn::KeyChain& keyChain);
akmhoque298385a2014-02-13 14:13:09 -060073
akmhoque53353462014-04-22 08:43:45 -050074 void
75 registrationFailed(const ndn::Name& name);
76
77 void
akmhoque157b0a42014-05-13 00:26:37 -050078 onRegistrationSuccess(const ndn::Name& name);
79
80 void
alvy297f4162015-03-03 17:15:33 -060081 onLocalhostRegistrationSuccess(const ndn::Name& name);
82
83 void
akmhoque31d1d4b2014-05-05 22:08:14 -050084 setInfoInterestFilter();
85
86 void
87 setLsaInterestFilter();
akmhoque53353462014-04-22 08:43:45 -050088
89 void
90 startEventLoop();
91
akmhoque53353462014-04-22 08:43:45 -050092 std::string
akmhoquefdbddb12014-05-02 18:35:19 -050093 getConfFileName() const
Yingdi Yu40cd1c32014-04-17 15:02:17 -070094 {
akmhoque53353462014-04-22 08:43:45 -050095 return m_configFileName;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070096 }
97
akmhoque53353462014-04-22 08:43:45 -050098 void
akmhoquefdbddb12014-05-02 18:35:19 -050099 setConfFileName(const std::string& fileName)
akmhoque5a44dd42014-03-12 18:11:32 -0500100 {
akmhoque53353462014-04-22 08:43:45 -0500101 m_configFileName = fileName;
102 }
akmhoque5a44dd42014-03-12 18:11:32 -0500103
akmhoque53353462014-04-22 08:43:45 -0500104 bool
105 getIsSetDaemonProcess()
106 {
107 return m_isDaemonProcess;
108 }
akmhoque5a44dd42014-03-12 18:11:32 -0500109
akmhoque53353462014-04-22 08:43:45 -0500110 void
111 setIsDaemonProcess(bool value)
112 {
113 m_isDaemonProcess = value;
114 }
akmhoque5a44dd42014-03-12 18:11:32 -0500115
akmhoque53353462014-04-22 08:43:45 -0500116 ConfParameter&
117 getConfParameter()
118 {
119 return m_confParam;
120 }
akmhoque5a44dd42014-03-12 18:11:32 -0500121
akmhoquec8a10f72014-04-25 18:42:55 -0500122 AdjacencyList&
123 getAdjacencyList()
akmhoque53353462014-04-22 08:43:45 -0500124 {
akmhoquec8a10f72014-04-25 18:42:55 -0500125 return m_adjacencyList;
akmhoque53353462014-04-22 08:43:45 -0500126 }
akmhoque298385a2014-02-13 14:13:09 -0600127
akmhoquec8a10f72014-04-25 18:42:55 -0500128 NamePrefixList&
129 getNamePrefixList()
akmhoque53353462014-04-22 08:43:45 -0500130 {
akmhoquec8a10f72014-04-25 18:42:55 -0500131 return m_namePrefixList;
akmhoque53353462014-04-22 08:43:45 -0500132 }
akmhoque298385a2014-02-13 14:13:09 -0600133
akmhoquefdbddb12014-05-02 18:35:19 -0500134 ndn::Face&
akmhoque53353462014-04-22 08:43:45 -0500135 getNlsrFace()
136 {
137 return m_nlsrFace;
138 }
akmhoque298385a2014-02-13 14:13:09 -0600139
akmhoque53353462014-04-22 08:43:45 -0500140 SequencingManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500141 getSequencingManager()
akmhoque53353462014-04-22 08:43:45 -0500142 {
akmhoquec8a10f72014-04-25 18:42:55 -0500143 return m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500144 }
akmhoque298385a2014-02-13 14:13:09 -0600145
akmhoque53353462014-04-22 08:43:45 -0500146 Lsdb&
147 getLsdb()
148 {
149 return m_nlsrLsdb;
150 }
akmhoque298385a2014-02-13 14:13:09 -0600151
akmhoque53353462014-04-22 08:43:45 -0500152 RoutingTable&
153 getRoutingTable()
154 {
155 return m_routingTable;
156 }
akmhoque298385a2014-02-13 14:13:09 -0600157
akmhoquec8a10f72014-04-25 18:42:55 -0500158 NamePrefixTable&
159 getNamePrefixTable()
akmhoque53353462014-04-22 08:43:45 -0500160 {
akmhoquec8a10f72014-04-25 18:42:55 -0500161 return m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500162 }
akmhoque298385a2014-02-13 14:13:09 -0600163
akmhoque53353462014-04-22 08:43:45 -0500164 Fib&
165 getFib()
166 {
167 return m_fib;
168 }
akmhoque298385a2014-02-13 14:13:09 -0600169
akmhoque53353462014-04-22 08:43:45 -0500170 long int
171 getAdjBuildCount()
172 {
173 return m_adjBuildCount;
174 }
akmhoque298385a2014-02-13 14:13:09 -0600175
akmhoque53353462014-04-22 08:43:45 -0500176 void
177 incrementAdjBuildCount()
178 {
179 m_adjBuildCount++;
180 }
akmhoque298385a2014-02-13 14:13:09 -0600181
akmhoque53353462014-04-22 08:43:45 -0500182 void
akmhoquefdbddb12014-05-02 18:35:19 -0500183 setAdjBuildCount(int64_t abc)
akmhoque53353462014-04-22 08:43:45 -0500184 {
185 m_adjBuildCount = abc;
186 }
akmhoque298385a2014-02-13 14:13:09 -0600187
akmhoque157b0a42014-05-13 00:26:37 -0500188 bool
akmhoque53353462014-04-22 08:43:45 -0500189 getIsBuildAdjLsaSheduled()
190 {
191 return m_isBuildAdjLsaSheduled;
192 }
akmhoque298385a2014-02-13 14:13:09 -0600193
akmhoque53353462014-04-22 08:43:45 -0500194 void
195 setIsBuildAdjLsaSheduled(bool iabls)
196 {
197 m_isBuildAdjLsaSheduled = iabls;
198 }
akmhoque298385a2014-02-13 14:13:09 -0600199
akmhoque53353462014-04-22 08:43:45 -0500200 bool
201 getIsRoutingTableCalculating()
202 {
203 return m_isRoutingTableCalculating;
204 }
akmhoque85d88332014-02-17 21:11:21 -0600205
akmhoque53353462014-04-22 08:43:45 -0500206 void
207 setIsRoutingTableCalculating(bool irtc)
208 {
209 m_isRoutingTableCalculating = irtc;
210 }
akmhoque298385a2014-02-13 14:13:09 -0600211
akmhoque53353462014-04-22 08:43:45 -0500212 bool
213 getIsRouteCalculationScheduled()
214 {
215 return m_isRouteCalculationScheduled;
216 }
akmhoque298385a2014-02-13 14:13:09 -0600217
akmhoque53353462014-04-22 08:43:45 -0500218 void
219 setIsRouteCalculationScheduled(bool ircs)
220 {
221 m_isRouteCalculationScheduled = ircs;
222 }
akmhoque298385a2014-02-13 14:13:09 -0600223
akmhoque53353462014-04-22 08:43:45 -0500224 SyncLogicHandler&
akmhoquec8a10f72014-04-25 18:42:55 -0500225 getSyncLogicHandler()
akmhoque53353462014-04-22 08:43:45 -0500226 {
akmhoquec8a10f72014-04-25 18:42:55 -0500227 return m_syncLogicHandler;
akmhoque53353462014-04-22 08:43:45 -0500228 }
akmhoque2bb198e2014-02-28 11:46:27 -0600229
Muktadir R Chowdhury3ac07282016-06-17 16:30:29 -0500230 LsdbDatasetInterestHandler&
231 getLsdbDatasetHandler()
232 {
233 return m_lsdbDatasetHandler;
234 }
235
akmhoque53353462014-04-22 08:43:45 -0500236 void
237 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600238
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700239 void
akmhoque443ad812014-07-29 10:26:56 -0500240 initializeKey();
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700241
242 void
243 loadValidator(boost::property_tree::ptree section,
244 const std::string& filename)
245 {
246 m_validator.load(section, filename);
247 }
248
249 Validator&
250 getValidator()
251 {
252 return m_validator;
253 }
254
255 void
256 loadCertToPublish(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
257 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500258 m_certStore.insert(certificate);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700259 }
260
261 ndn::shared_ptr<const ndn::IdentityCertificate>
262 getCertificate(const ndn::Name& certificateNameWithoutVersion)
263 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500264 shared_ptr<const ndn::IdentityCertificate> cert =
265 m_certStore.find(certificateNameWithoutVersion);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700266
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500267 if (cert != nullptr) {
268 return cert;
269 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700270
271 return m_certificateCache->getCertificate(certificateNameWithoutVersion);
272 }
273
274 ndn::KeyChain&
275 getKeyChain()
276 {
277 return m_keyChain;
278 }
279
280 const ndn::Name&
281 getDefaultCertName()
282 {
283 return m_defaultCertName;
284 }
285
alvy297f4162015-03-03 17:15:33 -0600286 update::PrefixUpdateProcessor&
287 getPrefixUpdateProcessor()
288 {
289 return m_prefixUpdateProcessor;
290 }
291
Nick Gordond1f4f332017-01-20 13:40:57 -0600292 ndn::mgmt::Dispatcher&
293 getDispatcher()
294 {
295 return m_dispatcher;
296 }
297
akmhoquee1765152014-06-30 11:32:01 -0500298 void
299 createFace(const std::string& faceUri,
akmhoquee1765152014-06-30 11:32:01 -0500300 const CommandSucceedCallback& onSuccess,
301 const CommandFailCallback& onFailure);
302
303 void
304 destroyFaces();
305
akmhoque157b0a42014-05-13 00:26:37 -0500306 void
akmhoquec04e7272014-07-02 11:00:14 -0500307 setStrategies();
akmhoque157b0a42014-05-13 00:26:37 -0500308
akmhoque0494c252014-07-23 23:46:44 -0500309 void
310 daemonize();
311
Vince Lehman7b616582014-10-17 16:25:39 -0500312 uint32_t
313 getFirstHelloInterval() const
314 {
315 return m_firstHelloInterval;
316 }
317
alvy297f4162015-03-03 17:15:33 -0600318PUBLIC_WITH_TESTS_ELSE_PRIVATE:
319 void
320 addCertificateToCache(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
321 {
322 if (certificate != nullptr) {
323 m_certificateCache->insertCertificate(certificate);
324 }
325 }
326
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500327 security::CertificateStore&
328 getCertificateStore()
329 {
330 return m_certStore;
331 }
332
akmhoque393d4ff2014-07-16 14:27:03 -0500333private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700334 void
335 registerKeyPrefix();
336
337 void
alvy297f4162015-03-03 17:15:33 -0600338 registerLocalhostPrefix();
339
340 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700341 onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
342
343 void
344 onKeyPrefixRegSuccess(const ndn::Name& name);
345
akmhoquee1765152014-06-30 11:32:01 -0500346 void
akmhoquee1765152014-06-30 11:32:01 -0500347 onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
348
349 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000350 onDestroyFaceFailure(const ndn::nfd::ControlResponse& response);
akmhoquee1765152014-06-30 11:32:01 -0500351
352 void
akmhoquec04e7272014-07-02 11:00:14 -0500353 onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
akmhoquee1765152014-06-30 11:32:01 -0500354
Vince Lehman7b616582014-10-17 16:25:39 -0500355 void
356 setFirstHelloInterval(uint32_t interval)
357 {
358 m_firstHelloInterval = interval;
359 }
360
alvy297f4162015-03-03 17:15:33 -0600361public:
362 static const ndn::Name LOCALHOST_PREFIX;
363
akmhoque157b0a42014-05-13 00:26:37 -0500364private:
Vince Lehman904c2412014-09-23 19:36:11 -0500365 ndn::Face& m_nlsrFace;
Vince Lehman7c603292014-09-11 17:48:16 -0500366 ndn::Scheduler& m_scheduler;
Laqin Fana4cf4022017-01-03 18:57:35 +0000367 ndn::KeyChain& m_keyChain;
akmhoque53353462014-04-22 08:43:45 -0500368 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500369 AdjacencyList m_adjacencyList;
370 NamePrefixList m_namePrefixList;
akmhoquec8a10f72014-04-25 18:42:55 -0500371 SequencingManager m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500372 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500373 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500374 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500375 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500376 bool m_isBuildAdjLsaSheduled;
377 bool m_isRouteCalculationScheduled;
378 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500379 RoutingTable m_routingTable;
akmhoque53353462014-04-22 08:43:45 -0500380 Fib m_fib;
akmhoque31d1d4b2014-05-05 22:08:14 -0500381 NamePrefixTable m_namePrefixTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500382 SyncLogicHandler m_syncLogicHandler;
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500383 LsdbDatasetInterestHandler m_lsdbDatasetHandler;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700384
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500385PUBLIC_WITH_TESTS_ELSE_PRIVATE:
386 HelloProtocol m_helloProtocol;
387
Vince Lehman7b616582014-10-17 16:25:39 -0500388private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700389 ndn::shared_ptr<ndn::CertificateCacheTtl> m_certificateCache;
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500390 security::CertificateStore m_certStore;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700391 Validator m_validator;
Joao Pereira97473d42015-07-03 16:57:27 -0400392 ndn::security::SigningInfo m_signingInfo;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700393 ndn::Name m_defaultCertName;
alvy297f4162015-03-03 17:15:33 -0600394 update::PrefixUpdateProcessor m_prefixUpdateProcessor;
Nick Gordond1f4f332017-01-20 13:40:57 -0600395 ndn::mgmt::Dispatcher m_dispatcher;
akmhoquee1765152014-06-30 11:32:01 -0500396
akmhoque060d3022014-08-12 13:35:06 -0500397 ndn::nfd::FaceMonitor m_faceMonitor;
Vince Lehman7b616582014-10-17 16:25:39 -0500398
399 uint32_t m_firstHelloInterval;
akmhoque53353462014-04-22 08:43:45 -0500400};
akmhoque298385a2014-02-13 14:13:09 -0600401
Nick Gordonfad8e252016-08-11 14:21:38 -0500402} // namespace nlsr
akmhoqueb1710aa2014-02-19 17:13:36 -0600403
akmhoque53353462014-04-22 08:43:45 -0500404#endif //NLSR_HPP