NS2 in Ad Hoc Network

Document Sample
NS2 in Ad Hoc Network Powered By Docstoc
					NS2 in Ad Hoc Network

     492516207
       邱朝螢
Ad Hoc Wireless Simulations in
            NS2
   Topography
   Routing Protocols
       AODV
       DSR
       DSDV
       TORA
   Configure Node
   Traffic
   Mobile Node
             Configure Node
   $ns_ node-config
   -adhocRouting AODV \ ;# routing protocol
   -llType LL\ ;# link layer type
   -macType Mac/802_11\ ;# MAC type
   -ifqType Queue/DropTail/PriQueue\ ;# interface
    queue type
   -ifqLen 100 \ ;# max packet in ifq
   -antType Antenna/OmniAntenna\ ;# antenna model
   -propType Propagation/TwoRayGround\ ;# radio-
    propagation model
             Configure Node
   -phyType Phy/WirelessPhy\;# network interface
    type
   -topoInstance $topo \
   -agentTrace ON \
   -routerTrace ON \
   -macTrace OFF \
   -movementTrace OFF \
   -channel $chan_1_
               Topography
   # set up topography object
    set topo [new Topography]
    $topo load_flatgrid $val(x) $val(y)
   # Create God
    create-god $val(nn)
                           Node
   Create Node
       for {set i 0} {$i < $val(nn)} {incr i} {
        set node_($i) [$ns_ node]}
   Random initial node position
       for {set i 0} {$i < $val(nn)} {incr i}{
        $node_($i) set X_ [expr { $val(x)*rand() } ]
        $node_($i) set Y_ [expr { $val(y)*rand() } ]
        $node_($i) set Z_ 0.0
        $node_($i) radius 500}
                          Node
   Initial node size
       for {set i 0} {$i < $val(nn)} {incr i} {
        $ns_ initial_node_pos $node_($i) 50;}
   Link
       $ns duplex-link $n0 $n2 2Mb 10ms DropTail
       $node_($i) radius 500
Simulation of AODV
                        Traffic
   CBR
       set cbr [new Application/Traffic/CBR]
        $cbr attach-agent $udp
        $cbr set packet_size_ 512
        $cbr set packet_rate_ 4
        $cbr set rate_ 2mb
        $ns_ at 0.01 "$cbr start"
        $ns_ at $val(stop) "$cbr stop"
                 Mobile Node
   for {set j 0} {$j < $val(mvnodes)} {incr j} {
    set addx [expr {$val(x)*rand()}]
    set addy [expr {$val(y)*rand()}]
    set ranspeed [expr {$val(nodespeed)*rand()}]
    set temp 0.1
    $ns_ at $temp "$node_($j) setdest $addx $addy
    $ranspeed"
    }

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:5/9/2013
language:English
pages:14