A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  return &(*it);
45  }
46  return NULL;
47 }
48 
49 void
51 {
52  for (MprSelectorSet::iterator it = m_mprSelectorSet.begin ();
53  it != m_mprSelectorSet.end (); it++)
54  {
55  if (*it == tuple)
56  {
57  m_mprSelectorSet.erase (it);
58  break;
59  }
60  }
61 }
62 
63 void
65 {
66  for (MprSelectorSet::iterator it = m_mprSelectorSet.begin ();
67  it != m_mprSelectorSet.end ();)
68  {
69  if (it->mainAddr == mainAddr)
70  {
71  it = m_mprSelectorSet.erase (it);
72  }
73  else
74  {
75  it++;
76  }
77  }
78 }
79 
80 void
82 {
83  m_mprSelectorSet.push_back (tuple);
84 }
85 
86 std::string
88 {
89  std::ostringstream os;
90  os << "[";
91  for (MprSelectorSet::const_iterator iter = m_mprSelectorSet.begin ();
92  iter != m_mprSelectorSet.end (); iter++)
93  {
94  MprSelectorSet::const_iterator next = iter;
95  next++;
96  os << iter->mainAddr;
97  if (next != m_mprSelectorSet.end ())
98  os << ", ";
99  }
100  os << "]";
101  return os.str ();
102 }
103 
104 
105 /********** Neighbor Set Manipulation **********/
106 
109 {
110  for (NeighborSet::iterator it = m_neighborSet.begin ();
111  it != m_neighborSet.end (); it++)
112  {
113  if (it->neighborMainAddr == mainAddr)
114  return &(*it);
115  }
116  return NULL;
117 }
118 
119 const NeighborTuple*
121 {
122  for (NeighborSet::const_iterator it = m_neighborSet.begin ();
123  it != m_neighborSet.end (); it++)
124  {
125  if (it->neighborMainAddr == mainAddr && it->status == NeighborTuple::STATUS_SYM)
126  return &(*it);
127  }
128  return NULL;
129 }
130 
132 OlsrState::FindNeighborTuple (Ipv4Address const &mainAddr, uint8_t willingness)
133 {
134  for (NeighborSet::iterator it = m_neighborSet.begin ();
135  it != m_neighborSet.end (); it++)
136  {
137  if (it->neighborMainAddr == mainAddr && it->willingness == willingness)
138  return &(*it);
139  }
140  return NULL;
141 }
142 
143 void
145 {
146  for (NeighborSet::iterator it = m_neighborSet.begin ();
147  it != m_neighborSet.end (); it++)
148  {
149  if (*it == tuple)
150  {
151  m_neighborSet.erase (it);
152  break;
153  }
154  }
155 }
156 
157 void
159 {
160  for (NeighborSet::iterator it = m_neighborSet.begin ();
161  it != m_neighborSet.end (); it++)
162  {
163  if (it->neighborMainAddr == mainAddr)
164  {
165  it = m_neighborSet.erase (it);
166  break;
167  }
168  }
169 }
170 
171 void
173 {
174  for (NeighborSet::iterator it = m_neighborSet.begin ();
175  it != m_neighborSet.end (); it++)
176  {
177  if (it->neighborMainAddr == tuple.neighborMainAddr)
178  {
179  // Update it
180  *it = tuple;
181  return;
182  }
183  }
184  m_neighborSet.push_back (tuple);
185 }
186 
187 /********** Neighbor 2 Hop Set Manipulation **********/
188 
191  Ipv4Address const &twoHopNeighborAddr)
192 {
193  for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
194  it != m_twoHopNeighborSet.end (); it++)
195  {
196  if (it->neighborMainAddr == neighborMainAddr
197  && it->twoHopNeighborAddr == twoHopNeighborAddr)
198  {
199  return &(*it);
200  }
201  }
202  return NULL;
203 }
204 
205 void
207 {
208  for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
209  it != m_twoHopNeighborSet.end (); it++)
210  {
211  if (*it == tuple)
212  {
213  m_twoHopNeighborSet.erase (it);
214  break;
215  }
216  }
217 }
218 
219 void
221  const Ipv4Address &twoHopNeighborAddr)
222 {
223  for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
224  it != m_twoHopNeighborSet.end ();)
225  {
226  if (it->neighborMainAddr == neighborMainAddr
227  && it->twoHopNeighborAddr == twoHopNeighborAddr)
228  {
229  it = m_twoHopNeighborSet.erase (it);
230  }
231  else
232  {
233  it++;
234  }
235  }
236 }
237 
238 void
240 {
241  for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
242  it != m_twoHopNeighborSet.end ();)
243  {
244  if (it->neighborMainAddr == neighborMainAddr)
245  {
246  it = m_twoHopNeighborSet.erase (it);
247  }
248  else
249  {
250  it++;
251  }
252  }
253 }
254 
255 void
257 {
258  m_twoHopNeighborSet.push_back (tuple);
259 }
260 
261 /********** MPR Set Manipulation **********/
262 
263 bool
265 {
266  MprSet::iterator it = m_mprSet.find (addr);
267  return (it != m_mprSet.end ());
268 }
269 
270 void
272 {
273  m_mprSet = mprSet;
274 }
275 MprSet
277 {
278  return m_mprSet;
279 }
280 
281 /********** Duplicate Set Manipulation **********/
282 
284 OlsrState::FindDuplicateTuple (Ipv4Address const &addr, uint16_t sequenceNumber)
285 {
286  for (DuplicateSet::iterator it = m_duplicateSet.begin ();
287  it != m_duplicateSet.end (); it++)
288  {
289  if (it->address == addr && it->sequenceNumber == sequenceNumber)
290  return &(*it);
291  }
292  return NULL;
293 }
294 
295 void
297 {
298  for (DuplicateSet::iterator it = m_duplicateSet.begin ();
299  it != m_duplicateSet.end (); it++)
300  {
301  if (*it == tuple)
302  {
303  m_duplicateSet.erase (it);
304  break;
305  }
306  }
307 }
308 
309 void
311 {
312  m_duplicateSet.push_back (tuple);
313 }
314 
315 /********** Link Set Manipulation **********/
316 
317 LinkTuple*
319 {
320  for (LinkSet::iterator it = m_linkSet.begin ();
321  it != m_linkSet.end (); it++)
322  {
323  if (it->neighborIfaceAddr == ifaceAddr)
324  return &(*it);
325  }
326  return NULL;
327 }
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  if (it->symTime > now)
338  return &(*it);
339  else
340  break;
341  }
342  }
343  return NULL;
344 }
345 
346 void
348 {
349  for (LinkSet::iterator it = m_linkSet.begin ();
350  it != m_linkSet.end (); it++)
351  {
352  if (*it == tuple)
353  {
354  m_linkSet.erase (it);
355  break;
356  }
357  }
358 }
359 
360 LinkTuple&
362 {
363  m_linkSet.push_back (tuple);
364  return m_linkSet.back ();
365 }
366 
367 /********** Topology Set Manipulation **********/
368 
371  Ipv4Address const &lastAddr)
372 {
373  for (TopologySet::iterator it = m_topologySet.begin ();
374  it != m_topologySet.end (); it++)
375  {
376  if (it->destAddr == destAddr && it->lastAddr == lastAddr)
377  return &(*it);
378  }
379  return NULL;
380 }
381 
383 OlsrState::FindNewerTopologyTuple (Ipv4Address const & lastAddr, uint16_t ansn)
384 {
385  for (TopologySet::iterator it = m_topologySet.begin ();
386  it != m_topologySet.end (); it++)
387  {
388  if (it->lastAddr == lastAddr && it->sequenceNumber > ansn)
389  return &(*it);
390  }
391  return NULL;
392 }
393 
394 void
396 {
397  for (TopologySet::iterator it = m_topologySet.begin ();
398  it != m_topologySet.end (); it++)
399  {
400  if (*it == tuple)
401  {
402  m_topologySet.erase (it);
403  break;
404  }
405  }
406 }
407 
408 void
409 OlsrState::EraseOlderTopologyTuples (const Ipv4Address &lastAddr, uint16_t ansn)
410 {
411  for (TopologySet::iterator it = m_topologySet.begin ();
412  it != m_topologySet.end ();)
413  {
414  if (it->lastAddr == lastAddr && it->sequenceNumber < ansn)
415  {
416  it = m_topologySet.erase (it);
417  }
418  else
419  {
420  it++;
421  }
422  }
423 }
424 
425 void
427 {
428  m_topologySet.push_back (tuple);
429 }
430 
431 /********** Interface Association Set Manipulation **********/
432 
435 {
436  for (IfaceAssocSet::iterator it = m_ifaceAssocSet.begin ();
437  it != m_ifaceAssocSet.end (); it++)
438  {
439  if (it->ifaceAddr == ifaceAddr)
440  return &(*it);
441  }
442  return NULL;
443 }
444 
445 const IfaceAssocTuple*
447 {
448  for (IfaceAssocSet::const_iterator it = m_ifaceAssocSet.begin ();
449  it != m_ifaceAssocSet.end (); it++)
450  {
451  if (it->ifaceAddr == ifaceAddr)
452  return &(*it);
453  }
454  return NULL;
455 }
456 
457 void
459 {
460  for (IfaceAssocSet::iterator it = m_ifaceAssocSet.begin ();
461  it != m_ifaceAssocSet.end (); it++)
462  {
463  if (*it == tuple)
464  {
465  m_ifaceAssocSet.erase (it);
466  break;
467  }
468  }
469 }
470 
471 void
473 {
474  m_ifaceAssocSet.push_back (tuple);
475 }
476 
477 std::vector<Ipv4Address>
478 OlsrState::FindNeighborInterfaces (const Ipv4Address &neighborMainAddr) const
479 {
480  std::vector<Ipv4Address> retval;
481  for (IfaceAssocSet::const_iterator it = m_ifaceAssocSet.begin ();
482  it != m_ifaceAssocSet.end (); it++)
483  {
484  if (it->mainAddr == neighborMainAddr)
485  retval.push_back (it->ifaceAddr);
486  }
487  return retval;
488 }
489 
490 /********** Host-Network Association Set Manipulation **********/
491 
493 OlsrState::FindAssociationTuple (const Ipv4Address &gatewayAddr, const Ipv4Address &networkAddr, const Ipv4Mask &netmask)
494 {
495  for (AssociationSet::iterator it = m_associationSet.begin ();
496  it != m_associationSet.end (); it++)
497  {
498  if (it->gatewayAddr == gatewayAddr and it->networkAddr == networkAddr and it->netmask == netmask)
499  {
500  return &(*it);
501  }
502  }
503  return NULL;
504 }
505 
506 void
508 {
509  for (AssociationSet::iterator it = m_associationSet.begin ();
510  it != m_associationSet.end (); it++)
511  {
512  if (*it == tuple)
513  {
514  m_associationSet.erase (it);
515  break;
516  }
517  }
518 }
519 
520 void
522 {
523  m_associationSet.push_back (tuple);
524 }
525 
526 void
528 {
529  for (Associations::iterator it = m_associations.begin ();
530  it != m_associations.end (); it++)
531  {
532  if (*it == tuple)
533  {
534  m_associations.erase (it);
535  break;
536  }
537  }
538 }
539 
540 void
542 {
543  m_associations.push_back (tuple);
544 }
545 
546 }} // namespace olsr, ns3
An MPR-Selector Tuple.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
AssociationSet m_associationSet
Association Set (RFC 3626, section12.2). Associations obtained from HNA messages generated by other n...
Definition: olsr-state.h:47
TwoHopNeighborTuple * FindTwoHopNeighborTuple(const Ipv4Address &neighbor, const Ipv4Address &twoHopNeighbor)
Definition: olsr-state.cc:190
void EraseMprSelectorTuples(const Ipv4Address &mainAddr)
Definition: olsr-state.cc:64
void InsertAssociationTuple(const AssociationTuple &tuple)
Definition: olsr-state.cc:521
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:222
const NeighborTuple * FindSymNeighborTuple(const Ipv4Address &mainAddr) const
Definition: olsr-state.cc:120
std::string PrintMprSelectorSet() const
Definition: olsr-state.cc:87
void InsertNeighborTuple(const NeighborTuple &tuple)
Definition: olsr-state.cc:172
std::vector< Ipv4Address > FindNeighborInterfaces(const Ipv4Address &neighborMainAddr) const
Definition: olsr-state.cc:478
TwoHopNeighborSet m_twoHopNeighborSet
2-hop Neighbor Set (RFC 3626, section 4.3.2).
Definition: olsr-state.h:41
void SetMprSet(MprSet mprSet)
MprSet is set by routing protocol after MprCompute.
Definition: olsr-state.cc:271
bool FindMprAddress(const Ipv4Address &address)
Definition: olsr-state.cc:264
void InsertMprSelectorTuple(const MprSelectorTuple &tuple)
Definition: olsr-state.cc:81
NeighborTuple * FindNeighborTuple(const Ipv4Address &mainAddr)
Definition: olsr-state.cc:108
void EraseIfaceAssocTuple(const IfaceAssocTuple &tuple)
Definition: olsr-state.cc:458
LinkTuple * FindSymLinkTuple(const Ipv4Address &ifaceAddr, Time time)
Definition: olsr-state.cc:330
LinkTuple * FindLinkTuple(const Ipv4Address &ifaceAddr)
Definition: olsr-state.cc:318
void EraseDuplicateTuple(const DuplicateTuple &tuple)
Definition: olsr-state.cc:296
void EraseTopologyTuple(const TopologyTuple &tuple)
Definition: olsr-state.cc:395
NeighborSet m_neighborSet
Neighbor Set (RFC 3626, section 4.3.1).
Definition: olsr-state.h:40
void EraseOlderTopologyTuples(const Ipv4Address &lastAddr, uint16_t ansn)
Definition: olsr-state.cc:409
TopologyTuple * FindTopologyTuple(const Ipv4Address &destAddr, const Ipv4Address &lastAddr)
Definition: olsr-state.cc:370
IfaceAssocSet m_ifaceAssocSet
Interface Association Set (RFC 3626, section 4.1).
Definition: olsr-state.h:46
An Association Tuple.
IfaceAssocTuple * FindIfaceAssocTuple(const Ipv4Address &ifaceAddr)
Definition: olsr-state.cc:434
LinkSet m_linkSet
Link Set (RFC 3626, section 4.2.1).
Definition: olsr-state.h:39
void InsertDuplicateTuple(const DuplicateTuple &tuple)
Definition: olsr-state.cc:310
MprSet GetMprSet() const
Gets an MPR Set needed by tests.
Definition: olsr-state.cc:276
void EraseLinkTuple(const LinkTuple &tuple)
Definition: olsr-state.cc:347
AssociationTuple * FindAssociationTuple(const Ipv4Address &gatewayAddr, const Ipv4Address &networkAddr, const Ipv4Mask &netmask)
Definition: olsr-state.cc:493
void InsertIfaceAssocTuple(const IfaceAssocTuple &tuple)
Definition: olsr-state.cc:472
Ipv4Address neighborMainAddr
Main address of a neighbor node.
MprSelectorTuple * FindMprSelectorTuple(const Ipv4Address &mainAddr)
Definition: olsr-state.cc:38
DuplicateSet m_duplicateSet
Duplicate Set (RFC 3626, section 3.4).
Definition: olsr-state.h:45
void EraseAssociationTuple(const AssociationTuple &tuple)
Definition: olsr-state.cc:507
Associations m_associations
The node's local Host Network Associations that will be advertised using HNA messages.
Definition: olsr-state.h:48
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
void EraseAssociation(const Association &tuple)
Definition: olsr-state.cc:527
DuplicateTuple * FindDuplicateTuple(const Ipv4Address &address, uint16_t sequenceNumber)
Definition: olsr-state.cc:284
void InsertTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Definition: olsr-state.cc:256
std::set< Ipv4Address > MprSet
MPR Set type.
void EraseTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Definition: olsr-state.cc:206
LinkTuple & InsertLinkTuple(const LinkTuple &tuple)
Definition: olsr-state.cc:361
MprSet m_mprSet
MPR Set (RFC 3626, section 4.3.3).
Definition: olsr-state.h:43
MprSelectorSet m_mprSelectorSet
MPR Selector Set (RFC 3626, section 4.3.4).
Definition: olsr-state.h:44
void EraseNeighborTuple(const NeighborTuple &neighborTuple)
Definition: olsr-state.cc:144
TopologyTuple * FindNewerTopologyTuple(const Ipv4Address &lastAddr, uint16_t ansn)
Definition: olsr-state.cc:383
TopologySet m_topologySet
Topology Set (RFC 3626, section 4.4).
Definition: olsr-state.h:42
An Interface Association Tuple.
The type "list of interface addresses".
void EraseMprSelectorTuple(const MprSelectorTuple &tuple)
Definition: olsr-state.cc:50
void InsertAssociation(const Association &tuple)
Definition: olsr-state.cc:541
void EraseTwoHopNeighborTuples(const Ipv4Address &neighbor)
Definition: olsr-state.cc:239
void InsertTopologyTuple(const TopologyTuple &tuple)
Definition: olsr-state.cc:426