blob: a82c8a34266c8ebb66fa4d92151434f3df778d07 [file] [log] [blame]
akmhoquebd7c8e62014-02-01 14:57:40 -06001#include<string>
2#include "nlsr_lsdb.hpp"
3#include "nlsr.hpp"
4
5using namespace std;
6
7
8
9
10
11bool
12Lsdb::doesLsaExist(string key, int lsType)
13{
14 if ( lsType == 1)
15 {
16 return doesNameLsaExist(key);
17 }
18 else if ( lsType == 2)
19 {
20 return doesAdjLsaExist(key);
21 }
22 else if ( lsType == 3)
23 {
24 return doesCorLsaExist(key);
25 }
26
27 return false;
28
29}
30
31static bool
32nameLsaCompare(NameLsa& nlsa1, NameLsa& nlsa2){
33 return nlsa1.getLsaKey()==nlsa1.getLsaKey();
34}
35
36static bool
37nameLsaCompareByKey(NameLsa& nlsa1, string& key){
38 return nlsa1.getLsaKey()==key;
39}
40
41
42bool
43Lsdb::buildAndInstallOwnNameLsa(nlsr& pnlsr)
44{
45 NameLsa nameLsa(pnlsr.getConfParameter().getRouterPrefix()
46 , 1
47 , pnlsr.getNameLsaSeq()+1
48 , pnlsr.getConfParameter().getRouterDeadInterval()
49 , pnlsr.getNpl() );
50 pnlsr.setNameLsaSeq(pnlsr.getNameLsaSeq()+1);
51 cout<<nameLsa;
52 return installNameLsa(nameLsa);
53
54}
55
56NameLsa&
57Lsdb::getNameLsa(string key)
58{
59 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
60 nameLsdb.end(),
61 bind(nameLsaCompareByKey, _1, key));
62
63 if( it != nameLsdb.end()){
64 return (*it);
65 }
66}
67
68
69
70bool
71Lsdb::installNameLsa(NameLsa &nlsa)
72{
73 bool doesLsaExist_ = doesNameLsaExist(nlsa.getLsaKey());
74 if ( !doesLsaExist_ )
75 {
76 // add name LSA
77 addNameLsa(nlsa);
78 // update NPT and FIB
79 }
80 else
81 {
82 // check for newer name LSA
83 NameLsa oldNameLsa=getNameLsa(nlsa.getLsaKey());
84 // Discard or Update Name lsa, NPT, FIB
85 }
86
87 return true;
88}
89
90bool
91Lsdb::addNameLsa(NameLsa &nlsa)
92{
93 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
94 nameLsdb.end(),
95 bind(nameLsaCompare, _1, nlsa));
96
97 if( it == nameLsdb.end()){
98 nameLsdb.push_back(nlsa);
99 return true;
100 }
101 return false;
102}
103
104bool
105Lsdb::removeNameLsa(string& key)
106{
107 return false;
108}
109
110void
111Lsdb::printNameLsdb()
112{
113 for( std::list<NameLsa>::iterator it=nameLsdb.begin();
114 it!= nameLsdb.end() ; it++)
115 {
116 cout<< (*it) <<endl;
117 }
118}
119
120bool
121Lsdb::doesNameLsaExist(string key)
122{
123 std::list<NameLsa >::iterator it = std::find_if( nameLsdb.begin(),
124 nameLsdb.end(),
125 bind(nameLsaCompareByKey, _1, key));
126
127 if( it == nameLsdb.end()){
128 return false;
129 }
130
131 return true;
132}
133
134
135bool
136Lsdb::doesAdjLsaExist(string key)
137{
138 return false;
139}
140
141bool
142Lsdb::doesCorLsaExist(string key)
143{
144 return false;
145}