In this report, I will try to re-do the simulations at
http://www.ece.rice.edu/~jpr/ns/docs/ns-802_11b.html.
Note. If you want to execute the following example, please read
http://140.116.164.80/~smallko/ns2/tool_en.htm (see method 2).
[Tcl script] (file name: test.tcl)
if {$argc !=2} {
puts "Usage: ns test.tcl RTSThreshold PacketSize "
puts "Example:ns test.tcl 3000 144"
exit
}
set par1 [lindex $argv 0]
set par2 [lindex $argv 1]
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
Mac/802_11 set RTSThreshold_ $par1 ;# bytes
Mac/802_11 set ShortRetryLimit_ 7 ;# retransmittions
Mac/802_11 set LongRetryLimit_ 4 ;# retransmissions
Mac/802_11 set PreambleLength_ 72 ;# 72 bit
Mac/802_11 set dataRate_ 11Mb
set val(rp) DumbAgent
set ns [new Simulator]
set f [open test.tr w]
$ns trace-all $f
$ns eventtrace-all
set nf [open test.nam w]
$ns namtrace-all-wireless $nf 500 500
# set up topography object
set topo [new Topography]
$topo load_flatgrid 500 500
# Create God
create-god 2
# create channel
set chan [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) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace OFF \
-macTrace ON \
-movementTrace OFF
for {set i 0} {$i < 2} {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0
}
$node_(0) set X_ 30.0
$node_(0) set Y_ 30.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 200.0
$node_(1) set Y_ 30.0
$node_(1) set Z_ 0.0
set udp [new Agent/mUDP]
#set the sender trace file name to sd
$udp set_filename sd
$ns attach-agent $node_(0) $udp
set null [new Agent/mUdpSink]
#set the receiver filename to rd
$null set_filename rd
$ns attach-agent $node_(1) $null
$ns connect $udp $null
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ $par2
$cbr set rate_ 10Mb
$cbr set random_ false
$ns at 0.0 "$cbr start"
$ns at 15.0 "$cbr stop"
for {set i 0} {$i < 2} {incr i} {
$ns initial_node_pos $node_($i) 30
$ns at 20.0 "$node_($i) reset";
}
$ns at 20.0 "finish"
$ns at 20.1 "puts \"NS EXITING...\"; $ns halt"
#INSERT ANNOTATIONS HERE
proc finish {} {
global ns f nf val
$ns flush-trace
close $f
close $nf
}
puts "Starting Simulation..."
$ns run
[throughput parsing perl script] ( file name: throughput.pl)
#使用方法: perl throughput.pl <trace file> <granlarity>
#記錄檔檔名
$infile=$ARGV[0];
#多少時間計算一次(單位為秒)
$granularity=$ARGV[1];
$sum=0;
$sum_total=0;
$clock=0;
$maxrate=0;
$init=0;
#打開記錄檔
open (DATA,"<$infile")
|| die "Can't open $infile $!";
#讀取記錄檔中的每行資料,資料是以空白分成眾多欄位
while (<DATA>) {
@x = split(' ');
if($init==0){
$start=$x[2];
$init=1;
}
#讀取的第一個欄位是時間
#判斷所讀到的時間,是否已經達到要統計吞吐量的時候
if ($x[2]-$clock <= $granularity)
{
#計算單位時間內累積的封包大小
$sum=$sum+$x[4];
#計算累積的總封包大小
$sum_total=$sum_total+$x[4];
}
else
{
#計算吞吐量
$throughput=$sum*8.0/$granularity;
if ($throughput > $maxrate){
$maxrate=$throughput;
}
#輸出結果: 時間 吞吐量(bps)
print STDOUT "$x[2]: $throughput bps\n";
#設定下次要計算吞吐量的時間
$clock=$clock+$granularity;
#把累積量規零
$sum=0;
}
}
$endtime=$x[2];
#計算最後一次的吞吐量大小
$throughput=$sum*8.0/$granularity;
print STDOUT "$x[2]: $throughput bps\n";
$clock=$clock+$granularity;
$sum=0;
#print STDOUT "$sum_total $start $endtime\n";
$avgrate=$sum_total*8.0/($endtime-$start);
print STDOUT "Average rate: $avgrate bps\n";
print STDOUT "Peak rate: $maxrate bps\n";
#關閉檔案
close DATA;
exit(0);
l If no RTS/CTS and the packet size is set to 128, then run the command as follows
$ns test.tcl 3000 128
After simulation, run the throughput parsing program
$perl throughput.pl rd 1.0
Then you can get the average throughput of 1237668 bps.
l If RTS/CTS is on and the packet size is set to 128, then run the commands as follows.
$ns test.tcl 0 128
After simulation, run the throughput parsing program
$perl throughput.pl rd 1.0
Then you can get the average throughput of 750428 bps.
Try to complete all the settings. Although the simulation results are not the same, the results are close to the results in that webpage.
Last modified date: 2006/04/25
Author: Chih-Heng, Ke
Email: smallko@ee.ncku.edu.tw