--- a/src/internet/model/ipv4-global-routing.cc +++ a/src/internet/model/ipv4-global-routing.cc @@ -489,53 +489,25 @@ NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0); uint32_t iif = m_ipv4->GetInterfaceForDevice (idev); - if (header.GetDestination ().IsMulticast ()) + if (m_ipv4->IsDestinationAddress (header.GetDestination (), iif)) { - NS_LOG_LOGIC ("Multicast destination-- returning false"); - return false; // Let other routing protocols try to handle this + if (!lcb.IsNull ()) + { + NS_LOG_LOGIC ("Local delivery to " << header.GetDestination ()); + lcb (p, header, iif); + return true; + } + else + { + // The local delivery callback is null. This may be a multicast + // or broadcast packet, so return false so that another + // multicast routing protocol can handle it. It should be possible + // to extend this to explicitly check whether it is a unicast + // packet, and invoke the error callback if so + return false; + } } - if (header.GetDestination ().IsBroadcast ()) - { - NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)"); - /// \todo Local Deliver for broadcast - /// \todo Forward broadcast - } - - /// \todo Configurable option to enable \RFC{1222} Strong End System Model - // Right now, we will be permissive and allow a source to send us - // a packet to one of our other interface addresses; that is, the - // destination unicast address does not match one of the iif addresses, - // but we check our other interfaces. This could be an option - // (to remove the outer loop immediately below and just check iif). - for (uint32_t j = 0; j < m_ipv4->GetNInterfaces (); j++) - { - for (uint32_t i = 0; i < m_ipv4->GetNAddresses (j); i++) - { - Ipv4InterfaceAddress iaddr = m_ipv4->GetAddress (j, i); - Ipv4Address addr = iaddr.GetLocal (); - if (addr.IsEqual (header.GetDestination ())) - { - if (j == iif) - { - NS_LOG_LOGIC ("For me (destination " << addr << " match)"); - } - else - { - NS_LOG_LOGIC ("For me (destination " << addr << " match) on another interface " << header.GetDestination ()); - } - lcb (p, header, iif); - return true; - } - if (header.GetDestination ().IsEqual (iaddr.GetBroadcast ())) - { - NS_LOG_LOGIC ("For me (interface broadcast address)"); - lcb (p, header, iif); - return true; - } - NS_LOG_LOGIC ("Address "<< addr << " not a match"); - } - } // Check if input device supports IP forwarding if (m_ipv4->IsForwarding (iif) == false) { --- a/src/internet/model/ipv4-static-routing.cc +++ a/src/internet/model/ipv4-static-routing.cc @@ -495,7 +495,7 @@ uint32_t iif = m_ipv4->GetInterfaceForDevice (idev); // Multicast recognition; handle local delivery here - // + if (ipHeader.GetDestination ().IsMulticast ()) { NS_LOG_LOGIC ("Multicast destination"); @@ -514,48 +514,26 @@ return false; // Let other routing protocols try to handle this } } - if (ipHeader.GetDestination ().IsBroadcast ()) + + if (m_ipv4->IsDestinationAddress (ipHeader.GetDestination (), iif)) { - NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)"); - /// \todo Local Deliver for broadcast - /// \todo Forward broadcast + if (!lcb.IsNull ()) + { + NS_LOG_LOGIC ("Local delivery to " << ipHeader.GetDestination ()); + lcb (p, ipHeader, iif); + return true; + } + else + { + // The local delivery callback is null. This may be a multicast + // or broadcast packet, so return false so that another + // multicast routing protocol can handle it. It should be possible + // to extend this to explicitly check whether it is a unicast + // packet, and invoke the error callback if so + return false; + } } - NS_LOG_LOGIC ("Unicast destination"); - /// \todo Configurable option to enable \RFC{1222} Strong End System Model - // Right now, we will be permissive and allow a source to send us - // a packet to one of our other interface addresses; that is, the - // destination unicast address does not match one of the iif addresses, - // but we check our other interfaces. This could be an option - // (to remove the outer loop immediately below and just check iif). - for (uint32_t j = 0; j < m_ipv4->GetNInterfaces (); j++) - { - for (uint32_t i = 0; i < m_ipv4->GetNAddresses (j); i++) - { - Ipv4InterfaceAddress iaddr = m_ipv4->GetAddress (j, i); - Ipv4Address addr = iaddr.GetLocal (); - if (addr.IsEqual (ipHeader.GetDestination ())) - { - if (j == iif) - { - NS_LOG_LOGIC ("For me (destination " << addr << " match)"); - } - else - { - NS_LOG_LOGIC ("For me (destination " << addr << " match) on another interface " << ipHeader.GetDestination ()); - } - lcb (p, ipHeader, iif); - return true; - } - if (ipHeader.GetDestination ().IsEqual (iaddr.GetBroadcast ())) - { - NS_LOG_LOGIC ("For me (interface broadcast address)"); - lcb (p, ipHeader, iif); - return true; - } - NS_LOG_LOGIC ("Address "<< addr << " not a match"); - } - } // Check if input device supports IP forwarding if (m_ipv4->IsForwarding (iif) == false) { --- a/src/olsr/doc/olsr.rst +++ a/src/olsr/doc/olsr.rst @@ -9,13 +9,16 @@ University of Murcia (Spain) by Francisco J. Ros for NS-2, and was ported to NS-3 by Gustavo Carneiro at INESC Porto (Portugal). +The implementation is based on OLSR Version 1 (:rfc:`3626`) and +it is *not* compliant with OLSR Version 2 (:rfc:`7181`) or any +of the Version 2 extensions. + Model Description ***************** The source code for the OLSR model lives in the directory `src/olsr`. - -Design -++++++ +As stated before, the model is based on :rfc:`3626`. Moreover, many +design choices are based on the previous ns2 model. Scope and Limitations +++++++++++++++++++++ @@ -35,13 +38,23 @@ ++++++++++ .. [rfc3626] :rfc:`3626` *Optimized Link State Routing* +.. [rfc7181] :rfc:`7181` *The Optimized Link State Routing Protocol Version 2* Usage ***** +The usage pattern is the one of all the Internet routing protocols. +Since OLSR is not installed by default in the Internet stack, it is necessary to +set it in the Internet Stack helper by using ``InternetStackHelper::SetRoutingHelper`` + Examples ++++++++ +The examples are in the ``src/olsr/examples/`` directory. However, many other examples esists in the +general examples directory, e.g., ``examples/routing/manet-routing-compare.cc``. + +For specific examples of the HNA feature, see the examples in ``src/olsr/examples/``. + Helpers +++++++ @@ -61,21 +74,29 @@ MidInterval, Willingness. Other parameters are defined as macros in ``olsr-routing-protocol.cc``. +The list of configurabel attributes is: + +* HelloInterval (time, default 2s), HELLO messages emission interval. +* TcInterval (time, default 5s), TC messages emission interval. +* MidInterval (time, default 5s), MID messages emission interval. +* HnaInterval (time, default 5s), HNA messages emission interval. +* Willingness (enum, default OLSR_WILL_DEFAULT), Willingness of a node to carry and forward traffic for other nodes. + Tracing +++++++ -Logging -+++++++ +The available traces are: + +* Rx: Receive OLSR packet. +* Tx: Send OLSR packet. +* RoutingTableChanged: The OLSR routing table has changed. Caveats +++++++ +The code does not present any known issue. + Validation ********** -Unit tests -++++++++++ - -Larger-scale performance tests -++++++++++++++++++++++++++++++ - +The code validationhas been done through Wireshark message compliance and unit testings. --- a/src/olsr/helper/olsr-helper.h +++ a/src/olsr/helper/olsr-helper.h @@ -30,6 +30,8 @@ namespace ns3 { /** + * \ingroup olsr + * * \brief Helper class that adds OLSR routing to nodes. * * This class is expected to be used in conjunction with --- a/src/olsr/model/olsr-header.h +++ a/src/olsr/model/olsr-header.h @@ -34,67 +34,95 @@ double EmfToSeconds (uint8_t emf); uint8_t SecondsToEmf (double seconds); -// 3.3. Packet Format -// -// The basic layout of any packet in OLSR is as follows (omitting IP and -// UDP headers): -// -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Packet Length | Packet Sequence Number | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Message Type | Vtime | Message Size | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Originator Address | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Time To Live | Hop Count | Message Sequence Number | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// : MESSAGE : -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Message Type | Vtime | Message Size | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Originator Address | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Time To Live | Hop Count | Message Sequence Number | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// : MESSAGE : -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// : : -// (etc.) +/** + * \ingroup olsr + * + * The basic layout of any packet in OLSR is as follows (omitting IP and + * UDP headers): + \verbatim + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Packet Length | Packet Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Message Type | Vtime | Message Size | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Time To Live | Hop Count | Message Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | + : MESSAGE : + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Message Type | Vtime | Message Size | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Time To Live | Hop Count | Message Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | + : MESSAGE : + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + : : + (etc.) + \endverbatim + * + * This header only holds the common part of a message group, i.e., + * the first 4 bytes. + */ class PacketHeader : public Header { public: PacketHeader (); virtual ~PacketHeader (); + /** + * Set the packet total length. + * \param length The packet length. + */ void SetPacketLength (uint16_t length) { m_packetLength = length; } + + /** + * Get the packet total length. + * \return The packet length. + */ uint16_t GetPacketLength () const { return m_packetLength; } + /** + * Set the packet sequence number. + * \param seqnum The packet sequence number. + */ void SetPacketSequenceNumber (uint16_t seqnum) { m_packetSequenceNumber = seqnum; } + + /** + * Get the packet sequence number. + * \returns The packet sequence number. + */ uint16_t GetPacketSequenceNumber () const { return m_packetSequenceNumber; } private: - uint16_t m_packetLength; - uint16_t m_packetSequenceNumber; + uint16_t m_packetLength; //!< The packet length. + uint16_t m_packetSequenceNumber; //!< The packet sequence number. public: + /** + * \brief Get the type ID. + * \return The object TypeId. + */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; virtual void Print (std::ostream &os) const; @@ -103,20 +131,36 @@ virtual uint32_t Deserialize (Buffer::Iterator start); }; - -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Message Type | Vtime | Message Size | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Originator Address | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Time To Live | Hop Count | Message Sequence Number | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +/** + * \ingroup olsr + * + * This header can store HELP, TC, MID and HNA messages. + * The header size is variable, and depends on the + * actual message type. + * + \verbatim + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Message Type | Vtime | Message Size | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Originator Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Time To Live | Hop Count | Message Sequence Number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | + : MESSAGE : + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \endverbatim + */ class MessageHeader : public Header { public: + /** + * Message type + */ enum MessageType { HELLO_MESSAGE = 1, TC_MESSAGE = 2, @@ -127,79 +171,122 @@ MessageHeader (); virtual ~MessageHeader (); + /** + * Set the message type. + * \param messageType The message type. + */ void SetMessageType (MessageType messageType) { m_messageType = messageType; } + /** + * Get the message type. + * \return The message type. + */ MessageType GetMessageType () const { return m_messageType; } + /** + * Set the validity time. + * \param time The validity time. + */ void SetVTime (Time time) { m_vTime = SecondsToEmf (time.GetSeconds ()); } + /** + * Get the validity time. + * \return The validity time. + */ Time GetVTime () const { return Seconds (EmfToSeconds (m_vTime)); } + /** + * Set the originator address. + * \param originatorAddress The originator address. + */ void SetOriginatorAddress (Ipv4Address originatorAddress) { m_originatorAddress = originatorAddress; } + /** + * Get the originator address. + * \return The originator address. + */ Ipv4Address GetOriginatorAddress () const { return m_originatorAddress; } + /** + * Set the time to live. + * \param timeToLive The time to live. + */ void SetTimeToLive (uint8_t timeToLive) { m_timeToLive = timeToLive; } + /** + * Get the time to live. + * \return The time to live. + */ uint8_t GetTimeToLive () const { return m_timeToLive; } + /** + * Set the hop count. + * \param hopCount The hop count. + */ void SetHopCount (uint8_t hopCount) { m_hopCount = hopCount; } + /** + * Get the hop count. + * \return The hop count. + */ uint8_t GetHopCount () const { return m_hopCount; } + /** + * Set the message sequence number. + * \param messageSequenceNumber The message sequence number. + */ void SetMessageSequenceNumber (uint16_t messageSequenceNumber) { m_messageSequenceNumber = messageSequenceNumber; } + /** + * Get the message sequence number. + * \return The message sequence number. + */ uint16_t GetMessageSequenceNumber () const { return m_messageSequenceNumber; } -// void SetMessageSize (uint16_t messageSize) -// { -// m_messageSize = messageSize; -// } -// uint16_t GetMessageSize () const -// { -// return m_messageSize; -// } - private: - MessageType m_messageType; - uint8_t m_vTime; - Ipv4Address m_originatorAddress; - uint8_t m_timeToLive; - uint8_t m_hopCount; - uint16_t m_messageSequenceNumber; - uint16_t m_messageSize; + MessageType m_messageType; //!< The message type + uint8_t m_vTime; //!< The validity time. + Ipv4Address m_originatorAddress; //!< The originator address. + uint8_t m_timeToLive; //!< The time to live. + uint8_t m_hopCount; //!< The hop count. + uint16_t m_messageSequenceNumber; //!< The message sequence number. + uint16_t m_messageSize; //!< The message size. public: + /** + * \brief Get the type ID. + * \return The object TypeId. + */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; virtual void Print (std::ostream &os) const; @@ -207,153 +294,284 @@ virtual void Serialize (Buffer::Iterator start) const; virtual uint32_t Deserialize (Buffer::Iterator start); - // 5.1. MID Message Format - // - // The proposed format of a MID message is as follows: - // - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | OLSR Interface Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | OLSR Interface Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ... | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + /** + * \ingroup olsr + * MID Message Format + * + \verbatim + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | OLSR Interface Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | OLSR Interface Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | ... | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \endverbatim + */ struct Mid { - std::vector interfaceAddresses; + std::vector interfaceAddresses; //!< Interface Address container. + /** + * This method is used to print the content of a MID message. + * \param os output stream + */ void Print (std::ostream &os) const; + /** + * Returns the expected size of the header. + * \returns the expected size of the header. + */ uint32_t GetSerializedSize (void) const; + /** + * This method is used by Packet::AddHeader to + * store a header into the byte buffer of a packet. + * + * \param start an iterator which points to where the header should + * be written. + */ void Serialize (Buffer::Iterator start) const; - uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize); + /** + * This method is used by Packet::RemoveHeader to + * re-create a header from the byte buffer of a packet. + * + * \param start an iterator which points to where the header should + * read from. + * \param messageSize the message size. + * \returns the number of bytes read. + */ + uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize); }; - // 6.1. HELLO Message Format - // - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Reserved | Htime | Willingness | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Link Code | Reserved | Link Message Size | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Neighbor Interface Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Neighbor Interface Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // : . . . : - // : : - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Link Code | Reserved | Link Message Size | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Neighbor Interface Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Neighbor Interface Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // : : - // : : - // (etc.) - struct Hello + /** + * \ingroup olsr + * HELLO Message Format + * + \verbatim + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Reserved | Htime | Willingness | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Link Code | Reserved | Link Message Size | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Neighbor Interface Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Neighbor Interface Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + : . . . : + : : + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Link Code | Reserved | Link Message Size | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Neighbor Interface Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Neighbor Interface Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + : : + (etc.) + \endverbatim + */ + struct Hello { + /** + * Link message item + */ struct LinkMessage { - uint8_t linkCode; - std::vector neighborInterfaceAddresses; + uint8_t linkCode; //!< Link code + std::vector neighborInterfaceAddresses; //!< Neighbor interface address container. }; - uint8_t hTime; + uint8_t hTime; //!< HELLO emission interval (coded) + + /** + * Set the HELLO emission interval. + * \param time The HELLO emission interval. + */ void SetHTime (Time time) { this->hTime = SecondsToEmf (time.GetSeconds ()); } + + /** + * Get the HELLO emission interval. + * \return The HELLO emission interval. + */ Time GetHTime () const { return Seconds (EmfToSeconds (this->hTime)); } - uint8_t willingness; - std::vector linkMessages; + uint8_t willingness; //!< The willingness of a node to carry and forward traffic for other nodes. + std::vector linkMessages; //!< Link messages container. + /** + * This method is used to print the content of a MID message. + * \param os output stream + */ void Print (std::ostream &os) const; + /** + * Returns the expected size of the header. + * \returns the expected size of the header. + */ uint32_t GetSerializedSize (void) const; + /** + * This method is used by Packet::AddHeader to + * store a header into the byte buffer of a packet. + * + * \param start an iterator which points to where the header should + * be written. + */ void Serialize (Buffer::Iterator start) const; + /** + * This method is used by Packet::RemoveHeader to + * re-create a header from the byte buffer of a packet. + * + * \param start an iterator which points to where the header should + * read from. + * \param messageSize the message size. + * \returns the number of bytes read. + */ uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize); }; - // 9.1. TC Message Format - // - // The proposed format of a TC message is as follows: - // - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ANSN | Reserved | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Advertised Neighbor Main Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Advertised Neighbor Main Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ... | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + /** + * \ingroup olsr + * TC Message Format + * + \verbatim + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | ANSN | Reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Advertised Neighbor Main Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Advertised Neighbor Main Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | ... | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \endverbatim + */ + struct Tc + { + std::vector neighborAddresses; //!< Neighbor address container. + uint16_t ansn; //!< Advertised Neighbor Sequence Number. - struct Tc - { - std::vector neighborAddresses; - uint16_t ansn; - + /** + * This method is used to print the content of a MID message. + * \param os output stream + */ void Print (std::ostream &os) const; + /** + * Returns the expected size of the header. + * \returns the expected size of the header. + */ uint32_t GetSerializedSize (void) const; + /** + * This method is used by Packet::AddHeader to + * store a header into the byte buffer of a packet. + * + * \param start an iterator which points to where the header should + * be written. + */ void Serialize (Buffer::Iterator start) const; - uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize); + /** + * This method is used by Packet::RemoveHeader to + * re-create a header from the byte buffer of a packet. + * + * \param start an iterator which points to where the header should + * read from. + * \param messageSize the message size. + * \returns the number of bytes read. + */ + uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize); }; - // 12.1. HNA Message Format - // - // The proposed format of an HNA-message is: - // - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Network Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Netmask | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Network Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Netmask | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ... | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - // Note: HNA stands for Host Network Association + /** + * \ingroup olsr + * HNA (Host Network Association) Message Format + * + \verbatim + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Network Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Netmask | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Network Address | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Netmask | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | ... | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + \endverbatim + */ struct Hna { + /** + * Association item structure. + */ struct Association { - Ipv4Address address; - Ipv4Mask mask; + Ipv4Address address; //!< IPv4 Address. + Ipv4Mask mask; //!< IPv4 netmask. }; - std::vector associations; + std::vector associations; //!< Association container. + + /** + * This method is used to print the content of a MID message. + * \param os output stream + */ void Print (std::ostream &os) const; + /** + * Returns the expected size of the header. + * \returns the expected size of the header. + */ uint32_t GetSerializedSize (void) const; + /** + * This method is used by Packet::AddHeader to + * store a header into the byte buffer of a packet. + * + * \param start an iterator which points to where the header should + * be written. + */ void Serialize (Buffer::Iterator start) const; + /** + * This method is used by Packet::RemoveHeader to + * re-create a header from the byte buffer of a packet. + * + * \param start an iterator which points to where the header should + * read from. + * \param messageSize the message size. + * \returns the number of bytes read. + */ uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize); }; private: + + /** + * Structure holding the message content. + */ struct { - Mid mid; - Hello hello; - Tc tc; - Hna hna; - } m_message; // union not allowed + Mid mid; //!< MID message (optional). + Hello hello; //!< HELLO message (optional). + Tc tc; //!< TC message (optional). + Hna hna; //!< HNA message (optional). + } m_message; //!< The actual message being carried. public: + /** + * Set the message type to MID and return the message content. + * \returns The MID message. + */ Mid& GetMid () { if (m_messageType == 0) @@ -367,6 +585,10 @@ return m_message.mid; } + /** + * Set the message type to HELLO and return the message content. + * \returns The HELLO message. + */ Hello& GetHello () { if (m_messageType == 0) @@ -380,6 +602,10 @@ return m_message.hello; } + /** + * Set the message type to TC and return the message content. + * \returns The TC message. + */ Tc& GetTc () { if (m_messageType == 0) @@ -393,6 +619,10 @@ return m_message.tc; } + /** + * Set the message type to HNA and return the message content. + * \returns The HNA message. + */ Hna& GetHna () { if (m_messageType == 0) @@ -407,24 +637,40 @@ } + /** + * Get the MID message. + * \returns The MID message. + */ const Mid& GetMid () const { NS_ASSERT (m_messageType == MID_MESSAGE); return m_message.mid; } + /** + * Get the HELLO message. + * \returns The HELLO message. + */ const Hello& GetHello () const { NS_ASSERT (m_messageType == HELLO_MESSAGE); return m_message.hello; } + /** + * Get the TC message. + * \returns The TC message. + */ const Tc& GetTc () const { NS_ASSERT (m_messageType == TC_MESSAGE); return m_message.tc; } + /** + * Get the HNA message. + * \returns The HNA message. + */ const Hna& GetHna () const { NS_ASSERT (m_messageType == HNA_MESSAGE); --- a/src/olsr/model/olsr-repositories.h +++ a/src/olsr/model/olsr-repositories.h @@ -36,268 +36,276 @@ namespace ns3 { namespace olsr { +/// \ingroup olsr +/// An Interface Association Tuple. +struct IfaceAssocTuple +{ + /// Interface address of a node. + Ipv4Address ifaceAddr; + /// Main address of the node. + Ipv4Address mainAddr; + /// Time at which this tuple expires and must be removed. + Time time; +}; -/// An Interface Association Tuple. - struct IfaceAssocTuple - { - /// Interface address of a node. - Ipv4Address ifaceAddr; - /// Main address of the node. - Ipv4Address mainAddr; - /// Time at which this tuple expires and must be removed. - Time time; - }; +static inline bool +operator == (const IfaceAssocTuple &a, const IfaceAssocTuple &b) +{ + return (a.ifaceAddr == b.ifaceAddr + && a.mainAddr == b.mainAddr); +} - static inline bool - operator == (const IfaceAssocTuple &a, const IfaceAssocTuple &b) - { - return (a.ifaceAddr == b.ifaceAddr - && a.mainAddr == b.mainAddr); - } +static inline std::ostream& +operator << (std::ostream &os, const IfaceAssocTuple &tuple) +{ + os << "IfaceAssocTuple(ifaceAddr=" << tuple.ifaceAddr + << ", mainAddr=" << tuple.mainAddr + << ", time=" << tuple.time << ")"; + return os; +} - static inline std::ostream& - operator << (std::ostream &os, const IfaceAssocTuple &tuple) - { - os << "IfaceAssocTuple(ifaceAddr=" << tuple.ifaceAddr - << ", mainAddr=" << tuple.mainAddr - << ", time=" << tuple.time << ")"; - return os; - } +/// \ingroup olsr +/// A Link Tuple. +struct LinkTuple +{ + /// Interface address of the local node. + Ipv4Address localIfaceAddr; + /// Interface address of the neighbor node. + Ipv4Address neighborIfaceAddr; + /// The link is considered bidirectional until this time. + Time symTime; + /// The link is considered unidirectional until this time. + Time asymTime; + /// Time at which this tuple expires and must be removed. + Time time; +}; -/// A Link Tuple. - struct LinkTuple - { - /// Interface address of the local node. - Ipv4Address localIfaceAddr; - /// Interface address of the neighbor node. - Ipv4Address neighborIfaceAddr; - /// The link is considered bidirectional until this time. - Time symTime; - /// The link is considered unidirectional until this time. - Time asymTime; - /// Time at which this tuple expires and must be removed. - Time time; - }; +static inline bool +operator == (const LinkTuple &a, const LinkTuple &b) +{ + return (a.localIfaceAddr == b.localIfaceAddr + && a.neighborIfaceAddr == b.neighborIfaceAddr); +} - static inline bool - operator == (const LinkTuple &a, const LinkTuple &b) - { - return (a.localIfaceAddr == b.localIfaceAddr - && a.neighborIfaceAddr == b.neighborIfaceAddr); - } +static inline std::ostream& +operator << (std::ostream &os, const LinkTuple &tuple) +{ + os << "LinkTuple(localIfaceAddr=" << tuple.localIfaceAddr + << ", neighborIfaceAddr=" << tuple.neighborIfaceAddr + << ", symTime=" << tuple.symTime + << ", asymTime=" << tuple.asymTime + << ", expTime=" << tuple.time + << ")"; + return os; +} - static inline std::ostream& - operator << (std::ostream &os, const LinkTuple &tuple) - { - os << "LinkTuple(localIfaceAddr=" << tuple.localIfaceAddr - << ", neighborIfaceAddr=" << tuple.neighborIfaceAddr - << ", symTime=" << tuple.symTime - << ", asymTime=" << tuple.asymTime - << ", expTime=" << tuple.time - << ")"; - return os; - } +/// \ingroup olsr +/// A Neighbor Tuple. +struct NeighborTuple +{ + /// Main address of a neighbor node. + Ipv4Address neighborMainAddr; + /// Status of the link (Symmetric or not Symmetric). + enum Status { + STATUS_NOT_SYM = 0, // "not symmetric" + STATUS_SYM = 1, // "symmetric" + } status; //!< Status of the link. + /// A value between 0 and 7 specifying the node's willingness to carry traffic on behalf of other nodes. + uint8_t willingness; +}; -/// A Neighbor Tuple. - struct NeighborTuple - { - /// Main address of a neighbor node. - Ipv4Address neighborMainAddr; - /// Neighbor Type and Link Type at the four less significative digits. - enum Status { - STATUS_NOT_SYM = 0, // "not symmetric" - STATUS_SYM = 1, // "symmetric" - } status; - /// A value between 0 and 7 specifying the node's willingness to carry traffic on behalf of other nodes. - uint8_t willingness; - }; +static inline bool +operator == (const NeighborTuple &a, const NeighborTuple &b) +{ + return (a.neighborMainAddr == b.neighborMainAddr + && a.status == b.status + && a.willingness == b.willingness); +} - static inline bool - operator == (const NeighborTuple &a, const NeighborTuple &b) - { - return (a.neighborMainAddr == b.neighborMainAddr - && a.status == b.status - && a.willingness == b.willingness); - } +static inline std::ostream& +operator << (std::ostream &os, const NeighborTuple &tuple) +{ + os << "NeighborTuple(neighborMainAddr=" << tuple.neighborMainAddr + << ", status=" << (tuple.status == NeighborTuple::STATUS_SYM ? "SYM" : "NOT_SYM") + << ", willingness=" << (int) tuple.willingness << ")"; + return os; +} - static inline std::ostream& - operator << (std::ostream &os, const NeighborTuple &tuple) - { - os << "NeighborTuple(neighborMainAddr=" << tuple.neighborMainAddr - << ", status=" << (tuple.status == NeighborTuple::STATUS_SYM ? "SYM" : "NOT_SYM") - << ", willingness=" << (int) tuple.willingness << ")"; - return os; - } +/// \ingroup olsr +/// A 2-hop Tuple. +struct TwoHopNeighborTuple +{ + /// Main address of a neighbor. + Ipv4Address neighborMainAddr; + /// Main address of a 2-hop neighbor with a symmetric link to nb_main_addr. + Ipv4Address twoHopNeighborAddr; + /// Time at which this tuple expires and must be removed. + Time expirationTime; // previously called 'time_' +}; -/// A 2-hop Tuple. - struct TwoHopNeighborTuple - { - /// Main address of a neighbor. - Ipv4Address neighborMainAddr; - /// Main address of a 2-hop neighbor with a symmetric link to nb_main_addr. - Ipv4Address twoHopNeighborAddr; - /// Time at which this tuple expires and must be removed. - Time expirationTime; // previously called 'time_' - }; +static inline std::ostream& +operator << (std::ostream &os, const TwoHopNeighborTuple &tuple) +{ + os << "TwoHopNeighborTuple(neighborMainAddr=" << tuple.neighborMainAddr + << ", twoHopNeighborAddr=" << tuple.twoHopNeighborAddr + << ", expirationTime=" << tuple.expirationTime + << ")"; + return os; +} - static inline std::ostream& - operator << (std::ostream &os, const TwoHopNeighborTuple &tuple) - { - os << "TwoHopNeighborTuple(neighborMainAddr=" << tuple.neighborMainAddr - << ", twoHopNeighborAddr=" << tuple.twoHopNeighborAddr - << ", expirationTime=" << tuple.expirationTime - << ")"; - return os; - } +static inline bool +operator == (const TwoHopNeighborTuple &a, const TwoHopNeighborTuple &b) +{ + return (a.neighborMainAddr == b.neighborMainAddr + && a.twoHopNeighborAddr == b.twoHopNeighborAddr); +} - static inline bool - operator == (const TwoHopNeighborTuple &a, const TwoHopNeighborTuple &b) - { - return (a.neighborMainAddr == b.neighborMainAddr - && a.twoHopNeighborAddr == b.twoHopNeighborAddr); - } +/// \ingroup olsr +/// An MPR-Selector Tuple. +struct MprSelectorTuple +{ + /// Main address of a node which have selected this node as a MPR. + Ipv4Address mainAddr; + /// Time at which this tuple expires and must be removed. + Time expirationTime; // previously called 'time_' +}; -/// An MPR-Selector Tuple. - struct MprSelectorTuple - { - /// Main address of a node which have selected this node as a MPR. - Ipv4Address mainAddr; - /// Time at which this tuple expires and must be removed. - Time expirationTime; // previously called 'time_' - }; +static inline bool +operator == (const MprSelectorTuple &a, const MprSelectorTuple &b) +{ + return (a.mainAddr == b.mainAddr); +} - static inline bool - operator == (const MprSelectorTuple &a, const MprSelectorTuple &b) - { - return (a.mainAddr == b.mainAddr); - } - -/// The type "list of interface addresses" +// The type "list of interface addresses" //typedef std::vector addr_list_t; +/// \ingroup olsr /// A Duplicate Tuple - struct DuplicateTuple - { - /// Originator address of the message. - Ipv4Address address; - /// Message sequence number. - uint16_t sequenceNumber; - /// Indicates whether the message has been retransmitted or not. - bool retransmitted; - /// List of interfaces which the message has been received on. - std::vector ifaceList; - /// Time at which this tuple expires and must be removed. - Time expirationTime; - }; +struct DuplicateTuple +{ + /// Originator address of the message. + Ipv4Address address; + /// Message sequence number. + uint16_t sequenceNumber; + /// Indicates whether the message has been retransmitted or not. + bool retransmitted; + /// List of interfaces which the message has been received on. + std::vector ifaceList; + /// Time at which this tuple expires and must be removed. + Time expirationTime; +}; - static inline bool - operator == (const DuplicateTuple &a, const DuplicateTuple &b) - { - return (a.address == b.address - && a.sequenceNumber == b.sequenceNumber); - } +static inline bool +operator == (const DuplicateTuple &a, const DuplicateTuple &b) +{ + return (a.address == b.address + && a.sequenceNumber == b.sequenceNumber); +} +/// \ingroup olsr /// A Topology Tuple - struct TopologyTuple - { - /// Main address of the destination. - Ipv4Address destAddr; - /// Main address of a node which is a neighbor of the destination. - Ipv4Address lastAddr; - /// Sequence number. - uint16_t sequenceNumber; - /// Time at which this tuple expires and must be removed. - Time expirationTime; - }; +struct TopologyTuple +{ + /// Main address of the destination. + Ipv4Address destAddr; + /// Main address of a node which is a neighbor of the destination. + Ipv4Address lastAddr; + /// Sequence number. + uint16_t sequenceNumber; + /// Time at which this tuple expires and must be removed. + Time expirationTime; +}; - static inline bool - operator == (const TopologyTuple &a, const TopologyTuple &b) - { - return (a.destAddr == b.destAddr - && a.lastAddr == b.lastAddr - && a.sequenceNumber == b.sequenceNumber); - } +static inline bool +operator == (const TopologyTuple &a, const TopologyTuple &b) +{ + return (a.destAddr == b.destAddr + && a.lastAddr == b.lastAddr + && a.sequenceNumber == b.sequenceNumber); +} - static inline std::ostream& - operator << (std::ostream &os, const TopologyTuple &tuple) - { - os << "TopologyTuple(destAddr=" << tuple.destAddr - << ", lastAddr=" << tuple.lastAddr - << ", sequenceNumber=" << (int) tuple.sequenceNumber - << ", expirationTime=" << tuple.expirationTime - << ")"; - return os; - } +static inline std::ostream& +operator << (std::ostream &os, const TopologyTuple &tuple) +{ + os << "TopologyTuple(destAddr=" << tuple.destAddr + << ", lastAddr=" << tuple.lastAddr + << ", sequenceNumber=" << (int) tuple.sequenceNumber + << ", expirationTime=" << tuple.expirationTime + << ")"; + return os; +} +/// \ingroup olsr /// Association - struct Association - { - Ipv4Address networkAddr; - Ipv4Mask netmask; - }; +struct Association +{ + Ipv4Address networkAddr; //!< IPv4 Network address. + Ipv4Mask netmask; //!< IPv4 Network mask. +}; - static inline bool - operator == (const Association &a, const Association &b) - { - return (a.networkAddr == b.networkAddr - && a.netmask == b.netmask); - } +static inline bool +operator == (const Association &a, const Association &b) +{ + return (a.networkAddr == b.networkAddr + && a.netmask == b.netmask); +} - static inline std::ostream& - operator << (std::ostream &os, const Association &tuple) - { - os << "Association(networkAddr=" << tuple.networkAddr - << ", netmask=" << tuple.netmask - << ")"; - return os; - } +static inline std::ostream& +operator << (std::ostream &os, const Association &tuple) +{ + os << "Association(networkAddr=" << tuple.networkAddr + << ", netmask=" << tuple.netmask + << ")"; + return os; +} +/// \ingroup olsr /// An Association Tuple - struct AssociationTuple - { - /// Main address of the gateway. - Ipv4Address gatewayAddr; - /// Network Address of network reachable through gatewayAddr - Ipv4Address networkAddr; - /// Netmask of network reachable through gatewayAddr - Ipv4Mask netmask; - /// Time at which this tuple expires and must be removed - Time expirationTime; - }; +struct AssociationTuple +{ + /// Main address of the gateway. + Ipv4Address gatewayAddr; + /// Network Address of network reachable through gatewayAddr + Ipv4Address networkAddr; + /// Netmask of network reachable through gatewayAddr + Ipv4Mask netmask; + /// Time at which this tuple expires and must be removed + Time expirationTime; +}; - static inline bool - operator == (const AssociationTuple &a, const AssociationTuple &b) - { - return (a.gatewayAddr == b.gatewayAddr - && a.networkAddr == b.networkAddr - && a.netmask == b.netmask); - } +static inline bool +operator == (const AssociationTuple &a, const AssociationTuple &b) +{ + return (a.gatewayAddr == b.gatewayAddr + && a.networkAddr == b.networkAddr + && a.netmask == b.netmask); +} - static inline std::ostream& - operator << (std::ostream &os, const AssociationTuple &tuple) - { - os << "AssociationTuple(gatewayAddr=" << tuple.gatewayAddr - << ", networkAddr=" << tuple.networkAddr - << ", netmask=" << tuple.netmask - << ", expirationTime=" << tuple.expirationTime - << ")"; - return os; - } +static inline std::ostream& +operator << (std::ostream &os, const AssociationTuple &tuple) +{ + os << "AssociationTuple(gatewayAddr=" << tuple.gatewayAddr + << ", networkAddr=" << tuple.networkAddr + << ", netmask=" << tuple.netmask + << ", expirationTime=" << tuple.expirationTime + << ")"; + return os; +} - typedef std::set MprSet; ///< MPR Set type. - typedef std::vector MprSelectorSet; ///< MPR Selector Set type. - typedef std::vector LinkSet; ///< Link Set type. - typedef std::vector NeighborSet; ///< Neighbor Set type. - typedef std::vector TwoHopNeighborSet; ///< 2-hop Neighbor Set type. - typedef std::vector TopologySet; ///< Topology Set type. - typedef std::vector DuplicateSet; ///< Duplicate Set type. - typedef std::vector IfaceAssocSet; ///< Interface Association Set type. - typedef std::vector AssociationSet; ///< Association Set type. - typedef std::vector Associations; ///< Association Set type. +typedef std::set MprSet; //!< MPR Set type. +typedef std::vector MprSelectorSet; //!< MPR Selector Set type. +typedef std::vector LinkSet; //!< Link Set type. +typedef std::vector NeighborSet; //!< Neighbor Set type. +typedef std::vector TwoHopNeighborSet; //!< 2-hop Neighbor Set type. +typedef std::vector TopologySet; //!< Topology Set type. +typedef std::vector DuplicateSet; //!< Duplicate Set type. +typedef std::vector IfaceAssocSet; //!< Interface Association Set type. +typedef std::vector AssociationSet; //!< Association Set type. +typedef std::vector Associations; //!< Association Set type. - }} // namespace ns3, olsr +}} // namespace ns3, olsr #endif /* OLSR_REPOSITORIES_H */ --- a/src/olsr/model/olsr-routing-protocol.cc +++ a/src/olsr/model/olsr-routing-protocol.cc @@ -550,7 +550,11 @@ namespace { /// -/// \brief Remove all covered 2-hop neighbors from N2 set. This is a helper function used by MprComputation algorithm. +/// \brief Remove all covered 2-hop neighbors from N2 set. +/// This is a helper function used by MprComputation algorithm. +/// +/// \param neighborMainAddr Neighbor main address. +/// \param N2 Reference to the 2-hop neighbor set. /// void CoverTwoHopNeighbors (Ipv4Address neighborMainAddr, TwoHopNeighborSet & N2) @@ -579,9 +583,6 @@ } } // anonymous namespace -/// -/// \brief Computates MPR set of a node following \RFC{3626} hints. -/// void RoutingProtocol::MprComputation () { @@ -869,12 +870,6 @@ m_state.SetMprSet (mprSet); } -/// -/// \brief Gets the main address associated with a given interface address. -/// -/// \param iface_addr the interface address. -/// \return the corresponding main address. -/// Ipv4Address RoutingProtocol::GetMainAddress (Ipv4Address iface_addr) const { @@ -887,9 +882,6 @@ return iface_addr; } -/// -/// \brief Creates the routing table of the node following \RFC{3626} hints. -/// void RoutingProtocol::RoutingTableComputation () { @@ -1205,16 +1197,6 @@ } -/// -/// \brief Processes a HELLO message following \RFC{3626} specification. -/// -/// Link sensing and population of the Neighbor Set, 2-hop Neighbor Set and MPR -/// Selector Set are performed. -/// -/// \param msg the %OLSR message which contains the HELLO message. -/// \param receiver_iface the address of the interface where the message was received from. -/// \param sender_iface the address of the interface where the message was sent from. -/// void RoutingProtocol::ProcessHello (const olsr::MessageHeader &msg, const Ipv4Address &receiverIface, @@ -1269,15 +1251,6 @@ PopulateMprSelectorSet (msg, hello); } -/// -/// \brief Processes a TC message following \RFC{3626} specification. -/// -/// The Topology Set is updated (if needed) with the information of -/// the received TC message. -/// -/// \param msg the %OLSR message which contains the TC message. -/// \param sender_iface the address of the interface where the message was sent from. -/// void RoutingProtocol::ProcessTc (const olsr::MessageHeader &msg, const Ipv4Address &senderIface) @@ -1364,15 +1337,6 @@ #endif // NS3_LOG_ENABLE } -/// -/// \brief Processes a MID message following \RFC{3626} specification. -/// -/// The Interface Association Set is updated (if needed) with the information -/// of the received MID message. -/// -/// \param msg the %OLSR message which contains the MID message. -/// \param sender_iface the address of the interface where the message was sent from. -/// void RoutingProtocol::ProcessMid (const olsr::MessageHeader &msg, const Ipv4Address &senderIface) @@ -1443,15 +1407,6 @@ NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface << " -> END."); } -/// -/// \brief Processes a HNA message following \RFC{3626} specification. -/// -/// The Host Network Association Set is updated (if needed) with the information -/// of the received HNA message. -/// -/// \param msg the %OLSR message which contains the HNA message. -/// \param sender_iface the address of the interface where the message was sent from. -/// void RoutingProtocol::ProcessHna (const olsr::MessageHeader &msg, const Ipv4Address &senderIface) @@ -1509,17 +1464,6 @@ } } -/// -/// \brief OLSR's default forwarding algorithm. -/// -/// See \RFC{3626} for details. -/// -/// \param p the %OLSR packet which has been received. -/// \param msg the %OLSR message which must be forwarded. -/// \param dup_tuple NULL if the message has never been considered for forwarding, -/// or a duplicate tuple in other case. -/// \param local_iface the address of the interface where the message was received from. -/// void RoutingProtocol::ForwardDefault (olsr::MessageHeader olsrMessage, DuplicateTuple *duplicated, @@ -1586,15 +1530,6 @@ } } -/// -/// \brief Enques an %OLSR message which will be sent with a delay of (0, delay]. -/// -/// This buffering system is used in order to piggyback several %OLSR messages in -/// a same %OLSR packet. -/// -/// \param msg the %OLSR message which must be sent. -/// \param delay maximum delay the %OLSR message is going to be buffered. -/// void RoutingProtocol::QueueMessage (const olsr::MessageHeader &message, Time delay) { @@ -1630,13 +1565,6 @@ } } -/// -/// \brief Creates as many %OLSR packets as needed in order to send all buffered -/// %OLSR messages. -/// -/// Maximum number of messages which can be contained in an %OLSR packet is -/// dictated by OLSR_MAX_MSGS constant. -/// void RoutingProtocol::SendQueuedMessages () { @@ -1673,9 +1601,6 @@ m_queuedMessages.clear (); } -/// -/// \brief Creates a new %OLSR HELLO message which is buffered for being sent later on. -/// void RoutingProtocol::SendHello () { @@ -1784,9 +1709,6 @@ QueueMessage (msg, JITTER); } -/// -/// \brief Creates a new %OLSR TC message which is buffered for being sent later on. -/// void RoutingProtocol::SendTc () { @@ -1811,9 +1733,6 @@ QueueMessage (msg, JITTER); } -/// -/// \brief Creates a new %OLSR MID message which is buffered for being sent later on. -/// void RoutingProtocol::SendMid () { @@ -1855,9 +1774,6 @@ QueueMessage (msg, JITTER); } -/// -/// \brief Creates a new %OLSR HNA message which is buffered for being sent later on. -/// void RoutingProtocol::SendHna () { @@ -1891,11 +1807,6 @@ QueueMessage (msg, JITTER); } -/// -/// \brief Injects the specified (networkAddr, netmask) tuple in the list of -/// local HNA associations to be sent by the node via HNA messages. -/// If this tuple already exists, nothing is done. -/// void RoutingProtocol::AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask) { @@ -1917,11 +1828,6 @@ m_state.InsertAssociation ( (Association) { networkAddr, netmask} ); } -/// -/// \brief Removes the specified (networkAddr, netmask) tuple from the list of -/// local HNA associations to be sent by the node via HNA messages. -/// If this tuple does not exist, nothing is done (see "OlsrState::EraseAssociation()"). -/// void RoutingProtocol::RemoveHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask) { @@ -1929,16 +1835,6 @@ m_state.EraseAssociation ( (Association) { networkAddr, netmask} ); } -/// -/// \brief Associates the specified Ipv4StaticRouting routing table -/// to the OLSR routing protocol. Entries from this associated -/// routing table that use non-olsr outgoing interfaces are added -/// to the list of local HNA associations so that they are included -/// in HNA messages sent by the node. -/// If this method is called more than once, entries from the old -/// association are deleted before entries from the new one are added. -/// \param routingTable the Ipv4StaticRouting routing table to be associated. -/// void RoutingProtocol::SetRoutingTableAssociation (Ptr routingTable) { @@ -1984,11 +1880,6 @@ "the associated routing table: " << m_state.GetAssociations ().size ()); } -/// -/// \brief Tests whether or not the specified route uses a non-OLSR outgoing interface. -/// Returns true if the outgoing interface of the specified route is a non-OLSR interface. -/// Returns false otherwise. -/// bool RoutingProtocol::UsesNonOlsrOutgoingInterface (const Ipv4RoutingTableEntry &route) { @@ -1998,9 +1889,6 @@ return ci != m_interfaceExclusions.end (); } -/// -/// \brief Updates Link Set according to a new received HELLO message -/// (following \RFC{3626} specification). Neighbor Set is also updated if needed. void RoutingProtocol::LinkSensing (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello, @@ -2135,9 +2023,6 @@ << ": LinkSensing END"); } -/// -/// \brief Updates the Neighbor Set according to the information contained in -/// a new received HELLO message (following \RFC{3626}). void RoutingProtocol::PopulateNeighborSet (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello) @@ -2149,10 +2034,6 @@ } } - -/// -/// \brief Updates the 2-hop Neighbor Set according to the information contained -/// in a new received HELLO message (following \RFC{3626}). void RoutingProtocol::PopulateTwoHopNeighborSet (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello) @@ -2260,11 +2141,6 @@ NS_LOG_DEBUG ("Olsr node " << m_mainAddress << ": PopulateTwoHopNeighborSet END"); } - - -/// -/// \brief Updates the MPR Selector Set according to the information contained in -/// a new received HELLO message (following \RFC{3626}). void RoutingProtocol::PopulateMprSelectorSet (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello) @@ -2324,7 +2200,7 @@ #if 0 /// /// \brief Drops a given packet because it couldn't be delivered to the corresponding -/// destination by the MAC layer. This may cause a neighbor loss, and appropiate +/// destination by the MAC layer. This may cause a neighbor loss, and appropriate /// actions are then taken. /// /// \param p the packet which couldn't be delivered by the MAC layer. @@ -2358,13 +2234,6 @@ -/// -/// \brief Performs all actions needed when a neighbor loss occurs. -/// -/// Neighbor Set, 2-hop Neighbor Set, MPR Set and MPR Selector Set are updated. -/// -/// \param tuple link tuple with the information of the link to the neighbor which has been lost. -/// void RoutingProtocol::NeighborLoss (const LinkTuple &tuple) { @@ -2379,11 +2248,6 @@ RoutingTableComputation (); } -/// -/// \brief Adds a duplicate tuple to the Duplicate Set. -/// -/// \param tuple the duplicate tuple to be added. -/// void RoutingProtocol::AddDuplicateTuple (const DuplicateTuple &tuple) { @@ -2395,11 +2259,6 @@ m_state.InsertDuplicateTuple (tuple); } -/// -/// \brief Removes a duplicate tuple from the Duplicate Set. -/// -/// \param tuple the duplicate tuple to be removed. -/// void RoutingProtocol::RemoveDuplicateTuple (const DuplicateTuple &tuple) { @@ -2431,11 +2290,6 @@ AddNeighborTuple (nb_tuple); } -/// -/// \brief Removes a link tuple from the Link Set. -/// -/// \param tuple the link tuple to be removed. -/// void RoutingProtocol::RemoveLinkTuple (const LinkTuple &tuple) { @@ -2447,12 +2301,6 @@ m_state.EraseLinkTuple (tuple); } -/// -/// \brief This function is invoked when a link tuple is updated. Its aim is to -/// also update the corresponding neighbor tuple if it is needed. -/// -/// \param tuple the link tuple which has been updated. -/// void RoutingProtocol::LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness) { @@ -2509,11 +2357,6 @@ } } -/// -/// \brief Adds a neighbor tuple to the Neighbor Set. -/// -/// \param tuple the neighbor tuple to be added. -/// void RoutingProtocol::AddNeighborTuple (const NeighborTuple &tuple) { @@ -2527,11 +2370,6 @@ IncrementAnsn (); } -/// -/// \brief Removes a neighbor tuple from the Neighbor Set. -/// -/// \param tuple the neighbor tuple to be removed. -/// void RoutingProtocol::RemoveNeighborTuple (const NeighborTuple &tuple) { @@ -2545,11 +2383,6 @@ IncrementAnsn (); } -/// -/// \brief Adds a 2-hop neighbor tuple to the 2-hop Neighbor Set. -/// -/// \param tuple the 2-hop neighbor tuple to be added. -/// void RoutingProtocol::AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple) { @@ -2562,11 +2395,6 @@ m_state.InsertTwoHopNeighborTuple (tuple); } -/// -/// \brief Removes a 2-hop neighbor tuple from the 2-hop Neighbor Set. -/// -/// \param tuple the 2-hop neighbor tuple to be removed. -/// void RoutingProtocol::RemoveTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple) { @@ -2585,13 +2413,6 @@ m_ansn = (m_ansn + 1) % (OLSR_MAX_SEQ_NUM + 1); } -/// -/// \brief Adds an MPR selector tuple to the MPR Selector Set. -/// -/// Advertised Neighbor Sequence Number (ANSN) is also updated. -/// -/// \param tuple the MPR selector tuple to be added. -/// void RoutingProtocol::AddMprSelectorTuple (const MprSelectorTuple &tuple) { @@ -2604,13 +2425,6 @@ IncrementAnsn (); } -/// -/// \brief Removes an MPR selector tuple from the MPR Selector Set. -/// -/// Advertised Neighbor Sequence Number (ANSN) is also updated. -/// -/// \param tuple the MPR selector tuple to be removed. -/// void RoutingProtocol::RemoveMprSelectorTuple (const MprSelectorTuple &tuple) { @@ -2623,11 +2437,6 @@ IncrementAnsn (); } -/// -/// \brief Adds a topology tuple to the Topology Set. -/// -/// \param tuple the topology tuple to be added. -/// void RoutingProtocol::AddTopologyTuple (const TopologyTuple &tuple) { @@ -2641,11 +2450,6 @@ m_state.InsertTopologyTuple (tuple); } -/// -/// \brief Removes a topology tuple from the Topology Set. -/// -/// \param tuple the topology tuple to be removed. -/// void RoutingProtocol::RemoveTopologyTuple (const TopologyTuple &tuple) { @@ -2659,11 +2463,6 @@ m_state.EraseTopologyTuple (tuple); } -/// -/// \brief Adds an interface association tuple to the Interface Association Set. -/// -/// \param tuple the interface association tuple to be added. -/// void RoutingProtocol::AddIfaceAssocTuple (const IfaceAssocTuple &tuple) { @@ -2676,11 +2475,6 @@ m_state.InsertIfaceAssocTuple (tuple); } -/// -/// \brief Removes an interface association tuple from the Interface Association Set. -/// -/// \param tuple the interface association tuple to be removed. -/// void RoutingProtocol::RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple) { @@ -2693,48 +2487,30 @@ m_state.EraseIfaceAssocTuple (tuple); } -/// -/// \brief Adds a host network association tuple to the Association Set. -/// -/// \param tuple the host network association tuple to be added. -/// void RoutingProtocol::AddAssociationTuple (const AssociationTuple &tuple) { m_state.InsertAssociationTuple (tuple); } -/// -/// \brief Removes a host network association tuple from the Association Set. -/// -/// \param tuple the host network association tuple to be removed. -/// void RoutingProtocol::RemoveAssociationTuple (const AssociationTuple &tuple) { m_state.EraseAssociationTuple (tuple); } - - uint16_t RoutingProtocol::GetPacketSequenceNumber () { m_packetSequenceNumber = (m_packetSequenceNumber + 1) % (OLSR_MAX_SEQ_NUM + 1); return m_packetSequenceNumber; } -/// Increments message sequence number and returns the new value. uint16_t RoutingProtocol::GetMessageSequenceNumber () { m_messageSequenceNumber = (m_messageSequenceNumber + 1) % (OLSR_MAX_SEQ_NUM + 1); return m_messageSequenceNumber; } - -/// -/// \brief Sends a HELLO message and reschedules the HELLO timer. -/// \param e The event which has expired. -/// void RoutingProtocol::HelloTimerExpire () { @@ -2742,10 +2518,6 @@ m_helloTimer.Schedule (m_helloInterval); } -/// -/// \brief Sends a TC message (if there exists any MPR selector) and reschedules the TC timer. -/// \param e The event which has expired. -/// void RoutingProtocol::TcTimerExpire () { @@ -2760,10 +2532,6 @@ m_tcTimer.Schedule (m_tcInterval); } -/// -/// \brief Sends a MID message (if the node has more than one interface) and resets the MID timer. -/// \param e The event which has expired. -/// void RoutingProtocol::MidTimerExpire () { @@ -2771,9 +2539,6 @@ m_midTimer.Schedule (m_midInterval); } -/// -/// \brief Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer. -/// void RoutingProtocol::HnaTimerExpire () { @@ -2788,13 +2553,6 @@ m_hnaTimer.Schedule (m_hnaInterval); } -/// -/// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime. -/// -/// The task of actually removing the tuple is left to the OLSR agent. -/// -/// \param tuple The tuple which has expired. -/// void RoutingProtocol::DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber) { @@ -2816,17 +2574,6 @@ } } -/// -/// \brief Removes tuple_ if expired. Else if symmetric time -/// has expired then it is assumed a neighbor loss and agent_->nb_loss() -/// is called. In this case the timer is rescheduled to expire at -/// tuple_->time(). Otherwise the timer is rescheduled to expire at -/// the minimum between tuple_->time() and tuple_->sym_time(). -/// -/// The task of actually removing the tuple is left to the OLSR agent. -/// -/// \param e The event which has expired. -/// void RoutingProtocol::LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr) { @@ -2861,13 +2608,6 @@ } } -/// -/// \brief Removes tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). -/// -/// The task of actually removing the tuple is left to the OLSR agent. -/// -/// \param e The event which has expired. -/// void RoutingProtocol::Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr) { @@ -2889,13 +2629,6 @@ } } -/// -/// \brief Removes tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). -/// -/// The task of actually removing the tuple is left to the OLSR agent. -/// -/// \param e The event which has expired. -/// void RoutingProtocol::MprSelTupleTimerExpire (Ipv4Address mainAddr) { @@ -2916,13 +2649,6 @@ } } -/// -/// \brief Removes tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). -/// -/// The task of actually removing the tuple is left to the OLSR agent. -/// -/// \param e The event which has expired. -/// void RoutingProtocol::TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr) { @@ -2943,10 +2669,6 @@ } } -/// -/// \brief Removes tuple_ if expired. Else timer is rescheduled to expire at tuple_->time(). -/// \param e The event which has expired. -/// void RoutingProtocol::IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr) { @@ -2967,9 +2689,6 @@ } } -/// \brief Removes tuple_ if expired. Else timer is rescheduled to expire at tuple_->time(). -/// \param e The event which has expired. -/// void RoutingProtocol::AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask) { @@ -2990,9 +2709,6 @@ } } -/// -/// \brief Clears the routing table and frees the memory assigned to each one of its entries. -/// void RoutingProtocol::Clear () { @@ -3000,22 +2716,12 @@ m_table.clear (); } -/// -/// \brief Deletes the entry whose destination address is given. -/// \param dest address of the destination node. -/// void RoutingProtocol::RemoveEntry (Ipv4Address const &dest) { m_table.erase (dest); } -/// -/// \brief Looks up an entry for the specified destination address. -/// \param dest destination address. -/// \param outEntry output parameter to hold the routing entry result, if fuond -/// \return true if found, false if not found -/// bool RoutingProtocol::Lookup (Ipv4Address const &dest, RoutingTableEntry &outEntry) const @@ -3030,22 +2736,6 @@ return true; } -/// -/// \brief Finds the appropiate entry which must be used in order to forward -/// a data packet to a next hop (given a destination). -/// -/// Imagine a routing table like this: [A,B] [B,C] [C,C]; being each pair of the -/// form [dest addr,next-hop addr]. In this case, if this function is invoked with -/// [A,B] then pair [C,C] is returned because C is the next hop that must be used -/// to forward a data packet destined to A. That is, C is a neighbor of this node, -/// but B isn't. This function finds the appropiate neighbor for forwarding a packet. -/// -/// \param entry the routing table entry which indicates the destination node -/// we are interested in. -/// \return the appropiate routing table entry which indicates the next -/// hop which must be used for forwarding a data packet, or NULL -/// if there is no such entry. -/// bool RoutingProtocol::FindSendEntry (RoutingTableEntry const &entry, RoutingTableEntry &outEntry) const @@ -3251,16 +2941,6 @@ {} -/// -/// \brief Adds a new entry into the routing table. -/// -/// If an entry for the given destination existed, it is deleted and freed. -/// -/// \param dest address of the destination node. -/// \param next address of the next hop node. -/// \param iface address of the local interface. -/// \param dist distance to the destination node. -/// void RoutingProtocol::AddEntry (Ipv4Address const &dest, Ipv4Address const &next, --- a/src/olsr/model/olsr-routing-protocol.h +++ a/src/olsr/model/olsr-routing-protocol.h @@ -54,13 +54,14 @@ /// This section documents the API of the ns-3 OLSR module. For a generic /// functional description, please refer to the ns-3 manual. +/// \ingroup olsr /// An %OLSR's routing table entry. struct RoutingTableEntry { - Ipv4Address destAddr; ///< Address of the destination node. - Ipv4Address nextAddr; ///< Address of the next hop. - uint32_t interface; ///< Interface index - uint32_t distance; ///< Distance in hops to the destination. + Ipv4Address destAddr; //!< Address of the destination node. + Ipv4Address nextAddr; //!< Address of the next hop. + uint32_t interface; //!< Interface index + uint32_t distance; //!< Distance in hops to the destination. RoutingTableEntry () : // default values destAddr (), nextAddr (), @@ -78,28 +79,33 @@ { public: friend class ::OlsrMprTestCase; + + /** + * \brief Get the type ID. + * \return The object TypeId. + */ static TypeId GetTypeId (void); RoutingProtocol (); virtual ~RoutingProtocol (); - /// - /// \brief Set the OLSR main address to the first address on the indicated - /// interface - /// \param interface IPv4 interface index - /// + /** + * \brief Set the OLSR main address to the first address on the indicated interface. + * + * \param interface IPv4 interface index + */ void SetMainInterface (uint32_t interface); - /// - /// Dump the neighbor table, two-hop neighbor table, and routing table - /// to logging output (NS_LOG_DEBUG log level). If logging is disabled, - /// this function does nothing. - /// + /** + * Dump the neighbor table, two-hop neighbor table, and routing table + * to logging output (NS_LOG_DEBUG log level). If logging is disabled, + * this function does nothing. + */ void Dump (void); /** * Return the list of routing table entries discovered by OLSR - **/ + */ std::vector GetRoutingTableEntries () const; /** @@ -129,22 +135,55 @@ typedef void (* TableChangeTracedCallback) (uint32_t size); private: - std::set m_interfaceExclusions; - Ptr m_routingTableAssociation; + std::set m_interfaceExclusions; //!< Set of interfaces excluded by OSLR. + Ptr m_routingTableAssociation; //!< Associations from an Ipv4StaticRouting instance public: + /** + * Get the excluded interfaces. + * \returns Container of excluded interfaces. + */ std::set GetInterfaceExclusions () const { return m_interfaceExclusions; } + + /** + * Set the interfaces to be excluded. + * \param exceptions Container of excluded interfaces. + */ void SetInterfaceExclusions (std::set exceptions); - /// Inject Association to be sent in HNA message + /** + * \brief Injects the specified (networkAddr, netmask) tuple in the list of + * local HNA associations to be sent by the node via HNA messages. + * If this tuple already exists, nothing is done. + * + * \param networkAddr The network address. + * \param netmask The network mask. + */ void AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask); - /// Removes Association sent in HNA message + + /** + * \brief Removes the specified (networkAddr, netmask) tuple from the list of + * local HNA associations to be sent by the node via HNA messages. + * If this tuple does not exist, nothing is done (see "OlsrState::EraseAssociation()"). + * + * \param networkAddr The network address. + * \param netmask The network mask. + */ void RemoveHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask); - /// Inject Associations from an Ipv4StaticRouting instance + /** + * \brief Associates the specified Ipv4StaticRouting routing table + * to the OLSR routing protocol. Entries from this associated + * routing table that use non-olsr outgoing interfaces are added + * to the list of local HNA associations so that they are included + * in HNA messages sent by the node. + * If this method is called more than once, entries from the old + * association are deleted before entries from the new one are added. + * \param routingTable the Ipv4StaticRouting routing table to be associated. + */ void SetRoutingTableAssociation (Ptr routingTable); /** @@ -156,48 +195,97 @@ protected: virtual void DoInitialize (void); private: - std::map m_table; ///< Data structure for the routing table. + std::map m_table; //!< Data structure for the routing table. - Ptr m_hnaRoutingTable; + Ptr m_hnaRoutingTable; //!< Routing table for HNA routes - EventGarbageCollector m_events; + EventGarbageCollector m_events; //!< Running events. - /// Packets sequence number counter. - uint16_t m_packetSequenceNumber; - /// Messages sequence number counter. - uint16_t m_messageSequenceNumber; - /// Advertised Neighbor Set sequence number. - uint16_t m_ansn; + uint16_t m_packetSequenceNumber; //!< Packets sequence number counter. + uint16_t m_messageSequenceNumber; //!< Messages sequence number counter. + uint16_t m_ansn; //!< Advertised Neighbor Set sequence number. - /// HELLO messages' emission interval. - Time m_helloInterval; - /// TC messages' emission interval. - Time m_tcInterval; - /// MID messages' emission interval. - Time m_midInterval; - /// HNA messages' emission interval. - Time m_hnaInterval; - /// Willingness for forwarding packets on behalf of other nodes. - uint8_t m_willingness; + Time m_helloInterval; //!< HELLO messages' emission interval. + Time m_tcInterval; //!< TC messages' emission interval. + Time m_midInterval; //!< MID messages' emission interval. + Time m_hnaInterval; //!< HNA messages' emission interval. + uint8_t m_willingness; //!< Willingness for forwarding packets on behalf of other nodes. - /// Internal state with all needed data structs. - OlsrState m_state; + OlsrState m_state; //!< Internal state with all needed data structs. + Ptr m_ipv4; //!< IPv4 object the routing is linked to. - Ptr m_ipv4; + /** + * \brief Clears the routing table and frees the memory assigned to each one of its entries. + */ + void Clear (); - void Clear (); + /** + * Returns the routing table size. + * \return The routing table size. + */ uint32_t GetSize () const { return m_table.size (); } + + /** + * \brief Deletes the entry whose destination address is given. + * \param dest address of the destination node. + */ void RemoveEntry (const Ipv4Address &dest); + /** + * \brief Adds a new entry into the routing table. + * + * If an entry for the given destination existed, it is deleted and freed. + * + * \param dest address of the destination node. + * \param next address of the next hop node. + * \param interface address of the local interface. + * \param distance distance to the destination node. + */ void AddEntry (const Ipv4Address &dest, const Ipv4Address &next, uint32_t interface, uint32_t distance); + /** + * \brief Adds a new entry into the routing table. + * + * If an entry for the given destination existed, an error is thrown. + * + * \param dest address of the destination node. + * \param next address of the next hop node. + * \param interfaceAddress address of the local interface. + * \param distance distance to the destination node. + */ void AddEntry (const Ipv4Address &dest, const Ipv4Address &next, const Ipv4Address &interfaceAddress, uint32_t distance); + + /** + * \brief Looks up an entry for the specified destination address. + * \param [in] dest Destination address. + * \param [out] outEntry Holds the routing entry result, if found. + * \return true if found, false if not found. + */ bool Lookup (const Ipv4Address &dest, RoutingTableEntry &outEntry) const; + + /** + * \brief Finds the appropriate entry which must be used in order to forward + * a data packet to a next hop (given a destination). + * + * Imagine a routing table like this: [A,B] [B,C] [C,C]; being each pair of the + * form [dest addr, next-hop addr]. In this case, if this function is invoked + * with [A,B] then pair [C,C] is returned because C is the next hop that must be used + * to forward a data packet destined to A. That is, C is a neighbor of this node, + * but B isn't. This function finds the appropriate neighbor for forwarding a packet. + * + * \param[in] entry The routing table entry which indicates the destination node + * we are interested in. + * + * \param[out] outEntry The appropriate routing table entry which indicates the next + * hop which must be used for forwarding a data packet, or NULL if there is no such entry. + * + * \return True if an entry was found, false otherwise. + */ bool FindSendEntry (const RoutingTableEntry &entry, RoutingTableEntry &outEntry) const; @@ -222,96 +310,435 @@ void DoDispose (); + /** + * Send an OLSR message. + * \param packet The packet to be sent. + * \param containedMessages The messages contained in the packet. + */ void SendPacket (Ptr packet, const MessageList &containedMessages); - /// Increments packet sequence number and returns the new value. + /** + * Increments packet sequence number and returns the new value. + * \return The packet sequence number. + */ inline uint16_t GetPacketSequenceNumber (); - /// Increments message sequence number and returns the new value. + + /** + * Increments message sequence number and returns the new value. + * \return The message sequence number. + */ inline uint16_t GetMessageSequenceNumber (); + /** + * Receive an OLSR message. + * \param socket The receiving socket. + */ void RecvOlsr (Ptr socket); + /** + * \brief Computates MPR set of a node following \RFC{3626} hints. + */ void MprComputation (); + + /** + * \brief Creates the routing table of the node following \RFC{3626} hints. + */ void RoutingTableComputation (); + + /** + * \brief Gets the main address associated with a given interface address. + * \param iface_addr the interface address. + * \return the corresponding main address. + */ Ipv4Address GetMainAddress (Ipv4Address iface_addr) const; + + /** + * \brief Tests whether or not the specified route uses a non-OLSR outgoing interface. + * \param route The route to be tested. + * \returns True if the outgoing interface of the specified route is a non-OLSR interface, false otherwise. + */ bool UsesNonOlsrOutgoingInterface (const Ipv4RoutingTableEntry &route); // Timer handlers - Timer m_helloTimer; + Timer m_helloTimer; //!< Timer for the HELLO message. + /** + * \brief Sends a HELLO message and reschedules the HELLO timer. + */ void HelloTimerExpire (); - Timer m_tcTimer; + Timer m_tcTimer; //!< Timer for the TC message. + /** + * \brief Sends a TC message (if there exists any MPR selector) and reschedules the TC timer. + */ void TcTimerExpire (); - Timer m_midTimer; + Timer m_midTimer; //!< Timer for the MID message. + /** + * \brief \brief Sends a MID message (if the node has more than one interface) and resets the MID timer. + */ void MidTimerExpire (); - Timer m_hnaTimer; + Timer m_hnaTimer; //!< Timer for the HNA message. + /** + * \brief Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer. + */ void HnaTimerExpire (); + /** + * \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime. + * + * The task of actually removing the tuple is left to the OLSR agent. + * + * \param address The address of the tuple. + * \param sequenceNumber The sequence number of the tuple. + */ void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber); - bool m_linkTupleTimerFirstTime; + + bool m_linkTupleTimerFirstTime; //!< Flag to indicate if it is the first time the LinkTupleTimer fires. + /** + * \brief Removes tuple_ if expired. Else if symmetric time + * has expired then it is assumed a neighbor loss and agent_->nb_loss() + * is called. In this case the timer is rescheduled to expire at + * tuple_->time(). Otherwise the timer is rescheduled to expire at + * the minimum between tuple_->time() and tuple_->sym_time(). + * + * The task of actually removing the tuple is left to the OLSR agent. + * + * \param neighborIfaceAddr The tuple neighbor interface address. + */ void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr); + + /** + * \brief Removes 2_hop neighbor tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). + * + * The task of actually removing the tuple is left to the OLSR agent. + * + * \param neighborMainAddr The neighbor main address. + * \param twoHopNeighborAddr The 2-hop neighbor address. + */ void Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr); + + /** + * \brief Removes MPR selector tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). + * + * The task of actually removing the tuple is left to the OLSR agent. + * + * \param mainAddr The tuple IPv4 address. + */ void MprSelTupleTimerExpire (Ipv4Address mainAddr); + + /** + * \brief Removes topology tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). + * + * The task of actually removing the tuple is left to the OLSR agent. + * + * \param destAddr The destination address. + * \param lastAddr The last address. + */ void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr); + + /** + * \brief Removes interface association tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time(). + * + * \param ifaceAddr The interface address. + */ void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr); + + /** + * \brief Removes association tuple_ if expired. Else timer is rescheduled to expire at tuple_->time(). + * + * \param gatewayAddr The gateway address. + * \param networkAddr The network address. + * \param netmask The network mask. + */ void AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask); + /** + * Increments the ANSN counter. + */ void IncrementAnsn (); /// A list of pending messages which are buffered awaiting for being sent. olsr::MessageList m_queuedMessages; - Timer m_queuedMessagesTimer; // timer for throttling outgoing messages + Timer m_queuedMessagesTimer; //!< timer for throttling outgoing messages + /** + * \brief OLSR's default forwarding algorithm. + * + * See \RFC{3626} for details. + * + * \param olsrMessage The %OLSR message which must be forwarded. + * \param duplicated NULL if the message has never been considered for forwarding, or a duplicate tuple in other case. + * \param localIface The address of the interface where the message was received from. + * \param senderAddress The sender IPv4 address. + */ void ForwardDefault (olsr::MessageHeader olsrMessage, DuplicateTuple *duplicated, const Ipv4Address &localIface, const Ipv4Address &senderAddress); + + /** + * \brief Enques an %OLSR message which will be sent with a delay of (0, delay]. + * + * This buffering system is used in order to piggyback several %OLSR messages in + * a same %OLSR packet. + * + * \param message the %OLSR message which must be sent. + * \param delay maximum delay the %OLSR message is going to be buffered. + */ void QueueMessage (const olsr::MessageHeader &message, Time delay); + + /** + * \brief Creates as many %OLSR packets as needed in order to send all buffered + * %OLSR messages. + * + * Maximum number of messages which can be contained in an %OLSR packet is + * dictated by OLSR_MAX_MSGS constant. + */ void SendQueuedMessages (); - void SendHello (); + + /** + * \brief Creates a new %OLSR HELLO message which is buffered for being sent later on. + */ + void SendHello (); + + /** + * \brief Creates a new %OLSR TC message which is buffered for being sent later on. + */ void SendTc (); + + /** + * \brief Creates a new %OLSR MID message which is buffered for being sent later on. + */ void SendMid (); + + /** + * \brief Creates a new %OLSR HNA message which is buffered for being sent later on. + */ void SendHna (); + /** + * \brief Performs all actions needed when a neighbor loss occurs. + * + * Neighbor Set, 2-hop Neighbor Set, MPR Set and MPR Selector Set are updated. + * + * \param tuple link tuple with the information of the link to the neighbor which has been lost. + */ void NeighborLoss (const LinkTuple &tuple); + + /** + * \brief Adds a duplicate tuple to the Duplicate Set. + * + * \param tuple The duplicate tuple to be added. + */ void AddDuplicateTuple (const DuplicateTuple &tuple); + + /** + * \brief Removes a duplicate tuple from the Duplicate Set. + * + * \param tuple The duplicate tuple to be removed. + */ void RemoveDuplicateTuple (const DuplicateTuple &tuple); + + /** + * Adds a link tuple. + * \param tuple Thetuple to be added. + * \param willingness The tuple willingness. + */ void LinkTupleAdded (const LinkTuple &tuple, uint8_t willingness); + + /** + * \brief Removes a link tuple from the Link Set. + * + * \param tuple The link tuple to be removed. + */ void RemoveLinkTuple (const LinkTuple &tuple); + + /** + * \brief This function is invoked when a link tuple is updated. Its aim is to + * also update the corresponding neighbor tuple if it is needed. + * + * \param tuple The link tuple which has been updated. + * \param willingness The tuple willingness. + */ void LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness); + + /** + * \brief Adds a neighbor tuple to the Neighbor Set. + * + * \param tuple The neighbor tuple to be added. + */ void AddNeighborTuple (const NeighborTuple &tuple); + + /** + * \brief Removes a neighbor tuple from the Neighbor Set. + * + * \param tuple The neighbor tuple to be removed. + */ void RemoveNeighborTuple (const NeighborTuple &tuple); + + /** + * \brief Adds a 2-hop neighbor tuple to the 2-hop Neighbor Set. + * + * \param tuple The 2-hop neighbor tuple to be added. + */ void AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple); + + /** + * \brief Removes a 2-hop neighbor tuple from the 2-hop Neighbor Set. + * + * \param tuple The 2-hop neighbor tuple to be removed. + */ void RemoveTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple); + + /** + * \brief Adds an MPR selector tuple to the MPR Selector Set. + * Advertised Neighbor Sequence Number (ANSN) is also updated. + * + * \param tuple The MPR selector tuple to be added. + */ void AddMprSelectorTuple (const MprSelectorTuple &tuple); + + /** + * \brief Removes an MPR selector tuple from the MPR Selector Set. + * Advertised Neighbor Sequence Number (ANSN) is also updated. + * + * \param tuple The MPR selector tuple to be removed. + */ void RemoveMprSelectorTuple (const MprSelectorTuple &tuple); + + /** + * \brief Adds a topology tuple to the Topology Set. + * + * \param tuple The topology tuple to be added. + */ void AddTopologyTuple (const TopologyTuple &tuple); + + /** + * \brief Removes a topology tuple to the Topology Set. + * + * \param tuple The topology tuple to be removed. + */ void RemoveTopologyTuple (const TopologyTuple &tuple); + + /** + * \brief Adds an interface association tuple to the Interface Association Set. + * + * \param tuple The interface association tuple to be added. + */ void AddIfaceAssocTuple (const IfaceAssocTuple &tuple); + + /** + * \brief Removed an interface association tuple to the Interface Association Set. + * + * \param tuple The interface association tuple to be removed. + */ void RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple); + + /** + * \brief Adds a host network association tuple to the Association Set. + * + * \param tuple The host network association tuple to be added. + */ void AddAssociationTuple (const AssociationTuple &tuple); + + /** + * \brief Removes a host network association tuple to the Association Set. + * + * \param tuple The host network association tuple to be removed. + */ void RemoveAssociationTuple (const AssociationTuple &tuple); + /** + * \brief Processes a HELLO message following \RFC{3626} specification. + * + * Link sensing and population of the Neighbor Set, 2-hop Neighbor Set and MPR + * Selector Set are performed. + * + * \param msg the %OLSR message which contains the HELLO message. + * \param receiverIface the address of the interface where the message was received from. + * \param senderIface the address of the interface where the message was sent from. + */ void ProcessHello (const olsr::MessageHeader &msg, const Ipv4Address &receiverIface, const Ipv4Address &senderIface); + + /** + * \brief Processes a TC message following \RFC{3626} specification. + * + * The Topology Set is updated (if needed) with the information of + * the received TC message. + * + * \param msg The %OLSR message which contains the TC message. + * \param senderIface The address of the interface where the message was sent from. + * + */ void ProcessTc (const olsr::MessageHeader &msg, const Ipv4Address &senderIface); + + /** + * \brief Processes a MID message following \RFC{3626} specification. + * + * The Interface Association Set is updated (if needed) with the information + * of the received MID message. + * + * \param msg the %OLSR message which contains the MID message. + * \param senderIface the address of the interface where the message was sent from. + */ void ProcessMid (const olsr::MessageHeader &msg, const Ipv4Address &senderIface); + + /** + * + * \brief Processes a HNA message following \RFC{3626} specification. + * + * The Host Network Association Set is updated (if needed) with the information + * of the received HNA message. + * + * \param msg the %OLSR message which contains the HNA message. + * \param senderIface the address of the interface where the message was sent from. + * + */ void ProcessHna (const olsr::MessageHeader &msg, const Ipv4Address &senderIface); + /** + * \brief Updates Link Set according to a new received HELLO message + * (following \RFC{3626} specification). Neighbor Set is also updated if needed. + * \param msg The received message. + * \param hello The received HELLO sub-message. + * \param receiverIface The interface that received the message. + * \param senderIface The sender interface. + */ void LinkSensing (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello, const Ipv4Address &receiverIface, - const Ipv4Address &sender_iface); + const Ipv4Address &senderIface); + + /** + * \brief Updates the Neighbor Set according to the information contained in + * a new received HELLO message (following \RFC{3626}). + * \param msg The received message. + * \param hello The received HELLO sub-message. + */ void PopulateNeighborSet (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello); + + /** + * \brief Updates the 2-hop Neighbor Set according to the information contained + * in a new received HELLO message (following \RFC{3626}). + * \param msg The received message. + * \param hello The received HELLO sub-message. + */ void PopulateTwoHopNeighborSet (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello); + + /** + * \brief Updates the MPR Selector Set according to the information contained in + * a new received HELLO message (following \RFC{3626}). + * \param msg The received message. + * \param hello The received HELLO sub-message. + */ void PopulateMprSelectorSet (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello); @@ -319,17 +746,20 @@ /// Check that address is one of my interfaces bool IsMyOwnAddress (const Ipv4Address & a) const; - Ipv4Address m_mainAddress; + Ipv4Address m_mainAddress; //!< the node main address. // One socket per interface, each bound to that interface's address // (reason: for OLSR Link Sensing we need to know on which interface // HELLO messages arrive) - std::map< Ptr, Ipv4InterfaceAddress > m_socketAddresses; + std::map< Ptr, Ipv4InterfaceAddress > m_socketAddresses; //!< Container of sockets and the interfaces they are opened onto. - TracedCallback m_rxPacketTrace; - TracedCallback m_txPacketTrace; + /// Rx packet trace. + TracedCallback m_rxPacketTrace; + + /// Tx packet trace. + TracedCallback m_txPacketTrace; + + /// Routing table chanes challback TracedCallback m_routingTableChanged; /// Provides uniform random variables. --- a/src/olsr/model/olsr-state.h +++ a/src/olsr/model/olsr-state.h @@ -30,22 +30,23 @@ namespace ns3 { namespace olsr { +/// \ingroup olsr /// This class encapsulates all data structures needed for maintaining internal state of an OLSR node. class OlsrState { // friend class Olsr; protected: - LinkSet m_linkSet; ///< Link Set (\RFC{3626}, section 4.2.1). - NeighborSet m_neighborSet; ///< Neighbor Set (\RFC{3626}, section 4.3.1). - TwoHopNeighborSet m_twoHopNeighborSet; ///< 2-hop Neighbor Set (\RFC{3626}, section 4.3.2). - TopologySet m_topologySet; ///< Topology Set (\RFC{3626}, section 4.4). - MprSet m_mprSet; ///< MPR Set (\RFC{3626}, section 4.3.3). - MprSelectorSet m_mprSelectorSet; ///< MPR Selector Set (\RFC{3626}, section 4.3.4). - DuplicateSet m_duplicateSet; ///< Duplicate Set (\RFC{3626}, section 3.4). - IfaceAssocSet m_ifaceAssocSet; ///< Interface Association Set (\RFC{3626}, section 4.1). - AssociationSet m_associationSet; ///< Association Set (\RFC{3626}, section12.2). Associations obtained from HNA messages generated by other nodes. - Associations m_associations; ///< The node's local Host Network Associations that will be advertised using HNA messages. + LinkSet m_linkSet; //!< Link Set (\RFC{3626}, section 4.2.1). + NeighborSet m_neighborSet; //!< Neighbor Set (\RFC{3626}, section 4.3.1). + TwoHopNeighborSet m_twoHopNeighborSet; //!< 2-hop Neighbor Set (\RFC{3626}, section 4.3.2). + TopologySet m_topologySet; //!< Topology Set (\RFC{3626}, section 4.4). + MprSet m_mprSet; //!< MPR Set (\RFC{3626}, section 4.3.3). + MprSelectorSet m_mprSelectorSet; //!< MPR Selector Set (\RFC{3626}, section 4.3.4). + DuplicateSet m_duplicateSet; //!< Duplicate Set (\RFC{3626}, section 3.4). + IfaceAssocSet m_ifaceAssocSet; //!< Interface Association Set (\RFC{3626}, section 4.1). + AssociationSet m_associationSet; //!< Association Set (\RFC{3626}, section12.2). Associations obtained from HNA messages generated by other nodes. + Associations m_associations; //!< The node's local Host Network Associations that will be advertised using HNA messages. public: @@ -53,122 +54,377 @@ {} // MPR selector + + /** + * Gets the MPR selectors. + * \returns The MPR selectors. + */ const MprSelectorSet & GetMprSelectors () const { return m_mprSelectorSet; } + + /** + * Finds a MPR selector tuple. + * \param mainAddr The MPR selector main address. + * \returns The MPR selector, if found. Else it returns a null pointer. + */ MprSelectorTuple* FindMprSelectorTuple (const Ipv4Address &mainAddr); + + /** + * Erases a MPR selector tuple. + * \param tuple The MPR selector tuple. + */ void EraseMprSelectorTuple (const MprSelectorTuple &tuple); + + /** + * Erases all MPR selector tuples belonging to the same address. + * \param mainAddr The MPR selector main address. + */ void EraseMprSelectorTuples (const Ipv4Address &mainAddr); + + /** + * Inserts a MPR selector tuple + * \param tuple The MPR selector tuple. + */ void InsertMprSelectorTuple (const MprSelectorTuple &tuple); + + /** + * Prints the MPR selector sets. + * \return a string with the output data. + */ std::string PrintMprSelectorSet () const; // Neighbor + + /** + * Gets the neighbor set. + * \returns The neighbor set. + */ const NeighborSet & GetNeighbors () const { return m_neighborSet; } + /** + * Gets the neighbor set. + * \returns The neighbor set. + */ NeighborSet & GetNeighbors () { return m_neighborSet; } + + /** + * Finds a neighbor tuple. + * \param mainAddr The neighbor tuple main address. + * \returns The neighbor tuple, if found. Else it returns a null pointer. + */ NeighborTuple* FindNeighborTuple (const Ipv4Address &mainAddr); + + /** + * Finds a symmetrical neighbor tuple. + * \param mainAddr The neighbor tuple main address. + * \returns The neighbor tuple, if found. Else it returns a null pointer. + */ const NeighborTuple* FindSymNeighborTuple (const Ipv4Address &mainAddr) const; + + /** + * Finds a neighbor tuple. + * \param mainAddr The neighbor tuple main address. + * \param willingness The neighbor willingness. + * \returns The neighbor tuple, if found. Else it returns a null pointer. + */ NeighborTuple* FindNeighborTuple (const Ipv4Address &mainAddr, uint8_t willingness); + + /** + * Erases a neighbor tuple. + * \param neighborTuple The neighbor tuple. + */ void EraseNeighborTuple (const NeighborTuple &neighborTuple); + /** + * Erases a neighbor tuple. + * \param mainAddr The neighbor tuple main address. + */ void EraseNeighborTuple (const Ipv4Address &mainAddr); + + /** + * Inserts a neighbor tuple. + * \param tuple The neighbor tuple. + */ void InsertNeighborTuple (const NeighborTuple &tuple); // Two-hop neighbor + + /** + * Gets the 2-hop neighbor set. + * \returns The 2-hop neighbor set. + */ const TwoHopNeighborSet & GetTwoHopNeighbors () const { return m_twoHopNeighborSet; } + /** + * Gets the 2-hop neighbor set. + * \returns The 2-hop neighbor set. + */ TwoHopNeighborSet & GetTwoHopNeighbors () { return m_twoHopNeighborSet; } + + /** + * Finds a 2-hop neighbor tuple. + * \param neighbor The neighbor main address. + * \param twoHopNeighbor The 2-hop neighbor main address. + * \returns The 2-hop neighbor tuple, if found. Else it returns a null pointer. + */ TwoHopNeighborTuple* FindTwoHopNeighborTuple (const Ipv4Address &neighbor, const Ipv4Address &twoHopNeighbor); + + /** + * Erases a 2-hop neighbor tuple. + * \param tuple The 2-hop neighbor tuple. + */ void EraseTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple); + /** + * Erases the 2-hop neighbor tuples with the same 1-hop neighbor. + * \param neighbor The neighbor address. + */ void EraseTwoHopNeighborTuples (const Ipv4Address &neighbor); + /** + * Erases the 2-hop neighbor tuples with matching predicates. + * \param neighbor The neighbor address. + * \param twoHopNeighbor The 2-hop neighbor main address. + */ void EraseTwoHopNeighborTuples (const Ipv4Address &neighbor, const Ipv4Address &twoHopNeighbor); + /** + * Inserts a 2-hop neighbor tuple. + * \param tuple The 2-hop neighbor tuple. + */ void InsertTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple); // MPR + + /** + * Checks if there's an MPR with a specific address. + * \param address The address to test. + * \return True if a MPR with the specified address exists. + */ bool FindMprAddress (const Ipv4Address &address); - /// MprSet is set by routing protocol after MprCompute + + /** + * Sets the MPR set to the one specified. + * \param mprSet The new MPR set. + */ void SetMprSet (MprSet mprSet); - /// Gets an MPR Set needed by tests + + /** + * Gets the MPR set. + * \return The MPR set. + */ MprSet GetMprSet () const; // Duplicate + + /** + * Finds a duplicate tuple. + * \param address The duplicate tuple address. + * \param sequenceNumber The duplicate tuple sequence number. + * \returns The duplicate tuple, or a null pointer if no match. + */ DuplicateTuple* FindDuplicateTuple (const Ipv4Address &address, uint16_t sequenceNumber); + + /** + * Erases a duplicate tuple. + * \param tuple The tuple to erase. + */ void EraseDuplicateTuple (const DuplicateTuple &tuple); + /** + * Inserts a duplicate tuple. + * \param tuple The tuple to insert. + */ void InsertDuplicateTuple (const DuplicateTuple &tuple); // Link + + /** + * Gets the Link set. + * \return The Link set. + */ const LinkSet & GetLinks () const { return m_linkSet; } + /** + * Finds a link tuple. + * \param ifaceAddr The interface address of the link. + * \returns The link tuple, or a null pointer if no match. + */ LinkTuple* FindLinkTuple (const Ipv4Address &ifaceAddr); + /** + * Finds a symmetrical link tuple. + * \param ifaceAddr The interface address of the link. + * \param time The time at which the link should be considered symmetrical. + * \returns The link tuple, or a null pointer if no match. + */ LinkTuple* FindSymLinkTuple (const Ipv4Address &ifaceAddr, Time time); + /** + * Erases a link tuple. + * \param tuple The tuple to erase. + */ void EraseLinkTuple (const LinkTuple &tuple); + /** + * Inserts a link tuple. + * \param tuple The tuple to insert. + * \returns A reference to the inserted tuple. + */ LinkTuple& InsertLinkTuple (const LinkTuple &tuple); // Topology + + /** + * Gets the topology set. + * \returns The topology set. + */ const TopologySet & GetTopologySet () const { return m_topologySet; } + /** + * Finds a topology tuple. + * \param destAddr The destination address. + * \param lastAddr The address of the node previous to the destination. + * \returns The topology tuple, or a null pointer if no match. + */ TopologyTuple* FindTopologyTuple (const Ipv4Address &destAddr, const Ipv4Address &lastAddr); + /** + * Finds a topology tuple. + * \param lastAddr The address of the node previous to the destination. + * \param ansn The Advertised Neighbor Sequence Number. + * \returns The topology tuple, or a null pointer if no match. + */ TopologyTuple* FindNewerTopologyTuple (const Ipv4Address &lastAddr, uint16_t ansn); + /** + * Erases a topology tuple. + * \param tuple The tuple to erase. + */ void EraseTopologyTuple (const TopologyTuple &tuple); + /** + * Erases a topology tuple. + * \param lastAddr The address of the node previous to the destination. + * \param ansn The Advertised Neighbor Sequence Number. + */ void EraseOlderTopologyTuples (const Ipv4Address &lastAddr, uint16_t ansn); + /** + * Inserts a topology tuple. + * \param tuple The tuple to insert. + */ void InsertTopologyTuple (const TopologyTuple &tuple); // Interface association + + /** + * Gets the interface association set. + * \returns The interface association set. + */ const IfaceAssocSet & GetIfaceAssocSet () const { return m_ifaceAssocSet; } + /** + * Gets a mutable reference to the interface association set. + * \returns The interface association set. + */ IfaceAssocSet & GetIfaceAssocSetMutable () { return m_ifaceAssocSet; } + + /** + * Finds a interface association tuple. + * \param ifaceAddr The interface address. + * \returns The interface association tuple, or a null pointer if no match. + */ IfaceAssocTuple* FindIfaceAssocTuple (const Ipv4Address &ifaceAddr); + /** + * Finds a interface association tuple. + * \param ifaceAddr The interface address. + * \returns The interface association tuple, or a null pointer if no match. + */ const IfaceAssocTuple* FindIfaceAssocTuple (const Ipv4Address &ifaceAddr) const; + /** + * Erases a interface association tuple. + * \param tuple The tuple to erase. + */ void EraseIfaceAssocTuple (const IfaceAssocTuple &tuple); + /** + * Inserts a interface association tuple. + * \param tuple The tuple to insert. + */ void InsertIfaceAssocTuple (const IfaceAssocTuple &tuple); // Host-Network Association + /** + * Gets the association set known to the node. + * \returns The association set known to the node. + */ const AssociationSet & GetAssociationSet () const // Associations known to the node { return m_associationSet; } + /** + * Gets the association set the node has. + * \returns The association set the node has. + */ const Associations & GetAssociations () const // Set of associations that the node has { return m_associations; } + /** + * Finds an association tuple. + * \param gatewayAddr The gateway address. + * \param networkAddr The network address. + * \param netmask The network mask. + * \returns The association tuple, or a null pointer if no match. + */ AssociationTuple* FindAssociationTuple (const Ipv4Address &gatewayAddr, \ const Ipv4Address &networkAddr, \ const Ipv4Mask &netmask); + /** + * Erases a known association tuple. + * \param tuple The tuple to erase. + */ void EraseAssociationTuple (const AssociationTuple &tuple); + /** + * Inserts a known association tuple. + * \param tuple The tuple to insert. + */ void InsertAssociationTuple (const AssociationTuple &tuple); + /** + * Erases an association. + * \param tuple The tuple to erase. + */ void EraseAssociation (const Association &tuple); + /** + * Inserts an association tuple. + * \param tuple The tuple to insert. + */ void InsertAssociation (const Association &tuple); - // Returns a vector of all interfaces of a given neighbor, with the - // exception of the "main" one. + /** + * Returns a vector of all interfaces of a given neighbor, with the + * exception of the "main" one. + * \param neighborMainAddr The neighbor main address + * \returns A container of the neighbor addresses (excluding the main one). + */ std::vector FindNeighborInterfaces (const Ipv4Address &neighborMainAddr) const;