免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1316 | 回复: 0
打印 上一主题 下一主题

ns模拟3 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-31 21:26 |只看该作者 |倒序浏览
# Define options
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)             8                          ;# number of mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(x)              1200                              ;# X dimension of topography
set val(y)              1200                              ;# Y dimension of topography  
set val(stop)            2                           ;# time of simulation end
set ns                  [new Simulator]
set tracefd       [open simple.tr w]
set namtrace      [open simwrls.nam w]   
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
#set different colors for data flows
$ns color 0 Blue
$ns color 1 Red
# set up topography object
set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)
set chan_1 [new $val(chan)]
create-god $val(nn)
#
#  Create nn mobilenodes [$val(nn)] and attach them to the channel.
#
# configure 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) \
                         -channel $chan_1 \
                         -topoInstance $topo \
                         -agentTrace ON \
                         -routerTrace ON \
                         -macTrace ON \
                         -movementTrace OFF
set node_(0) [$ns node]
$node_(0) color black
set node_(1) [$ns node]
$node_(1) color black
$ns at 0.0 "$node_(0) color red"
$ns at 0.0 "$node_(1) color red"
$node_(0) set X_ 370.71
$node_(0) set Y_ 270.71
$node_(0) set Z_ 0.0
$node_(1) set X_ 529.29
$node_(1) set Y_ 429.29
$node_(1) set Z_ 0.0
Phy/WirelessPhy set Pt_ 7.214e-3
set chan_2 [new $val(chan)]
$ns node-config \
    -channel $chan_2
for {set i 2} {$i <= 8 } { incr i } {
set node_($i) [$ns node]      
}
# Provide initial location of mobilenodes
for {set i 2} {$i <= 8 } { incr i } {
    if {$i<=5} {
        $node_($i) set X_ [expr 200.0+($i-1)*100.0]
        $node_($i) set Y_ 200
    } else {
        $node_($i) set X_ 600
        $node_($i) set Y_ [expr 200+($i-5)*100.0]
    }      
$node_($i) set Z_ 0.0
}
# Generation of movements
$ns at 110.0 "$node_(0) setdest 124.0 272.0 30.0"
$ns at 110.0 "$node_(1) setdest 45.0 285.0 50.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"
# Set a TCP connection between node_(0) and node_(1)
set tcp [new Agent/TCP/Newreno]
$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
$ftp set fid_ 1
$ns at 0.3 "$ftp start"
# Define node initial position in nam
for {set i 0} {$i <= $val(nn)} { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}
# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "$node_($i) reset";
}
# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 2.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
    exec nam simwrls.nam &
}
$ns run
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93856/showart_2014617.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP