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 | f7c2c7c | 2014-02-06 11:32:43 -0600 | [diff] [blame^] | 167 | installCorLsa(pnlsr, corLsa); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 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 |
akmhoque | f7c2c7c | 2014-02-06 11:32:43 -0600 | [diff] [blame^] | 185 | Lsdb::installCorLsa(nlsr& pnlsr, CorLsa &clsa) |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 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 | f7c2c7c | 2014-02-06 11:32:43 -0600 | [diff] [blame^] | 192 | printCorLsdb(); //debugging purpose |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 193 | //schedule routing table calculation only if |
| 194 | //hyperbolic calculation is scheduled |
akmhoque | f7c2c7c | 2014-02-06 11:32:43 -0600 | [diff] [blame^] | 195 | if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 ) |
| 196 | { |
| 197 | if ( pnlsr.getIsRouteCalculationScheduled() != 1 ) |
| 198 | { |
| 199 | pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15), |
| 200 | ndn::bind(&RoutingTable::calculate, |
| 201 | &pnlsr.getRoutingTable(),boost::ref(pnlsr))); |
| 202 | pnlsr.setIsRouteCalculationScheduled(1); |
| 203 | } |
| 204 | } |
| 205 | |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 206 | } |
| 207 | else |
| 208 | { |
| 209 | // check for newer cor LSA |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 210 | CorLsa oldCorLsa=getCorLsa(clsa.getCorLsaKey()); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 211 | |
| 212 | } |
| 213 | |
| 214 | return true; |
| 215 | } |
| 216 | |
| 217 | bool |
| 218 | Lsdb::addCorLsa(CorLsa& clsa) |
| 219 | { |
| 220 | std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 221 | corLsdb.end(), |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 222 | bind(corLsaCompareByKey, _1, clsa.getCorLsaKey())); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 223 | |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 224 | if( it == corLsdb.end()) |
| 225 | { |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 226 | corLsdb.push_back(clsa); |
| 227 | return true; |
| 228 | } |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 229 | return false; |
| 230 | } |
| 231 | |
| 232 | bool |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 233 | Lsdb::removeCorLsa(string& key) |
| 234 | { |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 235 | std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 236 | corLsdb.end(), |
| 237 | bind(corLsaCompareByKey, _1, key)); |
| 238 | if ( it != corLsdb.end() ) |
| 239 | { |
| 240 | corLsdb.erase(it); |
| 241 | return true; |
| 242 | } |
| 243 | return false; |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 244 | |
| 245 | } |
| 246 | |
| 247 | bool |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 248 | Lsdb::doesCorLsaExist(string key) |
| 249 | { |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 250 | std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(), |
| 251 | corLsdb.end(), |
| 252 | bind(corLsaCompareByKey, _1, key)); |
| 253 | |
| 254 | if( it == corLsdb.end()){ |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | return true; |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 259 | } |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 260 | |
| 261 | void |
| 262 | Lsdb::printCorLsdb() //debugging |
| 263 | { |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 264 | cout<<"---------------Cor LSDB-------------------"<<endl; |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 265 | for( std::list<CorLsa>::iterator it=corLsdb.begin(); |
| 266 | it!= corLsdb.end() ; it++) |
| 267 | { |
| 268 | cout<< (*it) <<endl; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | |
| 273 | // Adj LSA and LSDB related function starts here |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 274 | /* |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 275 | static bool |
| 276 | adjLsaCompare(AdjLsa& alsa1, AdjLsa& alsa2){ |
| 277 | return alsa1.getLsaKey()==alsa1.getLsaKey(); |
| 278 | } |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 279 | */ |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 280 | static bool |
| 281 | adjLsaCompareByKey(AdjLsa& alsa, string& key){ |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 282 | return alsa.getAdjLsaKey()==key; |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 286 | void |
| 287 | Lsdb::scheduledAdjLsaBuild(nlsr& pnlsr) |
| 288 | { |
| 289 | cout<<"scheduledAdjLsaBuild Called"<<endl; |
| 290 | pnlsr.setIsBuildAdjLsaSheduled(0); |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 291 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 292 | if( pnlsr.getAdl().isAdjLsaBuildable(pnlsr)) |
| 293 | { |
| 294 | int adjBuildCount=pnlsr.getAdjBuildCount(); |
| 295 | if(adjBuildCount>0 ) |
| 296 | { |
| 297 | if (pnlsr.getAdl().getNumOfActiveNeighbor()>0) |
| 298 | { |
| 299 | buildAndInstallOwnAdjLsa(pnlsr); |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | //remove if there is any adj lsa in LSDB |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 304 | string key=pnlsr.getConfParameter().getRouterPrefix()+"/2"; |
| 305 | removeAdjLsa(key); |
| 306 | // Remove alll fib entries as per NPT |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 307 | } |
| 308 | pnlsr.setAdjBuildCount(pnlsr.getAdjBuildCount()-adjBuildCount); |
| 309 | } |
| 310 | } |
| 311 | else |
| 312 | { |
| 313 | pnlsr.setIsBuildAdjLsaSheduled(1); |
| 314 | int schedulingTime=pnlsr.getConfParameter().getInterestRetryNumber()* |
| 315 | pnlsr.getConfParameter().getInterestRetryNumber(); |
| 316 | pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime), |
| 317 | ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(), |
| 318 | boost::ref(pnlsr))); |
| 319 | } |
| 320 | |
| 321 | } |
| 322 | |
| 323 | |
| 324 | bool |
| 325 | Lsdb::addAdjLsa(AdjLsa &alsa) |
| 326 | { |
| 327 | std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 328 | adjLsdb.end(), |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 329 | bind(adjLsaCompareByKey, _1, alsa.getAdjLsaKey())); |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 330 | |
| 331 | if( it == adjLsdb.end()){ |
| 332 | adjLsdb.push_back(alsa); |
| 333 | return true; |
| 334 | } |
| 335 | return false; |
| 336 | |
| 337 | } |
| 338 | |
| 339 | AdjLsa& |
| 340 | Lsdb::getAdjLsa(string key) |
| 341 | { |
| 342 | std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 343 | adjLsdb.end(), |
| 344 | bind(adjLsaCompareByKey, _1, key)); |
| 345 | |
| 346 | if( it != adjLsdb.end()){ |
| 347 | return (*it); |
| 348 | } |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | bool |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 352 | Lsdb::installAdjLsa(nlsr& pnlsr, AdjLsa &alsa) |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 353 | { |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 354 | bool doesLsaExist_ = doesAdjLsaExist(alsa.getAdjLsaKey()); |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 355 | if ( !doesLsaExist_ ) |
| 356 | { |
| 357 | // add Adj LSA |
| 358 | addAdjLsa(alsa); |
| 359 | // schedule routing table calculation |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 360 | if ( pnlsr.getIsRouteCalculationScheduled() != 1 ) |
| 361 | { |
| 362 | pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15), |
| 363 | ndn::bind(&RoutingTable::calculate, |
| 364 | &pnlsr.getRoutingTable(),boost::ref(pnlsr))); |
| 365 | pnlsr.setIsRouteCalculationScheduled(1); |
| 366 | } |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 367 | } |
| 368 | else |
| 369 | { |
| 370 | // check for newer name LSA |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 371 | AdjLsa oldAdjLsa=getAdjLsa(alsa.getAdjLsaKey()); |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 372 | |
| 373 | } |
| 374 | |
| 375 | printAdjLsdb(); |
| 376 | |
| 377 | return true; |
| 378 | } |
| 379 | |
| 380 | bool |
| 381 | Lsdb::buildAndInstallOwnAdjLsa(nlsr& pnlsr) |
| 382 | { |
| 383 | AdjLsa adjLsa(pnlsr.getConfParameter().getRouterPrefix() |
| 384 | , 2 |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 385 | , pnlsr.getSm().getAdjLsaSeq()+1 |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 386 | , pnlsr.getConfParameter().getRouterDeadInterval() |
| 387 | , pnlsr.getAdl().getNumOfActiveNeighbor() |
| 388 | , pnlsr.getAdl() ); |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 389 | pnlsr.getSm().setAdjLsaSeq(pnlsr.getSm().getAdjLsaSeq()+1); |
| 390 | return installAdjLsa(pnlsr, adjLsa); |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | bool |
| 394 | Lsdb::removeAdjLsa(string& key) |
| 395 | { |
akmhoque | fcf765d | 2014-02-01 23:46:17 -0600 | [diff] [blame] | 396 | std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 397 | adjLsdb.end(), |
| 398 | bind(adjLsaCompareByKey, _1, key)); |
| 399 | if ( it != adjLsdb.end() ) |
| 400 | { |
| 401 | adjLsdb.erase(it); |
| 402 | return true; |
| 403 | } |
| 404 | return false; |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 405 | |
| 406 | } |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 407 | |
| 408 | bool |
| 409 | Lsdb::doesAdjLsaExist(string key) |
| 410 | { |
| 411 | std::list< AdjLsa >::iterator it = std::find_if( adjLsdb.begin(), |
| 412 | adjLsdb.end(), |
| 413 | bind(adjLsaCompareByKey, _1, key)); |
| 414 | |
| 415 | if( it == adjLsdb.end()){ |
| 416 | return false; |
| 417 | } |
| 418 | |
| 419 | return true; |
| 420 | } |
| 421 | |
akmhoque | 79d355f | 2014-02-04 15:11:16 -0600 | [diff] [blame] | 422 | std::list<AdjLsa>& |
| 423 | Lsdb::getAdjLsdb() |
| 424 | { |
| 425 | return adjLsdb; |
| 426 | } |
| 427 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 428 | void |
| 429 | Lsdb::printAdjLsdb() |
| 430 | { |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 431 | cout<<"---------------Adj LSDB-------------------"<<endl; |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 432 | for( std::list<AdjLsa>::iterator it=adjLsdb.begin(); |
| 433 | it!= adjLsdb.end() ; it++) |
| 434 | { |
| 435 | cout<< (*it) <<endl; |
| 436 | } |
| 437 | } |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 438 | |