How To Install ENERGY MODEL.H Packages in Ns2

To import the ENERGY-MODEL.H packages in the NS2 tool, our team is here to assist you in finding the optimal solution. Stay connected with our research team for the best research ideas and topics. Drop a message to ns2projects.com we do gurantee you with best results. Energy-model.h is designed to simulate the energy usage of nodes within wireless networks. This class plays a crucial role in contexts such as wireless sensor networks (WSNs), mobile ad hoc networks (MANETs), and other situations where energy efficiency is paramount. The EnergyModel monitors the energy consumption of a node across various functions, including transmitting, receiving, idling, and executing computations, ensuring that energy resources are depleted in a realistic manner over time. The energy-model.h file includes the definition of the EnergyModel class, along with methods and attributes that establish the total energy available to a node at the beginning of the simulation. It details the energy expenditure associated with different activities, such as data transmission and reception, and keeps track of the node’s remaining energy as it engages in these activities, updating the energy levels accordingly.

PRE-REQUISITES:

  1. Fresh installation of Ubuntu 16.04 LTS:

Screenshot:

Fresh installation of Ubuntu 16.04 LTS

2.NS-2.35 Installation:

Screenshot:

NS-2.35 Installation

Here, Percentage (%)  symbol Denotes the successful installation of the NS 2.35 Simulator.

Screenshot:

NS-2.35 Installation

HEADER FILE VERIFICATION:

  1. Locate to the ns-2.35 folder:

Screenshot:

Locate to the ns-2.35 folder

2.Create the Main.tcl file in the scratch folder:

Next we need to create the Main.tcl file by using text editor in the ns-2.35 folder.

Screenshot:

Next we need to paste the below code to the Main.tcl file and save the file in the ns-2.35 folder.

Code:

set val(chan)       Channel/WirelessChannel 

set val(prop)       Propagation/TwoRayGround

set val(netif)      Phy/WirelessPhy

set val(mac)        Mac/802_11              

set val(ifq)        Queue/DropTail/PriQueue 

set val(ll)         LL                   

set val(ant)        Energy-model/OmniEnergy-model    

set val(ifqlen)     50                      

set val(nn)         25                

set val(rp)         AODV                   

set val(x)          500                     

set val(y)          400                    

set val(stop)       150                   

set ns      [new Simulator]

set tracefd [open testAODV.tr w]

set namtrace [open testAODV.nam w]

$ns trace-all $tracefd

$ns namtrace-all-wireless $namtrace $val(x) $val(y)

set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# Node Configuration based on Energy Model

$ns node-config -adhocRouting $val(rp) \

    -llType $val(ll) \

    -macType $val(mac) \

    -ifqType $val(ifq) \

    -ifqLen $val(ifqlen) \ 

    -antType $val(ant) \ 

    -propType $val(prop) \ 

    -phyType $val(netif) \ 

    -channelType $val(chan) \ 

    -topoInstance $topo \ 

    -agentTrace ON \ 

    -routerTrace OFF \ 

    -movementTrace ON \ 

    -energyModel “EnergyModel” \ 

    -initialEnergy 1000.0 \ 

    -rxPower 0.3 \ 

    -txPower 0.6 \ 

    -idlePower 0.1 

for {set i 0} {$i < $val(nn)} {incr i} { 

    set node_($i) [$ns node] 

    $node_($i) set X_ [expr 10+round(rand()*480)] 

    $node_($i) set Y_ [expr 10+round(rand()*380)] 

    $node_($i) set Z_ 0.0 

for {set i 0} {$i < $val(nn)} {incr i} { 

    $ns at [expr 15+round(rand()*60)] \ 

        “$node_($i) setdest [expr 10+round(rand()*480)] [expr 10+round(rand()*380)] [expr 2+round(rand()*15)]” 

$ns at 10.0 “$node_(0) setdest 250.0 250.0 3.0” 

$ns at 15.0 “$node_(1) setdest 45.0 285.0 5.0” 

$ns at 70.0 “$node_(2) setdest 480.0 300.0 5.0” 

$ns at 20.0 “$node_(3) setdest 200.0 200.0 5.0” 

$ns at 25.0 “$node_(4) setdest 50.0 50.0 10.0” 

$ns at 60.0 “$node_(5) setdest 150.0 70.0 2.0” 

$ns at 90.0 “$node_(6) setdest 380.0 150.0 8.0” 

$ns at 42.0 “$node_(7) setdest 200.0 100.0 15.0” 

$ns at 55.0 “$node_(8) setdest 50.0 275.0 5.0” 

$ns at 19.0 “$node_(9) setdest 250.0 250.0 7.0” 

set tcp [new Agent/TCP/Newreno] 

$tcp set class_ 2 

set sink [new Agent/TCPSink] 

$ns attach-agent $node_(2) $tcp 

$ns attach-agent $node_(9) $sink 

$ns connect $tcp $sink 

set ftp [new Application/FTP] 

$ftp attach-agent $tcp 

proc plotWindow {tcpSource file} { 

    global ns 

    set time 0.01 

    set now [$ns now] 

    set cwnd [$tcpSource set cwnd_] 

    puts $file “$now $cwnd” 

    $ns at [expr $now+$time] “plotWindow $tcpSource $file” 

proc stop {} { 

    global ns tracefd namtrace 

    $ns flush-trace 

    close $tracefd 

    close $namtrace 

    exec nam testAODV.nam & 

    exit 0 

$ns at 10.0 “$ftp start” 

$ns at $val(stop) “stop” 

$ns run   

Screenshot:

Create the Main.tcl file in the scratch folder

3.Open the Terminal:

Next, we need to launch the terminal by right clicking the mouse in the ns-2.35 location.

Screenshot:

Screenshot:

Open the Terminal

4.NS-2.35 Configuration && Building Process:

Next, we need to configure and build the ns-2.35 folder to make the Created files need to work in ns-2.35 configuration.

Command:      “./make”

Screenshot:

Screenshot:

NS-2.35 Configuration && Building Process

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Screenshot:

NS-2.35 Configuration && Building Process

Here, NS-2.35 Building process completed successfully.

5.Importing Energy-model.h:

Here we imported the Energy-model.h header file code indirectly accessed the Energy-model class used in the Tcl script that we had highlighted lines that tracks how much energy a node consumes during various activities, such as transmitting, receiving, idling and ensures that nodes deplete energy resources realistically over time in the wireless Network in this example program. Here we highlighted the code line that highlighted which is internally accessed Energy-model.h, we will show class file that used in this code via Mobile folder.

Screenshot:

Importing Energy-model.h

Screenshot:

Importing Energy-model.h

Here we will show the header file by opening Energy-model.h file to show the class or function imported from the Energy-model.h in the example code. This Tcl Script Line are configured with Energy-model which tracks how much energy a node consumes during various activities, such as transmitting, receiving, idling and ensures that nodes deplete energy resources realistically over time in the wireless Network with each node in this example program.

Screenshot:

Importing Energy-model.h

Screenshot:

Importing Energy-model.h

6.Executing the Example Program for Energy-model Header:

Then we need to run the Example program for Energy-model Header to view output of the program.

Command:      “./ns Main.tcl”

Screenshot:

Executing the Example Program for Energy-model Header

Here we shown the output of the example program by using Energy-model.h.

Screenshot:

Executing the Example Program for Energy-model Header

Screenshot:

Executing the Example Program for Energy-model Header

Screenshot:

Executing the Example Program for Energy-model Header

In the NS 2.35 Simulation Example Program, the Energy-model.h Header file is successfully imported. Access tailored research services at ns2projects.com. If you need more information about ENERGY-MODEL.H PACKAGES, feel free to contact us! Our development team is here to help you achieve optimal results. We possess all the necessary tools and resources to support you effectively.