How to generate xgraph for routing overhead for wired network in ns2

Description

Wired Network with communication model is established using TCL script. Execution of tcl script generates a trace file with all simulation events recorded in it. Routing Overhead is calculated using awk script which processes the trace file and produces the result in a file with .xg extension. Xgraph for Routing Overhead is plotted using the results (.xg file) obtained from the execution of awk script.

# Filename: test18.tcl
$ns rtproto LS
# —————-ESTABLISHING COMMUNICATION ————-#

#————–TCP CONNECTION BETWEEN NODES—————#
$ns at 0.0 "Tranmission"
proc Tranmission {} {
global C ROU R ns

set now [$ns now]
set time 10.0
set x 3
set y 4

set tcp1 [$ns create-connection TCP $C($x) TCPSink $R($y) 1]
$ns at $now "$ns trace-annotate \"Time: $now Pkt Transfer between Client($x) Receiver($y)..\""
$tcp1 set class_ 1
$tcp1 set maxcwnd_ 16
$tcp1 set packetsize_ 4000
$tcp1 set fid_ 1
set ftp1 [$tcp1 attach-app FTP]
$ftp1 set interval_ .005
$ns at $now "$ftp1 start"
$ns at [expr $now+$time] "$ftp1 stop"

}

exec awk -f RoutingOverhead.awk test18.tr > routingoverhead.xg &
exec xgraph -P -bg white -t Routing_Overhead -x time(s) -y RoutingOverhead(packets) routingoverhead.xg &
###################################################################

#filename: RoutingOverhead.awk

#——— Formula ————:

Routing Overhead = RoutingPacketsCount

#——— AWK script Format——–#

The script has the following format:
BEGIN {}
{
content
}
END {}
Begin part comprises of initialization of variable.
Commands in the content part scan every row of trace file only once.
Ex:
if (pattern) {
action;
}

If the pattern is matched with the line in the trace in the trace file specified action will be performed.

In the END part final calculation is performed on the data obtained from the content part.

#——— Steps ————:
1. set pattern and action for routing packets
2. print the result in .xg file

Routing process

Xgraph generation for routing overhead for wired network in ns2
Xgraph generation for routing overhead for wired network in ns2