blob: 8f1e77932a6148ed666528d6ec48a675cec23d4f [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#ifndef NLSR_LSDB_HPP
24#define NLSR_LSDB_HPP
25
26#include <utility>
akmhoquefdbddb12014-05-02 18:35:19 -050027#include <boost/cstdint.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050028#include <ndn-cxx/security/key-chain.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050029#include <ndn-cxx/util/time.hpp>
akmhoquefdbddb12014-05-02 18:35:19 -050030
akmhoque53353462014-04-22 08:43:45 -050031#include "lsa.hpp"
32
33namespace nlsr {
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070034
35using namespace ndn::time;
36
akmhoque53353462014-04-22 08:43:45 -050037class Nlsr;
38
39class Lsdb
40{
41public:
Vince Lehman7c603292014-09-11 17:48:16 -050042 Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler)
akmhoque31d1d4b2014-05-05 22:08:14 -050043 : m_nlsr(nlsr)
Vince Lehman7c603292014-09-11 17:48:16 -050044 , m_scheduler(scheduler)
akmhoque31d1d4b2014-05-05 22:08:14 -050045 , m_lsaRefreshTime(0)
akmhoque53353462014-04-22 08:43:45 -050046 {
47 }
48
49
50 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050051 doesLsaExist(const ndn::Name& key, const std::string& lsType);
akmhoque53353462014-04-22 08:43:45 -050052 // function related to Name LSDB
53
54 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050055 buildAndInstallOwnNameLsa();
akmhoque53353462014-04-22 08:43:45 -050056
akmhoqueb6450b12014-04-24 00:01:03 -050057 NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050058 findNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050059
60 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050061 installNameLsa(NameLsa& nlsa);
akmhoque53353462014-04-22 08:43:45 -050062
63 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050064 removeNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050065
66 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050067 isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050068
69 void
akmhoque2f423352014-06-03 11:49:35 -050070 writeNameLsdbLog();
akmhoque53353462014-04-22 08:43:45 -050071
72 //function related to Cor LSDB
73 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050074 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -050075
akmhoqueb6450b12014-04-24 00:01:03 -050076 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050077 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050078
79 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050080 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -050081
82 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050083 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050084
85 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050086 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050087
88 void
akmhoque2f423352014-06-03 11:49:35 -050089 writeCorLsdbLog();
akmhoque53353462014-04-22 08:43:45 -050090
91 //function related to Adj LSDB
92 void
akmhoque31d1d4b2014-05-05 22:08:14 -050093 scheduledAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -050094
95 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050096 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -050097
98 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050099 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500100
101 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500102 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500103 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500104 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500105
akmhoqueb6450b12014-04-24 00:01:03 -0500106 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500107 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500108
109 std::list<AdjLsa>&
110 getAdjLsdb();
111
112 void
akmhoque2f423352014-06-03 11:49:35 -0500113 writeAdjLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500114
akmhoque53353462014-04-22 08:43:45 -0500115 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700116 setLsaRefreshTime(const seconds& lsaRefreshTime);
akmhoque53353462014-04-22 08:43:45 -0500117
118 void
119 setThisRouterPrefix(std::string trp);
120
121private:
122 bool
123 addNameLsa(NameLsa& nlsa);
124
125 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500126 doesNameLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500127
128
129 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500130 addCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500131
132 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500133 doesCoordinateLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500134
135 bool
136 addAdjLsa(AdjLsa& alsa);
137
138 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500139 doesAdjLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500140
141 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500142 scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700143 const seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500144
145 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500146 exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500147
148 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500149 scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700150 const seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500151
152 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500153 exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500154
155 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500156 scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700157 const seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500158
159 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500160 exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500161 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500162public:
163 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700164 expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
165 steady_clock::TimePoint deadline = steady_clock::TimePoint::min());
akmhoque53353462014-04-22 08:43:45 -0500166
akmhoque31d1d4b2014-05-05 22:08:14 -0500167 void
168 processInterest(const ndn::Name& name, const ndn::Interest& interest);
akmhoque53353462014-04-22 08:43:45 -0500169
170private:
171 void
akmhoque69c9aa92014-07-23 15:15:05 -0500172 putLsaData(const ndn::Interest& interest, const std::string& content);
173
174 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500175 processInterestForNameLsa(const ndn::Interest& interest,
176 const ndn::Name& lsaKey,
177 uint32_t interestedlsSeqNo);
akmhoque53353462014-04-22 08:43:45 -0500178
akmhoque31d1d4b2014-05-05 22:08:14 -0500179 void
180 processInterestForAdjacencyLsa(const ndn::Interest& interest,
181 const ndn::Name& lsaKey,
182 uint32_t interestedlsSeqNo);
183
184 void
185 processInterestForCoordinateLsa(const ndn::Interest& interest,
186 const ndn::Name& lsaKey,
187 uint32_t interestedlsSeqNo);
188
189 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700190 onContent(const ndn::Data& data, const steady_clock::TimePoint& deadline);
191
192 /**
193 * @brief Retry validation after it fails
194 *
195 * Data packet validation can fail either because the packet does not have
196 * valid signature (fatal) or because some of the certificate chain Data packets
197 * failed to be fetched (non-fatal). Currently, the library does not provide
198 * clear indication (besides plain-text message in error callback) of what is
199 * the reason for failure and we will try to re-validate for as long as it the deadline.
200 */
201 void
202 retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
203 const steady_clock::TimePoint& deadline);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700204
205 void
206 onContentValidated(const ndn::shared_ptr<const ndn::Data>& data);
207
208 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700209 onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, const std::string& msg,
210 const steady_clock::TimePoint& deadline);
akmhoque31d1d4b2014-05-05 22:08:14 -0500211
212 void
213 processContentNameLsa(const ndn::Name& lsaKey,
214 uint32_t lsSeqNo, std::string& dataContent);
215
216 void
217 processContentAdjacencyLsa(const ndn::Name& lsaKey,
218 uint32_t lsSeqNo, std::string& dataContent);
219
220 void
221 processContentCoordinateLsa(const ndn::Name& lsaKey,
222 uint32_t lsSeqNo, std::string& dataContent);
223
224 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700225 processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
226 const steady_clock::TimePoint& deadline);
akmhoque31d1d4b2014-05-05 22:08:14 -0500227
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700228 system_clock::TimePoint
akmhoquec7a79b22014-05-26 08:06:19 -0500229 getLsaExpirationTimePoint();
230
akmhoque31d1d4b2014-05-05 22:08:14 -0500231private:
232 void
233 cancelScheduleLsaExpiringEvent(ndn::EventId eid);
234
235 Nlsr& m_nlsr;
Vince Lehman7c603292014-09-11 17:48:16 -0500236 ndn::Scheduler& m_scheduler;
237
akmhoque53353462014-04-22 08:43:45 -0500238 std::list<NameLsa> m_nameLsdb;
239 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500240 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500241
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700242 seconds m_lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500243 std::string m_thisRouterPrefix;
244
Vince Lehman18841082014-08-19 17:15:24 -0500245 static const ndn::time::seconds GRACE_PERIOD;
akmhoque53353462014-04-22 08:43:45 -0500246};
247
248}//namespace nlsr
249
250#endif //NLSR_LSDB_HPP