- Home Page of ProjectGuideline.com ›
- Forums ›
- Get Help to do your B.E., and M.E., M.Tech., & M.S., Project in Ns2 ›
- Throughput and collision measurement in 802.11 AP-mode
Hi!
I am a beginner in Ns-2, but I managed to alter “infra.tcl” script to my needs – I had to model several independent 802.11 g networks. Now I have to calculate the throughput of each of them and to see how the throughput is affected by collision (because networls affect each other). Can anyone help we with throughpu and collision (bit error rate) measurement? Thanks in advance!
This is my script:
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 ;# 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) 20 ;# number of mobilenodes
set val(rp) DumbAgent ;# routing protocol
set val(x) 50
set val(y) 50
Mac/802_11 set dataRate_ 11Mb
#Phy/WirelessPhy set CSThresh_ 10.00e-12
#Phy/WirelessPhy set RXThresh_ 10.00e-11
#Phy/WirelessPhy set Pt_ 0.1
#Phy/WirelessPhy set Pt_ 7.214e-3
# Initialize Global Variables
set ns_ [new Simulator]
set tracefd [open infra.tr w]
set namtrace [open infra.nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
#Open the output files
set f0 [open out0.tr w]
#Define a ‘finish’ procedure
proc finish {} {
global f0 #Close the output files
close $f0
#Call xgraph to display the results
exec xgraph out0.tr -geometry 800×400 &
exit 0
}
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# Create God
create-god $val(nn)
# Create channel
set chan_1_ [new $val(chan)]
$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)
-topoInstance $topo
-agentTrace OFF
-routerTrace OFF
-macTrace ON
-movementTrace OFF
-channel $chan_1_
for {set i 0} {$i < [expr $val(nn)]} {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
set mac_($i) [$node_($i) getMac 0]
$mac_($i) set RTSThreshold_ 3000
}
set sizeRNG [new RNG]
for {set j 0} {$j < $val(nn) } {incr j} {
set randX [$sizeRNG uniform 0 $val(x)];
set randY [$sizeRNG uniform 0 $val(y)];
$node_($j) set X_ $randX
$node_($j) set Y_ $randY
$node_($j) set Z_ 0.000000000000
}
#Set Node 0, Node 10 and Node $val(nn) as the APs.
set AP_ADDR1 [$mac_(0) id]
$mac_(0) ap $AP_ADDR1
set AP_ADDR2 [$mac_([expr $val(nn) – 1]) id]
$mac_([expr $val(nn) – 1]) ap $AP_ADDR2
set AP_ADDR3 [$mac_([expr $val(nn) – 10]) id]
$mac_([expr $val(nn) – 10]) ap $AP_ADDR3
#$mac_([expr $val(nn) – 1]) set BeaconInterval_ 0.2
$mac_(1) ScanType Passive ;#изменил на Passive, было Active
for {set i 2} {$i < [expr $val(nn) - 1]} {incr i} { ;# было ещё & $i != 10
$mac_($i) ScanType PASSIVE ;#Passive
}
;#$ns_ at 1.0 “$mac_(2) ScanType ACTIVE”
Application/Traffic/CBR set packetSize_ 1023
Application/Traffic/CBR set rate_ 256Kb
# TCP connections between node_(10) and node_{11, 16}
set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
for {set i [expr $val(nn) – 10] } {$i < 17 } {incr i} {
$ns_ attach-agent $node_($i) $tcp
$ns_ attach-agent $node_([expr $val(nn) – 10]) $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
}
for {set i 0 } {$i < [expr $val(nn) - 10] } {incr i} {
$ns_ attach-agent $node_($i) $tcp
$ns_ attach-agent $node_(0) $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
}
for {set i [expr $val(nn) – 10]} {$i < [expr $val(nn) - 1] } {incr i} {
$ns_ attach-agent $node_($i) $tcp
$ns_ attach-agent $node_(10) $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
}
#Define a procedure which periodically records the bandwidth received by the
#three traffic sinks sink0/1/2 and writes it to the three files f0/1/2.
proc record {} {
global sink_(0) f0 #Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.5
#How many bytes have been received by the traffic sinks?
set bw0 [$sink_(0) set bytes_]
#Get the current time
set now [$ns now]
#Calculate the bandwidth (in MBit/s) and write it to the files
puts $f0 “$now [expr $bw0/$time*8/1000000]”
#Reset the bytes_ values on the traffic sinks
$sink(0) set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] “record”
}
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} {incr i} {
# 2 defines the node size in nam, must adjust it according to your scenario
# The function must be called after mobility model is defined
$ns_ initial_node_pos $node_($i) 3
}
$ns_ at 5.0 “$ftp start”
$ns_ at 20.0 “stop”
$ns_ at 20.0 “puts “NS EXITING…” ; $ns_ halt”
$ns_ at 20.0 “finish”
proc stop {} {
global ns_ tracefd
$ns_ flush-trace
close $tracefd
exit 0
}
puts “Starting Simulation…”
$ns_ run
[/code]
There are some awk scripts freely available for doing trace analysis. Just use google to find suitable scripts for your requirement. (use suitable keywords like trace analysis, ns2 .awk etc)