# ping-wireless tcl # a simple example for wireless simulation



Download 19.07 Kb.
Date conversion21.03.2016
Size19.07 Kb.
# ping-wireless.tcl

# A simple example for wireless simulation

#===================================================================

# Define options

#===================================================================

set val(chan) Channel/WirelessChannel ;# channel type

set val(prop) Propagation/TwoRayGround ;# radio-propagation model

#set val(prop) Propagation/RFMGroundProp ;# radio-propagation model

#set val(prop) Propagation/SimpleProp ;# radio-propagation model

set val(netif) Phy/WirelessPhy ;# network interface type

set val(mac) Mac/802_11 ;# MAC type

#set val(mac) Mac/Tdma ;# 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) DSDV ;# routing protocol

set val(batterymodel) Battery/Simple ;# battery model

set val(batterymonitor) "on"

set val(initialenergy) 36 ;# Initial battery capacity

set val(radiomodel) Radio/Simple ;# generic radio hardware

set val(receivepower) .5 ;# Receiving Power

set val(transmitpower) .5 ;# Transmitting Power

set val(idlepower) .05 ;# Idle Power
#===================================================================

# Other Settings

#==================================================================
LL set mindelay_ 50us

LL set delay_ 25us

LL set bandwidth_ 0 ;# not used
Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1
# unity gain, omni-directional antennas

# set up the antennas to be centered in the node and 1.5 meters above it

Antenna/OmniAntenna set X_ 0

Antenna/OmniAntenna set Y_ 0

Antenna/OmniAntenna set Z_ 1.5

Antenna/OmniAntenna set Gt_ 1.0

Antenna/OmniAntenna set Gr_ 1.0

# Initialize the SharedMedia for a transmission range of 20 m for TwoRay Ground model

Phy/WirelessPhy set CPThresh_ 10.0

Phy/WirelessPhy set CSThresh_ 1.559e-11

Phy/WirelessPhy set RXThresh_ 4.80696e-07

Phy/WirelessPhy set Rb_ 2*1e6

Phy/WirelessPhy set Pt_ 0.2818

Phy/WirelessPhy set freq_ 914e+6

Phy/WirelessPhy set L_ 1.0

#===================================================================

# Main Program

#===================================================================


#

# Initialize Global Variables

#

#remove-all-packet-headers



#add-packet-header DSDV Agent/Ping Mac/802_11 Mac/Tdma
set ns_ [new Simulator]

set tracefd [open simple.tr w]

$ns_ trace-all $tracefd
# set up topography object

set topo [new Topography]


$topo load_flatgrid 100 100
#

# Create God

#

create-god $val(nn)


#

# Create channel

set chan_1_ [new $val(chan)]
#

# Create the specified number of mobilenodes [$val(nn)] and "attach" them

# to the channel.
# 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 ON \

-macTrace OFF \

-movementTrace OFF \

-energyModel "EnergyModel" \

-initialEnergy $val(initialenergy) \

-rxPower $val(receivepower) \

-txPower $val(transmitpower) \

-idlePower $val(idlepower)

# Generating nodes

for {set i 0} {$i < $val(nn) } {incr i} {

set node_($i) [$ns_ node]

}
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes

$node_(0) set X_ 94.85

$node_(0) set Y_ 12.75

$node_(0) set Z_ 0.0

$node_(1) set X_ 60.79

$node_(1) set Y_ 92.33

$node_(1) set Z_ 0.0

$node_(2) set X_ 41.86

$node_(2) set Y_ 10.13

$node_(2) set Z_ 0.0


#Create two ping agents and attach them to the nodes n0 and n2

set p0 [new Agent/Ping]

$ns attach-agent $n0 $p0
set p1 [new Agent/Ping]

$ns attach-agent $n2 $p1


#Connect the two agents

$ns connect $p0 $p1

#Define a 'recv' function for the class 'Agent/Ping'

Agent/Ping instproc recv {from rtt} {

$self instvar node_

puts "node [$node_ id] received ping answer from \

$from with round-trip-time $rtt ms."

}

#Schedule events



$ns_ at 100.0 "puts \"hell-O\" "

$ns_ at 10.2 "$p0 send"

$ns_ at 10.4 "$p1 send"

$ns_ at 20.6 "$p0 send"

$ns_ at 120.4 "$p0 send"

$ns_ at 200.4 "$p1 send"

$ns_ at 10000.0 "$ns_ halt"
#Run the Simulation

puts "Starting Simulation..."



$ns_ run


The database is protected by copyright ©essaydocs.org 2016
send message

    Main page