akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame^] | 1 | #ifndef NLSR_LSA_HPP |
| 2 | #define NLSR_LSA_HPP |
| 3 | |
| 4 | #include <ndn-cpp-dev/util/scheduler.hpp> |
| 5 | #include "adjacent.hpp" |
| 6 | #include "npl.hpp" |
| 7 | #include "adl.hpp" |
| 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 | |
| 100 | NameLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl npl); |
| 101 | |
| 102 | Npl& |
| 103 | getNpl() |
| 104 | { |
| 105 | return m_npl; |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | addName(std::string& name) |
| 110 | { |
| 111 | m_npl.insert(name); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | removeName(std::string& name) |
| 116 | { |
| 117 | m_npl.remove(name); |
| 118 | } |
| 119 | |
| 120 | std::string |
| 121 | getKey(); |
| 122 | |
| 123 | std::string |
| 124 | getData(); |
| 125 | |
| 126 | bool |
| 127 | initializeFromContent(std::string content); |
| 128 | |
| 129 | void |
| 130 | writeLog(); |
| 131 | |
| 132 | private: |
| 133 | Npl m_npl; |
| 134 | |
| 135 | }; |
| 136 | |
| 137 | std::ostream& |
| 138 | operator<<(std::ostream& os, NameLsa& nLsa); |
| 139 | |
| 140 | class AdjLsa: public Lsa |
| 141 | { |
| 142 | public: |
| 143 | AdjLsa() |
| 144 | : Lsa() |
| 145 | , m_adl() |
| 146 | { |
| 147 | setLsType(2); |
| 148 | } |
| 149 | |
| 150 | AdjLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt, |
| 151 | uint32_t nl , Adl padl); |
| 152 | |
| 153 | Adl& |
| 154 | getAdl() |
| 155 | { |
| 156 | return m_adl; |
| 157 | } |
| 158 | |
| 159 | void |
| 160 | addAdjacent(Adjacent adj) |
| 161 | { |
| 162 | m_adl.insert(adj); |
| 163 | } |
| 164 | |
| 165 | std::string |
| 166 | getKey(); |
| 167 | |
| 168 | std::string |
| 169 | getData(); |
| 170 | |
| 171 | bool |
| 172 | initializeFromContent(std::string content); |
| 173 | |
| 174 | uint32_t |
| 175 | getNoLink() |
| 176 | { |
| 177 | return m_noLink; |
| 178 | } |
| 179 | |
| 180 | bool |
| 181 | isEqual(AdjLsa& alsa); |
| 182 | |
| 183 | void |
| 184 | addNptEntries(Nlsr& pnlsr); |
| 185 | |
| 186 | void |
| 187 | removeNptEntries(Nlsr& pnlsr); |
| 188 | |
| 189 | private: |
| 190 | uint32_t m_noLink; |
| 191 | Adl m_adl; |
| 192 | }; |
| 193 | |
| 194 | std::ostream& |
| 195 | operator<<(std::ostream& os, AdjLsa& aLsa); |
| 196 | |
| 197 | class CorLsa: public Lsa |
| 198 | { |
| 199 | public: |
| 200 | CorLsa() |
| 201 | : Lsa() |
| 202 | , m_corRad(0) |
| 203 | , m_corTheta(0) |
| 204 | { |
| 205 | setLsType(3); |
| 206 | } |
| 207 | |
| 208 | CorLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt |
| 209 | , double r, double theta); |
| 210 | |
| 211 | std::string |
| 212 | getKey(); |
| 213 | |
| 214 | std::string |
| 215 | getData(); |
| 216 | |
| 217 | bool |
| 218 | initializeFromContent(std::string content); |
| 219 | |
| 220 | double |
| 221 | getCorRadius() |
| 222 | { |
| 223 | if (m_corRad >= 0) |
| 224 | { |
| 225 | return m_corRad; |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | return -1; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void |
| 234 | setCorRadius(double cr) |
| 235 | { |
| 236 | m_corRad = cr; |
| 237 | } |
| 238 | |
| 239 | double |
| 240 | getCorTheta() |
| 241 | { |
| 242 | return m_corTheta; |
| 243 | } |
| 244 | |
| 245 | void |
| 246 | setCorTheta(double ct) |
| 247 | { |
| 248 | m_corTheta = ct; |
| 249 | } |
| 250 | |
| 251 | bool |
| 252 | isEqual(CorLsa& clsa); |
| 253 | |
| 254 | private: |
| 255 | double m_corRad; |
| 256 | double m_corTheta; |
| 257 | |
| 258 | }; |
| 259 | |
| 260 | std::ostream& |
| 261 | operator<<(std::ostream& os, CorLsa& cLsa); |
| 262 | |
| 263 | |
| 264 | }//namespace nlsr |
| 265 | |
| 266 | #endif //NLSR_LSA_HPP |