blob: 8db25c2e6277699d63b2eac3febf3b6c422451fe [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoque298385a2014-02-13 14:13:09 -060023#ifndef NLSR_HPP
24#define NLSR_HPP
25
akmhoquefdbddb12014-05-02 18:35:19 -050026#include <boost/cstdint.hpp>
27#include <stdexcept>
28
akmhoquec8a10f72014-04-25 18:42:55 -050029#include <ndn-cxx/face.hpp>
30#include <ndn-cxx/security/key-chain.hpp>
31#include <ndn-cxx/util/scheduler.hpp>
akmhoque298385a2014-02-13 14:13:09 -060032
akmhoque53353462014-04-22 08:43:45 -050033#include "conf-parameter.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050034#include "adjacency-list.hpp"
35#include "name-prefix-list.hpp"
akmhoque53353462014-04-22 08:43:45 -050036#include "lsdb.hpp"
37#include "sequencing-manager.hpp"
38#include "route/routing-table.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050039#include "route/name-prefix-table.hpp"
akmhoque53353462014-04-22 08:43:45 -050040#include "route/fib.hpp"
akmhoque53353462014-04-22 08:43:45 -050041#include "communication/sync-logic-handler.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050042#include "hello-protocol.hpp"
akmhoque2bb198e2014-02-28 11:46:27 -060043
44
akmhoque53353462014-04-22 08:43:45 -050045namespace nlsr {
46
akmhoque53353462014-04-22 08:43:45 -050047class Nlsr
48{
akmhoquefdbddb12014-05-02 18:35:19 -050049 class Error : public std::runtime_error
50 {
51 public:
52 explicit
53 Error(const std::string& what)
54 : std::runtime_error(what)
55 {
56 }
57 };
58
akmhoque53353462014-04-22 08:43:45 -050059public:
60 Nlsr()
akmhoquefdbddb12014-05-02 18:35:19 -050061 : m_scheduler(m_nlsrFace.getIoService())
akmhoque53353462014-04-22 08:43:45 -050062 , m_confParam()
akmhoquec8a10f72014-04-25 18:42:55 -050063 , m_adjacencyList()
64 , m_namePrefixList()
akmhoquec8a10f72014-04-25 18:42:55 -050065 , m_sequencingManager()
akmhoque53353462014-04-22 08:43:45 -050066 , m_isDaemonProcess(false)
67 , m_configFileName("nlsr.conf")
akmhoque31d1d4b2014-05-05 22:08:14 -050068 , m_nlsrLsdb(*this)
akmhoque53353462014-04-22 08:43:45 -050069 , m_adjBuildCount(0)
70 , m_isBuildAdjLsaSheduled(false)
71 , m_isRouteCalculationScheduled(false)
72 , m_isRoutingTableCalculating(false)
73 , m_routingTable()
akmhoque31d1d4b2014-05-05 22:08:14 -050074 , m_fib(*this, m_nlsrFace)
75 , m_namePrefixTable(*this)
akmhoquefdbddb12014-05-02 18:35:19 -050076 , m_syncLogicHandler(m_nlsrFace.getIoService())
akmhoque31d1d4b2014-05-05 22:08:14 -050077 , m_helloProtocol(*this)
akmhoque53353462014-04-22 08:43:45 -050078 {}
akmhoque298385a2014-02-13 14:13:09 -060079
akmhoque53353462014-04-22 08:43:45 -050080 void
81 registrationFailed(const ndn::Name& name);
82
83 void
akmhoque157b0a42014-05-13 00:26:37 -050084 onRegistrationSuccess(const ndn::Name& name);
85
86 void
akmhoque31d1d4b2014-05-05 22:08:14 -050087 setInfoInterestFilter();
88
89 void
90 setLsaInterestFilter();
akmhoque53353462014-04-22 08:43:45 -050091
92 void
93 startEventLoop();
94
akmhoquefdbddb12014-05-02 18:35:19 -050095 void
96 usage(const std::string& progname);
akmhoque53353462014-04-22 08:43:45 -050097
98 std::string
akmhoquefdbddb12014-05-02 18:35:19 -050099 getConfFileName() const
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700100 {
akmhoque53353462014-04-22 08:43:45 -0500101 return m_configFileName;
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700102 }
103
akmhoque53353462014-04-22 08:43:45 -0500104 void
akmhoquefdbddb12014-05-02 18:35:19 -0500105 setConfFileName(const std::string& fileName)
akmhoque5a44dd42014-03-12 18:11:32 -0500106 {
akmhoque53353462014-04-22 08:43:45 -0500107 m_configFileName = fileName;
108 }
akmhoque5a44dd42014-03-12 18:11:32 -0500109
akmhoque53353462014-04-22 08:43:45 -0500110 bool
111 getIsSetDaemonProcess()
112 {
113 return m_isDaemonProcess;
114 }
akmhoque5a44dd42014-03-12 18:11:32 -0500115
akmhoque53353462014-04-22 08:43:45 -0500116 void
117 setIsDaemonProcess(bool value)
118 {
119 m_isDaemonProcess = value;
120 }
akmhoque5a44dd42014-03-12 18:11:32 -0500121
akmhoque53353462014-04-22 08:43:45 -0500122 ConfParameter&
123 getConfParameter()
124 {
125 return m_confParam;
126 }
akmhoque5a44dd42014-03-12 18:11:32 -0500127
akmhoquec8a10f72014-04-25 18:42:55 -0500128 AdjacencyList&
129 getAdjacencyList()
akmhoque53353462014-04-22 08:43:45 -0500130 {
akmhoquec8a10f72014-04-25 18:42:55 -0500131 return m_adjacencyList;
akmhoque53353462014-04-22 08:43:45 -0500132 }
akmhoque298385a2014-02-13 14:13:09 -0600133
akmhoquec8a10f72014-04-25 18:42:55 -0500134 NamePrefixList&
135 getNamePrefixList()
akmhoque53353462014-04-22 08:43:45 -0500136 {
akmhoquec8a10f72014-04-25 18:42:55 -0500137 return m_namePrefixList;
akmhoque53353462014-04-22 08:43:45 -0500138 }
akmhoque298385a2014-02-13 14:13:09 -0600139
akmhoque53353462014-04-22 08:43:45 -0500140 ndn::Scheduler&
141 getScheduler()
142 {
143 return m_scheduler;
144 }
akmhoque298385a2014-02-13 14:13:09 -0600145
akmhoquefdbddb12014-05-02 18:35:19 -0500146 ndn::Face&
akmhoque53353462014-04-22 08:43:45 -0500147 getNlsrFace()
148 {
149 return m_nlsrFace;
150 }
akmhoque298385a2014-02-13 14:13:09 -0600151
akmhoque53353462014-04-22 08:43:45 -0500152 SequencingManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500153 getSequencingManager()
akmhoque53353462014-04-22 08:43:45 -0500154 {
akmhoquec8a10f72014-04-25 18:42:55 -0500155 return m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500156 }
akmhoque298385a2014-02-13 14:13:09 -0600157
akmhoque53353462014-04-22 08:43:45 -0500158 Lsdb&
159 getLsdb()
160 {
161 return m_nlsrLsdb;
162 }
akmhoque298385a2014-02-13 14:13:09 -0600163
akmhoque53353462014-04-22 08:43:45 -0500164 RoutingTable&
165 getRoutingTable()
166 {
167 return m_routingTable;
168 }
akmhoque298385a2014-02-13 14:13:09 -0600169
akmhoquec8a10f72014-04-25 18:42:55 -0500170 NamePrefixTable&
171 getNamePrefixTable()
akmhoque53353462014-04-22 08:43:45 -0500172 {
akmhoquec8a10f72014-04-25 18:42:55 -0500173 return m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500174 }
akmhoque298385a2014-02-13 14:13:09 -0600175
akmhoque53353462014-04-22 08:43:45 -0500176 Fib&
177 getFib()
178 {
179 return m_fib;
180 }
akmhoque298385a2014-02-13 14:13:09 -0600181
akmhoque53353462014-04-22 08:43:45 -0500182 long int
183 getAdjBuildCount()
184 {
185 return m_adjBuildCount;
186 }
akmhoque298385a2014-02-13 14:13:09 -0600187
akmhoque53353462014-04-22 08:43:45 -0500188 void
189 incrementAdjBuildCount()
190 {
191 m_adjBuildCount++;
192 }
akmhoque298385a2014-02-13 14:13:09 -0600193
akmhoque53353462014-04-22 08:43:45 -0500194 void
akmhoquefdbddb12014-05-02 18:35:19 -0500195 setAdjBuildCount(int64_t abc)
akmhoque53353462014-04-22 08:43:45 -0500196 {
197 m_adjBuildCount = abc;
198 }
akmhoque298385a2014-02-13 14:13:09 -0600199
akmhoque157b0a42014-05-13 00:26:37 -0500200 bool
akmhoque53353462014-04-22 08:43:45 -0500201 getIsBuildAdjLsaSheduled()
202 {
203 return m_isBuildAdjLsaSheduled;
204 }
akmhoque298385a2014-02-13 14:13:09 -0600205
akmhoque53353462014-04-22 08:43:45 -0500206 void
207 setIsBuildAdjLsaSheduled(bool iabls)
208 {
209 m_isBuildAdjLsaSheduled = iabls;
210 }
akmhoque298385a2014-02-13 14:13:09 -0600211
akmhoque298385a2014-02-13 14:13:09 -0600212
akmhoque53353462014-04-22 08:43:45 -0500213 void
akmhoquefdbddb12014-05-02 18:35:19 -0500214 setApiPort(int32_t ap)
akmhoque53353462014-04-22 08:43:45 -0500215 {
216 m_apiPort = ap;
217 }
akmhoque298385a2014-02-13 14:13:09 -0600218
akmhoquefdbddb12014-05-02 18:35:19 -0500219 int32_t
akmhoque53353462014-04-22 08:43:45 -0500220 getApiPort()
221 {
222 return m_apiPort;
223 }
akmhoque298385a2014-02-13 14:13:09 -0600224
akmhoque53353462014-04-22 08:43:45 -0500225 bool
226 getIsRoutingTableCalculating()
227 {
228 return m_isRoutingTableCalculating;
229 }
akmhoque85d88332014-02-17 21:11:21 -0600230
akmhoque53353462014-04-22 08:43:45 -0500231 void
232 setIsRoutingTableCalculating(bool irtc)
233 {
234 m_isRoutingTableCalculating = irtc;
235 }
akmhoque298385a2014-02-13 14:13:09 -0600236
akmhoque53353462014-04-22 08:43:45 -0500237 bool
238 getIsRouteCalculationScheduled()
239 {
240 return m_isRouteCalculationScheduled;
241 }
akmhoque298385a2014-02-13 14:13:09 -0600242
akmhoque53353462014-04-22 08:43:45 -0500243 void
244 setIsRouteCalculationScheduled(bool ircs)
245 {
246 m_isRouteCalculationScheduled = ircs;
247 }
akmhoque298385a2014-02-13 14:13:09 -0600248
akmhoque53353462014-04-22 08:43:45 -0500249 SyncLogicHandler&
akmhoquec8a10f72014-04-25 18:42:55 -0500250 getSyncLogicHandler()
akmhoque53353462014-04-22 08:43:45 -0500251 {
akmhoquec8a10f72014-04-25 18:42:55 -0500252 return m_syncLogicHandler;
akmhoque53353462014-04-22 08:43:45 -0500253 }
akmhoque2bb198e2014-02-28 11:46:27 -0600254
akmhoque53353462014-04-22 08:43:45 -0500255 void
256 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600257
akmhoque53353462014-04-22 08:43:45 -0500258private:
akmhoque157b0a42014-05-13 00:26:37 -0500259 void
260 registerPrefixes();
261
262private:
akmhoquefdbddb12014-05-02 18:35:19 -0500263 ndn::Face m_nlsrFace;
akmhoque53353462014-04-22 08:43:45 -0500264 ndn::Scheduler m_scheduler;
265 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500266 AdjacencyList m_adjacencyList;
267 NamePrefixList m_namePrefixList;
akmhoquec8a10f72014-04-25 18:42:55 -0500268 SequencingManager m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500269 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500270 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500271 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500272 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500273 bool m_isBuildAdjLsaSheduled;
274 bool m_isRouteCalculationScheduled;
275 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500276 RoutingTable m_routingTable;
akmhoque53353462014-04-22 08:43:45 -0500277 Fib m_fib;
akmhoque31d1d4b2014-05-05 22:08:14 -0500278 NamePrefixTable m_namePrefixTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500279 SyncLogicHandler m_syncLogicHandler;
akmhoquefdbddb12014-05-02 18:35:19 -0500280 int32_t m_apiPort;
akmhoque31d1d4b2014-05-05 22:08:14 -0500281 HelloProtocol m_helloProtocol;
akmhoque53353462014-04-22 08:43:45 -0500282};
akmhoque298385a2014-02-13 14:13:09 -0600283
akmhoqueb1710aa2014-02-19 17:13:36 -0600284} //namespace nlsr
285
akmhoque53353462014-04-22 08:43:45 -0500286#endif //NLSR_HPP