Ns2简单无线网络模拟实验

编程入门 行业动态 更新时间:2024-10-24 22:22:50

Ns2简单<a href=https://www.elefans.com/category/jswz/34/1767237.html style=无线网络模拟实验"/>

Ns2简单无线网络模拟实验

Ns2简单无线网络模拟实验

如果你尝试了很久都没有运行这个实验的话,建议直接复制粘贴以下代码。因为,好像这个好像跟代码的格式,缩进有关(可能跟python有点像)。直接复制粘贴吧,不然会搞到怀疑人生。

#============================================================================
set val(chan) Channel/WirelessChannel ;# channel typeset val(prop) Propagation/TwoRayGround ;# radio-propagation modelset val(netif) Phy/WirelessPhy ;# network interface typeset val(mac) Mac/802_11 ;# MAC typeset val(ifq) Queue/DropTail/PriQueue ;# interface queue typeset val(ll) LL ;# link layer typeset val(ant) Antenna/OmniAntenna ;# antenna modelset val(ifqlen) 50 ;# max packet in ifqset val(nn) 2 ;# number of mobilenodesset val(rp) AODV ;# routing protocolset val(x) 100 ;# X dimension of the topographyset val(y) 100 ;# Y dimension of the topography#============================================================================set ns [new Simulator]set tracefd [open wireless.tr w]$ns trace-all $tracefdset namtracefd [open wireless.nam w]#设置无线坐标范围$ns namtrace-all-wireless $namtracefd $val(x) $val(y)proc finish {} {global ns tracefd namtracefd$ns flush-traceclose $tracefdclose $namtracefdexec nam wireless.nam &exit 0}set topo [new Topography]$topo load_flatgrid $val(x) $val(y)create-god $val(nn)$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 OFF \-macTrace OFFfor {set i 0} {$i < $val(nn) } {incr i} {set node_($i) [$ns node]$node_($i) random-motion 0}#设置节点 0 与 节点 1 的初始坐标$node_(0) set X_ 5.0$node_(0) set Y_ 2.0$node_(0) set Z_ 0.0$node_(1) set X_ 39.0$node_(1) set Y_ 38.0$node_(1) set Z_ 0.0#在50.0s时 节点1 向坐标(25.0,20.0)以速度2.0/s移动$ns at 50.0 "$node_(1) setdest 25.0 20.0 2.0"#在10.0s时 节点0 向坐标(20.0,18.0)以速度1.0/s移动$ns at 10.0 "$node_(0) setdest 20.0 18.0 1.0"#在100.0s时 节点1 向坐标(49.0,48.0)以速度2.0/s移动$ns at 100.0 "$node_(1) setdest 49.0 48.0 2.0"#创建TCP协议节点 和 SINK 协议节点set tcp [new Agent/TCP]$tcp set class_ 2set sink [new Agent/TCPSink]$ns attach-agent $node_(0) $tcp$ns attach-agent $node_(1) $sink$ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp$ns at 10.0 "$ftp start"#在150.0s时重新初始化节点node_0 和节点 node_1 的坐标位置for {set i 0} {$i < $val(nn) } {incr i} {$ns at 150.0 "$node_($i) reset";}$ns at 150.0 "finish"$ns run

运行结果如下,是一个动态的演示:(一脸懵逼是什么感受?就是如下感受)



更多推荐

Ns2简单无线网络模拟实验

本文发布于:2024-03-09 05:32:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1723996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无线网络   简单

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!