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

📄 2hops.tcl

📁 ns2.31下的UWB(Ultra WideBand)实现
💻 TCL
字号:
#-------------------------# Ajing  2007-4-18#-------------------------set val(chan)    Channel/WirelessChannel;    #channel typeset val(prop)    Propagation/TwoRayGround;   #radio-propagation modelset val(ant)     Antenna/OmniAntenna;        #Antenna typeset val(ll)      LL;                         #Link layer typeset val(ifq)     Queue/DropTail/PriQueue;    #Interface queue typeset val(ifqlen)  500;                         #max packet in ifqset val(netif)   Phy/WirelessPhy;            #network interface typeset val(mac)     Mac/802_11;                 #MAC typeset val(nn)      3;                          #number of mobilenodesset val(rp)      AODV;                       #ad-hoc routing protocol# --------------------------------------------------------------------------------------------------------------------# Some settings to make your results different# Note that differnt settings give different results, you can compare the performance with different settings.# --------------------------------------------------------------------------------------------------------------------# The threshold of RTS function, when the size of the packet is larger than RTSThreshold_, RTS/CTS function is enabled. If yuo don't want to active this function, you could set it to a very big value, such as 999999.Mac/802_11 set RTSThreshold_ 250# The rate of MAC layer, the base-line rate of 802.11a/b/g is 1Mbps. For 802.11b, the rate can be 1, 2, 5.5, 11Mbps. For 802.11a/g, it can be maximized to 54Mbps.Mac/802_11 set dataRate_ 11mb# sending rate of cbr, you can set it to different values, ex. 200Kb, 448Kb or 1mb. corresponds to interval of 3.75msApplication/Traffic/CBR set rate_ 1mb# packet size of cbr packet, the default value is 210 byte, you can change it to other values. I think 210 ~ 1000 will be resonalbe.Application/Traffic/CBR set packetSize_ 210# packet size of UDP frame, the default value is 1000 byte, you can change it to other values. I think 500 ~ 1000 willbe resonable.Agent/UDP set packetSize_ 10000# New a simulatorset ns_ [new Simulator]# New a tracefd file, and trace the wireless communication.set tracefd [open test.tr w]$ns_ use-newtrace;$ns_ trace-all $tracefd# generate nam file, that you can see the video of whole transmission, if you have installed nam successfully, by excuting "nam test.nam"set namnf [open test.nam w]$ns_ namtrace-all-wireless $namnf 700 300# new a file to stall the bandwidth you want to monitor.set ncf [open calfile.tr w]# Generate the topologyset topo [new Topography]$topo load_flatgrid 400 300create-god $val(nn)#Configure nodes     $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 \                      -channelType $val(chan) \                      -agentTrace ON \                      -routerTrace ON \                      -macTrace ON \                      -movementTrace OFF# initialize the nodesfor {set i 0} {$i < $val(nn) } {incr i} {        set node_($i) [$ns_ node]        $node_($i) random-motion 0;     #disable random motion}#to set the position, provide initial (X,Y, for now Z=0) co-ordinates for node_(0) and node_(1)$node_(0) set X_ 150.0$node_(0) set Y_ 100.0$node_(0) set Z_ 0.0$node_(1) set X_ 400.0$node_(1) set Y_ 100.0$node_(1) set Z_ 0.0$node_(2) set X_ 650.0$node_(2) set Y_ 100.0$node_(2) set Z_ 0.0for {set i 0} {$i < $val(nn) } {incr i} {       $ns_ initial_node_pos $node_($i) 30}set udp [new Agent/UDP]set cbr [new Application/Traffic/CBR]set sink [new Agent/LossMonitor]$ns_ attach-agent $node_(0) $udp$ns_ attach-agent $node_(2) $sink$cbr attach-agent $udp$ns_ connect $udp $sink$ns_ at 0.01 "$cbr start"$ns_ at 1 "record"#tell nodes when the simulation endsfor {set i 0} {$i < $val(nn) } {incr i} {    $ns_ at 20.0 "$node_($i) reset";}$ns_ at 20.0001 "stop"$ns_ at 20.0002 "puts \"NS EXITING... \"; $ns_ halt"# Two functionsproc stop {} {     	global ns_ tracefd  namnf ncf     	$ns_ flush-trace     	close $tracefd     	close $namnf	close $ncf}proc record {} {#     	puts "into record"	global ns_ sink ncf	#Set the time after which the procedure should be called again	set time 1	#How many bytes have been received by the sink?	set bw [$sink set bytes_]	#Get the current time        set now [$ns_ now]	# Note, it should be 8.0 here	puts $ncf "$now --- [expr $bw*8.0/$time/1000000]"        	$sink set bytes_ 0        #Re-schedule the procedure        $ns_ at [expr $now+$time] "record"}puts "Starting Simulation..."$ns_ run

⌨️ 快捷键说明

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