akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 1 | #include<string> |
| 2 | #include "nlsr_lsdb.hpp" |
| 3 | #include "nlsr.hpp" |
| 4 | |
| 5 | using namespace std; |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | bool |
| 12 | Lsdb::doesLsaExist(string key, int lsType) |
| 13 | { |
| 14 | if ( lsType == 1) |
| 15 | { |
| 16 | return doesNameLsaExist(key); |
| 17 | } |
| 18 | else if ( lsType == 2) |
| 19 | { |
| 20 | return doesAdjLsaExist(key); |
| 21 | } |
| 22 | else if ( lsType == 3) |
| 23 | { |
| 24 | return doesCorLsaExist(key); |
| 25 | } |
| 26 | |
| 27 | return false; |
| 28 | |
| 29 | } |
| 30 | |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 31 | //Name LSA and LSDB related functions start here |
| 32 | |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 33 | |
| 34 | static bool |
| 35 | nameLsaCompareByKey(NameLsa& nlsa1, string& key){ |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 36 | return nlsa1.getNameLsaKey()==key; |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | |
| 40 | bool |
| 41 | Lsdb::buildAndInstallOwnNameLsa(nlsr& pnlsr) |
| 42 | { |
| 43 | NameLsa nameLsa(pnlsr.getConfParameter().getRouterPrefix() |
| 44 | , 1 |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 45 | , pnlsr.getSm().getNameLsaSeq()+1 |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 46 | , pnlsr.getConfParameter().getRouterDeadInterval() |
| 47 | , pnlsr.getNpl() ); |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 48 | pnlsr.getSm().setNameLsaSeq(pnlsr.getSm().getNameLsaSeq()+1); |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 49 | return installNameLsa(nameLsa); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | NameLsa& |
| 54 | Lsdb::getNameLsa(string key) |
| 55 | { |
| 56 | std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(), |
| 57 | nameLsdb.end(), |
| 58 | bind(nameLsaCompareByKey, _1, key)); |
| 59 | |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 60 | if( it != nameLsdb.end()) |
| 61 | { |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 62 | return (*it); |
| 63 | } |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 64 | |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
| 68 | |
| 69 | bool |
| 70 | Lsdb::installNameLsa(NameLsa &nlsa) |
| 71 | { |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 72 | bool doesLsaExist_ = doesNameLsaExist(nlsa.getNameLsaKey()); |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 73 | if ( !doesLsaExist_ ) |
| 74 | { |
| 75 | // add name LSA |
| 76 | addNameLsa(nlsa); |
| 77 | // update NPT and FIB |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 78 | // if its not own LSA |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 79 | printNameLsdb(); |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 80 | } |
| 81 | else |
| 82 | { |
| 83 | // check for newer name LSA |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 84 | NameLsa oldNameLsa=getNameLsa(nlsa.getNameLsaKey()); |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 85 | // Discard or Update Name lsa, NPT, FIB |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 86 | // if its not own LSA |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | bool |
| 93 | Lsdb::addNameLsa(NameLsa &nlsa) |
| 94 | { |
| 95 | std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(), |
| 96 | nameLsdb.end(), |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 97 | bind(nameLsaCompareByKey, _1, nlsa.getNameLsaKey())); |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 98 | |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 99 | if( it == nameLsdb.end()) |
| 100 | { |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 101 | nameLsdb.push_back(nlsa); |
| 102 | return true; |
| 103 | } |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | bool |
| 108 | Lsdb::removeNameLsa(string& key) |
| 109 | { |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 110 | std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(), |
| 111 | nameLsdb.end(), |
| 112 | bind(nameLsaCompareByKey, _1, key)); |
| 113 | if ( it != nameLsdb.end() ) |
| 114 | { |
| 115 | nameLsdb.erase(it); |
| 116 | return true; |
| 117 | } |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 118 | return false; |
| 119 | } |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 120 | |
| 121 | bool |
| 122 | Lsdb::doesNameLsaExist(string key) |
| 123 | { |
| 124 | std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(), |
| 125 | nameLsdb.end(), |
| 126 | bind(nameLsaCompareByKey, _1, key)); |
| 127 | |
| 128 | if( it == nameLsdb.end()){ |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | return true; |
| 133 | } |
| 134 | |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 135 | void |
| 136 | Lsdb::printNameLsdb() |
| 137 | { |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 138 | cout<<"---------------Name LSDB-------------------"<<endl; |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 139 | for( std::list<NameLsa>::iterator it=nameLsdb.begin(); |
| 140 | it!= nameLsdb.end() ; it++) |
| 141 | { |
| 142 | cout<< (*it) <<endl; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // Cor LSA and LSDB related Functions start here |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 147 | /* |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 148 | static bool |
| 149 | corLsaCompare(CorLsa& clsa1, CorLsa& clsa2){ |
| 150 | return clsa1.getLsaKey()==clsa1.getLsaKey(); |
| 151 | } |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 152 | */ |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 153 | static bool |
| 154 | corLsaCompareByKey(CorLsa& clsa, string& key){ |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 155 | return clsa.getCorLsaKey()==key; |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 156 | } |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 157 | |
| 158 | bool |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 159 | Lsdb::buildAndInstallOwnCorLsa(nlsr& pnlsr){ |
| 160 | CorLsa corLsa(pnlsr.getConfParameter().getRouterPrefix() |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 161 | , 3 |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 162 | , pnlsr.getSm().getCorLsaSeq()+1 |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 163 | , pnlsr.getConfParameter().getRouterDeadInterval() |
| 164 | , pnlsr.getConfParameter().getCorR() |
| 165 | , pnlsr.getConfParameter().getCorTheta() ); |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 166 | pnlsr.getSm().setCorLsaSeq(pnlsr.getSm().getCorLsaSeq()+1); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 167 | installCorLsa(corLsa); |
| 168 | |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 169 | return true; |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | CorLsa& |
| 173 | Lsdb::getCorLsa(string key) |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 174 | { |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 175 | std::list< CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 176 | corLsdb.end(), |
| 177 | bind(corLsaCompareByKey, _1, key)); |
| 178 | |
| 179 | if( it != corLsdb.end()){ |
| 180 | return (*it); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | bool |
| 185 | Lsdb::installCorLsa(CorLsa &clsa) |
| 186 | { |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 187 | bool doesLsaExist_ = doesCorLsaExist(clsa.getCorLsaKey()); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 188 | if ( !doesLsaExist_ ) |
| 189 | { |
| 190 | // add cor LSA |
| 191 | addCorLsa(clsa); |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 192 | //schedule routing table calculation only if |
| 193 | //hyperbolic calculation is scheduled |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 194 | printCorLsdb(); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 195 | } |
| 196 | else |
| 197 | { |
| 198 | // check for newer cor LSA |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 199 | CorLsa oldCorLsa=getCorLsa(clsa.getCorLsaKey()); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 200 | |
| 201 | } |
| 202 | |
| 203 | return true; |
| 204 | } |
| 205 | |
| 206 | bool |
| 207 | Lsdb::addCorLsa(CorLsa& clsa) |
| 208 | { |
| 209 | std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 210 | corLsdb.end(), |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 211 | bind(corLsaCompareByKey, _1, clsa.getCorLsaKey())); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 212 | |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 213 | if( it == corLsdb.end()) |
| 214 | { |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 215 | corLsdb.push_back(clsa); |
| 216 | return true; |
| 217 | } |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 218 | return false; |
| 219 | } |
| 220 | |
| 221 | bool |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 222 | Lsdb::removeCorLsa(string& key) |
| 223 | { |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 224 | std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 225 | corLsdb.end(), |
| 226 | bind(corLsaCompareByKey, _1, key)); |
| 227 | if ( it != corLsdb.end() ) |
| 228 | { |
| 229 | corLsdb.erase(it); |
| 230 | return true; |
| 231 | } |
| 232 | return false; |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 233 | |
| 234 | } |
| 235 | |
| 236 | bool |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 237 | Lsdb::doesCorLsaExist(string key) |
| 238 | { |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 239 | std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 240 | corLsdb.end(), |
| 241 | bind(corLsaCompareByKey, _1, key)); |
| 242 | |
| 243 | if( it == corLsdb.end()){ |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | return true; |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 248 | } |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 249 | |
| 250 | void |
| 251 | Lsdb::printCorLsdb() //debugging |
| 252 | { |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 253 | cout<<"---------------Cor LSDB-------------------"<<endl; |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 254 | for( std::list<CorLsa>::iterator it=corLsdb.begin(); |
| 255 | it!= corLsdb.end() ; it++) |
| 256 | { |
| 257 | cout<< (*it) <<endl; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | |
| 262 | // Adj LSA and LSDB related function starts here |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 263 | /* |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 264 | static bool |
| 265 | adjLsaCompare(AdjLsa& alsa1, AdjLsa& alsa2){ |
| 266 | return alsa1.getLsaKey()==alsa1.getLsaKey(); |
| 267 | } |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 268 | */ |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 269 | static bool |
| 270 | adjLsaCompareByKey(AdjLsa& alsa, string& key){ |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 271 | return alsa.getAdjLsaKey()==key; |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 275 | void |
| 276 | Lsdb::scheduledAdjLsaBuild(nlsr& pnlsr) |
| 277 | { |
| 278 | cout<<"scheduledAdjLsaBuild Called"<<endl; |
| 279 | pnlsr.setIsBuildAdjLsaSheduled(0); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 280 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 281 | if( pnlsr.getAdl().isAdjLsaBuildable(pnlsr)) |
| 282 | { |
| 283 | int adjBuildCount=pnlsr.getAdjBuildCount(); |
| 284 | if(adjBuildCount>0 ) |
| 285 | { |
| 286 | if (pnlsr.getAdl().getNumOfActiveNeighbor()>0) |
| 287 | { |
| 288 | buildAndInstallOwnAdjLsa(pnlsr); |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | //remove if there is any adj lsa in LSDB |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 293 | string key=pnlsr.getConfParameter().getRouterPrefix()+"/2"; |
| 294 | removeAdjLsa(key); |
| 295 | // Remove alll fib entries as per NPT |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 296 | } |
| 297 | pnlsr.setAdjBuildCount(pnlsr.getAdjBuildCount()-adjBuildCount); |
| 298 | } |
| 299 | } |
| 300 | else |
| 301 | { |
| 302 | pnlsr.setIsBuildAdjLsaSheduled(1); |
| 303 | int schedulingTime=pnlsr.getConfParameter().getInterestRetryNumber()* |
| 304 | pnlsr.getConfParameter().getInterestRetryNumber(); |
| 305 | pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime), |
| 306 | ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(), |
| 307 | boost::ref(pnlsr))); |
| 308 | } |
| 309 | |
| 310 | } |
| 311 | |
| 312 | |
| 313 | bool |
| 314 | Lsdb::addAdjLsa(AdjLsa &alsa) |
| 315 | { |
| 316 | std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 317 | adjLsdb.end(), |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 318 | bind(adjLsaCompareByKey, _1, alsa.getAdjLsaKey())); |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 319 | |
| 320 | if( it == adjLsdb.end()){ |
| 321 | adjLsdb.push_back(alsa); |
| 322 | return true; |
| 323 | } |
| 324 | return false; |
| 325 | |
| 326 | } |
| 327 | |
| 328 | AdjLsa& |
| 329 | Lsdb::getAdjLsa(string key) |
| 330 | { |
| 331 | std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 332 | adjLsdb.end(), |
| 333 | bind(adjLsaCompareByKey, _1, key)); |
| 334 | |
| 335 | if( it != adjLsdb.end()){ |
| 336 | return (*it); |
| 337 | } |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | bool |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 341 | Lsdb::installAdjLsa(nlsr& pnlsr, AdjLsa &alsa) |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 342 | { |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 343 | bool doesLsaExist_ = doesAdjLsaExist(alsa.getAdjLsaKey()); |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 344 | if ( !doesLsaExist_ ) |
| 345 | { |
| 346 | // add Adj LSA |
| 347 | addAdjLsa(alsa); |
| 348 | // schedule routing table calculation |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 349 | if ( pnlsr.getIsRouteCalculationScheduled() != 1 ) |
| 350 | { |
| 351 | pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15), |
| 352 | ndn::bind(&RoutingTable::calculate, |
| 353 | &pnlsr.getRoutingTable(),boost::ref(pnlsr))); |
| 354 | pnlsr.setIsRouteCalculationScheduled(1); |
| 355 | } |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 356 | } |
| 357 | else |
| 358 | { |
| 359 | // check for newer name LSA |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame^] | 360 | AdjLsa oldAdjLsa=getAdjLsa(alsa.getAdjLsaKey()); |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 361 | |
| 362 | } |
| 363 | |
| 364 | printAdjLsdb(); |
| 365 | |
| 366 | return true; |
| 367 | } |
| 368 | |
| 369 | bool |
| 370 | Lsdb::buildAndInstallOwnAdjLsa(nlsr& pnlsr) |
| 371 | { |
| 372 | AdjLsa adjLsa(pnlsr.getConfParameter().getRouterPrefix() |
| 373 | , 2 |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 374 | , pnlsr.getSm().getAdjLsaSeq()+1 |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 375 | , pnlsr.getConfParameter().getRouterDeadInterval() |
| 376 | , pnlsr.getAdl().getNumOfActiveNeighbor() |
| 377 | , pnlsr.getAdl() ); |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 378 | pnlsr.getSm().setAdjLsaSeq(pnlsr.getSm().getAdjLsaSeq()+1); |
| 379 | return installAdjLsa(pnlsr, adjLsa); |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | bool |
| 383 | Lsdb::removeAdjLsa(string& key) |
| 384 | { |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 385 | std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 386 | adjLsdb.end(), |
| 387 | bind(adjLsaCompareByKey, _1, key)); |
| 388 | if ( it != adjLsdb.end() ) |
| 389 | { |
| 390 | adjLsdb.erase(it); |
| 391 | return true; |
| 392 | } |
| 393 | return false; |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 394 | |
| 395 | } |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 396 | |
| 397 | bool |
| 398 | Lsdb::doesAdjLsaExist(string key) |
| 399 | { |
| 400 | std::list< AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 401 | adjLsdb.end(), |
| 402 | bind(adjLsaCompareByKey, _1, key)); |
| 403 | |
| 404 | if( it == adjLsdb.end()){ |
| 405 | return false; |
| 406 | } |
| 407 | |
| 408 | return true; |
| 409 | } |
| 410 | |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 411 | std::list<AdjLsa>& |
| 412 | Lsdb::getAdjLsdb() |
| 413 | { |
| 414 | return adjLsdb; |
| 415 | } |
| 416 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 417 | void |
| 418 | Lsdb::printAdjLsdb() |
| 419 | { |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 420 | cout<<"---------------Adj LSDB-------------------"<<endl; |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 421 | for( std::list<AdjLsa>::iterator it=adjLsdb.begin(); |
| 422 | it!= adjLsdb.end() ; it++) |
| 423 | { |
| 424 | cout<< (*it) <<endl; |
| 425 | } |
| 426 | } |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 427 | |