blob: 5b1fda683c9af0b499303daabbaae258eaf96ee2 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05003 * Copyright (c) 2014-2016, 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
32#include <string>
akmhoque53353462014-04-22 08:43:45 -050033
34namespace nlsr {
35
akmhoque674b0b12014-05-20 14:33:28 -050036INIT_LOGGER("Lsdb");
37
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050038class LsaContentPublisher : public SegmentPublisher<ndn::Face>
39{
40public:
41 LsaContentPublisher(ndn::Face& face,
42 ndn::KeyChain& keyChain,
43 const ndn::time::milliseconds& freshnessPeriod,
44 const std::string& content)
45 : SegmentPublisher(face, keyChain, freshnessPeriod)
46 , m_content(content)
47 {
48 }
49
50 virtual size_t
51 generate(ndn::EncodingBuffer& outBuffer) {
52 size_t totalLength = 0;
53 totalLength += outBuffer.prependByteArray(reinterpret_cast<const uint8_t*>(m_content.c_str()),
54 m_content.size());
55 return totalLength;
56 }
57
58private:
59 const std::string m_content;
60};
61
Jiewen Tana0497d82015-02-02 21:59:18 -080062const ndn::Name::Component Lsdb::NAME_COMPONENT = ndn::Name::Component("lsdb");
Vince Lehman18841082014-08-19 17:15:24 -050063const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -050064const steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = steady_clock::TimePoint::min();
Vince Lehman18841082014-08-19 17:15:24 -050065
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -050066Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler, SyncLogicHandler& sync)
67 : m_nlsr(nlsr)
68 , m_scheduler(scheduler)
69 , m_sync(sync)
70 , m_lsaRefreshTime(0)
71 , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
72{
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{
110 shared_ptr<ndn::Data> data = make_shared<ndn::Data>(ndn::Name(interestName));
111 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;
123 }
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
137static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500138nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500139{
140 return nlsa1.getKey() == key;
141}
142
akmhoque53353462014-04-22 08:43:45 -0500143bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500144Lsdb::buildAndInstallOwnNameLsa()
akmhoque53353462014-04-22 08:43:45 -0500145{
akmhoque31d1d4b2014-05-05 22:08:14 -0500146 NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500147 m_nlsr.getSequencingManager().getNameLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500148 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500149 m_nlsr.getNamePrefixList());
150 m_nlsr.getSequencingManager().increaseNameLsaSeq();
151 return installNameLsa(nameLsa);
akmhoque53353462014-04-22 08:43:45 -0500152}
153
akmhoqueb6450b12014-04-24 00:01:03 -0500154NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500155Lsdb::findNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500156{
157 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
158 m_nameLsdb.end(),
159 bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500160 if (it != m_nameLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500161 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500162 }
akmhoqueb6450b12014-04-24 00:01:03 -0500163 return 0;
akmhoque53353462014-04-22 08:43:45 -0500164}
165
166bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500167Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500168{
akmhoqueb6450b12014-04-24 00:01:03 -0500169 NameLsa* nameLsaCheck = findNameLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500170 if (nameLsaCheck != 0) {
171 if (nameLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500172 return true;
173 }
akmhoque157b0a42014-05-13 00:26:37 -0500174 else {
akmhoque53353462014-04-22 08:43:45 -0500175 return false;
176 }
177 }
178 return true;
179}
180
181ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500182Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
183 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500184{
Vince Lehman7c603292014-09-11 17:48:16 -0500185 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
186 ndn::bind(&Lsdb::exprireOrRefreshNameLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500187}
188
189bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500190Lsdb::installNameLsa(NameLsa& nlsa)
akmhoque53353462014-04-22 08:43:45 -0500191{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700192 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500193 NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500194 if (chkNameLsa == 0) {
akmhoque53353462014-04-22 08:43:45 -0500195 addNameLsa(nlsa);
akmhoque2f423352014-06-03 11:49:35 -0500196 _LOG_DEBUG("New Name LSA");
197 _LOG_DEBUG("Adding Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500198 nlsa.writeLog();
akmhoque674b0b12014-05-20 14:33:28 -0500199
akmhoque157b0a42014-05-13 00:26:37 -0500200 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500201 m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
202 nlsa.getOrigRouter());
203 std::list<ndn::Name> nameList = nlsa.getNpl().getNameList();
204 for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end();
akmhoque157b0a42014-05-13 00:26:37 -0500205 it++) {
206 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500207 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500208 }
209 }
210 }
akmhoque157b0a42014-05-13 00:26:37 -0500211 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500212 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
213 ndn::time::system_clock::now();
214 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500215 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500216 nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500217 nlsa.getLsSeqNo(),
218 timeToExpire));
219 }
akmhoque157b0a42014-05-13 00:26:37 -0500220 else {
221 if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500222 _LOG_DEBUG("Updated Name LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500223 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500224 chkNameLsa->writeLog();
225 chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500226 chkNameLsa->setExpirationTimePoint(nlsa.getExpirationTimePoint());
akmhoqueb6450b12014-04-24 00:01:03 -0500227 chkNameLsa->getNpl().sort();
akmhoque53353462014-04-22 08:43:45 -0500228 nlsa.getNpl().sort();
akmhoque31d1d4b2014-05-05 22:08:14 -0500229 std::list<ndn::Name> nameToAdd;
akmhoque53353462014-04-22 08:43:45 -0500230 std::set_difference(nlsa.getNpl().getNameList().begin(),
231 nlsa.getNpl().getNameList().end(),
akmhoqueb6450b12014-04-24 00:01:03 -0500232 chkNameLsa->getNpl().getNameList().begin(),
233 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500234 std::inserter(nameToAdd, nameToAdd.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500235 for (std::list<ndn::Name>::iterator it = nameToAdd.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500236 it != nameToAdd.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500237 chkNameLsa->addName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500238 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
239 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500240 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500241 }
242 }
243 }
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500244
245 chkNameLsa->getNpl().sort();
246
akmhoque31d1d4b2014-05-05 22:08:14 -0500247 std::list<ndn::Name> nameToRemove;
akmhoqueb6450b12014-04-24 00:01:03 -0500248 std::set_difference(chkNameLsa->getNpl().getNameList().begin(),
249 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500250 nlsa.getNpl().getNameList().begin(),
251 nlsa.getNpl().getNameList().end(),
252 std::inserter(nameToRemove, nameToRemove.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500253 for (std::list<ndn::Name>::iterator it = nameToRemove.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500254 it != nameToRemove.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500255 chkNameLsa->removeName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500256 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
257 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500258 m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500259 }
260 }
261 }
akmhoque157b0a42014-05-13 00:26:37 -0500262 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500263 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
264 ndn::time::system_clock::now();
265 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500266 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500267 cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
268 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500269 nlsa.getLsSeqNo(),
270 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500271 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500272 chkNameLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500273 }
274 }
275 return true;
276}
277
278bool
279Lsdb::addNameLsa(NameLsa& nlsa)
280{
281 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
282 m_nameLsdb.end(),
283 bind(nameLsaCompareByKey, _1,
284 nlsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500285 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500286 m_nameLsdb.push_back(nlsa);
287 return true;
288 }
289 return false;
290}
291
292bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500293Lsdb::removeNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500294{
295 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
296 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500297 ndn::bind(nameLsaCompareByKey, _1, key));
298 if (it != m_nameLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500299 _LOG_DEBUG("Deleting Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500300 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500301 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500302 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500303 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
304 (*it).getOrigRouter());
305 for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500306 nit != (*it).getNpl().getNameList().end(); ++nit) {
307 if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500308 m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500309 }
310 }
311 }
312 m_nameLsdb.erase(it);
313 return true;
314 }
315 return false;
316}
317
318bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500319Lsdb::doesNameLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500320{
321 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
322 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500323 ndn::bind(nameLsaCompareByKey, _1, key));
324 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500325 return false;
326 }
327 return true;
328}
329
330void
akmhoque2f423352014-06-03 11:49:35 -0500331Lsdb::writeNameLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500332{
akmhoque2f423352014-06-03 11:49:35 -0500333 _LOG_DEBUG("---------------Name LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -0500334 for (std::list<NameLsa>::iterator it = m_nameLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500335 it != m_nameLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500336 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500337 }
338}
339
Jiewen Tana0497d82015-02-02 21:59:18 -0800340const std::list<NameLsa>&
341Lsdb::getNameLsdb()
342{
343 return m_nameLsdb;
344}
345
akmhoque53353462014-04-22 08:43:45 -0500346// Cor LSA and LSDB related Functions start here
347
akmhoque53353462014-04-22 08:43:45 -0500348static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500349corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500350{
351 return clsa.getKey() == key;
352}
353
354bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500355Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500356{
akmhoque31d1d4b2014-05-05 22:08:14 -0500357 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500358 m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500359 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500360 m_nlsr.getConfParameter().getCorR(),
361 m_nlsr.getConfParameter().getCorTheta());
Nick Gordon5c467f02016-07-13 13:40:10 -0500362
363 // Sync coordinate LSAs if using HR or HR dry run.
364 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
365 m_nlsr.getSequencingManager().increaseCorLsaSeq();
366 m_sync.publishRoutingUpdate();
367 }
368
akmhoque31d1d4b2014-05-05 22:08:14 -0500369 installCoordinateLsa(corLsa);
Nick Gordon5c467f02016-07-13 13:40:10 -0500370
akmhoque53353462014-04-22 08:43:45 -0500371 return true;
372}
373
akmhoqueb6450b12014-04-24 00:01:03 -0500374CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500375Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500376{
akmhoqueb6450b12014-04-24 00:01:03 -0500377 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
378 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500379 ndn::bind(corLsaCompareByKey, _1, key));
380 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500381 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500382 }
akmhoqueb6450b12014-04-24 00:01:03 -0500383 return 0;
akmhoque53353462014-04-22 08:43:45 -0500384}
385
386bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500387Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500388{
akmhoqueb6450b12014-04-24 00:01:03 -0500389 CoordinateLsa* clsa = findCoordinateLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500390 if (clsa != 0) {
391 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500392 return true;
393 }
akmhoque157b0a42014-05-13 00:26:37 -0500394 else {
akmhoque53353462014-04-22 08:43:45 -0500395 return false;
396 }
397 }
398 return true;
399}
400
401ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500402Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500403 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500404{
Vince Lehman7c603292014-09-11 17:48:16 -0500405 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
406 ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
407 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500408}
409
410bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500411Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500412{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700413 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500414 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500415 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500416 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500417 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500418 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500419 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500420
Nick Gordon5c467f02016-07-13 13:40:10 -0500421 // Register the LSA's origin router prefix
akmhoque157b0a42014-05-13 00:26:37 -0500422 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500423 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
424 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500425 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500426 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500427 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500428 }
akmhoque157b0a42014-05-13 00:26:37 -0500429 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500430 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
431 ndn::time::system_clock::now();
432 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500433 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500434 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500435 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500436 }
akmhoque157b0a42014-05-13 00:26:37 -0500437 else {
438 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500439 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500440 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500441 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500442 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500443 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500444 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500445 chkCorLsa->setCorRadius(clsa.getCorRadius());
446 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500447 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500448 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500449 }
450 }
akmhoque157b0a42014-05-13 00:26:37 -0500451 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500452 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
453 ndn::time::system_clock::now();
454 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500455 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500456 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
457 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500458 clsa.getLsSeqNo(),
459 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500460 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500461 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500462 }
463 }
464 return true;
465}
466
467bool
akmhoqueb6450b12014-04-24 00:01:03 -0500468Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500469{
akmhoqueb6450b12014-04-24 00:01:03 -0500470 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
471 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500472 ndn::bind(corLsaCompareByKey, _1,
473 clsa.getKey()));
474 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500475 m_corLsdb.push_back(clsa);
476 return true;
477 }
478 return false;
479}
480
481bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500482Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500483{
akmhoqueb6450b12014-04-24 00:01:03 -0500484 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
485 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500486 ndn::bind(corLsaCompareByKey,
487 _1, key));
488 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500489 _LOG_DEBUG("Deleting Coordinate Lsa");
Nick Gordon5c467f02016-07-13 13:40:10 -0500490 it->writeLog();
491
492 if (it->getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
493 m_nlsr.getNamePrefixTable().removeEntry(it->getOrigRouter(), it->getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500494 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500495
akmhoque53353462014-04-22 08:43:45 -0500496 m_corLsdb.erase(it);
497 return true;
498 }
499 return false;
500}
501
502bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500503Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500504{
akmhoqueb6450b12014-04-24 00:01:03 -0500505 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
506 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500507 ndn::bind(corLsaCompareByKey,
508 _1, key));
509 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500510 return false;
511 }
512 return true;
513}
514
515void
akmhoque2f423352014-06-03 11:49:35 -0500516Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500517{
akmhoque2f423352014-06-03 11:49:35 -0500518 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500519 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500520 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500521 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500522 }
523}
524
Jiewen Tana0497d82015-02-02 21:59:18 -0800525const std::list<CoordinateLsa>&
526Lsdb::getCoordinateLsdb()
527{
528 return m_corLsdb;
529}
530
akmhoque53353462014-04-22 08:43:45 -0500531// Adj LSA and LSDB related function starts here
532
533static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500534adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500535{
536 return alsa.getKey() == key;
537}
538
akmhoque53353462014-04-22 08:43:45 -0500539void
Vince Lehman50df6b72015-03-03 12:06:40 -0600540Lsdb::scheduleAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500541{
Vince Lehman50df6b72015-03-03 12:06:40 -0600542 m_nlsr.incrementAdjBuildCount();
543
Nick Gordon5c467f02016-07-13 13:40:10 -0500544 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
545 // Don't build adjacency LSAs in hyperbolic routing
546 return;
547 }
548
Vince Lehman50df6b72015-03-03 12:06:40 -0600549 if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
550 _LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
551
552 m_scheduler.scheduleEvent(m_adjLsaBuildInterval, ndn::bind(&Lsdb::buildAdjLsa, this));
553 m_nlsr.setIsBuildAdjLsaSheduled(true);
554 }
555}
556
557void
558Lsdb::buildAdjLsa()
559{
560 _LOG_TRACE("buildAdjLsa called");
561
akmhoque674b0b12014-05-20 14:33:28 -0500562 m_nlsr.setIsBuildAdjLsaSheduled(false);
akmhoque157b0a42014-05-13 00:26:37 -0500563 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500564 int adjBuildCount = m_nlsr.getAdjBuildCount();
akmhoque157b0a42014-05-13 00:26:37 -0500565 if (adjBuildCount > 0) {
566 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500567 _LOG_DEBUG("Building and installing Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500568 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500569 }
akmhoque157b0a42014-05-13 00:26:37 -0500570 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500571 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
alvy49b1c0c2014-12-19 13:57:46 -0600572 key.append(AdjLsa::TYPE_STRING);
akmhoque31d1d4b2014-05-05 22:08:14 -0500573 removeAdjLsa(key);
574 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500575 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500576 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500577 }
578 }
akmhoque157b0a42014-05-13 00:26:37 -0500579 else {
akmhoque674b0b12014-05-20 14:33:28 -0500580 m_nlsr.setIsBuildAdjLsaSheduled(true);
akmhoque31d1d4b2014-05-05 22:08:14 -0500581 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
582 m_nlsr.getConfParameter().getInterestResendTime();
Vince Lehman7c603292014-09-11 17:48:16 -0500583 m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
Vince Lehman50df6b72015-03-03 12:06:40 -0600584 ndn::bind(&Lsdb::buildAdjLsa, this));
akmhoque53353462014-04-22 08:43:45 -0500585 }
586}
587
588
589bool
590Lsdb::addAdjLsa(AdjLsa& alsa)
591{
592 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
593 m_adjLsdb.end(),
594 bind(adjLsaCompareByKey, _1,
595 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500596 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500597 m_adjLsdb.push_back(alsa);
598 return true;
599 }
600 return false;
601}
602
akmhoqueb6450b12014-04-24 00:01:03 -0500603AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500604Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500605{
606 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
607 m_adjLsdb.end(),
608 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500609 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500610 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500611 }
akmhoqueb6450b12014-04-24 00:01:03 -0500612 return 0;
akmhoque53353462014-04-22 08:43:45 -0500613}
614
615
616bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500617Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500618{
akmhoqueb6450b12014-04-24 00:01:03 -0500619 AdjLsa* adjLsaCheck = findAdjLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500620 if (adjLsaCheck != 0) {
621 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500622 return true;
623 }
akmhoque157b0a42014-05-13 00:26:37 -0500624 else {
akmhoque53353462014-04-22 08:43:45 -0500625 return false;
626 }
627 }
628 return true;
629}
630
631
632ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500633Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
634 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500635{
Vince Lehman7c603292014-09-11 17:48:16 -0500636 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
637 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500638}
639
640bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500641Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500642{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700643 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500644 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500645 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500646 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500647 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500648 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500649 addAdjLsa(alsa);
akmhoque31d1d4b2014-05-05 22:08:14 -0500650 alsa.addNptEntries(m_nlsr);
651 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500652 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500653 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
654 ndn::time::system_clock::now();
655 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500656 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500657 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500658 alsa.getLsSeqNo(), timeToExpire);
659 }
akmhoque157b0a42014-05-13 00:26:37 -0500660 else {
661 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500662 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500663 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500664 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500665 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500666 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500667 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500668 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500669 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500670 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500671 }
akmhoque157b0a42014-05-13 00:26:37 -0500672 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500673 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
674 ndn::time::system_clock::now();
675 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500676 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500677 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
678 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500679 alsa.getLsSeqNo(),
680 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500681 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500682 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500683 }
684 }
685 return true;
686}
687
688bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500689Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500690{
akmhoque31d1d4b2014-05-05 22:08:14 -0500691 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500692 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500693 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500694 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
695 m_nlsr.getAdjacencyList());
Vince Lehman904c2412014-09-23 19:36:11 -0500696
Nick Gordon5c467f02016-07-13 13:40:10 -0500697 //Sync adjacency LSAs if link-state or dry-run HR is enabled.
698 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_ON) {
699 m_nlsr.getSequencingManager().increaseAdjLsaSeq();
700 m_sync.publishRoutingUpdate();
701 }
Vince Lehman904c2412014-09-23 19:36:11 -0500702
Vince Lehman9d097802015-03-16 17:55:59 -0500703 return installAdjLsa(adjLsa);
akmhoque53353462014-04-22 08:43:45 -0500704}
705
706bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500707Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500708{
709 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
710 m_adjLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500711 ndn::bind(adjLsaCompareByKey, _1, key));
712 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500713 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500714 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500715 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500716 m_adjLsdb.erase(it);
717 return true;
718 }
719 return false;
720}
721
722bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500723Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500724{
725 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
726 m_adjLsdb.end(),
727 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500728 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500729 return false;
730 }
731 return true;
732}
733
Jiewen Tana0497d82015-02-02 21:59:18 -0800734const std::list<AdjLsa>&
akmhoque53353462014-04-22 08:43:45 -0500735Lsdb::getAdjLsdb()
736{
737 return m_adjLsdb;
738}
739
740void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700741Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500742{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700743 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500744}
745
746void
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500747Lsdb::setThisRouterPrefix(std::string trp)
akmhoque53353462014-04-22 08:43:45 -0500748{
749 m_thisRouterPrefix = trp;
750}
751
752void
akmhoque31d1d4b2014-05-05 22:08:14 -0500753Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500754{
akmhoque674b0b12014-05-20 14:33:28 -0500755 _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called");
756 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500757 NameLsa* chkNameLsa = findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500758 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500759 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500760 if (chkNameLsa->getLsSeqNo() == seqNo) {
761 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500762 _LOG_DEBUG("Own Name LSA, so refreshing it");
763 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500764 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500765 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500766 m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500767 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500768 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500769 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500770 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500771 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500772 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700773 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600774 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500775 }
akmhoque157b0a42014-05-13 00:26:37 -0500776 else {
akmhoque674b0b12014-05-20 14:33:28 -0500777 _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500778 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500779 }
780 }
781 }
782}
783
784void
akmhoque31d1d4b2014-05-05 22:08:14 -0500785Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500786{
akmhoque674b0b12014-05-20 14:33:28 -0500787 _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
788 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500789 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500790 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500791 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500792 if (chkAdjLsa->getLsSeqNo() == seqNo) {
793 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500794 _LOG_DEBUG("Own Adj LSA, so refreshing it");
795 _LOG_DEBUG("Deleting Adj Lsa");
796 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500797 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500798 m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500799 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500800 _LOG_DEBUG("Adding Adj Lsa");
801 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500802 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500803 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500804 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700805 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600806 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500807 }
akmhoque157b0a42014-05-13 00:26:37 -0500808 else {
akmhoque674b0b12014-05-20 14:33:28 -0500809 _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500810 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500811 }
812 // schedule Routing table calculaiton
akmhoque31d1d4b2014-05-05 22:08:14 -0500813 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500814 }
815 }
816}
817
818void
akmhoque31d1d4b2014-05-05 22:08:14 -0500819Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500820 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500821{
akmhoque674b0b12014-05-20 14:33:28 -0500822 _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
823 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500824 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500825 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500826 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500827 if (chkCorLsa->getLsSeqNo() == seqNo) {
828 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500829 _LOG_DEBUG("Own Cor LSA, so refreshing it");
830 _LOG_DEBUG("Deleting Coordinate Lsa");
831 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500832 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
Nick Gordon5c467f02016-07-13 13:40:10 -0500833 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
834 m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
835 }
836
akmhoquec7a79b22014-05-26 08:06:19 -0500837 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500838 _LOG_DEBUG("Adding Coordinate Lsa");
839 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500840 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500841 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
842 chkCorLsa->getKey(),
843 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700844 m_lsaRefreshTime));
Nick Gordon5c467f02016-07-13 13:40:10 -0500845 // Only sync coordinate LSAs if link-state routing is disabled
846 if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
847 m_sync.publishRoutingUpdate();
848 }
akmhoque53353462014-04-22 08:43:45 -0500849 }
akmhoque157b0a42014-05-13 00:26:37 -0500850 else {
akmhoque674b0b12014-05-20 14:33:28 -0500851 _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500852 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500853 }
Nick Gordon5c467f02016-07-13 13:40:10 -0500854 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500855 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500856 }
857 }
858 }
859}
860
akmhoque53353462014-04-22 08:43:45 -0500861void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700862Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500863 steady_clock::TimePoint deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500864{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500865 if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) {
866 deadline = steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700867 }
868
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500869 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500870 uint64_t seqNo = interestName[-1].toNumber();
871
872 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
873 m_highestSeqNo[lsaName] = seqNo;
874 }
875 else if (seqNo > m_highestSeqNo[lsaName]) {
876 m_highestSeqNo[lsaName] = seqNo;
877 }
878 else if (seqNo < m_highestSeqNo[lsaName]) {
879 return;
880 }
881
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500882 ndn::Interest interest(interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700883 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500884
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500885 _LOG_DEBUG("Fetching Data for LSA: " << interestName << " Seq number: " << seqNo);
886 ndn::util::SegmentFetcher::fetch(m_nlsr.getNlsrFace(), interest,
887 m_nlsr.getValidator(),
888 ndn::bind(&Lsdb::afterFetchLsa, this, _1, interestName),
889 ndn::bind(&Lsdb::onFetchLsaError, this, _1, _2, interestName,
890 timeoutCount, deadline, lsaName, seqNo));
akmhoque31d1d4b2014-05-05 22:08:14 -0500891}
892
893void
894Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
895{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500896 const ndn::Name& interestName(interest.getName());
897 _LOG_DEBUG("Interest received for LSA: " << interestName);
898
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500899 std::string chkString("LSA");
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500900 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
901
akmhoque157b0a42014-05-13 00:26:37 -0500902 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500903
904 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
905 originRouter.append(interestName.getSubName(lsaPosition + 1,
906 interest.getName().size() - lsaPosition - 3));
907
908 uint64_t seqNo = interestName[-1].toNumber();
909 _LOG_DEBUG("LSA sequence number from interest: " << seqNo);
910
911 std::string interestedLsType = interestName[-2].toUri();
912
alvy49b1c0c2014-12-19 13:57:46 -0600913 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500914 processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500915 }
alvy49b1c0c2014-12-19 13:57:46 -0600916 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500917 processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500918 }
alvy49b1c0c2014-12-19 13:57:46 -0600919 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500920 processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500921 }
akmhoque157b0a42014-05-13 00:26:37 -0500922 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500923 _LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500924 }
925 }
926}
927
928void
akmhoque69c9aa92014-07-23 15:15:05 -0500929Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
930{
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500931 LsaContentPublisher publisher(m_nlsr.getNlsrFace(),
932 m_nlsr.getKeyChain(),
933 m_lsaRefreshTime,
934 content);
935 publisher.publish(interest.getName(),
936 ndn::security::signingByCertificate(m_nlsr.getDefaultCertName()));
akmhoque69c9aa92014-07-23 15:15:05 -0500937}
938
939void
akmhoque31d1d4b2014-05-05 22:08:14 -0500940Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
941 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500942 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500943{
944 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500945 if (nameLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500946 if (nameLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500947 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500948 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500949 }
950 }
951}
952
953void
954Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
955 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500956 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500957{
Nick Gordon5c467f02016-07-13 13:40:10 -0500958 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
959 _LOG_ERROR("Received interest for an adjacency LSA when hyperbolic routing is enabled.");
960 }
961
akmhoque31d1d4b2014-05-05 22:08:14 -0500962 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500963 if (adjLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500964 if (adjLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500965 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500966 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500967 }
968 }
969}
970
971void
972Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
973 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500974 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500975{
Nick Gordon5c467f02016-07-13 13:40:10 -0500976 if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
977 _LOG_ERROR("Received Interest for a coordinate LSA when link-state routing is enabled.");
978 }
979
akmhoque31d1d4b2014-05-05 22:08:14 -0500980 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500981 if (corLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500982 if (corLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500983 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500984 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500985 }
986 }
987}
988
989void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700990Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
991{
992 const ndn::Name& dataName = data->getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500993 _LOG_DEBUG("Data validation successful for LSA: " << dataName);
994
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500995 std::string chkString("LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500996 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500997
akmhoque157b0a42014-05-13 00:26:37 -0500998 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500999
1000 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001001 originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 3));
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001002
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001003 uint64_t seqNo = dataName[-1].toNumber();
1004 std::string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001005
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -05001006 std::string interestedLsType = dataName[-2].toUri();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001007
alvy49b1c0c2014-12-19 13:57:46 -06001008 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001009 processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -05001010 }
alvy49b1c0c2014-12-19 13:57:46 -06001011 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001012 processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -05001013 }
alvy49b1c0c2014-12-19 13:57:46 -06001014 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001015 processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -05001016 }
akmhoque157b0a42014-05-13 00:26:37 -05001017 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001018 _LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -05001019 }
1020 }
1021}
1022
1023void
1024Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001025 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001026{
akmhoque157b0a42014-05-13 00:26:37 -05001027 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001028 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001029 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001030 installNameLsa(nameLsa);
1031 }
akmhoque157b0a42014-05-13 00:26:37 -05001032 else {
akmhoque2f423352014-06-03 11:49:35 -05001033 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001034 }
1035 }
1036}
1037
1038void
1039Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001040 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001041{
akmhoque157b0a42014-05-13 00:26:37 -05001042 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001043 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001044 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001045 installAdjLsa(adjLsa);
1046 }
akmhoque157b0a42014-05-13 00:26:37 -05001047 else {
akmhoque2f423352014-06-03 11:49:35 -05001048 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001049 }
1050 }
1051}
1052
1053void
1054Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001055 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001056{
akmhoque157b0a42014-05-13 00:26:37 -05001057 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001058 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001059 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001060 installCoordinateLsa(corLsa);
1061 }
akmhoque157b0a42014-05-13 00:26:37 -05001062 else {
akmhoque2f423352014-06-03 11:49:35 -05001063 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001064 }
1065 }
1066}
1067
akmhoquec7a79b22014-05-26 08:06:19 -05001068ndn::time::system_clock::TimePoint
1069Lsdb::getLsaExpirationTimePoint()
1070{
1071 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1072 expirationTimePoint = expirationTimePoint +
1073 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1074 return expirationTimePoint;
1075}
akmhoque31d1d4b2014-05-05 22:08:14 -05001076
1077void
akmhoque2f423352014-06-03 11:49:35 -05001078Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001079{
akmhoque2f423352014-06-03 11:49:35 -05001080 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001081 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001082 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001083 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001084 }
1085}
1086
1087//-----utility function -----
1088bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001089Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001090{
alvy49b1c0c2014-12-19 13:57:46 -06001091 if (lsType == NameLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001092 return doesNameLsaExist(key);
1093 }
alvy49b1c0c2014-12-19 13:57:46 -06001094 else if (lsType == AdjLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001095 return doesAdjLsaExist(key);
1096 }
alvy49b1c0c2014-12-19 13:57:46 -06001097 else if (lsType == CoordinateLsa::TYPE_STRING) {
akmhoqueb6450b12014-04-24 00:01:03 -05001098 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001099 }
1100 return false;
1101}
1102
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001103} // namespace nlsr