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" |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 5 | #include "utility/name-helper.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 6 | |
| 7 | namespace nlsr { |
| 8 | |
| 9 | using namespace std; |
| 10 | |
| 11 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 12 | Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 13 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 14 | m_nlsr.getScheduler().cancelEvent(eid); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 18 | nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 19 | { |
| 20 | return nlsa1.getKey() == key; |
| 21 | } |
| 22 | |
| 23 | |
| 24 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 25 | Lsdb::buildAndInstallOwnNameLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 26 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 27 | NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(), |
| 28 | "name", |
| 29 | m_nlsr.getSequencingManager().getNameLsaSeq() + 1, |
| 30 | m_nlsr.getConfParameter().getRouterDeadInterval(), |
| 31 | m_nlsr.getNamePrefixList()); |
| 32 | m_nlsr.getSequencingManager().increaseNameLsaSeq(); |
| 33 | return installNameLsa(nameLsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | } |
| 35 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 36 | NameLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 37 | Lsdb::findNameLsa(const ndn::Name& 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 |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 50 | Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 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 |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 68 | Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, int expTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 69 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 70 | return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime), |
| 71 | ndn::bind(&Lsdb::exprireOrRefreshNameLsa, |
| 72 | this, key, seqNo)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 76 | Lsdb::installNameLsa(NameLsa& nlsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 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(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 85 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 86 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 87 | m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(), |
| 88 | nlsa.getOrigRouter()); |
| 89 | std::list<ndn::Name> nameList = nlsa.getNpl().getNameList(); |
| 90 | for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 91 | it++) |
| 92 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 93 | if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 94 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 95 | m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 99 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 100 | { |
| 101 | timeToExpire = nlsa.getLifeTime(); |
| 102 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 103 | nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(), |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 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(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 116 | std::list<ndn::Name> nameToAdd; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 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())); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 122 | for (std::list<ndn::Name>::iterator it = nameToAdd.begin(); |
| 123 | it != nameToAdd.end(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 124 | ++it) |
| 125 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 126 | chkNameLsa->addName((*it)); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 127 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 128 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 129 | if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 130 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 131 | m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 135 | std::list<ndn::Name> nameToRemove; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 136 | std::set_difference(chkNameLsa->getNpl().getNameList().begin(), |
| 137 | chkNameLsa->getNpl().getNameList().end(), |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 138 | nlsa.getNpl().getNameList().begin(), |
| 139 | nlsa.getNpl().getNameList().end(), |
| 140 | std::inserter(nameToRemove, nameToRemove.begin())); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 141 | for (std::list<ndn::Name>::iterator it = nameToRemove.begin(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 142 | it != nameToRemove.end(); ++it) |
| 143 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 144 | chkNameLsa->removeName((*it)); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 145 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 146 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 147 | if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 148 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 149 | m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 153 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 154 | { |
| 155 | timeToExpire = nlsa.getLifeTime(); |
| 156 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 157 | cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId()); |
| 158 | chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 159 | nlsa.getLsSeqNo(), |
| 160 | timeToExpire)); |
| 161 | chkNameLsa->writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | bool |
| 168 | Lsdb::addNameLsa(NameLsa& nlsa) |
| 169 | { |
| 170 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 171 | m_nameLsdb.end(), |
| 172 | bind(nameLsaCompareByKey, _1, |
| 173 | nlsa.getKey())); |
| 174 | if (it == m_nameLsdb.end()) |
| 175 | { |
| 176 | m_nameLsdb.push_back(nlsa); |
| 177 | return true; |
| 178 | } |
| 179 | return false; |
| 180 | } |
| 181 | |
| 182 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 183 | Lsdb::removeNameLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 184 | { |
| 185 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 186 | m_nameLsdb.end(), |
| 187 | bind(nameLsaCompareByKey, _1, key)); |
| 188 | if (it != m_nameLsdb.end()) |
| 189 | { |
| 190 | (*it).writeLog(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 191 | if ((*it).getOrigRouter() != |
| 192 | m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 193 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 194 | m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(), |
| 195 | (*it).getOrigRouter()); |
| 196 | for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 197 | nit != (*it).getNpl().getNameList().end(); ++nit) |
| 198 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 199 | if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 200 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 201 | m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter()); |
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 |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 212 | Lsdb::doesNameLsaExist(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 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 | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 239 | corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 240 | { |
| 241 | return clsa.getKey() == key; |
| 242 | } |
| 243 | |
| 244 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 245 | Lsdb::buildAndInstallOwnCoordinateLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 246 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 247 | CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(), |
| 248 | "coordinate", |
| 249 | m_nlsr.getSequencingManager().getCorLsaSeq() + 1, |
| 250 | m_nlsr.getConfParameter().getRouterDeadInterval(), |
| 251 | m_nlsr.getConfParameter().getCorR(), |
| 252 | m_nlsr.getConfParameter().getCorTheta()); |
| 253 | m_nlsr.getSequencingManager().increaseCorLsaSeq(); |
| 254 | installCoordinateLsa(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* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 259 | Lsdb::findCoordinateLsa(const ndn::Name& 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 | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 272 | Lsdb::isCoordinateLsaNew(const ndn::Name& 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 | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 290 | Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo, |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 291 | int expTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 292 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 293 | return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime), |
| 294 | ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa, |
| 295 | this, key, seqNo)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 299 | Lsdb::installCoordinateLsa(CoordinateLsa& clsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 300 | { |
| 301 | int timeToExpire = m_lsaRefreshTime; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 302 | CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey()); |
| 303 | if (chkCorLsa == 0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 304 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 305 | addCoordinateLsa(clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 306 | printCorLsdb(); //debugging purpose |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 307 | if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 308 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 309 | m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(), |
| 310 | clsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 311 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 312 | if (m_nlsr.getConfParameter().getIsHyperbolicCalc() >= 1) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 313 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 314 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 315 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 316 | if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 317 | { |
| 318 | timeToExpire = clsa.getLifeTime(); |
| 319 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 320 | scheduleCoordinateLsaExpiration(clsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 321 | clsa.getLsSeqNo(), timeToExpire); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 322 | } |
| 323 | else |
| 324 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 325 | if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 326 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 327 | chkCorLsa->setLsSeqNo(clsa.getLsSeqNo()); |
| 328 | chkCorLsa->setLifeTime(clsa.getLifeTime()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 329 | if (!chkCorLsa->isEqualContent(clsa)) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 330 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 331 | chkCorLsa->setCorRadius(clsa.getCorRadius()); |
| 332 | chkCorLsa->setCorTheta(clsa.getCorTheta()); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 333 | if (m_nlsr.getConfParameter().getIsHyperbolicCalc() >= 1) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 334 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 335 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 336 | } |
| 337 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 338 | if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 339 | { |
| 340 | timeToExpire = clsa.getLifeTime(); |
| 341 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 342 | cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId()); |
| 343 | chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 344 | clsa.getLsSeqNo(), |
| 345 | timeToExpire)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | bool |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 352 | Lsdb::addCoordinateLsa(CoordinateLsa& clsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 353 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 354 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 355 | m_corLsdb.end(), |
| 356 | bind(corLsaCompareByKey, _1, |
| 357 | clsa.getKey())); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 358 | if (it == m_corLsdb.end()) |
| 359 | { |
| 360 | m_corLsdb.push_back(clsa); |
| 361 | return true; |
| 362 | } |
| 363 | return false; |
| 364 | } |
| 365 | |
| 366 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 367 | Lsdb::removeCoordinateLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 368 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 369 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 370 | m_corLsdb.end(), |
| 371 | bind(corLsaCompareByKey, _1, key)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 372 | if (it != m_corLsdb.end()) |
| 373 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 374 | if ((*it).getOrigRouter() != |
| 375 | m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 376 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 377 | m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(), |
| 378 | (*it).getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 379 | } |
| 380 | m_corLsdb.erase(it); |
| 381 | return true; |
| 382 | } |
| 383 | return false; |
| 384 | } |
| 385 | |
| 386 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 387 | Lsdb::doesCoordinateLsaExist(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 388 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 389 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 390 | m_corLsdb.end(), |
| 391 | bind(corLsaCompareByKey, _1, key)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 392 | if (it == m_corLsdb.end()) |
| 393 | { |
| 394 | return false; |
| 395 | } |
| 396 | return true; |
| 397 | } |
| 398 | |
| 399 | void |
| 400 | Lsdb::printCorLsdb() //debugging |
| 401 | { |
| 402 | cout << "---------------Cor LSDB-------------------" << endl; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 403 | for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 404 | it != m_corLsdb.end() ; it++) |
| 405 | { |
| 406 | cout << (*it) << endl; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | |
| 411 | // Adj LSA and LSDB related function starts here |
| 412 | |
| 413 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 414 | adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 415 | { |
| 416 | return alsa.getKey() == key; |
| 417 | } |
| 418 | |
| 419 | |
| 420 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 421 | Lsdb::scheduledAdjLsaBuild() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 422 | { |
| 423 | cout << "scheduledAdjLsaBuild Called" << endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 424 | m_nlsr.setIsBuildAdjLsaSheduled(0); |
| 425 | if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 426 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 427 | int adjBuildCount = m_nlsr.getAdjBuildCount(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 428 | if (adjBuildCount > 0) |
| 429 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 430 | if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 431 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 432 | buildAndInstallOwnAdjLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 433 | } |
| 434 | else |
| 435 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 436 | ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix(); |
| 437 | key.append("adjacency"); |
| 438 | removeAdjLsa(key); |
| 439 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 440 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 441 | m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | else |
| 445 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 446 | m_nlsr.setIsBuildAdjLsaSheduled(1); |
| 447 | int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() * |
| 448 | m_nlsr.getConfParameter().getInterestResendTime(); |
| 449 | m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime), |
| 450 | ndn::bind(&Lsdb::scheduledAdjLsaBuild, |
| 451 | this)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
| 455 | |
| 456 | bool |
| 457 | Lsdb::addAdjLsa(AdjLsa& alsa) |
| 458 | { |
| 459 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 460 | m_adjLsdb.end(), |
| 461 | bind(adjLsaCompareByKey, _1, |
| 462 | alsa.getKey())); |
| 463 | if (it == m_adjLsdb.end()) |
| 464 | { |
| 465 | m_adjLsdb.push_back(alsa); |
| 466 | return true; |
| 467 | } |
| 468 | return false; |
| 469 | } |
| 470 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 471 | AdjLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 472 | Lsdb::findAdjLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 473 | { |
| 474 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 475 | m_adjLsdb.end(), |
| 476 | bind(adjLsaCompareByKey, _1, key)); |
| 477 | if (it != m_adjLsdb.end()) |
| 478 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 479 | return &(*it); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 480 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 481 | return 0; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | |
| 485 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 486 | Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 487 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 488 | AdjLsa* adjLsaCheck = findAdjLsa(key); |
| 489 | if (adjLsaCheck != 0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 490 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 491 | if (adjLsaCheck->getLsSeqNo() < seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 492 | { |
| 493 | return true; |
| 494 | } |
| 495 | else |
| 496 | { |
| 497 | return false; |
| 498 | } |
| 499 | } |
| 500 | return true; |
| 501 | } |
| 502 | |
| 503 | |
| 504 | ndn::EventId |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 505 | Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, int expTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 506 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 507 | return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime), |
| 508 | ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, |
| 509 | this, key, seqNo)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 513 | Lsdb::installAdjLsa(AdjLsa& alsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 514 | { |
| 515 | int timeToExpire = m_lsaRefreshTime; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 516 | AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey()); |
| 517 | if (chkAdjLsa == 0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 518 | { |
| 519 | addAdjLsa(alsa); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 520 | alsa.addNptEntries(m_nlsr); |
| 521 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
| 522 | if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 523 | { |
| 524 | timeToExpire = alsa.getLifeTime(); |
| 525 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 526 | scheduleAdjLsaExpiration(alsa.getKey(), |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 527 | alsa.getLsSeqNo(), timeToExpire); |
| 528 | } |
| 529 | else |
| 530 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 531 | if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 532 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 533 | chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo()); |
| 534 | chkAdjLsa->setLifeTime(alsa.getLifeTime()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 535 | if (!chkAdjLsa->isEqualContent(alsa)) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 536 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 537 | chkAdjLsa->getAdl().reset(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 538 | chkAdjLsa->getAdl().addAdjacents(alsa.getAdl()); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 539 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 540 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 541 | if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 542 | { |
| 543 | timeToExpire = alsa.getLifeTime(); |
| 544 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 545 | cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId()); |
| 546 | chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 547 | alsa.getLsSeqNo(), |
| 548 | timeToExpire)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | return true; |
| 552 | } |
| 553 | |
| 554 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 555 | Lsdb::buildAndInstallOwnAdjLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 556 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 557 | AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(), |
| 558 | "adjacency", |
| 559 | m_nlsr.getSequencingManager().getAdjLsaSeq() + 1, |
| 560 | m_nlsr.getConfParameter().getRouterDeadInterval(), |
| 561 | m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(), |
| 562 | m_nlsr.getAdjacencyList()); |
| 563 | m_nlsr.getSequencingManager().increaseAdjLsaSeq(); |
| 564 | // publish routing update |
| 565 | ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix(); |
| 566 | lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix()); |
| 567 | m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(), |
| 568 | lsaPrefix); |
| 569 | return installAdjLsa(adjLsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 573 | Lsdb::removeAdjLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 574 | { |
| 575 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 576 | m_adjLsdb.end(), |
| 577 | bind(adjLsaCompareByKey, _1, key)); |
| 578 | if (it != m_adjLsdb.end()) |
| 579 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 580 | (*it).removeNptEntries(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 581 | m_adjLsdb.erase(it); |
| 582 | return true; |
| 583 | } |
| 584 | return false; |
| 585 | } |
| 586 | |
| 587 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 588 | Lsdb::doesAdjLsaExist(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 589 | { |
| 590 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 591 | m_adjLsdb.end(), |
| 592 | bind(adjLsaCompareByKey, _1, key)); |
| 593 | if (it == m_adjLsdb.end()) |
| 594 | { |
| 595 | return false; |
| 596 | } |
| 597 | return true; |
| 598 | } |
| 599 | |
| 600 | std::list<AdjLsa>& |
| 601 | Lsdb::getAdjLsdb() |
| 602 | { |
| 603 | return m_adjLsdb; |
| 604 | } |
| 605 | |
| 606 | void |
| 607 | Lsdb::setLsaRefreshTime(int lrt) |
| 608 | { |
| 609 | m_lsaRefreshTime = lrt; |
| 610 | } |
| 611 | |
| 612 | void |
| 613 | Lsdb::setThisRouterPrefix(string trp) |
| 614 | { |
| 615 | m_thisRouterPrefix = trp; |
| 616 | } |
| 617 | |
| 618 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 619 | Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 620 | { |
| 621 | cout << "Lsdb::exprireOrRefreshNameLsa Called " << endl; |
| 622 | cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 623 | NameLsa* chkNameLsa = findNameLsa(lsaKey); |
| 624 | if (chkNameLsa != 0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 625 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 626 | cout << " LSA Exists with seq no: " << chkNameLsa->getLsSeqNo() << endl; |
| 627 | if (chkNameLsa->getLsSeqNo() == seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 628 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 629 | if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 630 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 631 | chkNameLsa->writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 632 | cout << "Own Name LSA, so refreshing name LSA" << endl; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 633 | chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 634 | m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo()); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 635 | chkNameLsa->writeLog(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 636 | // schedule refreshing event again |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 637 | chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 638 | chkNameLsa->getLsSeqNo(), |
| 639 | m_lsaRefreshTime)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 640 | // publish routing update |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 641 | ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix(); |
| 642 | lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix()); |
| 643 | m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(), |
| 644 | lsaPrefix); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 645 | } |
| 646 | else |
| 647 | { |
| 648 | cout << "Other's Name LSA, so removing form LSDB" << endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 649 | removeNameLsa(lsaKey); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 656 | Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 657 | { |
| 658 | cout << "Lsdb::exprireOrRefreshAdjLsa Called " << endl; |
| 659 | cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 660 | AdjLsa* chkAdjLsa = findAdjLsa(lsaKey); |
| 661 | if (chkAdjLsa != 0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 662 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 663 | cout << " LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo() << endl; |
| 664 | if (chkAdjLsa->getLsSeqNo() == seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 665 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 666 | if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 667 | { |
| 668 | cout << "Own Adj LSA, so refreshing Adj LSA" << endl; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 669 | chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 670 | m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 671 | // schedule refreshing event again |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 672 | chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 673 | chkAdjLsa->getLsSeqNo(), |
| 674 | m_lsaRefreshTime)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 675 | // publish routing update |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 676 | ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix(); |
| 677 | lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix()); |
| 678 | m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(), |
| 679 | lsaPrefix); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 680 | } |
| 681 | else |
| 682 | { |
| 683 | cout << "Other's Adj LSA, so removing form LSDB" << endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 684 | removeAdjLsa(lsaKey); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 685 | } |
| 686 | // schedule Routing table calculaiton |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 687 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 693 | Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey, |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 694 | uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 695 | { |
| 696 | cout << "Lsdb::exprireOrRefreshCorLsa Called " << endl; |
| 697 | cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 698 | CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey); |
| 699 | if (chkCorLsa != 0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 700 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 701 | cout << " LSA Exists with seq no: " << chkCorLsa->getLsSeqNo() << endl; |
| 702 | if (chkCorLsa->getLsSeqNo() == seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 703 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 704 | if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 705 | { |
| 706 | cout << "Own Cor LSA, so refreshing Cor LSA" << endl; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 707 | chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 708 | m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 709 | // schedule refreshing event again |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 710 | chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration( |
| 711 | chkCorLsa->getKey(), |
| 712 | chkCorLsa->getLsSeqNo(), |
| 713 | m_lsaRefreshTime)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 714 | // publish routing update |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 715 | ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix(); |
| 716 | lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix()); |
| 717 | m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(), |
| 718 | lsaPrefix); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 719 | } |
| 720 | else |
| 721 | { |
| 722 | cout << "Other's Cor LSA, so removing form LSDB" << endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 723 | removeCoordinateLsa(lsaKey); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 724 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 725 | if (m_nlsr.getConfParameter().getIsHyperbolicCalc() >= 1) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 726 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 727 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | |
| 734 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 735 | Lsdb::expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime) |
| 736 | { |
| 737 | std::cout << "Expressing Interest :" << interestName << std::endl; |
| 738 | ndn::Interest interest(interestName); |
| 739 | interest.setInterestLifetime(ndn::time::seconds(interestLifeTime)); |
| 740 | interest.setMustBeFresh(true); |
| 741 | m_nlsr.getNlsrFace().expressInterest(interest, |
| 742 | ndn::bind(&Lsdb::processContent, |
| 743 | this, _1, _2), |
| 744 | ndn::bind(&Lsdb::processInterestTimedOut, |
| 745 | this, _1)); |
| 746 | } |
| 747 | |
| 748 | void |
| 749 | Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest) |
| 750 | { |
| 751 | const ndn::Name& intName(interest.getName()); |
| 752 | std::cout << "Interest recevied for LSA: " << intName << std::endl; |
| 753 | string chkString("LSA"); |
| 754 | int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), |
| 755 | chkString); |
| 756 | if (lsaPosition >= 0) |
| 757 | { |
| 758 | std::string interestedLsType; |
| 759 | uint64_t interestedLsSeqNo; |
| 760 | ndn::Name origRouter = intName.getSubName(lsaPosition + 1, |
| 761 | interest.getName().size() - lsaPosition - 3); |
| 762 | interestedLsType = intName[-2].toEscapedString(); |
| 763 | interestedLsSeqNo = intName[-1].toNumber(); |
| 764 | std::cout << "Router Name: " << origRouter << std::endl; |
| 765 | std::cout << "Ls Type : " << interestedLsType << std::endl; |
| 766 | std::cout << "Ls Seq : " << interestedLsSeqNo << endl; |
| 767 | std::cout << "Ls Type: " << interestedLsType << std::endl; |
| 768 | if (interestedLsType == "name") |
| 769 | { |
| 770 | processInterestForNameLsa(interest, |
| 771 | origRouter.append(interestedLsType), |
| 772 | interestedLsSeqNo); |
| 773 | return; |
| 774 | } |
| 775 | else if (interestedLsType == "adjacency") |
| 776 | { |
| 777 | processInterestForAdjacencyLsa(interest, |
| 778 | origRouter.append(interestedLsType), |
| 779 | interestedLsSeqNo); |
| 780 | return; |
| 781 | } |
| 782 | else if (interestedLsType == "coordinate") |
| 783 | { |
| 784 | processInterestForCoordinateLsa(interest, |
| 785 | origRouter.append(interestedLsType), |
| 786 | interestedLsSeqNo); |
| 787 | return; |
| 788 | } |
| 789 | else |
| 790 | { |
| 791 | cout << "Unrecognized LSA Type :(" << endl; |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | void |
| 797 | Lsdb::processInterestForNameLsa(const ndn::Interest& interest, |
| 798 | const ndn::Name& lsaKey, |
| 799 | uint32_t interestedlsSeqNo) |
| 800 | { |
| 801 | NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey); |
| 802 | if (nameLsa != 0) |
| 803 | { |
| 804 | if (nameLsa->getLsSeqNo() >= interestedlsSeqNo) |
| 805 | { |
| 806 | ndn::Data data(ndn::Name(interest.getName()).appendVersion()); |
| 807 | data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec |
| 808 | std::string content = nameLsa->getData(); |
| 809 | data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()), |
| 810 | content.size()); |
| 811 | m_keyChain.sign(data); |
| 812 | std::cout << ">> D: " << data << std::endl; |
| 813 | m_nlsr.getNlsrFace().put(data); |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | void |
| 819 | Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest, |
| 820 | const ndn::Name& lsaKey, |
| 821 | uint32_t interestedlsSeqNo) |
| 822 | { |
| 823 | AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey); |
| 824 | if (adjLsa != 0) |
| 825 | { |
| 826 | if (adjLsa->getLsSeqNo() >= interestedlsSeqNo) |
| 827 | { |
| 828 | ndn::Data data(ndn::Name(interest.getName()).appendVersion()); |
| 829 | data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec |
| 830 | std::string content = adjLsa->getData(); |
| 831 | data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()), |
| 832 | content.size()); |
| 833 | m_keyChain.sign(data); |
| 834 | std::cout << ">> D: " << data << std::endl; |
| 835 | m_nlsr.getNlsrFace().put(data); |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | void |
| 841 | Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest, |
| 842 | const ndn::Name& lsaKey, |
| 843 | uint32_t interestedlsSeqNo) |
| 844 | { |
| 845 | CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey); |
| 846 | if (corLsa != 0) |
| 847 | { |
| 848 | if (corLsa->getLsSeqNo() >= interestedlsSeqNo) |
| 849 | { |
| 850 | ndn::Data data(ndn::Name(interest.getName()).appendVersion()); |
| 851 | data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec |
| 852 | std::string content = corLsa->getData(); |
| 853 | data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()), |
| 854 | content.size()); |
| 855 | m_keyChain.sign(data); |
| 856 | std::cout << ">> D: " << data << std::endl; |
| 857 | m_nlsr.getNlsrFace().put(data); |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | void |
| 863 | Lsdb::processContent(const ndn::Interest& interest, const ndn::Data& data) |
| 864 | { |
| 865 | const ndn::Name& dataName = data.getName(); |
| 866 | std::cout << "Data received for name: " << dataName << std::endl; |
| 867 | string dataContent(reinterpret_cast<const char*>(data.getContent().value())); |
| 868 | string chkString("LSA"); |
| 869 | int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString); |
| 870 | if (lsaPosition >= 0) |
| 871 | { |
| 872 | std::string interestedLsType; |
| 873 | uint64_t interestedLsSeqNo; |
| 874 | ndn::Name origRouter = dataName.getSubName(lsaPosition + 1, |
| 875 | dataName.size() - lsaPosition - 4); |
| 876 | interestedLsType = dataName[-3].toEscapedString(); |
| 877 | interestedLsSeqNo = dataName[-2].toNumber(); |
| 878 | std::cout << "Ls Type : " << interestedLsType << std::endl; |
| 879 | std::cout << "Ls Seq : " << interestedLsSeqNo << std::endl; |
| 880 | std::cout << "Ls Type: " << interestedLsType << std::endl; |
| 881 | if (interestedLsType == "name") |
| 882 | { |
| 883 | processContentNameLsa(origRouter.append(interestedLsType), |
| 884 | interestedLsSeqNo, dataContent); |
| 885 | return; |
| 886 | } |
| 887 | else if (interestedLsType == "adjacency") |
| 888 | { |
| 889 | processContentAdjacencyLsa(origRouter.append(interestedLsType), |
| 890 | interestedLsSeqNo, dataContent); |
| 891 | return; |
| 892 | } |
| 893 | else if (interestedLsType == "coordinate") |
| 894 | { |
| 895 | processContentCoordinateLsa(origRouter.append(interestedLsType), |
| 896 | interestedLsSeqNo, dataContent); |
| 897 | return; |
| 898 | } |
| 899 | else |
| 900 | { |
| 901 | cout << "Unrecognized LSA Type :(" << endl; |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | void |
| 907 | Lsdb::processContentNameLsa(const ndn::Name& lsaKey, |
| 908 | uint32_t lsSeqNo, std::string& dataContent) |
| 909 | { |
| 910 | if (isNameLsaNew(lsaKey, lsSeqNo)) |
| 911 | { |
| 912 | NameLsa nameLsa; |
| 913 | if (nameLsa.initializeFromContent(dataContent)) |
| 914 | { |
| 915 | installNameLsa(nameLsa); |
| 916 | } |
| 917 | else |
| 918 | { |
| 919 | std::cout << "LSA data decoding error :(" << std::endl; |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | void |
| 925 | Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey, |
| 926 | uint32_t lsSeqNo, std::string& dataContent) |
| 927 | { |
| 928 | if (isAdjLsaNew(lsaKey, lsSeqNo)) |
| 929 | { |
| 930 | AdjLsa adjLsa; |
| 931 | if (adjLsa.initializeFromContent(dataContent)) |
| 932 | { |
| 933 | installAdjLsa(adjLsa); |
| 934 | } |
| 935 | else |
| 936 | { |
| 937 | std::cout << "LSA data decoding error :(" << std::endl; |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | void |
| 943 | Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey, |
| 944 | uint32_t lsSeqNo, std::string& dataContent) |
| 945 | { |
| 946 | if (isCoordinateLsaNew(lsaKey, lsSeqNo)) |
| 947 | { |
| 948 | CoordinateLsa corLsa; |
| 949 | if (corLsa.initializeFromContent(dataContent)) |
| 950 | { |
| 951 | installCoordinateLsa(corLsa); |
| 952 | } |
| 953 | else |
| 954 | { |
| 955 | std::cout << "LSA data decoding error :(" << std::endl; |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | void |
| 961 | Lsdb::processInterestTimedOut(const ndn::Interest& interest) |
| 962 | { |
| 963 | const ndn::Name& interestName(interest.getName()); |
| 964 | cout << "Interest timed out for Name: " << interestName << endl; |
| 965 | } |
| 966 | |
| 967 | |
| 968 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 969 | Lsdb::printAdjLsdb() |
| 970 | { |
| 971 | cout << "---------------Adj LSDB-------------------" << endl; |
| 972 | for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin(); |
| 973 | it != m_adjLsdb.end() ; it++) |
| 974 | { |
| 975 | cout << (*it) << endl; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | //-----utility function ----- |
| 980 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 981 | Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 982 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 983 | if (lsType == "name") |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 984 | { |
| 985 | return doesNameLsaExist(key); |
| 986 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 987 | else if (lsType == "adjacency") |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 988 | { |
| 989 | return doesAdjLsaExist(key); |
| 990 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 991 | else if (lsType == "coordinate") |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 992 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 993 | return doesCoordinateLsaExist(key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 994 | } |
| 995 | return false; |
| 996 | } |
| 997 | |
| 998 | }//namespace nlsr |
| 999 | |