src/routing/olsr/olsr-agent-impl.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 3853 f04e7f61b1ed
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 
    24 #ifndef __OLSR_AGENT_IMPL_H__
    25 #define __OLSR_AGENT_IMPL_H__
    26 
    27 #include <vector>
    28 
    29 #include "olsr-agent.h"
    30 #include "olsr-header.h"
    31 #include "olsr-state.h"
    32 
    33 #include "olsr-routing-table.h"
    34 #include "repositories.h"
    35 
    36 #include "ns3/object.h"
    37 #include "ns3/packet.h"
    38 #include "ns3/node.h"
    39 #include "ns3/socket.h"
    40 #include "ns3/event-garbage-collector.h"
    41 #include "ns3/timer.h"
    42 #include "ns3/traced-callback.h"
    43 
    44 
    45 namespace ns3 {
    46 namespace olsr {
    47 
    48 
    49 class AgentImpl : public Agent
    50 {
    51 public:
    52   static TypeId GetTypeId (void);
    53 
    54   AgentImpl ();
    55   virtual ~AgentImpl ();
    56 
    57   virtual void SetNode (Ptr<Node> node);
    58 
    59   virtual void Start ();
    60   virtual void SetMainInterface (uint32_t interface);
    61   virtual Ptr<const olsr::RoutingTable> GetRoutingTable () const;
    62 
    63 private:
    64   EventGarbageCollector m_events;
    65 
    66   /// Address of the routing agent.
    67   Ipv4Address m_routingAgentAddr;
    68 	
    69   /// Packets sequence number counter.
    70   uint16_t m_packetSequenceNumber;
    71   /// Messages sequence number counter.
    72   uint16_t m_messageSequenceNumber;
    73   /// Advertised Neighbor Set sequence number.
    74   uint16_t m_ansn;
    75   
    76   /// HELLO messages' emission interval.
    77   Time m_helloInterval;
    78   /// TC messages' emission interval.
    79   Time m_tcInterval;
    80   /// MID messages' emission interval.
    81   Time m_midInterval;
    82   /// Willingness for forwarding packets on behalf of other nodes.
    83   uint8_t m_willingness;
    84 	
    85   /// Routing table.
    86   Ptr<RoutingTable> m_routingTable;
    87   /// Internal state with all needed data structs.
    88   OlsrState m_state;
    89 
    90   Ptr<Ipv4> m_ipv4;
    91 	
    92 protected:
    93   void DoDispose ();
    94 
    95   void SendPacket (Ptr<Packet> packet, const MessageList &containedMessages);
    96 	
    97   /// Increments packet sequence number and returns the new value.
    98   inline uint16_t GetPacketSequenceNumber ();
    99   /// Increments message sequence number and returns the new value.
   100   inline uint16_t GetMessageSequenceNumber ();
   101 	
   102   void RecvOlsr (Ptr<Socket> socket);
   103 
   104   void MprComputation ();
   105   void RoutingTableComputation ();
   106   Ipv4Address GetMainAddress (Ipv4Address iface_addr) const;
   107 
   108   // Timer handlers
   109   Timer m_helloTimer;
   110   void HelloTimerExpire ();
   111   
   112   Timer m_tcTimer;
   113   void TcTimerExpire ();
   114 
   115   Timer m_midTimer;
   116   void MidTimerExpire ();
   117 
   118   void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber);
   119   bool m_linkTupleTimerFirstTime;
   120   void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr);
   121   void Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr);
   122   void MprSelTupleTimerExpire (Ipv4Address mainAddr);
   123   void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr);
   124   void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr);
   125 
   126   void IncrementAnsn ();
   127 
   128   /// A list of pending messages which are buffered awaiting for being sent.
   129   olsr::MessageList m_queuedMessages;
   130   Timer m_queuedMessagesTimer; // timer for throttling outgoing messages
   131 
   132   void ForwardDefault (olsr::MessageHeader olsrMessage,
   133                        DuplicateTuple *duplicated,
   134                        const Ipv4Address &localIface,
   135                        const Ipv4Address &senderAddress);
   136   void QueueMessage (const olsr::MessageHeader &message, Time delay);
   137   void SendQueuedMessages ();
   138   void SendHello ();
   139   void SendTc ();
   140   void SendMid ();
   141 
   142   void NeighborLoss (const LinkTuple &tuple);
   143   void AddDuplicateTuple (const DuplicateTuple &tuple);
   144   void RemoveDuplicateTuple (const DuplicateTuple &tuple);
   145   void LinkTupleAdded (const LinkTuple &tuple, uint8_t willingness);
   146   void RemoveLinkTuple (const LinkTuple &tuple);
   147   void LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness);
   148   void AddNeighborTuple (const NeighborTuple &tuple);
   149   void RemoveNeighborTuple (const NeighborTuple &tuple);
   150   void AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple);
   151   void RemoveTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple);
   152   void AddMprSelectorTuple (const MprSelectorTuple  &tuple);
   153   void RemoveMprSelectorTuple (const MprSelectorTuple &tuple);
   154   void AddTopologyTuple (const TopologyTuple &tuple);
   155   void RemoveTopologyTuple (const TopologyTuple &tuple);
   156   void AddIfaceAssocTuple (const IfaceAssocTuple &tuple);
   157   void RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple);
   158 
   159   void ProcessHello (const olsr::MessageHeader &msg,
   160                      const Ipv4Address &receiverIface,
   161                      const Ipv4Address &senderIface);
   162   void ProcessTc (const olsr::MessageHeader &msg,
   163                   const Ipv4Address &senderIface);
   164   void ProcessMid (const olsr::MessageHeader &msg,
   165                    const Ipv4Address &senderIface);
   166 
   167   void LinkSensing (const olsr::MessageHeader &msg,
   168                     const olsr::MessageHeader::Hello &hello,
   169                     const Ipv4Address &receiverIface,
   170                     const Ipv4Address &sender_iface);
   171   void PopulateNeighborSet (const olsr::MessageHeader &msg,
   172                             const olsr::MessageHeader::Hello &hello);
   173   void PopulateTwoHopNeighborSet (const olsr::MessageHeader &msg,
   174                                   const olsr::MessageHeader::Hello &hello);
   175   void PopulateMprSelectorSet (const olsr::MessageHeader &msg,
   176                                const olsr::MessageHeader::Hello &hello);
   177 
   178   int Degree (NeighborTuple const &tuple);
   179 
   180   Ipv4Address m_mainAddress;
   181 
   182   // One socket per interface, each bound to that interface's address
   183   // (reason: for OLSR Link Sensing we need to know on which interface
   184   // HELLO messages arrive)
   185   std::map< Ptr<Socket>, Ipv4Address > m_socketAddresses;
   186 
   187   TracedCallback <const PacketHeader &,
   188                   const MessageList &> m_rxPacketTrace;
   189   TracedCallback <const PacketHeader &,
   190                   const MessageList &> m_txPacketTrace;
   191   TracedCallback <uint32_t> m_routingTableChanged;
   192 
   193 };
   194 
   195 }} // namespace ns3
   196 
   197 #endif