NS2 nam没有显示任何事情

时间:2013-12-24 08:47:46

标签: networking ns2

我创建了一个工作正常的tcl文件但是当我执行nam out.nam时,nam应用程序没有显示任何内容,任何人都可以帮助我吗?

# Some constants
set area_width      100
set area_height     100
set stop_time       20

# MAC stuff
Mac/802_11 set dataRate_    2.0e6
Mac/802_11 set RTSThreshold_    3000

# Define the simulator
set simulator [new Simulator]

set trace_file  [open out.tr w]

$simulator trace-all $trace_file

#Open the NAM trace file
set nam_file [open out.nam w]
$simulator namtrace-all $nam_file

#Adjusting the topography
set topography [new Topography]
$topography load_flatgrid $area_width $area_height

# General Operations Director
create-god 2

# Some configuration just as same as the expamle 'ex6sta.tcl'
$simulator node-config -adhocRouting    DumbAgent \
                 -llType    LL \
                 -macType   Mac/802_11 \
                 -ifqType   Queue/DropTail/PriQueue \
                 -ifqLen    50 \
                 -antType   Antenna/OmniAntenna \
         -propType  Propagation/FreeSpace \
                 -phyType   Phy/WirelessPhy \
                 -channelType   Channel/WirelessChannel \
                 -topoInstance  $topography \
                 -agentTrace    ON \
                 -routerTrace   OFF \
                 -macTrace  OFF \
         -movementTrace OFF

set host(1) [ $simulator node ]
set host(2) [ $simulator node ]

$host(1) set X_ 20
$host(1) set Y_ 20
$host(1) set Z_ 0.0

$host(2) set X_ 70
$host(2) set Y_ 70
$host(2) set Z_ 0.0

# Connection 1 UDP
set udp [new Agent/UDP]
$simulator attach-agent $host(1) $udp
set sink [new Agent/Null]
$simulator attach-agent $host(2) $sink
$simulator connect $udp $sink
set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 1000
$cbr set interval_ 0.005
$cbr attach-agent $udp
$simulator at 5.0  "$cbr start"

# invoking finish procedure
$simulator at $stop_time "finish"

proc finish {} {
    global simulator host cbr nam_file trace_file
    $host(1) reset
    $host(2) reset  
    $cbr stop
    $simulator flush-trace
    close $nam_file 
    close $trace_file
    $simulator halt
    puts "Finished"
}

puts "Starting Simulation..."
$simulator run

请注意,我在ns 2.34

上使用ubuntu 12.4

2 个答案:

答案 0 :(得分:1)

立即尝试,它会起作用

# Some constants
set area_width      100
set area_height     100
set stop_time       20

# MAC stuff
Mac/802_11 set dataRate_    2.0e6
Mac/802_11 set RTSThreshold_    3000

# Define the simulator
set simulator [new Simulator]

set trace_file  [open out.tr w]

$simulator trace-all $trace_file

#Open the NAM trace file
set nam_file [open out.nam w]

$simulator namtrace-all-wireless $nam_file $area_width  $area_height


#Adjusting the topography
set topography [new Topography]
$topography load_flatgrid $area_width $area_height

# General Operations Director
create-god 2

# Some configuration just as same as the expamle 'ex6sta.tcl'
$simulator node-config -adhocRouting    DumbAgent \
                 -llType    LL \
                 -macType   Mac/802_11 \
                 -ifqType   Queue/DropTail/PriQueue \
                 -ifqLen    50 \
                 -antType   Antenna/OmniAntenna \
         -propType  Propagation/FreeSpace \
                 -phyType   Phy/WirelessPhy \
                 -channelType   Channel/WirelessChannel \
                 -topoInstance  $topography \
                 -agentTrace    ON \
                 -routerTrace   ON \
                 -macTrace  ON \
         -movementTrace ON

set host(1) [ $simulator node ]
set host(2) [ $simulator node ]

$host(1) set X_ 20
$host(1) set Y_ 20
$host(1) set Z_ 0.0

$host(2) set X_ 70
$host(2) set Y_ 70
$host(2) set Z_ 0.0
$simulator initial_node_pos $host(1) 30
$simulator initial_node_pos $host(2) 30
# Connection 1 UDP
set udp [new Agent/UDP]
$simulator attach-agent $host(1) $udp
set sink [new Agent/Null]
$simulator attach-agent $host(2) $sink
$simulator connect $udp $sink
set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 1000
$cbr set interval_ 0.005
$cbr attach-agent $udp
$simulator at 5.0  "$cbr start"

# invoking finish procedure
$simulator at $stop_time "finish"

proc finish {} {
    global simulator host cbr nam_file trace_file
    $host(1) reset
    $host(2) reset  
    $cbr stop
    $simulator flush-trace
    close $nam_file 
    close $trace_file
    $simulator halt
    puts "Finished"
}

puts "Starting Simulation..."
$simulator run

答案 1 :(得分:0)

namtrace-all适用于有线连接。

对于节点之间没有建立物理链路的无线仿真,有必要使用namtrace-all-wireless