blob: c0fb7654f6c820e1d7be3cd5271c4bb9c2cbb2c5 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehmanc2e51f62015-01-20 15:03:11 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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 <string>
23#include <utility>
akmhoque157b0a42014-05-13 00:26:37 -050024
akmhoque53353462014-04-22 08:43:45 -050025#include "lsdb.hpp"
26#include "nlsr.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050027#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050028#include "utility/name-helper.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050029#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050030
31namespace nlsr {
32
akmhoque674b0b12014-05-20 14:33:28 -050033INIT_LOGGER("Lsdb");
34
Jiewen Tana0497d82015-02-02 21:59:18 -080035const ndn::Name::Component Lsdb::NAME_COMPONENT = ndn::Name::Component("lsdb");
Vince Lehman18841082014-08-19 17:15:24 -050036const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -050037const steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = steady_clock::TimePoint::min();
Vince Lehman18841082014-08-19 17:15:24 -050038
akmhoque53353462014-04-22 08:43:45 -050039using namespace std;
40
41void
akmhoque31d1d4b2014-05-05 22:08:14 -050042Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
akmhoque53353462014-04-22 08:43:45 -050043{
Vince Lehman7c603292014-09-11 17:48:16 -050044 m_scheduler.cancelEvent(eid);
akmhoque53353462014-04-22 08:43:45 -050045}
46
47static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050048nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -050049{
50 return nlsa1.getKey() == key;
51}
52
53
54bool
akmhoque31d1d4b2014-05-05 22:08:14 -050055Lsdb::buildAndInstallOwnNameLsa()
akmhoque53353462014-04-22 08:43:45 -050056{
akmhoque31d1d4b2014-05-05 22:08:14 -050057 NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
alvy49b1c0c2014-12-19 13:57:46 -060058 NameLsa::TYPE_STRING,
akmhoque31d1d4b2014-05-05 22:08:14 -050059 m_nlsr.getSequencingManager().getNameLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -050060 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -050061 m_nlsr.getNamePrefixList());
62 m_nlsr.getSequencingManager().increaseNameLsaSeq();
63 return installNameLsa(nameLsa);
akmhoque53353462014-04-22 08:43:45 -050064}
65
akmhoqueb6450b12014-04-24 00:01:03 -050066NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050067Lsdb::findNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -050068{
69 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
70 m_nameLsdb.end(),
71 bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -050072 if (it != m_nameLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -050073 return &(*it);
akmhoque53353462014-04-22 08:43:45 -050074 }
akmhoqueb6450b12014-04-24 00:01:03 -050075 return 0;
akmhoque53353462014-04-22 08:43:45 -050076}
77
78bool
akmhoque31d1d4b2014-05-05 22:08:14 -050079Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -050080{
akmhoqueb6450b12014-04-24 00:01:03 -050081 NameLsa* nameLsaCheck = findNameLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -050082 if (nameLsaCheck != 0) {
83 if (nameLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -050084 return true;
85 }
akmhoque157b0a42014-05-13 00:26:37 -050086 else {
akmhoque53353462014-04-22 08:43:45 -050087 return false;
88 }
89 }
90 return true;
91}
92
93ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -050094Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
95 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -050096{
Vince Lehman7c603292014-09-11 17:48:16 -050097 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
98 ndn::bind(&Lsdb::exprireOrRefreshNameLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -050099}
100
101bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500102Lsdb::installNameLsa(NameLsa& nlsa)
akmhoque53353462014-04-22 08:43:45 -0500103{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700104 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500105 NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500106 if (chkNameLsa == 0) {
akmhoque53353462014-04-22 08:43:45 -0500107 addNameLsa(nlsa);
akmhoque2f423352014-06-03 11:49:35 -0500108 _LOG_DEBUG("New Name LSA");
109 _LOG_DEBUG("Adding Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500110 nlsa.writeLog();
akmhoque674b0b12014-05-20 14:33:28 -0500111
akmhoque157b0a42014-05-13 00:26:37 -0500112 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500113 m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
114 nlsa.getOrigRouter());
115 std::list<ndn::Name> nameList = nlsa.getNpl().getNameList();
116 for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end();
akmhoque157b0a42014-05-13 00:26:37 -0500117 it++) {
118 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500119 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500120 }
121 }
122 }
akmhoque157b0a42014-05-13 00:26:37 -0500123 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500124 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
125 ndn::time::system_clock::now();
126 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500127 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500128 nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500129 nlsa.getLsSeqNo(),
130 timeToExpire));
131 }
akmhoque157b0a42014-05-13 00:26:37 -0500132 else {
133 if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500134 _LOG_DEBUG("Updated Name LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500135 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500136 chkNameLsa->writeLog();
137 chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500138 chkNameLsa->setExpirationTimePoint(nlsa.getExpirationTimePoint());
akmhoqueb6450b12014-04-24 00:01:03 -0500139 chkNameLsa->getNpl().sort();
akmhoque53353462014-04-22 08:43:45 -0500140 nlsa.getNpl().sort();
akmhoque31d1d4b2014-05-05 22:08:14 -0500141 std::list<ndn::Name> nameToAdd;
akmhoque53353462014-04-22 08:43:45 -0500142 std::set_difference(nlsa.getNpl().getNameList().begin(),
143 nlsa.getNpl().getNameList().end(),
akmhoqueb6450b12014-04-24 00:01:03 -0500144 chkNameLsa->getNpl().getNameList().begin(),
145 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500146 std::inserter(nameToAdd, nameToAdd.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500147 for (std::list<ndn::Name>::iterator it = nameToAdd.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500148 it != nameToAdd.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500149 chkNameLsa->addName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500150 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
151 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500152 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500153 }
154 }
155 }
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500156
157 chkNameLsa->getNpl().sort();
158
akmhoque31d1d4b2014-05-05 22:08:14 -0500159 std::list<ndn::Name> nameToRemove;
akmhoqueb6450b12014-04-24 00:01:03 -0500160 std::set_difference(chkNameLsa->getNpl().getNameList().begin(),
161 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500162 nlsa.getNpl().getNameList().begin(),
163 nlsa.getNpl().getNameList().end(),
164 std::inserter(nameToRemove, nameToRemove.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500165 for (std::list<ndn::Name>::iterator it = nameToRemove.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500166 it != nameToRemove.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500167 chkNameLsa->removeName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500168 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
169 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500170 m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500171 }
172 }
173 }
akmhoque157b0a42014-05-13 00:26:37 -0500174 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500175 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
176 ndn::time::system_clock::now();
177 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500178 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500179 cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
180 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500181 nlsa.getLsSeqNo(),
182 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500183 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500184 chkNameLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500185 }
186 }
187 return true;
188}
189
190bool
191Lsdb::addNameLsa(NameLsa& nlsa)
192{
193 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
194 m_nameLsdb.end(),
195 bind(nameLsaCompareByKey, _1,
196 nlsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500197 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500198 m_nameLsdb.push_back(nlsa);
199 return true;
200 }
201 return false;
202}
203
204bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500205Lsdb::removeNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500206{
207 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
208 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500209 ndn::bind(nameLsaCompareByKey, _1, key));
210 if (it != m_nameLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500211 _LOG_DEBUG("Deleting Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500212 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500213 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500214 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500215 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
216 (*it).getOrigRouter());
217 for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500218 nit != (*it).getNpl().getNameList().end(); ++nit) {
219 if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500220 m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500221 }
222 }
223 }
224 m_nameLsdb.erase(it);
225 return true;
226 }
227 return false;
228}
229
230bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500231Lsdb::doesNameLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500232{
233 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
234 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500235 ndn::bind(nameLsaCompareByKey, _1, key));
236 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500237 return false;
238 }
239 return true;
240}
241
242void
akmhoque2f423352014-06-03 11:49:35 -0500243Lsdb::writeNameLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500244{
akmhoque2f423352014-06-03 11:49:35 -0500245 _LOG_DEBUG("---------------Name LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -0500246 for (std::list<NameLsa>::iterator it = m_nameLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500247 it != m_nameLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500248 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500249 }
250}
251
Jiewen Tana0497d82015-02-02 21:59:18 -0800252const std::list<NameLsa>&
253Lsdb::getNameLsdb()
254{
255 return m_nameLsdb;
256}
257
akmhoque53353462014-04-22 08:43:45 -0500258// Cor LSA and LSDB related Functions start here
259
akmhoque53353462014-04-22 08:43:45 -0500260static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500261corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500262{
263 return clsa.getKey() == key;
264}
265
266bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500267Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500268{
akmhoque31d1d4b2014-05-05 22:08:14 -0500269 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
alvy49b1c0c2014-12-19 13:57:46 -0600270 CoordinateLsa::TYPE_STRING,
akmhoque31d1d4b2014-05-05 22:08:14 -0500271 m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500272 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500273 m_nlsr.getConfParameter().getCorR(),
274 m_nlsr.getConfParameter().getCorTheta());
275 m_nlsr.getSequencingManager().increaseCorLsaSeq();
276 installCoordinateLsa(corLsa);
akmhoque53353462014-04-22 08:43:45 -0500277 return true;
278}
279
akmhoqueb6450b12014-04-24 00:01:03 -0500280CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500281Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500282{
akmhoqueb6450b12014-04-24 00:01:03 -0500283 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
284 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500285 ndn::bind(corLsaCompareByKey, _1, key));
286 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500287 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500288 }
akmhoqueb6450b12014-04-24 00:01:03 -0500289 return 0;
akmhoque53353462014-04-22 08:43:45 -0500290}
291
292bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500293Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500294{
akmhoqueb6450b12014-04-24 00:01:03 -0500295 CoordinateLsa* clsa = findCoordinateLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500296 if (clsa != 0) {
297 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500298 return true;
299 }
akmhoque157b0a42014-05-13 00:26:37 -0500300 else {
akmhoque53353462014-04-22 08:43:45 -0500301 return false;
302 }
303 }
304 return true;
305}
306
307ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500308Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500309 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500310{
Vince Lehman7c603292014-09-11 17:48:16 -0500311 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
312 ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
313 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500314}
315
316bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500317Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500318{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700319 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500320 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500321 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500322 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500323 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500324 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500325 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500326
akmhoque157b0a42014-05-13 00:26:37 -0500327 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500328 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
329 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500330 }
akmhoque157b0a42014-05-13 00:26:37 -0500331 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500332 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500333 }
akmhoque157b0a42014-05-13 00:26:37 -0500334 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500335 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
336 ndn::time::system_clock::now();
337 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500338 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500339 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500340 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500341 }
akmhoque157b0a42014-05-13 00:26:37 -0500342 else {
343 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500344 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500345 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500346 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500347 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500348 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500349 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500350 chkCorLsa->setCorRadius(clsa.getCorRadius());
351 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500352 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500353 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500354 }
355 }
akmhoque157b0a42014-05-13 00:26:37 -0500356 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500357 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
358 ndn::time::system_clock::now();
359 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500360 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500361 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
362 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500363 clsa.getLsSeqNo(),
364 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500365 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500366 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500367 }
368 }
369 return true;
370}
371
372bool
akmhoqueb6450b12014-04-24 00:01:03 -0500373Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500374{
akmhoqueb6450b12014-04-24 00:01:03 -0500375 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
376 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500377 ndn::bind(corLsaCompareByKey, _1,
378 clsa.getKey()));
379 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500380 m_corLsdb.push_back(clsa);
381 return true;
382 }
383 return false;
384}
385
386bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500387Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500388{
akmhoqueb6450b12014-04-24 00:01:03 -0500389 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
390 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500391 ndn::bind(corLsaCompareByKey,
392 _1, key));
393 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500394 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500395 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500396 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500397 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500398 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
399 (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500400 }
401 m_corLsdb.erase(it);
402 return true;
403 }
404 return false;
405}
406
407bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500408Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500409{
akmhoqueb6450b12014-04-24 00:01:03 -0500410 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
411 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500412 ndn::bind(corLsaCompareByKey,
413 _1, key));
414 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500415 return false;
416 }
417 return true;
418}
419
420void
akmhoque2f423352014-06-03 11:49:35 -0500421Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500422{
akmhoque2f423352014-06-03 11:49:35 -0500423 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500424 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500425 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500426 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500427 }
428}
429
Jiewen Tana0497d82015-02-02 21:59:18 -0800430const std::list<CoordinateLsa>&
431Lsdb::getCoordinateLsdb()
432{
433 return m_corLsdb;
434}
435
akmhoque53353462014-04-22 08:43:45 -0500436// Adj LSA and LSDB related function starts here
437
438static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500439adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500440{
441 return alsa.getKey() == key;
442}
443
akmhoque53353462014-04-22 08:43:45 -0500444void
Vince Lehman50df6b72015-03-03 12:06:40 -0600445Lsdb::scheduleAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500446{
Vince Lehman50df6b72015-03-03 12:06:40 -0600447 m_nlsr.incrementAdjBuildCount();
448
449 if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
450 _LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
451
452 m_scheduler.scheduleEvent(m_adjLsaBuildInterval, ndn::bind(&Lsdb::buildAdjLsa, this));
453 m_nlsr.setIsBuildAdjLsaSheduled(true);
454 }
455}
456
457void
458Lsdb::buildAdjLsa()
459{
460 _LOG_TRACE("buildAdjLsa called");
461
akmhoque674b0b12014-05-20 14:33:28 -0500462 m_nlsr.setIsBuildAdjLsaSheduled(false);
akmhoque157b0a42014-05-13 00:26:37 -0500463 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500464 int adjBuildCount = m_nlsr.getAdjBuildCount();
akmhoque157b0a42014-05-13 00:26:37 -0500465 if (adjBuildCount > 0) {
466 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500467 _LOG_DEBUG("Building and installing Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500468 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500469 }
akmhoque157b0a42014-05-13 00:26:37 -0500470 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500471 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
alvy49b1c0c2014-12-19 13:57:46 -0600472 key.append(AdjLsa::TYPE_STRING);
akmhoque31d1d4b2014-05-05 22:08:14 -0500473 removeAdjLsa(key);
474 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500475 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500476 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500477 }
478 }
akmhoque157b0a42014-05-13 00:26:37 -0500479 else {
akmhoque674b0b12014-05-20 14:33:28 -0500480 m_nlsr.setIsBuildAdjLsaSheduled(true);
akmhoque31d1d4b2014-05-05 22:08:14 -0500481 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
482 m_nlsr.getConfParameter().getInterestResendTime();
Vince Lehman7c603292014-09-11 17:48:16 -0500483 m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
Vince Lehman50df6b72015-03-03 12:06:40 -0600484 ndn::bind(&Lsdb::buildAdjLsa, this));
akmhoque53353462014-04-22 08:43:45 -0500485 }
486}
487
488
489bool
490Lsdb::addAdjLsa(AdjLsa& alsa)
491{
492 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
493 m_adjLsdb.end(),
494 bind(adjLsaCompareByKey, _1,
495 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500496 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500497 m_adjLsdb.push_back(alsa);
498 return true;
499 }
500 return false;
501}
502
akmhoqueb6450b12014-04-24 00:01:03 -0500503AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500504Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500505{
506 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
507 m_adjLsdb.end(),
508 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500509 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500510 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500511 }
akmhoqueb6450b12014-04-24 00:01:03 -0500512 return 0;
akmhoque53353462014-04-22 08:43:45 -0500513}
514
515
516bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500517Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500518{
akmhoqueb6450b12014-04-24 00:01:03 -0500519 AdjLsa* adjLsaCheck = findAdjLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500520 if (adjLsaCheck != 0) {
521 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500522 return true;
523 }
akmhoque157b0a42014-05-13 00:26:37 -0500524 else {
akmhoque53353462014-04-22 08:43:45 -0500525 return false;
526 }
527 }
528 return true;
529}
530
531
532ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500533Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
534 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500535{
Vince Lehman7c603292014-09-11 17:48:16 -0500536 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
537 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500538}
539
540bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500541Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500542{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700543 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500544 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500545 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500546 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500547 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500548 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500549 addAdjLsa(alsa);
akmhoque31d1d4b2014-05-05 22:08:14 -0500550 alsa.addNptEntries(m_nlsr);
551 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500552 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500553 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
554 ndn::time::system_clock::now();
555 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500556 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500557 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500558 alsa.getLsSeqNo(), timeToExpire);
559 }
akmhoque157b0a42014-05-13 00:26:37 -0500560 else {
561 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500562 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500563 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500564 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500565 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500566 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500567 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500568 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500569 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500570 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500571 }
akmhoque157b0a42014-05-13 00:26:37 -0500572 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500573 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
574 ndn::time::system_clock::now();
575 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500576 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500577 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
578 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500579 alsa.getLsSeqNo(),
580 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500581 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500582 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500583 }
584 }
585 return true;
586}
587
588bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500589Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500590{
akmhoque31d1d4b2014-05-05 22:08:14 -0500591 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
alvy49b1c0c2014-12-19 13:57:46 -0600592 AdjLsa::TYPE_STRING,
akmhoque31d1d4b2014-05-05 22:08:14 -0500593 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500594 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500595 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
596 m_nlsr.getAdjacencyList());
Vince Lehman904c2412014-09-23 19:36:11 -0500597
akmhoque31d1d4b2014-05-05 22:08:14 -0500598 m_nlsr.getSequencingManager().increaseAdjLsaSeq();
Vince Lehman904c2412014-09-23 19:36:11 -0500599
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600600 m_sync.publishRoutingUpdate();
Vince Lehman904c2412014-09-23 19:36:11 -0500601
Vince Lehman9d097802015-03-16 17:55:59 -0500602 return installAdjLsa(adjLsa);
akmhoque53353462014-04-22 08:43:45 -0500603}
604
605bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500606Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500607{
608 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
609 m_adjLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500610 ndn::bind(adjLsaCompareByKey, _1, key));
611 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500612 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500613 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500614 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500615 m_adjLsdb.erase(it);
616 return true;
617 }
618 return false;
619}
620
621bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500622Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500623{
624 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
625 m_adjLsdb.end(),
626 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500627 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500628 return false;
629 }
630 return true;
631}
632
Jiewen Tana0497d82015-02-02 21:59:18 -0800633const std::list<AdjLsa>&
akmhoque53353462014-04-22 08:43:45 -0500634Lsdb::getAdjLsdb()
635{
636 return m_adjLsdb;
637}
638
639void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700640Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500641{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700642 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500643}
644
645void
646Lsdb::setThisRouterPrefix(string trp)
647{
648 m_thisRouterPrefix = trp;
649}
650
651void
akmhoque31d1d4b2014-05-05 22:08:14 -0500652Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500653{
akmhoque674b0b12014-05-20 14:33:28 -0500654 _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called");
655 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500656 NameLsa* chkNameLsa = findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500657 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500658 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500659 if (chkNameLsa->getLsSeqNo() == seqNo) {
660 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500661 _LOG_DEBUG("Own Name LSA, so refreshing it");
662 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500663 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500664 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500665 m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500666 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500667 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500668 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500669 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500670 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500671 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700672 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600673 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500674 }
akmhoque157b0a42014-05-13 00:26:37 -0500675 else {
akmhoque674b0b12014-05-20 14:33:28 -0500676 _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500677 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500678 }
679 }
680 }
681}
682
683void
akmhoque31d1d4b2014-05-05 22:08:14 -0500684Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500685{
akmhoque674b0b12014-05-20 14:33:28 -0500686 _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
687 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500688 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500689 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500690 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500691 if (chkAdjLsa->getLsSeqNo() == seqNo) {
692 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500693 _LOG_DEBUG("Own Adj LSA, so refreshing it");
694 _LOG_DEBUG("Deleting Adj Lsa");
695 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500696 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500697 m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500698 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500699 _LOG_DEBUG("Adding Adj Lsa");
700 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500701 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500702 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500703 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700704 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600705 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500706 }
akmhoque157b0a42014-05-13 00:26:37 -0500707 else {
akmhoque674b0b12014-05-20 14:33:28 -0500708 _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500709 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500710 }
711 // schedule Routing table calculaiton
akmhoque31d1d4b2014-05-05 22:08:14 -0500712 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500713 }
714 }
715}
716
717void
akmhoque31d1d4b2014-05-05 22:08:14 -0500718Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500719 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500720{
akmhoque674b0b12014-05-20 14:33:28 -0500721 _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
722 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500723 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500724 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500725 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500726 if (chkCorLsa->getLsSeqNo() == seqNo) {
727 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500728 _LOG_DEBUG("Own Cor LSA, so refreshing it");
729 _LOG_DEBUG("Deleting Coordinate Lsa");
730 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500731 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500732 m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500733 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500734 _LOG_DEBUG("Adding Coordinate Lsa");
735 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500736 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500737 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
738 chkCorLsa->getKey(),
739 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700740 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600741 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500742 }
akmhoque157b0a42014-05-13 00:26:37 -0500743 else {
akmhoque674b0b12014-05-20 14:33:28 -0500744 _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500745 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500746 }
akmhoque157b0a42014-05-13 00:26:37 -0500747 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500748 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500749 }
750 }
751 }
752}
753
754
755void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700756Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500757 steady_clock::TimePoint deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500758{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500759 if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) {
760 deadline = steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700761 }
762
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500763 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
764
akmhoque31d1d4b2014-05-05 22:08:14 -0500765 ndn::Interest interest(interestName);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500766 uint64_t seqNo = interestName[-1].toNumber();
767
768 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
769 m_highestSeqNo[lsaName] = seqNo;
770 }
771 else if (seqNo > m_highestSeqNo[lsaName]) {
772 m_highestSeqNo[lsaName] = seqNo;
773 }
774 else if (seqNo < m_highestSeqNo[lsaName]) {
775 return;
776 }
777
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700778 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500779
780 _LOG_DEBUG("Expressing Interest for LSA: " << interestName << " Seq number: " << seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500781 m_nlsr.getNlsrFace().expressInterest(interest,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700782 ndn::bind(&Lsdb::onContent,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500783 this, _2, deadline, lsaName, seqNo),
akmhoque31d1d4b2014-05-05 22:08:14 -0500784 ndn::bind(&Lsdb::processInterestTimedOut,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500785 this, _1, timeoutCount, deadline, lsaName, seqNo));
akmhoque31d1d4b2014-05-05 22:08:14 -0500786}
787
788void
789Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
790{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500791 const ndn::Name& interestName(interest.getName());
792 _LOG_DEBUG("Interest received for LSA: " << interestName);
793
akmhoque31d1d4b2014-05-05 22:08:14 -0500794 string chkString("LSA");
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500795 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
796
akmhoque157b0a42014-05-13 00:26:37 -0500797 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500798
799 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
800 originRouter.append(interestName.getSubName(lsaPosition + 1,
801 interest.getName().size() - lsaPosition - 3));
802
803 uint64_t seqNo = interestName[-1].toNumber();
804 _LOG_DEBUG("LSA sequence number from interest: " << seqNo);
805
806 std::string interestedLsType = interestName[-2].toUri();
807
alvy49b1c0c2014-12-19 13:57:46 -0600808 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500809 processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500810 }
alvy49b1c0c2014-12-19 13:57:46 -0600811 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500812 processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500813 }
alvy49b1c0c2014-12-19 13:57:46 -0600814 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500815 processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500816 }
akmhoque157b0a42014-05-13 00:26:37 -0500817 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500818 _LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500819 }
820 }
821}
822
823void
akmhoque69c9aa92014-07-23 15:15:05 -0500824Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
825{
826 ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
827 data->setName(ndn::Name(interest.getName()).appendVersion());
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700828 data->setFreshnessPeriod(m_lsaRefreshTime);
akmhoque69c9aa92014-07-23 15:15:05 -0500829 data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
830 m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
akmhoquedfe615f2014-07-27 14:12:21 -0500831 ndn::SignatureSha256WithRsa signature(data->getSignature());
832 ndn::Name signingCertName = signature.getKeyLocator().getName();
akmhoque69c9aa92014-07-23 15:15:05 -0500833 _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
akmhoquedfe615f2014-07-27 14:12:21 -0500834 _LOG_DEBUG("Data signed with: " << signingCertName);
akmhoque69c9aa92014-07-23 15:15:05 -0500835 m_nlsr.getNlsrFace().put(*data);
836}
837
838void
akmhoque31d1d4b2014-05-05 22:08:14 -0500839Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
840 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500841 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500842{
843 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500844 if (nameLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500845 if (nameLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500846 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500847 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500848 }
849 }
850}
851
852void
853Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
854 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500855 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500856{
857 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500858 if (adjLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500859 if (adjLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500860 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500861 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500862 }
863 }
864}
865
866void
867Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
868 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500869 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500870{
871 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500872 if (corLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500873 if (corLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500874 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500875 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500876 }
877 }
878}
879
880void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700881Lsdb::onContent(const ndn::Data& data,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500882 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
883 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500884{
akmhoquedfe615f2014-07-27 14:12:21 -0500885 _LOG_DEBUG("Received data for LSA(name): " << data.getName());
886 if (data.getSignature().hasKeyLocator()) {
887 if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
888 _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
889 }
890 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700891 m_nlsr.getValidator().validate(data,
892 ndn::bind(&Lsdb::onContentValidated, this, _1),
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700893 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500894 deadline, lsaName, seqNo));
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700895
896}
897
898void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700899Lsdb::retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500900 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
901 uint64_t seqNo)
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700902{
903 _LOG_DEBUG("Retrying validation of LSA(name): " << data->getName());
904 if (data->getSignature().hasKeyLocator()) {
905 if (data->getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
906 _LOG_DEBUG("Data signed with: " << data->getSignature().getKeyLocator().getName());
907 }
908 }
909 m_nlsr.getValidator().validate(*data,
910 ndn::bind(&Lsdb::onContentValidated, this, _1),
911 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500912 deadline, lsaName, seqNo));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700913}
914
915void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700916Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
917{
918 const ndn::Name& dataName = data->getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500919 _LOG_DEBUG("Data validation successful for LSA: " << dataName);
920
akmhoque31d1d4b2014-05-05 22:08:14 -0500921 string chkString("LSA");
922 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500923
akmhoque157b0a42014-05-13 00:26:37 -0500924 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500925
926 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
927 originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 4));
928
929 uint64_t seqNo = dataName[-2].toNumber();
930 string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
931
932 std::string interestedLsType = dataName[-3].toUri();
933
alvy49b1c0c2014-12-19 13:57:46 -0600934 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500935 processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500936 }
alvy49b1c0c2014-12-19 13:57:46 -0600937 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500938 processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500939 }
alvy49b1c0c2014-12-19 13:57:46 -0600940 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500941 processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500942 }
akmhoque157b0a42014-05-13 00:26:37 -0500943 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500944 _LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500945 }
946 }
947}
948
949void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700950Lsdb::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
951 const std::string& msg,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500952 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
953 uint64_t seqNo)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700954{
akmhoque2f423352014-06-03 11:49:35 -0500955 _LOG_DEBUG("Validation Error: " << msg);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700956
957 // Delay re-validation by LSA Interest Lifetime. When error callback will have an error
958 // code, re-validation should be done only when some keys from certification chain failed
959 // to be fetched. After that change, delaying will no longer be necessary.
960
961 // Stop retrying if delayed re-validation will be scheduled pass the deadline
962 if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500963
964 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
965
966 if (it != m_highestSeqNo.end() && it->second == seqNo) {
967 _LOG_DEBUG("Scheduling revalidation attempt");
968 m_scheduler.scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
969 ndn::bind(&Lsdb::retryContentValidation, this, data,
970 deadline, lsaName, seqNo));
971 }
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700972 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700973}
974
975void
akmhoque31d1d4b2014-05-05 22:08:14 -0500976Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500977 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500978{
akmhoque157b0a42014-05-13 00:26:37 -0500979 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500980 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500981 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500982 installNameLsa(nameLsa);
983 }
akmhoque157b0a42014-05-13 00:26:37 -0500984 else {
akmhoque2f423352014-06-03 11:49:35 -0500985 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500986 }
987 }
988}
989
990void
991Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500992 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500993{
akmhoque157b0a42014-05-13 00:26:37 -0500994 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500995 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500996 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500997 installAdjLsa(adjLsa);
998 }
akmhoque157b0a42014-05-13 00:26:37 -0500999 else {
akmhoque2f423352014-06-03 11:49:35 -05001000 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001001 }
1002 }
1003}
1004
1005void
1006Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001007 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001008{
akmhoque157b0a42014-05-13 00:26:37 -05001009 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001010 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001011 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001012 installCoordinateLsa(corLsa);
1013 }
akmhoque157b0a42014-05-13 00:26:37 -05001014 else {
akmhoque2f423352014-06-03 11:49:35 -05001015 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001016 }
1017 }
1018}
1019
1020void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001021Lsdb::processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001022 const ndn::time::steady_clock::TimePoint& deadline, ndn::Name lsaName,
1023 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001024{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001025 const ndn::Name& interestName = interest.getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001026 _LOG_DEBUG("Interest timed out for LSA: " << interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001027
1028 if (ndn::time::steady_clock::now() < deadline) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001029
1030 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
1031
1032 if (it != m_highestSeqNo.end() && it->second == seqNo) {
1033 expressInterest(interestName, retransmitNo + 1, deadline);
1034 }
akmhoque06986672014-05-27 13:55:53 -05001035 }
akmhoque31d1d4b2014-05-05 22:08:14 -05001036}
1037
akmhoquec7a79b22014-05-26 08:06:19 -05001038ndn::time::system_clock::TimePoint
1039Lsdb::getLsaExpirationTimePoint()
1040{
1041 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1042 expirationTimePoint = expirationTimePoint +
1043 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1044 return expirationTimePoint;
1045}
akmhoque31d1d4b2014-05-05 22:08:14 -05001046
1047void
akmhoque2f423352014-06-03 11:49:35 -05001048Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001049{
akmhoque2f423352014-06-03 11:49:35 -05001050 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001051 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001052 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001053 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001054 }
1055}
1056
1057//-----utility function -----
1058bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001059Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001060{
alvy49b1c0c2014-12-19 13:57:46 -06001061 if (lsType == NameLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001062 return doesNameLsaExist(key);
1063 }
alvy49b1c0c2014-12-19 13:57:46 -06001064 else if (lsType == AdjLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001065 return doesAdjLsaExist(key);
1066 }
alvy49b1c0c2014-12-19 13:57:46 -06001067 else if (lsType == CoordinateLsa::TYPE_STRING) {
akmhoqueb6450b12014-04-24 00:01:03 -05001068 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001069 }
1070 return false;
1071}
1072
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001073} // namespace nlsr