blob: 25df9ee02209dc4e0a7b96f6cfc8c3138a709dd4 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoquefdbddb12014-05-02 18:35:19 -050023#ifndef CONF_PARAMETER_HPP
24#define CONF_PARAMETER_HPP
akmhoque53353462014-04-22 08:43:45 -050025
26#include <iostream>
akmhoquefdbddb12014-05-02 18:35:19 -050027#include <boost/cstdint.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050028#include <ndn-cxx/common.hpp>
29#include <ndn-cxx/face.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 {
42 HELLO_RETRIES_MIN = 1,
43 HELLO_RETRIES_DEFAULT = 3,
44 HELLO_RETRIES_MAX = 15
45};
46
47enum {
48 HELLO_TIMEOUT_MIN = 1,
49 HELLO_TIMEOUT_DEFAULT = 3,
50 HELLO_TIMEOUT_MAX = 15
51};
52
53enum {
54 HELLO_INTERVAL_MIN = 30,
55 HELLO_INTERVAL_DEFAULT = 60,
56 HELLO_INTERVAL_MAX =90
57};
58
59enum {
60 MAX_FACES_PER_PREFIX_MIN = 0,
61 MAX_FACES_PER_PREFIX_MAX = 60
62};
63
64enum {
65 HYPERBOLIC_STATE_OFF = 0,
66 HYPERBOLIC_STATE_ON = 1,
67 HYPERBOLIC_STATE_DRY_RUN = 2
68};
69
akmhoque53353462014-04-22 08:43:45 -050070class ConfParameter
71{
72
73public:
74 ConfParameter()
akmhoque157b0a42014-05-13 00:26:37 -050075 : m_lsaRefreshTime(LSA_REFRESH_TIME_DEFAULT)
76 , m_routerDeadInterval(2*LSA_REFRESH_TIME_DEFAULT)
77 , m_logLevel("INFO")
78 , m_interestRetryNumber(HELLO_RETRIES_DEFAULT)
79 , m_interestResendTime(HELLO_TIMEOUT_DEFAULT)
80 , m_infoInterestInterval(HELLO_INTERVAL_DEFAULT)
81 , m_hyperbolicState(HYPERBOLIC_STATE_OFF)
akmhoque53353462014-04-22 08:43:45 -050082 , m_corR(0)
83 , m_corTheta(0)
akmhoque157b0a42014-05-13 00:26:37 -050084 , m_maxFacesPerPrefix(MAX_FACES_PER_PREFIX_MIN)
akmhoque53353462014-04-22 08:43:45 -050085 {}
86
87 void
akmhoque157b0a42014-05-13 00:26:37 -050088 setNetwork(const ndn::Name& networkName)
akmhoque53353462014-04-22 08:43:45 -050089 {
akmhoque157b0a42014-05-13 00:26:37 -050090 m_network = networkName;
91 m_chronosyncPrefix = m_network;
92 m_chronosyncPrefix.append("nlsr");
93 m_chronosyncPrefix.append("sync");
94
95 m_lsaPrefix = m_network;
96 m_lsaPrefix.append("nlsr");
97 m_lsaPrefix.append("LSA");
akmhoque53353462014-04-22 08:43:45 -050098 }
99
akmhoque31d1d4b2014-05-05 22:08:14 -0500100 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -0500101 getNetwork()
102 {
103 return m_network;
104 }
105
106 void
akmhoque157b0a42014-05-13 00:26:37 -0500107 setRouterName(const ndn::Name& routerName)
108 {
109 m_routerName = routerName;
110 }
111
112 const ndn::Name&
113 getRouterName()
114 {
115 return m_routerName;
116 }
117
118 void
119 setSiteName(const ndn::Name& siteName)
120 {
121 m_siteName = siteName;
122 }
123
124 const ndn::Name&
125 getSiteName()
126 {
127 return m_siteName;
128 }
129
130 void
akmhoque53353462014-04-22 08:43:45 -0500131 buildRouterPrefix()
132 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500133 m_routerPrefix = m_network;
134 m_routerPrefix.append(m_siteName);
135 m_routerPrefix.append(m_routerName);
akmhoque53353462014-04-22 08:43:45 -0500136 }
137
akmhoque31d1d4b2014-05-05 22:08:14 -0500138 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -0500139 getRouterPrefix()
140 {
141 return m_routerPrefix;
142 }
143
akmhoque157b0a42014-05-13 00:26:37 -0500144
akmhoque31d1d4b2014-05-05 22:08:14 -0500145 const ndn::Name&
akmhoque157b0a42014-05-13 00:26:37 -0500146 getChronosyncPrefix()
akmhoque53353462014-04-22 08:43:45 -0500147 {
akmhoque157b0a42014-05-13 00:26:37 -0500148 return m_chronosyncPrefix;
akmhoque53353462014-04-22 08:43:45 -0500149 }
150
akmhoque157b0a42014-05-13 00:26:37 -0500151 const ndn::Name&
152 getLsaPrefix()
akmhoque53353462014-04-22 08:43:45 -0500153 {
akmhoque157b0a42014-05-13 00:26:37 -0500154 return m_lsaPrefix;
akmhoque53353462014-04-22 08:43:45 -0500155 }
156
157 void
akmhoquefdbddb12014-05-02 18:35:19 -0500158 setLsaRefreshTime(int32_t lrt)
akmhoque53353462014-04-22 08:43:45 -0500159 {
160 m_lsaRefreshTime = lrt;
161 m_routerDeadInterval = 2 * m_lsaRefreshTime;
162 }
163
akmhoquefdbddb12014-05-02 18:35:19 -0500164 int32_t
akmhoque53353462014-04-22 08:43:45 -0500165 getLsaRefreshTime()
166 {
167 return m_lsaRefreshTime;
168 }
169
170 void
akmhoquefdbddb12014-05-02 18:35:19 -0500171 setRouterDeadInterval(int64_t rdt)
akmhoque53353462014-04-22 08:43:45 -0500172 {
173 m_routerDeadInterval = rdt;
174 }
175
akmhoquefdbddb12014-05-02 18:35:19 -0500176 int64_t
akmhoque53353462014-04-22 08:43:45 -0500177 getRouterDeadInterval()
178 {
179 return m_routerDeadInterval;
180 }
akmhoque157b0a42014-05-13 00:26:37 -0500181
182 void
183 setLogLevel(const std::string& logLevel)
184 {
185 m_logLevel = logLevel;
186 }
187
188 const std::string&
189 getLogLevel()
190 {
191 return m_logLevel;
192 }
akmhoque53353462014-04-22 08:43:45 -0500193
194 void
akmhoque157b0a42014-05-13 00:26:37 -0500195 setInterestRetryNumber(uint32_t irn)
akmhoque53353462014-04-22 08:43:45 -0500196 {
akmhoque157b0a42014-05-13 00:26:37 -0500197 m_interestRetryNumber = irn;
198 }
199
200 uint32_t
201 getInterestRetryNumber()
202 {
203 return m_interestRetryNumber;
204 }
205
206 void
207 setInterestResendTime(int32_t irt)
208 {
209 m_interestResendTime = irt;
akmhoque53353462014-04-22 08:43:45 -0500210 }
211
akmhoquefdbddb12014-05-02 18:35:19 -0500212 int32_t
akmhoque157b0a42014-05-13 00:26:37 -0500213 getInterestResendTime()
akmhoque53353462014-04-22 08:43:45 -0500214 {
akmhoque157b0a42014-05-13 00:26:37 -0500215 return m_interestResendTime;
akmhoque53353462014-04-22 08:43:45 -0500216 }
217
akmhoquefdbddb12014-05-02 18:35:19 -0500218 int32_t
akmhoque157b0a42014-05-13 00:26:37 -0500219 getInfoInterestInterval()
akmhoque53353462014-04-22 08:43:45 -0500220 {
akmhoque157b0a42014-05-13 00:26:37 -0500221 return m_infoInterestInterval;
akmhoque53353462014-04-22 08:43:45 -0500222 }
223
224 void
akmhoque157b0a42014-05-13 00:26:37 -0500225 setInfoInterestInterval(int32_t iii)
akmhoque53353462014-04-22 08:43:45 -0500226 {
akmhoque157b0a42014-05-13 00:26:37 -0500227 m_infoInterestInterval = iii;
228 }
229
230 void
231 setHyperbolicState(int32_t ihc)
232 {
233 m_hyperbolicState = ihc;
akmhoque53353462014-04-22 08:43:45 -0500234 }
235
akmhoquefdbddb12014-05-02 18:35:19 -0500236 int32_t
akmhoque157b0a42014-05-13 00:26:37 -0500237 getHyperbolicState()
akmhoque53353462014-04-22 08:43:45 -0500238 {
akmhoque157b0a42014-05-13 00:26:37 -0500239 return m_hyperbolicState;
akmhoque53353462014-04-22 08:43:45 -0500240 }
241
akmhoque157b0a42014-05-13 00:26:37 -0500242 bool
akmhoque53353462014-04-22 08:43:45 -0500243 setCorR(double cr)
244 {
akmhoque157b0a42014-05-13 00:26:37 -0500245 if ( cr >= 0 ) {
246 m_corR = cr;
247 return true;
248 }
249 return false;
akmhoque53353462014-04-22 08:43:45 -0500250 }
251
252 double
253 getCorR()
254 {
255 return m_corR;
256 }
257
258 void
259 setCorTheta(double ct)
260 {
261 m_corTheta = ct;
262 }
263
264 double
265 getCorTheta()
266 {
267 return m_corTheta;
268 }
akmhoque157b0a42014-05-13 00:26:37 -0500269
akmhoque53353462014-04-22 08:43:45 -0500270 void
akmhoque157b0a42014-05-13 00:26:37 -0500271 setMaxFacesPerPrefix(int32_t mfpp)
akmhoque53353462014-04-22 08:43:45 -0500272 {
akmhoque157b0a42014-05-13 00:26:37 -0500273 m_maxFacesPerPrefix = mfpp;
akmhoque53353462014-04-22 08:43:45 -0500274 }
275
akmhoquefdbddb12014-05-02 18:35:19 -0500276 int32_t
akmhoque157b0a42014-05-13 00:26:37 -0500277 getMaxFacesPerPrefix()
akmhoque53353462014-04-22 08:43:45 -0500278 {
akmhoque157b0a42014-05-13 00:26:37 -0500279 return m_maxFacesPerPrefix;
akmhoque53353462014-04-22 08:43:45 -0500280 }
281
282 void
akmhoque674b0b12014-05-20 14:33:28 -0500283 setLogDir(const std::string& logDir)
284 {
285 m_logDir = logDir;
286 }
287
288 const std::string&
289 getLogDir()
290 {
291 return m_logDir;
292 }
293
294 void
akmhoque157b0a42014-05-13 00:26:37 -0500295 setSeqFileDir(const std::string& ssfd)
akmhoque53353462014-04-22 08:43:45 -0500296 {
akmhoque157b0a42014-05-13 00:26:37 -0500297 m_seqFileDir = ssfd;
akmhoque53353462014-04-22 08:43:45 -0500298 }
299
akmhoque157b0a42014-05-13 00:26:37 -0500300 const std::string&
301 getSeqFileDir()
akmhoque53353462014-04-22 08:43:45 -0500302 {
akmhoque157b0a42014-05-13 00:26:37 -0500303 return m_seqFileDir;
akmhoque53353462014-04-22 08:43:45 -0500304 }
305
akmhoque674b0b12014-05-20 14:33:28 -0500306 void
307 writeLog();
akmhoque53353462014-04-22 08:43:45 -0500308
309private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500310 ndn::Name m_routerName;
311 ndn::Name m_siteName;
312 ndn::Name m_network;
akmhoque53353462014-04-22 08:43:45 -0500313
akmhoque31d1d4b2014-05-05 22:08:14 -0500314 ndn::Name m_routerPrefix;
315 ndn::Name m_lsaRouterPrefix;
akmhoque53353462014-04-22 08:43:45 -0500316
akmhoque157b0a42014-05-13 00:26:37 -0500317 ndn::Name m_chronosyncPrefix;
318 ndn::Name m_lsaPrefix;
319
320 int32_t m_lsaRefreshTime;
321 int64_t m_routerDeadInterval;
322 std::string m_logLevel;
akmhoque53353462014-04-22 08:43:45 -0500323
akmhoquefdbddb12014-05-02 18:35:19 -0500324 uint32_t m_interestRetryNumber;
akmhoque157b0a42014-05-13 00:26:37 -0500325 int32_t m_interestResendTime;
326
327
328 int32_t m_infoInterestInterval;
329
330 int32_t m_hyperbolicState;
akmhoque53353462014-04-22 08:43:45 -0500331 double m_corR;
332 double m_corTheta;
333
akmhoque157b0a42014-05-13 00:26:37 -0500334 int32_t m_maxFacesPerPrefix;
335
akmhoque674b0b12014-05-20 14:33:28 -0500336 std::string m_logDir;
akmhoque157b0a42014-05-13 00:26:37 -0500337 std::string m_seqFileDir;
akmhoque53353462014-04-22 08:43:45 -0500338
339};
340
akmhoque157b0a42014-05-13 00:26:37 -0500341inline std::ostream&
342operator<<(std::ostream& os, ConfParameter& cfp)
343{
akmhoque674b0b12014-05-20 14:33:28 -0500344 os << "Router Name: " << cfp.getRouterName() << std::endl;
345 os << "Site Name: " << cfp.getSiteName() << std::endl;
346 os << "Network: " << cfp.getNetwork() << std::endl;
347 os << "Router Prefix: " << cfp.getRouterPrefix() << std::endl;
348 os << "ChronoSync sync Prifex: " << cfp.getChronosyncPrefix() << std::endl;
349 os << "ChronoSync LSA prefix: " << cfp.getLsaPrefix() << std::endl;
350 os << "Interest Retry number: " << cfp.getInterestRetryNumber() << std::endl;
351 os << "Interest Resend second: " << cfp.getInterestResendTime() << std::endl;
352 os << "Info Interest Interval: " << cfp.getInfoInterestInterval() << std::endl;
353 os << "LSA refresh time: " << cfp.getLsaRefreshTime() << std::endl;
354 os << "Max Faces Per Prefix: " << cfp.getMaxFacesPerPrefix() << std::endl;
355 os << "Hyperbolic ROuting: " << cfp.getHyperbolicState() << std::endl;
356 os << "Hyp R: " << cfp.getCorR() << std::endl;
357 os << "Hyp theta: " << cfp.getCorTheta() << std::endl;
358 os << "Log Directory: " << cfp.getLogDir() << std::endl;
359 os << "Seq Directory: " << cfp.getSeqFileDir() << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500360 return os;
361}
akmhoque53353462014-04-22 08:43:45 -0500362
363} // namespace nlsr
364
akmhoquefdbddb12014-05-02 18:35:19 -0500365#endif //CONF_PARAMETER_HPP