blob: 6bf45bd0b34f67aacc0d57631df4fff70836e820 [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
akmhoque31d1d4b2014-05-05 22:08:14 -050062 setInfoInterestFilter();
63
64 void
65 setLsaInterestFilter();
akmhoque53353462014-04-22 08:43:45 -050066
67 void
68 startEventLoop();
69
akmhoquefdbddb12014-05-02 18:35:19 -050070 void
71 usage(const std::string& progname);
akmhoque53353462014-04-22 08:43:45 -050072
73 std::string
akmhoquefdbddb12014-05-02 18:35:19 -050074 getConfFileName() const
Yingdi Yu40cd1c32014-04-17 15:02:17 -070075 {
akmhoque53353462014-04-22 08:43:45 -050076 return m_configFileName;
Yingdi Yu40cd1c32014-04-17 15:02:17 -070077 }
78
akmhoque53353462014-04-22 08:43:45 -050079 void
akmhoquefdbddb12014-05-02 18:35:19 -050080 setConfFileName(const std::string& fileName)
akmhoque5a44dd42014-03-12 18:11:32 -050081 {
akmhoque53353462014-04-22 08:43:45 -050082 m_configFileName = fileName;
83 }
akmhoque5a44dd42014-03-12 18:11:32 -050084
akmhoque53353462014-04-22 08:43:45 -050085 bool
86 getIsSetDaemonProcess()
87 {
88 return m_isDaemonProcess;
89 }
akmhoque5a44dd42014-03-12 18:11:32 -050090
akmhoque53353462014-04-22 08:43:45 -050091 void
92 setIsDaemonProcess(bool value)
93 {
94 m_isDaemonProcess = value;
95 }
akmhoque5a44dd42014-03-12 18:11:32 -050096
akmhoque53353462014-04-22 08:43:45 -050097 ConfParameter&
98 getConfParameter()
99 {
100 return m_confParam;
101 }
akmhoque5a44dd42014-03-12 18:11:32 -0500102
akmhoquec8a10f72014-04-25 18:42:55 -0500103 AdjacencyList&
104 getAdjacencyList()
akmhoque53353462014-04-22 08:43:45 -0500105 {
akmhoquec8a10f72014-04-25 18:42:55 -0500106 return m_adjacencyList;
akmhoque53353462014-04-22 08:43:45 -0500107 }
akmhoque298385a2014-02-13 14:13:09 -0600108
akmhoquec8a10f72014-04-25 18:42:55 -0500109 NamePrefixList&
110 getNamePrefixList()
akmhoque53353462014-04-22 08:43:45 -0500111 {
akmhoquec8a10f72014-04-25 18:42:55 -0500112 return m_namePrefixList;
akmhoque53353462014-04-22 08:43:45 -0500113 }
akmhoque298385a2014-02-13 14:13:09 -0600114
akmhoque53353462014-04-22 08:43:45 -0500115 ndn::Scheduler&
116 getScheduler()
117 {
118 return m_scheduler;
119 }
akmhoque298385a2014-02-13 14:13:09 -0600120
akmhoquefdbddb12014-05-02 18:35:19 -0500121 ndn::Face&
akmhoque53353462014-04-22 08:43:45 -0500122 getNlsrFace()
123 {
124 return m_nlsrFace;
125 }
akmhoque298385a2014-02-13 14:13:09 -0600126
akmhoque53353462014-04-22 08:43:45 -0500127 SequencingManager&
akmhoquec8a10f72014-04-25 18:42:55 -0500128 getSequencingManager()
akmhoque53353462014-04-22 08:43:45 -0500129 {
akmhoquec8a10f72014-04-25 18:42:55 -0500130 return m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500131 }
akmhoque298385a2014-02-13 14:13:09 -0600132
akmhoque53353462014-04-22 08:43:45 -0500133 Lsdb&
134 getLsdb()
135 {
136 return m_nlsrLsdb;
137 }
akmhoque298385a2014-02-13 14:13:09 -0600138
akmhoque53353462014-04-22 08:43:45 -0500139 RoutingTable&
140 getRoutingTable()
141 {
142 return m_routingTable;
143 }
akmhoque298385a2014-02-13 14:13:09 -0600144
akmhoquec8a10f72014-04-25 18:42:55 -0500145 NamePrefixTable&
146 getNamePrefixTable()
akmhoque53353462014-04-22 08:43:45 -0500147 {
akmhoquec8a10f72014-04-25 18:42:55 -0500148 return m_namePrefixTable;
akmhoque53353462014-04-22 08:43:45 -0500149 }
akmhoque298385a2014-02-13 14:13:09 -0600150
akmhoque53353462014-04-22 08:43:45 -0500151 Fib&
152 getFib()
153 {
154 return m_fib;
155 }
akmhoque298385a2014-02-13 14:13:09 -0600156
akmhoque53353462014-04-22 08:43:45 -0500157 long int
158 getAdjBuildCount()
159 {
160 return m_adjBuildCount;
161 }
akmhoque298385a2014-02-13 14:13:09 -0600162
akmhoque53353462014-04-22 08:43:45 -0500163 void
164 incrementAdjBuildCount()
165 {
166 m_adjBuildCount++;
167 }
akmhoque298385a2014-02-13 14:13:09 -0600168
akmhoque53353462014-04-22 08:43:45 -0500169 void
akmhoquefdbddb12014-05-02 18:35:19 -0500170 setAdjBuildCount(int64_t abc)
akmhoque53353462014-04-22 08:43:45 -0500171 {
172 m_adjBuildCount = abc;
173 }
akmhoque298385a2014-02-13 14:13:09 -0600174
akmhoque53353462014-04-22 08:43:45 -0500175 int
176 getIsBuildAdjLsaSheduled()
177 {
178 return m_isBuildAdjLsaSheduled;
179 }
akmhoque298385a2014-02-13 14:13:09 -0600180
akmhoque53353462014-04-22 08:43:45 -0500181 void
182 setIsBuildAdjLsaSheduled(bool iabls)
183 {
184 m_isBuildAdjLsaSheduled = iabls;
185 }
akmhoque298385a2014-02-13 14:13:09 -0600186
akmhoque298385a2014-02-13 14:13:09 -0600187
akmhoque53353462014-04-22 08:43:45 -0500188 void
akmhoquefdbddb12014-05-02 18:35:19 -0500189 setApiPort(int32_t ap)
akmhoque53353462014-04-22 08:43:45 -0500190 {
191 m_apiPort = ap;
192 }
akmhoque298385a2014-02-13 14:13:09 -0600193
akmhoquefdbddb12014-05-02 18:35:19 -0500194 int32_t
akmhoque53353462014-04-22 08:43:45 -0500195 getApiPort()
196 {
197 return m_apiPort;
198 }
akmhoque298385a2014-02-13 14:13:09 -0600199
akmhoque53353462014-04-22 08:43:45 -0500200 bool
201 getIsRoutingTableCalculating()
202 {
203 return m_isRoutingTableCalculating;
204 }
akmhoque85d88332014-02-17 21:11:21 -0600205
akmhoque53353462014-04-22 08:43:45 -0500206 void
207 setIsRoutingTableCalculating(bool irtc)
208 {
209 m_isRoutingTableCalculating = irtc;
210 }
akmhoque298385a2014-02-13 14:13:09 -0600211
akmhoque53353462014-04-22 08:43:45 -0500212 bool
213 getIsRouteCalculationScheduled()
214 {
215 return m_isRouteCalculationScheduled;
216 }
akmhoque298385a2014-02-13 14:13:09 -0600217
akmhoque53353462014-04-22 08:43:45 -0500218 void
219 setIsRouteCalculationScheduled(bool ircs)
220 {
221 m_isRouteCalculationScheduled = ircs;
222 }
akmhoque298385a2014-02-13 14:13:09 -0600223
akmhoque53353462014-04-22 08:43:45 -0500224 SyncLogicHandler&
akmhoquec8a10f72014-04-25 18:42:55 -0500225 getSyncLogicHandler()
akmhoque53353462014-04-22 08:43:45 -0500226 {
akmhoquec8a10f72014-04-25 18:42:55 -0500227 return m_syncLogicHandler;
akmhoque53353462014-04-22 08:43:45 -0500228 }
akmhoque2bb198e2014-02-28 11:46:27 -0600229
akmhoque53353462014-04-22 08:43:45 -0500230 void
231 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600232
akmhoque53353462014-04-22 08:43:45 -0500233private:
akmhoquefdbddb12014-05-02 18:35:19 -0500234 ndn::Face m_nlsrFace;
akmhoque53353462014-04-22 08:43:45 -0500235 ndn::Scheduler m_scheduler;
236 ConfParameter m_confParam;
akmhoquec8a10f72014-04-25 18:42:55 -0500237 AdjacencyList m_adjacencyList;
238 NamePrefixList m_namePrefixList;
akmhoquec8a10f72014-04-25 18:42:55 -0500239 SequencingManager m_sequencingManager;
akmhoque53353462014-04-22 08:43:45 -0500240 bool m_isDaemonProcess;
akmhoquefdbddb12014-05-02 18:35:19 -0500241 std::string m_configFileName;
akmhoque53353462014-04-22 08:43:45 -0500242 Lsdb m_nlsrLsdb;
akmhoquefdbddb12014-05-02 18:35:19 -0500243 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500244 bool m_isBuildAdjLsaSheduled;
245 bool m_isRouteCalculationScheduled;
246 bool m_isRoutingTableCalculating;
akmhoque53353462014-04-22 08:43:45 -0500247 RoutingTable m_routingTable;
akmhoque53353462014-04-22 08:43:45 -0500248 Fib m_fib;
akmhoque31d1d4b2014-05-05 22:08:14 -0500249 NamePrefixTable m_namePrefixTable;
akmhoquec8a10f72014-04-25 18:42:55 -0500250 SyncLogicHandler m_syncLogicHandler;
akmhoquefdbddb12014-05-02 18:35:19 -0500251 int32_t m_apiPort;
akmhoque31d1d4b2014-05-05 22:08:14 -0500252 HelloProtocol m_helloProtocol;
akmhoque53353462014-04-22 08:43:45 -0500253};
akmhoque298385a2014-02-13 14:13:09 -0600254
akmhoqueb1710aa2014-02-19 17:13:36 -0600255} //namespace nlsr
256
akmhoque53353462014-04-22 08:43:45 -0500257#endif //NLSR_HPP