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