An example to measure the throughput of TCP-based application over wire-cum-wireless environment

 

[Preparation]

1.        Follow the steps of method2 at http://csie.nqu.edu.tw/smallko/ns2_old/tool_en.htm

2.        Download mtcpsink.cc, mtcpsink.h

3.        Put these two files into measure folder

4.        Add the “measure/mtcpsink.o” in the OBJ_CC of Makefile

5.        make clean; make

 

[TCL script] (test-tcp.tcl)

 

set ns [new Simulator]

set num_wired_nodes  1

set num_mobile_nodes 1

set num_bs_nodes     1 ;# number of base stations

set num_nodes [expr $num_wired_nodes + $num_mobile_nodes + $num_bs_nodes]

set bs_id $num_wired_nodes

 

# Parameter for wireless nodes

set opt(chan)           Channel/WirelessChannel    ;# channel type

set opt(prop)           Propagation/TwoRayGround   ;# radio-propagation model

set opt(netif)          Phy/WirelessPhy            ;# network interface type

set opt(mac)            Mac/802_11                 ;# MAC type

set opt(ifq)                Queue/DropTail/PriQueue

set opt(ifqlen)         50

set opt(ll)             LL                         ;# link layer type

set opt(ant)            Antenna/OmniAntenna        ;# antenna model

set opt(adhocRouting)   NOAH                       ;# routing protocol

set opt(x)          500          ;# X dimension of the topography

set opt(y)          500          ;# Y dimension of the topography

 

Mac/802_11 set SlotTime_          0.000020        ;# 20us

Mac/802_11 set SIFS_              0.000010        ;# 10us

Mac/802_11 set PreambleLength_    144             ;# 144 bit

Mac/802_11 set PLCPHeaderLength_  48              ;# 48 bits

Mac/802_11 set PLCPDataRate_      1.0e6           ;# 1Mbps

Mac/802_11 set dataRate_          11.0e6           ;# 11Mbps

Mac/802_11 set basicRate_         1.0e6           ;# 1Mbps

Mac/802_11 set RTSThreshold_       3000

Mac/802_11 set ShortRetryLimit_       7               ;# retransmittions

Mac/802_11 set LongRetryLimit_        4               ;# retransmissions

 

#set up for hierarchical routing

#(needed for routing over a basestation)

$ns node-config -addressType hierarchical

AddrParams set domain_num_ 2          ;# domain number

lappend cluster_num 1 1               ;# cluster number for each domain

AddrParams set cluster_num_ $cluster_num

lappend eilastlevel $num_wired_nodes [expr $num_mobile_nodes + $num_bs_nodes] ;# number of nodes for each cluster            

AddrParams set nodes_num_ $eilastlevel

 

set ntr [open out.tr w]

$ns trace-all $ntr

 

set chan    [new $opt(chan)]

set topo    [new Topography]

$topo load_flatgrid $opt(x) $opt(y)

 

# Create God

create-god [expr $num_mobile_nodes + $num_bs_nodes]

 

# creating wired nodes

set s1 [$ns node 0.0.0]

 

# creating base station

$ns node-config -adhocRouting $opt(adhocRouting) \

                 -llType $opt(ll) \

                 -macType $opt(mac) \

                 -ifqType $opt(ifq) \

                 -ifqLen $opt(ifqlen) \

                 -antType $opt(ant) \

                 -propType $opt(prop)    \

                 -phyType $opt(netif) \

                 -channel $chan      \

                 -topoInstance $topo \

                 -wiredRouting ON \

                 -agentTrace OFF \

                 -routerTrace OFF \

                 -macTrace OFF    \

                 -movementTrace OFF

 

set BS(0) [$ns node 1.0.0]

$BS(0) random-motion 0

puts "Base-Station node $bs_id created"

#provide some co-ord (fixed) to base station node

$BS(0) set X_ 250.0

$BS(0) set Y_ 250.0

$BS(0) set Z_ 0.0

 

set  rng  [new RNG]

$rng seed 1

set  rand1  [new RandomVariable/Uniform]

$rand1  use-rng $rng

$rand1  set  min_ -50.0

$rand1  set  max_ 50.0

 

# creating mobile nodes

$ns node-config -wiredRouting OFF

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

    set wl_node_($i) [$ns node 1.0.[expr $i + 1]]  

    $wl_node_($i) random-motion 0               ;# disable random motion

    puts "wireless node $i created ..."

    $wl_node_($i) base-station [AddrParams addr2id [$BS(0) node-addr]]

    set x [expr 250+[$rand1 value]]

    set y [expr 250+[$rand1 value]]

    $wl_node_($i) set X_ $x

    $wl_node_($i) set Y_ $y

    $wl_node_($i) set Z_ 0.0

    puts "X_:$x Y_:$y"

}

 

# linking of wired node to base-station node

$ns duplex-link $s1 $BS(0) 100Mb 1ms DropTail

 

set tcp1 [new Agent/TCP/Reno]

$ns attach-agent $s1 $tcp1

set tcpsink1 [new Agent/TCPSink/mTcpSink]

$tcpsink1 set_filename tcp_sink

$ns attach-agent $wl_node_(0) $tcpsink1

$ns connect $tcp1 $tcpsink1

set ftp1 [$tcp1 attach-source FTP]

 

proc stop {} {

    global ns ntr

    $ns flush-trace

    close $ntr

}

 

$ns at  0.0 "$ftp1 start"

$ns at 45.0 "$ftp1 stop"

$ns at 50.0 "$tcpsink1 closefile"

$ns at 50.1] "stop"

$ns at 50.2  "puts \"NS EXITING...\" ; $ns halt"

$ns run

 

After running the script, you will get “tcp_sink”.

1                0.003497         40             

2                0.007974         1040           

3                0.009467         1040           

4                0.013904         1040           

5                0.015277         1040            

6                0.016750         1040           

7                0.018923         1040           

8                0.022197         1040           

9                0.024490         1040           

10               0.027323         1040            

11               0.028776         1040           

12               0.030189         1040           

13               0.031582         1040           

14               0.033035         1040           

15               0.035128         1040            

16               0.036761         1040            

………………………………………………………………………….

 

[use perl to calculate the throughput] (throughput.pl)

#使用方法: perl throughput.pl <trace file> <granlarity>

 

#記錄檔名

$infile=$ARGV[0];

 

#多少時間計算一次(單位為秒)

$granularity=$ARGV[1];

 

$sum=0;

$sum_total=0;

$clock=0;

$init=0;

 

#打開記錄

open (DATA,"<$infile")

    || die "Can't open $infile $!";

       

#讀取記錄中的每行資料,資料是以空白分成眾多欄位 

while (<DATA>) {

        @x = split(' ');

       

        if($init==0){

          $start=$x[1];

          $init=1;

        }

 

        #讀取的第一個欄位是時間

        #判斷所讀到的時間,是否已經達到要統計吞吐量的時候

        if ($x[1]-$clock <= $granularity)

        {

                #計算單位時間內累積的封包大小

                    $sum=$sum+$x[2];

                   

             #計算累積的總封包大小

                    $sum_total=$sum_total+$x[2];

        }

        else

        {

                #計算吞吐量

               $throughput=$sum*8.0/$granularity;

              

               #輸出結果: 時間 吞吐量(bps)

                    print STDOUT "$x[1]: $throughput bps\n";

                   

                    #設定下次要計算吞吐量的時間

                    $clock=$clock+$granularity;

                   

                    #計算單位時間內累積的封包大小

                    $sum=$sum+$x[1];

                   

                    #把累積量規零

                    $sum=0;

        }  

}

 

$endtime=$x[1];

 

#計算最後一次的吞吐量大小  

$throughput=$sum*8.0/$granularity;

print STDOUT "$x[1]: $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";

 

#關閉檔案

close DATA;

exit(0);

 

Each 1 second, we calculate the TCP throughput.

$perl throughput.pl tcp.sink 1.0

……………………………………………………………………………………

42.003966: 3502720 bps

43.000810: 3452800 bps

44.001948: 3452800 bps

45.001001: 3494400 bps

45.026674: 83200 bps

Average rate: 3463041.26872255 bps

 

 

Last modified: 2006/06/12

 

Author : Chih-Heng, Ke

Website: http://csie.nqu.edu.tw/smallko

Email: smallko@ee.ncku.edu.tw

Phd candidate, EE Department, NCKU, Taiwan