blob: 3f9fa249b782a8dd316e80c8b36b556be97a10bd [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
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
akmhoque53353462014-04-22 08:43:45 -0500229 void
230 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600231
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700232 void
akmhoque443ad812014-07-29 10:26:56 -0500233 initializeKey();
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700234
235 void
236 loadValidator(boost::property_tree::ptree section,
237 const std::string& filename)
238 {
239 m_validator.load(section, filename);
240 }
241
242 Validator&
243 getValidator()
244 {
245 return m_validator;
246 }
247
248 void
249 loadCertToPublish(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
250 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500251 m_certStore.insert(certificate);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700252 }
253
254 ndn::shared_ptr<const ndn::IdentityCertificate>
255 getCertificate(const ndn::Name& certificateNameWithoutVersion)
256 {
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500257 shared_ptr<const ndn::IdentityCertificate> cert =
258 m_certStore.find(certificateNameWithoutVersion);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700259
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500260 if (cert != nullptr) {
261 return cert;
262 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700263
264 return m_certificateCache->getCertificate(certificateNameWithoutVersion);
265 }
266
267 ndn::KeyChain&
268 getKeyChain()
269 {
270 return m_keyChain;
271 }
272
273 const ndn::Name&
274 getDefaultCertName()
275 {
276 return m_defaultCertName;
277 }
278
alvy297f4162015-03-03 17:15:33 -0600279 update::PrefixUpdateProcessor&
280 getPrefixUpdateProcessor()
281 {
282 return m_prefixUpdateProcessor;
283 }
284
akmhoquee1765152014-06-30 11:32:01 -0500285 void
286 createFace(const std::string& faceUri,
akmhoquee1765152014-06-30 11:32:01 -0500287 const CommandSucceedCallback& onSuccess,
288 const CommandFailCallback& onFailure);
289
290 void
291 destroyFaces();
292
akmhoque157b0a42014-05-13 00:26:37 -0500293 void
akmhoquec04e7272014-07-02 11:00:14 -0500294 setStrategies();
akmhoque157b0a42014-05-13 00:26:37 -0500295
akmhoque0494c252014-07-23 23:46:44 -0500296 void
297 daemonize();
298
Vince Lehman7b616582014-10-17 16:25:39 -0500299 uint32_t
300 getFirstHelloInterval() const
301 {
302 return m_firstHelloInterval;
303 }
304
alvy297f4162015-03-03 17:15:33 -0600305PUBLIC_WITH_TESTS_ELSE_PRIVATE:
306 void
307 addCertificateToCache(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
308 {
309 if (certificate != nullptr) {
310 m_certificateCache->insertCertificate(certificate);
311 }
312 }
313
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500314 security::CertificateStore&
315 getCertificateStore()
316 {
317 return m_certStore;
318 }
319
akmhoque393d4ff2014-07-16 14:27:03 -0500320private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700321 void
322 registerKeyPrefix();
323
324 void
alvy297f4162015-03-03 17:15:33 -0600325 registerLocalhostPrefix();
326
327 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700328 onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
329
330 void
331 onKeyPrefixRegSuccess(const ndn::Name& name);
332
akmhoquee1765152014-06-30 11:32:01 -0500333 void
akmhoquee1765152014-06-30 11:32:01 -0500334 onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
335
336 void
337 onDestroyFaceFailure(int32_t code, const std::string& error);
338
339 void
akmhoquec04e7272014-07-02 11:00:14 -0500340 onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
akmhoquee1765152014-06-30 11:32:01 -0500341
Vince Lehman7b616582014-10-17 16:25:39 -0500342 void
343 setFirstHelloInterval(uint32_t interval)
344 {
345 m_firstHelloInterval = interval;
346 }
347
alvy297f4162015-03-03 17:15:33 -0600348public:
349 static const ndn::Name LOCALHOST_PREFIX;
350
akmhoque157b0a42014-05-13 00:26:37 -0500351private:
Vince Lehman904c2412014-09-23 19:36:11 -0500352 ndn::Face& m_nlsrFace;
Vince Lehman7c603292014-09-11 17:48:16 -0500353 ndn::Scheduler& m_scheduler;
akmhoque53353462014-04-22 08:43:45 -0500354 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500355 AdjacencyList m_adjacencyList;
356 NamePrefixList m_namePrefixList;
akmhoquec8a10f72014-04-25 18:42:55 -0500357 SequencingManager m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500358 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500359 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500360 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500361 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500362 bool m_isBuildAdjLsaSheduled;
363 bool m_isRouteCalculationScheduled;
364 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500365 RoutingTable m_routingTable;
akmhoque53353462014-04-22 08:43:45 -0500366 Fib m_fib;
akmhoque31d1d4b2014-05-05 22:08:14 -0500367 NamePrefixTable m_namePrefixTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500368 SyncLogicHandler m_syncLogicHandler;
akmhoque31d1d4b2014-05-05 22:08:14 -0500369 HelloProtocol m_helloProtocol;
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500370 LsdbDatasetInterestHandler m_lsdbDatasetHandler;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700371
Vince Lehman7b616582014-10-17 16:25:39 -0500372private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700373 ndn::shared_ptr<ndn::CertificateCacheTtl> m_certificateCache;
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500374 security::CertificateStore m_certStore;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700375 Validator m_validator;
376 ndn::KeyChain m_keyChain;
Joao Pereira97473d42015-07-03 16:57:27 -0400377 ndn::security::SigningInfo m_signingInfo;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700378 ndn::Name m_defaultCertName;
alvy297f4162015-03-03 17:15:33 -0600379 update::PrefixUpdateProcessor m_prefixUpdateProcessor;
akmhoquee1765152014-06-30 11:32:01 -0500380
akmhoque060d3022014-08-12 13:35:06 -0500381 ndn::nfd::FaceMonitor m_faceMonitor;
Vince Lehman7b616582014-10-17 16:25:39 -0500382
383 uint32_t m_firstHelloInterval;
akmhoque53353462014-04-22 08:43:45 -0500384};
akmhoque298385a2014-02-13 14:13:09 -0600385
akmhoqueb1710aa2014-02-19 17:13:36 -0600386} //namespace nlsr
387
akmhoque53353462014-04-22 08:43:45 -0500388#endif //NLSR_HPP