计算机网路实验使用NS模拟多媒体通讯与无线网路实验.ppt

上传人:本田雅阁 文档编号:2260793 上传时间:2019-03-12 格式:PPT 页数:29 大小:415.01KB
返回 下载 相关 举报
计算机网路实验使用NS模拟多媒体通讯与无线网路实验.ppt_第1页
第1页 / 共29页
计算机网路实验使用NS模拟多媒体通讯与无线网路实验.ppt_第2页
第2页 / 共29页
计算机网路实验使用NS模拟多媒体通讯与无线网路实验.ppt_第3页
第3页 / 共29页
亲,该文档总共29页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《计算机网路实验使用NS模拟多媒体通讯与无线网路实验.ppt》由会员分享,可在线阅读,更多相关《计算机网路实验使用NS模拟多媒体通讯与无线网路实验.ppt(29页珍藏版)》请在三一文库上搜索。

1、計算機網路實驗- 使用NS2模擬多媒體通訊與無線網路(實驗四),指導教授:許子衡老師 學生:羅英辰,2010/3/5,2,網路模擬,結束模擬後,通常我們會要用到過程中產生的記錄來分析以得到吞吐量(Throughput)、封包延遲(Packet delay)、抖動率(Jitter)和封包遺失率(Packet loss rate)。 以下就是有線網路記錄的格式:,2010/3/5,3,tcp,sink,sink,udp,r,d,s1,s2,ftp,cbr,2Mbps, 10ms,2Mbps, 10ms,1.7Mbps, 20ms,ftp,cbr,0.1 1.0 4.0 4.5,sec,2010/3

2、/5,4,2010/3/5,5,2010/3/5,6,#使用方法: perl measure-throughput.pl #記錄檔檔名 $infile=$ARGV0; #多少時間計算一次(單位為秒) $granularity=$ARGV1; $sum=0; $sum_total=0; $clock=0; $maxrate=0; $init=0; #打開記錄檔 open (DATA,“$infile“) | die “Cant open $infile $!“;,UDP的吞吐量計算,2010/3/5,7,#讀取記錄檔中的每行資料,資料是以空白分成眾多欄位 while () x = split(

3、); if($init=0) $start=$x2; $init=1; #讀取的第零個欄位是pkt_id #讀取的第一個欄位是封包傳送時間 #讀取的第二個欄位是封包接收時間 #讀取的第三個欄位是封包end to end delay #讀取的第四個欄位是封包大小 #判斷所讀到的時間,是否已經達到要統計吞吐量的時候 if ($x2-$clock = $granularity) #計算單位時間內累積的封包大小 $sum=$sum+$x4; #計算累積的總封包大小 $sum_total=$sum_total+$x4; ,2010/3/5,8,else #計算吞吐量 $throughput=$sum*8

4、.0/$granularity; if ($throughput $maxrate) $maxrate=$throughput; #輸出結果: 時間 吞吐量(bps) print STDOUT “$x2: $throughput bpsn“; #設定下次要計算吞吐量的時間 $clock=$clock+$granularity; $sum_total=$sum_total+$x4; $sum=$x4; ,2010/3/5,9,$endtime=$x2; #計算最後一次的吞吐量大小 $throughput=$sum*8.0/$granularity; print STDOUT “$x2: $thr

5、oughput bpsn“; $clock=$clock+$granularity; $sum=0; #print STDOUT “$sum_total $start $endtimen“; $avgrate=$sum_total*8.0/($endtime-$start); print STDOUT “Average rate: $avgrate bpsn“; print STDOUT “Peak rate: $maxrate bpsn“; #關閉檔案 close DATA; exit(0);,2010/3/5,10,2010/3/5,11,TCP的吞吐量計算,2010/3/5,12,無線網

6、路,以下是無線網路模擬後所產生的值: s -t 0.267662078 -Hs 0 -Hd -1 -Ni 0 -Nx 5.00 -Ny 2.00 -Nz 0.00 -Ne -1.000000 -Nl RTR -Nw - -Ma 0 -Md 0 -Ms 0 -Mt 0 -Is 0.255 -Id -1.255 -It message -Il 32 -If 0 -Ii 0 -Iv 32,s -t 0.267662078 在上述trace記錄中,第一列描述了發生在節點上的事件類型,有四種: s 發送 r 接收 d 丟棄 f 轉發 第二列以“-t”開始,表示的是時間或者全局設置 -t 時間 -t *

7、(全局設置),2010/3/5,13,-Hs 0 -Hd -1 Hs:目前節點的id Hd:下一個hop節點的id -Ni 0 -Nx 5.00 -Ny 2.00 -Nz 0.00 -Ne -1.000000 -Nl RTR -Nw - 這一列描述了節點諸如node-id等屬性,tracing的層級可能是agent、router或者MAC。這些標識以“-N”開始並如下所示: -Ni: 節點id -Nx: 節點的x坐標 -Ny: 節點的y坐標 -Nz: 節點的z坐標 -Ne: 節點能量級別 -Nl: 節點trace層級,比如AGT,RTR,MAC -Nw: 事件原因。,2010/3/5,14,-

8、Ma 0 -Md 0 -Ms 0 -Mt 0 該列給出了MAC層信息,標識以“-M”開始 -Ma: 持續時間 -Md: 目的乙太網址 -Ms: 來源乙太網址 -Mt: 乙太網類型 -Is 0.255 -Id -1.255 -It message -Il 32 -If 0 -Ii 0 -Iv 32 該列標識以“-I”開始,其解釋如下: -Is: 來源地址 -Id: 目的地址 -It: 封包類型 -Il: 封包大小 -If: 資料流id -Ii: 唯一的id -Iv: ttl值(time to live),2010/3/5,15,2010/3/5,16,範圍:1000m*1000m 移動節點:三個

9、 N0和N2是以CBR/UDP連線。 當time=200時,N1從(500,500)移到(500,900)。 當time=500時,N1從(500,900)移到(500,100)。 當time=1000時結束。,2010/3/5,17,(500,900),(500,500),(650,500),(350,500),(500,100),Time = 200,Time = 500,2010/3/5,18,# Define options 定義一些變數 #= set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Pro

10、pagation/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

11、(x) 1000 ;#拓樸範圍:X set val(y) 1000 ;#拓樸範圍:Y set val(ifqlen) 50 ;# max packet in ifq set val(nn) 3 ;# number of mobile nodes set val(seed) 0.0 set val(stop) 1000.0 ;# simulation time set val(tr) exp.tr ;# trace file name set val(rp) DSDV ;# routing protocol,2010/3/5,19,# Initialize Global Variables se

12、t ns_ new Simulator # Open trace file 開啟trace file $ns_ use-newtrace set namfd open nam-exp.tr w $ns_ namtrace-all-wireless $namfd $val(x) $val(y) set tracefd open $val(tr) w $ns_ trace-all $tracefd # set up topography object #建立一個拓樸物件,以紀錄mobilenodes在拓樸內移動的情況 set topo new Topography # 拓樸的範圍為 1000m x

13、 1000m $topo load_flatgrid $val(x) $val(y) # create channel set chan new $val(chan) # Create God set god_ create-god $val(nn),2010/3/5,20,# Create the specified number of mobile nodes $val(nn) and “attach“ them # to the channel. Three nodes are created : node(0), node(1) and node(2) # 設置Mobile node的

14、參數 $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 ON -macTrace OFF -movementTrace OFF for set i 0 $i $val(n

15、n) incr i set node_($i) $ns_ node $node_($i) random-motion 0 ;# disable random motion ,2010/3/5,21,# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes # # 設定節點0在一開始時,位置在(350.0, 500.0) $node_(0) set X_ 350.0 $node_(0) set Y_ 500.0 $node_(0) set Z_ 0.0 # 設定節點1在一開始時,位置在(500.0, 500.0) $nod

16、e_(1) set X_ 500.0 $node_(1) set Y_ 500.0 $node_(1) set Z_ 0.0 # 設定節點2在一開始時,位置在(650.0, 500.0) $node_(2) set X_ 650.0 $node_(2) set Y_ 500.0 $node_(2) set Z_ 0.0 # Load the god object with shortest hop information # 在節點1和節點2之間最短的hop數為1 $god_ set-dist 1 2 1 # 在節點0和節點2之間最短的hop數為2 $god_ set-dist 0 2 2 #

17、 在節點0和節點1之間最短的hop數為1 $god_ set-dist 0 1 1,2010/3/5,22,# Now produce some simple node movements # Node_(1) starts to move upward and then downward set god_ God instance # 在模擬時間200秒的時候,節點1開始從位置(500, 500)移動到(500, 900), # 速度為2.0 m/sec $ns_ at 200.0 “$node_(1) setdest 500.0 900.0 2.0“ # 然後在500秒的時候,再從位置(5

18、00, 900)移動到(500, 100),速度為2.0 m/sec $ns_ at 500.0 “$node_(1) setdest 500.0 100.0 2.0“,2010/3/5,23,# Setup traffic flow between nodes 0 connecting to 2 at time 100.0 # 在節點0和節點2建立一條CBR/UDP的連線,且在時間為100秒開始傳送 set udp_(0) new Agent/mUDP #設定傳送記錄檔檔名為sd_udp $udp_(0) set_filename sd_udp $udp_(0) set fid_ 1 $ns

19、_ attach-agent $node_(0) $udp_(0) set null_(0) new Agent/mUdpSink #設定接收檔記錄檔檔名為rd_udp $null_(0) set_filename rd_udp $ns_ attach-agent $node_(2) $null_(0) set cbr_(0) new Application/Traffic/CBR $cbr_(0) set packetSize_ 200 $cbr_(0) set interval_ 2.0 $cbr_(0) set random_ 1 $cbr_(0) set maxpkts_ 10000

20、$cbr_(0) attach-agent $udp_(0) $ns_ connect $udp_(0) $null_(0) $ns_ at 100.0 “$cbr_(0) start“,2010/3/5,24,#Define node initial position in nam, only for nam # 在nam中定義節點初始所在位置 for set i 0 $i $val(nn) incr i # The function must be called after mobility model is defined. $ns_ initial_node_pos $node_($i

21、) 60 # Tell nodes when the simulation ends # 設定節點模擬結束時間 for set i 0 $i $val(nn) incr i $ns_ at $val(stop) “$node_($i) reset“; $ns_ at $val(stop) “stop“ $ns_ at $val(stop) “puts “NS EXITING.“ ; $ns_ halt“ proc stop global ns_ tracefd namfd $ns_ flush-trace close $tracefd close $namfd puts “Starting Simulation.“ $ns_ run,2010/3/5,25,2010/3/5,26,2010/3/5,27,2010/3/5,28,2010/3/5,29,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1