1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2004 Francisco J. Ros 4 * Copyright (c) 2007 INESC Porto 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation; 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 19 * Authors: Francisco J. Ros <fjrm@dif.um.es> 20 * Gustavo J. A. M. Carneiro <gjc@inescporto.pt> 21 */ 22 23 #ifndef OLSR_AGENT_IMPL_H 24 #define OLSR_AGENT_IMPL_H 25 26 #include "olsr-header.h" 27 #include "ns3/test.h" 28 #include "olsr-state.h" 29 #include "olsr-repositories.h" 30 31 #include "ns3/object.h" 32 #include "ns3/packet.h" 33 #include "ns3/node.h" 34 #include "ns3/socket.h" 35 #include "ns3/event-garbage-collector.h" 36 #include "ns3/random-variable-stream.h" 37 #include "ns3/timer.h" 38 #include "ns3/traced-callback.h" 39 #include "ns3/ipv4.h" 40 #include "ns3/ipv4-routing-protocol.h" 41 #include "ns3/ipv4-static-routing.h" 42 43 #include <vector> 44 #include <map> 45 46 /// Testcase for MPR computation mechanism 47 class OlsrMprTestCase; 48 49 namespace ns3 { 50 namespace olsr { 51 52 /// 53 /// \defgroup olsr OLSR Routing 54 /// This section documents the API of the ns-3 OLSR module. For a generic 55 /// functional description, please refer to the ns-3 manual. 56 57 /// \ingroup olsr 58 /// An %OLSR's routing table entry. 59 struct RoutingTableEntry 60 { 61 Ipv4Address destAddr; //!< Address of the destination node. 62 Ipv4Address nextAddr; //!< Address of the next hop. 63 uint32_t interface; //!< Interface index 64 uint32_t distance; //!< Distance in hops to the destination. 65 RoutingTableEntryRoutingTableEntry66 RoutingTableEntry (void) : // default values 67 destAddr (), nextAddr (), 68 interface (0), distance (0) 69 { 70 } 71 }; 72 73 class RoutingProtocol; 74 75 /// 76 /// \ingroup olsr 77 /// 78 /// \brief OLSR routing protocol for IPv4 79 /// 80 class RoutingProtocol : public Ipv4RoutingProtocol 81 { 82 public: 83 /** 84 * Declared friend to enable unit tests. 85 */ 86 friend class ::OlsrMprTestCase; 87 88 static const uint16_t OLSR_PORT_NUMBER; //!< port number (698) 89 90 /** 91 * \brief Get the type ID. 92 * \return The object TypeId. 93 */ 94 static TypeId GetTypeId (void); 95 96 RoutingProtocol (void); 97 virtual ~RoutingProtocol (void); 98 99 /** 100 * \brief Set the OLSR main address to the first address on the indicated interface. 101 * 102 * \param interface IPv4 interface index 103 */ 104 void SetMainInterface (uint32_t interface); 105 106 /** 107 * Dump the neighbor table, two-hop neighbor table, and routing table 108 * to logging output (NS_LOG_DEBUG log level). If logging is disabled, 109 * this function does nothing. 110 */ 111 void Dump (void); 112 113 /** 114 * Get the routing table entries. 115 * \return the list of routing table entries discovered by OLSR 116 */ 117 std::vector<RoutingTableEntry> GetRoutingTableEntries (void) const; 118 119 /** 120 * Gets the MPR set. 121 * \return The MPR set. 122 */ 123 MprSet GetMprSet (void) const; 124 125 /** 126 * Gets the MPR selectors. 127 * \returns The MPR selectors. 128 */ 129 const MprSelectorSet & GetMprSelectors (void) const; 130 131 /** 132 * Get the one hop neighbors. 133 * \return the set of neighbors discovered by OLSR 134 */ 135 const NeighborSet & GetNeighbors (void) const; 136 137 /** 138 * Get the two hop neighbors. 139 * \return the set of two hop neighbors discovered by OLSR 140 */ 141 const TwoHopNeighborSet & GetTwoHopNeighbors (void) const; 142 143 /** 144 * Gets the topology set. 145 * \returns The topology set discovery by OLSR 146 */ 147 const TopologySet & GetTopologySet (void) const; 148 149 /** 150 * Gets the underlying OLSR state object 151 * \returns The OLSR state object 152 */ 153 const OlsrState & GetOlsrState (void) const; 154 155 /** 156 * Assign a fixed random variable stream number to the random variables 157 * used by this model. Return the number of streams (possibly zero) that 158 * have been assigned. 159 * 160 * \param stream first stream index to use 161 * \return the number of stream indices assigned by this model 162 */ 163 int64_t AssignStreams (int64_t stream); 164 165 /** 166 * TracedCallback signature for Packet transmit and receive events. 167 * 168 * \param [in] header 169 * \param [in] messages 170 */ 171 typedef void (* PacketTxRxTracedCallback)(const PacketHeader & header, const MessageList & messages); 172 173 /** 174 * TracedCallback signature for routing table computation. 175 * 176 * \param [in] size Final routing table size. 177 */ 178 typedef void (* TableChangeTracedCallback) (uint32_t size); 179 180 private: 181 std::set<uint32_t> m_interfaceExclusions; //!< Set of interfaces excluded by OSLR. 182 Ptr<Ipv4StaticRouting> m_routingTableAssociation; //!< Associations from an Ipv4StaticRouting instance 183 184 public: 185 /** 186 * Get the excluded interfaces. 187 * \returns Container of excluded interfaces. 188 */ GetInterfaceExclusions(void)189 std::set<uint32_t> GetInterfaceExclusions (void) const 190 { 191 return m_interfaceExclusions; 192 } 193 194 /** 195 * Set the interfaces to be excluded. 196 * \param exceptions Container of excluded interfaces. 197 */ 198 void SetInterfaceExclusions (std::set<uint32_t> exceptions); 199 200 /** 201 * \brief Injects the specified (networkAddr, netmask) tuple in the list of 202 * local HNA associations to be sent by the node via HNA messages. 203 * If this tuple already exists, nothing is done. 204 * 205 * \param networkAddr The network address. 206 * \param netmask The network mask. 207 */ 208 void AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask); 209 210 /** 211 * \brief Removes the specified (networkAddr, netmask) tuple from the list of 212 * local HNA associations to be sent by the node via HNA messages. 213 * If this tuple does not exist, nothing is done (see "OlsrState::EraseAssociation()"). 214 * 215 * \param networkAddr The network address. 216 * \param netmask The network mask. 217 */ 218 void RemoveHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask); 219 220 /** 221 * \brief Associates the specified Ipv4StaticRouting routing table 222 * to the OLSR routing protocol. Entries from this associated 223 * routing table that use non-olsr outgoing interfaces are added 224 * to the list of local HNA associations so that they are included 225 * in HNA messages sent by the node. 226 * If this method is called more than once, entries from the old 227 * association are deleted before entries from the new one are added. 228 * \param routingTable the Ipv4StaticRouting routing table to be associated. 229 */ 230 void SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable); 231 232 /** 233 * \brief Returns the internal HNA table 234 * \returns the internal HNA table 235 */ 236 Ptr<const Ipv4StaticRouting> GetRoutingTableAssociation (void) const; 237 238 protected: 239 virtual void DoInitialize (void); 240 virtual void DoDispose (void); 241 242 private: 243 std::map<Ipv4Address, RoutingTableEntry> m_table; //!< Data structure for the routing table. 244 245 Ptr<Ipv4StaticRouting> m_hnaRoutingTable; //!< Routing table for HNA routes 246 247 EventGarbageCollector m_events; //!< Running events. 248 249 uint16_t m_packetSequenceNumber; //!< Packets sequence number counter. 250 uint16_t m_messageSequenceNumber; //!< Messages sequence number counter. 251 uint16_t m_ansn; //!< Advertised Neighbor Set sequence number. 252 253 Time m_helloInterval; //!< HELLO messages' emission interval. 254 Time m_tcInterval; //!< TC messages' emission interval. 255 Time m_midInterval; //!< MID messages' emission interval. 256 Time m_hnaInterval; //!< HNA messages' emission interval. 257 uint8_t m_willingness; //!< Willingness for forwarding packets on behalf of other nodes. 258 259 OlsrState m_state; //!< Internal state with all needed data structs. 260 Ptr<Ipv4> m_ipv4; //!< IPv4 object the routing is linked to. 261 262 /** 263 * \brief Clears the routing table and frees the memory assigned to each one of its entries. 264 */ 265 void Clear (void); 266 267 /** 268 * Returns the routing table size. 269 * \return The routing table size. 270 */ GetSize(void)271 uint32_t GetSize (void) const 272 { 273 return m_table.size (); 274 } 275 276 /** 277 * \brief Deletes the entry whose destination address is given. 278 * \param dest address of the destination node. 279 */ 280 void RemoveEntry (const Ipv4Address &dest); 281 /** 282 * \brief Adds a new entry into the routing table. 283 * 284 * If an entry for the given destination existed, it is deleted and freed. 285 * 286 * \param dest address of the destination node. 287 * \param next address of the next hop node. 288 * \param interface address of the local interface. 289 * \param distance distance to the destination node. 290 */ 291 void AddEntry (const Ipv4Address &dest, 292 const Ipv4Address &next, 293 uint32_t interface, 294 uint32_t distance); 295 /** 296 * \brief Adds a new entry into the routing table. 297 * 298 * If an entry for the given destination existed, an error is thrown. 299 * 300 * \param dest address of the destination node. 301 * \param next address of the next hop node. 302 * \param interfaceAddress address of the local interface. 303 * \param distance distance to the destination node. 304 */ 305 void AddEntry (const Ipv4Address &dest, 306 const Ipv4Address &next, 307 const Ipv4Address &interfaceAddress, 308 uint32_t distance); 309 310 /** 311 * \brief Looks up an entry for the specified destination address. 312 * \param [in] dest Destination address. 313 * \param [out] outEntry Holds the routing entry result, if found. 314 * \return true if found, false if not found. 315 */ 316 bool Lookup (const Ipv4Address &dest, 317 RoutingTableEntry &outEntry) const; 318 319 /** 320 * \brief Finds the appropriate entry which must be used in order to forward 321 * a data packet to a next hop (given a destination). 322 * 323 * Imagine a routing table like this: [A,B] [B,C] [C,C]; being each pair of the 324 * form [dest addr, next-hop addr]. In this case, if this function is invoked 325 * with [A,B] then pair [C,C] is returned because C is the next hop that must be used 326 * to forward a data packet destined to A. That is, C is a neighbor of this node, 327 * but B isn't. This function finds the appropriate neighbor for forwarding a packet. 328 * 329 * \param[in] entry The routing table entry which indicates the destination node 330 * we are interested in. 331 * 332 * \param[out] outEntry The appropriate routing table entry which indicates the next 333 * hop which must be used for forwarding a data packet, or NULL if there is no such entry. 334 * 335 * \return True if an entry was found, false otherwise. 336 */ 337 bool FindSendEntry (const RoutingTableEntry &entry, 338 RoutingTableEntry &outEntry) const; 339 340 public: 341 // From Ipv4RoutingProtocol 342 virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, 343 const Ipv4Header &header, 344 Ptr<NetDevice> oif, 345 Socket::SocketErrno &sockerr); 346 virtual bool RouteInput (Ptr<const Packet> p, 347 const Ipv4Header &header, 348 Ptr<const NetDevice> idev, 349 UnicastForwardCallback ucb, 350 MulticastForwardCallback mcb, 351 LocalDeliverCallback lcb, 352 ErrorCallback ecb); 353 virtual void SetIpv4 (Ptr<Ipv4> ipv4); 354 355 /** 356 * \returns the ipv4 object this routing protocol is associated with 357 */ 358 NS_DEPRECATED_3_34 359 virtual Ptr<Ipv4> GetIpv4 (void) const; 360 virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const; 361 362 363 private: 364 virtual void NotifyInterfaceUp (uint32_t interface); 365 virtual void NotifyInterfaceDown (uint32_t interface); 366 virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address); 367 virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address); 368 369 /** 370 * Send an OLSR message. 371 * \param packet The packet to be sent. 372 * \param containedMessages The messages contained in the packet. 373 */ 374 void SendPacket (Ptr<Packet> packet, const MessageList &containedMessages); 375 376 /** 377 * Increments packet sequence number and returns the new value. 378 * \return The packet sequence number. 379 */ 380 inline uint16_t GetPacketSequenceNumber (void); 381 382 /** 383 * Increments message sequence number and returns the new value. 384 * \return The message sequence number. 385 */ 386 inline uint16_t GetMessageSequenceNumber (void); 387 388 /** 389 * Receive an OLSR message. 390 * \param socket The receiving socket. 391 */ 392 void RecvOlsr (Ptr<Socket> socket); 393 394 /** 395 * \brief Computates MPR set of a node following \RFC{3626} hints. 396 */ 397 void MprComputation (void); 398 399 /** 400 * \brief Creates the routing table of the node following \RFC{3626} hints. 401 */ 402 void RoutingTableComputation (void); 403 404 public: 405 /** 406 * \brief Gets the main address associated with a given interface address. 407 * \param iface_addr the interface address. 408 * \return the corresponding main address. 409 */ 410 Ipv4Address GetMainAddress (Ipv4Address iface_addr) const; 411 412 private: 413 /** 414 * \brief Tests whether or not the specified route uses a non-OLSR outgoing interface. 415 * \param route The route to be tested. 416 * \returns True if the outgoing interface of the specified route is a non-OLSR interface, false otherwise. 417 */ 418 bool UsesNonOlsrOutgoingInterface (const Ipv4RoutingTableEntry &route); 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 (void); 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 (void); 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 MID timer. 436 */ 437 void MidTimerExpire (void); 438 439 Timer m_hnaTimer; //!< Timer for the HNA message. 440 /** 441 * \brief Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer. 442 */ 443 void HnaTimerExpire (void); 444 445 /** 446 * \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime. 447 * 448 * The task of actually removing the tuple is left to the OLSR agent. 449 * 450 * \param address The address of the tuple. 451 * \param sequenceNumber The sequence number of the tuple. 452 */ 453 void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber); 454 455 bool m_linkTupleTimerFirstTime; //!< Flag to indicate if it is the first time the LinkTupleTimer fires. 456 /** 457 * \brief Removes tuple_ if expired. Else if symmetric time 458 * has expired then it is assumed a neighbor loss and agent_->nb_loss() 459 * is called. In this case the timer is rescheduled to expire at 460 * tuple_->time(). Otherwise the timer is rescheduled to expire at 461 * the minimum between tuple_->time() and tuple_->sym_time(). 462 * 463 * The task of actually removing the tuple is left to the OLSR agent. 464 * 465 * \param neighborIfaceAddr The tuple neighbor interface address. 466 */ 467 void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr); 468 469 /** 470 * \brief Removes 2_hop neighbor tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). 471 * 472 * The task of actually removing the tuple is left to the OLSR agent. 473 * 474 * \param neighborMainAddr The neighbor main address. 475 * \param twoHopNeighborAddr The 2-hop neighbor address. 476 */ 477 void Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr); 478 479 /** 480 * \brief Removes MPR selector tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). 481 * 482 * The task of actually removing the tuple is left to the OLSR agent. 483 * 484 * \param mainAddr The tuple IPv4 address. 485 */ 486 void MprSelTupleTimerExpire (Ipv4Address mainAddr); 487 488 /** 489 * \brief Removes topology tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). 490 * 491 * The task of actually removing the tuple is left to the OLSR agent. 492 * 493 * \param destAddr The destination address. 494 * \param lastAddr The last address. 495 */ 496 void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr); 497 498 /** 499 * \brief Removes interface association tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). 500 * 501 * \param ifaceAddr The interface address. 502 */ 503 void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr); 504 505 /** 506 * \brief Removes association tuple_ if expired. Else timer is rescheduled to expire at tuple_->time(). 507 * 508 * \param gatewayAddr The gateway address. 509 * \param networkAddr The network address. 510 * \param netmask The network mask. 511 */ 512 void AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask); 513 514 /** 515 * Increments the ANSN counter. 516 */ 517 void IncrementAnsn (void); 518 519 /// A list of pending messages which are buffered awaiting for being sent. 520 olsr::MessageList m_queuedMessages; 521 Timer m_queuedMessagesTimer; //!< timer for throttling outgoing messages 522 523 /** 524 * \brief OLSR's default forwarding algorithm. 525 * 526 * See \RFC{3626} for details. 527 * 528 * \param olsrMessage The %OLSR message which must be forwarded. 529 * \param duplicated NULL if the message has never been considered for forwarding, or a 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 Enques 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 (void); 557 558 /** 559 * \brief Creates a new %OLSR HELLO message which is buffered for being sent later on. 560 */ 561 void SendHello (void); 562 563 /** 564 * \brief Creates a new %OLSR TC message which is buffered for being sent later on. 565 */ 566 void SendTc (void); 567 568 /** 569 * \brief Creates a new %OLSR MID message which is buffered for being sent later on. 570 */ 571 void SendMid (void); 572 573 /** 574 * \brief Creates a new %OLSR HNA message which is buffered for being sent later on. 575 */ 576 void SendHna (void); 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 Thetuple to be added. 604 * \param willingness The tuple willingness. 605 */ 606 void LinkTupleAdded (const LinkTuple &tuple, uint8_t 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, uint8_t 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 */ 643 void AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple); 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 */ 650 void RemoveTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple); 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, 735 const Ipv4Address &senderIface); 736 737 /** 738 * \brief Processes a MID message following \RFC{3626} specification. 739 * 740 * The Interface Association Set is updated (if needed) with the information 741 * of the received MID message. 742 * 743 * \param msg the %OLSR message which contains the MID message. 744 * \param senderIface the address of the interface where the message was sent from. 745 */ 746 void ProcessMid (const olsr::MessageHeader &msg, 747 const Ipv4Address &senderIface); 748 749 /** 750 * 751 * \brief Processes a HNA message following \RFC{3626} specification. 752 * 753 * The Host Network Association Set is updated (if needed) with the information 754 * of the received HNA message. 755 * 756 * \param msg the %OLSR message which contains the HNA message. 757 * \param senderIface the address of the interface where the message was sent from. 758 * 759 */ 760 void ProcessHna (const olsr::MessageHeader &msg, 761 const Ipv4Address &senderIface); 762 763 /** 764 * \brief Updates Link Set according to a new received HELLO message 765 * (following \RFC{3626} specification). Neighbor Set is also updated if needed. 766 * \param msg The received message. 767 * \param hello The received HELLO sub-message. 768 * \param receiverIface The interface that received the message. 769 * \param senderIface The sender interface. 770 */ 771 void LinkSensing (const olsr::MessageHeader &msg, 772 const olsr::MessageHeader::Hello &hello, 773 const Ipv4Address &receiverIface, 774 const Ipv4Address &senderIface); 775 776 /** 777 * \brief Updates the Neighbor Set according to the information contained in 778 * a new received HELLO message (following \RFC{3626}). 779 * \param msg The received message. 780 * \param hello The received HELLO sub-message. 781 */ 782 void PopulateNeighborSet (const olsr::MessageHeader &msg, 783 const olsr::MessageHeader::Hello &hello); 784 785 /** 786 * \brief Updates the 2-hop Neighbor Set according to the information contained 787 * in a new received HELLO message (following \RFC{3626}). 788 * \param msg The received message. 789 * \param hello The received HELLO sub-message. 790 */ 791 void PopulateTwoHopNeighborSet (const olsr::MessageHeader &msg, 792 const olsr::MessageHeader::Hello &hello); 793 794 /** 795 * \brief Updates the MPR Selector Set according to the information contained in 796 * a new received HELLO message (following \RFC{3626}). 797 * \param msg The received message. 798 * \param hello The received HELLO sub-message. 799 */ 800 void PopulateMprSelectorSet (const olsr::MessageHeader &msg, 801 const olsr::MessageHeader::Hello &hello); 802 803 int Degree (NeighborTuple const &tuple); 804 805 /** 806 * Check that address is one of my interfaces. 807 * \param a the address to check. 808 * \return true if the address is own by the node. 809 */ 810 bool IsMyOwnAddress (const Ipv4Address & a) const; 811 812 Ipv4Address m_mainAddress; //!< the node main address. 813 814 // One socket per interface, each bound to that interface's address 815 // (reason: for OLSR Link Sensing we need to know on which interface 816 // HELLO messages arrive) 817 std::map< Ptr<Socket>, Ipv4InterfaceAddress > m_sendSockets; //!< Container of sockets and the interfaces they are opened onto. 818 Ptr<Socket> m_recvSocket; //!< Receiving socket. 819 820 821 /// Rx packet trace. 822 TracedCallback <const PacketHeader &, const MessageList &> m_rxPacketTrace; 823 824 /// Tx packet trace. 825 TracedCallback <const PacketHeader &, const MessageList &> m_txPacketTrace; 826 827 /// Routing table chanes challback 828 TracedCallback <uint32_t> m_routingTableChanged; 829 830 /// Provides uniform random variables. 831 Ptr<UniformRandomVariable> m_uniformRandomVariable; 832 833 }; 834 835 } 836 } // namespace ns3 837 838 #endif /* OLSR_AGENT_IMPL_H */ 839