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