blob: 427cc0b279428b355aac5b79fc9c19dbd2697229 [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);
37
akmhoque53353462014-04-22 08:43:45 -050038using namespace std;
39
40void
akmhoque31d1d4b2014-05-05 22:08:14 -050041Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
akmhoque53353462014-04-22 08:43:45 -050042{
Vince Lehman7c603292014-09-11 17:48:16 -050043 m_scheduler.cancelEvent(eid);
akmhoque53353462014-04-22 08:43:45 -050044}
45
46static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050047nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -050048{
49 return nlsa1.getKey() == key;
50}
51
52
53bool
akmhoque31d1d4b2014-05-05 22:08:14 -050054Lsdb::buildAndInstallOwnNameLsa()
akmhoque53353462014-04-22 08:43:45 -050055{
akmhoque31d1d4b2014-05-05 22:08:14 -050056 NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
57 "name",
58 m_nlsr.getSequencingManager().getNameLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -050059 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -050060 m_nlsr.getNamePrefixList());
61 m_nlsr.getSequencingManager().increaseNameLsaSeq();
62 return installNameLsa(nameLsa);
akmhoque53353462014-04-22 08:43:45 -050063}
64
akmhoqueb6450b12014-04-24 00:01:03 -050065NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050066Lsdb::findNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -050067{
68 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
69 m_nameLsdb.end(),
70 bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -050071 if (it != m_nameLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -050072 return &(*it);
akmhoque53353462014-04-22 08:43:45 -050073 }
akmhoqueb6450b12014-04-24 00:01:03 -050074 return 0;
akmhoque53353462014-04-22 08:43:45 -050075}
76
77bool
akmhoque31d1d4b2014-05-05 22:08:14 -050078Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -050079{
akmhoqueb6450b12014-04-24 00:01:03 -050080 NameLsa* nameLsaCheck = findNameLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -050081 if (nameLsaCheck != 0) {
82 if (nameLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -050083 return true;
84 }
akmhoque157b0a42014-05-13 00:26:37 -050085 else {
akmhoque53353462014-04-22 08:43:45 -050086 return false;
87 }
88 }
89 return true;
90}
91
92ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -050093Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
94 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -050095{
Vince Lehman7c603292014-09-11 17:48:16 -050096 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
97 ndn::bind(&Lsdb::exprireOrRefreshNameLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -050098}
99
100bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500101Lsdb::installNameLsa(NameLsa& nlsa)
akmhoque53353462014-04-22 08:43:45 -0500102{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700103 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500104 NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500105 if (chkNameLsa == 0) {
akmhoque53353462014-04-22 08:43:45 -0500106 addNameLsa(nlsa);
akmhoque2f423352014-06-03 11:49:35 -0500107 _LOG_DEBUG("New Name LSA");
108 _LOG_DEBUG("Adding Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500109 nlsa.writeLog();
akmhoque674b0b12014-05-20 14:33:28 -0500110
akmhoque157b0a42014-05-13 00:26:37 -0500111 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500112 m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
113 nlsa.getOrigRouter());
114 std::list<ndn::Name> nameList = nlsa.getNpl().getNameList();
115 for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end();
akmhoque157b0a42014-05-13 00:26:37 -0500116 it++) {
117 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500118 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500119 }
120 }
121 }
akmhoque157b0a42014-05-13 00:26:37 -0500122 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500123 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
124 ndn::time::system_clock::now();
125 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500126 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500127 nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500128 nlsa.getLsSeqNo(),
129 timeToExpire));
130 }
akmhoque157b0a42014-05-13 00:26:37 -0500131 else {
132 if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500133 _LOG_DEBUG("Updated Name LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500134 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500135 chkNameLsa->writeLog();
136 chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500137 chkNameLsa->setExpirationTimePoint(nlsa.getExpirationTimePoint());
akmhoqueb6450b12014-04-24 00:01:03 -0500138 chkNameLsa->getNpl().sort();
akmhoque53353462014-04-22 08:43:45 -0500139 nlsa.getNpl().sort();
akmhoque31d1d4b2014-05-05 22:08:14 -0500140 std::list<ndn::Name> nameToAdd;
akmhoque53353462014-04-22 08:43:45 -0500141 std::set_difference(nlsa.getNpl().getNameList().begin(),
142 nlsa.getNpl().getNameList().end(),
akmhoqueb6450b12014-04-24 00:01:03 -0500143 chkNameLsa->getNpl().getNameList().begin(),
144 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500145 std::inserter(nameToAdd, nameToAdd.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500146 for (std::list<ndn::Name>::iterator it = nameToAdd.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500147 it != nameToAdd.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500148 chkNameLsa->addName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500149 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
150 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500151 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500152 }
153 }
154 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500155 std::list<ndn::Name> nameToRemove;
akmhoqueb6450b12014-04-24 00:01:03 -0500156 std::set_difference(chkNameLsa->getNpl().getNameList().begin(),
157 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500158 nlsa.getNpl().getNameList().begin(),
159 nlsa.getNpl().getNameList().end(),
160 std::inserter(nameToRemove, nameToRemove.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500161 for (std::list<ndn::Name>::iterator it = nameToRemove.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500162 it != nameToRemove.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500163 chkNameLsa->removeName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500164 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
165 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500166 m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500167 }
168 }
169 }
akmhoque157b0a42014-05-13 00:26:37 -0500170 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500171 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
172 ndn::time::system_clock::now();
173 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500174 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500175 cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
176 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500177 nlsa.getLsSeqNo(),
178 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500179 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500180 chkNameLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500181 }
182 }
183 return true;
184}
185
186bool
187Lsdb::addNameLsa(NameLsa& nlsa)
188{
189 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
190 m_nameLsdb.end(),
191 bind(nameLsaCompareByKey, _1,
192 nlsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500193 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500194 m_nameLsdb.push_back(nlsa);
195 return true;
196 }
197 return false;
198}
199
200bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500201Lsdb::removeNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500202{
203 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
204 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500205 ndn::bind(nameLsaCompareByKey, _1, key));
206 if (it != m_nameLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500207 _LOG_DEBUG("Deleting Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500208 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500209 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500210 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500211 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
212 (*it).getOrigRouter());
213 for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500214 nit != (*it).getNpl().getNameList().end(); ++nit) {
215 if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500216 m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500217 }
218 }
219 }
220 m_nameLsdb.erase(it);
221 return true;
222 }
223 return false;
224}
225
226bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500227Lsdb::doesNameLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500228{
229 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
230 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500231 ndn::bind(nameLsaCompareByKey, _1, key));
232 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500233 return false;
234 }
235 return true;
236}
237
238void
akmhoque2f423352014-06-03 11:49:35 -0500239Lsdb::writeNameLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500240{
akmhoque2f423352014-06-03 11:49:35 -0500241 _LOG_DEBUG("---------------Name LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -0500242 for (std::list<NameLsa>::iterator it = m_nameLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500243 it != m_nameLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500244 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500245 }
246}
247
248// Cor LSA and LSDB related Functions start here
249
akmhoque53353462014-04-22 08:43:45 -0500250static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500251corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500252{
253 return clsa.getKey() == key;
254}
255
256bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500257Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500258{
akmhoque31d1d4b2014-05-05 22:08:14 -0500259 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
260 "coordinate",
261 m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500262 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500263 m_nlsr.getConfParameter().getCorR(),
264 m_nlsr.getConfParameter().getCorTheta());
265 m_nlsr.getSequencingManager().increaseCorLsaSeq();
266 installCoordinateLsa(corLsa);
akmhoque53353462014-04-22 08:43:45 -0500267 return true;
268}
269
akmhoqueb6450b12014-04-24 00:01:03 -0500270CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500271Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500272{
akmhoqueb6450b12014-04-24 00:01:03 -0500273 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
274 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500275 ndn::bind(corLsaCompareByKey, _1, key));
276 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500277 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500278 }
akmhoqueb6450b12014-04-24 00:01:03 -0500279 return 0;
akmhoque53353462014-04-22 08:43:45 -0500280}
281
282bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500283Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500284{
akmhoqueb6450b12014-04-24 00:01:03 -0500285 CoordinateLsa* clsa = findCoordinateLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500286 if (clsa != 0) {
287 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500288 return true;
289 }
akmhoque157b0a42014-05-13 00:26:37 -0500290 else {
akmhoque53353462014-04-22 08:43:45 -0500291 return false;
292 }
293 }
294 return true;
295}
296
297ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500298Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500299 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500300{
Vince Lehman7c603292014-09-11 17:48:16 -0500301 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
302 ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
303 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500304}
305
306bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500307Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500308{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700309 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500310 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500311 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500312 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500313 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500314 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500315 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500316
akmhoque157b0a42014-05-13 00:26:37 -0500317 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500318 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
319 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500320 }
akmhoque157b0a42014-05-13 00:26:37 -0500321 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500322 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500323 }
akmhoque157b0a42014-05-13 00:26:37 -0500324 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500325 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
326 ndn::time::system_clock::now();
327 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500328 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500329 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500330 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500331 }
akmhoque157b0a42014-05-13 00:26:37 -0500332 else {
333 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500334 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500335 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500336 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500337 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500338 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500339 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500340 chkCorLsa->setCorRadius(clsa.getCorRadius());
341 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500342 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500343 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500344 }
345 }
akmhoque157b0a42014-05-13 00:26:37 -0500346 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500347 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
348 ndn::time::system_clock::now();
349 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500350 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500351 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
352 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500353 clsa.getLsSeqNo(),
354 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500355 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500356 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500357 }
358 }
359 return true;
360}
361
362bool
akmhoqueb6450b12014-04-24 00:01:03 -0500363Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500364{
akmhoqueb6450b12014-04-24 00:01:03 -0500365 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
366 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500367 ndn::bind(corLsaCompareByKey, _1,
368 clsa.getKey()));
369 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500370 m_corLsdb.push_back(clsa);
371 return true;
372 }
373 return false;
374}
375
376bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500377Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500378{
akmhoqueb6450b12014-04-24 00:01:03 -0500379 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
380 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500381 ndn::bind(corLsaCompareByKey,
382 _1, key));
383 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500384 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500385 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500386 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500387 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500388 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
389 (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500390 }
391 m_corLsdb.erase(it);
392 return true;
393 }
394 return false;
395}
396
397bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500398Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500399{
akmhoqueb6450b12014-04-24 00:01:03 -0500400 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
401 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500402 ndn::bind(corLsaCompareByKey,
403 _1, key));
404 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500405 return false;
406 }
407 return true;
408}
409
410void
akmhoque2f423352014-06-03 11:49:35 -0500411Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500412{
akmhoque2f423352014-06-03 11:49:35 -0500413 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500414 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500415 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500416 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500417 }
418}
419
akmhoque53353462014-04-22 08:43:45 -0500420// Adj LSA and LSDB related function starts here
421
422static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500423adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500424{
425 return alsa.getKey() == key;
426}
427
akmhoque53353462014-04-22 08:43:45 -0500428void
akmhoque31d1d4b2014-05-05 22:08:14 -0500429Lsdb::scheduledAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500430{
akmhoque674b0b12014-05-20 14:33:28 -0500431 _LOG_DEBUG("scheduledAdjLsaBuild Called");
432 m_nlsr.setIsBuildAdjLsaSheduled(false);
akmhoque157b0a42014-05-13 00:26:37 -0500433 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500434 int adjBuildCount = m_nlsr.getAdjBuildCount();
akmhoque157b0a42014-05-13 00:26:37 -0500435 if (adjBuildCount > 0) {
436 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500437 _LOG_DEBUG("Building and installing Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500438 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500439 }
akmhoque157b0a42014-05-13 00:26:37 -0500440 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500441 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
442 key.append("adjacency");
443 removeAdjLsa(key);
444 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500445 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500446 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500447 }
448 }
akmhoque157b0a42014-05-13 00:26:37 -0500449 else {
akmhoque674b0b12014-05-20 14:33:28 -0500450 m_nlsr.setIsBuildAdjLsaSheduled(true);
akmhoque31d1d4b2014-05-05 22:08:14 -0500451 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
452 m_nlsr.getConfParameter().getInterestResendTime();
Vince Lehman7c603292014-09-11 17:48:16 -0500453 m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
454 ndn::bind(&Lsdb::scheduledAdjLsaBuild, this));
akmhoque53353462014-04-22 08:43:45 -0500455 }
456}
457
458
459bool
460Lsdb::addAdjLsa(AdjLsa& alsa)
461{
462 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
463 m_adjLsdb.end(),
464 bind(adjLsaCompareByKey, _1,
465 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500466 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500467 m_adjLsdb.push_back(alsa);
468 return true;
469 }
470 return false;
471}
472
akmhoqueb6450b12014-04-24 00:01:03 -0500473AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500474Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500475{
476 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
477 m_adjLsdb.end(),
478 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500479 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500480 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500481 }
akmhoqueb6450b12014-04-24 00:01:03 -0500482 return 0;
akmhoque53353462014-04-22 08:43:45 -0500483}
484
485
486bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500487Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500488{
akmhoqueb6450b12014-04-24 00:01:03 -0500489 AdjLsa* adjLsaCheck = findAdjLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500490 if (adjLsaCheck != 0) {
491 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500492 return true;
493 }
akmhoque157b0a42014-05-13 00:26:37 -0500494 else {
akmhoque53353462014-04-22 08:43:45 -0500495 return false;
496 }
497 }
498 return true;
499}
500
501
502ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500503Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
504 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500505{
Vince Lehman7c603292014-09-11 17:48:16 -0500506 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
507 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500508}
509
510bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500511Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500512{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700513 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500514 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500515 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500516 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500517 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500518 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500519 addAdjLsa(alsa);
akmhoque31d1d4b2014-05-05 22:08:14 -0500520 alsa.addNptEntries(m_nlsr);
521 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500522 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500523 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
524 ndn::time::system_clock::now();
525 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500526 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500527 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500528 alsa.getLsSeqNo(), timeToExpire);
529 }
akmhoque157b0a42014-05-13 00:26:37 -0500530 else {
531 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500532 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500533 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500534 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500535 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500536 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500537 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500538 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500539 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500540 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500541 }
akmhoque157b0a42014-05-13 00:26:37 -0500542 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500543 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
544 ndn::time::system_clock::now();
545 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500546 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500547 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
548 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500549 alsa.getLsSeqNo(),
550 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500551 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500552 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500553 }
554 }
555 return true;
556}
557
558bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500559Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500560{
akmhoque31d1d4b2014-05-05 22:08:14 -0500561 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
562 "adjacency",
563 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500564 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500565 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
566 m_nlsr.getAdjacencyList());
Vince Lehman904c2412014-09-23 19:36:11 -0500567
akmhoque31d1d4b2014-05-05 22:08:14 -0500568 m_nlsr.getSequencingManager().increaseAdjLsaSeq();
Vince Lehman904c2412014-09-23 19:36:11 -0500569
570 bool isInstalled = installAdjLsa(adjLsa);
571
572 // Delay Sync prefix registration until the first Adjacency LSA is built
573 if (isInstalled && !m_hasSyncPrefixBeenRegistered) {
574 m_nlsr.getSyncLogicHandler().createSyncSocket();
575 m_hasSyncPrefixBeenRegistered = true;
576 }
577
akmhoque157b0a42014-05-13 00:26:37 -0500578 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500579 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
580 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
Vince Lehman904c2412014-09-23 19:36:11 -0500581
582 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(), lsaPrefix);
583
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));
akmhoque53353462014-04-22 08:43:45 -0500655 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500656 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
657 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500658 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500659 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
660 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500661 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
662 lsaPrefix);
akmhoque53353462014-04-22 08:43:45 -0500663 }
akmhoque157b0a42014-05-13 00:26:37 -0500664 else {
akmhoque674b0b12014-05-20 14:33:28 -0500665 _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500666 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500667 }
668 }
669 }
670}
671
672void
akmhoque31d1d4b2014-05-05 22:08:14 -0500673Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500674{
akmhoque674b0b12014-05-20 14:33:28 -0500675 _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
676 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500677 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500678 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500679 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500680 if (chkAdjLsa->getLsSeqNo() == seqNo) {
681 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500682 _LOG_DEBUG("Own Adj LSA, so refreshing it");
683 _LOG_DEBUG("Deleting Adj Lsa");
684 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500685 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500686 m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500687 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500688 _LOG_DEBUG("Adding Adj Lsa");
689 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500690 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500691 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500692 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700693 m_lsaRefreshTime));
akmhoque53353462014-04-22 08:43:45 -0500694 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500695 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
696 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500697 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500698 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
699 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500700 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
701 lsaPrefix);
akmhoque53353462014-04-22 08:43:45 -0500702 }
akmhoque157b0a42014-05-13 00:26:37 -0500703 else {
akmhoque674b0b12014-05-20 14:33:28 -0500704 _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500705 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500706 }
707 // schedule Routing table calculaiton
akmhoque31d1d4b2014-05-05 22:08:14 -0500708 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500709 }
710 }
711}
712
713void
akmhoque31d1d4b2014-05-05 22:08:14 -0500714Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500715 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500716{
akmhoque674b0b12014-05-20 14:33:28 -0500717 _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
718 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500719 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500720 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500721 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500722 if (chkCorLsa->getLsSeqNo() == seqNo) {
723 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500724 _LOG_DEBUG("Own Cor LSA, so refreshing it");
725 _LOG_DEBUG("Deleting Coordinate Lsa");
726 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500727 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500728 m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500729 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500730 _LOG_DEBUG("Adding Coordinate Lsa");
731 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500732 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500733 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
734 chkCorLsa->getKey(),
735 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700736 m_lsaRefreshTime));
akmhoque53353462014-04-22 08:43:45 -0500737 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500738 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
739 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500740 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500741 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
742 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500743 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
744 lsaPrefix);
akmhoque53353462014-04-22 08:43:45 -0500745 }
akmhoque157b0a42014-05-13 00:26:37 -0500746 else {
akmhoque674b0b12014-05-20 14:33:28 -0500747 _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500748 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500749 }
akmhoque157b0a42014-05-13 00:26:37 -0500750 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500751 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500752 }
753 }
754 }
755}
756
757
758void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700759Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
760 steady_clock::TimePoint deadline/* = steady_clock::TimePoint::min()*/)
akmhoque31d1d4b2014-05-05 22:08:14 -0500761{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700762 if (deadline == steady_clock::TimePoint::min()) {
763 deadline = steady_clock::now() + m_lsaRefreshTime;
764 }
765
akmhoque31d1d4b2014-05-05 22:08:14 -0500766 ndn::Interest interest(interestName);
akmhoquedfe615f2014-07-27 14:12:21 -0500767 uint64_t interestedLsSeqNo = interestName[-1].toNumber();
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700768 _LOG_DEBUG("Expressing Interest for LSA(name): " << interestName
769 << " Seq number: " << interestedLsSeqNo);
770 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
akmhoque31d1d4b2014-05-05 22:08:14 -0500771 m_nlsr.getNlsrFace().expressInterest(interest,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700772 ndn::bind(&Lsdb::onContent,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700773 this, _2, deadline),
akmhoque31d1d4b2014-05-05 22:08:14 -0500774 ndn::bind(&Lsdb::processInterestTimedOut,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700775 this, _1, timeoutCount, deadline));
akmhoque31d1d4b2014-05-05 22:08:14 -0500776}
777
778void
779Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
780{
781 const ndn::Name& intName(interest.getName());
akmhoque674b0b12014-05-20 14:33:28 -0500782 _LOG_DEBUG("Interest recevied for LSA(name): " << intName);
akmhoque31d1d4b2014-05-05 22:08:14 -0500783 string chkString("LSA");
784 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(),
785 chkString);
akmhoque157b0a42014-05-13 00:26:37 -0500786 if (lsaPosition >= 0) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500787 std::string interestedLsType;
788 uint64_t interestedLsSeqNo;
akmhoque50125a92014-06-30 08:54:17 -0500789 ndn::Name origRouter = m_nlsr.getConfParameter().getNetwork();
790 origRouter.append(intName.getSubName(lsaPosition + 1,
791 interest.getName().size() - lsaPosition - 3));
akmhoque157b0a42014-05-13 00:26:37 -0500792 interestedLsType = intName[-2].toUri();
akmhoque31d1d4b2014-05-05 22:08:14 -0500793 interestedLsSeqNo = intName[-1].toNumber();
akmhoquedfe615f2014-07-27 14:12:21 -0500794 _LOG_DEBUG("LSA sequence number from interest: " << interestedLsSeqNo);
akmhoque157b0a42014-05-13 00:26:37 -0500795 if (interestedLsType == "name") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500796 processInterestForNameLsa(interest,
797 origRouter.append(interestedLsType),
798 interestedLsSeqNo);
799 return;
800 }
akmhoque157b0a42014-05-13 00:26:37 -0500801 else if (interestedLsType == "adjacency") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500802 processInterestForAdjacencyLsa(interest,
803 origRouter.append(interestedLsType),
804 interestedLsSeqNo);
805 return;
806 }
akmhoque157b0a42014-05-13 00:26:37 -0500807 else if (interestedLsType == "coordinate") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500808 processInterestForCoordinateLsa(interest,
809 origRouter.append(interestedLsType),
810 interestedLsSeqNo);
811 return;
812 }
akmhoque157b0a42014-05-13 00:26:37 -0500813 else {
akmhoque2f423352014-06-03 11:49:35 -0500814 _LOG_DEBUG("Unrecognized LSA Type :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500815 }
816 }
817}
818
819void
akmhoque69c9aa92014-07-23 15:15:05 -0500820Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
821{
822 ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
823 data->setName(ndn::Name(interest.getName()).appendVersion());
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700824 data->setFreshnessPeriod(m_lsaRefreshTime);
akmhoque69c9aa92014-07-23 15:15:05 -0500825 data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
826 m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
akmhoquedfe615f2014-07-27 14:12:21 -0500827 ndn::SignatureSha256WithRsa signature(data->getSignature());
828 ndn::Name signingCertName = signature.getKeyLocator().getName();
akmhoque69c9aa92014-07-23 15:15:05 -0500829 _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
akmhoquedfe615f2014-07-27 14:12:21 -0500830 _LOG_DEBUG("Data signed with: " << signingCertName);
akmhoque69c9aa92014-07-23 15:15:05 -0500831 m_nlsr.getNlsrFace().put(*data);
832}
833
834void
akmhoque31d1d4b2014-05-05 22:08:14 -0500835Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
836 const ndn::Name& lsaKey,
837 uint32_t interestedlsSeqNo)
838{
839 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500840 if (nameLsa != 0) {
841 if (nameLsa->getLsSeqNo() >= interestedlsSeqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500842 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500843 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500844 }
845 }
846}
847
848void
849Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
850 const ndn::Name& lsaKey,
851 uint32_t interestedlsSeqNo)
852{
853 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500854 if (adjLsa != 0) {
855 if (adjLsa->getLsSeqNo() >= interestedlsSeqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500856 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500857 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500858 }
859 }
860}
861
862void
863Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
864 const ndn::Name& lsaKey,
865 uint32_t interestedlsSeqNo)
866{
867 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500868 if (corLsa != 0) {
869 if (corLsa->getLsSeqNo() >= interestedlsSeqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500870 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500871 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500872 }
873 }
874}
875
876void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700877Lsdb::onContent(const ndn::Data& data,
878 const steady_clock::TimePoint& deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500879{
akmhoquedfe615f2014-07-27 14:12:21 -0500880 _LOG_DEBUG("Received data for LSA(name): " << data.getName());
881 if (data.getSignature().hasKeyLocator()) {
882 if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
883 _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
884 }
885 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700886 m_nlsr.getValidator().validate(data,
887 ndn::bind(&Lsdb::onContentValidated, this, _1),
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700888 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
889 deadline));
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700890
891}
892
893void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700894Lsdb::retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
895 const steady_clock::TimePoint& deadline)
896{
897 _LOG_DEBUG("Retrying validation of LSA(name): " << data->getName());
898 if (data->getSignature().hasKeyLocator()) {
899 if (data->getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
900 _LOG_DEBUG("Data signed with: " << data->getSignature().getKeyLocator().getName());
901 }
902 }
903 m_nlsr.getValidator().validate(*data,
904 ndn::bind(&Lsdb::onContentValidated, this, _1),
905 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
906 deadline));
907}
908
909void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700910Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
911{
912 const ndn::Name& dataName = data->getName();
akmhoquedfe615f2014-07-27 14:12:21 -0500913 _LOG_DEBUG("Data validation successful for LSA(name): " << dataName);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700914 string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500915 string chkString("LSA");
916 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
akmhoque157b0a42014-05-13 00:26:37 -0500917 if (lsaPosition >= 0) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500918 std::string interestedLsType;
919 uint64_t interestedLsSeqNo;
akmhoque50125a92014-06-30 08:54:17 -0500920 ndn::Name origRouter = m_nlsr.getConfParameter().getNetwork();
921 origRouter.append(dataName.getSubName(lsaPosition + 1,
922 dataName.size() - lsaPosition - 4));
akmhoque157b0a42014-05-13 00:26:37 -0500923 interestedLsType = dataName[-3].toUri();
akmhoque31d1d4b2014-05-05 22:08:14 -0500924 interestedLsSeqNo = dataName[-2].toNumber();
akmhoque157b0a42014-05-13 00:26:37 -0500925 if (interestedLsType == "name") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500926 processContentNameLsa(origRouter.append(interestedLsType),
927 interestedLsSeqNo, dataContent);
928 return;
929 }
akmhoque157b0a42014-05-13 00:26:37 -0500930 else if (interestedLsType == "adjacency") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500931 processContentAdjacencyLsa(origRouter.append(interestedLsType),
932 interestedLsSeqNo, dataContent);
933 return;
934 }
akmhoque157b0a42014-05-13 00:26:37 -0500935 else if (interestedLsType == "coordinate") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500936 processContentCoordinateLsa(origRouter.append(interestedLsType),
937 interestedLsSeqNo, dataContent);
938 return;
939 }
akmhoque157b0a42014-05-13 00:26:37 -0500940 else {
akmhoque2f423352014-06-03 11:49:35 -0500941 _LOG_DEBUG("Unrecognized LSA Type :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500942 }
943 }
944}
945
946void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700947Lsdb::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
948 const std::string& msg,
949 const steady_clock::TimePoint& deadline)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700950{
akmhoque2f423352014-06-03 11:49:35 -0500951 _LOG_DEBUG("Validation Error: " << msg);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700952
953 // Delay re-validation by LSA Interest Lifetime. When error callback will have an error
954 // code, re-validation should be done only when some keys from certification chain failed
955 // to be fetched. After that change, delaying will no longer be necessary.
956
957 // Stop retrying if delayed re-validation will be scheduled pass the deadline
958 if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) {
959 _LOG_DEBUG("Scheduling revalidation");
Vince Lehman7c603292014-09-11 17:48:16 -0500960 m_scheduler.scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
961 ndn::bind(&Lsdb::retryContentValidation, this, data, deadline));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700962 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700963}
964
965void
akmhoque31d1d4b2014-05-05 22:08:14 -0500966Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
967 uint32_t lsSeqNo, std::string& dataContent)
968{
akmhoque157b0a42014-05-13 00:26:37 -0500969 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500970 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500971 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500972 installNameLsa(nameLsa);
973 }
akmhoque157b0a42014-05-13 00:26:37 -0500974 else {
akmhoque2f423352014-06-03 11:49:35 -0500975 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500976 }
977 }
978}
979
980void
981Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
982 uint32_t lsSeqNo, std::string& dataContent)
983{
akmhoque157b0a42014-05-13 00:26:37 -0500984 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500985 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500986 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500987 installAdjLsa(adjLsa);
988 }
akmhoque157b0a42014-05-13 00:26:37 -0500989 else {
akmhoque2f423352014-06-03 11:49:35 -0500990 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500991 }
992 }
993}
994
995void
996Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
997 uint32_t lsSeqNo, std::string& dataContent)
998{
akmhoque157b0a42014-05-13 00:26:37 -0500999 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001000 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001001 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001002 installCoordinateLsa(corLsa);
1003 }
akmhoque157b0a42014-05-13 00:26:37 -05001004 else {
akmhoque2f423352014-06-03 11:49:35 -05001005 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001006 }
1007 }
1008}
1009
1010void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001011Lsdb::processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
1012 const ndn::time::steady_clock::TimePoint& deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -05001013{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001014 const ndn::Name& interestName = interest.getName();
akmhoque674b0b12014-05-20 14:33:28 -05001015 _LOG_DEBUG("Interest timed out for LSA(name): " << interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001016
1017 if (ndn::time::steady_clock::now() < deadline) {
1018 expressInterest(interestName, retransmitNo + 1, deadline);
akmhoque06986672014-05-27 13:55:53 -05001019 }
akmhoque31d1d4b2014-05-05 22:08:14 -05001020}
1021
akmhoquec7a79b22014-05-26 08:06:19 -05001022ndn::time::system_clock::TimePoint
1023Lsdb::getLsaExpirationTimePoint()
1024{
1025 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1026 expirationTimePoint = expirationTimePoint +
1027 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1028 return expirationTimePoint;
1029}
akmhoque31d1d4b2014-05-05 22:08:14 -05001030
1031void
akmhoque2f423352014-06-03 11:49:35 -05001032Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001033{
akmhoque2f423352014-06-03 11:49:35 -05001034 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001035 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001036 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001037 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001038 }
1039}
1040
1041//-----utility function -----
1042bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001043Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001044{
akmhoque157b0a42014-05-13 00:26:37 -05001045 if (lsType == "name") {
akmhoque53353462014-04-22 08:43:45 -05001046 return doesNameLsaExist(key);
1047 }
akmhoque157b0a42014-05-13 00:26:37 -05001048 else if (lsType == "adjacency") {
akmhoque53353462014-04-22 08:43:45 -05001049 return doesAdjLsaExist(key);
1050 }
akmhoque157b0a42014-05-13 00:26:37 -05001051 else if (lsType == "coordinate") {
akmhoqueb6450b12014-04-24 00:01:03 -05001052 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001053 }
1054 return false;
1055}
1056
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001057} // namespace nlsr