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