A Discrete-Event Network Simulator
API
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 
47 class OlsrMprTestCase;
48 
49 namespace ns3 {
50 namespace olsr {
51 
56 
59 {
62  uint32_t interface;
63  uint32_t distance;
64 
65  RoutingTableEntry () : // default values
66  destAddr (), nextAddr (),
67  interface (0), distance (0) {};
68 };
69 
70 class RoutingProtocol;
71 
78 {
79 public:
80  friend class ::OlsrMprTestCase;
81  static TypeId GetTypeId (void);
82 
83  RoutingProtocol ();
84  virtual ~RoutingProtocol ();
85 
91  void SetMainInterface (uint32_t interface);
92 
98  void Dump (void);
99 
103  std::vector<RoutingTableEntry> GetRoutingTableEntries () const;
104 
113  int64_t AssignStreams (int64_t stream);
114 
121  typedef void (* PacketTxRxTracedCallback)
122  (const PacketHeader & header, const MessageList & messages);
123 
129  typedef void (* TableChangeTracedCallback) (uint32_t size);
130 
131 private:
132  std::set<uint32_t> m_interfaceExclusions;
134 
135 public:
136  std::set<uint32_t> GetInterfaceExclusions () const
137  {
138  return m_interfaceExclusions;
139  }
140  void SetInterfaceExclusions (std::set<uint32_t> exceptions);
141 
143  void AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask);
145  void RemoveHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask);
146 
149 
155 
156 protected:
157  virtual void DoInitialize (void);
158 private:
159  std::map<Ipv4Address, RoutingTableEntry> m_table;
160 
162 
164 
170  uint16_t m_ansn;
171 
181  uint8_t m_willingness;
182 
185 
187 
188  void Clear ();
189  uint32_t GetSize () const { return m_table.size (); }
190  void RemoveEntry (const Ipv4Address &dest);
191  void AddEntry (const Ipv4Address &dest,
192  const Ipv4Address &next,
193  uint32_t interface,
194  uint32_t distance);
195  void AddEntry (const Ipv4Address &dest,
196  const Ipv4Address &next,
197  const Ipv4Address &interfaceAddress,
198  uint32_t distance);
199  bool Lookup (const Ipv4Address &dest,
200  RoutingTableEntry &outEntry) const;
201  bool FindSendEntry (const RoutingTableEntry &entry,
202  RoutingTableEntry &outEntry) const;
203 
204  // From Ipv4RoutingProtocol
206  const Ipv4Header &header,
207  Ptr<NetDevice> oif,
208  Socket::SocketErrno &sockerr);
209  virtual bool RouteInput (Ptr<const Packet> p,
210  const Ipv4Header &header,
215  ErrorCallback ecb);
216  virtual void NotifyInterfaceUp (uint32_t interface);
217  virtual void NotifyInterfaceDown (uint32_t interface);
218  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
219  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
220  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
221  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
222 
223  void DoDispose ();
224 
225  void SendPacket (Ptr<Packet> packet, const MessageList &containedMessages);
226 
228  inline uint16_t GetPacketSequenceNumber ();
230  inline uint16_t GetMessageSequenceNumber ();
231 
232  void RecvOlsr (Ptr<Socket> socket);
233 
234  void MprComputation ();
235  void RoutingTableComputation ();
236  Ipv4Address GetMainAddress (Ipv4Address iface_addr) const;
238 
239  // Timer handlers
241  void HelloTimerExpire ();
242 
244  void TcTimerExpire ();
245 
247  void MidTimerExpire ();
248 
250  void HnaTimerExpire ();
251 
252  void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber);
254  void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr);
255  void Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr);
256  void MprSelTupleTimerExpire (Ipv4Address mainAddr);
257  void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr);
258  void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr);
259  void AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask);
260 
261  void IncrementAnsn ();
262 
265  Timer m_queuedMessagesTimer; // timer for throttling outgoing messages
266 
267  void ForwardDefault (olsr::MessageHeader olsrMessage,
268  DuplicateTuple *duplicated,
269  const Ipv4Address &localIface,
270  const Ipv4Address &senderAddress);
271  void QueueMessage (const olsr::MessageHeader &message, Time delay);
272  void SendQueuedMessages ();
273  void SendHello ();
274  void SendTc ();
275  void SendMid ();
276  void SendHna ();
277 
278  void NeighborLoss (const LinkTuple &tuple);
279  void AddDuplicateTuple (const DuplicateTuple &tuple);
280  void RemoveDuplicateTuple (const DuplicateTuple &tuple);
281  void LinkTupleAdded (const LinkTuple &tuple, uint8_t willingness);
282  void RemoveLinkTuple (const LinkTuple &tuple);
283  void LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness);
284  void AddNeighborTuple (const NeighborTuple &tuple);
285  void RemoveNeighborTuple (const NeighborTuple &tuple);
286  void AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple);
288  void AddMprSelectorTuple (const MprSelectorTuple &tuple);
289  void RemoveMprSelectorTuple (const MprSelectorTuple &tuple);
290  void AddTopologyTuple (const TopologyTuple &tuple);
291  void RemoveTopologyTuple (const TopologyTuple &tuple);
292  void AddIfaceAssocTuple (const IfaceAssocTuple &tuple);
293  void RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple);
294  void AddAssociationTuple (const AssociationTuple &tuple);
295  void RemoveAssociationTuple (const AssociationTuple &tuple);
296 
297  void ProcessHello (const olsr::MessageHeader &msg,
298  const Ipv4Address &receiverIface,
299  const Ipv4Address &senderIface);
300  void ProcessTc (const olsr::MessageHeader &msg,
301  const Ipv4Address &senderIface);
302  void ProcessMid (const olsr::MessageHeader &msg,
303  const Ipv4Address &senderIface);
304  void ProcessHna (const olsr::MessageHeader &msg,
305  const Ipv4Address &senderIface);
306 
307  void LinkSensing (const olsr::MessageHeader &msg,
308  const olsr::MessageHeader::Hello &hello,
309  const Ipv4Address &receiverIface,
310  const Ipv4Address &sender_iface);
311  void PopulateNeighborSet (const olsr::MessageHeader &msg,
312  const olsr::MessageHeader::Hello &hello);
314  const olsr::MessageHeader::Hello &hello);
316  const olsr::MessageHeader::Hello &hello);
317 
318  int Degree (NeighborTuple const &tuple);
320  bool IsMyOwnAddress (const Ipv4Address & a) const;
321 
323 
324  // One socket per interface, each bound to that interface's address
325  // (reason: for OLSR Link Sensing we need to know on which interface
326  // HELLO messages arrive)
327  std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_socketAddresses;
328 
329  TracedCallback <const PacketHeader &,
331  TracedCallback <const PacketHeader &,
334 
337 
338 };
339 
340 }
341 } // namespace ns3
342 
343 #endif /* OLSR_AGENT_IMPL_H */
An MPR-Selector Tuple.
std::set< uint32_t > m_interfaceExclusions
An OLSR's routing table entry.
uint32_t distance
Distance in hops to the destination.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void HelloTimerExpire()
Sends a HELLO message and reschedules the HELLO timer.
std::set< uint32_t > GetInterfaceExclusions() const
void AddTopologyTuple(const TopologyTuple &tuple)
Adds a topology tuple to the Topology Set.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void DoDispose()
Destructor implementation.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
void IfaceAssocTupleTimerExpire(Ipv4Address ifaceAddr)
Removes tuple_ if expired.
void RemoveMprSelectorTuple(const MprSelectorTuple &tuple)
Removes an MPR selector tuple from the MPR Selector Set.
uint16_t GetPacketSequenceNumber()
Increments packet sequence number and returns the new value.
Time m_midInterval
MID messages' emission interval.
A simple Timer class.
Definition: timer.h:73
Introspection did not find any typical Config paths.
Definition: olsr-header.h:116
void Clear()
Clears the routing table and frees the memory assigned to each one of its entries.
uint16_t m_messageSequenceNumber
Messages sequence number counter.
Ipv4Address destAddr
Address of the destination node.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:226
void HnaTimerExpire()
Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer...
void LinkTupleUpdated(const LinkTuple &tuple, uint8_t willingness)
This function is invoked when a link tuple is updated.
void LinkSensing(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello, const Ipv4Address &receiverIface, const Ipv4Address &sender_iface)
Updates Link Set according to a new received HELLO message (following RFC 3626 specification).
Forward calls to a chain of Callback.
uint16_t m_ansn
Advertised Neighbor Set sequence number.
void AddEntry(const Ipv4Address &dest, const Ipv4Address &next, uint32_t interface, uint32_t distance)
Adds a new entry into the routing table.
virtual void NotifyInterfaceUp(uint32_t interface)
void SendTc()
Creates a new OLSR TC message which is buffered for being sent later on.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
void(* TableChangeTracedCallback)(uint32_t size)
TracedCallback signature for routing table computation.
void DupTupleTimerExpire(Ipv4Address address, uint16_t sequenceNumber)
Removes tuple if expired.
void AddHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Inject Association to be sent in HNA message.
void LinkTupleTimerExpire(Ipv4Address neighborIfaceAddr)
Removes tuple_ if expired.
void SetMainInterface(uint32_t interface)
Set the OLSR main address to the first address on the indicated interface.
void Nb2hopTupleTimerExpire(Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr)
Removes tuple_ if expired.
void RemoveAssociationTuple(const AssociationTuple &tuple)
Removes a host network association tuple from the Association Set.
void ProcessTc(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a TC message following RFC 3626 specification.
void MprSelTupleTimerExpire(Ipv4Address mainAddr)
Removes tuple_ if expired.
Callback< void, Ptr< const Packet >, const Ipv4Header &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found)
std::map< Ipv4Address, RoutingTableEntry > m_table
Data structure for the routing table.
TracedCallback< const PacketHeader &, const MessageList & > m_rxPacketTrace
void RemoveIfaceAssocTuple(const IfaceAssocTuple &tuple)
Removes an interface association tuple from the Interface Association Set.
Packet header for IPv4.
Definition: ipv4-header.h:31
EventGarbageCollector m_events
An object that tracks scheduled events and automatically cancels them when it is destroyed.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
uint8_t m_willingness
Willingness for forwarding packets on behalf of other nodes.
void PopulateNeighborSet(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello)
Updates the Neighbor Set according to the information contained in a new received HELLO message (foll...
void RemoveHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Removes Association sent in HNA message.
void AddIfaceAssocTuple(const IfaceAssocTuple &tuple)
Adds an interface association tuple to the Interface Association Set.
void QueueMessage(const olsr::MessageHeader &message, Time delay)
Enques an OLSR message which will be sent with a delay of (0, delay].
void SendPacket(Ptr< Packet > packet, const MessageList &containedMessages)
OLSR routing protocol for IPv4.
An Association Tuple.
void ProcessHello(const olsr::MessageHeader &msg, const Ipv4Address &receiverIface, const Ipv4Address &senderIface)
Processes a HELLO message following RFC 3626 specification.
void AddAssociationTuple(const AssociationTuple &tuple)
Adds a host network association tuple to the Association Set.
Ptr< Ipv4StaticRouting > m_hnaRoutingTable
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
void MprComputation()
Computates MPR set of a node following RFC 3626 hints.
void RemoveDuplicateTuple(const DuplicateTuple &tuple)
Removes a duplicate tuple from the Duplicate Set.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
Time m_helloInterval
HELLO messages' emission interval.
void SetRoutingTableAssociation(Ptr< Ipv4StaticRouting > routingTable)
Inject Associations from an Ipv4StaticRouting instance.
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_socketAddresses
void TopologyTupleTimerExpire(Ipv4Address destAddr, Ipv4Address lastAddr)
Removes tuple_ if expired.
Time m_tcInterval
TC messages' emission interval.
void AddTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Adds a 2-hop neighbor tuple to the 2-hop Neighbor Set.
void AssociationTupleTimerExpire(Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask)
Removes tuple_ if expired.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
void NeighborLoss(const LinkTuple &tuple)
Performs all actions needed when a neighbor loss occurs.
void RemoveTopologyTuple(const TopologyTuple &tuple)
Removes a topology tuple from the Topology Set.
void SendMid()
Creates a new OLSR MID message which is buffered for being sent later on.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void RecvOlsr(Ptr< Socket > socket)
This class encapsulates all data structures needed for maintaining internal state of an OLSR node...
Definition: olsr-state.h:34
void MidTimerExpire()
Sends a MID message (if the node has more than one interface) and resets the MID timer.
Ptr< Ipv4StaticRouting > m_routingTableAssociation
Ptr< const Ipv4StaticRouting > GetRoutingTableAssociation() const
Returns the internal HNA table.
void AddNeighborTuple(const NeighborTuple &tuple)
Adds a neighbor tuple to the Neighbor Set.
void SendHello()
Creates a new OLSR HELLO message which is buffered for being sent later on.
void RemoveLinkTuple(const LinkTuple &tuple)
Removes a link tuple from the Link Set.
bool UsesNonOlsrOutgoingInterface(const Ipv4RoutingTableEntry &route)
Tests whether or not the specified route uses a non-OLSR outgoing interface.
bool Lookup(const Ipv4Address &dest, RoutingTableEntry &outEntry) const
Looks up an entry for the specified destination address.
std::vector< MessageHeader > MessageList
Definition: olsr-header.h:450
Definition: olsr.py:1
virtual void NotifyInterfaceDown(uint32_t interface)
Introspection did not find any typical Config paths.
Definition: olsr-header.h:69
uint16_t m_packetSequenceNumber
Packets sequence number counter.
void PopulateTwoHopNeighborSet(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello)
Updates the 2-hop Neighbor Set according to the information contained in a new received HELLO message...
Ipv4Address GetMainAddress(Ipv4Address iface_addr) const
Gets the main address associated with a given interface address.
void RoutingTableComputation()
Creates the routing table of the node following RFC 3626 hints.
void RemoveTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Removes a 2-hop neighbor tuple from the 2-hop Neighbor Set.
void RemoveEntry(const Ipv4Address &dest)
Deletes the entry whose destination address is given.
void ForwardDefault(olsr::MessageHeader olsrMessage, DuplicateTuple *duplicated, const Ipv4Address &localIface, const Ipv4Address &senderAddress)
OLSR's default forwarding algorithm.
Callback< void, Ptr< const Packet >, const Ipv4Header &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
void ProcessHna(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a HNA message following RFC 3626 specification.
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
int Degree(NeighborTuple const &tuple)
This auxiliary function (defined in RFC 3626) is used for calculating the MPR Set.
uint32_t interface
Interface index.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void(* PacketTxRxTracedCallback)(const PacketHeader &header, const MessageList &messages)
TracedCallback signature for Packet transmit and receive events.
bool IsMyOwnAddress(const Ipv4Address &a) const
Check that address is one of my interfaces.
a class to store IPv4 address information on an interface
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
void PopulateMprSelectorSet(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello)
Updates the MPR Selector Set according to the information contained in a new received HELLO message (...
void SendQueuedMessages()
Creates as many OLSR packets as needed in order to send all buffered OLSR messages.
Ipv4Address nextAddr
Address of the next hop.
TracedCallback< const PacketHeader &, const MessageList & > m_txPacketTrace
void SendHna()
Creates a new OLSR HNA message which is buffered for being sent later on.
Abstract base class for IPv4 routing protocols.
void LinkTupleAdded(const LinkTuple &tuple, uint8_t willingness)
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Time m_hnaInterval
HNA messages' emission interval.
void Dump(void)
Dump the neighbor table, two-hop neighbor table, and routing table to logging output (NS_LOG_DEBUG lo...
virtual void DoInitialize(void)
Initialize() implementation.
std::vector< RoutingTableEntry > GetRoutingTableEntries() const
Return the list of routing table entries discovered by OLSR.
tuple address
Definition: first.py:37
RoutingTableEntry()
void AddDuplicateTuple(const DuplicateTuple &tuple)
Adds a duplicate tuple to the Duplicate Set.
void TcTimerExpire()
Sends a TC message (if there exists any MPR selector) and reschedules the TC timer.
void RemoveNeighborTuple(const NeighborTuple &tuple)
Removes a neighbor tuple from the Neighbor Set.
uint16_t GetMessageSequenceNumber()
Increments message sequence number and returns the new value.
OlsrState m_state
Internal state with all needed data structs.
Callback< void, Ptr< Ipv4MulticastRoute >, Ptr< const Packet >, const Ipv4Header & > MulticastForwardCallback
Callback for multicast packets to be forwarded.
void AddMprSelectorTuple(const MprSelectorTuple &tuple)
Adds an MPR selector tuple to the MPR Selector Set.
TracedCallback< uint32_t > m_routingTableChanged
a unique identifier for an interface.
Definition: type-id.h:58
An Interface Association Tuple.
The type "list of interface addresses".
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
olsr::MessageList m_queuedMessages
A list of pending messages which are buffered awaiting for being sent.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
bool FindSendEntry(const RoutingTableEntry &entry, RoutingTableEntry &outEntry) const
Finds the appropiate entry which must be used in order to forward a data packet to a next hop (given ...
Callback< void, Ptr< Ipv4Route >, Ptr< const Packet >, const Ipv4Header & > UnicastForwardCallback
Callback for unicast packets to be forwarded.
Testcase for MPR computation mechanism.
void ProcessMid(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a MID message following RFC 3626 specification.