myEvalvid: An Evaluation Framework for MPEG video transmission in NS2 environment

[Introduction]

   Please refer to the following paper for more information.

 

C. H. Ke, C. K. Shieh, W. S. Hwang, A. Ziviani, “An Evaluation Framework for More Realistic Simulations of MPEG Video Transmission”, Journal of  Information  Science and Engineering, vol. 24, no. 2, pp.425-440, March 2008 (SCI)

 

[Steps]

1. Open Cygwin_Terminal

2. Change the path to myevalvid.

 

3. Start to encode the raw yuv video with ffmpeg. (The following command will encode the raw qcif YUV into MPEG4 format, with GOP=9, rate=30 frames/second, and number of b frames between I/P and P/I frame is 2, and variable bitrate quality=31.) (p.s. qscale” is a way of rep­re­sent­ing vari­able bitrate qual­i­ties, and the lower the qscale value, the bet­ter the qual­ity. The avail­able qscale val­ues range from 1 (high­est qual­ity) to 31 (low­est qual­ity).

4. Use MP4Box to transfer m4v into mp4. (The mtu size is important here. We will use this value in our NS2 simulation script. Using different mtu values needs to change the setting in tcl file accordingly.)

5. The mp4trace is able to send a hinted mp4-file per RTP/UDP/IP to a specified destination host. The output of mp4trace will be needed later, so it should be redirected to a file for further processing. (192.168.0.2 is the destination IP address, and 12346 is the port number. It is not important here. Because we just need the related information stored in foreman_qcif.st.)

 

6. We can get the foreman_qcif.st. (The first column indicates the frame number, the second is the frame type, the third is frame size, the fourth is the total number of packets needed to send out this frame, and the last one is the sending time.)

 

7. Wired simulation scenario: There are one sender, two routers, and one receiver. The link between router r1 and r2 is the bottleneck, i.e. 50kbps. The senders sends out the MPEG video to the receiver. When the buffer is overflowed in the r1-r2 link, the video packets are dropped.

set ns [new Simulator]

 

set nd [open out.tr w]

$ns trace-all $nd

 

#we use mtu size =1024 in mp4trace, and therefore the following setting also needs 1024

set max_fragmented_size   1024

#add rtp header (12 bytes), udp header(8 bytes) and IP header (20bytes)

set packetSize  1064

 

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  50kb  1ms DropTail

$ns simplex-link $r2 $r1  50kb  1ms DropTail

$ns duplex-link  $r2 $d1  10Mb   1ms DropTail

 

set qr1r2 [[$ns link $r1 $r2] queue]

$qr1r2 set limit_ 10

 

set udp1 [new Agent/my_UDP]

$ns attach-agent $s1 $udp1

$udp1 set packetSize_ $packetSize

#set the sender trace file name

$udp1 set_filename wired_sd

#when the sending node is a wired node, please add wired in the following setting.

$udp1 wired

set null1 [new Agent/myEvalvid_Sink]

$ns attach-agent $d1 $null1

$ns connect $udp1 $null1

#set the receiver trace file name

$null1 set_filename wired_rd

#when the receiving node is a wired node, please add wired in the following setting.

$null1 wired

 

set original_file_name foreman_qcif.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 pre_time 0

 

while {[eof $original_file_id] == 0} {

    gets $original_file_id current_line

    scan $current_line "%d%s%d%d%f" no_ frametype_ length_ tmp1_ tmp2_

    set time [expr int(($tmp2_ - $pre_time)*1000000.0)]

 

    if { $frametype_ == "I" } {

        set type_v 1

        set prio_p 0

    } 

 

    if { $frametype_ == "P" } {

        set type_v 2

        set prio_p 0

    } 

 

    if { $frametype_ == "B" } {

        set type_v 3

        set prio_p 0

    } 

 

    if { $frametype_ == "H" } {

        set type_v 1

        set prio_p 0

    }

 

    puts  $trace_file_id "$time $length_ $type_v $prio_p $max_fragmented_size"

    set pre_time $tmp2_

}

 

close $original_file_id

close $trace_file_id

set end_sim_time $tmp2_

puts "$end_sim_time"

 

set trace_file [new Tracefile]

$trace_file filename $trace_file_name

set video1 [new Application/Traffic/myEvalvid]

$video1 attach-agent $udp1

$video1 attach-tracefile $trace_file

$video1 wired

 

proc finish {} {

        global ns nd udp1 null1

        $ns flush-trace

        close $nd

        $udp1 closefile

        $null1 closefile

        puts "simulation completed"

        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

 

8. Do the simulation. (After simulation, we will get the wired_sd for sender trace file and wired_rd for the receiver trace file.)

 

9. Post processing

9.1 Network Level Evaluation: use these two trace files, and we can easily get the packet loss rate, packet end-to-end delay, and throughput.

 

9.2 Application Level Evaluation: etmp4 will generate a corresponding receiver received video file by referring to sender trace file, receiver trace file, and the send trace file. Comparing these files, we will know which parts in original file, i.e. foreman_qcif.mp4, are missing. Remove those parts and we can get the corresponding received video file.

 

Decode the corresponding received video file into raw yuv format.

 

 

Compare the received video with the original one and we can get the average PSNR (25.433).

 

10. Wireless simulation scenario: A video is transmitted from a wireless node 0 to another wireless node 1. The wireless channel adopts random uniform error model.

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

 

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

set loss_model  $opt(0)

set pGG $opt(1)

set pBB $opt(2)

#only opt(3) will be used to set the channel error rate

set pG $opt(3)

set pB $opt(4)

 

 

#===================================

#     Simulation parameters setup

#===================================

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

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

set val(netifPhy/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(ifqlen) 50                         ;# max packet in ifq

set val(nn)     2                          ;# number of mobilenodes

set val(rp)     AODV                       ;# routing protocol

set val(x)      500                        ;# X dimension of topography

set val(y)      500                        ;# Y dimension of topography

set val(stop)   50.0                       ;# time of simulation end

Mac/802_11 set dataRate_  2Mb

Mac/802_11 set basicRate_ 1Mb

 

#===================================

#        Initialization       

#===================================

#Create a ns simulator

set ns [new Simulator]

 

#Setup topography object

set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

 

#Open the NS trace file

set tracefile [open out.tr w]

$ns trace-all $tracefile

 

set chan [new $val(chan)];#Create wireless channel

 

#===================================

#     Mobile node parameter setup

#===================================

$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   OFF \

                -macTrace      ON \

                -movementTrace OFF

 

#===================================

#        Nodes Definition       

#===================================

#Create 3 nodes

set n0 [$ns node]

$n0 set X_ 200

$n0 set Y_ 400

$n0 set Z_ 0.0

$ns initial_node_pos $n0 20

set n1 [$ns node]

$n1 set X_ 300

$n1 set Y_ 400

$n1 set Z_ 0.0

$ns initial_node_pos $n1 20

 

set n0if_ [$n0 set netif_(0)]

$n0if_ set-error-level $pGG $pBB $pG $pB $loss_model

 

set n1if_ [$n1 set netif_(0)]

$n1if_ set-error-level $pGG $pBB $pG $pB $loss_model

 

#===================================================

set max_fragmented_size 1024

#8 bytes:UDP header, 12 bytes: RTP header

set packetSize [expr $max_fragmented_size+20] 

 

set src_udp1 [new Agent/my_UDP]

$src_udp1 set packetSize_ $packetSize

$src_udp1 set_filename wireless_sd

set dst_udp1 [new Agent/myEvalvid_Sink]

$ns attach-agent $n0 $src_udp1

$ns attach-agent $n1 $dst_udp1

$ns connect $src_udp1 $dst_udp1

$dst_udp1 set_filename wireless_rd

 

set original_file_name foreman_qcif.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 pre_time 0

 

while {[eof $original_file_id] == 0} {

    gets $original_file_id current_line

    scan $current_line "%d%s%d%d%f" no_ frametype_ length_ tmp1_ tmp2_

    set time [expr int(($tmp2_ - $pre_time)*1000000.0)]

 

    if { $frametype_ == "I" } {

        set type_v 1

        set prio_p 0

    } 

 

    if { $frametype_ == "P" } {

        set type_v 2

        set prio_p 0

    } 

 

    if { $frametype_ == "B" } {

        set type_v 3

        set prio_p 0

    } 

 

    if { $frametype_ == "H" } {

        set type_v 1

        set prio_p 0

    }

 

    puts  $trace_file_id "$time $length_ $type_v $prio_p $max_fragmented_size"

    set pre_time $tmp2_

}

 

close $original_file_id

close $trace_file_id

set end_sim_time $tmp2_

puts "$end_sim_time"

 

set trace_file [new Tracefile]

$trace_file filename $trace_file_name

set video1 [new Application/Traffic/myEvalvid]

$video1 attach-agent $src_udp1

$video1 attach-tracefile $trace_file

 

$ns at 0.5  "$video1 start"

$ns at 30.0 "$video1 stop"

 

#===================================

#        Termination       

#===================================

#Define a 'finish' procedure

proc finish {} {

    global ns tracefile namfile src_udp1 dst_udp1

    $ns flush-trace

    close $tracefile

    $src_udp1 closefile

    $dst_udp1 closefile

    puts "simulation completed"

    exit 0

}

for {set i 0} {$i < $val(nn) } { incr i } {

    $ns at $val(stop) "\$n$i reset"

}

$ns at $val(stop) "finish"

$ns at $val(stop) "puts \"done\" ; $ns halt"

$ns run

 

11. Do the simulation. (After simulation, we will get the wireless_sd for sender trace file and wireless_rd for the receiver trace file.)

 

 

 

 

Last updated: 2012/04/23

 

Dr. Chih-Heng Ke

Department of Computer Science and Information Engineering, National Quemoy University, Taiwan

Email: smallko@gmail.com