blob: 6fc255da28a6a9b27a72f727db153c9a007b3373 [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#ifndef NLSR_HPP
2#define NLSR_HPP
3
akmhoquefdbddb12014-05-02 18:35:19 -05004#include <boost/cstdint.hpp>
5#include <stdexcept>
6
akmhoquec8a10f72014-04-25 18:42:55 -05007#include <ndn-cxx/face.hpp>
8#include <ndn-cxx/security/key-chain.hpp>
9#include <ndn-cxx/util/scheduler.hpp>
akmhoque298385a2014-02-13 14:13:09 -060010
akmhoque53353462014-04-22 08:43:45 -050011#include "conf-parameter.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050012#include "adjacency-list.hpp"
13#include "name-prefix-list.hpp"
akmhoque53353462014-04-22 08:43:45 -050014#include "lsdb.hpp"
15#include "sequencing-manager.hpp"
16#include "route/routing-table.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050017#include "route/name-prefix-table.hpp"
akmhoque53353462014-04-22 08:43:45 -050018#include "route/fib.hpp"
akmhoque53353462014-04-22 08:43:45 -050019#include "communication/sync-logic-handler.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050020#include "hello-protocol.hpp"
akmhoque2bb198e2014-02-28 11:46:27 -060021
22
akmhoque53353462014-04-22 08:43:45 -050023namespace nlsr {
24
akmhoque53353462014-04-22 08:43:45 -050025class Nlsr
26{
akmhoquefdbddb12014-05-02 18:35:19 -050027 class Error : public std::runtime_error
28 {
29 public:
30 explicit
31 Error(const std::string& what)
32 : std::runtime_error(what)
33 {
34 }
35 };
36
akmhoque53353462014-04-22 08:43:45 -050037public:
38 Nlsr()
akmhoquefdbddb12014-05-02 18:35:19 -050039 : m_scheduler(m_nlsrFace.getIoService())
akmhoque53353462014-04-22 08:43:45 -050040 , m_confParam()
akmhoquec8a10f72014-04-25 18:42:55 -050041 , m_adjacencyList()
42 , m_namePrefixList()
akmhoquec8a10f72014-04-25 18:42:55 -050043 , m_sequencingManager()
akmhoque53353462014-04-22 08:43:45 -050044 , m_isDaemonProcess(false)
45 , m_configFileName("nlsr.conf")
akmhoque31d1d4b2014-05-05 22:08:14 -050046 , m_nlsrLsdb(*this)
akmhoque53353462014-04-22 08:43:45 -050047 , m_adjBuildCount(0)
48 , m_isBuildAdjLsaSheduled(false)
49 , m_isRouteCalculationScheduled(false)
50 , m_isRoutingTableCalculating(false)
51 , m_routingTable()
akmhoque31d1d4b2014-05-05 22:08:14 -050052 , m_fib(*this, m_nlsrFace)
53 , m_namePrefixTable(*this)
akmhoquefdbddb12014-05-02 18:35:19 -050054 , m_syncLogicHandler(m_nlsrFace.getIoService())
akmhoque31d1d4b2014-05-05 22:08:14 -050055 , m_helloProtocol(*this)
akmhoque53353462014-04-22 08:43:45 -050056 {}
akmhoque298385a2014-02-13 14:13:09 -060057
akmhoque53353462014-04-22 08:43:45 -050058 void
59 registrationFailed(const ndn::Name& name);
60
61 void
akmhoque157b0a42014-05-13 00:26:37 -050062 onRegistrationSuccess(const ndn::Name& name);
63
64 void
akmhoque31d1d4b2014-05-05 22:08:14 -050065 setInfoInterestFilter();
66
67 void
68 setLsaInterestFilter();
akmhoque53353462014-04-22 08:43:45 -050069
70 void
71 startEventLoop();
72
akmhoquefdbddb12014-05-02 18:35:19 -050073 void
74 usage(const std::string& progname);
akmhoque53353462014-04-22 08:43:45 -050075
76 std::string
akmhoquefdbddb12014-05-02 18:35:19 -050077 getConfFileName() const
Yingdi Yu40cd1c32014-04-17 15:02:17 -070078 {
akmhoque53353462014-04-22 08:43:45 -050079 return m_configFileName;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070080 }
81
akmhoque53353462014-04-22 08:43:45 -050082 void
akmhoquefdbddb12014-05-02 18:35:19 -050083 setConfFileName(const std::string& fileName)
akmhoque5a44dd42014-03-12 18:11:32 -050084 {
akmhoque53353462014-04-22 08:43:45 -050085 m_configFileName = fileName;
86 }
akmhoque5a44dd42014-03-12 18:11:32 -050087
akmhoque53353462014-04-22 08:43:45 -050088 bool
89 getIsSetDaemonProcess()
90 {
91 return m_isDaemonProcess;
92 }
akmhoque5a44dd42014-03-12 18:11:32 -050093
akmhoque53353462014-04-22 08:43:45 -050094 void
95 setIsDaemonProcess(bool value)
96 {
97 m_isDaemonProcess = value;
98 }
akmhoque5a44dd42014-03-12 18:11:32 -050099
akmhoque53353462014-04-22 08:43:45 -0500100 ConfParameter&
101 getConfParameter()
102 {
103 return m_confParam;
104 }
akmhoque5a44dd42014-03-12 18:11:32 -0500105
akmhoquec8a10f72014-04-25 18:42:55 -0500106 AdjacencyList&
107 getAdjacencyList()
akmhoque53353462014-04-22 08:43:45 -0500108 {
akmhoquec8a10f72014-04-25 18:42:55 -0500109 return m_adjacencyList;
akmhoque53353462014-04-22 08:43:45 -0500110 }
akmhoque298385a2014-02-13 14:13:09 -0600111
akmhoquec8a10f72014-04-25 18:42:55 -0500112 NamePrefixList&
113 getNamePrefixList()
akmhoque53353462014-04-22 08:43:45 -0500114 {
akmhoquec8a10f72014-04-25 18:42:55 -0500115 return m_namePrefixList;
akmhoque53353462014-04-22 08:43:45 -0500116 }
akmhoque298385a2014-02-13 14:13:09 -0600117
akmhoque53353462014-04-22 08:43:45 -0500118 ndn::Scheduler&
119 getScheduler()
120 {
121 return m_scheduler;
122 }
akmhoque298385a2014-02-13 14:13:09 -0600123
akmhoquefdbddb12014-05-02 18:35:19 -0500124 ndn::Face&
akmhoque53353462014-04-22 08:43:45 -0500125 getNlsrFace()
126 {
127 return m_nlsrFace;
128 }
akmhoque298385a2014-02-13 14:13:09 -0600129
akmhoque53353462014-04-22 08:43:45 -0500130 SequencingManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500131 getSequencingManager()
akmhoque53353462014-04-22 08:43:45 -0500132 {
akmhoquec8a10f72014-04-25 18:42:55 -0500133 return m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500134 }
akmhoque298385a2014-02-13 14:13:09 -0600135
akmhoque53353462014-04-22 08:43:45 -0500136 Lsdb&
137 getLsdb()
138 {
139 return m_nlsrLsdb;
140 }
akmhoque298385a2014-02-13 14:13:09 -0600141
akmhoque53353462014-04-22 08:43:45 -0500142 RoutingTable&
143 getRoutingTable()
144 {
145 return m_routingTable;
146 }
akmhoque298385a2014-02-13 14:13:09 -0600147
akmhoquec8a10f72014-04-25 18:42:55 -0500148 NamePrefixTable&
149 getNamePrefixTable()
akmhoque53353462014-04-22 08:43:45 -0500150 {
akmhoquec8a10f72014-04-25 18:42:55 -0500151 return m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500152 }
akmhoque298385a2014-02-13 14:13:09 -0600153
akmhoque53353462014-04-22 08:43:45 -0500154 Fib&
155 getFib()
156 {
157 return m_fib;
158 }
akmhoque298385a2014-02-13 14:13:09 -0600159
akmhoque53353462014-04-22 08:43:45 -0500160 long int
161 getAdjBuildCount()
162 {
163 return m_adjBuildCount;
164 }
akmhoque298385a2014-02-13 14:13:09 -0600165
akmhoque53353462014-04-22 08:43:45 -0500166 void
167 incrementAdjBuildCount()
168 {
169 m_adjBuildCount++;
170 }
akmhoque298385a2014-02-13 14:13:09 -0600171
akmhoque53353462014-04-22 08:43:45 -0500172 void
akmhoquefdbddb12014-05-02 18:35:19 -0500173 setAdjBuildCount(int64_t abc)
akmhoque53353462014-04-22 08:43:45 -0500174 {
175 m_adjBuildCount = abc;
176 }
akmhoque298385a2014-02-13 14:13:09 -0600177
akmhoque157b0a42014-05-13 00:26:37 -0500178 bool
akmhoque53353462014-04-22 08:43:45 -0500179 getIsBuildAdjLsaSheduled()
180 {
181 return m_isBuildAdjLsaSheduled;
182 }
akmhoque298385a2014-02-13 14:13:09 -0600183
akmhoque53353462014-04-22 08:43:45 -0500184 void
185 setIsBuildAdjLsaSheduled(bool iabls)
186 {
187 m_isBuildAdjLsaSheduled = iabls;
188 }
akmhoque298385a2014-02-13 14:13:09 -0600189
akmhoque298385a2014-02-13 14:13:09 -0600190
akmhoque53353462014-04-22 08:43:45 -0500191 void
akmhoquefdbddb12014-05-02 18:35:19 -0500192 setApiPort(int32_t ap)
akmhoque53353462014-04-22 08:43:45 -0500193 {
194 m_apiPort = ap;
195 }
akmhoque298385a2014-02-13 14:13:09 -0600196
akmhoquefdbddb12014-05-02 18:35:19 -0500197 int32_t
akmhoque53353462014-04-22 08:43:45 -0500198 getApiPort()
199 {
200 return m_apiPort;
201 }
akmhoque298385a2014-02-13 14:13:09 -0600202
akmhoque53353462014-04-22 08:43:45 -0500203 bool
204 getIsRoutingTableCalculating()
205 {
206 return m_isRoutingTableCalculating;
207 }
akmhoque85d88332014-02-17 21:11:21 -0600208
akmhoque53353462014-04-22 08:43:45 -0500209 void
210 setIsRoutingTableCalculating(bool irtc)
211 {
212 m_isRoutingTableCalculating = irtc;
213 }
akmhoque298385a2014-02-13 14:13:09 -0600214
akmhoque53353462014-04-22 08:43:45 -0500215 bool
216 getIsRouteCalculationScheduled()
217 {
218 return m_isRouteCalculationScheduled;
219 }
akmhoque298385a2014-02-13 14:13:09 -0600220
akmhoque53353462014-04-22 08:43:45 -0500221 void
222 setIsRouteCalculationScheduled(bool ircs)
223 {
224 m_isRouteCalculationScheduled = ircs;
225 }
akmhoque298385a2014-02-13 14:13:09 -0600226
akmhoque53353462014-04-22 08:43:45 -0500227 SyncLogicHandler&
akmhoquec8a10f72014-04-25 18:42:55 -0500228 getSyncLogicHandler()
akmhoque53353462014-04-22 08:43:45 -0500229 {
akmhoquec8a10f72014-04-25 18:42:55 -0500230 return m_syncLogicHandler;
akmhoque53353462014-04-22 08:43:45 -0500231 }
akmhoque2bb198e2014-02-28 11:46:27 -0600232
akmhoque53353462014-04-22 08:43:45 -0500233 void
234 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600235
akmhoque53353462014-04-22 08:43:45 -0500236private:
akmhoque157b0a42014-05-13 00:26:37 -0500237 void
238 registerPrefixes();
239
240private:
akmhoquefdbddb12014-05-02 18:35:19 -0500241 ndn::Face m_nlsrFace;
akmhoque53353462014-04-22 08:43:45 -0500242 ndn::Scheduler m_scheduler;
243 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500244 AdjacencyList m_adjacencyList;
245 NamePrefixList m_namePrefixList;
akmhoquec8a10f72014-04-25 18:42:55 -0500246 SequencingManager m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500247 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500248 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500249 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500250 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500251 bool m_isBuildAdjLsaSheduled;
252 bool m_isRouteCalculationScheduled;
253 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500254 RoutingTable m_routingTable;
akmhoque53353462014-04-22 08:43:45 -0500255 Fib m_fib;
akmhoque31d1d4b2014-05-05 22:08:14 -0500256 NamePrefixTable m_namePrefixTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500257 SyncLogicHandler m_syncLogicHandler;
akmhoquefdbddb12014-05-02 18:35:19 -0500258 int32_t m_apiPort;
akmhoque31d1d4b2014-05-05 22:08:14 -0500259 HelloProtocol m_helloProtocol;
akmhoque53353462014-04-22 08:43:45 -0500260};
akmhoque298385a2014-02-13 14:13:09 -0600261
akmhoqueb1710aa2014-02-19 17:13:36 -0600262} //namespace nlsr
263
akmhoque53353462014-04-22 08:43:45 -0500264#endif //NLSR_HPP