Schedule a method inside another one

66 views
Skip to first unread message

Olim

unread,
Jul 7, 2015, 10:12:05 AM7/7/15
to ns-3-...@googlegroups.com
Hi guys! Please help me!
My problem is as follows:

I have a method Receive (Ptr<packet>) and Method(Ptr<packet>)
I just want to keep the packet during very few time (I need it :)

void MyApp::Receive (Ptr<packet>) {
  if (i.e. packet is seen before) {
    some changes on packet;
   /*!!!*/
    Simulator::Schedule(seconds(timeSlot), &MyApp::Method); // there should be added the packet
  }
}

void MyApp::Method(Ptr<packet>) {
  if (timeSlot is expired) then Forward(p);
}

Guys, I read the how to Schedule the methods,
but couldn't find how to Schedule one method inside of another.
For any clarification please write me!!!

Thank you so much!
Best Regards
Olim

Konstantinos

unread,
Jul 7, 2015, 10:23:35 AM7/7/15
to ns-3-...@googlegroups.com, yalg...@gmail.com
Hi Olim,

Doesn't this procedure you have written work?
The process of scheduling a method within another does not change from the scheduling it at the first place.

Regards,
K.

Olim

unread,
Jul 7, 2015, 11:01:29 AM7/7/15
to ns-3-...@googlegroups.com, yalg...@gmail.com
Hi Konstantinos,

So... is it impossible?

Konstantinos

unread,
Jul 7, 2015, 11:16:06 AM7/7/15
to ns-3-...@googlegroups.com, yalg...@gmail.com
Yes,

this is also the way to do 'periodic' functions, you schedule the same function within itself.
e.g schedule the 'Foo' to run periodically every second.

void Foo()
{
... 
Simulator::Schedule(Seconds(1), &Foo);

Olim

unread,
Jul 7, 2015, 11:20:56 AM7/7/15
to ns-3-...@googlegroups.com, yalg...@gmail.com
Thank you very much Konstantinos!
then I will think of other ways to solve my problem.

Have a good day!

Bo Zhang

unread,
Jul 7, 2015, 11:27:04 AM7/7/15
to ns-3-...@googlegroups.com, yalg...@gmail.com
Sorry to interrupt. You guys talk like this IS the way of doing it, while the outcome of the conversation somehow convinced Olim that it's impossible.

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Konstantinos

unread,
Jul 7, 2015, 11:32:44 AM7/7/15
to ns-3-...@googlegroups.com, zhang...@gmail.com, yalg...@gmail.com
I was about to write the same thing Zhang.
As I said, YES it is possible to schedule a method within another one and I gave the example.
I don't know how Olim go it the other way.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.

Olim

unread,
Jul 7, 2015, 11:43:42 AM7/7/15
to ns-3-...@googlegroups.com, yalg...@gmail.com, zhang...@gmail.com
Hi Konstantinos!
Yes, you gave me an example to schedule a method inside the method.
But I still have no idea to schedule a method within another one.

OK, thanks!

Have a good day!
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.

Bo Zhang

unread,
Jul 7, 2015, 11:48:48 AM7/7/15
to Olim, ns-3-...@googlegroups.com
How about in the example, you switch 
Simulator::Schedule(Seconds(1), &Foo);

to

Simulator::Schedule(Seconds(1), &Bar);

?

Bo Zhang

unread,
Jul 7, 2015, 11:49:43 AM7/7/15
to Olim, ns-3-...@googlegroups.com
Konstantinos did suspect that your code should work.

Olim

unread,
Jul 7, 2015, 12:44:01 PM7/7/15
to ns-3-...@googlegroups.com, yalg...@gmail.com
Thank you for your reply Zhang,
I tried that code, but something went wrong maybe,
But when I remove the code it works (of course not correctly :)

Have a good day,
Best regards,
Olim

Konstantinos

unread,
Jul 7, 2015, 1:00:51 PM7/7/15
to ns-3-...@googlegroups.com, yalg...@gmail.com
Unless you give us the complete error or code to verify the problem, we can only say that the method to schedule another function within one function does not vary for scheduling it anywhere else (e.g. the main).

pdbarnes

unread,
Jul 7, 2015, 4:08:15 PM7/7/15
to ns-3-...@googlegroups.com
Given your function signature:

void MyApp::Method(Ptr<packet>);

I think the Schedule call should be:

Simulator::Schedule(seconds(timeSlot), &MyApp::Method, this, packet);

Notice that you have to give the (normally implicit) "this" argument, as well as the explicit "packet" argument.

Peter

Olim

unread,
Jul 9, 2015, 5:38:29 AM7/9/15
to ns-3-...@googlegroups.com
Thank you very much!
Now I solve the problem! :)
Reply all
Reply to author
Forward
0 new messages