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