📄 mobileudpfso.tcl
字号:
# ======================================================================
# Define options
# ======================================================================
set val(chan) Channel/FSOWirelessChannel ;# channel type
set val(prop) Propagation/FreeSpaceOptical;# 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/FSOAntenna ;# 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] ;# routing protocol
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
# FSO Default Values:
Phy/WirelessPhy set Visibility_ 60000
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 1.559e-11
Phy/WirelessPhy set RXThresh_ 0.0070794
Phy/WirelessPhy set bandwidth_ 2e6
Phy/WirelessPhy set Pt_ 0.28183815
Phy/WirelessPhy set freq_ 3.529e14
Phy/WirelessPhy set L_ 1.0
Phy/WirelessPhy set debug_ false
Antenna/FSOAntenna set Tx_Power
Antenna/FSOAntenna set Tx_Area 0.005
Antenna/FSOAntenna set Tx_Angle 0.523598
Antenna/FSOAntenna set Rx_Sensitivity 4e-9
Antenna/FSOAntenna set Rx_Area 0.005
Antenna/FSOAntenna set Rx_Angle 0.523598
$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
}
for {set i 0} {$i < $val(nn) } {incr i} {
add-multiple-interfaces $i 24 1 0 0 $chan_1_ $val(prop) $val(ll) $val(mac) $val(ifq) $val(ifqlen) $val(netif) $val(ant) $topo $val(mod)
}
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 + -