Advertisement
Guest User

Untitled

a guest
Mar 12th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.34 KB | None | 0 0
  1. # инициализация NS2
  2. set ns [new Simulator]
  3. set nf [open out.nam w]
  4. $ns namtrace-all $nf
  5. set f [open out.tr w]
  6. $ns trace-all $f
  7.  
  8. proc finish {} {
  9.   global ns f nf
  10.   $ns flush-trace
  11.   close $f
  12.   close $nf
  13.  
  14.   exec nam out.nam &
  15.   exit 0  
  16. }
  17. #=======================
  18. set N 4
  19. set red_node [$ns node]
  20. set target_node [$ns node]
  21. for {set i 0} {$i < $N } {incr i} {
  22.     set n($i) [$ns node]
  23. }
  24. #=======================
  25. $ns duplex-link $red_node $target_node $N\\Mb 20ms RED
  26. $ns queue-limit $red_node $target_node [expr $N * 10 ]
  27. #=======================
  28. for {set i 0} {$i < $N } {incr i} {
  29.     $ns duplex-link $n($i) $red_node 1Mb 10ms DropTail
  30. }
  31. #=======================
  32. set sink [new Agent/TCPSink]
  33. $ns attach-agent $target_node $sink
  34. set null [new Agent/Null]
  35. $ns attach-agent $target_node $null
  36. #=======================
  37. set udp [$ns create-connection UDP $n(0) Null $target_node 0]
  38. set cbr [new Application/Traffic/CBR]
  39. $cbr attach-agent $udp
  40. $cbr set packetSize_ 1024
  41. $cbr set rate_ 1Mbps
  42. #=======================
  43. for {set i 1} {$i < $N} {incr i} {
  44.     set tcp($i) [$ns create-connection TCP/Reno $n($i) TCPSink $target_node 0]
  45.     set ftp($i) [$tcp($i) attach-source FTP]
  46. }
  47. #=======================
  48. for {set i 1} {$i < $N} {incr i} {
  49.     $ns at 0.0 "$ftp($i) start"
  50. }
  51. $ns at 0.0 "$cbr start"
  52. $ns at 5.0 "finish"
  53. $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement