Monday, 25 May 2015

HTCP code in NS2



  set ns [new Simulator]
  set file1 [open out.nam w]
  $ns namtrace-all $file1
  set tf [open ui.tr w]  
  $ns trace-all $tf

# Open the Window trace file
  set winfile [open htcp.tr w]


  proc finish {} {
     global ns file1 tf
     $ns flush-trace
     close $tf
     close $file1
     exec nam out.nam &
     exit 0
  }


# Create the nodes:
  set n0 [$ns node]
  set n2 [$ns node]
  set n3 [$ns node]
  set n4 [$ns node]


  $ns duplex-link $n0 $n2 2Gb 10ms DropTail

  $ns duplex-link $n2 $n3 1.0Gb 200ms DropTail
 
  $ns duplex-link $n3 $n4 2.0Gb 40ms DropTail
 

$ns duplex-link-op $n2 $n3 queuePos 0.1

# Give node position (for NAM)
  $ns duplex-link-op  $n0 $n2 orient right-down
 
  $ns duplex-link-op $n2 $n3 orient right
  $ns duplex-link-op $n3 $n2 orient left
  $ns duplex-link-op  $n3 $n4 orient right-up
 
  $ns queue-limit $n2 $n3 10


  set tcp [new Agent/TCP/Linux]
  $ns at 0 "$tcp select_ca htcp"
  $ns attach-agent $n0 $tcp

  set sink [new Agent/TCPSink/Sack1]
  $sink set ts_echo_rfc1323_ true

  $ns attach-agent $n4 $sink

  $ns connect $tcp $sink
  $tcp set fid_ 1
  $tcp set window_ 1500
  $tcp set packetSize_ 552


  set ftp [new Application/FTP]
  $ftp attach-agent $tcp
  $ftp set type_ FTP

  $ns at 0.1 "$ftp start"
  $ns at 500.0 "$ftp stop"


  proc plotWindow {tcpSource file} {
     global ns

     set time 0.1
     set now [$ns now]
     set cwnd [$tcpSource set cwnd_]
     set wnd [$tcpSource set window_]
     puts $file "$now $cwnd"
     $ns at [expr $now+$time] "plotWindow $tcpSource $file"
  }

  $ns at 0.1 "plotWindow $tcp $winfile"

  $ns at 150.0 "finish"

  $ns run
The xgraph for the above code is
 

 

2 comments:

  1. Good night Mr akarsh,Im from indonesia im a student i have one problem with Tcp westwood agent,im confuse to input tcp agent for westwood in ns2. i was try source code on your blog and me put new agen/TCP/Linux select_ca westwood and its work,and im searching on internet i found other agent tcp of westwood :new agent/TCP/WeswoodNR.i need only tcp westwood no tcp westwood+. i hope you can help me Mr. Thank you

    ReplyDelete
  2. Best Casinos Nearby (ALT) - JamBase
    A map showing casinos and 양산 출장마사지 other gaming 고양 출장마사지 facilities located 서울특별 출장안마 near casinos in the area, located in at 1 의왕 출장안마 Casino 전라북도 출장안마 Dr, Las Vegas, NV, US.

    ReplyDelete