blob: 0945a658adb5f6d7b5c0c6e6c20dfbb2a98f915a [file] [log] [blame]
akmhoquefdbddb12014-05-02 18:35:19 -05001#ifndef CONF_PARAMETER_HPP
2#define CONF_PARAMETER_HPP
akmhoque53353462014-04-22 08:43:45 -05003
4#include <iostream>
akmhoquefdbddb12014-05-02 18:35:19 -05005#include <boost/cstdint.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -05006#include <ndn-cxx/common.hpp>
7#include <ndn-cxx/face.hpp>
akmhoque53353462014-04-22 08:43:45 -05008
akmhoque674b0b12014-05-20 14:33:28 -05009#include "logger.hpp"
10
akmhoque53353462014-04-22 08:43:45 -050011namespace nlsr {
akmhoque157b0a42014-05-13 00:26:37 -050012
13enum {
14 LSA_REFRESH_TIME_MIN = 240,
15 LSA_REFRESH_TIME_DEFAULT = 1800,
16 LSA_REFRESH_TIME_MAX = 7200
17};
18
19enum {
20 HELLO_RETRIES_MIN = 1,
21 HELLO_RETRIES_DEFAULT = 3,
22 HELLO_RETRIES_MAX = 15
23};
24
25enum {
26 HELLO_TIMEOUT_MIN = 1,
27 HELLO_TIMEOUT_DEFAULT = 3,
28 HELLO_TIMEOUT_MAX = 15
29};
30
31enum {
32 HELLO_INTERVAL_MIN = 30,
33 HELLO_INTERVAL_DEFAULT = 60,
34 HELLO_INTERVAL_MAX =90
35};
36
37enum {
38 MAX_FACES_PER_PREFIX_MIN = 0,
39 MAX_FACES_PER_PREFIX_MAX = 60
40};
41
42enum {
43 HYPERBOLIC_STATE_OFF = 0,
44 HYPERBOLIC_STATE_ON = 1,
45 HYPERBOLIC_STATE_DRY_RUN = 2
46};
47
akmhoque53353462014-04-22 08:43:45 -050048class ConfParameter
49{
50
51public:
52 ConfParameter()
akmhoque157b0a42014-05-13 00:26:37 -050053 : m_lsaRefreshTime(LSA_REFRESH_TIME_DEFAULT)
54 , m_routerDeadInterval(2*LSA_REFRESH_TIME_DEFAULT)
55 , m_logLevel("INFO")
56 , m_interestRetryNumber(HELLO_RETRIES_DEFAULT)
57 , m_interestResendTime(HELLO_TIMEOUT_DEFAULT)
58 , m_infoInterestInterval(HELLO_INTERVAL_DEFAULT)
59 , m_hyperbolicState(HYPERBOLIC_STATE_OFF)
akmhoque53353462014-04-22 08:43:45 -050060 , m_corR(0)
61 , m_corTheta(0)
akmhoque157b0a42014-05-13 00:26:37 -050062 , m_maxFacesPerPrefix(MAX_FACES_PER_PREFIX_MIN)
akmhoque53353462014-04-22 08:43:45 -050063 {}
64
65 void
akmhoque157b0a42014-05-13 00:26:37 -050066 setNetwork(const ndn::Name& networkName)
akmhoque53353462014-04-22 08:43:45 -050067 {
akmhoque157b0a42014-05-13 00:26:37 -050068 m_network = networkName;
69 m_chronosyncPrefix = m_network;
70 m_chronosyncPrefix.append("nlsr");
71 m_chronosyncPrefix.append("sync");
72
73 m_lsaPrefix = m_network;
74 m_lsaPrefix.append("nlsr");
75 m_lsaPrefix.append("LSA");
akmhoque53353462014-04-22 08:43:45 -050076 }
77
akmhoque31d1d4b2014-05-05 22:08:14 -050078 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050079 getNetwork()
80 {
81 return m_network;
82 }
83
84 void
akmhoque157b0a42014-05-13 00:26:37 -050085 setRouterName(const ndn::Name& routerName)
86 {
87 m_routerName = routerName;
88 }
89
90 const ndn::Name&
91 getRouterName()
92 {
93 return m_routerName;
94 }
95
96 void
97 setSiteName(const ndn::Name& siteName)
98 {
99 m_siteName = siteName;
100 }
101
102 const ndn::Name&
103 getSiteName()
104 {
105 return m_siteName;
106 }
107
108 void
akmhoque53353462014-04-22 08:43:45 -0500109 buildRouterPrefix()
110 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500111 m_routerPrefix = m_network;
112 m_routerPrefix.append(m_siteName);
113 m_routerPrefix.append(m_routerName);
akmhoque53353462014-04-22 08:43:45 -0500114 }
115
akmhoque31d1d4b2014-05-05 22:08:14 -0500116 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -0500117 getRouterPrefix()
118 {
119 return m_routerPrefix;
120 }
121
akmhoque157b0a42014-05-13 00:26:37 -0500122
akmhoque31d1d4b2014-05-05 22:08:14 -0500123 const ndn::Name&
akmhoque157b0a42014-05-13 00:26:37 -0500124 getChronosyncPrefix()
akmhoque53353462014-04-22 08:43:45 -0500125 {
akmhoque157b0a42014-05-13 00:26:37 -0500126 return m_chronosyncPrefix;
akmhoque53353462014-04-22 08:43:45 -0500127 }
128
akmhoque157b0a42014-05-13 00:26:37 -0500129 const ndn::Name&
130 getLsaPrefix()
akmhoque53353462014-04-22 08:43:45 -0500131 {
akmhoque157b0a42014-05-13 00:26:37 -0500132 return m_lsaPrefix;
akmhoque53353462014-04-22 08:43:45 -0500133 }
134
135 void
akmhoquefdbddb12014-05-02 18:35:19 -0500136 setLsaRefreshTime(int32_t lrt)
akmhoque53353462014-04-22 08:43:45 -0500137 {
138 m_lsaRefreshTime = lrt;
139 m_routerDeadInterval = 2 * m_lsaRefreshTime;
140 }
141
akmhoquefdbddb12014-05-02 18:35:19 -0500142 int32_t
akmhoque53353462014-04-22 08:43:45 -0500143 getLsaRefreshTime()
144 {
145 return m_lsaRefreshTime;
146 }
147
148 void
akmhoquefdbddb12014-05-02 18:35:19 -0500149 setRouterDeadInterval(int64_t rdt)
akmhoque53353462014-04-22 08:43:45 -0500150 {
151 m_routerDeadInterval = rdt;
152 }
153
akmhoquefdbddb12014-05-02 18:35:19 -0500154 int64_t
akmhoque53353462014-04-22 08:43:45 -0500155 getRouterDeadInterval()
156 {
157 return m_routerDeadInterval;
158 }
akmhoque157b0a42014-05-13 00:26:37 -0500159
160 void
161 setLogLevel(const std::string& logLevel)
162 {
163 m_logLevel = logLevel;
164 }
165
166 const std::string&
167 getLogLevel()
168 {
169 return m_logLevel;
170 }
akmhoque53353462014-04-22 08:43:45 -0500171
172 void
akmhoque157b0a42014-05-13 00:26:37 -0500173 setInterestRetryNumber(uint32_t irn)
akmhoque53353462014-04-22 08:43:45 -0500174 {
akmhoque157b0a42014-05-13 00:26:37 -0500175 m_interestRetryNumber = irn;
176 }
177
178 uint32_t
179 getInterestRetryNumber()
180 {
181 return m_interestRetryNumber;
182 }
183
184 void
185 setInterestResendTime(int32_t irt)
186 {
187 m_interestResendTime = irt;
akmhoque53353462014-04-22 08:43:45 -0500188 }
189
akmhoquefdbddb12014-05-02 18:35:19 -0500190 int32_t
akmhoque157b0a42014-05-13 00:26:37 -0500191 getInterestResendTime()
akmhoque53353462014-04-22 08:43:45 -0500192 {
akmhoque157b0a42014-05-13 00:26:37 -0500193 return m_interestResendTime;
akmhoque53353462014-04-22 08:43:45 -0500194 }
195
akmhoquefdbddb12014-05-02 18:35:19 -0500196 int32_t
akmhoque157b0a42014-05-13 00:26:37 -0500197 getInfoInterestInterval()
akmhoque53353462014-04-22 08:43:45 -0500198 {
akmhoque157b0a42014-05-13 00:26:37 -0500199 return m_infoInterestInterval;
akmhoque53353462014-04-22 08:43:45 -0500200 }
201
202 void
akmhoque157b0a42014-05-13 00:26:37 -0500203 setInfoInterestInterval(int32_t iii)
akmhoque53353462014-04-22 08:43:45 -0500204 {
akmhoque157b0a42014-05-13 00:26:37 -0500205 m_infoInterestInterval = iii;
206 }
207
208 void
209 setHyperbolicState(int32_t ihc)
210 {
211 m_hyperbolicState = ihc;
akmhoque53353462014-04-22 08:43:45 -0500212 }
213
akmhoquefdbddb12014-05-02 18:35:19 -0500214 int32_t
akmhoque157b0a42014-05-13 00:26:37 -0500215 getHyperbolicState()
akmhoque53353462014-04-22 08:43:45 -0500216 {
akmhoque157b0a42014-05-13 00:26:37 -0500217 return m_hyperbolicState;
akmhoque53353462014-04-22 08:43:45 -0500218 }
219
akmhoque157b0a42014-05-13 00:26:37 -0500220 bool
akmhoque53353462014-04-22 08:43:45 -0500221 setCorR(double cr)
222 {
akmhoque157b0a42014-05-13 00:26:37 -0500223 if ( cr >= 0 ) {
224 m_corR = cr;
225 return true;
226 }
227 return false;
akmhoque53353462014-04-22 08:43:45 -0500228 }
229
230 double
231 getCorR()
232 {
233 return m_corR;
234 }
235
236 void
237 setCorTheta(double ct)
238 {
239 m_corTheta = ct;
240 }
241
242 double
243 getCorTheta()
244 {
245 return m_corTheta;
246 }
akmhoque157b0a42014-05-13 00:26:37 -0500247
akmhoque53353462014-04-22 08:43:45 -0500248 void
akmhoque157b0a42014-05-13 00:26:37 -0500249 setMaxFacesPerPrefix(int32_t mfpp)
akmhoque53353462014-04-22 08:43:45 -0500250 {
akmhoque157b0a42014-05-13 00:26:37 -0500251 m_maxFacesPerPrefix = mfpp;
akmhoque53353462014-04-22 08:43:45 -0500252 }
253
akmhoquefdbddb12014-05-02 18:35:19 -0500254 int32_t
akmhoque157b0a42014-05-13 00:26:37 -0500255 getMaxFacesPerPrefix()
akmhoque53353462014-04-22 08:43:45 -0500256 {
akmhoque157b0a42014-05-13 00:26:37 -0500257 return m_maxFacesPerPrefix;
akmhoque53353462014-04-22 08:43:45 -0500258 }
259
260 void
akmhoque674b0b12014-05-20 14:33:28 -0500261 setLogDir(const std::string& logDir)
262 {
263 m_logDir = logDir;
264 }
265
266 const std::string&
267 getLogDir()
268 {
269 return m_logDir;
270 }
271
272 void
akmhoque157b0a42014-05-13 00:26:37 -0500273 setSeqFileDir(const std::string& ssfd)
akmhoque53353462014-04-22 08:43:45 -0500274 {
akmhoque157b0a42014-05-13 00:26:37 -0500275 m_seqFileDir = ssfd;
akmhoque53353462014-04-22 08:43:45 -0500276 }
277
akmhoque157b0a42014-05-13 00:26:37 -0500278 const std::string&
279 getSeqFileDir()
akmhoque53353462014-04-22 08:43:45 -0500280 {
akmhoque157b0a42014-05-13 00:26:37 -0500281 return m_seqFileDir;
akmhoque53353462014-04-22 08:43:45 -0500282 }
283
akmhoque674b0b12014-05-20 14:33:28 -0500284 void
285 writeLog();
akmhoque53353462014-04-22 08:43:45 -0500286
287private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500288 ndn::Name m_routerName;
289 ndn::Name m_siteName;
290 ndn::Name m_network;
akmhoque53353462014-04-22 08:43:45 -0500291
akmhoque31d1d4b2014-05-05 22:08:14 -0500292 ndn::Name m_routerPrefix;
293 ndn::Name m_lsaRouterPrefix;
akmhoque53353462014-04-22 08:43:45 -0500294
akmhoque157b0a42014-05-13 00:26:37 -0500295 ndn::Name m_chronosyncPrefix;
296 ndn::Name m_lsaPrefix;
297
298 int32_t m_lsaRefreshTime;
299 int64_t m_routerDeadInterval;
300 std::string m_logLevel;
akmhoque53353462014-04-22 08:43:45 -0500301
akmhoquefdbddb12014-05-02 18:35:19 -0500302 uint32_t m_interestRetryNumber;
akmhoque157b0a42014-05-13 00:26:37 -0500303 int32_t m_interestResendTime;
304
305
306 int32_t m_infoInterestInterval;
307
308 int32_t m_hyperbolicState;
akmhoque53353462014-04-22 08:43:45 -0500309 double m_corR;
310 double m_corTheta;
311
akmhoque157b0a42014-05-13 00:26:37 -0500312 int32_t m_maxFacesPerPrefix;
313
akmhoque674b0b12014-05-20 14:33:28 -0500314 std::string m_logDir;
akmhoque157b0a42014-05-13 00:26:37 -0500315 std::string m_seqFileDir;
akmhoque53353462014-04-22 08:43:45 -0500316
317};
318
akmhoque157b0a42014-05-13 00:26:37 -0500319inline std::ostream&
320operator<<(std::ostream& os, ConfParameter& cfp)
321{
akmhoque674b0b12014-05-20 14:33:28 -0500322 os << "Router Name: " << cfp.getRouterName() << std::endl;
323 os << "Site Name: " << cfp.getSiteName() << std::endl;
324 os << "Network: " << cfp.getNetwork() << std::endl;
325 os << "Router Prefix: " << cfp.getRouterPrefix() << std::endl;
326 os << "ChronoSync sync Prifex: " << cfp.getChronosyncPrefix() << std::endl;
327 os << "ChronoSync LSA prefix: " << cfp.getLsaPrefix() << std::endl;
328 os << "Interest Retry number: " << cfp.getInterestRetryNumber() << std::endl;
329 os << "Interest Resend second: " << cfp.getInterestResendTime() << std::endl;
330 os << "Info Interest Interval: " << cfp.getInfoInterestInterval() << std::endl;
331 os << "LSA refresh time: " << cfp.getLsaRefreshTime() << std::endl;
332 os << "Max Faces Per Prefix: " << cfp.getMaxFacesPerPrefix() << std::endl;
333 os << "Hyperbolic ROuting: " << cfp.getHyperbolicState() << std::endl;
334 os << "Hyp R: " << cfp.getCorR() << std::endl;
335 os << "Hyp theta: " << cfp.getCorTheta() << std::endl;
336 os << "Log Directory: " << cfp.getLogDir() << std::endl;
337 os << "Seq Directory: " << cfp.getSeqFileDir() << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500338 return os;
339}
akmhoque53353462014-04-22 08:43:45 -0500340
341} // namespace nlsr
342
akmhoquefdbddb12014-05-02 18:35:19 -0500343#endif //CONF_PARAMETER_HPP