blob: ff7450ae808504d66cef99a2964934061a5f08af [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>
akmhoquefdbddb12014-05-02 18:35:19 -05007
akmhoque53353462014-04-22 08:43:45 -05008#include "lsa.hpp"
9
10namespace nlsr {
11class Nlsr;
12
13class Lsdb
14{
15public:
akmhoque31d1d4b2014-05-05 22:08:14 -050016 Lsdb(Nlsr& nlsr)
17 : m_nlsr(nlsr)
18 , m_lsaRefreshTime(0)
akmhoque53353462014-04-22 08:43:45 -050019 {
20 }
21
22
23 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050024 doesLsaExist(const ndn::Name& key, const std::string& lsType);
akmhoque53353462014-04-22 08:43:45 -050025 // function related to Name LSDB
26
27 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050028 buildAndInstallOwnNameLsa();
akmhoque53353462014-04-22 08:43:45 -050029
akmhoqueb6450b12014-04-24 00:01:03 -050030 NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050031 findNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050032
33 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050034 installNameLsa(NameLsa& nlsa);
akmhoque53353462014-04-22 08:43:45 -050035
36 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050037 removeNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050038
39 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050040 isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050041
akmhoque157b0a42014-05-13 00:26:37 -050042 //debugging
akmhoque53353462014-04-22 08:43:45 -050043 void
akmhoque157b0a42014-05-13 00:26:37 -050044 printNameLsdb();
akmhoque53353462014-04-22 08:43:45 -050045
46 //function related to Cor LSDB
47 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050048 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -050049
akmhoqueb6450b12014-04-24 00:01:03 -050050 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050051 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050052
53 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050054 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -050055
56 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050057 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050058
59 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050060 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050061
akmhoque157b0a42014-05-13 00:26:37 -050062 //debugging
akmhoque53353462014-04-22 08:43:45 -050063 void
akmhoque157b0a42014-05-13 00:26:37 -050064 printCorLsdb();
akmhoque53353462014-04-22 08:43:45 -050065
66 //function related to Adj LSDB
67 void
akmhoque31d1d4b2014-05-05 22:08:14 -050068 scheduledAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -050069
70 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050071 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -050072
73 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050074 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050075
76 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050077 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050078 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050079 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -050080
akmhoqueb6450b12014-04-24 00:01:03 -050081 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050082 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050083
84 std::list<AdjLsa>&
85 getAdjLsdb();
86
87 void
88 printAdjLsdb();
89
90 //void scheduleRefreshLsdb(Nlsr& pnlsr, int interval);
91 void
92 setLsaRefreshTime(int lrt);
93
94 void
95 setThisRouterPrefix(std::string trp);
96
97private:
98 bool
99 addNameLsa(NameLsa& nlsa);
100
101 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500102 doesNameLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500103
104
105 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500106 addCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500107
108 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500109 doesCoordinateLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500110
111 bool
112 addAdjLsa(AdjLsa& alsa);
113
114 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500115 doesAdjLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500116
117 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500118 scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, int expTime);
akmhoque53353462014-04-22 08:43:45 -0500119
120 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500121 exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500122
123 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500124 scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, int expTime);
akmhoque53353462014-04-22 08:43:45 -0500125
126 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500127 exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500128
129 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500130 scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoqueb6450b12014-04-24 00:01:03 -0500131 int expTime);
akmhoque53353462014-04-22 08:43:45 -0500132
133 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500134 exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500135 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500136public:
137 void
138 expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime);
akmhoque53353462014-04-22 08:43:45 -0500139
akmhoque31d1d4b2014-05-05 22:08:14 -0500140 void
141 processInterest(const ndn::Name& name, const ndn::Interest& interest);
akmhoque53353462014-04-22 08:43:45 -0500142
143private:
144 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500145 processInterestForNameLsa(const ndn::Interest& interest,
146 const ndn::Name& lsaKey,
147 uint32_t interestedlsSeqNo);
akmhoque53353462014-04-22 08:43:45 -0500148
akmhoque31d1d4b2014-05-05 22:08:14 -0500149 void
150 processInterestForAdjacencyLsa(const ndn::Interest& interest,
151 const ndn::Name& lsaKey,
152 uint32_t interestedlsSeqNo);
153
154 void
155 processInterestForCoordinateLsa(const ndn::Interest& interest,
156 const ndn::Name& lsaKey,
157 uint32_t interestedlsSeqNo);
158
159 void
160 processContent(const ndn::Interest& interest, const ndn::Data& data);
161
162 void
163 processContentNameLsa(const ndn::Name& lsaKey,
164 uint32_t lsSeqNo, std::string& dataContent);
165
166 void
167 processContentAdjacencyLsa(const ndn::Name& lsaKey,
168 uint32_t lsSeqNo, std::string& dataContent);
169
170 void
171 processContentCoordinateLsa(const ndn::Name& lsaKey,
172 uint32_t lsSeqNo, std::string& dataContent);
173
174 void
175 processInterestTimedOut(const ndn::Interest& interest);
176
177private:
178 void
179 cancelScheduleLsaExpiringEvent(ndn::EventId eid);
180
181 Nlsr& m_nlsr;
182 ndn::KeyChain m_keyChain;
akmhoque53353462014-04-22 08:43:45 -0500183 std::list<NameLsa> m_nameLsdb;
184 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500185 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500186
187 int m_lsaRefreshTime;
188 std::string m_thisRouterPrefix;
189
190};
191
192}//namespace nlsr
193
194#endif //NLSR_LSDB_HPP