tcl的第二个脚本

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(nn) 2 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
#set val(rp) DSR ;# routing protocol
set val(x) 500
set val(y) 500
#Initialize Global Variables
set ns [new Simulator]

set tracefd [open wireless.tr w]
$ns trace-all $tracefd
set namtracefd [open wireless.nam w]
$ns namtrace-all-wireless $namtracefd $val(x) $val(y)

#set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

#
#Greate God
#
create-god $val(nn)

set chan_1_ [new $val(chan)]
#
#create the specified of mobilenodes [$val(nn)] and "attach" them
#to the channel
#here two nodes are created:node(0)and node(1)
#configure node

$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 \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF \
-channel $chan_1_

for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0
;#$ns initial_node_pos $node_($i) 20
}


#
#provide initial(X,Y,for now Z=0) co-ordinates for moilenodes
#

$node_(0) set X_ 5.0
$node_(0) set Y_ 2.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 390.0
$node_(1) set Y_ 385.0
$node_(1) set Z_ 0.0

#
#Now produce some simple node movement
#Node_(1)starts to move to node_(0)
#

$ns at 5.0 "$node_(1) setdest 25.0 20.0 15.0"
$ns at 1.0 "$node_(0) setdest 20.0 18.0 1.0"

#Node_(1) then starts to move away from node_(0)
$ns at 10.0 "$node_(1) setdest 490.0 480.0 30.0"

#Setup traffic flow between nodes
#TCP connection between node_(0) and node_(1)

set tcp [new Agent/TCP]
$tcp set class_ 2
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 3.0 "$ftp start"

#
#Tell nodes when the simulation ends
#
for {set i 0} {$i<$val(nn)} {incr i} {
$ns at 15.0 "$node_($i) reset";
}

$ns at 15.0 "stop"
;#$ns at 15.01 "puts \"NS EXITING...\" ; $ns halt"
proc stop {} {
global ns tracefd namtracefd
$ns flush-trace
close $tracefd
close $namtracefd
exec nam wireless.nam&
exit 0
}
;#puts "Starting Simulation..."
$ns run

 

1、这个脚本就没有了第一个脚本里那些类似缺少空格的错误。但是问题在于,书上给的代码是旧版的。新版在无线节点设置时有了改动。所以,节点配置那部分是看的NS2自带的例子。不得不说这个例子给的真的挺有用的。“不用读系列”有时候真的要读一读。

2、书上的这个代码跑出来。视觉效果没有那么强。我最开始以为是发送包的周期没有调整好,就把除了位置信息以外其他参数,都是按照自带的例子设置的。结果还是没有达到例子里的结果。后来我把节点的位置也按照例子里的改了,就一直在发送包了。所以我觉得这里是,因为树上的代码设置的节点位置太远而不发送信号。也就是说,和距离有关!

3、下一步还是要学tcl语言的具体语法

4、再下一步翻一番计网书,和802.11的书。协议什么的都不懂了。现在还是聚焦于代码吧。

转载于:https://www.cnblogs.com/fastchargingpikachu/p/11179529.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值