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