blob: 5cfc78396cc18b0810583c3219f48ad9d595d9e2 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonfeae5572017-01-13 12:06:26 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
akmhoque53353462014-04-22 08:43:45 -050022#include "lsdb.hpp"
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050023
akmhoque674b0b12014-05-20 14:33:28 -050024#include "logger.hpp"
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050025#include "nlsr.hpp"
26#include "publisher/segment-publisher.hpp"
27#include "utility/name-helper.hpp"
28
29#include <ndn-cxx/security/signing-helpers.hpp>
30#include <ndn-cxx/util/segment-fetcher.hpp>
31
akmhoque53353462014-04-22 08:43:45 -050032namespace nlsr {
33
akmhoque674b0b12014-05-20 14:33:28 -050034INIT_LOGGER("Lsdb");
35
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050036class LsaContentPublisher : public SegmentPublisher<ndn::Face>
37{
38public:
39 LsaContentPublisher(ndn::Face& face,
40 ndn::KeyChain& keyChain,
41 const ndn::time::milliseconds& freshnessPeriod,
42 const std::string& content)
43 : SegmentPublisher(face, keyChain, freshnessPeriod)
44 , m_content(content)
45 {
46 }
47
48 virtual size_t
49 generate(ndn::EncodingBuffer& outBuffer) {
50 size_t totalLength = 0;
51 totalLength += outBuffer.prependByteArray(reinterpret_cast<const uint8_t*>(m_content.c_str()),
52 m_content.size());
53 return totalLength;
54 }
55
56private:
57 const std::string m_content;
58};
59
Jiewen Tana0497d82015-02-02 21:59:18 -080060const ndn::Name::Component Lsdb::NAME_COMPONENT = ndn::Name::Component("lsdb");
Vince Lehman18841082014-08-19 17:15:24 -050061const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -050062const steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = steady_clock::TimePoint::min();
Vince Lehman18841082014-08-19 17:15:24 -050063
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050064Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler)
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050065 : m_nlsr(nlsr)
66 , m_scheduler(scheduler)
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050067 , m_sync(m_nlsr.getNlsrFace(), *this, m_nlsr.getConfParameter())
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050068 , m_lsaRefreshTime(0)
69 , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050070 , m_sequencingManager()
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050071{
72}
73
74void
75Lsdb::onFetchLsaError(uint32_t errorCode,
76 const std::string& msg,
77 ndn::Name& interestName,
78 uint32_t retransmitNo,
79 const ndn::time::steady_clock::TimePoint& deadline,
80 ndn::Name lsaName,
81 uint64_t seqNo)
82{
83 _LOG_DEBUG("Failed to fetch LSA: " << lsaName << ", Error code: " << errorCode
84 << ", Message: " << msg);
85
86 if (ndn::time::steady_clock::now() < deadline) {
87 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
88
89 if (it != m_highestSeqNo.end() && it->second == seqNo) {
90 // If the SegmentFetcher failed due to an Interest timeout, it is safe to re-express
91 // immediately since at the least the LSA Interest lifetime has elapsed.
92 // Otherwise, it is necessary to delay the Interest re-expression to prevent
93 // the potential for constant Interest flooding.
94 ndn::time::seconds delay = m_nlsr.getConfParameter().getLsaInterestLifetime();
95
96 if (errorCode == ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT) {
97 delay = ndn::time::seconds(0);
98 }
99
100 m_scheduler.scheduleEvent(delay, std::bind(&Lsdb::expressInterest, this,
101 interestName, retransmitNo + 1, deadline));
102 }
103 }
104}
105
106void
107Lsdb::afterFetchLsa(const ndn::ConstBufferPtr& bufferPtr, ndn::Name& interestName)
108{
dmcoomes9f936662017-03-02 10:33:09 -0600109 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(ndn::Name(interestName));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500110 data->setContent(bufferPtr);
111
112 _LOG_DEBUG("Received data for LSA(name): " << data->getName());
113
114 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
115 uint64_t seqNo = interestName[-1].toNumber();
116
117 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
118 m_highestSeqNo[lsaName] = seqNo;
119 }
120 else if (seqNo > m_highestSeqNo[lsaName]) {
121 m_highestSeqNo[lsaName] = seqNo;
dmcoomes9eaf3f42017-02-21 11:39:01 -0600122 _LOG_TRACE("SeqNo for LSA(name): " << data->getName() << " updated");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500123 }
124 else if (seqNo < m_highestSeqNo[lsaName]) {
125 return;
126 }
127
128 onContentValidated(data);
129}
akmhoque53353462014-04-22 08:43:45 -0500130
131void
akmhoque31d1d4b2014-05-05 22:08:14 -0500132Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
akmhoque53353462014-04-22 08:43:45 -0500133{
Vince Lehman7c603292014-09-11 17:48:16 -0500134 m_scheduler.cancelEvent(eid);
akmhoque53353462014-04-22 08:43:45 -0500135}
136
Nick G97e34942016-07-11 14:46:27 -0500137 /*! \brief Compares if a name LSA is the same as the one specified by key
138
139 \param nlsa1 A name LSA object
140 \param key A key of an originating router to compare to nlsa1
141 */
akmhoque53353462014-04-22 08:43:45 -0500142static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500143nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500144{
145 return nlsa1.getKey() == key;
146}
147
akmhoque53353462014-04-22 08:43:45 -0500148bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500149Lsdb::buildAndInstallOwnNameLsa()
akmhoque53353462014-04-22 08:43:45 -0500150{
akmhoque31d1d4b2014-05-05 22:08:14 -0500151 NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500152 m_sequencingManager.getNameLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500153 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500154 m_nlsr.getNamePrefixList());
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500155 m_sequencingManager.increaseNameLsaSeq();
156
157 m_sequencingManager.writeSeqNoToFile();
158 m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
159
akmhoque31d1d4b2014-05-05 22:08:14 -0500160 return installNameLsa(nameLsa);
akmhoque53353462014-04-22 08:43:45 -0500161}
162
akmhoqueb6450b12014-04-24 00:01:03 -0500163NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500164Lsdb::findNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500165{
166 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
167 m_nameLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600168 std::bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500169 if (it != m_nameLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500170 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500171 }
akmhoqueb6450b12014-04-24 00:01:03 -0500172 return 0;
akmhoque53353462014-04-22 08:43:45 -0500173}
174
175bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500176Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500177{
akmhoqueb6450b12014-04-24 00:01:03 -0500178 NameLsa* nameLsaCheck = findNameLsa(key);
Nick G97e34942016-07-11 14:46:27 -0500179 // Is the name in the LSDB
akmhoque157b0a42014-05-13 00:26:37 -0500180 if (nameLsaCheck != 0) {
Nick G97e34942016-07-11 14:46:27 -0500181 // And the supplied seq no is the highest so far
akmhoque157b0a42014-05-13 00:26:37 -0500182 if (nameLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500183 return true;
184 }
akmhoque157b0a42014-05-13 00:26:37 -0500185 else {
akmhoque53353462014-04-22 08:43:45 -0500186 return false;
187 }
188 }
189 return true;
190}
191
192ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500193Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
194 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500195{
Vince Lehman7c603292014-09-11 17:48:16 -0500196 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500197 std::bind(&Lsdb::expireOrRefreshNameLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500198}
199
200bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500201Lsdb::installNameLsa(NameLsa& nlsa)
akmhoque53353462014-04-22 08:43:45 -0500202{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700203 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500204 NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
Nick G97e34942016-07-11 14:46:27 -0500205 // Determines if the name LSA is new or not.
akmhoque157b0a42014-05-13 00:26:37 -0500206 if (chkNameLsa == 0) {
akmhoque53353462014-04-22 08:43:45 -0500207 addNameLsa(nlsa);
akmhoque2f423352014-06-03 11:49:35 -0500208 _LOG_DEBUG("New Name LSA");
209 _LOG_DEBUG("Adding Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500210 nlsa.writeLog();
akmhoque674b0b12014-05-20 14:33:28 -0500211
akmhoque157b0a42014-05-13 00:26:37 -0500212 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
Nick G97e34942016-07-11 14:46:27 -0500213 // If this name LSA is from another router, add the advertised
214 // prefixes to the NPT.
akmhoque31d1d4b2014-05-05 22:08:14 -0500215 m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
216 nlsa.getOrigRouter());
Nick Gordonf14ec352017-07-24 16:09:58 -0500217 std::list<ndn::Name> nameList = nlsa.getNpl().getNames();
akmhoque31d1d4b2014-05-05 22:08:14 -0500218 for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end();
akmhoque157b0a42014-05-13 00:26:37 -0500219 it++) {
220 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500221 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500222 }
223 }
224 }
akmhoque157b0a42014-05-13 00:26:37 -0500225 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500226 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
227 ndn::time::system_clock::now();
228 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500229 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500230 nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500231 nlsa.getLsSeqNo(),
232 timeToExpire));
233 }
Nick G97e34942016-07-11 14:46:27 -0500234 // Else this is a known name LSA, so we are updating it.
akmhoque157b0a42014-05-13 00:26:37 -0500235 else {
236 if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500237 _LOG_DEBUG("Updated Name LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500238 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500239 chkNameLsa->writeLog();
240 chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500241 chkNameLsa->setExpirationTimePoint(nlsa.getExpirationTimePoint());
akmhoqueb6450b12014-04-24 00:01:03 -0500242 chkNameLsa->getNpl().sort();
akmhoque53353462014-04-22 08:43:45 -0500243 nlsa.getNpl().sort();
Nick G97e34942016-07-11 14:46:27 -0500244 // Obtain the set difference of the current and the incoming
245 // name prefix sets, and add those.
Nick Gordonf14ec352017-07-24 16:09:58 -0500246 std::list<ndn::Name> newNames = nlsa.getNpl().getNames();
247 std::list<ndn::Name> oldNames = chkNameLsa->getNpl().getNames();
248 std::list<ndn::Name> namesToAdd;
249 std::set_difference(newNames.begin(), newNames.end(), oldNames.begin(), oldNames.end(),
250 std::inserter(namesToAdd, namesToAdd.begin()));
251 for (std::list<ndn::Name>::iterator it = namesToAdd.begin();
252 it != namesToAdd.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500253 chkNameLsa->addName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500254 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
255 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500256 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500257 }
258 }
259 }
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500260
261 chkNameLsa->getNpl().sort();
262
Nick G97e34942016-07-11 14:46:27 -0500263 // Also remove any names that are no longer being advertised.
Nick Gordonf14ec352017-07-24 16:09:58 -0500264 std::list<ndn::Name> namesToRemove;
265 std::set_difference(oldNames.begin(), oldNames.end(), newNames.begin(), newNames.end(),
266 std::inserter(namesToRemove, namesToRemove.begin()));
267 for (std::list<ndn::Name>::iterator it = namesToRemove.begin();
268 it != namesToRemove.end(); ++it) {
dmcoomes9eaf3f42017-02-21 11:39:01 -0600269 _LOG_DEBUG("Removing name LSA no longer advertised: " << (*it).toUri());
akmhoqueb6450b12014-04-24 00:01:03 -0500270 chkNameLsa->removeName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500271 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
272 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500273 m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500274 }
275 }
276 }
dmcoomes9eaf3f42017-02-21 11:39:01 -0600277
akmhoque157b0a42014-05-13 00:26:37 -0500278 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500279 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
280 ndn::time::system_clock::now();
281 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500282 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500283 cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
284 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500285 nlsa.getLsSeqNo(),
286 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500287 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500288 chkNameLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500289 }
290 }
291 return true;
292}
293
294bool
295Lsdb::addNameLsa(NameLsa& nlsa)
296{
297 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
298 m_nameLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600299 std::bind(nameLsaCompareByKey, _1,
akmhoque53353462014-04-22 08:43:45 -0500300 nlsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500301 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500302 m_nameLsdb.push_back(nlsa);
303 return true;
304 }
305 return false;
306}
307
308bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500309Lsdb::removeNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500310{
311 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
312 m_nameLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600313 std::bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500314 if (it != m_nameLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500315 _LOG_DEBUG("Deleting Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500316 (*it).writeLog();
Nick G97e34942016-07-11 14:46:27 -0500317 // If the requested name LSA is not ours, we also need to remove
318 // its entries from the NPT.
akmhoque31d1d4b2014-05-05 22:08:14 -0500319 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500320 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500321 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
322 (*it).getOrigRouter());
Nick Gordonf14ec352017-07-24 16:09:58 -0500323 for (const auto& name : it->getNpl().getNames()) {
324 if (name != m_nlsr.getConfParameter().getRouterPrefix()) {
325 m_nlsr.getNamePrefixTable().removeEntry(name, it->getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500326 }
327 }
328 }
329 m_nameLsdb.erase(it);
330 return true;
331 }
332 return false;
333}
334
335bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500336Lsdb::doesNameLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500337{
338 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
339 m_nameLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600340 std::bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500341 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500342 return false;
343 }
344 return true;
345}
346
347void
akmhoque2f423352014-06-03 11:49:35 -0500348Lsdb::writeNameLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500349{
akmhoque2f423352014-06-03 11:49:35 -0500350 _LOG_DEBUG("---------------Name LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -0500351 for (std::list<NameLsa>::iterator it = m_nameLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500352 it != m_nameLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500353 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500354 }
355}
356
Jiewen Tana0497d82015-02-02 21:59:18 -0800357const std::list<NameLsa>&
358Lsdb::getNameLsdb()
359{
360 return m_nameLsdb;
361}
362
akmhoque53353462014-04-22 08:43:45 -0500363// Cor LSA and LSDB related Functions start here
364
Nick G97e34942016-07-11 14:46:27 -0500365/*! \brief Compares whether an LSA object is the same as a key.
366 \param clsa The cor. LSA to check the identity of.
367 \param key The key of the publishing router to check against.
368*/
akmhoque53353462014-04-22 08:43:45 -0500369static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500370corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500371{
372 return clsa.getKey() == key;
373}
374
375bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500376Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500377{
akmhoque31d1d4b2014-05-05 22:08:14 -0500378 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500379 m_sequencingManager.getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500380 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500381 m_nlsr.getConfParameter().getCorR(),
382 m_nlsr.getConfParameter().getCorTheta());
Nick Gordon5c467f02016-07-13 13:40:10 -0500383
384 // Sync coordinate LSAs if using HR or HR dry run.
385 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500386 m_sequencingManager.increaseCorLsaSeq();
387 m_sequencingManager.writeSeqNoToFile();
388 m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
Nick Gordon5c467f02016-07-13 13:40:10 -0500389 }
390
akmhoque31d1d4b2014-05-05 22:08:14 -0500391 installCoordinateLsa(corLsa);
Nick Gordon5c467f02016-07-13 13:40:10 -0500392
akmhoque53353462014-04-22 08:43:45 -0500393 return true;
394}
395
akmhoqueb6450b12014-04-24 00:01:03 -0500396CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500397Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500398{
akmhoqueb6450b12014-04-24 00:01:03 -0500399 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
400 m_corLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600401 std::bind(corLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500402 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500403 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500404 }
akmhoqueb6450b12014-04-24 00:01:03 -0500405 return 0;
akmhoque53353462014-04-22 08:43:45 -0500406}
407
408bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500409Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500410{
akmhoqueb6450b12014-04-24 00:01:03 -0500411 CoordinateLsa* clsa = findCoordinateLsa(key);
Nick G97e34942016-07-11 14:46:27 -0500412 // Is the coordinate LSA in the LSDB already
akmhoque157b0a42014-05-13 00:26:37 -0500413 if (clsa != 0) {
Nick G97e34942016-07-11 14:46:27 -0500414 // And the seq no is newer (higher) than the current one
akmhoque157b0a42014-05-13 00:26:37 -0500415 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500416 return true;
417 }
akmhoque157b0a42014-05-13 00:26:37 -0500418 else {
akmhoque53353462014-04-22 08:43:45 -0500419 return false;
420 }
421 }
422 return true;
423}
424
Nick G97e34942016-07-11 14:46:27 -0500425 // Schedules a refresh/expire event in the scheduler.
426 // \param key The name of the router that published the LSA.
427 // \param seqNo the seq. no. associated with the LSA to check.
428 // \param expTime How long to wait before triggering the event.
akmhoque53353462014-04-22 08:43:45 -0500429ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500430Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500431 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500432{
Vince Lehman7c603292014-09-11 17:48:16 -0500433 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500434 std::bind(&Lsdb::expireOrRefreshCoordinateLsa,
Vince Lehman7c603292014-09-11 17:48:16 -0500435 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500436}
437
438bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500439Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500440{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700441 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500442 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
Nick G97e34942016-07-11 14:46:27 -0500443 // Checking whether the LSA is new or not.
akmhoque157b0a42014-05-13 00:26:37 -0500444 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500445 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500446 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500447 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500448 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500449
Nick Gordon5c467f02016-07-13 13:40:10 -0500450 // Register the LSA's origin router prefix
akmhoque157b0a42014-05-13 00:26:37 -0500451 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500452 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
453 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500454 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500455 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500456 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500457 }
Nick G97e34942016-07-11 14:46:27 -0500458 // Set the expiration time for the new LSA.
akmhoque157b0a42014-05-13 00:26:37 -0500459 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500460 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
461 ndn::time::system_clock::now();
462 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500463 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500464 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500465 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500466 }
Nick G97e34942016-07-11 14:46:27 -0500467 // We are just updating this LSA.
akmhoque157b0a42014-05-13 00:26:37 -0500468 else {
469 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500470 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500471 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500472 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500473 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500474 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
Nick G97e34942016-07-11 14:46:27 -0500475 // If the new LSA contains new routing information, update the LSDB with it.
akmhoque157b0a42014-05-13 00:26:37 -0500476 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500477 chkCorLsa->setCorRadius(clsa.getCorRadius());
478 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500479 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500480 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500481 }
482 }
Nick G97e34942016-07-11 14:46:27 -0500483 // If this is an LSA from another router, refresh its expiration time.
akmhoque157b0a42014-05-13 00:26:37 -0500484 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500485 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
486 ndn::time::system_clock::now();
487 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500488 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500489 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
490 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500491 clsa.getLsSeqNo(),
492 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500493 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500494 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500495 }
496 }
497 return true;
498}
499
500bool
akmhoqueb6450b12014-04-24 00:01:03 -0500501Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500502{
akmhoqueb6450b12014-04-24 00:01:03 -0500503 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
504 m_corLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600505 std::bind(corLsaCompareByKey, _1,
akmhoque157b0a42014-05-13 00:26:37 -0500506 clsa.getKey()));
507 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500508 m_corLsdb.push_back(clsa);
509 return true;
510 }
511 return false;
512}
513
514bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500515Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500516{
akmhoqueb6450b12014-04-24 00:01:03 -0500517 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
518 m_corLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600519 std::bind(corLsaCompareByKey,
akmhoque157b0a42014-05-13 00:26:37 -0500520 _1, key));
521 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500522 _LOG_DEBUG("Deleting Coordinate Lsa");
Nick Gordon5c467f02016-07-13 13:40:10 -0500523 it->writeLog();
524
525 if (it->getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
526 m_nlsr.getNamePrefixTable().removeEntry(it->getOrigRouter(), it->getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500527 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500528
akmhoque53353462014-04-22 08:43:45 -0500529 m_corLsdb.erase(it);
530 return true;
531 }
532 return false;
533}
534
535bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500536Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500537{
akmhoqueb6450b12014-04-24 00:01:03 -0500538 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
539 m_corLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600540 std::bind(corLsaCompareByKey,
akmhoque157b0a42014-05-13 00:26:37 -0500541 _1, key));
542 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500543 return false;
544 }
545 return true;
546}
547
548void
akmhoque2f423352014-06-03 11:49:35 -0500549Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500550{
akmhoque2f423352014-06-03 11:49:35 -0500551 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500552 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500553 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500554 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500555 }
556}
557
Jiewen Tana0497d82015-02-02 21:59:18 -0800558const std::list<CoordinateLsa>&
559Lsdb::getCoordinateLsdb()
560{
561 return m_corLsdb;
562}
563
akmhoque53353462014-04-22 08:43:45 -0500564// Adj LSA and LSDB related function starts here
565
Nick G97e34942016-07-11 14:46:27 -0500566 /*! \brief Returns whether an adj. LSA object is from some router.
567 \param alsa The adj. LSA object.
568 \param key The router name that you want to compare the LSA with.
569 */
akmhoque53353462014-04-22 08:43:45 -0500570static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500571adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500572{
573 return alsa.getKey() == key;
574}
575
akmhoque53353462014-04-22 08:43:45 -0500576void
Vince Lehman50df6b72015-03-03 12:06:40 -0600577Lsdb::scheduleAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500578{
Vince Lehman50df6b72015-03-03 12:06:40 -0600579 m_nlsr.incrementAdjBuildCount();
580
Nick Gordon5c467f02016-07-13 13:40:10 -0500581 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
582 // Don't build adjacency LSAs in hyperbolic routing
dmcoomes9eaf3f42017-02-21 11:39:01 -0600583 _LOG_DEBUG("Adjacency LSA not built. Currently in hyperbolic routing state.");
Nick Gordon5c467f02016-07-13 13:40:10 -0500584 return;
585 }
586
Vince Lehman50df6b72015-03-03 12:06:40 -0600587 if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
588 _LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
589
dmcoomes9f936662017-03-02 10:33:09 -0600590 m_scheduler.scheduleEvent(m_adjLsaBuildInterval, std::bind(&Lsdb::buildAdjLsa, this));
Vince Lehman50df6b72015-03-03 12:06:40 -0600591 m_nlsr.setIsBuildAdjLsaSheduled(true);
592 }
593}
594
595void
596Lsdb::buildAdjLsa()
597{
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500598 _LOG_TRACE("Lsdb::buildAdjLsa called");
Vince Lehman50df6b72015-03-03 12:06:40 -0600599
akmhoque674b0b12014-05-20 14:33:28 -0500600 m_nlsr.setIsBuildAdjLsaSheduled(false);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500601
602 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr.getConfParameter().getInterestRetryNumber())) {
603
akmhoque31d1d4b2014-05-05 22:08:14 -0500604 int adjBuildCount = m_nlsr.getAdjBuildCount();
Nick G97e34942016-07-11 14:46:27 -0500605 // Only do the adjLsa build if there's one scheduled
akmhoque157b0a42014-05-13 00:26:37 -0500606 if (adjBuildCount > 0) {
Nick G97e34942016-07-11 14:46:27 -0500607 // It only makes sense to do the adjLsa build if we have neighbors
akmhoque157b0a42014-05-13 00:26:37 -0500608 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500609 _LOG_DEBUG("Building and installing own Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500610 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500611 }
Nick G97e34942016-07-11 14:46:27 -0500612 // We have no active neighbors, meaning no one can route through
613 // us. So delete our entry in the LSDB. This prevents this
614 // router from refreshing the LSA, eventually causing other
615 // routers to delete it, too.
akmhoque157b0a42014-05-13 00:26:37 -0500616 else {
dmcoomes9f936662017-03-02 10:33:09 -0600617 _LOG_DEBUG("Removing own Adj LSA; no ACTIVE neighbors");
Nick G97e34942016-07-11 14:46:27 -0500618 // Get this router's key
akmhoque31d1d4b2014-05-05 22:08:14 -0500619 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
alvy49b1c0c2014-12-19 13:57:46 -0600620 key.append(AdjLsa::TYPE_STRING);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500621
akmhoque31d1d4b2014-05-05 22:08:14 -0500622 removeAdjLsa(key);
Nick G97e34942016-07-11 14:46:27 -0500623 // Recompute routing table after removal
akmhoque31d1d4b2014-05-05 22:08:14 -0500624 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500625 }
Nick G97e34942016-07-11 14:46:27 -0500626 // In the case that during building the adj LSA, the FIB has to
627 // wait on an Interest response, the number of scheduled adj LSA
628 // builds could change, so we shouldn't just set it to 0.
akmhoque31d1d4b2014-05-05 22:08:14 -0500629 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500630 }
631 }
Nick G97e34942016-07-11 14:46:27 -0500632 // We are still waiting to know the adjacency status of some
633 // neighbor, so schedule a build for later (when all that has
634 // hopefully finished)
635 else {
636 m_nlsr.setIsBuildAdjLsaSheduled(true);
637 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
638 m_nlsr.getConfParameter().getInterestResendTime();
639 m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
dmcoomes9f936662017-03-02 10:33:09 -0600640 std::bind(&Lsdb::buildAdjLsa, this));
Nick G97e34942016-07-11 14:46:27 -0500641 }
akmhoque53353462014-04-22 08:43:45 -0500642}
643
akmhoque53353462014-04-22 08:43:45 -0500644bool
645Lsdb::addAdjLsa(AdjLsa& alsa)
646{
647 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
648 m_adjLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600649 std::bind(adjLsaCompareByKey, _1,
akmhoque53353462014-04-22 08:43:45 -0500650 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500651 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500652 m_adjLsdb.push_back(alsa);
653 return true;
654 }
655 return false;
656}
657
akmhoqueb6450b12014-04-24 00:01:03 -0500658AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500659Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500660{
661 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
662 m_adjLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600663 std::bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500664 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500665 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500666 }
akmhoqueb6450b12014-04-24 00:01:03 -0500667 return 0;
akmhoque53353462014-04-22 08:43:45 -0500668}
669
akmhoque53353462014-04-22 08:43:45 -0500670bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500671Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500672{
akmhoqueb6450b12014-04-24 00:01:03 -0500673 AdjLsa* adjLsaCheck = findAdjLsa(key);
Nick G97e34942016-07-11 14:46:27 -0500674 // If it is in the LSDB
akmhoque157b0a42014-05-13 00:26:37 -0500675 if (adjLsaCheck != 0) {
Nick G97e34942016-07-11 14:46:27 -0500676 // And the supplied seq no is newer (higher) than the current one.
akmhoque157b0a42014-05-13 00:26:37 -0500677 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500678 return true;
679 }
akmhoque157b0a42014-05-13 00:26:37 -0500680 else {
akmhoque53353462014-04-22 08:43:45 -0500681 return false;
682 }
683 }
684 return true;
685}
686
akmhoque53353462014-04-22 08:43:45 -0500687ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500688Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
689 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500690{
Vince Lehman7c603292014-09-11 17:48:16 -0500691 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500692 std::bind(&Lsdb::expireOrRefreshAdjLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500693}
694
695bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500696Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500697{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700698 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500699 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
Nick G97e34942016-07-11 14:46:27 -0500700 // If this adj. LSA is not in the LSDB already
akmhoque157b0a42014-05-13 00:26:37 -0500701 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500702 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500703 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500704 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500705 addAdjLsa(alsa);
Nick G97e34942016-07-11 14:46:27 -0500706 // Add any new name prefixes to the NPT
akmhoque31d1d4b2014-05-05 22:08:14 -0500707 alsa.addNptEntries(m_nlsr);
708 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500709 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500710 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
711 ndn::time::system_clock::now();
712 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500713 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500714 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500715 alsa.getLsSeqNo(), timeToExpire);
716 }
akmhoque157b0a42014-05-13 00:26:37 -0500717 else {
718 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500719 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500720 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500721 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500722 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500723 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
Nick G97e34942016-07-11 14:46:27 -0500724 // If the new adj LSA has new content, update the contents of
725 // the LSDB entry. Additionally, since we've changed the
726 // contents of the LSDB, we have to schedule a routing
727 // calculation.
akmhoque157b0a42014-05-13 00:26:37 -0500728 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500729 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500730 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500731 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500732 }
akmhoque157b0a42014-05-13 00:26:37 -0500733 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500734 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
735 ndn::time::system_clock::now();
736 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500737 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500738 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
739 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500740 alsa.getLsSeqNo(),
741 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500742 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500743 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500744 }
745 }
746 return true;
747}
748
749bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500750Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500751{
akmhoque31d1d4b2014-05-05 22:08:14 -0500752 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500753 m_sequencingManager.getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500754 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500755 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
756 m_nlsr.getAdjacencyList());
Vince Lehman904c2412014-09-23 19:36:11 -0500757
Nick Gordon5c467f02016-07-13 13:40:10 -0500758 //Sync adjacency LSAs if link-state or dry-run HR is enabled.
759 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_ON) {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500760 m_sequencingManager.increaseAdjLsaSeq();
761 m_sequencingManager.writeSeqNoToFile();
762 m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
Nick Gordon5c467f02016-07-13 13:40:10 -0500763 }
Vince Lehman904c2412014-09-23 19:36:11 -0500764
Vince Lehman9d097802015-03-16 17:55:59 -0500765 return installAdjLsa(adjLsa);
akmhoque53353462014-04-22 08:43:45 -0500766}
767
768bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500769Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500770{
771 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
772 m_adjLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600773 std::bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500774 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500775 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500776 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500777 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500778 m_adjLsdb.erase(it);
779 return true;
780 }
781 return false;
782}
783
784bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500785Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500786{
787 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
788 m_adjLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600789 std::bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500790 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500791 return false;
792 }
793 return true;
794}
795
Jiewen Tana0497d82015-02-02 21:59:18 -0800796const std::list<AdjLsa>&
akmhoque53353462014-04-22 08:43:45 -0500797Lsdb::getAdjLsdb()
798{
799 return m_adjLsdb;
800}
801
802void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700803Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500804{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700805 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500806}
807
808void
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500809Lsdb::setThisRouterPrefix(std::string trp)
akmhoque53353462014-04-22 08:43:45 -0500810{
811 m_thisRouterPrefix = trp;
812}
813
Nick G97e34942016-07-11 14:46:27 -0500814 // 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.
akmhoque53353462014-04-22 08:43:45 -0500821void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500822Lsdb::expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500823{
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500824 _LOG_DEBUG("Lsdb::expireOrRefreshNameLsa Called");
akmhoque674b0b12014-05-20 14:33:28 -0500825 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500826 NameLsa* chkNameLsa = findNameLsa(lsaKey);
Nick G97e34942016-07-11 14:46:27 -0500827 // If this name LSA exists in the LSDB
akmhoque157b0a42014-05-13 00:26:37 -0500828 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500829 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
Nick G97e34942016-07-11 14:46:27 -0500830 // If its seq no is the one we are expecting.
akmhoque157b0a42014-05-13 00:26:37 -0500831 if (chkNameLsa->getLsSeqNo() == seqNo) {
832 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500833 _LOG_DEBUG("Own Name LSA, so refreshing it");
834 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500835 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500836 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500837 m_sequencingManager.setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500838 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500839 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500840 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500841 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500842 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500843 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700844 m_lsaRefreshTime));
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500845 m_sequencingManager.writeSeqNoToFile();
846 m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
akmhoque53353462014-04-22 08:43:45 -0500847 }
Nick G97e34942016-07-11 14:46:27 -0500848 // Since we cannot refresh other router's LSAs, our only choice is to expire.
akmhoque157b0a42014-05-13 00:26:37 -0500849 else {
dmcoomes9eaf3f42017-02-21 11:39:01 -0600850 _LOG_DEBUG("Other's Name LSA, so removing from LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500851 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500852 }
853 }
854 }
855}
856
Nick G97e34942016-07-11 14:46:27 -0500857 // 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.
akmhoque53353462014-04-22 08:43:45 -0500864void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500865Lsdb::expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500866{
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500867 _LOG_DEBUG("Lsdb::expireOrRefreshAdjLsa Called");
dmcoomes9eaf3f42017-02-21 11:39:01 -0600868 _LOG_DEBUG("LSA Key: " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500869 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
Nick G97e34942016-07-11 14:46:27 -0500870 // If this is a valid LSA
akmhoque157b0a42014-05-13 00:26:37 -0500871 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500872 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
Nick G97e34942016-07-11 14:46:27 -0500873 // And if it hasn't been updated for some other reason
akmhoque157b0a42014-05-13 00:26:37 -0500874 if (chkAdjLsa->getLsSeqNo() == seqNo) {
Nick G97e34942016-07-11 14:46:27 -0500875 // If it is our own LSA
akmhoque157b0a42014-05-13 00:26:37 -0500876 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500877 _LOG_DEBUG("Own Adj LSA, so refreshing it");
878 _LOG_DEBUG("Deleting Adj Lsa");
879 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500880 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500881 m_sequencingManager.setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500882 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500883 _LOG_DEBUG("Adding Adj Lsa");
884 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500885 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500886 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500887 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700888 m_lsaRefreshTime));
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500889 m_sequencingManager.writeSeqNoToFile();
890 m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
akmhoque53353462014-04-22 08:43:45 -0500891 }
Nick G97e34942016-07-11 14:46:27 -0500892 // An LSA from another router is expiring
akmhoque157b0a42014-05-13 00:26:37 -0500893 else {
dmcoomes9eaf3f42017-02-21 11:39:01 -0600894 _LOG_DEBUG("Other's Adj LSA, so removing from LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500895 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500896 }
Nick G97e34942016-07-11 14:46:27 -0500897 // We have changed the contents of the LSDB, so we have to
898 // schedule a routing calculation
akmhoque31d1d4b2014-05-05 22:08:14 -0500899 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500900 }
901 }
902}
903
Nick G97e34942016-07-11 14:46:27 -0500904 // 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.
akmhoque53353462014-04-22 08:43:45 -0500911void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500912Lsdb::expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500913 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500914{
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500915 _LOG_DEBUG("Lsdb::expireOrRefreshCorLsa Called ");
akmhoque674b0b12014-05-20 14:33:28 -0500916 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500917 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
Nick G97e34942016-07-11 14:46:27 -0500918 // Whether the LSA is in the LSDB or not.
akmhoque157b0a42014-05-13 00:26:37 -0500919 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500920 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
Nick G97e34942016-07-11 14:46:27 -0500921 // Whether the LSA has been updated without our knowledge.
akmhoque157b0a42014-05-13 00:26:37 -0500922 if (chkCorLsa->getLsSeqNo() == seqNo) {
923 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500924 _LOG_DEBUG("Own Cor LSA, so refreshing it");
925 _LOG_DEBUG("Deleting Coordinate Lsa");
926 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500927 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
Nick Gordon5c467f02016-07-13 13:40:10 -0500928 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500929 m_sequencingManager.setCorLsaSeq(chkCorLsa->getLsSeqNo());
Nick Gordon5c467f02016-07-13 13:40:10 -0500930 }
931
akmhoquec7a79b22014-05-26 08:06:19 -0500932 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500933 _LOG_DEBUG("Adding Coordinate Lsa");
934 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500935 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500936 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
937 chkCorLsa->getKey(),
938 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700939 m_lsaRefreshTime));
Nick Gordon5c467f02016-07-13 13:40:10 -0500940 // Only sync coordinate LSAs if link-state routing is disabled
941 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500942 m_sequencingManager.writeSeqNoToFile();
943 m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
Nick Gordon5c467f02016-07-13 13:40:10 -0500944 }
akmhoque53353462014-04-22 08:43:45 -0500945 }
Nick G97e34942016-07-11 14:46:27 -0500946 // We can't refresh other router's LSAs, so we remove it.
akmhoque157b0a42014-05-13 00:26:37 -0500947 else {
dmcoomes9eaf3f42017-02-21 11:39:01 -0600948 _LOG_DEBUG("Other's Cor LSA, so removing from LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500949 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500950 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500951 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500952 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500953 }
954 }
955 }
956}
957
akmhoque53353462014-04-22 08:43:45 -0500958void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700959Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500960 steady_clock::TimePoint deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500961{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600962 // increment SENT_LSA_INTEREST
963 lsaIncrementSignal(Statistics::PacketType::SENT_LSA_INTEREST);
964
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500965 if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) {
966 deadline = steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700967 }
Nick G97e34942016-07-11 14:46:27 -0500968 // The first component of the interest is the name.
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500969 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
Nick G97e34942016-07-11 14:46:27 -0500970 // The seq no is the last
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500971 uint64_t seqNo = interestName[-1].toNumber();
972
Nick G97e34942016-07-11 14:46:27 -0500973 // If the LSA is not found in the list currently.
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500974 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
975 m_highestSeqNo[lsaName] = seqNo;
976 }
Nick G97e34942016-07-11 14:46:27 -0500977 // If the new seq no is higher, that means the LSA is valid
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500978 else if (seqNo > m_highestSeqNo[lsaName]) {
979 m_highestSeqNo[lsaName] = seqNo;
980 }
Nick G97e34942016-07-11 14:46:27 -0500981 // Otherwise, its an old/invalid LSA
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500982 else if (seqNo < m_highestSeqNo[lsaName]) {
983 return;
984 }
985
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500986 ndn::Interest interest(interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700987 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500988
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500989 _LOG_DEBUG("Fetching Data for LSA: " << interestName << " Seq number: " << seqNo);
990 ndn::util::SegmentFetcher::fetch(m_nlsr.getNlsrFace(), interest,
991 m_nlsr.getValidator(),
dmcoomes9f936662017-03-02 10:33:09 -0600992 std::bind(&Lsdb::afterFetchLsa, this, _1, interestName),
993 std::bind(&Lsdb::onFetchLsaError, this, _1, _2, interestName,
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500994 timeoutCount, deadline, lsaName, seqNo));
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600995 // increment a specific SENT_LSA_INTEREST
996 std::string typeLSA = interestName[-2].toUri();
997 if (typeLSA == AdjLsa::TYPE_STRING) {
998 lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_INTEREST);
999 }
1000 else if (typeLSA == CoordinateLsa::TYPE_STRING) {
1001 lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_INTEREST);
1002 }
1003 else if (typeLSA == NameLsa::TYPE_STRING) {
1004 lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_INTEREST);
1005 }
1006 else {
1007 _LOG_ERROR("typeLSA " + typeLSA + " not recognized; failed Statistics::PacketType conversion");
1008 }
akmhoque31d1d4b2014-05-05 22:08:14 -05001009}
1010
1011void
1012Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
1013{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001014 // increment RCV_LSA_INTEREST
1015 lsaIncrementSignal(Statistics::PacketType::RCV_LSA_INTEREST);
1016
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001017 const ndn::Name& interestName(interest.getName());
1018 _LOG_DEBUG("Interest received for LSA: " << interestName);
1019
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001020 std::string chkString("LSA");
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001021 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
1022
akmhoque157b0a42014-05-13 00:26:37 -05001023 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001024
Nick G97e34942016-07-11 14:46:27 -05001025 // Forms the name of the router that the Interest packet came from.
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001026 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
1027 originRouter.append(interestName.getSubName(lsaPosition + 1,
1028 interest.getName().size() - lsaPosition - 3));
1029
1030 uint64_t seqNo = interestName[-1].toNumber();
1031 _LOG_DEBUG("LSA sequence number from interest: " << seqNo);
1032
1033 std::string interestedLsType = interestName[-2].toUri();
1034
alvy49b1c0c2014-12-19 13:57:46 -06001035 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001036 processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -05001037 }
alvy49b1c0c2014-12-19 13:57:46 -06001038 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001039 processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -05001040 }
alvy49b1c0c2014-12-19 13:57:46 -06001041 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001042 processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -05001043 }
akmhoque157b0a42014-05-13 00:26:37 -05001044 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001045 _LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -05001046 }
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001047 lsaIncrementSignal(Statistics::PacketType::SENT_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001048 }
1049}
1050
Nick G97e34942016-07-11 14:46:27 -05001051 // \brief Sends LSA data.
1052 // \param interest The Interest that warranted the data.
1053 // \param content The data that the Interest was seeking.
akmhoque31d1d4b2014-05-05 22:08:14 -05001054void
akmhoque69c9aa92014-07-23 15:15:05 -05001055Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
1056{
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001057 LsaContentPublisher publisher(m_nlsr.getNlsrFace(),
1058 m_nlsr.getKeyChain(),
1059 m_lsaRefreshTime,
1060 content);
dmcoomes9eaf3f42017-02-21 11:39:01 -06001061 _LOG_DEBUG("Sending requested data ( " << content << ") for interest (" << interest
1062 << ") to be published and added to face.");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001063 publisher.publish(interest.getName(),
1064 ndn::security::signingByCertificate(m_nlsr.getDefaultCertName()));
akmhoque69c9aa92014-07-23 15:15:05 -05001065}
1066
Nick G97e34942016-07-11 14:46:27 -05001067 // \brief Finds and sends a requested name LSA.
1068 // \param interest The interest that seeks the name LSA.
1069 // \param lsaKey The LSA that the Interest is seeking.
1070 // \param seqNo A sequence number to ensure that we are sending the
1071 // version that was requested.
akmhoque69c9aa92014-07-23 15:15:05 -05001072void
akmhoque31d1d4b2014-05-05 22:08:14 -05001073Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
1074 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001075 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001076{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001077 // increment RCV_NAME_LSA_INTEREST
1078 lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_INTEREST);
dmcoomes9eaf3f42017-02-21 11:39:01 -06001079 _LOG_DEBUG("nameLsa interest " << interest << " received");
akmhoque31d1d4b2014-05-05 22:08:14 -05001080 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -05001081 if (nameLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001082 if (nameLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001083 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -05001084 putLsaData(interest,content);
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001085 // increment SENT_NAME_LSA_DATA
1086 lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001087 }
dmcoomes9eaf3f42017-02-21 11:39:01 -06001088 else {
1089 _LOG_TRACE("SeqNo for nameLsa does not match");
1090 }
1091 }
1092 else {
1093 _LOG_TRACE(interest << " was not found in this lsdb");
akmhoque31d1d4b2014-05-05 22:08:14 -05001094 }
1095}
1096
Nick G97e34942016-07-11 14:46:27 -05001097 // \brief Finds and sends a requested adj. LSA.
1098 // \param interest The interest that seeks the adj. LSA.
1099 // \param lsaKey The LSA that the Interest is seeking.
1100 // \param seqNo A sequence number to ensure that we are sending the
1101 // version that was requested.
akmhoque31d1d4b2014-05-05 22:08:14 -05001102void
1103Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
1104 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001105 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001106{
Nick Gordon5c467f02016-07-13 13:40:10 -05001107 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
dmcoomes9eaf3f42017-02-21 11:39:01 -06001108 _LOG_ERROR("Received interest for an adjacency LSA when hyperbolic routing is enabled");
Nick Gordon5c467f02016-07-13 13:40:10 -05001109 }
1110
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001111 // increment RCV_ADJ_LSA_INTEREST
1112 lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_INTEREST);
dmcoomes9eaf3f42017-02-21 11:39:01 -06001113 _LOG_DEBUG("AdjLsa interest " << interest << " received");
akmhoque31d1d4b2014-05-05 22:08:14 -05001114 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -05001115 if (adjLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001116 if (adjLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001117 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -05001118 putLsaData(interest,content);
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001119 // increment SENT_ADJ_LSA_DATA
1120 lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001121 }
dmcoomes9eaf3f42017-02-21 11:39:01 -06001122 else {
1123 _LOG_TRACE("SeqNo for AdjLsa does not match");
1124 }
1125 }
1126 else {
1127 _LOG_TRACE(interest << " was not found in this lsdb");
akmhoque31d1d4b2014-05-05 22:08:14 -05001128 }
1129}
1130
Nick G97e34942016-07-11 14:46:27 -05001131 // \brief Finds and sends a requested cor. LSA.
1132 // \param interest The interest that seeks the cor. LSA.
1133 // \param lsaKey The LSA that the Interest is seeking.
1134 // \param seqNo A sequence number to ensure that we are sending the
1135 // version that was requested.
akmhoque31d1d4b2014-05-05 22:08:14 -05001136void
1137Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
1138 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001139 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001140{
Nick Gordon5c467f02016-07-13 13:40:10 -05001141 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
dmcoomes9eaf3f42017-02-21 11:39:01 -06001142 _LOG_ERROR("Received Interest for a coordinate LSA when link-state routing is enabled");
Nick Gordon5c467f02016-07-13 13:40:10 -05001143 }
1144
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001145 // increment RCV_COORD_LSA_INTEREST
1146 lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_INTEREST);
dmcoomes9eaf3f42017-02-21 11:39:01 -06001147 _LOG_DEBUG("CoordinateLsa interest " << interest << " received");
akmhoque31d1d4b2014-05-05 22:08:14 -05001148 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -05001149 if (corLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001150 if (corLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001151 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -05001152 putLsaData(interest,content);
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001153 // increment SENT_COORD_LSA_DATA
1154 lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001155 }
dmcoomes9eaf3f42017-02-21 11:39:01 -06001156 else {
1157 _LOG_TRACE("SeqNo for CoordinateLsa does not match");
1158 }
1159 }
1160 else {
1161 _LOG_TRACE(interest << " was not found in this lsdb");
akmhoque31d1d4b2014-05-05 22:08:14 -05001162 }
1163}
1164
1165void
dmcoomes9f936662017-03-02 10:33:09 -06001166Lsdb::onContentValidated(const std::shared_ptr<const ndn::Data>& data)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -07001167{
1168 const ndn::Name& dataName = data->getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001169 _LOG_DEBUG("Data validation successful for LSA: " << dataName);
1170
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001171 std::string chkString("LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -05001172 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001173
akmhoque157b0a42014-05-13 00:26:37 -05001174 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001175
Nick G97e34942016-07-11 14:46:27 -05001176 // Extracts the prefix of the originating router from the data.
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001177 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001178 originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 3));
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001179
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001180 uint64_t seqNo = dataName[-1].toNumber();
Ashlesh Gawande820bb662017-08-03 16:12:07 -05001181 std::string dataContent(reinterpret_cast<const char*>(data->getContent().value()),
1182 data->getContent().value_size());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001183
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001184 std::string interestedLsType = dataName[-2].toUri();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001185
alvy49b1c0c2014-12-19 13:57:46 -06001186 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001187 processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -05001188 }
alvy49b1c0c2014-12-19 13:57:46 -06001189 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001190 processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -05001191 }
alvy49b1c0c2014-12-19 13:57:46 -06001192 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001193 processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -05001194 }
akmhoque157b0a42014-05-13 00:26:37 -05001195 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001196 _LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -05001197 }
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001198
1199 // increment RCV_LSA_DATA
1200 lsaIncrementSignal(Statistics::PacketType::RCV_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001201 }
1202}
1203
1204void
1205Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001206 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001207{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001208 // increment RCV_NAME_LSA_DATA
1209 lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_DATA);
akmhoque157b0a42014-05-13 00:26:37 -05001210 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001211 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001212 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001213 installNameLsa(nameLsa);
1214 }
akmhoque157b0a42014-05-13 00:26:37 -05001215 else {
akmhoque2f423352014-06-03 11:49:35 -05001216 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001217 }
1218 }
1219}
1220
1221void
1222Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001223 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001224{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001225 // increment RCV_ADJ_LSA_DATA
1226 lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_DATA);
akmhoque157b0a42014-05-13 00:26:37 -05001227 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001228 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001229 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001230 installAdjLsa(adjLsa);
1231 }
akmhoque157b0a42014-05-13 00:26:37 -05001232 else {
akmhoque2f423352014-06-03 11:49:35 -05001233 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001234 }
1235 }
1236}
1237
1238void
1239Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001240 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001241{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001242 // increment RCV_COORD_LSA_DATA
1243 lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_DATA);
akmhoque157b0a42014-05-13 00:26:37 -05001244 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001245 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001246 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001247 installCoordinateLsa(corLsa);
1248 }
akmhoque157b0a42014-05-13 00:26:37 -05001249 else {
akmhoque2f423352014-06-03 11:49:35 -05001250 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001251 }
1252 }
1253}
1254
akmhoquec7a79b22014-05-26 08:06:19 -05001255ndn::time::system_clock::TimePoint
1256Lsdb::getLsaExpirationTimePoint()
1257{
1258 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1259 expirationTimePoint = expirationTimePoint +
1260 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1261 return expirationTimePoint;
1262}
akmhoque31d1d4b2014-05-05 22:08:14 -05001263
1264void
akmhoque2f423352014-06-03 11:49:35 -05001265Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001266{
akmhoque2f423352014-06-03 11:49:35 -05001267 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001268 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001269 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001270 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001271 }
1272}
1273
1274//-----utility function -----
1275bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001276Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001277{
alvy49b1c0c2014-12-19 13:57:46 -06001278 if (lsType == NameLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001279 return doesNameLsaExist(key);
1280 }
alvy49b1c0c2014-12-19 13:57:46 -06001281 else if (lsType == AdjLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001282 return doesAdjLsaExist(key);
1283 }
alvy49b1c0c2014-12-19 13:57:46 -06001284 else if (lsType == CoordinateLsa::TYPE_STRING) {
akmhoqueb6450b12014-04-24 00:01:03 -05001285 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001286 }
1287 return false;
1288}
1289
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001290} // namespace nlsr