blob: 56c4245f470251124b9ba96b94c1638ffaa4fa0a [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
akmhoque157b0a42014-05-13 00:26:37 -050065 //debugging
akmhoque53353462014-04-22 08:43:45 -050066 void
akmhoque157b0a42014-05-13 00:26:37 -050067 printNameLsdb();
akmhoque53353462014-04-22 08:43:45 -050068
69 //function related to Cor LSDB
70 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050071 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -050072
akmhoqueb6450b12014-04-24 00:01:03 -050073 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050074 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050075
76 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050077 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -050078
79 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050080 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050081
82 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050083 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050084
akmhoque157b0a42014-05-13 00:26:37 -050085 //debugging
akmhoque53353462014-04-22 08:43:45 -050086 void
akmhoque157b0a42014-05-13 00:26:37 -050087 printCorLsdb();
akmhoque53353462014-04-22 08:43:45 -050088
89 //function related to Adj LSDB
90 void
akmhoque31d1d4b2014-05-05 22:08:14 -050091 scheduledAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -050092
93 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050094 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -050095
96 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050097 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050098
99 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500100 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500101 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500102 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500103
akmhoqueb6450b12014-04-24 00:01:03 -0500104 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500105 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500106
107 std::list<AdjLsa>&
108 getAdjLsdb();
109
110 void
111 printAdjLsdb();
112
113 //void scheduleRefreshLsdb(Nlsr& pnlsr, int interval);
114 void
115 setLsaRefreshTime(int lrt);
116
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,
142 const ndn::time::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,
149 const ndn::time::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,
akmhoquec7a79b22014-05-26 08:06:19 -0500156 const ndn::time::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
akmhoque06986672014-05-27 13:55:53 -0500163 expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime,
164 uint32_t timeoutCount);
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
akmhoque31d1d4b2014-05-05 22:08:14 -0500171 processInterestForNameLsa(const ndn::Interest& interest,
172 const ndn::Name& lsaKey,
173 uint32_t interestedlsSeqNo);
akmhoque53353462014-04-22 08:43:45 -0500174
akmhoque31d1d4b2014-05-05 22:08:14 -0500175 void
176 processInterestForAdjacencyLsa(const ndn::Interest& interest,
177 const ndn::Name& lsaKey,
178 uint32_t interestedlsSeqNo);
179
180 void
181 processInterestForCoordinateLsa(const ndn::Interest& interest,
182 const ndn::Name& lsaKey,
183 uint32_t interestedlsSeqNo);
184
185 void
186 processContent(const ndn::Interest& interest, const ndn::Data& data);
187
188 void
189 processContentNameLsa(const ndn::Name& lsaKey,
190 uint32_t lsSeqNo, std::string& dataContent);
191
192 void
193 processContentAdjacencyLsa(const ndn::Name& lsaKey,
194 uint32_t lsSeqNo, std::string& dataContent);
195
196 void
197 processContentCoordinateLsa(const ndn::Name& lsaKey,
198 uint32_t lsSeqNo, std::string& dataContent);
199
200 void
akmhoque06986672014-05-27 13:55:53 -0500201 processInterestTimedOut(const ndn::Interest& interest, uint32_t timeoutCount);
akmhoque31d1d4b2014-05-05 22:08:14 -0500202
akmhoquec7a79b22014-05-26 08:06:19 -0500203 ndn::time::system_clock::TimePoint
204 getLsaExpirationTimePoint();
205
akmhoque31d1d4b2014-05-05 22:08:14 -0500206private:
207 void
208 cancelScheduleLsaExpiringEvent(ndn::EventId eid);
209
210 Nlsr& m_nlsr;
211 ndn::KeyChain m_keyChain;
akmhoque53353462014-04-22 08:43:45 -0500212 std::list<NameLsa> m_nameLsdb;
213 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500214 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500215
216 int m_lsaRefreshTime;
217 std::string m_thisRouterPrefix;
218
219};
220
221}//namespace nlsr
222
223#endif //NLSR_LSDB_HPP