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