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