1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2004 Francisco J. Ros
4 * Copyright (c) 2007 INESC Porto
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;
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.
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
19 * Authors: Francisco J. Ros <fjrm@dif.um.es>
20 * Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
24 #ifndef __OLSR_AGENT_IMPL_H__
25 #define __OLSR_AGENT_IMPL_H__
29 #include "olsr-agent.h"
30 #include "olsr-header.h"
31 #include "olsr-state.h"
33 #include "olsr-routing-table.h"
34 #include "repositories.h"
36 #include "ns3/object.h"
37 #include "ns3/packet.h"
39 #include "ns3/socket.h"
40 #include "ns3/event-garbage-collector.h"
41 #include "ns3/timer.h"
42 #include "ns3/traced-callback.h"
49 class AgentImpl : public Agent
52 static TypeId GetTypeId (void);
55 virtual ~AgentImpl ();
57 virtual void SetNode (Ptr<Node> node);
59 virtual void Start ();
60 virtual void SetMainInterface (uint32_t interface);
61 virtual Ptr<const olsr::RoutingTable> GetRoutingTable () const;
64 EventGarbageCollector m_events;
66 /// Address of the routing agent.
67 Ipv4Address m_routingAgentAddr;
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.
76 /// HELLO messages' emission interval.
78 /// TC messages' emission interval.
80 /// MID messages' emission interval.
82 /// Willingness for forwarding packets on behalf of other nodes.
83 uint8_t m_willingness;
86 Ptr<RoutingTable> m_routingTable;
87 /// Internal state with all needed data structs.
95 void SendPacket (Ptr<Packet> packet, const MessageList &containedMessages);
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 ();
102 void RecvOlsr (Ptr<Socket> socket);
104 void MprComputation ();
105 void RoutingTableComputation ();
106 Ipv4Address GetMainAddress (Ipv4Address iface_addr) const;
110 void HelloTimerExpire ();
113 void TcTimerExpire ();
116 void MidTimerExpire ();
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);
126 void IncrementAnsn ();
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
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 ();
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);
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);
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);
178 int Degree (NeighborTuple const &tuple);
180 Ipv4Address m_mainAddress;
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;
187 TracedCallback <const PacketHeader &,
188 const MessageList &> m_rxPacketTrace;
189 TracedCallback <const PacketHeader &,
190 const MessageList &> m_txPacketTrace;
191 TracedCallback <uint32_t> m_routingTableChanged;