Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set ns [new Simulator]
- set nf [open lab1.nam w]
- $ns nametrace-all $nf
- #Part 2 exercise section
- set f [open lab1.tr w]
- proc record(){
- global sink f
- set ns [Simulator instance]
- set time 0.15
- set bw [$sink set bytes_]
- set now [$ns now]
- puts $f "$now [expr (($bw/$time)*8)/1000000)]"
- $sink set bytes_ 0
- $ns at [expr $now + $time] "record"
- }
- #Part 2 end
- proc finish(){
- global ns nf f
- $ns flush-trace
- close $nf
- close $f
- exit 0
- }
- #Node creations
- set n0 [$ns node]
- set n1 [$ns node]
- $ns duplex-link $n0 $n1
- #Transmitting agent
- set udp0 [new Agent/UDP]
- $udp0 set packetSize_ 1200
- $ns attach-agent $n0 $udp0
- #Transmittion
- set traffic0 [new Application/Traffic/CBR]
- $traffic0 set packetSize_ 1200
- $traffic0 set interval_ 0.01
- $traffic attach-agent $udp0
- #Sink agent ( reciever )
- set sink [new Agent/LossMonitor]
- $ns attach-agent $n1 $sink
- #Agent relation
- $ns connect $udp0 $sink
- #Record initiation
- $ns at 0.0 "record"
- #Traffic initiation
- $ns at 2.0 "$traffic0 start"
- $ns at 13.0 "$traffic0 stop"
- #Script termination / call to finish() function
- $ns at 15.0 "finish"
- $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement