blob: ef45cea2f525e560c5b028851470d9188e313c01 [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:
akmhoque31d1d4b2014-05-05 22:08:14 -050042 Lsdb(Nlsr& nlsr)
43 : m_nlsr(nlsr)
44 , m_lsaRefreshTime(0)
akmhoque53353462014-04-22 08:43:45 -050045 {
46 }
47
48
49 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050050 doesLsaExist(const ndn::Name& key, const std::string& lsType);
akmhoque53353462014-04-22 08:43:45 -050051 // function related to Name LSDB
52
53 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050054 buildAndInstallOwnNameLsa();
akmhoque53353462014-04-22 08:43:45 -050055
akmhoqueb6450b12014-04-24 00:01:03 -050056 NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050057 findNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050058
59 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050060 installNameLsa(NameLsa& nlsa);
akmhoque53353462014-04-22 08:43:45 -050061
62 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050063 removeNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050064
65 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050066 isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050067
68 void
akmhoque2f423352014-06-03 11:49:35 -050069 writeNameLsdbLog();
akmhoque53353462014-04-22 08:43:45 -050070
71 //function related to Cor LSDB
72 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050073 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -050074
akmhoqueb6450b12014-04-24 00:01:03 -050075 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050076 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050077
78 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050079 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -050080
81 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050082 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050083
84 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050085 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050086
87 void
akmhoque2f423352014-06-03 11:49:35 -050088 writeCorLsdbLog();
akmhoque53353462014-04-22 08:43:45 -050089
90 //function related to Adj LSDB
91 void
akmhoque31d1d4b2014-05-05 22:08:14 -050092 scheduledAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -050093
94 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050095 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -050096
97 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050098 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050099
100 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500101 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500102 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500103 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500104
akmhoqueb6450b12014-04-24 00:01:03 -0500105 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500106 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500107
108 std::list<AdjLsa>&
109 getAdjLsdb();
110
111 void
akmhoque2f423352014-06-03 11:49:35 -0500112 writeAdjLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500113
akmhoque53353462014-04-22 08:43:45 -0500114 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700115 setLsaRefreshTime(const seconds& lsaRefreshTime);
akmhoque53353462014-04-22 08:43:45 -0500116
117 void
118 setThisRouterPrefix(std::string trp);
119
120private:
121 bool
122 addNameLsa(NameLsa& nlsa);
123
124 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500125 doesNameLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500126
127
128 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500129 addCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500130
131 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500132 doesCoordinateLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500133
134 bool
135 addAdjLsa(AdjLsa& alsa);
136
137 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500138 doesAdjLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500139
140 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500141 scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700142 const seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500143
144 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500145 exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500146
147 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500148 scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700149 const seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500150
151 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500152 exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500153
154 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500155 scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700156 const seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500157
158 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500159 exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500160 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500161public:
162 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700163 expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
164 steady_clock::TimePoint deadline = steady_clock::TimePoint::min());
akmhoque53353462014-04-22 08:43:45 -0500165
akmhoque31d1d4b2014-05-05 22:08:14 -0500166 void
167 processInterest(const ndn::Name& name, const ndn::Interest& interest);
akmhoque53353462014-04-22 08:43:45 -0500168
169private:
170 void
akmhoque69c9aa92014-07-23 15:15:05 -0500171 putLsaData(const ndn::Interest& interest, const std::string& content);
172
173 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500174 processInterestForNameLsa(const ndn::Interest& interest,
175 const ndn::Name& lsaKey,
176 uint32_t interestedlsSeqNo);
akmhoque53353462014-04-22 08:43:45 -0500177
akmhoque31d1d4b2014-05-05 22:08:14 -0500178 void
179 processInterestForAdjacencyLsa(const ndn::Interest& interest,
180 const ndn::Name& lsaKey,
181 uint32_t interestedlsSeqNo);
182
183 void
184 processInterestForCoordinateLsa(const ndn::Interest& interest,
185 const ndn::Name& lsaKey,
186 uint32_t interestedlsSeqNo);
187
188 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700189 onContent(const ndn::Data& data, const steady_clock::TimePoint& deadline);
190
191 /**
192 * @brief Retry validation after it fails
193 *
194 * Data packet validation can fail either because the packet does not have
195 * valid signature (fatal) or because some of the certificate chain Data packets
196 * failed to be fetched (non-fatal). Currently, the library does not provide
197 * clear indication (besides plain-text message in error callback) of what is
198 * the reason for failure and we will try to re-validate for as long as it the deadline.
199 */
200 void
201 retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data,
202 const steady_clock::TimePoint& deadline);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700203
204 void
205 onContentValidated(const ndn::shared_ptr<const ndn::Data>& data);
206
207 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700208 onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, const std::string& msg,
209 const steady_clock::TimePoint& deadline);
akmhoque31d1d4b2014-05-05 22:08:14 -0500210
211 void
212 processContentNameLsa(const ndn::Name& lsaKey,
213 uint32_t lsSeqNo, std::string& dataContent);
214
215 void
216 processContentAdjacencyLsa(const ndn::Name& lsaKey,
217 uint32_t lsSeqNo, std::string& dataContent);
218
219 void
220 processContentCoordinateLsa(const ndn::Name& lsaKey,
221 uint32_t lsSeqNo, std::string& dataContent);
222
223 void
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700224 processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo,
225 const steady_clock::TimePoint& deadline);
akmhoque31d1d4b2014-05-05 22:08:14 -0500226
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700227 system_clock::TimePoint
akmhoquec7a79b22014-05-26 08:06:19 -0500228 getLsaExpirationTimePoint();
229
akmhoque31d1d4b2014-05-05 22:08:14 -0500230private:
231 void
232 cancelScheduleLsaExpiringEvent(ndn::EventId eid);
233
234 Nlsr& m_nlsr;
akmhoque53353462014-04-22 08:43:45 -0500235 std::list<NameLsa> m_nameLsdb;
236 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500237 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500238
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700239 seconds m_lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500240 std::string m_thisRouterPrefix;
241
242};
243
244}//namespace nlsr
245
246#endif //NLSR_LSDB_HPP