|
gjc@1716
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
|
gjc@1752
|
2 |
/*
|
|
gjc@1752
|
3 |
* Copyright (c) 2004 Francisco J. Ros
|
|
gjc@1752
|
4 |
* Copyright (c) 2007 INESC Porto
|
|
gjc@1752
|
5 |
*
|
|
gjc@1752
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
gjc@1752
|
7 |
* it under the terms of the GNU General Public License version 2 as
|
|
gjc@1752
|
8 |
* published by the Free Software Foundation;
|
|
gjc@1752
|
9 |
*
|
|
gjc@1752
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
gjc@1752
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
gjc@1752
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
gjc@1752
|
13 |
* GNU General Public License for more details.
|
|
gjc@1752
|
14 |
*
|
|
gjc@1752
|
15 |
* You should have received a copy of the GNU General Public License
|
|
gjc@1752
|
16 |
* along with this program; if not, write to the Free Software
|
|
gjc@1752
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
gjc@1752
|
18 |
*
|
|
gjc@1752
|
19 |
* Authors: Francisco J. Ros <fjrm@dif.um.es>
|
|
gjc@1752
|
20 |
* Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
|
|
gjc@1752
|
21 |
*/
|
|
gjc@1716
|
22 |
|
|
gjc@1716
|
23 |
///
|
|
gjc@1716
|
24 |
/// \file OlsrState.cc
|
|
gjc@1716
|
25 |
/// \brief Implementation of all functions needed for manipulating the internal
|
|
gjc@1716
|
26 |
/// state of an OLSR node.
|
|
gjc@1716
|
27 |
///
|
|
gjc@1716
|
28 |
|
|
gjc@1716
|
29 |
#include "olsr-state.h"
|
|
gjc@1716
|
30 |
|
|
gjc@1716
|
31 |
|
|
gjc@1731
|
32 |
namespace ns3 {
|
|
gjc@1716
|
33 |
|
|
gjc@1716
|
34 |
|
|
gjc@1716
|
35 |
/********** MPR Selector Set Manipulation **********/
|
|
gjc@1716
|
36 |
|
|
gjc@1716
|
37 |
MprSelectorTuple*
|
|
gjc@1716
|
38 |
OlsrState::FindMprSelectorTuple (Ipv4Address const &mainAddr)
|
|
gjc@1716
|
39 |
{
|
|
gjc@1716
|
40 |
for (MprSelectorSet::iterator it = m_mprSelectorSet.begin ();
|
|
gjc@1716
|
41 |
it != m_mprSelectorSet.end (); it++)
|
|
gjc@1716
|
42 |
{
|
|
gjc@1716
|
43 |
if (it->mainAddr == mainAddr)
|
|
gjc@1716
|
44 |
return &(*it);
|
|
gjc@1716
|
45 |
}
|
|
gjc@1716
|
46 |
return NULL;
|
|
gjc@1716
|
47 |
}
|
|
gjc@1716
|
48 |
|
|
gjc@1716
|
49 |
void
|
|
gjc@1716
|
50 |
OlsrState::EraseMprSelectorTuple (const MprSelectorTuple &tuple)
|
|
gjc@1716
|
51 |
{
|
|
gjc@1716
|
52 |
for (MprSelectorSet::iterator it = m_mprSelectorSet.begin ();
|
|
gjc@1716
|
53 |
it != m_mprSelectorSet.end (); it++)
|
|
gjc@1716
|
54 |
{
|
|
gjc@1716
|
55 |
if (*it == tuple)
|
|
gjc@1716
|
56 |
{
|
|
gjc@1716
|
57 |
m_mprSelectorSet.erase (it);
|
|
gjc@1716
|
58 |
break;
|
|
gjc@1716
|
59 |
}
|
|
gjc@1716
|
60 |
}
|
|
gjc@1716
|
61 |
}
|
|
gjc@1716
|
62 |
|
|
gjc@1716
|
63 |
void
|
|
gjc@1716
|
64 |
OlsrState::EraseMprSelectorTuples (const Ipv4Address &mainAddr)
|
|
gjc@1716
|
65 |
{
|
|
gjc@1716
|
66 |
for (MprSelectorSet::iterator it = m_mprSelectorSet.begin ();
|
|
gjc@2916
|
67 |
it != m_mprSelectorSet.end ();)
|
|
gjc@1716
|
68 |
{
|
|
gjc@1716
|
69 |
if (it->mainAddr == mainAddr)
|
|
gjc@1716
|
70 |
{
|
|
gjc@1716
|
71 |
it = m_mprSelectorSet.erase (it);
|
|
gjc@2916
|
72 |
}
|
|
gjc@2916
|
73 |
else
|
|
gjc@2916
|
74 |
{
|
|
gjc@2916
|
75 |
it++;
|
|
gjc@1716
|
76 |
}
|
|
gjc@1716
|
77 |
}
|
|
gjc@1716
|
78 |
}
|
|
gjc@1716
|
79 |
|
|
gjc@1716
|
80 |
void
|
|
gjc@1716
|
81 |
OlsrState::InsertMprSelectorTuple (MprSelectorTuple const &tuple)
|
|
gjc@1716
|
82 |
{
|
|
gjc@1716
|
83 |
m_mprSelectorSet.push_back (tuple);
|
|
gjc@1716
|
84 |
}
|
|
gjc@1716
|
85 |
|
|
gjc@3970
|
86 |
std::string
|
|
gjc@3970
|
87 |
OlsrState::PrintMprSelectorSet () const
|
|
gjc@3970
|
88 |
{
|
|
gjc@3970
|
89 |
std::ostringstream os;
|
|
gjc@3970
|
90 |
os << "[";
|
|
gjc@3970
|
91 |
for (MprSelectorSet::const_iterator iter = m_mprSelectorSet.begin ();
|
|
gjc@3970
|
92 |
iter != m_mprSelectorSet.end (); iter++)
|
|
gjc@3970
|
93 |
{
|
|
gjc@3970
|
94 |
MprSelectorSet::const_iterator next = iter;
|
|
gjc@3970
|
95 |
next++;
|
|
gjc@3970
|
96 |
os << iter->mainAddr;
|
|
gjc@3970
|
97 |
if (next != m_mprSelectorSet.end ())
|
|
gjc@3970
|
98 |
os << ", ";
|
|
gjc@3970
|
99 |
}
|
|
gjc@3970
|
100 |
os << "]";
|
|
gjc@3970
|
101 |
return os.str ();
|
|
gjc@3970
|
102 |
}
|
|
gjc@3970
|
103 |
|
|
gjc@3970
|
104 |
|
|
gjc@1716
|
105 |
/********** Neighbor Set Manipulation **********/
|
|
gjc@1716
|
106 |
|
|
gjc@1716
|
107 |
NeighborTuple*
|
|
gjc@1716
|
108 |
OlsrState::FindNeighborTuple (Ipv4Address const &mainAddr)
|
|
gjc@1716
|
109 |
{
|
|
gjc@1716
|
110 |
for (NeighborSet::iterator it = m_neighborSet.begin ();
|
|
gjc@1716
|
111 |
it != m_neighborSet.end (); it++)
|
|
gjc@1716
|
112 |
{
|
|
gjc@1716
|
113 |
if (it->neighborMainAddr == mainAddr)
|
|
gjc@1716
|
114 |
return &(*it);
|
|
gjc@1716
|
115 |
}
|
|
gjc@1716
|
116 |
return NULL;
|
|
gjc@1716
|
117 |
}
|
|
gjc@1716
|
118 |
|
|
gjc@1799
|
119 |
const NeighborTuple*
|
|
gjc@1799
|
120 |
OlsrState::FindSymNeighborTuple (Ipv4Address const &mainAddr) const
|
|
gjc@1716
|
121 |
{
|
|
gjc@1799
|
122 |
for (NeighborSet::const_iterator it = m_neighborSet.begin ();
|
|
gjc@1716
|
123 |
it != m_neighborSet.end (); it++)
|
|
gjc@1716
|
124 |
{
|
|
gjc@1716
|
125 |
if (it->neighborMainAddr == mainAddr && it->status == NeighborTuple::STATUS_SYM)
|
|
gjc@1716
|
126 |
return &(*it);
|
|
gjc@1716
|
127 |
}
|
|
gjc@1716
|
128 |
return NULL;
|
|
gjc@1716
|
129 |
}
|
|
gjc@1716
|
130 |
|
|
gjc@1716
|
131 |
NeighborTuple*
|
|
gjc@1716
|
132 |
OlsrState::FindNeighborTuple (Ipv4Address const &mainAddr, uint8_t willingness)
|
|
gjc@1716
|
133 |
{
|
|
gjc@1716
|
134 |
for (NeighborSet::iterator it = m_neighborSet.begin ();
|
|
gjc@1716
|
135 |
it != m_neighborSet.end (); it++)
|
|
gjc@1716
|
136 |
{
|
|
gjc@1716
|
137 |
if (it->neighborMainAddr == mainAddr && it->willingness == willingness)
|
|
gjc@1716
|
138 |
return &(*it);
|
|
gjc@1716
|
139 |
}
|
|
gjc@1716
|
140 |
return NULL;
|
|
gjc@1716
|
141 |
}
|
|
gjc@1716
|
142 |
|
|
gjc@1716
|
143 |
void
|
|
gjc@1716
|
144 |
OlsrState::EraseNeighborTuple (const NeighborTuple &tuple)
|
|
gjc@1716
|
145 |
{
|
|
gjc@1716
|
146 |
for (NeighborSet::iterator it = m_neighborSet.begin ();
|
|
gjc@1716
|
147 |
it != m_neighborSet.end (); it++)
|
|
gjc@1716
|
148 |
{
|
|
gjc@1716
|
149 |
if (*it == tuple)
|
|
gjc@1716
|
150 |
{
|
|
gjc@1716
|
151 |
m_neighborSet.erase (it);
|
|
gjc@1716
|
152 |
break;
|
|
gjc@1716
|
153 |
}
|
|
gjc@1716
|
154 |
}
|
|
gjc@1716
|
155 |
}
|
|
gjc@1716
|
156 |
|
|
gjc@1716
|
157 |
void
|
|
gjc@1716
|
158 |
OlsrState::EraseNeighborTuple (const Ipv4Address &mainAddr)
|
|
gjc@1716
|
159 |
{
|
|
gjc@1716
|
160 |
for (NeighborSet::iterator it = m_neighborSet.begin ();
|
|
gjc@1716
|
161 |
it != m_neighborSet.end (); it++)
|
|
gjc@1716
|
162 |
{
|
|
gjc@1716
|
163 |
if (it->neighborMainAddr == mainAddr)
|
|
gjc@1716
|
164 |
{
|
|
gjc@1716
|
165 |
it = m_neighborSet.erase (it);
|
|
gjc@1716
|
166 |
break;
|
|
gjc@1716
|
167 |
}
|
|
gjc@1716
|
168 |
}
|
|
gjc@1716
|
169 |
}
|
|
gjc@1716
|
170 |
|
|
gjc@1716
|
171 |
void
|
|
gjc@1716
|
172 |
OlsrState::InsertNeighborTuple (NeighborTuple const &tuple)
|
|
gjc@1716
|
173 |
{
|
|
gjc@2328
|
174 |
for (NeighborSet::iterator it = m_neighborSet.begin ();
|
|
gjc@2328
|
175 |
it != m_neighborSet.end (); it++)
|
|
gjc@2328
|
176 |
{
|
|
gjc@2328
|
177 |
if (it->neighborMainAddr == tuple.neighborMainAddr)
|
|
gjc@2328
|
178 |
{
|
|
gjc@2328
|
179 |
// Update it
|
|
gjc@2328
|
180 |
*it = tuple;
|
|
gjc@2328
|
181 |
return;
|
|
gjc@2328
|
182 |
}
|
|
gjc@2328
|
183 |
}
|
|
gjc@1716
|
184 |
m_neighborSet.push_back (tuple);
|
|
gjc@1716
|
185 |
}
|
|
gjc@1716
|
186 |
|
|
gjc@1716
|
187 |
/********** Neighbor 2 Hop Set Manipulation **********/
|
|
gjc@1716
|
188 |
|
|
gjc@1716
|
189 |
TwoHopNeighborTuple*
|
|
gjc@1716
|
190 |
OlsrState::FindTwoHopNeighborTuple (Ipv4Address const &neighborMainAddr,
|
|
gjc@1716
|
191 |
Ipv4Address const &twoHopNeighborAddr)
|
|
gjc@1716
|
192 |
{
|
|
gjc@1716
|
193 |
for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
|
|
gjc@1716
|
194 |
it != m_twoHopNeighborSet.end (); it++)
|
|
gjc@1716
|
195 |
{
|
|
gjc@1716
|
196 |
if (it->neighborMainAddr == neighborMainAddr
|
|
gjc@1716
|
197 |
&& it->twoHopNeighborAddr == twoHopNeighborAddr)
|
|
gjc@1716
|
198 |
{
|
|
gjc@1716
|
199 |
return &(*it);
|
|
gjc@1716
|
200 |
}
|
|
gjc@1716
|
201 |
}
|
|
gjc@1716
|
202 |
return NULL;
|
|
gjc@1716
|
203 |
}
|
|
gjc@1716
|
204 |
|
|
gjc@1716
|
205 |
void
|
|
gjc@1716
|
206 |
OlsrState::EraseTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple)
|
|
gjc@1716
|
207 |
{
|
|
gjc@1716
|
208 |
for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
|
|
gjc@1716
|
209 |
it != m_twoHopNeighborSet.end (); it++)
|
|
gjc@1716
|
210 |
{
|
|
gjc@1716
|
211 |
if (*it == tuple)
|
|
gjc@1716
|
212 |
{
|
|
gjc@1716
|
213 |
m_twoHopNeighborSet.erase(it);
|
|
gjc@1716
|
214 |
break;
|
|
gjc@1716
|
215 |
}
|
|
gjc@1716
|
216 |
}
|
|
gjc@1716
|
217 |
}
|
|
gjc@1716
|
218 |
|
|
gjc@1716
|
219 |
void
|
|
gjc@1716
|
220 |
OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr,
|
|
gjc@1716
|
221 |
const Ipv4Address &twoHopNeighborAddr)
|
|
gjc@1716
|
222 |
{
|
|
gjc@1716
|
223 |
for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
|
|
gjc@2916
|
224 |
it != m_twoHopNeighborSet.end ();)
|
|
gjc@1716
|
225 |
{
|
|
gjc@1716
|
226 |
if (it->neighborMainAddr == neighborMainAddr
|
|
gjc@1716
|
227 |
&& it->twoHopNeighborAddr == twoHopNeighborAddr)
|
|
gjc@1716
|
228 |
{
|
|
gjc@1716
|
229 |
it = m_twoHopNeighborSet.erase (it);
|
|
gjc@1716
|
230 |
}
|
|
gjc@2916
|
231 |
else
|
|
gjc@2916
|
232 |
{
|
|
gjc@2916
|
233 |
it++;
|
|
gjc@2916
|
234 |
}
|
|
gjc@1716
|
235 |
}
|
|
gjc@1716
|
236 |
}
|
|
gjc@1716
|
237 |
|
|
gjc@1716
|
238 |
void
|
|
gjc@1716
|
239 |
OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr)
|
|
gjc@1716
|
240 |
{
|
|
gjc@1716
|
241 |
for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
|
|
gjc@2916
|
242 |
it != m_twoHopNeighborSet.end ();)
|
|
gjc@1716
|
243 |
{
|
|
gjc@2916
|
244 |
if (it->neighborMainAddr == neighborMainAddr)
|
|
gjc@2916
|
245 |
{
|
|
gjc@2916
|
246 |
it = m_twoHopNeighborSet.erase (it);
|
|
gjc@2916
|
247 |
}
|
|
gjc@2916
|
248 |
else
|
|
gjc@2916
|
249 |
{
|
|
gjc@2916
|
250 |
it++;
|
|
gjc@2916
|
251 |
}
|
|
gjc@1716
|
252 |
}
|
|
gjc@1716
|
253 |
}
|
|
gjc@1716
|
254 |
|
|
gjc@1716
|
255 |
void
|
|
gjc@2359
|
256 |
OlsrState::InsertTwoHopNeighborTuple (TwoHopNeighborTuple const &tuple)
|
|
gjc@2359
|
257 |
{
|
|
gjc@1716
|
258 |
m_twoHopNeighborSet.push_back (tuple);
|
|
gjc@1716
|
259 |
}
|
|
gjc@1716
|
260 |
|
|
gjc@1716
|
261 |
/********** MPR Set Manipulation **********/
|
|
gjc@1716
|
262 |
|
|
gjc@1716
|
263 |
bool
|
|
gjc@1716
|
264 |
OlsrState::FindMprAddress (Ipv4Address const &addr)
|
|
gjc@1716
|
265 |
{
|
|
gjc@1716
|
266 |
MprSet::iterator it = m_mprSet.find (addr);
|
|
gjc@1716
|
267 |
return (it != m_mprSet.end ());
|
|
gjc@1716
|
268 |
}
|
|
gjc@1716
|
269 |
|
|
gjc@1716
|
270 |
void
|
|
gjc@2361
|
271 |
OlsrState::SetMprSet (MprSet mprSet)
|
|
gjc@1716
|
272 |
{
|
|
gjc@2361
|
273 |
m_mprSet = mprSet;
|
|
gjc@1716
|
274 |
}
|
|
gjc@1716
|
275 |
|
|
gjc@1716
|
276 |
/********** Duplicate Set Manipulation **********/
|
|
gjc@1716
|
277 |
|
|
gjc@1716
|
278 |
DuplicateTuple*
|
|
gjc@1716
|
279 |
OlsrState::FindDuplicateTuple (Ipv4Address const &addr, uint16_t sequenceNumber)
|
|
gjc@1716
|
280 |
{
|
|
gjc@1716
|
281 |
for (DuplicateSet::iterator it = m_duplicateSet.begin ();
|
|
gjc@1716
|
282 |
it != m_duplicateSet.end(); it++)
|
|
gjc@1716
|
283 |
{
|
|
gjc@1716
|
284 |
if (it->address == addr && it->sequenceNumber == sequenceNumber)
|
|
gjc@1716
|
285 |
return &(*it);
|
|
gjc@1716
|
286 |
}
|
|
gjc@1716
|
287 |
return NULL;
|
|
gjc@1716
|
288 |
}
|
|
gjc@1716
|
289 |
|
|
gjc@1716
|
290 |
void
|
|
gjc@1716
|
291 |
OlsrState::EraseDuplicateTuple (const DuplicateTuple &tuple)
|
|
gjc@1716
|
292 |
{
|
|
gjc@1716
|
293 |
for (DuplicateSet::iterator it = m_duplicateSet.begin ();
|
|
gjc@1716
|
294 |
it != m_duplicateSet.end (); it++)
|
|
gjc@1716
|
295 |
{
|
|
gjc@1716
|
296 |
if (*it == tuple)
|
|
gjc@1716
|
297 |
{
|
|
gjc@1716
|
298 |
m_duplicateSet.erase (it);
|
|
gjc@1716
|
299 |
break;
|
|
gjc@1716
|
300 |
}
|
|
gjc@1716
|
301 |
}
|
|
gjc@1716
|
302 |
}
|
|
gjc@1716
|
303 |
|
|
gjc@1716
|
304 |
void
|
|
gjc@1716
|
305 |
OlsrState::InsertDuplicateTuple (DuplicateTuple const &tuple)
|
|
gjc@1716
|
306 |
{
|
|
gjc@1716
|
307 |
m_duplicateSet.push_back (tuple);
|
|
gjc@1716
|
308 |
}
|
|
gjc@1716
|
309 |
|
|
gjc@1716
|
310 |
/********** Link Set Manipulation **********/
|
|
gjc@1716
|
311 |
|
|
gjc@1716
|
312 |
LinkTuple*
|
|
gjc@1716
|
313 |
OlsrState::FindLinkTuple (Ipv4Address const & ifaceAddr)
|
|
gjc@1716
|
314 |
{
|
|
gjc@1716
|
315 |
for (LinkSet::iterator it = m_linkSet.begin ();
|
|
gjc@1716
|
316 |
it != m_linkSet.end (); it++)
|
|
gjc@1716
|
317 |
{
|
|
gjc@1716
|
318 |
if (it->neighborIfaceAddr == ifaceAddr)
|
|
gjc@1716
|
319 |
return &(*it);
|
|
gjc@1716
|
320 |
}
|
|
gjc@1716
|
321 |
return NULL;
|
|
gjc@1716
|
322 |
}
|
|
gjc@1716
|
323 |
|
|
gjc@1716
|
324 |
LinkTuple*
|
|
gjc@1716
|
325 |
OlsrState::FindSymLinkTuple (Ipv4Address const &ifaceAddr, Time now)
|
|
gjc@1716
|
326 |
{
|
|
gjc@1716
|
327 |
for (LinkSet::iterator it = m_linkSet.begin ();
|
|
gjc@1716
|
328 |
it != m_linkSet.end (); it++)
|
|
gjc@1716
|
329 |
{
|
|
gjc@1716
|
330 |
if (it->neighborIfaceAddr == ifaceAddr)
|
|
gjc@1716
|
331 |
{
|
|
gjc@1716
|
332 |
if (it->symTime > now)
|
|
gjc@1716
|
333 |
return &(*it);
|
|
gjc@1716
|
334 |
else
|
|
gjc@1716
|
335 |
break;
|
|
gjc@1716
|
336 |
}
|
|
gjc@1716
|
337 |
}
|
|
gjc@1716
|
338 |
return NULL;
|
|
gjc@1716
|
339 |
}
|
|
gjc@1716
|
340 |
|
|
gjc@1716
|
341 |
void
|
|
gjc@1716
|
342 |
OlsrState::EraseLinkTuple (const LinkTuple &tuple)
|
|
gjc@1716
|
343 |
{
|
|
gjc@1716
|
344 |
for (LinkSet::iterator it = m_linkSet.begin ();
|
|
gjc@1716
|
345 |
it != m_linkSet.end (); it++)
|
|
gjc@1716
|
346 |
{
|
|
gjc@1716
|
347 |
if (*it == tuple)
|
|
gjc@1716
|
348 |
{
|
|
gjc@1716
|
349 |
m_linkSet.erase (it);
|
|
gjc@1716
|
350 |
break;
|
|
gjc@1716
|
351 |
}
|
|
gjc@1716
|
352 |
}
|
|
gjc@1716
|
353 |
}
|
|
gjc@1716
|
354 |
|
|
gjc@1716
|
355 |
LinkTuple&
|
|
gjc@1716
|
356 |
OlsrState::InsertLinkTuple (LinkTuple const &tuple)
|
|
gjc@1716
|
357 |
{
|
|
gjc@1716
|
358 |
m_linkSet.push_back (tuple);
|
|
gjc@1716
|
359 |
return m_linkSet.back ();
|
|
gjc@1716
|
360 |
}
|
|
gjc@1716
|
361 |
|
|
gjc@1716
|
362 |
/********** Topology Set Manipulation **********/
|
|
gjc@1716
|
363 |
|
|
gjc@1716
|
364 |
TopologyTuple*
|
|
gjc@1716
|
365 |
OlsrState::FindTopologyTuple (Ipv4Address const &destAddr,
|
|
gjc@1716
|
366 |
Ipv4Address const &lastAddr)
|
|
gjc@1716
|
367 |
{
|
|
gjc@1716
|
368 |
for (TopologySet::iterator it = m_topologySet.begin ();
|
|
gjc@1716
|
369 |
it != m_topologySet.end (); it++)
|
|
gjc@1716
|
370 |
{
|
|
gjc@1716
|
371 |
if (it->destAddr == destAddr && it->lastAddr == lastAddr)
|
|
gjc@1716
|
372 |
return &(*it);
|
|
gjc@1716
|
373 |
}
|
|
gjc@1716
|
374 |
return NULL;
|
|
gjc@1716
|
375 |
}
|
|
gjc@1716
|
376 |
|
|
gjc@1716
|
377 |
TopologyTuple*
|
|
gjc@1716
|
378 |
OlsrState::FindNewerTopologyTuple (Ipv4Address const & lastAddr, uint16_t ansn)
|
|
gjc@1716
|
379 |
{
|
|
gjc@1716
|
380 |
for (TopologySet::iterator it = m_topologySet.begin ();
|
|
gjc@1716
|
381 |
it != m_topologySet.end (); it++)
|
|
gjc@1716
|
382 |
{
|
|
gjc@1716
|
383 |
if (it->lastAddr == lastAddr && it->sequenceNumber > ansn)
|
|
gjc@1716
|
384 |
return &(*it);
|
|
gjc@1716
|
385 |
}
|
|
gjc@1716
|
386 |
return NULL;
|
|
gjc@1716
|
387 |
}
|
|
gjc@1716
|
388 |
|
|
gjc@1716
|
389 |
void
|
|
gjc@1716
|
390 |
OlsrState::EraseTopologyTuple(const TopologyTuple &tuple)
|
|
gjc@1716
|
391 |
{
|
|
gjc@1716
|
392 |
for (TopologySet::iterator it = m_topologySet.begin ();
|
|
gjc@1716
|
393 |
it != m_topologySet.end (); it++)
|
|
gjc@1716
|
394 |
{
|
|
gjc@1716
|
395 |
if (*it == tuple)
|
|
gjc@1716
|
396 |
{
|
|
gjc@1716
|
397 |
m_topologySet.erase (it);
|
|
gjc@1716
|
398 |
break;
|
|
gjc@1716
|
399 |
}
|
|
gjc@1716
|
400 |
}
|
|
gjc@1716
|
401 |
}
|
|
gjc@1716
|
402 |
|
|
gjc@1716
|
403 |
void
|
|
gjc@1716
|
404 |
OlsrState::EraseOlderTopologyTuples (const Ipv4Address &lastAddr, uint16_t ansn)
|
|
gjc@1716
|
405 |
{
|
|
gjc@1716
|
406 |
for (TopologySet::iterator it = m_topologySet.begin();
|
|
gjc@2916
|
407 |
it != m_topologySet.end();)
|
|
gjc@1716
|
408 |
{
|
|
gjc@1716
|
409 |
if (it->lastAddr == lastAddr && it->sequenceNumber < ansn)
|
|
gjc@1716
|
410 |
{
|
|
gjc@1716
|
411 |
it = m_topologySet.erase (it);
|
|
gjc@1716
|
412 |
}
|
|
gjc@2916
|
413 |
else
|
|
gjc@2916
|
414 |
{
|
|
gjc@2916
|
415 |
it++;
|
|
gjc@2916
|
416 |
}
|
|
gjc@1716
|
417 |
}
|
|
gjc@1716
|
418 |
}
|
|
gjc@1716
|
419 |
|
|
gjc@1716
|
420 |
void
|
|
gjc@1716
|
421 |
OlsrState::InsertTopologyTuple (TopologyTuple const &tuple)
|
|
gjc@1716
|
422 |
{
|
|
gjc@1716
|
423 |
m_topologySet.push_back (tuple);
|
|
gjc@1716
|
424 |
}
|
|
gjc@1716
|
425 |
|
|
gjc@1716
|
426 |
/********** Interface Association Set Manipulation **********/
|
|
gjc@1716
|
427 |
|
|
gjc@1716
|
428 |
IfaceAssocTuple*
|
|
gjc@1716
|
429 |
OlsrState::FindIfaceAssocTuple (Ipv4Address const &ifaceAddr)
|
|
gjc@1716
|
430 |
{
|
|
gjc@1716
|
431 |
for (IfaceAssocSet::iterator it = m_ifaceAssocSet.begin ();
|
|
gjc@1716
|
432 |
it != m_ifaceAssocSet.end (); it++)
|
|
gjc@1716
|
433 |
{
|
|
gjc@1716
|
434 |
if (it->ifaceAddr == ifaceAddr)
|
|
gjc@1716
|
435 |
return &(*it);
|
|
gjc@1716
|
436 |
}
|
|
gjc@1716
|
437 |
return NULL;
|
|
gjc@1716
|
438 |
}
|
|
gjc@1716
|
439 |
|
|
gjc@1798
|
440 |
const IfaceAssocTuple*
|
|
gjc@1798
|
441 |
OlsrState::FindIfaceAssocTuple (Ipv4Address const &ifaceAddr) const
|
|
gjc@1798
|
442 |
{
|
|
gjc@1798
|
443 |
for (IfaceAssocSet::const_iterator it = m_ifaceAssocSet.begin ();
|
|
gjc@1798
|
444 |
it != m_ifaceAssocSet.end (); it++)
|
|
gjc@1798
|
445 |
{
|
|
gjc@1798
|
446 |
if (it->ifaceAddr == ifaceAddr)
|
|
gjc@1798
|
447 |
return &(*it);
|
|
gjc@1798
|
448 |
}
|
|
gjc@1798
|
449 |
return NULL;
|
|
gjc@1798
|
450 |
}
|
|
gjc@1798
|
451 |
|
|
gjc@1716
|
452 |
void
|
|
gjc@1716
|
453 |
OlsrState::EraseIfaceAssocTuple (const IfaceAssocTuple &tuple)
|
|
gjc@1716
|
454 |
{
|
|
gjc@1716
|
455 |
for (IfaceAssocSet::iterator it = m_ifaceAssocSet.begin ();
|
|
gjc@1716
|
456 |
it != m_ifaceAssocSet.end (); it++)
|
|
gjc@1716
|
457 |
{
|
|
gjc@1716
|
458 |
if (*it == tuple)
|
|
gjc@1716
|
459 |
{
|
|
gjc@1716
|
460 |
m_ifaceAssocSet.erase (it);
|
|
gjc@1716
|
461 |
break;
|
|
gjc@1716
|
462 |
}
|
|
gjc@1716
|
463 |
}
|
|
gjc@1716
|
464 |
}
|
|
gjc@1716
|
465 |
|
|
gjc@1716
|
466 |
void
|
|
gjc@1716
|
467 |
OlsrState::InsertIfaceAssocTuple (const IfaceAssocTuple &tuple)
|
|
gjc@1716
|
468 |
{
|
|
gjc@1716
|
469 |
m_ifaceAssocSet.push_back (tuple);
|
|
gjc@1716
|
470 |
}
|
|
gjc@1716
|
471 |
|
|
gjc@1716
|
472 |
std::vector<Ipv4Address>
|
|
gjc@1716
|
473 |
OlsrState::FindNeighborInterfaces (const Ipv4Address &neighborMainAddr) const
|
|
gjc@1716
|
474 |
{
|
|
gjc@1716
|
475 |
std::vector<Ipv4Address> retval;
|
|
gjc@1716
|
476 |
for (IfaceAssocSet::const_iterator it = m_ifaceAssocSet.begin ();
|
|
gjc@1716
|
477 |
it != m_ifaceAssocSet.end (); it++)
|
|
gjc@1716
|
478 |
{
|
|
gjc@1716
|
479 |
if (it->mainAddr == neighborMainAddr)
|
|
gjc@1716
|
480 |
retval.push_back (it->ifaceAddr);
|
|
gjc@1716
|
481 |
}
|
|
gjc@1716
|
482 |
return retval;
|
|
gjc@1716
|
483 |
}
|
|
gjc@1716
|
484 |
|
|
gjc@1731
|
485 |
} // namespace ns3
|