Bug 2569

Summary: ns3::Address serialization does not update ns3::TagBuffer
Product: ns-3 Reporter: William R. Dieter <william.r.dieter>
Component: networkAssignee: ns-bugs <ns-bugs>
Status: PATCH PENDING ---    
Severity: normal CC: tomh
Priority: P3    
Version: ns-3.26   
Hardware: All   
OS: All   
Attachments: Pass ns3::TagBuffer to ns3::Address::Serialize by reference
Cleaned up patch
re-updated patch

Description William R. Dieter 2016-12-06 13:32:01 EST
Created attachment 2691 [details]
Pass ns3::TagBuffer to ns3::Address::Serialize by reference

The `buffer` parameter to `ns3::Address::Serialize(TagBuffer buffer)` and `ns3::Address::Deserialize(TagBuffer buffer)` is passed by value rather than reference.  As a result, when the `Serialize` method calls ns3::TagBuffer::WriteU8 and ns3::TagBuffer::Write the data pointed to by `buffer` is updated and local copy of `buffer` in Address::Serialize is updated, but not the caller's copy of the `buffer` object.  That is, the `TagBuffer::m_current` does not get updated for the caller.

If the `ns3::Address` is the last thing serialized into the `ns3::TagBuffer`, then Serialize seems to work, because the data did get written into the buffer.  For example, if I do

    Address addr;
    // ... set addr to something
    TagBuffer tag;
    
    addr.Serialize(tag);

And then deserialize on the other end, I seem to get the write Address.  However, if I do 

    Address addr;
    // ... set addr to something
    TagBuffer tag;
    
    addr.Serialize(tag);
    tag.WriteU32(1234);

The part of the address is overwritten by `1234`.

Changing the signature of `ns3::Address::Serialize` and `ns3::Address::Deserialize` to pass by reference fixes the problem for me (see attached patch).  I am not sure if any other code is depending on this bug.  It looks like `ns3::Ipv4FlowProbeTag::Serialize` and `ns3::Ipv4FlowProbeTag::Deserialize`are working around this problem by writing to a temporary buffer then writing the temporary buffer into the tag.
Comment 1 William R. Dieter 2016-12-06 13:35:30 EST
Created attachment 2692 [details]
Cleaned up patch

Previous patch accidentally deleted a comment.
Comment 2 William R. Dieter 2016-12-06 13:37:08 EST
Created attachment 2693 [details]
re-updated patch

Generated a new patch, then uploaded the old file in the last attachment.  This one should be correct.