diff --git a/bindings/python/apidefs/gcc-ILP32/ns3_module_common.py b/bindings/python/apidefs/gcc-ILP32/ns3_module_common.py index 8b1da8399..30d61ac1f 100644 --- a/bindings/python/apidefs/gcc-ILP32/ns3_module_common.py +++ b/bindings/python/apidefs/gcc-ILP32/ns3_module_common.py @@ -2033,6 +2033,11 @@ def register_Ns3NixVector_methods(root_module, cls): 'uint32_t', [param('uint32_t', 'numberOfNeighbors')], is_const=True) + ## nix-vector.h: ns3::Ptr ns3::NixVector::Copy() const [member function] + cls.add_method('Copy', + 'ns3::Ptr< ns3::NixVector >', + [], + is_const=True) ## nix-vector.h: uint32_t ns3::NixVector::Deserialize(uint32_t const * buffer, uint32_t size) [member function] cls.add_method('Deserialize', 'uint32_t', diff --git a/bindings/python/apidefs/gcc-LP64/ns3_module_common.py b/bindings/python/apidefs/gcc-LP64/ns3_module_common.py index 8b1da8399..30d61ac1f 100644 --- a/bindings/python/apidefs/gcc-LP64/ns3_module_common.py +++ b/bindings/python/apidefs/gcc-LP64/ns3_module_common.py @@ -2033,6 +2033,11 @@ def register_Ns3NixVector_methods(root_module, cls): 'uint32_t', [param('uint32_t', 'numberOfNeighbors')], is_const=True) + ## nix-vector.h: ns3::Ptr ns3::NixVector::Copy() const [member function] + cls.add_method('Copy', + 'ns3::Ptr< ns3::NixVector >', + [], + is_const=True) ## nix-vector.h: uint32_t ns3::NixVector::Deserialize(uint32_t const * buffer, uint32_t size) [member function] cls.add_method('Deserialize', 'uint32_t', diff --git a/src/common/nix-vector.cc b/src/common/nix-vector.cc index 4cac8976b..20936ff15 100644 --- a/src/common/nix-vector.cc +++ b/src/common/nix-vector.cc @@ -65,6 +65,15 @@ NixVector::operator = (const NixVector &o) return *this; } +Ptr +NixVector::Copy (void) const +{ + // we need to invoke the copy constructor directly + // rather than calling Create because the copy constructor + // is private. + return Ptr (new NixVector (*this), false); +} + std::ostream & operator << (std::ostream &os, const NixVector &nix) { nix.DumpNixVector (os); diff --git a/src/common/nix-vector.h b/src/common/nix-vector.h index bdea091e8..fd41fefa7 100644 --- a/src/common/nix-vector.h +++ b/src/common/nix-vector.h @@ -21,6 +21,7 @@ #ifndef __NIX_VECTOR_H__ #define __NIX_VECTOR_H__ +#include "ns3/ptr.h" #include "ns3/simple-ref-count.h" #include "ns3/buffer.h" @@ -64,6 +65,7 @@ class NixVector : public SimpleRefCount public: NixVector (); ~NixVector (); + Ptr Copy (void) const; NixVector (const NixVector &o); NixVector &operator = (const NixVector &o); /** diff --git a/src/common/packet.cc b/src/common/packet.cc index b506f3e88..bfe715b4e 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -148,7 +148,7 @@ Packet::Packet (const Packet &o) m_packetTagList (o.m_packetTagList), m_metadata (o.m_metadata) { - o.m_nixVector ? m_nixVector = o.m_nixVector + o.m_nixVector ? m_nixVector = o.m_nixVector->Copy () : m_nixVector = 0; } @@ -163,7 +163,7 @@ Packet::operator = (const Packet &o) m_byteTagList = o.m_byteTagList; m_packetTagList = o.m_packetTagList; m_metadata = o.m_metadata; - o.m_nixVector ? m_nixVector = o.m_nixVector + o.m_nixVector ? m_nixVector = o.m_nixVector->Copy () : m_nixVector = 0; return *this; } diff --git a/src/routing/nix-vector-routing/ipv4-nix-vector-routing.cc b/src/routing/nix-vector-routing/ipv4-nix-vector-routing.cc index 698c92d81..c60988e3a 100644 --- a/src/routing/nix-vector-routing/ipv4-nix-vector-routing.cc +++ b/src/routing/nix-vector-routing/ipv4-nix-vector-routing.cc @@ -510,7 +510,7 @@ Ipv4NixVectorRouting::RouteOutput (Ptr p, const Ipv4Header &header, Ptr< // create a new nix vector to be used, // we want to keep the cached version clean nixVectorForPacket = Create (); - nixVectorForPacket = nixVectorInCache; + nixVectorForPacket = nixVectorInCache->Copy (); // Get the interface number that we go out of, by extracting // from the nix-vector