How do I Run a Program in Ns3

          Let’s start this article to know about the essential processes that are deployed to run ns3 program.

Ns3 Program Creation

        En route for the initiation of this process, the file extension .cc is deployed to create and store the simulation program in the scratch folder.

Create Ns3 Simulation Program

Sample Ns3 Program Code

          To showcase some sample ns3 program codes for your reference, we have enlisted the some significant processes with programming code.

  • Energy model configuration
BasicEnergySourceHelper basicSourceHelper;
basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (1.0));
EnergySourceContainer sources = basicSourceHelper.Install (c);
WifiRadioEnergyModelHelper radioEnergyHelper;
radioEnergyHelper.Set ("TxCurrentA", DoubleValue (0.0174));
radioEnergyHelper.Set ("RxCurrentA", DoubleValue (0.0197));
DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);
BasicEnergyHarvesterHelper basicHarvesterHelper;
basicHarvesterHelper.Set ("PeriodicHarvestedPowerUpdateInterval", TimeValue (Seconds (harvestingUpdateInterval)));
basicHarvesterHelper.Set ("HarvestablePower", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=0.1]"));
EnergyHarvesterContainer harvesters = basicHarvesterHelper.Install (sources);
  • Header file initialization
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/energy-module.h"
#include "ns3/internet-module.h"

Run Ns3 Program

            Finally, we have to run the simulation program based on Ns3 through the implementation of the commands that are highlighted below.

cd /home/research/ns-allinone-3.26/ns-3.26

sudo ./waf –run ProgramCode –vis

Run Ns3 Simulation Program

         Notably, we have illustrated the result that is acquired through the program execution through the below mentioned screen.

Result of Ns3 Simulation

        If you guys feel that you are lacking somewhere just take a while to interact with our technical experts and we hope that you have acquired some required information about running ns3 program through this article.