I have the following problem to get my trace simulation working . I would
like to simulate a simple video streaming client server simulation with two
routers and client server node. I'm using a video trace file
(Verbose_Jurassic_64.dat) from
http://trace.eas.asu.edu/tools/ns-example2.tar.gz.

The following codes has been modified from the above codes. The codes run on
my ubuntu 8.04 with ns2.31allinone ok but the .tr file output from the
simulation shows weird output. The packets queue about 99% percent of the
simulation time.

+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 0 0
- 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 0 0
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 1 1
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 2 2
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 3 3
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 4 4
.....
d 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 89 89
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 90 90
d 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 90 90
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 91 91
d 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 91 91
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 92 92
d 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 92 92
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 93 93
.....
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 454 454
d 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 454 454
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 455 455
d 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 455 455
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 456 456
d 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 456 456
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 457 457
d 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 457 457
+ 141.242416 0 1 udp 1000 ------- 1 0.0 3.0 458 458


Here are the codes..
set ns [new Simulator]
set nf [open out.nam w]
set f [open out.tr w]
$ns trace-all $f
$ns namtrace-all $nf

$ns color 1 Blue
$ns color 2 Red

# generate the sending node:
set send_node [$ns node]
set router_node_1 [$ns node]

# generate the routers:
set router_node_2 [$ns node]
set recv_node [$ns node]

# set router shape & label
$router_node_1 shape "box"
$router_node_2 shape "box"
$send_node label "VSer"
$router_node_1 label "R1"
$router_node_2 label "R2"
$recv_node label "VClie"

# define the links between the nodes:
$ns duplex-link $send_node $router_node_1 10Mb 10ms DropTail
$ns duplex-link $router_node_1 $router_node_2 54Mb 10ms DropTail
$ns duplex-link $router_node_2 $recv_node 10Mb 10ms DropTail

# orientation of the links:
$ns duplex-link-op $send_node $router_node_1 orient down
$ns duplex-link-op $router_node_1 $router_node_2 orient right
$ns duplex-link-op $router_node_2 $recv_node orient up

# set que
$ns duplex-link-op $router_node_1 $router_node_2 queuePos 0.5
$ns duplex-link-op $router_node_2 $recv_node queuePos 0.5

# set the maximal queue lengths of the routers:
$ns queue-limit $router_node_1 $router_node_2 5
$ns queue-limit $router_node_2 $recv_node 5

#convert the trace file into binary for ns2 video data attachment.
set original_file_name Verbose_Jurassic_64.dat
set trace_file_name video.dat
set original_file_id [open $original_file_name r]
set trace_file_id [open $trace_file_name w]
set last_time 0

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

    if {[string length $current_line] == 0 ||
    [string compare [string index $current_line 0] "#"] == 0} {
    continue
   }

    scan $current_line "%d %s %d" next_time type length
    set time [expr 1000*($next_time-$last_time)]
    set last_time $next_time
    puts -nonewline $trace_file_id[binary format "II" $time $length]
    #puts -nonewline $trace_file_id [binary format "II" $time $length]
}

close $original_file_id
close $trace_file_id
# set the simulation end time based on the video length:
set end_sim_time [expr 1.0 * $last_time / 1000 + 0.001]

# define the source and the source model:
set udp [new Agent/UDP]
$ns attach-agent $send_node $udp

# define the destination:
set snk [new Agent/Null]
$ns attach-agent $recv_node $snk
$ns connect $udp $snk
$udp set fid_ 1

# read the video trace file:
set trace_file [new Tracefile]
$trace_file filename $trace_file_name

#Attach binary trace file to the agent
set video [new Application/Traffic/Trace]
$video attach-tracefile $trace_file
$video attach-agent $udp

set cbr [new Application/Traffic/Trace]
$cbr attach-agent $udp
$cbr attach-tracefile $trace_file
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set random_ false
$cbr set rate_ 1MB

#start the simulation
$ns at 0.0 "$cbr start"
$ns at $end_sim_time "$cbr stop"
$ns at [expr $end_sim_time + 1.0] "finish"

proc finish {} {
  global ns nf f
  $ns flush-trace
  close $nf
  close $f
  exec nam out.nam &
  exit 0
}

$ns run

Reply via email to