AODV Avec 3noeuds

Embed Size (px)

Citation preview

  • 7/27/2019 AODV Avec 3noeuds

    1/6

    AODV avec 3noeuds

    # wrls1.tcl# A 3-node example for ad-hoc simulation with AODV

    # Define optionsset val(chan) Channel/WirelessChannel ;# channel typeset val(prop) Propagation/TwoRayGround ;# radio-propagationmodelset val(netif) Phy/WirelessPhy ;# network interfacetypeset val(mac) Mac/802_11 ;# MAC typeset val(ifq) Queue/DropTail/PriQueue ;# interface queue typeset val(ll) LL ;# link layer typeset val(ant) Antenna/OmniAntenna ;# antenna modelset val(ifqlen) 50 ;# max packet in ifqset val(nn) 5 ;# number of mobilenodesset val(rp) AODV ;# routing protocol

    set val(x) 500 ;# X dimension oftopographyset val(y) 400 ;# Y dimension oftopographyset val(stop) 150 ;# time of simulation end

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

    $ns trace-all $tracefd$ns namtrace-all-wireless $namtrace $val(x) $val(y)

    # set up topography objectset 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

  • 7/27/2019 AODV Avec 3noeuds

    2/6

    for {set i 0} {$i < $val(nn) } { incr i } {set node_($i) [$ns node]

    }

    # Provide initial location of mobilenodes$node_(0) set X_ 5.0

    $node_(0) set Y_ 5.0$node_(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_ 2set sink [new Agent/TCPSink]$ns attach-agent $node_(0) $tcp$ns attach-agent $node_(1) $sink$ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp$ns at 10.0 "$ftp start"

    # Printing the window sizeproc plotWindow {tcpSource file} {

    global nsset time 0.01set 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 namfor {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

  • 7/27/2019 AODV Avec 3noeuds

    3/6

    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-traceclose $tracefdclose $namtrace#Execute nam on the trace fileexec 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 headersMac/802_11 set CWMin_ 31Mac/802_11 set CWMax_ 1023Mac/802_11 set SlotTime_ 0.000020 ;# 20usMac/802_11 set SIFS_ 0.000010 ;# 10usMac/802_11 set PreambleLength_ 144 ;# 144 bitMac/802_11 set ShortPreambleLength_ 72 ;# 72 bitMac/802_11 set PreambleDataRate_ 1.0e6 ;# 1MbpsMac/802_11 set PLCPHeaderLength_ 48 ;# 48 bitsMac/802_11 set PLCPDataRate_ 1.0e6 ;# 1MbpsMac/802_11 set ShortPLCPDataRate_ 2.0e6 ;# 2MbpsMac/802_11 set RTSThreshold_ 3000 ;# bytesMac/802_11 set ShortRetryLimit_ 7 ;# retransmissions

    Mac/802_11 set LongRetryLimit_ 4 ;# retransmissionsMac/802_11 set newchipset_ false ;# use new chipset, allowing a more recentpacket to be correctly received in place of the first sensed packetMac/802_11 set dataRate_ 11Mb ;# 802.11 data transmission rateMac/802_11 set basicRate_ 1Mb ;# 802.11 basic transmission rateMac/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 typeset val(propagation) TwoRay ;# propagation modelset val(netif) Phy/WirelessPhy ;# network interface type

  • 7/27/2019 AODV Avec 3noeuds

    4/6

    set val(ll) LL ;# link layer typeset val(ifq) Queue/DropTail/PriQueue ;# interface queue typeset val(ifqlen) 50 ;# max packet in ifqset val(mac) Mac/802_11 ;# MAC typeset val(rp) AOMDV ;# routing protocolset val(nn) 16.0 ;# node number

    set val(stop) 600.0 ;# simulation time [s]set val(seed) 1 ;# general pseudo-random sequence generatorset val(x) 1000set val(y) 1000

    # ------------------------------------------------------------------------------# Fixing DSR bug# ------------------------------------------------------------------------------if {$val(rp) == "DSR"} {set val(ifq) CMUPriQueue}

    # ------------------------------------------------------------------------------# Channel model# ------------------------------------------------------------------------------Antenna/OmniAntenna set X_ 0Antenna/OmniAntenna set Y_ 0Antenna/OmniAntenna set Z_ 1.5Antenna/OmniAntenna set Gt_ 1 ;# transmitter antenna gainAntenna/OmniAntenna set Gr_ 1 ;# receiver antenna gainPhy/WirelessPhy set L_ 1.0 ;# system loss factor (mostly 1.0)if {$val(propagation) == "TwoRay"} { ;# range tx = 250mset val(prop) Propagation/TwoRayGroundset prop [new $val(prop)]Phy/WirelessPhy set CPThresh_ 10.0 ;# capture threshold in WattPhy/WirelessPhy set CSThresh_ 1.559e-11 ;# Carrier Sensing thresholdPhy/WirelessPhy set RXThresh_ 3.652e-10 ;# receiver signal thresholdPhy/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/Shadowingset 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

  • 7/27/2019 AODV Avec 3noeuds

    5/6

    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 topologyset topo [new Topography]$topo load_flatgrid $val(x) $val(y);#Create channelset chan [new $val(chan)]$prop topography $topocreate-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 Inspectset nsTrc [open $val(log) w]$ns_ trace-all $nsTrc

    # ------------------------------------------------------------------------------

    # Nodes definition# -------------------------------------------------------------------------

  • 7/27/2019 AODV Avec 3noeuds

    6/6

    -----;# Create the specified number of nodes [$val(nn)] and "attach" them to thechannel.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 modelsource $val(cp) ; # connection pattern

    # Define traffic modelsource $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