blob: 8d7f1ec758ebcb5087db77c3495f87137348eb24 [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());
362 m_nlsr.getSequencingManager().increaseCorLsaSeq();
363 installCoordinateLsa(corLsa);
akmhoque53353462014-04-22 08:43:45 -0500364 return true;
365}
366
akmhoqueb6450b12014-04-24 00:01:03 -0500367CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500368Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500369{
akmhoqueb6450b12014-04-24 00:01:03 -0500370 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
371 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500372 ndn::bind(corLsaCompareByKey, _1, key));
373 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500374 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500375 }
akmhoqueb6450b12014-04-24 00:01:03 -0500376 return 0;
akmhoque53353462014-04-22 08:43:45 -0500377}
378
379bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500380Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500381{
akmhoqueb6450b12014-04-24 00:01:03 -0500382 CoordinateLsa* clsa = findCoordinateLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500383 if (clsa != 0) {
384 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500385 return true;
386 }
akmhoque157b0a42014-05-13 00:26:37 -0500387 else {
akmhoque53353462014-04-22 08:43:45 -0500388 return false;
389 }
390 }
391 return true;
392}
393
394ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500395Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500396 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500397{
Vince Lehman7c603292014-09-11 17:48:16 -0500398 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
399 ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
400 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500401}
402
403bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500404Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500405{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700406 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500407 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500408 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500409 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500410 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500411 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500412 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500413
akmhoque157b0a42014-05-13 00:26:37 -0500414 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500415 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
416 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500417 }
akmhoque157b0a42014-05-13 00:26:37 -0500418 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500419 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500420 }
akmhoque157b0a42014-05-13 00:26:37 -0500421 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500422 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
423 ndn::time::system_clock::now();
424 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500425 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500426 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500427 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500428 }
akmhoque157b0a42014-05-13 00:26:37 -0500429 else {
430 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500431 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500432 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500433 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500434 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500435 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500436 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500437 chkCorLsa->setCorRadius(clsa.getCorRadius());
438 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500439 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500440 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500441 }
442 }
akmhoque157b0a42014-05-13 00:26:37 -0500443 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500444 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
445 ndn::time::system_clock::now();
446 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500447 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500448 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
449 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500450 clsa.getLsSeqNo(),
451 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500452 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500453 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500454 }
455 }
456 return true;
457}
458
459bool
akmhoqueb6450b12014-04-24 00:01:03 -0500460Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500461{
akmhoqueb6450b12014-04-24 00:01:03 -0500462 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
463 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500464 ndn::bind(corLsaCompareByKey, _1,
465 clsa.getKey()));
466 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500467 m_corLsdb.push_back(clsa);
468 return true;
469 }
470 return false;
471}
472
473bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500474Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500475{
akmhoqueb6450b12014-04-24 00:01:03 -0500476 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
477 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500478 ndn::bind(corLsaCompareByKey,
479 _1, key));
480 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500481 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500482 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500483 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500484 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500485 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
486 (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500487 }
488 m_corLsdb.erase(it);
489 return true;
490 }
491 return false;
492}
493
494bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500495Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500496{
akmhoqueb6450b12014-04-24 00:01:03 -0500497 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
498 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500499 ndn::bind(corLsaCompareByKey,
500 _1, key));
501 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500502 return false;
503 }
504 return true;
505}
506
507void
akmhoque2f423352014-06-03 11:49:35 -0500508Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500509{
akmhoque2f423352014-06-03 11:49:35 -0500510 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500511 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500512 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500513 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500514 }
515}
516
Jiewen Tana0497d82015-02-02 21:59:18 -0800517const std::list<CoordinateLsa>&
518Lsdb::getCoordinateLsdb()
519{
520 return m_corLsdb;
521}
522
akmhoque53353462014-04-22 08:43:45 -0500523// Adj LSA and LSDB related function starts here
524
525static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500526adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500527{
528 return alsa.getKey() == key;
529}
530
akmhoque53353462014-04-22 08:43:45 -0500531void
Vince Lehman50df6b72015-03-03 12:06:40 -0600532Lsdb::scheduleAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500533{
Vince Lehman50df6b72015-03-03 12:06:40 -0600534 m_nlsr.incrementAdjBuildCount();
535
536 if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
537 _LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
538
539 m_scheduler.scheduleEvent(m_adjLsaBuildInterval, ndn::bind(&Lsdb::buildAdjLsa, this));
540 m_nlsr.setIsBuildAdjLsaSheduled(true);
541 }
542}
543
544void
545Lsdb::buildAdjLsa()
546{
547 _LOG_TRACE("buildAdjLsa called");
548
akmhoque674b0b12014-05-20 14:33:28 -0500549 m_nlsr.setIsBuildAdjLsaSheduled(false);
akmhoque157b0a42014-05-13 00:26:37 -0500550 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500551 int adjBuildCount = m_nlsr.getAdjBuildCount();
akmhoque157b0a42014-05-13 00:26:37 -0500552 if (adjBuildCount > 0) {
553 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500554 _LOG_DEBUG("Building and installing Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500555 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500556 }
akmhoque157b0a42014-05-13 00:26:37 -0500557 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500558 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
alvy49b1c0c2014-12-19 13:57:46 -0600559 key.append(AdjLsa::TYPE_STRING);
akmhoque31d1d4b2014-05-05 22:08:14 -0500560 removeAdjLsa(key);
561 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500562 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500563 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500564 }
565 }
akmhoque157b0a42014-05-13 00:26:37 -0500566 else {
akmhoque674b0b12014-05-20 14:33:28 -0500567 m_nlsr.setIsBuildAdjLsaSheduled(true);
akmhoque31d1d4b2014-05-05 22:08:14 -0500568 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
569 m_nlsr.getConfParameter().getInterestResendTime();
Vince Lehman7c603292014-09-11 17:48:16 -0500570 m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
Vince Lehman50df6b72015-03-03 12:06:40 -0600571 ndn::bind(&Lsdb::buildAdjLsa, this));
akmhoque53353462014-04-22 08:43:45 -0500572 }
573}
574
575
576bool
577Lsdb::addAdjLsa(AdjLsa& alsa)
578{
579 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
580 m_adjLsdb.end(),
581 bind(adjLsaCompareByKey, _1,
582 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500583 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500584 m_adjLsdb.push_back(alsa);
585 return true;
586 }
587 return false;
588}
589
akmhoqueb6450b12014-04-24 00:01:03 -0500590AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500591Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500592{
593 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
594 m_adjLsdb.end(),
595 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500596 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500597 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500598 }
akmhoqueb6450b12014-04-24 00:01:03 -0500599 return 0;
akmhoque53353462014-04-22 08:43:45 -0500600}
601
602
603bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500604Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500605{
akmhoqueb6450b12014-04-24 00:01:03 -0500606 AdjLsa* adjLsaCheck = findAdjLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500607 if (adjLsaCheck != 0) {
608 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500609 return true;
610 }
akmhoque157b0a42014-05-13 00:26:37 -0500611 else {
akmhoque53353462014-04-22 08:43:45 -0500612 return false;
613 }
614 }
615 return true;
616}
617
618
619ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500620Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
621 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500622{
Vince Lehman7c603292014-09-11 17:48:16 -0500623 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
624 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500625}
626
627bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500628Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500629{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700630 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500631 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500632 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500633 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500634 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500635 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500636 addAdjLsa(alsa);
akmhoque31d1d4b2014-05-05 22:08:14 -0500637 alsa.addNptEntries(m_nlsr);
638 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500639 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500640 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
641 ndn::time::system_clock::now();
642 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500643 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500644 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500645 alsa.getLsSeqNo(), timeToExpire);
646 }
akmhoque157b0a42014-05-13 00:26:37 -0500647 else {
648 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500649 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500650 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500651 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500652 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500653 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500654 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500655 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500656 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500657 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500658 }
akmhoque157b0a42014-05-13 00:26:37 -0500659 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500660 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
661 ndn::time::system_clock::now();
662 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500663 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500664 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
665 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500666 alsa.getLsSeqNo(),
667 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500668 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500669 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500670 }
671 }
672 return true;
673}
674
675bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500676Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500677{
akmhoque31d1d4b2014-05-05 22:08:14 -0500678 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500679 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500680 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500681 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
682 m_nlsr.getAdjacencyList());
Vince Lehman904c2412014-09-23 19:36:11 -0500683
akmhoque31d1d4b2014-05-05 22:08:14 -0500684 m_nlsr.getSequencingManager().increaseAdjLsaSeq();
Vince Lehman904c2412014-09-23 19:36:11 -0500685
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600686 m_sync.publishRoutingUpdate();
Vince Lehman904c2412014-09-23 19:36:11 -0500687
Vince Lehman9d097802015-03-16 17:55:59 -0500688 return installAdjLsa(adjLsa);
akmhoque53353462014-04-22 08:43:45 -0500689}
690
691bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500692Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500693{
694 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
695 m_adjLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500696 ndn::bind(adjLsaCompareByKey, _1, key));
697 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500698 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500699 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500700 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500701 m_adjLsdb.erase(it);
702 return true;
703 }
704 return false;
705}
706
707bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500708Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500709{
710 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
711 m_adjLsdb.end(),
712 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500713 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500714 return false;
715 }
716 return true;
717}
718
Jiewen Tana0497d82015-02-02 21:59:18 -0800719const std::list<AdjLsa>&
akmhoque53353462014-04-22 08:43:45 -0500720Lsdb::getAdjLsdb()
721{
722 return m_adjLsdb;
723}
724
725void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700726Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500727{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700728 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500729}
730
731void
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500732Lsdb::setThisRouterPrefix(std::string trp)
akmhoque53353462014-04-22 08:43:45 -0500733{
734 m_thisRouterPrefix = trp;
735}
736
737void
akmhoque31d1d4b2014-05-05 22:08:14 -0500738Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500739{
akmhoque674b0b12014-05-20 14:33:28 -0500740 _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called");
741 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500742 NameLsa* chkNameLsa = findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500743 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500744 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500745 if (chkNameLsa->getLsSeqNo() == seqNo) {
746 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500747 _LOG_DEBUG("Own Name LSA, so refreshing it");
748 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500749 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500750 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500751 m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500752 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500753 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500754 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500755 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500756 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500757 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700758 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600759 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500760 }
akmhoque157b0a42014-05-13 00:26:37 -0500761 else {
akmhoque674b0b12014-05-20 14:33:28 -0500762 _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500763 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500764 }
765 }
766 }
767}
768
769void
akmhoque31d1d4b2014-05-05 22:08:14 -0500770Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500771{
akmhoque674b0b12014-05-20 14:33:28 -0500772 _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
773 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500774 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500775 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500776 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500777 if (chkAdjLsa->getLsSeqNo() == seqNo) {
778 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500779 _LOG_DEBUG("Own Adj LSA, so refreshing it");
780 _LOG_DEBUG("Deleting Adj Lsa");
781 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500782 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500783 m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500784 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500785 _LOG_DEBUG("Adding Adj Lsa");
786 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500787 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500788 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500789 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700790 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600791 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500792 }
akmhoque157b0a42014-05-13 00:26:37 -0500793 else {
akmhoque674b0b12014-05-20 14:33:28 -0500794 _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500795 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500796 }
797 // schedule Routing table calculaiton
akmhoque31d1d4b2014-05-05 22:08:14 -0500798 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500799 }
800 }
801}
802
803void
akmhoque31d1d4b2014-05-05 22:08:14 -0500804Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500805 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500806{
akmhoque674b0b12014-05-20 14:33:28 -0500807 _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
808 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500809 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500810 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500811 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500812 if (chkCorLsa->getLsSeqNo() == seqNo) {
813 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500814 _LOG_DEBUG("Own Cor LSA, so refreshing it");
815 _LOG_DEBUG("Deleting Coordinate Lsa");
816 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500817 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500818 m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500819 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500820 _LOG_DEBUG("Adding Coordinate Lsa");
821 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500822 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500823 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
824 chkCorLsa->getKey(),
825 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700826 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600827 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500828 }
akmhoque157b0a42014-05-13 00:26:37 -0500829 else {
akmhoque674b0b12014-05-20 14:33:28 -0500830 _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500831 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500832 }
akmhoque157b0a42014-05-13 00:26:37 -0500833 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500834 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500835 }
836 }
837 }
838}
839
akmhoque53353462014-04-22 08:43:45 -0500840void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700841Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500842 steady_clock::TimePoint deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500843{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500844 if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) {
845 deadline = steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700846 }
847
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500848 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500849 uint64_t seqNo = interestName[-1].toNumber();
850
851 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
852 m_highestSeqNo[lsaName] = seqNo;
853 }
854 else if (seqNo > m_highestSeqNo[lsaName]) {
855 m_highestSeqNo[lsaName] = seqNo;
856 }
857 else if (seqNo < m_highestSeqNo[lsaName]) {
858 return;
859 }
860
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500861 ndn::Interest interest(interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700862 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500863
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500864 _LOG_DEBUG("Fetching Data for LSA: " << interestName << " Seq number: " << seqNo);
865 ndn::util::SegmentFetcher::fetch(m_nlsr.getNlsrFace(), interest,
866 m_nlsr.getValidator(),
867 ndn::bind(&Lsdb::afterFetchLsa, this, _1, interestName),
868 ndn::bind(&Lsdb::onFetchLsaError, this, _1, _2, interestName,
869 timeoutCount, deadline, lsaName, seqNo));
akmhoque31d1d4b2014-05-05 22:08:14 -0500870}
871
872void
873Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
874{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500875 const ndn::Name& interestName(interest.getName());
876 _LOG_DEBUG("Interest received for LSA: " << interestName);
877
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500878 std::string chkString("LSA");
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500879 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
880
akmhoque157b0a42014-05-13 00:26:37 -0500881 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500882
883 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
884 originRouter.append(interestName.getSubName(lsaPosition + 1,
885 interest.getName().size() - lsaPosition - 3));
886
887 uint64_t seqNo = interestName[-1].toNumber();
888 _LOG_DEBUG("LSA sequence number from interest: " << seqNo);
889
890 std::string interestedLsType = interestName[-2].toUri();
891
alvy49b1c0c2014-12-19 13:57:46 -0600892 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500893 processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500894 }
alvy49b1c0c2014-12-19 13:57:46 -0600895 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500896 processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500897 }
alvy49b1c0c2014-12-19 13:57:46 -0600898 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500899 processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500900 }
akmhoque157b0a42014-05-13 00:26:37 -0500901 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500902 _LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500903 }
904 }
905}
906
907void
akmhoque69c9aa92014-07-23 15:15:05 -0500908Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
909{
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500910 LsaContentPublisher publisher(m_nlsr.getNlsrFace(),
911 m_nlsr.getKeyChain(),
912 m_lsaRefreshTime,
913 content);
914 publisher.publish(interest.getName(),
915 ndn::security::signingByCertificate(m_nlsr.getDefaultCertName()));
akmhoque69c9aa92014-07-23 15:15:05 -0500916}
917
918void
akmhoque31d1d4b2014-05-05 22:08:14 -0500919Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
920 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500921 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500922{
923 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500924 if (nameLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500925 if (nameLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500926 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500927 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500928 }
929 }
930}
931
932void
933Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
934 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500935 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500936{
937 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500938 if (adjLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500939 if (adjLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500940 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500941 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500942 }
943 }
944}
945
946void
947Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
948 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500949 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500950{
951 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500952 if (corLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500953 if (corLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500954 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500955 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500956 }
957 }
958}
959
960void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700961Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
962{
963 const ndn::Name& dataName = data->getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500964 _LOG_DEBUG("Data validation successful for LSA: " << dataName);
965
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500966 std::string chkString("LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500967 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500968
akmhoque157b0a42014-05-13 00:26:37 -0500969 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500970
971 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500972 originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 3));
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500973
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500974 uint64_t seqNo = dataName[-1].toNumber();
975 std::string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500976
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500977 std::string interestedLsType = dataName[-2].toUri();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500978
alvy49b1c0c2014-12-19 13:57:46 -0600979 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500980 processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500981 }
alvy49b1c0c2014-12-19 13:57:46 -0600982 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500983 processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500984 }
alvy49b1c0c2014-12-19 13:57:46 -0600985 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500986 processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500987 }
akmhoque157b0a42014-05-13 00:26:37 -0500988 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500989 _LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500990 }
991 }
992}
993
994void
995Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500996 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500997{
akmhoque157b0a42014-05-13 00:26:37 -0500998 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500999 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001000 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001001 installNameLsa(nameLsa);
1002 }
akmhoque157b0a42014-05-13 00:26:37 -05001003 else {
akmhoque2f423352014-06-03 11:49:35 -05001004 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001005 }
1006 }
1007}
1008
1009void
1010Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001011 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001012{
akmhoque157b0a42014-05-13 00:26:37 -05001013 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001014 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001015 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001016 installAdjLsa(adjLsa);
1017 }
akmhoque157b0a42014-05-13 00:26:37 -05001018 else {
akmhoque2f423352014-06-03 11:49:35 -05001019 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001020 }
1021 }
1022}
1023
1024void
1025Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001026 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001027{
akmhoque157b0a42014-05-13 00:26:37 -05001028 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001029 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001030 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001031 installCoordinateLsa(corLsa);
1032 }
akmhoque157b0a42014-05-13 00:26:37 -05001033 else {
akmhoque2f423352014-06-03 11:49:35 -05001034 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001035 }
1036 }
1037}
1038
akmhoquec7a79b22014-05-26 08:06:19 -05001039ndn::time::system_clock::TimePoint
1040Lsdb::getLsaExpirationTimePoint()
1041{
1042 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1043 expirationTimePoint = expirationTimePoint +
1044 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1045 return expirationTimePoint;
1046}
akmhoque31d1d4b2014-05-05 22:08:14 -05001047
1048void
akmhoque2f423352014-06-03 11:49:35 -05001049Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001050{
akmhoque2f423352014-06-03 11:49:35 -05001051 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001052 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001053 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001054 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001055 }
1056}
1057
1058//-----utility function -----
1059bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001060Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001061{
alvy49b1c0c2014-12-19 13:57:46 -06001062 if (lsType == NameLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001063 return doesNameLsaExist(key);
1064 }
alvy49b1c0c2014-12-19 13:57:46 -06001065 else if (lsType == AdjLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001066 return doesAdjLsaExist(key);
1067 }
alvy49b1c0c2014-12-19 13:57:46 -06001068 else if (lsType == CoordinateLsa::TYPE_STRING) {
akmhoqueb6450b12014-04-24 00:01:03 -05001069 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001070 }
1071 return false;
1072}
1073
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001074} // namespace nlsr