src/routing/olsr/olsr-state.h
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Tue Dec 02 18:42:24 2008 +0000 (2008-12-02)
changeset 3970 8658841e4782
parent 2361 743e0e351379
child 4358 e63305078fe5
permissions -rw-r--r--
Fix a couple of OLSR bugs (#415)

- Added a lot more logging messages;

- When "link sensing" tries to update a link tuple for a neighbor that has been removed, just re-add the neighbor, rather than silently failing;

- The optimization of not recomputing the routing table if we think no state has changed has been removed: it turned out to be just too buggy and the code base makes it difficult to catch all places where a state mofication is done. Instead now we just recompute the table for any message processed, like the RFC says.
gjc@1716
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
gjc@1752
     2
/*
gjc@1752
     3
 * Copyright (c) 2004 Francisco J. Ros 
gjc@1752
     4
 * Copyright (c) 2007 INESC Porto
gjc@1752
     5
 *
gjc@1752
     6
 * This program is free software; you can redistribute it and/or modify
gjc@1752
     7
 * it under the terms of the GNU General Public License version 2 as
gjc@1752
     8
 * published by the Free Software Foundation;
gjc@1752
     9
 *
gjc@1752
    10
 * This program is distributed in the hope that it will be useful,
gjc@1752
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
gjc@1752
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
gjc@1752
    13
 * GNU General Public License for more details.
gjc@1752
    14
 *
gjc@1752
    15
 * You should have received a copy of the GNU General Public License
gjc@1752
    16
 * along with this program; if not, write to the Free Software
gjc@1752
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
gjc@1752
    18
 *
gjc@1752
    19
 * Authors: Francisco J. Ros  <fjrm@dif.um.es>
gjc@1752
    20
 *          Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
gjc@1752
    21
 */
gjc@1716
    22
gjc@1716
    23
/// \brief	This header file declares and defines internal state of an OLSR node.
gjc@1716
    24
gjc@1731
    25
#ifndef __OLSR_STATE_H__
gjc@1731
    26
#define __OLSR_STATE_H__
gjc@1716
    27
gjc@1731
    28
#include "repositories.h"
gjc@1716
    29
gjc@1731
    30
namespace ns3 {
gjc@1731
    31
gjc@1731
    32
using namespace olsr;
gjc@1716
    33
gjc@1716
    34
/// This class encapsulates all data structures needed for maintaining internal state of an OLSR node.
gjc@1716
    35
class OlsrState
gjc@1716
    36
{
gjc@1716
    37
  //  friend class Olsr;
gjc@1716
    38
  
gjc@1716
    39
protected:
gjc@1716
    40
  LinkSet m_linkSet;	///< Link Set (RFC 3626, section 4.2.1).
gjc@1716
    41
  NeighborSet m_neighborSet;		///< Neighbor Set (RFC 3626, section 4.3.1).
gjc@1716
    42
  TwoHopNeighborSet m_twoHopNeighborSet;	///< 2-hop Neighbor Set (RFC 3626, section 4.3.2).
gjc@1716
    43
  TopologySet m_topologySet;	///< Topology Set (RFC 3626, section 4.4).
gjc@1716
    44
  MprSet m_mprSet;	///< MPR Set (RFC 3626, section 4.3.3).
gjc@1716
    45
  MprSelectorSet m_mprSelectorSet;	///< MPR Selector Set (RFC 3626, section 4.3.4).
gjc@1716
    46
  DuplicateSet m_duplicateSet;	///< Duplicate Set (RFC 3626, section 3.4).
gjc@1716
    47
  IfaceAssocSet m_ifaceAssocSet;	///< Interface Association Set (RFC 3626, section 4.1).
gjc@1716
    48
gjc@1716
    49
public:
gjc@1716
    50
gjc@2359
    51
  OlsrState ()
gjc@2359
    52
  {}
gjc@2359
    53
  
gjc@1716
    54
  // MPR selector
gjc@1716
    55
  const MprSelectorSet & GetMprSelectors () const
gjc@1716
    56
  {
gjc@1716
    57
    return m_mprSelectorSet;
gjc@1716
    58
  }
gjc@1716
    59
  MprSelectorTuple* FindMprSelectorTuple (const Ipv4Address &mainAddr);
gjc@1716
    60
  void EraseMprSelectorTuple (const MprSelectorTuple &tuple);
gjc@1716
    61
  void EraseMprSelectorTuples (const Ipv4Address &mainAddr);
gjc@1716
    62
  void InsertMprSelectorTuple (const MprSelectorTuple &tuple);
gjc@3970
    63
  std::string PrintMprSelectorSet () const;
gjc@1716
    64
gjc@1716
    65
  // Neighbor
gjc@1716
    66
  const NeighborSet & GetNeighbors () const
gjc@1716
    67
  {
gjc@1716
    68
    return m_neighborSet;
gjc@1716
    69
  }
gjc@2328
    70
  NeighborSet & GetNeighbors ()
gjc@2328
    71
  {
gjc@2328
    72
    return m_neighborSet;
gjc@2328
    73
  }
gjc@1716
    74
  NeighborTuple* FindNeighborTuple (const Ipv4Address &mainAddr);
gjc@1799
    75
  const NeighborTuple* FindSymNeighborTuple (const Ipv4Address &mainAddr) const;
gjc@1716
    76
  NeighborTuple* FindNeighborTuple (const Ipv4Address &mainAddr,
gjc@1716
    77
                                    uint8_t willingness);
gjc@1716
    78
  void EraseNeighborTuple (const NeighborTuple &neighborTuple);
gjc@1716
    79
  void EraseNeighborTuple (const Ipv4Address &mainAddr);
gjc@1716
    80
  void InsertNeighborTuple (const NeighborTuple &tuple);
gjc@1716
    81
gjc@1716
    82
  // Two-hop neighbor
gjc@1716
    83
  const TwoHopNeighborSet & GetTwoHopNeighbors () const
gjc@1716
    84
  {
gjc@1716
    85
    return m_twoHopNeighborSet;
gjc@1716
    86
  }
gjc@2328
    87
  TwoHopNeighborSet & GetTwoHopNeighbors ()
gjc@2328
    88
  {
gjc@2328
    89
    return m_twoHopNeighborSet;
gjc@2328
    90
  }
gjc@1716
    91
  TwoHopNeighborTuple* FindTwoHopNeighborTuple (const Ipv4Address &neighbor,
gjc@1716
    92
                                                const Ipv4Address &twoHopNeighbor);
gjc@1716
    93
  void EraseTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple);
gjc@1716
    94
  void EraseTwoHopNeighborTuples (const Ipv4Address &neighbor);
gjc@1716
    95
  void EraseTwoHopNeighborTuples (const Ipv4Address &neighbor,
gjc@1716
    96
                                  const Ipv4Address &twoHopNeighbor);
gjc@1716
    97
  void InsertTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple);
gjc@1716
    98
gjc@1716
    99
  // MPR
gjc@1716
   100
  bool FindMprAddress (const Ipv4Address &address);
gjc@2361
   101
  void SetMprSet (MprSet mprSet);
gjc@1716
   102
gjc@1716
   103
  // Duplicate
gjc@1716
   104
  DuplicateTuple* FindDuplicateTuple (const Ipv4Address &address,
gjc@1716
   105
                                      uint16_t sequenceNumber);
gjc@1716
   106
  void EraseDuplicateTuple (const DuplicateTuple &tuple);
gjc@1716
   107
  void InsertDuplicateTuple (const DuplicateTuple &tuple);
gjc@1716
   108
gjc@1716
   109
  // Link
gjc@1716
   110
  const LinkSet & GetLinks () const
gjc@1716
   111
  {
gjc@1716
   112
    return m_linkSet;
gjc@1716
   113
  }
gjc@1716
   114
  LinkTuple* FindLinkTuple (const Ipv4Address &ifaceAddr);
gjc@1716
   115
  LinkTuple* FindSymLinkTuple (const Ipv4Address &ifaceAddr, Time time);
gjc@1716
   116
  void EraseLinkTuple (const LinkTuple &tuple);
gjc@1716
   117
  LinkTuple& InsertLinkTuple (const LinkTuple &tuple);
gjc@1716
   118
gjc@1716
   119
  // Topology
gjc@1716
   120
  const TopologySet & GetTopologySet () const
gjc@1716
   121
  {
gjc@1716
   122
    return m_topologySet;
gjc@1716
   123
  }
gjc@1716
   124
  TopologyTuple* FindTopologyTuple (const Ipv4Address &destAddr,
gjc@1716
   125
                                    const Ipv4Address &lastAddr);
gjc@1716
   126
  TopologyTuple* FindNewerTopologyTuple (const Ipv4Address &lastAddr,
gjc@1716
   127
                                         uint16_t ansn);
gjc@1716
   128
  void EraseTopologyTuple (const TopologyTuple &tuple);
gjc@1716
   129
  void EraseOlderTopologyTuples (const Ipv4Address &lastAddr,
gjc@1716
   130
                                 uint16_t ansn);
gjc@1716
   131
  void InsertTopologyTuple (const TopologyTuple &tuple);
gjc@1716
   132
gjc@1716
   133
  // Interface association
gjc@1716
   134
  const IfaceAssocSet & GetIfaceAssocSet () const
gjc@1716
   135
  {
gjc@1716
   136
    return m_ifaceAssocSet;
gjc@1716
   137
  }
gjc@1716
   138
  IfaceAssocSet & GetIfaceAssocSetMutable ()
gjc@1716
   139
  {
gjc@1716
   140
    return m_ifaceAssocSet;
gjc@1716
   141
  }
gjc@1716
   142
  IfaceAssocTuple* FindIfaceAssocTuple (const Ipv4Address &ifaceAddr);
gjc@1798
   143
  const IfaceAssocTuple* FindIfaceAssocTuple (const Ipv4Address &ifaceAddr) const;
gjc@1716
   144
  void EraseIfaceAssocTuple (const IfaceAssocTuple &tuple);
gjc@1716
   145
  void InsertIfaceAssocTuple (const IfaceAssocTuple &tuple);
gjc@1716
   146
gjc@1716
   147
  // Returns a vector of all interfaces of a given neighbor, with the
gjc@1716
   148
  // exception of the "main" one.
gjc@1716
   149
  std::vector<Ipv4Address>
gjc@1716
   150
  FindNeighborInterfaces (const Ipv4Address &neighborMainAddr) const;
gjc@1716
   151
gjc@1716
   152
};
gjc@1716
   153
gjc@1731
   154
} // namespace ns3
gjc@1716
   155
gjc@1716
   156
#endif