Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.11 KB | None | 0 0
  1. set ns [new Simulator]
  2. set nf [open lab1.nam w]
  3. $ns nametrace-all $nf
  4. #Part 2 exercise section
  5. set f [open lab1.tr w]
  6.  
  7. proc record(){
  8.     global sink f
  9.     set ns [Simulator instance]
  10.     set time 0.15
  11.     set bw [$sink set bytes_]
  12.     set now [$ns now]
  13.     puts $f "$now [expr (($bw/$time)*8)/1000000)]"
  14.     $sink set bytes_ 0
  15.     $ns at [expr $now + $time] "record"
  16. }
  17. #Part 2 end
  18. proc finish(){
  19.     global ns nf f
  20.     $ns flush-trace
  21.     close $nf
  22.     close $f
  23.     exit 0
  24. }
  25.  
  26. #Node creations
  27.  
  28. set n0 [$ns node]
  29. set n1 [$ns node]
  30. $ns duplex-link $n0 $n1
  31. #Transmitting agent
  32. set udp0 [new Agent/UDP]
  33. $udp0 set packetSize_ 1200
  34. $ns attach-agent $n0 $udp0
  35. #Transmittion
  36. set traffic0 [new Application/Traffic/CBR]
  37. $traffic0 set packetSize_ 1200
  38. $traffic0 set interval_ 0.01
  39. $traffic attach-agent $udp0
  40. #Sink agent ( reciever )
  41. set sink [new Agent/LossMonitor]
  42. $ns attach-agent $n1 $sink
  43. #Agent relation
  44. $ns connect $udp0 $sink
  45.  
  46. #Record initiation
  47. $ns at 0.0 "record"
  48. #Traffic initiation
  49. $ns at 2.0 "$traffic0 start"
  50. $ns at 13.0 "$traffic0 stop"
  51. #Script termination / call to finish() function
  52. $ns at 15.0 "finish"
  53. $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement