blob: 8c41c9f44ec871b0a8f475be1977cb6ee832671d [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehmanc2e51f62015-01-20 15:03:11 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
akmhoque53353462014-04-22 08:43:45 -050022#include <string>
23#include <utility>
akmhoque157b0a42014-05-13 00:26:37 -050024
akmhoque53353462014-04-22 08:43:45 -050025#include "lsdb.hpp"
26#include "nlsr.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050027#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050028#include "utility/name-helper.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050029#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050030
31namespace nlsr {
32
akmhoque674b0b12014-05-20 14:33:28 -050033INIT_LOGGER("Lsdb");
34
Vince Lehman18841082014-08-19 17:15:24 -050035const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -050036const steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = steady_clock::TimePoint::min();
Vince Lehman18841082014-08-19 17:15:24 -050037
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(),
alvy49b1c0c2014-12-19 13:57:46 -060057 NameLsa::TYPE_STRING,
akmhoque31d1d4b2014-05-05 22:08:14 -050058 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 }
Vince Lehmanf1aa5232014-10-06 17:57:35 -0500155
156 chkNameLsa->getNpl().sort();
157
akmhoque31d1d4b2014-05-05 22:08:14 -0500158 std::list<ndn::Name> nameToRemove;
akmhoqueb6450b12014-04-24 00:01:03 -0500159 std::set_difference(chkNameLsa->getNpl().getNameList().begin(),
160 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500161 nlsa.getNpl().getNameList().begin(),
162 nlsa.getNpl().getNameList().end(),
163 std::inserter(nameToRemove, nameToRemove.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500164 for (std::list<ndn::Name>::iterator it = nameToRemove.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500165 it != nameToRemove.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500166 chkNameLsa->removeName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500167 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
168 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500169 m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500170 }
171 }
172 }
akmhoque157b0a42014-05-13 00:26:37 -0500173 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500174 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
175 ndn::time::system_clock::now();
176 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500177 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500178 cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
179 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500180 nlsa.getLsSeqNo(),
181 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500182 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500183 chkNameLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500184 }
185 }
186 return true;
187}
188
189bool
190Lsdb::addNameLsa(NameLsa& nlsa)
191{
192 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
193 m_nameLsdb.end(),
194 bind(nameLsaCompareByKey, _1,
195 nlsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500196 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500197 m_nameLsdb.push_back(nlsa);
198 return true;
199 }
200 return false;
201}
202
203bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500204Lsdb::removeNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500205{
206 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
207 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500208 ndn::bind(nameLsaCompareByKey, _1, key));
209 if (it != m_nameLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500210 _LOG_DEBUG("Deleting Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500211 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500212 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500213 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500214 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
215 (*it).getOrigRouter());
216 for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500217 nit != (*it).getNpl().getNameList().end(); ++nit) {
218 if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500219 m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500220 }
221 }
222 }
223 m_nameLsdb.erase(it);
224 return true;
225 }
226 return false;
227}
228
229bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500230Lsdb::doesNameLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500231{
232 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
233 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500234 ndn::bind(nameLsaCompareByKey, _1, key));
235 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500236 return false;
237 }
238 return true;
239}
240
241void
akmhoque2f423352014-06-03 11:49:35 -0500242Lsdb::writeNameLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500243{
akmhoque2f423352014-06-03 11:49:35 -0500244 _LOG_DEBUG("---------------Name LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -0500245 for (std::list<NameLsa>::iterator it = m_nameLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500246 it != m_nameLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500247 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500248 }
249}
250
251// Cor LSA and LSDB related Functions start here
252
akmhoque53353462014-04-22 08:43:45 -0500253static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500254corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500255{
256 return clsa.getKey() == key;
257}
258
259bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500260Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500261{
akmhoque31d1d4b2014-05-05 22:08:14 -0500262 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
alvy49b1c0c2014-12-19 13:57:46 -0600263 CoordinateLsa::TYPE_STRING,
akmhoque31d1d4b2014-05-05 22:08:14 -0500264 m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500265 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500266 m_nlsr.getConfParameter().getCorR(),
267 m_nlsr.getConfParameter().getCorTheta());
268 m_nlsr.getSequencingManager().increaseCorLsaSeq();
269 installCoordinateLsa(corLsa);
akmhoque53353462014-04-22 08:43:45 -0500270 return true;
271}
272
akmhoqueb6450b12014-04-24 00:01:03 -0500273CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500274Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500275{
akmhoqueb6450b12014-04-24 00:01:03 -0500276 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
277 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500278 ndn::bind(corLsaCompareByKey, _1, key));
279 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500280 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500281 }
akmhoqueb6450b12014-04-24 00:01:03 -0500282 return 0;
akmhoque53353462014-04-22 08:43:45 -0500283}
284
285bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500286Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500287{
akmhoqueb6450b12014-04-24 00:01:03 -0500288 CoordinateLsa* clsa = findCoordinateLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500289 if (clsa != 0) {
290 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500291 return true;
292 }
akmhoque157b0a42014-05-13 00:26:37 -0500293 else {
akmhoque53353462014-04-22 08:43:45 -0500294 return false;
295 }
296 }
297 return true;
298}
299
300ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500301Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500302 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500303{
Vince Lehman7c603292014-09-11 17:48:16 -0500304 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
305 ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
306 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500307}
308
309bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500310Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500311{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700312 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500313 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500314 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500315 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500316 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500317 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500318 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500319
akmhoque157b0a42014-05-13 00:26:37 -0500320 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500321 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
322 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500323 }
akmhoque157b0a42014-05-13 00:26:37 -0500324 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500325 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500326 }
akmhoque157b0a42014-05-13 00:26:37 -0500327 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500328 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
329 ndn::time::system_clock::now();
330 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500331 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500332 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500333 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500334 }
akmhoque157b0a42014-05-13 00:26:37 -0500335 else {
336 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500337 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500338 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500339 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500340 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500341 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500342 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500343 chkCorLsa->setCorRadius(clsa.getCorRadius());
344 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500345 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500346 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500347 }
348 }
akmhoque157b0a42014-05-13 00:26:37 -0500349 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500350 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
351 ndn::time::system_clock::now();
352 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500353 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500354 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
355 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500356 clsa.getLsSeqNo(),
357 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500358 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500359 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500360 }
361 }
362 return true;
363}
364
365bool
akmhoqueb6450b12014-04-24 00:01:03 -0500366Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500367{
akmhoqueb6450b12014-04-24 00:01:03 -0500368 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
369 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500370 ndn::bind(corLsaCompareByKey, _1,
371 clsa.getKey()));
372 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500373 m_corLsdb.push_back(clsa);
374 return true;
375 }
376 return false;
377}
378
379bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500380Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500381{
akmhoqueb6450b12014-04-24 00:01:03 -0500382 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
383 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500384 ndn::bind(corLsaCompareByKey,
385 _1, key));
386 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500387 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500388 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500389 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500390 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500391 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
392 (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500393 }
394 m_corLsdb.erase(it);
395 return true;
396 }
397 return false;
398}
399
400bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500401Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500402{
akmhoqueb6450b12014-04-24 00:01:03 -0500403 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
404 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500405 ndn::bind(corLsaCompareByKey,
406 _1, key));
407 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500408 return false;
409 }
410 return true;
411}
412
413void
akmhoque2f423352014-06-03 11:49:35 -0500414Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500415{
akmhoque2f423352014-06-03 11:49:35 -0500416 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500417 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500418 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500419 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500420 }
421}
422
akmhoque53353462014-04-22 08:43:45 -0500423// Adj LSA and LSDB related function starts here
424
425static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500426adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500427{
428 return alsa.getKey() == key;
429}
430
akmhoque53353462014-04-22 08:43:45 -0500431void
Vince Lehman50df6b72015-03-03 12:06:40 -0600432Lsdb::scheduleAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500433{
Vince Lehman50df6b72015-03-03 12:06:40 -0600434 m_nlsr.incrementAdjBuildCount();
435
436 if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
437 _LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
438
439 m_scheduler.scheduleEvent(m_adjLsaBuildInterval, ndn::bind(&Lsdb::buildAdjLsa, this));
440 m_nlsr.setIsBuildAdjLsaSheduled(true);
441 }
442}
443
444void
445Lsdb::buildAdjLsa()
446{
447 _LOG_TRACE("buildAdjLsa called");
448
akmhoque674b0b12014-05-20 14:33:28 -0500449 m_nlsr.setIsBuildAdjLsaSheduled(false);
akmhoque157b0a42014-05-13 00:26:37 -0500450 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500451 int adjBuildCount = m_nlsr.getAdjBuildCount();
akmhoque157b0a42014-05-13 00:26:37 -0500452 if (adjBuildCount > 0) {
453 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500454 _LOG_DEBUG("Building and installing Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500455 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500456 }
akmhoque157b0a42014-05-13 00:26:37 -0500457 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500458 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
alvy49b1c0c2014-12-19 13:57:46 -0600459 key.append(AdjLsa::TYPE_STRING);
akmhoque31d1d4b2014-05-05 22:08:14 -0500460 removeAdjLsa(key);
461 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500462 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500463 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500464 }
465 }
akmhoque157b0a42014-05-13 00:26:37 -0500466 else {
akmhoque674b0b12014-05-20 14:33:28 -0500467 m_nlsr.setIsBuildAdjLsaSheduled(true);
akmhoque31d1d4b2014-05-05 22:08:14 -0500468 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
469 m_nlsr.getConfParameter().getInterestResendTime();
Vince Lehman7c603292014-09-11 17:48:16 -0500470 m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
Vince Lehman50df6b72015-03-03 12:06:40 -0600471 ndn::bind(&Lsdb::buildAdjLsa, this));
akmhoque53353462014-04-22 08:43:45 -0500472 }
473}
474
475
476bool
477Lsdb::addAdjLsa(AdjLsa& alsa)
478{
479 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
480 m_adjLsdb.end(),
481 bind(adjLsaCompareByKey, _1,
482 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500483 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500484 m_adjLsdb.push_back(alsa);
485 return true;
486 }
487 return false;
488}
489
akmhoqueb6450b12014-04-24 00:01:03 -0500490AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500491Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500492{
493 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
494 m_adjLsdb.end(),
495 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500496 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500497 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500498 }
akmhoqueb6450b12014-04-24 00:01:03 -0500499 return 0;
akmhoque53353462014-04-22 08:43:45 -0500500}
501
502
503bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500504Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500505{
akmhoqueb6450b12014-04-24 00:01:03 -0500506 AdjLsa* adjLsaCheck = findAdjLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500507 if (adjLsaCheck != 0) {
508 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500509 return true;
510 }
akmhoque157b0a42014-05-13 00:26:37 -0500511 else {
akmhoque53353462014-04-22 08:43:45 -0500512 return false;
513 }
514 }
515 return true;
516}
517
518
519ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500520Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
521 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500522{
Vince Lehman7c603292014-09-11 17:48:16 -0500523 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
524 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500525}
526
527bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500528Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500529{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700530 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500531 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500532 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500533 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500534 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500535 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500536 addAdjLsa(alsa);
akmhoque31d1d4b2014-05-05 22:08:14 -0500537 alsa.addNptEntries(m_nlsr);
538 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500539 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500540 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
541 ndn::time::system_clock::now();
542 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500543 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500544 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500545 alsa.getLsSeqNo(), timeToExpire);
546 }
akmhoque157b0a42014-05-13 00:26:37 -0500547 else {
548 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500549 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500550 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500551 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500552 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500553 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500554 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500555 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500556 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500557 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500558 }
akmhoque157b0a42014-05-13 00:26:37 -0500559 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500560 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
561 ndn::time::system_clock::now();
562 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500563 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500564 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
565 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500566 alsa.getLsSeqNo(),
567 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500568 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500569 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500570 }
571 }
572 return true;
573}
574
575bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500576Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500577{
akmhoque31d1d4b2014-05-05 22:08:14 -0500578 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
alvy49b1c0c2014-12-19 13:57:46 -0600579 AdjLsa::TYPE_STRING,
akmhoque31d1d4b2014-05-05 22:08:14 -0500580 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500581 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500582 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
583 m_nlsr.getAdjacencyList());
Vince Lehman904c2412014-09-23 19:36:11 -0500584
akmhoque31d1d4b2014-05-05 22:08:14 -0500585 m_nlsr.getSequencingManager().increaseAdjLsaSeq();
Vince Lehman904c2412014-09-23 19:36:11 -0500586
587 bool isInstalled = installAdjLsa(adjLsa);
588
589 // Delay Sync prefix registration until the first Adjacency LSA is built
590 if (isInstalled && !m_hasSyncPrefixBeenRegistered) {
591 m_nlsr.getSyncLogicHandler().createSyncSocket();
592 m_hasSyncPrefixBeenRegistered = true;
593 }
594
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600595 m_sync.publishRoutingUpdate();
Vince Lehman904c2412014-09-23 19:36:11 -0500596
597 return isInstalled;
akmhoque53353462014-04-22 08:43:45 -0500598}
599
600bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500601Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500602{
603 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
604 m_adjLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500605 ndn::bind(adjLsaCompareByKey, _1, key));
606 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500607 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500608 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500609 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500610 m_adjLsdb.erase(it);
611 return true;
612 }
613 return false;
614}
615
616bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500617Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500618{
619 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
620 m_adjLsdb.end(),
621 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500622 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500623 return false;
624 }
625 return true;
626}
627
628std::list<AdjLsa>&
629Lsdb::getAdjLsdb()
630{
631 return m_adjLsdb;
632}
633
634void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700635Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500636{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700637 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500638}
639
640void
641Lsdb::setThisRouterPrefix(string trp)
642{
643 m_thisRouterPrefix = trp;
644}
645
646void
akmhoque31d1d4b2014-05-05 22:08:14 -0500647Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500648{
akmhoque674b0b12014-05-20 14:33:28 -0500649 _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called");
650 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500651 NameLsa* chkNameLsa = findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500652 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500653 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500654 if (chkNameLsa->getLsSeqNo() == seqNo) {
655 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500656 _LOG_DEBUG("Own Name LSA, so refreshing it");
657 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500658 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500659 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500660 m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500661 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500662 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500663 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500664 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500665 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500666 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700667 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600668 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500669 }
akmhoque157b0a42014-05-13 00:26:37 -0500670 else {
akmhoque674b0b12014-05-20 14:33:28 -0500671 _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500672 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500673 }
674 }
675 }
676}
677
678void
akmhoque31d1d4b2014-05-05 22:08:14 -0500679Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500680{
akmhoque674b0b12014-05-20 14:33:28 -0500681 _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
682 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500683 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500684 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500685 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500686 if (chkAdjLsa->getLsSeqNo() == seqNo) {
687 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500688 _LOG_DEBUG("Own Adj LSA, so refreshing it");
689 _LOG_DEBUG("Deleting Adj Lsa");
690 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500691 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500692 m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500693 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500694 _LOG_DEBUG("Adding Adj Lsa");
695 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500696 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500697 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500698 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700699 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600700 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500701 }
akmhoque157b0a42014-05-13 00:26:37 -0500702 else {
akmhoque674b0b12014-05-20 14:33:28 -0500703 _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500704 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500705 }
706 // schedule Routing table calculaiton
akmhoque31d1d4b2014-05-05 22:08:14 -0500707 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500708 }
709 }
710}
711
712void
akmhoque31d1d4b2014-05-05 22:08:14 -0500713Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500714 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500715{
akmhoque674b0b12014-05-20 14:33:28 -0500716 _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
717 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500718 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500719 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500720 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500721 if (chkCorLsa->getLsSeqNo() == seqNo) {
722 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500723 _LOG_DEBUG("Own Cor LSA, so refreshing it");
724 _LOG_DEBUG("Deleting Coordinate Lsa");
725 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500726 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500727 m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500728 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500729 _LOG_DEBUG("Adding Coordinate Lsa");
730 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500731 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500732 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
733 chkCorLsa->getKey(),
734 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700735 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600736 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500737 }
akmhoque157b0a42014-05-13 00:26:37 -0500738 else {
akmhoque674b0b12014-05-20 14:33:28 -0500739 _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500740 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500741 }
akmhoque157b0a42014-05-13 00:26:37 -0500742 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500743 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500744 }
745 }
746 }
747}
748
749
750void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700751Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500752 steady_clock::TimePoint deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500753{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500754 if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) {
755 deadline = steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700756 }
757
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500758 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
759
akmhoque31d1d4b2014-05-05 22:08:14 -0500760 ndn::Interest interest(interestName);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500761 uint64_t seqNo = interestName[-1].toNumber();
762
763 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
764 m_highestSeqNo[lsaName] = seqNo;
765 }
766 else if (seqNo > m_highestSeqNo[lsaName]) {
767 m_highestSeqNo[lsaName] = seqNo;
768 }
769 else if (seqNo < m_highestSeqNo[lsaName]) {
770 return;
771 }
772
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700773 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500774
775 _LOG_DEBUG("Expressing Interest for LSA: " << interestName << " Seq number: " << seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500776 m_nlsr.getNlsrFace().expressInterest(interest,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700777 ndn::bind(&Lsdb::onContent,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500778 this, _2, deadline, lsaName, seqNo),
akmhoque31d1d4b2014-05-05 22:08:14 -0500779 ndn::bind(&Lsdb::processInterestTimedOut,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500780 this, _1, timeoutCount, deadline, lsaName, seqNo));
akmhoque31d1d4b2014-05-05 22:08:14 -0500781}
782
783void
784Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
785{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500786 const ndn::Name& interestName(interest.getName());
787 _LOG_DEBUG("Interest received for LSA: " << interestName);
788
akmhoque31d1d4b2014-05-05 22:08:14 -0500789 string chkString("LSA");
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500790 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
791
akmhoque157b0a42014-05-13 00:26:37 -0500792 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500793
794 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
795 originRouter.append(interestName.getSubName(lsaPosition + 1,
796 interest.getName().size() - lsaPosition - 3));
797
798 uint64_t seqNo = interestName[-1].toNumber();
799 _LOG_DEBUG("LSA sequence number from interest: " << seqNo);
800
801 std::string interestedLsType = interestName[-2].toUri();
802
alvy49b1c0c2014-12-19 13:57:46 -0600803 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500804 processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500805 }
alvy49b1c0c2014-12-19 13:57:46 -0600806 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500807 processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500808 }
alvy49b1c0c2014-12-19 13:57:46 -0600809 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500810 processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500811 }
akmhoque157b0a42014-05-13 00:26:37 -0500812 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500813 _LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500814 }
815 }
816}
817
818void
akmhoque69c9aa92014-07-23 15:15:05 -0500819Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
820{
821 ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
822 data->setName(ndn::Name(interest.getName()).appendVersion());
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700823 data->setFreshnessPeriod(m_lsaRefreshTime);
akmhoque69c9aa92014-07-23 15:15:05 -0500824 data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
825 m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
akmhoquedfe615f2014-07-27 14:12:21 -0500826 ndn::SignatureSha256WithRsa signature(data->getSignature());
827 ndn::Name signingCertName = signature.getKeyLocator().getName();
akmhoque69c9aa92014-07-23 15:15:05 -0500828 _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
akmhoquedfe615f2014-07-27 14:12:21 -0500829 _LOG_DEBUG("Data signed with: " << signingCertName);
akmhoque69c9aa92014-07-23 15:15:05 -0500830 m_nlsr.getNlsrFace().put(*data);
831}
832
833void
akmhoque31d1d4b2014-05-05 22:08:14 -0500834Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
835 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500836 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500837{
838 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500839 if (nameLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500840 if (nameLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500841 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500842 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500843 }
844 }
845}
846
847void
848Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
849 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500850 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500851{
852 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500853 if (adjLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500854 if (adjLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500855 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500856 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500857 }
858 }
859}
860
861void
862Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
863 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500864 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500865{
866 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500867 if (corLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500868 if (corLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500869 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500870 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500871 }
872 }
873}
874
875void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700876Lsdb::onContent(const ndn::Data& data,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500877 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
878 uint64_t seqNo)
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,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500889 deadline, lsaName, seqNo));
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,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500895 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
896 uint64_t seqNo)
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700897{
898 _LOG_DEBUG("Retrying validation of LSA(name): " << data->getName());
899 if (data->getSignature().hasKeyLocator()) {
900 if (data->getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
901 _LOG_DEBUG("Data signed with: " << data->getSignature().getKeyLocator().getName());
902 }
903 }
904 m_nlsr.getValidator().validate(*data,
905 ndn::bind(&Lsdb::onContentValidated, this, _1),
906 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500907 deadline, lsaName, seqNo));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700908}
909
910void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700911Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
912{
913 const ndn::Name& dataName = data->getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500914 _LOG_DEBUG("Data validation successful for LSA: " << dataName);
915
akmhoque31d1d4b2014-05-05 22:08:14 -0500916 string chkString("LSA");
917 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500918
akmhoque157b0a42014-05-13 00:26:37 -0500919 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500920
921 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
922 originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 4));
923
924 uint64_t seqNo = dataName[-2].toNumber();
925 string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
926
927 std::string interestedLsType = dataName[-3].toUri();
928
alvy49b1c0c2014-12-19 13:57:46 -0600929 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500930 processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500931 }
alvy49b1c0c2014-12-19 13:57:46 -0600932 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500933 processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500934 }
alvy49b1c0c2014-12-19 13:57:46 -0600935 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500936 processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500937 }
akmhoque157b0a42014-05-13 00:26:37 -0500938 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500939 _LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500940 }
941 }
942}
943
944void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700945Lsdb::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
946 const std::string& msg,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500947 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
948 uint64_t seqNo)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700949{
akmhoque2f423352014-06-03 11:49:35 -0500950 _LOG_DEBUG("Validation Error: " << msg);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700951
952 // Delay re-validation by LSA Interest Lifetime. When error callback will have an error
953 // code, re-validation should be done only when some keys from certification chain failed
954 // to be fetched. After that change, delaying will no longer be necessary.
955
956 // Stop retrying if delayed re-validation will be scheduled pass the deadline
957 if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500958
959 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
960
961 if (it != m_highestSeqNo.end() && it->second == seqNo) {
962 _LOG_DEBUG("Scheduling revalidation attempt");
963 m_scheduler.scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
964 ndn::bind(&Lsdb::retryContentValidation, this, data,
965 deadline, lsaName, seqNo));
966 }
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700967 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700968}
969
970void
akmhoque31d1d4b2014-05-05 22:08:14 -0500971Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500972 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500973{
akmhoque157b0a42014-05-13 00:26:37 -0500974 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500975 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500976 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500977 installNameLsa(nameLsa);
978 }
akmhoque157b0a42014-05-13 00:26:37 -0500979 else {
akmhoque2f423352014-06-03 11:49:35 -0500980 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500981 }
982 }
983}
984
985void
986Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500987 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500988{
akmhoque157b0a42014-05-13 00:26:37 -0500989 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500990 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500991 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500992 installAdjLsa(adjLsa);
993 }
akmhoque157b0a42014-05-13 00:26:37 -0500994 else {
akmhoque2f423352014-06-03 11:49:35 -0500995 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500996 }
997 }
998}
999
1000void
1001Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001002 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001003{
akmhoque157b0a42014-05-13 00:26:37 -05001004 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001005 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001006 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001007 installCoordinateLsa(corLsa);
1008 }
akmhoque157b0a42014-05-13 00:26:37 -05001009 else {
akmhoque2f423352014-06-03 11:49:35 -05001010 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001011 }
1012 }
1013}
1014
1015void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001016Lsdb::processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001017 const ndn::time::steady_clock::TimePoint& deadline, ndn::Name lsaName,
1018 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001019{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001020 const ndn::Name& interestName = interest.getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001021 _LOG_DEBUG("Interest timed out for LSA: " << interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001022
1023 if (ndn::time::steady_clock::now() < deadline) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001024
1025 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
1026
1027 if (it != m_highestSeqNo.end() && it->second == seqNo) {
1028 expressInterest(interestName, retransmitNo + 1, deadline);
1029 }
akmhoque06986672014-05-27 13:55:53 -05001030 }
akmhoque31d1d4b2014-05-05 22:08:14 -05001031}
1032
akmhoquec7a79b22014-05-26 08:06:19 -05001033ndn::time::system_clock::TimePoint
1034Lsdb::getLsaExpirationTimePoint()
1035{
1036 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1037 expirationTimePoint = expirationTimePoint +
1038 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1039 return expirationTimePoint;
1040}
akmhoque31d1d4b2014-05-05 22:08:14 -05001041
1042void
akmhoque2f423352014-06-03 11:49:35 -05001043Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001044{
akmhoque2f423352014-06-03 11:49:35 -05001045 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001046 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001047 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001048 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001049 }
1050}
1051
1052//-----utility function -----
1053bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001054Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001055{
alvy49b1c0c2014-12-19 13:57:46 -06001056 if (lsType == NameLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001057 return doesNameLsaExist(key);
1058 }
alvy49b1c0c2014-12-19 13:57:46 -06001059 else if (lsType == AdjLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001060 return doesAdjLsaExist(key);
1061 }
alvy49b1c0c2014-12-19 13:57:46 -06001062 else if (lsType == CoordinateLsa::TYPE_STRING) {
akmhoqueb6450b12014-04-24 00:01:03 -05001063 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001064 }
1065 return false;
1066}
1067
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001068} // namespace nlsr