Advertisement
fongoses

Exercício A - Item 1

Jan 4th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.91 KB | None | 0 0
  1. #
  2. # Valter Roesler
  3. # UFRGS - Instituto de Informática
  4. #
  5. ##############################################
  6. # TESTE: MOSTRAR ADAPTACAO TCP com UDP
  7. #         Rodar g.bat e usar gnuplot.
  8. ##############################################
  9. set taxaudp 1500kbps ;# Taxa do UDP. Usar 500kbps, 100kbps e 1800kbps
  10. set run_nam 0
  11.  
  12. proc avisaprog {} {
  13. #Get an instance of the simulator
  14.   set ns [Simulator instance]
  15.   set now [$ns now]
  16.   set tempo $now
  17.   puts $now
  18.   set tempo [expr $tempo+1]
  19.   $ns at $tempo avisaprog
  20. }
  21.  
  22. set ns [new Simulator]
  23.  
  24. #Cria arquivos de saida
  25. set f [open out.tr w]
  26. $ns trace-all $f
  27. set nf [open out.nam w]
  28. $ns namtrace-all $nf
  29.  
  30. #Determina cores para os fluxos
  31. $ns color 0 Blue
  32. $ns color 1 Red
  33.  
  34. #Cria a topologia
  35. set n0 [$ns node]
  36. set n1 [$ns node]
  37.  
  38. $ns duplex-link $n0 $n1 2Mb 5ms DropTail
  39. $ns duplex-link-op $n0 $n1 orient right
  40. $ns duplex-link-op $n0 $n1 queuePos 0.5
  41. $ns queue-limit $n0 $n1 20
  42.  
  43. #Cria trafego 0
  44. set tcp0 [new Agent/TCP/FullTcp]
  45. $tcp0 set fid_ 0
  46. $tcp0 set window_ 10
  47. puts [$tcp0 set window_]
  48. set sink0 [new Agent/TCP/FullTcp]
  49. $ns attach-agent $n0 $tcp0
  50. $ns attach-agent $n1 $sink0
  51. $ns connect $tcp0 $sink0
  52. $sink0 listen
  53.  
  54. set ftp0 [new Application/FTP]
  55. $ftp0 attach-agent $tcp0
  56.  
  57. #Cria trafego 1 - UDP
  58. set udp0 [new Agent/UDP]
  59. set udpsink [new Agent/Null]
  60. $udp0 set fid_ 1
  61. $ns attach-agent $n0 $udp0
  62. $ns attach-agent $n1 $udpsink
  63. $ns connect $udp0 $udpsink
  64.  
  65. set cbr0 [new Application/Traffic/CBR]
  66. $cbr0 set packetSize_ 1000
  67. $cbr0 set rate_ $taxaudp
  68. $cbr0 attach-agent $udp0
  69.  
  70. #Escalonamento de trafego
  71. $ns at 0.0 "avisaprog"
  72. $ns at 0.5 "$ftp0 start"
  73. $ns at 2.0 "$cbr0 start"
  74. $ns at 6.0 "$cbr0 stop"
  75. $ns at 8.0 "finish"
  76.  
  77. #Procedimento de finalizacao
  78. proc finish {} {
  79.     global ns nf f run_nam
  80.     $ns flush-trace
  81.     close $nf
  82.     close $f
  83.  
  84.     if {$run_nam} {
  85.       puts "running nam..."
  86.       exec nam out.nam
  87.     }
  88.     exit 0
  89. }
  90.  
  91. $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement