Sie sind auf Seite 1von 6

AODV avec 3noeuds

# wrls1.tcl # A 3-node example for ad-hoc simulation with AODV # Define options set val(chan) set val(prop) model set val(netif) type set val(mac) set val(ifq) set val(ll) set val(ant) set val(ifqlen) set val(nn) set val(rp) set val(x) topography set val(y) topography set val(stop) set set set set Channel/WirelessChannel Propagation/TwoRayGround Phy/WirelessPhy Mac/802_11 Queue/DropTail/PriQueue LL Antenna/OmniAntenna 50 5 AODV 500 400 150 ;# channel type ;# radio-propagation ;# network interface ;# ;# ;# ;# ;# ;# ;# ;# X MAC type interface queue type link layer type antenna model max packet in ifq number of mobilenodes routing protocol dimension of

;# Y dimension of ;# time of simulation end

ns [new Simulator] tracefd [open simple.tr w] windowVsTime2 [open win.tr w] namtrace [open simwrls.nam w]

$ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) create-god $val(nn) # # # Create nn mobilenodes [$val(nn)] and attach them to the channel.

# configure the 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) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON

for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns node] } # Provide $node_(0) $node_(0) $node_(0) initial location of mobilenodes set X_ 5.0 set Y_ 5.0 set Z_ 0.0

$node_(1) set X_ 490.0 $node_(1) set Y_ 285.0 $node_(1) set Z_ 0.0 $node_(2) set X_ 150.0 $node_(2) set Y_ 240.0 $node_(2) set Z_ 0.0 $node_(3) set X_ 250.0 $node_(3) set Y_ 240.0 $node_(3) set Z_ 0.0 $node_(4) set X_ 100.0 $node_(4) set Y_ 70.0 $node_(4) set Z_ 0.0

# Generation of movements $ns at 10.0 "$node_(0) setdest 250.0 250.0 10.0" $ns at 15.0 "$node_(1) setdest 45.0 285.0 10.0" $ns at 110.0 "$node_(0) setdest 480.0 300.0 10.0" $ns at 70.0 "$node_(3) setdest 180.0 30.0 10.0" # Set a TCP connection between node_(0) and node_(1) set tcp [new Agent/TCP/Newreno] $tcp set class_ 2 set sink [new Agent/TCPSink] $ns attach-agent $node_(0) $tcp $ns attach-agent $node_(1) $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 10.0 "$ftp start" # Printing the window size proc plotWindow {tcpSource file} { global ns set time 0.01 set now [$ns now] set cwnd [$tcpSource set cwnd_] puts $file "$now $cwnd" $ns at [expr $now+$time] "plotWindow $tcpSource $file" } $ns at 10.1 "plotWindow $tcp $windowVsTime2" # Define node initial position in nam for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } # Telling nodes when the simulation ends

for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"; } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 150.01 "puts \"end simulation\" ; $ns halt" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace #Execute nam on the trace file exec nam simwrls.nam & exit 0 } #Call the finish procedure after 5 seconds of simulation time $ns run

AMODV 16 NOEUDS

# Marco Fiore's Patch # ----------------------------------------------------------------------------#remove-all-packet-headers ;# removes all except common #add-packet-header IP LL Mac AODV AOMDV ATR DSDV DSR OLSR UDP TCP CBR FTP ;# needed headers Mac/802_11 set CWMin_ 31 Mac/802_11 set CWMax_ 1023 Mac/802_11 set SlotTime_ 0.000020 ;# 20us Mac/802_11 set SIFS_ 0.000010 ;# 10us Mac/802_11 set PreambleLength_ 144 ;# 144 bit Mac/802_11 set ShortPreambleLength_ 72 ;# 72 bit Mac/802_11 set PreambleDataRate_ 1.0e6 ;# 1Mbps Mac/802_11 set PLCPHeaderLength_ 48 ;# 48 bits Mac/802_11 set PLCPDataRate_ 1.0e6 ;# 1Mbps Mac/802_11 set ShortPLCPDataRate_ 2.0e6 ;# 2Mbps Mac/802_11 set RTSThreshold_ 3000 ;# bytes Mac/802_11 set ShortRetryLimit_ 7 ;# retransmissions Mac/802_11 set LongRetryLimit_ 4 ;# retransmissions Mac/802_11 set newchipset_ false ;# use new chipset, allowing a more recent packet to be correctly received in place of the first sensed packet Mac/802_11 set dataRate_ 11Mb ;# 802.11 data transmission rate Mac/802_11 set basicRate_ 1Mb ;# 802.11 basic transmission rate Mac/802_11 set aarf_ false ;# 802.11 Auto Rate Fallback #----------------------------------------------------------------------------# Defining options # ----------------------------------------------------------------------------set val(chan) Channel/WirelessChannel ;# channel type set val(ant) Antenna/OmniAntenna ;# antenna type set val(propagation) TwoRay ;# propagation model set val(netif) Phy/WirelessPhy ;# network interface type

set set set set set set set set set set

val(ll) LL ;# link layer type val(ifq) Queue/DropTail/PriQueue ;# interface queue type val(ifqlen) 50 ;# max packet in ifq val(mac) Mac/802_11 ;# MAC type val(rp) AOMDV ;# routing protocol val(nn) 16.0 ;# node number val(stop) 600.0 ;# simulation time [s] val(seed) 1 ;# general pseudo-random sequence generator val(x) 1000 val(y) 1000

# ----------------------------------------------------------------------------# Fixing DSR bug # ----------------------------------------------------------------------------if {$val(rp) == "DSR"} { set val(ifq) CMUPriQueue } # ----------------------------------------------------------------------------# Channel model # ----------------------------------------------------------------------------Antenna/OmniAntenna set X_ 0 Antenna/OmniAntenna set Y_ 0 Antenna/OmniAntenna set Z_ 1.5 Antenna/OmniAntenna set Gt_ 1 ;# transmitter antenna gain Antenna/OmniAntenna set Gr_ 1 ;# receiver antenna gain Phy/WirelessPhy set L_ 1.0 ;# system loss factor (mostly 1.0) if {$val(propagation) == "TwoRay"} { ;# range tx = 250m set val(prop) Propagation/TwoRayGround set prop [new $val(prop)] Phy/WirelessPhy set CPThresh_ 10.0 ;# capture threshold in Watt Phy/WirelessPhy set CSThresh_ 1.559e-11 ;# Carrier Sensing threshold Phy/WirelessPhy set RXThresh_ 3.652e-10 ;# receiver signal threshold Phy/WirelessPhy set freq_ 2.4e9 ;# channel frequency (Hz) Phy/WirelessPhy set Pt_ 0.28 ;# transmitter signal power (Watt) } if {$val(propagation) == "Shado"} { set val(prop) Propagation/Shadowing set prop [new $val(prop)] $prop set pathlossExp_ 3.8 ;# path loss exponent $prop set std_db_ 2.0 ;# shadowing deviation (dB) $prop set seed_ 1 ;# seed for RNG $prop set dist0_ 1.0 ;# reference distance (m) $prop set CPThresh_ 10.0 ;# capture threshold in Watt $prop set RXThresh_ 2.37e-13 ;# receiver signal threshold $prop set CSThresh_ [expr 2.37e-13 * 0.0427] ;# Carrier Sensing threshold $prop set freq_ 2.4e9 ;# channel frequency (Hz) Phy/WirelessPhy set Pt_ 0.28 }

proc getopt {argc argv} { global val lappend optlist nn seed mc rate type

for {set i 0} {$i < $argc} {incr i} { set arg [lindex $argv $i] if {[string range $arg 0 0] != "-"} continue set name [string range $arg 1 end] set val($name) [lindex $argv [expr $i+1]] puts "$name $val($name)" } } getopt $argc $argv # ----------------------------------------------------------------------------# General definition # ----------------------------------------------------------------------------;#Instantiate the simulator set ns_ [new Simulator] ;#Define topology set topo [new Topography] $topo load_flatgrid $val(x) $val(y) ;#Create channel set chan [new $val(chan)] $prop topography $topo create-god $val(nn) $ns_ node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propInstance $prop \ -phyType $val(netif) \ -channel $chan \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace OFF # ----------------------------------------------------------------------------# Trace file definition # ----------------------------------------------------------------------------#New format for wireless traces $ns_ use-newtrace #Create trace object for ns, nam, monitor and Inspect set nsTrc [open $val(log) w] $ns_ trace-all $nsTrc # ----------------------------------------------------------------------------# Nodes definition # -------------------------------------------------------------------------

----;# Create the specified number of nodes [$val(nn)] and "attach" them to the channel. for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 ;# disable random motion } # Define node movement model source $val(cp) ; # connection pattern # Define traffic model source $val(sc) for {set i 0} {$i < $val(nn) } {incr i} { $ns_ at $val(stop) "$node_($i) reset"; } $ns_ at $val(stop) "$ns_ halt" $ns_ run

Das könnte Ihnen auch gefallen