blob: d4b7193ee71048ec5f91458ef2afa4c551b7a09a [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehmanc2e51f62015-01-20 15:03:11 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
akmhoque53353462014-04-22 08:43:45 -050022#include <string>
23#include <utility>
akmhoque157b0a42014-05-13 00:26:37 -050024
akmhoque53353462014-04-22 08:43:45 -050025#include "lsdb.hpp"
26#include "nlsr.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050027#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050028#include "utility/name-helper.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050029#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050030
31namespace nlsr {
32
akmhoque674b0b12014-05-20 14:33:28 -050033INIT_LOGGER("Lsdb");
34
Jiewen Tana0497d82015-02-02 21:59:18 -080035const ndn::Name::Component Lsdb::NAME_COMPONENT = ndn::Name::Component("lsdb");
Vince Lehman18841082014-08-19 17:15:24 -050036const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -050037const steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = steady_clock::TimePoint::min();
Vince Lehman18841082014-08-19 17:15:24 -050038
akmhoque53353462014-04-22 08:43:45 -050039using namespace std;
40
41void
akmhoque31d1d4b2014-05-05 22:08:14 -050042Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
akmhoque53353462014-04-22 08:43:45 -050043{
Vince Lehman7c603292014-09-11 17:48:16 -050044 m_scheduler.cancelEvent(eid);
akmhoque53353462014-04-22 08:43:45 -050045}
46
47static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050048nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -050049{
50 return nlsa1.getKey() == key;
51}
52
53
54bool
akmhoque31d1d4b2014-05-05 22:08:14 -050055Lsdb::buildAndInstallOwnNameLsa()
akmhoque53353462014-04-22 08:43:45 -050056{
akmhoque31d1d4b2014-05-05 22:08:14 -050057 NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
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
Jiewen Tana0497d82015-02-02 21:59:18 -0800251const std::list<NameLsa>&
252Lsdb::getNameLsdb()
253{
254 return m_nameLsdb;
255}
256
akmhoque53353462014-04-22 08:43:45 -0500257// Cor LSA and LSDB related Functions start here
258
akmhoque53353462014-04-22 08:43:45 -0500259static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500260corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500261{
262 return clsa.getKey() == key;
263}
264
265bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500266Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500267{
akmhoque31d1d4b2014-05-05 22:08:14 -0500268 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500269 m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500270 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500271 m_nlsr.getConfParameter().getCorR(),
272 m_nlsr.getConfParameter().getCorTheta());
273 m_nlsr.getSequencingManager().increaseCorLsaSeq();
274 installCoordinateLsa(corLsa);
akmhoque53353462014-04-22 08:43:45 -0500275 return true;
276}
277
akmhoqueb6450b12014-04-24 00:01:03 -0500278CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500279Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500280{
akmhoqueb6450b12014-04-24 00:01:03 -0500281 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
282 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500283 ndn::bind(corLsaCompareByKey, _1, key));
284 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500285 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500286 }
akmhoqueb6450b12014-04-24 00:01:03 -0500287 return 0;
akmhoque53353462014-04-22 08:43:45 -0500288}
289
290bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500291Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500292{
akmhoqueb6450b12014-04-24 00:01:03 -0500293 CoordinateLsa* clsa = findCoordinateLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500294 if (clsa != 0) {
295 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500296 return true;
297 }
akmhoque157b0a42014-05-13 00:26:37 -0500298 else {
akmhoque53353462014-04-22 08:43:45 -0500299 return false;
300 }
301 }
302 return true;
303}
304
305ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500306Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500307 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500308{
Vince Lehman7c603292014-09-11 17:48:16 -0500309 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
310 ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
311 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500312}
313
314bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500315Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500316{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700317 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500318 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500319 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500320 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500321 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500322 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500323 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500324
akmhoque157b0a42014-05-13 00:26:37 -0500325 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500326 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
327 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500328 }
akmhoque157b0a42014-05-13 00:26:37 -0500329 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500330 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500331 }
akmhoque157b0a42014-05-13 00:26:37 -0500332 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500333 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
334 ndn::time::system_clock::now();
335 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500336 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500337 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500338 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500339 }
akmhoque157b0a42014-05-13 00:26:37 -0500340 else {
341 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500342 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500343 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500344 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500345 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500346 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500347 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500348 chkCorLsa->setCorRadius(clsa.getCorRadius());
349 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500350 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500351 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500352 }
353 }
akmhoque157b0a42014-05-13 00:26:37 -0500354 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500355 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
356 ndn::time::system_clock::now();
357 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500358 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500359 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
360 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500361 clsa.getLsSeqNo(),
362 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500363 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500364 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500365 }
366 }
367 return true;
368}
369
370bool
akmhoqueb6450b12014-04-24 00:01:03 -0500371Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500372{
akmhoqueb6450b12014-04-24 00:01:03 -0500373 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
374 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500375 ndn::bind(corLsaCompareByKey, _1,
376 clsa.getKey()));
377 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500378 m_corLsdb.push_back(clsa);
379 return true;
380 }
381 return false;
382}
383
384bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500385Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500386{
akmhoqueb6450b12014-04-24 00:01:03 -0500387 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
388 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500389 ndn::bind(corLsaCompareByKey,
390 _1, key));
391 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500392 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500393 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500394 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500395 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500396 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
397 (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500398 }
399 m_corLsdb.erase(it);
400 return true;
401 }
402 return false;
403}
404
405bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500406Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500407{
akmhoqueb6450b12014-04-24 00:01:03 -0500408 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
409 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500410 ndn::bind(corLsaCompareByKey,
411 _1, key));
412 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500413 return false;
414 }
415 return true;
416}
417
418void
akmhoque2f423352014-06-03 11:49:35 -0500419Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500420{
akmhoque2f423352014-06-03 11:49:35 -0500421 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500422 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500423 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500424 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500425 }
426}
427
Jiewen Tana0497d82015-02-02 21:59:18 -0800428const std::list<CoordinateLsa>&
429Lsdb::getCoordinateLsdb()
430{
431 return m_corLsdb;
432}
433
akmhoque53353462014-04-22 08:43:45 -0500434// Adj LSA and LSDB related function starts here
435
436static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500437adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500438{
439 return alsa.getKey() == key;
440}
441
akmhoque53353462014-04-22 08:43:45 -0500442void
Vince Lehman50df6b72015-03-03 12:06:40 -0600443Lsdb::scheduleAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500444{
Vince Lehman50df6b72015-03-03 12:06:40 -0600445 m_nlsr.incrementAdjBuildCount();
446
447 if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
448 _LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval);
449
450 m_scheduler.scheduleEvent(m_adjLsaBuildInterval, ndn::bind(&Lsdb::buildAdjLsa, this));
451 m_nlsr.setIsBuildAdjLsaSheduled(true);
452 }
453}
454
455void
456Lsdb::buildAdjLsa()
457{
458 _LOG_TRACE("buildAdjLsa called");
459
akmhoque674b0b12014-05-20 14:33:28 -0500460 m_nlsr.setIsBuildAdjLsaSheduled(false);
akmhoque157b0a42014-05-13 00:26:37 -0500461 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500462 int adjBuildCount = m_nlsr.getAdjBuildCount();
akmhoque157b0a42014-05-13 00:26:37 -0500463 if (adjBuildCount > 0) {
464 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500465 _LOG_DEBUG("Building and installing Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500466 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500467 }
akmhoque157b0a42014-05-13 00:26:37 -0500468 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500469 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
alvy49b1c0c2014-12-19 13:57:46 -0600470 key.append(AdjLsa::TYPE_STRING);
akmhoque31d1d4b2014-05-05 22:08:14 -0500471 removeAdjLsa(key);
472 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500473 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500474 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500475 }
476 }
akmhoque157b0a42014-05-13 00:26:37 -0500477 else {
akmhoque674b0b12014-05-20 14:33:28 -0500478 m_nlsr.setIsBuildAdjLsaSheduled(true);
akmhoque31d1d4b2014-05-05 22:08:14 -0500479 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
480 m_nlsr.getConfParameter().getInterestResendTime();
Vince Lehman7c603292014-09-11 17:48:16 -0500481 m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime),
Vince Lehman50df6b72015-03-03 12:06:40 -0600482 ndn::bind(&Lsdb::buildAdjLsa, this));
akmhoque53353462014-04-22 08:43:45 -0500483 }
484}
485
486
487bool
488Lsdb::addAdjLsa(AdjLsa& alsa)
489{
490 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
491 m_adjLsdb.end(),
492 bind(adjLsaCompareByKey, _1,
493 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500494 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500495 m_adjLsdb.push_back(alsa);
496 return true;
497 }
498 return false;
499}
500
akmhoqueb6450b12014-04-24 00:01:03 -0500501AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500502Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500503{
504 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
505 m_adjLsdb.end(),
506 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500507 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500508 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500509 }
akmhoqueb6450b12014-04-24 00:01:03 -0500510 return 0;
akmhoque53353462014-04-22 08:43:45 -0500511}
512
513
514bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500515Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500516{
akmhoqueb6450b12014-04-24 00:01:03 -0500517 AdjLsa* adjLsaCheck = findAdjLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500518 if (adjLsaCheck != 0) {
519 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500520 return true;
521 }
akmhoque157b0a42014-05-13 00:26:37 -0500522 else {
akmhoque53353462014-04-22 08:43:45 -0500523 return false;
524 }
525 }
526 return true;
527}
528
529
530ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500531Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
532 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500533{
Vince Lehman7c603292014-09-11 17:48:16 -0500534 return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD,
535 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500536}
537
538bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500539Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500540{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700541 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500542 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500543 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500544 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500545 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500546 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500547 addAdjLsa(alsa);
akmhoque31d1d4b2014-05-05 22:08:14 -0500548 alsa.addNptEntries(m_nlsr);
549 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500550 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500551 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
552 ndn::time::system_clock::now();
553 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500554 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500555 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500556 alsa.getLsSeqNo(), timeToExpire);
557 }
akmhoque157b0a42014-05-13 00:26:37 -0500558 else {
559 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500560 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500561 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500562 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500563 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500564 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500565 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500566 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500567 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500568 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500569 }
akmhoque157b0a42014-05-13 00:26:37 -0500570 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500571 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
572 ndn::time::system_clock::now();
573 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500574 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500575 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
576 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500577 alsa.getLsSeqNo(),
578 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500579 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500580 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500581 }
582 }
583 return true;
584}
585
586bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500587Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500588{
akmhoque31d1d4b2014-05-05 22:08:14 -0500589 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500590 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500591 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500592 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
593 m_nlsr.getAdjacencyList());
Vince Lehman904c2412014-09-23 19:36:11 -0500594
akmhoque31d1d4b2014-05-05 22:08:14 -0500595 m_nlsr.getSequencingManager().increaseAdjLsaSeq();
Vince Lehman904c2412014-09-23 19:36:11 -0500596
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600597 m_sync.publishRoutingUpdate();
Vince Lehman904c2412014-09-23 19:36:11 -0500598
Vince Lehman9d097802015-03-16 17:55:59 -0500599 return installAdjLsa(adjLsa);
akmhoque53353462014-04-22 08:43:45 -0500600}
601
602bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500603Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500604{
605 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
606 m_adjLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500607 ndn::bind(adjLsaCompareByKey, _1, key));
608 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500609 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500610 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500611 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500612 m_adjLsdb.erase(it);
613 return true;
614 }
615 return false;
616}
617
618bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500619Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500620{
621 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
622 m_adjLsdb.end(),
623 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500624 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500625 return false;
626 }
627 return true;
628}
629
Jiewen Tana0497d82015-02-02 21:59:18 -0800630const std::list<AdjLsa>&
akmhoque53353462014-04-22 08:43:45 -0500631Lsdb::getAdjLsdb()
632{
633 return m_adjLsdb;
634}
635
636void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700637Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500638{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700639 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500640}
641
642void
643Lsdb::setThisRouterPrefix(string trp)
644{
645 m_thisRouterPrefix = trp;
646}
647
648void
akmhoque31d1d4b2014-05-05 22:08:14 -0500649Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500650{
akmhoque674b0b12014-05-20 14:33:28 -0500651 _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called");
652 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500653 NameLsa* chkNameLsa = findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500654 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500655 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500656 if (chkNameLsa->getLsSeqNo() == seqNo) {
657 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500658 _LOG_DEBUG("Own Name LSA, so refreshing it");
659 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500660 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500661 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500662 m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500663 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500664 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500665 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500666 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500667 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500668 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700669 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600670 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500671 }
akmhoque157b0a42014-05-13 00:26:37 -0500672 else {
akmhoque674b0b12014-05-20 14:33:28 -0500673 _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500674 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500675 }
676 }
677 }
678}
679
680void
akmhoque31d1d4b2014-05-05 22:08:14 -0500681Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500682{
akmhoque674b0b12014-05-20 14:33:28 -0500683 _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
684 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500685 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500686 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500687 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500688 if (chkAdjLsa->getLsSeqNo() == seqNo) {
689 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500690 _LOG_DEBUG("Own Adj LSA, so refreshing it");
691 _LOG_DEBUG("Deleting Adj Lsa");
692 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500693 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500694 m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500695 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500696 _LOG_DEBUG("Adding Adj Lsa");
697 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500698 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500699 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500700 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700701 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600702 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500703 }
akmhoque157b0a42014-05-13 00:26:37 -0500704 else {
akmhoque674b0b12014-05-20 14:33:28 -0500705 _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500706 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500707 }
708 // schedule Routing table calculaiton
akmhoque31d1d4b2014-05-05 22:08:14 -0500709 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500710 }
711 }
712}
713
714void
akmhoque31d1d4b2014-05-05 22:08:14 -0500715Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500716 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500717{
akmhoque674b0b12014-05-20 14:33:28 -0500718 _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
719 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500720 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500721 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500722 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500723 if (chkCorLsa->getLsSeqNo() == seqNo) {
724 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500725 _LOG_DEBUG("Own Cor LSA, so refreshing it");
726 _LOG_DEBUG("Deleting Coordinate Lsa");
727 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500728 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500729 m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500730 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500731 _LOG_DEBUG("Adding Coordinate Lsa");
732 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500733 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500734 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
735 chkCorLsa->getKey(),
736 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700737 m_lsaRefreshTime));
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600738 m_sync.publishRoutingUpdate();
akmhoque53353462014-04-22 08:43:45 -0500739 }
akmhoque157b0a42014-05-13 00:26:37 -0500740 else {
akmhoque674b0b12014-05-20 14:33:28 -0500741 _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500742 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500743 }
akmhoque157b0a42014-05-13 00:26:37 -0500744 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500745 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500746 }
747 }
748 }
749}
750
751
752void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700753Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500754 steady_clock::TimePoint deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500755{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500756 if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) {
757 deadline = steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700758 }
759
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500760 ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1);
761
akmhoque31d1d4b2014-05-05 22:08:14 -0500762 ndn::Interest interest(interestName);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500763 uint64_t seqNo = interestName[-1].toNumber();
764
765 if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) {
766 m_highestSeqNo[lsaName] = seqNo;
767 }
768 else if (seqNo > m_highestSeqNo[lsaName]) {
769 m_highestSeqNo[lsaName] = seqNo;
770 }
771 else if (seqNo < m_highestSeqNo[lsaName]) {
772 return;
773 }
774
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700775 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500776
777 _LOG_DEBUG("Expressing Interest for LSA: " << interestName << " Seq number: " << seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500778 m_nlsr.getNlsrFace().expressInterest(interest,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700779 ndn::bind(&Lsdb::onContent,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500780 this, _2, deadline, lsaName, seqNo),
akmhoque31d1d4b2014-05-05 22:08:14 -0500781 ndn::bind(&Lsdb::processInterestTimedOut,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500782 this, _1, timeoutCount, deadline, lsaName, seqNo));
akmhoque31d1d4b2014-05-05 22:08:14 -0500783}
784
785void
786Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
787{
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500788 const ndn::Name& interestName(interest.getName());
789 _LOG_DEBUG("Interest received for LSA: " << interestName);
790
akmhoque31d1d4b2014-05-05 22:08:14 -0500791 string chkString("LSA");
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500792 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString);
793
akmhoque157b0a42014-05-13 00:26:37 -0500794 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500795
796 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
797 originRouter.append(interestName.getSubName(lsaPosition + 1,
798 interest.getName().size() - lsaPosition - 3));
799
800 uint64_t seqNo = interestName[-1].toNumber();
801 _LOG_DEBUG("LSA sequence number from interest: " << seqNo);
802
803 std::string interestedLsType = interestName[-2].toUri();
804
alvy49b1c0c2014-12-19 13:57:46 -0600805 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500806 processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500807 }
alvy49b1c0c2014-12-19 13:57:46 -0600808 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500809 processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500810 }
alvy49b1c0c2014-12-19 13:57:46 -0600811 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500812 processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500813 }
akmhoque157b0a42014-05-13 00:26:37 -0500814 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500815 _LOG_WARN("Received unrecognized LSA type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500816 }
817 }
818}
819
820void
akmhoque69c9aa92014-07-23 15:15:05 -0500821Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
822{
823 ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
824 data->setName(ndn::Name(interest.getName()).appendVersion());
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700825 data->setFreshnessPeriod(m_lsaRefreshTime);
akmhoque69c9aa92014-07-23 15:15:05 -0500826 data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
827 m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
akmhoquedfe615f2014-07-27 14:12:21 -0500828 ndn::SignatureSha256WithRsa signature(data->getSignature());
829 ndn::Name signingCertName = signature.getKeyLocator().getName();
akmhoque69c9aa92014-07-23 15:15:05 -0500830 _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
akmhoquedfe615f2014-07-27 14:12:21 -0500831 _LOG_DEBUG("Data signed with: " << signingCertName);
akmhoque69c9aa92014-07-23 15:15:05 -0500832 m_nlsr.getNlsrFace().put(*data);
833}
834
835void
akmhoque31d1d4b2014-05-05 22:08:14 -0500836Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
837 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500838 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500839{
840 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500841 if (nameLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500842 if (nameLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500843 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500844 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500845 }
846 }
847}
848
849void
850Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
851 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500852 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500853{
854 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500855 if (adjLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500856 if (adjLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500857 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500858 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500859 }
860 }
861}
862
863void
864Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
865 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500866 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500867{
868 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500869 if (corLsa != 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500870 if (corLsa->getLsSeqNo() == seqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500871 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500872 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500873 }
874 }
875}
876
877void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700878Lsdb::onContent(const ndn::Data& data,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500879 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
880 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -0500881{
akmhoquedfe615f2014-07-27 14:12:21 -0500882 _LOG_DEBUG("Received data for LSA(name): " << data.getName());
883 if (data.getSignature().hasKeyLocator()) {
884 if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
885 _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
886 }
887 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700888 m_nlsr.getValidator().validate(data,
889 ndn::bind(&Lsdb::onContentValidated, this, _1),
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700890 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500891 deadline, lsaName, seqNo));
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700892
893}
894
895void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700896Lsdb::retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500897 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
898 uint64_t seqNo)
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700899{
900 _LOG_DEBUG("Retrying validation of LSA(name): " << data->getName());
901 if (data->getSignature().hasKeyLocator()) {
902 if (data->getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
903 _LOG_DEBUG("Data signed with: " << data->getSignature().getKeyLocator().getName());
904 }
905 }
906 m_nlsr.getValidator().validate(*data,
907 ndn::bind(&Lsdb::onContentValidated, this, _1),
908 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500909 deadline, lsaName, seqNo));
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700910}
911
912void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700913Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
914{
915 const ndn::Name& dataName = data->getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500916 _LOG_DEBUG("Data validation successful for LSA: " << dataName);
917
akmhoque31d1d4b2014-05-05 22:08:14 -0500918 string chkString("LSA");
919 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500920
akmhoque157b0a42014-05-13 00:26:37 -0500921 if (lsaPosition >= 0) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500922
923 ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork();
924 originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 4));
925
926 uint64_t seqNo = dataName[-2].toNumber();
927 string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
928
929 std::string interestedLsType = dataName[-3].toUri();
930
alvy49b1c0c2014-12-19 13:57:46 -0600931 if (interestedLsType == NameLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500932 processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500933 }
alvy49b1c0c2014-12-19 13:57:46 -0600934 else if (interestedLsType == AdjLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500935 processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500936 }
alvy49b1c0c2014-12-19 13:57:46 -0600937 else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500938 processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500939 }
akmhoque157b0a42014-05-13 00:26:37 -0500940 else {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500941 _LOG_WARN("Received unrecognized LSA Type: " << interestedLsType);
akmhoque31d1d4b2014-05-05 22:08:14 -0500942 }
943 }
944}
945
946void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700947Lsdb::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
948 const std::string& msg,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500949 const steady_clock::TimePoint& deadline, ndn::Name lsaName,
950 uint64_t seqNo)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700951{
akmhoque2f423352014-06-03 11:49:35 -0500952 _LOG_DEBUG("Validation Error: " << msg);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700953
954 // Delay re-validation by LSA Interest Lifetime. When error callback will have an error
955 // code, re-validation should be done only when some keys from certification chain failed
956 // to be fetched. After that change, delaying will no longer be necessary.
957
958 // Stop retrying if delayed re-validation will be scheduled pass the deadline
959 if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500960
961 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
962
963 if (it != m_highestSeqNo.end() && it->second == seqNo) {
964 _LOG_DEBUG("Scheduling revalidation attempt");
965 m_scheduler.scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
966 ndn::bind(&Lsdb::retryContentValidation, this, data,
967 deadline, lsaName, seqNo));
968 }
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700969 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700970}
971
972void
akmhoque31d1d4b2014-05-05 22:08:14 -0500973Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500974 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500975{
akmhoque157b0a42014-05-13 00:26:37 -0500976 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500977 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500978 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500979 installNameLsa(nameLsa);
980 }
akmhoque157b0a42014-05-13 00:26:37 -0500981 else {
akmhoque2f423352014-06-03 11:49:35 -0500982 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500983 }
984 }
985}
986
987void
988Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500989 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -0500990{
akmhoque157b0a42014-05-13 00:26:37 -0500991 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500992 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500993 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500994 installAdjLsa(adjLsa);
995 }
akmhoque157b0a42014-05-13 00:26:37 -0500996 else {
akmhoque2f423352014-06-03 11:49:35 -0500997 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500998 }
999 }
1000}
1001
1002void
1003Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001004 uint64_t lsSeqNo, std::string& dataContent)
akmhoque31d1d4b2014-05-05 22:08:14 -05001005{
akmhoque157b0a42014-05-13 00:26:37 -05001006 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001007 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -05001008 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -05001009 installCoordinateLsa(corLsa);
1010 }
akmhoque157b0a42014-05-13 00:26:37 -05001011 else {
akmhoque2f423352014-06-03 11:49:35 -05001012 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001013 }
1014 }
1015}
1016
1017void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001018Lsdb::processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001019 const ndn::time::steady_clock::TimePoint& deadline, ndn::Name lsaName,
1020 uint64_t seqNo)
akmhoque31d1d4b2014-05-05 22:08:14 -05001021{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001022 const ndn::Name& interestName = interest.getName();
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001023 _LOG_DEBUG("Interest timed out for LSA: " << interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001024
1025 if (ndn::time::steady_clock::now() < deadline) {
Ashlesh Gawande5bf83172014-09-19 12:38:17 -05001026
1027 SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName);
1028
1029 if (it != m_highestSeqNo.end() && it->second == seqNo) {
1030 expressInterest(interestName, retransmitNo + 1, deadline);
1031 }
akmhoque06986672014-05-27 13:55:53 -05001032 }
akmhoque31d1d4b2014-05-05 22:08:14 -05001033}
1034
akmhoquec7a79b22014-05-26 08:06:19 -05001035ndn::time::system_clock::TimePoint
1036Lsdb::getLsaExpirationTimePoint()
1037{
1038 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1039 expirationTimePoint = expirationTimePoint +
1040 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1041 return expirationTimePoint;
1042}
akmhoque31d1d4b2014-05-05 22:08:14 -05001043
1044void
akmhoque2f423352014-06-03 11:49:35 -05001045Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001046{
akmhoque2f423352014-06-03 11:49:35 -05001047 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001048 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001049 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001050 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001051 }
1052}
1053
1054//-----utility function -----
1055bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001056Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001057{
alvy49b1c0c2014-12-19 13:57:46 -06001058 if (lsType == NameLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001059 return doesNameLsaExist(key);
1060 }
alvy49b1c0c2014-12-19 13:57:46 -06001061 else if (lsType == AdjLsa::TYPE_STRING) {
akmhoque53353462014-04-22 08:43:45 -05001062 return doesAdjLsaExist(key);
1063 }
alvy49b1c0c2014-12-19 13:57:46 -06001064 else if (lsType == CoordinateLsa::TYPE_STRING) {
akmhoqueb6450b12014-04-24 00:01:03 -05001065 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001066 }
1067 return false;
1068}
1069
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001070} // namespace nlsr