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