Tcl [NS2模拟]没有显示模拟图

Tcl [NS2模拟]没有显示模拟图,tcl,ns2,Tcl,Ns2,有人能在这里查看一下代码,看看为什么它没有显示模拟程序吗 它所做的只是成功地执行了文件,但没有生成。只生成了。tr。我应该用什么代码生成一个.nam文件 set cbr_size 500 set cbr_interval 0.002 set num_row 4 set time_duration 100 set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;#

有人能在这里查看一下代码,看看为什么它没有显示模拟程序吗

它所做的只是成功地执行了文件,但没有生成。只生成了。tr。我应该用什么代码生成一个.nam文件

set cbr_size 500
set cbr_interval 0.002
set num_row 4
set time_duration 100

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) 50 ;# max packet in ifq
set val(rp) DSDV ;# routing protocol
# 
# Initialize ns
#
set ns_ [new Simulator]
set tracefd [open simple.tr w]
$ns_ trace-all $tracefd

# set up topography object
set topo       [new Topography]
$topo load_flatgrid 1000 1000

create-god [expr $num_row * $num_row ]

$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  [new $val(chan)] -topoInstance $topo \
     -agentTrace ON -routerTrace OFF\
     -macTrace ON \
     -movementTrace OFF

for {set i 0} {$i < [expr $num_row*$num_row]} {incr i} {
    set node_($i) [$ns_ node]
}
set k 0;
while {$k < $num_row } {
    for {set i 0} {$i < $num_row } {incr i} {
    set m [expr $i+$k*$num_row];
    $node_($m) set X_ [expr $i*240];
    $node_($m) set Y_ [expr $k*240+20.0];
    $node_($m) set Z_ 0.0
    }
    incr k;
}; 
for {set i 0} {$i < $num_row } {incr i} {
    set udp_($i) [new Agent/UDP]
    set null_($i) [new Agent/Null]
} 
  $ns_ attach-agent $node_(0) $udp_(0)
  $ns_ attach-agent $node_(7) $udp_(1)
  $ns_ attach-agent $node_(2) $udp_(2)
  $ns_ attach-agent $node_(7) $udp_(3)
  $ns_ attach-agent $node_(6) $null_(0)
  $ns_ attach-agent $node_(1) $null_(1)
  $ns_ attach-agent $node_(8) $null_(2)
  $ns_ attach-agent $node_(15) $null_(3)
for {set i 0} {$i < $num_row } {incr i} {
     $ns_ connect $udp_($i) $null_($i)
}
for {set i 0} {$i < $num_row } {incr i} {
    set cbr_($i) [new Application/Traffic/CBR]
$cbr_($i) set packetSize_ $cbr_size
$cbr_($i) set interval_ 0.5
$cbr_($i) attach-agent $udp_($i)
} 
$ns_ at 11.0234 "$cbr_(0) start"
$ns_ at 10.4578 "$cbr_(1) start" 
$ns_ at 12.7184 "$cbr_(2) start"
$ns_ at 12.2456 "$cbr_(3) start" 
# Tell nodes when the simulation ends
#
for {set i 0} {$i < [expr $num_row*$num_row] } {incr i} {
    $ns_ at [expr $time_duration +10.0] "$node_($i) reset";
}
$ns_ at [expr $time_duration +10.0] "finish"
$ns_ at [expr $time_duration +10.01] "puts \"NS Exiting...\"; $ns_ halt"

proc finish {} {
global ns_ tracefd
$ns_ flush-trace
close $tracefd
}

puts "Starting Simulation..."
$ns_ run 
设置cbr\u尺寸500
将cbr_间隔设置为0.002
设置第4行的数值
设置时间和持续时间100
设置val(chan)频道/无线信道通道类型
设置val(道具)传播/TwoRayGround;#无线传播模型
设置值(netif)物理/无线物理;#网络接口类型
设置val(mac)mac/802#11;#MAC类型
设置val(ifq)队列/DropTail/PriQueue;#接口队列类型
设置值(ll)ll;#链路层类型
设置val(ant)天线/全向天线;#天线模型
设置val(ifqlen)50;#ifq中的最大数据包
设置值(rp)DSDV;#路由协议
# 
#初始化ns
#
设置ns_u2;[新模拟器]
设置tracefd[打开simple.tr w]
$ns_uu跟踪所有$tracefd
#设置地形对象
设置地形[新地形]
$topo负载\u扁平电网1000
创建上帝[expr$num\u行*$num\u行]
$ns_uu节点配置-adhocRouting$val(rp)-llType$val(ll)\
-mac类型$val(mac)-ifq类型$val(ifq)\
-ifqLen$val(ifqLen)-antType$val(ant)\
-propType$val(prop)-phyType$val(netif)\
-频道[新$val(chan)]-拓扑实例$topo\
-代理竞速接通-路由器竞速断开\
-麦克特雷森\
-移动跟踪
对于{set i 0}{$i<[expr$num_row*$num_row]}{incr i}{
设置节点($i)[$ns\uunode]
}
设置k0;
而{$k<$num_row}{
对于{set i 0}{$i<$num_row}{incr i}{
设置m[expr$i+$k*$num_行];
$node_($m)集合X_[expr$i*240];
$node_($m)集合Y_[expr$k*240+20.0];
$node_um($m)集Z_0.0
}
增量k;
}; 
对于{set i 0}{$i<$num_row}{incr i}{
设置udp($i)[新代理/udp]
设置空值($i)[新代理/null]
} 
$ns\连接代理$node\ 0$udp\ 0
$ns\连接代理$node\ 7$udp\ 1
$ns\连接代理$node\ 2$udp\ 2
$ns\连接代理$node\ 7$udp\ 3
$ns\附加代理$node\ 6$null\ 0
$ns\附加代理$node\ 1)$null\ 1
$ns\附加代理$node\ 8)$null\ 2
$ns\附加代理$node\ 15)$null\ 3
对于{set i 0}{$i<$num_row}{incr i}{
$ns_uu连接$udp_uu($i)$null_u($i)
}
对于{set i 0}{$i<$num_row}{incr i}{
设置cbr_($i)[新应用程序/流量/cbr]
$cbr_uu($i)设置包大小\uu$cbr_u大小
$cbr\ui($i)设置间隔\u0.5
$cbr\$i)附加代理$udp\$i
} 
$ns_uu11.0234“$cbr_uu0)开始”
$ns_u在10.4578“$cbr_uu(1)开始”
$ns_uu12.7184“$cbr_u2)开始”
$ns_uu12.2456“$cbr_u3)开始”
#在模拟结束时通知节点
#
对于{set i 0}{$i<[expr$num_row*$num_row]}{incr i}{
$ns_u在[expr$time_uduration+10.0]“$node_u($i)reset”处;
}
$ns_u在[expr$time_u持续时间+10.0]“完成”
$ns_u在[expr$time_uduration+10.01]“放置\“ns退出…”;$ns_u停止”
过程完成{}{
全局ns_uuTraceFD
$ns_uu刷新跟踪
关闭$tracefd
}
将“开始模拟…”
$ns_uu运行

您可以通过在tcl中添加以下两行来生成NAM文件

set namfile [open out.nam w]
$ns_ namtrace-all-wireless $namfile $val(x) $val(y)
Val(x)和Val(y)
只不过是最大x和y坐标