convert CsmaNetDevice to Attributes.
--- a/examples/csma-packet-socket.cc Wed Feb 27 19:51:34 2008 +0100
+++ b/examples/csma-packet-socket.cc Wed Feb 27 20:23:57 2008 +0100
@@ -61,8 +61,9 @@
static Ptr<CsmaNetDevice>
CreateCsmaDevice (Ptr<Node> node, Ptr<CsmaChannel> channel)
{
- Ptr<CsmaNetDevice> device = CreateObject<CsmaNetDevice> (node, Mac48Address::Allocate (),
- CsmaNetDevice::LLC);
+ Ptr<CsmaNetDevice> device = CreateObjectWith<CsmaNetDevice> ("Node", node,
+ "Address", Mac48Address::Allocate (),
+ "EncapsulationMode", "Llc");
node->AddDevice (device);
device->Attach (channel);
Ptr<Queue> queue = Queue::CreateDefault ();
--- a/src/devices/csma/csma-ipv4-topology.cc Wed Feb 27 19:51:34 2008 +0100
+++ b/src/devices/csma/csma-ipv4-topology.cc Wed Feb 27 20:23:57 2008 +0100
@@ -42,8 +42,9 @@
Ptr<Queue> q = Queue::CreateDefault ();
// assume full-duplex
- Ptr<CsmaNetDevice> nd = CreateObject<CsmaNetDevice> (node, addr,
- ns3::CsmaNetDevice::IP_ARP);
+ Ptr<CsmaNetDevice> nd = CreateObjectWith<CsmaNetDevice> ("Node", node,
+ "Address", addr,
+ "EncapsulationMode", "IpArp");
node->AddDevice (nd);
nd->AddQueue(q);
@@ -59,16 +60,18 @@
{
Ptr<Queue> q = Queue::CreateDefault ();
- Ptr<CsmaNetDevice> nd0 = CreateObject<CsmaNetDevice> (n1, addr,
- ns3::CsmaNetDevice::LLC);
+ Ptr<CsmaNetDevice> nd0 = CreateObjectWith<CsmaNetDevice> ("Node", n1,
+ "Address", addr,
+ "EncapsulationMode", "Llc");
n1->AddDevice (nd0);
nd0->SetSendEnable (true);
nd0->SetReceiveEnable (false);
nd0->AddQueue(q);
nd0->Attach (ch);
- Ptr<CsmaNetDevice> nd1 = CreateObject<CsmaNetDevice> (n1, addr,
- ns3::CsmaNetDevice::LLC);
+ Ptr<CsmaNetDevice> nd1 = CreateObjectWith<CsmaNetDevice> ("Node", n1,
+ "Address", addr,
+ "EncapsulationMode", "Llc");
n1->AddDevice (nd1);
nd1->SetSendEnable (false);
nd1->SetReceiveEnable (true);
@@ -83,16 +86,18 @@
{
Ptr<Queue> q = Queue::CreateDefault ();
- Ptr<CsmaNetDevice> nd0 = CreateObject<CsmaNetDevice> (n1, addr,
- ns3::CsmaNetDevice::RAW);
+ Ptr<CsmaNetDevice> nd0 = CreateObjectWith<CsmaNetDevice> ("Node", n1,
+ "Address", addr,
+ "EncapsulationMode", "Raw");
n1->AddDevice (nd0);
nd0->SetSendEnable (true);
nd0->SetReceiveEnable (false);
nd0->AddQueue(q);
nd0->Attach (ch);
- Ptr<CsmaNetDevice> nd1 = CreateObject<CsmaNetDevice> (n1, addr,
- ns3::CsmaNetDevice::RAW);
+ Ptr<CsmaNetDevice> nd1 = CreateObjectWith<CsmaNetDevice> ("Node", n1,
+ "Address", addr,
+ "EncapsulationMode", "Raw");
n1->AddDevice (nd1);
nd1->SetSendEnable (false);
nd1->SetReceiveEnable (true);
--- a/src/devices/csma/csma-net-device.cc Wed Feb 27 19:51:34 2008 +0100
+++ b/src/devices/csma/csma-net-device.cc Wed Feb 27 20:23:57 2008 +0100
@@ -22,80 +22,81 @@
#include "ns3/log.h"
#include "ns3/queue.h"
#include "ns3/simulator.h"
-#include "ns3/composite-trace-resolver.h"
-#include "csma-net-device.h"
-#include "csma-channel.h"
#include "ns3/ethernet-header.h"
#include "ns3/ethernet-trailer.h"
#include "ns3/llc-snap-header.h"
#include "ns3/error-model.h"
+#include "ns3/enum.h"
+#include "ns3/boolean.h"
+#include "ns3/trace-source-accessor.h"
+#include "csma-net-device.h"
+#include "csma-channel.h"
+
NS_LOG_COMPONENT_DEFINE ("CsmaNetDevice");
namespace ns3 {
-CsmaTraceType::CsmaTraceType (enum Type type)
- : m_type (type)
-{
- NS_LOG_FUNCTION;
-}
-
-CsmaTraceType::CsmaTraceType ()
- : m_type (RX)
+TypeId
+CsmaNetDevice::GetTypeId (void)
{
- NS_LOG_FUNCTION;
-}
-
-void
-CsmaTraceType::Print (std::ostream &os) const
-{
- switch (m_type) {
- case RX:
- os << "dev-rx";
- break;
- case DROP:
- os << "dev-drop";
- break;
- }
+ static TypeId tid = TypeId ("CsmaNetDevice")
+ .SetParent<NetDevice> ()
+ .AddConstructor<CsmaNetDevice> ()
+ .AddAttribute ("Node", "The node with which this device is associated",
+ TypeId::ATTR_GET | TypeId::ATTR_CONSTRUCT,
+ Ptr<Node> (0),
+ MakePtrAccessor (&CsmaNetDevice::m_node),
+ MakePtrChecker<Node> ())
+ .AddAttribute ("Address", "The address of this device.",
+ Mac48Address ("ff:ff:ff:ff:ff:ff"),
+ MakeMac48AddressAccessor (&CsmaNetDevice::m_address),
+ MakeMac48AddressChecker ())
+ .AddAttribute ("EncapsulationMode", "The mode of link-layer encapsulation to use.",
+ Enum (LLC),
+ MakeEnumAccessor (&CsmaNetDevice::m_encapMode),
+ MakeEnumChecker (ETHERNET_V1, "EthernetV1",
+ IP_ARP, "IpArp",
+ RAW, "Raw",
+ LLC, "Llc"))
+ .AddAttribute ("SendEnable", "should tx be enabled ?",
+ Boolean (true),
+ MakeBooleanAccessor (&CsmaNetDevice::m_sendEnable),
+ MakeBooleanChecker ())
+ .AddAttribute ("ReceiveEnable", "should rx be enabled ?",
+ Boolean (true),
+ MakeBooleanAccessor (&CsmaNetDevice::m_receiveEnable),
+ MakeBooleanChecker ())
+ .AddAttribute ("DataRate", "XXX",
+ DataRate (0xffffffff),
+ MakeDataRateAccessor (&CsmaNetDevice::m_bps),
+ MakeDataRateChecker ())
+ .AddAttribute ("RxErrorModel", "XXX",
+ Ptr<ErrorModel> (0),
+ MakePtrAccessor (&CsmaNetDevice::m_receiveErrorModel),
+ MakePtrChecker<ErrorModel> ())
+ .AddAttribute ("TxQueue", "XXX",
+ Ptr<Queue> (0),
+ MakePtrAccessor (&CsmaNetDevice::m_queue),
+ MakePtrChecker<Queue> ())
+ .AddTraceSource ("Rx", "Receive MAC packet.",
+ MakeTraceSourceAccessor (&CsmaNetDevice::m_rxTrace))
+ .AddTraceSource ("Drop", "Drop MAC packet.",
+ MakeTraceSourceAccessor (&CsmaNetDevice::m_dropTrace))
+ ;
+ return tid;
}
-uint16_t
-CsmaTraceType::GetUid (void)
-{
- NS_LOG_FUNCTION;
- static uint16_t uid = AllocateUid<CsmaTraceType> ("CsmaTraceType");
- return uid;
-}
-
-std::string
-CsmaTraceType::GetTypeName (void) const
-{
- NS_LOG_FUNCTION;
- return "ns3::CsmaTraceType";
-}
-
-enum CsmaTraceType::Type
-CsmaTraceType::Get (void) const
-{
- NS_LOG_FUNCTION;
- return m_type;
-}
-
-CsmaNetDevice::CsmaNetDevice (Ptr<Node> node, Mac48Address addr,
- CsmaEncapsulationMode encapMode)
- : m_bps (DataRate (0xffffffff)),
- m_receiveErrorModel (0),
- m_node (node),
- m_address (addr),
- m_name (""),
+CsmaNetDevice::CsmaNetDevice ()
+ : m_name (""),
m_linkUp (false),
m_mtu (0xffff)
{
NS_LOG_FUNCTION;
- NS_LOG_PARAMS (this << node);
- m_encapMode = encapMode;
-
- Init(true, true);
+ NS_LOG_PARAMS (this);
+ m_txMachineState = READY;
+ m_tInterframeGap = Seconds(0);
+ m_channel = 0;
}
CsmaNetDevice::~CsmaNetDevice()
@@ -113,19 +114,6 @@
NetDevice::DoDispose ();
}
-void
-CsmaNetDevice::Init(bool sendEnable, bool receiveEnable)
-{
- NS_LOG_FUNCTION;
- m_txMachineState = READY;
- m_tInterframeGap = Seconds(0);
- m_channel = 0;
- m_queue = 0;
-
- SetSendEnable (sendEnable);
- SetReceiveEnable (receiveEnable);
-}
-
void
CsmaNetDevice::SetSendEnable (bool sendEnable)
{
@@ -394,26 +382,6 @@
}
}
-Ptr<TraceResolver>
-CsmaNetDevice::GetTraceResolver (void) const
-{
- NS_LOG_FUNCTION;
- Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
- resolver->AddComposite ("queue", m_queue);
- resolver->AddSource ("rx",
- TraceDoc ("receive MAC packet",
- "Ptr<const Packet>", "packet received"),
- m_rxTrace,
- CsmaTraceType (CsmaTraceType::RX));
- resolver->AddSource ("drop",
- TraceDoc ("drop MAC packet",
- "Ptr<const Packet>", "packet dropped"),
- m_dropTrace,
- CsmaTraceType (CsmaTraceType::DROP));
- resolver->SetParentResolver (NetDevice::GetTraceResolver ());
- return resolver;
-}
-
bool
CsmaNetDevice::Attach (Ptr<CsmaChannel> ch)
{
@@ -448,7 +416,6 @@
NS_LOG_PARAM ("(" << em << ")");
m_receiveErrorModel = em;
- AggregateObject (em);
}
void
--- a/src/devices/csma/csma-net-device.h Wed Feb 27 19:51:34 2008 +0100
+++ b/src/devices/csma/csma-net-device.h Wed Feb 27 20:23:57 2008 +0100
@@ -29,7 +29,7 @@
#include "ns3/net-device.h"
#include "ns3/callback.h"
#include "ns3/packet.h"
-#include "ns3/callback-trace-source.h"
+#include "ns3/traced-callback.h"
#include "ns3/nstime.h"
#include "ns3/data-rate.h"
#include "ns3/ptr.h"
@@ -43,29 +43,6 @@
class ErrorModel;
/**
- * \brief hold in a TraceContext the type of trace source from a CsmaNetDevice
- */
-class CsmaTraceType : public TraceContextElement
-{
-public:
- enum Type {
- RX,
- DROP
- };
- CsmaTraceType (enum Type type);
- CsmaTraceType ();
- void Print (std::ostream &os) const;
- static uint16_t GetUid (void);
- std::string GetTypeName (void) const;
- /**
- * \returns the type of the trace source which generated an event.
- */
- enum Type Get (void) const;
-private:
- enum Type m_type;
-};
-
-/**
* \class CsmaNetDevice
* \brief A Device for a Csma Network Link.
*
@@ -84,9 +61,10 @@
* devices
*
*/
-class CsmaNetDevice : public NetDevice {
+class CsmaNetDevice : public NetDevice
+{
public:
-
+ static TypeId GetTypeId (void);
/**
* Enumeration of the types of packets supported in the class.
*
@@ -105,11 +83,8 @@
* parameter the Node to which this device is connected. Ownership of the
* Node pointer is not implied and the node must not be deleted.
*
- * \param node the Node to which this device is connected.
- * \param addr The source MAC address of the net device.
- * \param pktType the type of encapsulation
*/
- CsmaNetDevice (Ptr<Node> node, Mac48Address addr, CsmaEncapsulationMode pktType);
+ CsmaNetDevice ();
/**
* Destroy a CsmaNetDevice
@@ -252,12 +227,6 @@
protected:
virtual void DoDispose (void);
- /**
- * Create a Trace Resolver for events in the net device.
- * (NOT TESTED)
- * @see class TraceResolver
- */
- virtual Ptr<TraceResolver> GetTraceResolver (void) const;
/**
* Get a copy of the attached Queue.
@@ -450,8 +419,8 @@
* @see class CallBackTraceSource
* @see class TraceResolver
*/
- CallbackTraceSource<Ptr<const Packet> > m_rxTrace;
- CallbackTraceSource<Ptr<const Packet> > m_dropTrace;
+ TracedCallback<Ptr<const Packet> > m_rxTrace;
+ TracedCallback<Ptr<const Packet> > m_dropTrace;
Ptr<Node> m_node;
Mac48Address m_address;
--- a/src/devices/csma/csma-topology.cc Wed Feb 27 19:51:34 2008 +0100
+++ b/src/devices/csma/csma-topology.cc Wed Feb 27 20:23:57 2008 +0100
@@ -46,10 +46,11 @@
CsmaTopology::AddCsmaEthernetNode(
Ptr<Node> n1,
Ptr<CsmaChannel> ch,
- MacAddress addr)
+ Mac48Address addr)
{
- Ptr<CsmaNetDevice> nd1 = CreateObject<CsmaNetDevice> (n1, addr,
- ns3::CsmaNetDevice::ETHERNET_V1);
+ Ptr<CsmaNetDevice> nd1 = CreateObjectWith<CsmaNetDevice> ("Node", Ptr<Node> (n1),
+ "Address", addr,
+ "EncapsulationMode", "EthernetV1");
Ptr<Queue> q = Queue::CreateDefault ();
nd1->AddQueue(q);
@@ -60,8 +61,8 @@
Ptr<PacketSocket>
CsmaTopology::ConnectPacketSocket(Ptr<PacketSocketApp> app,
- Ptr<CsmaNetDevice> ndSrc,
- Ptr<CsmaNetDevice> ndDest)
+ Ptr<CsmaNetDevice> ndSrc,
+ Ptr<CsmaNetDevice> ndDest)
{
Ptr<PacketSocket> socket = CreateObject<PacketSocket> ();
socket->Bind(ndSrc);
--- a/src/node/node.cc Wed Feb 27 19:51:34 2008 +0100
+++ b/src/node/node.cc Wed Feb 27 20:23:57 2008 +0100
@@ -55,64 +55,6 @@
return tid;
}
-NodeNetDeviceIndex::NodeNetDeviceIndex ()
- : m_index (0)
-{}
-NodeNetDeviceIndex::NodeNetDeviceIndex (uint32_t index)
- : m_index (index)
-{}
-uint32_t
-NodeNetDeviceIndex::Get (void) const
-{
- return m_index;
-}
-void
-NodeNetDeviceIndex::Print (std::ostream &os) const
-{
- os << "device=" << m_index;
-}
-uint16_t
-NodeNetDeviceIndex::GetUid (void)
-{
- static uint16_t uid = AllocateUid<NodeNetDeviceIndex> ("NodeNetDeviceIndex");
- return uid;
-}
-std::string
-NodeNetDeviceIndex::GetTypeName (void) const
-{
- return "ns3::NodeNetDeviceIndex";
-}
-
-
-NodeApplicationIndex::NodeApplicationIndex ()
- : m_index (0)
-{}
-NodeApplicationIndex::NodeApplicationIndex (uint32_t index)
- : m_index (index)
-{}
-uint32_t
-NodeApplicationIndex::Get (void) const
-{
- return m_index;
-}
-void
-NodeApplicationIndex::Print (std::ostream &os) const
-{
- os << "device=" << m_index;
-}
-uint16_t
-NodeApplicationIndex::GetUid (void)
-{
- static uint16_t uid = AllocateUid<NodeApplicationIndex> ("NodeApplicationIndex");
- return uid;
-}
-std::string
-NodeApplicationIndex::GetTypeName (void) const
-{
- return "ns3::NodeApplicationIndex";
-}
-
-
Node::Node()
: m_id(0),
m_sid(0)
@@ -138,16 +80,6 @@
Node::~Node ()
{}
-Ptr<TraceResolver>
-Node::GetTraceResolver (void) const
-{
- Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
- resolver->AddArray ("devices", m_devices.begin (), m_devices.end (), NodeNetDeviceIndex ());
- resolver->AddArray ("applications", m_applications.begin (), m_applications.end (), NodeApplicationIndex ());
- resolver->SetParentResolver (Object::GetTraceResolver ());
- return resolver;
-}
-
uint32_t
Node::GetId (void) const
{
--- a/src/node/node.h Wed Feb 27 19:51:34 2008 +0100
+++ b/src/node/node.h Wed Feb 27 20:23:57 2008 +0100
@@ -25,56 +25,16 @@
#include "ns3/object.h"
#include "ns3/callback.h"
-#include "ns3/trace-context-element.h"
#include "ns3/ptr.h"
namespace ns3 {
class TraceContext;
-class TraceResolver;
class NetDevice;
class Application;
class Packet;
class Address;
-class CompositeTraceResolver;
-/**
- * \brief hold in a TraceContext the index of a NetDevice within a Node
- */
-class NodeNetDeviceIndex : public TraceContextElement
-{
-public:
- NodeNetDeviceIndex ();
- NodeNetDeviceIndex (uint32_t index);
- /**
- * \returns the index of the NetDevice within its container Node.
- */
- uint32_t Get (void) const;
- void Print (std::ostream &os) const;
- std::string GetTypeName (void) const;
- static uint16_t GetUid (void);
-private:
- uint32_t m_index;
-};
-
-/**
- * \brief hold in a TraceContext the index of an Application within a Node
- */
-class NodeApplicationIndex : public TraceContextElement
-{
-public:
- NodeApplicationIndex ();
- NodeApplicationIndex (uint32_t index);
- /**
- * \returns the index of the Application within its container Node.
- */
- uint32_t Get (void) const;
- void Print (std::ostream &os) const;
- std::string GetTypeName (void) const;
- static uint16_t GetUid (void);
-private:
- uint32_t m_index;
-};
/**
* \brief A network Node.
@@ -199,7 +159,6 @@
void UnregisterProtocolHandler (ProtocolHandler handler);
protected:
- virtual Ptr<TraceResolver> GetTraceResolver (void) const;
/**
* The dispose method. Subclasses must override this method
* and must chain up to it by calling Node::DoDispose at the
--- a/utils/print-introspected-doxygen.cc Wed Feb 27 19:51:34 2008 +0100
+++ b/utils/print-introspected-doxygen.cc Wed Feb 27 20:23:57 2008 +0100
@@ -122,8 +122,9 @@
Ptr<PointToPointNetDevice> p2p = CreateObject<PointToPointNetDevice> (node, Mac48Address::Allocate ());
node->AddDevice (p2p);
p2p->AddQueue (Queue::CreateDefault ());
- Ptr<CsmaNetDevice> csma = CreateObject<CsmaNetDevice> (node, Mac48Address::Allocate (),
- CsmaNetDevice::LLC);
+ Ptr<CsmaNetDevice> csma = CreateObjectWith<CsmaNetDevice> ("Node", node,
+ "Address", Mac48Address::Allocate (),
+ "EncapsulationMode", "Llc");
node->AddDevice (csma);
csma->AddQueue (Queue::CreateDefault ());