--- a/src/helper/internet-stack-helper.cc Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/internet-stack-helper.cc Wed Sep 30 22:46:38 2009 -0700 @@ -179,15 +179,17 @@ 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 @@ 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 --- a/src/helper/internet-stack-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/internet-stack-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -53,6 +53,7 @@ * such as ns3::OlsrHelper */ InternetStackHelper(void); + virtual ~InternetStackHelper(void); /** * \param routing a new routing helper --- a/src/helper/ipv4-global-routing-helper.cc Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv4-global-routing-helper.cc Wed Sep 30 22:46:38 2009 -0700 @@ -29,6 +29,23 @@ Ipv4GlobalRoutingHelper::Ipv4GlobalRoutingHelper () {} + +Ipv4GlobalRoutingHelper::Ipv4GlobalRoutingHelper (const Ipv4GlobalRoutingHelper &o) +{ +} + +Ipv4GlobalRoutingHelper & +Ipv4GlobalRoutingHelper::operator = (const Ipv4GlobalRoutingHelper &o) +{ + return *this; +} + +Ipv4GlobalRoutingHelper* +Ipv4GlobalRoutingHelper::Copy (void) const +{ + return new Ipv4GlobalRoutingHelper (*this); +} + Ptr Ipv4GlobalRoutingHelper::Create (Ptr node) const { --- a/src/helper/ipv4-global-routing-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv4-global-routing-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -32,6 +32,16 @@ { public: Ipv4GlobalRoutingHelper (); + Ipv4GlobalRoutingHelper (const Ipv4GlobalRoutingHelper &); + Ipv4GlobalRoutingHelper &operator = (const Ipv4GlobalRoutingHelper &o); + /** + * \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 --- a/src/helper/ipv4-list-routing-helper.cc Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv4-list-routing-helper.cc Wed Sep 30 22:46:38 2009 -0700 @@ -25,16 +25,57 @@ Ipv4ListRoutingHelper::Ipv4ListRoutingHelper() {} + +Ipv4ListRoutingHelper::~Ipv4ListRoutingHelper() +{ + for (std::list >::iterator i = m_list.begin (); + i != m_list.end (); ++i) + { + delete i->first; + } +} + +Ipv4ListRoutingHelper::Ipv4ListRoutingHelper (const Ipv4ListRoutingHelper &o) +{ + std::list >::const_iterator i; + for (i = o.m_list.begin (); i != o.m_list.end (); ++i) + { + m_list.push_back (std::make_pair (const_cast (i->first->Copy ()), i->second)); + } +} + +Ipv4ListRoutingHelper & +Ipv4ListRoutingHelper::operator = (const Ipv4ListRoutingHelper &o) +{ + if (this == &o) + { + return *this; + } + std::list >::const_iterator i; + for (i = o.m_list.begin (); i != o.m_list.end (); ++i) + { + m_list.push_back (std::make_pair (const_cast (i->first->Copy ()), i->second)); + } + return *this; +} + +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 (routing.Copy ()), priority)); } + Ptr Ipv4ListRoutingHelper::Create (Ptr node) const { Ptr list = CreateObject (); - for (std::list >::const_iterator i = m_list.begin (); + for (std::list >::const_iterator i = m_list.begin (); i != m_list.end (); ++i) { Ptr prot = i->first->Create (node); --- a/src/helper/ipv4-list-routing-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv4-list-routing-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -35,7 +35,18 @@ class Ipv4ListRoutingHelper : public Ipv4RoutingHelper { public: - Ipv4ListRoutingHelper(); + Ipv4ListRoutingHelper (); + virtual ~Ipv4ListRoutingHelper (); + Ipv4ListRoutingHelper (const Ipv4ListRoutingHelper &); + Ipv4ListRoutingHelper &operator = (const Ipv4ListRoutingHelper &o); + /** + * \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 --- a/src/helper/ipv4-nix-vector-helper.cc Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv4-nix-vector-helper.cc Wed Sep 30 22:46:38 2009 -0700 @@ -28,6 +28,28 @@ m_agentFactory.SetTypeId ("ns3::Ipv4NixVectorRouting"); } +Ipv4NixVectorHelper::Ipv4NixVectorHelper (const Ipv4NixVectorHelper &o) + : m_agentFactory (o.m_agentFactory) +{ +} + +Ipv4NixVectorHelper & +Ipv4NixVectorHelper::operator = (const Ipv4NixVectorHelper &o) +{ + if (this == &o) + { + return *this; + } + m_agentFactory = o.m_agentFactory; + return *this; +} + +Ipv4NixVectorHelper* +Ipv4NixVectorHelper::Copy (void) const +{ + return new Ipv4NixVectorHelper (*this); +} + Ptr Ipv4NixVectorHelper::Create (Ptr node) const { --- a/src/helper/ipv4-nix-vector-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv4-nix-vector-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -38,6 +38,15 @@ { public: Ipv4NixVectorHelper (); + Ipv4NixVectorHelper (const Ipv4NixVectorHelper &); + Ipv4NixVectorHelper &operator = (const Ipv4NixVectorHelper &o); + /** + * \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 --- a/src/helper/ipv4-routing-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv4-routing-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -40,6 +40,16 @@ { 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 --- a/src/helper/ipv4-static-routing-helper.cc Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv4-static-routing-helper.cc Wed Sep 30 22:46:38 2009 -0700 @@ -35,6 +35,23 @@ Ipv4StaticRoutingHelper::Ipv4StaticRoutingHelper() {} + +Ipv4StaticRoutingHelper::Ipv4StaticRoutingHelper (const Ipv4StaticRoutingHelper &o) +{ +} + +Ipv4StaticRoutingHelper & +Ipv4StaticRoutingHelper::operator = (const Ipv4StaticRoutingHelper &o) +{ + return *this; +} + +Ipv4StaticRoutingHelper* +Ipv4StaticRoutingHelper::Copy (void) const +{ + return new Ipv4StaticRoutingHelper (*this); +} + Ptr Ipv4StaticRoutingHelper::Create (Ptr node) const { --- a/src/helper/ipv4-static-routing-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv4-static-routing-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -40,7 +40,16 @@ class Ipv4StaticRoutingHelper : public Ipv4RoutingHelper { public: - Ipv4StaticRoutingHelper(); + Ipv4StaticRoutingHelper (); + Ipv4StaticRoutingHelper (const Ipv4StaticRoutingHelper &); + Ipv4StaticRoutingHelper &operator = (const Ipv4StaticRoutingHelper &o); + /** + * \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 --- a/src/helper/ipv6-list-routing-helper.cc Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv6-list-routing-helper.cc Wed Sep 30 22:46:38 2009 -0700 @@ -27,10 +27,49 @@ Ipv6ListRoutingHelper::Ipv6ListRoutingHelper () {} + +Ipv6ListRoutingHelper::~Ipv6ListRoutingHelper() +{ + for (std::list >::iterator i = m_list.begin (); + i != m_list.end (); ++i) + { + delete i->first; + } +} +Ipv6ListRoutingHelper::Ipv6ListRoutingHelper (const Ipv6ListRoutingHelper &o) +{ + std::list >::const_iterator i; + for (i = o.m_list.begin (); i != o.m_list.end (); ++i) + { + m_list.push_back (std::make_pair (const_cast (i->first->Copy ()), i->second)); + } +} + +Ipv6ListRoutingHelper & +Ipv6ListRoutingHelper::operator = (const Ipv6ListRoutingHelper &o) +{ + if (this == &o) + { + return *this; + } + std::list >::const_iterator i; + for (i = o.m_list.begin (); i != o.m_list.end (); ++i) + { + m_list.push_back (std::make_pair (const_cast (i->first->Copy ()), i->second)); + } + return *this; +} + +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 (routing.Copy ()), priority)); } Ptr Ipv6ListRoutingHelper::Create (Ptr node) const --- a/src/helper/ipv6-list-routing-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv6-list-routing-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -38,6 +38,17 @@ { public: Ipv6ListRoutingHelper (); + virtual ~Ipv6ListRoutingHelper (); + Ipv6ListRoutingHelper (const Ipv6ListRoutingHelper &); + Ipv6ListRoutingHelper &operator = (const Ipv6ListRoutingHelper &o); + /** + * \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 --- a/src/helper/ipv6-routing-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv6-routing-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -41,6 +41,16 @@ { 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 --- a/src/helper/ipv6-static-routing-helper.cc Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv6-static-routing-helper.cc Wed Sep 30 22:46:38 2009 -0700 @@ -37,6 +37,23 @@ Ipv6StaticRoutingHelper::Ipv6StaticRoutingHelper () {} + +Ipv6StaticRoutingHelper::Ipv6StaticRoutingHelper (const Ipv6StaticRoutingHelper &o) +{ +} + +Ipv6StaticRoutingHelper & +Ipv6StaticRoutingHelper::operator = (const Ipv6StaticRoutingHelper &o) +{ + return *this; +} + +Ipv6StaticRoutingHelper* +Ipv6StaticRoutingHelper::Copy (void) const +{ + return new Ipv6StaticRoutingHelper (*this); +} + Ptr Ipv6StaticRoutingHelper::Create (Ptr node) const { --- a/src/helper/ipv6-static-routing-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/ipv6-static-routing-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -45,6 +45,15 @@ * \brief Constructor. */ Ipv6StaticRoutingHelper (); + Ipv6StaticRoutingHelper (const Ipv6StaticRoutingHelper &); + Ipv6StaticRoutingHelper &operator = (const Ipv6StaticRoutingHelper &o); + /** + * \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 --- a/src/helper/olsr-helper.cc Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/olsr-helper.cc Wed Sep 30 22:46:38 2009 -0700 @@ -30,6 +30,28 @@ m_agentFactory.SetTypeId ("ns3::olsr::RoutingProtocol"); } +OlsrHelper::OlsrHelper (const OlsrHelper &o) + : m_agentFactory (o.m_agentFactory) +{ +} + +OlsrHelper & +OlsrHelper::operator = (const OlsrHelper &o) +{ + if (this == &o) + { + return *this; + } + m_agentFactory = o.m_agentFactory; + return *this; +} + +OlsrHelper* +OlsrHelper::Copy (void) const +{ + return new OlsrHelper (*this); +} + Ptr OlsrHelper::Create (Ptr node) const { --- a/src/helper/olsr-helper.h Wed Sep 30 16:16:14 2009 +0100 +++ a/src/helper/olsr-helper.h Wed Sep 30 22:46:38 2009 -0700 @@ -37,6 +37,15 @@ { public: OlsrHelper (); + OlsrHelper (const OlsrHelper &); + OlsrHelper &operator = (const OlsrHelper &o); + /** + * \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