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

📄 fixedtcprf.tcl

📁 fso antenna model for ns2
💻 TCL
字号:

source $env(NS)/tcl/rpi/tcp-stats.tcl
#source $env(NS)/tcl/rpi/link-stats.tcl
source $env(NS)/tcl/rpi/script-tools.tcl
source $env(NS)/tcl/rpi/monitor.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(mod)            Modulation/BPSK             ;#Type of modulation 
set val(dur)		[lindex $argv 1]

# ======================================================================
# 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 TCP IP AODV

set ns_		[new Simulator]
set tracefd     [open simple.tr w]
set outfd 	[open RF[lindex $argv 0].txt 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

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 0		;# disable random motion   
}

for {set i 0} {$i < sqrt($val(nn)) } {incr i} {
	for {set j 0} {$j < sqrt($val(nn)) } {incr j} { 
		$node_([expr $i*int(sqrt($val(nn))) + $j]) set X_ [expr ($i+1) * 5 ]
		$node_([expr $i*int(sqrt($val(nn))) + $j]) set Y_ [expr ($j+1) * 5 ]
		$node_([expr $i*int(sqrt($val(nn))) + $j]) set Z_ 0
	}
}

for {set i 0} {$i < $val(nn) } {incr i} {
	add-multiple-interfaces $i 4 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 } {
			puts $k
			set tcp($k) [new Agent/TCP]
			$tcp($k) set class_ 2
			set sink($k) [new Agent/TCPSink]
			$ns_ attach-agent $node_($i) $tcp($k)
			$ns_ attach-agent $node_($j) $sink($k)
			$ns_ connect $tcp($k) $sink($k)
			set ftp($k) [new Application/FTP]
			$ftp($k) attach-agent $tcp($k)
			$ns_ at [expr .5 + ($k)] "$ftp($k) start"
			$ns_ at $val(dur) "$ftp($k) stop"
			$tcp($k) init-stats
			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]\";"
}

unset ftp
unset sink
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.1] "stop tcp"
$ns_ at [expr $val(dur) + 0.3] "puts \"NS EXITING...\" ; $ns_ halt"
#$ns_ namtrace-end-wireless 20.0
proc stop { tcpName } {
	global ns_ outfd
	upvar 1 $tcpName tcp
	foreach { index session } [array get tcp] {
		set total_useful_bytes_ 0    
		set tmp [$session get-useful-bytes]
		set total_useful_bytes_ [expr $total_useful_bytes_ + $tmp]
    
		set total_data_packets_ 0
		set tmp [get-total-data-packets $session]
		set total_data_packets_ [expr $total_data_packets_ + $tmp]
		
		set total_retrans_packets_ 0
		set tmp [get-total-retransmitted-packets $session]
		set total_retrans_packets_ [expr $total_retrans_packets_ + $tmp]
		puts $outfd "$total_data_packets_ $total_retrans_packets_ $total_useful_bytes_"
	}
	
	close $outfd
	#$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 + -