blob: a0968f1155f88960811786bbd72a0b4d1ef724ac [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
akmhoque1fd8c1e2014-02-19 19:41:49 -060012 using namespace std;
13 using namespace ndn;
akmhoque298385a2014-02-13 14:13:09 -060014
akmhoque1fd8c1e2014-02-19 19:41:49 -060015 class Lsa
16 {
17 public:
18 Lsa()
19 : origRouter()
20 , lsSeqNo()
21 , lifeTime()
22 , lsaExpiringEventId()
23 {
24 }
akmhoque298385a2014-02-13 14:13:09 -060025
26
akmhoque1fd8c1e2014-02-19 19:41:49 -060027 void setLsType(uint8_t lst)
28 {
29 lsType=lst;
30 }
akmhoque298385a2014-02-13 14:13:09 -060031
akmhoque1fd8c1e2014-02-19 19:41:49 -060032 uint8_t getLsType()
33 {
34 return lsType;
35 }
akmhoque298385a2014-02-13 14:13:09 -060036
akmhoque1fd8c1e2014-02-19 19:41:49 -060037 void setLsSeqNo(uint32_t lsn)
38 {
39 lsSeqNo=lsn;
40 }
akmhoque298385a2014-02-13 14:13:09 -060041
akmhoque1fd8c1e2014-02-19 19:41:49 -060042 uint32_t getLsSeqNo()
43 {
44 return lsSeqNo;
45 }
akmhoque298385a2014-02-13 14:13:09 -060046
akmhoque1fd8c1e2014-02-19 19:41:49 -060047 string& getOrigRouter()
48 {
49 return origRouter;
50 }
akmhoque298385a2014-02-13 14:13:09 -060051
akmhoque1fd8c1e2014-02-19 19:41:49 -060052 void setOrigRouter(string& org)
53 {
54 origRouter=org;
55 }
akmhoque298385a2014-02-13 14:13:09 -060056
akmhoque1fd8c1e2014-02-19 19:41:49 -060057 uint32_t getLifeTime()
58 {
59 return lifeTime;
60 }
akmhoque298385a2014-02-13 14:13:09 -060061
akmhoque1fd8c1e2014-02-19 19:41:49 -060062 void setLifeTime(uint32_t lt)
63 {
64 lifeTime=lt;
65 }
akmhoque85d88332014-02-17 21:11:21 -060066
akmhoque1fd8c1e2014-02-19 19:41:49 -060067 void setLsaExpiringEventId(ndn::EventId leei)
68 {
69 lsaExpiringEventId=leei;
70 }
akmhoque85d88332014-02-17 21:11:21 -060071
akmhoque1fd8c1e2014-02-19 19:41:49 -060072 ndn::EventId getLsaExpiringEventId()
73 {
74 return lsaExpiringEventId;
75 }
akmhoque298385a2014-02-13 14:13:09 -060076
akmhoque298385a2014-02-13 14:13:09 -060077
akmhoque1fd8c1e2014-02-19 19:41:49 -060078 protected:
79 string origRouter;
80 uint8_t lsType;
81 uint32_t lsSeqNo;
82 uint32_t lifeTime;
83 ndn::EventId lsaExpiringEventId;
84 };
akmhoque298385a2014-02-13 14:13:09 -060085
akmhoque1fd8c1e2014-02-19 19:41:49 -060086 class NameLsa:public Lsa
87 {
88 public:
89 NameLsa()
90 : Lsa()
91 , npl()
92 {
93 setLsType(1);
94 }
akmhoque298385a2014-02-13 14:13:09 -060095
akmhoque1fd8c1e2014-02-19 19:41:49 -060096 NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl npl);
akmhoque298385a2014-02-13 14:13:09 -060097
akmhoque1fd8c1e2014-02-19 19:41:49 -060098 Npl& getNpl()
99 {
100 return npl;
101 }
akmhoque298385a2014-02-13 14:13:09 -0600102
akmhoque1fd8c1e2014-02-19 19:41:49 -0600103 void addNameToLsa(string& name)
104 {
105 npl.insertIntoNpl(name);
106 }
akmhoque298385a2014-02-13 14:13:09 -0600107
akmhoque1fd8c1e2014-02-19 19:41:49 -0600108 void removeNameFromLsa(string& name)
109 {
110 npl.removeFromNpl(name);
111 }
akmhoque298385a2014-02-13 14:13:09 -0600112
akmhoque1fd8c1e2014-02-19 19:41:49 -0600113 string getNameLsaKey();
akmhoque298385a2014-02-13 14:13:09 -0600114
akmhoque1fd8c1e2014-02-19 19:41:49 -0600115 string getNameLsaData();
akmhoque2bb198e2014-02-28 11:46:27 -0600116 bool initNameLsaFromContent(string content);
akmhoque298385a2014-02-13 14:13:09 -0600117
akmhoque1fd8c1e2014-02-19 19:41:49 -0600118 private:
119 Npl npl;
akmhoque298385a2014-02-13 14:13:09 -0600120
akmhoque1fd8c1e2014-02-19 19:41:49 -0600121 };
akmhoque298385a2014-02-13 14:13:09 -0600122
akmhoque1fd8c1e2014-02-19 19:41:49 -0600123 std::ostream&
124 operator<<(std::ostream& os, NameLsa& nLsa);
akmhoque298385a2014-02-13 14:13:09 -0600125
akmhoque1fd8c1e2014-02-19 19:41:49 -0600126 class AdjLsa: public Lsa
127 {
128 public:
129 AdjLsa()
130 : Lsa()
131 , adl()
132 {
133 setLsType(2);
134 }
akmhoque298385a2014-02-13 14:13:09 -0600135
akmhoque1fd8c1e2014-02-19 19:41:49 -0600136 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 }
akmhoque298385a2014-02-13 14:13:09 -0600142
akmhoque1fd8c1e2014-02-19 19:41:49 -0600143 void addAdjacentToLsa(Adjacent adj)
144 {
145 adl.insert(adj);
146 }
147 string getAdjLsaKey();
148 string getAdjLsaData();
akmhoque2bb198e2014-02-28 11:46:27 -0600149 bool initAdjLsaFromContent(string content);
akmhoque1fd8c1e2014-02-19 19:41:49 -0600150 uint32_t getNoLink()
151 {
152 return noLink;
153 }
akmhoque298385a2014-02-13 14:13:09 -0600154
akmhoque1fd8c1e2014-02-19 19:41:49 -0600155 bool isLsaContentEqual(AdjLsa& alsa);
156 void addNptEntriesForAdjLsa(Nlsr& pnlsr);
157 void removeNptEntriesForAdjLsa(Nlsr& pnlsr);
akmhoque298385a2014-02-13 14:13:09 -0600158
akmhoque1fd8c1e2014-02-19 19:41:49 -0600159 private:
160 uint32_t noLink;
161 Adl adl;
162 };
akmhoque298385a2014-02-13 14:13:09 -0600163
akmhoque1fd8c1e2014-02-19 19:41:49 -0600164 std::ostream&
165 operator<<(std::ostream& os, AdjLsa& aLsa);
akmhoque298385a2014-02-13 14:13:09 -0600166
akmhoque1fd8c1e2014-02-19 19:41:49 -0600167 class CorLsa:public Lsa
168 {
169 public:
170 CorLsa()
akmhoque2bb198e2014-02-28 11:46:27 -0600171 : Lsa()
172 , corRad(0)
173 , corTheta(0)
akmhoque1fd8c1e2014-02-19 19:41:49 -0600174 {
175 setLsType(3);
176 }
akmhoque298385a2014-02-13 14:13:09 -0600177
akmhoque1fd8c1e2014-02-19 19:41:49 -0600178 CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt
179 , double r, double theta);
180 string getCorLsaKey();
181 string getCorLsaData();
akmhoque2bb198e2014-02-28 11:46:27 -0600182 bool initCorLsaFromContent(string content);
akmhoque1fd8c1e2014-02-19 19:41:49 -0600183 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);
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