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