How to Install MOBILE NODE.H Packages in Ns2

To import the mobilnode.h packages in NS2, please review the concepts we’ve shared and feel free to gather innovative research ideas from us. To get more research details on mobilnode.h packages in ns2tool our team will help you with best outcomes.

MobileNode.h plays a crucial role in simulating mobile nodes within wireless and mobile ad hoc network settings. It models the behavior of nodes that traverse the simulation area, engaging with other nodes through wireless communication. This file encompasses class declarations and methods that manage mobility, radio propagation, and interactions among nodes in a dynamic environment. The MobileNode incorporates various components, such as defining movement patterns within the simulation space, enabling users to replicate different mobility scenarios, including random waypoint mobility or tailored trajectories. It interacts with both the physical layer and the MAC layer to emulate packet transmission and reception as nodes navigate. Additionally, it collaborates with routing protocols to facilitate route discovery and maintenance in mobile networks. Key features of the MobileNode include tracking and updating node positions, managing handoffs when a node transitions out of one access point’s range and into another’s, and adapting to changes in topologies and connectivity due to node movement. A mobile node is instantiated, its position established within the simulation area, and then assigned a destination and speed through the setdest method, effectively simulating mobility.

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:

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:

Create the Main.tcl file in the scratch folder

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)        Antenna/OmniAntenna    

set val(ifqlen)     50                      

set val(nn)         10                 

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 for mobile nodes

$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:

Open the Terminal

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:

NS-2.35 Configuration && Building Process

Screenshot:

NS-2.35 Configuration && Building Process

Screenshot:

NS-2.35 Configuration && Building Process

Here, NS-2.35 Building process completed successfully.

5.Importing Mobilenode.h:

Here we imported the Mobilenode.h header file code indirectly accessed the Mobilenode class used in the Tcl script that we had highlighted lines are used for simulating the behaviour of a node that can move across the simulation area, interacting with other nodes through wireless Network communication in this example program. Here we highlighted the code line that highlighted which is internally accessed Mobilenode.h, we will show class file that used in this code via Common folder.

Screenshot:

Importing Mobilenode.h

Screenshot:

Importing Mobilenode.h

Here we will show the header file by opening Mobilenode.h file to show the class or function imported from the Mobilenode.h in the example code. This Tcl Script Line are used for simulating the behaviour of a node that can move across the simulation area, interacting with other nodes through wireless Network communication in this example program.

Screenshot:

Importing Mobilenode.h

Screenshot:

Importing Mobilenode.h

6.Executing the Example Program for Mobilenode Header:

Then we need to run the Example program for Mobilenode Header to view output of the program.

Command:      “./ns Main.tcl”

Screenshot:

Executing the Example Program for Mobilenode Header

Here we shown the output of the example program by using Mobilenode.h.

Screenshot:

Executing the Example Program for Mobilenode Header

Screenshot:

Executing the Example Program for Mobilenode Header

Screenshot:

Executing the Example Program for Mobilenode Header

In the NS 2.35 Simulation Example Program, the Mobilenode.h Header file is successfully imported.