blob: 7c6ceb1612c6ad086e81592ef1a86b3d9ac6c019 [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 {
34class Nlsr;
35
36class Lsdb
37{
38public:
akmhoque31d1d4b2014-05-05 22:08:14 -050039 Lsdb(Nlsr& nlsr)
40 : m_nlsr(nlsr)
41 , m_lsaRefreshTime(0)
akmhoque53353462014-04-22 08:43:45 -050042 {
43 }
44
45
46 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050047 doesLsaExist(const ndn::Name& key, const std::string& lsType);
akmhoque53353462014-04-22 08:43:45 -050048 // function related to Name LSDB
49
50 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050051 buildAndInstallOwnNameLsa();
akmhoque53353462014-04-22 08:43:45 -050052
akmhoqueb6450b12014-04-24 00:01:03 -050053 NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050054 findNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050055
56 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050057 installNameLsa(NameLsa& nlsa);
akmhoque53353462014-04-22 08:43:45 -050058
59 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050060 removeNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050061
62 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050063 isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050064
65 void
akmhoque2f423352014-06-03 11:49:35 -050066 writeNameLsdbLog();
akmhoque53353462014-04-22 08:43:45 -050067
68 //function related to Cor LSDB
69 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050070 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -050071
akmhoqueb6450b12014-04-24 00:01:03 -050072 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050073 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050074
75 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050076 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -050077
78 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050079 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050080
81 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050082 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050083
84 void
akmhoque2f423352014-06-03 11:49:35 -050085 writeCorLsdbLog();
akmhoque53353462014-04-22 08:43:45 -050086
87 //function related to Adj LSDB
88 void
akmhoque31d1d4b2014-05-05 22:08:14 -050089 scheduledAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -050090
91 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050092 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -050093
94 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050095 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050096
97 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050098 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050099 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500100 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500101
akmhoqueb6450b12014-04-24 00:01:03 -0500102 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500103 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500104
105 std::list<AdjLsa>&
106 getAdjLsdb();
107
108 void
akmhoque2f423352014-06-03 11:49:35 -0500109 writeAdjLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500110
akmhoque53353462014-04-22 08:43:45 -0500111 void
112 setLsaRefreshTime(int lrt);
113
114 void
115 setThisRouterPrefix(std::string trp);
116
117private:
118 bool
119 addNameLsa(NameLsa& nlsa);
120
121 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500122 doesNameLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500123
124
125 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500126 addCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500127
128 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500129 doesCoordinateLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500130
131 bool
132 addAdjLsa(AdjLsa& alsa);
133
134 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500135 doesAdjLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500136
137 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500138 scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
139 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500140
141 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500142 exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500143
144 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500145 scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
146 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500147
148 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500149 exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500150
151 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500152 scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500153 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500154
155 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500156 exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500157 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500158public:
159 void
akmhoque06986672014-05-27 13:55:53 -0500160 expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime,
161 uint32_t timeoutCount);
akmhoque53353462014-04-22 08:43:45 -0500162
akmhoque31d1d4b2014-05-05 22:08:14 -0500163 void
164 processInterest(const ndn::Name& name, const ndn::Interest& interest);
akmhoque53353462014-04-22 08:43:45 -0500165
166private:
167 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500168 processInterestForNameLsa(const ndn::Interest& interest,
169 const ndn::Name& lsaKey,
170 uint32_t interestedlsSeqNo);
akmhoque53353462014-04-22 08:43:45 -0500171
akmhoque31d1d4b2014-05-05 22:08:14 -0500172 void
173 processInterestForAdjacencyLsa(const ndn::Interest& interest,
174 const ndn::Name& lsaKey,
175 uint32_t interestedlsSeqNo);
176
177 void
178 processInterestForCoordinateLsa(const ndn::Interest& interest,
179 const ndn::Name& lsaKey,
180 uint32_t interestedlsSeqNo);
181
182 void
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700183 onContent(const ndn::Interest& interest, const ndn::Data& data);
184
185 void
186 onContentValidated(const ndn::shared_ptr<const ndn::Data>& data);
187
188 void
189 onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, const std::string& msg);
akmhoque31d1d4b2014-05-05 22:08:14 -0500190
191 void
192 processContentNameLsa(const ndn::Name& lsaKey,
193 uint32_t lsSeqNo, std::string& dataContent);
194
195 void
196 processContentAdjacencyLsa(const ndn::Name& lsaKey,
197 uint32_t lsSeqNo, std::string& dataContent);
198
199 void
200 processContentCoordinateLsa(const ndn::Name& lsaKey,
201 uint32_t lsSeqNo, std::string& dataContent);
202
203 void
akmhoque06986672014-05-27 13:55:53 -0500204 processInterestTimedOut(const ndn::Interest& interest, uint32_t timeoutCount);
akmhoque31d1d4b2014-05-05 22:08:14 -0500205
akmhoquec7a79b22014-05-26 08:06:19 -0500206 ndn::time::system_clock::TimePoint
207 getLsaExpirationTimePoint();
208
akmhoque31d1d4b2014-05-05 22:08:14 -0500209private:
210 void
211 cancelScheduleLsaExpiringEvent(ndn::EventId eid);
212
213 Nlsr& m_nlsr;
akmhoque53353462014-04-22 08:43:45 -0500214 std::list<NameLsa> m_nameLsdb;
215 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500216 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500217
218 int m_lsaRefreshTime;
219 std::string m_thisRouterPrefix;
220
221};
222
223}//namespace nlsr
224
225#endif //NLSR_LSDB_HPP