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