A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
olsr-routing-protocol.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004 Francisco J. Ros
3 * Copyright (c) 2007 INESC Porto
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Francisco J. Ros <fjrm@dif.um.es>
8 * Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
9 */
10
11#ifndef OLSR_AGENT_IMPL_H
12#define OLSR_AGENT_IMPL_H
13
14#include "olsr-header.h"
15#include "olsr-repositories.h"
16#include "olsr-state.h"
17
18#include "ns3/event-garbage-collector.h"
19#include "ns3/ipv4-routing-protocol.h"
20#include "ns3/ipv4-static-routing.h"
21#include "ns3/ipv4.h"
22#include "ns3/node.h"
23#include "ns3/object.h"
24#include "ns3/packet.h"
25#include "ns3/random-variable-stream.h"
26#include "ns3/socket.h"
27#include "ns3/test.h"
28#include "ns3/timer.h"
29#include "ns3/traced-callback.h"
30
31#include <map>
32#include <vector>
33
34/// Testcase for MPR computation mechanism
35class OlsrMprTestCase;
36
37namespace ns3
38{
39namespace olsr
40{
41
42///
43/// \defgroup olsr OLSR Routing
44/// This section documents the API of the ns-3 OLSR module. For a generic
45/// functional description, please refer to the ns-3 manual.
46
47/// \ingroup olsr
48/// An OLSR's routing table entry.
50{
51 Ipv4Address destAddr; //!< Address of the destination node.
52 Ipv4Address nextAddr; //!< Address of the next hop.
53 uint32_t interface; //!< Interface index
54 uint32_t distance; //!< Distance in hops to the destination.
55
57 : // default values
58 destAddr(),
59 nextAddr(),
60 interface(0),
61 distance(0)
62 {
63 }
64};
65
66class RoutingProtocol;
67
68///
69/// \ingroup olsr
70///
71/// \brief OLSR routing protocol for IPv4
72///
74{
75 public:
76 /**
77 * Declared friend to enable unit tests.
78 */
79 friend class ::OlsrMprTestCase;
80
81 static const uint16_t OLSR_PORT_NUMBER; //!< port number (698)
82
83 /**
84 * \brief Get the type ID.
85 * \return The object TypeId.
86 */
87 static TypeId GetTypeId();
88
90 ~RoutingProtocol() override;
91
92 /**
93 * \brief Set the OLSR main address to the first address on the indicated interface.
94 *
95 * \param interface IPv4 interface index
96 */
97 void SetMainInterface(uint32_t interface);
98
99 /**
100 * Dump the neighbor table, two-hop neighbor table, and routing table
101 * to logging output (NS_LOG_DEBUG log level). If logging is disabled,
102 * this function does nothing.
103 */
104 void Dump();
105
106 /**
107 * Get the routing table entries.
108 * \return the list of routing table entries discovered by OLSR
109 */
110 std::vector<RoutingTableEntry> GetRoutingTableEntries() const;
111
112 /**
113 * Gets the MPR set.
114 * \return The MPR set.
115 */
116 MprSet GetMprSet() const;
117
118 /**
119 * Gets the MPR selectors.
120 * \returns The MPR selectors.
121 */
122 const MprSelectorSet& GetMprSelectors() const;
123
124 /**
125 * Get the one hop neighbors.
126 * \return the set of neighbors discovered by OLSR
127 */
128 const NeighborSet& GetNeighbors() const;
129
130 /**
131 * Get the two hop neighbors.
132 * \return the set of two hop neighbors discovered by OLSR
133 */
135
136 /**
137 * Gets the topology set.
138 * \returns The topology set discovery by OLSR
139 */
140 const TopologySet& GetTopologySet() const;
141
142 /**
143 * Gets the underlying OLSR state object
144 * \returns The OLSR state object
145 */
146 const OlsrState& GetOlsrState() const;
147
148 /**
149 * Assign a fixed random variable stream number to the random variables
150 * used by this model. Return the number of streams (possibly zero) that
151 * have been assigned.
152 *
153 * \param stream first stream index to use
154 * \return the number of stream indices assigned by this model
155 */
156 int64_t AssignStreams(int64_t stream);
157
158 /**
159 * TracedCallback signature for Packet transmit and receive events.
160 *
161 * \param [in] header
162 * \param [in] messages
163 */
164 typedef void (*PacketTxRxTracedCallback)(const PacketHeader& header,
165 const MessageList& messages);
166
167 /**
168 * TracedCallback signature for routing table computation.
169 *
170 * \param [in] size Final routing table size.
171 */
172 typedef void (*TableChangeTracedCallback)(uint32_t size);
173
174 private:
175 std::set<uint32_t> m_interfaceExclusions; //!< Set of interfaces excluded by OSLR.
177 m_routingTableAssociation; //!< Associations from an Ipv4StaticRouting instance
178
179 public:
180 /**
181 * Get the excluded interfaces.
182 * \returns Container of excluded interfaces.
183 */
184 std::set<uint32_t> GetInterfaceExclusions() const
185 {
187 }
188
189 /**
190 * Set the interfaces to be excluded.
191 * \param exceptions Container of excluded interfaces.
192 */
193 void SetInterfaceExclusions(std::set<uint32_t> exceptions);
194
195 /**
196 * \brief Injects the specified (networkAddr, netmask) tuple in the list of
197 * local HNA associations to be sent by the node via HNA messages.
198 * If this tuple already exists, nothing is done.
199 *
200 * \param networkAddr The network address.
201 * \param netmask The network mask.
202 */
203 void AddHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask);
204
205 /**
206 * \brief Removes the specified (networkAddr, netmask) tuple from the list of
207 * local HNA associations to be sent by the node via HNA messages.
208 * If this tuple does not exist, nothing is done (see "OlsrState::EraseAssociation()").
209 *
210 * \param networkAddr The network address.
211 * \param netmask The network mask.
212 */
213 void RemoveHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask);
214
215 /**
216 * \brief Associates the specified Ipv4StaticRouting routing table
217 * to the OLSR routing protocol. Entries from this associated
218 * routing table that use non-olsr outgoing interfaces are added
219 * to the list of local HNA associations so that they are included
220 * in HNA messages sent by the node.
221 * If this method is called more than once, entries from the old
222 * association are deleted before entries from the new one are added.
223 * \param routingTable the Ipv4StaticRouting routing table to be associated.
224 */
226
227 /**
228 * \brief Returns the internal HNA table
229 * \returns the internal HNA table
230 */
232
233 protected:
234 void DoInitialize() override;
235 void DoDispose() override;
236
237 private:
238 std::map<Ipv4Address, RoutingTableEntry> m_table; //!< Data structure for the routing table.
239
240 Ptr<Ipv4StaticRouting> m_hnaRoutingTable; //!< Routing table for HNA routes
241
242 EventGarbageCollector m_events; //!< Running events.
243
244 uint16_t m_packetSequenceNumber; //!< Packets sequence number counter.
245 uint16_t m_messageSequenceNumber; //!< Messages sequence number counter.
246 uint16_t m_ansn; //!< Advertised Neighbor Set sequence number.
247
248 Time m_helloInterval; //!< HELLO messages' emission interval.
249 Time m_tcInterval; //!< TC messages' emission interval.
250 Time m_midInterval; //!< MID messages' emission interval.
251 Time m_hnaInterval; //!< HNA messages' emission interval.
252 Willingness m_willingness; //!< Willingness for forwarding packets on behalf of other nodes.
253
254 OlsrState m_state; //!< Internal state with all needed data structs.
255 Ptr<Ipv4> m_ipv4; //!< IPv4 object the routing is linked to.
256
257 /**
258 * \brief Clears the routing table and frees the memory assigned to each one of its entries.
259 */
260 void Clear();
261
262 /**
263 * Returns the routing table size.
264 * \return The routing table size.
265 */
267 {
268 return m_table.size();
269 }
270
271 /**
272 * \brief Deletes the entry whose destination address is given.
273 * \param dest address of the destination node.
274 */
275 void RemoveEntry(const Ipv4Address& dest);
276 /**
277 * \brief Adds a new entry into the routing table.
278 *
279 * If an entry for the given destination existed, it is deleted and freed.
280 *
281 * \param dest address of the destination node.
282 * \param next address of the next hop node.
283 * \param interface address of the local interface.
284 * \param distance distance to the destination node.
285 */
286 void AddEntry(const Ipv4Address& dest,
287 const Ipv4Address& next,
288 uint32_t interface,
289 uint32_t distance);
290 /**
291 * \brief Adds a new entry into the routing table.
292 *
293 * If an entry for the given destination existed, an error is thrown.
294 *
295 * \param dest address of the destination node.
296 * \param next address of the next hop node.
297 * \param interfaceAddress address of the local interface.
298 * \param distance distance to the destination node.
299 */
300 void AddEntry(const Ipv4Address& dest,
301 const Ipv4Address& next,
302 const Ipv4Address& interfaceAddress,
303 uint32_t distance);
304
305 /**
306 * \brief Looks up an entry for the specified destination address.
307 * \param [in] dest Destination address.
308 * \param [out] outEntry Holds the routing entry result, if found.
309 * \return true if found, false if not found.
310 */
311 bool Lookup(const Ipv4Address& dest, RoutingTableEntry& outEntry) const;
312
313 /**
314 * \brief Finds the appropriate entry which must be used in order to forward
315 * a data packet to a next hop (given a destination).
316 *
317 * Imagine a routing table like this: [A,B] [B,C] [C,C]; being each pair of the
318 * form [dest addr, next-hop addr]. In this case, if this function is invoked
319 * with [A,B] then pair [C,C] is returned because C is the next hop that must be used
320 * to forward a data packet destined to A. That is, C is a neighbor of this node,
321 * but B isn't. This function finds the appropriate neighbor for forwarding a packet.
322 *
323 * \param[in] entry The routing table entry which indicates the destination node
324 * we are interested in.
325 *
326 * \param[out] outEntry The appropriate routing table entry which indicates the next
327 * hop which must be used for forwarding a data packet, or NULL if there is no such entry.
328 *
329 * \return True if an entry was found, false otherwise.
330 */
331 bool FindSendEntry(const RoutingTableEntry& entry, RoutingTableEntry& outEntry) const;
332
333 public:
334 // From Ipv4RoutingProtocol
336 const Ipv4Header& header,
337 Ptr<NetDevice> oif,
338 Socket::SocketErrno& sockerr) override;
340 const Ipv4Header& header,
342 const UnicastForwardCallback& ucb,
343 const MulticastForwardCallback& mcb,
344 const LocalDeliverCallback& lcb,
345 const ErrorCallback& ecb) override;
346 void SetIpv4(Ptr<Ipv4> ipv4) override;
347
349 Time::Unit unit = Time::S) const override;
350
351 private:
352 void NotifyInterfaceUp(uint32_t interface) override;
353 void NotifyInterfaceDown(uint32_t interface) override;
354 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
355 void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
356
357 /**
358 * Send an OLSR message.
359 * \param packet The packet to be sent.
360 * \param containedMessages The messages contained in the packet.
361 */
362 void SendPacket(Ptr<Packet> packet, const MessageList& containedMessages);
363
364 /**
365 * Increments packet sequence number and returns the new value.
366 * \return The packet sequence number.
367 */
368 inline uint16_t GetPacketSequenceNumber();
369
370 /**
371 * Increments message sequence number and returns the new value.
372 * \return The message sequence number.
373 */
374 inline uint16_t GetMessageSequenceNumber();
375
376 /**
377 * Receive an OLSR message.
378 * \param socket The receiving socket.
379 */
380 void RecvOlsr(Ptr<Socket> socket);
381
382 /**
383 * \brief Computes MPR set of a node following \RFC{3626} hints.
384 */
385 void MprComputation();
386
387 /**
388 * \brief Creates the routing table of the node following \RFC{3626} hints.
389 */
391
392 public:
393 /**
394 * \brief Gets the main address associated with a given interface address.
395 * \param iface_addr the interface address.
396 * \return the corresponding main address.
397 */
398 Ipv4Address GetMainAddress(Ipv4Address iface_addr) const;
399
400 private:
401 /**
402 * \brief Tests whether or not the specified route uses a non-OLSR outgoing interface.
403 * \param route The route to be tested.
404 * \returns True if the outgoing interface of the specified route is a non-OLSR interface,
405 * false otherwise.
406 */
408
409 // Timer handlers
410 Timer m_helloTimer; //!< Timer for the HELLO message.
411 /**
412 * \brief Sends a HELLO message and reschedules the HELLO timer.
413 */
414 void HelloTimerExpire();
415
416 Timer m_tcTimer; //!< Timer for the TC message.
417 /**
418 * \brief Sends a TC message (if there exists any MPR selector) and reschedules the TC timer.
419 */
420 void TcTimerExpire();
421
422 Timer m_midTimer; //!< Timer for the MID message.
423 /**
424 * \brief \brief Sends a MID message (if the node has more than one interface) and resets the
425 * MID timer.
426 */
427 void MidTimerExpire();
428
429 Timer m_hnaTimer; //!< Timer for the HNA message.
430 /**
431 * \brief Sends an HNA message (if the node has associated hosts/networks) and reschedules the
432 * HNA timer.
433 */
434 void HnaTimerExpire();
435
436 /**
437 * \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime.
438 *
439 * The task of actually removing the tuple is left to the OLSR agent.
440 *
441 * \param address The address of the tuple.
442 * \param sequenceNumber The sequence number of the tuple.
443 */
444 void DupTupleTimerExpire(Ipv4Address address, uint16_t sequenceNumber);
445
446 bool m_linkTupleTimerFirstTime; //!< Flag to indicate if it is the first time the LinkTupleTimer
447 //!< fires.
448 /**
449 * \brief Removes tuple_ if expired. Else if symmetric time
450 * has expired then it is assumed a neighbor loss and agent_->nb_loss()
451 * is called. In this case the timer is rescheduled to expire at
452 * tuple_->time(). Otherwise the timer is rescheduled to expire at
453 * the minimum between tuple_->time() and tuple_->sym_time().
454 *
455 * The task of actually removing the tuple is left to the OLSR agent.
456 *
457 * \param neighborIfaceAddr The tuple neighbor interface address.
458 */
459 void LinkTupleTimerExpire(Ipv4Address neighborIfaceAddr);
460
461 /**
462 * \brief Removes 2_hop neighbor tuple_ if expired. Else the timer is rescheduled to expire at
463 * tuple_->time().
464 *
465 * The task of actually removing the tuple is left to the OLSR agent.
466 *
467 * \param neighborMainAddr The neighbor main address.
468 * \param twoHopNeighborAddr The 2-hop neighbor address.
469 */
470 void Nb2hopTupleTimerExpire(Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr);
471
472 /**
473 * \brief Removes MPR selector tuple_ if expired. Else the timer is rescheduled to expire at
474 * tuple_->time().
475 *
476 * The task of actually removing the tuple is left to the OLSR agent.
477 *
478 * \param mainAddr The tuple IPv4 address.
479 */
480 void MprSelTupleTimerExpire(Ipv4Address mainAddr);
481
482 /**
483 * \brief Removes topology tuple_ if expired. Else the timer is rescheduled to expire at
484 * tuple_->time().
485 *
486 * The task of actually removing the tuple is left to the OLSR agent.
487 *
488 * \param destAddr The destination address.
489 * \param lastAddr The last address.
490 */
491 void TopologyTupleTimerExpire(Ipv4Address destAddr, Ipv4Address lastAddr);
492
493 /**
494 * \brief Removes interface association tuple_ if expired. Else the timer is rescheduled to
495 * expire at tuple_->time().
496 *
497 * \param ifaceAddr The interface address.
498 */
500
501 /**
502 * \brief Removes association tuple_ if expired. Else timer is rescheduled to expire at
503 * tuple_->time().
504 *
505 * \param gatewayAddr The gateway address.
506 * \param networkAddr The network address.
507 * \param netmask The network mask.
508 */
510 Ipv4Address networkAddr,
511 Ipv4Mask netmask);
512
513 /**
514 * Increments the ANSN counter.
515 */
516 void IncrementAnsn();
517
518 /// A list of pending messages which are buffered awaiting for being sent.
520 Timer m_queuedMessagesTimer; //!< timer for throttling outgoing messages
521
522 /**
523 * \brief OLSR's default forwarding algorithm.
524 *
525 * See \RFC{3626} for details.
526 *
527 * \param olsrMessage The %OLSR message which must be forwarded.
528 * \param duplicated NULL if the message has never been considered for forwarding, or a
529 * duplicate tuple in other case.
530 * \param localIface The address of the interface where the message was received from.
531 * \param senderAddress The sender IPv4 address.
532 */
533 void ForwardDefault(olsr::MessageHeader olsrMessage,
534 DuplicateTuple* duplicated,
535 const Ipv4Address& localIface,
536 const Ipv4Address& senderAddress);
537
538 /**
539 * \brief Enqueues an %OLSR message which will be sent with a delay of (0, delay].
540 *
541 * This buffering system is used in order to piggyback several %OLSR messages in
542 * a same %OLSR packet.
543 *
544 * \param message the %OLSR message which must be sent.
545 * \param delay maximum delay the %OLSR message is going to be buffered.
546 */
547 void QueueMessage(const olsr::MessageHeader& message, Time delay);
548
549 /**
550 * \brief Creates as many %OLSR packets as needed in order to send all buffered
551 * %OLSR messages.
552 *
553 * Maximum number of messages which can be contained in an %OLSR packet is
554 * dictated by OLSR_MAX_MSGS constant.
555 */
556 void SendQueuedMessages();
557
558 /**
559 * \brief Creates a new %OLSR HELLO message which is buffered for being sent later on.
560 */
561 void SendHello();
562
563 /**
564 * \brief Creates a new %OLSR TC message which is buffered for being sent later on.
565 */
566 void SendTc();
567
568 /**
569 * \brief Creates a new %OLSR MID message which is buffered for being sent later on.
570 */
571 void SendMid();
572
573 /**
574 * \brief Creates a new %OLSR HNA message which is buffered for being sent later on.
575 */
576 void SendHna();
577
578 /**
579 * \brief Performs all actions needed when a neighbor loss occurs.
580 *
581 * Neighbor Set, 2-hop Neighbor Set, MPR Set and MPR Selector Set are updated.
582 *
583 * \param tuple link tuple with the information of the link to the neighbor which has been lost.
584 */
585 void NeighborLoss(const LinkTuple& tuple);
586
587 /**
588 * \brief Adds a duplicate tuple to the Duplicate Set.
589 *
590 * \param tuple The duplicate tuple to be added.
591 */
592 void AddDuplicateTuple(const DuplicateTuple& tuple);
593
594 /**
595 * \brief Removes a duplicate tuple from the Duplicate Set.
596 *
597 * \param tuple The duplicate tuple to be removed.
598 */
599 void RemoveDuplicateTuple(const DuplicateTuple& tuple);
600
601 /**
602 * Adds a link tuple.
603 * \param tuple The tuple to be added.
604 * \param willingness The tuple willingness.
605 */
606 void LinkTupleAdded(const LinkTuple& tuple, Willingness willingness);
607
608 /**
609 * \brief Removes a link tuple from the Link Set.
610 *
611 * \param tuple The link tuple to be removed.
612 */
613 void RemoveLinkTuple(const LinkTuple& tuple);
614
615 /**
616 * \brief This function is invoked when a link tuple is updated. Its aim is to
617 * also update the corresponding neighbor tuple if it is needed.
618 *
619 * \param tuple The link tuple which has been updated.
620 * \param willingness The tuple willingness.
621 */
622 void LinkTupleUpdated(const LinkTuple& tuple, Willingness willingness);
623
624 /**
625 * \brief Adds a neighbor tuple to the Neighbor Set.
626 *
627 * \param tuple The neighbor tuple to be added.
628 */
629 void AddNeighborTuple(const NeighborTuple& tuple);
630
631 /**
632 * \brief Removes a neighbor tuple from the Neighbor Set.
633 *
634 * \param tuple The neighbor tuple to be removed.
635 */
636 void RemoveNeighborTuple(const NeighborTuple& tuple);
637
638 /**
639 * \brief Adds a 2-hop neighbor tuple to the 2-hop Neighbor Set.
640 *
641 * \param tuple The 2-hop neighbor tuple to be added.
642 */
644
645 /**
646 * \brief Removes a 2-hop neighbor tuple from the 2-hop Neighbor Set.
647 *
648 * \param tuple The 2-hop neighbor tuple to be removed.
649 */
651
652 /**
653 * \brief Adds an MPR selector tuple to the MPR Selector Set.
654 * Advertised Neighbor Sequence Number (ANSN) is also updated.
655 *
656 * \param tuple The MPR selector tuple to be added.
657 */
658 void AddMprSelectorTuple(const MprSelectorTuple& tuple);
659
660 /**
661 * \brief Removes an MPR selector tuple from the MPR Selector Set.
662 * Advertised Neighbor Sequence Number (ANSN) is also updated.
663 *
664 * \param tuple The MPR selector tuple to be removed.
665 */
666 void RemoveMprSelectorTuple(const MprSelectorTuple& tuple);
667
668 /**
669 * \brief Adds a topology tuple to the Topology Set.
670 *
671 * \param tuple The topology tuple to be added.
672 */
673 void AddTopologyTuple(const TopologyTuple& tuple);
674
675 /**
676 * \brief Removes a topology tuple to the Topology Set.
677 *
678 * \param tuple The topology tuple to be removed.
679 */
680 void RemoveTopologyTuple(const TopologyTuple& tuple);
681
682 /**
683 * \brief Adds an interface association tuple to the Interface Association Set.
684 *
685 * \param tuple The interface association tuple to be added.
686 */
687 void AddIfaceAssocTuple(const IfaceAssocTuple& tuple);
688
689 /**
690 * \brief Removed an interface association tuple to the Interface Association Set.
691 *
692 * \param tuple The interface association tuple to be removed.
693 */
694 void RemoveIfaceAssocTuple(const IfaceAssocTuple& tuple);
695
696 /**
697 * \brief Adds a host network association tuple to the Association Set.
698 *
699 * \param tuple The host network association tuple to be added.
700 */
701 void AddAssociationTuple(const AssociationTuple& tuple);
702
703 /**
704 * \brief Removes a host network association tuple to the Association Set.
705 *
706 * \param tuple The host network association tuple to be removed.
707 */
708 void RemoveAssociationTuple(const AssociationTuple& tuple);
709
710 /**
711 * \brief Processes a HELLO message following \RFC{3626} specification.
712 *
713 * Link sensing and population of the Neighbor Set, 2-hop Neighbor Set and MPR
714 * Selector Set are performed.
715 *
716 * \param msg the %OLSR message which contains the HELLO message.
717 * \param receiverIface the address of the interface where the message was received from.
718 * \param senderIface the address of the interface where the message was sent from.
719 */
720 void ProcessHello(const olsr::MessageHeader& msg,
721 const Ipv4Address& receiverIface,
722 const Ipv4Address& senderIface);
723
724 /**
725 * \brief Processes a TC message following \RFC{3626} specification.
726 *
727 * The Topology Set is updated (if needed) with the information of
728 * the received TC message.
729 *
730 * \param msg The %OLSR message which contains the TC message.
731 * \param senderIface The address of the interface where the message was sent from.
732 *
733 */
734 void ProcessTc(const olsr::MessageHeader& msg, const Ipv4Address& senderIface);
735
736 /**
737 * \brief Processes a MID message following \RFC{3626} specification.
738 *
739 * The Interface Association Set is updated (if needed) with the information
740 * of the received MID message.
741 *
742 * \param msg the %OLSR message which contains the MID message.
743 * \param senderIface the address of the interface where the message was sent from.
744 */
745 void ProcessMid(const olsr::MessageHeader& msg, const Ipv4Address& senderIface);
746
747 /**
748 *
749 * \brief Processes a HNA message following \RFC{3626} specification.
750 *
751 * The Host Network Association Set is updated (if needed) with the information
752 * of the received HNA message.
753 *
754 * \param msg the %OLSR message which contains the HNA message.
755 * \param senderIface the address of the interface where the message was sent from.
756 *
757 */
758 void ProcessHna(const olsr::MessageHeader& msg, const Ipv4Address& senderIface);
759
760 /**
761 * \brief Updates Link Set according to a new received HELLO message
762 * (following \RFC{3626} specification). Neighbor Set is also updated if needed.
763 * \param msg The received message.
764 * \param hello The received HELLO sub-message.
765 * \param receiverIface The interface that received the message.
766 * \param senderIface The sender interface.
767 */
768 void LinkSensing(const olsr::MessageHeader& msg,
769 const olsr::MessageHeader::Hello& hello,
770 const Ipv4Address& receiverIface,
771 const Ipv4Address& senderIface);
772
773 /**
774 * \brief Updates the Neighbor Set according to the information contained in
775 * a new received HELLO message (following \RFC{3626}).
776 * \param msg The received message.
777 * \param hello The received HELLO sub-message.
778 */
780 const olsr::MessageHeader::Hello& hello);
781
782 /**
783 * \brief Updates the 2-hop Neighbor Set according to the information contained
784 * in a new received HELLO message (following \RFC{3626}).
785 * \param msg The received message.
786 * \param hello The received HELLO sub-message.
787 */
789 const olsr::MessageHeader::Hello& hello);
790
791 /**
792 * \brief Updates the MPR Selector Set according to the information contained in
793 * a new received HELLO message (following \RFC{3626}).
794 * \param msg The received message.
795 * \param hello The received HELLO sub-message.
796 */
798 const olsr::MessageHeader::Hello& hello);
799
800 int Degree(const NeighborTuple& tuple);
801
802 /**
803 * Check that address is one of my interfaces.
804 * \param a the address to check.
805 * \return true if the address is own by the node.
806 */
807 bool IsMyOwnAddress(const Ipv4Address& a) const;
808
809 Ipv4Address m_mainAddress; //!< the node main address.
810
811 // One socket per interface, each bound to that interface's address
812 // (reason: for OLSR Link Sensing we need to know on which interface
813 // HELLO messages arrive)
814 std::map<Ptr<Socket>, Ipv4InterfaceAddress>
815 m_sendSockets; //!< Container of sockets and the interfaces they are opened onto.
816 Ptr<Socket> m_recvSocket; //!< Receiving socket.
817
818 /// Rx packet trace.
820
821 /// Tx packet trace.
823
824 /// Routing table changes callback
826
827 /// Provides uniform random variables.
829};
830
831} // namespace olsr
832} // namespace ns3
833
834#endif /* OLSR_AGENT_IMPL_H */
Testcase for MPR computation mechanism.
An object that tracks scheduled events and automatically cancels them when it is destroyed.
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
Abstract base class for IPv4 routing protocols.
Callback< void, Ptr< Ipv4MulticastRoute >, Ptr< const Packet >, const Ipv4Header & > MulticastForwardCallback
Callback for multicast packets to be forwarded.
Callback< void, Ptr< const Packet >, const Ipv4Header &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Smart pointer class similar to boost::intrusive_ptr.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
@ S
second
Definition nstime.h:105
A simple virtual Timer class.
Definition timer.h:67
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
This header can store HELP, TC, MID and HNA messages.
This class encapsulates all data structures needed for maintaining internal state of an OLSR node.
Definition olsr-state.h:25
The basic layout of any packet in OLSR is as follows (omitting IP and UDP headers):
Definition olsr-header.h:68
OLSR routing protocol for IPv4.
void SendHna()
Creates a new OLSR HNA message which is buffered for being sent later on.
void RemoveHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Removes the specified (networkAddr, netmask) tuple from the list of local HNA associations to be sent...
OlsrState m_state
Internal state with all needed data structs.
void AddTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Adds a 2-hop neighbor tuple to the 2-hop Neighbor Set.
Time m_hnaInterval
HNA messages' emission interval.
const MprSelectorSet & GetMprSelectors() const
Gets the MPR selectors.
void SendQueuedMessages()
Creates as many OLSR packets as needed in order to send all buffered OLSR messages.
uint16_t m_messageSequenceNumber
Messages sequence number counter.
const TwoHopNeighborSet & GetTwoHopNeighbors() const
Get the two hop neighbors.
olsr::MessageList m_queuedMessages
A list of pending messages which are buffered awaiting for being sent.
void RemoveLinkTuple(const LinkTuple &tuple)
Removes a link tuple from the Link Set.
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void NotifyInterfaceUp(uint32_t interface) override
TracedCallback< uint32_t > m_routingTableChanged
Routing table changes callback.
void QueueMessage(const olsr::MessageHeader &message, Time delay)
Enqueues an OLSR message which will be sent with a delay of (0, delay].
void LinkTupleAdded(const LinkTuple &tuple, Willingness willingness)
Adds a link tuple.
void AddNeighborTuple(const NeighborTuple &tuple)
Adds a neighbor tuple to the Neighbor Set.
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_sendSockets
Container of sockets and the interfaces they are opened onto.
void LinkSensing(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello, const Ipv4Address &receiverIface, const Ipv4Address &senderIface)
Updates Link Set according to a new received HELLO message (following RFC 3626 specification).
void SendPacket(Ptr< Packet > packet, const MessageList &containedMessages)
Send an OLSR message.
Timer m_tcTimer
Timer for the TC message.
void AddHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Injects the specified (networkAddr, netmask) tuple in the list of local HNA associations to be sent b...
const NeighborSet & GetNeighbors() const
Get the one hop neighbors.
Ptr< Ipv4StaticRouting > m_hnaRoutingTable
Routing table for HNA routes.
void SendHello()
Creates a new OLSR HELLO message which is buffered for being sent later on.
void DoDispose() override
Destructor implementation.
bool IsMyOwnAddress(const Ipv4Address &a) const
Check that address is one of my interfaces.
bool FindSendEntry(const RoutingTableEntry &entry, RoutingTableEntry &outEntry) const
Finds the appropriate entry which must be used in order to forward a data packet to a next hop (given...
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) override
Route an input packet (to be forwarded or locally delivered)
void LinkTupleTimerExpire(Ipv4Address neighborIfaceAddr)
Removes tuple_ if expired.
void MprSelTupleTimerExpire(Ipv4Address mainAddr)
Removes MPR selector tuple_ if expired.
void RemoveTopologyTuple(const TopologyTuple &tuple)
Removes a topology tuple to the Topology Set.
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...
void AddTopologyTuple(const TopologyTuple &tuple)
Adds a topology tuple to the Topology Set.
void ProcessTc(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a TC message following RFC 3626 specification.
void SetRoutingTableAssociation(Ptr< Ipv4StaticRouting > routingTable)
Associates the specified Ipv4StaticRouting routing table to the OLSR routing protocol.
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 (...
MprSet GetMprSet() const
Gets the MPR set.
Ipv4Address m_mainAddress
the node main address.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
void Nb2hopTupleTimerExpire(Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr)
Removes 2_hop neighbor tuple_ if expired.
void HelloTimerExpire()
Sends a HELLO message and reschedules the HELLO timer.
void AssociationTupleTimerExpire(Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask)
Removes association tuple_ if expired.
static const uint16_t OLSR_PORT_NUMBER
port number (698)
uint32_t GetSize() const
Returns the routing table size.
void SetMainInterface(uint32_t interface)
Set the OLSR main address to the first address on the indicated interface.
void RoutingTableComputation()
Creates the routing table of the node following RFC 3626 hints.
void SendMid()
Creates a new OLSR MID message which is buffered for being sent later on.
void AddEntry(const Ipv4Address &dest, const Ipv4Address &next, uint32_t interface, uint32_t distance)
Adds a new entry into the routing table.
void HnaTimerExpire()
Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer.
void AddIfaceAssocTuple(const IfaceAssocTuple &tuple)
Adds an interface association tuple to the Interface Association Set.
void RemoveDuplicateTuple(const DuplicateTuple &tuple)
Removes a duplicate tuple from the Duplicate Set.
const TopologySet & GetTopologySet() const
Gets the topology set.
void SendTc()
Creates a new OLSR TC message which is buffered for being sent later on.
void DupTupleTimerExpire(Ipv4Address address, uint16_t sequenceNumber)
Removes tuple if expired.
Ipv4Address GetMainAddress(Ipv4Address iface_addr) const
Gets the main address associated with a given interface address.
Timer m_midTimer
Timer for the MID message.
EventGarbageCollector m_events
Running events.
void SetIpv4(Ptr< Ipv4 > ipv4) override
bool Lookup(const Ipv4Address &dest, RoutingTableEntry &outEntry) const
Looks up an entry for the specified destination address.
void ProcessMid(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a MID message following RFC 3626 specification.
Ptr< const Ipv4StaticRouting > GetRoutingTableAssociation() const
Returns the internal HNA table.
Timer m_queuedMessagesTimer
timer for throttling outgoing messages
Willingness m_willingness
Willingness for forwarding packets on behalf of other nodes.
uint16_t m_ansn
Advertised Neighbor Set sequence number.
void RemoveIfaceAssocTuple(const IfaceAssocTuple &tuple)
Removed an interface association tuple to the Interface Association Set.
void NotifyInterfaceDown(uint32_t interface) override
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
Time m_midInterval
MID messages' emission interval.
void Clear()
Clears the routing table and frees the memory assigned to each one of its entries.
void TopologyTupleTimerExpire(Ipv4Address destAddr, Ipv4Address lastAddr)
Removes topology tuple_ if expired.
void MprComputation()
Computes MPR set of a node following RFC 3626 hints.
void ProcessHello(const olsr::MessageHeader &msg, const Ipv4Address &receiverIface, const Ipv4Address &senderIface)
Processes a HELLO message following RFC 3626 specification.
static TypeId GetTypeId()
Get the type ID.
std::map< Ipv4Address, RoutingTableEntry > m_table
Data structure for the routing table.
void RemoveEntry(const Ipv4Address &dest)
Deletes the entry whose destination address is given.
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...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
uint16_t m_packetSequenceNumber
Packets sequence number counter.
Timer m_helloTimer
Timer for the HELLO message.
void(* PacketTxRxTracedCallback)(const PacketHeader &header, const MessageList &messages)
TracedCallback signature for Packet transmit and receive events.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
int Degree(const NeighborTuple &tuple)
This auxiliary function (defined in RFC 3626 ) is used for calculating the MPR Set.
void RemoveMprSelectorTuple(const MprSelectorTuple &tuple)
Removes an MPR selector tuple from the MPR Selector Set.
void ProcessHna(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a HNA message following RFC 3626 specification.
Ptr< Socket > m_recvSocket
Receiving socket.
uint16_t GetPacketSequenceNumber()
Increments packet sequence number and returns the new value.
void DoInitialize() override
Initialize() implementation.
TracedCallback< const PacketHeader &, const MessageList & > m_txPacketTrace
Tx packet trace.
void IncrementAnsn()
Increments the ANSN counter.
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the interfaces to be excluded.
void ForwardDefault(olsr::MessageHeader olsrMessage, DuplicateTuple *duplicated, const Ipv4Address &localIface, const Ipv4Address &senderAddress)
OLSR's default forwarding algorithm.
Time m_helloInterval
HELLO messages' emission interval.
Timer m_hnaTimer
Timer for the HNA message.
std::vector< RoutingTableEntry > GetRoutingTableEntries() const
Get the routing table entries.
void LinkTupleUpdated(const LinkTuple &tuple, Willingness willingness)
This function is invoked when a link tuple is updated.
std::set< uint32_t > GetInterfaceExclusions() const
Get the excluded interfaces.
void AddAssociationTuple(const AssociationTuple &tuple)
Adds a host network association tuple to the Association Set.
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.
TracedCallback< const PacketHeader &, const MessageList & > m_rxPacketTrace
Rx packet trace.
void Dump()
Dump the neighbor table, two-hop neighbor table, and routing table to logging output (NS_LOG_DEBUG lo...
void MidTimerExpire()
Sends a MID message (if the node has more than one interface) and resets the MID timer.
void RemoveTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Removes a 2-hop neighbor tuple from the 2-hop Neighbor Set.
void RemoveAssociationTuple(const AssociationTuple &tuple)
Removes a host network association tuple to the Association Set.
void(* TableChangeTracedCallback)(uint32_t size)
TracedCallback signature for routing table computation.
Time m_tcInterval
TC messages' emission interval.
bool UsesNonOlsrOutgoingInterface(const Ipv4RoutingTableEntry &route)
Tests whether or not the specified route uses a non-OLSR outgoing interface.
Ptr< Ipv4StaticRouting > m_routingTableAssociation
Associations from an Ipv4StaticRouting instance.
bool m_linkTupleTimerFirstTime
Flag to indicate if it is the first time the LinkTupleTimer fires.
const OlsrState & GetOlsrState() const
Gets the underlying OLSR state object.
uint16_t GetMessageSequenceNumber()
Increments message sequence number and returns the new value.
void RemoveNeighborTuple(const NeighborTuple &tuple)
Removes a neighbor tuple from the Neighbor Set.
void IfaceAssocTupleTimerExpire(Ipv4Address ifaceAddr)
Removes interface association tuple_ if expired.
void RecvOlsr(Ptr< Socket > socket)
Receive an OLSR message.
std::set< uint32_t > m_interfaceExclusions
Set of interfaces excluded by OSLR.
void NeighborLoss(const LinkTuple &tuple)
Performs all actions needed when a neighbor loss occurs.
Ptr< Ipv4 > m_ipv4
IPv4 object the routing is linked to.
void AddMprSelectorTuple(const MprSelectorTuple &tuple)
Adds an MPR selector tuple to the MPR Selector Set.
Willingness
Willingness for forwarding packets from other nodes.
std::vector< MprSelectorTuple > MprSelectorSet
MPR Selector Set type.
std::vector< TwoHopNeighborTuple > TwoHopNeighborSet
2-hop Neighbor Set type.
std::vector< TopologyTuple > TopologySet
Topology Set type.
std::set< Ipv4Address > MprSet
MPR Set type.
std::vector< NeighborTuple > NeighborSet
Neighbor Set type.
std::vector< MessageHeader > MessageList
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition olsr.py:1
An Interface Association Tuple.
HELLO Message Format.
An OLSR's routing table entry.
RoutingTableEntry()
uint32_t distance
Distance in hops to the destination.
Ipv4Address nextAddr
Address of the next hop.
uint32_t interface
Interface index.
Ipv4Address destAddr
Address of the destination node.