blob: ef981388dbeef34061a1df7fc51fee367499ad3c [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
akmhoque06986672014-05-27 13:55:53 -0500141 expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime,
142 uint32_t timeoutCount);
akmhoque53353462014-04-22 08:43:45 -0500143
akmhoque31d1d4b2014-05-05 22:08:14 -0500144 void
145 processInterest(const ndn::Name& name, const ndn::Interest& interest);
akmhoque53353462014-04-22 08:43:45 -0500146
147private:
148 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500149 processInterestForNameLsa(const ndn::Interest& interest,
150 const ndn::Name& lsaKey,
151 uint32_t interestedlsSeqNo);
akmhoque53353462014-04-22 08:43:45 -0500152
akmhoque31d1d4b2014-05-05 22:08:14 -0500153 void
154 processInterestForAdjacencyLsa(const ndn::Interest& interest,
155 const ndn::Name& lsaKey,
156 uint32_t interestedlsSeqNo);
157
158 void
159 processInterestForCoordinateLsa(const ndn::Interest& interest,
160 const ndn::Name& lsaKey,
161 uint32_t interestedlsSeqNo);
162
163 void
164 processContent(const ndn::Interest& interest, const ndn::Data& data);
165
166 void
167 processContentNameLsa(const ndn::Name& lsaKey,
168 uint32_t lsSeqNo, std::string& dataContent);
169
170 void
171 processContentAdjacencyLsa(const ndn::Name& lsaKey,
172 uint32_t lsSeqNo, std::string& dataContent);
173
174 void
175 processContentCoordinateLsa(const ndn::Name& lsaKey,
176 uint32_t lsSeqNo, std::string& dataContent);
177
178 void
akmhoque06986672014-05-27 13:55:53 -0500179 processInterestTimedOut(const ndn::Interest& interest, uint32_t timeoutCount);
akmhoque31d1d4b2014-05-05 22:08:14 -0500180
akmhoquec7a79b22014-05-26 08:06:19 -0500181 ndn::time::system_clock::TimePoint
182 getLsaExpirationTimePoint();
183
akmhoque31d1d4b2014-05-05 22:08:14 -0500184private:
185 void
186 cancelScheduleLsaExpiringEvent(ndn::EventId eid);
187
188 Nlsr& m_nlsr;
189 ndn::KeyChain m_keyChain;
akmhoque53353462014-04-22 08:43:45 -0500190 std::list<NameLsa> m_nameLsdb;
191 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500192 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500193
194 int m_lsaRefreshTime;
195 std::string m_thisRouterPrefix;
196
197};
198
199}//namespace nlsr
200
201#endif //NLSR_LSDB_HPP