Tag issues with fragmentation

56 views
Skip to first unread message

Charles Lacaze

unread,
Jul 6, 2015, 12:50:29 PM7/6/15
to ns-3-...@googlegroups.com
Hello,
I am currently trying to tag packets (with my own tags) with the following code :
 
 
class TagTesT : public Tag
{
public:
  /**
   * \brief Get the type ID.
   * \return the object TypeId
   */
  static TypeId GetTypeId (void);
  virtual TypeId GetInstanceTypeId (void) const;
  virtual uint32_t GetSerializedSize (void) const;
  virtual void Serialize (TagBuffer buf) const;
  virtual void Deserialize (TagBuffer buf);
  virtual void Print (std::ostream &os) const;
  TagTesT ();

  TagTesT (uint32_t txNumber);
  void SetTxNumber (uint32_t txNumber);

  uint32_t GetTxNumber (void) const;
private:
  uint32_t m_txNumber;     

};
TypeId
TagTesT::GetTypeId (void)
{
  static TypeId tid = TypeId ("ns3::TagTesT")
    .SetParent<Tag> ()
    .AddConstructor<TagTesT> ()
  ;
  return tid;
}
TypeId
TagTesT::GetInstanceTypeId (void) const
{
  return GetTypeId ();
}
uint32_t
TagTesT::GetSerializedSize (void) const
{
  return 4;
}
void
TagTesT::Serialize (TagBuffer buf) const
{
  buf.WriteU32 (m_txNumber);
}
void
TagTesT::Deserialize (TagBuffer buf)
{
  m_txNumber = buf.ReadU32 ();
}
void
TagTesT::Print (std::ostream &os) const
{
  os << "TxNumber=" << m_txNumber;
}
TagTesT::TagTesT ()
  : Tag (), m_txNumber (0)
{
}
TagTesT::TagTesT (uint32_t txNumber)
  : Tag (), m_txNumber (txNumber)
{
}
void
TagTesT::SetTxNumber (uint32_t id)
{
  m_txNumber = id;
}
uint32_t
TagTesT::GetTxNumber (void) const
{
  return m_txNumber;
}
 
 
 
 
 

int main (int argc, char *argv[])
{
 Packet::EnablePrinting ();
 uint32_t size = 256;
 
 Ptr<Packet> packetUn = Create<Packet>(reinterpret_cast<const uint8_t*> ("u") ,size);
 Ptr<Packet> packetDeux = Create<Packet>(size);
 Ptr<Packet> packetTrois =Create<Packet>(size);
 
 
 TagTesT packetTagUn = TagTesT(1);
 TagTesT packetTagDeux = TagTesT(2);
 TagTesT packetTagTrois = TagTesT(3);
 
 std::cout<<"packetTagUn : "<<packetTagUn.GetTxNumber()<<std::endl;
 std::cout<<"packetTagDeux : "<<packetTagDeux.GetTxNumber()<<std::endl;
 std::cout<<"packetTagTrois : "<<packetTagTrois.GetTxNumber()<<std::endl;
 
 packetUn->AddByteTag(packetTagUn);
 packetDeux->AddByteTag(packetTagDeux);
 packetTrois->AddByteTag(packetTagTrois);
 
 
 packetUn->AddAtEnd(packetDeux);
 packetUn->AddAtEnd(packetTrois);
 
 
 Ptr<Packet> newPacketUn = packetUn->CreateFragment(0,256);
 Ptr<Packet> newPacketDeux = packetUn->CreateFragment(256,256);
 Ptr<Packet> newPacketTrois = packetUn->CreateFragment(512,256);
 
 TagTesT tagUn;
 TagTesT tagDeux;
 TagTesT tagTrois;
 bool foundUn = newPacketUn->FindFirstMatchingByteTag (tagUn);
 bool foundDeux = newPacketDeux->FindFirstMatchingByteTag (tagDeux);
 bool foundTrois = newPacketTrois->FindFirstMatchingByteTag (tagTrois);
 if (foundUn)
  {
   std::cout<<"tagUn : "<<tagUn.GetTxNumber()<<std::endl;
  }
 if (foundDeux)
  {
   std::cout<<"tagDeux : "<<tagDeux.GetTxNumber()<<std::endl;
  }
 if (foundTrois)
  {
   std::cout<<"tagTrois : "<<tagTrois.GetTxNumber()<<std::endl;
  }
 
 
 return 0;
}
 
 
Here is the result :
 
packetTagUn : 1
packetTagDeux : 2
packetTagTrois : 3
tagUn : 1
tagDeux : 2
tagTrois : 2

 
Now if I change the creation of my packets in the main:
 
Ptr<Packet> packetUn = Create<Packet>(reinterpret_cast<const uint8_t*> ("u") ,size);
Ptr<Packet> packetDeux = Create<Packet>(size);
Ptr<Packet> packetTrois =Create<Packet>(size);
 
by :
 
Ptr<Packet> packetUn = Create<Packet>(size);
Ptr<Packet> packetDeux = Create<Packet>(size);
Ptr<Packet> packetTrois =Create<Packet>(size);
 
I obtain :
 
packetTagUn : 1
packetTagDeux : 2
packetTagTrois : 3
tagUn : 1
tagDeux : 1
tagTrois : 1
 
Is it a normal behavior ?

Charles Lacaze

unread,
Jul 9, 2015, 11:34:34 AM7/9/15
to ns-3-...@googlegroups.com
Hello again,
 
I think it is a bug. When we concatenate and fragment packets, the byteTag management seems to fail.
Moreover it is still strange to me that the tag management differs when we define the payload of the packet instead of just the size of the packet.
 
If anybody have any clue...
Thanks for your help.

Tommaso Pecorella

unread,
Jul 9, 2015, 12:46:15 PM7/9/15
to ns-3-...@googlegroups.com
Hi,

it's a bug (sort of). Mind to report it on Bugzilla with a link to this thread and the test program ?

Explanation of the bug (and how to avoid it).
In ns-3 packets are stored by aggressively "forgetting" about zero-filled payloads. The payload is there only as a byte length, unless it's actually filled with something else.
The same happens with packet copy, the original is used until the "new" one is modified (its called COW, Copy On Write).

Now, you did create 3 packets, one with a payload, the other two with just a size. Once joined, the 3 packets generated a small "real" payload (for the first fragment) and two large chunks of zeroes (optimized).
Once you add tags, they **should** be marked and added to the right places, and they are. But once you split the packet again something bad happens: the 3rd one is not copied in the right place.

The workaround is simple: add a payload to all the fragments. Even a random byte will do. Check the attached program.

Hope this helps,

T.
tagTest.cc

Charles Lacaze

unread,
Jul 10, 2015, 3:49:01 AM7/10/15
to ns-3-...@googlegroups.com
 Thanks for the quick and detailed answer. It's helping !
I am going to report it on Bugzilla.
Reply all
Reply to author
Forward
0 new messages