blob: f238bce2a67c998756c6a34e0d01b53de4521d4d [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include<string>
2#include<iostream>
3#include<algorithm>
4#include<cmath>
5#include<limits>
6
7#include "nlsr_lsa.hpp"
8#include "nlsr_npl.hpp"
9#include "nlsr_adjacent.hpp"
10#include "nlsr.hpp"
11
akmhoque1fd8c1e2014-02-19 19:41:49 -060012namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -060013{
akmhoque298385a2014-02-13 14:13:09 -060014
akmhoque1fd8c1e2014-02-19 19:41:49 -060015 using namespace std;
akmhoque298385a2014-02-13 14:13:09 -060016
akmhoque298385a2014-02-13 14:13:09 -060017
akmhoque1fd8c1e2014-02-19 19:41:49 -060018 string
19 NameLsa::getNameLsaKey()
20 {
21 string key;
22 key=origRouter + "/" + boost::lexical_cast<std::string>(1);
23 return key;
24 }
akmhoque298385a2014-02-13 14:13:09 -060025
akmhoque1fd8c1e2014-02-19 19:41:49 -060026 NameLsa::NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl npl)
27 {
28 origRouter=origR;
29 lsType=lst;
30 lsSeqNo=lsn;
31 lifeTime=lt;
akmhoque1fd8c1e2014-02-19 19:41:49 -060032 std::list<string> nl=npl.getNameList();
33 for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
34 {
35 addNameToLsa((*it));
36 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060037 }
38
39 string
40 NameLsa::getNameLsaData()
41 {
42 string nameLsaData;
43 nameLsaData=origRouter + "|" + boost::lexical_cast<std::string>(lsType) + "|"
44 + boost::lexical_cast<std::string>(lsSeqNo) + "|"
45 + boost::lexical_cast<std::string>(lifeTime);
46 nameLsaData+="|";
47 nameLsaData+=boost::lexical_cast<std::string>(npl.getNplSize());
akmhoque1fd8c1e2014-02-19 19:41:49 -060048 std::list<string> nl=npl.getNameList();
49 for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
50 {
51 nameLsaData+="|";
52 nameLsaData+=(*it);
53 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060054 return nameLsaData;
55 }
56
57 std::ostream&
58 operator<<(std::ostream& os, NameLsa& nLsa)
59 {
60 os<<"Name Lsa: "<<endl;
61 os<<" Origination Router: "<<nLsa.getOrigRouter()<<endl;
62 os<<" Ls Type: "<<(unsigned short)nLsa.getLsType()<<endl;
63 os<<" Ls Seq No: "<<(unsigned int)nLsa.getLsSeqNo()<<endl;
64 os<<" Ls Lifetime: "<<(unsigned int)nLsa.getLifeTime()<<endl;
65 os<<" Names: "<<endl;
66 int i=1;
67 std::list<string> nl=nLsa.getNpl().getNameList();
68 for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
69 {
70 os<<" Name "<<i<<": "<<(*it)<<endl;
71 }
akmhoque1fd8c1e2014-02-19 19:41:49 -060072 return os;
73 }
akmhoque298385a2014-02-13 14:13:09 -060074
75
76
akmhoque1fd8c1e2014-02-19 19:41:49 -060077 CorLsa::CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt
78 , double r, double theta)
79 {
80 origRouter=origR;
81 lsType=lst;
82 lsSeqNo=lsn;
83 lifeTime=lt;
84 corRad=r;
85 corTheta=theta;
86 }
akmhoque298385a2014-02-13 14:13:09 -060087
akmhoque1fd8c1e2014-02-19 19:41:49 -060088 string
89 CorLsa::getCorLsaKey()
90 {
91 string key;
92 key=origRouter + "/" + boost::lexical_cast<std::string>(3);
93 return key;
94 }
akmhoque298385a2014-02-13 14:13:09 -060095
akmhoque1fd8c1e2014-02-19 19:41:49 -060096 bool
97 CorLsa::isLsaContentEqual(CorLsa& clsa)
98 {
99 return (std::abs(corRad - clsa.getCorRadius()) <
100 std::numeric_limits<double>::epsilon()) &&
101 (std::abs(corTheta - clsa.getCorTheta()) <
102 std::numeric_limits<double>::epsilon());
103 }
akmhoque298385a2014-02-13 14:13:09 -0600104
akmhoque1fd8c1e2014-02-19 19:41:49 -0600105 string
106 CorLsa::getCorLsaData()
107 {
108 string corLsaData;
109 corLsaData=origRouter + "|";
110 corLsaData+=(boost::lexical_cast<std::string>(lsType) + "|");
111 corLsaData+=(boost::lexical_cast<std::string>(lsSeqNo) + "|");
112 corLsaData+=(boost::lexical_cast<std::string>(lifeTime) + "|");
113 corLsaData+=(boost::lexical_cast<std::string>(corRad) + "|");
114 corLsaData+=(boost::lexical_cast<std::string>(corTheta) + "|");
akmhoque1fd8c1e2014-02-19 19:41:49 -0600115 return corLsaData;
116 }
akmhoque298385a2014-02-13 14:13:09 -0600117
akmhoque1fd8c1e2014-02-19 19:41:49 -0600118 std::ostream&
119 operator<<(std::ostream& os, CorLsa& cLsa)
120 {
121 os<<"Cor Lsa: "<<endl;
122 os<<" Origination Router: "<<cLsa.getOrigRouter()<<endl;
123 os<<" Ls Type: "<<(unsigned short)cLsa.getLsType()<<endl;
124 os<<" Ls Seq No: "<<(unsigned int)cLsa.getLsSeqNo()<<endl;
125 os<<" Ls Lifetime: "<<(unsigned int)cLsa.getLifeTime()<<endl;
126 os<<" Hyperbolic Radius: "<<cLsa.getCorRadius()<<endl;
127 os<<" Hyperbolic Theta: "<<cLsa.getCorTheta()<<endl;
akmhoque1fd8c1e2014-02-19 19:41:49 -0600128 return os;
129 }
akmhoque298385a2014-02-13 14:13:09 -0600130
131
akmhoque1fd8c1e2014-02-19 19:41:49 -0600132 AdjLsa::AdjLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
133 uint32_t nl ,Adl padl)
134 {
135 origRouter=origR;
136 lsType=lst;
137 lsSeqNo=lsn;
138 lifeTime=lt;
139 noLink=nl;
akmhoque1fd8c1e2014-02-19 19:41:49 -0600140 std::list<Adjacent> al=padl.getAdjList();
141 for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++)
142 {
143 if((*it).getStatus()==1)
144 {
145 addAdjacentToLsa((*it));
146 }
147 }
148 }
akmhoque298385a2014-02-13 14:13:09 -0600149
akmhoque1fd8c1e2014-02-19 19:41:49 -0600150 string
151 AdjLsa::getAdjLsaKey()
152 {
153 string key;
154 key=origRouter + "/" + boost::lexical_cast<std::string>(2);
155 return key;
156 }
akmhoque298385a2014-02-13 14:13:09 -0600157
akmhoque1fd8c1e2014-02-19 19:41:49 -0600158 bool
159 AdjLsa::isLsaContentEqual(AdjLsa& alsa)
160 {
161 return adl.isAdlEqual(alsa.getAdl());
162 }
akmhoque298385a2014-02-13 14:13:09 -0600163
164
akmhoque1fd8c1e2014-02-19 19:41:49 -0600165 string
166 AdjLsa::getAdjLsaData()
167 {
168 string adjLsaData;
169 adjLsaData=origRouter + "|" + boost::lexical_cast<std::string>(lsType) + "|"
170 + boost::lexical_cast<std::string>(lsSeqNo) + "|"
171 + boost::lexical_cast<std::string>(lifeTime);
172 adjLsaData+="|";
173 adjLsaData+=boost::lexical_cast<std::string>(adl.getAdlSize());
akmhoque1fd8c1e2014-02-19 19:41:49 -0600174 std::list<Adjacent> al=adl.getAdjList();
175 for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++)
176 {
177 adjLsaData+="|";
178 adjLsaData+=(*it).getAdjacentName();
179 adjLsaData+="|";
180 adjLsaData+=boost::lexical_cast<std::string>((*it).getConnectingFace());
181 adjLsaData+="|";
182 adjLsaData+=boost::lexical_cast<std::string>((*it).getLinkCost());
akmhoque1fd8c1e2014-02-19 19:41:49 -0600183 }
184 return adjLsaData;
185 }
akmhoque298385a2014-02-13 14:13:09 -0600186
187
akmhoque1fd8c1e2014-02-19 19:41:49 -0600188 void
189 AdjLsa::addNptEntriesForAdjLsa(Nlsr& pnlsr)
190 {
191 if ( getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
192 {
193 pnlsr.getNpt().addNpte(getOrigRouter(), getOrigRouter(),pnlsr);
194 }
akmhoque1fd8c1e2014-02-19 19:41:49 -0600195 }
akmhoque298385a2014-02-13 14:13:09 -0600196
197
akmhoque1fd8c1e2014-02-19 19:41:49 -0600198 void
199 AdjLsa::removeNptEntriesForAdjLsa(Nlsr& pnlsr)
200 {
201 if ( getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
202 {
203 pnlsr.getNpt().removeNpte(getOrigRouter(), getOrigRouter(),pnlsr);
204 }
205 }
akmhoque298385a2014-02-13 14:13:09 -0600206
207
208
akmhoque1fd8c1e2014-02-19 19:41:49 -0600209 std::ostream&
210 operator<<(std::ostream& os, AdjLsa& aLsa)
211 {
212 os<<"Adj Lsa: "<<endl;
213 os<<" Origination Router: "<<aLsa.getOrigRouter()<<endl;
214 os<<" Ls Type: "<<(unsigned short)aLsa.getLsType()<<endl;
215 os<<" Ls Seq No: "<<(unsigned int)aLsa.getLsSeqNo()<<endl;
216 os<<" Ls Lifetime: "<<(unsigned int)aLsa.getLifeTime()<<endl;
217 os<<" No Link: "<<(unsigned int)aLsa.getNoLink()<<endl;
218 os<<" Adjacents: "<<endl;
219 int i=1;
220 std::list<Adjacent> al=aLsa.getAdl().getAdjList();
221 for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++)
222 {
223 os<<" Adjacent "<<i<<": "<<endl;
224 os<<" Adjacent Name: "<<(*it).getAdjacentName()<<endl;
225 os<<" Connecting Face: "<<(*it).getConnectingFace()<<endl;
226 os<<" Link Cost: "<<(*it).getLinkCost()<<endl;
227 }
akmhoque1fd8c1e2014-02-19 19:41:49 -0600228 return os;
229 }
akmhoqueb1710aa2014-02-19 17:13:36 -0600230
231}//namespace nlsr