diff -r 20ee319e7e71 src/helper/olsr-helper.cc --- a/src/helper/olsr-helper.cc Sun Feb 14 02:06:30 2010 +0300 +++ b/src/helper/olsr-helper.cc Mon Mar 08 10:56:08 2010 +0530 @@ -33,6 +33,7 @@ OlsrHelper::OlsrHelper (const OlsrHelper &o) : m_agentFactory (o.m_agentFactory) { + m_interfaceExclusions = o.m_interfaceExclusions; } OlsrHelper* @@ -41,10 +42,36 @@ return new OlsrHelper (*this); } +void +OlsrHelper::ExcludeInterface (Ptr node, uint32_t interface) +{ + std::map< Ptr, std::set >::iterator it = m_interfaceExclusions.find (node); + + if(it == m_interfaceExclusions.end ()) + { + std::set interfaces; + interfaces.insert (interface); + + m_interfaceExclusions.insert (std::make_pair (node, std::set (interfaces) )); + } + else + { + it->second.insert (interface); + } +} + Ptr OlsrHelper::Create (Ptr node) const { Ptr agent = m_agentFactory.Create (); + + std::map, std::set >::const_iterator it = m_interfaceExclusions.find (node); + + if(it != m_interfaceExclusions.end ()) + { + agent->SetInterfaceExclusions (it->second); + } + node->AggregateObject (agent); return agent; } diff -r 20ee319e7e71 src/helper/olsr-helper.h --- a/src/helper/olsr-helper.h Sun Feb 14 02:06:30 2010 +0300 +++ b/src/helper/olsr-helper.h Mon Mar 08 10:56:08 2010 +0530 @@ -24,6 +24,8 @@ #include "ns3/node.h" #include "node-container.h" #include "ipv4-routing-helper.h" +#include +#include namespace ns3 { @@ -57,6 +59,14 @@ */ OlsrHelper* Copy (void) const; + /** + * \param node the node for which an exception is to be defined + * \param interface an interface of node on which OLSR is not to be installed + * + * This method allows the user to specify an interface on which OLSR is not to be installed on + */ + void ExcludeInterface (Ptr node, uint32_t interface); + /** * \param node the node on which the routing protocol will run * \returns a newly-created routing protocol @@ -72,6 +82,7 @@ * This method controls the attributes of ns3::olsr::RoutingProtocol */ void Set (std::string name, const AttributeValue &value); + private: /** * \internal @@ -80,6 +91,8 @@ */ OlsrHelper &operator = (const OlsrHelper &o); ObjectFactory m_agentFactory; + + std::map< Ptr, std::set > m_interfaceExclusions; }; } // namespace ns3 diff -r 20ee319e7e71 src/routing/olsr/olsr-repositories.h --- a/src/routing/olsr/olsr-repositories.h Sun Feb 14 02:06:30 2010 +0300 +++ b/src/routing/olsr/olsr-repositories.h Mon Mar 08 10:56:08 2010 +0530 @@ -231,6 +231,61 @@ return os; } +/// Association +struct Association +{ + Ipv4Address networkAddr; + Ipv4Mask 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; +} + +/// 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; +}; + +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; +} + typedef std::set MprSet; ///< MPR Set type. typedef std::vector MprSelectorSet; ///< MPR Selector Set type. @@ -240,6 +295,8 @@ 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 diff -r 20ee319e7e71 src/routing/olsr/olsr-routing-protocol.cc --- a/src/routing/olsr/olsr-routing-protocol.cc Sun Feb 14 02:06:30 2010 +0300 +++ b/src/routing/olsr/olsr-routing-protocol.cc Mon Mar 08 10:56:08 2010 +0530 @@ -41,6 +41,7 @@ #include "ns3/random-variable.h" #include "ns3/inet-socket-address.h" #include "ns3/ipv4-routing-protocol.h" +#include "ns3/ipv4-routing-table-entry.h" #include "ns3/ipv4-route.h" #include "ns3/boolean.h" #include "ns3/uinteger.h" @@ -79,7 +80,8 @@ #define OLSR_DUP_HOLD_TIME Seconds (30) /// MID holding time. #define OLSR_MID_HOLD_TIME (Scalar (3) * m_midInterval) - +/// HNA holding time. +#define OLSR_HNA_HOLD_TIME (Scalar (3) * m_hnaInterval) /********** Link types **********/ @@ -165,6 +167,10 @@ TimeValue (Seconds (5)), MakeTimeAccessor (&RoutingProtocol::m_midInterval), MakeTimeChecker ()) + .AddAttribute ("HnaInterval", "HNA messages emission interval. Normally it is equal to TcInterval.", + TimeValue (Seconds (5)), + MakeTimeAccessor (&RoutingProtocol::m_hnaInterval), + MakeTimeChecker ()) .AddAttribute ("Willingness", "Willingness of a node to carry and forward traffic for other nodes.", EnumValue (OLSR_WILL_DEFAULT), MakeEnumAccessor (&RoutingProtocol::m_willingness), @@ -189,6 +195,7 @@ m_helloTimer (Timer::CANCEL_ON_DESTROY), m_tcTimer (Timer::CANCEL_ON_DESTROY), m_midTimer (Timer::CANCEL_ON_DESTROY), + m_hnaTimer (Timer::CANCEL_ON_DESTROY), m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY) {} @@ -204,6 +211,7 @@ m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this); m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this); + m_hnaTimer.SetFunction (&RoutingProtocol::HnaTimerExpire, this); m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this); m_packetSequenceNumber = OLSR_MAX_SEQ_NUM; @@ -213,6 +221,8 @@ m_linkTupleTimerFirstTime = true; m_ipv4 = ipv4; + + HnaRoutingTable.SetIpv4 (ipv4); } void RoutingProtocol::DoDispose () @@ -251,6 +261,8 @@ NS_LOG_DEBUG ("Starting OLSR on node " << m_mainAddress); Ipv4Address loopback ("127.0.0.1"); + + bool canRunOlsr = false; for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) { Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal (); @@ -269,6 +281,9 @@ NS_ASSERT (GetMainAddress (addr) == m_mainAddress); } + if(m_interfaceExclusions.find (i) != m_interfaceExclusions.end ()) + continue; + // Create a socket to listen only on this interface Ptr socket = Socket::CreateSocket (GetObject (), UdpSocketFactory::GetTypeId()); @@ -279,13 +294,19 @@ } socket->Connect (InetSocketAddress (Ipv4Address (0xffffffff), OLSR_PORT_NUMBER)); m_socketAddresses[socket] = m_ipv4->GetAddress (i, 0); + + canRunOlsr = true; } - HelloTimerExpire (); - TcTimerExpire (); - MidTimerExpire (); + if(canRunOlsr) + { + HelloTimerExpire (); + TcTimerExpire (); + MidTimerExpire (); + HnaTimerExpire (); - NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started"); + NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started"); + } } void RoutingProtocol::SetMainInterface (uint32_t interface) @@ -293,6 +314,10 @@ m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal (); } +void RoutingProtocol::SetInterfaceExclusions (std::set exceptions) +{ + m_interfaceExclusions = exceptions; +} // // \brief Processes an incoming %OLSR packet following RFC 3626 specification. @@ -397,6 +422,12 @@ << " received MID message of size " << messageHeader.GetSerializedSize ()); ProcessMid (messageHeader, senderIfaceAddr); break; + case olsr::MessageHeader::HNA_MESSAGE: + NS_LOG_DEBUG (Simulator::Now ().GetSeconds () + << "s OLSR node " << m_mainAddress + << " received HNA message of size " << messageHeader.GetSerializedSize ()); + ProcessHna (messageHeader, senderIfaceAddr); + break; default: NS_LOG_DEBUG ("OLSR message type " << @@ -1039,6 +1070,53 @@ } } + // 5. For each tuple in the association set, + // If there is no entry in the routing table with: + // R_dest_addr == A_network_addr/A_netmask + // then a new routing entry is created. + const AssociationSet &associationSet = m_state.GetAssociationSet (); + for (AssociationSet::const_iterator it = associationSet.begin (); + it != associationSet.end (); it++) + { + AssociationTuple const &tuple = *it; + RoutingTableEntry gateway_entry; + + bool have_gateway_entry = Lookup (tuple.gatewayAddr, gateway_entry); + bool to_add = false; + + uint32_t route_index = 0; + + for (route_index = 0; route_index < HnaRoutingTable.GetNRoutes (); route_index++) + { + Ipv4RoutingTableEntry route = HnaRoutingTable.GetRoute (route_index); + if (route.GetDestNetwork () == tuple.networkAddr && + route.GetDestNetworkMask () == tuple.netmask) + { + break; + } + } + + if (route_index == HnaRoutingTable.GetNRoutes ()) + { + to_add = true; + } + else if(have_gateway_entry && HnaRoutingTable.GetMetric (route_index) > gateway_entry.distance) + { + HnaRoutingTable.RemoveRoute(route_index); + to_add = true; + } + + if(to_add && have_gateway_entry) + { + HnaRoutingTable.AddNetworkRouteTo (tuple.networkAddr, + tuple.netmask, + gateway_entry.nextAddr, + gateway_entry.interface, + gateway_entry.distance); + + } + } + NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end."); m_routingTableChanged (GetSize ()); } @@ -1280,6 +1358,67 @@ 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) +{ + + const olsr::MessageHeader::Hna &hna = msg.GetHna (); + Time now = Simulator::Now (); + + // 1. If the sender interface of this message is not in the symmetric + // 1-hop neighborhood of this node, the message MUST be discarded. + const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now); + if (link_tuple == NULL) + return; + + // 2. Otherwise, for each (network address, netmask) pair in the + // message: + + for (std::vector::const_iterator it = hna.associations.begin(); + it != hna.associations.end() ; it++) + { + AssociationTuple *tuple = m_state.FindAssociationTuple(msg.GetOriginatorAddress(),it->address,it->mask); + + // 2.1 if an entry in the association set already exists, where: + // A_gateway_addr == originator address + // A_network_addr == network address + // A_netmask == netmask + // then the holding time for that tuple MUST be set to: + // A_time = current time + validity time + if(tuple != NULL) + { + tuple->expirationTime = now + msg.GetVTime (); + } + + // 2.2 otherwise, a new tuple MUST be recorded with: + // A_gateway_addr = originator address + // A_network_addr = network address + // A_netmask = netmask + // A_time = current time + validity time + else + { + const AssociationTuple &assocTuple = (AssociationTuple){msg.GetOriginatorAddress(),it->address,it->mask,now + msg.GetVTime ()}; + + AddAssociationTuple (assocTuple); + + //Schedule Association Tuple deletion + Simulator::Schedule (DELAY (assocTuple.expirationTime), + &RoutingProtocol::AssociationTupleTimerExpire, this, + assocTuple.gatewayAddr,assocTuple.networkAddr,assocTuple.netmask); + } + + } +} /// /// \brief OLSR's default forwarding algorithm. @@ -1622,6 +1761,52 @@ } /// +/// \brief Creates a new %OLSR HNA message which is buffered for being sent later on. +/// +void +RoutingProtocol::SendHna () +{ + + olsr::MessageHeader msg; + + msg.SetVTime (OLSR_HNA_HOLD_TIME); + msg.SetOriginatorAddress (m_mainAddress); + msg.SetTimeToLive (255); + msg.SetHopCount (0); + msg.SetMessageSequenceNumber (GetMessageSequenceNumber ()); + olsr::MessageHeader::Hna &hna = msg.GetHna (); + + std::vector + &associations = hna.associations; + + // Pack all host-network associations into the packet's associations vector + for (Associations::const_iterator it = m_state.GetAssociations ().begin (); + it != m_state.GetAssociations ().end (); it++) + { + associations.push_back((olsr::MessageHeader::Hna::Association){it->networkAddr,it->netmask}); + } + + if(associations.size () == 0) + return; + + QueueMessage (msg, JITTER); +} + + +/// +/// \brief Injects a (networkAddr, netmask) tuple for which the node +/// can generate an HNA message for +/// +void +RoutingProtocol::AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask) +{ + m_state.InsertAssociation ((Association) {networkAddr, netmask}); +} + +/// + + +/// /// \brief Updates Link Set according to a new received HELLO message (following RFC 3626 /// specification). Neighbor Set is also updated if needed. void @@ -2301,6 +2486,29 @@ 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 () { @@ -2357,6 +2565,17 @@ m_midTimer.Schedule (m_midInterval); } +/// \brief Sends an HNA message (if the node implements support for non-OLSR interfaces). +/// \warning Currently it does nothing because there is no support for mixed interfaces. +/// \param e The event which has expired. +/// +void +RoutingProtocol::HnaTimerExpire () +{ + SendHna (); + m_hnaTimer.Schedule (m_hnaInterval); +} + /// /// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime. /// @@ -2537,6 +2756,30 @@ } } +/// \brief Removes tuple_ if expired. Else timer is rescheduled to expire at tuple_->time(). +/// \warning Actually this is never invoked because there is no support for mixed interfaces. +/// \param e The event which has expired. +/// +void +RoutingProtocol::AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask) +{ + AssociationTuple *tuple = m_state.FindAssociationTuple (gatewayAddr, networkAddr, netmask); + if (tuple == NULL) + { + return; + } + if (tuple->expirationTime < Simulator::Now ()) + { + RemoveAssociationTuple (*tuple); + } + else + { + m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), + &RoutingProtocol::AssociationTupleTimerExpire, + this, gatewayAddr, networkAddr, netmask)); + } +} + /// /// \brief Clears the routing table and frees the memory assigned to each one of its entries. /// @@ -2612,6 +2855,8 @@ NS_LOG_FUNCTION (this << " " << m_ipv4->GetObject ()->GetId() << " " << header.GetDestination () << " " << oif); Ptr rtentry; RoutingTableEntry entry1, entry2; + bool found = false; + if (Lookup (header.GetDestination (), entry1) != 0) { bool foundSendEntry = FindSendEntry (entry1, entry2); @@ -2654,10 +2899,22 @@ NS_LOG_DEBUG ("Olsr node " << m_mainAddress << ": RouteOutput for dest=" << header.GetDestination () << " --> nextHop=" << entry2.nextAddr - << " interface=" << entry2.interface); NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice()); + << " interface=" << entry2.interface); + NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice()); + found = true; } else { + rtentry = HnaRoutingTable.RouteOutput (p, header, oif, sockerr); + + NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice()); + + if (rtentry) + found = true; + } + + if (!found) + { NS_LOG_DEBUG ("Olsr node " << m_mainAddress << ": RouteOutput for dest=" << header.GetDestination () << " No route to host"); @@ -2729,18 +2986,30 @@ } else { + if(HnaRoutingTable.RouteInput (p, header, idev, ucb, mcb, lcb, ecb)) + { + return true; + } + else + { + #ifdef NS3_LOG_ENABLE - NS_LOG_DEBUG ("Olsr node " << m_mainAddress + NS_LOG_DEBUG ("Olsr node " << m_mainAddress << ": RouteInput for dest=" << header.GetDestination () - << " --> NOT FOUND; ** Dumping routing table..."); for (std::map::const_iterator iter = m_table.begin (); - iter != m_table.end (); iter++) - { NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr + << " --> NOT FOUND; ** Dumping routing table..."); + + for (std::map::const_iterator iter = m_table.begin (); + iter != m_table.end (); iter++) + { + NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr << " via interface " << iter->second.interface); + } + + NS_LOG_DEBUG ("** Routing table dump end."); +#endif // NS3_LOG_ENABLE + + return false; } - - NS_LOG_DEBUG ("** Routing table dump end."); -#endif // NS3_LOG_ENABLE - return false; } } void diff -r 20ee319e7e71 src/routing/olsr/olsr-routing-protocol.h --- a/src/routing/olsr/olsr-routing-protocol.h Sun Feb 14 02:06:30 2010 +0300 +++ b/src/routing/olsr/olsr-routing-protocol.h Mon Mar 08 10:56:08 2010 +0530 @@ -38,6 +38,7 @@ #include "ns3/traced-callback.h" #include "ns3/ipv4.h" #include "ns3/ipv4-routing-protocol.h" +#include "ns3/ipv4-static-routing.h" #include #include @@ -105,11 +106,23 @@ **/ std::vector GetRoutingTableEntries () const; +private: + std::set m_interfaceExclusions; + +public: + std::set GetInterfaceExclusions () const + { + return m_interfaceExclusions; + } + void SetInterfaceExclusions (std::set exceptions); + protected: virtual void DoStart (void); private: std::map m_table; ///< Data structure for the routing table. + Ipv4StaticRouting HnaRoutingTable; + EventGarbageCollector m_events; /// Address of the routing agent. @@ -128,6 +141,8 @@ 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; @@ -189,6 +204,9 @@ Timer m_midTimer; void MidTimerExpire (); + Timer m_hnaTimer; + void HnaTimerExpire (); + void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber); bool m_linkTupleTimerFirstTime; void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr); @@ -196,6 +214,7 @@ void MprSelTupleTimerExpire (Ipv4Address mainAddr); void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr); void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr); + void AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask); void IncrementAnsn (); @@ -212,6 +231,7 @@ void SendHello (); void SendTc (); void SendMid (); + void SendHna (); void NeighborLoss (const LinkTuple &tuple); void AddDuplicateTuple (const DuplicateTuple &tuple); @@ -229,6 +249,8 @@ void RemoveTopologyTuple (const TopologyTuple &tuple); void AddIfaceAssocTuple (const IfaceAssocTuple &tuple); void RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple); + void AddAssociationTuple (const AssociationTuple &tuple); + void RemoveAssociationTuple (const AssociationTuple &tuple); void ProcessHello (const olsr::MessageHeader &msg, const Ipv4Address &receiverIface, @@ -237,6 +259,8 @@ const Ipv4Address &senderIface); void ProcessMid (const olsr::MessageHeader &msg, const Ipv4Address &senderIface); + void ProcessHna (const olsr::MessageHeader &msg, + const Ipv4Address &senderIface); void LinkSensing (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello, @@ -250,6 +274,13 @@ const olsr::MessageHeader::Hello &hello); int Degree (NeighborTuple const &tuple); + + /// Inject Association to be sent in HNA message + void AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask); + + /// Inject Associations from an Ipv4StaticRouting instance + void AddRoutingTableAssociation (Ptr); + /// Check that address is one of my interfaces bool IsMyOwnAddress (const Ipv4Address & a) const; diff -r 20ee319e7e71 src/routing/olsr/olsr-state.cc --- a/src/routing/olsr/olsr-state.cc Sun Feb 14 02:06:30 2010 +0300 +++ b/src/routing/olsr/olsr-state.cc Mon Mar 08 10:56:08 2010 +0530 @@ -487,4 +487,60 @@ return retval; } +/********** Host-Network Association Set Manipulation **********/ + +AssociationTuple* +OlsrState::FindAssociationTuple (const Ipv4Address &gatewayAddr, const Ipv4Address &networkAddr, const Ipv4Mask &netmask) +{ + for (AssociationSet::iterator it = m_associationSet.begin (); + it != m_associationSet.end (); it++) + { + if (it->gatewayAddr == gatewayAddr and it->networkAddr == networkAddr and it->netmask == netmask) + { + return &(*it); + } + } + return NULL; +} + +void +OlsrState::EraseAssociationTuple (const AssociationTuple &tuple) +{ + for (AssociationSet::iterator it = m_associationSet.begin (); + it != m_associationSet.end (); it++) + { + if (*it == tuple) + { + m_associationSet.erase (it); + break; + } + } +} + +void +OlsrState::InsertAssociationTuple (const AssociationTuple &tuple) +{ + m_associationSet.push_back (tuple); +} + +void +OlsrState::EraseAssociation (const Association &tuple) +{ + for (Associations::iterator it = m_associations.begin (); + it != m_associations.end (); it++) + { + if (*it == tuple) + { + m_associations.erase (it); + break; + } + } +} + +void +OlsrState::InsertAssociation (const Association &tuple) +{ + m_associations.push_back(tuple); +} + } // namespace ns3 diff -r 20ee319e7e71 src/routing/olsr/olsr-state.h --- a/src/routing/olsr/olsr-state.h Sun Feb 14 02:06:30 2010 +0300 +++ b/src/routing/olsr/olsr-state.h Mon Mar 08 10:56:08 2010 +0530 @@ -45,6 +45,8 @@ 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, section 12.2) + Associations m_associations; ///< The Host Network Associations of the node public: @@ -147,6 +149,25 @@ void EraseIfaceAssocTuple (const IfaceAssocTuple &tuple); void InsertIfaceAssocTuple (const IfaceAssocTuple &tuple); + // Host-Network Association + const AssociationSet & GetAssociationSet () const // Associations known to the node + { + return m_associationSet; + } + + const Associations & GetAssociations () const // Set of associations that the node has + { + return m_associations; + } + + AssociationTuple* FindAssociationTuple (const Ipv4Address &gatewayAddr,\ + const Ipv4Address &networkAddr,\ + const Ipv4Mask &netmask); + void EraseAssociationTuple (const AssociationTuple &tuple); + void InsertAssociationTuple (const AssociationTuple &tuple); + void EraseAssociation (const Association &tuple); + void InsertAssociation (const Association &tuple); + // Returns a vector of all interfaces of a given neighbor, with the // exception of the "main" one. std::vector