Presentation is loading. Please wait.

Presentation is loading. Please wait.

NS2 tutorial ChihHeng, Ke ( 柯志亨 ) Phd Candidate, EE Department, NCKU MSN:

Similar presentations


Presentation on theme: "NS2 tutorial ChihHeng, Ke ( 柯志亨 ) Phd Candidate, EE Department, NCKU MSN:"— Presentation transcript:

1 NS2 tutorial ChihHeng, Ke ( 柯志亨 ) Phd Candidate, EE Department, NCKU Email: smallko@ee.ncku.edu.twsmallko@ee.ncku.edu.tw MSN: smallko@hotmail.comsmallko@hotmail.com Skype: smallko2001

2 Agenda NS2 setup nsBench How to measure the loss rate, throughput, delay, jitter ? –Parse the trace file –Modify the C++ codes How to use the gnuplot to draw the simulation results? Trace the C++ codes –CBR –DropTail –802.11 Wireless Error Model 802.11e (wireless network with QoS support---EDCF) My research: video and audio simulations

3 NS2 setup --- 常見的問題 Cygwin 的安裝 –gcc 版本 NS2 的安裝 – 路徑設定 –NAM 安裝多個 NS2 版本

4 nsBench 直接展示操作 介紹 trace file format 介紹如何使用 awk 來分析 trace file 如何使用 gnuplot 來畫圖 介紹如何安裝 mudp, mudpsink, mtcpsink 來 量測 UDP 或 TCP 的 Throughput, Delay, Jitter, Loss Rate ( 不需要再分析原本的 trace file)

5 802.11 (DCF) How to send a multicast packet over 802_11 network.ppt How to receive a multicast packet.ppt How to send a unicast packet.ppt How to receive a unicast packet.ppt

6 802.11e (EDCF) http://www.tkn.tu-berlin.de/research/802.11e_ns2/

7 # globals and flags set ns [new Simulator] #number of nodes 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_11e ;# MAC type set opt(ifq) Queue/DTail/PriQ ;# interface queue type set opt(ifqlen) 50 set opt(ll) LL ;# link layer type set opt(ant) Antenna/OmniAntenna ;# antenna model set opt(ifqlen) 50 ;# max packet in ifq set opt(adhocRouting) NOAH ;# routing protocol set opt(x)670;# X dimension of the topography set opt(y)670;# Y dimension of the topography #smallko add the following two lines Mac/802_11e set dataRate_ 1Mb Mac/802_11e set basicRate_ 1Mb BSMH multi_udpflows_802_11e.tc

8 #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 #Open the nam trace file set nf [open out.nam w] $ns namtrace-all-wireless $nf $opt(x) $opt(y) 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 for {set i 0} {$i < $num_wired_nodes} {incr i} { set W($i) [$ns node 0.0.$i] puts "wired node $i created" }

9 # 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_ 1.0 $BS(0) set Y_ 2.0 $BS(0) set Z_ 0.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]] $wl_node_($i) set X_ [expr $i * 10] $wl_node_($i) set Y_ [expr $i * 10] $wl_node_($i) set Z_ 0.0 }

10 # linking of root to base-station node $ns duplex-link $W(0) $BS(0) 10Mb 2ms DropTail # linking of wired nodes to root node #for {set i 1} {$i < $num_wired_nodes} {incr i} { # $ns duplex-link $W($i) $W(0) 10Mb 2ms DropTail #} set src_udp0 [new Agent/UDP] $src_udp0 set class_ 0 $src_udp0 set prio_ 0 set dst_udp0 [new Agent/Null] $ns attach-agent $wl_node_(0) $src_udp0 $ns attach-agent $W(0) $dst_udp0 set app0 [new Application/Traffic/CBR] $app0 attach-agent $src_udp0 $ns connect $src_udp0 $dst_udp0 $ns at 0.0 "$app0 start" set src_udp1 [new Agent/UDP] $src_udp1 set class_ 1 $src_udp1 set prio_ 1 set dst_udp1 [new Agent/Null] $ns attach-agent $wl_node_(0) $src_udp1 $ns attach-agent $W(0) $dst_udp1 set app1 [new Application/Traffic/CBR] $app1 attach-agent $src_udp1 $ns connect $src_udp1 $dst_udp1 $ns at 0.3 "$app1 start"

11 set src_udp2 [new Agent/UDP] $src_udp2 set class_ 2 $src_udp2 set prio_ 2 set dst_udp2 [new Agent/Null] $ns attach-agent $wl_node_(0) $src_udp2 $ns attach-agent $W(0) $dst_udp2 set app2 [new Application/Traffic/CBR] $app2 attach-agent $src_udp2 $ns connect $src_udp2 $dst_udp2 $ns at 0.1 "$app2 start" set src_udp3 [new Agent/UDP] $src_udp3 set class_ 3 $src_udp3 set prio_ 3 set dst_udp3 [new Agent/Null] $ns attach-agent $wl_node_(0) $src_udp3 $ns attach-agent $W(0) $dst_udp3 set app3 [new Application/Traffic/CBR] $app3 attach-agent $src_udp3 $ns connect $src_udp3 $dst_udp3 $ns at 0.2 "$app3 start" # Define node initial position in nam for {set i 0} {$i < $num_mobile_nodes} {incr i} { $ns initial_node_pos $wl_node_($i) 20 } # Tell nodes when the simulation ends for {set i 0} {$i < $num_mobile_nodes } {incr i} { $ns at 10.0 "$wl_node_($i) reset"; } $ns at 100.0 "$BS(0) reset"; $ns at 100.0 "$app0 stop" $ns at 100.0 "$app1 stop" $ns at 100.0 "$app2 stop" $ns at 100.0 "$app3 stop" $ns at 110.0 "puts \"NS EXITING...\" ; $ns halt" proc stop {} { global ns ntr nf close $ntr close $nf } # run the simulation $ns run

12 # 這是測量 CBR 封包平均吞吐量 (average throughput) 的 awk 程式 BEGIN { i0=0; i1=0; i2=0; i3=0; } { action = $1; time = $2; from = $3; to = $4; type = $5; pktsize = $6; flow_id = $8; src = $9; dst = $10; seq_no = $11; packet_id = $12; if(action=="r" && from==1 && to==0 && flow_id==0) { pkt_byte_sum0[i0+1]=pkt_byte_sum0[i0]+ pktsize; end_time0[i0] = time; i0 = i0+1; } if(action=="r" && from==1 && to==0 && flow_id==1) { pkt_byte_sum1[i1+1]=pkt_byte_sum1[i1]+ pktsize; end_time1[i1] = time; i1 = i1+1; } measure-throughput.awk

13 if(action=="r" && from==1 && to==0 && flow_id==2) { pkt_byte_sum2[i2+1]=pkt_byte_sum2[i2]+ pktsize; end_time2[i2] = time; i2 = i2+1; } if(action=="r" && from==1 && to==0 && flow_id==3) { pkt_byte_sum3[i3+1]=pkt_byte_sum3[i3]+ pktsize; end_time3[i3] = time; i3 = i3+1; } END { if(pkt_byte_sum0[i0]!=0) printf("average throughput of Flow 0:%f Bytes Per Second\n", pkt_byte_sum0[i0]/(end_time0[i0-1]-end_time0[0])); if(pkt_byte_sum1[i1]!=0) printf("average throughput of Flow 1:%f Bytes Per Second\n", pkt_byte_sum1[i1]/(end_time1[i1-1]-end_time1[0])); if(pkt_byte_sum2[i2]!=0) printf("average throughput of Flow 2:%f Bytes Per Second\n", pkt_byte_sum2[i2]/(end_time2[i2-1]-end_time2[0])); if(pkt_byte_sum3[i3]!=0) printf("average throughput of Flow 3:%f Bytes Per Second\n", pkt_byte_sum3[i3]/(end_time3[i3-1]-end_time3[0])); } ns multi_udpflows_802_11e.tcl awk –f measure-throughput.awk out.tr average throughput of Flow 0:60341.412277 Bytes Per Second average throughput of Flow 1:19359.667045 Bytes Per Second average throughput of Flow 2:6124.881852 Bytes Per Second average throughput of Flow 3:580.070331 Bytes Per Second

14 Wireless error model Random uniform model Gilbert-Elliot (GE) model

15 Uniform Distribution Model Multicast (without any retransmission when packet is lost): Packet Loss Rate = P G Unicast: The perceived correct rate at transport protocol is where N is the maximum number of retransmission at MAC (DCF mode) and p is packet loss rate at physical layer. Consequently, the perceived lost rate at transport protocol is

16 Gilbert-Elliott (GE) model In the “ good ” state (G) losses occur with low probability P G while in the “ bad ” state (B) they happen with high probability P B. The steady state probabilities of being in states G and B are and, respectively. The average packet loss rate produced by the Gilbert channel is

17 Uniform P~0.2 GE model P~0.22

18 Simulation Topology W(0) HA (base station) MH 10Mbps, 10ms 802.11

19 # 設定模擬結束時間 set opt(stop) 250 # 設定 base station 的數目 set opt(num_FA) 1 # 讀取使用者設定的參數 proc getopt {argc argv} { global opt lappend optlist nn for {set i 0} {$i < $argc} {incr i} { set opt($i) [lindex $argv $i] } getopt $argc $argv set pGG $opt(0) set pBB $opt(1) set pG $opt(2) set pB $opt(3) set fname $opt(4) set comm_type $opt(5) set loss_model $opt(6)

20 # 產生一個模擬的物件 set ns_ [new Simulator] # 使用 hierarchial addressing 的方式定址 $ns_ node-config -addressType hierarchical puts [ns-random 0] # 設定有兩個 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 test$fname w] $ns_ trace-all $tracefd # 設定 mobile node 的個數 set opt(nnn) 1 # 拓樸的範圍為 100m x 100m set topo [new Topography] $topo load_flatgrid 100 100 Tcl 程式碼

21 #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 ON \ -routerTrace ON \ -macTrace ON

22 # 設定 base station 節點 set HA [$ns_ node 1.0.0] set HAnetif_ [$HA set netif_(0)] $HAnetif_ set-error-level $pGG $pBB $pG $pB $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)] $MHnetif_(0) set-error-level $pGG $pBB $pG $pB $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

23 # 在 wired node 和 base station 之間建立一條連線 $ns_ duplex-link $W(0) $HA 10Mb 10ms DropTail $ns_ at $opt(stop).1 "$MH(0) reset"; $ns_ at $opt(stop).0001 "$W(0) reset" # 建立一個 CBR 的應用程式 (wired node ---> base station) set udp0 [new Agent/UDP] $ns_ attach-agent $W(0) $udp0 $udp0 set packetSize_ 1000 set cbr0 [new Application/Traffic/CBR] $cbr0 attach-agent $udp0 $cbr0 set rate_ 50000 $cbr0 set packetSize_ 1000 set null0 [new Agent/Null] $MH(0) attach $null0 3 # 當 base station 收到 cbr packet 時, 可以根據使用者設定以 unicast 或 multicast 轉送封包到 mobile node) set forwarder_ [$HA set forwarder_] puts [$forwarder_ port] $ns_ connect $udp0 $forwarder_ $forwarder_ dst-addr [AddrParams addr2id [$MH(0) node-addr]] $forwarder_ comm-type $comm_type

24 # 在 2.4 秒時, 開始送出 cbr 封包 $ns_ at 2.4 "$cbr0 start" # 在 200.0 秒時, 停止傳送 $ns_ at 200.0 "$cbr0 stop" $ns_ at $opt(stop).0002 "stop " $ns_ at $opt(stop).0003 "$ns_ halt" # 設定一個 stop 的程序 proc stop {} { global ns_ tracefd # 關閉記錄檔 close $tracefd } # 執行模擬 $ns_ run

25 comm_type=1 loss_model=0 for x in 0.3 0.4 0.5 0.6 do pG=$x pB=0 pGG=0 pBB=0 ith=20 for xx in $( seq 1 $ith ) do echo $xx echo $x./ns.exe wireless_error.tcl $pGG $pBB $pG $pB $xx $comm_type $loss_model done./plot_err.pl test $ith $x done # ith is the number of iteration # if BSC channel packet loos rate =pG # loss_model: 0 for BSC, 1 for GE model # comm_type: 0 for broacdcast, 1 for unicast run_bsc_error: 測試 uniform distribution 的 script

26 comm_type=0 loss_model=1 run_ge_error: 測試 GE model 的 script for x in 0.4 0.5 0.6 0.7 do pG=0.01 pB=$x pGG=0.96 pBB=0.94 ith=20 for xx in $( seq 1 $ith ) do echo $xx echo $x./ns.exe wireless_error.tcl $pGG $pBB $pG $pB $xx $comm_type $loss_model done./plot_err.pl test $ith $x done # ith is the number of iteration # if BSC channel packet loos rate =pG # loss_model: 0 for BSC, 1 for GE model # comm_type: 0 for broacdcast, 1 for unicast

27 執行的方法 : ( 以 run_bsc_error 為例 ) $./run_bsc_error 執行後會產生許多的記錄檔, 底下為某次實驗的範例 + 2.4 0 1 cbr 1000 ------- 0 0.0.0.0 1.0.0.4 0 7 (wired trace file format) - 2.4 0 1 cbr 1000 ------- 0 0.0.0.0 1.0.0.4 0 7 r 2.4108 0 1 cbr 1000 ------- 0 0.0.0.0 1.0.0.4 0 7 r 2.410800000 _1_ AGT --- 7 cbr 1000 [0 0 0 0] ------- [0:0 4194304:4 31 0] [0] 0 0 f 2.410800000 _1_ RTR --- 7 cbr 1020 [0 0 0 0] ------- [4194304:4 -1:3 32 0] [0] 0 0 s 2.411475000 _1_ MAC --- 7 cbr 1072 [0 ffffffff 0 800] ------- [4194304:4 -1:3 32 0] [0] 0 0 r 2.420051094 _2_ MAC --- 7 cbr 1020 [0 ffffffff 0 800] ------- [4194304:4 -1:3 32 0] [0] 1 0 (wireless) r 2.420076094 _2_ RTR --- 7 cbr 1020 [0 ffffffff 0 800] ------- [4194304:4 -1:3 32 0] [0] 1 0 r 2.420076094 _2_ AGT --- 7 cbr 1020 [0 ffffffff 0 800] ------- [4194304:4 -1:3 31 0] [0] 1 0 + 2.56 0 1 cbr 1000 ------- 0 0.0.0.0 1.0.0.4 1 8 - 2.56 0 1 cbr 1000 ------- 0 0.0.0.0 1.0.0.4 1 8 r 2.5708 0 1 cbr 1000 ------- 0 0.0.0.0 1.0.0.4 1 8 r 2.570800000 _1_ AGT --- 8 cbr 1000 [0 0 0 0] ------- [0:0 4194304:4 31 0] [1] 0 0 f 2.570800000 _1_ RTR --- 8 cbr 1020 [0 0 0 0] ------- [4194304:4 -1:3 32 0] [1] 0 0 s 2.571455000 _1_ MAC --- 8 cbr 1072 [0 ffffffff 0 800] ------- [4194304:4 -1:3 32 0] [1] 0 0 r 2.580031094 _2_ MAC --- 8 cbr 1020 [0 ffffffff 0 800] ------- [4194304:4 -1:3 32 0] [1] 1 0 r 2.580056094 _2_ RTR --- 8 cbr 1020 [0 ffffffff 0 800] ------- [4194304:4 -1:3 32 0] [1] 1 0 r 2.580056094 _2_ AGT --- 8 cbr 1020 [0 ffffffff 0 800] ------- [4194304:4 -1:3 31 0] [1] 1 0

28 #!/usr/bin/perl $event_filter = “[rs]”; 分析 trace file format 的程式 @ptype_filter = ("tcp", "cbr", "exp"); $ttype_filter = "MAC"; if (@ARGV < 1) { printf "usage plot_tp.pl [-s size] [node1,...]\n"; exit; } $tracenametmp = shift; $numith =shift; $errorlevel=shift; @trace_type = (); print "tracenametmp=$tracenametmp numith=$numith errorlevel=$errorlevel\n"; $tt=1; @iteration=(); while($tt<=$numith){ push @iteration,$tt; $tt=$tt+1; }

29 $totalarverror=0.0; $indith=0; $maxseqno=0; foreach $ith (@iteration){ $indith=$indith+1; $tracename="$tracenametmp$ith"; $totalpktsize=0; @src =(); @mh1 =(); open(infile, $tracename) or die "couldn't open $tracename"; while ($line = ) { ++$line_no; @entry = split(/[\s\(\)\[\]]+/, $line); $event = $entry[0]; $time = $entry[1];

30 # check for trace format and parse entry (wireless traffic trace format.) # The format of all records is not the same. if ($entry[2] =~ /_+(\d+)_+/) { # mobile $to = $1; next if ($entry[3] ne $ttype_filter); $pktid = $entry[5]; #die "packet error $pktid (line $line_no)" if ($packet_source{$pktid} == undef); $from = $packet_source{$pktid}; $type = $entry[6]; $size = $entry[7]; $packet_source{$pktid} = $to; $seqno=$entry[17]; } else { # standard (wired traffic trace format) $to = $entry[3]; $pktid = $entry[11]; $from = $entry[2]; $type = $entry[4]; $size = $entry[5]; $seqno=$entry[10]; $packet_source{$pktid} = $to; }

31 # 判斷 event 是接收 (r) 且封包型態是 cbr 的記錄 if(($event eq "r")&&($type eq "cbr")) { $tmpname="mh1"; # 記錄從 HA 到 MH 的 packet seqno 到 $tmpname if ($to == 2) { push @$tmpname,{ SEQNO => $seqno,TIME => $time}; } # 記錄從 W(0) 到 HA 的 packet seqno 到 $src if($to == 1){ push @src,{ SEQNO => $seqno,TIME => $time}; } # 關閉檔案 close($infile); # 開啟檔案 (Open the file for writing) open(datafile, ">data_raw") or die "couldn't open data";

32 $error=0; $maxseqno=0; $tmpmaxseqno=0; foreach $srcdata (@src) { $tmpname="mh1"; $chk=0; foreach $mhdata (@$tmpname) { # 判斷 $src 中的記錄中是否可在 $tmpname 中找到相同的記錄 if($srcdata->{SEQNO}==$mhdata->{SEQNO}){ if ($chk==0) { # 把沒遺失的封包記錄為 0 print datafile "$srcdata->{SEQNO} 0\n"; $chk=1; }else { $dup=$dup+1; }

33 # 找不到相同記錄時, 代表有封包遺失 if ($chk==0) { # 把遺失的封包記錄為 1 print datafile "$srcdata->{SEQNO} 1\n"; $error=$error+1; } # 記錄目前處理封包的最大 seqno( 最後的值就是共傳送多少封包 ) if($srcdata->{SEQNO}>$maxseqno){ $maxseqno=$srcdata->{SEQNO}; } print "errr $error\t $maxseqno\n"; # 單次平均的 error rate = error 發生的次數 / 總共的封包數 * 100% $arverror=$error/$maxseqno*100; $totalarverror=$totalarverror+$arverror; } # 總平均的 error rate = 全部 error rate 總和 / 模擬的字數 $arverror=$totalarverror/$numith; print "Average error =\t$arverror \tpercent\n"; # 開啟檔案 (Open the file for appending) open(cmd, ">>data.out"); # 記錄 errorlevel 和模擬所得到的總平均 error rate printf cmd "$errorlevel\t$arverror\n"; # 關閉檔案 close(cmd);

34 實驗結果 (1) pSimulated p (%) 10.110.0971659919028 20.220.2914979757085 30.330.2348178137652 40.439.7651821862348 50.550.085020242915 Uniform Distribution: I ran 20 iterations. Broadcasting is used.

35 實驗結果 (2) Uniform Distribution: I ran 20 iterations. Unicast is used. Maximum Retransmission Times: 4 pPrPr Simulated p (%) 10.30.00810.817813765182186 20.40.02562.47773279352227 30.50.06256.18218623481781 40.60.129612.7894736842105

36 實驗結果 (3) PBPB Simulated p (%) 10.40.166016.17004048583 20.50.206022.1336032388664 30.60.246024.6923076923077 40.70.286028.0283400809717 GE model: Multicast is used. I ran 20 iterations P G =0.01 P GG =0.96 P BB =0.94

37 Toward more realistic network simulations of video transmission

38 Outline Introduction Overview of Evalvid Enhancement of Evalvid One example –Video transmission over BE and QoS network Conclusion and Future works

39 Introduction (1) As mentioned in *, a survey of over 2246 research papers on the network published in the prominent IEEE journals and conferences revealed that over 51% of all publications on the network adopt computer simulation to verify their ideas and report network performance results. Therefore, network simulation tools are very important and helpful to modern network researchers. * K. Pawlikowski, "Do Not Trust All Simulation Studies of Telecommunication Networks“, (invited paper) Proc. International Conference on Information Networking, ICOIN'03

40 Introduction (2) The ever-increasing demand for multimedia distribution in the Internet motivates research on how to provide better-delivered video quality through IP-based networks. Previous studies often use publicly available video traces to evaluate their proposed network mechanisms in a simulation environment. Results are usually presented using different performance metrics, such as the packet/frame loss rate, packet/frame jitter, effective frame loss rate, picture quality rating (PQR), and the fraction of decodable frames.

41 Introduction (3) Nevertheless, packet loss or jitter are network performance metrics and may be insufficient to adequately rate the perceived quality by an end user. In *, a 3% packet loss percentage could translate into a 30% frame error probability. Therefore, lower packet loss rate can not indicate better delivered video quality. *J. M. Boyce, and R. D. Gaglianello, “Packet Loss Effects on MPEG Video Sent over the Public Internet,” In Proc. of the ACM Multimedia, September 1998.

42 Introduction (4) Although effective frame loss rate, PQR, and the fraction of decodable frames are application-level metrics, they are not as well known and acceptable as MOS (Mean Opinion Scores) and PSNR (Peak Signal Noise Ratio). To the best of my knowledge, no tool-set is publicly available to perform a comprehensive video quality evaluation of real video streams in network simulation environment. This drives me to develop one publicly available evaluation framework.

43 Introduction (5) My work was based on Evalvid. The primary aim of EvalVid is to assist researchers in evaluating their network designs or setups in terms of the perceived video quality by the end user over a real or simulated network. But the simulated environment provided by EvalVid is simply an error model to represent corrupted or missing packets in the real network. What I has done is to build the connecting interfaces between Evalvid and NS2. Then make it be more complete and useful to network researchers.

44 Overview of Evalvid Coded Video

45 Video Source  The video source can be either in the YUV QCIF (176 x 144) or in the YUV CIF (352 x 288) formats. QCIF CIF 144 pixels 176 pixels352 pixels 288 pixels

46 Video Encoder Currently, EvalVid supports two MPEG4 codecs, namely the NCTU codec [1] and ffmpeg [2]. [1]. http://megaera.ee.nctu.edu.tw/mpeg [2]. http://ffmpeg.sourceforge.net/index.php

47 Video Sender (VS) 1.Reads the compressed video file from the output of the video encoder 2.Fragments each large video frame into smaller segments 3.Transmits these segments via UDP/IP packets over a real or simulated network 4.For each transmitted UDP packet, the framework records the timestamp, the packet id, and the packet payload size in the sender trace file with the aid of third-party tools, such as tcp- dump or win-dump, if the network is a real link

48 Evaluate Trace (ET) Based on the original encoded video file, the video trace file, the sender trace file, and the receiver trace file, the ET component creates a frame/packet loss and frame/packet jitter report and generates a reconstructed video file, which corresponds to the possibly corrupted video found at the receiver side as it would be reproduced to an end user In principle, the generation of the possibly corrupted video can be regarded as a process of copying the original video file frame by frame, omitting frames indicated as lost or corrupted at the receiver side

49 Fix Video (FV) Digital video quality assessment is performed frame by frame. If the codec cannot handle missing frames (lost during transmission), the FV component is used to tackle this problem by inserting the last successfully decoded frame in the place of each lost frame as an error concealment technique

50 Peak Signal Noise Ratio (PSNR) PSNR is one of the most widespread objective metrics to assess the application-level QoS of video transmissions. The following equation shows the definition of the PSNR between the luminance component Y of source image S and destination image D: PSNR(n)dB = 20 log10 where Vpeak = 2k-1 and k = number of bits per pixel (luminance component)

51 Mean Opinion Score (MOS) MOS is a subjective metric to measure digital video quality at the application level. This metric of the human quality impression is usually given on a scale that ranges from 1 (worst) to 5 (best). PSNR[dB]MOS >37 31-37 25-31 20-25 <20 5 (Excellent) 4 (Good) 3 (Fair) 2 (Poor) 1 (Bad)

52 Enhancement of Evalvid

53 Video transmission over BE and QoS network This example is provided in my web site (http://140.116.72.80/~smallko/ns2/Evalvid_in_NS2.htm)http://140.116.72.80/~smallko/ns2/Evalvid_in_NS2.htm Best Effort Network: the queue management is DropTail QoS Network: the queue management is Weighted Random Early Detection (WRED) (I frame packets are marked as highest priority, P frame packets are marked as medium priority, B frame packets are marked as lowest priority)

54 Encoding the raw YUV video $mpeg4encoder.exe example.par //example.par ………………………………… Source.Width = 176 Source.Height = 144 // set the first encoding frame to 0 Source.FirstFrame = 0 // set the last encoding frame to 399 Source.LastFrame = 399 //set the prefix file name Source.FilePrefix = "foreman_qcif“ Scalability.Spatial.PredictionType = "PBB"// One of "PPP", "PBB" After encoding, a compressed video file “foreman_qcif.cmp” can be found.

55 Get the Video Traffic Trace File $MP4.exe –send 224.1.2.3 5555 1000 foreman_cif.cmp > st This MP4.exe command will read the compressed file. Fragment each frame into small packets with the maximum size of 1000 bytes. Then send this packets to IP:224.1.2.3 Port:5555. Here, the IP and Port is not important. Because we just need the frame information (stored in st file). 0H 29 1 segm at 33 ms 1I 3036 4 segm at 66 ms 2P 659 1 segm at 99 ms 3B 357 1 segm at 132 ms 4B 374 1 segm at 165 ms 5P 693 1 segm at 198 ms 6B 420 1 segm at 231 ms 7B 460 1 segm at 264 ms st

56 Run the simulation script (1) set ns [new Simulator] set nd [open out.tr w] $ns trace-all $nd set max_fragmented_size 1000 #add udp header(8 bytes) and IP header (20bytes) set packetSize 1028 set s1 [$ns node] set r1 [$ns node] set r2 [$ns node] set d1 [$ns node] $ns duplex-link $s1 $r1 10Mb 1ms DropTail $ns simplex-link $r1 $r2 0.18Mb 10ms DropTail $ns simplex-link $r2 $r1 0.18Mb 10ms DropTail $ns duplex-link $r2 $d1 10Mb 1ms DropTail set qr1r2 [[$ns link $r1 $r2] queue] $qr1r2 set limit_ 10 set udp1 [new Agent/myUDP] $ns attach-agent $s1 $udp1 $udp1 set packetSize_ $packetSize $udp1 set_filename sd_be set null1 [new Agent/myUdpSink2] $ns attach-agent $d1 $null1 $ns connect $udp1 $null1 $null1 set_trace_filename rd_be set original_file_name st set trace_file_name video1.dat set original_file_id [open $original_file_name r] set trace_file_id [open $trace_file_name w]

57 Run the simulation script (2) set frame_count 0 set last_time 0 while {[eof $original_file_id] == 0} { gets $original_file_id current_line scan $current_line "%d%s%d%s%s%s%d%s" no_ frametype_ length_ tmp1_ tmp2_ tmp3_ tmp4_ tmp5_ # 30 frames/sec. (1 sec -> 1000000us) set time [expr 1000 * 1000/30] if { $frametype_ == "I" } { set type_v 1 } if { $frametype_ == "P" } { set type_v 2 } if { $frametype_ == "B" } { set type_v 3 } if { $frametype_ == "H" } { set type_v 1 } puts $trace_file_id "$time $length_ $type_v $max_fragmented_size" incr frame_count }

58 Run the simulation script (3) close $original_file_id close $trace_file_id set end_sim_time [expr 1.0 * 1000/30 * ($frame_count + 1) / 1000] puts "$end_sim_time" set trace_file [new Tracefile] $trace_file filename $trace_file_name set video1 [new Application/Traffic/myTrace2] $video1 attach-agent $udp1 $video1 attach-tracefile $trace_file proc finish {} { global ns nd $ns flush-trace close $nd exit 0 } $ns at 0.0 "$video1 start" $ns at $end_sim_time "$video1 stop" $ns at [expr $end_sim_time + 1.0] "$null1 closefile" $ns at [expr $end_sim_time + 1.0] "finish" $ns run

59 Run the simulation script (4) $ns be.tcl 0.033333 id 0 udp 29 0.066666 id 1 udp 1000 0.066666 id 2 udp 1000 0.066666 id 3 udp 1000 0.066666 id 4 udp 36 0.099999 id 5 udp 659 0.133332 id 6 udp 357 0.166665 id 7 udp 374 0.199998 id 8 udp 693 0.233331 id 9 udp 420 0.266664 id 10 udp 460 sd_be 0.047958 id 0 udp 29 0.126000 id 1 udp 1000 0.171689 id 2 udp 1000 0.217377 id 3 udp 1000 0.219451 id 4 udp 36 0.250482 id 5 udp 659 0.267352 id 6 udp 357 0.285232 id 7 udp 374 0.317532 id 8 udp 693 0.337225 id 9 udp 420 0.358945 id 10 udp 460 rd_be

60 Video Quality Evaluation (1) execute et program $et.exe sd_be rd_be st foreman_cif.cmp err_be.cmp 0 p->nA:1022, p->nI:350, p->nP:222, p->nB:449 p->lA:161, p->lI:109, p->lP:22, p->lB:30 f->nA:301, f->nI:34, f->nP:67, f->nB:199 f->lA:54, f->lI:20, f->lP:13, f->lB:21 Packet/Frame lost report The first line indicates that the total number of packets sent (p->nA) is 1022. It includes 350 I frame packets (p->nI); 222 P frame packets (p->nP); and 449 B frame packets (p->nB). The second line indicates that the total number of packets lost (p->lA) is 161. It includes 109 I frame packets (p->lI); 22 P frame packets (p->lP); and 30 B frame packets (p->lB).

61 Video Quality Evaluation (2) Decode the video $mpeg4decoder.exe err_be.cmp err_be 176 144 > df_be Error concealment $myfixyuv.exe df_be qcif 400 err_be.yuv myfix_be.yuv Calculate the average PSNR $avgpsnr.exe 176 144 420 foreman_qcif.yuv myfix_be.yuv avgerage psnr:24.363058

62 Run the qos.tcl and compare the results from be.tcl

63 Conclusion With the aid of this evaluation framework, researchers or practitioners have greater freedom to analyze their proposed network designs for video transmission without considering an appropriate tool- set.

64 Country / CompanyResearch Group & Research Interests America1.Stanford CS grad student 2.PhD candidate at Univ. of Houston Australia1.Lecture at La Trobe University Canada1. Carleton University: MPEG4 transmission evaluation over Resilient Packet Ring Networks China Egypt1. search assistant at Computer division Faculty of Engineering, Suez Canal University France1. Doctorant student at Paris 13 university Germany1. TKN Iceland1. master student at University of Iceland: Modelling the Icelandic Health Network India1.Asst.Prof. at Engg. College:Wireless MANET and multimedia transmission 2.PG student: Accelerating peer to peer video streaming on Multipoint to point communication Indonesia1. collage students at STTTelkom Bandung: video streaming over umts network Israel1. Ph.D : sumulation of the behaviour of the traffic manager in the MPLS-diffserv environment. Japan1. PhD student: real-time P2P video streaming Korea1. student at Kunsan National University: streaming video over the Internet Lebanon1. using Evalvid to investigate the performance of 802.11 and 802.11e Mexico1. IATM Norway1. PhD student at NTNU: Singapore1.PhD student at National University of Singapore 2.student at Nanyang Technological University: video transmission over MANETs

65 Country / CompanyResearch Group & Research Interests Sweden1. PhD student at KTH: cross-layer issues in wireless multimedia Switzerland1. PhD student at EPFL Taiwan1. Master students at National Yulin of University of Science & Technology 2. Master student at National Taiwan University 3. Master student at National Chung Hsing University Tunisia1. researcher in the tunisian supcom university: I have optimized QoS on ad hoc network and implement it in ns-2 and i want to experiment it with MPEG video and other multimedia applications U.K.1. PhD student at University of London 2. master student: in the area of QoS 3. postgraduate student from University of Hertfordshire: video evaluation over Mobile Ad hoc Network 4. B(Eng) Computer Systems student at Brunel University: video in ad hoc network 5. Research student at Sheffield Hallam University Company1.Ericsson: test the wireless channel and the channels error-probability that at what extent it affects a video transmission. 2.Motorola: 3.Nokia: video transmission project (in China) UnknownNo information left in the email

66 Audio Simulation Reference: http://www.tkn.tu-berlin.de/research/voiptrace/qofis_v2.pdfhttp://www.tkn.tu-berlin.de/research/voiptrace/qofis_v2.pdf Source code: http://www.tkn.tu-berlin.de/research/voiptrace/qofis_v2.tar.bz2http://www.tkn.tu-berlin.de/research/voiptrace/qofis_v2.tar.bz2

67

68 proc getopt {argc argv} { global opt lappend optlist nn for {set i 0} {$i < $argc} {incr i} { set opt($i) [lindex $argv $i] } getopt $argc $argv set ns [new Simulator] set num_wired_nodes 3 set num_mobile_nodes 2 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 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 ;# interface queue type set opt(ifqlen) 50 set opt(ll) LL ;# link layer type set opt(ant) Antenna/OmniAntenna ;# antenna model set opt(ifqlen) 50 ;# max packet in ifq set opt(adhocRouting) DSDV ;# routing protocol set opt(x)670;# X dimension of the topography set opt(y)670;# Y dimension of the topography BS senderreceiver 1VOIP_802_11.tcl

69 $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 nf [open out.nam w] set nf [open /dev/null w] $ns namtrace-all-wireless $nf $opt(x) $opt(y) #set ntr [open out.tr w] set ntr [open /dev/null w] $ns trace-all $ntr set chan[new $opt(chan)] set topo[new Topography] $topo load_flatgrid $opt(x) $opt(y) create-god [expr $num_mobile_nodes + $num_bs_nodes] for {set i 0} {$i < $num_wired_nodes} {incr i} { set W($i) [$ns node 0.0.$i] puts "wired node $i created" }

70 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 nodei set X_bstn 20.0 set Y_bstn 20.0 $BS(0) set X_ $X_bstn $BS(0) set Y_ $Y_bstn $BS(0) set Z_ 0.0

71 set pi 3.14159265 set om [expr 2 * $pi / $num_mobile_nodes] set radius 5 $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]] $wl_node_($i) set X_ [expr $X_bstn + [expr $radius * cos([expr $om * ($i + 1)])]] $wl_node_($i) set Y_ [expr $Y_bstn + [expr $radius * sin([expr $om * ($i + 1)])]] $wl_node_($i) set Z_ 0.0 } # linking of root wired station to base-station node $ns duplex-link $W(0) $BS(0) 100Mb 0.00005ms DropTail # linking of wired nodes to root node, link length 100m for {set i 1} {$i < $num_wired_nodes} {incr i} { $ns duplex-link $W($i) $W(0) 100Mb 0.0005ms DropTail } #loss model->(0:random uniform; 1:GE) set wl_phy [$wl_node_(0) set netif_(0)] $wl_phy set-error-level $opt(0) $opt(1) $opt(2) $opt(3) $opt(4)

72 set rtp0 [new Agent/RTPdata] $ns attach-agent $wl_node_(0) $rtp0 $rtp0 set prio_ 0 set rtp1 [new Agent/RTPdata] $ns attach-agent $W(1) $rtp1 $rtp1 set prio_ 0 set voip0 [new Application/Traffic/VOIP] $voip0 set status_ 0 ;# receiving $voip0 set_OUTFile rxstats_wl0_w1.out $voip0 attach-agent $rtp0 set voip1 [new Application/Traffic/VOIP] $voip1 set status_ 1 ; #sending $voip1 set_BITFile in.bit $voip1 set interval_ 0.02 $voip1 set packetSize_ 160 $voip1 attach-agent $rtp1 $ns connect $rtp0 $rtp1 set jitter0 [uniform 0 0.02] set jitter1 [uniform 0 0.02] $ns at [expr $jitter0 + 1.0] "$voip0 start" $ns at [expr $jitter1 + 1.0] "$voip1 start"

73 # Define node initial position in nam for {set i 0} {$i < $num_mobile_nodes} {incr i} { $ns initial_node_pos $wl_node_($i) 60 } # # Tell nodes when the simulation ends # $ns at 700.0 "$voip0 stop" $ns at 700.0 "$voip1 stop" $ns at 701.0 "$wl_node_(0) reset"; $ns at 701.0 "$wl_node_(1) reset"; $ns at 701.0 "$BS(0) reset"; $ns at 702.0 "puts \"NS EXITING...\" ; $ns halt" proc stop {} { global ns ntr nf close $ntr close $nf } # run the simulation $ns run

74 Script to run 1VOIP_802_11.tcl #!/bin/sh rm rxstats_wl0_w1.out rm __g729in.bit rm __g729out.bit rm result000.sw rm result000.wav rm _pesq_itu_results.txt rm _pesq_results.txt rm playout_result.txt ns 1VOIP_802_11.tcl 0 0 0.6 0 0./playout2.exe -c G729 -t rxstats_wl0_w1.out -d 0.150 -f 0.01 -m -r in.sw sox result000.sw result000.wav After simulation, you will get PesqMOS and Emodel (R-factor). Also, you can use MediaPlayer to compare the original sound file with the distorted one.


Download ppt "NS2 tutorial ChihHeng, Ke ( 柯志亨 ) Phd Candidate, EE Department, NCKU MSN:"

Similar presentations


Ads by Google