📄 wireless_mpeg.tcl
字号:
#==========================================
#Define options
#==========================================
set val(chan) Channel/WirelessChannel; #channel type
set val(prop) Propagation/TwoRayGround; #radio-propagation model
set val(ant) Antenna/OmniAntenna; #Antenna type
set val(ll) LL; #Link layer type
set val(ifq) Queue/DropTail/PriQueue; #Interface queue type
set val(ifqlen) 50; #max packet in ifq
set val(netif) Phy/WirelessPhy; #network interface type
set val(mac) Mac/802_11; #MAC type
set val(nn) 5; #number of mobilenodes
set val(rp) DSDV; #ad-hoc routing protocol
#initialize the sharedmedia interface with parameters
#Phy/WirelessPhy set RXThresh_ 1.47635e-07
#Phy/WirelessPhy set freq_ 2400e+6
Phy/WirelessPhy set CSThresh_ 3.652e-10
Mac/802_11 set RTSThreshold_ 0
set ns_ [new Simulator]
#设置颜色
$ns_ color 1 Blue
$ns_ color 2 Red
set tracefd [open chooseroute1.tr w]
$ns_ trace-all $tracefd
set namnf [open chooseroute1.nam w]
$ns_ namtrace-all-wireless $namnf 1000 1000
set topo [new Topography]
$topo load_flatgrid 500 500
create-god $val(nn)
#Configure nodes
$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) \
-topoInstance $topo \
-channelType $val(chan) \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0; #disable random motion
}
#provide initial (X,Y, for now Z=0) co-ordinates for node_(0) and node_(1)
$node_(0) set X_ 0.0
$node_(0) set Y_ 0.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 250.0
$node_(1) set Y_ 0.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 500.0
$node_(2) set Y_ 0.0
$node_(2) set Z_ 0.0
$node_(3) set X_ 300.0
$node_(3) set Y_ 300.0
$node_(3) set Z_ 0.0
$node_(4) set X_ 500.0
$node_(4) set Y_ 250.0
$node_(4) set Z_ 0.0
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ initial_node_pos $node_($i) 30
}
set q1 [[$ns link $r1 $r2] queue]
$q1 meanPktSize $packetSize
$q1 set numQueues_ 1
$q1 setNumPrec 3
$q1 set limit_ 10
$q1 addPHBEntry 10 0 0
$q1 addPHBEntry 11 0 1
$q1 addPHBEntry 12 0 2
$q1 configQ 0 0 6 8 0.025
$q1 configQ 0 1 4 6 0.05
$q1 configQ 0 2 2 4 0.10
set udp1 [new Agent/UDP]
$ns attach-agent $node_(0) $udp1
$udp1 set packetSize_ $packetSize
set null1 [new Agent/MyUdpSink]
$ns attach-agent $node_(2) $null1
$ns connect $udp1 $null1
$null1 set_filename output_result_flow1.dat
set original_file_name Verbose_StarWarsIV.dat
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 frame_count 0
while {[eof $original_file_id] == 0} {
gets $original_file_id current_line
scan $current_line "%d%s%d%d" seq_ frametype_ nexttime_ length_
# 25Frames/sec ( 1000/25 = 40ms = 40000 us)
set time [expr 1000*40]
if { $frametype_ == "I" } {
set type_v 1
}
if { $frametype_ == "P" } {
set type_v 2
}
if { $frametype_ == "B" } {
set type_v 3
}
puts $trace_file_id "$time $length_ $type_v $seq_"
incr frame_count
}
close $original_file_id
close $trace_file_id
set end_sim_time [expr 1.0 * 40 * ($frame_count) / 1000]
puts "$end_sim_time"
set trace_file [new Tracefile]
$trace_file filename $trace_file_name
set video1 [new Application/Traffic/myTrace]
$video1 attach-agent $udp1
$video1 attach-tracefile $trace_file
proc finish {} {
global ns
exit 0
}
$ns at 0.0 "$video1 start"
$ns at $end_sim_time "$video1 stop"
$ns at $end_sim_time "$null1 closefile"
$ns at [expr $end_sim_time + 1.0] "finish"
$ns run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -