blob: 74daed494810f2e2908a0bac2a17a5c2f29db3f5 [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{
akmhoque31d1d4b2014-05-05 22:08:14 -050043 m_nlsr.getScheduler().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 Lehman18841082014-08-19 17:15:24 -050096 return m_nlsr.getScheduler().scheduleEvent(expTime + GRACE_PERIOD,
akmhoque31d1d4b2014-05-05 22:08:14 -050097 ndn::bind(&Lsdb::exprireOrRefreshNameLsa,
98 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 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500156 std::list<ndn::Name> nameToRemove;
akmhoqueb6450b12014-04-24 00:01:03 -0500157 std::set_difference(chkNameLsa->getNpl().getNameList().begin(),
158 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500159 nlsa.getNpl().getNameList().begin(),
160 nlsa.getNpl().getNameList().end(),
161 std::inserter(nameToRemove, nameToRemove.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500162 for (std::list<ndn::Name>::iterator it = nameToRemove.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500163 it != nameToRemove.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500164 chkNameLsa->removeName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500165 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
166 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500167 m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500168 }
169 }
170 }
akmhoque157b0a42014-05-13 00:26:37 -0500171 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500172 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
173 ndn::time::system_clock::now();
174 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500175 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500176 cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
177 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500178 nlsa.getLsSeqNo(),
179 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500180 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500181 chkNameLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500182 }
183 }
184 return true;
185}
186
187bool
188Lsdb::addNameLsa(NameLsa& nlsa)
189{
190 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
191 m_nameLsdb.end(),
192 bind(nameLsaCompareByKey, _1,
193 nlsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500194 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500195 m_nameLsdb.push_back(nlsa);
196 return true;
197 }
198 return false;
199}
200
201bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500202Lsdb::removeNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500203{
204 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
205 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500206 ndn::bind(nameLsaCompareByKey, _1, key));
207 if (it != m_nameLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500208 _LOG_DEBUG("Deleting Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500209 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500210 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500211 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500212 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
213 (*it).getOrigRouter());
214 for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500215 nit != (*it).getNpl().getNameList().end(); ++nit) {
216 if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500217 m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500218 }
219 }
220 }
221 m_nameLsdb.erase(it);
222 return true;
223 }
224 return false;
225}
226
227bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500228Lsdb::doesNameLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500229{
230 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
231 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500232 ndn::bind(nameLsaCompareByKey, _1, key));
233 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500234 return false;
235 }
236 return true;
237}
238
239void
akmhoque2f423352014-06-03 11:49:35 -0500240Lsdb::writeNameLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500241{
akmhoque2f423352014-06-03 11:49:35 -0500242 _LOG_DEBUG("---------------Name LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -0500243 for (std::list<NameLsa>::iterator it = m_nameLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500244 it != m_nameLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500245 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500246 }
247}
248
249// Cor LSA and LSDB related Functions start here
250
akmhoque53353462014-04-22 08:43:45 -0500251static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500252corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500253{
254 return clsa.getKey() == key;
255}
256
257bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500258Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500259{
akmhoque31d1d4b2014-05-05 22:08:14 -0500260 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
261 "coordinate",
262 m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500263 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500264 m_nlsr.getConfParameter().getCorR(),
265 m_nlsr.getConfParameter().getCorTheta());
266 m_nlsr.getSequencingManager().increaseCorLsaSeq();
267 installCoordinateLsa(corLsa);
akmhoque53353462014-04-22 08:43:45 -0500268 return true;
269}
270
akmhoqueb6450b12014-04-24 00:01:03 -0500271CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500272Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500273{
akmhoqueb6450b12014-04-24 00:01:03 -0500274 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
275 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500276 ndn::bind(corLsaCompareByKey, _1, key));
277 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500278 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500279 }
akmhoqueb6450b12014-04-24 00:01:03 -0500280 return 0;
akmhoque53353462014-04-22 08:43:45 -0500281}
282
283bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500284Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500285{
akmhoqueb6450b12014-04-24 00:01:03 -0500286 CoordinateLsa* clsa = findCoordinateLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500287 if (clsa != 0) {
288 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500289 return true;
290 }
akmhoque157b0a42014-05-13 00:26:37 -0500291 else {
akmhoque53353462014-04-22 08:43:45 -0500292 return false;
293 }
294 }
295 return true;
296}
297
298ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500299Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500300 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500301{
Vince Lehman18841082014-08-19 17:15:24 -0500302 return m_nlsr.getScheduler().scheduleEvent(expTime + GRACE_PERIOD,
akmhoque31d1d4b2014-05-05 22:08:14 -0500303 ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
304 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500305}
306
307bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500308Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500309{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700310 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500311 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500312 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500313 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500314 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500315 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500316 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500317
akmhoque157b0a42014-05-13 00:26:37 -0500318 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500319 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
320 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500321 }
akmhoque157b0a42014-05-13 00:26:37 -0500322 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500323 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500324 }
akmhoque157b0a42014-05-13 00:26:37 -0500325 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500326 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
327 ndn::time::system_clock::now();
328 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500329 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500330 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500331 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500332 }
akmhoque157b0a42014-05-13 00:26:37 -0500333 else {
334 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500335 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500336 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500337 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500338 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500339 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500340 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500341 chkCorLsa->setCorRadius(clsa.getCorRadius());
342 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500343 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500344 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500345 }
346 }
akmhoque157b0a42014-05-13 00:26:37 -0500347 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500348 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
349 ndn::time::system_clock::now();
350 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500351 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500352 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
353 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500354 clsa.getLsSeqNo(),
355 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500356 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500357 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500358 }
359 }
360 return true;
361}
362
363bool
akmhoqueb6450b12014-04-24 00:01:03 -0500364Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500365{
akmhoqueb6450b12014-04-24 00:01:03 -0500366 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
367 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500368 ndn::bind(corLsaCompareByKey, _1,
369 clsa.getKey()));
370 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500371 m_corLsdb.push_back(clsa);
372 return true;
373 }
374 return false;
375}
376
377bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500378Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500379{
akmhoqueb6450b12014-04-24 00:01:03 -0500380 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
381 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500382 ndn::bind(corLsaCompareByKey,
383 _1, key));
384 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500385 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500386 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500387 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500388 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500389 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
390 (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500391 }
392 m_corLsdb.erase(it);
393 return true;
394 }
395 return false;
396}
397
398bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500399Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500400{
akmhoqueb6450b12014-04-24 00:01:03 -0500401 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
402 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500403 ndn::bind(corLsaCompareByKey,
404 _1, key));
405 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500406 return false;
407 }
408 return true;
409}
410
411void
akmhoque2f423352014-06-03 11:49:35 -0500412Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500413{
akmhoque2f423352014-06-03 11:49:35 -0500414 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500415 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500416 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500417 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500418 }
419}
420
akmhoque53353462014-04-22 08:43:45 -0500421// Adj LSA and LSDB related function starts here
422
423static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500424adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500425{
426 return alsa.getKey() == key;
427}
428
akmhoque53353462014-04-22 08:43:45 -0500429void
akmhoque31d1d4b2014-05-05 22:08:14 -0500430Lsdb::scheduledAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500431{
akmhoque674b0b12014-05-20 14:33:28 -0500432 _LOG_DEBUG("scheduledAdjLsaBuild Called");
433 m_nlsr.setIsBuildAdjLsaSheduled(false);
akmhoque157b0a42014-05-13 00:26:37 -0500434 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500435 int adjBuildCount = m_nlsr.getAdjBuildCount();
akmhoque157b0a42014-05-13 00:26:37 -0500436 if (adjBuildCount > 0) {
437 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500438 _LOG_DEBUG("Building and installing Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500439 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500440 }
akmhoque157b0a42014-05-13 00:26:37 -0500441 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500442 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
443 key.append("adjacency");
444 removeAdjLsa(key);
445 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500446 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500447 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500448 }
449 }
akmhoque157b0a42014-05-13 00:26:37 -0500450 else {
akmhoque674b0b12014-05-20 14:33:28 -0500451 m_nlsr.setIsBuildAdjLsaSheduled(true);
akmhoque31d1d4b2014-05-05 22:08:14 -0500452 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
453 m_nlsr.getConfParameter().getInterestResendTime();
454 m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime),
455 ndn::bind(&Lsdb::scheduledAdjLsaBuild,
456 this));
akmhoque53353462014-04-22 08:43:45 -0500457 }
458}
459
460
461bool
462Lsdb::addAdjLsa(AdjLsa& alsa)
463{
464 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
465 m_adjLsdb.end(),
466 bind(adjLsaCompareByKey, _1,
467 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500468 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500469 m_adjLsdb.push_back(alsa);
470 return true;
471 }
472 return false;
473}
474
akmhoqueb6450b12014-04-24 00:01:03 -0500475AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500476Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500477{
478 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
479 m_adjLsdb.end(),
480 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500481 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500482 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500483 }
akmhoqueb6450b12014-04-24 00:01:03 -0500484 return 0;
akmhoque53353462014-04-22 08:43:45 -0500485}
486
487
488bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500489Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500490{
akmhoqueb6450b12014-04-24 00:01:03 -0500491 AdjLsa* adjLsaCheck = findAdjLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500492 if (adjLsaCheck != 0) {
493 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500494 return true;
495 }
akmhoque157b0a42014-05-13 00:26:37 -0500496 else {
akmhoque53353462014-04-22 08:43:45 -0500497 return false;
498 }
499 }
500 return true;
501}
502
503
504ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500505Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
506 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500507{
Vince Lehman18841082014-08-19 17:15:24 -0500508 return m_nlsr.getScheduler().scheduleEvent(expTime + GRACE_PERIOD,
akmhoque31d1d4b2014-05-05 22:08:14 -0500509 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa,
510 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500511}
512
513bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500514Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500515{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700516 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500517 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500518 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500519 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500520 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500521 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500522 addAdjLsa(alsa);
akmhoque31d1d4b2014-05-05 22:08:14 -0500523 alsa.addNptEntries(m_nlsr);
524 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500525 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500526 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
527 ndn::time::system_clock::now();
528 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500529 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500530 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500531 alsa.getLsSeqNo(), timeToExpire);
532 }
akmhoque157b0a42014-05-13 00:26:37 -0500533 else {
534 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500535 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500536 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500537 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500538 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500539 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500540 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500541 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500542 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500543 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500544 }
akmhoque157b0a42014-05-13 00:26:37 -0500545 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500546 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
547 ndn::time::system_clock::now();
548 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500549 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500550 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
551 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500552 alsa.getLsSeqNo(),
553 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500554 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500555 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500556 }
557 }
558 return true;
559}
560
561bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500562Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500563{
akmhoque31d1d4b2014-05-05 22:08:14 -0500564 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
565 "adjacency",
566 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500567 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500568 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
569 m_nlsr.getAdjacencyList());
570 m_nlsr.getSequencingManager().increaseAdjLsaSeq();
571 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500572 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
573 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500574 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500575 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
576 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500577 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
578 lsaPrefix);
579 return installAdjLsa(adjLsa);
akmhoque53353462014-04-22 08:43:45 -0500580}
581
582bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500583Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500584{
585 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
586 m_adjLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500587 ndn::bind(adjLsaCompareByKey, _1, key));
588 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500589 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500590 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500591 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500592 m_adjLsdb.erase(it);
593 return true;
594 }
595 return false;
596}
597
598bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500599Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500600{
601 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
602 m_adjLsdb.end(),
603 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500604 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500605 return false;
606 }
607 return true;
608}
609
610std::list<AdjLsa>&
611Lsdb::getAdjLsdb()
612{
613 return m_adjLsdb;
614}
615
616void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700617Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500618{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700619 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500620}
621
622void
623Lsdb::setThisRouterPrefix(string trp)
624{
625 m_thisRouterPrefix = trp;
626}
627
628void
akmhoque31d1d4b2014-05-05 22:08:14 -0500629Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500630{
akmhoque674b0b12014-05-20 14:33:28 -0500631 _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called");
632 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500633 NameLsa* chkNameLsa = findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500634 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500635 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500636 if (chkNameLsa->getLsSeqNo() == seqNo) {
637 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500638 _LOG_DEBUG("Own Name LSA, so refreshing it");
639 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500640 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500641 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500642 m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500643 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500644 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500645 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500646 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500647 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500648 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700649 m_lsaRefreshTime));
akmhoque53353462014-04-22 08:43:45 -0500650 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500651 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
652 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500653 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500654 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
655 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500656 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
657 lsaPrefix);
akmhoque53353462014-04-22 08:43:45 -0500658 }
akmhoque157b0a42014-05-13 00:26:37 -0500659 else {
akmhoque674b0b12014-05-20 14:33:28 -0500660 _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500661 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500662 }
663 }
664 }
665}
666
667void
akmhoque31d1d4b2014-05-05 22:08:14 -0500668Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500669{
akmhoque674b0b12014-05-20 14:33:28 -0500670 _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
671 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500672 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500673 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500674 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500675 if (chkAdjLsa->getLsSeqNo() == seqNo) {
676 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500677 _LOG_DEBUG("Own Adj LSA, so refreshing it");
678 _LOG_DEBUG("Deleting Adj Lsa");
679 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500680 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500681 m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500682 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500683 _LOG_DEBUG("Adding Adj Lsa");
684 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500685 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500686 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500687 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700688 m_lsaRefreshTime));
akmhoque53353462014-04-22 08:43:45 -0500689 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500690 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
691 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500692 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500693 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
694 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500695 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
696 lsaPrefix);
akmhoque53353462014-04-22 08:43:45 -0500697 }
akmhoque157b0a42014-05-13 00:26:37 -0500698 else {
akmhoque674b0b12014-05-20 14:33:28 -0500699 _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500700 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500701 }
702 // schedule Routing table calculaiton
akmhoque31d1d4b2014-05-05 22:08:14 -0500703 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500704 }
705 }
706}
707
708void
akmhoque31d1d4b2014-05-05 22:08:14 -0500709Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500710 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500711{
akmhoque674b0b12014-05-20 14:33:28 -0500712 _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
713 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500714 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500715 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500716 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500717 if (chkCorLsa->getLsSeqNo() == seqNo) {
718 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500719 _LOG_DEBUG("Own Cor LSA, so refreshing it");
720 _LOG_DEBUG("Deleting Coordinate Lsa");
721 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500722 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500723 m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500724 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500725 _LOG_DEBUG("Adding Coordinate Lsa");
726 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500727 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500728 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
729 chkCorLsa->getKey(),
730 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700731 m_lsaRefreshTime));
akmhoque53353462014-04-22 08:43:45 -0500732 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500733 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
734 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500735 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500736 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
737 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500738 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
739 lsaPrefix);
akmhoque53353462014-04-22 08:43:45 -0500740 }
akmhoque157b0a42014-05-13 00:26:37 -0500741 else {
akmhoque674b0b12014-05-20 14:33:28 -0500742 _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500743 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500744 }
akmhoque157b0a42014-05-13 00:26:37 -0500745 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500746 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500747 }
748 }
749 }
750}
751
752
753void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700754Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
755 steady_clock::TimePoint deadline/* = steady_clock::TimePoint::min()*/)
akmhoque31d1d4b2014-05-05 22:08:14 -0500756{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700757 if (deadline == steady_clock::TimePoint::min()) {
758 deadline = steady_clock::now() + m_lsaRefreshTime;
759 }
760
akmhoque31d1d4b2014-05-05 22:08:14 -0500761 ndn::Interest interest(interestName);
akmhoquedfe615f2014-07-27 14:12:21 -0500762 uint64_t interestedLsSeqNo = interestName[-1].toNumber();
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700763 _LOG_DEBUG("Expressing Interest for LSA(name): " << interestName
764 << " Seq number: " << interestedLsSeqNo);
765 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
akmhoque31d1d4b2014-05-05 22:08:14 -0500766 m_nlsr.getNlsrFace().expressInterest(interest,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700767 ndn::bind(&Lsdb::onContent,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700768 this, _2, deadline),
akmhoque31d1d4b2014-05-05 22:08:14 -0500769 ndn::bind(&Lsdb::processInterestTimedOut,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700770 this, _1, timeoutCount, deadline));
akmhoque31d1d4b2014-05-05 22:08:14 -0500771}
772
773void
774Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
775{
776 const ndn::Name& intName(interest.getName());
akmhoque674b0b12014-05-20 14:33:28 -0500777 _LOG_DEBUG("Interest recevied for LSA(name): " << intName);
akmhoque31d1d4b2014-05-05 22:08:14 -0500778 string chkString("LSA");
779 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(),
780 chkString);
akmhoque157b0a42014-05-13 00:26:37 -0500781 if (lsaPosition >= 0) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500782 std::string interestedLsType;
783 uint64_t interestedLsSeqNo;
akmhoque50125a92014-06-30 08:54:17 -0500784 ndn::Name origRouter = m_nlsr.getConfParameter().getNetwork();
785 origRouter.append(intName.getSubName(lsaPosition + 1,
786 interest.getName().size() - lsaPosition - 3));
akmhoque157b0a42014-05-13 00:26:37 -0500787 interestedLsType = intName[-2].toUri();
akmhoque31d1d4b2014-05-05 22:08:14 -0500788 interestedLsSeqNo = intName[-1].toNumber();
akmhoquedfe615f2014-07-27 14:12:21 -0500789 _LOG_DEBUG("LSA sequence number from interest: " << interestedLsSeqNo);
akmhoque157b0a42014-05-13 00:26:37 -0500790 if (interestedLsType == "name") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500791 processInterestForNameLsa(interest,
792 origRouter.append(interestedLsType),
793 interestedLsSeqNo);
794 return;
795 }
akmhoque157b0a42014-05-13 00:26:37 -0500796 else if (interestedLsType == "adjacency") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500797 processInterestForAdjacencyLsa(interest,
798 origRouter.append(interestedLsType),
799 interestedLsSeqNo);
800 return;
801 }
akmhoque157b0a42014-05-13 00:26:37 -0500802 else if (interestedLsType == "coordinate") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500803 processInterestForCoordinateLsa(interest,
804 origRouter.append(interestedLsType),
805 interestedLsSeqNo);
806 return;
807 }
akmhoque157b0a42014-05-13 00:26:37 -0500808 else {
akmhoque2f423352014-06-03 11:49:35 -0500809 _LOG_DEBUG("Unrecognized LSA Type :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500810 }
811 }
812}
813
814void
akmhoque69c9aa92014-07-23 15:15:05 -0500815Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
816{
817 ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
818 data->setName(ndn::Name(interest.getName()).appendVersion());
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700819 data->setFreshnessPeriod(m_lsaRefreshTime);
akmhoque69c9aa92014-07-23 15:15:05 -0500820 data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
821 m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
akmhoquedfe615f2014-07-27 14:12:21 -0500822 ndn::SignatureSha256WithRsa signature(data->getSignature());
823 ndn::Name signingCertName = signature.getKeyLocator().getName();
akmhoque69c9aa92014-07-23 15:15:05 -0500824 _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
akmhoquedfe615f2014-07-27 14:12:21 -0500825 _LOG_DEBUG("Data signed with: " << signingCertName);
akmhoque69c9aa92014-07-23 15:15:05 -0500826 m_nlsr.getNlsrFace().put(*data);
827}
828
829void
akmhoque31d1d4b2014-05-05 22:08:14 -0500830Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
831 const ndn::Name& lsaKey,
832 uint32_t interestedlsSeqNo)
833{
834 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500835 if (nameLsa != 0) {
836 if (nameLsa->getLsSeqNo() >= interestedlsSeqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500837 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500838 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500839 }
840 }
841}
842
843void
844Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
845 const ndn::Name& lsaKey,
846 uint32_t interestedlsSeqNo)
847{
848 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500849 if (adjLsa != 0) {
850 if (adjLsa->getLsSeqNo() >= interestedlsSeqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500851 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500852 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500853 }
854 }
855}
856
857void
858Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
859 const ndn::Name& lsaKey,
860 uint32_t interestedlsSeqNo)
861{
862 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500863 if (corLsa != 0) {
864 if (corLsa->getLsSeqNo() >= interestedlsSeqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500865 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500866 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500867 }
868 }
869}
870
871void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700872Lsdb::onContent(const ndn::Data& data,
873 const steady_clock::TimePoint& deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500874{
akmhoquedfe615f2014-07-27 14:12:21 -0500875 _LOG_DEBUG("Received data for LSA(name): " << data.getName());
876 if (data.getSignature().hasKeyLocator()) {
877 if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
878 _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
879 }
880 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700881 m_nlsr.getValidator().validate(data,
882 ndn::bind(&Lsdb::onContentValidated, this, _1),
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700883 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
884 deadline));
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700885
886}
887
888void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700889Lsdb::retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
890 const steady_clock::TimePoint& deadline)
891{
892 _LOG_DEBUG("Retrying validation of LSA(name): " << data->getName());
893 if (data->getSignature().hasKeyLocator()) {
894 if (data->getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
895 _LOG_DEBUG("Data signed with: " << data->getSignature().getKeyLocator().getName());
896 }
897 }
898 m_nlsr.getValidator().validate(*data,
899 ndn::bind(&Lsdb::onContentValidated, this, _1),
900 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
901 deadline));
902}
903
904void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700905Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
906{
907 const ndn::Name& dataName = data->getName();
akmhoquedfe615f2014-07-27 14:12:21 -0500908 _LOG_DEBUG("Data validation successful for LSA(name): " << dataName);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700909 string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500910 string chkString("LSA");
911 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
akmhoque157b0a42014-05-13 00:26:37 -0500912 if (lsaPosition >= 0) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500913 std::string interestedLsType;
914 uint64_t interestedLsSeqNo;
akmhoque50125a92014-06-30 08:54:17 -0500915 ndn::Name origRouter = m_nlsr.getConfParameter().getNetwork();
916 origRouter.append(dataName.getSubName(lsaPosition + 1,
917 dataName.size() - lsaPosition - 4));
akmhoque157b0a42014-05-13 00:26:37 -0500918 interestedLsType = dataName[-3].toUri();
akmhoque31d1d4b2014-05-05 22:08:14 -0500919 interestedLsSeqNo = dataName[-2].toNumber();
akmhoque157b0a42014-05-13 00:26:37 -0500920 if (interestedLsType == "name") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500921 processContentNameLsa(origRouter.append(interestedLsType),
922 interestedLsSeqNo, dataContent);
923 return;
924 }
akmhoque157b0a42014-05-13 00:26:37 -0500925 else if (interestedLsType == "adjacency") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500926 processContentAdjacencyLsa(origRouter.append(interestedLsType),
927 interestedLsSeqNo, dataContent);
928 return;
929 }
akmhoque157b0a42014-05-13 00:26:37 -0500930 else if (interestedLsType == "coordinate") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500931 processContentCoordinateLsa(origRouter.append(interestedLsType),
932 interestedLsSeqNo, dataContent);
933 return;
934 }
akmhoque157b0a42014-05-13 00:26:37 -0500935 else {
akmhoque2f423352014-06-03 11:49:35 -0500936 _LOG_DEBUG("Unrecognized LSA Type :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500937 }
938 }
939}
940
941void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700942Lsdb::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
943 const std::string& msg,
944 const steady_clock::TimePoint& deadline)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700945{
akmhoque2f423352014-06-03 11:49:35 -0500946 _LOG_DEBUG("Validation Error: " << msg);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700947
948 // Delay re-validation by LSA Interest Lifetime. When error callback will have an error
949 // code, re-validation should be done only when some keys from certification chain failed
950 // to be fetched. After that change, delaying will no longer be necessary.
951
952 // Stop retrying if delayed re-validation will be scheduled pass the deadline
953 if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) {
954 _LOG_DEBUG("Scheduling revalidation");
955 m_nlsr.getScheduler().scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
956 ndn::bind(&Lsdb::retryContentValidation,
957 this, data, deadline));
958 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700959}
960
961void
akmhoque31d1d4b2014-05-05 22:08:14 -0500962Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
963 uint32_t lsSeqNo, std::string& dataContent)
964{
akmhoque157b0a42014-05-13 00:26:37 -0500965 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500966 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500967 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500968 installNameLsa(nameLsa);
969 }
akmhoque157b0a42014-05-13 00:26:37 -0500970 else {
akmhoque2f423352014-06-03 11:49:35 -0500971 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500972 }
973 }
974}
975
976void
977Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
978 uint32_t lsSeqNo, std::string& dataContent)
979{
akmhoque157b0a42014-05-13 00:26:37 -0500980 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500981 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500982 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500983 installAdjLsa(adjLsa);
984 }
akmhoque157b0a42014-05-13 00:26:37 -0500985 else {
akmhoque2f423352014-06-03 11:49:35 -0500986 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500987 }
988 }
989}
990
991void
992Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
993 uint32_t lsSeqNo, std::string& dataContent)
994{
akmhoque157b0a42014-05-13 00:26:37 -0500995 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500996 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500997 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500998 installCoordinateLsa(corLsa);
999 }
akmhoque157b0a42014-05-13 00:26:37 -05001000 else {
akmhoque2f423352014-06-03 11:49:35 -05001001 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001002 }
1003 }
1004}
1005
1006void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001007Lsdb::processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
1008 const ndn::time::steady_clock::TimePoint& deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -05001009{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001010 const ndn::Name& interestName = interest.getName();
akmhoque674b0b12014-05-20 14:33:28 -05001011 _LOG_DEBUG("Interest timed out for LSA(name): " << interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001012
1013 if (ndn::time::steady_clock::now() < deadline) {
1014 expressInterest(interestName, retransmitNo + 1, deadline);
akmhoque06986672014-05-27 13:55:53 -05001015 }
akmhoque31d1d4b2014-05-05 22:08:14 -05001016}
1017
akmhoquec7a79b22014-05-26 08:06:19 -05001018ndn::time::system_clock::TimePoint
1019Lsdb::getLsaExpirationTimePoint()
1020{
1021 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1022 expirationTimePoint = expirationTimePoint +
1023 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1024 return expirationTimePoint;
1025}
akmhoque31d1d4b2014-05-05 22:08:14 -05001026
1027void
akmhoque2f423352014-06-03 11:49:35 -05001028Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001029{
akmhoque2f423352014-06-03 11:49:35 -05001030 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001031 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001032 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001033 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001034 }
1035}
1036
1037//-----utility function -----
1038bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001039Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001040{
akmhoque157b0a42014-05-13 00:26:37 -05001041 if (lsType == "name") {
akmhoque53353462014-04-22 08:43:45 -05001042 return doesNameLsaExist(key);
1043 }
akmhoque157b0a42014-05-13 00:26:37 -05001044 else if (lsType == "adjacency") {
akmhoque53353462014-04-22 08:43:45 -05001045 return doesAdjLsaExist(key);
1046 }
akmhoque157b0a42014-05-13 00:26:37 -05001047 else if (lsType == "coordinate") {
akmhoqueb6450b12014-04-24 00:01:03 -05001048 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001049 }
1050 return false;
1051}
1052
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001053} // namespace nlsr