akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1 | #ifndef NLSR_LSA_HPP |
| 2 | #define NLSR_LSA_HPP |
| 3 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 4 | #include <boost/cstdint.hpp> |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 5 | #include <ndn-cxx/util/scheduler.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 6 | #include "adjacent.hpp" |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 7 | #include "name-prefix-list.hpp" |
| 8 | #include "adjacency-list.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 9 | |
| 10 | namespace nlsr { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 11 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 12 | class Lsa |
| 13 | { |
| 14 | public: |
| 15 | Lsa() |
| 16 | : m_origRouter() |
| 17 | , m_lsSeqNo() |
| 18 | , m_lifeTime() |
| 19 | , m_expiringEventId() |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | |
| 24 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 25 | setLsType(const std::string& lst) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 26 | { |
| 27 | m_lsType = lst; |
| 28 | } |
| 29 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 30 | const std::string& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | getLsType() const |
| 32 | { |
| 33 | return m_lsType; |
| 34 | } |
| 35 | |
| 36 | void |
| 37 | setLsSeqNo(uint32_t lsn) |
| 38 | { |
| 39 | m_lsSeqNo = lsn; |
| 40 | } |
| 41 | |
| 42 | uint32_t |
| 43 | getLsSeqNo() const |
| 44 | { |
| 45 | return m_lsSeqNo; |
| 46 | } |
| 47 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 48 | const ndn::Name& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 49 | getOrigRouter() const |
| 50 | { |
| 51 | return m_origRouter; |
| 52 | } |
| 53 | |
| 54 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 55 | setOrigRouter(const ndn::Name& org) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 56 | { |
| 57 | m_origRouter = org; |
| 58 | } |
| 59 | |
| 60 | uint32_t |
| 61 | getLifeTime() const |
| 62 | { |
| 63 | return m_lifeTime; |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | setLifeTime(uint32_t lt) |
| 68 | { |
| 69 | m_lifeTime = lt; |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | setExpiringEventId(const ndn::EventId leei) |
| 74 | { |
| 75 | m_expiringEventId = leei; |
| 76 | } |
| 77 | |
| 78 | ndn::EventId |
| 79 | getExpiringEventId() const |
| 80 | { |
| 81 | return m_expiringEventId; |
| 82 | } |
| 83 | |
| 84 | protected: |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 85 | ndn::Name m_origRouter; |
| 86 | std::string m_lsType; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 87 | uint32_t m_lsSeqNo; |
| 88 | uint32_t m_lifeTime; |
| 89 | ndn::EventId m_expiringEventId; |
| 90 | }; |
| 91 | |
| 92 | class NameLsa: public Lsa |
| 93 | { |
| 94 | public: |
| 95 | NameLsa() |
| 96 | : Lsa() |
| 97 | , m_npl() |
| 98 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 99 | setLsType("name"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 100 | } |
| 101 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 102 | NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn, |
| 103 | uint32_t lt, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 104 | NamePrefixList& npl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 105 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 106 | NamePrefixList& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 107 | getNpl() |
| 108 | { |
| 109 | return m_npl; |
| 110 | } |
| 111 | |
| 112 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 113 | addName(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 114 | { |
| 115 | m_npl.insert(name); |
| 116 | } |
| 117 | |
| 118 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 119 | removeName(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 120 | { |
| 121 | m_npl.remove(name); |
| 122 | } |
| 123 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 124 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 125 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 126 | |
| 127 | std::string |
| 128 | getData(); |
| 129 | |
| 130 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 131 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 132 | |
| 133 | void |
| 134 | writeLog(); |
| 135 | |
| 136 | private: |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 137 | NamePrefixList m_npl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 138 | |
| 139 | }; |
| 140 | |
| 141 | std::ostream& |
| 142 | operator<<(std::ostream& os, NameLsa& nLsa); |
| 143 | |
| 144 | class AdjLsa: public Lsa |
| 145 | { |
| 146 | public: |
| 147 | AdjLsa() |
| 148 | : Lsa() |
| 149 | , m_adl() |
| 150 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 151 | setLsType("adjacency"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 152 | } |
| 153 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 154 | AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn, |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 155 | uint32_t lt, uint32_t nl , AdjacencyList& adl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 156 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 157 | AdjacencyList& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 158 | getAdl() |
| 159 | { |
| 160 | return m_adl; |
| 161 | } |
| 162 | |
| 163 | void |
| 164 | addAdjacent(Adjacent adj) |
| 165 | { |
| 166 | m_adl.insert(adj); |
| 167 | } |
| 168 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 169 | const ndn::Name |
| 170 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 171 | |
| 172 | std::string |
| 173 | getData(); |
| 174 | |
| 175 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 176 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 177 | |
| 178 | uint32_t |
| 179 | getNoLink() |
| 180 | { |
| 181 | return m_noLink; |
| 182 | } |
| 183 | |
| 184 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 185 | isEqualContent(AdjLsa& alsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 186 | |
| 187 | void |
| 188 | addNptEntries(Nlsr& pnlsr); |
| 189 | |
| 190 | void |
| 191 | removeNptEntries(Nlsr& pnlsr); |
| 192 | |
| 193 | private: |
| 194 | uint32_t m_noLink; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 195 | AdjacencyList m_adl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | std::ostream& |
| 199 | operator<<(std::ostream& os, AdjLsa& aLsa); |
| 200 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 201 | class CoordinateLsa: public Lsa |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 202 | { |
| 203 | public: |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 204 | CoordinateLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 205 | : Lsa() |
| 206 | , m_corRad(0) |
| 207 | , m_corTheta(0) |
| 208 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 209 | setLsType("coordinate"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 210 | } |
| 211 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 212 | CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn, |
| 213 | uint32_t lt |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 214 | , double r, double theta); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 215 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 216 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 217 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 218 | |
| 219 | std::string |
| 220 | getData(); |
| 221 | |
| 222 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 223 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 224 | |
| 225 | double |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 226 | getCorRadius() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 227 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 228 | return m_corRad; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | void |
| 232 | setCorRadius(double cr) |
| 233 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 234 | m_corRad = cr; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | double |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 238 | getCorTheta() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 239 | { |
| 240 | return m_corTheta; |
| 241 | } |
| 242 | |
| 243 | void |
| 244 | setCorTheta(double ct) |
| 245 | { |
| 246 | m_corTheta = ct; |
| 247 | } |
| 248 | |
| 249 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 250 | isEqualContent(const CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 251 | |
| 252 | private: |
| 253 | double m_corRad; |
| 254 | double m_corTheta; |
| 255 | |
| 256 | }; |
| 257 | |
| 258 | std::ostream& |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 259 | operator<<(std::ostream& os, const CoordinateLsa& cLsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 260 | |
| 261 | |
| 262 | }//namespace nlsr |
| 263 | |
| 264 | #endif //NLSR_LSA_HPP |