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() |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 19 | : m_origRouter() |
| 20 | , m_lsSeqNo() |
| 21 | , m_lifeTime() |
| 22 | , m_expiringEventId() |
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 | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 29 | m_lsType=lst; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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 | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 34 | return m_lsType; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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 | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 39 | m_lsSeqNo=lsn; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 44 | return m_lsSeqNo; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 49 | return m_origRouter; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 54 | m_origRouter=org; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 59 | return m_lifeTime; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 64 | m_lifeTime=lt; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 65 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 66 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 67 | void setExpiringEventId(ndn::EventId leei) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 68 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 69 | m_expiringEventId=leei; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 70 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 71 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 72 | ndn::EventId getExpiringEventId() |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 73 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 74 | return m_expiringEventId; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 75 | } |
| 76 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 77 | protected: |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 78 | string m_origRouter; |
| 79 | uint8_t m_lsType; |
| 80 | uint32_t m_lsSeqNo; |
| 81 | uint32_t m_lifeTime; |
| 82 | ndn::EventId m_expiringEventId; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | class NameLsa:public Lsa |
| 86 | { |
| 87 | public: |
| 88 | NameLsa() |
| 89 | : Lsa() |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 90 | , m_npl() |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 91 | { |
| 92 | setLsType(1); |
| 93 | } |
| 94 | |
| 95 | NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl npl); |
| 96 | |
| 97 | Npl& getNpl() |
| 98 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 99 | return m_npl; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 100 | } |
| 101 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 102 | void addName(string& name) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 103 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 104 | m_npl.insert(name); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 105 | } |
| 106 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 107 | void removeName(string& name) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 108 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 109 | m_npl.remove(name); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 110 | } |
| 111 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 112 | string getKey(); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 113 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 114 | string getData(); |
| 115 | bool initializeFromContent(string content); |
| 116 | void writeLog(); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 117 | |
| 118 | private: |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 119 | Npl m_npl; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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() |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 131 | , m_adl() |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 140 | return m_adl; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 141 | } |
| 142 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 143 | void addAdjacent(Adjacent adj) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 144 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 145 | m_adl.insert(adj); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 146 | } |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 147 | string getKey(); |
| 148 | string getData(); |
| 149 | bool initializeFromContent(string content); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 150 | uint32_t getNoLink() |
| 151 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 152 | return m_noLink; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 153 | } |
| 154 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 155 | bool isEqual(AdjLsa& alsa); |
| 156 | void addNptEntries(Nlsr& pnlsr); |
| 157 | void removeNptEntries(Nlsr& pnlsr); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 158 | |
| 159 | private: |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 160 | uint32_t m_noLink; |
| 161 | Adl m_adl; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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() |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 172 | , m_corRad(0) |
| 173 | , m_corTheta(0) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 174 | { |
| 175 | setLsType(3); |
| 176 | } |
| 177 | |
| 178 | CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt |
| 179 | , double r, double theta); |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 180 | string getKey(); |
| 181 | string getData(); |
| 182 | bool initializeFromContent(string content); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 183 | double getCorRadius() |
| 184 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 185 | if ( m_corRad >= 0 ) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 186 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 187 | return m_corRad; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 188 | } |
| 189 | else |
| 190 | { |
| 191 | return -1; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | void setCorRadius(double cr) |
| 196 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 197 | m_corRad=cr; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | double getCorTheta() |
| 201 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 202 | return m_corTheta; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void setCorTheta(double ct) |
| 206 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 207 | m_corTheta=ct; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 208 | } |
| 209 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 210 | bool isEqual(CorLsa& clsa); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 211 | private: |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame^] | 212 | double m_corRad; |
| 213 | double m_corTheta; |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 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 |