convert to new tag API.
--- a/samples/main-packet-tag.cc Thu Apr 24 15:44:15 2008 -0700
+++ b/samples/main-packet-tag.cc Thu Apr 24 15:44:35 2008 -0700
@@ -17,32 +17,22 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
-#include "ns3/tag.h"
+#include "ns3/mtag.h"
#include "ns3/packet.h"
+#include "ns3/uinteger.h"
#include <iostream>
using namespace ns3;
// define this class in a public header
-class MyTag : public Tag
+class MyTag : public Mtag
{
public:
- // we have to define a public constructor
- MyTag ();
- // we have to define a public copy constructor
- MyTag (const MyTag &other);
- // we have to define a public destructor
- ~MyTag ();
- // we have to define a public static GetUid method
- static uint32_t GetUid (void);
- // we have to define a public Print method
- void Print (std::ostream &os) const;
- // we have to define a public GetSerializedSize method
- uint32_t GetSerializedSize (void) const;
- // we have to define a public Serialize method
- void Serialize (Buffer::Iterator i) const;
- // we have to define a public Deserialize method
- uint32_t Deserialize (Buffer::Iterator i);
+ static TypeId GetTypeId (void);
+ virtual TypeId GetInstanceTypeId (void) const;
+ virtual uint32_t GetSerializedSize (void) const;
+ virtual void Serialize (MtagBuffer i) const;
+ virtual void Deserialize (MtagBuffer i);
// these are our accessors to our tag structure
void SetSimpleValue (uint8_t value);
@@ -51,52 +41,40 @@
uint8_t m_simpleValue;
};
-MyTag::MyTag ()
-{}
-MyTag::MyTag (const MyTag &other)
- : m_simpleValue (other.m_simpleValue)
-{}
-MyTag::~MyTag ()
-{}
-uint32_t
-MyTag::GetUid (void)
+TypeId
+MyTag::GetTypeId (void)
{
- // we input a unique string to AllocateUid
- // to avoid name collisions.
- static uint32_t uid = AllocateUid<MyTag> ("MyTag.tests.nsnam.org");
- return uid;
+ static TypeId tid = TypeId ("ns3::MyTag")
+ .SetParent<Mtag> ()
+ .AddConstructor<MyTag> ()
+ .AddAttribute ("SimpleValue",
+ "A simple value",
+ EmptyAttributeValue (),
+ MakeUintegerAccessor (&MyTag::GetSimpleValue),
+ MakeUintegerChecker<uint8_t> ())
+ ;
+ return tid;
}
-void
-MyTag::Print (std::ostream &os) const
+TypeId
+MyTag::GetInstanceTypeId (void) const
{
- // print the content of this tag for Packet::PrintTags
- os << "MyTag=0x" << std::hex << (uint32_t)m_simpleValue << std::dec;
+ return GetTypeId ();
}
uint32_t
MyTag::GetSerializedSize (void) const
{
- // we do not want to deal with parallel simulations
- // so we return 0.
- return 0;
+ return 1;
}
void
-MyTag::Serialize (Buffer::Iterator i) const
-{
- // we will never be invoked because we are not doing
- // parallel simulations so, we assert.
- NS_ASSERT (false);
-}
-uint32_t
-MyTag::Deserialize (Buffer::Iterator i)
+MyTag::Serialize (MtagBuffer i) const
{
- // we will never be invoked because we are not doing
- // parallel simulations so, we assert.
- NS_ASSERT (false);
- // theoretically, return the number of bytes read
- return 0;
+ i.WriteU8 (m_simpleValue);
}
-
-
+void
+MyTag::Deserialize (MtagBuffer i)
+{
+ m_simpleValue = i.ReadU8 ();
+}
void
MyTag::SetSimpleValue (uint8_t value)
{
@@ -117,14 +95,14 @@
// store the tag in a packet.
Ptr<Packet> p = Create<Packet> ();
- p->AddTag (tag);
+ p->AddMtag (tag);
// create a copy of the packet
Ptr<Packet> aCopy = p->Copy ();
// read the tag from the packet copy
MyTag tagCopy;
- p->PeekTag (tagCopy);
+ p->FindFirstMatchingTag (tagCopy);
// the copy and the original are the same !
NS_ASSERT (tagCopy.GetSimpleValue () == tag.GetSimpleValue ());
--- a/src/contrib/delay-jitter-estimation.cc Thu Apr 24 15:44:15 2008 -0700
+++ b/src/contrib/delay-jitter-estimation.cc Thu Apr 24 15:44:35 2008 -0700
@@ -1,19 +1,22 @@
#include "delay-jitter-estimation.h"
-#include "ns3/tag.h"
+#include "ns3/mtag.h"
#include "ns3/simulator.h"
+#include "ns3/string.h"
namespace {
-class TimestampTag : public ns3::Tag
+class TimestampTag : public ns3::Mtag
{
public:
TimestampTag ();
- static uint32_t GetUid (void);
- void Print (std::ostream &os) const;
- void Serialize (ns3::Buffer::Iterator start) const;
- uint32_t Deserialize (ns3::Buffer::Iterator start);
- uint32_t GetSerializedSize (void) const;
+ static ns3::TypeId GetTypeId (void);
+ virtual ns3::TypeId GetInstanceTypeId (void) const;
+
+ virtual uint32_t GetSerializedSize (void) const;
+ virtual void Serialize (ns3::MtagBuffer i) const;
+ virtual void Deserialize (ns3::MtagBuffer i);
+
ns3::Time GetTxTime (void) const;
private:
@@ -23,29 +26,41 @@
TimestampTag::TimestampTag ()
: m_creationTime (ns3::Simulator::Now ().GetTimeStep ())
{}
-uint32_t
-TimestampTag::GetUid (void)
-{
- static uint32_t uid = ns3::Tag::AllocateUid<TimestampTag> ("mathieu.paper.TimestampTag");
- return uid;
-}
-void
-TimestampTag::Print (std::ostream &os) const
+
+ns3::TypeId
+TimestampTag::GetTypeId (void)
{
- os << ns3::TimeStep (m_creationTime);
+ static ns3::TypeId tid = ns3::TypeId ("anon::TimestampTag")
+ .SetParent<Mtag> ()
+ .AddConstructor<TimestampTag> ()
+ .AddAttribute ("CreationTime",
+ "The time at which the timestamp was created",
+ ns3::StringValue ("0.0s"),
+ ns3::MakeTimeAccessor (&TimestampTag::GetTxTime),
+ ns3::MakeTimeChecker ())
+ ;
+ return tid;
}
-void
-TimestampTag::Serialize (ns3::Buffer::Iterator start) const
-{}
-uint32_t
-TimestampTag::Deserialize (ns3::Buffer::Iterator start)
+ns3::TypeId
+TimestampTag::GetInstanceTypeId (void) const
{
- return 0;
+ return GetTypeId ();
}
+
uint32_t
TimestampTag::GetSerializedSize (void) const
{
- return 0;
+ return 8;
+}
+void
+TimestampTag::Serialize (ns3::MtagBuffer i) const
+{
+ i.WriteU64 (m_creationTime);
+}
+void
+TimestampTag::Deserialize (ns3::MtagBuffer i)
+{
+ m_creationTime = i.ReadU64 ();
}
ns3::Time
TimestampTag::GetTxTime (void) const
@@ -67,14 +82,14 @@
DelayJitterEstimation::PrepareTx (Ptr<const Packet> packet)
{
TimestampTag tag;
- packet->AddTag (tag);
+ packet->AddMtag (tag);
}
void
DelayJitterEstimation::RecordRx (Ptr<const Packet> packet)
{
TimestampTag tag;
bool found;
- found = packet->PeekTag (tag);
+ found = packet->FindFirstMatchingTag (tag);
if (!found)
{
return;
--- a/src/devices/wifi/mac-low.cc Thu Apr 24 15:44:15 2008 -0700
+++ b/src/devices/wifi/mac-low.cc Thu Apr 24 15:44:35 2008 -0700
@@ -21,7 +21,7 @@
#include "ns3/assert.h"
#include "ns3/packet.h"
#include "ns3/simulator.h"
-#include "ns3/tag.h"
+#include "ns3/mtag.h"
#include "ns3/log.h"
#include "ns3/node.h"
@@ -37,17 +37,16 @@
namespace ns3 {
-class SnrTag : public Tag
+class SnrTag : public Mtag
{
public:
- SnrTag ();
- SnrTag (const SnrTag &o);
- ~SnrTag ();
- static uint32_t GetUid (void);
- void Print (std::ostream &os) const;
- uint32_t GetSerializedSize (void) const;
- void Serialize (Buffer::Iterator i) const;
- uint32_t Deserialize (Buffer::Iterator i);
+
+ static TypeId GetTypeId (void);
+ virtual TypeId GetInstanceTypeId (void) const;
+
+ virtual uint32_t GetSerializedSize (void) const;
+ virtual void Serialize (MtagBuffer i) const;
+ virtual void Deserialize (MtagBuffer i);
void Set (double snr);
double Get (void) const;
@@ -55,40 +54,39 @@
double m_snr;
};
-SnrTag::SnrTag ()
- : m_snr (0.0)
-{}
-SnrTag::SnrTag (const SnrTag &o)
- : m_snr (o.m_snr)
-{}
-SnrTag::~SnrTag ()
-{}
-uint32_t
-SnrTag::GetUid (void)
+TypeId
+SnrTag::GetTypeId (void)
{
- static uint32_t uid = AllocateUid<SnrTag> ("SnrTag.ns3.inria.fr");
- return uid;
+ static TypeId tid = TypeId ("ns3::SnrTag")
+ .SetParent<Mtag> ()
+ .AddConstructor<SnrTag> ()
+ .AddAttribute ("Snr", "The snr of the last packet received",
+ DoubleValue (0.0),
+ MakeDoubleAccessor (&SnrTag::Get),
+ MakeDoubleChecker<double> ())
+ ;
+ return tid;
}
-void
-SnrTag::Print (std::ostream &os) const
+TypeId
+SnrTag::GetInstanceTypeId (void) const
{
- os << "snr="<<m_snr;
+ return GetTypeId ();
}
+
uint32_t
SnrTag::GetSerializedSize (void) const
{
- return 0;
+ return sizeof (double);
}
void
-SnrTag::Serialize (Buffer::Iterator i) const
+SnrTag::Serialize (MtagBuffer i) const
{
- // would need to serialize double to platform-independent format.
+ i.WriteDouble (m_snr);
}
-uint32_t
-SnrTag::Deserialize (Buffer::Iterator i)
+void
+SnrTag::Deserialize (MtagBuffer i)
{
- // would need to deserialize double from platform-independent format.
- return 0;
+ m_snr = i.ReadDouble ();
}
void
SnrTag::Set (double snr)
@@ -472,7 +470,7 @@
{
MY_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
SnrTag tag;
- packet->PeekTag (tag);
+ packet->FindFirstMatchingTag (tag);
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
station->ReportRxOk (rxSnr, txMode);
station->ReportRtsOk (rxSnr, txMode, tag.Get ());
@@ -495,7 +493,7 @@
{
MY_DEBUG ("receive ack from="<<m_currentHdr.GetAddr1 ());
SnrTag tag;
- packet->PeekTag (tag);
+ packet->FindFirstMatchingTag (tag);
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
station->ReportRxOk (rxSnr, txMode);
station->ReportDataOk (rxSnr, txMode, tag.Get ());
@@ -1038,7 +1036,7 @@
struct SnrTag tag;
tag.Set (rtsSnr);
- packet->AddTag (tag);
+ packet->AddMtag (tag);
ForwardDown (packet, &cts, ctsTxMode);
}
@@ -1116,7 +1114,7 @@
struct SnrTag tag;
tag.Set (dataSnr);
- packet->AddTag (tag);
+ packet->AddMtag (tag);
ForwardDown (packet, &ack, ackTxMode);
}
--- a/src/devices/wifi/wifi-remote-station-manager.cc Thu Apr 24 15:44:15 2008 -0700
+++ b/src/devices/wifi/wifi-remote-station-manager.cc Thu Apr 24 15:44:35 2008 -0700
@@ -21,7 +21,7 @@
#include "wifi-remote-station-manager.h"
#include "ns3/assert.h"
#include "ns3/log.h"
-#include "ns3/tag.h"
+#include "ns3/mtag.h"
#include "ns3/boolean.h"
#include "ns3/uinteger.h"
#include "ns3/wifi-phy.h"
@@ -306,7 +306,7 @@
namespace ns3 {
-class TxModeTag : public Tag
+class TxModeTag : public Mtag
{
public:
TxModeTag ();
@@ -314,11 +314,11 @@
WifiMode GetRtsMode (void) const;
WifiMode GetDataMode (void) const;
- static uint32_t GetUid (void);
- void Print (std::ostream &os) const;
- void Serialize (ns3::Buffer::Iterator start) const;
- uint32_t Deserialize (ns3::Buffer::Iterator start);
- uint32_t GetSerializedSize (void) const;
+ static TypeId GetTypeId (void);
+ virtual TypeId GetInstanceTypeId (void) const;
+ virtual uint32_t GetSerializedSize (void) const;
+ virtual void Serialize (MtagBuffer i) const;
+ virtual void Deserialize (MtagBuffer i);
private:
WifiMode m_rtsMode;
WifiMode m_dataMode;
@@ -340,30 +340,46 @@
{
return m_dataMode;
}
-
-uint32_t
-TxModeTag::GetUid (void)
-{
- static uint32_t uid = Tag::AllocateUid<TxModeTag> ("ns3.wifi.TxModeTag");
- return uid;
-}
-void
-TxModeTag::Print (std::ostream &os) const
+TypeId
+TxModeTag::GetTypeId (void)
{
- os << "rts="<<m_rtsMode<<" data="<<m_dataMode;
+ static TypeId tid = TypeId ("ns3::TxModeTag")
+ .SetParent<Mtag> ()
+ .AddConstructor<TxModeTag> ()
+ .AddAttribute ("RtsTxMode",
+ "Tx mode of rts to use later",
+ EmptyAttributeValue (),
+ MakeWifiModeAccessor (&TxModeTag::GetRtsMode),
+ MakeWifiModeChecker ())
+ .AddAttribute ("DataTxMode",
+ "Tx mode of data to use later",
+ EmptyAttributeValue (),
+ MakeWifiModeAccessor (&TxModeTag::GetDataMode),
+ MakeWifiModeChecker ())
+ ;
+ return tid;
}
-void
-TxModeTag::Serialize (ns3::Buffer::Iterator start) const
-{}
-uint32_t
-TxModeTag::Deserialize (ns3::Buffer::Iterator start)
+TypeId
+TxModeTag::GetInstanceTypeId (void) const
{
- return 0;
+ return GetTypeId ();
}
uint32_t
TxModeTag::GetSerializedSize (void) const
{
- return 0;
+ return sizeof (WifiMode) * 2;
+}
+void
+TxModeTag::Serialize (MtagBuffer i) const
+{
+ i.Write ((uint8_t *)&m_rtsMode, sizeof (WifiMode));
+ i.Write ((uint8_t *)&m_dataMode, sizeof (WifiMode));
+}
+void
+TxModeTag::Deserialize (MtagBuffer i)
+{
+ i.Read ((uint8_t *)&m_rtsMode, sizeof (WifiMode));
+ i.Read ((uint8_t *)&m_dataMode, sizeof (WifiMode));
}
} // namespace ns3
@@ -535,7 +551,7 @@
return;
}
TxModeTag tag = TxModeTag (DoGetRtsMode (), DoGetDataMode (fullPacketSize));
- packet->AddTag (tag);
+ packet->AddMtag (tag);
}
WifiMode
WifiRemoteStation::GetDataMode (Ptr<const Packet> packet, uint32_t fullPacketSize)
@@ -546,7 +562,7 @@
}
TxModeTag tag;
bool found;
- found = packet->PeekTag (tag);
+ found = packet->FindFirstMatchingTag (tag);
NS_ASSERT (found);
return tag.GetDataMode ();
}
@@ -559,7 +575,7 @@
}
TxModeTag tag;
bool found;
- found = packet->PeekTag (tag);
+ found = packet->FindFirstMatchingTag (tag);
NS_ASSERT (found);
return tag.GetRtsMode ();
}