akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | #include "lsdb.hpp" |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 23 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 24 | #include "logger.hpp" |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 25 | #include "lsa-segment-storage.hpp" |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 26 | #include "nlsr.hpp" |
| 27 | #include "publisher/segment-publisher.hpp" |
| 28 | #include "utility/name-helper.hpp" |
| 29 | |
| 30 | #include <ndn-cxx/security/signing-helpers.hpp> |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 31 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | namespace nlsr { |
| 33 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 34 | INIT_LOGGER(Lsdb); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 35 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 36 | class LsaContentPublisher : public SegmentPublisher<ndn::Face> |
| 37 | { |
| 38 | public: |
| 39 | LsaContentPublisher(ndn::Face& face, |
| 40 | ndn::KeyChain& keyChain, |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 41 | const ndn::security::SigningInfo& signingInfo, |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 42 | const ndn::time::milliseconds& freshnessPeriod, |
| 43 | const std::string& content) |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 44 | : SegmentPublisher(face, keyChain, signingInfo, freshnessPeriod) |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 45 | , m_content(content) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | virtual size_t |
| 50 | generate(ndn::EncodingBuffer& outBuffer) { |
| 51 | size_t totalLength = 0; |
| 52 | totalLength += outBuffer.prependByteArray(reinterpret_cast<const uint8_t*>(m_content.c_str()), |
| 53 | m_content.size()); |
| 54 | return totalLength; |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | const std::string m_content; |
| 59 | }; |
| 60 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 61 | const ndn::Name::Component Lsdb::NAME_COMPONENT = ndn::Name::Component("lsdb"); |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 62 | const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10); |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 63 | const ndn::time::steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = |
| 64 | ndn::time::steady_clock::TimePoint::min(); |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 65 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 66 | Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler) |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 67 | : m_nlsr(nlsr) |
| 68 | , m_scheduler(scheduler) |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 69 | , m_sync(m_nlsr.getNlsrFace(), |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 70 | [this] (const ndn::Name& routerName, const Lsa::Type& lsaType, |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 71 | const uint64_t& sequenceNumber) { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 72 | return isLsaNew(routerName, lsaType, sequenceNumber); |
| 73 | }, m_nlsr.getConfParameter()) |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 74 | , m_lsaStorage(scheduler) |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 75 | , m_lsaRefreshTime(0) |
| 76 | , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT) |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 77 | , m_sequencingManager() |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 78 | , m_onNewLsaConnection(m_sync.onNewLsa->connect( |
| 79 | [this] (const ndn::Name& updateName, const uint64_t& sequenceNumber) { |
| 80 | ndn::Name lsaInterest{updateName}; |
| 81 | lsaInterest.appendNumber(sequenceNumber); |
| 82 | expressInterest(lsaInterest, 0); |
| 83 | })) |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 84 | { |
| 85 | } |
| 86 | |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 87 | Lsdb::~Lsdb() |
| 88 | { |
| 89 | for (const auto& sp : m_fetchers) { |
| 90 | sp->stop(); |
| 91 | } |
| 92 | } |
| 93 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 94 | void |
| 95 | Lsdb::onFetchLsaError(uint32_t errorCode, |
| 96 | const std::string& msg, |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 97 | const ndn::Name& interestName, |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 98 | uint32_t retransmitNo, |
| 99 | const ndn::time::steady_clock::TimePoint& deadline, |
| 100 | ndn::Name lsaName, |
| 101 | uint64_t seqNo) |
| 102 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 103 | NLSR_LOG_DEBUG("Failed to fetch LSA: " << lsaName << ", Error code: " << errorCode |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 104 | << ", Message: " << msg); |
| 105 | |
| 106 | if (ndn::time::steady_clock::now() < deadline) { |
| 107 | SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName); |
| 108 | |
| 109 | if (it != m_highestSeqNo.end() && it->second == seqNo) { |
| 110 | // If the SegmentFetcher failed due to an Interest timeout, it is safe to re-express |
| 111 | // immediately since at the least the LSA Interest lifetime has elapsed. |
| 112 | // Otherwise, it is necessary to delay the Interest re-expression to prevent |
| 113 | // the potential for constant Interest flooding. |
| 114 | ndn::time::seconds delay = m_nlsr.getConfParameter().getLsaInterestLifetime(); |
| 115 | |
| 116 | if (errorCode == ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT) { |
| 117 | delay = ndn::time::seconds(0); |
| 118 | } |
| 119 | |
| 120 | m_scheduler.scheduleEvent(delay, std::bind(&Lsdb::expressInterest, this, |
| 121 | interestName, retransmitNo + 1, deadline)); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 127 | Lsdb::afterFetchLsa(const ndn::ConstBufferPtr& bufferPtr, const ndn::Name& interestName) |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 128 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 129 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(ndn::Name(interestName)); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 130 | data->setContent(bufferPtr); |
| 131 | |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 132 | NLSR_LOG_DEBUG("Received data for LSA(name): " << data->getName()); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 133 | |
| 134 | ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1); |
| 135 | uint64_t seqNo = interestName[-1].toNumber(); |
| 136 | |
| 137 | if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) { |
| 138 | m_highestSeqNo[lsaName] = seqNo; |
| 139 | } |
| 140 | else if (seqNo > m_highestSeqNo[lsaName]) { |
| 141 | m_highestSeqNo[lsaName] = seqNo; |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 142 | NLSR_LOG_TRACE("SeqNo for LSA(name): " << data->getName() << " updated"); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 143 | } |
| 144 | else if (seqNo < m_highestSeqNo[lsaName]) { |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | onContentValidated(data); |
| 149 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 150 | |
| 151 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 152 | Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 153 | { |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 154 | m_scheduler.cancelEvent(eid); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 155 | } |
| 156 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 157 | /*! \brief Compares if a name LSA is the same as the one specified by key |
| 158 | |
| 159 | \param nlsa1 A name LSA object |
| 160 | \param key A key of an originating router to compare to nlsa1 |
| 161 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 162 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 163 | nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 164 | { |
| 165 | return nlsa1.getKey() == key; |
| 166 | } |
| 167 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 168 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 169 | Lsdb::buildAndInstallOwnNameLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 170 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 171 | NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(), |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 172 | m_sequencingManager.getNameLsaSeq() + 1, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 173 | getLsaExpirationTimePoint(), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 174 | m_nlsr.getNamePrefixList()); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 175 | m_sequencingManager.increaseNameLsaSeq(); |
| 176 | |
| 177 | m_sequencingManager.writeSeqNoToFile(); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 178 | m_sync.publishRoutingUpdate(Lsa::Type::NAME, m_sequencingManager.getNameLsaSeq()); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 179 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 180 | return installNameLsa(nameLsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 181 | } |
| 182 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 183 | NameLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 184 | Lsdb::findNameLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 185 | { |
| 186 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 187 | m_nameLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 188 | std::bind(nameLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 189 | if (it != m_nameLsdb.end()) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 190 | return &(*it); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 191 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 192 | return 0; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 196 | Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 197 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 198 | NameLsa* nameLsaCheck = findNameLsa(key); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 199 | // Is the name in the LSDB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 200 | if (nameLsaCheck != 0) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 201 | // And the supplied seq no is the highest so far |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 202 | if (nameLsaCheck->getLsSeqNo() < seqNo) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 203 | return true; |
| 204 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 205 | else { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 206 | return false; |
| 207 | } |
| 208 | } |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | ndn::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 213 | Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, |
| 214 | const ndn::time::seconds& expTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 215 | { |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 216 | return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD, |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 217 | std::bind(&Lsdb::expireOrRefreshNameLsa, this, key, seqNo)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 221 | Lsdb::installNameLsa(NameLsa& nlsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 222 | { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 223 | NLSR_LOG_TRACE("installNameLsa"); |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 224 | ndn::time::seconds timeToExpire = m_lsaRefreshTime; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 225 | NameLsa* chkNameLsa = findNameLsa(nlsa.getKey()); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 226 | // Determines if the name LSA is new or not. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 227 | if (chkNameLsa == 0) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 228 | addNameLsa(nlsa); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 229 | NLSR_LOG_DEBUG("New Name LSA"); |
| 230 | NLSR_LOG_DEBUG("Adding Name Lsa"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 231 | nlsa.writeLog(); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 232 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 233 | NLSR_LOG_TRACE("nlsa.getOrigRouter(): " << nlsa.getOrigRouter()); |
| 234 | NLSR_LOG_TRACE("m_nlsr.getConfParameter().getRouterPrefix(): " << m_nlsr.getConfParameter().getRouterPrefix()); |
| 235 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 236 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 237 | // If this name LSA is from another router, add the advertised |
| 238 | // prefixes to the NPT. |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 239 | m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(), |
| 240 | nlsa.getOrigRouter()); |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 241 | for (const auto& name : nlsa.getNpl().getNames()) { |
| 242 | if (name != m_nlsr.getConfParameter().getRouterPrefix()) { |
| 243 | m_nlsr.getNamePrefixTable().addEntry(name, nlsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 247 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 248 | ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() - |
| 249 | ndn::time::system_clock::now(); |
| 250 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 251 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 252 | nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(), |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 253 | nlsa.getLsSeqNo(), |
| 254 | timeToExpire)); |
| 255 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 256 | // Else this is a known name LSA, so we are updating it. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 257 | else { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 258 | NLSR_LOG_TRACE("Known name lsa"); |
| 259 | NLSR_LOG_TRACE("chkNameLsa->getLsSeqNo(): " << chkNameLsa->getLsSeqNo()); |
| 260 | NLSR_LOG_TRACE("nlsa.getLsSeqNo(): " << nlsa.getLsSeqNo()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 261 | if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 262 | NLSR_LOG_DEBUG("Updated Name LSA. Updating LSDB"); |
| 263 | NLSR_LOG_DEBUG("Deleting Name Lsa"); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 264 | chkNameLsa->writeLog(); |
| 265 | chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 266 | chkNameLsa->setExpirationTimePoint(nlsa.getExpirationTimePoint()); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 267 | chkNameLsa->getNpl().sort(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 268 | nlsa.getNpl().sort(); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 269 | // Obtain the set difference of the current and the incoming |
| 270 | // name prefix sets, and add those. |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 271 | std::list<ndn::Name> newNames = nlsa.getNpl().getNames(); |
| 272 | std::list<ndn::Name> oldNames = chkNameLsa->getNpl().getNames(); |
| 273 | std::list<ndn::Name> namesToAdd; |
| 274 | std::set_difference(newNames.begin(), newNames.end(), oldNames.begin(), oldNames.end(), |
| 275 | std::inserter(namesToAdd, namesToAdd.begin())); |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 276 | for (const auto& name : namesToAdd) { |
| 277 | chkNameLsa->addName(name); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 278 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 279 | if (name != m_nlsr.getConfParameter().getRouterPrefix()) { |
| 280 | m_nlsr.getNamePrefixTable().addEntry(name, nlsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | } |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 284 | |
| 285 | chkNameLsa->getNpl().sort(); |
| 286 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 287 | // Also remove any names that are no longer being advertised. |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 288 | std::list<ndn::Name> namesToRemove; |
| 289 | std::set_difference(oldNames.begin(), oldNames.end(), newNames.begin(), newNames.end(), |
| 290 | std::inserter(namesToRemove, namesToRemove.begin())); |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 291 | for (const auto& name : namesToRemove) { |
| 292 | NLSR_LOG_DEBUG("Removing name LSA no longer advertised: " << name); |
| 293 | chkNameLsa->removeName(name); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 294 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 295 | if (name != m_nlsr.getConfParameter().getRouterPrefix()) { |
| 296 | m_nlsr.getNamePrefixTable().removeEntry(name, nlsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | } |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 300 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 301 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 302 | ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() - |
| 303 | ndn::time::system_clock::now(); |
| 304 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 305 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 306 | cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId()); |
| 307 | chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 308 | nlsa.getLsSeqNo(), |
| 309 | timeToExpire)); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 310 | NLSR_LOG_DEBUG("Adding Name Lsa"); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 311 | chkNameLsa->writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | bool |
| 318 | Lsdb::addNameLsa(NameLsa& nlsa) |
| 319 | { |
| 320 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 321 | m_nameLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 322 | std::bind(nameLsaCompareByKey, _1, |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 323 | nlsa.getKey())); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 324 | if (it == m_nameLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 325 | m_nameLsdb.push_back(nlsa); |
| 326 | return true; |
| 327 | } |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 332 | Lsdb::removeNameLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 333 | { |
| 334 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 335 | m_nameLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 336 | std::bind(nameLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 337 | if (it != m_nameLsdb.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 338 | NLSR_LOG_DEBUG("Deleting Name Lsa"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 339 | (*it).writeLog(); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 340 | // If the requested name LSA is not ours, we also need to remove |
| 341 | // its entries from the NPT. |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 342 | if ((*it).getOrigRouter() != |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 343 | m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 344 | m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(), |
| 345 | (*it).getOrigRouter()); |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 346 | for (const auto& name : it->getNpl().getNames()) { |
| 347 | if (name != m_nlsr.getConfParameter().getRouterPrefix()) { |
| 348 | m_nlsr.getNamePrefixTable().removeEntry(name, it->getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | } |
| 352 | m_nameLsdb.erase(it); |
| 353 | return true; |
| 354 | } |
| 355 | return false; |
| 356 | } |
| 357 | |
| 358 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 359 | Lsdb::doesNameLsaExist(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 360 | { |
| 361 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 362 | m_nameLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 363 | std::bind(nameLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 364 | if (it == m_nameLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 365 | return false; |
| 366 | } |
| 367 | return true; |
| 368 | } |
| 369 | |
| 370 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 371 | Lsdb::writeNameLsdbLog() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 372 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 373 | NLSR_LOG_DEBUG("---------------Name LSDB-------------------"); |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 374 | for (const auto& nlsa : m_nameLsdb) { |
| 375 | nlsa.writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 379 | const std::list<NameLsa>& |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 380 | Lsdb::getNameLsdb() const |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 381 | { |
| 382 | return m_nameLsdb; |
| 383 | } |
| 384 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 385 | // Cor LSA and LSDB related Functions start here |
| 386 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 387 | /*! \brief Compares whether an LSA object is the same as a key. |
| 388 | \param clsa The cor. LSA to check the identity of. |
| 389 | \param key The key of the publishing router to check against. |
| 390 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 391 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 392 | corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 393 | { |
| 394 | return clsa.getKey() == key; |
| 395 | } |
| 396 | |
| 397 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 398 | Lsdb::buildAndInstallOwnCoordinateLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 399 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 400 | CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(), |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 401 | m_sequencingManager.getCorLsaSeq() + 1, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 402 | getLsaExpirationTimePoint(), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 403 | m_nlsr.getConfParameter().getCorR(), |
| 404 | m_nlsr.getConfParameter().getCorTheta()); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 405 | |
| 406 | // Sync coordinate LSAs if using HR or HR dry run. |
| 407 | if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 408 | m_sequencingManager.increaseCorLsaSeq(); |
| 409 | m_sequencingManager.writeSeqNoToFile(); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 410 | m_sync.publishRoutingUpdate(Lsa::Type::COORDINATE, m_sequencingManager.getCorLsaSeq()); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 411 | } |
| 412 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 413 | installCoordinateLsa(corLsa); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 414 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 415 | return true; |
| 416 | } |
| 417 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 418 | CoordinateLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 419 | Lsdb::findCoordinateLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 420 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 421 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 422 | m_corLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 423 | std::bind(corLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 424 | if (it != m_corLsdb.end()) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 425 | return &(*it); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 426 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 427 | return 0; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 431 | Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 432 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 433 | CoordinateLsa* clsa = findCoordinateLsa(key); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 434 | // Is the coordinate LSA in the LSDB already |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 435 | if (clsa != 0) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 436 | // And the seq no is newer (higher) than the current one |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 437 | if (clsa->getLsSeqNo() < seqNo) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 438 | return true; |
| 439 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 440 | else { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 441 | return false; |
| 442 | } |
| 443 | } |
| 444 | return true; |
| 445 | } |
| 446 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 447 | // Schedules a refresh/expire event in the scheduler. |
| 448 | // \param key The name of the router that published the LSA. |
| 449 | // \param seqNo the seq. no. associated with the LSA to check. |
| 450 | // \param expTime How long to wait before triggering the event. |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 451 | ndn::EventId |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 452 | Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 453 | const ndn::time::seconds& expTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 454 | { |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 455 | return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD, |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 456 | std::bind(&Lsdb::expireOrRefreshCoordinateLsa, |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 457 | this, key, seqNo)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 461 | Lsdb::installCoordinateLsa(CoordinateLsa& clsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 462 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 463 | ndn::time::seconds timeToExpire = m_lsaRefreshTime; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 464 | CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey()); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 465 | // Checking whether the LSA is new or not. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 466 | if (chkCorLsa == 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 467 | NLSR_LOG_DEBUG("New Coordinate LSA. Adding to LSDB"); |
| 468 | NLSR_LOG_DEBUG("Adding Coordinate Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 469 | clsa.writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 470 | addCoordinateLsa(clsa); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 471 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 472 | // Register the LSA's origin router prefix |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 473 | if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 474 | m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(), |
| 475 | clsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 476 | } |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 477 | if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 478 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 479 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 480 | // Set the expiration time for the new LSA. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 481 | if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 482 | ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() - |
| 483 | ndn::time::system_clock::now(); |
| 484 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 485 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 486 | scheduleCoordinateLsaExpiration(clsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 487 | clsa.getLsSeqNo(), timeToExpire); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 488 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 489 | // We are just updating this LSA. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 490 | else { |
| 491 | if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 492 | NLSR_LOG_DEBUG("Updated Coordinate LSA. Updating LSDB"); |
| 493 | NLSR_LOG_DEBUG("Deleting Coordinate Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 494 | chkCorLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 495 | chkCorLsa->setLsSeqNo(clsa.getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 496 | chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint()); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 497 | // If the new LSA contains new routing information, update the LSDB with it. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 498 | if (!chkCorLsa->isEqualContent(clsa)) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 499 | chkCorLsa->setCorRadius(clsa.getCorRadius()); |
| 500 | chkCorLsa->setCorTheta(clsa.getCorTheta()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 501 | if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 502 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 503 | } |
| 504 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 505 | // If this is an LSA from another router, refresh its expiration time. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 506 | if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 507 | ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() - |
| 508 | ndn::time::system_clock::now(); |
| 509 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 510 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 511 | cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId()); |
| 512 | chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 513 | clsa.getLsSeqNo(), |
| 514 | timeToExpire)); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 515 | NLSR_LOG_DEBUG("Adding Coordinate Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 516 | chkCorLsa->writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | return true; |
| 520 | } |
| 521 | |
| 522 | bool |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 523 | Lsdb::addCoordinateLsa(CoordinateLsa& clsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 524 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 525 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 526 | m_corLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 527 | std::bind(corLsaCompareByKey, _1, |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 528 | clsa.getKey())); |
| 529 | if (it == m_corLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 530 | m_corLsdb.push_back(clsa); |
| 531 | return true; |
| 532 | } |
| 533 | return false; |
| 534 | } |
| 535 | |
| 536 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 537 | Lsdb::removeCoordinateLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 538 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 539 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 540 | m_corLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 541 | std::bind(corLsaCompareByKey, |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 542 | _1, key)); |
| 543 | if (it != m_corLsdb.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 544 | NLSR_LOG_DEBUG("Deleting Coordinate Lsa"); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 545 | it->writeLog(); |
| 546 | |
| 547 | if (it->getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
| 548 | m_nlsr.getNamePrefixTable().removeEntry(it->getOrigRouter(), it->getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 549 | } |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 550 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 551 | m_corLsdb.erase(it); |
| 552 | return true; |
| 553 | } |
| 554 | return false; |
| 555 | } |
| 556 | |
| 557 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 558 | Lsdb::doesCoordinateLsaExist(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 559 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 560 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 561 | m_corLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 562 | std::bind(corLsaCompareByKey, |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 563 | _1, key)); |
| 564 | if (it == m_corLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 565 | return false; |
| 566 | } |
| 567 | return true; |
| 568 | } |
| 569 | |
| 570 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 571 | Lsdb::writeCorLsdbLog() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 572 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 573 | NLSR_LOG_DEBUG("---------------Cor LSDB-------------------"); |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 574 | for (const auto& corLsa : m_corLsdb) { |
| 575 | corLsa.writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 579 | const std::list<CoordinateLsa>& |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 580 | Lsdb::getCoordinateLsdb() const |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 581 | { |
| 582 | return m_corLsdb; |
| 583 | } |
| 584 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 585 | // Adj LSA and LSDB related function starts here |
| 586 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 587 | /*! \brief Returns whether an adj. LSA object is from some router. |
| 588 | \param alsa The adj. LSA object. |
| 589 | \param key The router name that you want to compare the LSA with. |
| 590 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 591 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 592 | adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 593 | { |
| 594 | return alsa.getKey() == key; |
| 595 | } |
| 596 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 597 | void |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 598 | Lsdb::scheduleAdjLsaBuild() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 599 | { |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 600 | m_nlsr.incrementAdjBuildCount(); |
| 601 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 602 | if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
| 603 | // Don't build adjacency LSAs in hyperbolic routing |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 604 | NLSR_LOG_DEBUG("Adjacency LSA not built. Currently in hyperbolic routing state."); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 605 | return; |
| 606 | } |
| 607 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 608 | if (m_nlsr.getIsBuildAdjLsaSheduled() == false) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 609 | NLSR_LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 610 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 611 | m_scheduler.scheduleEvent(m_adjLsaBuildInterval, std::bind(&Lsdb::buildAdjLsa, this)); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 612 | m_nlsr.setIsBuildAdjLsaSheduled(true); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | void |
| 617 | Lsdb::buildAdjLsa() |
| 618 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 619 | NLSR_LOG_TRACE("Lsdb::buildAdjLsa called"); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 620 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 621 | m_nlsr.setIsBuildAdjLsaSheduled(false); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 622 | |
| 623 | if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr.getConfParameter().getInterestRetryNumber())) { |
| 624 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 625 | int adjBuildCount = m_nlsr.getAdjBuildCount(); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 626 | // Only do the adjLsa build if there's one scheduled |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 627 | if (adjBuildCount > 0) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 628 | // It only makes sense to do the adjLsa build if we have neighbors |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 629 | if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 630 | NLSR_LOG_DEBUG("Building and installing own Adj LSA"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 631 | buildAndInstallOwnAdjLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 632 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 633 | // We have no active neighbors, meaning no one can route through |
| 634 | // us. So delete our entry in the LSDB. This prevents this |
| 635 | // router from refreshing the LSA, eventually causing other |
| 636 | // routers to delete it, too. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 637 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 638 | NLSR_LOG_DEBUG("Removing own Adj LSA; no ACTIVE neighbors"); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 639 | // Get this router's key |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 640 | ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix(); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 641 | key.append(std::to_string(Lsa::Type::ADJACENCY)); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 642 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 643 | removeAdjLsa(key); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 644 | // Recompute routing table after removal |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 645 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 646 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 647 | // In the case that during building the adj LSA, the FIB has to |
| 648 | // wait on an Interest response, the number of scheduled adj LSA |
| 649 | // builds could change, so we shouldn't just set it to 0. |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 650 | m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 651 | } |
| 652 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 653 | // We are still waiting to know the adjacency status of some |
| 654 | // neighbor, so schedule a build for later (when all that has |
| 655 | // hopefully finished) |
| 656 | else { |
| 657 | m_nlsr.setIsBuildAdjLsaSheduled(true); |
| 658 | int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() * |
| 659 | m_nlsr.getConfParameter().getInterestResendTime(); |
| 660 | m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 661 | std::bind(&Lsdb::buildAdjLsa, this)); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 662 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 663 | } |
| 664 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 665 | bool |
| 666 | Lsdb::addAdjLsa(AdjLsa& alsa) |
| 667 | { |
| 668 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 669 | m_adjLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 670 | std::bind(adjLsaCompareByKey, _1, |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 671 | alsa.getKey())); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 672 | if (it == m_adjLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 673 | m_adjLsdb.push_back(alsa); |
| 674 | return true; |
| 675 | } |
| 676 | return false; |
| 677 | } |
| 678 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 679 | AdjLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 680 | Lsdb::findAdjLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 681 | { |
| 682 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 683 | m_adjLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 684 | std::bind(adjLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 685 | if (it != m_adjLsdb.end()) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 686 | return &(*it); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 687 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 688 | return 0; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 689 | } |
| 690 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 691 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 692 | Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 693 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 694 | AdjLsa* adjLsaCheck = findAdjLsa(key); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 695 | // If it is in the LSDB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 696 | if (adjLsaCheck != 0) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 697 | // And the supplied seq no is newer (higher) than the current one. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 698 | if (adjLsaCheck->getLsSeqNo() < seqNo) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 699 | return true; |
| 700 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 701 | else { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 702 | return false; |
| 703 | } |
| 704 | } |
| 705 | return true; |
| 706 | } |
| 707 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 708 | ndn::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 709 | Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, |
| 710 | const ndn::time::seconds& expTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 711 | { |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 712 | return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD, |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 713 | std::bind(&Lsdb::expireOrRefreshAdjLsa, this, key, seqNo)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 717 | Lsdb::installAdjLsa(AdjLsa& alsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 718 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 719 | ndn::time::seconds timeToExpire = m_lsaRefreshTime; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 720 | AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey()); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 721 | // If this adj. LSA is not in the LSDB already |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 722 | if (chkAdjLsa == 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 723 | NLSR_LOG_DEBUG("New Adj LSA. Adding to LSDB"); |
| 724 | NLSR_LOG_DEBUG("Adding Adj Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 725 | alsa.writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 726 | addAdjLsa(alsa); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 727 | // Add any new name prefixes to the NPT |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 728 | alsa.addNptEntries(m_nlsr); |
| 729 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 730 | if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 731 | ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() - |
| 732 | ndn::time::system_clock::now(); |
| 733 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 734 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 735 | scheduleAdjLsaExpiration(alsa.getKey(), |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 736 | alsa.getLsSeqNo(), timeToExpire); |
| 737 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 738 | else { |
| 739 | if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 740 | NLSR_LOG_DEBUG("Updated Adj LSA. Updating LSDB"); |
| 741 | NLSR_LOG_DEBUG("Deleting Adj Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 742 | chkAdjLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 743 | chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 744 | chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint()); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 745 | // If the new adj LSA has new content, update the contents of |
| 746 | // the LSDB entry. Additionally, since we've changed the |
| 747 | // contents of the LSDB, we have to schedule a routing |
| 748 | // calculation. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 749 | if (!chkAdjLsa->isEqualContent(alsa)) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 750 | chkAdjLsa->getAdl().reset(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 751 | chkAdjLsa->getAdl().addAdjacents(alsa.getAdl()); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 752 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 753 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 754 | if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 755 | ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() - |
| 756 | ndn::time::system_clock::now(); |
| 757 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 758 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 759 | cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId()); |
| 760 | chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 761 | alsa.getLsSeqNo(), |
| 762 | timeToExpire)); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 763 | NLSR_LOG_DEBUG("Adding Adj Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 764 | chkAdjLsa->writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | return true; |
| 768 | } |
| 769 | |
| 770 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 771 | Lsdb::buildAndInstallOwnAdjLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 772 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 773 | AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(), |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 774 | m_sequencingManager.getAdjLsaSeq() + 1, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 775 | getLsaExpirationTimePoint(), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 776 | m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(), |
| 777 | m_nlsr.getAdjacencyList()); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 778 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 779 | //Sync adjacency LSAs if link-state or dry-run HR is enabled. |
| 780 | if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_ON) { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 781 | m_sequencingManager.increaseAdjLsaSeq(); |
| 782 | m_sequencingManager.writeSeqNoToFile(); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 783 | m_sync.publishRoutingUpdate(Lsa::Type::ADJACENCY, m_sequencingManager.getAdjLsaSeq()); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 784 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 785 | |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 786 | return installAdjLsa(adjLsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 790 | Lsdb::removeAdjLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 791 | { |
| 792 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 793 | m_adjLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 794 | std::bind(adjLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 795 | if (it != m_adjLsdb.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 796 | NLSR_LOG_DEBUG("Deleting Adj Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 797 | (*it).writeLog(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 798 | (*it).removeNptEntries(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 799 | m_adjLsdb.erase(it); |
| 800 | return true; |
| 801 | } |
| 802 | return false; |
| 803 | } |
| 804 | |
| 805 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 806 | Lsdb::doesAdjLsaExist(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 807 | { |
| 808 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 809 | m_adjLsdb.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 810 | std::bind(adjLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 811 | if (it == m_adjLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 812 | return false; |
| 813 | } |
| 814 | return true; |
| 815 | } |
| 816 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 817 | const std::list<AdjLsa>& |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 818 | Lsdb::getAdjLsdb() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 819 | { |
| 820 | return m_adjLsdb; |
| 821 | } |
| 822 | |
| 823 | void |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 824 | Lsdb::setLsaRefreshTime(const ndn::time::seconds& lsaRefreshTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 825 | { |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 826 | m_lsaRefreshTime = lsaRefreshTime; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | void |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 830 | Lsdb::setThisRouterPrefix(std::string trp) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 831 | { |
| 832 | m_thisRouterPrefix = trp; |
| 833 | } |
| 834 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 835 | // This function determines whether a name LSA should be refreshed |
| 836 | // or expired. The conditions for getting refreshed are: it is still |
| 837 | // in the LSDB, it hasn't been updated by something else already (as |
| 838 | // evidenced by its seq. no.), and this is the originating router for |
| 839 | // the LSA. Is it let expire in all other cases. |
| 840 | // lsaKey is the key of the LSA's publishing router. |
| 841 | // seqNo is the seq. no. of the candidate LSA. |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 842 | void |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 843 | Lsdb::expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 844 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 845 | NLSR_LOG_DEBUG("Lsdb::expireOrRefreshNameLsa Called"); |
| 846 | NLSR_LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 847 | NameLsa* chkNameLsa = findNameLsa(lsaKey); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 848 | // If this name LSA exists in the LSDB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 849 | if (chkNameLsa != 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 850 | NLSR_LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo()); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 851 | // If its seq no is the one we are expecting. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 852 | if (chkNameLsa->getLsSeqNo() == seqNo) { |
| 853 | if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 854 | NLSR_LOG_DEBUG("Own Name LSA, so refreshing it"); |
| 855 | NLSR_LOG_DEBUG("Deleting Name Lsa"); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 856 | chkNameLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 857 | chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 858 | m_sequencingManager.setNameLsaSeq(chkNameLsa->getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 859 | chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint()); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 860 | NLSR_LOG_DEBUG("Adding Name Lsa"); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 861 | chkNameLsa->writeLog(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 862 | // schedule refreshing event again |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 863 | chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 864 | chkNameLsa->getLsSeqNo(), |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 865 | m_lsaRefreshTime)); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 866 | m_sequencingManager.writeSeqNoToFile(); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 867 | m_sync.publishRoutingUpdate(Lsa::Type::NAME, m_sequencingManager.getNameLsaSeq()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 868 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 869 | // Since we cannot refresh other router's LSAs, our only choice is to expire. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 870 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 871 | NLSR_LOG_DEBUG("Other's Name LSA, so removing from LSDB"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 872 | removeNameLsa(lsaKey); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | } |
| 876 | } |
| 877 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 878 | // This function determines whether an adj. LSA should be refreshed |
| 879 | // or expired. The conditions for getting refreshed are: it is still |
| 880 | // in the LSDB, it hasn't been updated by something else already (as |
| 881 | // evidenced by its seq. no.), and this is the originating router for |
| 882 | // the LSA. Is it let expire in all other cases. |
| 883 | // lsaKey is the key of the LSA's publishing router. |
| 884 | // seqNo is the seq. no. of the candidate LSA. |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 885 | void |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 886 | Lsdb::expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 887 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 888 | NLSR_LOG_DEBUG("Lsdb::expireOrRefreshAdjLsa Called"); |
| 889 | NLSR_LOG_DEBUG("LSA Key: " << lsaKey << " Seq No: " << seqNo); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 890 | AdjLsa* chkAdjLsa = findAdjLsa(lsaKey); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 891 | // If this is a valid LSA |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 892 | if (chkAdjLsa != 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 893 | NLSR_LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo()); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 894 | // And if it hasn't been updated for some other reason |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 895 | if (chkAdjLsa->getLsSeqNo() == seqNo) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 896 | // If it is our own LSA |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 897 | if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 898 | NLSR_LOG_DEBUG("Own Adj LSA, so refreshing it"); |
| 899 | NLSR_LOG_DEBUG("Deleting Adj Lsa"); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 900 | chkAdjLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 901 | chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 902 | m_sequencingManager.setAdjLsaSeq(chkAdjLsa->getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 903 | chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint()); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 904 | NLSR_LOG_DEBUG("Adding Adj Lsa"); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 905 | chkAdjLsa->writeLog(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 906 | // schedule refreshing event again |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 907 | chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 908 | chkAdjLsa->getLsSeqNo(), |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 909 | m_lsaRefreshTime)); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 910 | m_sequencingManager.writeSeqNoToFile(); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 911 | m_sync.publishRoutingUpdate(Lsa::Type::ADJACENCY, m_sequencingManager.getAdjLsaSeq()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 912 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 913 | // An LSA from another router is expiring |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 914 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 915 | NLSR_LOG_DEBUG("Other's Adj LSA, so removing from LSDB"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 916 | removeAdjLsa(lsaKey); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 917 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 918 | // We have changed the contents of the LSDB, so we have to |
| 919 | // schedule a routing calculation |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 920 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | } |
| 924 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 925 | // This function determines whether an adj. LSA should be refreshed |
| 926 | // or expired. The conditions for getting refreshed are: it is still |
| 927 | // in the LSDB, it hasn't been updated by something else already (as |
| 928 | // evidenced by its seq. no.), and this is the originating router for |
| 929 | // the LSA. It is let expire in all other cases. |
| 930 | // lsaKey is the key of the LSA's publishing router. |
| 931 | // seqNo is the seq. no. of the candidate LSA. |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 932 | void |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 933 | Lsdb::expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey, |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 934 | uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 935 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 936 | NLSR_LOG_DEBUG("Lsdb::expireOrRefreshCorLsa Called "); |
| 937 | NLSR_LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 938 | CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 939 | // Whether the LSA is in the LSDB or not. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 940 | if (chkCorLsa != 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 941 | NLSR_LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo()); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 942 | // Whether the LSA has been updated without our knowledge. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 943 | if (chkCorLsa->getLsSeqNo() == seqNo) { |
| 944 | if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 945 | NLSR_LOG_DEBUG("Own Cor LSA, so refreshing it"); |
| 946 | NLSR_LOG_DEBUG("Deleting Coordinate Lsa"); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 947 | chkCorLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 948 | chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 949 | if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 950 | m_sequencingManager.setCorLsaSeq(chkCorLsa->getLsSeqNo()); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 951 | } |
| 952 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 953 | chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint()); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 954 | NLSR_LOG_DEBUG("Adding Coordinate Lsa"); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 955 | chkCorLsa->writeLog(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 956 | // schedule refreshing event again |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 957 | chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration( |
| 958 | chkCorLsa->getKey(), |
| 959 | chkCorLsa->getLsSeqNo(), |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 960 | m_lsaRefreshTime)); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 961 | // Only sync coordinate LSAs if link-state routing is disabled |
| 962 | if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 963 | m_sequencingManager.writeSeqNoToFile(); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 964 | m_sync.publishRoutingUpdate(Lsa::Type::COORDINATE, m_sequencingManager.getCorLsaSeq()); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 965 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 966 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 967 | // We can't refresh other router's LSAs, so we remove it. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 968 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 969 | NLSR_LOG_DEBUG("Other's Cor LSA, so removing from LSDB"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 970 | removeCoordinateLsa(lsaKey); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 971 | } |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 972 | if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 973 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 979 | void |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 980 | Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 981 | ndn::time::steady_clock::TimePoint deadline) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 982 | { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 983 | // increment SENT_LSA_INTEREST |
| 984 | lsaIncrementSignal(Statistics::PacketType::SENT_LSA_INTEREST); |
| 985 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 986 | if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) { |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 987 | deadline = ndn::time::steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX)); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 988 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 989 | // The first component of the interest is the name. |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 990 | ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 991 | // The seq no is the last |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 992 | uint64_t seqNo = interestName[-1].toNumber(); |
| 993 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 994 | // If the LSA is not found in the list currently. |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 995 | if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) { |
| 996 | m_highestSeqNo[lsaName] = seqNo; |
| 997 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 998 | // If the new seq no is higher, that means the LSA is valid |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 999 | else if (seqNo > m_highestSeqNo[lsaName]) { |
| 1000 | m_highestSeqNo[lsaName] = seqNo; |
| 1001 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 1002 | // Otherwise, its an old/invalid LSA |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1003 | else if (seqNo < m_highestSeqNo[lsaName]) { |
| 1004 | return; |
| 1005 | } |
| 1006 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 1007 | ndn::Interest interest(interestName); |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 1008 | ndn::util::SegmentFetcher::Options options; |
| 1009 | options.interestLifetime = m_nlsr.getConfParameter().getLsaInterestLifetime(); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1010 | |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1011 | NLSR_LOG_DEBUG("Fetching Data for LSA: " << interestName << " Seq number: " << seqNo); |
Ashlesh Gawande | 05cb728 | 2018-08-30 14:39:41 -0500 | [diff] [blame] | 1012 | auto fetcher = ndn::util::SegmentFetcher::start(m_nlsr.getNlsrFace(), |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 1013 | interest, m_nlsr.getValidator(), options); |
Ashlesh Gawande | 05cb728 | 2018-08-30 14:39:41 -0500 | [diff] [blame] | 1014 | |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 1015 | auto it = m_fetchers.insert(fetcher).first; |
| 1016 | |
| 1017 | fetcher->onComplete.connect([this, interestName, it] (ndn::ConstBufferPtr bufferPtr) { |
| 1018 | afterFetchLsa(bufferPtr, interestName); |
| 1019 | m_fetchers.erase(it); |
| 1020 | }); |
| 1021 | |
| 1022 | fetcher->onError.connect([this, interestName, timeoutCount, deadline, lsaName, seqNo, &fetcher, it] |
| 1023 | (uint32_t errorCode, const std::string& msg) { |
| 1024 | onFetchLsaError(errorCode, msg, interestName, |
| 1025 | timeoutCount, deadline, lsaName, seqNo); |
| 1026 | m_fetchers.erase(it); |
| 1027 | }); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1028 | |
| 1029 | m_lsaStorage.connectToFetcher(*fetcher); |
| 1030 | m_nlsr.connectToFetcher(*fetcher); |
| 1031 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1032 | // increment a specific SENT_LSA_INTEREST |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1033 | Lsa::Type lsaType; |
| 1034 | std::istringstream(interestName[-2].toUri()) >> lsaType; |
| 1035 | switch (lsaType) { |
| 1036 | case Lsa::Type::ADJACENCY: |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1037 | lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_INTEREST); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1038 | break; |
| 1039 | case Lsa::Type::COORDINATE: |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1040 | lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_INTEREST); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1041 | break; |
| 1042 | case Lsa::Type::NAME: |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1043 | lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_INTEREST); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1044 | break; |
| 1045 | default: |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1046 | NLSR_LOG_ERROR("lsaType " << lsaType << " not recognized; failed Statistics::PacketType conversion"); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1047 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | void |
| 1051 | Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest) |
| 1052 | { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1053 | // increment RCV_LSA_INTEREST |
| 1054 | lsaIncrementSignal(Statistics::PacketType::RCV_LSA_INTEREST); |
| 1055 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1056 | const ndn::Name& interestName(interest.getName()); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1057 | NLSR_LOG_DEBUG("Interest received for LSA: " << interestName); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1058 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 1059 | std::string chkString("LSA"); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1060 | int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString); |
| 1061 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1062 | // Forms the name of the router that the Interest packet came from. |
| 1063 | ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork(); |
| 1064 | originRouter.append(interestName.getSubName(lsaPosition + 1, |
| 1065 | interest.getName().size() - lsaPosition - 3)); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1066 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1067 | // if the interest is for this router's LSA |
| 1068 | if (originRouter == m_nlsr.getConfParameter().getRouterPrefix()) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1069 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1070 | if (lsaPosition >= 0) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1071 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1072 | uint64_t seqNo = interestName[-1].toNumber(); |
| 1073 | NLSR_LOG_DEBUG("LSA sequence number from interest: " << seqNo); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1074 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1075 | Lsa::Type interestedLsType; |
| 1076 | std::istringstream(interestName[-2].toUri()) >> interestedLsType; |
| 1077 | |
| 1078 | if (interestedLsType == Lsa::Type::NAME) { |
| 1079 | processInterestForNameLsa(interest, originRouter.append(std::to_string(interestedLsType)), |
| 1080 | seqNo); |
| 1081 | } |
| 1082 | else if (interestedLsType == Lsa::Type::ADJACENCY) { |
| 1083 | processInterestForAdjacencyLsa(interest, originRouter.append(std::to_string(interestedLsType)), |
| 1084 | seqNo); |
| 1085 | } |
| 1086 | else if (interestedLsType == Lsa::Type::COORDINATE) { |
| 1087 | processInterestForCoordinateLsa(interest, originRouter.append(std::to_string(interestedLsType)), |
| 1088 | seqNo); |
| 1089 | } |
| 1090 | else { |
| 1091 | NLSR_LOG_WARN("Received unrecognized LSA type: " << interestedLsType); |
| 1092 | } |
| 1093 | lsaIncrementSignal(Statistics::PacketType::SENT_LSA_DATA); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1094 | } |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1095 | } |
| 1096 | else { // else the interest is for other router's lsa, serve from LsaSegmentStorage |
| 1097 | const ndn::Data* lsaSegment = m_lsaStorage.getLsaSegment(interest); |
| 1098 | if (lsaSegment != nullptr) { |
| 1099 | NLSR_LOG_TRACE("Found data in lsa storage. Sending the data for " << interest.getName()); |
| 1100 | m_nlsr.getNlsrFace().put(*lsaSegment); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1101 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1102 | else { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1103 | NLSR_LOG_TRACE(interest << " was not found in this lsa storage."); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 1108 | // \brief Sends LSA data. |
| 1109 | // \param interest The Interest that warranted the data. |
| 1110 | // \param content The data that the Interest was seeking. |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1111 | void |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 1112 | Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content) |
| 1113 | { |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 1114 | LsaContentPublisher publisher(m_nlsr.getNlsrFace(), |
| 1115 | m_nlsr.getKeyChain(), |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 1116 | m_nlsr.getSigningInfo(), |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 1117 | m_lsaRefreshTime, |
| 1118 | content); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1119 | NLSR_LOG_DEBUG("Sending requested data ( " << content << ") for interest (" << interest |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1120 | << ") to be published and added to face."); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 1121 | publisher.publish(interest.getName()); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 1122 | } |
| 1123 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 1124 | // \brief Finds and sends a requested name LSA. |
| 1125 | // \param interest The interest that seeks the name LSA. |
| 1126 | // \param lsaKey The LSA that the Interest is seeking. |
| 1127 | // \param seqNo A sequence number to ensure that we are sending the |
| 1128 | // version that was requested. |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 1129 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1130 | Lsdb::processInterestForNameLsa(const ndn::Interest& interest, |
| 1131 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1132 | uint64_t seqNo) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1133 | { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1134 | // increment RCV_NAME_LSA_INTEREST |
| 1135 | lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_INTEREST); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1136 | NLSR_LOG_DEBUG("nameLsa interest " << interest << " received"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1137 | NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey); |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1138 | if (nameLsa != nullptr) { |
| 1139 | NLSR_LOG_TRACE("Verifying SeqNo for NameLsa is same as requested."); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1140 | if (nameLsa->getLsSeqNo() == seqNo) { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1141 | // if requested lsa belongs to this router then sign it and serve it |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 1142 | std::string content = nameLsa->serialize(); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 1143 | putLsaData(interest,content); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1144 | // else the requested belongs to neighboring routers, so serve the |
| 1145 | // original data packet corresponding to the lsa |
| 1146 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1147 | // increment SENT_NAME_LSA_DATA |
| 1148 | lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_DATA); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1149 | } |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1150 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1151 | NLSR_LOG_TRACE("SeqNo for nameLsa does not match"); |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1155 | NLSR_LOG_TRACE(interest << " was not found in this lsdb"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1156 | } |
| 1157 | } |
| 1158 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 1159 | // \brief Finds and sends a requested adj. LSA. |
| 1160 | // \param interest The interest that seeks the adj. LSA. |
| 1161 | // \param lsaKey The LSA that the Interest is seeking. |
| 1162 | // \param seqNo A sequence number to ensure that we are sending the |
| 1163 | // version that was requested. |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1164 | void |
| 1165 | Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest, |
| 1166 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1167 | uint64_t seqNo) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1168 | { |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 1169 | if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1170 | NLSR_LOG_ERROR("Received interest for an adjacency LSA when hyperbolic routing is enabled"); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 1171 | } |
| 1172 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1173 | // increment RCV_ADJ_LSA_INTEREST |
| 1174 | lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_INTEREST); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1175 | NLSR_LOG_DEBUG("AdjLsa interest " << interest << " received"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1176 | AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey); |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1177 | if (adjLsa != nullptr) { |
| 1178 | NLSR_LOG_TRACE("Verifying SeqNo for AdjLsa is same as requested."); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1179 | if (adjLsa->getLsSeqNo() == seqNo) { |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 1180 | std::string content = adjLsa->serialize(); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 1181 | putLsaData(interest,content); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1182 | // increment SENT_ADJ_LSA_DATA |
| 1183 | lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_DATA); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1184 | } |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1185 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1186 | NLSR_LOG_TRACE("SeqNo for AdjLsa does not match"); |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1190 | NLSR_LOG_TRACE(interest << " was not found in this lsdb"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 1194 | // \brief Finds and sends a requested cor. LSA. |
| 1195 | // \param interest The interest that seeks the cor. LSA. |
| 1196 | // \param lsaKey The LSA that the Interest is seeking. |
| 1197 | // \param seqNo A sequence number to ensure that we are sending the |
| 1198 | // version that was requested. |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1199 | void |
| 1200 | Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest, |
| 1201 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1202 | uint64_t seqNo) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1203 | { |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 1204 | if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1205 | NLSR_LOG_ERROR("Received Interest for a coordinate LSA when link-state routing is enabled"); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 1206 | } |
| 1207 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1208 | // increment RCV_COORD_LSA_INTEREST |
| 1209 | lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_INTEREST); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1210 | NLSR_LOG_DEBUG("CoordinateLsa interest " << interest << " received"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1211 | CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey); |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1212 | if (corLsa != nullptr) { |
| 1213 | NLSR_LOG_TRACE("Verifying SeqNo for CoordinateLsa is same as requested."); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1214 | if (corLsa->getLsSeqNo() == seqNo) { |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 1215 | std::string content = corLsa->serialize(); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 1216 | putLsaData(interest,content); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1217 | // increment SENT_COORD_LSA_DATA |
| 1218 | lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_DATA); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1219 | } |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1220 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1221 | NLSR_LOG_TRACE("SeqNo for CoordinateLsa does not match"); |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1225 | NLSR_LOG_TRACE(interest << " was not found in this lsdb"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | void |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 1230 | Lsdb::onContentValidated(const std::shared_ptr<const ndn::Data>& data) |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 1231 | { |
| 1232 | const ndn::Name& dataName = data->getName(); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1233 | NLSR_LOG_DEBUG("Data validation successful for LSA: " << dataName); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1234 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 1235 | std::string chkString("LSA"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1236 | int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1237 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1238 | if (lsaPosition >= 0) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1239 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 1240 | // Extracts the prefix of the originating router from the data. |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1241 | ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork(); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 1242 | originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 3)); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1243 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 1244 | uint64_t seqNo = dataName[-1].toNumber(); |
Ashlesh Gawande | 820bb66 | 2017-08-03 16:12:07 -0500 | [diff] [blame] | 1245 | std::string dataContent(reinterpret_cast<const char*>(data->getContent().value()), |
| 1246 | data->getContent().value_size()); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1247 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1248 | Lsa::Type interestedLsType; |
| 1249 | std::istringstream(dataName[-2].toUri()) >> interestedLsType; |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1250 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1251 | if (interestedLsType == Lsa::Type::NAME) { |
| 1252 | processContentNameLsa(originRouter.append(std::to_string(interestedLsType)), seqNo, |
| 1253 | dataContent); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1254 | } |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1255 | else if (interestedLsType == Lsa::Type::ADJACENCY) { |
| 1256 | processContentAdjacencyLsa(originRouter.append(std::to_string(interestedLsType)), seqNo, |
| 1257 | dataContent); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1258 | } |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1259 | else if (interestedLsType == Lsa::Type::COORDINATE) { |
| 1260 | processContentCoordinateLsa(originRouter.append(std::to_string(interestedLsType)), seqNo, |
| 1261 | dataContent); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1262 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1263 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1264 | NLSR_LOG_WARN("Received unrecognized LSA Type: " << interestedLsType); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1265 | } |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1266 | |
| 1267 | // increment RCV_LSA_DATA |
| 1268 | lsaIncrementSignal(Statistics::PacketType::RCV_LSA_DATA); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | void |
| 1273 | Lsdb::processContentNameLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1274 | uint64_t lsSeqNo, std::string& dataContent) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1275 | { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1276 | // increment RCV_NAME_LSA_DATA |
| 1277 | lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_DATA); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1278 | if (isNameLsaNew(lsaKey, lsSeqNo)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1279 | NameLsa nameLsa; |
Nick Gordon | 0fa4c77 | 2017-10-23 13:33:03 -0500 | [diff] [blame] | 1280 | if (nameLsa.deserialize(dataContent)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1281 | installNameLsa(nameLsa); |
| 1282 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1283 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1284 | NLSR_LOG_DEBUG("LSA data decoding error :("); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | void |
| 1290 | Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1291 | uint64_t lsSeqNo, std::string& dataContent) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1292 | { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1293 | // increment RCV_ADJ_LSA_DATA |
| 1294 | lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_DATA); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1295 | if (isAdjLsaNew(lsaKey, lsSeqNo)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1296 | AdjLsa adjLsa; |
Nick Gordon | 0fa4c77 | 2017-10-23 13:33:03 -0500 | [diff] [blame] | 1297 | if (adjLsa.deserialize(dataContent)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1298 | installAdjLsa(adjLsa); |
| 1299 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1300 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1301 | NLSR_LOG_DEBUG("LSA data decoding error :("); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | void |
| 1307 | Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1308 | uint64_t lsSeqNo, std::string& dataContent) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1309 | { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1310 | // increment RCV_COORD_LSA_DATA |
| 1311 | lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_DATA); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1312 | if (isCoordinateLsaNew(lsaKey, lsSeqNo)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1313 | CoordinateLsa corLsa; |
Nick Gordon | 0fa4c77 | 2017-10-23 13:33:03 -0500 | [diff] [blame] | 1314 | if (corLsa.deserialize(dataContent)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1315 | installCoordinateLsa(corLsa); |
| 1316 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1317 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1318 | NLSR_LOG_DEBUG("LSA data decoding error :("); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | } |
| 1322 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 1323 | ndn::time::system_clock::TimePoint |
| 1324 | Lsdb::getLsaExpirationTimePoint() |
| 1325 | { |
| 1326 | ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now(); |
| 1327 | expirationTimePoint = expirationTimePoint + |
| 1328 | ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval()); |
| 1329 | return expirationTimePoint; |
| 1330 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1331 | |
| 1332 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 1333 | Lsdb::writeAdjLsdbLog() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1334 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 1335 | NLSR_LOG_DEBUG("---------------Adj LSDB-------------------"); |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 1336 | for (const auto& adj : m_adjLsdb) { |
| 1337 | adj.writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | //-----utility function ----- |
| 1342 | bool |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1343 | Lsdb::doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1344 | { |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1345 | switch (lsType) { |
| 1346 | case Lsa::Type::ADJACENCY: |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1347 | return doesAdjLsaExist(key); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1348 | case Lsa::Type::COORDINATE: |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 1349 | return doesCoordinateLsaExist(key); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1350 | case Lsa::Type::NAME: |
| 1351 | return doesNameLsaExist(key); |
| 1352 | default: |
| 1353 | return false; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1354 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1355 | } |
| 1356 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 1357 | bool |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1358 | Lsdb::isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 1359 | const uint64_t& sequenceNumber) { |
| 1360 | ndn::Name lsaKey = routerName; |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1361 | lsaKey.append(std::to_string(lsaType)); |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 1362 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1363 | switch (lsaType) { |
| 1364 | case Lsa::Type::ADJACENCY: |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 1365 | return isAdjLsaNew(lsaKey, sequenceNumber); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1366 | case Lsa::Type::COORDINATE: |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 1367 | return isCoordinateLsaNew(lsaKey, sequenceNumber); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 1368 | case Lsa::Type::NAME: |
| 1369 | return isNameLsaNew(lsaKey, sequenceNumber); |
| 1370 | default: |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 1371 | return false; |
| 1372 | } |
| 1373 | } |
| 1374 | |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 1375 | } // namespace nlsr |