Advertisement
neeyoo11

Packet Transmission on LAN

May 25th, 2022
699
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set ns [new Simulator]
  2. set namfile [open lab3.tr w]
  3. $ns namtrace-all $namfile
  4. set namfile [open lab3.nam w]
  5. Agent/TCP set packetSize_ 1460
  6. set n0[$ns node]
  7. set n1[$ns node]
  8. set n2[$ns node]
  9. set n3[$ns node]
  10. set n4[$ns node]
  11. $ns duplex-link $n0 $n1 1Mb 10ms DropTail
  12. $ns duplex-link $n1 $n2 1Mb 10ms DropTail
  13. $ns make-lan "$n2 $n3 $n4" 100Mb 1ms LL Queue/DropTail Mac/802_3 Channel Phy/WiredPhy
  14. set errmodel [new ErrorModel]
  15. $errmodel set rate_ 0.2
  16. $errmodel ranvar [new RandomVariable/Uniform]
  17. $errmodel drop-target [new Agent/NULL]
  18. $ns lossmodel $errmodel $n1 $n2
  19. set tcp [new Agent/TCP]
  20. $ns attach-agent $n0 $tcp
  21. set sink [new Agent/TCPSink]
  22. $ns attach-agent $n4 $sink
  23. $ns connect $tcp $sink
  24. set ftp [new Application/FTP]
  25. $ftp attach-agent $tcp
  26. set filesize [expr 4*1024*1024]
  27. $ns at 0.0 "$ftp send $filesize"
  28. proc finish {} {
  29. global ns namfile tracefile
  30. $ns flush-trace
  31. close $namfile
  32. close $tracefile
  33. set awkCode {
  34. BEGIN{}
  35. {
  36. if($1=="d"){
  37. count_packets++;
  38. print $2, count_packets >> "lab3.data"
  39. }
  40. }
  41. END{}
  42. }
  43. exec awk $awkCode lab3.tr
  44. exec xgraph -bb -tk -x Time -y Dropped_Packets lab3.data -bg white &
  45. exit 0
  46. }
  47. $ns at 100.0 "finish"
  48. $ns run
Advertisement
RAW Paste Data Copied
Advertisement