A Discrete-Event Network Simulator
API
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
27
28#include "olsr-state.h"
29
30namespace ns3
31{
32namespace olsr
33{
34
35/********** MPR Selector Set Manipulation **********/
36
37MprSelectorTuple*
39{
40 for (MprSelectorSet::iterator 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 (MprSelectorSet::iterator 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 (MprSelectorSet::iterator 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 (MprSelectorSet::const_iterator iter = m_mprSelectorSet.begin();
91 iter != m_mprSelectorSet.end();
92 iter++)
93 {
94 MprSelectorSet::const_iterator next = iter;
95 next++;
96 os << iter->mainAddr;
97 if (next != m_mprSelectorSet.end())
98 {
99 os << ", ";
100 }
101 }
102 os << "]";
103 return os.str();
104}
105
106/********** Neighbor Set Manipulation **********/
107
110{
111 for (NeighborSet::iterator it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
112 {
113 if (it->neighborMainAddr == mainAddr)
114 {
115 return &(*it);
116 }
117 }
118 return nullptr;
119}
120
121const NeighborTuple*
123{
124 for (NeighborSet::const_iterator it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
125 {
126 if (it->neighborMainAddr == mainAddr && it->status == NeighborTuple::STATUS_SYM)
127 {
128 return &(*it);
129 }
130 }
131 return nullptr;
132}
133
135OlsrState::FindNeighborTuple(const Ipv4Address& mainAddr, uint8_t willingness)
136{
137 for (NeighborSet::iterator it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
138 {
139 if (it->neighborMainAddr == mainAddr && it->willingness == willingness)
140 {
141 return &(*it);
142 }
143 }
144 return nullptr;
145}
146
147void
149{
150 for (NeighborSet::iterator it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
151 {
152 if (*it == tuple)
153 {
154 m_neighborSet.erase(it);
155 break;
156 }
157 }
158}
159
160void
162{
163 for (NeighborSet::iterator it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
164 {
165 if (it->neighborMainAddr == mainAddr)
166 {
167 it = m_neighborSet.erase(it);
168 break;
169 }
170 }
171}
172
173void
175{
176 for (NeighborSet::iterator it = m_neighborSet.begin(); it != m_neighborSet.end(); it++)
177 {
178 if (it->neighborMainAddr == tuple.neighborMainAddr)
179 {
180 // Update it
181 *it = tuple;
182 return;
183 }
184 }
185 m_neighborSet.push_back(tuple);
186}
187
188/********** Neighbor 2 Hop Set Manipulation **********/
189
192 const Ipv4Address& twoHopNeighborAddr)
193{
194 for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin();
195 it != m_twoHopNeighborSet.end();
196 it++)
197 {
198 if (it->neighborMainAddr == neighborMainAddr &&
199 it->twoHopNeighborAddr == twoHopNeighborAddr)
200 {
201 return &(*it);
202 }
203 }
204 return nullptr;
205}
206
207void
209{
210 for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin();
211 it != m_twoHopNeighborSet.end();
212 it++)
213 {
214 if (*it == tuple)
215 {
216 m_twoHopNeighborSet.erase(it);
217 break;
218 }
219 }
220}
221
222void
224 const Ipv4Address& twoHopNeighborAddr)
225{
226 for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin();
227 it != m_twoHopNeighborSet.end();)
228 {
229 if (it->neighborMainAddr == neighborMainAddr &&
230 it->twoHopNeighborAddr == twoHopNeighborAddr)
231 {
232 it = m_twoHopNeighborSet.erase(it);
233 }
234 else
235 {
236 it++;
237 }
238 }
239}
240
241void
243{
244 for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin();
245 it != m_twoHopNeighborSet.end();)
246 {
247 if (it->neighborMainAddr == neighborMainAddr)
248 {
249 it = m_twoHopNeighborSet.erase(it);
250 }
251 else
252 {
253 it++;
254 }
255 }
256}
257
258void
260{
261 m_twoHopNeighborSet.push_back(tuple);
262}
263
264/********** MPR Set Manipulation **********/
265
266bool
268{
269 MprSet::iterator it = m_mprSet.find(addr);
270 return (it != m_mprSet.end());
271}
272
273void
275{
276 m_mprSet = mprSet;
277}
278
279MprSet
281{
282 return m_mprSet;
283}
284
285/********** Duplicate Set Manipulation **********/
286
288OlsrState::FindDuplicateTuple(const Ipv4Address& addr, uint16_t sequenceNumber)
289{
290 for (DuplicateSet::iterator it = m_duplicateSet.begin(); it != m_duplicateSet.end(); it++)
291 {
292 if (it->address == addr && it->sequenceNumber == sequenceNumber)
293 {
294 return &(*it);
295 }
296 }
297 return nullptr;
298}
299
300void
302{
303 for (DuplicateSet::iterator it = m_duplicateSet.begin(); it != m_duplicateSet.end(); it++)
304 {
305 if (*it == tuple)
306 {
307 m_duplicateSet.erase(it);
308 break;
309 }
310 }
311}
312
313void
315{
316 m_duplicateSet.push_back(tuple);
317}
318
319/********** Link Set Manipulation **********/
320
323{
324 for (LinkSet::iterator it = m_linkSet.begin(); it != m_linkSet.end(); it++)
325 {
326 if (it->neighborIfaceAddr == ifaceAddr)
327 {
328 return &(*it);
329 }
330 }
331 return nullptr;
332}
333
336{
337 for (LinkSet::iterator it = m_linkSet.begin(); it != m_linkSet.end(); it++)
338 {
339 if (it->neighborIfaceAddr == ifaceAddr)
340 {
341 if (it->symTime > now)
342 {
343 return &(*it);
344 }
345 else
346 {
347 break;
348 }
349 }
350 }
351 return nullptr;
352}
353
354void
356{
357 for (LinkSet::iterator it = m_linkSet.begin(); it != m_linkSet.end(); it++)
358 {
359 if (*it == tuple)
360 {
361 m_linkSet.erase(it);
362 break;
363 }
364 }
365}
366
369{
370 m_linkSet.push_back(tuple);
371 return m_linkSet.back();
372}
373
374/********** Topology Set Manipulation **********/
375
377OlsrState::FindTopologyTuple(const Ipv4Address& destAddr, const Ipv4Address& lastAddr)
378{
379 for (TopologySet::iterator it = m_topologySet.begin(); it != m_topologySet.end(); it++)
380 {
381 if (it->destAddr == destAddr && it->lastAddr == lastAddr)
382 {
383 return &(*it);
384 }
385 }
386 return nullptr;
387}
388
390OlsrState::FindNewerTopologyTuple(const Ipv4Address& lastAddr, uint16_t ansn)
391{
392 for (TopologySet::iterator it = m_topologySet.begin(); it != m_topologySet.end(); it++)
393 {
394 if (it->lastAddr == lastAddr && it->sequenceNumber > ansn)
395 {
396 return &(*it);
397 }
398 }
399 return nullptr;
400}
401
402void
404{
405 for (TopologySet::iterator it = m_topologySet.begin(); it != m_topologySet.end(); it++)
406 {
407 if (*it == tuple)
408 {
409 m_topologySet.erase(it);
410 break;
411 }
412 }
413}
414
415void
417{
418 for (TopologySet::iterator it = m_topologySet.begin(); it != m_topologySet.end();)
419 {
420 if (it->lastAddr == lastAddr && it->sequenceNumber < ansn)
421 {
422 it = m_topologySet.erase(it);
423 }
424 else
425 {
426 it++;
427 }
428 }
429}
430
431void
433{
434 m_topologySet.push_back(tuple);
435}
436
437/********** Interface Association Set Manipulation **********/
438
441{
442 for (IfaceAssocSet::iterator it = m_ifaceAssocSet.begin(); it != m_ifaceAssocSet.end(); it++)
443 {
444 if (it->ifaceAddr == ifaceAddr)
445 {
446 return &(*it);
447 }
448 }
449 return nullptr;
450}
451
452const IfaceAssocTuple*
454{
455 for (IfaceAssocSet::const_iterator it = m_ifaceAssocSet.begin(); it != m_ifaceAssocSet.end();
456 it++)
457 {
458 if (it->ifaceAddr == ifaceAddr)
459 {
460 return &(*it);
461 }
462 }
463 return nullptr;
464}
465
466void
468{
469 for (IfaceAssocSet::iterator it = m_ifaceAssocSet.begin(); it != m_ifaceAssocSet.end(); it++)
470 {
471 if (*it == tuple)
472 {
473 m_ifaceAssocSet.erase(it);
474 break;
475 }
476 }
477}
478
479void
481{
482 m_ifaceAssocSet.push_back(tuple);
483}
484
485std::vector<Ipv4Address>
486OlsrState::FindNeighborInterfaces(const Ipv4Address& neighborMainAddr) const
487{
488 std::vector<Ipv4Address> retval;
489 for (IfaceAssocSet::const_iterator it = m_ifaceAssocSet.begin(); it != m_ifaceAssocSet.end();
490 it++)
491 {
492 if (it->mainAddr == neighborMainAddr)
493 {
494 retval.push_back(it->ifaceAddr);
495 }
496 }
497 return retval;
498}
499
500/********** Host-Network Association Set Manipulation **********/
501
504 const Ipv4Address& networkAddr,
505 const Ipv4Mask& netmask)
506{
507 for (AssociationSet::iterator it = m_associationSet.begin(); it != m_associationSet.end(); it++)
508 {
509 if (it->gatewayAddr == gatewayAddr and it->networkAddr == networkAddr and
510 it->netmask == netmask)
511 {
512 return &(*it);
513 }
514 }
515 return nullptr;
516}
517
518void
520{
521 for (AssociationSet::iterator it = m_associationSet.begin(); it != m_associationSet.end(); it++)
522 {
523 if (*it == tuple)
524 {
525 m_associationSet.erase(it);
526 break;
527 }
528 }
529}
530
531void
533{
534 m_associationSet.push_back(tuple);
535}
536
537void
539{
540 for (Associations::iterator it = m_associations.begin(); it != m_associations.end(); it++)
541 {
542 if (*it == tuple)
543 {
544 m_associations.erase(it);
545 break;
546 }
547 }
548}
549
550void
552{
553 m_associations.push_back(tuple);
554}
555
556} // namespace olsr
557} // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
MprSet GetMprSet() const
Gets the MPR set.
Definition: olsr-state.cc:280
void EraseAssociation(const Association &tuple)
Erases an association.
Definition: olsr-state.cc:538
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:467
void InsertTopologyTuple(const TopologyTuple &tuple)
Inserts a topology tuple.
Definition: olsr-state.cc:432
IfaceAssocTuple * FindIfaceAssocTuple(const Ipv4Address &ifaceAddr)
Finds a interface association tuple.
Definition: olsr-state.cc:440
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:191
void EraseTwoHopNeighborTuples(const Ipv4Address &neighbor)
Erases the 2-hop neighbor tuples with the same 1-hop neighbor.
Definition: olsr-state.cc:242
void InsertAssociation(const Association &tuple)
Inserts an association tuple.
Definition: olsr-state.cc:551
LinkTuple * FindSymLinkTuple(const Ipv4Address &ifaceAddr, Time time)
Finds a symmetrical link tuple.
Definition: olsr-state.cc:335
const NeighborTuple * FindSymNeighborTuple(const Ipv4Address &mainAddr) const
Finds a symmetrical neighbor tuple.
Definition: olsr-state.cc:122
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:148
TopologyTuple * FindNewerTopologyTuple(const Ipv4Address &lastAddr, uint16_t ansn)
Finds a topology tuple.
Definition: olsr-state.cc:390
void InsertDuplicateTuple(const DuplicateTuple &tuple)
Inserts a duplicate tuple.
Definition: olsr-state.cc:314
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:274
void EraseAssociationTuple(const AssociationTuple &tuple)
Erases a known association tuple.
Definition: olsr-state.cc:519
void InsertNeighborTuple(const NeighborTuple &tuple)
Inserts a neighbor tuple.
Definition: olsr-state.cc:174
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:377
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:503
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:486
bool FindMprAddress(const Ipv4Address &address)
Checks if there's an MPR with a specific address.
Definition: olsr-state.cc:267
void EraseLinkTuple(const LinkTuple &tuple)
Erases a link tuple.
Definition: olsr-state.cc:355
DuplicateTuple * FindDuplicateTuple(const Ipv4Address &address, uint16_t sequenceNumber)
Finds a duplicate tuple.
Definition: olsr-state.cc:288
void InsertTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Inserts a 2-hop neighbor tuple.
Definition: olsr-state.cc:259
LinkTuple * FindLinkTuple(const Ipv4Address &ifaceAddr)
Finds a link tuple.
Definition: olsr-state.cc:322
void InsertAssociationTuple(const AssociationTuple &tuple)
Inserts a known association tuple.
Definition: olsr-state.cc:532
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:368
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:208
void InsertIfaceAssocTuple(const IfaceAssocTuple &tuple)
Inserts a interface association tuple.
Definition: olsr-state.cc:480
void EraseTopologyTuple(const TopologyTuple &tuple)
Erases a topology tuple.
Definition: olsr-state.cc:403
NeighborTuple * FindNeighborTuple(const Ipv4Address &mainAddr)
Finds a neighbor tuple.
Definition: olsr-state.cc:109
void EraseOlderTopologyTuples(const Ipv4Address &lastAddr, uint16_t ansn)
Erases a topology tuple.
Definition: olsr-state.cc:416
void EraseDuplicateTuple(const DuplicateTuple &tuple)
Erases a duplicate tuple.
Definition: olsr-state.cc:301
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
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.