How to vary the wireless error rate during simulation ?

 

[preparation]

1.      Install cygwin + myNS2

2.      Read Video transmission over wireless error channels and tool introduction.

 

 

[Tcl Script] (file name: test_bsc_multicast.tcl)

 

#網路的拓樸

#   Video               MyUdpSink

#   W(0) ------ HA------MH(0)

#  sorce -----> HA------MH

 

#設定base station的數目

set opt(num_FA) 1

 

#loss_model: 0 for uniform distribution, 1 for GE model

set loss_model  0

 

#comm_type: 0 for broacdcast, 1 for unicast

set comm_type 0

 

#產生一個模擬的物件

set ns_ [new Simulator]

 

#使用hierarchial addressing的方式定址

$ns_ node-config -addressType hierarchical

 

#設定有兩個domain,domain各有一個cluster

#第一個cluster(wired)有一個node,第二cluster(wireles)有兩個node (base state + mobile node)

AddrParams set domain_num_ 2

lappend cluster_num 1 1

AddrParams set cluster_num_ $cluster_num

lappend eilastlevel 1 2

AddrParams set nodes_num_ $eilastlevel

 

#設定記錄檔,把模擬過程都記錄下來

set tracefd [open bsc_multicast.tr w]

$ns_ trace-all $tracefd

 

#設定mobile node的個數

set opt(nnn) 1

 

# 拓樸的範圍為 100m x 100m

set topo [new Topography]

$topo load_flatgrid 100 100

 

#create god

set god_ [create-god [expr $opt(nnn)+$opt(num_FA)]]

 

# wired nodes

set W(0) [$ns_ node 0.0.0]

 

# create channel

set chan_ [new Channel/WirelessChannel]

 

#設定節點參數

$ns_ node-config     -mobileIP ON \

                      -adhocRouting NOAH \

                  -llType LL \

                  -macType Mac/802_11 \

                  -ifqType Queue/DropTail/PriQueue \

                  -ifqLen 2000 \

                  -antType Antenna/OmniAntenna \

                          -propType Propagation/TwoRayGround \

                          -phyType Phy/WirelessPhy \

                  -channel $chan_ \

                         -topoInstance $topo \

                  -wiredRouting ON\

                          -agentTrace OFF \

                  -routerTrace OFF \

                  -macTrace OFF

 

#設定base station節點

set HA [$ns_ node 1.0.0]

set HAnetif_ [$HA set netif_(0)]

$HAnetif_ set-error-level 0 0 0 0 $loss_model

 

#設定mobile node的參數

#不需要wired routing,所以把此功能off

$ns_ node-config -wiredRouting OFF

set MH(0) [$ns_ node 1.0.1]

set MHnetif_(0) [$MH(0) set netif_(0)]

 

#Initially, set the error rate to 0

$MHnetif_(0) set-error-level 0 0 0 0 $loss_model

 

#At 10.0 second, set the error rate to 0.5

$ns_ at 10.0 "$MHnetif_(0) set-error-level 0 0 0.5 0 $loss_model"

 

#At 40.0 second, set the error rate to 0

$ns_ at 40.0 "$MHnetif_(0) set-error-level 0 0 0 0 $loss_model"

 

#把此mobile node跟前面的base station節點做連結

[$MH(0)  set regagent_] set home_agent_ [AddrParams addr2id [$HA node-addr]]

 

#設定base station的位置在(100.0, 100.0)

$HA set X_ 100.0

$HA set Y_ 100.0

$HA set Z_ 0.0

 

#設定mobile node的位置在(80.0, 80.0)

$MH(0) set X_ 80.0

$MH(0) set Y_ 80.0

$MH(0) set Z_ 0.0

 

#wired nodebase station之間建立一條連線

$ns_ duplex-link $W(0) $HA 10Mb 10ms myfifo

set q1       [[$ns_ link $W(0) $HA] queue]

 

set udp [new Agent/mUDP]

#set the sender trace file name to sd

$udp set_filename sd

$ns_ attach-agent $W(0) $udp

 

set forwarder_ [$HA  set forwarder_]

puts [$forwarder_ port]

$ns_ connect $udp $forwarder_

$forwarder_ dst-addr [AddrParams addr2id [$MH(0) node-addr]]

$forwarder_ comm-type $comm_type

 

set null [new Agent/mUdpSink]

#set the receiver filename to rd

$null set_filename rd

$ns_ attach-agent $MH(0) $null

$ns_ connect $udp $null

 

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set type_ CBR

$cbr set packet_size_ 1000

$cbr set rate_ 1Mb

$cbr set random_ false

 

$ns_ at 0.0 "$cbr start"

$ns_ at 50.0 "$cbr stop"

$ns_ at 50.1 "$MH(0) reset";

$ns_ at 50.0001 "$W(0) reset"

$ns_ at 50.0002 "stop "

$ns_ at 50.0003  "$ns_  halt"

 

#設定一個stop的程序

proc stop {} {

    global ns_

    global tracefd

   

    #關閉記錄

    close $tracefd

}

 

#執行模擬

$ns_ run

 

Execution simulation:

 

 

After simulation, the sender trace file (sd) and the receiver trace file (rd) are generated.

sd

0                0.000000         1000           

1                0.008000         1000           

2                0.016000         1000           

3                0.024000         1000           

4                0.032000         1000            

5                0.040000         1000           

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

 

column 0: packet id; column 1: packet sending time; column 2: packet size

 

rd

0                0.000000         0.022604         0.022604         1000           

1                0.008000         0.032300         0.024300         1000           

2                0.016000         0.042236         0.026236         1000           

3                0.024000         0.052013         0.028013         1000           

4                0.032000         0.061689         0.029689         1000           

5                0.040000         0.071386         0.031386         1000           

6                0.048000         0.081022         0.033022         1000  

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

column 0: packet id; column 1: packet sending time; column2: packet receiving time; column 3: end-to-end delay; column 4: packet size

 

 

Parsing the throughput (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);

 

 

Parsing the result:

$perl throughput.pl rd 1

1.005898: 808000 bps

2.008333: 808000 bps

3.008638: 808000 bps

4.004449: 800000 bps

5.006966: 808000 bps

6.005089: 808000 bps

7.000482: 800000 bps

8.007642: 808000 bps

9.003153: 800000 bps

10.008157: 808000 bps

11.001218: 344000 bps

12.017854: 368000 bps

13.014576: 368000 bps

14.008435: 432000 bps

15.009277: 424000 bps

16.006631: 320000 bps

17.001956: 400000 bps

18.001959: 384000 bps

19.012253: 448000 bps

20.007894: 504000 bps

21.041371: 416000 bps

22.018773: 352000 bps

23.067804: 384000 bps

24.022132: 304000 bps

25.010523: 464000 bps

26.006661: 392000 bps

27.002642: 408000 bps

28.028958: 416000 bps

29.017351: 352000 bps

30.041349: 408000 bps

31.014940: 312000 bps

32.025908: 408000 bps

33.000755: 384000 bps

34.004545: 392000 bps

35.017949: 360000 bps

36.022990: 384000 bps

37.017209: 416000 bps

38.008508: 440000 bps

39.063724: 376000 bps

40.018592: 368000 bps

41.005137: 792000 bps

42.008068: 808000 bps

43.005950: 800000 bps

44.008706: 800000 bps

45.007241: 808000 bps

46.008820: 800000 bps

47.008366: 800000 bps

48.009651: 808000 bps

49.005323: 800000 bps

49.994861: 808000 bps

Average rate: 556468.762257426 bps

Peak rate: 808000 bps

 

Analysis: From the results, we can see that from 0~10 seconds, the throughput is around 808000 bps (the error rate is set to 0). From 10~40 seconds, there is a big drop in throughput (the error rate is set to 0.5). After 40 second, the throughput goes back to 808000 bps (the error rate is set to 0).

 

 

Last modified: 2006/04/21

 

Author : Chih-Heng, Ke

Website: http://140.116.164.80/~smallko

Email: smallko@ee.ncku.edu.tw

Phd candidate, EE Department, NCKU, Taiwan