Fix a couple of OLSR bugs (#415)
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Tue Dec 02 18:42:24 2008 +0000 (2008-12-02)
changeset 39708658841e4782
parent 3969 1db8fca96193
child 3971 d97b4527ec9b
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.
src/routing/olsr/olsr-agent-impl.cc
src/routing/olsr/olsr-agent-impl.h
src/routing/olsr/olsr-state.cc
src/routing/olsr/olsr-state.h
     1.1 --- a/src/routing/olsr/olsr-agent-impl.cc	Tue Dec 02 07:42:33 2008 -0800
     1.2 +++ b/src/routing/olsr/olsr-agent-impl.cc	Tue Dec 02 18:42:24 2008 +0000
     1.3 @@ -29,6 +29,10 @@
     1.4  /// implemented here.
     1.5  ///
     1.6  
     1.7 +#define NS_LOG_APPEND_CONTEXT                                   \
     1.8 +  if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId () << "] "; }
     1.9 +
    1.10 +
    1.11  #include "olsr-agent-impl.h"
    1.12  #include "ns3/socket-factory.h"
    1.13  #include "ns3/udp-socket-factory.h"
    1.14 @@ -343,8 +347,6 @@
    1.15  
    1.16    m_rxPacketTrace (olsrPacketHeader, messages);
    1.17  
    1.18 -  m_state.SetModified (false);
    1.19 -
    1.20    for (MessageList::const_iterator messageIter = messages.begin ();
    1.21         messageIter != messages.end (); messageIter++)
    1.22      {
    1.23 @@ -441,11 +443,7 @@
    1.24      }
    1.25  
    1.26    // After processing all OLSR messages, we must recompute the routing table
    1.27 -  if (m_state.GetModified ())
    1.28 -    {
    1.29 -      RoutingTableComputation ();
    1.30 -      m_state.SetModified (false);
    1.31 -    }
    1.32 +  RoutingTableComputation ();
    1.33  }
    1.34  
    1.35  ///
    1.36 @@ -464,7 +462,7 @@
    1.37        TwoHopNeighborTuple const &nb2hop_tuple = *it;
    1.38        if (nb2hop_tuple.neighborMainAddr == tuple.neighborMainAddr)
    1.39          {
    1.40 -          NeighborTuple *nb_tuple =
    1.41 +          const NeighborTuple *nb_tuple =
    1.42              m_state.FindNeighborTuple (nb2hop_tuple.neighborMainAddr);
    1.43            if (nb_tuple == NULL)
    1.44              degree++;
    1.45 @@ -479,6 +477,8 @@
    1.46  void
    1.47  AgentImpl::MprComputation()
    1.48  {
    1.49 +  NS_LOG_FUNCTION (this);
    1.50 +  
    1.51    // MPR computation should be done for each interface. See section 8.3.1
    1.52    // (RFC 3626) for details.
    1.53    MprSet mprSet;
    1.54 @@ -557,6 +557,8 @@
    1.55          }
    1.56      }
    1.57  
    1.58 +  NS_LOG_DEBUG ("Size of N2: " << N2.size ());  
    1.59 +
    1.60    // 1. Start with an MPR set made of all members of N with
    1.61    // N_willingness equal to WILL_ALWAYS
    1.62    for (NeighborSet::const_iterator neighbor = N.begin (); neighbor != N.end (); neighbor++)
    1.63 @@ -714,8 +716,25 @@
    1.64          }
    1.65      }
    1.66  
    1.67 +#ifdef NS3_LOG_ENABLE
    1.68 +  {
    1.69 +    std::ostringstream os;
    1.70 +    os << "[";
    1.71 +    for (MprSet::const_iterator iter = mprSet.begin ();
    1.72 +         iter != mprSet.end (); iter++)
    1.73 +      {
    1.74 +        MprSet::const_iterator next = iter;
    1.75 +        next++;
    1.76 +        os << *iter;
    1.77 +        if (next != mprSet.end ())
    1.78 +          os << ", ";
    1.79 +      }
    1.80 +    os << "]";
    1.81 +    NS_LOG_DEBUG ("Computed MPR set for node " << m_mainAddress << ": " << os.str ());
    1.82 +  }
    1.83 +#endif
    1.84 +
    1.85    m_state.SetMprSet (mprSet);
    1.86 -
    1.87  }
    1.88  
    1.89  ///
    1.90 @@ -1056,7 +1075,7 @@
    1.91  	
    1.92    // 1. If the sender interface of this message is not in the symmetric
    1.93    // 1-hop neighborhood of this node, the message MUST be discarded.
    1.94 -  LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now);
    1.95 +  const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now);
    1.96    if (link_tuple == NULL)
    1.97      return;
    1.98  	
    1.99 @@ -1065,7 +1084,7 @@
   1.100    // 	T_seq       >  ANSN,
   1.101    // then further processing of this TC message MUST NOT be
   1.102    // performed.
   1.103 -  TopologyTuple *topologyTuple =
   1.104 +  const TopologyTuple *topologyTuple =
   1.105      m_state.FindNewerTopologyTuple (msg.GetOriginatorAddress (), tc.ansn);
   1.106    if (topologyTuple != NULL)
   1.107      return;
   1.108 @@ -1152,7 +1171,7 @@
   1.109    NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface);
   1.110    // 1. If the sender interface of this message is not in the symmetric
   1.111    // 1-hop neighborhood of this node, the message MUST be discarded.
   1.112 -  LinkTuple *linkTuple = m_state.FindSymLinkTuple (senderIface, now);
   1.113 +  const LinkTuple *linkTuple = m_state.FindSymLinkTuple (senderIface, now);
   1.114    if (linkTuple == NULL)
   1.115      {
   1.116        NS_LOG_LOGIC ("Node " << m_mainAddress <<
   1.117 @@ -1234,7 +1253,7 @@
   1.118    
   1.119    // If the sender interface address is not in the symmetric
   1.120    // 1-hop neighborhood the message must not be forwarded
   1.121 -  LinkTuple *linkTuple = m_state.FindSymLinkTuple (senderAddress, now);
   1.122 +  const LinkTuple *linkTuple = m_state.FindSymLinkTuple (senderAddress, now);
   1.123    if (linkTuple == NULL)
   1.124      return;
   1.125  
   1.126 @@ -1253,7 +1272,7 @@
   1.127    bool retransmitted = false;
   1.128    if (olsrMessage.GetTimeToLive () > 1)
   1.129      {
   1.130 -      MprSelectorTuple *mprselTuple =
   1.131 +      const MprSelectorTuple *mprselTuple =
   1.132          m_state.FindMprSelectorTuple (GetMainAddress (senderAddress));
   1.133        if (mprselTuple != NULL)
   1.134          {
   1.135 @@ -1378,6 +1397,8 @@
   1.136  void
   1.137  AgentImpl::SendHello ()
   1.138  {
   1.139 +  NS_LOG_FUNCTION (this);
   1.140 +  
   1.141    olsr::MessageHeader msg;
   1.142    Time now = Simulator::Now ();
   1.143  
   1.144 @@ -1423,6 +1444,8 @@
   1.145        if (m_state.FindMprAddress (GetMainAddress (link_tuple->neighborIfaceAddr)))
   1.146          {
   1.147            nb_type = OLSR_MPR_NEIGH;
   1.148 +          NS_LOG_DEBUG ("I consider neighbor " << GetMainAddress (link_tuple->neighborIfaceAddr)
   1.149 +                        << " to be MPR_NEIGH.");
   1.150          }
   1.151        else
   1.152          {
   1.153 @@ -1435,11 +1458,15 @@
   1.154                  {
   1.155                    if (nb_tuple->status == NeighborTuple::STATUS_SYM)
   1.156                      {
   1.157 +                      NS_LOG_DEBUG ("I consider neighbor " << GetMainAddress (link_tuple->neighborIfaceAddr)
   1.158 +                                    << " to be SYM_NEIGH.");
   1.159                        nb_type = OLSR_SYM_NEIGH;
   1.160                      }
   1.161                    else if (nb_tuple->status == NeighborTuple::STATUS_NOT_SYM)
   1.162                      {
   1.163                        nb_type = OLSR_NOT_NEIGH;
   1.164 +                      NS_LOG_DEBUG ("I consider neighbor " << GetMainAddress (link_tuple->neighborIfaceAddr)
   1.165 +                                    << " to be NOT_NEIGH.");
   1.166                      }
   1.167                    else
   1.168                      {
   1.169 @@ -1451,6 +1478,7 @@
   1.170              }
   1.171            if (!ok)
   1.172              {
   1.173 +              NS_LOG_WARN ("I don't know the neighbor " << GetMainAddress (link_tuple->neighborIfaceAddr) << "!!!");
   1.174                continue;
   1.175              }
   1.176          }
   1.177 @@ -1480,6 +1508,8 @@
   1.178  void
   1.179  AgentImpl::SendTc ()
   1.180  {
   1.181 +  NS_LOG_FUNCTION (this);
   1.182 +  
   1.183    olsr::MessageHeader msg;
   1.184  
   1.185    msg.SetVTime (OLSR_TOP_HOLD_TIME);
   1.186 @@ -1662,7 +1692,7 @@
   1.187  
   1.188    if (updated)
   1.189      {
   1.190 -      LinkTupleUpdated (*link_tuple);
   1.191 +      LinkTupleUpdated (*link_tuple, hello.willingness);
   1.192      }
   1.193  
   1.194    // Schedules link tuple deletion
   1.195 @@ -1686,7 +1716,9 @@
   1.196  {
   1.197    NeighborTuple *nb_tuple = m_state.FindNeighborTuple (msg.GetOriginatorAddress ());
   1.198    if (nb_tuple != NULL)
   1.199 -    nb_tuple->willingness = hello.willingness;
   1.200 +    {
   1.201 +      nb_tuple->willingness = hello.willingness;
   1.202 +    }
   1.203  }
   1.204  
   1.205  
   1.206 @@ -1809,6 +1841,8 @@
   1.207  AgentImpl::PopulateMprSelectorSet (const olsr::MessageHeader &msg,
   1.208                                         const olsr::MessageHeader::Hello &hello)
   1.209  {
   1.210 +  NS_LOG_FUNCTION (this);
   1.211 +  
   1.212    Time now = Simulator::Now ();
   1.213  	
   1.214    typedef std::vector<olsr::MessageHeader::Hello::LinkMessage> LinkMessageVec;
   1.215 @@ -1819,6 +1853,8 @@
   1.216        int nt = linkMessage->linkCode >> 2;
   1.217        if (nt == OLSR_MPR_NEIGH)
   1.218          {
   1.219 +          NS_LOG_DEBUG ("Processing a link message with neighbor type MPR_NEIGH");
   1.220 +          
   1.221            for (std::vector<Ipv4Address>::const_iterator nb_iface_addr =
   1.222                   linkMessage->neighborInterfaceAddresses.begin ();
   1.223                 nb_iface_addr != linkMessage->neighborInterfaceAddresses.end ();
   1.224 @@ -1826,6 +1862,8 @@
   1.225              {
   1.226                if (GetMainAddress (*nb_iface_addr) == m_mainAddress)
   1.227                  {
   1.228 +                  NS_LOG_DEBUG ("Adding entry to mpr selector set for neighbor " << *nb_iface_addr);
   1.229 +                  
   1.230                    // We must create a new entry into the mpr selector set
   1.231                    MprSelectorTuple *existing_mprsel_tuple =
   1.232                      m_state.FindMprSelectorTuple (msg.GetOriginatorAddress ());
   1.233 @@ -1851,6 +1889,7 @@
   1.234              }
   1.235          }
   1.236      }
   1.237 +  NS_LOG_DEBUG ("Computed MPR selector set for node " << m_mainAddress << ": " << m_state.PrintMprSelectorSet ());
   1.238  }
   1.239  
   1.240  
   1.241 @@ -1904,7 +1943,7 @@
   1.242    NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
   1.243                  << "s: OLSR Node " << m_mainAddress
   1.244                  << " LinkTuple " << tuple.neighborIfaceAddr << " -> neighbor loss.");
   1.245 -  LinkTupleUpdated (tuple);
   1.246 +  LinkTupleUpdated (tuple, OLSR_WILL_DEFAULT);
   1.247    m_state.EraseTwoHopNeighborTuples (GetMainAddress (tuple.neighborIfaceAddr));
   1.248    m_state.EraseMprSelectorTuples (GetMainAddress (tuple.neighborIfaceAddr));
   1.249    
   1.250 @@ -1988,7 +2027,7 @@
   1.251  /// \param tuple the link tuple which has been updated.
   1.252  ///
   1.253  void
   1.254 -AgentImpl::LinkTupleUpdated (const LinkTuple &tuple)
   1.255 +AgentImpl::LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness)
   1.256  {
   1.257    // Each time a link tuple changes, the associated neighbor tuple must be recomputed
   1.258  
   1.259 @@ -1998,6 +2037,12 @@
   1.260  
   1.261    NeighborTuple *nb_tuple =
   1.262      m_state.FindNeighborTuple (GetMainAddress (tuple.neighborIfaceAddr));
   1.263 +  
   1.264 +  if (nb_tuple == NULL)
   1.265 +    {
   1.266 +      LinkTupleAdded (tuple, willingness);
   1.267 +      nb_tuple = m_state.FindNeighborTuple (GetMainAddress (tuple.neighborIfaceAddr));
   1.268 +    }
   1.269  
   1.270    if (nb_tuple != NULL)
   1.271      {
   1.272 @@ -2017,6 +2062,10 @@
   1.273                          << int (statusBefore != nb_tuple->status));
   1.274          }
   1.275      }
   1.276 +  else
   1.277 +    {
   1.278 +      NS_LOG_WARN ("ERROR! Wanted to update a NeighborTuple but none was found!");
   1.279 +    }
   1.280  }
   1.281  
   1.282  ///
   1.283 @@ -2240,6 +2289,10 @@
   1.284      {
   1.285        SendTc ();
   1.286      }
   1.287 +  else
   1.288 +    {
   1.289 +      NS_LOG_DEBUG ("Not sending any TC, no one selected me as MPR.");
   1.290 +    }
   1.291    m_tcTimer.Schedule (m_tcInterval);
   1.292  }
   1.293  
     2.1 --- a/src/routing/olsr/olsr-agent-impl.h	Tue Dec 02 07:42:33 2008 -0800
     2.2 +++ b/src/routing/olsr/olsr-agent-impl.h	Tue Dec 02 18:42:24 2008 +0000
     2.3 @@ -144,7 +144,7 @@
     2.4    void RemoveDuplicateTuple (const DuplicateTuple &tuple);
     2.5    void LinkTupleAdded (const LinkTuple &tuple, uint8_t willingness);
     2.6    void RemoveLinkTuple (const LinkTuple &tuple);
     2.7 -  void LinkTupleUpdated (const LinkTuple &tuple);
     2.8 +  void LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness);
     2.9    void AddNeighborTuple (const NeighborTuple &tuple);
    2.10    void RemoveNeighborTuple (const NeighborTuple &tuple);
    2.11    void AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple);
     3.1 --- a/src/routing/olsr/olsr-state.cc	Tue Dec 02 07:42:33 2008 -0800
     3.2 +++ b/src/routing/olsr/olsr-state.cc	Tue Dec 02 18:42:24 2008 +0000
     3.3 @@ -83,6 +83,25 @@
     3.4    m_mprSelectorSet.push_back (tuple);
     3.5  }
     3.6  
     3.7 +std::string
     3.8 +OlsrState::PrintMprSelectorSet () const
     3.9 +{
    3.10 +  std::ostringstream os;
    3.11 +  os << "[";
    3.12 +  for (MprSelectorSet::const_iterator iter = m_mprSelectorSet.begin ();
    3.13 +       iter != m_mprSelectorSet.end (); iter++)
    3.14 +    {
    3.15 +      MprSelectorSet::const_iterator next = iter;
    3.16 +      next++;
    3.17 +      os << iter->mainAddr;
    3.18 +      if (next != m_mprSelectorSet.end ())
    3.19 +        os << ", ";
    3.20 +    }
    3.21 +  os << "]";
    3.22 +  return os.str ();
    3.23 +}
    3.24 +  
    3.25 +
    3.26  /********** Neighbor Set Manipulation **********/
    3.27  
    3.28  NeighborTuple*
    3.29 @@ -130,7 +149,6 @@
    3.30        if (*it == tuple)
    3.31          {
    3.32            m_neighborSet.erase (it);
    3.33 -          m_modified = true;
    3.34            break;
    3.35          }
    3.36      }
    3.37 @@ -145,7 +163,6 @@
    3.38        if (it->neighborMainAddr == mainAddr)
    3.39          {
    3.40            it = m_neighborSet.erase (it);
    3.41 -          m_modified = true;
    3.42            break;
    3.43          }
    3.44      }
    3.45 @@ -161,7 +178,6 @@
    3.46          {
    3.47            // Update it
    3.48            *it = tuple;
    3.49 -          m_modified = true;
    3.50            return;
    3.51          }
    3.52      }
    3.53 @@ -195,7 +211,6 @@
    3.54        if (*it == tuple)
    3.55          {
    3.56            m_twoHopNeighborSet.erase(it);
    3.57 -          m_modified = true;
    3.58            break;
    3.59          }
    3.60      }
    3.61 @@ -212,7 +227,6 @@
    3.62            && it->twoHopNeighborAddr == twoHopNeighborAddr)
    3.63          {
    3.64            it = m_twoHopNeighborSet.erase (it);
    3.65 -          m_modified = true;
    3.66          }
    3.67        else
    3.68          {
    3.69 @@ -230,7 +244,6 @@
    3.70        if (it->neighborMainAddr == neighborMainAddr)
    3.71          {
    3.72            it = m_twoHopNeighborSet.erase (it);
    3.73 -          m_modified = true;
    3.74          }
    3.75        else
    3.76          {
    3.77 @@ -243,7 +256,6 @@
    3.78  OlsrState::InsertTwoHopNeighborTuple (TwoHopNeighborTuple const &tuple)
    3.79  {
    3.80    m_twoHopNeighborSet.push_back (tuple);
    3.81 -  m_modified = true;
    3.82  }
    3.83  
    3.84  /********** MPR Set Manipulation **********/
    3.85 @@ -335,7 +347,6 @@
    3.86        if (*it == tuple)
    3.87          {
    3.88            m_linkSet.erase (it);
    3.89 -          m_modified = true;
    3.90            break;
    3.91          }
    3.92      }
    3.93 @@ -345,7 +356,6 @@
    3.94  OlsrState::InsertLinkTuple (LinkTuple const &tuple)
    3.95  {
    3.96    m_linkSet.push_back (tuple);
    3.97 -  m_modified = true;
    3.98    return m_linkSet.back ();
    3.99  }
   3.100  
   3.101 @@ -385,7 +395,6 @@
   3.102        if (*it == tuple)
   3.103          {
   3.104            m_topologySet.erase (it);
   3.105 -          m_modified = true;
   3.106            break;
   3.107          }
   3.108      }
   3.109 @@ -400,7 +409,6 @@
   3.110        if (it->lastAddr == lastAddr && it->sequenceNumber < ansn)
   3.111          {
   3.112            it = m_topologySet.erase (it);
   3.113 -          m_modified = true;
   3.114          }
   3.115        else
   3.116          {
   3.117 @@ -413,7 +421,6 @@
   3.118  OlsrState::InsertTopologyTuple (TopologyTuple const &tuple)
   3.119  {
   3.120    m_topologySet.push_back (tuple);
   3.121 -  m_modified = true;
   3.122  }
   3.123  
   3.124  /********** Interface Association Set Manipulation **********/
   3.125 @@ -451,7 +458,6 @@
   3.126        if (*it == tuple)
   3.127          {
   3.128            m_ifaceAssocSet.erase (it);
   3.129 -          m_modified = true;
   3.130            break;
   3.131          }
   3.132      }
   3.133 @@ -461,7 +467,6 @@
   3.134  OlsrState::InsertIfaceAssocTuple (const IfaceAssocTuple &tuple)
   3.135  {
   3.136    m_ifaceAssocSet.push_back (tuple);
   3.137 -  m_modified = true;
   3.138  }
   3.139  
   3.140  std::vector<Ipv4Address>
     4.1 --- a/src/routing/olsr/olsr-state.h	Tue Dec 02 07:42:33 2008 -0800
     4.2 +++ b/src/routing/olsr/olsr-state.h	Tue Dec 02 18:42:24 2008 +0000
     4.3 @@ -46,29 +46,11 @@
     4.4    DuplicateSet m_duplicateSet;	///< Duplicate Set (RFC 3626, section 3.4).
     4.5    IfaceAssocSet m_ifaceAssocSet;	///< Interface Association Set (RFC 3626, section 4.1).
     4.6  
     4.7 -// m_modified is set to true when any of the following databases is modified:
     4.8 -//      -    the link set,
     4.9 -//      -    the neighbor set,
    4.10 -//      -    the 2-hop neighbor set,
    4.11 -//      -    the topology set,
    4.12 -//      -    the Multiple Interface Association Information Base,
    4.13 -  bool m_modified;
    4.14 -
    4.15  public:
    4.16  
    4.17    OlsrState ()
    4.18 -    : m_modified (false)
    4.19    {}
    4.20    
    4.21 -  bool GetModified () const
    4.22 -  {
    4.23 -    return m_modified;
    4.24 -  }
    4.25 -  void SetModified (bool modified)
    4.26 -  {
    4.27 -    m_modified = modified;
    4.28 -  }
    4.29 -
    4.30    // MPR selector
    4.31    const MprSelectorSet & GetMprSelectors () const
    4.32    {
    4.33 @@ -78,6 +60,7 @@
    4.34    void EraseMprSelectorTuple (const MprSelectorTuple &tuple);
    4.35    void EraseMprSelectorTuples (const Ipv4Address &mainAddr);
    4.36    void InsertMprSelectorTuple (const MprSelectorTuple &tuple);
    4.37 +  std::string PrintMprSelectorSet () const;
    4.38  
    4.39    // Neighbor
    4.40    const NeighborSet & GetNeighbors () const