Hi,
You can find the task description here at this link:
My task it to plot a graph of Fairness indices against different TCP packet sizes in a wired and wireless network transmission. I am trying to calculate throughput and fairness index values with the proc 'CalculateThroughput {}' and trying to put it in 'myfile' datafile. It prints the throughput values which it has been asked to but is giving an error at the end when it is about to execute Nam. Please go through the script if you can find anything.
This is the whole script.
# This simulation is a combination of wired and wireless topologies.
# Define options
#==============================================================
global opt
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac) Mac/802_11
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL
set opt(ant) Antenna/OmniAntenna
set opt(x) 670
set opt

670
set opt(ifqlen) 50
set opt(tr) wired-and-wireless.tr
set opt(namtr) wired-and-wireless.nam
set opt(nn) 3
set opt(adhocRouting) DSDV
set opt(cp) ""
set opt(sc) "../mobility/scene/scen-3-test"
set opt(finish) 60
#===============================================================
#argument setting for the input by the user
if { $argc != 1 } {
puts "Error: ns script.tcl <TCPpacket_size>, <TCPpacket_size> >= 0"
exit 1
}
set PacketSize_ [expr [lindex $argv 0]]
#setting number of wired and base sation node
set num_wired_nodes 2
set num_bs_nodes 2
#simulator instance
set ns_ [new Simulator]
# set up for hierarchical routing
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 3
lappend cluster_num 2 1 1
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 1 4 1
AddrParams set nodes_num_ $eilastlevel
#open trace and nam file
set tracefd [open $opt(tr) w]
$ns_ trace-all $tracefd
set namtracefd [open $opt(namtr) w]
$ns_ namtrace-all $namtracefd
#open trace file for tcpsizes and fairness indices..
set myfile [open fairnfd.tr w]
#setting up topology of the network
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt
# Define a 'finish' procedure
proc finish {} {
global ns_ tracefd namtracefd myfile
$ns_ flush-trace
close $tracefd
close $namtracefd
close $myfile
exec nam wired-and-wireless.nam &
}
#god needs to know the number of all wireless interfaces
create-god [expr $opt(nn) + $num_bs_nodes]
#create wired nodes
set temp {0.0.0 0.1.0}
for {set i 0} {$i < $num_wired_nodes} {incr i} {
set W($i) [$ns_ node [lindex $temp $i]]
}
#Configure nodes
$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propInstance [new $opt(prop)] \
-phyType $opt(netif) \
-channel [new $opt(chan)] \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace OFF \
-macTrace OFF
#setup base sations
set temp {1.0.0 1.0.1 1.0.2 1.0.3 1.0.4}
set BS(0) [$ns_ node [lindex $temp 0]]
set BS(1) [$ns_ node 2.0.0]
$BS(0) random-motion 0
$BS(1) random-motion 0
$BS(0) set X_ 1.0
$BS(0) set Y_ 2.0
$BS(0) set Z_ 0.0
$BS(1) set X_ 50.0
$BS(1) set Y_ 100.0
$BS(1) set Z_ 0.0
#configure mobilenodes in the base sation domain
$ns_ node-config -wiredRouting OFF
for {set j 0} {$j < $opt(nn)} {incr j} {
set node_($j) [ $ns_ node [lindex $temp \
[expr $j+1]] ]
$node_($j) base-station [AddrParams addr2id [$BS(0) node-addr]]
}
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
$node_(0) set X_ 100.0
$node_(0) set Y_ 200.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 10.0
$node_(1) set Y_ 300.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 100.0
$node_(2) set Y_ 400.0
$node_(2) set Z_ 0.0
#create links between wired and BS nodes
$ns_ duplex-link $W(0) $W(1) 1Mb 10ms DropTail
$ns_ duplex-link $W(1) $BS(0) 1Mb 10ms DropTail
$ns_ duplex-link $W(1) $BS(1) 1Mb 10ms DropTail
$ns_ duplex-link-op $W(0) $W(1) orient down
$ns_ duplex-link-op $W(1) $BS(0) orient left-down
$ns_ duplex-link-op $W(1) $BS(1) orient right-down
# setup TCP connections
set tcp(1) [new Agent/TCP]
$tcp(1) set class_ 2
$tcp(1) set packetSize_ $PacketSize_
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp(1)
$ns_ attach-agent $W(0) $sink1
$ns_ connect $tcp(1) $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp(1)
$ns_ at 5 "$ftp1 start"
set tcp(2) [new Agent/TCP]
$tcp(2) set class_ 2
$tcp(2) set packetSize_ $PacketSize_
set sink2 [new Agent/TCPSink]
$ns_ attach-agent $W(1) $tcp(2)
$ns_ attach-agent $node_(2) $sink2
$ns_ connect $tcp(2) $sink2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp(2)
$ns_ at 5 "$ftp2 start"
#Throughput calculation of the TCP flow
set TCP_Number 2
set STOP 60
set MITTAUS_ALKU 2
proc tallennaAlkutilanne {} {
global TCP_Number tcpBW tcp
for { set i 1 } { $i <= $TCP_Number } { incr i } {
set tcpBW($i) [$tcp($i) set ack_]
}
}
proc CalculateThroughput {} {
global TCP_Number fairness tcp tcpBW myfile PacketSize_
global MITTAUS_ALKU STOP
for { set i 1 } { $i <= $TCP_Number} { incr i } {
set BW($i) [expr [$tcp($i) set ack_] - $tcpBW($i)]
}
set d [expr $STOP - $MITTAUS_ALKU]
for { set i 1 } { $i <= $TCP_Number } { incr i } {
set Throughput($i) [expr 8*$BW($i)/$d * [$tcp($i) set packetSize_ ]]
set Throughput($i) [expr $Throughput($i)+0.00]
}
set x1 [expr ($Throughput(1)+$Throughput(2))*($Throughput(1)+$Throughput(2))]
set x2 [expr ($Throughput(1)*$Throughput(1))+($Throughput(2)*$Throughput(2))]
set x3 [expr 2*$x2]
set fairin_ [expr $x1/$x3]
puts "writing data into tracefile..."
puts $myfile "$PacketSize_ [expr $fairin_+0.00]"
puts "Throughput: $Throughput(1)"
puts "Throughput: $Throughput(2)"
}
#giving initial position to the nodes in the nam
for {set i 0} {$i < $opt(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 20
}
#telling the nodes when to stop
for {set i } {$i < $opt(nn) } {incr i} {
$ns_ at $opt(finish).0000010 "$node_($i) reset";
}
#calling the procedures defined earlier and ending the simulation
$ns_ at [expr $MITTAUS_ALKU] "tallennaAlkutilanne"
$ns_ at [expr $STOP] "CalculateThroughput"
$ns_ at $opt(finish).0000010 "$BS(0) reset";
$ns_ at $opt(finish) "finish"
$ns_ at $opt(finish).1 "puts \"NS EXITING...\" ; $ns_ halt"
puts "Starting Simulation..."
$ns_ run
Thanks.