blob: 3fed78828d97fc98a376916dc18a9ebcb3f9c3a1 [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);
Nick Gordone98480b2017-05-24 11:23:03 -050062const ndn::time::steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE =
63 ndn::time::steady_clock::TimePoint::min();
Vince Lehman18841082014-08-19 17:15:24 -050064
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050065Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler)
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050066 : m_nlsr(nlsr)
67 , m_scheduler(scheduler)
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050068 , m_sync(m_nlsr.getNlsrFace(), *this, m_nlsr.getConfParameter())
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050069 , m_lsaRefreshTime(0)
70 , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050071 , m_sequencingManager()
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050072{
73}
74
75void
76Lsdb::onFetchLsaError(uint32_t errorCode,
77 const std::string& msg,
78 ndn::Name& interestName,
79 uint32_t retransmitNo,
80 const ndn::time::steady_clock::TimePoint& deadline,
81 ndn::Name lsaName,
82 uint64_t seqNo)
83{
84 _LOG_DEBUG("Failed to fetch LSA: " << lsaName << ", Error code: " << errorCode
85 << ", Message: " << msg);
86
87 if (ndn::time::steady_clock::now() < deadline) {
88 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
89
90 if (it != m_highestSeqNo.end() && it->second == seqNo) {
91 // If the SegmentFetcher failed due to an Interest timeout, it is safe to re-express
92 // immediately since at the least the LSA Interest lifetime has elapsed.
93 // Otherwise, it is necessary to delay the Interest re-expression to prevent
94 // the potential for constant Interest flooding.
95 ndn::time::seconds delay = m_nlsr.getConfParameter().getLsaInterestLifetime();
96
97 if (errorCode == ndn::util::SegmentFetcher::ErrorCode::INTEREST_TIMEOUT) {
98 delay = ndn::time::seconds(0);
99 }
100
101 m_scheduler.scheduleEvent(delay, std::bind(&Lsdb::expressInterest, this,
102 interestName, retransmitNo + 1, deadline));
103 }
104 }
105}
106
107void
108Lsdb::afterFetchLsa(const ndn::ConstBufferPtr& bufferPtr, ndn::Name& interestName)
109{
dmcoomes9f936662017-03-02 10:33:09 -0600110 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(ndn::Name(interestName));
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500111 data->setContent(bufferPtr);
112
113 _LOG_DEBUG("Received data for LSA(name): " << data->getName());
114
115 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
116 uint64_t seqNo = interestName[-1].toNumber();
117
118 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
119 m_highestSeqNo[lsaName] = seqNo;
120 }
121 else if (seqNo > m_highestSeqNo[lsaName]) {
122 m_highestSeqNo[lsaName] = seqNo;
dmcoomes9eaf3f42017-02-21 11:39:01 -0600123 _LOG_TRACE("SeqNo for LSA(name): " << data->getName() << " updated");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500124 }
125 else if (seqNo < m_highestSeqNo[lsaName]) {
126 return;
127 }
128
129 onContentValidated(data);
130}
akmhoque53353462014-04-22 08:43:45 -0500131
132void
akmhoque31d1d4b2014-05-05 22:08:14 -0500133Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
akmhoque53353462014-04-22 08:43:45 -0500134{
Vince Lehman7c603292014-09-11 17:48:16 -0500135 m_scheduler.cancelEvent(eid);
akmhoque53353462014-04-22 08:43:45 -0500136}
137
Nick G97e34942016-07-11 14:46:27 -0500138 /*! \brief Compares if a name LSA is the same as the one specified by key
139
140 \param nlsa1 A name LSA object
141 \param key A key of an originating router to compare to nlsa1
142 */
akmhoque53353462014-04-22 08:43:45 -0500143static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500144nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500145{
146 return nlsa1.getKey() == key;
147}
148
akmhoque53353462014-04-22 08:43:45 -0500149bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500150Lsdb::buildAndInstallOwnNameLsa()
akmhoque53353462014-04-22 08:43:45 -0500151{
akmhoque31d1d4b2014-05-05 22:08:14 -0500152 NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500153 m_sequencingManager.getNameLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500154 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500155 m_nlsr.getNamePrefixList());
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500156 m_sequencingManager.increaseNameLsaSeq();
157
158 m_sequencingManager.writeSeqNoToFile();
159 m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
160
akmhoque31d1d4b2014-05-05 22:08:14 -0500161 return installNameLsa(nameLsa);
akmhoque53353462014-04-22 08:43:45 -0500162}
163
akmhoqueb6450b12014-04-24 00:01:03 -0500164NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500165Lsdb::findNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500166{
167 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
168 m_nameLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600169 std::bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500170 if (it != m_nameLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500171 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500172 }
akmhoqueb6450b12014-04-24 00:01:03 -0500173 return 0;
akmhoque53353462014-04-22 08:43:45 -0500174}
175
176bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500177Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500178{
akmhoqueb6450b12014-04-24 00:01:03 -0500179 NameLsa* nameLsaCheck = findNameLsa(key);
Nick G97e34942016-07-11 14:46:27 -0500180 // Is the name in the LSDB
akmhoque157b0a42014-05-13 00:26:37 -0500181 if (nameLsaCheck != 0) {
Nick G97e34942016-07-11 14:46:27 -0500182 // And the supplied seq no is the highest so far
akmhoque157b0a42014-05-13 00:26:37 -0500183 if (nameLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500184 return true;
185 }
akmhoque157b0a42014-05-13 00:26:37 -0500186 else {
akmhoque53353462014-04-22 08:43:45 -0500187 return false;
188 }
189 }
190 return true;
191}
192
193ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500194Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
195 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500196{
Vince Lehman7c603292014-09-11 17:48:16 -0500197 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500198 std::bind(&Lsdb::expireOrRefreshNameLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500199}
200
201bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500202Lsdb::installNameLsa(NameLsa& nlsa)
akmhoque53353462014-04-22 08:43:45 -0500203{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700204 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500205 NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
Nick G97e34942016-07-11 14:46:27 -0500206 // Determines if the name LSA is new or not.
akmhoque157b0a42014-05-13 00:26:37 -0500207 if (chkNameLsa == 0) {
akmhoque53353462014-04-22 08:43:45 -0500208 addNameLsa(nlsa);
akmhoque2f423352014-06-03 11:49:35 -0500209 _LOG_DEBUG("New Name LSA");
210 _LOG_DEBUG("Adding Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500211 nlsa.writeLog();
akmhoque674b0b12014-05-20 14:33:28 -0500212
akmhoque157b0a42014-05-13 00:26:37 -0500213 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
Nick G97e34942016-07-11 14:46:27 -0500214 // If this name LSA is from another router, add the advertised
215 // prefixes to the NPT.
akmhoque31d1d4b2014-05-05 22:08:14 -0500216 m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
217 nlsa.getOrigRouter());
Nick Gordonf14ec352017-07-24 16:09:58 -0500218 std::list<ndn::Name> nameList = nlsa.getNpl().getNames();
akmhoque31d1d4b2014-05-05 22:08:14 -0500219 for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end();
akmhoque157b0a42014-05-13 00:26:37 -0500220 it++) {
221 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500222 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500223 }
224 }
225 }
akmhoque157b0a42014-05-13 00:26:37 -0500226 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500227 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
228 ndn::time::system_clock::now();
229 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500230 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500231 nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500232 nlsa.getLsSeqNo(),
233 timeToExpire));
234 }
Nick G97e34942016-07-11 14:46:27 -0500235 // Else this is a known name LSA, so we are updating it.
akmhoque157b0a42014-05-13 00:26:37 -0500236 else {
237 if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500238 _LOG_DEBUG("Updated Name LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500239 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500240 chkNameLsa->writeLog();
241 chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500242 chkNameLsa->setExpirationTimePoint(nlsa.getExpirationTimePoint());
akmhoqueb6450b12014-04-24 00:01:03 -0500243 chkNameLsa->getNpl().sort();
akmhoque53353462014-04-22 08:43:45 -0500244 nlsa.getNpl().sort();
Nick G97e34942016-07-11 14:46:27 -0500245 // Obtain the set difference of the current and the incoming
246 // name prefix sets, and add those.
Nick Gordonf14ec352017-07-24 16:09:58 -0500247 std::list<ndn::Name> newNames = nlsa.getNpl().getNames();
248 std::list<ndn::Name> oldNames = chkNameLsa->getNpl().getNames();
249 std::list<ndn::Name> namesToAdd;
250 std::set_difference(newNames.begin(), newNames.end(), oldNames.begin(), oldNames.end(),
251 std::inserter(namesToAdd, namesToAdd.begin()));
252 for (std::list<ndn::Name>::iterator it = namesToAdd.begin();
253 it != namesToAdd.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500254 chkNameLsa->addName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500255 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
256 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500257 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500258 }
259 }
260 }
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500261
262 chkNameLsa->getNpl().sort();
263
Nick G97e34942016-07-11 14:46:27 -0500264 // Also remove any names that are no longer being advertised.
Nick Gordonf14ec352017-07-24 16:09:58 -0500265 std::list<ndn::Name> namesToRemove;
266 std::set_difference(oldNames.begin(), oldNames.end(), newNames.begin(), newNames.end(),
267 std::inserter(namesToRemove, namesToRemove.begin()));
268 for (std::list<ndn::Name>::iterator it = namesToRemove.begin();
269 it != namesToRemove.end(); ++it) {
dmcoomes9eaf3f42017-02-21 11:39:01 -0600270 _LOG_DEBUG("Removing name LSA no longer advertised: " << (*it).toUri());
akmhoqueb6450b12014-04-24 00:01:03 -0500271 chkNameLsa->removeName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500272 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
273 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500274 m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500275 }
276 }
277 }
dmcoomes9eaf3f42017-02-21 11:39:01 -0600278
akmhoque157b0a42014-05-13 00:26:37 -0500279 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500280 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
281 ndn::time::system_clock::now();
282 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500283 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500284 cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
285 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500286 nlsa.getLsSeqNo(),
287 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500288 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500289 chkNameLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500290 }
291 }
292 return true;
293}
294
295bool
296Lsdb::addNameLsa(NameLsa& nlsa)
297{
298 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
299 m_nameLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600300 std::bind(nameLsaCompareByKey, _1,
akmhoque53353462014-04-22 08:43:45 -0500301 nlsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500302 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500303 m_nameLsdb.push_back(nlsa);
304 return true;
305 }
306 return false;
307}
308
309bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500310Lsdb::removeNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500311{
312 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
313 m_nameLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600314 std::bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500315 if (it != m_nameLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500316 _LOG_DEBUG("Deleting Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500317 (*it).writeLog();
Nick G97e34942016-07-11 14:46:27 -0500318 // If the requested name LSA is not ours, we also need to remove
319 // its entries from the NPT.
akmhoque31d1d4b2014-05-05 22:08:14 -0500320 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500321 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500322 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
323 (*it).getOrigRouter());
Nick Gordonf14ec352017-07-24 16:09:58 -0500324 for (const auto& name : it->getNpl().getNames()) {
325 if (name != m_nlsr.getConfParameter().getRouterPrefix()) {
326 m_nlsr.getNamePrefixTable().removeEntry(name, it->getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500327 }
328 }
329 }
330 m_nameLsdb.erase(it);
331 return true;
332 }
333 return false;
334}
335
336bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500337Lsdb::doesNameLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500338{
339 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
340 m_nameLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600341 std::bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500342 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500343 return false;
344 }
345 return true;
346}
347
348void
akmhoque2f423352014-06-03 11:49:35 -0500349Lsdb::writeNameLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500350{
akmhoque2f423352014-06-03 11:49:35 -0500351 _LOG_DEBUG("---------------Name LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -0500352 for (std::list<NameLsa>::iterator it = m_nameLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500353 it != m_nameLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500354 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500355 }
356}
357
Jiewen Tana0497d82015-02-02 21:59:18 -0800358const std::list<NameLsa>&
359Lsdb::getNameLsdb()
360{
361 return m_nameLsdb;
362}
363
akmhoque53353462014-04-22 08:43:45 -0500364// Cor LSA and LSDB related Functions start here
365
Nick G97e34942016-07-11 14:46:27 -0500366/*! \brief Compares whether an LSA object is the same as a key.
367 \param clsa The cor. LSA to check the identity of.
368 \param key The key of the publishing router to check against.
369*/
akmhoque53353462014-04-22 08:43:45 -0500370static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500371corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500372{
373 return clsa.getKey() == key;
374}
375
376bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500377Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500378{
akmhoque31d1d4b2014-05-05 22:08:14 -0500379 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500380 m_sequencingManager.getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500381 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500382 m_nlsr.getConfParameter().getCorR(),
383 m_nlsr.getConfParameter().getCorTheta());
Nick Gordon5c467f02016-07-13 13:40:10 -0500384
385 // Sync coordinate LSAs if using HR or HR dry run.
386 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500387 m_sequencingManager.increaseCorLsaSeq();
388 m_sequencingManager.writeSeqNoToFile();
389 m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
Nick Gordon5c467f02016-07-13 13:40:10 -0500390 }
391
akmhoque31d1d4b2014-05-05 22:08:14 -0500392 installCoordinateLsa(corLsa);
Nick Gordon5c467f02016-07-13 13:40:10 -0500393
akmhoque53353462014-04-22 08:43:45 -0500394 return true;
395}
396
akmhoqueb6450b12014-04-24 00:01:03 -0500397CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500398Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500399{
akmhoqueb6450b12014-04-24 00:01:03 -0500400 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
401 m_corLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600402 std::bind(corLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500403 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500404 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500405 }
akmhoqueb6450b12014-04-24 00:01:03 -0500406 return 0;
akmhoque53353462014-04-22 08:43:45 -0500407}
408
409bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500410Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500411{
akmhoqueb6450b12014-04-24 00:01:03 -0500412 CoordinateLsa* clsa = findCoordinateLsa(key);
Nick G97e34942016-07-11 14:46:27 -0500413 // Is the coordinate LSA in the LSDB already
akmhoque157b0a42014-05-13 00:26:37 -0500414 if (clsa != 0) {
Nick G97e34942016-07-11 14:46:27 -0500415 // And the seq no is newer (higher) than the current one
akmhoque157b0a42014-05-13 00:26:37 -0500416 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500417 return true;
418 }
akmhoque157b0a42014-05-13 00:26:37 -0500419 else {
akmhoque53353462014-04-22 08:43:45 -0500420 return false;
421 }
422 }
423 return true;
424}
425
Nick G97e34942016-07-11 14:46:27 -0500426 // Schedules a refresh/expire event in the scheduler.
427 // \param key The name of the router that published the LSA.
428 // \param seqNo the seq. no. associated with the LSA to check.
429 // \param expTime How long to wait before triggering the event.
akmhoque53353462014-04-22 08:43:45 -0500430ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500431Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500432 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500433{
Vince Lehman7c603292014-09-11 17:48:16 -0500434 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500435 std::bind(&Lsdb::expireOrRefreshCoordinateLsa,
Vince Lehman7c603292014-09-11 17:48:16 -0500436 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500437}
438
439bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500440Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500441{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700442 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500443 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
Nick G97e34942016-07-11 14:46:27 -0500444 // Checking whether the LSA is new or not.
akmhoque157b0a42014-05-13 00:26:37 -0500445 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500446 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500447 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500448 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500449 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500450
Nick Gordon5c467f02016-07-13 13:40:10 -0500451 // Register the LSA's origin router prefix
akmhoque157b0a42014-05-13 00:26:37 -0500452 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500453 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
454 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500455 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500456 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500457 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500458 }
Nick G97e34942016-07-11 14:46:27 -0500459 // Set the expiration time for the new LSA.
akmhoque157b0a42014-05-13 00:26:37 -0500460 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500461 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
462 ndn::time::system_clock::now();
463 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500464 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500465 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500466 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500467 }
Nick G97e34942016-07-11 14:46:27 -0500468 // We are just updating this LSA.
akmhoque157b0a42014-05-13 00:26:37 -0500469 else {
470 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500471 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500472 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500473 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500474 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500475 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
Nick G97e34942016-07-11 14:46:27 -0500476 // If the new LSA contains new routing information, update the LSDB with it.
akmhoque157b0a42014-05-13 00:26:37 -0500477 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500478 chkCorLsa->setCorRadius(clsa.getCorRadius());
479 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500480 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500481 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500482 }
483 }
Nick G97e34942016-07-11 14:46:27 -0500484 // If this is an LSA from another router, refresh its expiration time.
akmhoque157b0a42014-05-13 00:26:37 -0500485 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500486 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
487 ndn::time::system_clock::now();
488 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500489 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500490 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
491 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500492 clsa.getLsSeqNo(),
493 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500494 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500495 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500496 }
497 }
498 return true;
499}
500
501bool
akmhoqueb6450b12014-04-24 00:01:03 -0500502Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500503{
akmhoqueb6450b12014-04-24 00:01:03 -0500504 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
505 m_corLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600506 std::bind(corLsaCompareByKey, _1,
akmhoque157b0a42014-05-13 00:26:37 -0500507 clsa.getKey()));
508 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500509 m_corLsdb.push_back(clsa);
510 return true;
511 }
512 return false;
513}
514
515bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500516Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500517{
akmhoqueb6450b12014-04-24 00:01:03 -0500518 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
519 m_corLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600520 std::bind(corLsaCompareByKey,
akmhoque157b0a42014-05-13 00:26:37 -0500521 _1, key));
522 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500523 _LOG_DEBUG("Deleting Coordinate Lsa");
Nick Gordon5c467f02016-07-13 13:40:10 -0500524 it->writeLog();
525
526 if (it->getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
527 m_nlsr.getNamePrefixTable().removeEntry(it->getOrigRouter(), it->getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500528 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500529
akmhoque53353462014-04-22 08:43:45 -0500530 m_corLsdb.erase(it);
531 return true;
532 }
533 return false;
534}
535
536bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500537Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500538{
akmhoqueb6450b12014-04-24 00:01:03 -0500539 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
540 m_corLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600541 std::bind(corLsaCompareByKey,
akmhoque157b0a42014-05-13 00:26:37 -0500542 _1, key));
543 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500544 return false;
545 }
546 return true;
547}
548
549void
akmhoque2f423352014-06-03 11:49:35 -0500550Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500551{
akmhoque2f423352014-06-03 11:49:35 -0500552 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500553 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500554 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500555 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500556 }
557}
558
Jiewen Tana0497d82015-02-02 21:59:18 -0800559const std::list<CoordinateLsa>&
560Lsdb::getCoordinateLsdb()
561{
562 return m_corLsdb;
563}
564
akmhoque53353462014-04-22 08:43:45 -0500565// Adj LSA and LSDB related function starts here
566
Nick G97e34942016-07-11 14:46:27 -0500567 /*! \brief Returns whether an adj. LSA object is from some router.
568 \param alsa The adj. LSA object.
569 \param key The router name that you want to compare the LSA with.
570 */
akmhoque53353462014-04-22 08:43:45 -0500571static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500572adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500573{
574 return alsa.getKey() == key;
575}
576
akmhoque53353462014-04-22 08:43:45 -0500577void
Vince Lehman50df6b72015-03-03 12:06:40 -0600578Lsdb::scheduleAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500579{
Vince Lehman50df6b72015-03-03 12:06:40 -0600580 m_nlsr.incrementAdjBuildCount();
581
Nick Gordon5c467f02016-07-13 13:40:10 -0500582 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
583 // Don't build adjacency LSAs in hyperbolic routing
dmcoomes9eaf3f42017-02-21 11:39:01 -0600584 _LOG_DEBUG("Adjacency LSA not built. Currently in hyperbolic routing state.");
Nick Gordon5c467f02016-07-13 13:40:10 -0500585 return;
586 }
587
Vince Lehman50df6b72015-03-03 12:06:40 -0600588 if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
589 _LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
590
dmcoomes9f936662017-03-02 10:33:09 -0600591 m_scheduler.scheduleEvent(m_adjLsaBuildInterval, std::bind(&Lsdb::buildAdjLsa, this));
Vince Lehman50df6b72015-03-03 12:06:40 -0600592 m_nlsr.setIsBuildAdjLsaSheduled(true);
593 }
594}
595
596void
597Lsdb::buildAdjLsa()
598{
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500599 _LOG_TRACE("Lsdb::buildAdjLsa called");
Vince Lehman50df6b72015-03-03 12:06:40 -0600600
akmhoque674b0b12014-05-20 14:33:28 -0500601 m_nlsr.setIsBuildAdjLsaSheduled(false);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500602
603 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr.getConfParameter().getInterestRetryNumber())) {
604
akmhoque31d1d4b2014-05-05 22:08:14 -0500605 int adjBuildCount = m_nlsr.getAdjBuildCount();
Nick G97e34942016-07-11 14:46:27 -0500606 // Only do the adjLsa build if there's one scheduled
akmhoque157b0a42014-05-13 00:26:37 -0500607 if (adjBuildCount > 0) {
Nick G97e34942016-07-11 14:46:27 -0500608 // It only makes sense to do the adjLsa build if we have neighbors
akmhoque157b0a42014-05-13 00:26:37 -0500609 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500610 _LOG_DEBUG("Building and installing own Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500611 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500612 }
Nick G97e34942016-07-11 14:46:27 -0500613 // We have no active neighbors, meaning no one can route through
614 // us. So delete our entry in the LSDB. This prevents this
615 // router from refreshing the LSA, eventually causing other
616 // routers to delete it, too.
akmhoque157b0a42014-05-13 00:26:37 -0500617 else {
dmcoomes9f936662017-03-02 10:33:09 -0600618 _LOG_DEBUG("Removing own Adj LSA; no ACTIVE neighbors");
Nick G97e34942016-07-11 14:46:27 -0500619 // Get this router's key
akmhoque31d1d4b2014-05-05 22:08:14 -0500620 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
alvy49b1c0c2014-12-19 13:57:46 -0600621 key.append(AdjLsa::TYPE_STRING);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500622
akmhoque31d1d4b2014-05-05 22:08:14 -0500623 removeAdjLsa(key);
Nick G97e34942016-07-11 14:46:27 -0500624 // Recompute routing table after removal
akmhoque31d1d4b2014-05-05 22:08:14 -0500625 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500626 }
Nick G97e34942016-07-11 14:46:27 -0500627 // In the case that during building the adj LSA, the FIB has to
628 // wait on an Interest response, the number of scheduled adj LSA
629 // builds could change, so we shouldn't just set it to 0.
akmhoque31d1d4b2014-05-05 22:08:14 -0500630 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500631 }
632 }
Nick G97e34942016-07-11 14:46:27 -0500633 // We are still waiting to know the adjacency status of some
634 // neighbor, so schedule a build for later (when all that has
635 // hopefully finished)
636 else {
637 m_nlsr.setIsBuildAdjLsaSheduled(true);
638 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
639 m_nlsr.getConfParameter().getInterestResendTime();
640 m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
dmcoomes9f936662017-03-02 10:33:09 -0600641 std::bind(&Lsdb::buildAdjLsa, this));
Nick G97e34942016-07-11 14:46:27 -0500642 }
akmhoque53353462014-04-22 08:43:45 -0500643}
644
akmhoque53353462014-04-22 08:43:45 -0500645bool
646Lsdb::addAdjLsa(AdjLsa& alsa)
647{
648 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
649 m_adjLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600650 std::bind(adjLsaCompareByKey, _1,
akmhoque53353462014-04-22 08:43:45 -0500651 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500652 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500653 m_adjLsdb.push_back(alsa);
654 return true;
655 }
656 return false;
657}
658
akmhoqueb6450b12014-04-24 00:01:03 -0500659AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500660Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500661{
662 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
663 m_adjLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600664 std::bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500665 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500666 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500667 }
akmhoqueb6450b12014-04-24 00:01:03 -0500668 return 0;
akmhoque53353462014-04-22 08:43:45 -0500669}
670
akmhoque53353462014-04-22 08:43:45 -0500671bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500672Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500673{
akmhoqueb6450b12014-04-24 00:01:03 -0500674 AdjLsa* adjLsaCheck = findAdjLsa(key);
Nick G97e34942016-07-11 14:46:27 -0500675 // If it is in the LSDB
akmhoque157b0a42014-05-13 00:26:37 -0500676 if (adjLsaCheck != 0) {
Nick G97e34942016-07-11 14:46:27 -0500677 // And the supplied seq no is newer (higher) than the current one.
akmhoque157b0a42014-05-13 00:26:37 -0500678 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500679 return true;
680 }
akmhoque157b0a42014-05-13 00:26:37 -0500681 else {
akmhoque53353462014-04-22 08:43:45 -0500682 return false;
683 }
684 }
685 return true;
686}
687
akmhoque53353462014-04-22 08:43:45 -0500688ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500689Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
690 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500691{
Vince Lehman7c603292014-09-11 17:48:16 -0500692 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500693 std::bind(&Lsdb::expireOrRefreshAdjLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500694}
695
696bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500697Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500698{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700699 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500700 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
Nick G97e34942016-07-11 14:46:27 -0500701 // If this adj. LSA is not in the LSDB already
akmhoque157b0a42014-05-13 00:26:37 -0500702 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500703 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500704 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500705 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500706 addAdjLsa(alsa);
Nick G97e34942016-07-11 14:46:27 -0500707 // Add any new name prefixes to the NPT
akmhoque31d1d4b2014-05-05 22:08:14 -0500708 alsa.addNptEntries(m_nlsr);
709 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500710 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500711 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
712 ndn::time::system_clock::now();
713 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500714 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500715 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500716 alsa.getLsSeqNo(), timeToExpire);
717 }
akmhoque157b0a42014-05-13 00:26:37 -0500718 else {
719 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500720 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500721 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500722 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500723 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500724 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
Nick G97e34942016-07-11 14:46:27 -0500725 // If the new adj LSA has new content, update the contents of
726 // the LSDB entry. Additionally, since we've changed the
727 // contents of the LSDB, we have to schedule a routing
728 // calculation.
akmhoque157b0a42014-05-13 00:26:37 -0500729 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500730 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500731 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500732 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500733 }
akmhoque157b0a42014-05-13 00:26:37 -0500734 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500735 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
736 ndn::time::system_clock::now();
737 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500738 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500739 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
740 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500741 alsa.getLsSeqNo(),
742 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500743 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500744 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500745 }
746 }
747 return true;
748}
749
750bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500751Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500752{
akmhoque31d1d4b2014-05-05 22:08:14 -0500753 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500754 m_sequencingManager.getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500755 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500756 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
757 m_nlsr.getAdjacencyList());
Vince Lehman904c2412014-09-23 19:36:11 -0500758
Nick Gordon5c467f02016-07-13 13:40:10 -0500759 //Sync adjacency LSAs if link-state or dry-run HR is enabled.
760 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_ON) {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500761 m_sequencingManager.increaseAdjLsaSeq();
762 m_sequencingManager.writeSeqNoToFile();
763 m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
Nick Gordon5c467f02016-07-13 13:40:10 -0500764 }
Vince Lehman904c2412014-09-23 19:36:11 -0500765
Vince Lehman9d097802015-03-16 17:55:59 -0500766 return installAdjLsa(adjLsa);
akmhoque53353462014-04-22 08:43:45 -0500767}
768
769bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500770Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500771{
772 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
773 m_adjLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600774 std::bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500775 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500776 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500777 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500778 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500779 m_adjLsdb.erase(it);
780 return true;
781 }
782 return false;
783}
784
785bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500786Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500787{
788 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
789 m_adjLsdb.end(),
dmcoomes9f936662017-03-02 10:33:09 -0600790 std::bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500791 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500792 return false;
793 }
794 return true;
795}
796
Jiewen Tana0497d82015-02-02 21:59:18 -0800797const std::list<AdjLsa>&
akmhoque53353462014-04-22 08:43:45 -0500798Lsdb::getAdjLsdb()
799{
800 return m_adjLsdb;
801}
802
803void
Nick Gordone98480b2017-05-24 11:23:03 -0500804Lsdb::setLsaRefreshTime(const ndn::time::seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500805{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700806 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500807}
808
809void
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500810Lsdb::setThisRouterPrefix(std::string trp)
akmhoque53353462014-04-22 08:43:45 -0500811{
812 m_thisRouterPrefix = trp;
813}
814
Nick G97e34942016-07-11 14:46:27 -0500815 // This function determines whether a name LSA should be refreshed
816 // or expired. The conditions for getting refreshed are: it is still
817 // in the LSDB, it hasn't been updated by something else already (as
818 // evidenced by its seq. no.), and this is the originating router for
819 // the LSA. Is it let expire in all other cases.
820 // lsaKey is the key of the LSA's publishing router.
821 // seqNo is the seq. no. of the candidate LSA.
akmhoque53353462014-04-22 08:43:45 -0500822void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500823Lsdb::expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500824{
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500825 _LOG_DEBUG("Lsdb::expireOrRefreshNameLsa Called");
akmhoque674b0b12014-05-20 14:33:28 -0500826 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500827 NameLsa* chkNameLsa = findNameLsa(lsaKey);
Nick G97e34942016-07-11 14:46:27 -0500828 // If this name LSA exists in the LSDB
akmhoque157b0a42014-05-13 00:26:37 -0500829 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500830 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
Nick G97e34942016-07-11 14:46:27 -0500831 // If its seq no is the one we are expecting.
akmhoque157b0a42014-05-13 00:26:37 -0500832 if (chkNameLsa->getLsSeqNo() == seqNo) {
833 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500834 _LOG_DEBUG("Own Name LSA, so refreshing it");
835 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500836 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500837 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500838 m_sequencingManager.setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500839 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500840 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500841 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500842 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500843 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500844 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700845 m_lsaRefreshTime));
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500846 m_sequencingManager.writeSeqNoToFile();
847 m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
akmhoque53353462014-04-22 08:43:45 -0500848 }
Nick G97e34942016-07-11 14:46:27 -0500849 // Since we cannot refresh other router's LSAs, our only choice is to expire.
akmhoque157b0a42014-05-13 00:26:37 -0500850 else {
dmcoomes9eaf3f42017-02-21 11:39:01 -0600851 _LOG_DEBUG("Other's Name LSA, so removing from LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500852 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500853 }
854 }
855 }
856}
857
Nick G97e34942016-07-11 14:46:27 -0500858 // This function determines whether an adj. LSA should be refreshed
859 // or expired. The conditions for getting refreshed are: it is still
860 // in the LSDB, it hasn't been updated by something else already (as
861 // evidenced by its seq. no.), and this is the originating router for
862 // the LSA. Is it let expire in all other cases.
863 // lsaKey is the key of the LSA's publishing router.
864 // seqNo is the seq. no. of the candidate LSA.
akmhoque53353462014-04-22 08:43:45 -0500865void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500866Lsdb::expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500867{
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500868 _LOG_DEBUG("Lsdb::expireOrRefreshAdjLsa Called");
dmcoomes9eaf3f42017-02-21 11:39:01 -0600869 _LOG_DEBUG("LSA Key: " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500870 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
Nick G97e34942016-07-11 14:46:27 -0500871 // If this is a valid LSA
akmhoque157b0a42014-05-13 00:26:37 -0500872 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500873 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
Nick G97e34942016-07-11 14:46:27 -0500874 // And if it hasn't been updated for some other reason
akmhoque157b0a42014-05-13 00:26:37 -0500875 if (chkAdjLsa->getLsSeqNo() == seqNo) {
Nick G97e34942016-07-11 14:46:27 -0500876 // If it is our own LSA
akmhoque157b0a42014-05-13 00:26:37 -0500877 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500878 _LOG_DEBUG("Own Adj LSA, so refreshing it");
879 _LOG_DEBUG("Deleting Adj Lsa");
880 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500881 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500882 m_sequencingManager.setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500883 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500884 _LOG_DEBUG("Adding Adj Lsa");
885 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500886 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500887 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500888 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700889 m_lsaRefreshTime));
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500890 m_sequencingManager.writeSeqNoToFile();
891 m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
akmhoque53353462014-04-22 08:43:45 -0500892 }
Nick G97e34942016-07-11 14:46:27 -0500893 // An LSA from another router is expiring
akmhoque157b0a42014-05-13 00:26:37 -0500894 else {
dmcoomes9eaf3f42017-02-21 11:39:01 -0600895 _LOG_DEBUG("Other's Adj LSA, so removing from LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500896 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500897 }
Nick G97e34942016-07-11 14:46:27 -0500898 // We have changed the contents of the LSDB, so we have to
899 // schedule a routing calculation
akmhoque31d1d4b2014-05-05 22:08:14 -0500900 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500901 }
902 }
903}
904
Nick G97e34942016-07-11 14:46:27 -0500905 // This function determines whether an adj. LSA should be refreshed
906 // or expired. The conditions for getting refreshed are: it is still
907 // in the LSDB, it hasn't been updated by something else already (as
908 // evidenced by its seq. no.), and this is the originating router for
909 // the LSA. It is let expire in all other cases.
910 // lsaKey is the key of the LSA's publishing router.
911 // seqNo is the seq. no. of the candidate LSA.
akmhoque53353462014-04-22 08:43:45 -0500912void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500913Lsdb::expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500914 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500915{
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500916 _LOG_DEBUG("Lsdb::expireOrRefreshCorLsa Called ");
akmhoque674b0b12014-05-20 14:33:28 -0500917 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500918 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
Nick G97e34942016-07-11 14:46:27 -0500919 // Whether the LSA is in the LSDB or not.
akmhoque157b0a42014-05-13 00:26:37 -0500920 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500921 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
Nick G97e34942016-07-11 14:46:27 -0500922 // Whether the LSA has been updated without our knowledge.
akmhoque157b0a42014-05-13 00:26:37 -0500923 if (chkCorLsa->getLsSeqNo() == seqNo) {
924 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500925 _LOG_DEBUG("Own Cor LSA, so refreshing it");
926 _LOG_DEBUG("Deleting Coordinate Lsa");
927 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500928 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
Nick Gordon5c467f02016-07-13 13:40:10 -0500929 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500930 m_sequencingManager.setCorLsaSeq(chkCorLsa->getLsSeqNo());
Nick Gordon5c467f02016-07-13 13:40:10 -0500931 }
932
akmhoquec7a79b22014-05-26 08:06:19 -0500933 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500934 _LOG_DEBUG("Adding Coordinate Lsa");
935 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500936 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500937 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
938 chkCorLsa->getKey(),
939 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700940 m_lsaRefreshTime));
Nick Gordon5c467f02016-07-13 13:40:10 -0500941 // Only sync coordinate LSAs if link-state routing is disabled
942 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500943 m_sequencingManager.writeSeqNoToFile();
944 m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
Nick Gordon5c467f02016-07-13 13:40:10 -0500945 }
akmhoque53353462014-04-22 08:43:45 -0500946 }
Nick G97e34942016-07-11 14:46:27 -0500947 // We can't refresh other router's LSAs, so we remove it.
akmhoque157b0a42014-05-13 00:26:37 -0500948 else {
dmcoomes9eaf3f42017-02-21 11:39:01 -0600949 _LOG_DEBUG("Other's Cor LSA, so removing from LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500950 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500951 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500952 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500953 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500954 }
955 }
956 }
957}
958
akmhoque53353462014-04-22 08:43:45 -0500959void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700960Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Nick Gordone98480b2017-05-24 11:23:03 -0500961 ndn::time::steady_clock::TimePoint deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500962{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600963 // increment SENT_LSA_INTEREST
964 lsaIncrementSignal(Statistics::PacketType::SENT_LSA_INTEREST);
965
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500966 if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) {
Nick Gordone98480b2017-05-24 11:23:03 -0500967 deadline = ndn::time::steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700968 }
Nick G97e34942016-07-11 14:46:27 -0500969 // The first component of the interest is the name.
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500970 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
Nick G97e34942016-07-11 14:46:27 -0500971 // The seq no is the last
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500972 uint64_t seqNo = interestName[-1].toNumber();
973
Nick G97e34942016-07-11 14:46:27 -0500974 // If the LSA is not found in the list currently.
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500975 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
976 m_highestSeqNo[lsaName] = seqNo;
977 }
Nick G97e34942016-07-11 14:46:27 -0500978 // If the new seq no is higher, that means the LSA is valid
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500979 else if (seqNo > m_highestSeqNo[lsaName]) {
980 m_highestSeqNo[lsaName] = seqNo;
981 }
Nick G97e34942016-07-11 14:46:27 -0500982 // Otherwise, its an old/invalid LSA
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500983 else if (seqNo < m_highestSeqNo[lsaName]) {
984 return;
985 }
986
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500987 ndn::Interest interest(interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700988 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500989
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500990 _LOG_DEBUG("Fetching Data for LSA: " << interestName << " Seq number: " << seqNo);
991 ndn::util::SegmentFetcher::fetch(m_nlsr.getNlsrFace(), interest,
992 m_nlsr.getValidator(),
dmcoomes9f936662017-03-02 10:33:09 -0600993 std::bind(&Lsdb::afterFetchLsa, this, _1, interestName),
994 std::bind(&Lsdb::onFetchLsaError, this, _1, _2, interestName,
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500995 timeoutCount, deadline, lsaName, seqNo));
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600996 // increment a specific SENT_LSA_INTEREST
997 std::string typeLSA = interestName[-2].toUri();
998 if (typeLSA == AdjLsa::TYPE_STRING) {
999 lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_INTEREST);
1000 }
1001 else if (typeLSA == CoordinateLsa::TYPE_STRING) {
1002 lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_INTEREST);
1003 }
1004 else if (typeLSA == NameLsa::TYPE_STRING) {
1005 lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_INTEREST);
1006 }
1007 else {
1008 _LOG_ERROR("typeLSA " + typeLSA + " not recognized; failed Statistics::PacketType conversion");
1009 }
akmhoque31d1d4b2014-05-05 22:08:14 -05001010}
1011
1012void
1013Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
1014{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001015 // increment RCV_LSA_INTEREST
1016 lsaIncrementSignal(Statistics::PacketType::RCV_LSA_INTEREST);
1017
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001018 const ndn::Name& interestName(interest.getName());
1019 _LOG_DEBUG("Interest received for LSA: " << interestName);
1020
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001021 std::string chkString("LSA");
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001022 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
1023
akmhoque157b0a42014-05-13 00:26:37 -05001024 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001025
Nick G97e34942016-07-11 14:46:27 -05001026 // Forms the name of the router that the Interest packet came from.
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001027 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
1028 originRouter.append(interestName.getSubName(lsaPosition + 1,
1029 interest.getName().size() - lsaPosition - 3));
1030
1031 uint64_t seqNo = interestName[-1].toNumber();
1032 _LOG_DEBUG("LSA sequence number from interest: " << seqNo);
1033
1034 std::string interestedLsType = interestName[-2].toUri();
1035
alvy49b1c0c2014-12-19 13:57:46 -06001036 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001037 processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -05001038 }
alvy49b1c0c2014-12-19 13:57:46 -06001039 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001040 processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -05001041 }
alvy49b1c0c2014-12-19 13:57:46 -06001042 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001043 processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -05001044 }
akmhoque157b0a42014-05-13 00:26:37 -05001045 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001046 _LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -05001047 }
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001048 lsaIncrementSignal(Statistics::PacketType::SENT_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001049 }
1050}
1051
Nick G97e34942016-07-11 14:46:27 -05001052 // \brief Sends LSA data.
1053 // \param interest The Interest that warranted the data.
1054 // \param content The data that the Interest was seeking.
akmhoque31d1d4b2014-05-05 22:08:14 -05001055void
akmhoque69c9aa92014-07-23 15:15:05 -05001056Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
1057{
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001058 LsaContentPublisher publisher(m_nlsr.getNlsrFace(),
1059 m_nlsr.getKeyChain(),
1060 m_lsaRefreshTime,
1061 content);
dmcoomes9eaf3f42017-02-21 11:39:01 -06001062 _LOG_DEBUG("Sending requested data ( " << content << ") for interest (" << interest
1063 << ") to be published and added to face.");
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001064 publisher.publish(interest.getName(),
1065 ndn::security::signingByCertificate(m_nlsr.getDefaultCertName()));
akmhoque69c9aa92014-07-23 15:15:05 -05001066}
1067
Nick G97e34942016-07-11 14:46:27 -05001068 // \brief Finds and sends a requested name LSA.
1069 // \param interest The interest that seeks the name LSA.
1070 // \param lsaKey The LSA that the Interest is seeking.
1071 // \param seqNo A sequence number to ensure that we are sending the
1072 // version that was requested.
akmhoque69c9aa92014-07-23 15:15:05 -05001073void
akmhoque31d1d4b2014-05-05 22:08:14 -05001074Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
1075 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001076 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001077{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001078 // increment RCV_NAME_LSA_INTEREST
1079 lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_INTEREST);
dmcoomes9eaf3f42017-02-21 11:39:01 -06001080 _LOG_DEBUG("nameLsa interest " << interest << " received");
akmhoque31d1d4b2014-05-05 22:08:14 -05001081 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -05001082 if (nameLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001083 if (nameLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001084 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -05001085 putLsaData(interest,content);
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001086 // increment SENT_NAME_LSA_DATA
1087 lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001088 }
dmcoomes9eaf3f42017-02-21 11:39:01 -06001089 else {
1090 _LOG_TRACE("SeqNo for nameLsa does not match");
1091 }
1092 }
1093 else {
1094 _LOG_TRACE(interest << " was not found in this lsdb");
akmhoque31d1d4b2014-05-05 22:08:14 -05001095 }
1096}
1097
Nick G97e34942016-07-11 14:46:27 -05001098 // \brief Finds and sends a requested adj. LSA.
1099 // \param interest The interest that seeks the adj. LSA.
1100 // \param lsaKey The LSA that the Interest is seeking.
1101 // \param seqNo A sequence number to ensure that we are sending the
1102 // version that was requested.
akmhoque31d1d4b2014-05-05 22:08:14 -05001103void
1104Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
1105 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001106 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001107{
Nick Gordon5c467f02016-07-13 13:40:10 -05001108 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
dmcoomes9eaf3f42017-02-21 11:39:01 -06001109 _LOG_ERROR("Received interest for an adjacency LSA when hyperbolic routing is enabled");
Nick Gordon5c467f02016-07-13 13:40:10 -05001110 }
1111
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001112 // increment RCV_ADJ_LSA_INTEREST
1113 lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_INTEREST);
dmcoomes9eaf3f42017-02-21 11:39:01 -06001114 _LOG_DEBUG("AdjLsa interest " << interest << " received");
akmhoque31d1d4b2014-05-05 22:08:14 -05001115 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -05001116 if (adjLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001117 if (adjLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001118 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -05001119 putLsaData(interest,content);
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001120 // increment SENT_ADJ_LSA_DATA
1121 lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001122 }
dmcoomes9eaf3f42017-02-21 11:39:01 -06001123 else {
1124 _LOG_TRACE("SeqNo for AdjLsa does not match");
1125 }
1126 }
1127 else {
1128 _LOG_TRACE(interest << " was not found in this lsdb");
akmhoque31d1d4b2014-05-05 22:08:14 -05001129 }
1130}
1131
Nick G97e34942016-07-11 14:46:27 -05001132 // \brief Finds and sends a requested cor. LSA.
1133 // \param interest The interest that seeks the cor. LSA.
1134 // \param lsaKey The LSA that the Interest is seeking.
1135 // \param seqNo A sequence number to ensure that we are sending the
1136 // version that was requested.
akmhoque31d1d4b2014-05-05 22:08:14 -05001137void
1138Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
1139 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001140 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001141{
Nick Gordon5c467f02016-07-13 13:40:10 -05001142 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
dmcoomes9eaf3f42017-02-21 11:39:01 -06001143 _LOG_ERROR("Received Interest for a coordinate LSA when link-state routing is enabled");
Nick Gordon5c467f02016-07-13 13:40:10 -05001144 }
1145
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001146 // increment RCV_COORD_LSA_INTEREST
1147 lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_INTEREST);
dmcoomes9eaf3f42017-02-21 11:39:01 -06001148 _LOG_DEBUG("CoordinateLsa interest " << interest << " received");
akmhoque31d1d4b2014-05-05 22:08:14 -05001149 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -05001150 if (corLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001151 if (corLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001152 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -05001153 putLsaData(interest,content);
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001154 // increment SENT_COORD_LSA_DATA
1155 lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001156 }
dmcoomes9eaf3f42017-02-21 11:39:01 -06001157 else {
1158 _LOG_TRACE("SeqNo for CoordinateLsa does not match");
1159 }
1160 }
1161 else {
1162 _LOG_TRACE(interest << " was not found in this lsdb");
akmhoque31d1d4b2014-05-05 22:08:14 -05001163 }
1164}
1165
1166void
dmcoomes9f936662017-03-02 10:33:09 -06001167Lsdb::onContentValidated(const std::shared_ptr<const ndn::Data>& data)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -07001168{
1169 const ndn::Name& dataName = data->getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001170 _LOG_DEBUG("Data validation successful for LSA: " << dataName);
1171
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001172 std::string chkString("LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -05001173 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001174
akmhoque157b0a42014-05-13 00:26:37 -05001175 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001176
Nick G97e34942016-07-11 14:46:27 -05001177 // Extracts the prefix of the originating router from the data.
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001178 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001179 originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 3));
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001180
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001181 uint64_t seqNo = dataName[-1].toNumber();
Ashlesh Gawande820bb662017-08-03 16:12:07 -05001182 std::string dataContent(reinterpret_cast<const char*>(data->getContent().value()),
1183 data->getContent().value_size());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001184
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001185 std::string interestedLsType = dataName[-2].toUri();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001186
alvy49b1c0c2014-12-19 13:57:46 -06001187 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001188 processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -05001189 }
alvy49b1c0c2014-12-19 13:57:46 -06001190 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001191 processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -05001192 }
alvy49b1c0c2014-12-19 13:57:46 -06001193 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001194 processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -05001195 }
akmhoque157b0a42014-05-13 00:26:37 -05001196 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001197 _LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -05001198 }
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001199
1200 // increment RCV_LSA_DATA
1201 lsaIncrementSignal(Statistics::PacketType::RCV_LSA_DATA);
akmhoque31d1d4b2014-05-05 22:08:14 -05001202 }
1203}
1204
1205void
1206Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001207 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001208{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001209 // increment RCV_NAME_LSA_DATA
1210 lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_DATA);
akmhoque157b0a42014-05-13 00:26:37 -05001211 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001212 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001213 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001214 installNameLsa(nameLsa);
1215 }
akmhoque157b0a42014-05-13 00:26:37 -05001216 else {
akmhoque2f423352014-06-03 11:49:35 -05001217 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001218 }
1219 }
1220}
1221
1222void
1223Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001224 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001225{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001226 // increment RCV_ADJ_LSA_DATA
1227 lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_DATA);
akmhoque157b0a42014-05-13 00:26:37 -05001228 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001229 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001230 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001231 installAdjLsa(adjLsa);
1232 }
akmhoque157b0a42014-05-13 00:26:37 -05001233 else {
akmhoque2f423352014-06-03 11:49:35 -05001234 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001235 }
1236 }
1237}
1238
1239void
1240Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001241 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001242{
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001243 // increment RCV_COORD_LSA_DATA
1244 lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_DATA);
akmhoque157b0a42014-05-13 00:26:37 -05001245 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001246 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001247 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001248 installCoordinateLsa(corLsa);
1249 }
akmhoque157b0a42014-05-13 00:26:37 -05001250 else {
akmhoque2f423352014-06-03 11:49:35 -05001251 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001252 }
1253 }
1254}
1255
akmhoquec7a79b22014-05-26 08:06:19 -05001256ndn::time::system_clock::TimePoint
1257Lsdb::getLsaExpirationTimePoint()
1258{
1259 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1260 expirationTimePoint = expirationTimePoint +
1261 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1262 return expirationTimePoint;
1263}
akmhoque31d1d4b2014-05-05 22:08:14 -05001264
1265void
akmhoque2f423352014-06-03 11:49:35 -05001266Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001267{
akmhoque2f423352014-06-03 11:49:35 -05001268 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001269 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001270 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001271 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001272 }
1273}
1274
1275//-----utility function -----
1276bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001277Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001278{
alvy49b1c0c2014-12-19 13:57:46 -06001279 if (lsType == NameLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001280 return doesNameLsaExist(key);
1281 }
alvy49b1c0c2014-12-19 13:57:46 -06001282 else if (lsType == AdjLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001283 return doesAdjLsaExist(key);
1284 }
alvy49b1c0c2014-12-19 13:57:46 -06001285 else if (lsType == CoordinateLsa::TYPE_STRING) {
akmhoqueb6450b12014-04-24 00:01:03 -05001286 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001287 }
1288 return false;
1289}
1290
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001291} // namespace nlsr