blob: 28301f4ee24ca4367627e83395d7b98c734b26c2 [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include<string>
2#include<utility>
3#include "nlsr_lsdb.hpp"
4#include "nlsr.hpp"
5
akmhoqueb1710aa2014-02-19 17:13:36 -06006namespace nlsr {
7
akmhoque298385a2014-02-13 14:13:09 -06008using namespace std;
9
akmhoque85d88332014-02-17 21:11:21 -060010void
akmhoque1a481092014-02-19 16:34:22 -060011Lsdb::cancelScheduleLsaExpiringEvent(Nlsr& pnlsr, EventId eid)
akmhoque85d88332014-02-17 21:11:21 -060012{
13 pnlsr.getScheduler().cancelEvent(eid);
14}
15
akmhoque298385a2014-02-13 14:13:09 -060016static bool
17nameLsaCompareByKey(NameLsa& nlsa1, string& key){
18 return nlsa1.getNameLsaKey()==key;
19}
20
21
22bool
akmhoque1a481092014-02-19 16:34:22 -060023Lsdb::buildAndInstallOwnNameLsa(Nlsr& pnlsr)
akmhoque298385a2014-02-13 14:13:09 -060024{
25 NameLsa nameLsa(pnlsr.getConfParameter().getRouterPrefix()
26 , 1
27 , pnlsr.getSm().getNameLsaSeq()+1
28 , pnlsr.getConfParameter().getRouterDeadInterval()
29 , pnlsr.getNpl() );
30 pnlsr.getSm().setNameLsaSeq(pnlsr.getSm().getNameLsaSeq()+1);
31 return installNameLsa(pnlsr,nameLsa);
32
33}
34
35std::pair<NameLsa&, bool>
36Lsdb::getNameLsa(string key)
37{
38 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
39 nameLsdb.end(),
40 bind(nameLsaCompareByKey, _1, key));
41
42 if( it != nameLsdb.end())
43 {
44 return std::make_pair(boost::ref((*it)),true);
45 }
46
47 NameLsa nlsa;
48 return std::make_pair(boost::ref(nlsa),false);
49
50}
51
52
akmhoque85d88332014-02-17 21:11:21 -060053ndn::EventId
akmhoque1a481092014-02-19 16:34:22 -060054Lsdb::scheduleNameLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime)
akmhoque298385a2014-02-13 14:13:09 -060055{
akmhoque85d88332014-02-17 21:11:21 -060056 return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
akmhoque298385a2014-02-13 14:13:09 -060057 ndn::bind(&Lsdb::exprireOrRefreshNameLsa,
58 this,boost::ref(pnlsr), key, seqNo));
59}
60
61bool
akmhoque1a481092014-02-19 16:34:22 -060062Lsdb::installNameLsa(Nlsr& pnlsr, NameLsa &nlsa)
akmhoque298385a2014-02-13 14:13:09 -060063{
64 int timeToExpire=lsaRefreshTime;
65 std::pair<NameLsa& , bool> chkNameLsa=getNameLsa(nlsa.getNameLsaKey());
66 if ( !chkNameLsa.second )
67 {
68 addNameLsa(nlsa);
69 printNameLsdb();
70 if ( nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
71 {
72 pnlsr.getNpt().addNpte(nlsa.getOrigRouter(),nlsa.getOrigRouter(),pnlsr);
73 std::list<string> nameList=nlsa.getNpl().getNameList();
74 for(std::list<string>::iterator it=nameList.begin(); it!=nameList.end();it++)
75 {
76 if ( (*it) !=pnlsr.getConfParameter().getRouterPrefix())
77 {
78 pnlsr.getNpt().addNpte((*it),nlsa.getOrigRouter(),pnlsr);
79 }
80 }
81 }
82
83 if(nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
84 {
85 timeToExpire=nlsa.getLifeTime();
86 }
akmhoque85d88332014-02-17 21:11:21 -060087 nlsa.setLsaExpiringEventId(scheduleNameLsaExpiration( pnlsr,
88 nlsa.getNameLsaKey(), nlsa.getLsSeqNo(), timeToExpire));
akmhoque298385a2014-02-13 14:13:09 -060089 }
90 else
91 {
92 if ( chkNameLsa.first.getLsSeqNo() < nlsa.getLsSeqNo() )
93 {
94 chkNameLsa.first.setLsSeqNo(nlsa.getLsSeqNo());
95 chkNameLsa.first.setLifeTime(nlsa.getLifeTime());
96
97 chkNameLsa.first.getNpl().sortNpl();
98 nlsa.getNpl().sortNpl();
99
100 std::list<string> nameToAdd;
101 std::set_difference(nlsa.getNpl().getNameList().begin(),
102 nlsa.getNpl().getNameList().end(),
103 chkNameLsa.first.getNpl().getNameList().begin(),
104 chkNameLsa.first.getNpl().getNameList().end(),
105 std::inserter(nameToAdd, nameToAdd.begin()));
106 for(std::list<string>::iterator it=nameToAdd.begin(); it!=nameToAdd.end();
107 ++it)
108 {
109 chkNameLsa.first.addNameToLsa((*it));
110 if ( nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
111 {
112 if ( (*it) !=pnlsr.getConfParameter().getRouterPrefix())
113 {
114 pnlsr.getNpt().addNpte((*it),nlsa.getOrigRouter(),pnlsr);
115 }
116 }
117 }
118
119 std::list<string> nameToRemove;
120 std::set_difference(chkNameLsa.first.getNpl().getNameList().begin(),
121 chkNameLsa.first.getNpl().getNameList().end(),
122 nlsa.getNpl().getNameList().begin(),
123 nlsa.getNpl().getNameList().end(),
124 std::inserter(nameToRemove, nameToRemove.begin()));
125 for(std::list<string>::iterator it=nameToRemove.begin();
126 it!=nameToRemove.end(); ++it)
127 {
128 chkNameLsa.first.removeNameFromLsa((*it));
129 if ( nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
130 {
131 if ( (*it) !=pnlsr.getConfParameter().getRouterPrefix())
132 {
133 pnlsr.getNpt().removeNpte((*it),nlsa.getOrigRouter(),pnlsr);
134 }
135 }
136 }
137
138 if(nlsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
139 {
140 timeToExpire=nlsa.getLifeTime();
141 }
akmhoque85d88332014-02-17 21:11:21 -0600142 cancelScheduleLsaExpiringEvent(pnlsr,
143 chkNameLsa.first.getLsaExpiringEventId());
144 chkNameLsa.first.setLsaExpiringEventId(scheduleNameLsaExpiration( pnlsr,
145 nlsa.getNameLsaKey(), nlsa.getLsSeqNo(), timeToExpire));
akmhoque298385a2014-02-13 14:13:09 -0600146 }
147 }
148
149 return true;
150}
151
152bool
153Lsdb::addNameLsa(NameLsa &nlsa)
154{
155 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
156 nameLsdb.end(), bind(nameLsaCompareByKey, _1, nlsa.getNameLsaKey()));
157
158 if( it == nameLsdb.end())
159 {
160 nameLsdb.push_back(nlsa);
161 return true;
162 }
163 return false;
164}
165
166bool
akmhoque1a481092014-02-19 16:34:22 -0600167Lsdb::removeNameLsa(Nlsr& pnlsr, string& key)
akmhoque298385a2014-02-13 14:13:09 -0600168{
169 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
170 nameLsdb.end(),
171 bind(nameLsaCompareByKey, _1, key));
172 if ( it != nameLsdb.end() )
173 {
174 if ( (*it).getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix() )
175 {
176 pnlsr.getNpt().removeNpte((*it).getOrigRouter(),(*it).getOrigRouter(),pnlsr);
177 for( std::list<string>::iterator nit=(*it).getNpl().getNameList().begin();
178 nit!=(*it).getNpl().getNameList().end(); ++nit)
179 {
180 if ( (*nit) !=pnlsr.getConfParameter().getRouterPrefix())
181 {
182 pnlsr.getNpt().removeNpte((*nit),(*it).getOrigRouter(),pnlsr);
183 }
184 }
185
186 }
187 nameLsdb.erase(it);
188 return true;
189 }
190 return false;
191}
192
193bool
194Lsdb::doesNameLsaExist(string key)
195{
196 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
197 nameLsdb.end(),
198 bind(nameLsaCompareByKey, _1, key));
199
200 if( it == nameLsdb.end()){
201 return false;
202 }
203
204 return true;
205}
206
207void
208Lsdb::printNameLsdb()
209{
210 cout<<"---------------Name LSDB-------------------"<<endl;
211 for( std::list<NameLsa>::iterator it=nameLsdb.begin();
212 it!= nameLsdb.end() ; it++)
213 {
214 cout<< (*it) <<endl;
215 }
216}
217
218// Cor LSA and LSDB related Functions start here
219
220
221static bool
222corLsaCompareByKey(CorLsa& clsa, string& key){
223 return clsa.getCorLsaKey()==key;
224}
225
226bool
akmhoque1a481092014-02-19 16:34:22 -0600227Lsdb::buildAndInstallOwnCorLsa(Nlsr& pnlsr){
akmhoque298385a2014-02-13 14:13:09 -0600228 CorLsa corLsa(pnlsr.getConfParameter().getRouterPrefix()
229 , 3
230 , pnlsr.getSm().getCorLsaSeq()+1
231 , pnlsr.getConfParameter().getRouterDeadInterval()
232 , pnlsr.getConfParameter().getCorR()
233 , pnlsr.getConfParameter().getCorTheta() );
234 pnlsr.getSm().setCorLsaSeq(pnlsr.getSm().getCorLsaSeq()+1);
235 installCorLsa(pnlsr, corLsa);
236
237 return true;
238}
239
240std::pair<CorLsa&, bool>
241Lsdb::getCorLsa(string key)
242{
243 std::list< CorLsa >::iterator it = std::find_if( corLsdb.begin(),
244 corLsdb.end(),
245 bind(corLsaCompareByKey, _1, key));
246
247 if( it != corLsdb.end()){
248 return std::make_pair(boost::ref((*it)), true);
249 }
250
251 CorLsa clsa;
252 return std::make_pair(boost::ref(clsa),false);
253}
254
akmhoque85d88332014-02-17 21:11:21 -0600255ndn::EventId
akmhoque1a481092014-02-19 16:34:22 -0600256Lsdb::scheduleCorLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime)
akmhoque298385a2014-02-13 14:13:09 -0600257{
akmhoque85d88332014-02-17 21:11:21 -0600258 return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
akmhoque298385a2014-02-13 14:13:09 -0600259 ndn::bind(&Lsdb::exprireOrRefreshCorLsa,
260 this,boost::ref(pnlsr),key,seqNo));
261}
262
263bool
akmhoque1a481092014-02-19 16:34:22 -0600264Lsdb::installCorLsa(Nlsr& pnlsr, CorLsa &clsa)
akmhoque298385a2014-02-13 14:13:09 -0600265{
266 int timeToExpire=lsaRefreshTime;
267 std::pair<CorLsa& , bool> chkCorLsa=getCorLsa(clsa.getCorLsaKey());
268 if ( !chkCorLsa.second )
269 {
270 addCorLsa(clsa);
271 printCorLsdb(); //debugging purpose
272 if ( clsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
273 {
274 pnlsr.getNpt().addNpte(clsa.getOrigRouter(),clsa.getOrigRouter(),pnlsr);
275 }
276 if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 )
277 {
278 pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
279 }
280
281 if(clsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
282 {
283 timeToExpire=clsa.getLifeTime();
284 }
285 scheduleCorLsaExpiration(pnlsr,clsa.getCorLsaKey(),
286 clsa.getLsSeqNo(), timeToExpire);
287
288 }
289 else
290 {
291 if ( chkCorLsa.first.getLsSeqNo() < clsa.getLsSeqNo() )
292 {
293 chkCorLsa.first.setLsSeqNo(clsa.getLsSeqNo());
294 chkCorLsa.first.setLifeTime(clsa.getLifeTime());
295 if ( !chkCorLsa.first.isLsaContentEqual(clsa) )
296 {
297 chkCorLsa.first.setCorRadius(clsa.getCorRadius());
298 chkCorLsa.first.setCorTheta(clsa.getCorTheta());
299
300 if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 )
301 {
302 pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
303 }
304
305 }
306
307 if(clsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
308 {
309 timeToExpire=clsa.getLifeTime();
310 }
akmhoque85d88332014-02-17 21:11:21 -0600311 cancelScheduleLsaExpiringEvent(pnlsr,
312 chkCorLsa.first.getLsaExpiringEventId());
313 chkCorLsa.first.setLsaExpiringEventId(scheduleCorLsaExpiration(pnlsr,
314 clsa.getCorLsaKey(),
315 clsa.getLsSeqNo(), timeToExpire));
akmhoque298385a2014-02-13 14:13:09 -0600316 }
317
318 }
319
320 return true;
321}
322
323bool
324Lsdb::addCorLsa(CorLsa& clsa)
325{
326 std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(),
327 corLsdb.end(),
328 bind(corLsaCompareByKey, _1, clsa.getCorLsaKey()));
329
330 if( it == corLsdb.end())
331 {
332 corLsdb.push_back(clsa);
333 return true;
334 }
335 return false;
336}
337
338bool
akmhoque1a481092014-02-19 16:34:22 -0600339Lsdb::removeCorLsa(Nlsr& pnlsr, string& key)
akmhoque298385a2014-02-13 14:13:09 -0600340{
341 std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(),
342 corLsdb.end(),
343 bind(corLsaCompareByKey, _1, key));
344 if ( it != corLsdb.end() )
345 {
346 if ( (*it).getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
347 {
348 pnlsr.getNpt().removeNpte((*it).getOrigRouter(),(*it).getOrigRouter(),pnlsr);
349 }
350 corLsdb.erase(it);
351 return true;
352 }
353 return false;
354
355}
356
357bool
358Lsdb::doesCorLsaExist(string key)
359{
360 std::list<CorLsa >::iterator it = std::find_if( corLsdb.begin(),
361 corLsdb.end(),
362 bind(corLsaCompareByKey, _1, key));
363
364 if( it == corLsdb.end()){
365 return false;
366 }
367
368 return true;
369}
370
371void
372Lsdb::printCorLsdb() //debugging
373{
374 cout<<"---------------Cor LSDB-------------------"<<endl;
375 for( std::list<CorLsa>::iterator it=corLsdb.begin();
376 it!= corLsdb.end() ; it++)
377 {
378 cout<< (*it) <<endl;
379 }
380}
381
382
383// Adj LSA and LSDB related function starts here
384
385static bool
386adjLsaCompareByKey(AdjLsa& alsa, string& key){
387 return alsa.getAdjLsaKey()==key;
388}
389
390
391void
akmhoque1a481092014-02-19 16:34:22 -0600392Lsdb::scheduledAdjLsaBuild(Nlsr& pnlsr)
akmhoque298385a2014-02-13 14:13:09 -0600393{
394 cout<<"scheduledAdjLsaBuild Called"<<endl;
395 pnlsr.setIsBuildAdjLsaSheduled(0);
396
397 if( pnlsr.getAdl().isAdjLsaBuildable(pnlsr))
398 {
399 int adjBuildCount=pnlsr.getAdjBuildCount();
400 if(adjBuildCount>0 )
401 {
402 if (pnlsr.getAdl().getNumOfActiveNeighbor()>0)
403 {
404 buildAndInstallOwnAdjLsa(pnlsr);
405 }
406 else
407 {
408 string key=pnlsr.getConfParameter().getRouterPrefix()+"/2";
409 removeAdjLsa(pnlsr,key);
410 pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
411 }
412 pnlsr.setAdjBuildCount(pnlsr.getAdjBuildCount()-adjBuildCount);
413 }
414 }
415 else
416 {
417 pnlsr.setIsBuildAdjLsaSheduled(1);
418 int schedulingTime=pnlsr.getConfParameter().getInterestRetryNumber()*
419 pnlsr.getConfParameter().getInterestResendTime();
420 pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime),
421 ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(),
422 boost::ref(pnlsr)));
423 }
424
425}
426
427
428bool
429Lsdb::addAdjLsa(AdjLsa &alsa)
430{
431 std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(),
432 adjLsdb.end(),
433 bind(adjLsaCompareByKey, _1, alsa.getAdjLsaKey()));
434
435 if( it == adjLsdb.end()){
436 adjLsdb.push_back(alsa);
437 return true;
438 }
439 return false;
440
441}
442
443std::pair<AdjLsa& , bool>
444Lsdb::getAdjLsa(string key)
445{
446 std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(),
447 adjLsdb.end(),
448 bind(adjLsaCompareByKey, _1, key));
449
450 if( it != adjLsdb.end()){
451 return std::make_pair(boost::ref((*it)),true);
452 }
453
454 AdjLsa alsa;
455 return std::make_pair(boost::ref(alsa),false);
456}
457
458
459
akmhoque85d88332014-02-17 21:11:21 -0600460ndn::EventId
akmhoque1a481092014-02-19 16:34:22 -0600461Lsdb::scheduleAdjLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime)
akmhoque298385a2014-02-13 14:13:09 -0600462{
akmhoque85d88332014-02-17 21:11:21 -0600463 return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
akmhoque298385a2014-02-13 14:13:09 -0600464 ndn::bind(&Lsdb::exprireOrRefreshAdjLsa,
465 this,boost::ref(pnlsr),key,seqNo));
466}
467
468bool
akmhoque1a481092014-02-19 16:34:22 -0600469Lsdb::installAdjLsa(Nlsr& pnlsr, AdjLsa &alsa)
akmhoque298385a2014-02-13 14:13:09 -0600470{
471 int timeToExpire=lsaRefreshTime;
472 std::pair<AdjLsa& , bool> chkAdjLsa=getAdjLsa(alsa.getAdjLsaKey());
473 if ( !chkAdjLsa.second )
474 {
475 addAdjLsa(alsa);
476 alsa.addNptEntriesForAdjLsa(pnlsr);
477 pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
478
479 if(alsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
480 {
481 timeToExpire=alsa.getLifeTime();
482 }
483 scheduleAdjLsaExpiration(pnlsr,alsa.getAdjLsaKey(),
484 alsa.getLsSeqNo(),timeToExpire);
485
486 }
487 else
488 {
489 if ( chkAdjLsa.first.getLsSeqNo() < alsa.getLsSeqNo() )
490 {
491 chkAdjLsa.first.setLsSeqNo(alsa.getLsSeqNo());
492 chkAdjLsa.first.setLifeTime(alsa.getLifeTime());
493
494 if ( ! chkAdjLsa.first.isLsaContentEqual(alsa))
495 {
496 chkAdjLsa.first.getAdl().resetAdl();
497 chkAdjLsa.first.getAdl().addAdjacentsFromAdl(alsa.getAdl());
498 pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
499 }
500
501 if(alsa.getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
502 {
503 timeToExpire=alsa.getLifeTime();
504 }
akmhoque85d88332014-02-17 21:11:21 -0600505 cancelScheduleLsaExpiringEvent(pnlsr,
506 chkAdjLsa.first.getLsaExpiringEventId());
507 chkAdjLsa.first.setLsaExpiringEventId(scheduleAdjLsaExpiration(pnlsr,
508 alsa.getAdjLsaKey(), alsa.getLsSeqNo(),timeToExpire));
akmhoque298385a2014-02-13 14:13:09 -0600509 }
510
511 }
512
513 printAdjLsdb();
514
515 return true;
516}
517
518bool
akmhoque1a481092014-02-19 16:34:22 -0600519Lsdb::buildAndInstallOwnAdjLsa(Nlsr& pnlsr)
akmhoque298385a2014-02-13 14:13:09 -0600520{
521 AdjLsa adjLsa(pnlsr.getConfParameter().getRouterPrefix()
522 , 2
523 , pnlsr.getSm().getAdjLsaSeq()+1
524 , pnlsr.getConfParameter().getRouterDeadInterval()
525 , pnlsr.getAdl().getNumOfActiveNeighbor()
526 , pnlsr.getAdl() );
527 pnlsr.getSm().setAdjLsaSeq(pnlsr.getSm().getAdjLsaSeq()+1);
528 return installAdjLsa(pnlsr, adjLsa);
529}
530
531bool
akmhoque1a481092014-02-19 16:34:22 -0600532Lsdb::removeAdjLsa(Nlsr& pnlsr, string& key)
akmhoque298385a2014-02-13 14:13:09 -0600533{
534 std::list<AdjLsa >::iterator it = std::find_if( adjLsdb.begin(),
535 adjLsdb.end(),
536 bind(adjLsaCompareByKey, _1, key));
537 if ( it != adjLsdb.end() )
538 {
539 (*it).removeNptEntriesForAdjLsa(pnlsr);
540 adjLsdb.erase(it);
541 return true;
542 }
543 return false;
544
545}
546
547bool
548Lsdb::doesAdjLsaExist(string key)
549{
550 std::list< AdjLsa >::iterator it = std::find_if( adjLsdb.begin(),
551 adjLsdb.end(),
552 bind(adjLsaCompareByKey, _1, key));
553
554 if( it == adjLsdb.end()){
555 return false;
556 }
557
558 return true;
559}
560
561std::list<AdjLsa>&
562Lsdb::getAdjLsdb()
563{
564 return adjLsdb;
565}
566
567void
568Lsdb::setLsaRefreshTime(int lrt)
569{
570 lsaRefreshTime=lrt;
571}
572
573void
574Lsdb::setThisRouterPrefix(string trp)
575{
576 thisRouterPrefix=trp;
577}
578
579void
akmhoque1a481092014-02-19 16:34:22 -0600580Lsdb::exprireOrRefreshNameLsa(Nlsr& pnlsr, string lsaKey, int seqNo)
akmhoque298385a2014-02-13 14:13:09 -0600581{
582 cout<<"Lsdb::exprireOrRefreshNameLsa Called "<<endl;
583 cout<<"LSA Key : "<<lsaKey<<" Seq No: "<<endl;
584 std::pair<NameLsa& , bool> chkNameLsa=getNameLsa(lsaKey);
585 if( chkNameLsa.second )
586 {
587 cout<<" LSA Exists with seq no: "<<chkNameLsa.first.getLsSeqNo()<<endl;
588 if ( chkNameLsa.first.getLsSeqNo() == seqNo )
589 {
590 if(chkNameLsa.first.getOrigRouter() == thisRouterPrefix )
591 {
592 cout<<"Own Name LSA, so refreshing name LSA"<<endl;
593 chkNameLsa.first.setLsSeqNo(chkNameLsa.first.getLsSeqNo()+1);
594 pnlsr.getSm().setNameLsaSeq(chkNameLsa.first.getLsSeqNo());
595 // publish routing update
596 }
597 else
598 {
599 cout<<"Other's Name LSA, so removing form LSDB"<<endl;
600 removeNameLsa(pnlsr, lsaKey);
601 }
602 }
603 }
604}
605
606void
akmhoque1a481092014-02-19 16:34:22 -0600607Lsdb::exprireOrRefreshAdjLsa(Nlsr& pnlsr, string lsaKey, int seqNo)
akmhoque298385a2014-02-13 14:13:09 -0600608{
609 cout<<"Lsdb::exprireOrRefreshAdjLsa Called "<<endl;
610 cout<<"LSA Key : "<<lsaKey<<" Seq No: "<<endl;
611 std::pair<AdjLsa& , bool> chkAdjLsa=getAdjLsa(lsaKey);
612 if( chkAdjLsa.second )
613 {
614 cout<<" LSA Exists with seq no: "<<chkAdjLsa.first.getLsSeqNo()<<endl;
615 if ( chkAdjLsa.first.getLsSeqNo() == seqNo )
616 {
617 if(chkAdjLsa.first.getOrigRouter() == thisRouterPrefix )
618 {
619 cout<<"Own Adj LSA, so refreshing Adj LSA"<<endl;
620 chkAdjLsa.first.setLsSeqNo(chkAdjLsa.first.getLsSeqNo()+1);
621 pnlsr.getSm().setAdjLsaSeq(chkAdjLsa.first.getLsSeqNo());
622 // publish routing update
623 }
624 else
625 {
626 cout<<"Other's Adj LSA, so removing form LSDB"<<endl;
627 removeAdjLsa(pnlsr, lsaKey);
628 }
629
630 // schedule Routing table calculaiton
631 pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
632 }
633 }
634}
635
636void
akmhoque1a481092014-02-19 16:34:22 -0600637Lsdb::exprireOrRefreshCorLsa(Nlsr& pnlsr, string lsaKey, int seqNo)
akmhoque298385a2014-02-13 14:13:09 -0600638{
639 cout<<"Lsdb::exprireOrRefreshCorLsa Called "<<endl;
640 cout<<"LSA Key : "<<lsaKey<<" Seq No: "<<endl;
641 std::pair<CorLsa& , bool> chkCorLsa=getCorLsa(lsaKey);
642 if( chkCorLsa.second )
643 {
644 cout<<" LSA Exists with seq no: "<<chkCorLsa.first.getLsSeqNo()<<endl;
645 if ( chkCorLsa.first.getLsSeqNo() == seqNo )
646 {
647 if(chkCorLsa.first.getOrigRouter() == thisRouterPrefix )
648 {
649 cout<<"Own Cor LSA, so refreshing Cor LSA"<<endl;
650 chkCorLsa.first.setLsSeqNo(chkCorLsa.first.getLsSeqNo()+1);
651 pnlsr.getSm().setCorLsaSeq(chkCorLsa.first.getLsSeqNo());
652 // publish routing update
653 }
654 else
655 {
656 cout<<"Other's Cor LSA, so removing form LSDB"<<endl;
657 removeCorLsa(pnlsr, lsaKey);
658 }
659
660 if (pnlsr.getConfParameter().getIsHyperbolicCalc() >=1 )
661 {
662 pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
663 }
664 }
665 }
666}
667
668
669void
670Lsdb::printAdjLsdb()
671{
672 cout<<"---------------Adj LSDB-------------------"<<endl;
673 for( std::list<AdjLsa>::iterator it=adjLsdb.begin();
674 it!= adjLsdb.end() ; it++)
675 {
676 cout<< (*it) <<endl;
677 }
678}
679
680//-----utility function -----
681bool
682Lsdb::doesLsaExist(string key, int lsType)
683{
684 if ( lsType == 1)
685 {
686 return doesNameLsaExist(key);
687 }
688 else if ( lsType == 2)
689 {
690 return doesAdjLsaExist(key);
691 }
692 else if ( lsType == 3)
693 {
694 return doesCorLsaExist(key);
695 }
696
697 return false;
698}
699
akmhoqueb1710aa2014-02-19 17:13:36 -0600700}//namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -0600701