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.
     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 
    23 /// \brief	This header file declares and defines internal state of an OLSR node.
    24 
    25 #ifndef __OLSR_STATE_H__
    26 #define __OLSR_STATE_H__
    27 
    28 #include "repositories.h"
    29 
    30 namespace ns3 {
    31 
    32 using namespace olsr;
    33 
    34 /// This class encapsulates all data structures needed for maintaining internal state of an OLSR node.
    35 class OlsrState
    36 {
    37   //  friend class Olsr;
    38   
    39 protected:
    40   LinkSet m_linkSet;	///< Link Set (RFC 3626, section 4.2.1).
    41   NeighborSet m_neighborSet;		///< Neighbor Set (RFC 3626, section 4.3.1).
    42   TwoHopNeighborSet m_twoHopNeighborSet;	///< 2-hop Neighbor Set (RFC 3626, section 4.3.2).
    43   TopologySet m_topologySet;	///< Topology Set (RFC 3626, section 4.4).
    44   MprSet m_mprSet;	///< MPR Set (RFC 3626, section 4.3.3).
    45   MprSelectorSet m_mprSelectorSet;	///< MPR Selector Set (RFC 3626, section 4.3.4).
    46   DuplicateSet m_duplicateSet;	///< Duplicate Set (RFC 3626, section 3.4).
    47   IfaceAssocSet m_ifaceAssocSet;	///< Interface Association Set (RFC 3626, section 4.1).
    48 
    49 public:
    50 
    51   OlsrState ()
    52   {}
    53   
    54   // MPR selector
    55   const MprSelectorSet & GetMprSelectors () const
    56   {
    57     return m_mprSelectorSet;
    58   }
    59   MprSelectorTuple* FindMprSelectorTuple (const Ipv4Address &mainAddr);
    60   void EraseMprSelectorTuple (const MprSelectorTuple &tuple);
    61   void EraseMprSelectorTuples (const Ipv4Address &mainAddr);
    62   void InsertMprSelectorTuple (const MprSelectorTuple &tuple);
    63   std::string PrintMprSelectorSet () const;
    64 
    65   // Neighbor
    66   const NeighborSet & GetNeighbors () const
    67   {
    68     return m_neighborSet;
    69   }
    70   NeighborSet & GetNeighbors ()
    71   {
    72     return m_neighborSet;
    73   }
    74   NeighborTuple* FindNeighborTuple (const Ipv4Address &mainAddr);
    75   const NeighborTuple* FindSymNeighborTuple (const Ipv4Address &mainAddr) const;
    76   NeighborTuple* FindNeighborTuple (const Ipv4Address &mainAddr,
    77                                     uint8_t willingness);
    78   void EraseNeighborTuple (const NeighborTuple &neighborTuple);
    79   void EraseNeighborTuple (const Ipv4Address &mainAddr);
    80   void InsertNeighborTuple (const NeighborTuple &tuple);
    81 
    82   // Two-hop neighbor
    83   const TwoHopNeighborSet & GetTwoHopNeighbors () const
    84   {
    85     return m_twoHopNeighborSet;
    86   }
    87   TwoHopNeighborSet & GetTwoHopNeighbors ()
    88   {
    89     return m_twoHopNeighborSet;
    90   }
    91   TwoHopNeighborTuple* FindTwoHopNeighborTuple (const Ipv4Address &neighbor,
    92                                                 const Ipv4Address &twoHopNeighbor);
    93   void EraseTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple);
    94   void EraseTwoHopNeighborTuples (const Ipv4Address &neighbor);
    95   void EraseTwoHopNeighborTuples (const Ipv4Address &neighbor,
    96                                   const Ipv4Address &twoHopNeighbor);
    97   void InsertTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple);
    98 
    99   // MPR
   100   bool FindMprAddress (const Ipv4Address &address);
   101   void SetMprSet (MprSet mprSet);
   102 
   103   // Duplicate
   104   DuplicateTuple* FindDuplicateTuple (const Ipv4Address &address,
   105                                       uint16_t sequenceNumber);
   106   void EraseDuplicateTuple (const DuplicateTuple &tuple);
   107   void InsertDuplicateTuple (const DuplicateTuple &tuple);
   108 
   109   // Link
   110   const LinkSet & GetLinks () const
   111   {
   112     return m_linkSet;
   113   }
   114   LinkTuple* FindLinkTuple (const Ipv4Address &ifaceAddr);
   115   LinkTuple* FindSymLinkTuple (const Ipv4Address &ifaceAddr, Time time);
   116   void EraseLinkTuple (const LinkTuple &tuple);
   117   LinkTuple& InsertLinkTuple (const LinkTuple &tuple);
   118 
   119   // Topology
   120   const TopologySet & GetTopologySet () const
   121   {
   122     return m_topologySet;
   123   }
   124   TopologyTuple* FindTopologyTuple (const Ipv4Address &destAddr,
   125                                     const Ipv4Address &lastAddr);
   126   TopologyTuple* FindNewerTopologyTuple (const Ipv4Address &lastAddr,
   127                                          uint16_t ansn);
   128   void EraseTopologyTuple (const TopologyTuple &tuple);
   129   void EraseOlderTopologyTuples (const Ipv4Address &lastAddr,
   130                                  uint16_t ansn);
   131   void InsertTopologyTuple (const TopologyTuple &tuple);
   132 
   133   // Interface association
   134   const IfaceAssocSet & GetIfaceAssocSet () const
   135   {
   136     return m_ifaceAssocSet;
   137   }
   138   IfaceAssocSet & GetIfaceAssocSetMutable ()
   139   {
   140     return m_ifaceAssocSet;
   141   }
   142   IfaceAssocTuple* FindIfaceAssocTuple (const Ipv4Address &ifaceAddr);
   143   const IfaceAssocTuple* FindIfaceAssocTuple (const Ipv4Address &ifaceAddr) const;
   144   void EraseIfaceAssocTuple (const IfaceAssocTuple &tuple);
   145   void InsertIfaceAssocTuple (const IfaceAssocTuple &tuple);
   146 
   147   // Returns a vector of all interfaces of a given neighbor, with the
   148   // exception of the "main" one.
   149   std::vector<Ipv4Address>
   150   FindNeighborInterfaces (const Ipv4Address &neighborMainAddr) const;
   151 
   152 };
   153 
   154 } // namespace ns3
   155 
   156 #endif