ns2.31下的UWB(Ultra WideBand)实现
源代码在线查看: 2hopudp.tcl
# VARIABLE PART 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) 3 ;# number of mobilenodes set val(rp) MANUAL ;# routing protocol set val(x) 300 set val(y) 300 set filename result Mac/802_11 set RTSThreshold_ 1000 # TRACE PART set ns_ [new Simulator] set tracefd [open $filename.tr w] $ns_ use-newtrace $ns_ trace-all $tracefd set namtrace [open $filename.nam w] $ns_ namtrace-all-wireless $namtrace $val(x) $val(y) set topo [new Topography] $topo load_flatgrid $val(x) $val(y) create-god $val(nn) # NODE CONFIG PART $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 set node_(0) [$ns_ node] $node_(0) random-motion 0 set node_(1) [$ns_ node] $node_(1) random-motion 0 set node_(2) [$ns_ node] $node_(2) random-motion 0 # Add routing tag $node_(0) add-route-tag 2 999 $node_(0) add-next-hop 2 999 1 0 $node_(1) add-next-hop 2 999 2 0 $node_(2) add-route-tag 0 999 $node_(2) add-next-hop 0 999 1 0 $node_(1) add-next-hop 0 999 0 0 # GRAPH PART $node_(0) set X_ 11 $node_(0) set Y_ 11 $node_(0) set Z_ 0.0 $node_(1) set X_ 111 $node_(1) set Y_ 11 $node_(1) set Z_ 0.0 $node_(2) set X_ 211 $node_(2) set Y_ 11 $node_(2) set Z_ 0.0 for {set i 0} {$i < $val(nn) } {incr i} { $ns_ initial_node_pos $node_($i) 50 } set udp0 [new Agent/UDP] set cbr0 [new Application/Traffic/CBR] set null2 [new Agent/Null] $cbr0 set packetSize_ 548 $cbr0 set maxpkts_ 30 $ns_ attach-agent $node_(0) $udp0 $ns_ attach-agent $node_(2) $null2 $udp0 set packetSize_ 1500 $cbr0 attach-agent $udp0 $ns_ connect $udp0 $null2 #set ftp [new Application/FTP] #$ftp attach-agent $tcp $ns_ at 0.02 "$cbr0 start" for {set i 0} {$i < $val(nn) } {incr i} { $ns_ at 5.0 "$node_($i) reset"; } $ns_ at 20.00 "stop" $ns_ at 20.01 "puts \"NS Existing... \";" proc stop {} { global ns_ tracefd global ns_ namtrace $ns_ flush-trace close $tracefd close $namtrace } puts "Starting Simulation..." $ns_ run