Accessing the "Enqueue" Trace source in a Queue object

148 views
Skip to first unread message

Dani Camps

unread,
May 3, 2010, 10:51:22 AM5/3/10
to ns-3-users

Dear all,

I would like to access the trace sources defined in the Queue of a
CsmaNetDevice. My set up is the following:

1 - CsmaHelper csma;
NetDeviceContainer devices = csma.Install (nodes);

2- I have defined my trace sink and If I for instance try to access a
source defined in the CsmaNetDevice object, it works, e.g.:

devices.Get(0)->TraceConnectWithoutContext ("MacTx",
MakeCallback(&myTraceSink));

However, I can not access the trace sources defined in the Queue class
of the CsmaNetDevice, so for instance the following does not work:

devices.Get(0)->TraceConnectWithoutContext ("Enqueue",
MakeCallback(&myTraceSink));

I wanted to try obtaining a CsmaNetDevice from "devices", and then
calling GetQueue() to apply "TraceConnectWithoutContext" directly on
the queue object, for instance:

devices.Get(0)->GetQueue()->TraceConnectWithoutContext ("Enqueue",
MakeCallback(&myTraceSink));

But the previous does not work because, "devices.Get(0)" is a
NetDevice, not a CsmaNetDevice. How could I recover a CsmaNetDevice
instead of a NetDevice in the previous example ?

Best Regards

Daniel

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.

cra...@ee.washington.edu

unread,
May 3, 2010, 12:45:01 PM5/3/10
to ns-3-...@googlegroups.com
> However, I can not access the trace sources defined in the Queue class
> of the CsmaNetDevice, so for instance the following does not work:
>
> devices.Get(0)->TraceConnectWithoutContext ("Enqueue",
> MakeCallback(&myTraceSink));

Correct. A device is not a queue as you observe below.

> devices.Get(0)->GetQueue()->TraceConnectWithoutContext ("Enqueue",
> MakeCallback(&myTraceSink));
>
> But the previous does not work because, "devices.Get(0)" is a
> NetDevice, not a CsmaNetDevice. How could I recover a CsmaNetDevice
> instead of a NetDevice in the previous example ?

You can use GetObject (which I like since it's conceptually consistent with
other ns-3 object model API). Something like,

devices.Get (0)->GetObject<CsmaNetDevice> ()->GetQueue
()->TraceConnectWithoutContext ("Enqueue", MakeCallback(&myTraceSink));

You could also use DynamicCast (which is a wrapper around dynamic_cast)
which is what GetObject will do internally. This would work something like,

DynamicCast<CsmaNetDevice> (devices.Get (0))-> GetQueue
()->TraceConnectWithoutContext ("Enqueue", MakeCallback(&myTraceSink));

Dani Camps

unread,
May 3, 2010, 1:53:01 PM5/3/10
to ns-3-users

Hi,

Thanks for your answer. I tried your proposed changes but I am still
getting an error. This is how my code looks like:

CsmaHelper csma;

csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (50)));
NetDeviceContainer devices = csma.Install (nodes);

Ptr<CsmaNetDevice> csma_device = devices.Get (0)-
>GetObject<CsmaNetDevice> ();

And the error I get is:

debug/ns3/object.h: In member function ‘ns3::Ptr<T>
ns3::Object::GetObject() const [with T = ns3::CsmaNetDevice]’:
../scratch/tap-host-lxc-example.cc:119: instantiated from here
debug/ns3/object.h:389: error: cannot dynamic_cast
‘((ns3::Object::Aggregates*)((const ns3::Object*)this)-
>ns3::Object::m_aggregates)->ns3::Object::Aggregates::buffer[0]’ (of
type ‘class ns3::Object*’) to type ‘struct
ns3::CsmaNetDevice*’ (target is not pointer or reference to complete
type)

Any help is appreciated.

Best Regards

Daniel

cra...@ee.washington.edu

unread,
May 3, 2010, 4:15:25 PM5/3/10
to ns-3-...@googlegroups.com

> ns3::CsmaNetDevice*' (target is not pointer or reference to complete type)

Did you,

#include "ns3/csma-net-device.h"

That will probably help the compiler understand what a CsmaNetDevice * is.

Dani Camps

unread,
May 3, 2010, 4:20:19 PM5/3/10
to ns-3-users

Hi Craig,

I forgot the include, thanks a lot! Now it works perfect.

Regards

Daniel
Reply all
Reply to author
Forward
0 new messages