Forum Replies Created
# Example 4, A simple Wireless Linear Adhoc Network
# ======================================================================
# Define options
# ======================================================================
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) 6 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(energymodel) EnergyModel
set val(initialenergy) 50
# ======================================================================
# Main Program
# ======================================================================
#
# Initialize Global Variables
#
set ns_ [new Simulator]
set tracefd [open WEx_4.tr w]
set namtrace [open WEx_4.nam w]
#$ns_ use-newtrace
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace 800 800
set topo [new Topography]
$topo load_flatgrid 800 800
#
# Create God
#
set god_ [create-god $val(nn)]
set chan_1_ [ new $val(chan) ]
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 3.652e-10
Phy/WirelessPhy set RXThresh_ 3.652e-10 ;# Receiving Threshold
Phy/WirelessPhy set Rb_ 1e6 ;# Bandwidth
Phy/WirelessPhy set Pt_ 0.0010436 ;# 40 m
Phy/WirelessPhy set freq_ 914e+6
Phy/WirelessPhy set L_ 1.0
# configure node
$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)
-channel $chan_1_
-topoInstance $topo
-agentTrace ON
-routerTrace OFF
-macTrace ON
-movementTrace OFF
-energyModel $val(energymodel)
-rxPower 0.0
-txPower 1.0
-idlePower 0.0
-sleepPower 0.00
-transitionPower 0.0
-transitionTime 0.00
-initialEnergy $val(initialenergy)
Phy/WirelessPhy set Pt_ 0.0010436
set opt(netif) Phy/WirelessPhy
$ns_ node-config
-phyType $opt(netif)
-txPower 0.173
-rxPower 0.05
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node $i ]
$ns_ initial_node_pos $node_($i) 15
$node_($i) random-motion 0 ;# disable random motion
$god_ new_node $node_($i)
}
proc coord_proc {a} {
return [expr 30.0 * $a ]
}
#Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
for {set i 0} {$i < $val(nn)} {incr i} {
$node_($i) set X_ [coord_proc $i]
$node_($i) set y_ 2.0
$node_($i) set Z_ 0.0
}
$ns_ at 1.0 “$node_(0) setdest 1 3 15.0”
for { set j 1} {$j<$val(nn)} {incr j} {
$ns_ at 1.0 “$node_($j) setdest [coord_proc $j] 3.0 15.0”
}
$ns_ at 1.0 “$node_(0) add-mark m1 blue circle”
$ns_ at 1.0 “$node_(0) label Base_station”
set null_0 [new Agent/Null]
$ns_ attach-agent $node_(0) $null_0 ;# Making Node 0 as the Base Station
###############################
## Connecting node 1 to node 0
##############################
set udp_(1) [new Agent/UDP]
$udp_(1) set class_ 1
$ns_ attach-agent $node_(1) $udp_(1)
set cbr_(1) [new Application/Traffic/CBR]
$cbr_(1) set packetSize_ 500
$cbr_(1) set interval_ 0.1
$cbr_(1) set random_ 1
$cbr_(1) set set maxpkts_ 10000
$cbr_(1) attach-agent $udp_(1)
$ns_ connect $udp_(1) $null_0
$ns_ at 5 “$cbr_(1) start”
###############################
## Connecting node 2 to node 0
##############################
set udp_(2) [new Agent/UDP]
$udp_(2) set class_ 2
$ns_ attach-agent $node_(2) $udp_(2)
set cbr_(2) [new Application/Traffic/CBR]
$cbr_(2) set packetSize_ 500
$cbr_(2) set interval_ 0.1
$cbr_(2) set random_ 1
$cbr_(2) set set maxpkts_ 10000
$cbr_(2) attach-agent $udp_(2)
$ns_ connect $udp_(2) $null_0
$ns_ at 5 “$cbr_(2) start”
###############################
## Connecting node 3 to node 0
##############################
set udp_(3) [new Agent/UDP]
$udp_(3) set class_ 3
$ns_ attach-agent $node_(3) $udp_(3)
set cbr_(3) [new Application/Traffic/CBR]
$cbr_(3) set packetSize_ 500
$cbr_(3) set interval_ 0.1
$cbr_(3) set random_ 1
$cbr_(3) set set maxpkts_ 10000
$cbr_(3) attach-agent $udp_(3)
$ns_ connect $udp_(3) $null_0
$ns_ at 5 “$cbr_(3) start”
###############################
## Connecting node 4 to node 0
##############################
set udp_(4) [new Agent/UDP]
$udp_(4) set class_ 4
$ns_ attach-agent $node_(4) $udp_(4)
set cbr_(4) [new Application/Traffic/CBR]
$cbr_(4) set packetSize_ 500
$cbr_(4) set interval_ 0.1
$cbr_(4) set random_ 1
$cbr_(4) set set maxpkts_ 10000
$cbr_(4) attach-agent $udp_(4)
$ns_ connect $udp_(4) $null_0
$ns_ at 5 “$cbr_(4) start”
###############################
## Connecting node 5 to node 0
##############################
set udp_(5) [new Agent/UDP]
$udp_(5) set class_ 5
$ns_ attach-agent $node_(5) $udp_(5)
set cbr_(5) [new Application/Traffic/CBR]
$cbr_(5) set packetSize_ 500
$cbr_(5) set interval_ 0.1
$cbr_(5) set random_ 1
$cbr_(5) set set maxpkts_ 10000
$cbr_(5) attach-agent $udp_(5)
$ns_ connect $udp_(5) $null_0
$ns_ at 5 “$cbr_(5) start”
#######################################
###################################################
$ns_ at 50.01 “stop”
$ns_ at 50.01 “puts “NS EXITING…” ; $ns_ halt”
proc stop {} {
global ns_ tracefd
$ns_ flush-trace
close $tracefd
puts “Finishing ns..”
exit 0
}
puts “Starting Simulation…”
$ns_ run[/code]
@aaron1125 wrote:
I want to do wireless sensor networks simulations under NS2.33.
Anybody can provide some sample code or suggestion in order to have an idea on simulating wsn under NS2?
please help me.
thank you.
How to send the code.
I am new to the forum.
Give your email id