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