【发布时间】:2018-04-23 00:36:22
【问题描述】:
我找不到解决这个问题的方法,当我改变时
for {set i 0} {$i < $opt(row)} {incr i} {
for {set j 0} {$j < $opt(col)} {incr j} {
到
for {set i 1} {$i < $opt(row)} {incr i} {
for {set j 1} {$j < $opt(col)} {incr j} {
我发现另一个问题是“无法读取”node_(0)”:没有这样的变量
set opt(netif) Phy/WirlessPhy ;#network interface type
set opt(chan) Channel/WirelessChannel ;#channel type
set opt(prop) Propagation/TwoRayGround ;#radio-propagation model
set opt(ant) Antenna/OmniAntenna ;#antenna model
set opt(mac) Mac/802_11 ;#mac type
set opt(ifq) Queue/DropTail/PriQueue ;#interface queue type
set opt(ll) LL ;#link layer type
set opt(ifqlen) 10 ;#max packet
set opt(nn) 2 ;#nombre de noeud
set opt(rp) DSDV ;#protocol
set opt(MaxX) 500 ;#longueur
set opt(MaxY) 500 ;#longuer
set opt(row) 2;
set opt(col) 1;
######################
set ns_ [new Simulator]
#####################
set nf [open TP2.nam w]
$ns_ namtrace-all $nf
$ns_ namtrace-all-wireless $nf $opt(MaxX) $opt(MaxY)
############################
set tracefile [open TP2.tr w]
$ns_ trace-all $tracefile
##########################
set topo [new Topography]
$topo load_flatgrid $opt(MaxX) $opt(MaxY)
########################
set god [create-god $opt(nn)]
##################
$ns_ color 1 Green
$ns_ color 2 Red
########################
$ns_ node-config -adhocRouting $opt(rp) \
-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\
-movementTrace ON
##################
for {set i 0} {$i < $opt(row)} {incr i} {
for {set j 0} {$j < $opt(col)} {incr j} {
set nodenum [expr ($i*$opt(col))+($j)]
set nodenum_($nodenum) [$ns_ node $nodenum]
set xpos[expr ($i+1)*$opt(dist)]
set ypos[expr ($j+1)*$opt(dist)]
$node_($nodenum) set X_$xpos
$node_($nodenum) set Y_$ypos
$node_($nodenum) random-motion 0
$ns_ initial_node_pos $node_($nodenum) 20 }}
###################################
$node_(0) Color Red
$node_(0) shape circle
$node_([expr $opt(nn)-1]) color Green
$ns_ at 0.0"$node_(0) color red"
$ns_ at 0.0"$node_(0) label Emetteur"
$ns_ at 0.0"$node_([expr$opt(nn)-1]) color blue"
$ns_ at 0.0"$node_([expr$opt(nn)-1]) label Recepteur"
################################
set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns_ attach-agent $node_(0)$tcp
$ns_ attach-agent $node_(1)$sink
$ns_ connect$tcp$sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns_ at 0.01 "$ftp start"
############################
proc finish{}{
global ns_tracefile
$ns_ flush-trace
close $tracefile
puts "simulation terminée"
exit 0
}
for {set i 0} {$i < $opt(nn)}{incr i}{
$ns_at$opt(stop) "\$node_($i) reset"
}
$ns_ at $opt(stop) "finish"
$ns_ at $opt(stop) "put\"done\";$ns_halt"
$ns_ run
帮助
【问题讨论】: