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