ns2.31下的UWB(Ultra WideBand)实现

源代码在线查看: 2hops.tcl

软件大小: 849 K
上传用户: z3021440
关键词: WideBand Ultra 2.31 UWB
下载地址: 免注册下载 普通下载 VIP

相关代码

				#-------------------------				# Ajing  2007-4-18				#-------------------------																set val(chan)    Channel/WirelessChannel;    #channel type				set val(prop)    Propagation/TwoRayGround;   #radio-propagation model				set val(ant)     Antenna/OmniAntenna;        #Antenna type				set val(ll)      LL;                         #Link layer type				set val(ifq)     Queue/DropTail/PriQueue;    #Interface queue type				set val(ifqlen)  500;                         #max packet in ifq				set val(netif)   Phy/WirelessPhy;            #network interface type				set val(mac)     Mac/802_11;                 #MAC type				set val(nn)      3;                          #number of mobilenodes				set 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.75ms				Application/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 simulator				set 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 topology				set topo [new Topography]				$topo load_flatgrid 400 300								create-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 nodes				for {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.0								for {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 ends								for {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 functions				proc 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											

相关资源