blob: dd8a4781c28454abf476105dd9ad3d8b3ea8a385 [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 Lehman0a7da612014-10-29 14:39:29 -050035#include "common.hpp"
akmhoque53353462014-04-22 08:43:45 -050036#include "conf-parameter.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050037#include "adjacency-list.hpp"
38#include "name-prefix-list.hpp"
akmhoque53353462014-04-22 08:43:45 -050039#include "lsdb.hpp"
40#include "sequencing-manager.hpp"
41#include "route/routing-table.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050042#include "route/name-prefix-table.hpp"
akmhoque53353462014-04-22 08:43:45 -050043#include "route/fib.hpp"
akmhoque53353462014-04-22 08:43:45 -050044#include "communication/sync-logic-handler.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050045#include "hello-protocol.hpp"
Vince Lehman7b616582014-10-17 16:25:39 -050046#include "test-access-control.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080047#include "publisher/lsdb-dataset-interest-handler.hpp"
alvy297f4162015-03-03 17:15:33 -060048#include "utility/name-helper.hpp"
49#include "update/prefix-update-processor.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070050#include "validator.hpp"
51
akmhoque2bb198e2014-02-28 11:46:27 -060052
akmhoque53353462014-04-22 08:43:45 -050053namespace nlsr {
54
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070055static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
56
akmhoque53353462014-04-22 08:43:45 -050057class Nlsr
58{
akmhoquefdbddb12014-05-02 18:35:19 -050059 class Error : public std::runtime_error
60 {
61 public:
62 explicit
63 Error(const std::string& what)
64 : std::runtime_error(what)
65 {
66 }
67 };
68
akmhoque53353462014-04-22 08:43:45 -050069public:
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050070 Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::Face& face);
akmhoque298385a2014-02-13 14:13:09 -060071
akmhoque53353462014-04-22 08:43:45 -050072 void
73 registrationFailed(const ndn::Name& name);
74
75 void
akmhoque157b0a42014-05-13 00:26:37 -050076 onRegistrationSuccess(const ndn::Name& name);
77
78 void
alvy297f4162015-03-03 17:15:33 -060079 onLocalhostRegistrationSuccess(const ndn::Name& name);
80
81 void
akmhoque31d1d4b2014-05-05 22:08:14 -050082 setInfoInterestFilter();
83
84 void
85 setLsaInterestFilter();
akmhoque53353462014-04-22 08:43:45 -050086
87 void
88 startEventLoop();
89
akmhoquefdbddb12014-05-02 18:35:19 -050090 void
91 usage(const std::string& progname);
akmhoque53353462014-04-22 08:43:45 -050092
93 std::string
akmhoquefdbddb12014-05-02 18:35:19 -050094 getConfFileName() const
Yingdi Yu40cd1c32014-04-17 15:02:17 -070095 {
akmhoque53353462014-04-22 08:43:45 -050096 return m_configFileName;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070097 }
98
akmhoque53353462014-04-22 08:43:45 -050099 void
akmhoquefdbddb12014-05-02 18:35:19 -0500100 setConfFileName(const std::string& fileName)
akmhoque5a44dd42014-03-12 18:11:32 -0500101 {
akmhoque53353462014-04-22 08:43:45 -0500102 m_configFileName = fileName;
103 }
akmhoque5a44dd42014-03-12 18:11:32 -0500104
akmhoque53353462014-04-22 08:43:45 -0500105 bool
106 getIsSetDaemonProcess()
107 {
108 return m_isDaemonProcess;
109 }
akmhoque5a44dd42014-03-12 18:11:32 -0500110
akmhoque53353462014-04-22 08:43:45 -0500111 void
112 setIsDaemonProcess(bool value)
113 {
114 m_isDaemonProcess = value;
115 }
akmhoque5a44dd42014-03-12 18:11:32 -0500116
akmhoque53353462014-04-22 08:43:45 -0500117 ConfParameter&
118 getConfParameter()
119 {
120 return m_confParam;
121 }
akmhoque5a44dd42014-03-12 18:11:32 -0500122
akmhoquec8a10f72014-04-25 18:42:55 -0500123 AdjacencyList&
124 getAdjacencyList()
akmhoque53353462014-04-22 08:43:45 -0500125 {
akmhoquec8a10f72014-04-25 18:42:55 -0500126 return m_adjacencyList;
akmhoque53353462014-04-22 08:43:45 -0500127 }
akmhoque298385a2014-02-13 14:13:09 -0600128
akmhoquec8a10f72014-04-25 18:42:55 -0500129 NamePrefixList&
130 getNamePrefixList()
akmhoque53353462014-04-22 08:43:45 -0500131 {
akmhoquec8a10f72014-04-25 18:42:55 -0500132 return m_namePrefixList;
akmhoque53353462014-04-22 08:43:45 -0500133 }
akmhoque298385a2014-02-13 14:13:09 -0600134
akmhoquefdbddb12014-05-02 18:35:19 -0500135 ndn::Face&
akmhoque53353462014-04-22 08:43:45 -0500136 getNlsrFace()
137 {
138 return m_nlsrFace;
139 }
akmhoque298385a2014-02-13 14:13:09 -0600140
akmhoque53353462014-04-22 08:43:45 -0500141 SequencingManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500142 getSequencingManager()
akmhoque53353462014-04-22 08:43:45 -0500143 {
akmhoquec8a10f72014-04-25 18:42:55 -0500144 return m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500145 }
akmhoque298385a2014-02-13 14:13:09 -0600146
akmhoque53353462014-04-22 08:43:45 -0500147 Lsdb&
148 getLsdb()
149 {
150 return m_nlsrLsdb;
151 }
akmhoque298385a2014-02-13 14:13:09 -0600152
akmhoque53353462014-04-22 08:43:45 -0500153 RoutingTable&
154 getRoutingTable()
155 {
156 return m_routingTable;
157 }
akmhoque298385a2014-02-13 14:13:09 -0600158
akmhoquec8a10f72014-04-25 18:42:55 -0500159 NamePrefixTable&
160 getNamePrefixTable()
akmhoque53353462014-04-22 08:43:45 -0500161 {
akmhoquec8a10f72014-04-25 18:42:55 -0500162 return m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500163 }
akmhoque298385a2014-02-13 14:13:09 -0600164
akmhoque53353462014-04-22 08:43:45 -0500165 Fib&
166 getFib()
167 {
168 return m_fib;
169 }
akmhoque298385a2014-02-13 14:13:09 -0600170
akmhoque53353462014-04-22 08:43:45 -0500171 long int
172 getAdjBuildCount()
173 {
174 return m_adjBuildCount;
175 }
akmhoque298385a2014-02-13 14:13:09 -0600176
akmhoque53353462014-04-22 08:43:45 -0500177 void
178 incrementAdjBuildCount()
179 {
180 m_adjBuildCount++;
181 }
akmhoque298385a2014-02-13 14:13:09 -0600182
akmhoque53353462014-04-22 08:43:45 -0500183 void
akmhoquefdbddb12014-05-02 18:35:19 -0500184 setAdjBuildCount(int64_t abc)
akmhoque53353462014-04-22 08:43:45 -0500185 {
186 m_adjBuildCount = abc;
187 }
akmhoque298385a2014-02-13 14:13:09 -0600188
akmhoque157b0a42014-05-13 00:26:37 -0500189 bool
akmhoque53353462014-04-22 08:43:45 -0500190 getIsBuildAdjLsaSheduled()
191 {
192 return m_isBuildAdjLsaSheduled;
193 }
akmhoque298385a2014-02-13 14:13:09 -0600194
akmhoque53353462014-04-22 08:43:45 -0500195 void
196 setIsBuildAdjLsaSheduled(bool iabls)
197 {
198 m_isBuildAdjLsaSheduled = iabls;
199 }
akmhoque298385a2014-02-13 14:13:09 -0600200
akmhoque53353462014-04-22 08:43:45 -0500201 bool
202 getIsRoutingTableCalculating()
203 {
204 return m_isRoutingTableCalculating;
205 }
akmhoque85d88332014-02-17 21:11:21 -0600206
akmhoque53353462014-04-22 08:43:45 -0500207 void
208 setIsRoutingTableCalculating(bool irtc)
209 {
210 m_isRoutingTableCalculating = irtc;
211 }
akmhoque298385a2014-02-13 14:13:09 -0600212
akmhoque53353462014-04-22 08:43:45 -0500213 bool
214 getIsRouteCalculationScheduled()
215 {
216 return m_isRouteCalculationScheduled;
217 }
akmhoque298385a2014-02-13 14:13:09 -0600218
akmhoque53353462014-04-22 08:43:45 -0500219 void
220 setIsRouteCalculationScheduled(bool ircs)
221 {
222 m_isRouteCalculationScheduled = ircs;
223 }
akmhoque298385a2014-02-13 14:13:09 -0600224
akmhoque53353462014-04-22 08:43:45 -0500225 SyncLogicHandler&
akmhoquec8a10f72014-04-25 18:42:55 -0500226 getSyncLogicHandler()
akmhoque53353462014-04-22 08:43:45 -0500227 {
akmhoquec8a10f72014-04-25 18:42:55 -0500228 return m_syncLogicHandler;
akmhoque53353462014-04-22 08:43:45 -0500229 }
akmhoque2bb198e2014-02-28 11:46:27 -0600230
akmhoque53353462014-04-22 08:43:45 -0500231 void
232 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600233
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700234 void
akmhoque443ad812014-07-29 10:26:56 -0500235 initializeKey();
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700236
237 void
238 loadValidator(boost::property_tree::ptree section,
239 const std::string& filename)
240 {
241 m_validator.load(section, filename);
242 }
243
244 Validator&
245 getValidator()
246 {
247 return m_validator;
248 }
249
250 void
251 loadCertToPublish(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
252 {
253 if (static_cast<bool>(certificate))
254 m_certToPublish[certificate->getName().getPrefix(-1)] = certificate; // key is cert name
255 // without version
256 }
257
258 ndn::shared_ptr<const ndn::IdentityCertificate>
259 getCertificate(const ndn::Name& certificateNameWithoutVersion)
260 {
261 CertMap::iterator it = m_certToPublish.find(certificateNameWithoutVersion);
262
263 if (it != m_certToPublish.end())
264 {
265 return it->second;
266 }
267
268 return m_certificateCache->getCertificate(certificateNameWithoutVersion);
269 }
270
271 ndn::KeyChain&
272 getKeyChain()
273 {
274 return m_keyChain;
275 }
276
277 const ndn::Name&
278 getDefaultCertName()
279 {
280 return m_defaultCertName;
281 }
282
alvy297f4162015-03-03 17:15:33 -0600283 update::PrefixUpdateProcessor&
284 getPrefixUpdateProcessor()
285 {
286 return m_prefixUpdateProcessor;
287 }
288
akmhoquee1765152014-06-30 11:32:01 -0500289 void
290 createFace(const std::string& faceUri,
akmhoquee1765152014-06-30 11:32:01 -0500291 const CommandSucceedCallback& onSuccess,
292 const CommandFailCallback& onFailure);
293
294 void
295 destroyFaces();
296
akmhoque157b0a42014-05-13 00:26:37 -0500297 void
akmhoquec04e7272014-07-02 11:00:14 -0500298 setStrategies();
akmhoque157b0a42014-05-13 00:26:37 -0500299
akmhoque0494c252014-07-23 23:46:44 -0500300 void
301 daemonize();
302
Vince Lehman7b616582014-10-17 16:25:39 -0500303 uint32_t
304 getFirstHelloInterval() const
305 {
306 return m_firstHelloInterval;
307 }
308
alvy297f4162015-03-03 17:15:33 -0600309PUBLIC_WITH_TESTS_ELSE_PRIVATE:
310 void
311 addCertificateToCache(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
312 {
313 if (certificate != nullptr) {
314 m_certificateCache->insertCertificate(certificate);
315 }
316 }
317
akmhoque393d4ff2014-07-16 14:27:03 -0500318private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700319 void
320 registerKeyPrefix();
321
322 void
alvy297f4162015-03-03 17:15:33 -0600323 registerLocalhostPrefix();
324
325 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700326 onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
327
328 void
329 onKeyPrefixRegSuccess(const ndn::Name& name);
330
akmhoquee1765152014-06-30 11:32:01 -0500331 void
akmhoquee1765152014-06-30 11:32:01 -0500332 onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
333
334 void
335 onDestroyFaceFailure(int32_t code, const std::string& error);
336
337 void
akmhoquec04e7272014-07-02 11:00:14 -0500338 onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
akmhoquee1765152014-06-30 11:32:01 -0500339
Vince Lehman7b616582014-10-17 16:25:39 -0500340 void
341 setFirstHelloInterval(uint32_t interval)
342 {
343 m_firstHelloInterval = interval;
344 }
345
alvy297f4162015-03-03 17:15:33 -0600346public:
347 static const ndn::Name LOCALHOST_PREFIX;
348
akmhoque157b0a42014-05-13 00:26:37 -0500349private:
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700350 typedef std::map<ndn::Name, ndn::shared_ptr<ndn::IdentityCertificate> > CertMap;
351
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;
374 CertMap m_certToPublish;
375 Validator m_validator;
376 ndn::KeyChain m_keyChain;
377 ndn::Name m_defaultIdentity;
378 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