A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
olsr-routing-protocol.h
Go to the documentation of this file.
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 #ifndef OLSR_AGENT_IMPL_H
24 #define OLSR_AGENT_IMPL_H
25 
26 #include "olsr-header.h"
27 #include "ns3/test.h"
28 #include "olsr-state.h"
29 #include "olsr-repositories.h"
30 
31 #include "ns3/object.h"
32 #include "ns3/packet.h"
33 #include "ns3/node.h"
34 #include "ns3/socket.h"
35 #include "ns3/event-garbage-collector.h"
36 #include "ns3/random-variable-stream.h"
37 #include "ns3/timer.h"
38 #include "ns3/traced-callback.h"
39 #include "ns3/ipv4.h"
40 #include "ns3/ipv4-routing-protocol.h"
41 #include "ns3/ipv4-static-routing.h"
42 
43 #include <vector>
44 #include <map>
45 
46 
47 namespace ns3 {
48 namespace olsr {
49 
54 
57 {
60  uint32_t interface;
61  uint32_t distance;
62 
63  RoutingTableEntry () : // default values
64  destAddr (), nextAddr (),
65  interface (0), distance (0) {};
66 };
67 
68 class RoutingProtocol;
69 
71 class OlsrMprTestCase;
72 
79 {
80 public:
81  friend class OlsrMprTestCase;
82  static TypeId GetTypeId (void);
83 
84  RoutingProtocol ();
85  virtual ~RoutingProtocol ();
86 
92  void SetMainInterface (uint32_t interface);
93 
99  void Dump (void);
100 
104  std::vector<RoutingTableEntry> GetRoutingTableEntries () const;
105 
114  int64_t AssignStreams (int64_t stream);
115 
116 private:
117  std::set<uint32_t> m_interfaceExclusions;
119 
120 public:
121  std::set<uint32_t> GetInterfaceExclusions () const
122  {
123  return m_interfaceExclusions;
124  }
125  void SetInterfaceExclusions (std::set<uint32_t> exceptions);
126 
128  void AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask);
130  void RemoveHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask);
131 
134 
135 protected:
136  virtual void DoStart (void);
137 private:
138  std::map<Ipv4Address, RoutingTableEntry> m_table;
139 
141 
143 
149  uint16_t m_ansn;
150 
160  uint8_t m_willingness;
161 
164 
166 
167  void Clear ();
168  uint32_t GetSize () const { return m_table.size (); }
169  void RemoveEntry (const Ipv4Address &dest);
170  void AddEntry (const Ipv4Address &dest,
171  const Ipv4Address &next,
172  uint32_t interface,
173  uint32_t distance);
174  void AddEntry (const Ipv4Address &dest,
175  const Ipv4Address &next,
176  const Ipv4Address &interfaceAddress,
177  uint32_t distance);
178  bool Lookup (const Ipv4Address &dest,
179  RoutingTableEntry &outEntry) const;
180  bool FindSendEntry (const RoutingTableEntry &entry,
181  RoutingTableEntry &outEntry) const;
182 
183  // From Ipv4RoutingProtocol
185  const Ipv4Header &header,
186  Ptr<NetDevice> oif,
187  Socket::SocketErrno &sockerr);
188  virtual bool RouteInput (Ptr<const Packet> p,
189  const Ipv4Header &header,
194  ErrorCallback ecb);
195  virtual void NotifyInterfaceUp (uint32_t interface);
196  virtual void NotifyInterfaceDown (uint32_t interface);
197  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
198  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
199  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
200  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
201 
202  void DoDispose ();
203 
204  void SendPacket (Ptr<Packet> packet, const MessageList &containedMessages);
205 
207  inline uint16_t GetPacketSequenceNumber ();
209  inline uint16_t GetMessageSequenceNumber ();
210 
211  void RecvOlsr (Ptr<Socket> socket);
212 
213  void MprComputation ();
214  void RoutingTableComputation ();
215  Ipv4Address GetMainAddress (Ipv4Address iface_addr) const;
217 
218  // Timer handlers
220  void HelloTimerExpire ();
221 
223  void TcTimerExpire ();
224 
226  void MidTimerExpire ();
227 
229  void HnaTimerExpire ();
230 
231  void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber);
233  void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr);
234  void Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr);
235  void MprSelTupleTimerExpire (Ipv4Address mainAddr);
236  void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr);
237  void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr);
238  void AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask);
239 
240  void IncrementAnsn ();
241 
244  Timer m_queuedMessagesTimer; // timer for throttling outgoing messages
245 
246  void ForwardDefault (olsr::MessageHeader olsrMessage,
247  DuplicateTuple *duplicated,
248  const Ipv4Address &localIface,
249  const Ipv4Address &senderAddress);
250  void QueueMessage (const olsr::MessageHeader &message, Time delay);
251  void SendQueuedMessages ();
252  void SendHello ();
253  void SendTc ();
254  void SendMid ();
255  void SendHna ();
256 
257  void NeighborLoss (const LinkTuple &tuple);
258  void AddDuplicateTuple (const DuplicateTuple &tuple);
259  void RemoveDuplicateTuple (const DuplicateTuple &tuple);
260  void LinkTupleAdded (const LinkTuple &tuple, uint8_t willingness);
261  void RemoveLinkTuple (const LinkTuple &tuple);
262  void LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness);
263  void AddNeighborTuple (const NeighborTuple &tuple);
264  void RemoveNeighborTuple (const NeighborTuple &tuple);
265  void AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple);
267  void AddMprSelectorTuple (const MprSelectorTuple &tuple);
268  void RemoveMprSelectorTuple (const MprSelectorTuple &tuple);
269  void AddTopologyTuple (const TopologyTuple &tuple);
270  void RemoveTopologyTuple (const TopologyTuple &tuple);
271  void AddIfaceAssocTuple (const IfaceAssocTuple &tuple);
272  void RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple);
273  void AddAssociationTuple (const AssociationTuple &tuple);
274  void RemoveAssociationTuple (const AssociationTuple &tuple);
275 
276  void ProcessHello (const olsr::MessageHeader &msg,
277  const Ipv4Address &receiverIface,
278  const Ipv4Address &senderIface);
279  void ProcessTc (const olsr::MessageHeader &msg,
280  const Ipv4Address &senderIface);
281  void ProcessMid (const olsr::MessageHeader &msg,
282  const Ipv4Address &senderIface);
283  void ProcessHna (const olsr::MessageHeader &msg,
284  const Ipv4Address &senderIface);
285 
286  void LinkSensing (const olsr::MessageHeader &msg,
287  const olsr::MessageHeader::Hello &hello,
288  const Ipv4Address &receiverIface,
289  const Ipv4Address &sender_iface);
290  void PopulateNeighborSet (const olsr::MessageHeader &msg,
291  const olsr::MessageHeader::Hello &hello);
293  const olsr::MessageHeader::Hello &hello);
295  const olsr::MessageHeader::Hello &hello);
296 
297  int Degree (NeighborTuple const &tuple);
299  bool IsMyOwnAddress (const Ipv4Address & a) const;
300 
302 
303  // One socket per interface, each bound to that interface's address
304  // (reason: for OLSR Link Sensing we need to know on which interface
305  // HELLO messages arrive)
306  std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_socketAddresses;
307 
308  TracedCallback <const PacketHeader &,
310  TracedCallback <const PacketHeader &,
313 
316 
317 };
318 
319 }
320 } // namespace ns3
321 
322 #endif /* OLSR_AGENT_IMPL_H */