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, |
| 155 | uint32_t lt, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 156 | uint32_t nl , AdjacencyList& adl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 157 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 158 | AdjacencyList& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 159 | getAdl() |
| 160 | { |
| 161 | return m_adl; |
| 162 | } |
| 163 | |
| 164 | void |
| 165 | addAdjacent(Adjacent adj) |
| 166 | { |
| 167 | m_adl.insert(adj); |
| 168 | } |
| 169 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 170 | const ndn::Name |
| 171 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 172 | |
| 173 | std::string |
| 174 | getData(); |
| 175 | |
| 176 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 177 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 178 | |
| 179 | uint32_t |
| 180 | getNoLink() |
| 181 | { |
| 182 | return m_noLink; |
| 183 | } |
| 184 | |
| 185 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 186 | isEqualContent(AdjLsa& alsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 187 | |
| 188 | void |
| 189 | addNptEntries(Nlsr& pnlsr); |
| 190 | |
| 191 | void |
| 192 | removeNptEntries(Nlsr& pnlsr); |
| 193 | |
| 194 | private: |
| 195 | uint32_t m_noLink; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 196 | AdjacencyList m_adl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | std::ostream& |
| 200 | operator<<(std::ostream& os, AdjLsa& aLsa); |
| 201 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 202 | class CoordinateLsa: public Lsa |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 203 | { |
| 204 | public: |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 205 | CoordinateLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 206 | : Lsa() |
| 207 | , m_corRad(0) |
| 208 | , m_corTheta(0) |
| 209 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 210 | setLsType("coordinate"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 211 | } |
| 212 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 213 | CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn, |
| 214 | uint32_t lt |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 215 | , double r, double theta); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 216 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 217 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 218 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 219 | |
| 220 | std::string |
| 221 | getData(); |
| 222 | |
| 223 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 224 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 225 | |
| 226 | double |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 227 | getCorRadius() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 228 | { |
| 229 | if (m_corRad >= 0) |
| 230 | { |
| 231 | return m_corRad; |
| 232 | } |
| 233 | else |
| 234 | { |
| 235 | return -1; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | void |
| 240 | setCorRadius(double cr) |
| 241 | { |
| 242 | m_corRad = cr; |
| 243 | } |
| 244 | |
| 245 | double |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 246 | getCorTheta() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 247 | { |
| 248 | return m_corTheta; |
| 249 | } |
| 250 | |
| 251 | void |
| 252 | setCorTheta(double ct) |
| 253 | { |
| 254 | m_corTheta = ct; |
| 255 | } |
| 256 | |
| 257 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 258 | isEqualContent(const CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 259 | |
| 260 | private: |
| 261 | double m_corRad; |
| 262 | double m_corTheta; |
| 263 | |
| 264 | }; |
| 265 | |
| 266 | std::ostream& |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 267 | operator<<(std::ostream& os, const CoordinateLsa& cLsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 268 | |
| 269 | |
| 270 | }//namespace nlsr |
| 271 | |
| 272 | #endif //NLSR_LSA_HPP |