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:
- Fresh installation of Ubuntu 22.04 LTS:
Screenshot:
2.NS-3.35 Installation:
Screenshot:
HEADER FILE VERIFICATION:
- Locate to the ns3/scratch folder:
Screenshot:
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:
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:
3.Open the Terminal:
Next, we need to launch the terminal by right clicking the mouse in the ns3 location.
Screenshot:
Screenshot:
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:
Screenshot:
5.Importing Event-id.h:
Here we imported the Event-id.h header file in this example program.
Screenshot:
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:
Screenshot:
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:
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:
Here we shown the output of the example Event-id program by using event-id.h.
Screenshot: