blob: 0e59adcbcf1ffa211f91020a0b9c9a15b53c6b18 [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 "communication/interest-manager.hpp"
15#include "communication/data-manager.hpp"
16#include "lsdb.hpp"
17#include "sequencing-manager.hpp"
18#include "route/routing-table.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050019#include "route/name-prefix-table.hpp"
akmhoque53353462014-04-22 08:43:45 -050020#include "route/fib.hpp"
Yingdi Yu0c217822014-04-24 14:22:42 -070021// #include "security/key-manager.hpp"
akmhoque53353462014-04-22 08:43:45 -050022#include "communication/sync-logic-handler.hpp"
akmhoque2bb198e2014-02-28 11:46:27 -060023
24
akmhoque53353462014-04-22 08:43:45 -050025namespace nlsr {
26
akmhoque53353462014-04-22 08:43:45 -050027class Nlsr
28{
akmhoquefdbddb12014-05-02 18:35:19 -050029 class Error : public std::runtime_error
30 {
31 public:
32 explicit
33 Error(const std::string& what)
34 : std::runtime_error(what)
35 {
36 }
37 };
38
akmhoque53353462014-04-22 08:43:45 -050039public:
40 Nlsr()
akmhoquefdbddb12014-05-02 18:35:19 -050041 : m_scheduler(m_nlsrFace.getIoService())
akmhoque53353462014-04-22 08:43:45 -050042 , m_confParam()
akmhoquec8a10f72014-04-25 18:42:55 -050043 , m_adjacencyList()
44 , m_namePrefixList()
45 , m_interestManager(*this)
46 , m_dataManager(*this)
47 , m_sequencingManager()
Yingdi Yu0c217822014-04-24 14:22:42 -070048 // , m_km()
akmhoque53353462014-04-22 08:43:45 -050049 , m_isDaemonProcess(false)
50 , m_configFileName("nlsr.conf")
51 , m_nlsrLsdb()
52 , m_adjBuildCount(0)
53 , m_isBuildAdjLsaSheduled(false)
54 , m_isRouteCalculationScheduled(false)
55 , m_isRoutingTableCalculating(false)
56 , m_routingTable()
akmhoquec8a10f72014-04-25 18:42:55 -050057 , m_namePrefixTable()
akmhoquefdbddb12014-05-02 18:35:19 -050058 , m_fib(m_nlsrFace)
59 , m_syncLogicHandler(m_nlsrFace.getIoService())
akmhoque53353462014-04-22 08:43:45 -050060 {}
akmhoque298385a2014-02-13 14:13:09 -060061
akmhoque53353462014-04-22 08:43:45 -050062 void
63 registrationFailed(const ndn::Name& name);
64
65 void
akmhoquefdbddb12014-05-02 18:35:19 -050066 setInterestFilter(const std::string& name);
akmhoque53353462014-04-22 08:43:45 -050067
68 void
69 startEventLoop();
70
akmhoquefdbddb12014-05-02 18:35:19 -050071 void
72 usage(const std::string& progname);
akmhoque53353462014-04-22 08:43:45 -050073
74 std::string
akmhoquefdbddb12014-05-02 18:35:19 -050075 getConfFileName() const
Yingdi Yu40cd1c32014-04-17 15:02:17 -070076 {
akmhoque53353462014-04-22 08:43:45 -050077 return m_configFileName;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070078 }
79
akmhoque53353462014-04-22 08:43:45 -050080 void
akmhoquefdbddb12014-05-02 18:35:19 -050081 setConfFileName(const std::string& fileName)
akmhoque5a44dd42014-03-12 18:11:32 -050082 {
akmhoque53353462014-04-22 08:43:45 -050083 m_configFileName = fileName;
84 }
akmhoque5a44dd42014-03-12 18:11:32 -050085
akmhoque53353462014-04-22 08:43:45 -050086 bool
87 getIsSetDaemonProcess()
88 {
89 return m_isDaemonProcess;
90 }
akmhoque5a44dd42014-03-12 18:11:32 -050091
akmhoque53353462014-04-22 08:43:45 -050092 void
93 setIsDaemonProcess(bool value)
94 {
95 m_isDaemonProcess = value;
96 }
akmhoque5a44dd42014-03-12 18:11:32 -050097
akmhoque53353462014-04-22 08:43:45 -050098 ConfParameter&
99 getConfParameter()
100 {
101 return m_confParam;
102 }
akmhoque5a44dd42014-03-12 18:11:32 -0500103
akmhoquec8a10f72014-04-25 18:42:55 -0500104 AdjacencyList&
105 getAdjacencyList()
akmhoque53353462014-04-22 08:43:45 -0500106 {
akmhoquec8a10f72014-04-25 18:42:55 -0500107 return m_adjacencyList;
akmhoque53353462014-04-22 08:43:45 -0500108 }
akmhoque298385a2014-02-13 14:13:09 -0600109
akmhoquec8a10f72014-04-25 18:42:55 -0500110 NamePrefixList&
111 getNamePrefixList()
akmhoque53353462014-04-22 08:43:45 -0500112 {
akmhoquec8a10f72014-04-25 18:42:55 -0500113 return m_namePrefixList;
akmhoque53353462014-04-22 08:43:45 -0500114 }
akmhoque298385a2014-02-13 14:13:09 -0600115
akmhoque53353462014-04-22 08:43:45 -0500116 ndn::Scheduler&
117 getScheduler()
118 {
119 return m_scheduler;
120 }
akmhoque298385a2014-02-13 14:13:09 -0600121
akmhoquefdbddb12014-05-02 18:35:19 -0500122 ndn::Face&
akmhoque53353462014-04-22 08:43:45 -0500123 getNlsrFace()
124 {
125 return m_nlsrFace;
126 }
akmhoque298385a2014-02-13 14:13:09 -0600127
Yingdi Yu0c217822014-04-24 14:22:42 -0700128 // KeyManager&
129 // getKeyManager()
130 // {
131 // return m_km;
132 // }
akmhoque298385a2014-02-13 14:13:09 -0600133
akmhoque66e66182014-02-21 17:56:03 -0600134
akmhoque53353462014-04-22 08:43:45 -0500135 InterestManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500136 getInterestManager()
akmhoque53353462014-04-22 08:43:45 -0500137 {
akmhoquec8a10f72014-04-25 18:42:55 -0500138 return m_interestManager;
akmhoque53353462014-04-22 08:43:45 -0500139 }
akmhoque298385a2014-02-13 14:13:09 -0600140
akmhoque53353462014-04-22 08:43:45 -0500141 DataManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500142 getDataManager()
akmhoque53353462014-04-22 08:43:45 -0500143 {
akmhoquec8a10f72014-04-25 18:42:55 -0500144 return m_dataManager;
akmhoque53353462014-04-22 08:43:45 -0500145 }
akmhoque298385a2014-02-13 14:13:09 -0600146
akmhoque53353462014-04-22 08:43:45 -0500147 SequencingManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500148 getSequencingManager()
akmhoque53353462014-04-22 08:43:45 -0500149 {
akmhoquec8a10f72014-04-25 18:42:55 -0500150 return m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500151 }
akmhoque298385a2014-02-13 14:13:09 -0600152
akmhoque53353462014-04-22 08:43:45 -0500153 Lsdb&
154 getLsdb()
155 {
156 return m_nlsrLsdb;
157 }
akmhoque298385a2014-02-13 14:13:09 -0600158
akmhoque53353462014-04-22 08:43:45 -0500159 RoutingTable&
160 getRoutingTable()
161 {
162 return m_routingTable;
163 }
akmhoque298385a2014-02-13 14:13:09 -0600164
akmhoquec8a10f72014-04-25 18:42:55 -0500165 NamePrefixTable&
166 getNamePrefixTable()
akmhoque53353462014-04-22 08:43:45 -0500167 {
akmhoquec8a10f72014-04-25 18:42:55 -0500168 return m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500169 }
akmhoque298385a2014-02-13 14:13:09 -0600170
akmhoque53353462014-04-22 08:43:45 -0500171 Fib&
172 getFib()
173 {
174 return m_fib;
175 }
akmhoque298385a2014-02-13 14:13:09 -0600176
akmhoque53353462014-04-22 08:43:45 -0500177 long int
178 getAdjBuildCount()
179 {
180 return m_adjBuildCount;
181 }
akmhoque298385a2014-02-13 14:13:09 -0600182
akmhoque53353462014-04-22 08:43:45 -0500183 void
184 incrementAdjBuildCount()
185 {
186 m_adjBuildCount++;
187 }
akmhoque298385a2014-02-13 14:13:09 -0600188
akmhoque53353462014-04-22 08:43:45 -0500189 void
akmhoquefdbddb12014-05-02 18:35:19 -0500190 setAdjBuildCount(int64_t abc)
akmhoque53353462014-04-22 08:43:45 -0500191 {
192 m_adjBuildCount = abc;
193 }
akmhoque298385a2014-02-13 14:13:09 -0600194
akmhoque53353462014-04-22 08:43:45 -0500195 int
196 getIsBuildAdjLsaSheduled()
197 {
198 return m_isBuildAdjLsaSheduled;
199 }
akmhoque298385a2014-02-13 14:13:09 -0600200
akmhoque53353462014-04-22 08:43:45 -0500201 void
202 setIsBuildAdjLsaSheduled(bool iabls)
203 {
204 m_isBuildAdjLsaSheduled = iabls;
205 }
akmhoque298385a2014-02-13 14:13:09 -0600206
akmhoque298385a2014-02-13 14:13:09 -0600207
akmhoque53353462014-04-22 08:43:45 -0500208 void
akmhoquefdbddb12014-05-02 18:35:19 -0500209 setApiPort(int32_t ap)
akmhoque53353462014-04-22 08:43:45 -0500210 {
211 m_apiPort = ap;
212 }
akmhoque298385a2014-02-13 14:13:09 -0600213
akmhoquefdbddb12014-05-02 18:35:19 -0500214 int32_t
akmhoque53353462014-04-22 08:43:45 -0500215 getApiPort()
216 {
217 return m_apiPort;
218 }
akmhoque298385a2014-02-13 14:13:09 -0600219
akmhoque53353462014-04-22 08:43:45 -0500220 bool
221 getIsRoutingTableCalculating()
222 {
223 return m_isRoutingTableCalculating;
224 }
akmhoque85d88332014-02-17 21:11:21 -0600225
akmhoque53353462014-04-22 08:43:45 -0500226 void
227 setIsRoutingTableCalculating(bool irtc)
228 {
229 m_isRoutingTableCalculating = irtc;
230 }
akmhoque298385a2014-02-13 14:13:09 -0600231
akmhoque53353462014-04-22 08:43:45 -0500232 bool
233 getIsRouteCalculationScheduled()
234 {
235 return m_isRouteCalculationScheduled;
236 }
akmhoque298385a2014-02-13 14:13:09 -0600237
akmhoque53353462014-04-22 08:43:45 -0500238 void
239 setIsRouteCalculationScheduled(bool ircs)
240 {
241 m_isRouteCalculationScheduled = ircs;
242 }
akmhoque298385a2014-02-13 14:13:09 -0600243
akmhoque53353462014-04-22 08:43:45 -0500244 SyncLogicHandler&
akmhoquec8a10f72014-04-25 18:42:55 -0500245 getSyncLogicHandler()
akmhoque53353462014-04-22 08:43:45 -0500246 {
akmhoquec8a10f72014-04-25 18:42:55 -0500247 return m_syncLogicHandler;
akmhoque53353462014-04-22 08:43:45 -0500248 }
akmhoque2bb198e2014-02-28 11:46:27 -0600249
akmhoque53353462014-04-22 08:43:45 -0500250 void
251 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600252
akmhoque53353462014-04-22 08:43:45 -0500253private:
akmhoquefdbddb12014-05-02 18:35:19 -0500254 ndn::Face m_nlsrFace;
akmhoque53353462014-04-22 08:43:45 -0500255 ndn::Scheduler m_scheduler;
256 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500257 AdjacencyList m_adjacencyList;
258 NamePrefixList m_namePrefixList;
259 InterestManager m_interestManager;
260 DataManager m_dataManager;
261 SequencingManager m_sequencingManager;
Yingdi Yu0c217822014-04-24 14:22:42 -0700262 // KeyManager m_km;
akmhoque53353462014-04-22 08:43:45 -0500263 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500264 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500265 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500266 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500267 bool m_isBuildAdjLsaSheduled;
268 bool m_isRouteCalculationScheduled;
269 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500270 RoutingTable m_routingTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500271 NamePrefixTable m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500272 Fib m_fib;
akmhoquec8a10f72014-04-25 18:42:55 -0500273 SyncLogicHandler m_syncLogicHandler;
akmhoquefdbddb12014-05-02 18:35:19 -0500274 int32_t m_apiPort;
akmhoque53353462014-04-22 08:43:45 -0500275};
akmhoque298385a2014-02-13 14:13:09 -0600276
akmhoqueb1710aa2014-02-19 17:13:36 -0600277} //namespace nlsr
278
akmhoque53353462014-04-22 08:43:45 -0500279#endif //NLSR_HPP