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

📄 sample_hfa.tcl

📁 运行于linux上的CIMS套件
💻 TCL
字号:
## HFA-simulation ##                       o W1                 WIRED NODES#                       |#                       o W2#                      / \#                     /   \                    #--*--*--*--*--*--*- o     o base-stn nodes  --*-*-*-*-*-*-*-#                   BS1      BS2               #                       o#                  o    MH       o          WIRELESS NODE MOVING#                MH               MH    FROM BS1 TO BS2.### Author: Chieh-Yih Wan#         wan@comet.columbia.edu#options for wireless domainset opt(chan)		Channel/WirelessChannelset opt(prop)		Propagation/TwoRayGroundset opt(netif)		Phy/WirelessPhyset opt(mac)		Mac/802_11set opt(ifq)		Queue/DropTail/PriQueueset opt(ll)		LLset opt(ant)            Antenna/OmniAntennaset opt(x)		500	;# X & Y dimension of the topographyset opt(y)		500     ;# hard wired for now...set opt(rp)             NOAH    ;# routing protocls: NOAHset opt(ifqlen)		50		;# max packet in ifqset opt(seed)		0.0set opt(stop)		15.2		;# default simulation timeset opt(cc)             "off"set opt(tr)		hawaii-air.tr	;# trace file (Wireless traffic)set opt(cp)             ""set opt(sc)             ""set opt(ftp0-start)     6.0set opt(BgTrafficStart) 0.1# =================================================================set num_wired_nodes    7set num_bs_nodes       4set num_wireless_nodes 1set opt(nn)            5         ;# total number of wireless nodes#==================================================================# Other class settingsAgent/TCP set sport_		0Agent/TCP set dport_		0Agent/TCP set packetSize_	1460Queue/DropTail/PriQueue set Prefer_Routing_Protocols    1# unity gain, omni-directional antennas# set up the antennas to be centered in the node and 1.5 meters above itAntenna/OmniAntenna set X_ 0Antenna/OmniAntenna set Y_ 0Antenna/OmniAntenna set Z_ 1.5Antenna/OmniAntenna set Gt_ 0.2Antenna/OmniAntenna set Gr_ 0.2# Initialize the SharedMedia interface with parameters to make# it work like the 914MHz Lucent WaveLAN DSSS radio interfacePhy/WirelessPhy set CPThresh_ 10.0Phy/WirelessPhy set CSThresh_ 1.559e-11Phy/WirelessPhy set RXThresh_ 3.652e-10Phy/WirelessPhy set Rb_ 2*1e6Phy/WirelessPhy set Pt_ 0.2818Phy/WirelessPhy set freq_ 914e+6 Phy/WirelessPhy set L_ 1.0# ==================================================================source ../lib/ns-wireless-mip.tcl# Registration interval in MobileAgent/MIPMH set reg_rtx_ 1.0# ==================================================================## Session Specific setting, command line arguments#  usage: ns sample_msf <speed> <overlap> <simulation Time>#set speed(1) [ lindex $argv 0 ]set overlap [ lindex $argv 1 ]set stopTime [ lindex $argv 2 ]if {$stopTime != ""} {    set opt(stop) $stopTime    if {$stopTime <= 1} {	set opt(stop) 1.1; # since traffic for MH start at 1    }}# Increase Queue in link to introduce delay instead of droppingQueue set limit_ 200# number of Packets received in MH's sinkset pktsNum 0# intial setup - set addressing to hierarchicalset ns [new Simulator]$ns set-address-format hierarchical# set mobileIP flagSimulator set mobile_ip_ 1# ==================================================================# enable HFA Routingset HFA_Routing 1# ==================================================================set namtrace [open hfa.nam w]$ns namtrace-all $namtrace# suppress huge trace fileset trace [open /dev/null w]$ns trace-all $trace# trace for CMUtrace, for wireless trafficset tracefd	[open $opt(tr) w]AddrParams set domain_num_ 1lappend cluster_num 11AddrParams set cluster_num_ $cluster_numlappend eilastlevel 1 1 1 1 1 1 2 1 1 1 1 ; AddrParams set nodes_num_ $eilastlevel#create intermediate hostset W(1) [$ns node 0.0.0]set W(2) [$ns node 0.1.0]set W(3) [$ns node 0.2.0]set W(4) [$ns node 0.3.0]set W(5) [$ns node 0.4.0]#create corresponding hostset host [$ns node 0.5.0]# ==================================================================#setup a wired-Gateway-ForeignAgentsource hfa-lib.tclSimulator set node_factory_ MobileNode/GFASimulator set EnableHierRt_ 1set W(0) [$ns node 0.6.0]$W(0) color "red"# Highlight mobility-unaware routerforeach i {1 2 3 4 5} {    $W($i) color "purple"}# ==================================================================## create common objects reqd for wireless sim.if { $opt(x) == 0 || $opt(y) == 0 } {	puts "No X-Y boundary values given for wireless topology\n"}set chan        [new $opt(chan)]set prop        [new $opt(prop)]set topo	[new Topography]# setup topography and propagation model$topo load_flatgrid $opt(x) $opt(y)$prop topography $topo# Create Godcreate-god $opt(nn)# Configure using NOAH routing in Wireless domain$ns node-config -mobileIP ON \                 -adhocRouting $opt(rp) \                 -llType $opt(ll) \                 -macType $opt(mac) \                 -ifqType $opt(ifq) \                 -ifqLen $opt(ifqlen) \                 -antType $opt(ant) \                 -propType $opt(prop) \                 -phyType $opt(netif) \                 -channelType $opt(chan) \                 -topoInstance $topo \                 -wiredRouting ON \                 -agentTrace ON \                 -routerTrace ON \                 -macTrace ON# Set tranmission Power so that overlapping area is desiredif {$overlap == ""} {    set overlap 30}set power 0.29705643626340894################################################################### create a mobilenode that would be moving between BS3 and BS4.  ###################################################################$ns node-config -wiredRouting OFF; $ns node-config -rxPower $power -txPower $powerset MH_(1) [$ns node  0.6.1]set GFAaddress [AddrParams set-hieraddr [$W(0) node-addr]]makeHfaMH $MH_(1) $GFAaddress##################################################################$ns node-config -wiredRouting ON; ## setup HFA Base Station nodes using NOAH$ns node-config -rxPower $power -txPower $powerset BS(1) [$ns node 0.7.0]$ns node-config -rxPower $power -txPower $powerset BS(2) [$ns node 0.8.0]$ns node-config -rxPower $power -txPower $powerset BS(3) [$ns node 0.9.0]$ns node-config -rxPower $power -txPower $powerset BS(4) [$ns node 0.10.0]foreach i {1 2 3 4} {    makeHfaBS $BS($i)}# Table to convert address between dot format and integer for all wired# nodesforeach i {0 1 2 3 4 5} {    createAddrTable $W($i)}#provide some co-ord (fixed) to these base-station nodes.$BS(1) set X_ 1.000000000000$BS(1) set Y_ 1.000000000000$BS(1) set Z_ 0.000000000000$BS(2) set X_ 140.000000000000$BS(2) set Y_ 140.000000000000$BS(2) set Z_ 0.000000000000$BS(3) set X_ 280.000000000000$BS(3) set Y_ 280.000000000000$BS(3) set Z_ 0.000000000000$BS(4) set X_ 420.000000000000$BS(4) set Y_ 420.000000000000$BS(4) set Z_ 0.000000000000# Set default mobile movement speed, cell overlapping size, simulation time.if {$speed(1) == ""} {    set speed(1) 20.000000000000}# Set tranmission Power so that overlapping area is desiredif {$overlap == ""} {    set overlap 30}set BS1address [AddrParams set-hieraddr [$BS(1) node-addr]]set ns_ [Simulator instance]## Label the Special Node in NAM$ns_ at 0.0 "$BS(1) label HFA_BStation"$ns_ at 0.0 "$BS(2) label HFA_BStation"$ns_ at 0.0 "$BS(3) label HFA_BStation"$ns_ at 0.0 "$BS(4) label HFA_BStation"$ns_ at 0.0 "$W(0) label Gateway_FA"$ns_ at 0.0 "$W(1) label Router"$ns_ at 0.0 "$W(2) label Router"$ns_ at 0.0 "$W(3) label Router"$ns_ at 0.0 "$W(4) label Router"$ns_ at 0.0 "$W(5) label Router"$ns_ at 0.0 "$host label C-Host"# ==================================================================# movement of the MH# move towards other BSset spoint 330.0set dpoint 370.0# number of handoff in this simulation sessionset NumOfHO 110set stime 4 set StayTime 2 set spoint 330.0set dpoint 370.0set dist [expr (sqrt(2 * (pow(($dpoint - $spoint), 2))))]puts "************************** DISTANCE: $dist ***********************"set trip_time [expr ($dist / $speed(1)) + $StayTime]$MH_(1) set Y_ $spoint$MH_(1) set X_ $spointset rnd [new RandomVariable/Uniform]$rnd set min_ 0.0$rnd set max_ 1for {set i 1} {$i < [expr $NumOfHO +1]} {incr i} {    set rv [$rnd value]    set rv [$rnd value]    set rv [$rnd value]    set j [expr $i * $trip_time - $stime]    set k [expr $i % 2]    if { $k == 1 } {         $ns at $j "$MH_(1) setdest $dpoint $dpoint $speed(1)"         $ns at $j "puts =============>>>"    } else {         $ns at $j "$MH_(1) setdest $spoint $spoint $speed(1)"         $ns at $j "puts <<<============="    }    puts "$i*****time: $j"}   if { $opt(x) == 0 || $opt(y) == 0 } {	usage $argv0	exit 1}if {$opt(seed) > 0} {	puts "Seeding Random number generator with $opt(seed)\n"	ns-random $opt(seed)}## Source the Connection and Movement scripts#if { $opt(cp) == "" } {	#puts "*** NOTE: no connection pattern specified."        set opt(cp) "none"} else {	puts "Loading connection pattern..."	source $opt(cp)}if { $opt(sc) == "" } {	#puts "*** NOTE: no scenario file specified."        set opt(sc) "none"} else {	puts "Loading scenario file..."	source $opt(sc)	puts "Load complete..."}# create links between wired and BaseStation nodes$ns duplex-link $host   $W(0) 10Mb 2ms DropTail$ns duplex-link $W(0) $W(1) 10Mb 2ms DropTail$ns duplex-link $W(0) $W(2) 10Mb 2ms DropTail$ns duplex-link $W(1) $W(3) 10Mb 2ms DropTail$ns duplex-link $W(1) $W(4) 10Mb 2ms DropTail$ns duplex-link $W(2) $W(5) 10Mb 2ms DropTail$ns duplex-link $W(3) $BS(1)  10Mb 2ms DropTail$ns duplex-link $W(3) $BS(2)  10Mb 2ms DropTail$ns duplex-link $W(4) $BS(3)  10Mb 2ms DropTail$ns duplex-link $W(5) $BS(4)  10Mb 2ms DropTail$ns duplex-link-op $host   $W(0) orient right$ns duplex-link-op $W(0) $W(1) orient left-down$ns duplex-link-op $W(0) $W(2) orient right-down$ns duplex-link-op $W(1) $W(3) orient left-down$ns duplex-link-op $W(1) $W(4) orient right-down$ns duplex-link-op $W(2) $W(5) orient right-down$ns duplex-link-op $W(3) $BS(1) orient left-down$ns duplex-link-op $W(3) $BS(2) orient right-down$ns duplex-link-op $W(4) $BS(3) orient right-down$ns duplex-link-op $W(5) $BS(4) orient right-down$ns color 1 Blue$ns color 5 Blue$ns color 6 Blue$ns color 7 Blue$ns color 8 green$ns color 22 Blue# Color for Control packet$ns color 0 Red #### Setup UDP connectionset udp0 [new Agent/UDP]$ns attach-agent $host $udp0set cbr_(0) [new Application/Traffic/CBR]$cbr_(0) set interval_ 10ms$cbr_(0) attach-agent $udp0   set null_(0) [new Agent/LossMonitor]$ns attach-agent $MH_(1) $null_(0)   $ns connect $udp0 $null_(0)$udp0 set fid_ 11foreach i {11 12} {$ns color $i Blue}foreach i {1 2 3} {$ns color $i orange}#endof UDP# UDP traffic to the MH 1 and MH 2$ns at 1.0 "$cbr_(0) start"$ns at [expr $opt(stop) - 0.5] "$cbr_(0) stop"## Tell all the nodes when the simulation ends#for {set i 1} {$i < $num_wireless_nodes } {incr i} {    $ns_ at $opt(stop).0000010 "$MH_($i) reset";}foreach i {1 2 3 4} {    $ns_ at $opt(stop).0000010 "$BS($i) reset";}foreach i {1} {$ns_ at $opt(stop).20 "$MH_($i) log-movement"}$ns_ at $opt(stop).21 "finish"$ns_ at $opt(stop).20 "puts \"NS EXITING...\" ; "proc finish {} {	global ns_ trace namtrace null_ cbr_ pktsNum mytrace        global HawaiiRoutingMSF    puts stderr "===================================================="    puts stderr "Result for 1-level Hierarchical Foreign Agent Scheme"    puts stderr "===================================================="    foreach i {0} {	puts stderr "Total number of packet lost:\		[expr [$cbr_($i) set seqno_]-[$null_($i) set npkts_]]"        puts stderr "Total packet sent:[$cbr_($i) set seqno_] \		received:[$null_($i) set npkts_]"    }	$ns_ flush-trace	close $namtrace	close $trace	puts "running nam..."	exec ../../../bin/nam hfa.nam &        puts "Finishing ns.."	exit 0}puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp $opt(rp)"puts $tracefd "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"puts "Starting Simulation..."$ns_ run

⌨️ 快捷键说明

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