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