blob: 0cbdb4a239b411d59d07d8927a7190f18eeec26d [file] [log] [blame]
akmhoque87347a32014-01-31 11:00:44 -06001#include<iostream>
2#include<algorithm>
3
akmhoque204e7542014-01-31 16:08:25 -06004#include "nlsr_adl.hpp"
5#include "nlsr_adjacent.hpp"
akmhoque87347a32014-01-31 11:00:44 -06006
7Adl::Adl(){
8}
9
10Adl::~Adl(){
11
12}
13
14static bool
15adjacent_compare(Adjacent& adj1, Adjacent& adj2){
16 return adj1.getAdjacentName()==adj2.getAdjacentName();
17}
18
19int
20Adl::insert(Adjacent& adj){
21 std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
22 adjList.end(),
23 bind(&adjacent_compare, _1, adj));
24 if ( it != adjList.end() ){
25 return -1;
26 }
27 adjList.push_back(adj);
28 return 0;
29}
30int
31Adl::updateAdjacentStatus(string adjName, int s){
32 Adjacent adj(adjName);
33
34 std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
35 adjList.end(),
36 bind(&adjacent_compare, _1, adj));
37
38 if( it == adjList.end()){
39 return -1;
40 }
41
42 (*it).setStatus(s);
43 return 0;
44
45
46}
47
48int
49Adl::updateAdjacentLinkCost(string adjName, double lc){
50 Adjacent adj(adjName);
51
52 std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
53 adjList.end(),
54 bind(&adjacent_compare, _1, adj));
55
56 if( it == adjList.end()){
57 return -1;
58 }
59
60 (*it).setLinkCost(lc);
61 return 0;
62
63}
64
akmhoquea8cd6b92014-01-31 20:13:26 -060065bool
66Adl::isNeighbor(string adjName){
67 Adjacent adj(adjName);
68 std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
69 adjList.end(),
70 bind(&adjacent_compare, _1, adj));
71
72 if( it == adjList.end()){
73 return false;
74 }
75
76 return true;
77}
78
79void
80Adl::incrementTimedOutInterestCount(string& neighbor){
81 Adjacent adj(neighbor);
82 std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
83 adjList.end(),
84 bind(&adjacent_compare, _1, adj));
85
86 if( it == adjList.end()){
87 return ;
88 }
89
90 (*it).setInterestTimedOutNo((*it).getInterestTimedOutNo()+1);
91
92}
93
94void
95Adl::setTimedOutInterestCount(string& neighbor, int count){
96 Adjacent adj(neighbor);
97 std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
98 adjList.end(),
99 bind(&adjacent_compare, _1, adj));
100
101 if( it != adjList.end()){
102 (*it).setInterestTimedOutNo(count);
103 }
104}
105
106int
107Adl::getTimedOutInterestCount(string& neighbor)
108{
109 Adjacent adj(neighbor);
110 std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
111 adjList.end(),
112 bind(&adjacent_compare, _1, adj));
113
114 if( it == adjList.end()){
115 return -1;
116 }
117
118 return (*it).getInterestTimedOutNo();
119}
120
121int
122Adl::getStatusOfNeighbor(string& neighbor)
123{
124 Adjacent adj(neighbor);
125 std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
126 adjList.end(),
127 bind(&adjacent_compare, _1, adj));
128
129 if( it == adjList.end()){
130 return -1;
131 }
132
133 return (*it).getStatus();
134}
135
136void
137Adl::setStatusOfNeighbor(string& neighbor, int status)
138{
139 Adjacent adj(neighbor);
140 std::list<Adjacent >::iterator it = std::find_if( adjList.begin(),
141 adjList.end(),
142 bind(&adjacent_compare, _1, adj));
143
144 if( it != adjList.end()){
145 (*it).setStatus(status);
146 }
147}
148
akmhoque87347a32014-01-31 11:00:44 -0600149std::list<Adjacent>
150Adl::getAdjList(){
151 return adjList;
152}
153
154// used for debugging purpose
155void
156Adl::printAdl(){
157 for( std::list<Adjacent>::iterator it=adjList.begin(); it!= adjList.end() ; it++){
158 cout<< (*it) <<endl;
159 }
160}