Fix memory management of routing helpers (bug 678)
This commit is contained in:
@@ -179,15 +179,17 @@ std::string InternetStackHelper::m_pcapBaseFilename;
|
||||
bool InternetStackHelper::m_isInitialized = false;
|
||||
|
||||
InternetStackHelper::InternetStackHelper ()
|
||||
: m_ipv4Enabled (true),
|
||||
: m_routing (0),
|
||||
m_routingv6 (0),
|
||||
m_ipv4Enabled (true),
|
||||
m_ipv6Enabled (true)
|
||||
{
|
||||
SetTcp ("ns3::TcpL4Protocol");
|
||||
static Ipv4StaticRoutingHelper staticRouting;
|
||||
static Ipv4GlobalRoutingHelper globalRouting;
|
||||
static Ipv4ListRoutingHelper listRouting;
|
||||
static Ipv6ListRoutingHelper listRoutingv6;
|
||||
static Ipv6StaticRoutingHelper staticRoutingv6;
|
||||
Ipv4StaticRoutingHelper staticRouting;
|
||||
Ipv4GlobalRoutingHelper globalRouting;
|
||||
Ipv4ListRoutingHelper listRouting;
|
||||
Ipv6ListRoutingHelper listRoutingv6;
|
||||
Ipv6StaticRoutingHelper staticRoutingv6;
|
||||
if (m_isInitialized == false)
|
||||
{
|
||||
// Only add these once
|
||||
@@ -203,16 +205,24 @@ InternetStackHelper::InternetStackHelper ()
|
||||
SetRoutingHelper (listRoutingv6);
|
||||
}
|
||||
|
||||
InternetStackHelper::~InternetStackHelper ()
|
||||
{
|
||||
delete m_routing;
|
||||
delete m_routingv6;
|
||||
}
|
||||
|
||||
void
|
||||
InternetStackHelper::SetRoutingHelper (const Ipv4RoutingHelper &routing)
|
||||
{
|
||||
m_routing = &routing;
|
||||
delete m_routing;
|
||||
m_routing = routing.Copy ();
|
||||
}
|
||||
|
||||
void
|
||||
InternetStackHelper::SetRoutingHelper (const Ipv6RoutingHelper &routing)
|
||||
{
|
||||
m_routingv6 = &routing;
|
||||
delete m_routingv6;
|
||||
m_routingv6 = routing.Copy ();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -53,6 +53,7 @@ public:
|
||||
* such as ns3::OlsrHelper
|
||||
*/
|
||||
InternetStackHelper(void);
|
||||
virtual ~InternetStackHelper(void);
|
||||
|
||||
/**
|
||||
* \param routing a new routing helper
|
||||
|
||||
@@ -29,6 +29,17 @@ namespace ns3 {
|
||||
|
||||
Ipv4GlobalRoutingHelper::Ipv4GlobalRoutingHelper ()
|
||||
{}
|
||||
|
||||
Ipv4GlobalRoutingHelper::Ipv4GlobalRoutingHelper (const Ipv4GlobalRoutingHelper &o)
|
||||
{
|
||||
}
|
||||
|
||||
Ipv4GlobalRoutingHelper*
|
||||
Ipv4GlobalRoutingHelper::Copy (void) const
|
||||
{
|
||||
return new Ipv4GlobalRoutingHelper (*this);
|
||||
}
|
||||
|
||||
Ptr<Ipv4RoutingProtocol>
|
||||
Ipv4GlobalRoutingHelper::Create (Ptr<Node> node) const
|
||||
{
|
||||
|
||||
@@ -32,6 +32,15 @@ class Ipv4GlobalRoutingHelper : public Ipv4RoutingHelper
|
||||
{
|
||||
public:
|
||||
Ipv4GlobalRoutingHelper ();
|
||||
Ipv4GlobalRoutingHelper (const Ipv4GlobalRoutingHelper &);
|
||||
/**
|
||||
* \returns pointer to clone of this Ipv4GlobalRoutingHelper
|
||||
*
|
||||
* This method is mainly for internal use by the other helpers;
|
||||
* clients are expected to free the dynamic memory allocated by this method
|
||||
*/
|
||||
Ipv4GlobalRoutingHelper* Copy (void) const;
|
||||
|
||||
/**
|
||||
* \param node the node on which the routing protocol will run
|
||||
* \returns a newly-created routing protocol
|
||||
@@ -63,6 +72,8 @@ public:
|
||||
*
|
||||
*/
|
||||
static void RecomputeRoutingTables (void);
|
||||
private:
|
||||
Ipv4GlobalRoutingHelper &operator = (const Ipv4GlobalRoutingHelper &o);
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -25,16 +25,42 @@ namespace ns3 {
|
||||
|
||||
Ipv4ListRoutingHelper::Ipv4ListRoutingHelper()
|
||||
{}
|
||||
|
||||
Ipv4ListRoutingHelper::~Ipv4ListRoutingHelper()
|
||||
{
|
||||
for (std::list<std::pair<const Ipv4RoutingHelper *, int16_t> >::iterator i = m_list.begin ();
|
||||
i != m_list.end (); ++i)
|
||||
{
|
||||
delete i->first;
|
||||
}
|
||||
}
|
||||
|
||||
Ipv4ListRoutingHelper::Ipv4ListRoutingHelper (const Ipv4ListRoutingHelper &o)
|
||||
{
|
||||
std::list<std::pair<const Ipv4RoutingHelper *, int16_t> >::const_iterator i;
|
||||
for (i = o.m_list.begin (); i != o.m_list.end (); ++i)
|
||||
{
|
||||
m_list.push_back (std::make_pair (const_cast<const Ipv4RoutingHelper *> (i->first->Copy ()), i->second));
|
||||
}
|
||||
}
|
||||
|
||||
Ipv4ListRoutingHelper*
|
||||
Ipv4ListRoutingHelper::Copy (void) const
|
||||
{
|
||||
return new Ipv4ListRoutingHelper (*this);
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4ListRoutingHelper::Add (const Ipv4RoutingHelper &routing, int16_t priority)
|
||||
{
|
||||
m_list.push_back (std::make_pair(&routing,priority));
|
||||
m_list.push_back (std::make_pair (const_cast<const Ipv4RoutingHelper *> (routing.Copy ()), priority));
|
||||
}
|
||||
|
||||
Ptr<Ipv4RoutingProtocol>
|
||||
Ipv4ListRoutingHelper::Create (Ptr<Node> node) const
|
||||
{
|
||||
Ptr<Ipv4ListRouting> list = CreateObject<Ipv4ListRouting> ();
|
||||
for (std::list<std::pair<const Ipv4RoutingHelper *,int16_t> >::const_iterator i = m_list.begin ();
|
||||
for (std::list<std::pair<const Ipv4RoutingHelper *, int16_t> >::const_iterator i = m_list.begin ();
|
||||
i != m_list.end (); ++i)
|
||||
{
|
||||
Ptr<Ipv4RoutingProtocol> prot = i->first->Create (node);
|
||||
|
||||
@@ -35,7 +35,17 @@ namespace ns3 {
|
||||
class Ipv4ListRoutingHelper : public Ipv4RoutingHelper
|
||||
{
|
||||
public:
|
||||
Ipv4ListRoutingHelper();
|
||||
Ipv4ListRoutingHelper ();
|
||||
virtual ~Ipv4ListRoutingHelper ();
|
||||
Ipv4ListRoutingHelper (const Ipv4ListRoutingHelper &);
|
||||
/**
|
||||
* \returns pointer to clone of this Ipv4ListRoutingHelper
|
||||
*
|
||||
* This method is mainly for internal use by the other helpers;
|
||||
* clients are expected to free the dynamic memory allocated by this method
|
||||
*/
|
||||
Ipv4ListRoutingHelper* Copy (void) const;
|
||||
|
||||
/**
|
||||
* \param routing a routing helper
|
||||
* \param priority the priority of the associated helper
|
||||
@@ -55,6 +65,8 @@ public:
|
||||
*/
|
||||
virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const;
|
||||
private:
|
||||
Ipv4ListRoutingHelper &operator = (const Ipv4ListRoutingHelper &o);
|
||||
|
||||
std::list<std::pair<const Ipv4RoutingHelper *,int16_t> > m_list;
|
||||
};
|
||||
|
||||
|
||||
@@ -28,6 +28,17 @@ Ipv4NixVectorHelper::Ipv4NixVectorHelper ()
|
||||
m_agentFactory.SetTypeId ("ns3::Ipv4NixVectorRouting");
|
||||
}
|
||||
|
||||
Ipv4NixVectorHelper::Ipv4NixVectorHelper (const Ipv4NixVectorHelper &o)
|
||||
: m_agentFactory (o.m_agentFactory)
|
||||
{
|
||||
}
|
||||
|
||||
Ipv4NixVectorHelper*
|
||||
Ipv4NixVectorHelper::Copy (void) const
|
||||
{
|
||||
return new Ipv4NixVectorHelper (*this);
|
||||
}
|
||||
|
||||
Ptr<Ipv4RoutingProtocol>
|
||||
Ipv4NixVectorHelper::Create (Ptr<Node> node) const
|
||||
{
|
||||
|
||||
@@ -38,6 +38,14 @@ class Ipv4NixVectorHelper : public Ipv4RoutingHelper
|
||||
{
|
||||
public:
|
||||
Ipv4NixVectorHelper ();
|
||||
Ipv4NixVectorHelper (const Ipv4NixVectorHelper &);
|
||||
/**
|
||||
* \returns pointer to clone of this Ipv4NixVectorHelper
|
||||
*
|
||||
* This method is mainly for internal use by the other helpers;
|
||||
* clients are expected to free the dynamic memory allocated by this method
|
||||
*/
|
||||
Ipv4NixVectorHelper* Copy (void) const;
|
||||
|
||||
/**
|
||||
* \param node the node on which the routing protocol will run
|
||||
@@ -48,6 +56,8 @@ public:
|
||||
virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const;
|
||||
|
||||
private:
|
||||
Ipv4NixVectorHelper &operator = (const Ipv4NixVectorHelper &o);
|
||||
|
||||
ObjectFactory m_agentFactory;
|
||||
};
|
||||
} // namespace ns3
|
||||
|
||||
@@ -40,6 +40,16 @@ class Ipv4RoutingHelper
|
||||
{
|
||||
public:
|
||||
virtual ~Ipv4RoutingHelper ();
|
||||
|
||||
/**
|
||||
* \brief virtual constructor
|
||||
* \returns pointer to clone of this Ipv4RoutingHelper
|
||||
*
|
||||
* This method is mainly for internal use by the other helpers;
|
||||
* clients are expected to free the dynamic memory allocated by this method
|
||||
*/
|
||||
virtual Ipv4RoutingHelper* Copy (void) const = 0;
|
||||
|
||||
/**
|
||||
* \param node the node within which the new routing protocol will run
|
||||
* \returns a newly-created routing protocol
|
||||
|
||||
@@ -35,6 +35,17 @@ namespace ns3 {
|
||||
|
||||
Ipv4StaticRoutingHelper::Ipv4StaticRoutingHelper()
|
||||
{}
|
||||
|
||||
Ipv4StaticRoutingHelper::Ipv4StaticRoutingHelper (const Ipv4StaticRoutingHelper &o)
|
||||
{
|
||||
}
|
||||
|
||||
Ipv4StaticRoutingHelper*
|
||||
Ipv4StaticRoutingHelper::Copy (void) const
|
||||
{
|
||||
return new Ipv4StaticRoutingHelper (*this);
|
||||
}
|
||||
|
||||
Ptr<Ipv4RoutingProtocol>
|
||||
Ipv4StaticRoutingHelper::Create (Ptr<Node> node) const
|
||||
{
|
||||
|
||||
@@ -40,7 +40,15 @@ namespace ns3 {
|
||||
class Ipv4StaticRoutingHelper : public Ipv4RoutingHelper
|
||||
{
|
||||
public:
|
||||
Ipv4StaticRoutingHelper();
|
||||
Ipv4StaticRoutingHelper ();
|
||||
Ipv4StaticRoutingHelper (const Ipv4StaticRoutingHelper &);
|
||||
/**
|
||||
* \returns pointer to clone of this Ipv4StaticRoutingHelper
|
||||
*
|
||||
* This method is mainly for internal use by the other helpers;
|
||||
* clients are expected to free the dynamic memory allocated by this method
|
||||
*/
|
||||
Ipv4StaticRoutingHelper* Copy (void) const;
|
||||
|
||||
/**
|
||||
* \param node the node on which the routing protocol will run
|
||||
@@ -74,6 +82,8 @@ public:
|
||||
void SetDefaultMulticastRoute (Ptr<Node> n, std::string ndName);
|
||||
void SetDefaultMulticastRoute (std::string nName, Ptr<NetDevice> nd);
|
||||
void SetDefaultMulticastRoute (std::string nName, std::string ndName);
|
||||
private:
|
||||
Ipv4StaticRoutingHelper &operator = (const Ipv4StaticRoutingHelper &o);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -27,10 +27,34 @@ namespace ns3 {
|
||||
|
||||
Ipv6ListRoutingHelper::Ipv6ListRoutingHelper ()
|
||||
{}
|
||||
|
||||
Ipv6ListRoutingHelper::~Ipv6ListRoutingHelper()
|
||||
{
|
||||
for (std::list<std::pair<const Ipv6RoutingHelper *, int16_t> >::iterator i = m_list.begin ();
|
||||
i != m_list.end (); ++i)
|
||||
{
|
||||
delete i->first;
|
||||
}
|
||||
}
|
||||
Ipv6ListRoutingHelper::Ipv6ListRoutingHelper (const Ipv6ListRoutingHelper &o)
|
||||
{
|
||||
std::list<std::pair<const Ipv6RoutingHelper *, int16_t> >::const_iterator i;
|
||||
for (i = o.m_list.begin (); i != o.m_list.end (); ++i)
|
||||
{
|
||||
m_list.push_back (std::make_pair (const_cast<const Ipv6RoutingHelper *> (i->first->Copy ()), i->second));
|
||||
}
|
||||
}
|
||||
|
||||
Ipv6ListRoutingHelper*
|
||||
Ipv6ListRoutingHelper::Copy (void) const
|
||||
{
|
||||
return new Ipv6ListRoutingHelper (*this);
|
||||
}
|
||||
|
||||
void
|
||||
Ipv6ListRoutingHelper::Add (const Ipv6RoutingHelper &routing, int16_t priority)
|
||||
{
|
||||
m_list.push_back (std::make_pair (&routing,priority));
|
||||
m_list.push_back (std::make_pair (const_cast<const Ipv6RoutingHelper *> (routing.Copy ()), priority));
|
||||
}
|
||||
Ptr<Ipv6RoutingProtocol>
|
||||
Ipv6ListRoutingHelper::Create (Ptr<Node> node) const
|
||||
|
||||
@@ -38,6 +38,16 @@ class Ipv6ListRoutingHelper : public Ipv6RoutingHelper
|
||||
{
|
||||
public:
|
||||
Ipv6ListRoutingHelper ();
|
||||
virtual ~Ipv6ListRoutingHelper ();
|
||||
Ipv6ListRoutingHelper (const Ipv6ListRoutingHelper &);
|
||||
/**
|
||||
* \returns pointer to clone of this Ipv6ListRoutingHelper
|
||||
*
|
||||
* This method is mainly for internal use by the other helpers;
|
||||
* clients are expected to free the dynamic memory allocated by this method
|
||||
*/
|
||||
Ipv6ListRoutingHelper* Copy (void) const;
|
||||
|
||||
/**
|
||||
* \param routing a routing helper
|
||||
* \param priority the priority of the associated helper
|
||||
@@ -57,6 +67,8 @@ public:
|
||||
*/
|
||||
virtual Ptr<Ipv6RoutingProtocol> Create (Ptr<Node> node) const;
|
||||
private:
|
||||
Ipv6ListRoutingHelper &operator = (const Ipv6ListRoutingHelper &o);
|
||||
|
||||
std::list<std::pair<const Ipv6RoutingHelper *,int16_t> > m_list;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,16 @@ class Ipv6RoutingHelper
|
||||
{
|
||||
public:
|
||||
virtual ~Ipv6RoutingHelper ();
|
||||
|
||||
/**
|
||||
* \brief virtual constructor
|
||||
* \returns pointer to clone of this Ipv6RoutingHelper
|
||||
*
|
||||
* This method is mainly for internal use by the other helpers;
|
||||
* clients are expected to free the dynamic memory allocated by this method
|
||||
*/
|
||||
virtual Ipv6RoutingHelper* Copy (void) const = 0;
|
||||
|
||||
/**
|
||||
* \param node the node within which the new routing protocol will run
|
||||
* \returns a newly-created routing protocol
|
||||
|
||||
@@ -37,6 +37,17 @@ namespace ns3 {
|
||||
|
||||
Ipv6StaticRoutingHelper::Ipv6StaticRoutingHelper ()
|
||||
{}
|
||||
|
||||
Ipv6StaticRoutingHelper::Ipv6StaticRoutingHelper (const Ipv6StaticRoutingHelper &o)
|
||||
{
|
||||
}
|
||||
|
||||
Ipv6StaticRoutingHelper*
|
||||
Ipv6StaticRoutingHelper::Copy (void) const
|
||||
{
|
||||
return new Ipv6StaticRoutingHelper (*this);
|
||||
}
|
||||
|
||||
Ptr<Ipv6RoutingProtocol>
|
||||
Ipv6StaticRoutingHelper::Create (Ptr<Node> node) const
|
||||
{
|
||||
|
||||
@@ -45,6 +45,14 @@ public:
|
||||
* \brief Constructor.
|
||||
*/
|
||||
Ipv6StaticRoutingHelper ();
|
||||
Ipv6StaticRoutingHelper (const Ipv6StaticRoutingHelper &);
|
||||
/**
|
||||
* \returns pointer to clone of this Ipv6StaticRoutingHelper
|
||||
*
|
||||
* This method is mainly for internal use by the other helpers;
|
||||
* clients are expected to free the dynamic memory allocated by this method
|
||||
*/
|
||||
Ipv6StaticRoutingHelper* Copy (void) const;
|
||||
|
||||
/**
|
||||
* \param node the node on which the routing protocol will run
|
||||
@@ -80,6 +88,8 @@ public:
|
||||
void SetDefaultMulticastRoute (std::string nName, Ptr<NetDevice> nd);
|
||||
void SetDefaultMulticastRoute (std::string nName, std::string ndName);
|
||||
#endif
|
||||
private:
|
||||
Ipv6StaticRoutingHelper &operator = (const Ipv6StaticRoutingHelper &o);
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -30,6 +30,17 @@ OlsrHelper::OlsrHelper ()
|
||||
m_agentFactory.SetTypeId ("ns3::olsr::RoutingProtocol");
|
||||
}
|
||||
|
||||
OlsrHelper::OlsrHelper (const OlsrHelper &o)
|
||||
: m_agentFactory (o.m_agentFactory)
|
||||
{
|
||||
}
|
||||
|
||||
OlsrHelper*
|
||||
OlsrHelper::Copy (void) const
|
||||
{
|
||||
return new OlsrHelper (*this);
|
||||
}
|
||||
|
||||
Ptr<Ipv4RoutingProtocol>
|
||||
OlsrHelper::Create (Ptr<Node> node) const
|
||||
{
|
||||
|
||||
@@ -37,6 +37,14 @@ class OlsrHelper : public Ipv4RoutingHelper
|
||||
{
|
||||
public:
|
||||
OlsrHelper ();
|
||||
OlsrHelper (const OlsrHelper &);
|
||||
/**
|
||||
* \returns pointer to clone of this OlsrHelper
|
||||
*
|
||||
* This method is mainly for internal use by the other helpers;
|
||||
* clients are expected to free the dynamic memory allocated by this method
|
||||
*/
|
||||
OlsrHelper* Copy (void) const;
|
||||
|
||||
/**
|
||||
* \param node the node on which the routing protocol will run
|
||||
@@ -54,6 +62,7 @@ public:
|
||||
*/
|
||||
void Set (std::string name, const AttributeValue &value);
|
||||
private:
|
||||
OlsrHelper &operator = (const OlsrHelper &o);
|
||||
ObjectFactory m_agentFactory;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user