A.2 Simulation Code
A.2 Simulation Code
2 Simulation Code
# CN 0.0.0
# |
# R1 1.0.0
# /|\
# /|\
# / | \
# R2 R3 R4
#
# 2.0.0 3.0.0 4.0.0
#
# MN1-------------->
# 2.0.1
#
#read arguments
set seed 5555
Mac/802_16 set scan_iteration_ 2
set use_going_down 1
if {$use_going_down == 1} {
Mac/802_16 set lgd_factor_ 1.1
} else {
Mac/802_16 set lgd_factor_ 1.0
}
# Handover
Agent/MIHUser/IFMNGMT/MIPV6/Handover/Handover1 set case_ 3
#destination of the MN
set X_dst 2999.0
set Y_dst 1310
#defines function for flushing and closing files
proc finish {} {
global ns tf f0 f1 f2
$ns flush-trace
close $f0
close $f1
close $f2
close $tf
# exec xgraph out0.tr -geometry 800x400 &
# exec xgraph out1.tr -geometry 800x400 &
# exec xgraph out2.tr -geometry 800x400 &
exit 0
}
#**********
set f0 [open out0.tr w] ;#for the 1st BS
set f1 [open out1.tr w] ;#for the 2nd BS
set f2 [open out2.tr w] ;#for the 3rd BS
#**********
# connect links
$ns duplex-link $router1 $CN 100MBit 30ms DropTail 1000
# Create God
create-god [expr ($opt(nbMN) + $opt(nbBS))] ;
# if {$i == 1} {
# $bstation($i) set X_ 1091.515
# $bstation($i) set Y_ 600
#}
#if {$i == 2} {
# $bstation($i) set X_ 1250
#if {$i == 0} {
# $bstation($i) set X_ 1250
# $bstation($i) set Y_ 800
#}
# if {$i == 1} {
# $m_node_($i) set X_ 1091.515
# $m_node_($i) set Y_ 600
# }
# if {$i == 2} {
# $m_node_($i) set X_ 1250
# $m_node_($i) set Y_ 1200
# }
# if {$i == 0} {
# $m_node_($i) set X_ 1250
# $m_node_($i) set Y_ 800
# }
#***********************
proc record {} {
global sink0 sink1 sink2 f0 f1 f2
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.001
#How many bytes have been received by the traffic sinks?
set bw0 [$sink0 set npkts_]
set bw1 [$sink1 set bytes_]
# set bw2 [$sink2 set bytes_]
#Get the current time
set now [$ns now]
#Calculate the bandwidth (in Mbit/s) and write it to the files
puts $f0 "$now [expr $bw0]" ;# /$time*8/1000000]"
puts $f1 "$now [expr $bw1]" ;# /$time*8/1000000]"
# puts $f2 "$now [expr $bw2]" ;# /$time*8/1000000]"
#Reset the bytes_ values on the traffic sinks
# $sink0 set bytes_ 0
$sink1 set bytes_ 0
# $sink2 set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record"
}
#***************************
# install MIH in multi-interface node
set mih_wl [$multiFaceNode_wl install-mih]
$handover_wl connect-mih $mih_wl
set tmp_wl [$wl_node set mac_(0)]
$handover_wl nd_mac $nd_mn_wl $tmp_wl
$tmp_wl mih $mih_wl
$mih_wl add-mac $tmp_wl
set quiet 0
if {$quiet == 0} {
puts "udp on node : $udp_"
}
if { $opt(mnSender) == 1} {
#CN is receiver
$ns attach-agent $CN $null_
#CN is transmitter
$ns attach-agent $CN $udp_
}
#******************
#Create three traffic sinks and attach them to the nodes
set sink0 [new Agent/LossMonitor]
set sink1 [new Agent/LossMonitor]
#set sink2 [new Agent/LossMonitor]
#Start the application 1sec before the MN is entering the WiMAX cell
$ns at [expr $moveStart - 1] "$cbr_ start"
#Stop the application according to another poisson distribution (note that we don't leave the
802.16 cell)
$ns at [expr $moveStop + 1] "$cbr_ stop"