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