⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aodvsim.tcl

📁 在linux下开发的用于仿真ping协议的仿真文件
💻 TCL
字号:
#define optionsset val(chan) Channel/WirelessChannelset val(prop) Propagation/TwoRayGroundset val(netif) Phy/WirelessPhyset val(mac) Mac/802_11set val(ifq) Queue/DropTail/PriQueueset val(ll) LLset val(ant) Antenna/OmniAntennaset val(ifqlen) 50set val(nn) 9set val(rp) AODVset val(x) 500set val(y) 500set val(stop) 30.0#Main Program#Initialize Global Variablesset ns [new Simulator]$ns color 1 Blue$ns color 2 Red$ns color 3 Yellowset tracefd [open aodvsim1.tr w]$ns trace-all $tracefdset namtracefd [open aodvsim1.nam w]$ns namtrace-all-wireless $namtracefd $val(x) $val(y)proc finish {} {	global ns tracefd namtracefd	$ns flush-trace	close $tracefd	close $namtracefd	exec nam aodvsim1.nam &	exit 0}#Set topography objectset topo [new Topography]$topo load_flatgrid $val(x) $val(y)#Create God存储了节点的总数,各个节点之间的最短路径等信息set god_  [create-god $val(nn)]#config the nodes $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)\-channelType $val(chan)\-topoInstance $topo\-agentTrace ON\-routerTrace ON\-macTrace OFF\-movementTrace ONfor {set i 0} {$i<$val(nn)} {incr i} {	set node_($i) [$ns node]	$node_($i) random-motion 0}#Provide initial(X,Y,Z)co-ordinates for mobilenodesfor {set i 0} {$i<$val(nn)} {incr i} {	$node_($i) set Z_ 0.0}$node_(0) set X_ 0.0$node_(0) set Y_ 0.0$node_(1) set X_ 0.0$node_(1) set Y_ 500.0$node_(2) set X_ 500.0$node_(2) set Y_ 0$node_(3) set X_ 500.0$node_(3) set Y_ 500.0$node_(4) set X_ 125.0$node_(4) set Y_ 125.0$node_(5) set X_ 125.0$node_(5) set Y_ 375.0$node_(6) set X_ 375.0$node_(6) set Y_ 125.0$node_(7) set X_ 375.0$node_(7) set Y_ 375.0$node_(8) set X_ 250.0$node_(8) set Y_ 250.0#Now produce some node movements#$ns at 1.000000 "$node_(0) setdest 0.00000 250.000000 9.0000"#$ns at 0.0 "$node_(3) setdest 500.0 100.0 10.0"#$ns at 0.0 "$node_(4) setdest 250.0 250.0 10.0"#Define the connections#connect node_(0) and node_(3) using FTPset tcp0 [new Agent/TCP]$tcp0 set class_ 2set sink0 [new Agent/TCPSink]$ns attach-agent $node_(0) $tcp0$ns attach-agent $node_(3) $sink0$ns connect $tcp0 $sink0set ftp0 [new Application/FTP]$ftp0 attach-agent $tcp0$ns at 0.5 "$ftp0 start"$tcp0 set fid_ 1#connect node_(1) and node_(2) using cbrset udp0 [new Agent/UDP]$ns attach-agent $node_(1) $udp0set null0 [new Agent/Null]$ns attach-agent $node_(2) $null0$ns connect $udp0 $null0set cbr0 [new Application/Traffic/CBR]$cbr0 attach-agent $udp0$cbr0 set packetSize_ 64$cbr0 set interval_ 0.1$ns at 0.8 "$cbr0 start"$udp0 set fid_ 2#connect node_(4) and node_(7) using TELNETset tcp1 [new Agent/TCP]$tcp1 set class_ 2set sink1 [new Agent/TCPSink]$ns attach-agent $node_(4) $tcp1$ns attach-agent $node_(7) $sink1$ns connect $tcp1 $sink1set telnet0 [new Application/Telnet]$telnet0 attach-agent $tcp1$ns at 1.0 "$telnet0 start"$tcp1 set fid_ 3#Define node initial position in namfor {set i 0} {$i<$val(nn)} {incr i} {$ns initial_node_pos $node_($i) 40}#Tell the nodes when the simulation endsfor {set i 0} {$i<$val(nn)} {incr i} {$ns at $val(stop) "$node_($i) reset"}$ns at $val(stop) "finish"$ns run

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -