akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 1 | #ifndef NLSR_LSA_HPP |
| 2 | #define NLSR_LSA_HPP |
| 3 | |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 4 | #include <ndn-cpp-dev/util/scheduler.hpp> |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 5 | #include "nlsr_adjacent.hpp" |
| 6 | #include "nlsr_npl.hpp" |
| 7 | #include "nlsr_adl.hpp" |
| 8 | |
| 9 | using namespace std; |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 10 | using namespace ndn; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 11 | |
| 12 | class Lsa{ |
| 13 | public: |
| 14 | Lsa() |
| 15 | : origRouter() |
| 16 | , lsSeqNo() |
| 17 | , lifeTime() |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 18 | , lsaExpiringEventId() |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 19 | { |
| 20 | } |
| 21 | |
| 22 | |
| 23 | void setLsType(uint8_t lst) |
| 24 | { |
| 25 | lsType=lst; |
| 26 | } |
| 27 | |
| 28 | uint8_t getLsType() |
| 29 | { |
| 30 | return lsType; |
| 31 | } |
| 32 | |
| 33 | void setLsSeqNo(uint32_t lsn) |
| 34 | { |
| 35 | lsSeqNo=lsn; |
| 36 | } |
| 37 | |
| 38 | uint32_t getLsSeqNo() |
| 39 | { |
| 40 | return lsSeqNo; |
| 41 | } |
| 42 | |
| 43 | string& getOrigRouter() |
| 44 | { |
| 45 | return origRouter; |
| 46 | } |
| 47 | |
| 48 | void setOrigRouter(string& org) |
| 49 | { |
| 50 | origRouter=org; |
| 51 | } |
| 52 | |
| 53 | uint32_t getLifeTime() |
| 54 | { |
| 55 | return lifeTime; |
| 56 | } |
| 57 | |
| 58 | void setLifeTime(uint32_t lt) |
| 59 | { |
| 60 | lifeTime=lt; |
| 61 | } |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 62 | |
| 63 | void setLsaExpiringEventId(ndn::EventId leei) |
| 64 | { |
| 65 | lsaExpiringEventId=leei; |
| 66 | } |
| 67 | |
| 68 | ndn::EventId getLsaExpiringEventId() |
| 69 | { |
| 70 | return lsaExpiringEventId; |
| 71 | } |
| 72 | |
| 73 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 74 | protected: |
| 75 | string origRouter; |
| 76 | uint8_t lsType; |
| 77 | uint32_t lsSeqNo; |
| 78 | uint32_t lifeTime; |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 79 | ndn::EventId lsaExpiringEventId; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | class NameLsa:public Lsa{ |
| 83 | public: |
| 84 | NameLsa() |
| 85 | : Lsa() |
| 86 | , npl() |
| 87 | { |
| 88 | setLsType(1); |
| 89 | } |
| 90 | |
| 91 | NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl npl); |
| 92 | |
| 93 | Npl& getNpl(){ |
| 94 | return npl; |
| 95 | } |
| 96 | |
| 97 | void addNameToLsa(string& name) |
| 98 | { |
| 99 | npl.insertIntoNpl(name); |
| 100 | } |
| 101 | |
| 102 | void removeNameFromLsa(string& name) |
| 103 | { |
| 104 | npl.removeFromNpl(name); |
| 105 | } |
| 106 | |
| 107 | string getNameLsaKey(); |
| 108 | |
| 109 | string getNameLsaData(); |
| 110 | |
| 111 | private: |
| 112 | Npl npl; |
| 113 | |
| 114 | }; |
| 115 | |
| 116 | std::ostream& |
| 117 | operator<<(std::ostream& os, NameLsa& nLsa); |
| 118 | |
| 119 | class AdjLsa: public Lsa{ |
| 120 | public: |
| 121 | AdjLsa() |
| 122 | : Lsa() |
| 123 | , adl() |
| 124 | { |
| 125 | setLsType(2); |
| 126 | } |
| 127 | |
| 128 | AdjLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, |
| 129 | uint32_t nl ,Adl padl); |
| 130 | Adl& getAdl(){ |
| 131 | return adl; |
| 132 | } |
| 133 | |
| 134 | void addAdjacentToLsa(Adjacent adj) |
| 135 | { |
| 136 | adl.insert(adj); |
| 137 | } |
| 138 | string getAdjLsaKey(); |
| 139 | string getAdjLsaData(); |
| 140 | uint32_t getNoLink() |
| 141 | { |
| 142 | return noLink; |
| 143 | } |
| 144 | |
| 145 | bool isLsaContentEqual(AdjLsa& alsa); |
akmhoque | 1a48109 | 2014-02-19 16:34:22 -0600 | [diff] [blame^] | 146 | void addNptEntriesForAdjLsa(Nlsr& pnlsr); |
| 147 | void removeNptEntriesForAdjLsa(Nlsr& pnlsr); |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 148 | |
| 149 | private: |
| 150 | uint32_t noLink; |
| 151 | Adl adl; |
| 152 | }; |
| 153 | |
| 154 | std::ostream& |
| 155 | operator<<(std::ostream& os, AdjLsa& aLsa); |
| 156 | |
| 157 | class CorLsa:public Lsa{ |
| 158 | public: |
| 159 | CorLsa() |
| 160 | :Lsa() |
| 161 | { |
| 162 | setLsType(3); |
| 163 | } |
| 164 | |
| 165 | CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt |
| 166 | , double r, double theta); |
| 167 | string getCorLsaKey(); |
| 168 | string getCorLsaData(); |
| 169 | |
| 170 | double getCorRadius() |
| 171 | { |
| 172 | if ( corRad >= 0 ) |
| 173 | { |
| 174 | return corRad; |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | return -1; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | void setCorRadius(double cr) |
| 183 | { |
| 184 | corRad=cr; |
| 185 | } |
| 186 | |
| 187 | double getCorTheta() |
| 188 | { |
| 189 | return corTheta; |
| 190 | } |
| 191 | |
| 192 | void setCorTheta(double ct){ |
| 193 | corTheta=ct; |
| 194 | } |
| 195 | |
| 196 | bool isLsaContentEqual(CorLsa& clsa); |
| 197 | private: |
| 198 | double corRad; |
| 199 | double corTheta; |
| 200 | |
| 201 | }; |
| 202 | |
| 203 | std::ostream& |
| 204 | operator<<(std::ostream& os, CorLsa& cLsa); |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | #endif |