Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to calculate Throughput using awk script in NS2?

Description

Throughput is the number of successfully received packets in a unit time and it is represented in bps. Throughput is calculated using awk script which processes the trace file and produces the result.

Sample Code

# Filename: sample27.tcl
# Simulator Instance Creation
set ns [new Simulator]

#Fixing the co-ordinate of simulation area
set val(x) 500
set val(y) 500
# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 3 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 500 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

#Nam File Creation nam – network animator
set namfile [open sample27.nam w]

#Tracing all the events and cofiguration
$ns namtrace-all-wireless $namfile $val(x) $val(y)

#Trace File creation
set tracefile [open sample27.tr w]

#Tracing all the events and cofiguration
$ns trace-all $tracefile

# general operational descriptor- storing the hop details in the network
create-god $val(nn)

# configure the 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 ON \
-macTrace OFF \
-movementTrace ON

# Node Creation

for {set i 0} {$i < 3} {incr i} {

set node_($i) [$ns node]
$node_($i) color black

}

#Location fixing for a single node

$node_(0) set X_ 258
$node_(0) set Y_ 222
$node_(0) set Z_ 0

for {set i 1} {$i < 3} {incr i} {

$node_($i) set X_ [expr rand()*$val(x)]
$node_($i) set Y_ [expr rand()*$val(y)]
$node_($i) set Z_ 0

}
# Label and coloring

for {set i 0} {$i < 3} {incr i} {

$ns at 0.1 "$node_($i) color blue"
$ns at 0.1 "$node_($i) label Node$i"

}
#Size of the node

for {set i 0} {$i < 3} {incr i} {

$ns initial_node_pos $node_($i) 30

}
#******************************Defining Communication Between node0 and all nodes ****************************8

for {set i 1} {$i < 3} {incr i} {

# Defining a transport agent for sending
set udp [new Agent/UDP]

# Attaching transport agent to sender node
$ns attach-agent $node_($i) $udp

# Defining a transport agent for receiving
set null [new Agent/Null]

# Attaching transport agent to receiver node
$ns attach-agent $node_(0) $null

#Connecting sending and receiving transport agents
$ns connect $udp $null

#Defining Application instance
set cbr [new Application/Traffic/CBR]

# Attaching transport agent to application agent
$cbr attach-agent $udp

#Packet size in bytes and interval in seconds definition
$cbr set packetSize_ 512
$cbr set interval_ 0.1

# data packet generation starting time
$ns at 1.0 "$cbr start"

# data packet generation ending time
#$ns at 6.0 "$cbr stop"

}
# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"

#Stopping the scheduler
$ns at 10.01 "puts \"end simulation\" ; $ns halt"
#$ns at 10.01 "$ns halt"

exec awk -f Throughput.awk sample27.tr > Throughput.tr &
#Starting scheduler
$ns run

#################################################################

############################################
#filename:Throughput.awk

#——— Formula ————:

Throughput = received_data*8/DataTransmissionPeriod

#——— 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 received data
2. apply the received data value in the formula to calculate throughput in bits/s

#################################################################

Execution:

ns sample27.tcl

 

Screenshots

file: Throughput.tr

Throughput = 3.45522MB/s


calculate Throughput using awk script in NS2