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