官方淘宝店 易迪拓培训 旧站入口
首页 > 无线通信 > 通信技术学习讨论 > 问个ns仿真的问题

问个ns仿真的问题

12-12
我建了一个2个节点的网络,主要是想运行一下SMAC协议...
但是我这个脚本仿完后,用nam看不到节点,也没有数据传送,请大家帮我修改一下。谢谢了
set opt(chan)           Channel/WirelessChannel
set opt(prop)           Propagation/TwoRayGround
set opt(netif)          Phy/WirelessPhy
set opt(mac)            Mac/SMAC                   ;# MAC type
set opt(ifq)            Queue/DropTail/PriQueue
set opt(ll)             LL
set opt(ant)            Antenna/OmniAntenna
set opt(x)              800     ;# X dimension of the topography
set opt(y)              800             ;# Y dimension of the topography
set opt(ifqlen)         50              ;# max packet in ifq
set opt(nn)             2               ;# number of nodes
set opt(seed)           0.0
set opt(stop)           700.0           ;# simulation time
set opt(tr)             mytest.tr       ;# trace file
set opt(nam)            mytest.nam      ;# animation file
set opt(rp)             DumbAgent       ;# routing protocol script
set opt(lm)             "off"           ;# log movement
set opt(agent)          Agent/DSDV
set opt(energymodel)    EnergyModel     ;
#set opt(energymodel)    RadioModel     ;
set opt(radiomodel)     RadioModel     ;
set opt(initialenergy)  1000            ;# Initial energy in Joules
#set opt(logenergy)      "on"           ;# log energy every 150 seconds
Mac/SMAC set syncFlag_ 1
Mac/SMAC set dutyCycle_ 10
set ns_         [new Simulator]
set topo        [new Topography]
set tracefd     [open $opt(tr) w]
set namtrace    [open $opt(nam) w]
set prop        [new $opt(prop)]
$topo load_flatgrid $opt(x) $opt(y)
ns-random 1.0
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace 800 800
#
# Create god
#
create-god $opt(nn)
#global node setting
        $ns_ node-config -adhocRouting DumbAgent \
                         -llType $opt(ll) \
                         -macType $opt(mac) \
                         -ifqType $opt(ifq) \
                         -ifqLen $opt(ifqlen) \
                         -antType $opt(ant) \
                         -propType $opt(prop) \
                         -phyType $opt(netif) \
                         -channelType $opt(chan) \
                         -topoInstance $topo \
                         -agentTrace ON \
                         -routerTrace ON \
                         -macTrace ON \
                         -energyModel $opt(energymodel) \
                         -idlePower 1.0 \
                         -rxPower 1.0 \
                         -txPower 1.0 \
                         -sleepPower 0.001 \
                         -transitionPower 0.2 \
                         -transitionTime 0.005 \
                         -initialEnergy $opt(initialenergy)
        
        $ns_ set WirelessNewTrace_ ON
        for {set i 0} {$i < $opt(nn) } {incr i} {
                set node_($i) [$ns_ node]      
                $node_($i) random-motion 0              ;# disable random motion
        }
        
$node_(0) set X_ 50.373306816804
$node_(0) set Y_ 400.256560093833
$node_(0) set Z_ 0.000000000000
$node_(1) set X_ 250.373306816804
$node_(1) set Y_ 400.256560093833
$node_(1) set Z_ 0.000000000000
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(0) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $node_(1) $null_(0)
set cbr_(0) [new Application/Traffic/CBR]
$cbr_(0) set packetSize_ 512
$cbr_(0) set interval_ 0.5
$cbr_(0) set random_ 1
$cbr_(0) set maxpkts_ 50000
$cbr_(0) attach-agent $udp_(0)
$ns_ connect $udp_(0) $null_(0)
$ns_ at 1.00 "$cbr_(0) start"
$ns_ at 180.00001 "puts \"NS EXITING...\" ; $ns_ halt"
$ns_ run

我觉得那几个trace语句是不是应该放在网络场景创建结束以后呢?
。。。

你对网络的各种设置都没有问题,已经粗略检查过了。
好像缺少对仿真过程的控制
以下是一个仿真语句例子:
具体你可以参考NS2里802.11的tcl场景来检查
proc finish {} {
     global ns namtrace
     $ns flush-trace
     close $namtrace
     exec nam scene1.nam &
     exit 0
  }
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 10.0 "$node_($i) reset";
}
$ns_ at 10.0001 "stop"
$ns_ at 10.0002 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
    global ns_ tracefd
    $ns_ flush-trace
    close $tracefd
}

Top