akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1 | #include <iostream> |
| 2 | #include <fstream> |
| 3 | #include <string> |
| 4 | #include <cstdlib> |
| 5 | #include <sstream> |
| 6 | |
| 7 | #include "conf-file-processor.hpp" |
| 8 | #include "conf-parameter.hpp" |
| 9 | #include "utility/tokenizer.hpp" |
| 10 | #include "adjacent.hpp" |
| 11 | |
| 12 | |
| 13 | namespace nlsr { |
| 14 | |
| 15 | using namespace std; |
| 16 | |
| 17 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 18 | ConfFileProcessor::processConfFile() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 19 | { |
| 20 | int ret = 0; |
| 21 | if (!m_confFileName.empty()) |
| 22 | { |
| 23 | std::ifstream inputFile(m_confFileName.c_str()); |
| 24 | if (inputFile.is_open()) |
| 25 | { |
| 26 | for (string line; getline(inputFile, line);) |
| 27 | { |
| 28 | if (!line.empty()) |
| 29 | { |
| 30 | if (line[0] != '#' && line[0] != '!') |
| 31 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 32 | ret = processConfCommand(line); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | if (ret == -1) |
| 34 | { |
| 35 | break; |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | std::cerr << "Configuration file: (" << m_confFileName << ") does not exist :("; |
| 44 | std::cerr << endl; |
| 45 | ret = -1; |
| 46 | } |
| 47 | } |
| 48 | return ret; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 53 | ConfFileProcessor::processConfCommand(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 54 | { |
| 55 | int ret = 0; |
| 56 | Tokenizer nt(command, " "); |
| 57 | if ((nt.getFirstToken() == "network")) |
| 58 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 59 | ret = processConfCommandNetwork(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 60 | } |
| 61 | else if ((nt.getFirstToken() == "site-name")) |
| 62 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 63 | ret = processConfCommandSiteName(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 64 | } |
| 65 | else if ((nt.getFirstToken() == "root-key-prefix")) |
| 66 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 67 | ret = processConfCommandRootKeyPrefix(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 68 | } |
| 69 | else if ((nt.getFirstToken() == "router-name")) |
| 70 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 71 | ret = processConfCommandRouterName(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 72 | } |
| 73 | else if ((nt.getFirstToken() == "ndnneighbor")) |
| 74 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 75 | ret = processConfCommandNdnNeighbor(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | } |
| 77 | else if ((nt.getFirstToken() == "link-cost")) |
| 78 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 79 | ret = processConfCommandLinkCost(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 80 | } |
| 81 | else if ((nt.getFirstToken() == "ndnname")) |
| 82 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 83 | ret = processConfCommandNdnName(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 84 | } |
| 85 | else if ((nt.getFirstToken() == "interest-retry-num")) |
| 86 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 87 | processConfCommandInterestRetryNumber(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 88 | } |
| 89 | else if ((nt.getFirstToken() == "interest-resend-time")) |
| 90 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 91 | processConfCommandInterestResendTime(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 92 | } |
| 93 | else if ((nt.getFirstToken() == "lsa-refresh-time")) |
| 94 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 95 | processConfCommandLsaRefreshTime(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 96 | } |
| 97 | else if ((nt.getFirstToken() == "max-faces-per-prefix")) |
| 98 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 99 | processConfCommandMaxFacesPerPrefix(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 100 | } |
| 101 | else if ((nt.getFirstToken() == "log-dir")) |
| 102 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 103 | processConfCommandLogDir(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 104 | } |
| 105 | else if ((nt.getFirstToken() == "cert-dir")) |
| 106 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 107 | processConfCommandCertDir(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 108 | } |
| 109 | else if ((nt.getFirstToken() == "detailed-logging")) |
| 110 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 111 | processConfCommandDetailedLogging(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 112 | } |
| 113 | else if ((nt.getFirstToken() == "debugging")) |
| 114 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 115 | processConfCommandDebugging(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 116 | } |
| 117 | else if ((nt.getFirstToken() == "chronosync-sync-prefix")) |
| 118 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 119 | processConfCommandChronosyncSyncPrefix(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 120 | } |
| 121 | else if ((nt.getFirstToken() == "hyperbolic-cordinate")) |
| 122 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 123 | processConfCommandHyperbolicCordinate(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 124 | } |
| 125 | else if ((nt.getFirstToken() == "hyperbolic-routing")) |
| 126 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 127 | processConfCommandIsHyperbolicCalc(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 128 | } |
| 129 | else if ((nt.getFirstToken() == "tunnel-type")) |
| 130 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 131 | processConfCommandTunnelType(nt.getRestOfLine()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 132 | } |
| 133 | else |
| 134 | { |
| 135 | cout << "Wrong configuration Command: " << nt.getFirstToken() << endl; |
| 136 | } |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 141 | ConfFileProcessor::processConfCommandNetwork(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 142 | { |
| 143 | if (command.empty()) |
| 144 | { |
| 145 | cerr << " Network can not be null or empty :( !" << endl; |
| 146 | return -1; |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | if (command[command.size() - 1] == '/') |
| 151 | { |
| 152 | command.erase(command.size() - 1); |
| 153 | } |
| 154 | if (command[0] == '/') |
| 155 | { |
| 156 | command.erase(0, 1); |
| 157 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 158 | m_nlsr.getConfParameter().setNetwork(command); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 159 | } |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 164 | ConfFileProcessor::processConfCommandSiteName(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 165 | { |
| 166 | if (command.empty()) |
| 167 | { |
| 168 | cerr << "Site name can not be null or empty :( !" << endl; |
| 169 | return -1; |
| 170 | } |
| 171 | else |
| 172 | { |
| 173 | if (command[command.size() - 1] == '/') |
| 174 | { |
| 175 | command.erase(command.size() - 1); |
| 176 | } |
| 177 | if (command[0] == '/') |
| 178 | { |
| 179 | command.erase(0, 1); |
| 180 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 181 | m_nlsr.getConfParameter().setSiteName(command); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 182 | } |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 187 | ConfFileProcessor::processConfCommandRootKeyPrefix(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 188 | { |
| 189 | if (command.empty()) |
| 190 | { |
| 191 | cerr << "Root Key Prefix can not be null or empty :( !" << endl; |
| 192 | return -1; |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | if (command[command.size() - 1] == '/') |
| 197 | { |
| 198 | command.erase(command.size() - 1); |
| 199 | } |
| 200 | if (command[0] == '/') |
| 201 | { |
| 202 | command.erase(0, 1); |
| 203 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 204 | m_nlsr.getConfParameter().setRootKeyPrefix(command); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 205 | } |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | |
| 210 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 211 | ConfFileProcessor::processConfCommandRouterName(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 212 | { |
| 213 | if (command.empty()) |
| 214 | { |
| 215 | cerr << " Router name can not be null or empty :( !" << endl; |
| 216 | return -1; |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | if (command[command.size() - 1] == '/') |
| 221 | { |
| 222 | command.erase(command.size() - 1); |
| 223 | } |
| 224 | if (command[0] == '/') |
| 225 | { |
| 226 | command.erase(0, 1); |
| 227 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 228 | m_nlsr.getConfParameter().setRouterName(command); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 229 | } |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 234 | ConfFileProcessor::processConfCommandInterestRetryNumber(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 235 | { |
| 236 | if (command.empty()) |
| 237 | { |
| 238 | cerr << " Wrong command format ! [interest-retry-num n]" << endl; |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | int irn; |
| 243 | stringstream ss(command.c_str()); |
| 244 | ss >> irn; |
| 245 | if (irn >= 1 && irn <= 5) |
| 246 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 247 | m_nlsr.getConfParameter().setInterestRetryNumber(irn); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 254 | ConfFileProcessor::processConfCommandInterestResendTime(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 255 | { |
| 256 | if (command.empty()) |
| 257 | { |
| 258 | cerr << " Wrong command format ! [interest-resend-time s]" << endl; |
| 259 | } |
| 260 | else |
| 261 | { |
| 262 | int irt; |
| 263 | stringstream ss(command.c_str()); |
| 264 | ss >> irt; |
| 265 | if (irt >= 1 && irt <= 20) |
| 266 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 267 | m_nlsr.getConfParameter().setInterestResendTime(irt); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 274 | ConfFileProcessor::processConfCommandLsaRefreshTime(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 275 | { |
| 276 | if (command.empty()) |
| 277 | { |
| 278 | cerr << " Wrong command format ! [interest-resend-time s]" << endl; |
| 279 | } |
| 280 | else |
| 281 | { |
| 282 | int lrt; |
| 283 | stringstream ss(command.c_str()); |
| 284 | ss >> lrt; |
| 285 | if (lrt >= 240 && lrt <= 7200) |
| 286 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 287 | m_nlsr.getConfParameter().setLsaRefreshTime(lrt); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 294 | ConfFileProcessor::processConfCommandMaxFacesPerPrefix(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 295 | { |
| 296 | if (command.empty()) |
| 297 | { |
| 298 | cerr << " Wrong command format ! [max-faces-per-prefix n]" << endl; |
| 299 | } |
| 300 | else |
| 301 | { |
| 302 | int mfpp; |
| 303 | stringstream ss(command.c_str()); |
| 304 | ss >> mfpp; |
| 305 | if (mfpp >= 0 && mfpp <= 60) |
| 306 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 307 | m_nlsr.getConfParameter().setMaxFacesPerPrefix(mfpp); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 314 | ConfFileProcessor::processConfCommandTunnelType(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 315 | { |
| 316 | if (command.empty()) |
| 317 | { |
| 318 | cerr << " Wrong command format ! [tunnel-type tcp/udp]!" << endl; |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | if (command == "tcp" || command == "TCP") |
| 323 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 324 | m_nlsr.getConfParameter().setTunnelType(1); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 325 | } |
| 326 | else if (command == "udp" || command == "UDP") |
| 327 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 328 | m_nlsr.getConfParameter().setTunnelType(0); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 329 | } |
| 330 | else |
| 331 | { |
| 332 | cerr << " Wrong command format ! [tunnel-type tcp/udp]!" << endl; |
| 333 | } |
| 334 | } |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 339 | ConfFileProcessor::processConfCommandChronosyncSyncPrefix(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 340 | { |
| 341 | if (command.empty()) |
| 342 | { |
| 343 | cerr << " Wrong command format ! [chronosync-sync-prefix name/prefix]!" << endl; |
| 344 | } |
| 345 | else |
| 346 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 347 | m_nlsr.getConfParameter().setChronosyncSyncPrefix(command); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 348 | } |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | |
| 353 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 354 | ConfFileProcessor::processConfCommandLogDir(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 355 | { |
| 356 | if (command.empty()) |
| 357 | { |
| 358 | cerr << " Wrong command format ! [log-dir /path/to/log/dir]!" << endl; |
| 359 | } |
| 360 | else |
| 361 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 362 | m_nlsr.getConfParameter().setLogDir(command); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 363 | } |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 368 | ConfFileProcessor::processConfCommandCertDir(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 369 | { |
| 370 | if (command.empty()) |
| 371 | { |
| 372 | cerr << " Wrong command format ! [cert-dir /path/to/cert/dir]!" << endl; |
| 373 | } |
| 374 | else |
| 375 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 376 | m_nlsr.getConfParameter().setCertDir(command); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 377 | } |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 382 | ConfFileProcessor::processConfCommandDebugging(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 383 | { |
| 384 | if (command.empty()) |
| 385 | { |
| 386 | cerr << " Wrong command format ! [debugging on/of]!" << endl; |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | if (command == "on" || command == "ON") |
| 391 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 392 | m_nlsr.getConfParameter().setDebugging(1); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 393 | } |
| 394 | else if (command == "off" || command == "off") |
| 395 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 396 | m_nlsr.getConfParameter().setDebugging(0); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 397 | } |
| 398 | else |
| 399 | { |
| 400 | cerr << " Wrong command format ! [debugging on/off]!" << endl; |
| 401 | } |
| 402 | } |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 407 | ConfFileProcessor::processConfCommandDetailedLogging(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 408 | { |
| 409 | if (command.empty()) |
| 410 | { |
| 411 | cerr << " Wrong command format ! [detailed-logging on/off]!" << endl; |
| 412 | } |
| 413 | else |
| 414 | { |
| 415 | if (command == "on" || command == "ON") |
| 416 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 417 | m_nlsr.getConfParameter().setDetailedLogging(1); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 418 | } |
| 419 | else if (command == "off" || command == "off") |
| 420 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 421 | m_nlsr.getConfParameter().setDetailedLogging(0); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 422 | } |
| 423 | else |
| 424 | { |
| 425 | cerr << " Wrong command format ! [detailed-logging on/off]!" << endl; |
| 426 | } |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 432 | ConfFileProcessor::processConfCommandIsHyperbolicCalc(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 433 | { |
| 434 | if (command.empty()) |
| 435 | { |
| 436 | cerr << " Wrong command format ! [hyperbolic-routing on/off/dry-run]!" << endl; |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | if (command == "on" || command == "ON") |
| 441 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 442 | m_nlsr.getConfParameter().setIsHyperbolicCalc(1); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 443 | } |
| 444 | else if (command == "dry-run" || command == "DRY-RUN") |
| 445 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 446 | m_nlsr.getConfParameter().setIsHyperbolicCalc(2); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 447 | } |
| 448 | else if (command == "off" || command == "off") |
| 449 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 450 | m_nlsr.getConfParameter().setIsHyperbolicCalc(0); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 451 | } |
| 452 | else |
| 453 | { |
| 454 | cerr << " Wrong command format ! [hyperbolic-routing on/off/dry-run]!" << endl; |
| 455 | } |
| 456 | } |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 461 | ConfFileProcessor::processConfCommandHyperbolicCordinate(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 462 | { |
| 463 | if (command.empty()) |
| 464 | { |
| 465 | cerr << " Wrong command format ! [hyperbolic-cordinate r 0]!" << endl; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 466 | if (m_nlsr.getConfParameter().getIsHyperbolicCalc() > 0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 467 | { |
| 468 | return -1; |
| 469 | } |
| 470 | } |
| 471 | else |
| 472 | { |
| 473 | Tokenizer nt(command, " "); |
| 474 | stringstream ssr(nt.getFirstToken().c_str()); |
| 475 | stringstream sst(nt.getRestOfLine().c_str()); |
| 476 | double r, theta; |
| 477 | ssr >> r; |
| 478 | sst >> theta; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 479 | m_nlsr.getConfParameter().setCorR(r); |
| 480 | m_nlsr.getConfParameter().setCorTheta(theta); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 481 | } |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | |
| 486 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 487 | ConfFileProcessor::processConfCommandNdnNeighbor(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 488 | { |
| 489 | if (command.empty()) |
| 490 | { |
| 491 | cerr << " Wrong command format ! [ndnneighbor /nbr/name/ FaceId]!" << endl; |
| 492 | } |
| 493 | else |
| 494 | { |
| 495 | Tokenizer nt(command, " "); |
| 496 | if (nt.getRestOfLine().empty()) |
| 497 | { |
| 498 | cerr << " Wrong command format ! [ndnneighbor /nbr/name/ FaceId]!" << endl; |
| 499 | return 0; |
| 500 | } |
| 501 | else |
| 502 | { |
| 503 | stringstream sst(nt.getRestOfLine().c_str()); |
| 504 | int faceId; |
| 505 | sst >> faceId; |
| 506 | Adjacent adj(nt.getFirstToken(), faceId, 0.0, 0, 0); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 507 | m_nlsr.getAdl().insert(adj); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 514 | ConfFileProcessor::processConfCommandNdnName(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 515 | { |
| 516 | if (command.empty()) |
| 517 | { |
| 518 | cerr << " Wrong command format ! [ndnname name/prefix]!" << endl; |
| 519 | } |
| 520 | else |
| 521 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 522 | m_nlsr.getNpl().insert(command); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 523 | } |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | int |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 529 | ConfFileProcessor::processConfCommandLinkCost(string command) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 530 | { |
| 531 | if (command.empty()) |
| 532 | { |
| 533 | cerr << " Wrong command format ! [link-cost nbr/name cost]!" << endl; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 534 | if (m_nlsr.getConfParameter().getIsHyperbolicCalc() > 0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 535 | { |
| 536 | return -1; |
| 537 | } |
| 538 | } |
| 539 | else |
| 540 | { |
| 541 | Tokenizer nt(command, " "); |
| 542 | stringstream sst(nt.getRestOfLine().c_str()); |
| 543 | double cost; |
| 544 | sst >> cost; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame^] | 545 | m_nlsr.getAdl().updateAdjacentLinkCost(nt.getFirstToken(), cost); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 546 | } |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | } //namespace nlsr |
| 551 | |