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