NS2上如何利用无线网络组播H.264/SVC视频

本文转载网址:http://140.116.164.80/~smallko/ns2/svc_multicast.htm

[To Read before running this example]

  Please refer to How to do H.264 SVC simulations? first. If you use this work, please add the following into your reference.

 

C. H. Ke, " myEvalSVC: an Integrated Simulation Framework for Evaluation of H.264/SVC Transmission ", KSII Transactions on Internet and Information Systems, vol. 6, no. 1, pp. 378-393, Jan. 2012 (SCI)

 

[Preparation]

1.     To fix two bugs.

a.     Go to /ns-allinone-2.29/ns-2.29/myvideo

b.     Open myevalsvc.cc

c.      Modify the code.

void myEvalSVC::timeout()

{

 …………………..

if(x_ > 0){

          for(i=0 ; i<x_; i++)

              agent_->sendmsg(max_);

        }

               

        if(y_!=0)

          agent_->sendmsg(y_);

……………………

          }

   

d.     Modify the prepare_receivedtrace1.awk

BEGIN{

 i=0;

}

{

  time=$1

  frameno=$2

  len=$3

  lid=$4

  tid=$5

  qid=$6

 

  if(frameno>i)

     i=frameno;

 

  FrameLen[frameno]+=len;

 

  if(time>FrameRcvTime[frameno]){

    FrameRcvTime[frameno]=time;

  }

 

    FrameLid[frameno]=lid;

    FrameTid[frameno]=tid;

    FrameQid[frameno]=qid;

}

END{

 

   for(j=0;j<=i;j++)

     if(FrameLen[j]!=0)

       printf("%f\t%d\t%d\t%d\t%d\t%d\n", FrameRcvTime[j], FrameLen[j], FrameLid[j],FrameTid[j], FrameQid[j], j);

 

}

 

 

2.     To install a multicast routing protocol for wireless networks. In this example, we use PUMA. (I port it into ns-2.29)

a.     Modify the packet.h that is under /ns-allineone-2.29/ns-2.29/common

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

 

// HDLC packet

        PT_HDLC,

       

        // added by smallko

        PT_PUMA,

       

        // insert new packet types here

  PT_NTYPE // This MUST be the LAST one

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

 

// XCP

                name_[PT_XCP]="xcp";

               

                //added by smallko

                name_[PT_PUMA]="PUMA";

               

          name_[PT_NTYPE]= "undefined";

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

 

b.     Modify the ns-lib.tcl that is under /ns-allinone-2.29/ns-2.29/tcl/lib

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

AODV {

                    set ragent [$self create-aodv-agent $node]

            }

            PUMA {

                    set ragent [$self create-puma-agent $node]                   

            }

            TORA {

                    Simulator set IMEPFlag_ ON

                    set ragent [$self create-tora-agent $node]

      }

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

Simulator instproc create-aodv-agent { node } {

                 Create AODV routing agent

                       ragent [new Agent/AODV [$node node-addr]]

                 self at 0.0 "$ragent start"     ;# start BEACON/HELLO Messages

                        ode set ragent_ $ragent

                        turn $ragent

}

 

Simulator instproc create-puma-agent { node } {

                        #  Create PUMA routing agent

                        set ragent [new Agent/PUMA [$node node-addr]]

                        $self at 0.0 "$ragent start"

                        $node set ragent_ $ragent

                        return $ragent

}

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

 

c.      Modify the Makefile.in that is under /ns-allinone-2.29/ns-2.29

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

xcp/xcpq.o xcp/xcp.o xcp/xcp-end-sys.o \

        measure/mtcpsink.o measure/mudp.o measure/mudpsink.o \

        myvideo/myevalvid.o myvideo/myevalvid_sink.o myvideo/my_udp.o myvideo/myfifo.o \

        myvideo/myevalsvc.o myvideo/myevalsvc_sink.o \

        noah/noah.o mac/forwarder.o \

        puma/puma.o \

  queue/dtrr-queue.o \

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

 

d.     Download svc_multicast.rar and decompress it.

 

e.     You will find a puma folder and copy this folder to /ns-allinone-2.29/ns-2.29

 

f.       Recompile.

$cd /ns-allinone-2.29/ns-2.29

$./configure; make clean; make depend; make

 

g.      Test the puma protocol

$cd /ns-allineone-2.29/ns-2.29/puma

$ns puma.tcl

 

If there is no error, it means that you have successfully install puma.

 

[Simulation]

       In this simple example, there are two nodes. One node sends the H.264/SVC video to the other node using multicast. Very simple.

When you decompress svc_multicast.rar, you will see ns_svc_multicast. Copy this folder to cygwin environment. (to C:\cygwin\home\smallko )

 

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

#     Simulation parameters setup

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

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

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

set val(nn)     2                          ;# number of mobilenodes

set val(rp)     PUMA                       ;# 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

 

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

#        Initialization       

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

#Create a ns simulator

set ns [new Simulator]

 

#Setup topography object

set topo       [new Topography]

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

set god_ [create-god $val(nn)]

 

#Open the NS trace file

set tracefile [open out.tr w]

$ns trace-all $tracefile

 

set tracenam [open out.nam w]

$ns namtrace-all-wireless $tracenam $val(x) $val(y)

 

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   ON \

                -macTrace      ON \

                -movementTrace OFF

 

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

#        Nodes Definition       

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

#Create 2 nodes

set n0 [$ns node]

$n0 set X_ 100

$n0 set Y_ 100

$n0 set Z_ 0.0

$ns initial_node_pos $n0 20

set n1 [$ns node]

$n1 set X_ 120

$n1 set Y_ 100

$n1 set Z_ 0.0

$ns initial_node_pos $n1 20

 

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

set max_fragmented_size 1500

set packetSize $max_fragmented_size

 

set src_udp1 [new Agent/my_UDP]

#set the multicast address and port number

$src_udp1 set dst_addr_ 0xE000000

$src_udp1 set dst_port_ 100

$src_udp1 set_filename sd

$src_udp1 set packetSize_ $packetSize

$ns attach-agent $n0 $src_udp1

 

set dst1_f0 [new Agent/myEvalSVC_Sink]

#Set the receiver port number

$n1 attach $dst1_f0 100

$dst1_f0 set_filename rd_n1_f0

 

set original_file_name ns2send

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 "%f%d%d%d%d%d" t_ size_ lid_ tid_ qid_ fno_

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

   

    if { $tid_ == 0 } {

      set prio_p 1

    }

   

    if { $tid_ == 1 } {

      set prio_p 1

    }

   

    if { $tid_ == 2 } {

      set prio_p 1

    }

   

    puts  $trace_file_id "$time $size_ $lid_ $tid_ $qid_ $fno_ $prio_p$max_fragmented_size"

    set pre_time $t_

}

 

close $original_file_id

close $trace_file_id

 

set trace_file [new Tracefile]

$trace_file filename $trace_file_name

set video1 [new Application/Traffic/myEvalSVC]

$video1 attach-agent $src_udp1

$video1 attach-tracefile $trace_file

 

Node instproc join { group } {

    $self instvar ragent_

    set group [expr $group]

 

    $ragent_ join $group

}

 

Node instproc leave { group } {

    $self instvar ragent_

    set group [expr $group] ;

 

    $ragent_ leave $group

}

 

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

#        Termination       

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

#Define a 'finish' procedure

proc finish {} {

    global ns tracefile tracenam

    $ns flush-trace

    close $tracefile

    close $tracenam

    exit 0

}

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

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

}

 

$ns at 1.0  "$video1 start"

$ns at $val(stop) "$video1 stop"

$ns at 0.010000000000000 "$n1 join 0xE000000"

$ns at $val(stop) "$n1 leave 0xE000000"

$ns at $val(stop) "finish"

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

$ns run

 

Click the cygwin icon on the desktop

$cd ns_svc_multicast

$ns test_svc_multicast.tcl

$awk  –f  prepare_receivedtrace1.awk rd_n1_f0 > ns2received

$./prepare_receivedtrace2.exe ns2send ns2received temporal_originaltrace-frameno.txt > received.txt

 

When you decompress svc_multicast.rar, you will see post_processing. Copy this folder to cygwin_new environment. (to C:\cygwin_new\home\smallko )

Please also copy the received.txt to the post_processing folder (C:\cygwin_new\home\smallko\ post_processing)

 

Click the cygwin_new icon on the desktop

$nalufilter temporal_originaltrace-frameno.txt received.txt 15000 30 > filteredtrace.txt

$BitStreamExtractorStatic.exe temporal.264 temporal-filter.264 –et filteredtrace.txt

$H264AVCDecoderLibTestStatic.exe temporal-filter.264 temporal-filter.yuv

$framefilter filteredtrace.txt 152064 300 temporal-filter.yuv temporal-conceal.yuv

$PSNRStatic.exe 352 288 foreman_cif temporal-conceal.yuv

 

From the simulation result, you can see that the PSNR is not good as you expect. This is because that multicast sender does not need any acknowledgement from the receiver. Consequently, when the collision occurs, sender does not know that the collision happens and then to retransmit.

 

In this example, n0 sends to n1. n1 forwards the received packets. Therefore, the packets sent by n0 and n1 may get collided.

 

So interested readers can think how to improve the protocol to make the performance better.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值