blob: 20adfb206df6e34c4cfdeea76c1778b7d932f9c8 [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
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>
akmhoquec04e7272014-07-02 11:00:14 -050032#include <ndn-cxx/management/nfd-face-event-notification.hpp>
akmhoque060d3022014-08-12 13:35:06 -050033#include <ndn-cxx/management/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
akmhoquefdbddb12014-05-02 18:35:19 -050091 void
92 usage(const std::string& progname);
akmhoque53353462014-04-22 08:43:45 -050093
94 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
akmhoque53353462014-04-22 08:43:45 -0500232 void
233 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600234
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700235 void
akmhoque443ad812014-07-29 10:26:56 -0500236 initializeKey();
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700237
238 void
239 loadValidator(boost::property_tree::ptree section,
240 const std::string& filename)
241 {
242 m_validator.load(section, filename);
243 }
244
245 Validator&
246 getValidator()
247 {
248 return m_validator;
249 }
250
251 void
252 loadCertToPublish(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
253 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500254 m_certStore.insert(certificate);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700255 }
256
257 ndn::shared_ptr<const ndn::IdentityCertificate>
258 getCertificate(const ndn::Name& certificateNameWithoutVersion)
259 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500260 shared_ptr<const ndn::IdentityCertificate> cert =
261 m_certStore.find(certificateNameWithoutVersion);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700262
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500263 if (cert != nullptr) {
264 return cert;
265 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700266
267 return m_certificateCache->getCertificate(certificateNameWithoutVersion);
268 }
269
270 ndn::KeyChain&
271 getKeyChain()
272 {
273 return m_keyChain;
274 }
275
276 const ndn::Name&
277 getDefaultCertName()
278 {
279 return m_defaultCertName;
280 }
281
alvy297f4162015-03-03 17:15:33 -0600282 update::PrefixUpdateProcessor&
283 getPrefixUpdateProcessor()
284 {
285 return m_prefixUpdateProcessor;
286 }
287
akmhoquee1765152014-06-30 11:32:01 -0500288 void
289 createFace(const std::string& faceUri,
akmhoquee1765152014-06-30 11:32:01 -0500290 const CommandSucceedCallback& onSuccess,
291 const CommandFailCallback& onFailure);
292
293 void
294 destroyFaces();
295
akmhoque157b0a42014-05-13 00:26:37 -0500296 void
akmhoquec04e7272014-07-02 11:00:14 -0500297 setStrategies();
akmhoque157b0a42014-05-13 00:26:37 -0500298
akmhoque0494c252014-07-23 23:46:44 -0500299 void
300 daemonize();
301
Vince Lehman7b616582014-10-17 16:25:39 -0500302 uint32_t
303 getFirstHelloInterval() const
304 {
305 return m_firstHelloInterval;
306 }
307
alvy297f4162015-03-03 17:15:33 -0600308PUBLIC_WITH_TESTS_ELSE_PRIVATE:
309 void
310 addCertificateToCache(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
311 {
312 if (certificate != nullptr) {
313 m_certificateCache->insertCertificate(certificate);
314 }
315 }
316
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500317 security::CertificateStore&
318 getCertificateStore()
319 {
320 return m_certStore;
321 }
322
akmhoque393d4ff2014-07-16 14:27:03 -0500323private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700324 void
325 registerKeyPrefix();
326
327 void
alvy297f4162015-03-03 17:15:33 -0600328 registerLocalhostPrefix();
329
330 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700331 onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
332
333 void
334 onKeyPrefixRegSuccess(const ndn::Name& name);
335
akmhoquee1765152014-06-30 11:32:01 -0500336 void
akmhoquee1765152014-06-30 11:32:01 -0500337 onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
338
339 void
340 onDestroyFaceFailure(int32_t code, const std::string& error);
341
342 void
akmhoquec04e7272014-07-02 11:00:14 -0500343 onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
akmhoquee1765152014-06-30 11:32:01 -0500344
Vince Lehman7b616582014-10-17 16:25:39 -0500345 void
346 setFirstHelloInterval(uint32_t interval)
347 {
348 m_firstHelloInterval = interval;
349 }
350
alvy297f4162015-03-03 17:15:33 -0600351public:
352 static const ndn::Name LOCALHOST_PREFIX;
353
akmhoque157b0a42014-05-13 00:26:37 -0500354private:
Vince Lehman904c2412014-09-23 19:36:11 -0500355 ndn::Face& m_nlsrFace;
Vince Lehman7c603292014-09-11 17:48:16 -0500356 ndn::Scheduler& m_scheduler;
akmhoque53353462014-04-22 08:43:45 -0500357 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500358 AdjacencyList m_adjacencyList;
359 NamePrefixList m_namePrefixList;
akmhoquec8a10f72014-04-25 18:42:55 -0500360 SequencingManager m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500361 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500362 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500363 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500364 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500365 bool m_isBuildAdjLsaSheduled;
366 bool m_isRouteCalculationScheduled;
367 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500368 RoutingTable m_routingTable;
akmhoque53353462014-04-22 08:43:45 -0500369 Fib m_fib;
akmhoque31d1d4b2014-05-05 22:08:14 -0500370 NamePrefixTable m_namePrefixTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500371 SyncLogicHandler m_syncLogicHandler;
akmhoque31d1d4b2014-05-05 22:08:14 -0500372 HelloProtocol m_helloProtocol;
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500373 LsdbDatasetInterestHandler m_lsdbDatasetHandler;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700374
Vince Lehman7b616582014-10-17 16:25:39 -0500375private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700376 ndn::shared_ptr<ndn::CertificateCacheTtl> m_certificateCache;
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500377 security::CertificateStore m_certStore;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700378 Validator m_validator;
379 ndn::KeyChain m_keyChain;
Joao Pereira97473d42015-07-03 16:57:27 -0400380 ndn::security::SigningInfo m_signingInfo;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700381 ndn::Name m_defaultCertName;
alvy297f4162015-03-03 17:15:33 -0600382 update::PrefixUpdateProcessor m_prefixUpdateProcessor;
akmhoquee1765152014-06-30 11:32:01 -0500383
akmhoque060d3022014-08-12 13:35:06 -0500384 ndn::nfd::FaceMonitor m_faceMonitor;
Vince Lehman7b616582014-10-17 16:25:39 -0500385
386 uint32_t m_firstHelloInterval;
akmhoque53353462014-04-22 08:43:45 -0500387};
akmhoque298385a2014-02-13 14:13:09 -0600388
akmhoqueb1710aa2014-02-19 17:13:36 -0600389} //namespace nlsr
390
akmhoque53353462014-04-22 08:43:45 -0500391#endif //NLSR_HPP