NS3 Simulator Schedule Example

Simulator schedule:

The Simulator API in ns3 tool was designed to make it really simple to schedule most events.

 

Types of schedule methods:

  • Schedule methods:

To schedule an event in the future by providing the delay between the current simulation time and the expiration date of the target event.

  • ScheduleNow methods

Schedule an event for the current simulation time: they will execute after the current event is finished executing but before the simulation time is changes for the next event.

  • ScheduleDestroy methods

Hook in the shutdown process of the simulator to cleanup simulation resources: every ‘destroy’ event is executed when the user calls the Simulator::Destroy method.

Ns3 Video Tutorial

Ns3 Video Tutorial – Latest NS3 Projects Output

Ns3 Tutorial

Ns3 Tutorial – Guide to Various Network Projects

Journal Support

Paper Publication for NS3 Simulation Projects

Contact Form

Contact Us- Customized Ns3 Simulator Projects

Sample code for network simulator schedule example:
#include
#include “ns3/simulator.h”
#include “ns3/nstime.h”
#include “ns3/random-variable-stream.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;
Ptr v = CreateObject ();
v->SetAttribute (“Min”, DoubleValue (10));
v->SetAttribute (“Max”, DoubleValue (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 ();