blob: da7d86e06afd23527bc1f267bfff1c703a6b4de5 [file] [log] [blame]
akmhoquebd7c8e62014-02-01 14:57:40 -06001#include<string>
akmhoque62a8e402014-02-08 12:00:27 -06002#include<utility>
akmhoquebd7c8e62014-02-01 14:57:40 -06003#include "nlsr_lsdb.hpp"
4#include "nlsr.hpp"
5
6using namespace std;
7
akmhoquebd7c8e62014-02-01 14:57:40 -06008static bool
9nameLsaCompareByKey(NameLsa& nlsa1, string& key){
akmhoque3fdf7612014-02-04 21:18:23 -060010 return nlsa1.getNameLsaKey()==key;
akmhoquebd7c8e62014-02-01 14:57:40 -060011}
12
13
14bool
15Lsdb::buildAndInstallOwnNameLsa(nlsr& pnlsr)
16{
17 NameLsa nameLsa(pnlsr.getConfParameter().getRouterPrefix()
18 , 1
akmhoquedfa4a5b2014-02-03 20:12:29 -060019 , pnlsr.getSm().getNameLsaSeq()+1
akmhoquebd7c8e62014-02-01 14:57:40 -060020 , pnlsr.getConfParameter().getRouterDeadInterval()
21 , pnlsr.getNpl() );
akmhoquedfa4a5b2014-02-03 20:12:29 -060022 pnlsr.getSm().setNameLsaSeq(pnlsr.getSm().getNameLsaSeq()+1);
akmhoque62a8e402014-02-08 12:00:27 -060023 return installNameLsa(pnlsr,nameLsa);
akmhoquebd7c8e62014-02-01 14:57:40 -060024
25}
26
akmhoque62a8e402014-02-08 12:00:27 -060027std::pair<NameLsa&, bool>
akmhoquebd7c8e62014-02-01 14:57:40 -060028Lsdb::getNameLsa(string key)
29{
30 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
31 nameLsdb.end(),
32 bind(nameLsaCompareByKey, _1, key));
33
akmhoquefcf765d2014-02-01 23:46:17 -060034 if( it != nameLsdb.end())
35 {
akmhoque62a8e402014-02-08 12:00:27 -060036 return std::make_pair(boost::ref((*it)),true);
akmhoquebd7c8e62014-02-01 14:57:40 -060037 }
akmhoquedfa4a5b2014-02-03 20:12:29 -060038
akmhoque62a8e402014-02-08 12:00:27 -060039 NameLsa nlsa;
40 return std::make_pair(boost::ref(nlsa),false);
41
akmhoquebd7c8e62014-02-01 14:57:40 -060042}
43
44
45
46bool
akmhoque62a8e402014-02-08 12:00:27 -060047Lsdb::installNameLsa(nlsr& pnlsr, NameLsa &nlsa)
akmhoquebd7c8e62014-02-01 14:57:40 -060048{
akmhoque62a8e402014-02-08 12:00:27 -060049 std::pair<NameLsa& , bool> chkNameLsa=getNameLsa(nlsa.getNameLsaKey());
50 if ( !chkNameLsa.second )
akmhoquebd7c8e62014-02-01 14:57:40 -060051 {
akmhoquebd7c8e62014-02-01 14:57:40 -060052 addNameLsa(nlsa);
akmhoquedfa4a5b2014-02-03 20:12:29 -060053 printNameLsdb();
akmhoque62a8e402014-02-08 12:00:27 -060054 if ( nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
55 {
56 pnlsr.getNpt().addNpte(nlsa.getOrigRouter(),nlsa.getOrigRouter(),pnlsr);
57 std::list<string> nameList=nlsa.getNpl().getNameList();
58 for(std::list<string>::iterator it=nameList.begin(); it!=nameList.end();it++)
59 {
akmhoque4768f892014-02-08 23:58:07 -060060 if ( (*it) !=pnlsr.getConfParameter().getRouterPrefix())
61 {
62 pnlsr.getNpt().addNpte((*it),nlsa.getOrigRouter(),pnlsr);
63 }
akmhoque62a8e402014-02-08 12:00:27 -060064 }
65 }
akmhoquebd7c8e62014-02-01 14:57:40 -060066 }
67 else
68 {
akmhoque62a8e402014-02-08 12:00:27 -060069 if ( chkNameLsa.first.getLsSeqNo() < nlsa.getLsSeqNo() )
70 {
71 chkNameLsa.first.setLsSeqNo(nlsa.getLsSeqNo());
72 chkNameLsa.first.setLifeTime(nlsa.getLifeTime());
73
74 chkNameLsa.first.getNpl().sortNpl();
75 nlsa.getNpl().sortNpl();
76
77 std::list<string> nameToAdd;
78 std::set_difference(nlsa.getNpl().getNameList().begin(),
79 nlsa.getNpl().getNameList().end(),
80 chkNameLsa.first.getNpl().getNameList().begin(),
81 chkNameLsa.first.getNpl().getNameList().end(),
82 std::inserter(nameToAdd, nameToAdd.begin()));
83 for(std::list<string>::iterator it=nameToAdd.begin(); it!=nameToAdd.end();
84 ++it)
85 {
86 chkNameLsa.first.addNameToLsa((*it));
87 if ( nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
88 {
akmhoque4768f892014-02-08 23:58:07 -060089 if ( (*it) !=pnlsr.getConfParameter().getRouterPrefix())
90 {
91 pnlsr.getNpt().addNpte((*it),nlsa.getOrigRouter(),pnlsr);
92 }
akmhoque62a8e402014-02-08 12:00:27 -060093 }
94 }
95
96 std::list<string> nameToRemove;
97 std::set_difference(chkNameLsa.first.getNpl().getNameList().begin(),
98 chkNameLsa.first.getNpl().getNameList().end(),
99 nlsa.getNpl().getNameList().begin(),
100 nlsa.getNpl().getNameList().end(),
101 std::inserter(nameToRemove, nameToRemove.begin()));
102 for(std::list<string>::iterator it=nameToRemove.begin();
103 it!=nameToRemove.end(); ++it)
104 {
105 chkNameLsa.first.removeNameFromLsa((*it));
106 if ( nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
107 {
akmhoque4768f892014-02-08 23:58:07 -0600108 if ( (*it) !=pnlsr.getConfParameter().getRouterPrefix())
109 {
110 pnlsr.getNpt().removeNpte((*it),nlsa.getOrigRouter(),pnlsr);
111 }
akmhoque62a8e402014-02-08 12:00:27 -0600112 }
113 }
114
115 }
akmhoquebd7c8e62014-02-01 14:57:40 -0600116 }
117
118 return true;
119}
120
121bool
122Lsdb::addNameLsa(NameLsa &nlsa)
123{
124 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
125 nameLsdb.end(),
akmhoque3fdf7612014-02-04 21:18:23 -0600126 bind(nameLsaCompareByKey, _1, nlsa.getNameLsaKey()));
akmhoquebd7c8e62014-02-01 14:57:40 -0600127
akmhoquedfa4a5b2014-02-03 20:12:29 -0600128 if( it == nameLsdb.end())
129 {
akmhoquebd7c8e62014-02-01 14:57:40 -0600130 nameLsdb.push_back(nlsa);
131 return true;
132 }
133 return false;
134}
135
136bool
akmhoque4768f892014-02-08 23:58:07 -0600137Lsdb::removeNameLsa(nlsr& pnlsr, string& key)
akmhoquebd7c8e62014-02-01 14:57:40 -0600138{
akmhoquefcf765d2014-02-01 23:46:17 -0600139 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
140 nameLsdb.end(),
141 bind(nameLsaCompareByKey, _1, key));
142 if ( it != nameLsdb.end() )
143 {
akmhoque4768f892014-02-08 23:58:07 -0600144 if ( (*it).getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix() )
145 {
146 pnlsr.getNpt().removeNpte((*it).getOrigRouter(),(*it).getOrigRouter(),pnlsr);
147 for( std::list<string>::iterator nit=(*it).getNpl().getNameList().begin();
148 nit!=(*it).getNpl().getNameList().end(); ++nit)
149 {
150 if ( (*nit) !=pnlsr.getConfParameter().getRouterPrefix())
151 {
152 pnlsr.getNpt().removeNpte((*nit),(*it).getOrigRouter(),pnlsr);
153 }
154 }
155
156 }
akmhoquefcf765d2014-02-01 23:46:17 -0600157 nameLsdb.erase(it);
158 return true;
159 }
akmhoquebd7c8e62014-02-01 14:57:40 -0600160 return false;
161}
akmhoquebd7c8e62014-02-01 14:57:40 -0600162
163bool
164Lsdb::doesNameLsaExist(string key)
165{
166 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
167 nameLsdb.end(),
168 bind(nameLsaCompareByKey, _1, key));
169
170 if( it == nameLsdb.end()){
171 return false;
172 }
173
174 return true;
175}
176
akmhoque3c6bd922014-02-01 17:10:17 -0600177void
178Lsdb::printNameLsdb()
179{
akmhoquedfa4a5b2014-02-03 20:12:29 -0600180 cout<<"---------------Name LSDB-------------------"<<endl;
akmhoque3c6bd922014-02-01 17:10:17 -0600181 for( std::list<NameLsa>::iterator it=nameLsdb.begin();
182 it!= nameLsdb.end() ; it++)
183 {
184 cout<< (*it) <<endl;
185 }
186}
187
188// Cor LSA and LSDB related Functions start here
akmhoque4768f892014-02-08 23:58:07 -0600189
190
akmhoque3c6bd922014-02-01 17:10:17 -0600191static bool
192corLsaCompareByKey(CorLsa& clsa, string& key){
akmhoque3fdf7612014-02-04 21:18:23 -0600193 return clsa.getCorLsaKey()==key;
akmhoque3c6bd922014-02-01 17:10:17 -0600194}
akmhoquebd7c8e62014-02-01 14:57:40 -0600195
196bool
akmhoque3c6bd922014-02-01 17:10:17 -0600197Lsdb::buildAndInstallOwnCorLsa(nlsr& pnlsr){
198 CorLsa corLsa(pnlsr.getConfParameter().getRouterPrefix()
akmhoquecd552472014-02-01 21:22:16 -0600199 , 3
akmhoquedfa4a5b2014-02-03 20:12:29 -0600200 , pnlsr.getSm().getCorLsaSeq()+1
akmhoque3c6bd922014-02-01 17:10:17 -0600201 , pnlsr.getConfParameter().getRouterDeadInterval()
202 , pnlsr.getConfParameter().getCorR()
203 , pnlsr.getConfParameter().getCorTheta() );
akmhoquedfa4a5b2014-02-03 20:12:29 -0600204 pnlsr.getSm().setCorLsaSeq(pnlsr.getSm().getCorLsaSeq()+1);
akmhoquef7c2c7c2014-02-06 11:32:43 -0600205 installCorLsa(pnlsr, corLsa);
akmhoque3c6bd922014-02-01 17:10:17 -0600206
akmhoquefcf765d2014-02-01 23:46:17 -0600207 return true;
akmhoque3c6bd922014-02-01 17:10:17 -0600208}
209
akmhoque62a8e402014-02-08 12:00:27 -0600210std::pair<CorLsa&, bool>
akmhoque3c6bd922014-02-01 17:10:17 -0600211Lsdb::getCorLsa(string key)
akmhoquebd7c8e62014-02-01 14:57:40 -0600212{
akmhoque3c6bd922014-02-01 17:10:17 -0600213 std::list< CorLsa >::iterator it = std::find_if( corLsdb.begin(),
214 corLsdb.end(),
215 bind(corLsaCompareByKey, _1, key));
216
217 if( it != corLsdb.end()){
akmhoque62a8e402014-02-08 12:00:27 -0600218 return std::make_pair(boost::ref((*it)), true);
akmhoque3c6bd922014-02-01 17:10:17 -0600219 }
akmhoque62a8e402014-02-08 12:00:27 -0600220
221 CorLsa clsa;
222 return std::make_pair(boost::ref(clsa),false);
akmhoque3c6bd922014-02-01 17:10:17 -0600223}
224
225bool
akmhoquef7c2c7c2014-02-06 11:32:43 -0600226Lsdb::installCorLsa(nlsr& pnlsr, CorLsa &clsa)
akmhoque3c6bd922014-02-01 17:10:17 -0600227{
akmhoque62a8e402014-02-08 12:00:27 -0600228 std::pair<CorLsa& , bool> chkCorLsa=getCorLsa(clsa.getCorLsaKey());
229 if ( !chkCorLsa.second )
akmhoque3c6bd922014-02-01 17:10:17 -0600230 {
akmhoque3c6bd922014-02-01 17:10:17 -0600231 addCorLsa(clsa);
akmhoquef7c2c7c2014-02-06 11:32:43 -0600232 printCorLsdb(); //debugging purpose
akmhoque62a8e402014-02-08 12:00:27 -0600233 if ( clsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
234 {
235 pnlsr.getNpt().addNpte(clsa.getOrigRouter(),clsa.getOrigRouter(),pnlsr);
236 }
akmhoquef7c2c7c2014-02-06 11:32:43 -0600237 if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 )
238 {
239 if ( pnlsr.getIsRouteCalculationScheduled() != 1 )
240 {
241 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
242 ndn::bind(&RoutingTable::calculate,
243 &pnlsr.getRoutingTable(),boost::ref(pnlsr)));
244 pnlsr.setIsRouteCalculationScheduled(1);
245 }
246 }
247
akmhoque3c6bd922014-02-01 17:10:17 -0600248 }
249 else
250 {
akmhoque4768f892014-02-08 23:58:07 -0600251 if ( chkCorLsa.first.getLsSeqNo() < clsa.getLsSeqNo() )
252 {
253 chkCorLsa.first.setLsSeqNo(clsa.getLsSeqNo());
254 chkCorLsa.first.setLifeTime(clsa.getLifeTime());
255 if ( !chkCorLsa.first.isLsaContentEqual(clsa) )
256 {
257 chkCorLsa.first.setCorRadius(clsa.getCorRadius());
258 chkCorLsa.first.setCorTheta(clsa.getCorTheta());
259
260 if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 )
261 {
262 if ( pnlsr.getIsRouteCalculationScheduled() != 1 )
263 {
264 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
265 ndn::bind(&RoutingTable::calculate,
266 &pnlsr.getRoutingTable(),boost::ref(pnlsr)));
267 pnlsr.setIsRouteCalculationScheduled(1);
268 }
269 }
270
271 }
272 }
akmhoque3c6bd922014-02-01 17:10:17 -0600273
274 }
275
276 return true;
277}
278
279bool
280Lsdb::addCorLsa(CorLsa& clsa)
281{
282 std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(),
283 corLsdb.end(),
akmhoque3fdf7612014-02-04 21:18:23 -0600284 bind(corLsaCompareByKey, _1, clsa.getCorLsaKey()));
akmhoque3c6bd922014-02-01 17:10:17 -0600285
akmhoquedfa4a5b2014-02-03 20:12:29 -0600286 if( it == corLsdb.end())
287 {
akmhoque3c6bd922014-02-01 17:10:17 -0600288 corLsdb.push_back(clsa);
289 return true;
290 }
akmhoquebd7c8e62014-02-01 14:57:40 -0600291 return false;
292}
293
294bool
akmhoque4768f892014-02-08 23:58:07 -0600295Lsdb::removeCorLsa(nlsr& pnlsr, string& key)
akmhoque3c6bd922014-02-01 17:10:17 -0600296{
akmhoquefcf765d2014-02-01 23:46:17 -0600297 std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(),
298 corLsdb.end(),
299 bind(corLsaCompareByKey, _1, key));
300 if ( it != corLsdb.end() )
301 {
akmhoque4768f892014-02-08 23:58:07 -0600302 if ( (*it).getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
303 {
304 pnlsr.getNpt().removeNpte((*it).getOrigRouter(),(*it).getOrigRouter(),pnlsr);
305 }
akmhoquefcf765d2014-02-01 23:46:17 -0600306 corLsdb.erase(it);
307 return true;
308 }
309 return false;
akmhoque3c6bd922014-02-01 17:10:17 -0600310
311}
312
313bool
akmhoquebd7c8e62014-02-01 14:57:40 -0600314Lsdb::doesCorLsaExist(string key)
315{
akmhoque3c6bd922014-02-01 17:10:17 -0600316 std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(),
317 corLsdb.end(),
318 bind(corLsaCompareByKey, _1, key));
319
320 if( it == corLsdb.end()){
321 return false;
322 }
323
324 return true;
akmhoquebd7c8e62014-02-01 14:57:40 -0600325}
akmhoque3c6bd922014-02-01 17:10:17 -0600326
327void
328Lsdb::printCorLsdb() //debugging
329{
akmhoquedfa4a5b2014-02-03 20:12:29 -0600330 cout<<"---------------Cor LSDB-------------------"<<endl;
akmhoque3c6bd922014-02-01 17:10:17 -0600331 for( std::list<CorLsa>::iterator it=corLsdb.begin();
332 it!= corLsdb.end() ; it++)
333 {
334 cout<< (*it) <<endl;
335 }
336}
337
338
339// Adj LSA and LSDB related function starts here
akmhoquedfa4a5b2014-02-03 20:12:29 -0600340/*
akmhoque3c6bd922014-02-01 17:10:17 -0600341static bool
342adjLsaCompare(AdjLsa& alsa1, AdjLsa& alsa2){
343 return alsa1.getLsaKey()==alsa1.getLsaKey();
344}
akmhoquedfa4a5b2014-02-03 20:12:29 -0600345*/
akmhoque3c6bd922014-02-01 17:10:17 -0600346static bool
347adjLsaCompareByKey(AdjLsa& alsa, string& key){
akmhoque3fdf7612014-02-04 21:18:23 -0600348 return alsa.getAdjLsaKey()==key;
akmhoque3c6bd922014-02-01 17:10:17 -0600349}
350
351
akmhoquecd552472014-02-01 21:22:16 -0600352void
353Lsdb::scheduledAdjLsaBuild(nlsr& pnlsr)
354{
355 cout<<"scheduledAdjLsaBuild Called"<<endl;
356 pnlsr.setIsBuildAdjLsaSheduled(0);
akmhoque3c6bd922014-02-01 17:10:17 -0600357
akmhoquecd552472014-02-01 21:22:16 -0600358 if( pnlsr.getAdl().isAdjLsaBuildable(pnlsr))
359 {
360 int adjBuildCount=pnlsr.getAdjBuildCount();
361 if(adjBuildCount>0 )
362 {
363 if (pnlsr.getAdl().getNumOfActiveNeighbor()>0)
364 {
365 buildAndInstallOwnAdjLsa(pnlsr);
366 }
367 else
368 {
369 //remove if there is any adj lsa in LSDB
akmhoquefcf765d2014-02-01 23:46:17 -0600370 string key=pnlsr.getConfParameter().getRouterPrefix()+"/2";
akmhoque4768f892014-02-08 23:58:07 -0600371 removeAdjLsa(pnlsr,key);
akmhoquefcf765d2014-02-01 23:46:17 -0600372 // Remove alll fib entries as per NPT
akmhoquecd552472014-02-01 21:22:16 -0600373 }
374 pnlsr.setAdjBuildCount(pnlsr.getAdjBuildCount()-adjBuildCount);
375 }
376 }
377 else
378 {
379 pnlsr.setIsBuildAdjLsaSheduled(1);
380 int schedulingTime=pnlsr.getConfParameter().getInterestRetryNumber()*
381 pnlsr.getConfParameter().getInterestRetryNumber();
382 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime),
383 ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(),
384 boost::ref(pnlsr)));
385 }
386
387}
388
389
390bool
391Lsdb::addAdjLsa(AdjLsa &alsa)
392{
393 std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(),
394 adjLsdb.end(),
akmhoque3fdf7612014-02-04 21:18:23 -0600395 bind(adjLsaCompareByKey, _1, alsa.getAdjLsaKey()));
akmhoquecd552472014-02-01 21:22:16 -0600396
397 if( it == adjLsdb.end()){
398 adjLsdb.push_back(alsa);
399 return true;
400 }
401 return false;
402
403}
404
akmhoque62a8e402014-02-08 12:00:27 -0600405std::pair<AdjLsa& , bool>
akmhoquecd552472014-02-01 21:22:16 -0600406Lsdb::getAdjLsa(string key)
407{
408 std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(),
409 adjLsdb.end(),
410 bind(adjLsaCompareByKey, _1, key));
411
412 if( it != adjLsdb.end()){
akmhoque62a8e402014-02-08 12:00:27 -0600413 return std::make_pair(boost::ref((*it)),true);
akmhoquecd552472014-02-01 21:22:16 -0600414 }
akmhoque62a8e402014-02-08 12:00:27 -0600415
416 AdjLsa alsa;
417 return std::make_pair(boost::ref(alsa),false);
akmhoquecd552472014-02-01 21:22:16 -0600418}
419
420bool
akmhoquedfa4a5b2014-02-03 20:12:29 -0600421Lsdb::installAdjLsa(nlsr& pnlsr, AdjLsa &alsa)
akmhoquecd552472014-02-01 21:22:16 -0600422{
akmhoque62a8e402014-02-08 12:00:27 -0600423 std::pair<AdjLsa& , bool> chkAdjLsa=getAdjLsa(alsa.getAdjLsaKey());
424 if ( !chkAdjLsa.second )
akmhoquecd552472014-02-01 21:22:16 -0600425 {
akmhoquecd552472014-02-01 21:22:16 -0600426 addAdjLsa(alsa);
akmhoque4768f892014-02-08 23:58:07 -0600427 alsa.addNptEntriesForAdjLsa(pnlsr);
akmhoque79d355f2014-02-04 15:11:16 -0600428 if ( pnlsr.getIsRouteCalculationScheduled() != 1 )
429 {
430 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
431 ndn::bind(&RoutingTable::calculate,
432 &pnlsr.getRoutingTable(),boost::ref(pnlsr)));
433 pnlsr.setIsRouteCalculationScheduled(1);
434 }
akmhoquecd552472014-02-01 21:22:16 -0600435 }
436 else
437 {
akmhoque4768f892014-02-08 23:58:07 -0600438 if ( chkAdjLsa.first.getLsSeqNo() < alsa.getLsSeqNo() )
439 {
440 chkAdjLsa.first.setLsSeqNo(alsa.getLsSeqNo());
441 chkAdjLsa.first.setLifeTime(alsa.getLifeTime());
442
443 if ( ! chkAdjLsa.first.isLsaContentEqual(alsa))
444 {
445 chkAdjLsa.first.getAdl().resetAdl();
446 chkAdjLsa.first.getAdl().addAdjacentsFromAdl(alsa.getAdl());
447 if ( pnlsr.getIsRouteCalculationScheduled() != 1 )
448 {
449 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(15),
450 ndn::bind(&RoutingTable::calculate,
451 &pnlsr.getRoutingTable(),boost::ref(pnlsr)));
452 pnlsr.setIsRouteCalculationScheduled(1);
453 }
454 }
455 }
akmhoquecd552472014-02-01 21:22:16 -0600456
457 }
458
459 printAdjLsdb();
460
461 return true;
462}
463
464bool
465Lsdb::buildAndInstallOwnAdjLsa(nlsr& pnlsr)
466{
467 AdjLsa adjLsa(pnlsr.getConfParameter().getRouterPrefix()
468 , 2
akmhoquedfa4a5b2014-02-03 20:12:29 -0600469 , pnlsr.getSm().getAdjLsaSeq()+1
akmhoquecd552472014-02-01 21:22:16 -0600470 , pnlsr.getConfParameter().getRouterDeadInterval()
471 , pnlsr.getAdl().getNumOfActiveNeighbor()
472 , pnlsr.getAdl() );
akmhoquedfa4a5b2014-02-03 20:12:29 -0600473 pnlsr.getSm().setAdjLsaSeq(pnlsr.getSm().getAdjLsaSeq()+1);
474 return installAdjLsa(pnlsr, adjLsa);
akmhoquecd552472014-02-01 21:22:16 -0600475}
476
477bool
akmhoque4768f892014-02-08 23:58:07 -0600478Lsdb::removeAdjLsa(nlsr& pnlsr, string& key)
akmhoquecd552472014-02-01 21:22:16 -0600479{
akmhoquefcf765d2014-02-01 23:46:17 -0600480 std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(),
481 adjLsdb.end(),
482 bind(adjLsaCompareByKey, _1, key));
483 if ( it != adjLsdb.end() )
484 {
akmhoque4768f892014-02-08 23:58:07 -0600485 (*it).removeNptEntriesForAdjLsa(pnlsr);
akmhoquefcf765d2014-02-01 23:46:17 -0600486 adjLsdb.erase(it);
487 return true;
488 }
489 return false;
akmhoquecd552472014-02-01 21:22:16 -0600490
491}
akmhoque3c6bd922014-02-01 17:10:17 -0600492
493bool
494Lsdb::doesAdjLsaExist(string key)
495{
496 std::list< AdjLsa >::iterator it = std::find_if( adjLsdb.begin(),
497 adjLsdb.end(),
498 bind(adjLsaCompareByKey, _1, key));
499
500 if( it == adjLsdb.end()){
501 return false;
502 }
503
504 return true;
505}
506
akmhoque79d355f2014-02-04 15:11:16 -0600507std::list<AdjLsa>&
508Lsdb::getAdjLsdb()
509{
510 return adjLsdb;
511}
512
akmhoque4768f892014-02-08 23:58:07 -0600513
akmhoquecd552472014-02-01 21:22:16 -0600514void
515Lsdb::printAdjLsdb()
516{
akmhoquedfa4a5b2014-02-03 20:12:29 -0600517 cout<<"---------------Adj LSDB-------------------"<<endl;
akmhoquecd552472014-02-01 21:22:16 -0600518 for( std::list<AdjLsa>::iterator it=adjLsdb.begin();
519 it!= adjLsdb.end() ; it++)
520 {
521 cout<< (*it) <<endl;
522 }
523}
akmhoque3c6bd922014-02-01 17:10:17 -0600524
akmhoque62a8e402014-02-08 12:00:27 -0600525//-----utility function -----
526bool
527Lsdb::doesLsaExist(string key, int lsType)
528{
529 if ( lsType == 1)
530 {
531 return doesNameLsaExist(key);
532 }
533 else if ( lsType == 2)
534 {
535 return doesAdjLsaExist(key);
536 }
537 else if ( lsType == 3)
538 {
539 return doesCorLsaExist(key);
540 }
541
542 return false;
543}
544
545