blob: 878d688b9e108a2f00fd70e0408d464237f013b7 [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#ifndef NLSR_LSA_HPP
2#define NLSR_LSA_HPP
3
akmhoque85d88332014-02-17 21:11:21 -06004#include <ndn-cpp-dev/util/scheduler.hpp>
akmhoque298385a2014-02-13 14:13:09 -06005#include "nlsr_adjacent.hpp"
6#include "nlsr_npl.hpp"
7#include "nlsr_adl.hpp"
8
akmhoque1fd8c1e2014-02-19 19:41:49 -06009namespace nlsr
10{
akmhoqueb1710aa2014-02-19 17:13:36 -060011
akmhoque5a44dd42014-03-12 18:11:32 -050012 using namespace std;
13 using namespace ndn;
akmhoque298385a2014-02-13 14:13:09 -060014
akmhoque5a44dd42014-03-12 18:11:32 -050015 class Lsa
16 {
17 public:
18 Lsa()
akmhoque05d5fcf2014-04-15 14:58:45 -050019 : m_origRouter()
20 , m_lsSeqNo()
21 , m_lifeTime()
22 , m_expiringEventId()
akmhoque1fd8c1e2014-02-19 19:41:49 -060023 {
akmhoque5a44dd42014-03-12 18:11:32 -050024 }
akmhoque298385a2014-02-13 14:13:09 -060025
26
akmhoque5a44dd42014-03-12 18:11:32 -050027 void setLsType(uint8_t lst)
akmhoque1fd8c1e2014-02-19 19:41:49 -060028 {
akmhoque05d5fcf2014-04-15 14:58:45 -050029 m_lsType=lst;
akmhoque5a44dd42014-03-12 18:11:32 -050030 }
akmhoque298385a2014-02-13 14:13:09 -060031
akmhoque5a44dd42014-03-12 18:11:32 -050032 uint8_t getLsType()
akmhoque1fd8c1e2014-02-19 19:41:49 -060033 {
akmhoque05d5fcf2014-04-15 14:58:45 -050034 return m_lsType;
akmhoque5a44dd42014-03-12 18:11:32 -050035 }
akmhoque298385a2014-02-13 14:13:09 -060036
akmhoque5a44dd42014-03-12 18:11:32 -050037 void setLsSeqNo(uint32_t lsn)
akmhoque1fd8c1e2014-02-19 19:41:49 -060038 {
akmhoque05d5fcf2014-04-15 14:58:45 -050039 m_lsSeqNo=lsn;
akmhoque5a44dd42014-03-12 18:11:32 -050040 }
akmhoque298385a2014-02-13 14:13:09 -060041
akmhoque5a44dd42014-03-12 18:11:32 -050042 uint32_t getLsSeqNo()
43 {
akmhoque05d5fcf2014-04-15 14:58:45 -050044 return m_lsSeqNo;
akmhoque5a44dd42014-03-12 18:11:32 -050045 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060046
akmhoque5a44dd42014-03-12 18:11:32 -050047 string& getOrigRouter()
48 {
akmhoque05d5fcf2014-04-15 14:58:45 -050049 return m_origRouter;
akmhoque5a44dd42014-03-12 18:11:32 -050050 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060051
akmhoque5a44dd42014-03-12 18:11:32 -050052 void setOrigRouter(string& org)
53 {
akmhoque05d5fcf2014-04-15 14:58:45 -050054 m_origRouter=org;
akmhoque5a44dd42014-03-12 18:11:32 -050055 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060056
akmhoque5a44dd42014-03-12 18:11:32 -050057 uint32_t getLifeTime()
58 {
akmhoque05d5fcf2014-04-15 14:58:45 -050059 return m_lifeTime;
akmhoque5a44dd42014-03-12 18:11:32 -050060 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060061
akmhoque5a44dd42014-03-12 18:11:32 -050062 void setLifeTime(uint32_t lt)
63 {
akmhoque05d5fcf2014-04-15 14:58:45 -050064 m_lifeTime=lt;
akmhoque5a44dd42014-03-12 18:11:32 -050065 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060066
akmhoque05d5fcf2014-04-15 14:58:45 -050067 void setExpiringEventId(ndn::EventId leei)
akmhoque5a44dd42014-03-12 18:11:32 -050068 {
akmhoque05d5fcf2014-04-15 14:58:45 -050069 m_expiringEventId=leei;
akmhoque5a44dd42014-03-12 18:11:32 -050070 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060071
akmhoque05d5fcf2014-04-15 14:58:45 -050072 ndn::EventId getExpiringEventId()
akmhoque5a44dd42014-03-12 18:11:32 -050073 {
akmhoque05d5fcf2014-04-15 14:58:45 -050074 return m_expiringEventId;
akmhoque5a44dd42014-03-12 18:11:32 -050075 }
76
akmhoque5a44dd42014-03-12 18:11:32 -050077 protected:
akmhoque05d5fcf2014-04-15 14:58:45 -050078 string m_origRouter;
79 uint8_t m_lsType;
80 uint32_t m_lsSeqNo;
81 uint32_t m_lifeTime;
82 ndn::EventId m_expiringEventId;
akmhoque5a44dd42014-03-12 18:11:32 -050083 };
84
85 class NameLsa:public Lsa
86 {
87 public:
88 NameLsa()
89 : Lsa()
akmhoque05d5fcf2014-04-15 14:58:45 -050090 , m_npl()
akmhoque5a44dd42014-03-12 18:11:32 -050091 {
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 {
akmhoque05d5fcf2014-04-15 14:58:45 -050099 return m_npl;
akmhoque5a44dd42014-03-12 18:11:32 -0500100 }
101
akmhoque05d5fcf2014-04-15 14:58:45 -0500102 void addName(string& name)
akmhoque5a44dd42014-03-12 18:11:32 -0500103 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500104 m_npl.insert(name);
akmhoque5a44dd42014-03-12 18:11:32 -0500105 }
106
akmhoque05d5fcf2014-04-15 14:58:45 -0500107 void removeName(string& name)
akmhoque5a44dd42014-03-12 18:11:32 -0500108 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500109 m_npl.remove(name);
akmhoque5a44dd42014-03-12 18:11:32 -0500110 }
111
akmhoque05d5fcf2014-04-15 14:58:45 -0500112 string getKey();
akmhoque5a44dd42014-03-12 18:11:32 -0500113
akmhoque05d5fcf2014-04-15 14:58:45 -0500114 string getData();
115 bool initializeFromContent(string content);
116 void writeLog();
akmhoque5a44dd42014-03-12 18:11:32 -0500117
118 private:
akmhoque05d5fcf2014-04-15 14:58:45 -0500119 Npl m_npl;
akmhoque5a44dd42014-03-12 18:11:32 -0500120
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()
akmhoque05d5fcf2014-04-15 14:58:45 -0500131 , m_adl()
akmhoque5a44dd42014-03-12 18:11:32 -0500132 {
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 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500140 return m_adl;
akmhoque5a44dd42014-03-12 18:11:32 -0500141 }
142
akmhoque05d5fcf2014-04-15 14:58:45 -0500143 void addAdjacent(Adjacent adj)
akmhoque5a44dd42014-03-12 18:11:32 -0500144 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500145 m_adl.insert(adj);
akmhoque5a44dd42014-03-12 18:11:32 -0500146 }
akmhoque05d5fcf2014-04-15 14:58:45 -0500147 string getKey();
148 string getData();
149 bool initializeFromContent(string content);
akmhoque5a44dd42014-03-12 18:11:32 -0500150 uint32_t getNoLink()
151 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500152 return m_noLink;
akmhoque5a44dd42014-03-12 18:11:32 -0500153 }
154
akmhoque05d5fcf2014-04-15 14:58:45 -0500155 bool isEqual(AdjLsa& alsa);
156 void addNptEntries(Nlsr& pnlsr);
157 void removeNptEntries(Nlsr& pnlsr);
akmhoque5a44dd42014-03-12 18:11:32 -0500158
159 private:
akmhoque05d5fcf2014-04-15 14:58:45 -0500160 uint32_t m_noLink;
161 Adl m_adl;
akmhoque5a44dd42014-03-12 18:11:32 -0500162 };
163
164 std::ostream&
165 operator<<(std::ostream& os, AdjLsa& aLsa);
166
167 class CorLsa:public Lsa
168 {
169 public:
170 CorLsa()
171 : Lsa()
akmhoque05d5fcf2014-04-15 14:58:45 -0500172 , m_corRad(0)
173 , m_corTheta(0)
akmhoque5a44dd42014-03-12 18:11:32 -0500174 {
175 setLsType(3);
176 }
177
178 CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt
179 , double r, double theta);
akmhoque05d5fcf2014-04-15 14:58:45 -0500180 string getKey();
181 string getData();
182 bool initializeFromContent(string content);
akmhoque5a44dd42014-03-12 18:11:32 -0500183 double getCorRadius()
184 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500185 if ( m_corRad >= 0 )
akmhoque5a44dd42014-03-12 18:11:32 -0500186 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500187 return m_corRad;
akmhoque5a44dd42014-03-12 18:11:32 -0500188 }
189 else
190 {
191 return -1;
192 }
193 }
194
195 void setCorRadius(double cr)
196 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500197 m_corRad=cr;
akmhoque5a44dd42014-03-12 18:11:32 -0500198 }
199
200 double getCorTheta()
201 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500202 return m_corTheta;
akmhoque5a44dd42014-03-12 18:11:32 -0500203 }
204
205 void setCorTheta(double ct)
206 {
akmhoque05d5fcf2014-04-15 14:58:45 -0500207 m_corTheta=ct;
akmhoque5a44dd42014-03-12 18:11:32 -0500208 }
209
akmhoque05d5fcf2014-04-15 14:58:45 -0500210 bool isEqual(CorLsa& clsa);
akmhoque5a44dd42014-03-12 18:11:32 -0500211 private:
akmhoque05d5fcf2014-04-15 14:58:45 -0500212 double m_corRad;
213 double m_corTheta;
akmhoque5a44dd42014-03-12 18:11:32 -0500214
215 };
216
217 std::ostream&
218 operator<<(std::ostream& os, CorLsa& cLsa);
akmhoque298385a2014-02-13 14:13:09 -0600219
220
akmhoqueb1710aa2014-02-19 17:13:36 -0600221}//namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -0600222
223#endif