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 Tue Feb 16 23:24:19 2010 +0530 @@ -33,6 +33,12 @@ OlsrHelper::OlsrHelper (const OlsrHelper &o) : m_agentFactory (o.m_agentFactory) { + std::map< Ptr, std::set >::const_iterator i; + + for (i = o.m_interfaceExclusions.begin (); i != o.m_interfaceExclusions.end (); i++) + { + m_interfaceExclusions.insert (std::make_pair (i->first, std::set (i->second) )); + } } OlsrHelper* @@ -41,10 +47,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 Tue Feb 16 23:24:19 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-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 Tue Feb 16 23:24:19 2010 +0530 @@ -251,6 +251,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 +271,11 @@ NS_ASSERT (GetMainAddress (addr) == m_mainAddress); } + const std::set ifaceExclusions = GetInterfaceExclusions(); + + if(ifaceExclusions.find(i) != ifaceExclusions.end ()) + continue; + // Create a socket to listen only on this interface Ptr socket = Socket::CreateSocket (GetObject (), UdpSocketFactory::GetTypeId()); @@ -279,13 +286,18 @@ } 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 (); - 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 +305,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. 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 Tue Feb 16 23:24:19 2010 +0530 @@ -105,6 +105,16 @@ **/ std::vector GetRoutingTableEntries () const; +private: + std::set m_interfaceExclusions; + +public: + std::set GetInterfaceExclusions () + { + return m_interfaceExclusions; + } + void SetInterfaceExclusions (std::set exceptions); + protected: virtual void DoStart (void); private: