blob: 42f0f16a0f1c45c9839db7261709bf5970c8406d [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoque53353462014-04-22 08:43:45 -050023#include <string>
24#include <utility>
akmhoque157b0a42014-05-13 00:26:37 -050025
akmhoque53353462014-04-22 08:43:45 -050026#include "lsdb.hpp"
27#include "nlsr.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050028#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050029#include "utility/name-helper.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050030#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050031
32namespace nlsr {
33
akmhoque674b0b12014-05-20 14:33:28 -050034INIT_LOGGER("Lsdb");
35
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
252// Cor LSA and LSDB related Functions start here
253
akmhoque53353462014-04-22 08:43:45 -0500254static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500255corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500256{
257 return clsa.getKey() == key;
258}
259
260bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500261Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500262{
akmhoque31d1d4b2014-05-05 22:08:14 -0500263 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
alvy49b1c0c2014-12-19 13:57:46 -0600264 CoordinateLsa::TYPE_STRING,
akmhoque31d1d4b2014-05-05 22:08:14 -0500265 m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500266 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500267 m_nlsr.getConfParameter().getCorR(),
268 m_nlsr.getConfParameter().getCorTheta());
269 m_nlsr.getSequencingManager().increaseCorLsaSeq();
270 installCoordinateLsa(corLsa);
akmhoque53353462014-04-22 08:43:45 -0500271 return true;
272}
273
akmhoqueb6450b12014-04-24 00:01:03 -0500274CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500275Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500276{
akmhoqueb6450b12014-04-24 00:01:03 -0500277 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
278 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500279 ndn::bind(corLsaCompareByKey, _1, key));
280 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500281 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500282 }
akmhoqueb6450b12014-04-24 00:01:03 -0500283 return 0;
akmhoque53353462014-04-22 08:43:45 -0500284}
285
286bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500287Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500288{
akmhoqueb6450b12014-04-24 00:01:03 -0500289 CoordinateLsa* clsa = findCoordinateLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500290 if (clsa != 0) {
291 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500292 return true;
293 }
akmhoque157b0a42014-05-13 00:26:37 -0500294 else {
akmhoque53353462014-04-22 08:43:45 -0500295 return false;
296 }
297 }
298 return true;
299}
300
301ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500302Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500303 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500304{
Vince Lehman7c603292014-09-11 17:48:16 -0500305 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
306 ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
307 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500308}
309
310bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500311Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500312{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700313 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500314 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500315 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500316 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500317 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500318 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500319 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500320
akmhoque157b0a42014-05-13 00:26:37 -0500321 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500322 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
323 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500324 }
akmhoque157b0a42014-05-13 00:26:37 -0500325 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500326 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500327 }
akmhoque157b0a42014-05-13 00:26:37 -0500328 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500329 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
330 ndn::time::system_clock::now();
331 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500332 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500333 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500334 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500335 }
akmhoque157b0a42014-05-13 00:26:37 -0500336 else {
337 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500338 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500339 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500340 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500341 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500342 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500343 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500344 chkCorLsa->setCorRadius(clsa.getCorRadius());
345 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500346 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500347 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500348 }
349 }
akmhoque157b0a42014-05-13 00:26:37 -0500350 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500351 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
352 ndn::time::system_clock::now();
353 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500354 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500355 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
356 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500357 clsa.getLsSeqNo(),
358 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500359 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500360 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500361 }
362 }
363 return true;
364}
365
366bool
akmhoqueb6450b12014-04-24 00:01:03 -0500367Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500368{
akmhoqueb6450b12014-04-24 00:01:03 -0500369 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
370 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500371 ndn::bind(corLsaCompareByKey, _1,
372 clsa.getKey()));
373 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500374 m_corLsdb.push_back(clsa);
375 return true;
376 }
377 return false;
378}
379
380bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500381Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500382{
akmhoqueb6450b12014-04-24 00:01:03 -0500383 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
384 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500385 ndn::bind(corLsaCompareByKey,
386 _1, key));
387 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500388 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500389 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500390 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500391 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500392 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
393 (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500394 }
395 m_corLsdb.erase(it);
396 return true;
397 }
398 return false;
399}
400
401bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500402Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500403{
akmhoqueb6450b12014-04-24 00:01:03 -0500404 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
405 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500406 ndn::bind(corLsaCompareByKey,
407 _1, key));
408 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500409 return false;
410 }
411 return true;
412}
413
414void
akmhoque2f423352014-06-03 11:49:35 -0500415Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500416{
akmhoque2f423352014-06-03 11:49:35 -0500417 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500418 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500419 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500420 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500421 }
422}
423
akmhoque53353462014-04-22 08:43:45 -0500424// Adj LSA and LSDB related function starts here
425
426static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500427adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500428{
429 return alsa.getKey() == key;
430}
431
akmhoque53353462014-04-22 08:43:45 -0500432void
akmhoque31d1d4b2014-05-05 22:08:14 -0500433Lsdb::scheduledAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500434{
akmhoque674b0b12014-05-20 14:33:28 -0500435 _LOG_DEBUG("scheduledAdjLsaBuild Called");
436 m_nlsr.setIsBuildAdjLsaSheduled(false);
akmhoque157b0a42014-05-13 00:26:37 -0500437 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500438 int adjBuildCount = m_nlsr.getAdjBuildCount();
akmhoque157b0a42014-05-13 00:26:37 -0500439 if (adjBuildCount > 0) {
440 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500441 _LOG_DEBUG("Building and installing Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500442 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500443 }
akmhoque157b0a42014-05-13 00:26:37 -0500444 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500445 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
alvy49b1c0c2014-12-19 13:57:46 -0600446 key.append(AdjLsa::TYPE_STRING);
akmhoque31d1d4b2014-05-05 22:08:14 -0500447 removeAdjLsa(key);
448 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500449 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500450 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500451 }
452 }
akmhoque157b0a42014-05-13 00:26:37 -0500453 else {
akmhoque674b0b12014-05-20 14:33:28 -0500454 m_nlsr.setIsBuildAdjLsaSheduled(true);
akmhoque31d1d4b2014-05-05 22:08:14 -0500455 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
456 m_nlsr.getConfParameter().getInterestResendTime();
Vince Lehman7c603292014-09-11 17:48:16 -0500457 m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
458 ndn::bind(&Lsdb::scheduledAdjLsaBuild, this));
akmhoque53353462014-04-22 08:43:45 -0500459 }
460}
461
462
463bool
464Lsdb::addAdjLsa(AdjLsa& alsa)
465{
466 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
467 m_adjLsdb.end(),
468 bind(adjLsaCompareByKey, _1,
469 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500470 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500471 m_adjLsdb.push_back(alsa);
472 return true;
473 }
474 return false;
475}
476
akmhoqueb6450b12014-04-24 00:01:03 -0500477AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500478Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500479{
480 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
481 m_adjLsdb.end(),
482 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500483 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500484 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500485 }
akmhoqueb6450b12014-04-24 00:01:03 -0500486 return 0;
akmhoque53353462014-04-22 08:43:45 -0500487}
488
489
490bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500491Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500492{
akmhoqueb6450b12014-04-24 00:01:03 -0500493 AdjLsa* adjLsaCheck = findAdjLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500494 if (adjLsaCheck != 0) {
495 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500496 return true;
497 }
akmhoque157b0a42014-05-13 00:26:37 -0500498 else {
akmhoque53353462014-04-22 08:43:45 -0500499 return false;
500 }
501 }
502 return true;
503}
504
505
506ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500507Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
508 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500509{
Vince Lehman7c603292014-09-11 17:48:16 -0500510 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
511 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500512}
513
514bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500515Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500516{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700517 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500518 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500519 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500520 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500521 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500522 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500523 addAdjLsa(alsa);
akmhoque31d1d4b2014-05-05 22:08:14 -0500524 alsa.addNptEntries(m_nlsr);
525 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500526 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500527 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
528 ndn::time::system_clock::now();
529 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500530 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500531 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500532 alsa.getLsSeqNo(), timeToExpire);
533 }
akmhoque157b0a42014-05-13 00:26:37 -0500534 else {
535 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500536 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500537 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500538 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500539 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500540 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500541 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500542 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500543 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500544 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500545 }
akmhoque157b0a42014-05-13 00:26:37 -0500546 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500547 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
548 ndn::time::system_clock::now();
549 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500550 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500551 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
552 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500553 alsa.getLsSeqNo(),
554 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500555 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500556 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500557 }
558 }
559 return true;
560}
561
562bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500563Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500564{
akmhoque31d1d4b2014-05-05 22:08:14 -0500565 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
alvy49b1c0c2014-12-19 13:57:46 -0600566 AdjLsa::TYPE_STRING,
akmhoque31d1d4b2014-05-05 22:08:14 -0500567 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500568 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500569 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
570 m_nlsr.getAdjacencyList());
Vince Lehman904c2412014-09-23 19:36:11 -0500571
akmhoque31d1d4b2014-05-05 22:08:14 -0500572 m_nlsr.getSequencingManager().increaseAdjLsaSeq();
Vince Lehman904c2412014-09-23 19:36:11 -0500573
574 bool isInstalled = installAdjLsa(adjLsa);
575
576 // Delay Sync prefix registration until the first Adjacency LSA is built
577 if (isInstalled && !m_hasSyncPrefixBeenRegistered) {
578 m_nlsr.getSyncLogicHandler().createSyncSocket();
579 m_hasSyncPrefixBeenRegistered = true;
580 }
581
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600582 m_sync.publishRoutingUpdate();
Vince Lehman904c2412014-09-23 19:36:11 -0500583
584 return isInstalled;
akmhoque53353462014-04-22 08:43:45 -0500585}
586
587bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500588Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500589{
590 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
591 m_adjLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500592 ndn::bind(adjLsaCompareByKey, _1, key));
593 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500594 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500595 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500596 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500597 m_adjLsdb.erase(it);
598 return true;
599 }
600 return false;
601}
602
603bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500604Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500605{
606 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
607 m_adjLsdb.end(),
608 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500609 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500610 return false;
611 }
612 return true;
613}
614
615std::list<AdjLsa>&
616Lsdb::getAdjLsdb()
617{
618 return m_adjLsdb;
619}
620
621void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700622Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500623{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700624 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500625}
626
627void
628Lsdb::setThisRouterPrefix(string trp)
629{
630 m_thisRouterPrefix = trp;
631}
632
633void
akmhoque31d1d4b2014-05-05 22:08:14 -0500634Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500635{
akmhoque674b0b12014-05-20 14:33:28 -0500636 _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called");
637 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500638 NameLsa* chkNameLsa = findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500639 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500640 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500641 if (chkNameLsa->getLsSeqNo() == seqNo) {
642 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500643 _LOG_DEBUG("Own Name LSA, so refreshing it");
644 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500645 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500646 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500647 m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500648 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500649 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500650 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500651 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500652 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500653 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700654 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600655 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500656 }
akmhoque157b0a42014-05-13 00:26:37 -0500657 else {
akmhoque674b0b12014-05-20 14:33:28 -0500658 _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500659 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500660 }
661 }
662 }
663}
664
665void
akmhoque31d1d4b2014-05-05 22:08:14 -0500666Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500667{
akmhoque674b0b12014-05-20 14:33:28 -0500668 _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
669 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500670 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500671 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500672 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500673 if (chkAdjLsa->getLsSeqNo() == seqNo) {
674 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500675 _LOG_DEBUG("Own Adj LSA, so refreshing it");
676 _LOG_DEBUG("Deleting Adj Lsa");
677 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500678 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500679 m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500680 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500681 _LOG_DEBUG("Adding Adj Lsa");
682 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500683 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500684 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500685 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700686 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600687 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500688 }
akmhoque157b0a42014-05-13 00:26:37 -0500689 else {
akmhoque674b0b12014-05-20 14:33:28 -0500690 _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500691 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500692 }
693 // schedule Routing table calculaiton
akmhoque31d1d4b2014-05-05 22:08:14 -0500694 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500695 }
696 }
697}
698
699void
akmhoque31d1d4b2014-05-05 22:08:14 -0500700Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500701 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500702{
akmhoque674b0b12014-05-20 14:33:28 -0500703 _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
704 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500705 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500706 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500707 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500708 if (chkCorLsa->getLsSeqNo() == seqNo) {
709 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500710 _LOG_DEBUG("Own Cor LSA, so refreshing it");
711 _LOG_DEBUG("Deleting Coordinate Lsa");
712 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500713 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500714 m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500715 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500716 _LOG_DEBUG("Adding Coordinate Lsa");
717 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500718 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500719 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
720 chkCorLsa->getKey(),
721 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700722 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600723 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500724 }
akmhoque157b0a42014-05-13 00:26:37 -0500725 else {
akmhoque674b0b12014-05-20 14:33:28 -0500726 _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500727 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500728 }
akmhoque157b0a42014-05-13 00:26:37 -0500729 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500730 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500731 }
732 }
733 }
734}
735
736
737void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700738Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500739 steady_clock::TimePoint deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500740{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500741 if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) {
742 deadline = steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700743 }
744
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500745 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
746
akmhoque31d1d4b2014-05-05 22:08:14 -0500747 ndn::Interest interest(interestName);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500748 uint64_t seqNo = interestName[-1].toNumber();
749
750 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
751 m_highestSeqNo[lsaName] = seqNo;
752 }
753 else if (seqNo > m_highestSeqNo[lsaName]) {
754 m_highestSeqNo[lsaName] = seqNo;
755 }
756 else if (seqNo < m_highestSeqNo[lsaName]) {
757 return;
758 }
759
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700760 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500761
762 _LOG_DEBUG("Expressing Interest for LSA: " << interestName << " Seq number: " << seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500763 m_nlsr.getNlsrFace().expressInterest(interest,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700764 ndn::bind(&Lsdb::onContent,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500765 this, _2, deadline, lsaName, seqNo),
akmhoque31d1d4b2014-05-05 22:08:14 -0500766 ndn::bind(&Lsdb::processInterestTimedOut,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500767 this, _1, timeoutCount, deadline, lsaName, seqNo));
akmhoque31d1d4b2014-05-05 22:08:14 -0500768}
769
770void
771Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
772{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500773 const ndn::Name& interestName(interest.getName());
774 _LOG_DEBUG("Interest received for LSA: " << interestName);
775
akmhoque31d1d4b2014-05-05 22:08:14 -0500776 string chkString("LSA");
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500777 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
778
akmhoque157b0a42014-05-13 00:26:37 -0500779 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500780
781 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
782 originRouter.append(interestName.getSubName(lsaPosition + 1,
783 interest.getName().size() - lsaPosition - 3));
784
785 uint64_t seqNo = interestName[-1].toNumber();
786 _LOG_DEBUG("LSA sequence number from interest: " << seqNo);
787
788 std::string interestedLsType = interestName[-2].toUri();
789
alvy49b1c0c2014-12-19 13:57:46 -0600790 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500791 processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500792 }
alvy49b1c0c2014-12-19 13:57:46 -0600793 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500794 processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500795 }
alvy49b1c0c2014-12-19 13:57:46 -0600796 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500797 processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500798 }
akmhoque157b0a42014-05-13 00:26:37 -0500799 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500800 _LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500801 }
802 }
803}
804
805void
akmhoque69c9aa92014-07-23 15:15:05 -0500806Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
807{
808 ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
809 data->setName(ndn::Name(interest.getName()).appendVersion());
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700810 data->setFreshnessPeriod(m_lsaRefreshTime);
akmhoque69c9aa92014-07-23 15:15:05 -0500811 data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
812 m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
akmhoquedfe615f2014-07-27 14:12:21 -0500813 ndn::SignatureSha256WithRsa signature(data->getSignature());
814 ndn::Name signingCertName = signature.getKeyLocator().getName();
akmhoque69c9aa92014-07-23 15:15:05 -0500815 _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
akmhoquedfe615f2014-07-27 14:12:21 -0500816 _LOG_DEBUG("Data signed with: " << signingCertName);
akmhoque69c9aa92014-07-23 15:15:05 -0500817 m_nlsr.getNlsrFace().put(*data);
818}
819
820void
akmhoque31d1d4b2014-05-05 22:08:14 -0500821Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
822 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500823 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500824{
825 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500826 if (nameLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500827 if (nameLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500828 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500829 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500830 }
831 }
832}
833
834void
835Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
836 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500837 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500838{
839 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500840 if (adjLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500841 if (adjLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500842 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500843 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500844 }
845 }
846}
847
848void
849Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
850 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500851 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500852{
853 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500854 if (corLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500855 if (corLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500856 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500857 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500858 }
859 }
860}
861
862void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700863Lsdb::onContent(const ndn::Data& data,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500864 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
865 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500866{
akmhoquedfe615f2014-07-27 14:12:21 -0500867 _LOG_DEBUG("Received data for LSA(name): " << data.getName());
868 if (data.getSignature().hasKeyLocator()) {
869 if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
870 _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
871 }
872 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700873 m_nlsr.getValidator().validate(data,
874 ndn::bind(&Lsdb::onContentValidated, this, _1),
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700875 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500876 deadline, lsaName, seqNo));
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700877
878}
879
880void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700881Lsdb::retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500882 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
883 uint64_t seqNo)
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700884{
885 _LOG_DEBUG("Retrying validation of 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 }
891 m_nlsr.getValidator().validate(*data,
892 ndn::bind(&Lsdb::onContentValidated, this, _1),
893 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500894 deadline, lsaName, seqNo));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700895}
896
897void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700898Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
899{
900 const ndn::Name& dataName = data->getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500901 _LOG_DEBUG("Data validation successful for LSA: " << dataName);
902
akmhoque31d1d4b2014-05-05 22:08:14 -0500903 string chkString("LSA");
904 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500905
akmhoque157b0a42014-05-13 00:26:37 -0500906 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500907
908 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
909 originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 4));
910
911 uint64_t seqNo = dataName[-2].toNumber();
912 string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
913
914 std::string interestedLsType = dataName[-3].toUri();
915
alvy49b1c0c2014-12-19 13:57:46 -0600916 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500917 processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500918 }
alvy49b1c0c2014-12-19 13:57:46 -0600919 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500920 processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500921 }
alvy49b1c0c2014-12-19 13:57:46 -0600922 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500923 processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500924 }
akmhoque157b0a42014-05-13 00:26:37 -0500925 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500926 _LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500927 }
928 }
929}
930
931void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700932Lsdb::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
933 const std::string& msg,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500934 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
935 uint64_t seqNo)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700936{
akmhoque2f423352014-06-03 11:49:35 -0500937 _LOG_DEBUG("Validation Error: " << msg);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700938
939 // Delay re-validation by LSA Interest Lifetime. When error callback will have an error
940 // code, re-validation should be done only when some keys from certification chain failed
941 // to be fetched. After that change, delaying will no longer be necessary.
942
943 // Stop retrying if delayed re-validation will be scheduled pass the deadline
944 if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500945
946 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
947
948 if (it != m_highestSeqNo.end() && it->second == seqNo) {
949 _LOG_DEBUG("Scheduling revalidation attempt");
950 m_scheduler.scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
951 ndn::bind(&Lsdb::retryContentValidation, this, data,
952 deadline, lsaName, seqNo));
953 }
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700954 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700955}
956
957void
akmhoque31d1d4b2014-05-05 22:08:14 -0500958Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500959 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500960{
akmhoque157b0a42014-05-13 00:26:37 -0500961 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500962 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500963 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500964 installNameLsa(nameLsa);
965 }
akmhoque157b0a42014-05-13 00:26:37 -0500966 else {
akmhoque2f423352014-06-03 11:49:35 -0500967 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500968 }
969 }
970}
971
972void
973Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500974 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500975{
akmhoque157b0a42014-05-13 00:26:37 -0500976 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500977 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500978 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500979 installAdjLsa(adjLsa);
980 }
akmhoque157b0a42014-05-13 00:26:37 -0500981 else {
akmhoque2f423352014-06-03 11:49:35 -0500982 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500983 }
984 }
985}
986
987void
988Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500989 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500990{
akmhoque157b0a42014-05-13 00:26:37 -0500991 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500992 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500993 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500994 installCoordinateLsa(corLsa);
995 }
akmhoque157b0a42014-05-13 00:26:37 -0500996 else {
akmhoque2f423352014-06-03 11:49:35 -0500997 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500998 }
999 }
1000}
1001
1002void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001003Lsdb::processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001004 const ndn::time::steady_clock::TimePoint& deadline, ndn::Name lsaName,
1005 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001006{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001007 const ndn::Name& interestName = interest.getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001008 _LOG_DEBUG("Interest timed out for LSA: " << interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001009
1010 if (ndn::time::steady_clock::now() < deadline) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001011
1012 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
1013
1014 if (it != m_highestSeqNo.end() && it->second == seqNo) {
1015 expressInterest(interestName, retransmitNo + 1, deadline);
1016 }
akmhoque06986672014-05-27 13:55:53 -05001017 }
akmhoque31d1d4b2014-05-05 22:08:14 -05001018}
1019
akmhoquec7a79b22014-05-26 08:06:19 -05001020ndn::time::system_clock::TimePoint
1021Lsdb::getLsaExpirationTimePoint()
1022{
1023 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1024 expirationTimePoint = expirationTimePoint +
1025 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1026 return expirationTimePoint;
1027}
akmhoque31d1d4b2014-05-05 22:08:14 -05001028
1029void
akmhoque2f423352014-06-03 11:49:35 -05001030Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001031{
akmhoque2f423352014-06-03 11:49:35 -05001032 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001033 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001034 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001035 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001036 }
1037}
1038
1039//-----utility function -----
1040bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001041Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001042{
alvy49b1c0c2014-12-19 13:57:46 -06001043 if (lsType == NameLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001044 return doesNameLsaExist(key);
1045 }
alvy49b1c0c2014-12-19 13:57:46 -06001046 else if (lsType == AdjLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001047 return doesAdjLsaExist(key);
1048 }
alvy49b1c0c2014-12-19 13:57:46 -06001049 else if (lsType == CoordinateLsa::TYPE_STRING) {
akmhoqueb6450b12014-04-24 00:01:03 -05001050 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001051 }
1052 return false;
1053}
1054
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001055} // namespace nlsr