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