akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1 | #ifndef NLSR_LSDB_HPP |
| 2 | #define NLSR_LSDB_HPP |
| 3 | |
| 4 | #include <utility> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 5 | #include <boost/cstdint.hpp> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 6 | #include <ndn-cxx/security/key-chain.hpp> |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 7 | #include <ndn-cxx/util/time.hpp> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 8 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 9 | #include "lsa.hpp" |
| 10 | |
| 11 | namespace nlsr { |
| 12 | class Nlsr; |
| 13 | |
| 14 | class Lsdb |
| 15 | { |
| 16 | public: |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 17 | Lsdb(Nlsr& nlsr) |
| 18 | : m_nlsr(nlsr) |
| 19 | , m_lsaRefreshTime(0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 20 | { |
| 21 | } |
| 22 | |
| 23 | |
| 24 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 25 | doesLsaExist(const ndn::Name& key, const std::string& lsType); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 26 | // function related to Name LSDB |
| 27 | |
| 28 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 29 | buildAndInstallOwnNameLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 30 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 31 | NameLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 32 | findNameLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | |
| 34 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 35 | installNameLsa(NameLsa& nlsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 36 | |
| 37 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 38 | removeNameLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 39 | |
| 40 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 41 | isNameLsaNew(const ndn::Name& key, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 42 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 43 | //debugging |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 44 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 45 | printNameLsdb(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 46 | |
| 47 | //function related to Cor LSDB |
| 48 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 49 | buildAndInstallOwnCoordinateLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 50 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 51 | CoordinateLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 52 | findCoordinateLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 53 | |
| 54 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 55 | installCoordinateLsa(CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 56 | |
| 57 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 58 | removeCoordinateLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 59 | |
| 60 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 61 | isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 62 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 63 | //debugging |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 64 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 65 | printCorLsdb(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 66 | |
| 67 | //function related to Adj LSDB |
| 68 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 69 | scheduledAdjLsaBuild(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 70 | |
| 71 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 72 | buildAndInstallOwnAdjLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 73 | |
| 74 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 75 | removeAdjLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | |
| 77 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 78 | isAdjLsaNew(const ndn::Name& key, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 80 | installAdjLsa(AdjLsa& alsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 82 | AdjLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 83 | findAdjLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 84 | |
| 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 | |
| 98 | private: |
| 99 | bool |
| 100 | addNameLsa(NameLsa& nlsa); |
| 101 | |
| 102 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 103 | doesNameLsaExist(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 104 | |
| 105 | |
| 106 | bool |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 107 | addCoordinateLsa(CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 108 | |
| 109 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 110 | doesCoordinateLsaExist(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 111 | |
| 112 | bool |
| 113 | addAdjLsa(AdjLsa& alsa); |
| 114 | |
| 115 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 116 | doesAdjLsaExist(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 117 | |
| 118 | ndn::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 119 | scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, |
| 120 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 121 | |
| 122 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 123 | exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 124 | |
| 125 | ndn::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 126 | scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, |
| 127 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 128 | |
| 129 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 130 | exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 131 | |
| 132 | ndn::EventId |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 133 | scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 134 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 135 | |
| 136 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 137 | exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey, |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 138 | uint64_t seqNo); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 139 | public: |
| 140 | void |
akmhoque | 0698667 | 2014-05-27 13:55:53 -0500 | [diff] [blame^] | 141 | expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime, |
| 142 | uint32_t timeoutCount); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 143 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 144 | void |
| 145 | processInterest(const ndn::Name& name, const ndn::Interest& interest); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 146 | |
| 147 | private: |
| 148 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 149 | processInterestForNameLsa(const ndn::Interest& interest, |
| 150 | const ndn::Name& lsaKey, |
| 151 | uint32_t interestedlsSeqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 152 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 153 | 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 |
akmhoque | 0698667 | 2014-05-27 13:55:53 -0500 | [diff] [blame^] | 179 | processInterestTimedOut(const ndn::Interest& interest, uint32_t timeoutCount); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 180 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 181 | ndn::time::system_clock::TimePoint |
| 182 | getLsaExpirationTimePoint(); |
| 183 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 184 | private: |
| 185 | void |
| 186 | cancelScheduleLsaExpiringEvent(ndn::EventId eid); |
| 187 | |
| 188 | Nlsr& m_nlsr; |
| 189 | ndn::KeyChain m_keyChain; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 190 | std::list<NameLsa> m_nameLsdb; |
| 191 | std::list<AdjLsa> m_adjLsdb; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 192 | std::list<CoordinateLsa> m_corLsdb; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 193 | |
| 194 | int m_lsaRefreshTime; |
| 195 | std::string m_thisRouterPrefix; |
| 196 | |
| 197 | }; |
| 198 | |
| 199 | }//namespace nlsr |
| 200 | |
| 201 | #endif //NLSR_LSDB_HPP |