📄 mobileudprf.tcl
字号:
# ======================================================================
# 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) [lindex $argv 0] ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(dur) [lindex $argv 1]
#set val(mod) Modulation/BPSK ;#Type of modulation
# ======================================================================
# Main Program
# ======================================================================
proc add-multiple-interfaces {node_number total_interfaces x y z chan prop ll mac ifq ifqlen netif ant topo mod} {
global node_
set Pi 3.1415926535897932384626433832795
set Spacing [expr double(2*$Pi)/double($total_interfaces)]
set Initial_Angle [expr atan($y/$x)]
$node_($node_number) instvar netif_ ll_ ant_ X_ Y_ Z_
# each node starts off with one interface already, so lets set the LOS for that one
$netif_(0) modulation [new Modulation/BPSK]
$ant_(0) set-los $x $y $z
$ant_(0) set-pos $X_ $Y_ $Z_
for {set i 1} {$i < $total_interfaces } {incr i} {
puts "[expr cos($Initial_Angle + $Spacing * $i)] + [expr sin($Initial_Angle + $Spacing * $i)]"
$node_($node_number) add-interface $chan [new $prop] $ll $mac $ifq $ifqlen $netif $ant $topo "" "" ""
$ant_($i) set-los [expr cos($Initial_Angle + $Spacing * $i)] [expr sin($Initial_Angle + $Spacing * $i)] $z
$ant_($i) set-pos $X_ $Y_ $Z_
$node_($node_number) add-LL-to-Route-Agent $i
$netif_($i) modulation [new Modulation/BPSK]
}
}
#
# Initialize Global Variables
#
remove-all-packet-headers
add-packet-header LL Mac UDP IP AODV
set ns_ [new Simulator]
set tracefd [open simple.tr w]
$ns_ trace-all $tracefd
#$ns_ eventtrace-all
#set namtrace [open FSO.nam w]
#$ns_ namtrace-all-wireless $namtrace 40 40
# set up topography object
set topo [new Topography]
$topo load_flatgrid [expr sqrt($val(nn)) * 5 + 5] [expr sqrt($val(nn)) * 5 + 5]
set chan_1_ [new $val(chan)]
#
# Create God
#
create-god $val(nn)
#
# Create the specified number of mobilenodes [$val(nn)] and "attach" them
# to the channel.
# configure node
# unity gain, omni-directional antennas
# set up the antennas to be centered in the node and 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.5
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0
# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 1.559e-11
Phy/WirelessPhy set RXThresh_ 3.652e-10
Phy/WirelessPhy set Rb_ 2*1e6
Phy/WirelessPhy set Pt_ 0.2818
Phy/WirelessPhy set freq_ 914e+6
Phy/WirelessPhy set L_ 1.0
$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 OFF \
-routerTrace OFF \
-macTrace OFF \
-movementTrace OFF \
-channel $chan_1_
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 1 ;# disable random motion
$node_($i) start
}
set k 0
for {set i 0} {$i < $val(nn) } {incr i} {
for {set j 0} {$j < $val(nn) } {incr j } {
if { $i != $j } {
set udp($k) [new Agent/UDP]
$ns_ attach-agent $node_($i) $udp($k)
set cbr($k) [new Application/Traffic/CBR]
$cbr($k) attach-agent $udp($k)
set lm($k) [new Agent/Null]
$ns_ attach-agent $node_($j) $lm($k)
$ns_ connect $udp($k) $lm($k)
$ns_ at [expr .1 + ($j)] "$cbr($k) start"
$ns_ at $val(dur) "$cbr($k) stop"
set k [expr $k + 1]
}
}
}
for {set i 1} {$i < [expr $val(dur)/60 + 1] } {incr i} {
$ns_ at [expr $i * 60] "puts \"[expr $i * 60]\"; stop; puts \" \""
}
unset cbr
unset udp
unset lm
unset i
unset k
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at [expr $val(dur) + 0.2] "$node_($i) reset";
#$ns_ initial_node_pos $node_($i) 3
#$node_($i) namattach $namtrace
}
$ns_ at [expr $val(dur) + 0.01] "stop"
$ns_ at [expr $val(dur) + 0.03] "puts \"NS EXITING...\" ; $ns_ halt"
proc stop { } {
global ns_ outfd node_
foreach { index n } [array get node_] {
$n instvar ll_
foreach { index l } [array get ll_] {
$l goodput
}
}
#$ns_ flush-trace
#close $tracefd
#close $namtrace
#exec nam -f dynamic-nam.conf FSO.nam &
}
puts "Starting Simulation..."
$ns_ run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -