# HG changeset patch # User Mathieu Lacage # Date 1204140237 -3600 # Node ID 1fb9430f642dfe325c0b129e780093ed34bb0687 # Parent 806f6efe1c33463f059af1b6d69f25e214bc4641 convert CsmaNetDevice to Attributes. diff -r 806f6efe1c33 -r 1fb9430f642d examples/csma-packet-socket.cc --- 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 CreateCsmaDevice (Ptr node, Ptr channel) { - Ptr device = CreateObject (node, Mac48Address::Allocate (), - CsmaNetDevice::LLC); + Ptr device = CreateObjectWith ("Node", node, + "Address", Mac48Address::Allocate (), + "EncapsulationMode", "Llc"); node->AddDevice (device); device->Attach (channel); Ptr queue = Queue::CreateDefault (); diff -r 806f6efe1c33 -r 1fb9430f642d src/devices/csma/csma-ipv4-topology.cc --- 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 q = Queue::CreateDefault (); // assume full-duplex - Ptr nd = CreateObject (node, addr, - ns3::CsmaNetDevice::IP_ARP); + Ptr nd = CreateObjectWith ("Node", node, + "Address", addr, + "EncapsulationMode", "IpArp"); node->AddDevice (nd); nd->AddQueue(q); @@ -59,16 +60,18 @@ { Ptr q = Queue::CreateDefault (); - Ptr nd0 = CreateObject (n1, addr, - ns3::CsmaNetDevice::LLC); + Ptr nd0 = CreateObjectWith ("Node", n1, + "Address", addr, + "EncapsulationMode", "Llc"); n1->AddDevice (nd0); nd0->SetSendEnable (true); nd0->SetReceiveEnable (false); nd0->AddQueue(q); nd0->Attach (ch); - Ptr nd1 = CreateObject (n1, addr, - ns3::CsmaNetDevice::LLC); + Ptr nd1 = CreateObjectWith ("Node", n1, + "Address", addr, + "EncapsulationMode", "Llc"); n1->AddDevice (nd1); nd1->SetSendEnable (false); nd1->SetReceiveEnable (true); @@ -83,16 +86,18 @@ { Ptr q = Queue::CreateDefault (); - Ptr nd0 = CreateObject (n1, addr, - ns3::CsmaNetDevice::RAW); + Ptr nd0 = CreateObjectWith ("Node", n1, + "Address", addr, + "EncapsulationMode", "Raw"); n1->AddDevice (nd0); nd0->SetSendEnable (true); nd0->SetReceiveEnable (false); nd0->AddQueue(q); nd0->Attach (ch); - Ptr nd1 = CreateObject (n1, addr, - ns3::CsmaNetDevice::RAW); + Ptr nd1 = CreateObjectWith ("Node", n1, + "Address", addr, + "EncapsulationMode", "Raw"); n1->AddDevice (nd1); nd1->SetSendEnable (false); nd1->SetReceiveEnable (true); diff -r 806f6efe1c33 -r 1fb9430f642d src/devices/csma/csma-net-device.cc --- 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 () + .AddConstructor () + .AddAttribute ("Node", "The node with which this device is associated", + TypeId::ATTR_GET | TypeId::ATTR_CONSTRUCT, + Ptr (0), + MakePtrAccessor (&CsmaNetDevice::m_node), + MakePtrChecker ()) + .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 (0), + MakePtrAccessor (&CsmaNetDevice::m_receiveErrorModel), + MakePtrChecker ()) + .AddAttribute ("TxQueue", "XXX", + Ptr (0), + MakePtrAccessor (&CsmaNetDevice::m_queue), + MakePtrChecker ()) + .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"); - 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, 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 -CsmaNetDevice::GetTraceResolver (void) const -{ - NS_LOG_FUNCTION; - Ptr resolver = Create (); - resolver->AddComposite ("queue", m_queue); - resolver->AddSource ("rx", - TraceDoc ("receive MAC packet", - "Ptr", "packet received"), - m_rxTrace, - CsmaTraceType (CsmaTraceType::RX)); - resolver->AddSource ("drop", - TraceDoc ("drop MAC packet", - "Ptr", "packet dropped"), - m_dropTrace, - CsmaTraceType (CsmaTraceType::DROP)); - resolver->SetParentResolver (NetDevice::GetTraceResolver ()); - return resolver; -} - bool CsmaNetDevice::Attach (Ptr ch) { @@ -448,7 +416,6 @@ NS_LOG_PARAM ("(" << em << ")"); m_receiveErrorModel = em; - AggregateObject (em); } void diff -r 806f6efe1c33 -r 1fb9430f642d src/devices/csma/csma-net-device.h --- 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, 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 GetTraceResolver (void) const; /** * Get a copy of the attached Queue. @@ -450,8 +419,8 @@ * @see class CallBackTraceSource * @see class TraceResolver */ - CallbackTraceSource > m_rxTrace; - CallbackTraceSource > m_dropTrace; + TracedCallback > m_rxTrace; + TracedCallback > m_dropTrace; Ptr m_node; Mac48Address m_address; diff -r 806f6efe1c33 -r 1fb9430f642d src/devices/csma/csma-topology.cc --- 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 n1, Ptr ch, - MacAddress addr) + Mac48Address addr) { - Ptr nd1 = CreateObject (n1, addr, - ns3::CsmaNetDevice::ETHERNET_V1); + Ptr nd1 = CreateObjectWith ("Node", Ptr (n1), + "Address", addr, + "EncapsulationMode", "EthernetV1"); Ptr q = Queue::CreateDefault (); nd1->AddQueue(q); @@ -60,8 +61,8 @@ Ptr CsmaTopology::ConnectPacketSocket(Ptr app, - Ptr ndSrc, - Ptr ndDest) + Ptr ndSrc, + Ptr ndDest) { Ptr socket = CreateObject (); socket->Bind(ndSrc); diff -r 806f6efe1c33 -r 1fb9430f642d src/node/node.cc --- 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"); - 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"); - 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 -Node::GetTraceResolver (void) const -{ - Ptr resolver = Create (); - 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 { diff -r 806f6efe1c33 -r 1fb9430f642d src/node/node.h --- 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 GetTraceResolver (void) const; /** * The dispose method. Subclasses must override this method * and must chain up to it by calling Node::DoDispose at the diff -r 806f6efe1c33 -r 1fb9430f642d utils/print-introspected-doxygen.cc --- 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 p2p = CreateObject (node, Mac48Address::Allocate ()); node->AddDevice (p2p); p2p->AddQueue (Queue::CreateDefault ()); - Ptr csma = CreateObject (node, Mac48Address::Allocate (), - CsmaNetDevice::LLC); + Ptr csma = CreateObjectWith ("Node", node, + "Address", Mac48Address::Allocate (), + "EncapsulationMode", "Llc"); node->AddDevice (csma); csma->AddQueue (Queue::CreateDefault ());