Bug 752 - Object::DoStart is not executed for objects created at t > 0
Object::DoStart is not executed for objects created at t > 0
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: core
ns-3-dev
All All
: P5 normal
Assigned To: Craig Dowell
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-11-25 05:52 EST by Pavel Boyko
Modified: 2010-01-08 12:05 EST (History)
4 users (show)

See Also:


Attachments
example program (735 bytes, text/x-c++src)
2009-11-25 05:53 EST, Pavel Boyko
Details
try to support dynamic creation of applications (1.64 KB, patch)
2009-11-25 14:56 EST, Mathieu Lacage
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Boyko 2009-11-25 05:52:48 EST
It is observed, that only objects created before Simulator::Run() are initialized via DoStart (). Attached program illustrates this. Expected output is 

A::A()
A::DoStart()

and actual is just A::A().

In particular I see no way to create and start applications dynamically at t > 0 since application start is implemented via Application::DoStart().

If Object's behavior is believed to be correct, I ask for particular Application fix (probably revert DoStart -> Start and schedule it from SetStartTime()).
Comment 1 Pavel Boyko 2009-11-25 05:53:26 EST
Created attachment 678 [details]
example program
Comment 2 Mathieu Lacage 2009-11-25 07:49:49 EST
(In reply to comment #0)
> It is observed, that only objects created before Simulator::Run() are
> initialized via DoStart (). Attached program illustrates this. Expected output
> is 
> 
> A::A()
> A::DoStart()
> 
> and actual is just A::A().
> 
> In particular I see no way to create and start applications dynamically at t >
> 0 since application start is implemented via Application::DoStart().
> 
> If Object's behavior is believed to be correct, I ask for particular
> Application fix (probably revert DoStart -> Start and schedule it from
> SetStartTime()).

I do not believe we ever explicitely supported the dynamic creation of applications during simulation, just like we don't support dynamically creating devices during simulation so, it is no wonder that it does not work.

I think that the first issue is deciding whether we want to support creating applications during the simulation. CCing tom since he will have input on that.
Comment 3 Pavel Boyko 2009-11-25 10:10:30 EST
> I do not believe we ever explicitely supported the dynamic creation of
> applications during simulation, 

  I use this since my first days with ns-3 and it always worked. Old Application::Start and Stop logic was very simple -- just schedule DoStart and DoStop, this can be done at any time.
Comment 4 Mathieu Lacage 2009-11-25 10:12:21 EST
(In reply to comment #3)
> > I do not believe we ever explicitely supported the dynamic creation of
> > applications during simulation, 
> 
>   I use this since my first days with ns-3 and it always worked. Old
> Application::Start and Stop logic was very simple -- just schedule DoStart and
> DoStop, this can be done at any time.

That was accidental: we never designed the system to support this and I introduced the Start method without this feature in mind.
Comment 5 Pavel Boyko 2009-11-25 10:25:59 EST
> That was accidental: we never designed the system to support this and I
> introduced the Start method without this feature in mind.

  Well, if you have serious doubts that ns-3 can support on demand application start and stop, I will implement any simple workaround in my applications. But I wonder why -- do you worry about ported "real" applications?
Comment 6 Mathieu Lacage 2009-11-25 12:27:09 EST
(In reply to comment #5)
> > That was accidental: we never designed the system to support this and I
> > introduced the Start method without this feature in mind.
> 
>   Well, if you have serious doubts that ns-3 can support on demand application
> start and stop, I will implement any simple workaround in my applications. But
> I wonder why -- do you worry about ported "real" applications?

I never said that this could not be supported. I merely said that, so far, we never actually purposedly made this work and if we want to make this work again, we need to think carefully about the consequences. So, I have nothing against it. I am merely saying that we need to think this through. i.e., it's not a 10s patch.
Comment 7 Tom Henderson 2009-11-25 12:39:38 EST
(In reply to comment #2)
(In reply to comment #2)
> (In reply to comment #0)
> > It is observed, that only objects created before Simulator::Run() are
> > initialized via DoStart (). Attached program illustrates this. Expected output
> > is 
> > 
> > A::A()
> > A::DoStart()
> > 
> > and actual is just A::A().
> > 
> > In particular I see no way to create and start applications dynamically at t >
> > 0 since application start is implemented via Application::DoStart().
> > 
> > If Object's behavior is believed to be correct, I ask for particular
> > Application fix (probably revert DoStart -> Start and schedule it from
> > SetStartTime()).
> 
> I do not believe we ever explicitely supported the dynamic creation of
> applications during simulation, just like we don't support dynamically creating
> devices during simulation so, it is no wonder that it does not work.

I don't think we ever explicitly excluded it, however, and there are statements
in our documentation such as "ns-3 is a C++ based system, except we have some
special base classes..." so I think it is probably going to be surprising to
users to discover that some Objects can't be instantiated after time 0.

> 
> I think that the first issue is deciding whether we want to support creating
> applications during the simulation. CCing tom since he will have input on that.

What would it take to support it?
Comment 8 Mathieu Lacage 2009-11-25 12:48:46 EST
(In reply to comment #7)

> > I do not believe we ever explicitely supported the dynamic creation of
> > applications during simulation, just like we don't support dynamically creating
> > devices during simulation so, it is no wonder that it does not work.
> 
> I don't think we ever explicitly excluded it, however, and there are statements
> in our documentation such as "ns-3 is a C++ based system, except we have some
> special base classes..." so I think it is probably going to be surprising to
> users to discover that some Objects can't be instantiated after time 0.

It's already the case (not legal to create them after time 0) for NetDevice, Channel, and Node and I thought that it was the case for Application: all these objects make up the overall simulation topology for me and I always expected them to be fully static/constructed before simulation starts. I understand that it's reasonable and convenient to create applications dynamically but I never thought that this would be allowed.

> > I think that the first issue is deciding whether we want to support creating
> > applications during the simulation. CCing tom since he will have input on that.
> 
> What would it take to support it?

I do not really know: I do not know what the impact is going to be on the multithreaded stuff.
Comment 9 Mathieu Lacage 2009-11-25 14:56:15 EST
Created attachment 679 [details]
try to support dynamic creation of applications

Can you try that patch ?
Comment 10 Pavel Boyko 2009-11-26 03:27:04 EST
(In reply to comment #9)
> Created an attachment (id=679) [details]
> try to support dynamic creation of applications
> 
> Can you try that patch ?

  it helps, thank you. 

  Obviously general problem with objects illustrated by attached do-start.cc program still here, only applications and devices are fixed.
Comment 11 Mathieu Lacage 2009-11-26 05:30:45 EST
(In reply to comment #10)
> (In reply to comment #9)
> > Created an attachment (id=679) [details] [details]
> > try to support dynamic creation of applications
> > 
> > Can you try that patch ?
> 
>   it helps, thank you. 
> 
>   Obviously general problem with objects illustrated by attached do-start.cc
> program still here, only applications and devices are fixed.

Well, it's pretty clear that the Start/DoStart methods will not get magically invoked for you unless your objects are a part of the structure of the simulation topology. i.e., if you create objects yourself, you become responsible for calling Start yourself. Does this clarify the issue for you ?
Comment 12 Pavel Boyko 2009-11-26 05:44:35 EST
> Well, it's pretty clear that the Start/DoStart methods will not get magically
> invoked for you unless your objects are a part of the structure of the
> simulation topology. i.e., if you create objects yourself, you become
> responsible for calling Start yourself. 

 That wasn't clear for me at all. When I read in CHANGES.html the description:

<li><b>Object::DoStart</b>: Users who need to complete their object setup at the start of a simulation can override this virtual method, perform their adhoc setup, and then, must chain up to their parent.

 I was sure that CreateObject() just schedules DoStart at Seconds(0). Now I see that my conclusion was wrong since it is said "at the start of a simulation". Nevertheless, I ask you to extend that description and explicitly clarify that DoStart is not called at all for objects created after the start of a simulation.  

> Does this clarify the issue for you ?

 Yes, thank you. I propose to commit patch, update docs and close this bug.
Comment 13 Craig Dowell 2010-01-05 14:52:12 EST
This patch changes the timing of a couple of regression tests in suspicious ways.  Need to understand before committing.

< 0.000263 Assoc Request () [6.0 9.0 12.0 18.0 24.0 36.0 48.0 54.0 Mbit]
< 0.000279 Acknowledgment RA:00:00:00:00:00:07
< 0.000357 Assoc Response AID(0) :: Succesful
< 0.000501 Acknowledgment RA:00:00:00:00:00:0a

vs.

> 0.000158 Beacon () [6.0* 9.0 12.0 18.0 24.0 36.0 48.0 54.0 Mbit] IBSS
> 0.000396 Assoc Request () [6.0 9.0 12.0 18.0 24.0 36.0 48.0 54.0 Mbit]
> 0.000412 Acknowledgment RA:00:00:00:00:00:07
> 0.000490 Assoc Response AID(0) :: Succesful
Comment 14 Mathieu Lacage 2010-01-08 12:05:07 EST
I have verified that current ns-3-dev does not trigger regressions with this patch applied so, I pushed it.

changeset: 8788d85a6c3e