SlideShare uma empresa Scribd logo
1 de 21
Carrier sense
# ======================================================================
# 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)             4                          ;# number of
mobilenodes
set val(rp)             DSDV                        ;# routing protocol
set val(x)       1000.0                    ;
set val(y)       1000.0                    ;
set val(simtime) 10.0                ; #sim time
set val(drate)         2.0e6               ; #default datarate
set val(dist)           100.0                    ;
# ======================================================================
# Main Program
# ======================================================================

if { $argc != 6} {
        puts "Wrong no. of cmdline args."
        puts "Usage: ns csense.tcl -RTSthresh <RTS_Threshold> -CSthresh
<carrier-sense threshold> -dist <x>"
        exit 0
}


proc getopt {argc argv} {
        global val
        lappend optlist RTSthresh CSthresh dist

        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]]
        }

}


getopt $argc $argv

#
# Initialize Global Variables
#
set ns_          [new Simulator]
set tracefd     [open csense.tr w]
$ns_ trace-all $tracefd

#set namtrace [open single-hop.nam w]           ;# for nam tracing
#$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
$ns_ use-newtrace

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

#
# Create God
#

set god_ [ create-god $val(nn) ]


$val(mac) set dataRate_ $val(drate)
if { $val(RTSthresh) >= 0 } { $val(mac) set RTSThreshold_ $val(RTSthresh)
}
if { $val(CSthresh) >= 0 } { $val(netif) set CSThresh_ $val(CSthresh) }
puts "Setting RTS_Threshold to $val(RTSthresh)"
puts "Setting CS_Threshold to $val(CSthresh)"

#
# 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) 
                  -channelType $val(chan) 
                  -topoInstance $topo 
                  -agentTrace ON 
                  -routerTrace ON 
                  -macTrace ON 
                  -movementTrace OFF
for {set i 0} {$i < $val(nn) } {incr i} {
           set node_($i) [$ns_ node]
           $node_($i) random-motion 0        ;# disable random motion
     }



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

#Conversation 1: Node 0 is the source, Node 1 is the dst

     $node_(0) set X_ 50.0
     $node_(0) set Y_ 0.0
     $node_(0) set Z_ 0.0


     $node_(1) set X_ 250.0
     $node_(1) set Y_ 0.0
     $node_(1) set Z_ 0.0

#Conversation 2: Node 2 is the source, Node 3 is the dst

     $node_(2) set X_ 450.0
     $node_(2) set Y_ $val(dist)
     $node_(2) set Z_ 0.0


     $node_(3) set X_ 250.0
     $node_(3) set Y_ $val(dist)
     $node_(3) set Z_ 0.0

# Define node initial position in nam

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

    # 20 defines the node size in nam, must adjust it according to your
scenario
    # The function must be called after mobility model is defined

    $ns_ initial_node_pos $node_($i) 20
}

#Attach a data-sink to destination

     set null_(0) [new Agent/Null]
     $ns_ attach-agent $node_(1) $null_(0)


     set null_(1) [new Agent/Null]
     $ns_ attach-agent $node_(3) $null_(1)
#traffic...make src talk to dst
           set udp_(0) [new Agent/UDP]
           $ns_ attach-agent $node_(0) $udp_(0)

           set cbr_(0) [new Application/Traffic/CBR]
           $cbr_(0) set packetSize_ 1024
           $udp_(0) set packetSize_ 1024
           $cbr_(0) set interval_ 0.001
           $cbr_(0) set random_ 0.18372
           $cbr_(0) set maxpkts_ 1000000
           $cbr_(0) attach-agent $udp_(0)
           $ns_ connect $udp_(0) $null_(0)
           $ns_ at 0.0 "$cbr_(0) start"

             set udp_(1) [new Agent/UDP]
           $ns_ attach-agent $node_(2) $udp_(1)

           set cbr_(1) [new Application/Traffic/CBR]
           $cbr_(1) set packetSize_ 1024
           $udp_(1) set packetSize_ 1024
           $cbr_(1) set interval_ 0.001
           $cbr_(1) set random_ 0.56272
           $cbr_(1) set maxpkts_ 1000000
           $cbr_(1) attach-agent $udp_(1)
           $ns_ connect $udp_(1) $null_(1)
           $ns_ at 1.0 "$cbr_(1) start"


#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at $val(simtime) "$node_($i) reset";
}
$ns_ at $val(simtime) "stop"
$ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt"
proc stop {} {
    global ns_ tracefd
    $ns_ flush-trace
    close $tracefd
}

puts "Starting Simulation..."
$ns_ run


Fairsim:
# ======================================================================
# 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)             4                         ;# number of
mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(sc)      "./scenario"              ;# scenario file
set val(x)       3000.0                    ;
set val(y)       400.0               ;
set val(simtime) 10.0                ; #sim time
set val(drate)         2.0e6               ; #default datarate
set val(dist)          150.0               ; #default datarate
# ======================================================================


if { $argc <   2} {
        puts   "Wrong no. of cmdline args."
        puts   "Usage: ns sim.tcl -dist <dist>"
        exit   0
}


proc getopt {argc argv} {
        global val
        lappend optlist dist

        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]]
        }

}
# Main Program
# ======================================================================

getopt $argc $argv

#
# Initialize Global Variables
#
set ns_          [new Simulator]
set tracefd     [open fairsim.tr w]
$ns_ trace-all $tracefd
set namtrace [open fairsim.nam w]           ;# for nam tracing
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
$ns_ use-newtrace

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

#
# Create God
#

set god_ [ create-god $val(nn) ]


$val(mac) set bandwidth_ 22.0e6
#$val(prop) set pathlossExp_ 3.0

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



     for {set i 0} {$i < $val(nn) } {incr i} {
           set node_($i) [$ns_ node]
           $node_($i) random-motion 0        ;# disable random motion
     }


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

#Node 0 is the source, Node 1 is the dst
$node_(1) set X_ 200.0
     $node_(1) set Y_ 200.0
     $node_(1) set Z_ 0.0

     $node_(0) set X_ 250.0
     $node_(0) set Y_ 200.0
     $node_(0) set Z_ 0.0

     set x [expr 250.0 + $val(dist)]
     $node_(3) set X_ $x
     $node_(3) set Y_ 200.0
     $node_(3) set Z_ 0.0

      $node_(2) set X_ [expr $x + 100.0]
      $node_(2) set Y_ 200.0
      $node_(2) set Z_ 0.0
# Define node initial position in nam

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

    # 20 defines the node size in nam, must adjust it according to your
scenario
    # The function must be called after mobility model is defined

    $ns_ initial_node_pos $node_($i) 20
}

#Attach a data-sink to destination

     set null_(1) [new Agent/Null]
     $ns_ attach-agent $node_(1) $null_(1)


     set null_(3) [new Agent/Null]
     $ns_ attach-agent $node_(3) $null_(3)


#traffic...make sources talk to dst
           set udp_(0) [new Agent/UDP]
           $ns_ attach-agent $node_(0) $udp_(0)

           set cbr_(0) [new Application/Traffic/CBR]
           $cbr_(0) set packetSize_ 512
           $cbr_(0) set interval_ 0.0008
           $cbr_(0) set random_ 0.96749
           $cbr_(0) set maxpkts_ 1000000
           $cbr_(0) attach-agent $udp_(0)

           set udp_(2) [new Agent/UDP]
           $ns_ attach-agent $node_(2) $udp_(2)

           set cbr_(2) [new Application/Traffic/CBR]
           $cbr_(2) set packetSize_ 512
$cbr_(2)   set interval_ 0.0008
             $cbr_(2)   set random_ 0.96749
             $cbr_(2)   set maxpkts_ 1000000
             $cbr_(2)   attach-agent $udp_(2)



             $ns_   connect $udp_(0)   $null_(1)
             $ns_   connect $udp_(2)   $null_(3)
             $ns_   at 0.0 "$cbr_(0)   start"
             $ns_   at 0.0 "$cbr_(2)   start"



#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at $val(simtime) "$node_($i) reset";
}
$ns_ at $val(simtime) "stop"
$ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt"
proc stop {} {
    global ns_ tracefd
    $ns_ flush-trace
    close $tracefd
}

puts "Starting Simulation..."
$ns_ run


Aodv:
set   val(chan) Channel/WirelessChannel ;
set   val(prop) Propagation/TwoRayGround ;
set   val(netif) Phy/WirelessPhy ;
set   val(mac) Mac/802_11 ;
set   val(ifq) Queue/DropTail/PriQueue ;
set   val(ll) LL ;
set   val(ant) Antenna/OmniAntenna ;
set   val(ifqlen) 50 ;
set   val(nn) 3 ;
set   val(rp) AODV ;
set   val(x) 500 ;
set   val(y) 400 ;
set   val(stop) 150 ;

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 topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

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)
                -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]
}

$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

$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

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"
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"

for {set i 0} {$i<$val(nn) } {incr i} {
$ns initial_node_pos $node_($i) 30
}

for {set i 0} {$i<$val(nn) } {incr i} {
          $ns at $val(stop) "$node_($i) reset";
}

$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
}
$ns run


Sim:
# ======================================================================
# Define options
# ======================================================================
set val(chan)           Channel/WirelessChannel    ;# channel type
set val(prop)           Propagation/Shadowing   ;# 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)             2                         ;# number of
mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(sc)      "./scenario"              ;# scenario file
set val(x)       3000.0                    ;
set val(y)       400.0               ;
set val(simtime) 10.0                ; #sim time
set val(drate)         2.0e6               ; #default datarate
set val(dist)          100                 ;
# ======================================================================
# Main Program
# ======================================================================

if { $argc != 2} {
        puts "Wrong no. of cmdline args."
        puts "Usage: ns sim.tcl -dist <x>"
        exit 0
}


proc getopt {argc argv} {
        global val
        lappend optlist dist

        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]]
        }

}



getopt $argc $argv

#
# Initialize Global Variables
#
set ns_          [new Simulator]
set tracefd     [open sim.tr w]
$ns_ trace-all $tracefd

$ns_ use-newtrace

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

#
# Create God
#

set god_ [ create-god $val(nn) ]

$val(netif) set Pt_ 0.100
$val(netif) set RXThresh_ 7.94328e-13
$val(netif) set CSThresh_ 6.30957e-14
$val(mac) set dataRate_ $val(drate)


#Shadowing Model Parameters
$val(prop) set std_db_ 4.0
$val(prop) set pathlossExp_ 3.5


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



     for {set i 0} {$i < $val(nn) } {incr i} {
           set node_($i) [$ns_ node]
           $node_($i) random-motion 0        ;# disable random motion
     }




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

#Node 0 is the source, Node 1 is the dst

     $node_(0) set X_ 100.0
     $node_(0) set Y_ 200.0
     $node_(0) set Z_ 0.0


     $node_(1) set X_ [expr 100.0 + $val(dist)]
$node_(1) set Y_ 200.0
     $node_(1) set Z_ 0.0



# Define node initial position in nam

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

    # 20 defines the node size in nam, must adjust it according to your
scenario
    # The function must be called after mobility model is defined

    $ns_ initial_node_pos $node_($i) 20
}



#Attach a data-sink to destination

     set null_(0) [new Agent/Null]
     $ns_ attach-agent $node_(1) $null_(0)




#traffic...make src talk to dst
           set udp_(0) [new Agent/UDP]
           $ns_ attach-agent $node_(0) $udp_(0)

           set cbr_(0) [new Application/Traffic/CBR]
           $cbr_(0) set packetSize_ 512
           $udp_(0) set packetSize_ 512
           $cbr_(0) set interval_ 0.0008
           $cbr_(0) set random_ 0.96749
           $cbr_(0) set maxpkts_ 1000000
           $cbr_(0) attach-agent $udp_(0)
           $ns_ connect $udp_(0) $null_(0)
           $ns_ at 0.0 "$cbr_(0) start"




#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at $val(simtime) "$node_($i) reset";
}
$ns_ at $val(simtime) "stop"
$ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt"
proc stop {} {
    global ns_ tracefd
$ns_ flush-trace
    close $tracefd
}

puts "Starting Simulation..."
$ns_ run


Rcs_sim:
# ======================================================================
# 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)              100                       ;# default number of
mobilenodes
set val(rp)              AODV                      ;# routing protocol
set val(x)        1500.0                    ;
set val(y)        1500.0                    ;
set val(simtime) 10.0                 ; #sim time
set val(rlen)           10                  ;
# ======================================================================
# Main Program
# ======================================================================



if { $argc != 8 } {
        puts "Wrong no. of cmdline args."
      puts "Usage: ns multi-hop.tcl -rate <rate (Mbps)> -rxthresh
<rcv_threshold> -cpthresh <capture-threshold> -csthresh <carrier-sense
threshold (W)>"
        exit 0
}


proc getopt {argc argv} {
        global val
        lappend optlist rate rxthresh cpthresh csthresh

        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]]
        }


}




getopt $argc $argv
#
# Initialize Global Variables
#
set ns_          [new Simulator]
set tracefd     [open rcssim.tr w]
$ns_ trace-all $tracefd

set namtrace [open rcssim.nam w]           ;# for nam tracing
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
$ns_ use-newtrace

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

#
# Create God
#

set god_ [ create-god $val(nn) ]


#set Propagation parameters
$val(prop) set pathlossExp_ 2.5
$val(prop) set std_db_ 2.0

#set PHY parameters

#2.4 GHz frequency
$val(netif) set freq_ 2.4e+09

#100 mW from Cisco 350
$val(netif) set Pt_ 0.100

$val(netif) set RXThresh_ $val(rxthresh)
$val(netif) set CPThresh_ $val(cpthresh)
$val(netif) set CSThresh_ $val(csthresh)
#$val(netif) set bandwidth_ $val(rate)

#set MAC parameters
#$val(mac) set bandwidth_ $val(rate)
$val(mac) set basicRate_ $val(rate)
$val(mac) set dataRate_ $val(rate)
#set RTSThreshold to some v. large value...effectively shutting down
RTS/CTS
$val(mac) set RTSThreshold_ 10192


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



     for {set i 0} {$i < $val(nn) } {incr i} {
           set node_($i) [$ns_ node]
           $node_($i) random-motion 0        ;# disable random motion
     }




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


     set gridspace [expr $val(x) / $val(rlen)]


     for {set i 0} {$i < $val(rlen) } {incr i} {
           for {set j 0} {$j < $val(rlen) } {incr j} {
                 set a [expr $j + [expr $i * $val(rlen)]]
                 $node_($a) set X_ [expr 0.0 + [ expr $i * $gridspace]]
                 $node_($a) set Y_ [expr 0.0 + [ expr $j * $gridspace]]
                 $node_($a) set Z_ 0.0
           }
     }
# Define node initial position in nam

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

    # 20 defines the node size in nam, must adjust it according to your
scenario
    # The function must be called after mobility model is defined

    $ns_ initial_node_pos $node_($i) 20

           set udp_($i) [new Agent/UDP]
           $udp_($i) set packetSize_ 1024
           $ns_ attach-agent $node_($i) $udp_($i)

           set cbr_($i) [new Application/Traffic/CBR]
           $cbr_($i) set packetSize_ 1024
           $cbr_($i) set interval_ 0.001
           $cbr_($i) set random_ 0.1346
           $cbr_($i) set maxpkts_ 1000000
           $cbr_($i) attach-agent $udp_($i)

           set null_($i) [new Agent/Null]
           $ns_ attach-agent $node_($i) $null_($i)


}


#
# Tell nodes when the simulation ends
#

expr srand(19987)

for {set i 0} {$i < 25 } {incr i} {
    set tmp [expr [expr rand()] * $val(nn)]
    set src [expr int($tmp)]
    set tmp [expr [expr rand()] * $val(nn)]
    set dst [expr int($tmp)]
    puts "$src to $dstn"
    $ns_ connect $udp_($src) $null_($dst)
    $ns_ at [expr 0.1 * $i] "$cbr_($src) start"
    #$ns_ at [expr 0.01 * $i] "puts " cbr_($i) start" "
}

for {set i 0} {$i < $val(nn)} {incr i} {
    $ns_ at $val(simtime) "$node_($i) reset";
}

$ns_ at $val(simtime) "stop"
$ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt"
proc stop {} {
    global ns_ tracefd
    $ns_ flush-trace
    close $tracefd
}
puts "Starting Simulation..."
$ns_ run

Single hop:
# ======================================================================
# 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)             2                         ;# number of
mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(sc)      "./scenario"              ;# scenario file
set val(x)       3000.0                    ;
set val(y)       400.0               ;
set val(simtime) 10.0                ; #sim time
set val(drate)         2.0e6               ; #default datarate
# ======================================================================
# Main Program
# ======================================================================

if { $argc != 2} {
        puts "Wrong no. of cmdline args."
        puts "Usage: ns single-hop.tcl -drate <dataRate>"
        exit 0
}


proc getopt {argc argv} {
        global val
        lappend optlist drate

        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]]
        }
}



getopt $argc $argv

#
# Initialize Global Variables
#
set ns_          [new Simulator]
set tracefd     [open single-hop.tr w]
$ns_ trace-all $tracefd

#set namtrace [open single-hop.nam w]           ;# for nam tracing
#$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
$ns_ use-newtrace

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

#
# Create God
#

set god_ [ create-god $val(nn) ]


$val(mac) set dataRate_ $val(drate)
$val(mac) set bandwidth_ 22.0e6
$val(prop) set pathlossExp_ 4.0

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



     for {set i 0} {$i < $val(nn) } {incr i} {
           set node_($i) [$ns_ node]
           $node_($i) random-motion 0        ;# disable random motion
     }




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

#Node 0 is the source, Node 1 is the dst

     $node_(0) set X_ 100.0
     $node_(0) set Y_ 200.0
     $node_(0) set Z_ 0.0


     $node_(1) set X_ 300.0
     $node_(1) set Y_ 200.0
     $node_(1) set Z_ 0.0



# Define node initial position in nam

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

    # 20 defines the node size in nam, must adjust it according to your
scenario
    # The function must be called after mobility model is defined

    $ns_ initial_node_pos $node_($i) 20
}



#Attach a data-sink to destination

     set null_(0) [new Agent/Null]
     $ns_ attach-agent $node_(1) $null_(0)




#traffic...make src talk to dst
           set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(0) $udp_(0)

           set cbr_(0) [new Application/Traffic/CBR]
           $cbr_(0) set packetSize_ 2048
           $udp_(0) set packetSize_ 2048
           $cbr_(0) set interval_ 0.0008
           $cbr_(0) set random_ 0.96749
           $cbr_(0) set maxpkts_ 1000000
           $cbr_(0) attach-agent $udp_(0)
           $ns_ connect $udp_(0) $null_(0)
           $ns_ at 0.0 "$cbr_(0) start"




#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at $val(simtime) "$node_($i) reset";
}
$ns_ at $val(simtime) "stop"
$ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt"
proc stop {} {
    global ns_ tracefd
    $ns_ flush-trace
    close $tracefd
}

puts "Starting Simulation..."
$ns_ run

Mais conteúdo relacionado

Mais procurados

Error Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks reportError Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks reportMuragesh Kabbinakantimath
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesTeerawat Issariyakul
 
This is not your father's monitoring.
This is not your father's monitoring.This is not your father's monitoring.
This is not your father's monitoring.Mathias Herberts
 
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Mathias Herberts
 
Protocol handler in Gecko
Protocol handler in GeckoProtocol handler in Gecko
Protocol handler in GeckoChih-Hsuan Kuo
 
DashProfiler 200807
DashProfiler 200807DashProfiler 200807
DashProfiler 200807Tim Bunce
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationrjsmelo
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Chih-Hsuan Kuo
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02nikomatsakis
 
Ownership System in Rust
Ownership System in RustOwnership System in Rust
Ownership System in RustChih-Hsuan Kuo
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorialnikomatsakis
 
C++totural file
C++totural fileC++totural file
C++totural filehalaisumit
 
Warp 10 Platform Presentation - Criteo Beer & Tech 2016-02-03
Warp 10 Platform Presentation - Criteo Beer & Tech 2016-02-03Warp 10 Platform Presentation - Criteo Beer & Tech 2016-02-03
Warp 10 Platform Presentation - Criteo Beer & Tech 2016-02-03Mathias Herberts
 
The Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RI
The Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RIThe Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RI
The Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RIEleanor McHugh
 
NativeBoost
NativeBoostNativeBoost
NativeBoostESUG
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueGleicon Moraes
 

Mais procurados (20)

Error Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks reportError Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks report
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
 
This is not your father's monitoring.
This is not your father's monitoring.This is not your father's monitoring.
This is not your father's monitoring.
 
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108
 
Protocol handler in Gecko
Protocol handler in GeckoProtocol handler in Gecko
Protocol handler in Gecko
 
DashProfiler 200807
DashProfiler 200807DashProfiler 200807
DashProfiler 200807
 
Introduction to Rust
Introduction to RustIntroduction to Rust
Introduction to Rust
 
Venkat ns2
Venkat ns2Venkat ns2
Venkat ns2
 
Rust言語紹介
Rust言語紹介Rust言語紹介
Rust言語紹介
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
Ownership System in Rust
Ownership System in RustOwnership System in Rust
Ownership System in Rust
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
 
C++totural file
C++totural fileC++totural file
C++totural file
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 
Warp 10 Platform Presentation - Criteo Beer & Tech 2016-02-03
Warp 10 Platform Presentation - Criteo Beer & Tech 2016-02-03Warp 10 Platform Presentation - Criteo Beer & Tech 2016-02-03
Warp 10 Platform Presentation - Criteo Beer & Tech 2016-02-03
 
The Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RI
The Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RIThe Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RI
The Ruby Guide to *nix Plumbing: on the quest for efficiency with Ruby [M|K]RI
 
NativeBoost
NativeBoostNativeBoost
NativeBoost
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
 

Destaque

Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Shaikhul Islam Chowdhury
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2amreshrai02
 
Simulation d'un réseau Ad-Hoc sous NS2
Simulation d'un réseau Ad-Hoc sous NS2Simulation d'un réseau Ad-Hoc sous NS2
Simulation d'un réseau Ad-Hoc sous NS2Rihab Chebbah
 
Use of NS-2 to Simulate MANET Routing Algorithms
Use of NS-2 to Simulate MANET Routing AlgorithmsUse of NS-2 to Simulate MANET Routing Algorithms
Use of NS-2 to Simulate MANET Routing AlgorithmsGiancarlo Romeo
 
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...Manoj Subramanian
 
Cour simulation ns2
Cour simulation ns2Cour simulation ns2
Cour simulation ns2Gilles Samba
 
Routage dans les réseaux ad hoc
Routage dans les réseaux ad hocRoutage dans les réseaux ad hoc
Routage dans les réseaux ad hochamouze
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manualPrabhu D
 
The Performance Analysis of Selected Routing Protocols for Mobile Ad hoc Netw...
The Performance Analysis of Selected Routing Protocols for Mobile Ad hoc Netw...The Performance Analysis of Selected Routing Protocols for Mobile Ad hoc Netw...
The Performance Analysis of Selected Routing Protocols for Mobile Ad hoc Netw...Oluwatomi Ajayi
 
An alternative Routing Mechanisms for Mobile Ad-hoc NetworksPresentation2
An alternative Routing Mechanisms for Mobile Ad-hoc NetworksPresentation2An alternative Routing Mechanisms for Mobile Ad-hoc NetworksPresentation2
An alternative Routing Mechanisms for Mobile Ad-hoc NetworksPresentation2Aws Ali
 
A Review of Ad hoc on demand distance vector routing and proposed AR-AODV
A Review of Ad hoc on demand distance vector routing and proposed AR-AODVA Review of Ad hoc on demand distance vector routing and proposed AR-AODV
A Review of Ad hoc on demand distance vector routing and proposed AR-AODVEditor IJMTER
 
Informe 1er debate proy OM reg barrios
Informe 1er debate proy OM reg barrios Informe 1er debate proy OM reg barrios
Informe 1er debate proy OM reg barrios Carlos Páez Pérez
 
Analysis of Packet Loss Rate in Wireless Sensor Network using LEACH Protocol
Analysis of Packet Loss Rate in Wireless Sensor Network using LEACH ProtocolAnalysis of Packet Loss Rate in Wireless Sensor Network using LEACH Protocol
Analysis of Packet Loss Rate in Wireless Sensor Network using LEACH ProtocolIJTET Journal
 

Destaque (20)

Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2
 
Ns2
Ns2Ns2
Ns2
 
Simulation d'un réseau Ad-Hoc sous NS2
Simulation d'un réseau Ad-Hoc sous NS2Simulation d'un réseau Ad-Hoc sous NS2
Simulation d'un réseau Ad-Hoc sous NS2
 
Use of NS-2 to Simulate MANET Routing Algorithms
Use of NS-2 to Simulate MANET Routing AlgorithmsUse of NS-2 to Simulate MANET Routing Algorithms
Use of NS-2 to Simulate MANET Routing Algorithms
 
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
 
Cour simulation ns2
Cour simulation ns2Cour simulation ns2
Cour simulation ns2
 
Ns2
Ns2Ns2
Ns2
 
Routage dans les réseaux ad hoc
Routage dans les réseaux ad hocRoutage dans les réseaux ad hoc
Routage dans les réseaux ad hoc
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manual
 
Manet ns2
Manet ns2Manet ns2
Manet ns2
 
Routage adhoc
Routage adhocRoutage adhoc
Routage adhoc
 
Manufacturing
ManufacturingManufacturing
Manufacturing
 
The Performance Analysis of Selected Routing Protocols for Mobile Ad hoc Netw...
The Performance Analysis of Selected Routing Protocols for Mobile Ad hoc Netw...The Performance Analysis of Selected Routing Protocols for Mobile Ad hoc Netw...
The Performance Analysis of Selected Routing Protocols for Mobile Ad hoc Netw...
 
An alternative Routing Mechanisms for Mobile Ad-hoc NetworksPresentation2
An alternative Routing Mechanisms for Mobile Ad-hoc NetworksPresentation2An alternative Routing Mechanisms for Mobile Ad-hoc NetworksPresentation2
An alternative Routing Mechanisms for Mobile Ad-hoc NetworksPresentation2
 
A Review of Ad hoc on demand distance vector routing and proposed AR-AODV
A Review of Ad hoc on demand distance vector routing and proposed AR-AODVA Review of Ad hoc on demand distance vector routing and proposed AR-AODV
A Review of Ad hoc on demand distance vector routing and proposed AR-AODV
 
JUF0646518
JUF0646518JUF0646518
JUF0646518
 
Informe 1er debate proy OM reg barrios
Informe 1er debate proy OM reg barrios Informe 1er debate proy OM reg barrios
Informe 1er debate proy OM reg barrios
 
Analysis of Packet Loss Rate in Wireless Sensor Network using LEACH Protocol
Analysis of Packet Loss Rate in Wireless Sensor Network using LEACH ProtocolAnalysis of Packet Loss Rate in Wireless Sensor Network using LEACH Protocol
Analysis of Packet Loss Rate in Wireless Sensor Network using LEACH Protocol
 
3586
35863586
3586
 

Semelhante a Ns2programs

Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Running wireless simulations in ns
Running wireless simulations in nsRunning wireless simulations in ns
Running wireless simulations in nsagam_alpine
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHPTaras Kalapun
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoMasahiro Nagano
 
Gta v savegame
Gta v savegameGta v savegame
Gta v savegamehozayfa999
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Laziness in Swift
Laziness in Swift Laziness in Swift
Laziness in Swift SwiftWro
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smartlichtkind
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netProgrammer Blog
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersIan Barber
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기JangHyuk You
 

Semelhante a Ns2programs (20)

Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Running wireless simulations in ns
Running wireless simulations in nsRunning wireless simulations in ns
Running wireless simulations in ns
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
 
Ns2
Ns2Ns2
Ns2
 
Gta v savegame
Gta v savegameGta v savegame
Gta v savegame
 
Ssaw08 0624
Ssaw08 0624Ssaw08 0624
Ssaw08 0624
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Php functions
Php functionsPhp functions
Php functions
 
Laziness in Swift
Laziness in Swift Laziness in Swift
Laziness in Swift
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
 
ddd+scala
ddd+scaladdd+scala
ddd+scala
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기
 
Groovy
GroovyGroovy
Groovy
 

Mais de Meenakshi Devi

Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Meenakshi Devi
 
Mobile computing seminar
Mobile computing seminarMobile computing seminar
Mobile computing seminarMeenakshi Devi
 
Ant colony optimization
Ant colony optimizationAnt colony optimization
Ant colony optimizationMeenakshi Devi
 
Asychronous transfer mode(atm)
Asychronous transfer mode(atm)Asychronous transfer mode(atm)
Asychronous transfer mode(atm)Meenakshi Devi
 

Mais de Meenakshi Devi (6)

Good habits
Good habitsGood habits
Good habits
 
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
 
Mobile computing seminar
Mobile computing seminarMobile computing seminar
Mobile computing seminar
 
Ant colony optimization
Ant colony optimizationAnt colony optimization
Ant colony optimization
 
Asychronous transfer mode(atm)
Asychronous transfer mode(atm)Asychronous transfer mode(atm)
Asychronous transfer mode(atm)
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 

Último

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Último (20)

Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Ns2programs

  • 1. Carrier sense # ====================================================================== # 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) 4 ;# number of mobilenodes set val(rp) DSDV ;# routing protocol set val(x) 1000.0 ; set val(y) 1000.0 ; set val(simtime) 10.0 ; #sim time set val(drate) 2.0e6 ; #default datarate set val(dist) 100.0 ; # ====================================================================== # Main Program # ====================================================================== if { $argc != 6} { puts "Wrong no. of cmdline args." puts "Usage: ns csense.tcl -RTSthresh <RTS_Threshold> -CSthresh <carrier-sense threshold> -dist <x>" exit 0 } proc getopt {argc argv} { global val lappend optlist RTSthresh CSthresh dist 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]] } } getopt $argc $argv #
  • 2. # Initialize Global Variables # set ns_ [new Simulator] set tracefd [open csense.tr w] $ns_ trace-all $tracefd #set namtrace [open single-hop.nam w] ;# for nam tracing #$ns_ namtrace-all-wireless $namtrace $val(x) $val(y) $ns_ use-newtrace # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # # Create God # set god_ [ create-god $val(nn) ] $val(mac) set dataRate_ $val(drate) if { $val(RTSthresh) >= 0 } { $val(mac) set RTSThreshold_ $val(RTSthresh) } if { $val(CSthresh) >= 0 } { $val(netif) set CSThresh_ $val(CSthresh) } puts "Setting RTS_Threshold to $val(RTSthresh)" puts "Setting CS_Threshold to $val(CSthresh)" # # 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) -channelType $val(chan) -topoInstance $topo -agentTrace ON -routerTrace ON -macTrace ON -movementTrace OFF
  • 3. for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 ;# disable random motion } # # Provide initial (X,Y, Z=0) co-ordinates for mobilenodes # #Conversation 1: Node 0 is the source, Node 1 is the dst $node_(0) set X_ 50.0 $node_(0) set Y_ 0.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 250.0 $node_(1) set Y_ 0.0 $node_(1) set Z_ 0.0 #Conversation 2: Node 2 is the source, Node 3 is the dst $node_(2) set X_ 450.0 $node_(2) set Y_ $val(dist) $node_(2) set Z_ 0.0 $node_(3) set X_ 250.0 $node_(3) set Y_ $val(dist) $node_(3) set Z_ 0.0 # Define node initial position in nam for {set i 0} {$i < $val(nn)} {incr i} { # 20 defines the node size in nam, must adjust it according to your scenario # The function must be called after mobility model is defined $ns_ initial_node_pos $node_($i) 20 } #Attach a data-sink to destination set null_(0) [new Agent/Null] $ns_ attach-agent $node_(1) $null_(0) set null_(1) [new Agent/Null] $ns_ attach-agent $node_(3) $null_(1)
  • 4. #traffic...make src talk to dst set udp_(0) [new Agent/UDP] $ns_ attach-agent $node_(0) $udp_(0) set cbr_(0) [new Application/Traffic/CBR] $cbr_(0) set packetSize_ 1024 $udp_(0) set packetSize_ 1024 $cbr_(0) set interval_ 0.001 $cbr_(0) set random_ 0.18372 $cbr_(0) set maxpkts_ 1000000 $cbr_(0) attach-agent $udp_(0) $ns_ connect $udp_(0) $null_(0) $ns_ at 0.0 "$cbr_(0) start" set udp_(1) [new Agent/UDP] $ns_ attach-agent $node_(2) $udp_(1) set cbr_(1) [new Application/Traffic/CBR] $cbr_(1) set packetSize_ 1024 $udp_(1) set packetSize_ 1024 $cbr_(1) set interval_ 0.001 $cbr_(1) set random_ 0.56272 $cbr_(1) set maxpkts_ 1000000 $cbr_(1) attach-agent $udp_(1) $ns_ connect $udp_(1) $null_(1) $ns_ at 1.0 "$cbr_(1) start" # # Tell nodes when the simulation ends # for {set i 0} {$i < $val(nn) } {incr i} { $ns_ at $val(simtime) "$node_($i) reset"; } $ns_ at $val(simtime) "stop" $ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt" proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd } puts "Starting Simulation..." $ns_ run Fairsim: # ====================================================================== # Define options # ====================================================================== set val(chan) Channel/WirelessChannel ;# channel type
  • 5. 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) 4 ;# number of mobilenodes set val(rp) AODV ;# routing protocol set val(sc) "./scenario" ;# scenario file set val(x) 3000.0 ; set val(y) 400.0 ; set val(simtime) 10.0 ; #sim time set val(drate) 2.0e6 ; #default datarate set val(dist) 150.0 ; #default datarate # ====================================================================== if { $argc < 2} { puts "Wrong no. of cmdline args." puts "Usage: ns sim.tcl -dist <dist>" exit 0 } proc getopt {argc argv} { global val lappend optlist dist 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]] } } # Main Program # ====================================================================== getopt $argc $argv # # Initialize Global Variables # set ns_ [new Simulator] set tracefd [open fairsim.tr w] $ns_ trace-all $tracefd
  • 6. set namtrace [open fairsim.nam w] ;# for nam tracing $ns_ namtrace-all-wireless $namtrace $val(x) $val(y) $ns_ use-newtrace # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # # Create God # set god_ [ create-god $val(nn) ] $val(mac) set bandwidth_ 22.0e6 #$val(prop) set pathlossExp_ 3.0 # # 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) -channelType $val(chan) -topoInstance $topo -agentTrace ON -routerTrace ON -macTrace ON -movementTrace OFF for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 ;# disable random motion } # # Provide initial (X,Y, Z=0) co-ordinates for mobilenodes # #Node 0 is the source, Node 1 is the dst
  • 7. $node_(1) set X_ 200.0 $node_(1) set Y_ 200.0 $node_(1) set Z_ 0.0 $node_(0) set X_ 250.0 $node_(0) set Y_ 200.0 $node_(0) set Z_ 0.0 set x [expr 250.0 + $val(dist)] $node_(3) set X_ $x $node_(3) set Y_ 200.0 $node_(3) set Z_ 0.0 $node_(2) set X_ [expr $x + 100.0] $node_(2) set Y_ 200.0 $node_(2) set Z_ 0.0 # Define node initial position in nam for {set i 0} {$i < $val(nn)} {incr i} { # 20 defines the node size in nam, must adjust it according to your scenario # The function must be called after mobility model is defined $ns_ initial_node_pos $node_($i) 20 } #Attach a data-sink to destination set null_(1) [new Agent/Null] $ns_ attach-agent $node_(1) $null_(1) set null_(3) [new Agent/Null] $ns_ attach-agent $node_(3) $null_(3) #traffic...make sources talk to dst set udp_(0) [new Agent/UDP] $ns_ attach-agent $node_(0) $udp_(0) set cbr_(0) [new Application/Traffic/CBR] $cbr_(0) set packetSize_ 512 $cbr_(0) set interval_ 0.0008 $cbr_(0) set random_ 0.96749 $cbr_(0) set maxpkts_ 1000000 $cbr_(0) attach-agent $udp_(0) set udp_(2) [new Agent/UDP] $ns_ attach-agent $node_(2) $udp_(2) set cbr_(2) [new Application/Traffic/CBR] $cbr_(2) set packetSize_ 512
  • 8. $cbr_(2) set interval_ 0.0008 $cbr_(2) set random_ 0.96749 $cbr_(2) set maxpkts_ 1000000 $cbr_(2) attach-agent $udp_(2) $ns_ connect $udp_(0) $null_(1) $ns_ connect $udp_(2) $null_(3) $ns_ at 0.0 "$cbr_(0) start" $ns_ at 0.0 "$cbr_(2) start" # # Tell nodes when the simulation ends # for {set i 0} {$i < $val(nn) } {incr i} { $ns_ at $val(simtime) "$node_($i) reset"; } $ns_ at $val(simtime) "stop" $ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt" proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd } puts "Starting Simulation..." $ns_ run Aodv: set val(chan) Channel/WirelessChannel ; set val(prop) Propagation/TwoRayGround ; set val(netif) Phy/WirelessPhy ; set val(mac) Mac/802_11 ; set val(ifq) Queue/DropTail/PriQueue ; set val(ll) LL ; set val(ant) Antenna/OmniAntenna ; set val(ifqlen) 50 ; set val(nn) 3 ; set val(rp) AODV ; set val(x) 500 ; set val(y) 400 ; set val(stop) 150 ; set ns [new Simulator] set tracefd [open simple.tr w] set windowVsTime2 [open win.tr w] set namtrace [open simwrls.nam w]
  • 9. $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) set topo [new Topography] $topo load_flatgrid $val(x) $val(y) 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) -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] } $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 $ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0" $ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0" $ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0" 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"
  • 10. 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" for {set i 0} {$i<$val(nn) } {incr i} { $ns initial_node_pos $node_($i) 30 } for {set i 0} {$i<$val(nn) } {incr i} { $ns at $val(stop) "$node_($i) reset"; } $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 } $ns run Sim: # ====================================================================== # Define options # ====================================================================== set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/Shadowing ;# 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) 2 ;# number of mobilenodes set val(rp) AODV ;# routing protocol set val(sc) "./scenario" ;# scenario file set val(x) 3000.0 ; set val(y) 400.0 ; set val(simtime) 10.0 ; #sim time set val(drate) 2.0e6 ; #default datarate set val(dist) 100 ;
  • 11. # ====================================================================== # Main Program # ====================================================================== if { $argc != 2} { puts "Wrong no. of cmdline args." puts "Usage: ns sim.tcl -dist <x>" exit 0 } proc getopt {argc argv} { global val lappend optlist dist 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]] } } getopt $argc $argv # # Initialize Global Variables # set ns_ [new Simulator] set tracefd [open sim.tr w] $ns_ trace-all $tracefd $ns_ use-newtrace # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # # Create God # set god_ [ create-god $val(nn) ] $val(netif) set Pt_ 0.100 $val(netif) set RXThresh_ 7.94328e-13 $val(netif) set CSThresh_ 6.30957e-14
  • 12. $val(mac) set dataRate_ $val(drate) #Shadowing Model Parameters $val(prop) set std_db_ 4.0 $val(prop) set pathlossExp_ 3.5 # # 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) -channelType $val(chan) -topoInstance $topo -agentTrace ON -routerTrace ON -macTrace ON -movementTrace OFF for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 ;# disable random motion } # # Provide initial (X,Y, Z=0) co-ordinates for mobilenodes # #Node 0 is the source, Node 1 is the dst $node_(0) set X_ 100.0 $node_(0) set Y_ 200.0 $node_(0) set Z_ 0.0 $node_(1) set X_ [expr 100.0 + $val(dist)]
  • 13. $node_(1) set Y_ 200.0 $node_(1) set Z_ 0.0 # Define node initial position in nam for {set i 0} {$i < $val(nn)} {incr i} { # 20 defines the node size in nam, must adjust it according to your scenario # The function must be called after mobility model is defined $ns_ initial_node_pos $node_($i) 20 } #Attach a data-sink to destination set null_(0) [new Agent/Null] $ns_ attach-agent $node_(1) $null_(0) #traffic...make src talk to dst set udp_(0) [new Agent/UDP] $ns_ attach-agent $node_(0) $udp_(0) set cbr_(0) [new Application/Traffic/CBR] $cbr_(0) set packetSize_ 512 $udp_(0) set packetSize_ 512 $cbr_(0) set interval_ 0.0008 $cbr_(0) set random_ 0.96749 $cbr_(0) set maxpkts_ 1000000 $cbr_(0) attach-agent $udp_(0) $ns_ connect $udp_(0) $null_(0) $ns_ at 0.0 "$cbr_(0) start" # # Tell nodes when the simulation ends # for {set i 0} {$i < $val(nn) } {incr i} { $ns_ at $val(simtime) "$node_($i) reset"; } $ns_ at $val(simtime) "stop" $ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt" proc stop {} { global ns_ tracefd
  • 14. $ns_ flush-trace close $tracefd } puts "Starting Simulation..." $ns_ run Rcs_sim: # ====================================================================== # 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) 100 ;# default number of mobilenodes set val(rp) AODV ;# routing protocol set val(x) 1500.0 ; set val(y) 1500.0 ; set val(simtime) 10.0 ; #sim time set val(rlen) 10 ; # ====================================================================== # Main Program # ====================================================================== if { $argc != 8 } { puts "Wrong no. of cmdline args." puts "Usage: ns multi-hop.tcl -rate <rate (Mbps)> -rxthresh <rcv_threshold> -cpthresh <capture-threshold> -csthresh <carrier-sense threshold (W)>" exit 0 } proc getopt {argc argv} { global val lappend optlist rate rxthresh cpthresh csthresh 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]
  • 15. set val($name) [lindex $argv [expr $i+1]] } } getopt $argc $argv # # Initialize Global Variables # set ns_ [new Simulator] set tracefd [open rcssim.tr w] $ns_ trace-all $tracefd set namtrace [open rcssim.nam w] ;# for nam tracing $ns_ namtrace-all-wireless $namtrace $val(x) $val(y) $ns_ use-newtrace # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # # Create God # set god_ [ create-god $val(nn) ] #set Propagation parameters $val(prop) set pathlossExp_ 2.5 $val(prop) set std_db_ 2.0 #set PHY parameters #2.4 GHz frequency $val(netif) set freq_ 2.4e+09 #100 mW from Cisco 350 $val(netif) set Pt_ 0.100 $val(netif) set RXThresh_ $val(rxthresh) $val(netif) set CPThresh_ $val(cpthresh) $val(netif) set CSThresh_ $val(csthresh) #$val(netif) set bandwidth_ $val(rate) #set MAC parameters #$val(mac) set bandwidth_ $val(rate) $val(mac) set basicRate_ $val(rate) $val(mac) set dataRate_ $val(rate)
  • 16. #set RTSThreshold to some v. large value...effectively shutting down RTS/CTS $val(mac) set RTSThreshold_ 10192 # # 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) -channelType $val(chan) -topoInstance $topo -agentTrace ON -routerTrace ON -macTrace ON -movementTrace OFF for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 ;# disable random motion } # # Provide initial (X,Y, Z=0) co-ordinates for mobilenodes # set gridspace [expr $val(x) / $val(rlen)] for {set i 0} {$i < $val(rlen) } {incr i} { for {set j 0} {$j < $val(rlen) } {incr j} { set a [expr $j + [expr $i * $val(rlen)]] $node_($a) set X_ [expr 0.0 + [ expr $i * $gridspace]] $node_($a) set Y_ [expr 0.0 + [ expr $j * $gridspace]] $node_($a) set Z_ 0.0 } }
  • 17. # Define node initial position in nam for {set i 0} {$i < $val(nn)} {incr i} { # 20 defines the node size in nam, must adjust it according to your scenario # The function must be called after mobility model is defined $ns_ initial_node_pos $node_($i) 20 set udp_($i) [new Agent/UDP] $udp_($i) set packetSize_ 1024 $ns_ attach-agent $node_($i) $udp_($i) set cbr_($i) [new Application/Traffic/CBR] $cbr_($i) set packetSize_ 1024 $cbr_($i) set interval_ 0.001 $cbr_($i) set random_ 0.1346 $cbr_($i) set maxpkts_ 1000000 $cbr_($i) attach-agent $udp_($i) set null_($i) [new Agent/Null] $ns_ attach-agent $node_($i) $null_($i) } # # Tell nodes when the simulation ends # expr srand(19987) for {set i 0} {$i < 25 } {incr i} { set tmp [expr [expr rand()] * $val(nn)] set src [expr int($tmp)] set tmp [expr [expr rand()] * $val(nn)] set dst [expr int($tmp)] puts "$src to $dstn" $ns_ connect $udp_($src) $null_($dst) $ns_ at [expr 0.1 * $i] "$cbr_($src) start" #$ns_ at [expr 0.01 * $i] "puts " cbr_($i) start" " } for {set i 0} {$i < $val(nn)} {incr i} { $ns_ at $val(simtime) "$node_($i) reset"; } $ns_ at $val(simtime) "stop" $ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt"
  • 18. proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd } puts "Starting Simulation..." $ns_ run Single hop: # ====================================================================== # 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) 2 ;# number of mobilenodes set val(rp) AODV ;# routing protocol set val(sc) "./scenario" ;# scenario file set val(x) 3000.0 ; set val(y) 400.0 ; set val(simtime) 10.0 ; #sim time set val(drate) 2.0e6 ; #default datarate # ====================================================================== # Main Program # ====================================================================== if { $argc != 2} { puts "Wrong no. of cmdline args." puts "Usage: ns single-hop.tcl -drate <dataRate>" exit 0 } proc getopt {argc argv} { global val lappend optlist drate 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]] }
  • 19. } getopt $argc $argv # # Initialize Global Variables # set ns_ [new Simulator] set tracefd [open single-hop.tr w] $ns_ trace-all $tracefd #set namtrace [open single-hop.nam w] ;# for nam tracing #$ns_ namtrace-all-wireless $namtrace $val(x) $val(y) $ns_ use-newtrace # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # # Create God # set god_ [ create-god $val(nn) ] $val(mac) set dataRate_ $val(drate) $val(mac) set bandwidth_ 22.0e6 $val(prop) set pathlossExp_ 4.0 # # 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) -channelType $val(chan) -topoInstance $topo -agentTrace ON -routerTrace ON
  • 20. -macTrace ON -movementTrace OFF for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 ;# disable random motion } # # Provide initial (X,Y, Z=0) co-ordinates for mobilenodes # #Node 0 is the source, Node 1 is the dst $node_(0) set X_ 100.0 $node_(0) set Y_ 200.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 300.0 $node_(1) set Y_ 200.0 $node_(1) set Z_ 0.0 # Define node initial position in nam for {set i 0} {$i < $val(nn)} {incr i} { # 20 defines the node size in nam, must adjust it according to your scenario # The function must be called after mobility model is defined $ns_ initial_node_pos $node_($i) 20 } #Attach a data-sink to destination set null_(0) [new Agent/Null] $ns_ attach-agent $node_(1) $null_(0) #traffic...make src talk to dst set udp_(0) [new Agent/UDP]
  • 21. $ns_ attach-agent $node_(0) $udp_(0) set cbr_(0) [new Application/Traffic/CBR] $cbr_(0) set packetSize_ 2048 $udp_(0) set packetSize_ 2048 $cbr_(0) set interval_ 0.0008 $cbr_(0) set random_ 0.96749 $cbr_(0) set maxpkts_ 1000000 $cbr_(0) attach-agent $udp_(0) $ns_ connect $udp_(0) $null_(0) $ns_ at 0.0 "$cbr_(0) start" # # Tell nodes when the simulation ends # for {set i 0} {$i < $val(nn) } {incr i} { $ns_ at $val(simtime) "$node_($i) reset"; } $ns_ at $val(simtime) "stop" $ns_ at $val(simtime).01 "puts "NS EXITING..." ; $ns_ halt" proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd } puts "Starting Simulation..." $ns_ run