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

📄 wireless.tcl

📁 我自己用的无线Ad-hoc网络的场景文件
💻 TCL
字号:
# wireless.tcl
# A simple example for wireless simulation
#======================================================================
# Define options
#======================================================================
set val(chan)           Channel/WirelessChannel    ;# channel type
set val(prop)           Propagation/TwoRayGround   ;# radio-propagationmodel
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)             10                          ;# number of mobilenodes
set val(rp)             DSDV                       ;# routing protocol
# =====================================================================
# Main Program (主程式)
# =====================================================================
# 產生一個模擬的物件
set ns_              [new Simulator]
#定義一個記錄檔,用來記錄封包傳送的過程
set tracefd     [open simple.tr w]
$ns_ trace-all $tracefd
#開啟一個NAM trace file
set nf [open out.nam w]
$ns_ namtrace-all-wireless $nf 500 500
# set up topography object
#建立一個拓樸物件
set topo       [new Topography]
# 拓樸的範圍為 500m x 500m
$topo load_flatgrid 500 500
#
# Create God
#
create-god $val(nn)
set chan_1_ [new $val(chan)]
#
#  Create the specified number 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) \
                         -channel $chan_1_ \
                         -topoInstance $topo \
                         -agentTrace ON \
                         -routerTrace ON \
                         -macTrace OFF \
                         -movementTrace OFF                    
#802.11b的參數設定
#Configuration for Orinoco 802.11b 11Mbps PC card with ->22.5m range
Phy/WirelessPhy set Pt_ 0.031622777
Phy/WirelessPhy set bandwidth_ 11Mb
Mac/802_11 set dataRate_ 11Mb
Mac/802_11 set basicRate_ 1Mb 
# for broadcast packets
Phy/WirelessPhy set freq_ 2.472e9 
# channel-13.2.472GHz
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 5.011872e-12
Phy/WirelessPhy set L_ 1.0               
Phy/WirelessPhy set RXThresh_ 5.82587e-09         
        for {set i 0} {$i < $val(nn) } {incr i} {
                set node_($i) [$ns_ node] 
                $node_($i) random-motion 0            ;# disable random motion
        }
#
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
#
# 設定節點0的位置在(10.0, 20.0, 0.0)
$node_(0) set X_ 10.0
$node_(0) set Y_ 20.0
$node_(0) set Z_ 0.0
# 設定節點1的位置在(10.0, 40.0, 0.0)
$node_(1) set X_ 10.0
$node_(1) set Y_ 40.0
$node_(1) set Z_ 0.0
$ns_ initial_node_pos $node_(0) 10
$ns_ initial_node_pos $node_(1) 10
  for {set i 2} {$i < $val(nn) } {incr i} {
                $ns_ initial_node_pos $node_($i) 10
        }
# Setup traffic flow between nodes
#在節點0到節點1之間建立一條FTP連線
set tcp [new Agent/TCP/Sack1]
$tcp set class_ 2
set sink [new Agent/TCPSink/Sack1]
$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
#在1.0秒時,開始傳送資料
$ns_ at 1.0 "$ftp start" 
# Tell nodes when the simulation ends
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 40.0 "$node_($i) reset";
}
#在40.0秒時,結束傳送資料
$ns_ at 40.0 "stop"
$ns_ at 40.01 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
    global ns_ tracefd nf
    $ns_ flush-trace
    close $tracefd 
    close $nf
}
puts "Starting Simulation..."
$ns_ run

⌨️ 快捷键说明

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