akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 1 | #include<string> |
| 2 | #include<utility> |
| 3 | #include "nlsr_lsdb.hpp" |
| 4 | #include "nlsr.hpp" |
| 5 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 6 | namespace nlsr |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 7 | { |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 8 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 9 | using namespace std; |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 10 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 11 | void |
| 12 | Lsdb::cancelScheduleLsaExpiringEvent(Nlsr& pnlsr, EventId eid) |
| 13 | { |
| 14 | pnlsr.getScheduler().cancelEvent(eid); |
| 15 | } |
| 16 | |
| 17 | static bool |
| 18 | nameLsaCompareByKey(NameLsa& nlsa1, string& key) |
| 19 | { |
| 20 | return nlsa1.getNameLsaKey()==key; |
| 21 | } |
| 22 | |
| 23 | |
| 24 | bool |
| 25 | Lsdb::buildAndInstallOwnNameLsa(Nlsr& pnlsr) |
| 26 | { |
| 27 | NameLsa nameLsa(pnlsr.getConfParameter().getRouterPrefix() |
| 28 | , 1 |
| 29 | , pnlsr.getSm().getNameLsaSeq()+1 |
| 30 | , pnlsr.getConfParameter().getRouterDeadInterval() |
| 31 | , pnlsr.getNpl() ); |
| 32 | pnlsr.getSm().setNameLsaSeq(pnlsr.getSm().getNameLsaSeq()+1); |
| 33 | return installNameLsa(pnlsr,nameLsa); |
| 34 | } |
| 35 | |
| 36 | std::pair<NameLsa&, bool> |
| 37 | Lsdb::getNameLsa(string key) |
| 38 | { |
| 39 | std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(), |
| 40 | nameLsdb.end(), |
| 41 | bind(nameLsaCompareByKey, _1, key)); |
| 42 | if( it != nameLsdb.end()) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 43 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 44 | return std::make_pair(boost::ref((*it)),true); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 45 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 46 | NameLsa nlsa; |
| 47 | return std::make_pair(boost::ref(nlsa),false); |
| 48 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 49 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 50 | bool |
| 51 | Lsdb::isNameLsaNew(string key, uint64_t seqNo) |
| 52 | { |
| 53 | std::pair<NameLsa& , bool> nameLsaCheck=getNameLsa(key); |
| 54 | if(nameLsaCheck.second) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 55 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 56 | if(nameLsaCheck.first.getLsSeqNo() < seqNo) |
| 57 | { |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 58 | return true; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 59 | } |
| 60 | else |
| 61 | { |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 62 | return false; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 63 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 64 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 65 | return true; |
| 66 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 67 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 68 | ndn::EventId |
| 69 | Lsdb::scheduleNameLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime) |
| 70 | { |
| 71 | return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime), |
| 72 | ndn::bind(&Lsdb::exprireOrRefreshNameLsa, |
| 73 | this,boost::ref(pnlsr), key, seqNo)); |
| 74 | } |
| 75 | |
| 76 | bool |
| 77 | Lsdb::installNameLsa(Nlsr& pnlsr, NameLsa &nlsa) |
| 78 | { |
| 79 | int timeToExpire=lsaRefreshTime; |
| 80 | std::pair<NameLsa& , bool> chkNameLsa=getNameLsa(nlsa.getNameLsaKey()); |
| 81 | if ( !chkNameLsa.second ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 82 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 83 | addNameLsa(nlsa); |
| 84 | printNameLsdb(); |
| 85 | if ( nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 86 | { |
| 87 | pnlsr.getNpt().addNpteByDestName(nlsa.getOrigRouter(),nlsa.getOrigRouter(), |
| 88 | pnlsr); |
| 89 | std::list<string> nameList=nlsa.getNpl().getNameList(); |
| 90 | for(std::list<string>::iterator it=nameList.begin(); it!=nameList.end(); it++) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 91 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 92 | if ( (*it) !=pnlsr.getConfParameter().getRouterPrefix()) |
| 93 | { |
| 94 | pnlsr.getNpt().addNpteByDestName((*it),nlsa.getOrigRouter(),pnlsr); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | if(nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 99 | { |
| 100 | timeToExpire=nlsa.getLifeTime(); |
| 101 | } |
| 102 | nlsa.setLsaExpiringEventId(scheduleNameLsaExpiration( pnlsr, |
| 103 | nlsa.getNameLsaKey(), nlsa.getLsSeqNo(), timeToExpire)); |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | if ( chkNameLsa.first.getLsSeqNo() < nlsa.getLsSeqNo() ) |
| 108 | { |
| 109 | chkNameLsa.first.setLsSeqNo(nlsa.getLsSeqNo()); |
| 110 | chkNameLsa.first.setLifeTime(nlsa.getLifeTime()); |
| 111 | chkNameLsa.first.getNpl().sortNpl(); |
| 112 | nlsa.getNpl().sortNpl(); |
| 113 | std::list<string> nameToAdd; |
| 114 | std::set_difference(nlsa.getNpl().getNameList().begin(), |
| 115 | nlsa.getNpl().getNameList().end(), |
| 116 | chkNameLsa.first.getNpl().getNameList().begin(), |
| 117 | chkNameLsa.first.getNpl().getNameList().end(), |
| 118 | std::inserter(nameToAdd, nameToAdd.begin())); |
| 119 | for(std::list<string>::iterator it=nameToAdd.begin(); it!=nameToAdd.end(); |
| 120 | ++it) |
| 121 | { |
| 122 | chkNameLsa.first.addNameToLsa((*it)); |
| 123 | if ( nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 124 | { |
| 125 | if ( (*it) !=pnlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 126 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 127 | pnlsr.getNpt().addNpteByDestName((*it),nlsa.getOrigRouter(),pnlsr); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 128 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 129 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 130 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 131 | std::list<string> nameToRemove; |
| 132 | std::set_difference(chkNameLsa.first.getNpl().getNameList().begin(), |
| 133 | chkNameLsa.first.getNpl().getNameList().end(), |
| 134 | nlsa.getNpl().getNameList().begin(), |
| 135 | nlsa.getNpl().getNameList().end(), |
| 136 | std::inserter(nameToRemove, nameToRemove.begin())); |
| 137 | for(std::list<string>::iterator it=nameToRemove.begin(); |
| 138 | it!=nameToRemove.end(); ++it) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 139 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 140 | chkNameLsa.first.removeNameFromLsa((*it)); |
| 141 | if ( nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 142 | { |
| 143 | if ( (*it) !=pnlsr.getConfParameter().getRouterPrefix()) |
| 144 | { |
| 145 | pnlsr.getNpt().removeNpte((*it),nlsa.getOrigRouter(),pnlsr); |
| 146 | } |
| 147 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 148 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 149 | if(nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 150 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 151 | timeToExpire=nlsa.getLifeTime(); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 152 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 153 | cancelScheduleLsaExpiringEvent(pnlsr, |
| 154 | chkNameLsa.first.getLsaExpiringEventId()); |
| 155 | chkNameLsa.first.setLsaExpiringEventId(scheduleNameLsaExpiration( pnlsr, |
| 156 | nlsa.getNameLsaKey(), nlsa.getLsSeqNo(), timeToExpire)); |
| 157 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 158 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 159 | return true; |
| 160 | } |
| 161 | |
| 162 | bool |
| 163 | Lsdb::addNameLsa(NameLsa &nlsa) |
| 164 | { |
| 165 | std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(), |
| 166 | nameLsdb.end(), bind(nameLsaCompareByKey, _1, nlsa.getNameLsaKey())); |
| 167 | if( it == nameLsdb.end()) |
| 168 | { |
| 169 | nameLsdb.push_back(nlsa); |
| 170 | return true; |
| 171 | } |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | bool |
| 176 | Lsdb::removeNameLsa(Nlsr& pnlsr, string& key) |
| 177 | { |
| 178 | std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(), |
| 179 | nameLsdb.end(), |
| 180 | bind(nameLsaCompareByKey, _1, key)); |
| 181 | if ( it != nameLsdb.end() ) |
| 182 | { |
| 183 | if ( (*it).getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix() ) |
| 184 | { |
| 185 | pnlsr.getNpt().removeNpte((*it).getOrigRouter(),(*it).getOrigRouter(),pnlsr); |
| 186 | for( std::list<string>::iterator nit=(*it).getNpl().getNameList().begin(); |
| 187 | nit!=(*it).getNpl().getNameList().end(); ++nit) |
| 188 | { |
| 189 | if ( (*nit) !=pnlsr.getConfParameter().getRouterPrefix()) |
| 190 | { |
| 191 | pnlsr.getNpt().removeNpte((*nit),(*it).getOrigRouter(),pnlsr); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | nameLsdb.erase(it); |
| 196 | return true; |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | bool |
| 202 | Lsdb::doesNameLsaExist(string key) |
| 203 | { |
| 204 | std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(), |
| 205 | nameLsdb.end(), |
| 206 | bind(nameLsaCompareByKey, _1, key)); |
| 207 | if( it == nameLsdb.end()) |
| 208 | { |
| 209 | return false; |
| 210 | } |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | void |
| 215 | Lsdb::printNameLsdb() |
| 216 | { |
| 217 | cout<<"---------------Name LSDB-------------------"<<endl; |
| 218 | for( std::list<NameLsa>::iterator it=nameLsdb.begin(); |
| 219 | it!= nameLsdb.end() ; it++) |
| 220 | { |
| 221 | cout<< (*it) <<endl; |
| 222 | } |
| 223 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 224 | |
| 225 | // Cor LSA and LSDB related Functions start here |
| 226 | |
| 227 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 228 | static bool |
| 229 | corLsaCompareByKey(CorLsa& clsa, string& key) |
| 230 | { |
| 231 | return clsa.getCorLsaKey()==key; |
| 232 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 233 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 234 | bool |
| 235 | Lsdb::buildAndInstallOwnCorLsa(Nlsr& pnlsr) |
| 236 | { |
| 237 | CorLsa corLsa(pnlsr.getConfParameter().getRouterPrefix() |
| 238 | , 3 |
| 239 | , pnlsr.getSm().getCorLsaSeq()+1 |
| 240 | , pnlsr.getConfParameter().getRouterDeadInterval() |
| 241 | , pnlsr.getConfParameter().getCorR() |
| 242 | , pnlsr.getConfParameter().getCorTheta() ); |
| 243 | pnlsr.getSm().setCorLsaSeq(pnlsr.getSm().getCorLsaSeq()+1); |
| 244 | installCorLsa(pnlsr, corLsa); |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | std::pair<CorLsa&, bool> |
| 249 | Lsdb::getCorLsa(string key) |
| 250 | { |
| 251 | std::list< CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 252 | corLsdb.end(), |
| 253 | bind(corLsaCompareByKey, _1, key)); |
| 254 | if( it != corLsdb.end()) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 255 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 256 | return std::make_pair(boost::ref((*it)), true); |
| 257 | } |
| 258 | CorLsa clsa; |
| 259 | return std::make_pair(boost::ref(clsa),false); |
| 260 | } |
| 261 | |
| 262 | bool |
| 263 | Lsdb::isCorLsaNew(string key, uint64_t seqNo) |
| 264 | { |
| 265 | std::pair<CorLsa& , bool> corLsaCheck=getCorLsa(key); |
| 266 | if(corLsaCheck.second) |
| 267 | { |
| 268 | if(corLsaCheck.first.getLsSeqNo() < seqNo) |
| 269 | { |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 270 | return true; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 271 | } |
| 272 | else |
| 273 | { |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 274 | return false; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 275 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 276 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 277 | return true; |
| 278 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 279 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 280 | ndn::EventId |
| 281 | Lsdb::scheduleCorLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime) |
| 282 | { |
| 283 | return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime), |
| 284 | ndn::bind(&Lsdb::exprireOrRefreshCorLsa, |
| 285 | this,boost::ref(pnlsr),key,seqNo)); |
| 286 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 287 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 288 | bool |
| 289 | Lsdb::installCorLsa(Nlsr& pnlsr, CorLsa &clsa) |
| 290 | { |
| 291 | int timeToExpire=lsaRefreshTime; |
| 292 | std::pair<CorLsa& , bool> chkCorLsa=getCorLsa(clsa.getCorLsaKey()); |
| 293 | if ( !chkCorLsa.second ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 294 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 295 | addCorLsa(clsa); |
| 296 | printCorLsdb(); //debugging purpose |
| 297 | if ( clsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 298 | { |
| 299 | pnlsr.getNpt().addNpteByDestName(clsa.getOrigRouter(),clsa.getOrigRouter(), |
| 300 | pnlsr); |
| 301 | } |
| 302 | if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 ) |
| 303 | { |
| 304 | pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr); |
| 305 | } |
| 306 | if(clsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 307 | { |
| 308 | timeToExpire=clsa.getLifeTime(); |
| 309 | } |
| 310 | scheduleCorLsaExpiration(pnlsr,clsa.getCorLsaKey(), |
| 311 | clsa.getLsSeqNo(), timeToExpire); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 312 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 313 | else |
| 314 | { |
| 315 | if ( chkCorLsa.first.getLsSeqNo() < clsa.getLsSeqNo() ) |
| 316 | { |
| 317 | chkCorLsa.first.setLsSeqNo(clsa.getLsSeqNo()); |
| 318 | chkCorLsa.first.setLifeTime(clsa.getLifeTime()); |
| 319 | if ( !chkCorLsa.first.isLsaContentEqual(clsa) ) |
| 320 | { |
| 321 | chkCorLsa.first.setCorRadius(clsa.getCorRadius()); |
| 322 | chkCorLsa.first.setCorTheta(clsa.getCorTheta()); |
| 323 | if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 ) |
| 324 | { |
| 325 | pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr); |
| 326 | } |
| 327 | } |
| 328 | if(clsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 329 | { |
| 330 | timeToExpire=clsa.getLifeTime(); |
| 331 | } |
| 332 | cancelScheduleLsaExpiringEvent(pnlsr, |
| 333 | chkCorLsa.first.getLsaExpiringEventId()); |
| 334 | chkCorLsa.first.setLsaExpiringEventId(scheduleCorLsaExpiration(pnlsr, |
| 335 | clsa.getCorLsaKey(), |
| 336 | clsa.getLsSeqNo(), timeToExpire)); |
| 337 | } |
| 338 | } |
| 339 | return true; |
| 340 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 341 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 342 | bool |
| 343 | Lsdb::addCorLsa(CorLsa& clsa) |
| 344 | { |
| 345 | std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 346 | corLsdb.end(), |
| 347 | bind(corLsaCompareByKey, _1, clsa.getCorLsaKey())); |
| 348 | if( it == corLsdb.end()) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 349 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 350 | corLsdb.push_back(clsa); |
| 351 | return true; |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 352 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 353 | return false; |
| 354 | } |
| 355 | |
| 356 | bool |
| 357 | Lsdb::removeCorLsa(Nlsr& pnlsr, string& key) |
| 358 | { |
| 359 | std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 360 | corLsdb.end(), |
| 361 | bind(corLsaCompareByKey, _1, key)); |
| 362 | if ( it != corLsdb.end() ) |
| 363 | { |
| 364 | if ( (*it).getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 365 | { |
| 366 | pnlsr.getNpt().removeNpte((*it).getOrigRouter(),(*it).getOrigRouter(),pnlsr); |
| 367 | } |
| 368 | corLsdb.erase(it); |
| 369 | return true; |
| 370 | } |
| 371 | return false; |
| 372 | } |
| 373 | |
| 374 | bool |
| 375 | Lsdb::doesCorLsaExist(string key) |
| 376 | { |
| 377 | std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 378 | corLsdb.end(), |
| 379 | bind(corLsaCompareByKey, _1, key)); |
| 380 | if( it == corLsdb.end()) |
| 381 | { |
| 382 | return false; |
| 383 | } |
| 384 | return true; |
| 385 | } |
| 386 | |
| 387 | void |
| 388 | Lsdb::printCorLsdb() //debugging |
| 389 | { |
| 390 | cout<<"---------------Cor LSDB-------------------"<<endl; |
| 391 | for( std::list<CorLsa>::iterator it=corLsdb.begin(); |
| 392 | it!= corLsdb.end() ; it++) |
| 393 | { |
| 394 | cout<< (*it) <<endl; |
| 395 | } |
| 396 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 397 | |
| 398 | |
| 399 | // Adj LSA and LSDB related function starts here |
| 400 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 401 | static bool |
| 402 | adjLsaCompareByKey(AdjLsa& alsa, string& key) |
| 403 | { |
| 404 | return alsa.getAdjLsaKey()==key; |
| 405 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 406 | |
| 407 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 408 | void |
| 409 | Lsdb::scheduledAdjLsaBuild(Nlsr& pnlsr) |
| 410 | { |
| 411 | cout<<"scheduledAdjLsaBuild Called"<<endl; |
| 412 | pnlsr.setIsBuildAdjLsaSheduled(0); |
| 413 | if( pnlsr.getAdl().isAdjLsaBuildable(pnlsr)) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 414 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 415 | int adjBuildCount=pnlsr.getAdjBuildCount(); |
| 416 | if(adjBuildCount>0 ) |
| 417 | { |
| 418 | if (pnlsr.getAdl().getNumOfActiveNeighbor()>0) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 419 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 420 | buildAndInstallOwnAdjLsa(pnlsr); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 421 | } |
| 422 | else |
| 423 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 424 | string key=pnlsr.getConfParameter().getRouterPrefix()+"/2"; |
| 425 | removeAdjLsa(pnlsr,key); |
| 426 | pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 427 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 428 | pnlsr.setAdjBuildCount(pnlsr.getAdjBuildCount()-adjBuildCount); |
| 429 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 430 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 431 | else |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 432 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 433 | pnlsr.setIsBuildAdjLsaSheduled(1); |
| 434 | int schedulingTime=pnlsr.getConfParameter().getInterestRetryNumber()* |
| 435 | pnlsr.getConfParameter().getInterestResendTime(); |
| 436 | pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime), |
| 437 | ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(), |
| 438 | boost::ref(pnlsr))); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 439 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 440 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 441 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 442 | |
| 443 | bool |
| 444 | Lsdb::addAdjLsa(AdjLsa &alsa) |
| 445 | { |
| 446 | std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 447 | adjLsdb.end(), |
| 448 | bind(adjLsaCompareByKey, _1, alsa.getAdjLsaKey())); |
| 449 | if( it == adjLsdb.end()) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 450 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 451 | adjLsdb.push_back(alsa); |
| 452 | return true; |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 453 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 454 | return false; |
| 455 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 456 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 457 | std::pair<AdjLsa& , bool> |
| 458 | Lsdb::getAdjLsa(string key) |
| 459 | { |
| 460 | std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 461 | adjLsdb.end(), |
| 462 | bind(adjLsaCompareByKey, _1, key)); |
| 463 | if( it != adjLsdb.end()) |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 464 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 465 | return std::make_pair(boost::ref((*it)),true); |
| 466 | } |
| 467 | AdjLsa alsa; |
| 468 | return std::make_pair(boost::ref(alsa),false); |
| 469 | } |
| 470 | |
| 471 | |
| 472 | bool |
| 473 | Lsdb::isAdjLsaNew(string key, uint64_t seqNo) |
| 474 | { |
| 475 | std::pair<AdjLsa& , bool> adjLsaCheck=getAdjLsa(key); |
| 476 | if(adjLsaCheck.second) |
| 477 | { |
| 478 | if(adjLsaCheck.first.getLsSeqNo() < seqNo) |
| 479 | { |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 480 | return true; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 481 | } |
| 482 | else |
| 483 | { |
| 484 | return false; |
| 485 | } |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 486 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 487 | return true; |
| 488 | } |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 489 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 490 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 491 | ndn::EventId |
| 492 | Lsdb::scheduleAdjLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime) |
| 493 | { |
| 494 | return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime), |
| 495 | ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, |
| 496 | this,boost::ref(pnlsr),key,seqNo)); |
| 497 | } |
| 498 | |
| 499 | bool |
| 500 | Lsdb::installAdjLsa(Nlsr& pnlsr, AdjLsa &alsa) |
| 501 | { |
| 502 | int timeToExpire=lsaRefreshTime; |
| 503 | std::pair<AdjLsa& , bool> chkAdjLsa=getAdjLsa(alsa.getAdjLsaKey()); |
| 504 | if ( !chkAdjLsa.second ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 505 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 506 | addAdjLsa(alsa); |
| 507 | alsa.addNptEntriesForAdjLsa(pnlsr); |
| 508 | pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr); |
| 509 | if(alsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 510 | { |
| 511 | timeToExpire=alsa.getLifeTime(); |
| 512 | } |
| 513 | scheduleAdjLsaExpiration(pnlsr,alsa.getAdjLsaKey(), |
| 514 | alsa.getLsSeqNo(),timeToExpire); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 515 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 516 | else |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 517 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 518 | if ( chkAdjLsa.first.getLsSeqNo() < alsa.getLsSeqNo() ) |
| 519 | { |
| 520 | chkAdjLsa.first.setLsSeqNo(alsa.getLsSeqNo()); |
| 521 | chkAdjLsa.first.setLifeTime(alsa.getLifeTime()); |
| 522 | if ( ! chkAdjLsa.first.isLsaContentEqual(alsa)) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 523 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 524 | chkAdjLsa.first.getAdl().resetAdl(); |
| 525 | chkAdjLsa.first.getAdl().addAdjacentsFromAdl(alsa.getAdl()); |
| 526 | pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr); |
| 527 | } |
| 528 | if(alsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() ) |
| 529 | { |
| 530 | timeToExpire=alsa.getLifeTime(); |
| 531 | } |
| 532 | cancelScheduleLsaExpiringEvent(pnlsr, |
| 533 | chkAdjLsa.first.getLsaExpiringEventId()); |
| 534 | chkAdjLsa.first.setLsaExpiringEventId(scheduleAdjLsaExpiration(pnlsr, |
| 535 | alsa.getAdjLsaKey(), alsa.getLsSeqNo(),timeToExpire)); |
| 536 | } |
| 537 | } |
| 538 | return true; |
| 539 | } |
| 540 | |
| 541 | bool |
| 542 | Lsdb::buildAndInstallOwnAdjLsa(Nlsr& pnlsr) |
| 543 | { |
| 544 | AdjLsa adjLsa(pnlsr.getConfParameter().getRouterPrefix() |
| 545 | , 2 |
| 546 | , pnlsr.getSm().getAdjLsaSeq()+1 |
| 547 | , pnlsr.getConfParameter().getRouterDeadInterval() |
| 548 | , pnlsr.getAdl().getNumOfActiveNeighbor() |
| 549 | , pnlsr.getAdl() ); |
| 550 | pnlsr.getSm().setAdjLsaSeq(pnlsr.getSm().getAdjLsaSeq()+1); |
| 551 | string lsaPrefix=pnlsr.getConfParameter().getChronosyncLsaPrefix() |
| 552 | + pnlsr.getConfParameter().getRouterPrefix(); |
| 553 | pnlsr.getSlh().publishRoutingUpdate(pnlsr.getSm(),lsaPrefix); |
| 554 | return pnlsr.getLsdb().installAdjLsa(pnlsr, adjLsa); |
| 555 | } |
| 556 | |
| 557 | bool |
| 558 | Lsdb::removeAdjLsa(Nlsr& pnlsr, string& key) |
| 559 | { |
| 560 | std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 561 | adjLsdb.end(), |
| 562 | bind(adjLsaCompareByKey, _1, key)); |
| 563 | if ( it != adjLsdb.end() ) |
| 564 | { |
| 565 | (*it).removeNptEntriesForAdjLsa(pnlsr); |
| 566 | adjLsdb.erase(it); |
| 567 | return true; |
| 568 | } |
| 569 | return false; |
| 570 | } |
| 571 | |
| 572 | bool |
| 573 | Lsdb::doesAdjLsaExist(string key) |
| 574 | { |
| 575 | std::list< AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 576 | adjLsdb.end(), |
| 577 | bind(adjLsaCompareByKey, _1, key)); |
| 578 | if( it == adjLsdb.end()) |
| 579 | { |
| 580 | return false; |
| 581 | } |
| 582 | return true; |
| 583 | } |
| 584 | |
| 585 | std::list<AdjLsa>& |
| 586 | Lsdb::getAdjLsdb() |
| 587 | { |
| 588 | return adjLsdb; |
| 589 | } |
| 590 | |
| 591 | void |
| 592 | Lsdb::setLsaRefreshTime(int lrt) |
| 593 | { |
| 594 | lsaRefreshTime=lrt; |
| 595 | } |
| 596 | |
| 597 | void |
| 598 | Lsdb::setThisRouterPrefix(string trp) |
| 599 | { |
| 600 | thisRouterPrefix=trp; |
| 601 | } |
| 602 | |
| 603 | void |
| 604 | Lsdb::exprireOrRefreshNameLsa(Nlsr& pnlsr, string lsaKey, int seqNo) |
| 605 | { |
| 606 | cout<<"Lsdb::exprireOrRefreshNameLsa Called "<<endl; |
| 607 | cout<<"LSA Key : "<<lsaKey<<" Seq No: "<<seqNo<<endl; |
| 608 | std::pair<NameLsa& , bool> chkNameLsa=getNameLsa(lsaKey); |
| 609 | if( chkNameLsa.second ) |
| 610 | { |
| 611 | cout<<" LSA Exists with seq no: "<<chkNameLsa.first.getLsSeqNo()<<endl; |
| 612 | if ( chkNameLsa.first.getLsSeqNo() == seqNo ) |
| 613 | { |
| 614 | if(chkNameLsa.first.getOrigRouter() == thisRouterPrefix ) |
| 615 | { |
| 616 | cout<<"Own Name LSA, so refreshing name LSA"<<endl; |
| 617 | chkNameLsa.first.setLsSeqNo(chkNameLsa.first.getLsSeqNo()+1); |
| 618 | pnlsr.getSm().setNameLsaSeq(chkNameLsa.first.getLsSeqNo()); |
| 619 | // publish routing update |
| 620 | string lsaPrefix=pnlsr.getConfParameter().getChronosyncLsaPrefix() |
| 621 | + pnlsr.getConfParameter().getRouterPrefix(); |
| 622 | pnlsr.getSlh().publishRoutingUpdate(pnlsr.getSm(),lsaPrefix); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 623 | } |
| 624 | else |
| 625 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 626 | cout<<"Other's Name LSA, so removing form LSDB"<<endl; |
| 627 | removeNameLsa(pnlsr, lsaKey); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 628 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 629 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 630 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 631 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 632 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 633 | void |
| 634 | Lsdb::exprireOrRefreshAdjLsa(Nlsr& pnlsr, string lsaKey, int seqNo) |
| 635 | { |
| 636 | cout<<"Lsdb::exprireOrRefreshAdjLsa Called "<<endl; |
| 637 | cout<<"LSA Key : "<<lsaKey<<" Seq No: "<<seqNo<<endl; |
| 638 | std::pair<AdjLsa& , bool> chkAdjLsa=getAdjLsa(lsaKey); |
| 639 | if( chkAdjLsa.second ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 640 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 641 | cout<<" LSA Exists with seq no: "<<chkAdjLsa.first.getLsSeqNo()<<endl; |
| 642 | if ( chkAdjLsa.first.getLsSeqNo() == seqNo ) |
| 643 | { |
| 644 | if(chkAdjLsa.first.getOrigRouter() == thisRouterPrefix ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 645 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 646 | cout<<"Own Adj LSA, so refreshing Adj LSA"<<endl; |
| 647 | chkAdjLsa.first.setLsSeqNo(chkAdjLsa.first.getLsSeqNo()+1); |
| 648 | pnlsr.getSm().setAdjLsaSeq(chkAdjLsa.first.getLsSeqNo()); |
| 649 | // publish routing update |
| 650 | string lsaPrefix=pnlsr.getConfParameter().getChronosyncLsaPrefix() |
| 651 | + pnlsr.getConfParameter().getRouterPrefix(); |
| 652 | pnlsr.getSlh().publishRoutingUpdate(pnlsr.getSm(),lsaPrefix); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 653 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 654 | else |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 655 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 656 | cout<<"Other's Adj LSA, so removing form LSDB"<<endl; |
| 657 | removeAdjLsa(pnlsr, lsaKey); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 658 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 659 | // schedule Routing table calculaiton |
| 660 | pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr); |
| 661 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 662 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 663 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 664 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 665 | void |
| 666 | Lsdb::exprireOrRefreshCorLsa(Nlsr& pnlsr, string lsaKey, int seqNo) |
| 667 | { |
| 668 | cout<<"Lsdb::exprireOrRefreshCorLsa Called "<<endl; |
| 669 | cout<<"LSA Key : "<<lsaKey<<" Seq No: "<<seqNo<<endl; |
| 670 | std::pair<CorLsa& , bool> chkCorLsa=getCorLsa(lsaKey); |
| 671 | if( chkCorLsa.second ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 672 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 673 | cout<<" LSA Exists with seq no: "<<chkCorLsa.first.getLsSeqNo()<<endl; |
| 674 | if ( chkCorLsa.first.getLsSeqNo() == seqNo ) |
| 675 | { |
| 676 | if(chkCorLsa.first.getOrigRouter() == thisRouterPrefix ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 677 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 678 | cout<<"Own Cor LSA, so refreshing Cor LSA"<<endl; |
| 679 | chkCorLsa.first.setLsSeqNo(chkCorLsa.first.getLsSeqNo()+1); |
| 680 | pnlsr.getSm().setCorLsaSeq(chkCorLsa.first.getLsSeqNo()); |
| 681 | // publish routing update |
| 682 | string lsaPrefix=pnlsr.getConfParameter().getChronosyncLsaPrefix() |
| 683 | + pnlsr.getConfParameter().getRouterPrefix(); |
| 684 | pnlsr.getSlh().publishRoutingUpdate(pnlsr.getSm(),lsaPrefix); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 685 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 686 | else |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 687 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 688 | cout<<"Other's Cor LSA, so removing form LSDB"<<endl; |
| 689 | removeCorLsa(pnlsr, lsaKey); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 690 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 691 | if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 ) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 692 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 693 | pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 694 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 695 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 696 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 697 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 698 | |
| 699 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 700 | void |
| 701 | Lsdb::printAdjLsdb() |
| 702 | { |
| 703 | cout<<"---------------Adj LSDB-------------------"<<endl; |
| 704 | for( std::list<AdjLsa>::iterator it=adjLsdb.begin(); |
| 705 | it!= adjLsdb.end() ; it++) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 706 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 707 | cout<< (*it) <<endl; |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 708 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 709 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 710 | |
| 711 | //-----utility function ----- |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 712 | bool |
| 713 | Lsdb::doesLsaExist(string key, int lsType) |
| 714 | { |
| 715 | if ( lsType == 1) |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 716 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 717 | return doesNameLsaExist(key); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 718 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 719 | else if ( lsType == 2) |
| 720 | { |
| 721 | return doesAdjLsaExist(key); |
| 722 | } |
| 723 | else if ( lsType == 3) |
| 724 | { |
| 725 | return doesCorLsaExist(key); |
| 726 | } |
| 727 | return false; |
| 728 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 729 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 730 | }//namespace nlsr |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 731 | |