blob: dc7882d81d70e85591f5af28f18bbf449af186cd [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoque53353462014-04-22 08:43:45 -050023#include <string>
24#include <utility>
akmhoque157b0a42014-05-13 00:26:37 -050025
akmhoque53353462014-04-22 08:43:45 -050026#include "lsdb.hpp"
27#include "nlsr.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050028#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050029#include "utility/name-helper.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050030#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050031
32namespace nlsr {
33
akmhoque674b0b12014-05-20 14:33:28 -050034INIT_LOGGER("Lsdb");
35
akmhoque53353462014-04-22 08:43:45 -050036using namespace std;
37
38void
akmhoque31d1d4b2014-05-05 22:08:14 -050039Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
akmhoque53353462014-04-22 08:43:45 -050040{
akmhoque31d1d4b2014-05-05 22:08:14 -050041 m_nlsr.getScheduler().cancelEvent(eid);
akmhoque53353462014-04-22 08:43:45 -050042}
43
44static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050045nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -050046{
47 return nlsa1.getKey() == key;
48}
49
50
51bool
akmhoque31d1d4b2014-05-05 22:08:14 -050052Lsdb::buildAndInstallOwnNameLsa()
akmhoque53353462014-04-22 08:43:45 -050053{
akmhoque31d1d4b2014-05-05 22:08:14 -050054 NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
55 "name",
56 m_nlsr.getSequencingManager().getNameLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -050057 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -050058 m_nlsr.getNamePrefixList());
59 m_nlsr.getSequencingManager().increaseNameLsaSeq();
60 return installNameLsa(nameLsa);
akmhoque53353462014-04-22 08:43:45 -050061}
62
akmhoqueb6450b12014-04-24 00:01:03 -050063NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050064Lsdb::findNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -050065{
66 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
67 m_nameLsdb.end(),
68 bind(nameLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -050069 if (it != m_nameLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -050070 return &(*it);
akmhoque53353462014-04-22 08:43:45 -050071 }
akmhoqueb6450b12014-04-24 00:01:03 -050072 return 0;
akmhoque53353462014-04-22 08:43:45 -050073}
74
75bool
akmhoque31d1d4b2014-05-05 22:08:14 -050076Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -050077{
akmhoqueb6450b12014-04-24 00:01:03 -050078 NameLsa* nameLsaCheck = findNameLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -050079 if (nameLsaCheck != 0) {
80 if (nameLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -050081 return true;
82 }
akmhoque157b0a42014-05-13 00:26:37 -050083 else {
akmhoque53353462014-04-22 08:43:45 -050084 return false;
85 }
86 }
87 return true;
88}
89
90ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -050091Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
92 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -050093{
akmhoquec7a79b22014-05-26 08:06:19 -050094 return m_nlsr.getScheduler().scheduleEvent(expTime,
akmhoque31d1d4b2014-05-05 22:08:14 -050095 ndn::bind(&Lsdb::exprireOrRefreshNameLsa,
96 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -050097}
98
99bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500100Lsdb::installNameLsa(NameLsa& nlsa)
akmhoque53353462014-04-22 08:43:45 -0500101{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700102 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500103 NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500104 if (chkNameLsa == 0) {
akmhoque53353462014-04-22 08:43:45 -0500105 addNameLsa(nlsa);
akmhoque2f423352014-06-03 11:49:35 -0500106 _LOG_DEBUG("New Name LSA");
107 _LOG_DEBUG("Adding Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500108 nlsa.writeLog();
akmhoque674b0b12014-05-20 14:33:28 -0500109
akmhoque157b0a42014-05-13 00:26:37 -0500110 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500111 m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
112 nlsa.getOrigRouter());
113 std::list<ndn::Name> nameList = nlsa.getNpl().getNameList();
114 for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end();
akmhoque157b0a42014-05-13 00:26:37 -0500115 it++) {
116 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500117 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500118 }
119 }
120 }
akmhoque157b0a42014-05-13 00:26:37 -0500121 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500122 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
123 ndn::time::system_clock::now();
124 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500125 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500126 nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500127 nlsa.getLsSeqNo(),
128 timeToExpire));
129 }
akmhoque157b0a42014-05-13 00:26:37 -0500130 else {
131 if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500132 _LOG_DEBUG("Updated Name LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500133 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500134 chkNameLsa->writeLog();
135 chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500136 chkNameLsa->setExpirationTimePoint(nlsa.getExpirationTimePoint());
akmhoqueb6450b12014-04-24 00:01:03 -0500137 chkNameLsa->getNpl().sort();
akmhoque53353462014-04-22 08:43:45 -0500138 nlsa.getNpl().sort();
akmhoque31d1d4b2014-05-05 22:08:14 -0500139 std::list<ndn::Name> nameToAdd;
akmhoque53353462014-04-22 08:43:45 -0500140 std::set_difference(nlsa.getNpl().getNameList().begin(),
141 nlsa.getNpl().getNameList().end(),
akmhoqueb6450b12014-04-24 00:01:03 -0500142 chkNameLsa->getNpl().getNameList().begin(),
143 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500144 std::inserter(nameToAdd, nameToAdd.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500145 for (std::list<ndn::Name>::iterator it = nameToAdd.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500146 it != nameToAdd.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500147 chkNameLsa->addName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500148 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
149 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500150 m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500151 }
152 }
153 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500154 std::list<ndn::Name> nameToRemove;
akmhoqueb6450b12014-04-24 00:01:03 -0500155 std::set_difference(chkNameLsa->getNpl().getNameList().begin(),
156 chkNameLsa->getNpl().getNameList().end(),
akmhoque53353462014-04-22 08:43:45 -0500157 nlsa.getNpl().getNameList().begin(),
158 nlsa.getNpl().getNameList().end(),
159 std::inserter(nameToRemove, nameToRemove.begin()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500160 for (std::list<ndn::Name>::iterator it = nameToRemove.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500161 it != nameToRemove.end(); ++it) {
akmhoqueb6450b12014-04-24 00:01:03 -0500162 chkNameLsa->removeName((*it));
akmhoque157b0a42014-05-13 00:26:37 -0500163 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
164 if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500165 m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500166 }
167 }
168 }
akmhoque157b0a42014-05-13 00:26:37 -0500169 if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500170 ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() -
171 ndn::time::system_clock::now();
172 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500173 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500174 cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
175 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500176 nlsa.getLsSeqNo(),
177 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500178 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500179 chkNameLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500180 }
181 }
182 return true;
183}
184
185bool
186Lsdb::addNameLsa(NameLsa& nlsa)
187{
188 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
189 m_nameLsdb.end(),
190 bind(nameLsaCompareByKey, _1,
191 nlsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500192 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500193 m_nameLsdb.push_back(nlsa);
194 return true;
195 }
196 return false;
197}
198
199bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500200Lsdb::removeNameLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500201{
202 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
203 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500204 ndn::bind(nameLsaCompareByKey, _1, key));
205 if (it != m_nameLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500206 _LOG_DEBUG("Deleting Name Lsa");
akmhoque53353462014-04-22 08:43:45 -0500207 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500208 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500209 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500210 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
211 (*it).getOrigRouter());
212 for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500213 nit != (*it).getNpl().getNameList().end(); ++nit) {
214 if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500215 m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500216 }
217 }
218 }
219 m_nameLsdb.erase(it);
220 return true;
221 }
222 return false;
223}
224
225bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500226Lsdb::doesNameLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500227{
228 std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
229 m_nameLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500230 ndn::bind(nameLsaCompareByKey, _1, key));
231 if (it == m_nameLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500232 return false;
233 }
234 return true;
235}
236
237void
akmhoque2f423352014-06-03 11:49:35 -0500238Lsdb::writeNameLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500239{
akmhoque2f423352014-06-03 11:49:35 -0500240 _LOG_DEBUG("---------------Name LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -0500241 for (std::list<NameLsa>::iterator it = m_nameLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500242 it != m_nameLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500243 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500244 }
245}
246
247// Cor LSA and LSDB related Functions start here
248
akmhoque53353462014-04-22 08:43:45 -0500249static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500250corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500251{
252 return clsa.getKey() == key;
253}
254
255bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500256Lsdb::buildAndInstallOwnCoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500257{
akmhoque31d1d4b2014-05-05 22:08:14 -0500258 CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
259 "coordinate",
260 m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500261 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500262 m_nlsr.getConfParameter().getCorR(),
263 m_nlsr.getConfParameter().getCorTheta());
264 m_nlsr.getSequencingManager().increaseCorLsaSeq();
265 installCoordinateLsa(corLsa);
akmhoque53353462014-04-22 08:43:45 -0500266 return true;
267}
268
akmhoqueb6450b12014-04-24 00:01:03 -0500269CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500270Lsdb::findCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500271{
akmhoqueb6450b12014-04-24 00:01:03 -0500272 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
273 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500274 ndn::bind(corLsaCompareByKey, _1, key));
275 if (it != m_corLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500276 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500277 }
akmhoqueb6450b12014-04-24 00:01:03 -0500278 return 0;
akmhoque53353462014-04-22 08:43:45 -0500279}
280
281bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500282Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500283{
akmhoqueb6450b12014-04-24 00:01:03 -0500284 CoordinateLsa* clsa = findCoordinateLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500285 if (clsa != 0) {
286 if (clsa->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500287 return true;
288 }
akmhoque157b0a42014-05-13 00:26:37 -0500289 else {
akmhoque53353462014-04-22 08:43:45 -0500290 return false;
291 }
292 }
293 return true;
294}
295
296ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500297Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500298 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500299{
akmhoquec7a79b22014-05-26 08:06:19 -0500300 return m_nlsr.getScheduler().scheduleEvent(expTime,
akmhoque31d1d4b2014-05-05 22:08:14 -0500301 ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
302 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500303}
304
305bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500306Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500307{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700308 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500309 CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500310 if (chkCorLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500311 _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500312 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500313 clsa.writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500314 addCoordinateLsa(clsa);
akmhoque2f423352014-06-03 11:49:35 -0500315
akmhoque157b0a42014-05-13 00:26:37 -0500316 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500317 m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
318 clsa.getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500319 }
akmhoque157b0a42014-05-13 00:26:37 -0500320 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500321 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500322 }
akmhoque157b0a42014-05-13 00:26:37 -0500323 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500324 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
325 ndn::time::system_clock::now();
326 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500327 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500328 scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500329 clsa.getLsSeqNo(), timeToExpire);
akmhoque53353462014-04-22 08:43:45 -0500330 }
akmhoque157b0a42014-05-13 00:26:37 -0500331 else {
332 if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500333 _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500334 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500335 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500336 chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500337 chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500338 if (!chkCorLsa->isEqualContent(clsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500339 chkCorLsa->setCorRadius(clsa.getCorRadius());
340 chkCorLsa->setCorTheta(clsa.getCorTheta());
akmhoque157b0a42014-05-13 00:26:37 -0500341 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500342 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500343 }
344 }
akmhoque157b0a42014-05-13 00:26:37 -0500345 if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500346 ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() -
347 ndn::time::system_clock::now();
348 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500349 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500350 cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
351 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500352 clsa.getLsSeqNo(),
353 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500354 _LOG_DEBUG("Adding Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500355 chkCorLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500356 }
357 }
358 return true;
359}
360
361bool
akmhoqueb6450b12014-04-24 00:01:03 -0500362Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
akmhoque53353462014-04-22 08:43:45 -0500363{
akmhoqueb6450b12014-04-24 00:01:03 -0500364 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
365 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500366 ndn::bind(corLsaCompareByKey, _1,
367 clsa.getKey()));
368 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500369 m_corLsdb.push_back(clsa);
370 return true;
371 }
372 return false;
373}
374
375bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500376Lsdb::removeCoordinateLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500377{
akmhoqueb6450b12014-04-24 00:01:03 -0500378 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
379 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500380 ndn::bind(corLsaCompareByKey,
381 _1, key));
382 if (it != m_corLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500383 _LOG_DEBUG("Deleting Coordinate Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500384 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500385 if ((*it).getOrigRouter() !=
akmhoque157b0a42014-05-13 00:26:37 -0500386 m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500387 m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
388 (*it).getOrigRouter());
akmhoque53353462014-04-22 08:43:45 -0500389 }
390 m_corLsdb.erase(it);
391 return true;
392 }
393 return false;
394}
395
396bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500397Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500398{
akmhoqueb6450b12014-04-24 00:01:03 -0500399 std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
400 m_corLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500401 ndn::bind(corLsaCompareByKey,
402 _1, key));
403 if (it == m_corLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500404 return false;
405 }
406 return true;
407}
408
409void
akmhoque2f423352014-06-03 11:49:35 -0500410Lsdb::writeCorLsdbLog()
akmhoque53353462014-04-22 08:43:45 -0500411{
akmhoque2f423352014-06-03 11:49:35 -0500412 _LOG_DEBUG("---------------Cor LSDB-------------------");
akmhoqueb6450b12014-04-24 00:01:03 -0500413 for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500414 it != m_corLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -0500415 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -0500416 }
417}
418
akmhoque53353462014-04-22 08:43:45 -0500419// Adj LSA and LSDB related function starts here
420
421static bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500422adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500423{
424 return alsa.getKey() == key;
425}
426
akmhoque53353462014-04-22 08:43:45 -0500427void
akmhoque31d1d4b2014-05-05 22:08:14 -0500428Lsdb::scheduledAdjLsaBuild()
akmhoque53353462014-04-22 08:43:45 -0500429{
akmhoque674b0b12014-05-20 14:33:28 -0500430 _LOG_DEBUG("scheduledAdjLsaBuild Called");
431 m_nlsr.setIsBuildAdjLsaSheduled(false);
akmhoque157b0a42014-05-13 00:26:37 -0500432 if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500433 int adjBuildCount = m_nlsr.getAdjBuildCount();
akmhoque157b0a42014-05-13 00:26:37 -0500434 if (adjBuildCount > 0) {
435 if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500436 _LOG_DEBUG("Building and installing Adj LSA");
akmhoque31d1d4b2014-05-05 22:08:14 -0500437 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500438 }
akmhoque157b0a42014-05-13 00:26:37 -0500439 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500440 ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
441 key.append("adjacency");
442 removeAdjLsa(key);
443 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500444 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500445 m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
akmhoque53353462014-04-22 08:43:45 -0500446 }
447 }
akmhoque157b0a42014-05-13 00:26:37 -0500448 else {
akmhoque674b0b12014-05-20 14:33:28 -0500449 m_nlsr.setIsBuildAdjLsaSheduled(true);
akmhoque31d1d4b2014-05-05 22:08:14 -0500450 int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
451 m_nlsr.getConfParameter().getInterestResendTime();
452 m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime),
453 ndn::bind(&Lsdb::scheduledAdjLsaBuild,
454 this));
akmhoque53353462014-04-22 08:43:45 -0500455 }
456}
457
458
459bool
460Lsdb::addAdjLsa(AdjLsa& alsa)
461{
462 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
463 m_adjLsdb.end(),
464 bind(adjLsaCompareByKey, _1,
465 alsa.getKey()));
akmhoque157b0a42014-05-13 00:26:37 -0500466 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500467 m_adjLsdb.push_back(alsa);
468 return true;
469 }
470 return false;
471}
472
akmhoqueb6450b12014-04-24 00:01:03 -0500473AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500474Lsdb::findAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500475{
476 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
477 m_adjLsdb.end(),
478 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500479 if (it != m_adjLsdb.end()) {
akmhoqueb6450b12014-04-24 00:01:03 -0500480 return &(*it);
akmhoque53353462014-04-22 08:43:45 -0500481 }
akmhoqueb6450b12014-04-24 00:01:03 -0500482 return 0;
akmhoque53353462014-04-22 08:43:45 -0500483}
484
485
486bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500487Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500488{
akmhoqueb6450b12014-04-24 00:01:03 -0500489 AdjLsa* adjLsaCheck = findAdjLsa(key);
akmhoque157b0a42014-05-13 00:26:37 -0500490 if (adjLsaCheck != 0) {
491 if (adjLsaCheck->getLsSeqNo() < seqNo) {
akmhoque53353462014-04-22 08:43:45 -0500492 return true;
493 }
akmhoque157b0a42014-05-13 00:26:37 -0500494 else {
akmhoque53353462014-04-22 08:43:45 -0500495 return false;
496 }
497 }
498 return true;
499}
500
501
502ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500503Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
504 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -0500505{
akmhoquec7a79b22014-05-26 08:06:19 -0500506 return m_nlsr.getScheduler().scheduleEvent(expTime,
akmhoque31d1d4b2014-05-05 22:08:14 -0500507 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa,
508 this, key, seqNo));
akmhoque53353462014-04-22 08:43:45 -0500509}
510
511bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500512Lsdb::installAdjLsa(AdjLsa& alsa)
akmhoque53353462014-04-22 08:43:45 -0500513{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700514 ndn::time::seconds timeToExpire = m_lsaRefreshTime;
akmhoqueb6450b12014-04-24 00:01:03 -0500515 AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
akmhoque157b0a42014-05-13 00:26:37 -0500516 if (chkAdjLsa == 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500517 _LOG_DEBUG("New Adj LSA. Adding to LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500518 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500519 alsa.writeLog();
akmhoque53353462014-04-22 08:43:45 -0500520 addAdjLsa(alsa);
akmhoque31d1d4b2014-05-05 22:08:14 -0500521 alsa.addNptEntries(m_nlsr);
522 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque157b0a42014-05-13 00:26:37 -0500523 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500524 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
525 ndn::time::system_clock::now();
526 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500527 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500528 scheduleAdjLsaExpiration(alsa.getKey(),
akmhoque53353462014-04-22 08:43:45 -0500529 alsa.getLsSeqNo(), timeToExpire);
530 }
akmhoque157b0a42014-05-13 00:26:37 -0500531 else {
532 if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
akmhoque674b0b12014-05-20 14:33:28 -0500533 _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
akmhoque2f423352014-06-03 11:49:35 -0500534 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500535 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500536 chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500537 chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint());
akmhoque157b0a42014-05-13 00:26:37 -0500538 if (!chkAdjLsa->isEqualContent(alsa)) {
akmhoqueb6450b12014-04-24 00:01:03 -0500539 chkAdjLsa->getAdl().reset();
akmhoquefdbddb12014-05-02 18:35:19 -0500540 chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
akmhoque31d1d4b2014-05-05 22:08:14 -0500541 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500542 }
akmhoque157b0a42014-05-13 00:26:37 -0500543 if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
akmhoquec7a79b22014-05-26 08:06:19 -0500544 ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() -
545 ndn::time::system_clock::now();
546 timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration);
akmhoque53353462014-04-22 08:43:45 -0500547 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500548 cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
549 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
akmhoqueb6450b12014-04-24 00:01:03 -0500550 alsa.getLsSeqNo(),
551 timeToExpire));
akmhoque2f423352014-06-03 11:49:35 -0500552 _LOG_DEBUG("Adding Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500553 chkAdjLsa->writeLog();
akmhoque53353462014-04-22 08:43:45 -0500554 }
555 }
556 return true;
557}
558
559bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500560Lsdb::buildAndInstallOwnAdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500561{
akmhoque31d1d4b2014-05-05 22:08:14 -0500562 AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
563 "adjacency",
564 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
akmhoquec7a79b22014-05-26 08:06:19 -0500565 getLsaExpirationTimePoint(),
akmhoque31d1d4b2014-05-05 22:08:14 -0500566 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
567 m_nlsr.getAdjacencyList());
568 m_nlsr.getSequencingManager().increaseAdjLsaSeq();
569 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500570 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
571 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500572 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500573 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
574 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500575 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
576 lsaPrefix);
577 return installAdjLsa(adjLsa);
akmhoque53353462014-04-22 08:43:45 -0500578}
579
580bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500581Lsdb::removeAdjLsa(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500582{
583 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
584 m_adjLsdb.end(),
akmhoque157b0a42014-05-13 00:26:37 -0500585 ndn::bind(adjLsaCompareByKey, _1, key));
586 if (it != m_adjLsdb.end()) {
akmhoque2f423352014-06-03 11:49:35 -0500587 _LOG_DEBUG("Deleting Adj Lsa");
akmhoque674b0b12014-05-20 14:33:28 -0500588 (*it).writeLog();
akmhoque31d1d4b2014-05-05 22:08:14 -0500589 (*it).removeNptEntries(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500590 m_adjLsdb.erase(it);
591 return true;
592 }
593 return false;
594}
595
596bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500597Lsdb::doesAdjLsaExist(const ndn::Name& key)
akmhoque53353462014-04-22 08:43:45 -0500598{
599 std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
600 m_adjLsdb.end(),
601 bind(adjLsaCompareByKey, _1, key));
akmhoque157b0a42014-05-13 00:26:37 -0500602 if (it == m_adjLsdb.end()) {
akmhoque53353462014-04-22 08:43:45 -0500603 return false;
604 }
605 return true;
606}
607
608std::list<AdjLsa>&
609Lsdb::getAdjLsdb()
610{
611 return m_adjLsdb;
612}
613
614void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700615Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime)
akmhoque53353462014-04-22 08:43:45 -0500616{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700617 m_lsaRefreshTime = lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500618}
619
620void
621Lsdb::setThisRouterPrefix(string trp)
622{
623 m_thisRouterPrefix = trp;
624}
625
626void
akmhoque31d1d4b2014-05-05 22:08:14 -0500627Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500628{
akmhoque674b0b12014-05-20 14:33:28 -0500629 _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called");
630 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500631 NameLsa* chkNameLsa = findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500632 if (chkNameLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500633 _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500634 if (chkNameLsa->getLsSeqNo() == seqNo) {
635 if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500636 _LOG_DEBUG("Own Name LSA, so refreshing it");
637 _LOG_DEBUG("Deleting Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500638 chkNameLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500639 chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500640 m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500641 chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500642 _LOG_DEBUG("Adding Name Lsa");
akmhoqueb6450b12014-04-24 00:01:03 -0500643 chkNameLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500644 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500645 chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500646 chkNameLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700647 m_lsaRefreshTime));
akmhoque53353462014-04-22 08:43:45 -0500648 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500649 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
650 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500651 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500652 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
653 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500654 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
655 lsaPrefix);
akmhoque53353462014-04-22 08:43:45 -0500656 }
akmhoque157b0a42014-05-13 00:26:37 -0500657 else {
akmhoque674b0b12014-05-20 14:33:28 -0500658 _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500659 removeNameLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500660 }
661 }
662 }
663}
664
665void
akmhoque31d1d4b2014-05-05 22:08:14 -0500666Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500667{
akmhoque674b0b12014-05-20 14:33:28 -0500668 _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
669 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500670 AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500671 if (chkAdjLsa != 0) {
akmhoque2f423352014-06-03 11:49:35 -0500672 _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500673 if (chkAdjLsa->getLsSeqNo() == seqNo) {
674 if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500675 _LOG_DEBUG("Own Adj LSA, so refreshing it");
676 _LOG_DEBUG("Deleting Adj Lsa");
677 chkAdjLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500678 chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500679 m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500680 chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500681 _LOG_DEBUG("Adding Adj Lsa");
682 chkAdjLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500683 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500684 chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
akmhoquefdbddb12014-05-02 18:35:19 -0500685 chkAdjLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700686 m_lsaRefreshTime));
akmhoque53353462014-04-22 08:43:45 -0500687 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500688 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
689 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500690 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500691 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
692 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500693 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
694 lsaPrefix);
akmhoque53353462014-04-22 08:43:45 -0500695 }
akmhoque157b0a42014-05-13 00:26:37 -0500696 else {
akmhoque674b0b12014-05-20 14:33:28 -0500697 _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500698 removeAdjLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500699 }
700 // schedule Routing table calculaiton
akmhoque31d1d4b2014-05-05 22:08:14 -0500701 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500702 }
703 }
704}
705
706void
akmhoque31d1d4b2014-05-05 22:08:14 -0500707Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500708 uint64_t seqNo)
akmhoque53353462014-04-22 08:43:45 -0500709{
akmhoque674b0b12014-05-20 14:33:28 -0500710 _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
711 _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
akmhoqueb6450b12014-04-24 00:01:03 -0500712 CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500713 if (chkCorLsa != 0) {
akmhoque674b0b12014-05-20 14:33:28 -0500714 _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
akmhoque157b0a42014-05-13 00:26:37 -0500715 if (chkCorLsa->getLsSeqNo() == seqNo) {
716 if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
akmhoque2f423352014-06-03 11:49:35 -0500717 _LOG_DEBUG("Own Cor LSA, so refreshing it");
718 _LOG_DEBUG("Deleting Coordinate Lsa");
719 chkCorLsa->writeLog();
akmhoqueb6450b12014-04-24 00:01:03 -0500720 chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500721 m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
akmhoquec7a79b22014-05-26 08:06:19 -0500722 chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
akmhoque2f423352014-06-03 11:49:35 -0500723 _LOG_DEBUG("Adding Coordinate Lsa");
724 chkCorLsa->writeLog();
akmhoquefdbddb12014-05-02 18:35:19 -0500725 // schedule refreshing event again
akmhoque31d1d4b2014-05-05 22:08:14 -0500726 chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
727 chkCorLsa->getKey(),
728 chkCorLsa->getLsSeqNo(),
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700729 m_lsaRefreshTime));
akmhoque53353462014-04-22 08:43:45 -0500730 // publish routing update
akmhoque50125a92014-06-30 08:54:17 -0500731 //ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
732 //lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
akmhoque157b0a42014-05-13 00:26:37 -0500733 ndn::Name lsaPrefix = m_nlsr.getConfParameter().getLsaPrefix();
akmhoque50125a92014-06-30 08:54:17 -0500734 lsaPrefix.append(m_nlsr.getConfParameter().getSiteName());
735 lsaPrefix.append(m_nlsr.getConfParameter().getRouterName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500736 m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
737 lsaPrefix);
akmhoque53353462014-04-22 08:43:45 -0500738 }
akmhoque157b0a42014-05-13 00:26:37 -0500739 else {
akmhoque674b0b12014-05-20 14:33:28 -0500740 _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
akmhoque31d1d4b2014-05-05 22:08:14 -0500741 removeCoordinateLsa(lsaKey);
akmhoque53353462014-04-22 08:43:45 -0500742 }
akmhoque157b0a42014-05-13 00:26:37 -0500743 if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500744 m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
akmhoque53353462014-04-22 08:43:45 -0500745 }
746 }
747 }
748}
749
750
751void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700752Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
753 steady_clock::TimePoint deadline/* = steady_clock::TimePoint::min()*/)
akmhoque31d1d4b2014-05-05 22:08:14 -0500754{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700755 if (deadline == steady_clock::TimePoint::min()) {
756 deadline = steady_clock::now() + m_lsaRefreshTime;
757 }
758
akmhoque31d1d4b2014-05-05 22:08:14 -0500759 ndn::Interest interest(interestName);
akmhoquedfe615f2014-07-27 14:12:21 -0500760 uint64_t interestedLsSeqNo = interestName[-1].toNumber();
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700761 _LOG_DEBUG("Expressing Interest for LSA(name): " << interestName
762 << " Seq number: " << interestedLsSeqNo);
763 interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime());
akmhoque31d1d4b2014-05-05 22:08:14 -0500764 m_nlsr.getNlsrFace().expressInterest(interest,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700765 ndn::bind(&Lsdb::onContent,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700766 this, _2, deadline),
akmhoque31d1d4b2014-05-05 22:08:14 -0500767 ndn::bind(&Lsdb::processInterestTimedOut,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700768 this, _1, timeoutCount, deadline));
akmhoque31d1d4b2014-05-05 22:08:14 -0500769}
770
771void
772Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
773{
774 const ndn::Name& intName(interest.getName());
akmhoque674b0b12014-05-20 14:33:28 -0500775 _LOG_DEBUG("Interest recevied for LSA(name): " << intName);
akmhoque31d1d4b2014-05-05 22:08:14 -0500776 string chkString("LSA");
777 int32_t lsaPosition = util::getNameComponentPosition(interest.getName(),
778 chkString);
akmhoque157b0a42014-05-13 00:26:37 -0500779 if (lsaPosition >= 0) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500780 std::string interestedLsType;
781 uint64_t interestedLsSeqNo;
akmhoque50125a92014-06-30 08:54:17 -0500782 ndn::Name origRouter = m_nlsr.getConfParameter().getNetwork();
783 origRouter.append(intName.getSubName(lsaPosition + 1,
784 interest.getName().size() - lsaPosition - 3));
akmhoque157b0a42014-05-13 00:26:37 -0500785 interestedLsType = intName[-2].toUri();
akmhoque31d1d4b2014-05-05 22:08:14 -0500786 interestedLsSeqNo = intName[-1].toNumber();
akmhoquedfe615f2014-07-27 14:12:21 -0500787 _LOG_DEBUG("LSA sequence number from interest: " << interestedLsSeqNo);
akmhoque157b0a42014-05-13 00:26:37 -0500788 if (interestedLsType == "name") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500789 processInterestForNameLsa(interest,
790 origRouter.append(interestedLsType),
791 interestedLsSeqNo);
792 return;
793 }
akmhoque157b0a42014-05-13 00:26:37 -0500794 else if (interestedLsType == "adjacency") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500795 processInterestForAdjacencyLsa(interest,
796 origRouter.append(interestedLsType),
797 interestedLsSeqNo);
798 return;
799 }
akmhoque157b0a42014-05-13 00:26:37 -0500800 else if (interestedLsType == "coordinate") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500801 processInterestForCoordinateLsa(interest,
802 origRouter.append(interestedLsType),
803 interestedLsSeqNo);
804 return;
805 }
akmhoque157b0a42014-05-13 00:26:37 -0500806 else {
akmhoque2f423352014-06-03 11:49:35 -0500807 _LOG_DEBUG("Unrecognized LSA Type :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500808 }
809 }
810}
811
812void
akmhoque69c9aa92014-07-23 15:15:05 -0500813Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
814{
815 ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
816 data->setName(ndn::Name(interest.getName()).appendVersion());
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700817 data->setFreshnessPeriod(m_lsaRefreshTime);
akmhoque69c9aa92014-07-23 15:15:05 -0500818 data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
819 m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
akmhoquedfe615f2014-07-27 14:12:21 -0500820 ndn::SignatureSha256WithRsa signature(data->getSignature());
821 ndn::Name signingCertName = signature.getKeyLocator().getName();
akmhoque69c9aa92014-07-23 15:15:05 -0500822 _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
akmhoquedfe615f2014-07-27 14:12:21 -0500823 _LOG_DEBUG("Data signed with: " << signingCertName);
akmhoque69c9aa92014-07-23 15:15:05 -0500824 m_nlsr.getNlsrFace().put(*data);
825}
826
827void
akmhoque31d1d4b2014-05-05 22:08:14 -0500828Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
829 const ndn::Name& lsaKey,
830 uint32_t interestedlsSeqNo)
831{
832 NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500833 if (nameLsa != 0) {
834 if (nameLsa->getLsSeqNo() >= interestedlsSeqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500835 std::string content = nameLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500836 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500837 }
838 }
839}
840
841void
842Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
843 const ndn::Name& lsaKey,
844 uint32_t interestedlsSeqNo)
845{
846 AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500847 if (adjLsa != 0) {
848 if (adjLsa->getLsSeqNo() >= interestedlsSeqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500849 std::string content = adjLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500850 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500851 }
852 }
853}
854
855void
856Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
857 const ndn::Name& lsaKey,
858 uint32_t interestedlsSeqNo)
859{
860 CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
akmhoque157b0a42014-05-13 00:26:37 -0500861 if (corLsa != 0) {
862 if (corLsa->getLsSeqNo() >= interestedlsSeqNo) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500863 std::string content = corLsa->getData();
akmhoque69c9aa92014-07-23 15:15:05 -0500864 putLsaData(interest,content);
akmhoque31d1d4b2014-05-05 22:08:14 -0500865 }
866 }
867}
868
869void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700870Lsdb::onContent(const ndn::Data& data,
871 const steady_clock::TimePoint& deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -0500872{
akmhoquedfe615f2014-07-27 14:12:21 -0500873 _LOG_DEBUG("Received data for LSA(name): " << data.getName());
874 if (data.getSignature().hasKeyLocator()) {
875 if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
876 _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
877 }
878 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700879 m_nlsr.getValidator().validate(data,
880 ndn::bind(&Lsdb::onContentValidated, this, _1),
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700881 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
882 deadline));
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700883
884}
885
886void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700887Lsdb::retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
888 const steady_clock::TimePoint& deadline)
889{
890 _LOG_DEBUG("Retrying validation of LSA(name): " << data->getName());
891 if (data->getSignature().hasKeyLocator()) {
892 if (data->getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
893 _LOG_DEBUG("Data signed with: " << data->getSignature().getKeyLocator().getName());
894 }
895 }
896 m_nlsr.getValidator().validate(*data,
897 ndn::bind(&Lsdb::onContentValidated, this, _1),
898 ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2,
899 deadline));
900}
901
902void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700903Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
904{
905 const ndn::Name& dataName = data->getName();
akmhoquedfe615f2014-07-27 14:12:21 -0500906 _LOG_DEBUG("Data validation successful for LSA(name): " << dataName);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700907 string dataContent(reinterpret_cast<const char*>(data->getContent().value()));
akmhoque31d1d4b2014-05-05 22:08:14 -0500908 string chkString("LSA");
909 int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
akmhoque157b0a42014-05-13 00:26:37 -0500910 if (lsaPosition >= 0) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500911 std::string interestedLsType;
912 uint64_t interestedLsSeqNo;
akmhoque50125a92014-06-30 08:54:17 -0500913 ndn::Name origRouter = m_nlsr.getConfParameter().getNetwork();
914 origRouter.append(dataName.getSubName(lsaPosition + 1,
915 dataName.size() - lsaPosition - 4));
akmhoque157b0a42014-05-13 00:26:37 -0500916 interestedLsType = dataName[-3].toUri();
akmhoque31d1d4b2014-05-05 22:08:14 -0500917 interestedLsSeqNo = dataName[-2].toNumber();
akmhoque157b0a42014-05-13 00:26:37 -0500918 if (interestedLsType == "name") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500919 processContentNameLsa(origRouter.append(interestedLsType),
920 interestedLsSeqNo, dataContent);
921 return;
922 }
akmhoque157b0a42014-05-13 00:26:37 -0500923 else if (interestedLsType == "adjacency") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500924 processContentAdjacencyLsa(origRouter.append(interestedLsType),
925 interestedLsSeqNo, dataContent);
926 return;
927 }
akmhoque157b0a42014-05-13 00:26:37 -0500928 else if (interestedLsType == "coordinate") {
akmhoque31d1d4b2014-05-05 22:08:14 -0500929 processContentCoordinateLsa(origRouter.append(interestedLsType),
930 interestedLsSeqNo, dataContent);
931 return;
932 }
akmhoque157b0a42014-05-13 00:26:37 -0500933 else {
akmhoque2f423352014-06-03 11:49:35 -0500934 _LOG_DEBUG("Unrecognized LSA Type :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500935 }
936 }
937}
938
939void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700940Lsdb::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
941 const std::string& msg,
942 const steady_clock::TimePoint& deadline)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700943{
akmhoque2f423352014-06-03 11:49:35 -0500944 _LOG_DEBUG("Validation Error: " << msg);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700945
946 // Delay re-validation by LSA Interest Lifetime. When error callback will have an error
947 // code, re-validation should be done only when some keys from certification chain failed
948 // to be fetched. After that change, delaying will no longer be necessary.
949
950 // Stop retrying if delayed re-validation will be scheduled pass the deadline
951 if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) {
952 _LOG_DEBUG("Scheduling revalidation");
953 m_nlsr.getScheduler().scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(),
954 ndn::bind(&Lsdb::retryContentValidation,
955 this, data, deadline));
956 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700957}
958
959void
akmhoque31d1d4b2014-05-05 22:08:14 -0500960Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
961 uint32_t lsSeqNo, std::string& dataContent)
962{
akmhoque157b0a42014-05-13 00:26:37 -0500963 if (isNameLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500964 NameLsa nameLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500965 if (nameLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500966 installNameLsa(nameLsa);
967 }
akmhoque157b0a42014-05-13 00:26:37 -0500968 else {
akmhoque2f423352014-06-03 11:49:35 -0500969 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500970 }
971 }
972}
973
974void
975Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
976 uint32_t lsSeqNo, std::string& dataContent)
977{
akmhoque157b0a42014-05-13 00:26:37 -0500978 if (isAdjLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500979 AdjLsa adjLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500980 if (adjLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500981 installAdjLsa(adjLsa);
982 }
akmhoque157b0a42014-05-13 00:26:37 -0500983 else {
akmhoque2f423352014-06-03 11:49:35 -0500984 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -0500985 }
986 }
987}
988
989void
990Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
991 uint32_t lsSeqNo, std::string& dataContent)
992{
akmhoque157b0a42014-05-13 00:26:37 -0500993 if (isCoordinateLsaNew(lsaKey, lsSeqNo)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500994 CoordinateLsa corLsa;
akmhoque157b0a42014-05-13 00:26:37 -0500995 if (corLsa.initializeFromContent(dataContent)) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500996 installCoordinateLsa(corLsa);
997 }
akmhoque157b0a42014-05-13 00:26:37 -0500998 else {
akmhoque2f423352014-06-03 11:49:35 -0500999 _LOG_DEBUG("LSA data decoding error :(");
akmhoque31d1d4b2014-05-05 22:08:14 -05001000 }
1001 }
1002}
1003
1004void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001005Lsdb::processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
1006 const ndn::time::steady_clock::TimePoint& deadline)
akmhoque31d1d4b2014-05-05 22:08:14 -05001007{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001008 const ndn::Name& interestName = interest.getName();
akmhoque674b0b12014-05-20 14:33:28 -05001009 _LOG_DEBUG("Interest timed out for LSA(name): " << interestName);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -07001010
1011 if (ndn::time::steady_clock::now() < deadline) {
1012 expressInterest(interestName, retransmitNo + 1, deadline);
akmhoque06986672014-05-27 13:55:53 -05001013 }
akmhoque31d1d4b2014-05-05 22:08:14 -05001014}
1015
akmhoquec7a79b22014-05-26 08:06:19 -05001016ndn::time::system_clock::TimePoint
1017Lsdb::getLsaExpirationTimePoint()
1018{
1019 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
1020 expirationTimePoint = expirationTimePoint +
1021 ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval());
1022 return expirationTimePoint;
1023}
akmhoque31d1d4b2014-05-05 22:08:14 -05001024
1025void
akmhoque2f423352014-06-03 11:49:35 -05001026Lsdb::writeAdjLsdbLog()
akmhoque53353462014-04-22 08:43:45 -05001027{
akmhoque2f423352014-06-03 11:49:35 -05001028 _LOG_DEBUG("---------------Adj LSDB-------------------");
akmhoque53353462014-04-22 08:43:45 -05001029 for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin();
akmhoque157b0a42014-05-13 00:26:37 -05001030 it != m_adjLsdb.end() ; it++) {
akmhoque2f423352014-06-03 11:49:35 -05001031 (*it).writeLog();
akmhoque53353462014-04-22 08:43:45 -05001032 }
1033}
1034
1035//-----utility function -----
1036bool
akmhoque31d1d4b2014-05-05 22:08:14 -05001037Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
akmhoque53353462014-04-22 08:43:45 -05001038{
akmhoque157b0a42014-05-13 00:26:37 -05001039 if (lsType == "name") {
akmhoque53353462014-04-22 08:43:45 -05001040 return doesNameLsaExist(key);
1041 }
akmhoque157b0a42014-05-13 00:26:37 -05001042 else if (lsType == "adjacency") {
akmhoque53353462014-04-22 08:43:45 -05001043 return doesAdjLsaExist(key);
1044 }
akmhoque157b0a42014-05-13 00:26:37 -05001045 else if (lsType == "coordinate") {
akmhoqueb6450b12014-04-24 00:01:03 -05001046 return doesCoordinateLsaExist(key);
akmhoque53353462014-04-22 08:43:45 -05001047 }
1048 return false;
1049}
1050
Alexander Afanasyev8388ec62014-08-16 18:38:57 -07001051} // namespace nlsr