Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ======================================================================
- # Define options
- # ======================================================================
- set val(chan) Channel/WirelessChannel ;# Channel Type
- set val(prop) Propagation/TwoRayGround ;# radio-propagation model
- set val(netif) Phy/WirelessPhy
- set val(mac) Mac/802_11
- set arg1 [lindex $argv 0]
- 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) [lindex $argv 0] ;# number of mobilenodes
- set val(rp) [lindex $argv 1] ;# routing protocol
- set val(ifq) Queue/DropTail/PriQueue
- set val(x) 500
- set val(y) 500
- set val(stop) 150;
- set ns [new Simulator]
- #Creating trace file and nam file
- set tracefd [open M.tr w]
- set windowVsTime2 [open win.tr w]
- set namtrace [open M.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)
- # 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 initial location of mobilenodes
- for {set i 0} {$i < $val(nn) } { incr i } {
- set u [new RandomVariable/Uniform]
- $u set min_ 20
- $u set max_ 600
- set y [new RandomVariable/Uniform]
- $y set min_ 20
- $y set max_ 600
- $node_($i) set X_ [$u value]
- $node_($i) set Y_ [$y value]
- $node_($i) set Z_ 0.0
- }
- $node_(0) set X_ 00.0
- $node_(0) set Y_ 100.0
- $node_(0) set Z_ 0.0
- $node_(1) set X_ 20.0
- $node_(1) set Y_ 20.0
- $node_(1) set Z_ 0.0
- $node_(2) set X_ 500.0
- $node_(2) set Y_ 500.0
- $node_(2) set Z_ 0.0
- # Generation of movements
- $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 90.0 "$node_(0) setdest 490.0 300.0 5.0"
- $ns at 10.0 "$node_(2) setdest 100 100.0 20.0"
- # Set a TCP connection between node_(0) and node_(1)
- set tcp [new Agent/TCP]
- $tcp set class_ 2 # Changes window_ for the $tcp object only
- 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 5.0 "$ftp start"
- # Set a TCP connection between node_(2) and node_(1)
- set tcp1 [new Agent/TCP]
- $tcp1 set class_ 3 # Changes window_ for the $tcp object only
- set sink1 [new Agent/TCPSink]
- $ns attach-agent $node_(2) $tcp1
- $ns attach-agent $node_(1) $sink1
- $ns connect $tcp1 $sink1
- set ftp1 [new Application/FTP]
- $ftp1 attach-agent $tcp1
- $ns at 5.0 "$ftp1 start"
- $ns color 2 Blue
- $ns color 3 Red
- # Printing the window size
- proc plotWindow {tcpSource file} {
- global ns
- set time 0.01
- set now [$ns now]
- set packetSize_ 1000 ;
- 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) 35
- }
- # 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
- exec nam M.nam &
- exec ./run.sh &
- exit 0
- }
- $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement