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