Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to import Event Id .h packages in NS3

To import EVENT-ID.H packages in NS3 let’s talk about what Event-id.h is. It’s a header file from the NS-3 network simulator that outlines the ns3::EventId class. This class serves as a unique ID for events that are scheduled during simulations. The EventId class helps in managing and referencing these events on the simulation timeline, making it easier to schedule and cancel them accurately. Understanding event-id.h is crucial for developers working on event-driven simulations in NS-3 so stay in touch with us to know more about project execution ideas.

The installation steps of Event-id.h.

PRE-REQUISITES:

  1. Fresh installation of Ubuntu 22.04 LTS:

Screenshot:

Fresh installation of Ubuntu 22_04 LTS

2.NS-3.35 Installation:

Screenshot:

NS-3.35 Installation

HEADER FILE VERIFICATION:

  1. Locate to the ns3/scratch folder:

Screenshot:

Locate to the ns3-scratch folder

2.Create the Event-id_eg.cc file in the scratch folder:

Next we need to create the Event-id_eg.cc file by using text editor in the ns3/scratch folder.

Screenshot:

Create the Event-id_eg.cc file in the scratch folder

Next we need to paste the below code to the Event-id_eg.cc file and save the file in the ns3/scratch folder.

Code:

#include “ns3/core-module.h”

#include “ns3/event-id.h”

using namespace ns3;

void MyFunction() {

    std::cout << “Event executed at: ” << Simulator::Now().GetSeconds() << ” seconds” << std::endl;

}

int main(int argc, char *argv[]) {

    Time::SetResolution(Time::NS);

    EventId eventId = Simulator::Schedule(Seconds(2.0), &MyFunction);

    std::cout << “Before cancel – IsRunning: ” << eventId.IsRunning() << “, IsExpired: ” << eventId.IsExpired() << std::endl;

    eventId.Cancel();

    std::cout << “After cancel – IsRunning: ” << eventId.IsRunning() << “, IsExpired: ” << eventId.IsExpired() << std::endl;

    eventId = Simulator::Schedule(Seconds(4.0), &MyFunction);

    std::cout << “Rescheduled – IsRunning: ” << eventId.IsRunning() << “, IsExpired: ” << eventId.IsExpired() << std::endl;

    Simulator::Run();

    std::cout << “After running – IsRunning: ” << eventId.IsRunning() << “, IsExpired: ” << eventId.IsExpired() << std::endl;

    Simulator::Destroy();

    return 0;

}

Screenshot:

Create the Event-id_eg.cc file in the scratch folder

3.Open the Terminal:

Next, we need to launch the terminal by right clicking the mouse in the ns3 location.

Screenshot:

Open the Terminal

Screenshot:

Open the Terminal

4.NS-3.35 Configuration && Building Process:

Next, we need to configure and build the ns3 folder to make the copied files to the scratch need to store in configuration.

Command:      “./waf configure && ./waf build”

Screenshot:

NS-3.35 Configuration && Building Process

Screenshot:

NS-3.35 Configuration && Building Process

5.Importing Event-id.h:

Here we imported the Event-id.h header file in this example program.

Screenshot:

Importing Event-id.h

Here we highlighted the code line that highlighted which is the part of the Event-id.h that we will show class file that used in this code via core folder which represents core-module.

Screenshot:

Importing Event-id.h

Screenshot:

Importing Event-id.h

Here we will show the header file by opening Event-id.h file to show the class imported from the Event-id.h in the example code.

Screenshot:

Importing Event-id.h

6.Executing the Example Event-id Program:

Then we need to run the Example Event-id program to view output of the program.

Command:      “./waf –run Event-id_eg –vis”

Screenshot:

Executing the Example Event-id Program

Here we shown the output of the example Event-id program by using event-id.h.

Screenshot:

Executing the Example Event-id Program