Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gnome-text-editor five-node-wireless.tcl &
- # ======================================================================
- # Define Wireless Simulation Parameters
- # ======================================================================
- 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) 5 ;# number of mobilenodes
- set val(rp) AODV ;# AODV Routing (Creates LOTS of broadcast ripples)
- set val(x) 500 ;# X dimension of topography
- set val(y) 500 ;# Y dimension of topography
- set val(stop) 10.0 ;# time of simulation end
- # --- NEW BANDWIDTH OPTION ---
- set val(bw) 11Mb ;# Set your custom bandwidth here (e.g., 2Mb, 11Mb, 54Mb)
- Mac/802_11 set dataRate_ $val(bw)
- Mac/802_11 set basicRate_ 1Mb
- # ======================================================================
- # Initialize Simulator and Trace Files
- # ======================================================================
- set ns_ [new Simulator]
- set tracefd [open five-node-wireless.tr w]
- $ns_ trace-all $tracefd
- set namtrace [open five-node-wireless.nam w]
- $ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
- # ======================================================================
- # Setup Topography and God
- # ======================================================================
- 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
- # ======================================================================
- # Create 5 Nodes and Set Their Starting Positions
- # ======================================================================
- for {set i 0} {$i < $val(nn)} {incr i} {
- set node_($i) [$ns_ node]
- $node_($i) random-motion 0
- }
- $node_(0) set X_ 50.0
- $node_(0) set Y_ 250.0
- $node_(0) set Z_ 0.0
- $node_(1) set X_ 150.0
- $node_(1) set Y_ 100.0
- $node_(1) set Z_ 0.0
- $node_(2) set X_ 250.0
- $node_(2) set Y_ 250.0
- $node_(2) set Z_ 0.0
- $node_(3) set X_ 350.0
- $node_(3) set Y_ 400.0
- $node_(3) set Z_ 0.0
- $node_(4) set X_ 450.0
- $node_(4) set Y_ 250.0
- $node_(4) set Z_ 0.0
- for {set i 0} {$i < $val(nn)} {incr i} {
- $ns_ initial_node_pos $node_($i) 30
- }
- # ======================================================================
- # Setup Network Traffic (Heavy traffic = more ripples)
- # ======================================================================
- # Traffic 1: TCP from Node 0 to Node 4
- set tcp [new Agent/TCP]
- $ns_ attach-agent $node_(0) $tcp
- set sink [new Agent/TCPSink]
- $ns_ attach-agent $node_(4) $sink
- $ns_ connect $tcp $sink
- set ftp [new Application/FTP]
- $ftp attach-agent $tcp
- $ns_ at 0.5 "$ftp start"
- $ns_ at 9.5 "$ftp stop"
- # Traffic 2: Aggressive UDP from Node 1 to Node 3
- set udp1 [new Agent/UDP]
- $ns_ attach-agent $node_(1) $udp1
- set null1 [new Agent/Null]
- $ns_ attach-agent $node_(3) $null1
- $ns_ connect $udp1 $null1
- set cbr1 [new Application/Traffic/CBR]
- $cbr1 set packetSize_ 1024
- $cbr1 set interval_ 0.01 ;# Blasting 100 packets a second
- $cbr1 attach-agent $udp1
- $ns_ at 1.0 "$cbr1 start"
- $ns_ at 8.5 "$cbr1 stop"
- # Traffic 3: Aggressive UDP from Node 2 to Node 0 (Creates cross-traffic ripples)
- set udp2 [new Agent/UDP]
- $ns_ attach-agent $node_(2) $udp2
- set null2 [new Agent/Null]
- $ns_ attach-agent $node_(0) $null2
- $ns_ connect $udp2 $null2
- set cbr2 [new Application/Traffic/CBR]
- $cbr2 set packetSize_ 1024
- $cbr2 set interval_ 0.01 ;# Blasting another 100 packets a second
- $cbr2 attach-agent $udp2
- $ns_ at 1.5 "$cbr2 start"
- $ns_ at 9.0 "$cbr2 stop"
- # ======================================================================
- # Stop the Simulation and Launch NAM
- # ======================================================================
- for {set i 0} {$i < $val(nn)} {incr i} {
- $ns_ at $val(stop) "$node_($i) reset"
- }
- proc finish {} {
- global ns_ tracefd namtrace
- $ns_ flush-trace
- close $tracefd
- close $namtrace
- puts "Simulation Complete. Launching NAM..."
- exec nam five-node-wireless.nam &
- exit 0
- }
- $ns_ at $val(stop) "finish"
- $ns_ at [expr $val(stop) + 0.1] "puts \"NS EXITING...\" ; $ns_ halt"
- puts "Starting Simulation..."
- $ns_ run
- ns five-node-wireless.tcl
Advertisement
Add Comment
Please, Sign In to add comment