Bug 2155 - Packets created with no precised payload generate errors in their tags.
Packets created with no precised payload generate errors in their tags.
Status: NEW
Product: ns-3
Classification: Unclassified
Component: general
ns-3.21
PC Linux
: P5 normal
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2015-07-10 05:20 EDT by Charles
Modified: 2015-07-10 05:20 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Charles 2015-07-10 05:20:11 EDT
/*We want to create packets, tag them, concatenate them and finally fragment the big packet we obtain in the first packets with their tags.
The thing is the tags change whether we create the packets with or
without precising their payload.*/


//Here is the declaration of the tag classe (an ordinary tag) :

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;      

};


//Here the implementation of the classe : 

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;
}


//Now we create the packets precising their payload :

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>(reinterpret_cast<const uint8_t*> ("d") ,size);
 Ptr<Packet> packetTrois =Create<Packet>(reinterpret_cast<const uint8_t*> ("t") ,size);
 

// we tag the packets
 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);
 

// we concatenate the three packets in one :
 packetUn->AddAtEnd(packetDeux);
 packetUn->AddAtEnd(packetTrois);
 

/* we fragment the "big" packet in three packets in order to take back the first three packets*/
 Ptr<Packet> newPacketUn = packetUn->CreateFragment(0,256);
 Ptr<Packet> newPacketDeux = packetUn->CreateFragment(256,256);
 Ptr<Packet> newPacketTrois = packetUn->CreateFragment(512,256);
 
// we print the tags found in the new packets:
 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 are the results :

packetTagUn : 1
packetTagDeux : 2
packetTagTrois : 3
tagUn : 1
tagDeux : 2
tagTrois : 3


/*They seems normal, the tags have been attached to their packets well and they are the same after fragmentation.
Now if we create the packets WITHOUT precising their payload : */

int main (int argc, char *argv[])
{
 Packet::EnablePrinting ();

 uint32_t size = 256;

 
 Ptr<Packet> packetUn = Create<Packet>(size);
 Ptr<Packet> packetDeux = Create<Packet>(size);
 Ptr<Packet> packetTrois =Create<Packet>(size);
 

// Then we do the same thing as before:
// we tag the packets
 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);
 

// we concatenate the three packets in one :
 packetUn->AddAtEnd(packetDeux);
 packetUn->AddAtEnd(packetTrois);
 

/* we fragment the "big" packet in three packets in order to take back the first three packets*/
 Ptr<Packet> newPacketUn = packetUn->CreateFragment(0,256);
 Ptr<Packet> newPacketDeux = packetUn->CreateFragment(256,256);
 Ptr<Packet> newPacketTrois = packetUn->CreateFragment(512,256);
 
// we print the tags found in the new packets:
 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 are the new results :

packetTagUn : 1
packetTagDeux : 2
packetTagTrois : 3
tagUn : 1
tagDeux : 1
tagTrois : 1


/* We are expecting here to have the same results as before, the payload of the packet should not have an effect on its tag.

Build 10 July 2015 on Linux 2.6.32
*/