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