How To Install Address.H Packages in Ns2
The Address Header, as defined in the address.h file, plays a crucial role in the management of addressing schemes utilized in network simulations. This class offers various methods for managing network node addresses, associating addresses with their corresponding nodes, and facilitating conversions among different address formats. The address.h file is vital for ensuring effective routing and communication between nodes, as it oversees both hierarchical and flat addressing schemes. It is instrumental in the organization and identification of nodes across diverse network topologies.
In the TCL script, the functionality of address.h is utilized indirectly via simulation commands. TCL scripts enable users to assign and manage node addresses without the necessity of directly incorporating the address.h file. The internal connection between TCL and the C++ codebase in NS-2 guarantees that addressing tasks such as node identification, routing, and message forwarding are smoothly incorporated into the simulation framework, allowing for dynamic configuration of node addresses throughout the simulations.
To implement Address_ Packages in NS2, please refer to the steps we have provided .
PRE-REQUISITES:
- Fresh installation of Ubuntu 16.04 LTS:
Screenshot:
2.NS-2.35 Installation:
Screenshot:
Here, Percentage (%) symbol Denotes the successful installation of the NS 2.35 Simulator.
Screenshot:
HEADER FILE VERIFICATION:
- Locate to the ns-2.35 folder:
Screenshot:
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 ns [new Simulator]
set tracefile [open out.tr w]
$ns trace-all $tracefile
set namfile [open out.nam w]
$ns namtrace-all $namfile
set nodeCount 6
# Address will be assign for each nodes
for {set i 0} {$i < $nodeCount} {incr i} {
set node($i) [$ns node]
puts “Node $i address: [$node($i) id]”
}
$node(0) set X_ 10
$node(0) set Y_ 20
$node(0) set Z_ 0
$node(1) set X_ 50
$node(1) set Y_ 20
$node(1) set Z_ 0
$node(2) set X_ 100
$node(2) set Y_ 20
$node(2) set Z_ 0
$node(3) set X_ 150
$node(3) set Y_ 20
$node(3) set Z_ 0
$node(4) set X_ 200
$node(4) set Y_ 20
$node(4) set Z_ 0
$node(5) set X_ 250
$node(5) set Y_ 20
$node(5) set Z_ 0
for {set i 0} {$i < $nodeCount-1} {incr i} {
$ns duplex-link $node($i) $node([expr $i+1]) 1Mb 10ms DropTail
}
set udp0 [new Agent/UDP]
$ns attach-agent $node(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 512
$cbr0 set rate_ 1Mb
set null0 [new Agent/Null]
$ns attach-agent $node(5) $null0
$ns connect $udp0 $null0
$ns at 0.5 “$cbr0 start”
$ns at 10.0 “finish”
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns run
3.Open the Terminal:
Next, we need to launch the terminal by right clicking the mouse in the ns-2.35 location.
Screenshot:
Screenshot:
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:
Screenshot:
Here, NS-2.35 Building process completed successfully.
5.Importing Address.h:
Here we imported the Address.h header file code indirectly accessed the Address class define a get_nodeaddr(int address) method, used in the Tcl script (set node($i) [$ns node]), Sets a Unique Address for each nodes in this example program. Here we highlighted the code line that highlighted which is internally accessed Address.h that we will show class file that used in this code via Routing folder.
Screenshot:
Screenshot:
Here we will show the header file by opening Address.h file to show the class or function imported from the Address.h in the example code. “set node($i) [$ns node]” eventually instantiating to extract the node part of an address, which is what the [$node($i) id] method in the Tcl script internally relies on when Assigning & printing node addresses.
Screenshot:
Screenshot:
6.Executing the Example Program for Packet Header:
Then we need to run the Example program for Packet Header to view output of the program.
Command: “./ns Main.tcl”
Screenshot:
Here we shown the output of the example program by using Address.h.
Screenshot:
Screenshot:
Screenshot:
Here, we have shown the out.tr file for Output of the Communication of the Network done in the simulation.
Screenshot:
In the NS 2.35 Simulation Example Program, the Address.h Header file is successfully imported.
For all types of Address.h_Importation feel free to share with us your project details we will help you with best outcomes, get tailored research services from ns2projects.com.