akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, 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/>. |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [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 R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 25 | #include "nlsr.hpp" |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 26 | #include "utility/name-helper.hpp" |
| 27 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 28 | namespace nlsr { |
| 29 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 30 | INIT_LOGGER(Lsdb); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 31 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 32 | const ndn::time::steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = |
| 33 | ndn::time::steady_clock::TimePoint::min(); |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 34 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 35 | Lsdb::Lsdb(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 36 | : m_face(face) |
| 37 | , m_scheduler(face.getIoService()) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 38 | , m_confParam(confParam) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 39 | , m_sync(m_face, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 40 | [this] (const ndn::Name& routerName, const Lsa::Type& lsaType, |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 41 | const uint64_t& sequenceNumber) { |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 42 | return isLsaNew(routerName, lsaType, sequenceNumber); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 43 | }, m_confParam) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 44 | , m_lsaRefreshTime(ndn::time::seconds(m_confParam.getLsaRefreshTime())) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 45 | , m_adjLsaBuildInterval(m_confParam.getAdjLsaBuildInterval()) |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 46 | , m_thisRouterPrefix(m_confParam.getRouterPrefix()) |
dulalsaurab | 82a34c2 | 2019-02-04 17:31:21 +0000 | [diff] [blame] | 47 | , m_sequencingManager(m_confParam.getStateFileDir(), m_confParam.getHyperbolicState()) |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 48 | , m_onNewLsaConnection(m_sync.onNewLsa->connect( |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 49 | [this] (const ndn::Name& updateName, uint64_t sequenceNumber, |
| 50 | const ndn::Name& originRouter) { |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 51 | ndn::Name lsaInterest{updateName}; |
| 52 | lsaInterest.appendNumber(sequenceNumber); |
| 53 | expressInterest(lsaInterest, 0); |
| 54 | })) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 55 | , m_segmentPublisher(m_face, keyChain) |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 56 | , m_isBuildAdjLsaScheduled(false) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 57 | , m_adjBuildCount(0) |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 58 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 59 | ndn::Name name = m_confParam.getLsaPrefix(); |
| 60 | NLSR_LOG_DEBUG("Setting interest filter for LsaPrefix: " << name); |
| 61 | |
| 62 | m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false), |
| 63 | [this] (const auto& name, const auto& interest) { processInterest(name, interest); }, |
| 64 | [] (const auto& name) { NLSR_LOG_DEBUG("Successfully registered prefix: " << name); }, |
| 65 | [] (const auto& name, const auto& reason) { |
| 66 | NLSR_LOG_ERROR("Failed to register prefix " << name); |
| 67 | NDN_THROW(std::runtime_error("Register prefix failed: " + reason)); |
| 68 | }, |
| 69 | m_confParam.getSigningInfo(), ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 70 | |
| 71 | buildAndInstallOwnNameLsa(); |
| 72 | // Install coordinate LSAs if using HR or dry-run HR. |
| 73 | if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
| 74 | buildAndInstallOwnCoordinateLsa(); |
| 75 | } |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 79 | Lsdb::buildAndInstallOwnNameLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 80 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 81 | NameLsa nameLsa(m_thisRouterPrefix, m_sequencingManager.getNameLsaSeq() + 1, |
| 82 | getLsaExpirationTimePoint(), m_confParam.getNamePrefixList()); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 83 | m_sequencingManager.increaseNameLsaSeq(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 84 | m_sequencingManager.writeSeqNoToFile(); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 85 | m_sync.publishRoutingUpdate(Lsa::Type::NAME, m_sequencingManager.getNameLsaSeq()); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 86 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 87 | installLsa(std::make_shared<NameLsa>(nameLsa)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 91 | Lsdb::buildAndInstallOwnCoordinateLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 92 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 93 | CoordinateLsa corLsa(m_thisRouterPrefix, m_sequencingManager.getCorLsaSeq() + 1, |
| 94 | getLsaExpirationTimePoint(), m_confParam.getCorR(), |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 95 | m_confParam.getCorTheta()); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 96 | m_sequencingManager.increaseCorLsaSeq(); |
| 97 | m_sequencingManager.writeSeqNoToFile(); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 98 | |
| 99 | // Sync coordinate LSAs if using HR or HR dry run. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 100 | if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 101 | m_sync.publishRoutingUpdate(Lsa::Type::COORDINATE, m_sequencingManager.getCorLsaSeq()); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 104 | installLsa(std::make_shared<CoordinateLsa>(corLsa)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 105 | } |
| 106 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 107 | void |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 108 | Lsdb::scheduleAdjLsaBuild() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 109 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 110 | m_adjBuildCount++; |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 111 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 112 | if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 113 | // Don't build adjacency LSAs in hyperbolic routing |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 114 | NLSR_LOG_DEBUG("Adjacency LSA not built. Currently in hyperbolic routing state."); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 115 | return; |
| 116 | } |
| 117 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 118 | if (m_isBuildAdjLsaScheduled) { |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 119 | NLSR_LOG_DEBUG("Rescheduling Adjacency LSA build in " << m_adjLsaBuildInterval); |
| 120 | } |
| 121 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 122 | NLSR_LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 123 | m_isBuildAdjLsaScheduled = true; |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 124 | } |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 125 | m_scheduledAdjLsaBuild = m_scheduler.schedule(m_adjLsaBuildInterval, [this] { buildAdjLsa(); }); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 126 | } |
| 127 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 128 | void |
| 129 | Lsdb::writeLog() const |
| 130 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 131 | static const Lsa::Type types[] = {Lsa::Type::COORDINATE, Lsa::Type::NAME, Lsa::Type::ADJACENCY}; |
| 132 | for (const auto& type : types) { |
| 133 | if ((type == Lsa::Type::COORDINATE && |
| 134 | m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) || |
| 135 | (type == Lsa::Type::ADJACENCY && |
| 136 | m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON)) { |
| 137 | continue; |
| 138 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 139 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 140 | NLSR_LOG_DEBUG("---------------" << type << " LSDB-------------------"); |
| 141 | auto lsaRange = m_lsdb.get<byType>().equal_range(type); |
| 142 | for (auto lsaIt = lsaRange.first; lsaIt != lsaRange.second; ++lsaIt) { |
| 143 | NLSR_LOG_DEBUG((*lsaIt)->toString()); |
| 144 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | void |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 149 | Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest) |
| 150 | { |
| 151 | ndn::Name interestName(interest.getName()); |
| 152 | NLSR_LOG_DEBUG("Interest received for LSA: " << interestName); |
| 153 | |
| 154 | if (interestName[-2].isVersion()) { |
| 155 | // Interest for particular segment |
| 156 | if (m_segmentPublisher.replyFromStore(interestName)) { |
| 157 | NLSR_LOG_TRACE("Reply from SegmentPublisher storage"); |
| 158 | return; |
| 159 | } |
| 160 | // Remove version and segment |
| 161 | interestName = interestName.getSubName(0, interestName.size() - 2); |
| 162 | NLSR_LOG_TRACE("Interest w/o segment and version: " << interestName); |
| 163 | } |
| 164 | |
| 165 | // increment RCV_LSA_INTEREST |
| 166 | lsaIncrementSignal(Statistics::PacketType::RCV_LSA_INTEREST); |
| 167 | |
| 168 | std::string chkString("LSA"); |
| 169 | int32_t lsaPosition = util::getNameComponentPosition(interestName, chkString); |
| 170 | |
| 171 | // Forms the name of the router that the Interest packet came from. |
| 172 | ndn::Name originRouter = m_confParam.getNetwork(); |
| 173 | originRouter.append(interestName.getSubName(lsaPosition + 1, |
| 174 | interestName.size() - lsaPosition - 3)); |
| 175 | |
| 176 | // if the interest is for this router's LSA |
| 177 | if (originRouter == m_thisRouterPrefix && lsaPosition >= 0) { |
| 178 | uint64_t seqNo = interestName[-1].toNumber(); |
| 179 | NLSR_LOG_DEBUG("LSA sequence number from interest: " << seqNo); |
| 180 | |
| 181 | std::string lsaType = interestName[-2].toUri(); |
| 182 | Lsa::Type interestedLsType; |
| 183 | std::istringstream(lsaType) >> interestedLsType; |
| 184 | if (interestedLsType == Lsa::Type::BASE) { |
| 185 | NLSR_LOG_WARN("Received unrecognized LSA type: " << lsaType); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | incrementInterestRcvdStats(interestedLsType); |
| 190 | if (processInterestForLsa(interest, originRouter, interestedLsType, seqNo)) { |
| 191 | lsaIncrementSignal(Statistics::PacketType::SENT_LSA_DATA); |
| 192 | } |
| 193 | } |
| 194 | // else the interest is for other router's LSA, serve signed data from LsaSegmentStorage |
| 195 | else if (auto lsaSegment = m_lsaStorage.find(interest)) { |
| 196 | NLSR_LOG_TRACE("Found data in lsa storage. Sending the data for " << interest.getName()); |
| 197 | m_face.put(*lsaSegment); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | bool |
| 202 | Lsdb::processInterestForLsa(const ndn::Interest& interest, const ndn::Name& originRouter, |
| 203 | Lsa::Type lsaType, uint64_t seqNo) |
| 204 | { |
| 205 | NLSR_LOG_DEBUG(interest << " received for " << lsaType); |
| 206 | if (auto lsaPtr = findLsa(originRouter, lsaType)) { |
| 207 | NLSR_LOG_TRACE("Verifying SeqNo for " << lsaType << " is same as requested."); |
| 208 | if (lsaPtr->getSeqNo() == seqNo) { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 209 | m_segmentPublisher.publish(interest.getName(), interest.getName(), lsaPtr->wireEncode(), |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 210 | m_lsaRefreshTime, m_confParam.getSigningInfo()); |
| 211 | incrementDataSentStats(lsaType); |
| 212 | return true; |
| 213 | } |
| 214 | } |
| 215 | else { |
| 216 | NLSR_LOG_TRACE(interest << " was not found in our LSDB"); |
| 217 | } |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | void |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 222 | Lsdb::installLsa(std::shared_ptr<Lsa> lsa) |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 223 | { |
| 224 | auto timeToExpire = m_lsaRefreshTime; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 225 | if (lsa->getOriginRouter() != m_thisRouterPrefix) { |
| 226 | auto duration = lsa->getExpirationTimePoint() - ndn::time::system_clock::now(); |
| 227 | if (duration > ndn::time::seconds(0)) { |
| 228 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
| 229 | } |
| 230 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 231 | |
| 232 | auto chkLsa = findLsa(lsa->getOriginRouter(), lsa->getType()); |
| 233 | if (chkLsa == nullptr) { |
| 234 | NLSR_LOG_DEBUG("Adding " << lsa->getType() << " LSA"); |
| 235 | NLSR_LOG_DEBUG(lsa->toString()); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 236 | |
| 237 | m_lsdb.emplace(lsa); |
| 238 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 239 | onLsdbModified(lsa, LsdbUpdate::INSTALLED, {}, {}); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 240 | |
| 241 | lsa->setExpiringEventId(scheduleLsaExpiration(lsa, timeToExpire)); |
| 242 | } |
| 243 | // Else this is a known name LSA, so we are updating it. |
| 244 | else if (chkLsa->getSeqNo() < lsa->getSeqNo()) { |
| 245 | NLSR_LOG_DEBUG("Updating " << lsa->getType() << " LSA:"); |
| 246 | NLSR_LOG_DEBUG(chkLsa->toString()); |
| 247 | chkLsa->setSeqNo(lsa->getSeqNo()); |
| 248 | chkLsa->setExpirationTimePoint(lsa->getExpirationTimePoint()); |
| 249 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 250 | bool updated; |
| 251 | std::list<ndn::Name> namesToAdd, namesToRemove; |
| 252 | std::tie(updated, namesToAdd, namesToRemove) = chkLsa->update(lsa); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 253 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 254 | if (updated) { |
| 255 | onLsdbModified(lsa, LsdbUpdate::UPDATED, namesToAdd, namesToRemove); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 258 | chkLsa->setExpiringEventId(scheduleLsaExpiration(chkLsa, timeToExpire)); |
| 259 | NLSR_LOG_DEBUG("Updated " << lsa->getType() << " LSA:"); |
| 260 | NLSR_LOG_DEBUG(chkLsa->toString()); |
| 261 | } |
| 262 | } |
| 263 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 264 | void |
| 265 | Lsdb::removeLsa(const LsaContainer::index<Lsdb::byName>::type::iterator& lsaIt) |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 266 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 267 | if (lsaIt != m_lsdb.end()) { |
| 268 | auto lsaPtr = *lsaIt; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 269 | NLSR_LOG_DEBUG("Removing " << lsaPtr->getType() << " LSA:"); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 270 | NLSR_LOG_DEBUG(lsaPtr->toString()); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 271 | m_lsdb.erase(lsaIt); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 272 | onLsdbModified(lsaPtr, LsdbUpdate::REMOVED, {}, {}); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 273 | } |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 274 | } |
| 275 | |
| 276 | void |
| 277 | Lsdb::removeLsa(const ndn::Name& router, Lsa::Type lsaType) |
| 278 | { |
| 279 | removeLsa(m_lsdb.get<byName>().find(std::make_tuple(router, lsaType))); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 282 | void |
| 283 | Lsdb::buildAdjLsa() |
| 284 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 285 | NLSR_LOG_TRACE("buildAdjLsa called"); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 286 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 287 | m_isBuildAdjLsaScheduled = false; |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 288 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 289 | if (m_confParam.getAdjacencyList().isAdjLsaBuildable(m_confParam.getInterestRetryNumber())) { |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 290 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 291 | int adjBuildCount = m_adjBuildCount; |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 292 | // Only do the adjLsa build if there's one scheduled |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 293 | if (adjBuildCount > 0) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 294 | // It only makes sense to do the adjLsa build if we have neighbors |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 295 | if (m_confParam.getAdjacencyList().getNumOfActiveNeighbor() > 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 296 | NLSR_LOG_DEBUG("Building and installing own Adj LSA"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 297 | buildAndInstallOwnAdjLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 298 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 299 | // We have no active neighbors, meaning no one can route through |
| 300 | // us. So delete our entry in the LSDB. This prevents this |
| 301 | // router from refreshing the LSA, eventually causing other |
| 302 | // routers to delete it, too. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 303 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 304 | NLSR_LOG_DEBUG("Removing own Adj LSA; no ACTIVE neighbors"); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 305 | removeLsa(m_thisRouterPrefix, Lsa::Type::ADJACENCY); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 306 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 307 | // In the case that during building the adj LSA, the FIB has to |
| 308 | // wait on an Interest response, the number of scheduled adj LSA |
| 309 | // builds could change, so we shouldn't just set it to 0. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 310 | m_adjBuildCount = m_adjBuildCount - adjBuildCount; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 311 | } |
| 312 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 313 | // We are still waiting to know the adjacency status of some |
| 314 | // neighbor, so schedule a build for later (when all that has |
| 315 | // hopefully finished) |
| 316 | else { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 317 | m_isBuildAdjLsaScheduled = true; |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 318 | auto schedulingTime = ndn::time::seconds(m_confParam.getInterestRetryNumber() * |
| 319 | m_confParam.getInterestResendTime()); |
| 320 | m_scheduledAdjLsaBuild = m_scheduler.schedule(schedulingTime, [this] { buildAdjLsa(); }); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 321 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 322 | } |
| 323 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 324 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 325 | Lsdb::buildAndInstallOwnAdjLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 326 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 327 | AdjLsa adjLsa(m_thisRouterPrefix, m_sequencingManager.getAdjLsaSeq() + 1, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 328 | getLsaExpirationTimePoint(), |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 329 | m_confParam.getAdjacencyList().getNumOfActiveNeighbor(), |
| 330 | m_confParam.getAdjacencyList()); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 331 | m_sequencingManager.increaseAdjLsaSeq(); |
| 332 | m_sequencingManager.writeSeqNoToFile(); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 333 | |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 334 | //Sync adjacency LSAs if link-state or dry-run HR is enabled. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 335 | if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_ON) { |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 336 | m_sync.publishRoutingUpdate(Lsa::Type::ADJACENCY, m_sequencingManager.getAdjLsaSeq()); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 337 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 338 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 339 | installLsa(std::make_shared<AdjLsa>(adjLsa)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 340 | } |
| 341 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 342 | ndn::scheduler::EventId |
| 343 | Lsdb::scheduleLsaExpiration(std::shared_ptr<Lsa> lsa, ndn::time::seconds expTime) |
| 344 | { |
| 345 | NLSR_LOG_DEBUG("Scheduling expiration in: " << expTime + GRACE_PERIOD << " for " << lsa->getOriginRouter()); |
| 346 | return m_scheduler.schedule(expTime + GRACE_PERIOD, [this, lsa] { expireOrRefreshLsa(lsa); }); |
| 347 | } |
| 348 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 349 | void |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 350 | Lsdb::expireOrRefreshLsa(std::shared_ptr<Lsa> lsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 351 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 352 | NLSR_LOG_DEBUG("ExpireOrRefreshLsa called for " << lsa->getType()); |
| 353 | NLSR_LOG_DEBUG("OriginRouter: " << lsa->getOriginRouter() << " Seq No: " << lsa->getSeqNo()); |
| 354 | |
| 355 | auto lsaIt = m_lsdb.get<byName>().find(std::make_tuple(lsa->getOriginRouter(), lsa->getType())); |
| 356 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 357 | // If this name LSA exists in the LSDB |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 358 | if (lsaIt != m_lsdb.end()) { |
| 359 | auto lsaPtr = *lsaIt; |
| 360 | NLSR_LOG_DEBUG(lsaPtr->toString()); |
| 361 | NLSR_LOG_DEBUG("LSA Exists with seq no: " << lsaPtr->getSeqNo()); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 362 | // If its seq no is the one we are expecting. |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 363 | if (lsaPtr->getSeqNo() == lsa->getSeqNo()) { |
| 364 | if (lsaPtr->getOriginRouter() == m_thisRouterPrefix) { |
| 365 | NLSR_LOG_DEBUG("Own " << lsaPtr->getType() << " LSA, so refreshing it."); |
| 366 | NLSR_LOG_DEBUG("Current LSA:"); |
| 367 | NLSR_LOG_DEBUG(lsaPtr->toString()); |
| 368 | lsaPtr->setSeqNo(lsaPtr->getSeqNo() + 1); |
| 369 | m_sequencingManager.setLsaSeq(lsaPtr->getSeqNo(), lsaPtr->getType()); |
| 370 | lsaPtr->setExpirationTimePoint(getLsaExpirationTimePoint()); |
| 371 | NLSR_LOG_DEBUG("Updated LSA:"); |
| 372 | NLSR_LOG_DEBUG(lsaPtr->toString()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 373 | // schedule refreshing event again |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 374 | lsaPtr->setExpiringEventId(scheduleLsaExpiration(lsaPtr, m_lsaRefreshTime)); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 375 | m_sequencingManager.writeSeqNoToFile(); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 376 | m_sync.publishRoutingUpdate(lsaPtr->getType(), m_sequencingManager.getLsaSeq(lsaPtr->getType())); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 377 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 378 | // 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] | 379 | else { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 380 | NLSR_LOG_DEBUG("Other's " << lsaPtr->getType() << " LSA, so removing from LSDB"); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 381 | removeLsa(lsaIt); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 387 | void |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 388 | Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 389 | ndn::time::steady_clock::TimePoint deadline) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 390 | { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 391 | // increment SENT_LSA_INTEREST |
| 392 | lsaIncrementSignal(Statistics::PacketType::SENT_LSA_INTEREST); |
| 393 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 394 | if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) { |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 395 | 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] | 396 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 397 | // The first component of the interest is the name. |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 398 | ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 399 | // The seq no is the last |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 400 | uint64_t seqNo = interestName[-1].toNumber(); |
| 401 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 402 | // If the LSA is not found in the list currently. |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 403 | if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) { |
| 404 | m_highestSeqNo[lsaName] = seqNo; |
| 405 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 406 | // 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] | 407 | else if (seqNo > m_highestSeqNo[lsaName]) { |
| 408 | m_highestSeqNo[lsaName] = seqNo; |
| 409 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 410 | // Otherwise, its an old/invalid LSA |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 411 | else if (seqNo < m_highestSeqNo[lsaName]) { |
| 412 | return; |
| 413 | } |
| 414 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 415 | ndn::Interest interest(interestName); |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 416 | ndn::util::SegmentFetcher::Options options; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 417 | options.interestLifetime = m_confParam.getLsaInterestLifetime(); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 418 | |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 419 | NLSR_LOG_DEBUG("Fetching Data for LSA: " << interestName << " Seq number: " << seqNo); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 420 | auto fetcher = ndn::util::SegmentFetcher::start(m_face, interest, |
| 421 | m_confParam.getValidator(), options); |
Ashlesh Gawande | 05cb728 | 2018-08-30 14:39:41 -0500 | [diff] [blame] | 422 | |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 423 | auto it = m_fetchers.insert(fetcher).first; |
| 424 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 425 | fetcher->afterSegmentValidated.connect([this] (const ndn::Data& data) { |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 426 | // Nlsr class subscribes to this to fetch certificates |
| 427 | afterSegmentValidatedSignal(data); |
| 428 | |
| 429 | // If we don't do this IMS throws: std::bad_weak_ptr: bad_weak_ptr |
| 430 | auto lsaSegment = std::make_shared<const ndn::Data>(data); |
| 431 | m_lsaStorage.insert(*lsaSegment); |
| 432 | const ndn::Name& segmentName = lsaSegment->getName(); |
| 433 | // Schedule deletion of the segment |
| 434 | m_scheduler.schedule(ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT), |
| 435 | [this, segmentName] { m_lsaStorage.erase(segmentName); }); |
| 436 | }); |
| 437 | |
| 438 | fetcher->onComplete.connect([=] (const ndn::ConstBufferPtr& bufferPtr) { |
| 439 | m_lsaStorage.erase(ndn::Name(lsaName).appendNumber(seqNo - 1)); |
| 440 | afterFetchLsa(bufferPtr, interestName); |
| 441 | m_fetchers.erase(it); |
| 442 | }); |
| 443 | |
| 444 | fetcher->onError.connect([=] (uint32_t errorCode, const std::string& msg) { |
| 445 | onFetchLsaError(errorCode, msg, interestName, timeoutCount, deadline, lsaName, seqNo); |
| 446 | m_fetchers.erase(it); |
| 447 | }); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 448 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 449 | Lsa::Type lsaType; |
| 450 | std::istringstream(interestName[-2].toUri()) >> lsaType; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 451 | incrementInterestSentStats(lsaType); |
| 452 | } |
| 453 | |
| 454 | void |
| 455 | Lsdb::onFetchLsaError(uint32_t errorCode, const std::string& msg, const ndn::Name& interestName, |
| 456 | uint32_t retransmitNo, const ndn::time::steady_clock::TimePoint& deadline, |
| 457 | ndn::Name lsaName, uint64_t seqNo) |
| 458 | { |
| 459 | NLSR_LOG_DEBUG("Failed to fetch LSA: " << lsaName << ", Error code: " << errorCode |
| 460 | << ", Message: " << msg); |
| 461 | |
| 462 | if (ndn::time::steady_clock::now() < deadline) { |
| 463 | auto it = m_highestSeqNo.find(lsaName); |
| 464 | if (it != m_highestSeqNo.end() && it->second == seqNo) { |
| 465 | // If the SegmentFetcher failed due to an Interest timeout, it is safe to re-express |
| 466 | // immediately since at the least the LSA Interest lifetime has elapsed. |
| 467 | // Otherwise, it is necessary to delay the Interest re-expression to prevent |
| 468 | // the potential for constant Interest flooding. |
| 469 | ndn::time::seconds delay = m_confParam.getLsaInterestLifetime(); |
| 470 | |
| 471 | if (errorCode == ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT) { |
| 472 | delay = ndn::time::seconds(0); |
| 473 | } |
| 474 | m_scheduler.schedule(delay, std::bind(&Lsdb::expressInterest, this, |
| 475 | interestName, retransmitNo + 1, deadline)); |
| 476 | } |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 477 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | void |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 481 | Lsdb::afterFetchLsa(const ndn::ConstBufferPtr& bufferPtr, const ndn::Name& interestName) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 482 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 483 | NLSR_LOG_DEBUG("Received data for LSA interest: " << interestName); |
| 484 | lsaIncrementSignal(Statistics::PacketType::RCV_LSA_DATA); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 485 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 486 | ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1); |
| 487 | uint64_t seqNo = interestName[-1].toNumber(); |
| 488 | |
| 489 | if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) { |
| 490 | m_highestSeqNo[lsaName] = seqNo; |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 491 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 492 | else if (seqNo > m_highestSeqNo[lsaName]) { |
| 493 | m_highestSeqNo[lsaName] = seqNo; |
| 494 | NLSR_LOG_TRACE("SeqNo for LSA(name): " << interestName << " updated"); |
| 495 | } |
| 496 | else if (seqNo < m_highestSeqNo[lsaName]) { |
| 497 | return; |
| 498 | } |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 499 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 500 | std::string chkString("LSA"); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 501 | int32_t lsaPosition = util::getNameComponentPosition(interestName, chkString); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 502 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 503 | if (lsaPosition >= 0) { |
| 504 | // Extracts the prefix of the originating router from the data. |
| 505 | ndn::Name originRouter = m_confParam.getNetwork(); |
| 506 | originRouter.append(interestName.getSubName(lsaPosition + 1, |
| 507 | interestName.size() - lsaPosition - 3)); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 508 | try { |
| 509 | Lsa::Type interestedLsType; |
| 510 | std::istringstream(interestName[-2].toUri()) >> interestedLsType; |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 511 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 512 | if (interestedLsType == Lsa::Type::BASE) { |
| 513 | NLSR_LOG_WARN("Received unrecognized LSA Type: " << interestName[-2].toUri()); |
| 514 | return; |
| 515 | } |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 516 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 517 | ndn::Block block(bufferPtr); |
| 518 | if (interestedLsType == Lsa::Type::NAME) { |
| 519 | lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_DATA); |
| 520 | if (isLsaNew(originRouter, interestedLsType, seqNo)) { |
| 521 | installLsa(std::make_shared<NameLsa>(block)); |
| 522 | } |
| 523 | } |
| 524 | else if (interestedLsType == Lsa::Type::ADJACENCY) { |
| 525 | lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_DATA); |
| 526 | if (isLsaNew(originRouter, interestedLsType, seqNo)) { |
| 527 | installLsa(std::make_shared<AdjLsa>(block)); |
| 528 | } |
| 529 | } |
| 530 | else if (interestedLsType == Lsa::Type::COORDINATE) { |
| 531 | lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_DATA); |
| 532 | if (isLsaNew(originRouter, interestedLsType, seqNo)) { |
| 533 | installLsa(std::make_shared<CoordinateLsa>(block)); |
| 534 | } |
| 535 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 536 | } |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 537 | catch (const std::exception& e) { |
| 538 | NLSR_LOG_TRACE("LSA data decoding error :( " << e.what()); |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 539 | } |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 543 | } // namespace nlsr |