Object aggregation with GetObject returns 0

97 views
Skip to first unread message

Jianhua Zhang

unread,
Feb 15, 2018, 7:35:27 PM2/15/18
to ns-3-users
Hi, 

I got an issue about aggregating an interface to the Net-Device.  The interface is the class of helics-receiver which is expected to aggregate to a NetDevice.

 

Ptr<HelicsReceiver> pHelicsRec = 0;

Ptr<NetDevice> pThisDev = destNode->GetDevice(i);

pHelicsRec = pThisDev->GetObject<HelicsReceiver>();

 

 

If aggregation is OK, the value of pHelicsRec should the pointer address.  While in my code, it is zero which means the netdevice does not have an Ipv4 object aggregated. 

 

Any suggestion will be very appreciated?

helics-receiver.cc
helics-receiver.h

Tom Henderson

unread,
Feb 15, 2018, 11:15:06 PM2/15/18
to ns-3-...@googlegroups.com
I can't see in the code that you shared that you are aggregating the HelicsReceiver object to the NetDevice.  Is this in other code that you did not share?

- Tom

Jianhua Zhang

unread,
Feb 16, 2018, 12:02:36 PM2/16/18
to ns-3-users
Hi Tom,

Thanks a lot for your reply.  Just attached the helics-simulator-impl class.  Please take a look at.

Looking forward to your comments.

Best wishes,
helics-simulator-impl.cc
helics-simulator-impl.h

Tom Henderson

unread,
Feb 16, 2018, 12:53:37 PM2/16/18
to ns-3-...@googlegroups.com
On 02/16/2018 09:02 AM, Jianhua Zhang wrote:
> Hi Tom,
>
> Thanks a lot for your reply.  Just attached the helics-simulator-impl
> class.  Please take a look at.

I see one line of code regarding aggregation, but it is commented out:

              //pHelicsRec = pThisDev->AggregateObject(HelicsReceiver);

Could this be your problem?

- Tom

Jianhua Zhang

unread,
Feb 16, 2018, 2:07:54 PM2/16/18
to ns-3-users
Hi Tom,

Great thanks for your quick response.  We could have two ways of the use of aggression in ns-3.  One way is to use AggregateObject(), and another way is to use GetObject().  I tried two of them :  for the GetObject() method,  the compiling is OK and the error message of running is to return null.  But for the method of AggregateObject(), I got the following compiling error:

../contrib/helics/model/helics-simulator-impl.cc:344:54: error: 'HelicsReceiver' does not refer to a value

              pHelicsRec = pThisDev->AggregateObject(HelicsReceiver);

                                                     ^

../contrib/helics/model/helics-receiver.h:42:7: note: declared here

class HelicsReceiver : public Object

      ^

../contrib/helics/model/helics-simulator-impl.cc:347:99: error: 'HelicsReceiver' does not refer to a value

              std::cout<<"Address of pThisDev aggregate With Object: "<<pThisDev->AggregateObject(HelicsReceiver)<<std::endl;

                                                                                                  ^

../contrib/helics/model/helics-receiver.h:42:7: note: declared here

class HelicsReceiver : public Object

      ^

2 errors generated.


From this, I guess it is possible that the object of HelicsReceiver() doesn't be built properly?

Best wishes,

Jianhua Zhang

unread,
Feb 16, 2018, 4:26:10 PM2/16/18
to ns-3-users
By the way, it is worth to note that the exact same method of GetObject() in the Granted-time-window-mpi-interface.cc of the Mpi module, which is for the distributed simulator, it works.   That is why I feel very confusing. 
granted-time-window-mpi-interface.cc
distributed-simulator-impl.cc

Tom Henderson

unread,
Feb 16, 2018, 4:26:39 PM2/16/18
to ns-3-...@googlegroups.com
On 02/16/2018 11:07 AM, Jianhua Zhang wrote:
> Hi Tom,
>
> Great thanks for your quick response.  We could have two ways of the
> use of aggression in ns-3.  One way is to use AggregateObject(), and
> another way is to use GetObject().  I tried two of them :  for the
> GetObject() method,  the compiling is OK and the error message of
> running is to return null.  But for the method of AggregateObject(), I
> got the following compiling error:

You are passing the name of a type (HelicsReceiver) to AggregateObject()
which is expecting a value (a pointer to an actual HelicsReceiver object).

Instead, you should create an instance of HelicsReceiver, and pass the
pointer to that object to AggregateObject (); e.g.

  Ptr<HelicsReceiver> helics = CreateObject<HelicsReceiver> ();
  pThisDev->AggregateObject (helics);

Note that AggregateObject() does not return a value.

At some later point, if you have a pointer to the device and want to get
a pointer to this aggregated object, you do:

  Ptr<NetDevice> device = ...;
  Ptr<HelicsReceiver> myHelicsObject =
device->GetObject<HelicsReceiver> ();

If a HelicsReceiver object has been aggregated, then myHelicsObject will
hold the pointer; if not, the pointer will be null.

In summary, please note that GetObject() and AggregateObject() do
different things.

- Tom

Jianhua Zhang

unread,
Feb 20, 2018, 4:46:03 PM2/20/18
to ns-3-users
Hi Tom,

Great thanks for your valuable comments. This problem has been solved and it means that after a HelicsReceiver object has been aggregated, then pHeicsRec really hold the pointer.  However, when the scheduler tries to execute this packet receiver object, it shows this following error message:
 

We are at ProcessOneEvent... 

This event time is 3100000000, id is 17, context is 0

assert failed. cond="!m_rxCallback.IsNull ()", file=../contrib/helics/model/helics-receiver.cc, line=5730859-2ee218ab-f299-4d72-be8d-41636780b5d2::|| cmd:send_message from 65537


By comparing the bindings folder of the MpiReceiver and HelicsReceiver object, it is possible that we miss something about callback list.  

Any suggestion will be very appreciated?

helics-simulator-impl_distributed.cc

Jianhua Zhang

unread,
Feb 20, 2018, 6:09:08 PM2/20/18
to ns-3-users
From the above message, we can see the function of "SetReceiveCallback()" in relics-receiver.cc doesn't been executed before calling "Receive()".  By comparing the log of mli-receiver.cc and relics-receiver.cc, we notice that "SetReceiveCallback()" of mpi-receiver.cc is executed at the beginning schedule stage, while in the helics case, it isn't.  

Also, I am confusing in MPI module, when the MpiReceiver object is been aggregated to the NetDevice object?   I went through all the possible modules, no clue yet.  

Any suggestion will be very appreciate?

Best wishes, 

Jianhua
Reply all
Reply to author
Forward
0 new messages