Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set val(chan) Channel/WirelessChannel ;# channel type
- set val(prop) Propagation/TwoRayGround ;# radio-propagation model
- set val(ant) Antenna/OmniAntenna ;# Antenna type
- set val(ll) LL ;# Link layer type
- set val(ifq) Queue/DropTail/PriQueue ;# Interface queue type
- set val(ifqlen) 50 ;# max packet in ifq
- set val(netif) Phy/WirelessPhy ;# network interface type
- set val(mac) Mac/802_11 ;# MAC type
- set val(rp) DSDV ;# ad-hoc routing protocol
- set val(nn) 5 ;# number of mobilenodes
- set val(x) 500
- set val(y) 400
- set val(stop) 150
- set ns [new Simulator]
- set tracefd [open ns2.tr w]
- set windowVsTime2 [open win.tr w]
- set namtrace [open ns2.nam w]
- $ns trace-all $tracefd
- $ns namtrace-all-wireless $namtrace $val(x) $val(y)
- $ns color 2 Red
- 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 245.0 285.0 5.0"
- $ns at 110.0 "$node_(0) setdest 480.0 300.0 10.0"
- set tcp [new Agent/TCP]
- $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
- $tcp set fid_ 2
- set ftp [new Application/FTP]
- $ftp attach-agent $tcp
- $ns at 10.0 "$ftp start"
- proc plotWindow {tcpSource file} {
- global ns
- set time 0.1
- 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
- }
- $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
- exit 0
- }
- $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement