src/routing/olsr/olsr-agent-impl.cc
changeset 3970 8658841e4782
parent 3853 f04e7f61b1ed
child 4218 debf1a8a96d3
     1.1 --- a/src/routing/olsr/olsr-agent-impl.cc	Fri Nov 07 19:51:00 2008 +0000
     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