Transcript ns2_051126

NS2 tutorial
ChihHeng, Ke (柯志亨)
Phd Candidate, EE Department, NCKU
Email: [email protected]
MSN: [email protected]
Skype: smallko2001
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
NS2 setup ---常見的問題
• Cygwin的安裝
– gcc 版本
• NS2的安裝
– 路徑設定
– NAM
• 安裝多個NS2版本
nsBench
•
•
•
•
•
直接展示操作
介紹trace file format
介紹如何使用awk來分析trace file
如何使用gnuplot來畫圖
介紹如何安裝mudp, mudpsink, mtcpsink來
量測UDP或TCP的Throughput, Delay, Jitter,
Loss Rate (不需要再分析原本的trace file)
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
802.11e (EDCF)
http://www.tkn.tu-berlin.de/research/802.11e_ns2/
# globals and flags
set ns [new Simulator]
BS
MH
#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
multi_udpflows_802_11e.tc
#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"
}
# 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
}
# 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"
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
#這是測量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
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;
ns multi_udpflows_802_11e.tcl
}
}
END {
awk –f measure-throughput.awk out.tr
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]));
}
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
Wireless error model
• Random uniform model
• Gilbert-Elliot (GE) model
Receiver(BS/MH)
Sender(BS/MH)
Add Error model
Transport
Transport
IP
IP
MAC
MAC
Phy
Add Error model
Phy
Uniform Distribution Model
Multicast (without any retransmission when packet is lost):
Packet Loss Rate = PG
Unicast:
The perceived correct rate at transport protocol is
N
pCORECT  i1(1  p) p i 1  1  p N
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
pT  p N
Gilbert-Elliott (GE) model
p GB
pGG
G
B
p BB
p BG
a.
0
1  pG
0
0
0
pB
pG
G
B
pB
pG
1
1  pB
1  pG
1
b.
1
1  pB
1
c.
In the “good” state (G) losses occur with low probability PG while in the “bad” state (B)
they happen with high probability PB. 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
p BG
p GB
G 
B 
p BG  p GB
p BG  p GB
p  pG G  pB B
Uniform
P~0.2
GE model
P~0.22
Simulation Topology
802.11
10Mbps, 10ms
W(0)
HA
(base station)
MH
#設定模擬結束時間
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)
#產生一個模擬的物件
set ns_ [new Simulator]
Tcl 程式碼
#使用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
#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
#設定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
#在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
#在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
comm_type=1
loss_model=0
for x in 0.3 0.4 0.5 0.6
do
run_bsc_error:測試uniform distribution的script
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
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
執行的方法: (以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
#!/usr/bin/perl
$event_filter = “[rs]”;
@ptype_filter = ("tcp", "cbr", "exp");
分析trace file format的程式
$ttype_filter = "MAC";
if (@ARGV < 1) {
printf "usage plot_tp.pl [-s size] <trace file> [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;
}
$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 = <infile>) {
++$line_no;
@entry = split(/[\s\(\)\[\]]+/, $line);
$event = $entry[0];
$time = $entry[1];
# 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;
}
#判斷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";
$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;
}
}
}
#找不到相同記錄時,代表有封包遺失
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);
實驗結果 (1)
p
Simulated p (%)
1
0.1
10.0971659919028
2
0.2
20.2914979757085
3
0.3
30.2348178137652
4
0.4
39.7651821862348
5
0.5
50.085020242915
Uniform Distribution:
I ran 20 iterations. Broadcasting is used.
實驗結果 (2)
p
Pr
Simulated p (%)
1
0.3
0.0081
0.817813765182186
2
0.4
0.0256
2.47773279352227
3
0.5
0.0625
6.18218623481781
4
0.6
0.1296
12.7894736842105
Uniform Distribution:
I ran 20 iterations. Unicast is used.
Maximum Retransmission Times: 4
實驗結果 (3)
PB
p  ( pG pBG  pB pGB ) /( pGB  pBG )
Simulated p (%)
1
0.4
0.1660
16.17004048583
2
0.5
0.2060
22.1336032388664
3
0.6
0.2460
24.6923076923077
4
0.7
0.2860
28.0283400809717
GE model:
Multicast is used. I ran 20 iterations
PG=0.01
PGG=0.96
PBB=0.94
Toward more realistic network simulations
of video transmission
Outline
•
•
•
•
Introduction
Overview of Evalvid
Enhancement of Evalvid
One example
– Video transmission over BE and QoS network
• Conclusion and Future works
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
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.
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.
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.
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.
Overview of Evalvid
Coded Video
Video Source
 The video source can be either in the YUV QCIF (176 x 144)
or in the YUV CIF (352 x 288) formats.
176 pixels
352 pixels
144 pixels
288 pixels
QCIF
CIF
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
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 tcpdump or win-dump, if the network is a real link
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
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
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








V peak
1
N col N row
N col N row
  [Y
S
i= 0
j=0
(n, i, j)  YD (n, i, j) ] 2








where Vpeak = 2k-1 and k = number of bits per pixel (luminance component)
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]
>37
31-37
25-31
20-25
<20
MOS
5 (Excellent)
4 (Good)
3 (Fair)
2 (Poor)
1 (Bad)
Enhancement of Evalvid
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)
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)
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.
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).
0
1
2
3
4
5
6
7
H
I
P
B
B
P
B
B
29
3036
659
357
374
693
420
460
1 segm at
4 segm at
1 segm at
1 segm at
1 segm at
1 segm at
1 segm at
1 segm at
33 ms
66 ms
99 ms
132 ms
165 ms
198 ms
231 ms
264 ms
st
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 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]
set s1 [$ns node]
set r1 [$ns node]
set r2 [$ns node]
set d1 [$ns node]
$ns duplex-link $s1 $r1
$ns simplex-link $r1 $r2
$ns simplex-link $r2 $r1
$ns duplex-link $r2 $d1
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
10Mb 1ms DropTail
0.18Mb 10ms DropTail
0.18Mb 10ms DropTail
10Mb 1ms DropTail
set qr1r2 [[$ns link $r1 $r2] queue]
$qr1r2 set limit_ 10
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
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
Run the simulation script (4)
$ns be.tcl
sd_be
0.033333
0.066666
0.066666
0.066666
0.066666
0.099999
0.133332
0.166665
0.199998
0.233331
0.266664
rd_be
id 0
id 1
id 2
id 3
id 4
id 5
id 6
id 7
id 8
id 9
id 10
udp 29
udp 1000
udp 1000
udp 1000
udp 36
udp 659
udp 357
udp 374
udp 693
udp 420
udp 460
0.047958
0.126000
0.171689
0.217377
0.219451
0.250482
0.267352
0.285232
0.317532
0.337225
0.358945
id 0
id 1
id 2
id 3
id 4
id 5
id 6
id 7
id 8
id 9
id 10
udp 29
udp 1000
udp 1000
udp 1000
udp 36
udp 659
udp 357
udp 374
udp 693
udp 420
udp 460
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).
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
Run the qos.tcl and compare the results from be.tcl
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 toolset.
Country / Company
Research Group & Research Interests
America
1.Stanford CS grad student
2.PhD candidate at Univ. of Houston
Australia
1.Lecture at La Trobe University
Canada
1. Carleton University: MPEG4 transmission evaluation over Resilient Packet Ring Networks
China
Egypt
1. search assistant at Computer division Faculty of Engineering, Suez Canal University
France
1. Doctorant student at Paris 13 university
Germany
1. TKN
Iceland
1. master student at University of Iceland: Modelling the Icelandic Health Network
India
1.Asst.Prof. at Engg. College:Wireless MANET and multimedia transmission
2.PG student: Accelerating peer to peer video streaming on Multipoint to point
communication
Indonesia
1. collage students at STTTelkom Bandung: video streaming over umts network
Israel
1. Ph.D : sumulation of the behaviour of the traffic manager in the MPLS-diffserv
environment.
Japan
1. PhD student: real-time P2P video streaming
Korea
1. student at Kunsan National University: streaming video over the Internet
Lebanon
1. using Evalvid to investigate the performance of 802.11 and 802.11e
Mexico
1. IATM
Norway
1. PhD student at NTNU:
Singapore
1.PhD student at National University of Singapore
2.student at Nanyang Technological University: video transmission over MANETs
Country / Company
Research Group & Research Interests
Sweden
1. PhD student at KTH: cross-layer issues in wireless multimedia
Switzerland
1. PhD student at EPFL
Taiwan
1. 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
Tunisia
1. 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
Company
1.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)
Unknown
No information left in the email
Audio Simulation
Reference: http://www.tkn.tu-berlin.de/research/voiptrace/qofis_v2.pdf
Source code: http://www.tkn.tu-berlin.de/research/voiptrace/qofis_v2.tar.bz2
proc getopt {argc argv} {
global opt
lappend optlist nn
for {set i 0} {$i < $argc} {incr i} {
set opt($i) [lindex $argv $i]
}
}
1VOIP_802_11.tcl
sender
receiver
BS
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)
set opt(y)
670
670
;# X dimension of the topography
;# Y dimension of the topography
$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"
}
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
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)
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"
# 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
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.