How to Install TRACE.H Packages in Ns2

To import Trace.h packages in NS2 we will give to the needed steps that are required for easy installation. Here, we will explain about the Trace.h is capable for overseeing the logging and following of recreation occasions, especially packet-level occasions like sending, getting, dropping, and sending of parcels. The Follow lesson plays a basic part in recording the points of interest of arrange exercises, which are significant for examining and investigating reenactments. It makes a difference analysts and engineers get it the conduct of arrange conventions by giving a nitty gritty follow of each occasion within the recreation. The trace.h record contains the statement of the Follow course, as well as strategies for taking care of different follow operations such as Logs subtle elements almost bundles being sent, gotten, dropped, or sent at distinctive layers of the arrange stack . Records occasions just like the time of transmission, hub IDs, bundle sorts, parcel sizes, and the status of the bundle (whether it was effectively transmitted or dropped). Gives a organized organize for the follow yield, which is ordinarily composed to a record that can be examined after the reenactment completes. Captures point by point data for each bundle, counting source and goal addresses, parcel grouping numbers, and parcel sorts (TCP, UDP, etc.).

Learn to import Trace.h packages in NS2 tool by following the steps listed below and explore top research ideas for your projects with our step-by-step guide.

PRE-REQUISITES:

  1. Fresh installation of Ubuntu 16.04 LTS:

Screenshot:

Fresh installation of Ubuntu 16.04 LTS

2.NS-2.35 Installation:

Screenshot:

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:

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 ns [new Simulator] 

$ns color 0 pink 

$ns color 1 cyan 

$ns color 2 yellow 

set n0 [$ns node] 

set n1 [$ns node] 

set n2 [$ns node] 

set n3 [$ns node] 

set f [open out.tr w] 

$ns trace-all $f 

set nf [open out.nam w] 

$ns namtrace-all $nf 

$ns duplex-link $n0 $n2 5Mb 2ms DropTail 

$ns duplex-link $n1 $n2 5Mb 2ms DropTail 

$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail 

$ns duplex-link-op $n0 $n2 orient right-up 

$ns duplex-link-op $n1 $n2 orient right-down 

$ns duplex-link-op $n2 $n3 orient right 

$ns duplex-link-op $n2 $n3 queuePos 0.5 

set udp0 [new Agent/UDP] 

$ns attach-agent $n0 $udp0 

set cbr0 [new Application/Traffic/CBR] 

$cbr0 attach-agent $udp0 

set udp1 [new Agent/UDP] 

$ns attach-agent $n3 $udp1 

$udp1 set class_ 1 

set cbr1 [new Application/Traffic/CBR] 

$cbr1 attach-agent $udp1 

set null0 [new Agent/Null] 

$ns attach-agent $n3 $null0 

set null1 [new Agent/Null] 

$ns attach-agent $n1 $null1 

$ns connect $udp0 $null0 

$ns connect $udp1 $null1 

$ns at 1.0 “$cbr0 start” 

$ns at 1.1 “$cbr1 start” 

set tcp [new Agent/TCP] 

$tcp set class_ 2 

set sink [new Agent/TCPSink] 

$ns attach-agent $n0 $tcp 

$ns attach-agent $n3 $sink 

$ns connect $tcp $sink 

set ftp [new Application/FTP] 

$ftp attach-agent $tcp 

$ns at 1.2 “$ftp start” 

$ns at 1.35 “$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink” 

puts [$cbr0 set packetSize_] 

puts [$cbr0 set interval_] 

$ns at 3.0 “finish” 

proc finish {} { 

               global ns f nf 

               $ns flush-trace 

               close $f 

               close $nf 

               puts “running nam…” 

               exec nam out.nam & 

               exit 0 

$ns run  

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:

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 Trace.h:

Here we imported the Trace.h header file code indirectly accessed the Trace class used in the Tcl script that we had highlighted lines that instructs the simulator to record all events in a file named `out.tr`. The trace file will log every packet transmission, reception, and drop event throughout the simulation in the Network in this example program. Here we highlighted the code line that highlighted which is internally accessed Trace.h, we will show class file that used in this code via Trace folder.

Screenshot:

Screenshot:

Here we will show the header file by opening Trace.h file to show the class or function imported from the Trace.h in the example code. This Tcl Script Line are configured with Trace which instructs the simulator to record all events in a file named `out.tr`. The trace file will log every packet transmission, reception, and drop event throughout the simulation in the Network with each node in this example program.

Screenshot:

Importing Trace.h

Screenshot:

Importing Trace.h

6.Executing the Example Program for Trace Header:

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

Command:      “./ns Main.tcl”

Screenshot:

Executing the Example Program for Trace Header

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

Screenshot:

Executing the Example Program for Trace Header

Screenshot:

Executing the Example Program for Trace Header

Screenshot:

Executing the Example Program for Trace Header

Screenshot:

Executing the Example Program for Trace Header

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