diff --git a/src/helper/internet-stack-helper.cc b/src/helper/internet-stack-helper.cc index 23ee1a5d8..212e34109 100644 --- a/src/helper/internet-stack-helper.cc +++ b/src/helper/internet-stack-helper.cc @@ -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 diff --git a/src/helper/internet-stack-helper.h b/src/helper/internet-stack-helper.h index ff96d22d2..5c8bc32e6 100644 --- a/src/helper/internet-stack-helper.h +++ b/src/helper/internet-stack-helper.h @@ -53,6 +53,7 @@ public: * such as ns3::OlsrHelper */ InternetStackHelper(void); + virtual ~InternetStackHelper(void); /** * \param routing a new routing helper diff --git a/src/helper/ipv4-global-routing-helper.cc b/src/helper/ipv4-global-routing-helper.cc index 11e2398d6..db491a953 100644 --- a/src/helper/ipv4-global-routing-helper.cc +++ b/src/helper/ipv4-global-routing-helper.cc @@ -29,6 +29,17 @@ namespace ns3 { Ipv4GlobalRoutingHelper::Ipv4GlobalRoutingHelper () {} + +Ipv4GlobalRoutingHelper::Ipv4GlobalRoutingHelper (const Ipv4GlobalRoutingHelper &o) +{ +} + +Ipv4GlobalRoutingHelper* +Ipv4GlobalRoutingHelper::Copy (void) const +{ + return new Ipv4GlobalRoutingHelper (*this); +} + Ptr Ipv4GlobalRoutingHelper::Create (Ptr node) const { diff --git a/src/helper/ipv4-global-routing-helper.h b/src/helper/ipv4-global-routing-helper.h index dadbd242a..2e685af03 100644 --- a/src/helper/ipv4-global-routing-helper.h +++ b/src/helper/ipv4-global-routing-helper.h @@ -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 diff --git a/src/helper/ipv4-list-routing-helper.cc b/src/helper/ipv4-list-routing-helper.cc index 5115bc2f3..71b2f351c 100644 --- a/src/helper/ipv4-list-routing-helper.cc +++ b/src/helper/ipv4-list-routing-helper.cc @@ -25,16 +25,42 @@ namespace ns3 { 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::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); diff --git a/src/helper/ipv4-list-routing-helper.h b/src/helper/ipv4-list-routing-helper.h index ef34068c7..5e6372936 100644 --- a/src/helper/ipv4-list-routing-helper.h +++ b/src/helper/ipv4-list-routing-helper.h @@ -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 Create (Ptr node) const; private: + Ipv4ListRoutingHelper &operator = (const Ipv4ListRoutingHelper &o); + std::list > m_list; }; diff --git a/src/helper/ipv4-nix-vector-helper.cc b/src/helper/ipv4-nix-vector-helper.cc index 3ac2d1eda..5d02e0e17 100644 --- a/src/helper/ipv4-nix-vector-helper.cc +++ b/src/helper/ipv4-nix-vector-helper.cc @@ -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 Ipv4NixVectorHelper::Create (Ptr node) const { diff --git a/src/helper/ipv4-nix-vector-helper.h b/src/helper/ipv4-nix-vector-helper.h index c524cb03f..24f0ad8b9 100644 --- a/src/helper/ipv4-nix-vector-helper.h +++ b/src/helper/ipv4-nix-vector-helper.h @@ -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 Create (Ptr node) const; private: + Ipv4NixVectorHelper &operator = (const Ipv4NixVectorHelper &o); + ObjectFactory m_agentFactory; }; } // namespace ns3 diff --git a/src/helper/ipv4-routing-helper.h b/src/helper/ipv4-routing-helper.h index 9c8a28233..ed686f826 100644 --- a/src/helper/ipv4-routing-helper.h +++ b/src/helper/ipv4-routing-helper.h @@ -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 diff --git a/src/helper/ipv4-static-routing-helper.cc b/src/helper/ipv4-static-routing-helper.cc index 6f05b0890..e5daf5e7f 100644 --- a/src/helper/ipv4-static-routing-helper.cc +++ b/src/helper/ipv4-static-routing-helper.cc @@ -35,6 +35,17 @@ namespace ns3 { Ipv4StaticRoutingHelper::Ipv4StaticRoutingHelper() {} + +Ipv4StaticRoutingHelper::Ipv4StaticRoutingHelper (const Ipv4StaticRoutingHelper &o) +{ +} + +Ipv4StaticRoutingHelper* +Ipv4StaticRoutingHelper::Copy (void) const +{ + return new Ipv4StaticRoutingHelper (*this); +} + Ptr Ipv4StaticRoutingHelper::Create (Ptr node) const { diff --git a/src/helper/ipv4-static-routing-helper.h b/src/helper/ipv4-static-routing-helper.h index 06907eff6..adc7952cb 100644 --- a/src/helper/ipv4-static-routing-helper.h +++ b/src/helper/ipv4-static-routing-helper.h @@ -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 n, std::string ndName); void SetDefaultMulticastRoute (std::string nName, Ptr nd); void SetDefaultMulticastRoute (std::string nName, std::string ndName); +private: + Ipv4StaticRoutingHelper &operator = (const Ipv4StaticRoutingHelper &o); }; diff --git a/src/helper/ipv6-list-routing-helper.cc b/src/helper/ipv6-list-routing-helper.cc index 006b63954..8479bfcac 100644 --- a/src/helper/ipv6-list-routing-helper.cc +++ b/src/helper/ipv6-list-routing-helper.cc @@ -27,10 +27,34 @@ namespace ns3 { 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::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 diff --git a/src/helper/ipv6-list-routing-helper.h b/src/helper/ipv6-list-routing-helper.h index 81fd725eb..945f78e11 100644 --- a/src/helper/ipv6-list-routing-helper.h +++ b/src/helper/ipv6-list-routing-helper.h @@ -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 Create (Ptr node) const; private: + Ipv6ListRoutingHelper &operator = (const Ipv6ListRoutingHelper &o); + std::list > m_list; }; diff --git a/src/helper/ipv6-routing-helper.h b/src/helper/ipv6-routing-helper.h index 8da0abce4..ac3536871 100644 --- a/src/helper/ipv6-routing-helper.h +++ b/src/helper/ipv6-routing-helper.h @@ -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 diff --git a/src/helper/ipv6-static-routing-helper.cc b/src/helper/ipv6-static-routing-helper.cc index 793e2b993..f155fa55d 100644 --- a/src/helper/ipv6-static-routing-helper.cc +++ b/src/helper/ipv6-static-routing-helper.cc @@ -37,6 +37,17 @@ namespace ns3 { Ipv6StaticRoutingHelper::Ipv6StaticRoutingHelper () {} + +Ipv6StaticRoutingHelper::Ipv6StaticRoutingHelper (const Ipv6StaticRoutingHelper &o) +{ +} + +Ipv6StaticRoutingHelper* +Ipv6StaticRoutingHelper::Copy (void) const +{ + return new Ipv6StaticRoutingHelper (*this); +} + Ptr Ipv6StaticRoutingHelper::Create (Ptr node) const { diff --git a/src/helper/ipv6-static-routing-helper.h b/src/helper/ipv6-static-routing-helper.h index 700dc86dd..92cecde79 100644 --- a/src/helper/ipv6-static-routing-helper.h +++ b/src/helper/ipv6-static-routing-helper.h @@ -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 nd); void SetDefaultMulticastRoute (std::string nName, std::string ndName); #endif +private: + Ipv6StaticRoutingHelper &operator = (const Ipv6StaticRoutingHelper &o); }; } // namespace ns3 diff --git a/src/helper/olsr-helper.cc b/src/helper/olsr-helper.cc index eb464afac..5ad1479a9 100644 --- a/src/helper/olsr-helper.cc +++ b/src/helper/olsr-helper.cc @@ -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 OlsrHelper::Create (Ptr node) const { diff --git a/src/helper/olsr-helper.h b/src/helper/olsr-helper.h index 7a40044d7..4baedd199 100644 --- a/src/helper/olsr-helper.h +++ b/src/helper/olsr-helper.h @@ -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; };