blob: c3573bb1f5eaac1f3a21e4d3bf7b8ddfa81ddfbd [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
dmcoomese689dd62017-03-29 11:05:12 -050022#ifndef NLSR_CONF_PARAMETER_HPP
23#define NLSR_CONF_PARAMETER_HPP
akmhoque53353462014-04-22 08:43:45 -050024
25#include <iostream>
akmhoquefdbddb12014-05-02 18:35:19 -050026#include <boost/cstdint.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050027#include <ndn-cxx/common.hpp>
28#include <ndn-cxx/face.hpp>
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070029#include <ndn-cxx/util/time.hpp>
akmhoque53353462014-04-22 08:43:45 -050030
akmhoque674b0b12014-05-20 14:33:28 -050031#include "logger.hpp"
32
akmhoque53353462014-04-22 08:43:45 -050033namespace nlsr {
akmhoque157b0a42014-05-13 00:26:37 -050034
35enum {
36 LSA_REFRESH_TIME_MIN = 240,
37 LSA_REFRESH_TIME_DEFAULT = 1800,
38 LSA_REFRESH_TIME_MAX = 7200
39};
40
41enum {
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070042 LSA_INTEREST_LIFETIME_MIN = 1,
43 LSA_INTEREST_LIFETIME_DEFAULT = 4,
44 LSA_INTEREST_LIFETIME_MAX = 60
45};
46
47enum {
Vince Lehman7b616582014-10-17 16:25:39 -050048 ADJ_LSA_BUILD_INTERVAL_MIN = 0,
49 ADJ_LSA_BUILD_INTERVAL_DEFAULT = 5,
50 ADJ_LSA_BUILD_INTERVAL_MAX = 5
51};
52
53enum {
54 FIRST_HELLO_INTERVAL_MIN = 0,
55 FIRST_HELLO_INTERVAL_DEFAULT = 10,
56 FIRST_HELLO_INTERVAL_MAX = 10
57};
58
59enum {
60 ROUTING_CALC_INTERVAL_MIN = 0,
61 ROUTING_CALC_INTERVAL_DEFAULT = 15,
62 ROUTING_CALC_INTERVAL_MAX = 15
63};
64
65enum {
akmhoque157b0a42014-05-13 00:26:37 -050066 HELLO_RETRIES_MIN = 1,
67 HELLO_RETRIES_DEFAULT = 3,
68 HELLO_RETRIES_MAX = 15
69};
70
71enum {
72 HELLO_TIMEOUT_MIN = 1,
73 HELLO_TIMEOUT_DEFAULT = 3,
74 HELLO_TIMEOUT_MAX = 15
75};
76
77enum {
78 HELLO_INTERVAL_MIN = 30,
79 HELLO_INTERVAL_DEFAULT = 60,
80 HELLO_INTERVAL_MAX =90
81};
82
83enum {
84 MAX_FACES_PER_PREFIX_MIN = 0,
alvya2228c62014-12-09 10:25:11 -060085 MAX_FACES_PER_PREFIX_DEFAULT = 0,
akmhoque157b0a42014-05-13 00:26:37 -050086 MAX_FACES_PER_PREFIX_MAX = 60
87};
88
Nick Gordon5c467f02016-07-13 13:40:10 -050089enum HyperbolicState {
akmhoque157b0a42014-05-13 00:26:37 -050090 HYPERBOLIC_STATE_OFF = 0,
91 HYPERBOLIC_STATE_ON = 1,
alvya2228c62014-12-09 10:25:11 -060092 HYPERBOLIC_STATE_DRY_RUN = 2,
93 HYPERBOLIC_STATE_DEFAULT = 0
akmhoque157b0a42014-05-13 00:26:37 -050094};
95
akmhoque53353462014-04-22 08:43:45 -050096class ConfParameter
97{
98
99public:
100 ConfParameter()
akmhoque157b0a42014-05-13 00:26:37 -0500101 : m_lsaRefreshTime(LSA_REFRESH_TIME_DEFAULT)
Vince Lehman7b616582014-10-17 16:25:39 -0500102 , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
103 , m_firstHelloInterval(FIRST_HELLO_INTERVAL_DEFAULT)
104 , m_routingCalcInterval(ROUTING_CALC_INTERVAL_DEFAULT)
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700105 , m_lsaInterestLifetime(ndn::time::seconds(static_cast<int>(LSA_INTEREST_LIFETIME_DEFAULT)))
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -0700106 , m_routerDeadInterval(2 * LSA_REFRESH_TIME_DEFAULT)
akmhoque157b0a42014-05-13 00:26:37 -0500107 , m_logLevel("INFO")
108 , m_interestRetryNumber(HELLO_RETRIES_DEFAULT)
109 , m_interestResendTime(HELLO_TIMEOUT_DEFAULT)
110 , m_infoInterestInterval(HELLO_INTERVAL_DEFAULT)
111 , m_hyperbolicState(HYPERBOLIC_STATE_OFF)
akmhoque53353462014-04-22 08:43:45 -0500112 , m_corR(0)
113 , m_corTheta(0)
akmhoque157b0a42014-05-13 00:26:37 -0500114 , m_maxFacesPerPrefix(MAX_FACES_PER_PREFIX_MIN)
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500115 , m_isLog4cxxConfAvailable(false)
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700116 {
117 }
akmhoque53353462014-04-22 08:43:45 -0500118
119 void
akmhoque157b0a42014-05-13 00:26:37 -0500120 setNetwork(const ndn::Name& networkName)
akmhoque53353462014-04-22 08:43:45 -0500121 {
akmhoque157b0a42014-05-13 00:26:37 -0500122 m_network = networkName;
Ashlesh Gawande44395232016-12-13 14:35:29 -0600123
124 m_chronosyncPrefix.append("localhop");
Ashlesh Gawande8bfd1242017-06-21 14:55:27 -0500125 m_chronosyncPrefix.append(m_network);
akmhoquea816bee2014-06-24 14:37:40 -0500126 m_chronosyncPrefix.append("NLSR");
akmhoque157b0a42014-05-13 00:26:37 -0500127 m_chronosyncPrefix.append("sync");
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700128
Ashlesh Gawande6077ea92017-01-19 11:48:29 -0600129 m_lsaPrefix.append("localhop");
130 m_lsaPrefix.append(m_network);
akmhoquea816bee2014-06-24 14:37:40 -0500131 m_lsaPrefix.append("NLSR");
akmhoque157b0a42014-05-13 00:26:37 -0500132 m_lsaPrefix.append("LSA");
akmhoque53353462014-04-22 08:43:45 -0500133 }
134
akmhoque31d1d4b2014-05-05 22:08:14 -0500135 const ndn::Name&
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700136 getNetwork() const
akmhoque53353462014-04-22 08:43:45 -0500137 {
138 return m_network;
139 }
140
141 void
akmhoque157b0a42014-05-13 00:26:37 -0500142 setRouterName(const ndn::Name& routerName)
143 {
144 m_routerName = routerName;
145 }
146
147 const ndn::Name&
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700148 getRouterName() const
akmhoque157b0a42014-05-13 00:26:37 -0500149 {
150 return m_routerName;
151 }
152
153 void
154 setSiteName(const ndn::Name& siteName)
155 {
156 m_siteName = siteName;
157 }
158
159 const ndn::Name&
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700160 getSiteName() const
akmhoque157b0a42014-05-13 00:26:37 -0500161 {
162 return m_siteName;
163 }
164
165 void
akmhoque53353462014-04-22 08:43:45 -0500166 buildRouterPrefix()
167 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500168 m_routerPrefix = m_network;
169 m_routerPrefix.append(m_siteName);
170 m_routerPrefix.append(m_routerName);
akmhoque53353462014-04-22 08:43:45 -0500171 }
172
akmhoque31d1d4b2014-05-05 22:08:14 -0500173 const ndn::Name&
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700174 getRouterPrefix() const
akmhoque53353462014-04-22 08:43:45 -0500175 {
176 return m_routerPrefix;
177 }
178
akmhoque157b0a42014-05-13 00:26:37 -0500179
akmhoque31d1d4b2014-05-05 22:08:14 -0500180 const ndn::Name&
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700181 getChronosyncPrefix() const
akmhoque53353462014-04-22 08:43:45 -0500182 {
akmhoque157b0a42014-05-13 00:26:37 -0500183 return m_chronosyncPrefix;
akmhoque53353462014-04-22 08:43:45 -0500184 }
185
akmhoque157b0a42014-05-13 00:26:37 -0500186 const ndn::Name&
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700187 getLsaPrefix() const
akmhoque53353462014-04-22 08:43:45 -0500188 {
akmhoque157b0a42014-05-13 00:26:37 -0500189 return m_lsaPrefix;
akmhoque53353462014-04-22 08:43:45 -0500190 }
191
192 void
alvy5a454952014-12-15 12:49:54 -0600193 setLsaRefreshTime(uint32_t lrt)
akmhoque53353462014-04-22 08:43:45 -0500194 {
195 m_lsaRefreshTime = lrt;
akmhoque53353462014-04-22 08:43:45 -0500196 }
197
alvy5a454952014-12-15 12:49:54 -0600198 uint32_t
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700199 getLsaRefreshTime() const
akmhoque53353462014-04-22 08:43:45 -0500200 {
201 return m_lsaRefreshTime;
202 }
203
204 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700205 setLsaInterestLifetime(const ndn::time::seconds& lifetime)
206 {
207 m_lsaInterestLifetime = lifetime;
208 }
209
210 const ndn::time::seconds&
211 getLsaInterestLifetime() const
212 {
213 return m_lsaInterestLifetime;
214 }
215
216 void
Vince Lehman7b616582014-10-17 16:25:39 -0500217 setAdjLsaBuildInterval(uint32_t interval)
218 {
219 m_adjLsaBuildInterval = interval;
220 }
221
222 uint32_t
223 getAdjLsaBuildInterval() const
224 {
225 return m_adjLsaBuildInterval;
226 }
227
228 void
229 setFirstHelloInterval(uint32_t interval)
230 {
231 m_firstHelloInterval = interval;
232 }
233
234 uint32_t
235 getFirstHelloInterval() const
236 {
237 return m_firstHelloInterval;
238 }
239
240 void
241 setRoutingCalcInterval(uint32_t interval)
242 {
243 m_routingCalcInterval = interval;
244 }
245
246 uint32_t
247 getRoutingCalcInterval() const
248 {
249 return m_routingCalcInterval;
250 }
251
252 void
alvy5a454952014-12-15 12:49:54 -0600253 setRouterDeadInterval(uint32_t rdt)
akmhoque53353462014-04-22 08:43:45 -0500254 {
255 m_routerDeadInterval = rdt;
256 }
257
alvy5a454952014-12-15 12:49:54 -0600258 uint32_t
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700259 getRouterDeadInterval() const
akmhoque53353462014-04-22 08:43:45 -0500260 {
261 return m_routerDeadInterval;
262 }
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700263
264 void
akmhoque157b0a42014-05-13 00:26:37 -0500265 setLogLevel(const std::string& logLevel)
266 {
267 m_logLevel = logLevel;
268 }
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700269
270 const std::string&
271 getLogLevel() const
akmhoque157b0a42014-05-13 00:26:37 -0500272 {
273 return m_logLevel;
274 }
akmhoque53353462014-04-22 08:43:45 -0500275
276 void
akmhoque157b0a42014-05-13 00:26:37 -0500277 setInterestRetryNumber(uint32_t irn)
akmhoque53353462014-04-22 08:43:45 -0500278 {
akmhoque157b0a42014-05-13 00:26:37 -0500279 m_interestRetryNumber = irn;
280 }
281
282 uint32_t
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700283 getInterestRetryNumber() const
akmhoque157b0a42014-05-13 00:26:37 -0500284 {
285 return m_interestRetryNumber;
286 }
287
288 void
alvy5a454952014-12-15 12:49:54 -0600289 setInterestResendTime(uint32_t irt)
akmhoque157b0a42014-05-13 00:26:37 -0500290 {
291 m_interestResendTime = irt;
akmhoque53353462014-04-22 08:43:45 -0500292 }
293
alvy5a454952014-12-15 12:49:54 -0600294 uint32_t
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700295 getInterestResendTime() const
akmhoque53353462014-04-22 08:43:45 -0500296 {
akmhoque157b0a42014-05-13 00:26:37 -0500297 return m_interestResendTime;
akmhoque53353462014-04-22 08:43:45 -0500298 }
299
alvy5a454952014-12-15 12:49:54 -0600300 uint32_t
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700301 getInfoInterestInterval() const
akmhoque53353462014-04-22 08:43:45 -0500302 {
akmhoque157b0a42014-05-13 00:26:37 -0500303 return m_infoInterestInterval;
akmhoque53353462014-04-22 08:43:45 -0500304 }
305
306 void
alvy5a454952014-12-15 12:49:54 -0600307 setInfoInterestInterval(uint32_t iii)
akmhoque53353462014-04-22 08:43:45 -0500308 {
akmhoque157b0a42014-05-13 00:26:37 -0500309 m_infoInterestInterval = iii;
310 }
311
312 void
313 setHyperbolicState(int32_t ihc)
314 {
315 m_hyperbolicState = ihc;
akmhoque53353462014-04-22 08:43:45 -0500316 }
317
akmhoquefdbddb12014-05-02 18:35:19 -0500318 int32_t
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700319 getHyperbolicState() const
akmhoque53353462014-04-22 08:43:45 -0500320 {
akmhoque157b0a42014-05-13 00:26:37 -0500321 return m_hyperbolicState;
akmhoque53353462014-04-22 08:43:45 -0500322 }
323
akmhoque157b0a42014-05-13 00:26:37 -0500324 bool
akmhoque53353462014-04-22 08:43:45 -0500325 setCorR(double cr)
326 {
akmhoque157b0a42014-05-13 00:26:37 -0500327 if ( cr >= 0 ) {
328 m_corR = cr;
329 return true;
330 }
331 return false;
akmhoque53353462014-04-22 08:43:45 -0500332 }
333
334 double
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700335 getCorR() const
akmhoque53353462014-04-22 08:43:45 -0500336 {
337 return m_corR;
338 }
339
340 void
341 setCorTheta(double ct)
342 {
343 m_corTheta = ct;
344 }
345
346 double
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700347 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500348 {
349 return m_corTheta;
350 }
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700351
akmhoque53353462014-04-22 08:43:45 -0500352 void
Vince Lehman942eb7b2014-10-02 10:09:27 -0500353 setMaxFacesPerPrefix(uint32_t mfpp)
akmhoque53353462014-04-22 08:43:45 -0500354 {
akmhoque157b0a42014-05-13 00:26:37 -0500355 m_maxFacesPerPrefix = mfpp;
akmhoque53353462014-04-22 08:43:45 -0500356 }
357
Vince Lehman942eb7b2014-10-02 10:09:27 -0500358 uint32_t
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700359 getMaxFacesPerPrefix() const
akmhoque53353462014-04-22 08:43:45 -0500360 {
akmhoque157b0a42014-05-13 00:26:37 -0500361 return m_maxFacesPerPrefix;
akmhoque53353462014-04-22 08:43:45 -0500362 }
363
364 void
akmhoque674b0b12014-05-20 14:33:28 -0500365 setLogDir(const std::string& logDir)
366 {
367 m_logDir = logDir;
368 }
369
370 const std::string&
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700371 getLogDir() const
akmhoque674b0b12014-05-20 14:33:28 -0500372 {
373 return m_logDir;
374 }
375
376 void
akmhoque157b0a42014-05-13 00:26:37 -0500377 setSeqFileDir(const std::string& ssfd)
akmhoque53353462014-04-22 08:43:45 -0500378 {
akmhoque157b0a42014-05-13 00:26:37 -0500379 m_seqFileDir = ssfd;
akmhoque53353462014-04-22 08:43:45 -0500380 }
381
akmhoque157b0a42014-05-13 00:26:37 -0500382 const std::string&
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700383 getSeqFileDir() const
akmhoque53353462014-04-22 08:43:45 -0500384 {
akmhoque157b0a42014-05-13 00:26:37 -0500385 return m_seqFileDir;
akmhoque53353462014-04-22 08:43:45 -0500386 }
387
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500388 bool
389 isLog4CxxConfAvailable() const
390 {
391 return m_isLog4cxxConfAvailable;
392 }
393
394 void
395 setLog4CxxConfPath(const std::string& path)
396 {
397 m_log4CxxConfPath = path;
398 m_isLog4cxxConfAvailable = true;
399 }
400
401 const std::string&
402 getLog4CxxConfPath() const
403 {
404 return m_log4CxxConfPath;
405 }
406
akmhoque674b0b12014-05-20 14:33:28 -0500407 void
408 writeLog();
akmhoque53353462014-04-22 08:43:45 -0500409
410private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500411 ndn::Name m_routerName;
412 ndn::Name m_siteName;
413 ndn::Name m_network;
akmhoque53353462014-04-22 08:43:45 -0500414
akmhoque31d1d4b2014-05-05 22:08:14 -0500415 ndn::Name m_routerPrefix;
416 ndn::Name m_lsaRouterPrefix;
akmhoque53353462014-04-22 08:43:45 -0500417
akmhoque157b0a42014-05-13 00:26:37 -0500418 ndn::Name m_chronosyncPrefix;
419 ndn::Name m_lsaPrefix;
420
alvy5a454952014-12-15 12:49:54 -0600421 uint32_t m_lsaRefreshTime;
Vince Lehman7b616582014-10-17 16:25:39 -0500422
423 uint32_t m_adjLsaBuildInterval;
424 uint32_t m_firstHelloInterval;
425 uint32_t m_routingCalcInterval;
426
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700427 ndn::time::seconds m_lsaInterestLifetime;
alvy5a454952014-12-15 12:49:54 -0600428 uint32_t m_routerDeadInterval;
akmhoque157b0a42014-05-13 00:26:37 -0500429 std::string m_logLevel;
akmhoque53353462014-04-22 08:43:45 -0500430
akmhoquefdbddb12014-05-02 18:35:19 -0500431 uint32_t m_interestRetryNumber;
alvy5a454952014-12-15 12:49:54 -0600432 uint32_t m_interestResendTime;
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700433
alvy5a454952014-12-15 12:49:54 -0600434 uint32_t m_infoInterestInterval;
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700435
akmhoque157b0a42014-05-13 00:26:37 -0500436 int32_t m_hyperbolicState;
akmhoque53353462014-04-22 08:43:45 -0500437 double m_corR;
438 double m_corTheta;
439
Vince Lehman942eb7b2014-10-02 10:09:27 -0500440 uint32_t m_maxFacesPerPrefix;
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700441
akmhoque674b0b12014-05-20 14:33:28 -0500442 std::string m_logDir;
akmhoque157b0a42014-05-13 00:26:37 -0500443 std::string m_seqFileDir;
akmhoque53353462014-04-22 08:43:45 -0500444
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500445 bool m_isLog4cxxConfAvailable;
446 std::string m_log4CxxConfPath;
akmhoque53353462014-04-22 08:43:45 -0500447};
448
akmhoque53353462014-04-22 08:43:45 -0500449} // namespace nlsr
450
dmcoomese689dd62017-03-29 11:05:12 -0500451#endif // NLSR_CONF_PARAMETER_HPP