Você está na página 1de 11

Installation of video-streaming implementations for the ns-2 simulator

V ctor Carrascal Fr as March 10, 2009

Introduction

In this document the instructions to follow to install the new developments created in this thesis are included. Lets suppose the reader has a fully operational ns-2 installation working on its computer. Our implementations have been developed and tested over version ns2-2.27, but have been also tested successfully with ns2-2.33. After reading these notes, the reader should be able to successfully install the following contributions that we have developed for the ns-2 simulator: RTP/RTCP implementation MPEG2 sender/receiver application Trace le generator (mpg2trace) MMDSR implementation All the implementations can be freely downloaded given that the proper GNU GPL (General Public License) license will be refered in any work1 : http://sertel.upc.es/vcarrascal/ns2/

RTP/RTCP installation

In order to install the RTP/RTCP implementation, we have to decompress the le rtp.tar.gz. After decompression a folder named rtp v2 will be created. Then, move the folder rtp v2 into the directory where the source of the simulator is stored, i.e. ns-2.xx (where xx is the version of the ns-2 simulator installed). After this, it is necessary to modify the le Makele.in (stored in the ns-2.xx folder of the simulator), in order to add the source les of this new RTP implementation. These are the steps to follow:
1 Multipath Multimedia Dynamic Source Routing (MMDSR), V ctor Carrascal Fr as, http://sertel.upc.es/vcarrascal/ns2/, Telematic Services Research Group. Technical University of Catalonia, Spain.

1. Add the following lines to the le Makele.in at the end of the OBJ CC section (but before the line @V STLOBJ@): rtp v2/rtp v2.o \ rtp v2/rtcp v2.o \ 2. Add -I/rtp v2 to the INCLUDES = section at the beginning of Makele.in 3. Exit, saving changes. 4. Copy le session-rtp.cc to folder ns-2.xx/common/. 5. Copy les rtp.cc and rtp.h to folder ns-2.xx/apps/. 6. Add the following at the end of the le ns-2.xx/tcl/lib/ns-default.tcl: Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTP_v2 Agent/RTCP_v2 Agent/RTCP_v2 Agent/RTCP_v2 Agent/RTCP_v2 set seqno_ 0 set interval_ 3.75ms set random_ 0 set packetSize_ 210 set maxpkts_ 0x10000000 instproc done {} { } set rtcp_in_use_ 0 set codification_ -1 set lostcounter_ 0 set losses_ 0 set multipath_ 1 set flow_id_ 0 set set set set seqno_ 0 interval_ 375ms random_ 0 flow_id_ 0

Session/RTP set debug_ 0

7. Add the packet type RTP v2 in le common/packet.h. This is done by adding the following lines: - In the structure enum packet t, write the two following lines before the line PT NTYPE // This MUST be the LAST one: PT RTP v2, PT RTCP v2, - In the class p info public: p info() write the two following lines but before name [PT NTYPE]= undened; line: name [PT RTP v2]=rtp v2; name [PT RTCP v2]=rtcp v2; 8. Exit, saving changes. 2

9. Run make. Once it is nished, a new binary le named ns in the ns-2.xx will be available with the new RTP/RTCP protocol implementation. Set conguration settings related to this RTP Agent in the TCL simulation le as shown in the TCL script sample shown below: set ns [new Simulator] set end_sim_time 10.0 #Open the nam trace file set nf [open final.nam w] set tf [open final.tr w] $ns namtrace-all $nf $ns trace-all $tf #Define a finish procedure proc finish {} { global ns nf tf $ns flush-trace #Close the trace file close $nf close $tf #Execute nam on the trace file exec nam final.nam & exit 0 } set node_(s1) [$ns node] set node_(s2) [$ns node] set node_(r1) [$ns node] $ns duplex-link $node_(s1) $node_(r1) 10Mb 5ms DropTail $ns duplex-link $node_(s2) $node_(r1) 10Mb 5ms DropTail set trace_file [new Tracefile] $trace_file filename starwars.nsformat set RTP_s [new Agent/RTP_v2] set RTCP_r [new Agent/RTCP_v2] set self [new Session/RTP] $ns attach-agent $node_(s1) $RTP_s $ns attach-agent $node_(s2) $RTCP_r $ns connect $RTP_s $RTCP_r set video [new Application/Traffic/Trace] $video attach-tracefile $trace_file 3

$video attach-agent $RTP_s $RTCP_r session $self $RTP_s session $self $RTCP_r set interval_ 100ms $RTCP_r set seqno_ 0 $RTP_s set packetSize_ 1064 $ns at 0.0 "$video start" $ns at 0.0 "$RTCP_r start" $ns at $end_sim_time { $video stop $RTCP_r stop #$RTP_s stop finish } $ns run The information contained in the periodic RTCP-RR packets sent between destination and source are displayed in the display by default (you can watch it on the terminal screen). If you want to store it to a le, you can try this command: ns rtp-rtcp-simulation.tcl > rtcps-info.log The information will be stored in a new le named rtcps-info.log.

MPEG2 sender/receiver installation

In order to install the MPEG2 sender/receiver implementation, we have to decompress the le ns-mpeg v2.tar.gz. Then, move the folder ns-mpeg v2 into the folder where the source of the simulator is stored, i.e. ns-2.xx (where xx is the version of the ns-2 simulator installed). After this, it is necessary to modify the le Makele.in, in order to add the source les of the MPEG2 application. These are the steps to follow: 1. Add the following lines to Makele.in at the OBJ CC section (but before the line @V STLOBJ@): ns-mpeg v2/mpegdata v2.o \ ns-mpeg v2/mpegnulldata.o \ ns-mpeg v2/mpegdatale.o \ ns-mpeg v2/mpeggen vIPB.o \ ns-mpeg v2/mpeg2RX2 vIPB.o \ 2. Add -I/ns-mpeg v2 to the INCLUDES = section at the beginning of Makele.in 3. Exit, saving changes. 4

4. Copy les ns-process.cc and ns-process.h to folder ns-2.xx/common/. 5. Run make. Once it is nished, a new binary le named ns in the ns-2.xx will be available with the new MPEG2 sender/receiver implementation. Set conguration settings related to this MPEG application in the TCL simulation le as shown in the script shown below. This is a complex simulation using simultaneously RTP/RTCP implementation, MMDSR (a modication of plain DSR) and the MPEG2 TX/RX application. You must follow the lines related to new Application/Trac/Mpeg2Gen2 and new Application/Mpeg2RX2. # Multipath simulations with MM-DSR and 802.11e set escenario [lindex $argv 0] # ====================================================================== # Fixed options # ====================================================================== 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(mac) Mac/802_11 ;# MAC type #set opt(ifq) CMUPriQueue ;# interface queue type set opt(ll) LL ;# link layer type set opt(ant) Antenna/OmniAntenna ;# antenna model set opt(CBRpsize) 1500 ;# Packet size set opt(CBRrate) 1000000 ;# CBR rate in bps. set NumofSources 1 # Invalidated parameter when using DSR! set opt(ifqlen) 50 ;# max packet in ifq, it is the MAC queue size # To modify it, change IFQLEN in dsr-priqueue.h! #Queue set limit_ set num_nodes 50 set opt(NumOfMN) 1000 $num_nodes ;# number of mobilenodes

set opt(RoutingProtocol) DSR ;# routing protocol # DSR has 4 different physical queues: queue size set in dsr-priqueue.h set set set set set set opt(X) 520 opt(Y) 520 opt(MNcoverage) opt(speed) opt(start) opt(stop) ;# X & Y dimension of the topography 120 2 0 100

Mac/802_11e set dataRate_ Mac/802_11e set basicRate_ Mac/802_11e set bandwidth_

11.0e6 11.0e6 11.0e6

;# 11Mbps ;# (1Mbps) ;# (1Mbps)

# Computes the necessary power fot a given coverage (the cell radius) proc SetPt { coverage } { set Gt [Antenna/OmniAntenna set Gt_] set Gr [Antenna/OmniAntenna set Gr_] set ht [Antenna/OmniAntenna set Z_] set hr [Antenna/OmniAntenna set Z_] set RXThresh [Phy/WirelessPhy set RXThresh_] set d4 [expr pow($coverage,4)] set Pt [expr ($RXThresh*$d4)/($Gt*$Gr*$ht*$ht*$hr*$hr)] return $Pt }

Phy/WirelessPhy set L_ 1.0 Phy/WirelessPhy set freq_ 2.472e9 Phy/WirelessPhy set bandwidth_ 11Mb #Phy/WirelessPhy set Pt_ 0.031622777 Phy/WirelessPhy set CPThresh_ 10.0 Phy/WirelessPhy set CSThresh_ 5.011872e-12 Phy/WirelessPhy set RXThresh_ 5.82587e-09 Phy/WirelessPhy set Pt_ [SetPt $opt(MNcoverage)] puts "Pt_ ========== $[SetPt $opt(MNcoverage)]"

# unity gain, omni-directional antennas # set up the antennas to be centered in the node and 1.5 meters above it Antenna/OmniAntenna set X_ 0 Antenna/OmniAntenna set Y_ 0 Antenna/OmniAntenna set Z_ 1.5 Antenna/OmniAntenna set Gt_ 1 Antenna/OmniAntenna set Gr_ 1 set ns_ [new Simulator] set trace [open "trace.tr" w] $ns_ trace-all $trace $ns_ use-newtrace set namtrace [open animation.nam w] $ns_ namtrace-all-wireless $namtrace $opt(X) $opt(Y) set topo [new Topography] $topo load_flatgrid $opt(X) $opt(Y) set god [create-god $opt(NumOfMN)] set chan_1_ [new $opt(chan)]

$ns_ node-config \ -mobileIP OFF \ -adhocRouting $opt(RoutingProtocol) \ -llType $opt(ll) \ -macType $opt(mac) \ -ifqType $opt(ifq) \ -ifqLen $opt(ifqlen) \ -antType $opt(ant) \ -propType $opt(prop) \ -phyType $opt(netif) \ -channel $chan_1_ \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON \ -wiredRouting OFF # Connets upper and lower MNs: Agent/Null set sport_ 0 Agent/Null set dport_ 0 Agent/CBR set sport_ 0 Agent/CBR set dport_ 0 set opt(CBRperiod) $ns_ $ns_ $ns_ $ns_ color color color color 1 2 3 4 Blue Green Red Yellow [expr 8.0 * double($opt(CBRpsize)+20) / double($opt(CBRrate))]

Agent/RTP_v2 set sport_ 0 Agent/RTP_v2 set dport_ 0 Agent/RTCP_v2 set sport_ 0 Agent/RTCP_v2 set dport_ 0 set rng [new RNG] set opt(seed) 0.1 $rng seed $opt(seed) for {set i 0} {$i < $opt(NumOfMN)} {incr i} { set node_($i) [$ns_ node] }

# puts "Loading scenario file..." set opt(sc) $escenario source $opt(sc) 7

puts "Load complete..." for {set i 0} {$i < $opt(NumOfMN)} {incr i} { $node_($i) set RTPsource_ 0 $node_($i) set RTPdestination_ 0 } set tmp 0.011 set start_tx_time 4 set selfs 0 for {set i 0} {$i < $NumofSources} {incr i} { set n [expr {$i + 20}] $node_($i) set RTPsource_ 1 $node_($n) set RTPdestination_ 1 $node_($i) set MMDSRfreq_ 14 # average speed of the nodes $node_($i) set mu_ 5 puts "RTPsource $i" puts "RTPdestination $n" set trace_file_($i) [new MpegDataFile_v2] $trace_file_($i) metafile /home/vico/ns2/adhoc/e/blade2.mdipbf4444 $trace_file_($i) datafile /home/vico/ns2/adhoc/e/blade.m2v set rtp_($i) [new Agent/RTP_v2] $ns_ attach-agent $node_($i) $rtp_($i) $rtp_($i) set class_ 2 $rtp_($i) set seqno_ 0 $rtp_($i) set packetSize_ 1500 $rtp_($i) set multipath_ 3 $rtp_($i) set flow_id_ $i $rtp_($i) set prio_ 0 $rtp_($i) set ptype_ 1 set rtcp_($n) [new Agent/RTCP_v2] $ns_ attach-agent $node_($n) $rtcp_($n) $rtcp_($n) set class_ 3 $rtcp_($n) set interval_ 1000ms $rtcp_($n) set seqno_ 0 $rtcp_($n) set flow_id_ $n set rtp_($n) [new Agent/RTP_v2] $ns_ attach-agent $node_($n) $rtp_($n) $rtp_($n) set class_ 2 $rtp_($n) set seqno_ 0 8

$rtp_($n) set packetSize_ 1500 $rtp_($n) set flow_id_ $n # Variable for RTCP: 0-> not in use, 1-> in use $rtp_($i) set rtcp_in_use_ 1 $ns_ connect $rtp_($i) $rtcp_($n) $ns_ attach-agent $node_($n) $rtcp_($n) set MPEG2_($i) [new Application/Traffic/Mpeg2Gen2] $MPEG2_($i) attach-mpegdatasrc $trace_file_($i) $MPEG2_($i) attach-agent $rtp_($i) #0: without codification #1: all data through the same path #2: I+B path 1, P path 2 #3: Even I, P, B frames by path 1, odd B frames by path 2 #4: I / P / B, each one through a different path (Multipath of 3) */ $MPEG2_($i) set codification_ 4 $rtp_($i) set codification_ 4 set sinkmpeg_($n) [new Application/Mpeg2RX2] $sinkmpeg_($n) attach-agent $rtcp_($n) $sinkmpeg_($n) attach-agent $rtp_($n) $sinkmpeg_($n) dumpfile "$i.multipath_video.m2v" set self_($i) [new Session/RTP] $rtcp_($n) session $self_($i) $rtp_($i) session $self_($i) $rtp_($n) session $self_($i) set udp_($i) [new Agent/UDP] $ns_ attach-agent $node_($i) $udp_($i) set null_($n) [new Agent/LossMonitor] $ns_ attach-agent $node_($n) $null_($n) set cbr_($i) [new Application/Traffic/CBR] $cbr_($i) set packetSize_ $opt(CBRpsize) $cbr_($i) set interval_ $opt(CBRperiod) $cbr_($i) set random_ 1 $udp_($i) set prio_ 3 $udp_($i) set ptype_ 2 $cbr_($i) set CBRrate $opt(CBRrate) $cbr_($i) attach-agent $udp_($i) $ns_ connect $udp_($i) $null_($n) $udp_($i) set fid_ 4 $ns_ at $start_tx_time "$cbr_($i) start" #$ns_ at 4.0 "$cbr_($i) stop" $ns_ at $start_tx_time "$MPEG2_($i) start" $ns_ at $start_tx_time "$rtcp_($n) start" 9

incr start_tx_time incr selfs } set udp_(1) [new Agent/UDP] $ns_ attach-agent $node_(1) $udp_(1) set null_(21) [new Agent/LossMonitor] $ns_ attach-agent $node_(21) $null_(21) set cbr_(1) [new Application/Traffic/CBR] $cbr_(1) set packetSize_ $opt(CBRpsize) $cbr_(1) set interval_ $opt(CBRperiod) $cbr_(1) set random_ 1 $cbr_(1) set CBRrate $opt(CBRrate) $cbr_(1) attach-agent $udp_(1) $ns_ connect $udp_(1) $null_(21) $udp_(1) set fid_ 4 #$ns at 0.0 "$cbr_(1) start" #$ns at 4.0 "$cbr_(1) stop" $ns_ at $opt(stop) {finish}

for {set i 0} {$i < $opt(NumOfMN)} {incr i} { $ns_ initial_node_pos $node_($i) 15 } proc finish {} { global ns node_ null_ nn2 opt trace namtrace namtrace_s sinkmpeg puts "Finishing ns at time [$ns_ now]." $ns_ flush-trace close $trace exit 0 } puts "Starting Simulation..." puts "Nmero de nodos:$num_nodes" u $ns_ run

Trace le generator

This tool generates a trace le of an MPEG-2 coded video. The ns-2 simulator needs a trace le of an MPEG-2 coded video which gathers the information needed to transmit the video stream. This was explained in detail in chapter ??, section ??. Download and decompress mpg2 trace ns2.tar.gz le. Source code is available in the src folder and the binary executable le mpg2 trace ns2 is found in the bin folder. This is the output of the program when no les are specied, showing the dierent available arguments:

10

Running program =./mpg2trace Number of Arguments = 0 Arguments: 1) 2) 3) 4) Mpeg Video Stream Ouput Text Data file Output Metadata file Output Slice info file

This way, if we want to create a trace le for a given sequence of video, we will just type the following in a command-line environment:
./mpg2trace video-mpeg2.m2v video-mpeg2.txt video-mpeg2.metadata video-mpeg2.sli

where video-mpeg2.m2v is the input le which contains the video sequence. Additionally, three output les are given: video-mpeg2.txt and video-mpeg2.sli, which are text les generated by mpg2trace with information related to the structure of the video sequence; le video-mpeg2.metadata is the trace le to be linked in the conguration of the MPEG2 sender/receiver application in the TCL code of the simulation.

MMDSR installation

In order to install the MMDSR implementation into the ns-2 simulator, we have to decompress the le dsr.mm.tar.gz. Then, move the folder dsr into the directory where the source of the simulator is stored, i.e. ns-2.xx (where xx is the version of the ns-2 simulator installed). All les corresponding to the original DSR must be overwritten. Then, run make to compile the simulator. After this, a new version of the simulator should be created. Once it is nished, a new binary executable le named ns will be available in the ns-2.xx with MMDSR protocol installed instead of standard DSR. Set conguration settings of the DSR protocol as usual. Some conguration parameters can be modied at the beginning of les dsragent.cc and dsragent.h. Remember to run make after the modications. NOTE: in some versions of ns-2, the function insert of the le scheduler.cc gives us a compilation error or the simulations get into an innite loop. In these cases the solution is to include the same function of a previous version of ns-2 (ns2-2.27 version is documented as working well).

11

Você também pode gostar