Scheduling events

654 views
Skip to first unread message

naskar

unread,
Nov 19, 2012, 11:17:36 PM11/19/12
to ns-3-...@googlegroups.com
Hi All,

Is it possible to insert a delay before a particular event after  events have been scheduled using Simulator::Schedule?
Is there any method for that?

Thanks!

Alessandro Russo

unread,
Nov 21, 2012, 7:51:31 AM11/21/12
to ns-3-...@googlegroups.com
You mean add a delay to an event that has been already scheduled,
actually re-scheduling the event?

Alessandro R.
> --
> You received this message because you are subscribed to the Google Groups
> "ns-3-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/ns-3-users/-/AUBt2t6nqocJ.
> 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.

sourav

unread,
Nov 21, 2012, 9:30:00 AM11/21/12
to ns-3-...@googlegroups.com
yes. I have scheduled some nodes to send messages at a particular time interval. Depending on some condition I want to defer a node from sending the for a certain time.

Thanks!

Alessandro Russo

unread,
Nov 22, 2012, 9:47:44 AM11/22/12
to ns-3-...@googlegroups.com
Basically, you use Schedule to add the event in the queue, setting the
delay corresponding to whatever-it-is

EventId eventX = Simulator::Schedule (delay1, &Function, this,
par1,par2,..parN);

then, if you wanna change delay1 with delay2, but the event is already
in the queue,
AFAIK you cannot "change it", but you have to cancel the event and
re-schedule it again, like

eventX.Cancel();
eventX = Simulator::Schedule (delay2, &Function, this, par1,par2,..parN);

OTHERWISE

you can set a "variable" in the node such that, when the event is schedule,
the Function check such a variable, if 0 continue, otherwise
reschedule the event.
BUT, this depends on the code ;)

Alessandro R.

sourav

unread,
Nov 22, 2012, 10:34:29 AM11/22/12
to ns-3-...@googlegroups.com
Thanks! I think my problem will be solved using the first one.

Fab

unread,
Nov 23, 2012, 4:25:17 PM11/23/12
to ns-3-...@googlegroups.com
Sourav,
I am a beginner at NS-3 and I am still trying to figure out how the event schedule is populated. After reading your post and the response to it I think you may be able to answer my question. Right now I am using preset statements (learned from the tutorial) in the main method to set up nodes and UDP applications. I assume the schedule is populated by the application's helper functions. Is that correct and if so how can I modify the schedule  or how can I access/find a particular event in the schedule?
Any help or suggestion would be greatly appreciated.

                  Fab

sourav

unread,
Nov 23, 2012, 9:01:39 PM11/23/12
to ns-3-...@googlegroups.com

A simple example of how to use the Simulator class to schedule events is shown below:

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2010 INRIA
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Authors: Mathieu Lacage <mathieu...@sophia.inria.fr>
 */

#include <iostream>
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include "ns3/command-line.h"
#include "ns3/random-variable.h"

using namespace ns3;

class MyModel
{
public:
  void Start (void);
private:
  void HandleEvent (double eventValue);
};

void
MyModel::Start (void)
{
  Simulator::Schedule (Seconds (10.0),
                       &MyModel::HandleEvent,
                       this, Simulator::Now ().GetSeconds ());
}
void
MyModel::HandleEvent (double value)
{
  std::cout << "Member method received event at "
            << Simulator::Now ().GetSeconds ()
            << "s started at " << value << "s" << std::endl;
}

static void
ExampleFunction (MyModel *model)
{
  std::cout << "ExampleFunction received event at "
            << Simulator::Now ().GetSeconds () << "s" << std::endl;
  model->Start ();
}

static void
RandomFunction (void)
{
  std::cout << "RandomFunction received event at "
            << Simulator::Now ().GetSeconds () << "s" << std::endl;
}

static void
CancelledEvent (void)
{
  std::cout << "I should never be called... " << std::endl;
}

int main (int argc, char *argv[])
{
  CommandLine cmd;
  cmd.Parse (argc, argv);

  MyModel model;
  UniformVariable v = UniformVariable (10, 20);

  Simulator::Schedule (Seconds (10.0), &ExampleFunction, &model);

  Simulator::Schedule (Seconds (v.GetValue ()), &RandomFunction);

  EventId id = Simulator::Schedule (Seconds (30.0), &CancelledEvent);
  Simulator::Cancel (id);

  Simulator::Run ();

  Simulator::Destroy ();
}
This is ns3 documentation

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ns-3-users/-/7Dcn94rYHtYJ.

Alessandro Russo

unread,
Nov 27, 2012, 11:23:02 AM11/27/12
to ns-3-...@googlegroups.com
Hi



On Fri, Nov 23, 2012 at 10:25 PM, Fab <F...@hawk.iit.edu> wrote:
> Sourav,
> I am a beginner at NS-3 and I am still trying to figure out how the event
> schedule is populated. After reading your post and the response to it I
> think you may be able to answer my question. Right now I am using preset
> statements (learned from the tutorial) in the main method to set up nodes
> and UDP applications. I assume the schedule is populated by the
> application's helper functions.

not the helper, but the application itself.
For instance the onoff application schedule the next TX
see ScheduleNextTx

m_sendEvent = Simulator::Schedule (nextTime,
&OnOffApplication::SendPacket, this);

> Is that correct and if so how can I modify the schedule

To my knowledge, you cannot "move" the event, you can just CANCEL it
and re-schedule the event,
actually adding it again with different parameters (e.g., delay).
You can have a look at the source code :)

> or how can I access/find a particular event in the schedule?

Look this piece of code.
When you schedule an event, you can "store" the corresponding EventId.

EventId m_sendEvent = Simulator::Schedule (nextTime,
&OnOffApplication::SendPacket, this);

means: after "nextTime" second, run SendPacket.

in m_sendEvent you have the ID of the corresponding event in the queue,

so you can Cancel it (cancel from the queue).
If you don't store the EventId...you don't have another "pointer" to it (AFAIK)

See http://www.nsnam.org/doxygen/classns3_1_1_simulator.html

> Any help or suggestion would be greatly appreciated.
>
> Fab
>
>
> On Thursday, November 22, 2012 9:34:32 AM UTC-6, sourav wrote:
>>
>> Thanks! I think my problem will be solved using the first one.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "ns-3-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/ns-3-users/-/7Dcn94rYHtYJ.
Reply all
Reply to author
Forward
0 new messages