blob: 752b52b201ea756582a280bf3969cf148ce23636 [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#ifndef NLSR_LSDB_HPP
2#define NLSR_LSDB_HPP
3
4#include <utility>
akmhoquefdbddb12014-05-02 18:35:19 -05005#include <boost/cstdint.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -05006#include <ndn-cxx/security/key-chain.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -05007#include <ndn-cxx/util/time.hpp>
akmhoquefdbddb12014-05-02 18:35:19 -05008
akmhoque53353462014-04-22 08:43:45 -05009#include "lsa.hpp"
10
11namespace nlsr {
12class Nlsr;
13
14class Lsdb
15{
16public:
akmhoque31d1d4b2014-05-05 22:08:14 -050017 Lsdb(Nlsr& nlsr)
18 : m_nlsr(nlsr)
19 , m_lsaRefreshTime(0)
akmhoque53353462014-04-22 08:43:45 -050020 {
21 }
22
23
24 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050025 doesLsaExist(const ndn::Name& key, const std::string& lsType);
akmhoque53353462014-04-22 08:43:45 -050026 // function related to Name LSDB
27
28 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050029 buildAndInstallOwnNameLsa();
akmhoque53353462014-04-22 08:43:45 -050030
akmhoqueb6450b12014-04-24 00:01:03 -050031 NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050032 findNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050033
34 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050035 installNameLsa(NameLsa& nlsa);
akmhoque53353462014-04-22 08:43:45 -050036
37 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050038 removeNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050039
40 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050041 isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050042
akmhoque157b0a42014-05-13 00:26:37 -050043 //debugging
akmhoque53353462014-04-22 08:43:45 -050044 void
akmhoque157b0a42014-05-13 00:26:37 -050045 printNameLsdb();
akmhoque53353462014-04-22 08:43:45 -050046
47 //function related to Cor LSDB
48 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050049 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -050050
akmhoqueb6450b12014-04-24 00:01:03 -050051 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050052 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050053
54 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050055 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -050056
57 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050058 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050059
60 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050061 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050062
akmhoque157b0a42014-05-13 00:26:37 -050063 //debugging
akmhoque53353462014-04-22 08:43:45 -050064 void
akmhoque157b0a42014-05-13 00:26:37 -050065 printCorLsdb();
akmhoque53353462014-04-22 08:43:45 -050066
67 //function related to Adj LSDB
68 void
akmhoque31d1d4b2014-05-05 22:08:14 -050069 scheduledAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -050070
71 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050072 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -050073
74 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050075 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050076
77 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050078 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050079 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050080 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -050081
akmhoqueb6450b12014-04-24 00:01:03 -050082 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050083 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050084
85 std::list<AdjLsa>&
86 getAdjLsdb();
87
88 void
89 printAdjLsdb();
90
91 //void scheduleRefreshLsdb(Nlsr& pnlsr, int interval);
92 void
93 setLsaRefreshTime(int lrt);
94
95 void
96 setThisRouterPrefix(std::string trp);
97
98private:
99 bool
100 addNameLsa(NameLsa& nlsa);
101
102 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500103 doesNameLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500104
105
106 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500107 addCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500108
109 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500110 doesCoordinateLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500111
112 bool
113 addAdjLsa(AdjLsa& alsa);
114
115 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500116 doesAdjLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500117
118 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500119 scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
120 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500121
122 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500123 exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500124
125 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500126 scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
127 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500128
129 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500130 exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500131
132 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500133 scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoquec7a79b22014-05-26 08:06:19 -0500134 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500135
136 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500137 exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500138 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500139public:
140 void
141 expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime);
akmhoque53353462014-04-22 08:43:45 -0500142
akmhoque31d1d4b2014-05-05 22:08:14 -0500143 void
144 processInterest(const ndn::Name& name, const ndn::Interest& interest);
akmhoque53353462014-04-22 08:43:45 -0500145
146private:
147 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500148 processInterestForNameLsa(const ndn::Interest& interest,
149 const ndn::Name& lsaKey,
150 uint32_t interestedlsSeqNo);
akmhoque53353462014-04-22 08:43:45 -0500151
akmhoque31d1d4b2014-05-05 22:08:14 -0500152 void
153 processInterestForAdjacencyLsa(const ndn::Interest& interest,
154 const ndn::Name& lsaKey,
155 uint32_t interestedlsSeqNo);
156
157 void
158 processInterestForCoordinateLsa(const ndn::Interest& interest,
159 const ndn::Name& lsaKey,
160 uint32_t interestedlsSeqNo);
161
162 void
163 processContent(const ndn::Interest& interest, const ndn::Data& data);
164
165 void
166 processContentNameLsa(const ndn::Name& lsaKey,
167 uint32_t lsSeqNo, std::string& dataContent);
168
169 void
170 processContentAdjacencyLsa(const ndn::Name& lsaKey,
171 uint32_t lsSeqNo, std::string& dataContent);
172
173 void
174 processContentCoordinateLsa(const ndn::Name& lsaKey,
175 uint32_t lsSeqNo, std::string& dataContent);
176
177 void
178 processInterestTimedOut(const ndn::Interest& interest);
179
akmhoquec7a79b22014-05-26 08:06:19 -0500180 ndn::time::system_clock::TimePoint
181 getLsaExpirationTimePoint();
182
akmhoque31d1d4b2014-05-05 22:08:14 -0500183private:
184 void
185 cancelScheduleLsaExpiringEvent(ndn::EventId eid);
186
187 Nlsr& m_nlsr;
188 ndn::KeyChain m_keyChain;
akmhoque53353462014-04-22 08:43:45 -0500189 std::list<NameLsa> m_nameLsdb;
190 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500191 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500192
193 int m_lsaRefreshTime;
194 std::string m_thisRouterPrefix;
195
196};
197
198}//namespace nlsr
199
200#endif //NLSR_LSDB_HPP