blob: 3ad3007c9efb0a9348d55b5a9e3c67a352e49ddf [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
42 void
43 printNameLsdb(); //debugging
44
45 //function related to Cor LSDB
46 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050047 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -050048
akmhoqueb6450b12014-04-24 00:01:03 -050049 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050050 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050051
52 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050053 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -050054
55 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050056 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050057
58 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050059 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050060
61 void
62 printCorLsdb(); //debugging
63
64 //function related to Adj LSDB
65 void
akmhoque31d1d4b2014-05-05 22:08:14 -050066 scheduledAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -050067
68 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050069 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -050070
71 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050072 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050073
74 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050075 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050076 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050077 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -050078
akmhoqueb6450b12014-04-24 00:01:03 -050079 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050080 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050081
82 std::list<AdjLsa>&
83 getAdjLsdb();
84
85 void
86 printAdjLsdb();
87
88 //void scheduleRefreshLsdb(Nlsr& pnlsr, int interval);
89 void
90 setLsaRefreshTime(int lrt);
91
92 void
93 setThisRouterPrefix(std::string trp);
94
95private:
96 bool
97 addNameLsa(NameLsa& nlsa);
98
99 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500100 doesNameLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500101
102
103 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500104 addCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500105
106 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500107 doesCoordinateLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500108
109 bool
110 addAdjLsa(AdjLsa& alsa);
111
112 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500113 doesAdjLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500114
115 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500116 scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, int expTime);
akmhoque53353462014-04-22 08:43:45 -0500117
118 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500119 exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500120
121 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500122 scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, int expTime);
akmhoque53353462014-04-22 08:43:45 -0500123
124 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500125 exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500126
127 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500128 scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
akmhoqueb6450b12014-04-24 00:01:03 -0500129 int expTime);
akmhoque53353462014-04-22 08:43:45 -0500130
131 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500132 exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500133 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500134public:
135 void
136 expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime);
akmhoque53353462014-04-22 08:43:45 -0500137
akmhoque31d1d4b2014-05-05 22:08:14 -0500138 void
139 processInterest(const ndn::Name& name, const ndn::Interest& interest);
akmhoque53353462014-04-22 08:43:45 -0500140
141private:
142 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500143 processInterestForNameLsa(const ndn::Interest& interest,
144 const ndn::Name& lsaKey,
145 uint32_t interestedlsSeqNo);
akmhoque53353462014-04-22 08:43:45 -0500146
akmhoque31d1d4b2014-05-05 22:08:14 -0500147 void
148 processInterestForAdjacencyLsa(const ndn::Interest& interest,
149 const ndn::Name& lsaKey,
150 uint32_t interestedlsSeqNo);
151
152 void
153 processInterestForCoordinateLsa(const ndn::Interest& interest,
154 const ndn::Name& lsaKey,
155 uint32_t interestedlsSeqNo);
156
157 void
158 processContent(const ndn::Interest& interest, const ndn::Data& data);
159
160 void
161 processContentNameLsa(const ndn::Name& lsaKey,
162 uint32_t lsSeqNo, std::string& dataContent);
163
164 void
165 processContentAdjacencyLsa(const ndn::Name& lsaKey,
166 uint32_t lsSeqNo, std::string& dataContent);
167
168 void
169 processContentCoordinateLsa(const ndn::Name& lsaKey,
170 uint32_t lsSeqNo, std::string& dataContent);
171
172 void
173 processInterestTimedOut(const ndn::Interest& interest);
174
175private:
176 void
177 cancelScheduleLsaExpiringEvent(ndn::EventId eid);
178
179 Nlsr& m_nlsr;
180 ndn::KeyChain m_keyChain;
akmhoque53353462014-04-22 08:43:45 -0500181 std::list<NameLsa> m_nameLsdb;
182 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500183 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500184
185 int m_lsaRefreshTime;
186 std::string m_thisRouterPrefix;
187
188};
189
190}//namespace nlsr
191
192#endif //NLSR_LSDB_HPP