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