A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
olsr-state.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004 Francisco J. Ros
3 * Copyright (c) 2007 INESC Porto
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors: Francisco J. Ros <fjrm@dif.um.es>
19 * Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
20 */
21
22///
23/// \file olsr-state.cc
24/// \brief Implementation of all functions needed for manipulating the internal
25/// state of an OLSR node.
26///
27
28#include "olsr-state.h"
29
30namespace ns3
31{
32namespace olsr
33{
34
35/********** MPR Selector Set Manipulation **********/
36
37MprSelectorTuple*
39{
40 for (auto it = m_mprSelectorSet.begin(); it != m_mprSelectorSet.end(); it++)
41 {
42 if (it->mainAddr == mainAddr)
43 {
44 return &(*it);
45 }
46 }
47 return nullptr;
48}
49
50void
52{
53 for (auto it = m_mprSelectorSet.begin(); it != m_mprSelectorSet.end(); it++)
54 {
55 if (*it == tuple)
56 {
57 m_mprSelectorSet.erase(it);
58 break;
59 }
60 }
61}
62
63void
65{
66 for (auto it = m_mprSelectorSet.begin(); it != m_mprSelectorSet.end();)
67 {
68 if (it->mainAddr == mainAddr)
69 {
70 it = m_mprSelectorSet.erase(it);
71 }
72 else
73 {
74 it++;
75 }
76 }
77}
78
79void
81{
82 m_mprSelectorSet.push_back(tuple);
83}
84
85std::string
87{
88 std::ostringstream os;
89 os << "[";
90 for (auto iter = m_mprSelectorSet.begin(); iter != m_mprSelectorSet.end(); iter++)
91 {
92 auto next = iter;
93 next++;
94 os << iter->mainAddr;
95 if (next != m_mprSelectorSet.end())
96 {
97 os << ", ";
98 }
99 }
100 os << "]";
101 return os.str();
102}
103
104/********** Neighbor Set Manipulation **********/
105
108{
109 for (auto it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
110 {
111 if (it->neighborMainAddr == mainAddr)
112 {
113 return &(*it);
114 }
115 }
116 return nullptr;
117}
118
119const NeighborTuple*
121{
122 for (auto it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
123 {
124 if (it->neighborMainAddr == mainAddr && it->status == NeighborTuple::STATUS_SYM)
125 {
126 return &(*it);
127 }
128 }
129 return nullptr;
130}
131
134{
135 for (auto it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
136 {
137 if (it->neighborMainAddr == mainAddr && it->willingness == willingness)
138 {
139 return &(*it);
140 }
141 }
142 return nullptr;
143}
144
145void
147{
148 for (auto it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
149 {
150 if (*it == tuple)
151 {
152 m_neighborSet.erase(it);
153 break;
154 }
155 }
156}
157
158void
160{
161 for (auto it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
162 {
163 if (it->neighborMainAddr == mainAddr)
164 {
165 it = m_neighborSet.erase(it);
166 break;
167 }
168 }
169}
170
171void
173{
174 for (auto it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
175 {
176 if (it->neighborMainAddr == tuple.neighborMainAddr)
177 {
178 // Update it
179 *it = tuple;
180 return;
181 }
182 }
183 m_neighborSet.push_back(tuple);
184}
185
186/********** Neighbor 2 Hop Set Manipulation **********/
187
190 const Ipv4Address& twoHopNeighborAddr)
191{
192 for (auto it = m_twoHopNeighborSet.begin(); it != m_twoHopNeighborSet.end(); it++)
193 {
194 if (it->neighborMainAddr == neighborMainAddr &&
195 it->twoHopNeighborAddr == twoHopNeighborAddr)
196 {
197 return &(*it);
198 }
199 }
200 return nullptr;
201}
202
203void
205{
206 for (auto it = m_twoHopNeighborSet.begin(); it != m_twoHopNeighborSet.end(); it++)
207 {
208 if (*it == tuple)
209 {
210 m_twoHopNeighborSet.erase(it);
211 break;
212 }
213 }
214}
215
216void
218 const Ipv4Address& twoHopNeighborAddr)
219{
220 for (auto it = m_twoHopNeighborSet.begin(); it != m_twoHopNeighborSet.end();)
221 {
222 if (it->neighborMainAddr == neighborMainAddr &&
223 it->twoHopNeighborAddr == twoHopNeighborAddr)
224 {
225 it = m_twoHopNeighborSet.erase(it);
226 }
227 else
228 {
229 it++;
230 }
231 }
232}
233
234void
236{
237 for (auto it = m_twoHopNeighborSet.begin(); it != m_twoHopNeighborSet.end();)
238 {
239 if (it->neighborMainAddr == neighborMainAddr)
240 {
241 it = m_twoHopNeighborSet.erase(it);
242 }
243 else
244 {
245 it++;
246 }
247 }
248}
249
250void
252{
253 m_twoHopNeighborSet.push_back(tuple);
254}
255
256/********** MPR Set Manipulation **********/
257
258bool
260{
261 auto it = m_mprSet.find(addr);
262 return (it != m_mprSet.end());
263}
264
265void
267{
268 m_mprSet = mprSet;
269}
270
271MprSet
273{
274 return m_mprSet;
275}
276
277/********** Duplicate Set Manipulation **********/
278
280OlsrState::FindDuplicateTuple(const Ipv4Address& addr, uint16_t sequenceNumber)
281{
282 for (auto it = m_duplicateSet.begin(); it != m_duplicateSet.end(); it++)
283 {
284 if (it->address == addr && it->sequenceNumber == sequenceNumber)
285 {
286 return &(*it);
287 }
288 }
289 return nullptr;
290}
291
292void
294{
295 for (auto it = m_duplicateSet.begin(); it != m_duplicateSet.end(); it++)
296 {
297 if (*it == tuple)
298 {
299 m_duplicateSet.erase(it);
300 break;
301 }
302 }
303}
304
305void
307{
308 m_duplicateSet.push_back(tuple);
309}
310
311/********** Link Set Manipulation **********/
312
315{
316 for (auto it = m_linkSet.begin(); it != m_linkSet.end(); it++)
317 {
318 if (it->neighborIfaceAddr == ifaceAddr)
319 {
320 return &(*it);
321 }
322 }
323 return nullptr;
324}
325
328{
329 for (auto it = m_linkSet.begin(); it != m_linkSet.end(); it++)
330 {
331 if (it->neighborIfaceAddr == ifaceAddr)
332 {
333 if (it->symTime > now)
334 {
335 return &(*it);
336 }
337 else
338 {
339 break;
340 }
341 }
342 }
343 return nullptr;
344}
345
346void
348{
349 for (auto it = m_linkSet.begin(); it != m_linkSet.end(); it++)
350 {
351 if (*it == tuple)
352 {
353 m_linkSet.erase(it);
354 break;
355 }
356 }
357}
358
361{
362 m_linkSet.push_back(tuple);
363 return m_linkSet.back();
364}
365
366/********** Topology Set Manipulation **********/
367
369OlsrState::FindTopologyTuple(const Ipv4Address& destAddr, const Ipv4Address& lastAddr)
370{
371 for (auto it = m_topologySet.begin(); it != m_topologySet.end(); it++)
372 {
373 if (it->destAddr == destAddr && it->lastAddr == lastAddr)
374 {
375 return &(*it);
376 }
377 }
378 return nullptr;
379}
380
382OlsrState::FindNewerTopologyTuple(const Ipv4Address& lastAddr, uint16_t ansn)
383{
384 for (auto it = m_topologySet.begin(); it != m_topologySet.end(); it++)
385 {
386 if (it->lastAddr == lastAddr && it->sequenceNumber > ansn)
387 {
388 return &(*it);
389 }
390 }
391 return nullptr;
392}
393
394void
396{
397 for (auto it = m_topologySet.begin(); it != m_topologySet.end(); it++)
398 {
399 if (*it == tuple)
400 {
401 m_topologySet.erase(it);
402 break;
403 }
404 }
405}
406
407void
409{
410 for (auto it = m_topologySet.begin(); it != m_topologySet.end();)
411 {
412 if (it->lastAddr == lastAddr && it->sequenceNumber < ansn)
413 {
414 it = m_topologySet.erase(it);
415 }
416 else
417 {
418 it++;
419 }
420 }
421}
422
423void
425{
426 m_topologySet.push_back(tuple);
427}
428
429/********** Interface Association Set Manipulation **********/
430
433{
434 for (auto it = m_ifaceAssocSet.begin(); it != m_ifaceAssocSet.end(); it++)
435 {
436 if (it->ifaceAddr == ifaceAddr)
437 {
438 return &(*it);
439 }
440 }
441 return nullptr;
442}
443
444const IfaceAssocTuple*
446{
447 for (auto it = m_ifaceAssocSet.begin(); it != m_ifaceAssocSet.end(); it++)
448 {
449 if (it->ifaceAddr == ifaceAddr)
450 {
451 return &(*it);
452 }
453 }
454 return nullptr;
455}
456
457void
459{
460 for (auto it = m_ifaceAssocSet.begin(); it != m_ifaceAssocSet.end(); it++)
461 {
462 if (*it == tuple)
463 {
464 m_ifaceAssocSet.erase(it);
465 break;
466 }
467 }
468}
469
470void
472{
473 m_ifaceAssocSet.push_back(tuple);
474}
475
476std::vector<Ipv4Address>
477OlsrState::FindNeighborInterfaces(const Ipv4Address& neighborMainAddr) const
478{
479 std::vector<Ipv4Address> retval;
480 for (auto it = m_ifaceAssocSet.begin(); it != m_ifaceAssocSet.end(); it++)
481 {
482 if (it->mainAddr == neighborMainAddr)
483 {
484 retval.push_back(it->ifaceAddr);
485 }
486 }
487 return retval;
488}
489
490/********** Host-Network Association Set Manipulation **********/
491
494 const Ipv4Address& networkAddr,
495 const Ipv4Mask& netmask)
496{
497 for (auto it = m_associationSet.begin(); it != m_associationSet.end(); it++)
498 {
499 if (it->gatewayAddr == gatewayAddr and it->networkAddr == networkAddr and
500 it->netmask == netmask)
501 {
502 return &(*it);
503 }
504 }
505 return nullptr;
506}
507
508void
510{
511 for (auto it = m_associationSet.begin(); it != m_associationSet.end(); it++)
512 {
513 if (*it == tuple)
514 {
515 m_associationSet.erase(it);
516 break;
517 }
518 }
519}
520
521void
523{
524 m_associationSet.push_back(tuple);
525}
526
527void
529{
530 for (auto it = m_associations.begin(); it != m_associations.end(); it++)
531 {
532 if (*it == tuple)
533 {
534 m_associations.erase(it);
535 break;
536 }
537 }
538}
539
540void
542{
543 m_associations.push_back(tuple);
544}
545
546} // namespace olsr
547} // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
MprSet GetMprSet() const
Gets the MPR set.
Definition: olsr-state.cc:272
void EraseAssociation(const Association &tuple)
Erases an association.
Definition: olsr-state.cc:528
AssociationSet m_associationSet
Association Set (RFC 3626, section12.2).
Definition: olsr-state.h:48
void EraseIfaceAssocTuple(const IfaceAssocTuple &tuple)
Erases a interface association tuple.
Definition: olsr-state.cc:458
void InsertTopologyTuple(const TopologyTuple &tuple)
Inserts a topology tuple.
Definition: olsr-state.cc:424
IfaceAssocTuple * FindIfaceAssocTuple(const Ipv4Address &ifaceAddr)
Finds a interface association tuple.
Definition: olsr-state.cc:432
std::string PrintMprSelectorSet() const
Prints the MPR selector sets.
Definition: olsr-state.cc:86
LinkSet m_linkSet
Link Set (RFC 3626, section 4.2.1).
Definition: olsr-state.h:40
TwoHopNeighborTuple * FindTwoHopNeighborTuple(const Ipv4Address &neighbor, const Ipv4Address &twoHopNeighbor)
Finds a 2-hop neighbor tuple.
Definition: olsr-state.cc:189
void EraseTwoHopNeighborTuples(const Ipv4Address &neighbor)
Erases the 2-hop neighbor tuples with the same 1-hop neighbor.
Definition: olsr-state.cc:235
void InsertAssociation(const Association &tuple)
Inserts an association tuple.
Definition: olsr-state.cc:541
LinkTuple * FindSymLinkTuple(const Ipv4Address &ifaceAddr, Time time)
Finds a symmetrical link tuple.
Definition: olsr-state.cc:327
const NeighborTuple * FindSymNeighborTuple(const Ipv4Address &mainAddr) const
Finds a symmetrical neighbor tuple.
Definition: olsr-state.cc:120
DuplicateSet m_duplicateSet
Duplicate Set (RFC 3626, section 3.4).
Definition: olsr-state.h:46
IfaceAssocSet m_ifaceAssocSet
Interface Association Set (RFC 3626, section 4.1).
Definition: olsr-state.h:47
void EraseNeighborTuple(const NeighborTuple &neighborTuple)
Erases a neighbor tuple.
Definition: olsr-state.cc:146
TopologyTuple * FindNewerTopologyTuple(const Ipv4Address &lastAddr, uint16_t ansn)
Finds a topology tuple.
Definition: olsr-state.cc:382
void InsertDuplicateTuple(const DuplicateTuple &tuple)
Inserts a duplicate tuple.
Definition: olsr-state.cc:306
Associations m_associations
The node's local Host Network Associations that will be advertised using HNA messages.
Definition: olsr-state.h:50
void EraseMprSelectorTuples(const Ipv4Address &mainAddr)
Erases all MPR selector tuples belonging to the same address.
Definition: olsr-state.cc:64
MprSelectorTuple * FindMprSelectorTuple(const Ipv4Address &mainAddr)
Finds a MPR selector tuple.
Definition: olsr-state.cc:38
void SetMprSet(MprSet mprSet)
Sets the MPR set to the one specified.
Definition: olsr-state.cc:266
void EraseAssociationTuple(const AssociationTuple &tuple)
Erases a known association tuple.
Definition: olsr-state.cc:509
void InsertNeighborTuple(const NeighborTuple &tuple)
Inserts a neighbor tuple.
Definition: olsr-state.cc:172
NeighborSet m_neighborSet
Neighbor Set (RFC 3626, section 4.3.1).
Definition: olsr-state.h:41
TopologyTuple * FindTopologyTuple(const Ipv4Address &destAddr, const Ipv4Address &lastAddr)
Finds a topology tuple.
Definition: olsr-state.cc:369
TwoHopNeighborSet m_twoHopNeighborSet
2-hop Neighbor Set (RFC 3626, section 4.3.2).
Definition: olsr-state.h:42
AssociationTuple * FindAssociationTuple(const Ipv4Address &gatewayAddr, const Ipv4Address &networkAddr, const Ipv4Mask &netmask)
Finds an association tuple.
Definition: olsr-state.cc:493
std::vector< Ipv4Address > FindNeighborInterfaces(const Ipv4Address &neighborMainAddr) const
Returns a vector of all interfaces of a given neighbor, with the exception of the "main" one.
Definition: olsr-state.cc:477
bool FindMprAddress(const Ipv4Address &address)
Checks if there's an MPR with a specific address.
Definition: olsr-state.cc:259
void EraseLinkTuple(const LinkTuple &tuple)
Erases a link tuple.
Definition: olsr-state.cc:347
DuplicateTuple * FindDuplicateTuple(const Ipv4Address &address, uint16_t sequenceNumber)
Finds a duplicate tuple.
Definition: olsr-state.cc:280
void InsertTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Inserts a 2-hop neighbor tuple.
Definition: olsr-state.cc:251
LinkTuple * FindLinkTuple(const Ipv4Address &ifaceAddr)
Finds a link tuple.
Definition: olsr-state.cc:314
void InsertAssociationTuple(const AssociationTuple &tuple)
Inserts a known association tuple.
Definition: olsr-state.cc:522
MprSet m_mprSet
MPR Set (RFC 3626, section 4.3.3).
Definition: olsr-state.h:44
void InsertMprSelectorTuple(const MprSelectorTuple &tuple)
Inserts a MPR selector tuple.
Definition: olsr-state.cc:80
LinkTuple & InsertLinkTuple(const LinkTuple &tuple)
Inserts a link tuple.
Definition: olsr-state.cc:360
MprSelectorSet m_mprSelectorSet
MPR Selector Set (RFC 3626, section 4.3.4).
Definition: olsr-state.h:45
void EraseTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Erases a 2-hop neighbor tuple.
Definition: olsr-state.cc:204
void InsertIfaceAssocTuple(const IfaceAssocTuple &tuple)
Inserts a interface association tuple.
Definition: olsr-state.cc:471
void EraseTopologyTuple(const TopologyTuple &tuple)
Erases a topology tuple.
Definition: olsr-state.cc:395
NeighborTuple * FindNeighborTuple(const Ipv4Address &mainAddr)
Finds a neighbor tuple.
Definition: olsr-state.cc:107
void EraseOlderTopologyTuples(const Ipv4Address &lastAddr, uint16_t ansn)
Erases a topology tuple.
Definition: olsr-state.cc:408
void EraseDuplicateTuple(const DuplicateTuple &tuple)
Erases a duplicate tuple.
Definition: olsr-state.cc:293
TopologySet m_topologySet
Topology Set (RFC 3626, section 4.4).
Definition: olsr-state.h:43
void EraseMprSelectorTuple(const MprSelectorTuple &tuple)
Erases a MPR selector tuple.
Definition: olsr-state.cc:51
Willingness
Willingness for forwarding packets from other nodes.
std::set< Ipv4Address > MprSet
MPR Set type.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: olsr.py:1
An Interface Association Tuple.
An MPR-Selector Tuple.
Ipv4Address neighborMainAddr
Main address of a neighbor node.